由http://www.huddledmasses.org/ 制作发布。
使用:
在
-
if( empty($autolinker_array) ) {
-
$autolinker_array = array(
下照模式添加需要加自动连接的地址。
-
<?php
-
/*
-
Plugin Name: AutoLinker
-
Version: 1.3
-
Plugin URI: http://www.huddledmasses.org/
-
Description: Makes links from predefined text
-
Author: Joel Bennett
-
Author URI: http://www.HuddledMasses.org
-
Copyright (c) 2003
-
Released under the GPL license
-
http://www.gnu.org/licenses/gpl.txt
-
This file is part of WordPress.
-
WordPress 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
-
*/
-
-
-
-
-
-
function autolinker($text) {
-
// First, we define all the things we're going to replace:
-
// and we name it weird so nobody will mistakenly use it
-
// each definition is in the form: // "text" => "url",
-
// ESPECIALLY note that they all end with commas EXCEPT the last one
-
global $autolinker_array;
-
-
"my site" => "http://www.antonio.hostonnet.com/",
-
"Geo Docs" => "http://docs.GeoShell.org/",
-
"GeoShell" => "http://www.GeoShell.org/",
-
"W3C" => "http://www.w3.org",
-
"google" => "http://www.google.com",
-
"sohu" => "http://www.sohu.com",
-
);
-
-
}
-
-
$text = " $text ";
-
foreach($autolinker_array as $match => $url) {
-
/* For advanced users, there are several possible regular expressions here....
-
* The safest, "default" one is at the top ...
-
* You (or I) may choose to use one of the others!
-
* Pick whichever you want, and make SURE there is only one that isn't preceded by slashes: //
-
*/
-
// DEFAULT
-
-
$text = preg_replace("|(<[A-Za-z]* [^>]*)<a href="$url">$match</a>([^<]*>)|msU" , "$1$match$2" , $text);
-
-
// SAFER ALTERNATIVE: requires square brackets which will be stripped off matched text
-
-
// SAFER ALTERNATIVE: [GeoShell] would become <a href="http://www.geoshell.org/">GeoShell</a>
-
-
// $text = preg_replace("|[$match]|msU" , "<a href="$url">$match</a>" , $text);
-
-
}
-
-
-
}
-
-
add_filter('the_content', 'autolinker', 7);
-
-
add_filter('comment_text', 'autolinker', 7);
-
-
?>












