flush_rules(); } } //add rewrite rules function anylink_rewrite_rules( $rules ) { $alOption = get_option( 'anylink_options' ); $cat = $alOption['redirectCat']; $newrules = array(); $newrules[$cat . '/([0-9a-z]{4,})/?$'] = 'index.php?' . $cat . '=$matches[1]'; return $newrules + $rules; } /** * This function is to replace old ACTTION hook 'publish_post' * * This change can filter and covert all post types besides * post itself. * * @param string $newStatus the new status of a post * @param string $oldStatus the old status of a post, if new to publish, it's new * @param string $post the post to add action * * @since version 0.1.4 */ function post_published( $newStatus, $oldStatus, $post) { if( $newStatus == 'publish' ) { $covert = new al_covert(); $covert -> covertURLs( $post -> ID ); } } /** * This function is to filter the post whose post type is specified * * Anylink covert all external links at all time, * but only filter the specified ones, the benefit of this is you needn't * regenerate slug any time you changed the post type * * @param object $content provided by hook * @return object $content * * @since version 0.1.4 */ function filterByType( $content ) { $type = get_post_type(); $types = get_option( 'anylink_options' ); $types = $types['postType']; if( empty( $types ) ){ return $content; } if( ( is_string( $types ) && ( $types == $type ) ) || ( is_array( $types ) && array_search( $type, $types ) !== false ) ){ $filter = new al_filter(); $id = get_the_id(); return $filter -> applyFilter( $content, $id ); } else { return $content; } } /** * Call actions when a new comment added * @param int $comment_id is the id of the comment * @param object $comment is the comment object * @since 0.1.9 */ function new_comment( $comment_id, $comment) { $covert = new al_covert(); $covert -> covertURLs( $comment_id, true ); } /** * 把评论内容中的外链转换成内容 * * @param string $comment_text 评论内容 * @param object $comment comment对象,默认为null * @return string $comment_text 返回处理后的评论内容以在页面上显示 * @since 0.2 */ function filter_comment( $comment_text, $comment = null ){ $filter = new al_filter(); if( is_null( $comment ) ) return $comment_text; return $filter -> applyFilter( $comment_text, $comment -> comment_ID, true ); } /** * 把留言者的链接转换成内链 * * @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; } } ?>