本文整理汇总了PHP中link_exists函数的典型用法代码示例。如果您正苦于以下问题:PHP link_exists函数的具体用法?PHP link_exists怎么用?PHP link_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了link_exists函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseLinks
/**
* @param $url
* Функция для парсинга ссылок
*/
function parseLinks($url)
{
global $domain;
//имя домена
global $recursiveDeep;
// глубина рекурсии
global $protocol;
//протокол
global $link_array;
// массив с спарсенными ссылками
if (strlen($url) <= 1) {
return;
}
if ($recursiveDeep == 0) {
//если глубина рекурсии равна 0
$res = parse_url($url);
if ($res != false) {
$domain = $res['host'];
$protocol = $res['scheme'];
} else {
return;
}
}
$recursiveDeep++;
// увеличиваем счетчик глубины рекурсии
$doc = new DOMDocument();
$doc->loadHTML(file_get_contents($url));
$elements = $doc->getElementsByTagName('a');
foreach ($elements as $element) {
if (count($link_array) > 300) {
return;
}
// устанавливаем лимит на кол-во ссылок
$link = $element->getAttribute('href');
if ($link[0] == '/' || $link[0] == '?') {
$link = $protocol . "://" . $domain . $link;
}
$p_link = parse_url($link);
if ($p_link == false) {
continue;
}
if ($p_link["host"] != $domain) {
continue;
}
// проверяем ведет ли эта ссылка на внешний сайт
if (!link_exists($link) && strlen($link) > 1) {
$link_array[] = $link;
if ($recursiveDeep < 5) {
// проверяем глубину рекурсии
parseLinks($link);
}
}
}
$recursiveDeep--;
// уменьшаем счетчик глубины рекурсии
}
示例2: nn_add_link
function nn_add_link($blog_id, $user_id, $domain, $path, $site_id, $meta)
{
$blog_details = get_blog_details($blog_id);
if (preg_match("/.*Test.*/i", $blog_details->blogname)) {
/*
* We don't create links to test sites
*/
return;
} elseif (link_exists($domain)) {
return;
} elseif (preg_match("/^Nerd Nite (.*)\$/", $blog_details->blogname, $matches)) {
$city_name = strtolower($matches[1]);
$term = get_term_by('slug', 'nerdnite', 'link_category');
$linkdata = array('link_name' => $city_name, 'link_url' => $domain, 'link_category' => $term->term_id, 'link_rel' => 'friend');
wp_insert_link($linkdata);
}
return;
}
示例3: links2wp
function links2wp($links = '')
{
// General Housekeeping
global $wpdb;
$count = 0;
// Deal with the links
if (is_array($links)) {
echo '<p>' . __('Importing Links...') . '<br /><br /></p>';
foreach ($links as $link) {
$count++;
extract($link);
if ($title != "") {
if ($cinfo = is_term(csc($title), 'link_category')) {
$category = $cinfo['term_id'];
} else {
$category = wp_insert_term($wpdb->escape(csc($title)), 'link_category');
$category = $category['term_id'];
}
} else {
$linkname = $wpdb->escape(csc($label));
$description = $wpdb->escape(csc($title));
if ($linfo = link_exists($linkname)) {
$ret_id = wp_insert_link(array('link_id' => $linfo, 'link_url' => $href, 'link_name' => $linkname, 'link_category' => $category, 'link_description' => $description));
} else {
$ret_id = wp_insert_link(array('link_url' => $url, 'link_name' => $linkname, 'link_category' => $category, 'link_description' => $description));
}
$dclinks2wplinks[$link_id] = $ret_id;
}
}
add_option('dclinks2wplinks', $dclinks2wplinks);
echo '<p>';
printf(__('Done! <strong>%s</strong> links or link categories imported'), $count);
echo '<br /><br /></p>';
return true;
}
echo __('No Links to Import!');
return false;
}
示例4: links2wp
function links2wp($links = '')
{
// General Housekeeping
global $wpdb;
$count = 0;
// Deal with the links
if (is_array($links)) {
echo '<p>' . __('Importing Links...') . '<br /><br /></p>';
foreach ($links as $link) {
$count++;
extract($link);
// Make nice vars
$category = $wpdb->escape($category);
$linkname = $wpdb->escape($linkname);
$description = $wpdb->escape($description);
if ($linfo = link_exists($linkname)) {
$ret_id = wp_insert_link(array('link_id' => $linfo, 'link_url' => $url, 'link_name' => $linkname, 'link_category' => $category, 'link_description' => $description, 'link_updated' => $date));
} else {
$ret_id = wp_insert_link(array('link_url' => $url, 'link_name' => $linkname, 'link_category' => $category, 'link_description' => $description, 'link_updated' => $date));
}
$txplinks2wplinks[$link_id] = $ret_id;
}
add_option('txplinks2wplinks', $txplinks2wplinks);
echo '<p>';
printf(_n('Done! <strong>%s</strong> link imported', 'Done! <strong>%s</strong> links imported', $count), $count);
echo '<br /><br /></p>';
return true;
}
echo __('No Links to Import!');
return false;
}
示例5: links2wp
function links2wp($links='')
{
// General Housekeeping
global $wpdb;
$count = 0;
// Deal with the links
if(is_array($links))
{
echo '<p>'.__('Importing Links (Friends)...').'<br /><br /></p>';
foreach($links as $link)
{
$count++;
extract($link);
// Make nice vars
$category = $wpdb->escape("Blogroll");
$linkname = utf8_decode($wpdb->escape($friend));
$description = "";
if($linfo = link_exists($linkname))
{
$ret_id = wp_insert_link(array(
'link_id' => $linfo,
'link_url' => $url,
'link_name' => $linkname,
'link_category' => $category,
'link_description' => $description,
'link_updated' => time())
);
}
else
{
$ret_id = wp_insert_link(array(
'link_url' => $url,
'link_name' => $linkname,
'link_category' => $category,
'link_description' => $description,
'link_updated' => time())
);
}
$jawslinks2wplinks[$id] = $ret_id;
}
add_option('jawslinks2wplinks',$jawslinks2wplinks);
echo '<p>';
printf(__('Done! <strong>%s</strong> Links (Friends) imported'), $count);
echo '<br /><br /></p>';
return true;
}
echo __('No Links to Import!');
return false;
}