prefix . "anchor_text"; $table_name_links = $wpdb->prefix . "anchor_redirects"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name_text'") != $table_name_text) { $sql = "CREATE TABLE `$table_name_links` ( `link_id` int(10) unsigned NOT NULL auto_increment, `link_text` varchar(50) NOT NULL, `link_url` varchar(200) NOT NULL, PRIMARY KEY (`link_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; CREATE TABLE `$table_name_text` ( `link_id` int(10) unsigned NOT NULL auto_increment, `link_text` varchar(200) NOT NULL, `link_url` varchar(800) NOT NULL, `nofollow` tinyint(4) NOT NULL, PRIMARY KEY (`link_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); add_option("anchortext_db_version", $anchortext_db_version); } } function anchortext_get_stored_anchors() { global $wpdb; $table_name = $wpdb->prefix . "anchor_text"; $sql = "SELECT link_text, link_url, link_id, nofollow from $table_name;"; $fivesdrafts = $wpdb->get_results($sql); return $fivesdrafts; } function anchortext_get_stored_redirects() { global $wpdb; $table_name = $wpdb->prefix . "anchor_redirects"; $sql = "SELECT link_text, link_url, link_id from $table_name;"; $fivesdrafts = $wpdb->get_results($sql); return $fivesdrafts; } function anchortext_save_anchor($text, $url, $nofollow) { global $wpdb; //check for duplicates $table_name = $wpdb->prefix . "anchor_text"; $sql = "SELECT link_text from $table_name;"; $existing = $wpdb->get_results($sql); foreach ($existing as $one) { if ($one->link_text == $text) { return false; //already exists } } $x = $wpdb->query($wpdb->prepare("INSERT INTO $table_name (link_text, link_url, nofollow) VALUES (%s, %s, %s)", $text, $url, $nofollow)); if ($x === false) { return false; } return true; } function anchortext_save_cloak_link($text, $url) { global $wpdb; //check for duplicates $table_name = $wpdb->prefix . "anchor_redirects"; $sql = "SELECT link_text from $table_name;"; $existing = $wpdb->get_results($sql); foreach ($existing as $one) { if ($one->link_text == $text) { return false; //already exists } } $x = $wpdb->query($wpdb->prepare("INSERT INTO $table_name (link_text, link_url) VALUES (%s, %s)", $text, $url)); if ($x === false) { return false; } return true; } function anchortext_remove_anchor($anchor_id) { global $wpdb; //check for duplicates $table_name = $wpdb->prefix . "anchor_text"; $wpdb->query(($wpdb->prepare("DELETE FROM $table_name WHERE link_id = %d", $anchor_id))); return true; } function anchortext_remove_cloaked_link($anchor_id) { global $wpdb; //check for duplicates $table_name = $wpdb->prefix . "anchor_redirects"; $wpdb->query(($wpdb->prepare("DELETE FROM $table_name WHERE link_id = %s", $anchor_id))); return true; } function anchortext_implement_anchortext($content) { $anchortext = anchortext_get_stored_anchors(); $redirects = anchortext_get_stored_redirects(); $redir_file = $_SERVER['PHP_SELF'] . '?go/'; $tempsplit = preg_split('/(*<\/a>)/',$content,-1,PREG_SPLIT_DELIM_CAPTURE); for($i=0; $i <= count($tempsplit); $i++) { if (substr($tempsplit[$i],0,2) == 'link_text .')(?!<\/a>)(?![^<>]*?>)#i'; $replacement = ''. $anchor->link_text . ''; $temp = preg_replace($pattern, $replacement, $temp,3); } foreach($anchortext as $anchor) { $pattern = '#(?!<.*?)(?!link_text .')(?!<\/a>)(?![^<>]*?>)#i'; if ($anchor->nofollow == 0) { $replacement = ''. $anchor->link_text . ''; } else { $replacement = ''. $anchor->link_text . ''; } $temp = preg_replace($pattern, $replacement, $temp,3); } $output .=$temp; } } $content = $output; return $content; } function anchortext_plugin_menu() { add_options_page('AnchorText Options', 'AnchorText', 8, __FILE__, 'anchortext_plugin_options'); } function anchortext_plugin_options() { echo <<AnchorText Settings

You can specify which text to replace with links here:

EOF; if (array_key_exists('_addingurl',$_POST)) { $nofollow = 0; if (array_key_exists('nofollow', $_POST)) { $nofollow = '1'; } if (anchortext_save_anchor($_POST['words'], $_POST['url'], $nofollow)) { //write in a success note } else { //write in an error } } if (array_key_exists('_addinghiddenurl', $_POST)) { if (anchortext_save_cloak_link($_POST['words'], $_POST['url'])) { //write in a success note } else { //write in an error } } $currentlinks = anchortext_get_stored_anchors(); foreach ($currentlinks as $onelink) { echo ''; } echo << EOF; $pluginpath = anchortext_pluginpath(); echo ''; echo <<
Text Link Nofollow Actions
Add New AnchorText Link
Word(s): Link: Nofollow:

You can specify which text to replace with cloaked links here:

EOF; $currentlinks = anchortext_get_stored_redirects(); foreach ($currentlinks as $onelink) { echo ''; } echo <<
Word(s) Original Link Actions
Add New Cloaked Links
Word(s): Link:
EOF; } if (array_key_exists('anchortextaction',$_GET)) { if ($_GET['anchortextaction']=='remove' && is_numeric($_GET['link_id'])) { anchortext_remove_anchor($_GET['link_id']); exit('1'); } if ($_GET['anchortextaction'] == 'removelink' && is_numeric($_GET['link_id'])) { anchortext_remove_cloaked_link($_GET['link_id']); exit('1'); } } function anchortext_pluginpath() { return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; } function category_overview($wp){ if(stripos($_SERVER['REQUEST_URI'], 'go/') > -1) { $temp = explode('/',$_SERVER['REQUEST_URI']); $keyword = str_replace('-',' ',$temp[count($temp)-1]); global $wpdb; $table_name = $wpdb->prefix . "anchor_redirects"; $sql = "SELECT link_url from $table_name where link_text = '$keyword';"; $link = $wpdb->get_var($sql); if ($link !== null) { Header("Location: $link"); exit(); } } } add_action('init', 'category_overview'); add_filter('the_content','anchortext_implement_anchortext',10, 2); add_action('admin_menu', 'anchortext_plugin_menu'); register_activation_hook(__FILE__,'anchortext_install'); ?> Contact | Cyndi Lauper - Photos, Videos, Music, Biography