with * Add parsing of pipes ([[something|other]] links to "something" and prints as "other") * Use XHTML conforming html (" instead of ') * Show where the broken interlink points to * Set target page title as anchor's title Original Author: Harley Original Plugin URI: http://www.harleyquine.com/php-scripts/interlinks/ Original Author URI: http://www.harleyquine.com */ /* Copyright 2007 Toni Corvera Copyright 2006 Harley (email : harleyquine@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ add_filter('the_content', 'kd_o_interparse'); function kd_o_interreplace($val,$lbl){ global $table_prefix, $wpdb, $user_ID; $table_name = $table_prefix . "posts"; $val = html_entity_decode($val); $post_id = $wpdb->get_var("SELECT ID FROM $table_name WHERE post_title='$val' AND post_status='publish'"); $permalink = get_permalink($post_id); if (empty($lbl)) { $lbl = $val; } if(!$post_id){ $val = "$lbl"; } if($post_id){ $val = "$lbl"; } return $val; } function kd_o_interparse($content){ if(strpos($content, "[[")){ preg_match_all('/(\[\[(.+?)(\|([^|\]]+))?\]\])/',$content,$wikilinks, PREG_SET_ORDER); foreach ($wikilinks as $val) { $new_val = preg_replace('/\[\[(.+?)\]\]/', '$1', $val[2]); $replace_with = kd_o_interreplace($new_val, $val[4]); $content = str_replace($val[0], $replace_with, $content); } } return $content; } ?>