/** * Covert any link to be used as a parameter * * if a link is not in an article, you can call method anylink anywhere * to covert it manually. * * @param string $link external link to be covert * @param integer $postId if the link doesn't belongs any post it will be set to 0 * * @example call anylink() like this: * <? * echo function_exists('anylink') ? anylink('http://dudo.org', get_the_ID()) : 'http://dudo.org'; * ?> * @since version 0.1.5 */ function anylink($link, $postId = 0) { require_once ANYLNK_PATH . '/config.php'; require_once ANYLNK_PATH . '/classes/al_covert.php'; require_once ANYLNK_PATH . '/classes/al_filter.php'; require_once ANYLNK_PATH . '/classes/al_slug.php'; require_once ANYLNK_PATH . '/classes/al_option.php'; $covert = new al_covert(); $filter = new al_filter(); $id = $covert->storeExtLnks((array) $link); //because method storeRel will delete relationships //so we must get all relationships to compare $urls = $filter->getAllLnks($postId); if (!empty($urls)) { foreach ($urls as $url) { $oldUrlIds[] = $url['al_id']; } } $urlIds = array_merge($oldUrlIds, $id); $covert->storeRel($postId, $urlIds); $objSlug = $filter->getSlugById($id); return $filter->getInternalLinkBySlug($objSlug['al_slug']); }
/** * 把留言者的链接转换成内链 * * @param string $comment_url 评论者留下的链接地址 * @since 0.2 */ function filter_comment_urls($comment_url) { //如果没有留下链接,放弃处理 if (empty($comment_url)) { return $comment_url; } $anylink_option = get_option('anylink_options'); $anylink_comment_option = $anylink_option['filter-comment']; //如果设置了不对评论中的链接进行处理则原样返回 if (!$anylink_comment_option) { return $comment_url; } $filter = new al_filter(); //通过链接查找对应的slug $new_comment_url_slug = $filter->get_slug_by_url($comment_url); if (!empty($new_comment_url_slug)) { //根据slug产生内部链接,并返回给模板显示 return $filter->getInternalLinkBySlug($new_comment_url_slug['al_slug']); } else { //如果链接表中没有索引这个链接,那么按原样返回 return $comment_url; } }