/** * check for link existence * * This function can be used either to see if a link exists in the database, or to check if one link has been * attached to a particular anchor. * * To query the whole database, use: * [php] * if(Links::have($that_beautiful_url)) * ... * [/php] * * To check that an article has a link attached, use: * [php] * $anchor = 'article:'.$article['id']; * if(Links::have($that_beautiful_url, $anchor)) * ... * [/php] * * If additional attributes are provided, they are used to update * link description if one exists. * * @param string the external url that is targeted * @param string an internal anchor, if any * @param array updated link attributes, if any * @return either TRUE or FALSE * * @see feeds/feeds.php * @see links/trackback.php * @see services/ping.php */ public static function have($url, $anchor = NULL, $attributes = NULL) { global $context; // does this (link, anchor) tupple exists? $query = "SELECT id FROM " . SQL::table_name('links') . " AS links " . " WHERE links.link_url LIKE '" . SQL::escape($url) . "'"; if ($anchor) { $query .= " AND links.anchor = '{$anchor}'"; } $query .= " LIMIT 1"; // no, this does not exist if (!($row = SQL::query_first($query))) { return FALSE; } // update the link, if any if (isset($row['id']) && is_array($attributes)) { $attributes['id'] = $row['id']; Links::put($attributes); } // the link does exist return TRUE; }
$menu = array_merge($menu, array('links/edit.php?anchor=' . $anchor->get_reference() => i18n::s('Submit another link'))); } $follow_up .= Skin::build_list($menu, 'menu_bar'); $context['text'] .= Skin::build_block($follow_up, 'bottom'); // log the submission of a new link by a non-associate if (!Surfer::is_associate() && is_object($anchor)) { $label = sprintf(i18n::c('New link at %s'), strip_tags($anchor->get_title())); $link = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url() . '#_attachments'; $description = $_REQUEST['link_url'] . "\n" . sprintf(i18n::c('at %s'), '<a href="' . $link . '">' . $link . '</a>'); Logger::notify('links/edit.php: ' . $label, $description); } } // update an existing link } else { // display the form on error if (!Links::put($_REQUEST)) { $item = $_REQUEST; $with_form = TRUE; // follow-up } else { // touch the related anchor $anchor->touch('link:update', $_REQUEST['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y'); // clear cache Links::clear($_REQUEST); // forward to the updated anchor page Safe::redirect($context['url_to_home'] . $context['url_to_root'] . $anchor->get_url() . '#_attachments'); } } // display the form on GET } else { $with_form = TRUE;