robots-meta.php
author Henryk Gerlach <hgerlach@gmx.de>
Thu, 10 Jul 2008 11:53:00 +0200
changeset 3 9ff5cad8a79d
parent 1 a54fe2712ade
permissions -rw-r--r--
Pushed my changes upstream: Vanilla robots-meta 3.0.5
     1 <?php
     2 /*
     3 Plugin Name: Robots Meta
     4 Plugin URI: http://www.joostdevalk.nl/wordpress/robots-meta/
     5 Description: This plugin allows you to add all the appropriate robots meta tags to your pages and feeds, disable unused archives and nofollow unnecessary links.
     6 Author: Joost de Valk
     7 Version: 3.0.2
     8 Author URI: http://www.joostdevalk.nl/
     9 */
    10 
    11 if ( ! class_exists( 'RobotsMeta_Admin' ) ) {
    12 
    13 	class RobotsMeta_Admin {
    14 
    15 		function add_config_page() {
    16 			global $wpdb;
    17 			if ( function_exists('add_submenu_page') ) {
    18 				add_submenu_page('plugins.php','Robots Meta Configuration', 'Robots Meta', 1, basename(__FILE__),array('RobotsMeta_Admin','config_page'));
    19 			}
    20 		} // end add_config_page()
    21 
    22 		function meta_box() {
    23 			if ( function_exists('add_meta_box') ) {
    24 				add_meta_box('robotsmeta','Robots Meta',array('RobotsMeta_Admin','noindex_option_fill'),'post');
    25 				add_meta_box('robotsmeta','Robots Meta',array('RobotsMeta_Admin','noindex_option_fill'),'page');
    26 			} else {
    27 				add_action('dbx_post_sidebar', array('RobotsMeta_Admin','noindex_option'));
    28 				add_action('dbx_page_sidebar', array('RobotsMeta_Admin','noindex_option'));				
    29 			}
    30 		}
    31 		function robotsmeta_insert_post($pID) {
    32 			global $wpdb;
    33 			extract($_POST);
    34 			$wpdb->query("UPDATE $wpdb->posts SET robotsmeta = '$robotsmeta' WHERE ID = $pID");
    35 		}
    36 
    37 		function noindex_option_fill() {
    38 			?>
    39 			<label for="meta_robots_index_follow" class="selectit"><input id="meta_robots_index_follow" name="robotsmeta" type="radio" value="index,follow" <?php if ($robotsmeta == "index,follow") echo 'checked="checked"'?>/> index, follow</label><br/>
    40 			<label for="meta_robots_index_nofollow" class="selectit"><input id="meta_robots_index_nofollow" name="robotsmeta" type="radio" value="index,nofollow" <?php if ($robotsmeta == "index,nofollow") echo 'checked="checked"'?>/> index, nofollow</label><br/>
    41 			<label for="meta_robots_noindex_follow" class="selectit"><input id="meta_robots_noindex_follow" name="robotsmeta" type="radio" value="noindex,follow" <?php if ($robotsmeta == "noindex,follow") echo 'checked="checked"'?>/> noindex, follow</label><br/>
    42 			<label for="meta_robots_noindex_nofollow" class="selectit"><input id="meta_robots_noindex_nofollow" name="robotsmeta" type="radio" value="noindex,nofollow" <?php if ($robotsmeta == "noindex,nofollow") echo 'checked="checked"'?>/> noindex, nofollow</label><br/>
    43 			<?php
    44 		}
    45 
    46 		function noindex_option() {
    47 			global $post;
    48 			$robotsmeta = $post->robotsmeta;
    49 			if (!isset($robotsmeta) || $robotsmeta == "") {
    50 				$robotsmeta = "index,follow";
    51 			}
    52 			if ( current_user_can('edit_posts') ) { ?>
    53 			<fieldset id="robotsmeta-noindexoption" class="dbx-box">
    54 			<h3 class="dbx-handle">Robots Meta</h3>
    55 			<div class="dbx-content">
    56 				<label for="meta_robots_index_follow" class="selectit"><input id="meta_robots_index_follow" name="robotsmeta" type="radio" value="index,follow" <?php if ($robotsmeta == "index,follow") echo 'checked="checked"'?>/> index, follow</label>
    57 				<label for="meta_robots_index_nofollow" class="selectit"><input id="meta_robots_index_nofollow" name="robotsmeta" type="radio" value="index,nofollow" <?php if ($robotsmeta == "index,nofollow") echo 'checked="checked"'?>/> index, nofollow</label>
    58 				<label for="meta_robots_noindex_follow" class="selectit"><input id="meta_robots_noindex_follow" name="robotsmeta" type="radio" value="noindex,follow" <?php if ($robotsmeta == "noindex,follow") echo 'checked="checked"'?>/> noindex, follow</label>
    59 				<label for="meta_robots_noindex_nofollow" class="selectit"><input id="meta_robots_noindex_nofollow" name="robotsmeta" type="radio" value="noindex,nofollow" <?php if ($robotsmeta == "noindex,nofollow") echo 'checked="checked"'?>/> noindex, nofollow</label>
    60 			</div>
    61 			</fieldset>
    62 			<?php 
    63 			}
    64 		}
    65 		
    66 		function config_page() {
    67 			if ( isset($_POST['submitrobots']) ) {
    68 				if (!current_user_can('manage_options')) die(__('You cannot edit the robots.txt file.'));
    69 				check_admin_referer('robots-meta-udpaterobotstxt');
    70 				
    71 				if (file_exists("../robots.txt")) {
    72 					$robots_file = "../robots.txt";
    73 				} else if (file_exists("../../robots.txt")) {
    74 					$robots_file = "../../robots.txt";
    75 				} else {
    76 					$robots_file = false;
    77 				}
    78 				
    79 				$robotsnew = stripslashes($_POST['robotsnew']);
    80 				if ($robots_file != false && is_writeable($robots_file)) {
    81 					$f = fopen($robots_file, 'w+');
    82 					fwrite($f, $robotsnew);
    83 					fclose($f);
    84 				}
    85 			}
    86 			if ( isset($_POST['submithtaccess']) ) {
    87 				if (!current_user_can('manage_options')) die(__('You cannot edit the .htaccess.'));
    88 				check_admin_referer('robots-meta-udpatehtaccesstxt');
    89 
    90 				if (file_exists("../.htaccess")) {
    91 					$htaccess_file = "../.htaccess";
    92 				} else if (file_exists("../../.htaccess")) {
    93 					$htaccess_file = "../../.htaccess";
    94 				} else {
    95 					$htaccess_file = false;
    96 				}
    97 
    98 				$htaccessnew = stripslashes($_POST['htaccessnew']);
    99 				if (is_writeable($htaccess_file)) {
   100 					$f = fopen($htaccess_file, 'w+');
   101 					fwrite($f, $htaccessnew);
   102 					fclose($f);
   103 				}
   104 
   105 			}
   106 			if ( isset($_POST['submit']) ) {
   107 				if (!current_user_can('manage_options')) die(__('You cannot edit the Robots Meta options.'));
   108 				check_admin_referer('robots-meta-udpatesettings');
   109 				
   110 				foreach (array('admin', 'allfeeds', 'commentfeeds', 'disableauthor', 'disabledate', 
   111 				          'disableexplanation', 'login', 'noindexauthor', 'noindexcat', 'noindexdate', 
   112 					  'noindextag', 'noarchive', 'nofollowcatsingle', 'nofollowcatpage', 
   113 					  'nofollowindexlinks', 'nofollowmeta', 'nofollowmeta', 'nofollowcommentlinks', 
   114 					  'nofollowtaglinks', 'noodp', 'noydir', 'pagedhome', 'search', 'replacemetawidget',
   115 					  'redirectsearch', 'trailingslash') 
   116 				as $option_name) {
   117 					if (isset($_POST[$option_name])) {
   118 						$options[$option_name] = true;
   119 					} else {
   120 						$options[$option_name] = false;
   121 					}
   122 				}
   123 			        foreach (array('googleverify', 'msverify', 'yahooverify', 'version') as $option_name) {
   124 					if (isset($_POST[$option_name])) {
   125 						$options[$option_name] = $_POST[$option_name];
   126 					}
   127 				}
   128                                 if ($options['allfeeds']) {
   129 					$options['commentfeeds'] = true;
   130 				} 
   131 				
   132 				$opt = serialize($options);
   133 				update_option('RobotsMeta', $opt);
   134 			}
   135 			
   136 			$opt  = get_option('RobotsMeta');
   137 			$options = unserialize($opt);
   138 			if ($options['allfeeds']) {
   139 				$options['comments'] = true;
   140 			}
   141 
   142 			if (file_exists("../robots.txt")) {
   143 				$robots_file = "../robots.txt";
   144 			} else if (file_exists("../../robots.txt")) {
   145 				$robots_file = "../../robots.txt";
   146 			} else {
   147 				$robots_file = false;
   148 				$error = 1;
   149 			}
   150 			
   151 			if (!$error && filesize($robots_file) > 0) {
   152 				$f = fopen($robots_file, 'r');
   153 				$content = fread($f, filesize($robots_file));
   154 				$content = htmlspecialchars($content);
   155 			}
   156 
   157 			$error = 0;
   158 			if (file_exists("../.htaccess")) {
   159 				$htaccess_file = "../.htaccess";
   160 			} else if (file_exists("../../.htaccess")) {
   161 				$htaccess_file = "../../.htaccess";
   162 			} else {
   163 				$htaccess_file = false;
   164 				$error = 1;
   165 			}
   166 
   167 			if (!$error && filesize($htaccess_file) > 0) {
   168 				$f = fopen($htaccess_file, 'r');
   169 				$contentht = fread($f, filesize($htaccess_file));
   170 				$contentht = htmlspecialchars($contentht);
   171 			}
   172 			
   173 			?>
   174 			<div class="wrap">
   175 				<h2>Robots Meta Configuration</h2>
   176 				<form action="" method="post" id="robotsmeta-conf">
   177 					<span style="border: 0; float: right; margin-top: -35px;" class="submit"><input type="submit" name="submit" value="Save Settings" /></span>
   178 					<table class="form-table">
   179 						<?php if (function_exists('wp_nonce_field')) { wp_nonce_field('robots-meta-udpatesettings'); } ?>
   180 						<input type="hidden" value="<?php echo $options['version']; ?>" name="version"/>
   181 						<tr>
   182 							<th scope="row" valign="top">Plugin settings</th>
   183 							<td>
   184 								<input type="checkbox" id="disableexplanation" name="disableexplanation" <?php if ( $options['disableexplanation'] == true ) echo ' checked="checked" '; ?>/>
   185 								<label for="disableexplanation">Hide verbose explanations of settings</label><br/>
   186 							</td>
   187 						</tr>						
   188 						<tr valign="top">
   189 							<th scope="row" width="20%">RSS Feeds</th>
   190 							<td>
   191 								<input type="checkbox" id="commentfeeds" name="commentfeeds" <?php if ( $options['commentfeeds'] == true ) echo ' checked="checked" '; ?>/>
   192 								<label for="commentfeeds"><code>noindex</code> the comment RSS feeds</label><br/>
   193 								<?php if (!$options['disableexplanation']) { ?>
   194 								<p>
   195 									This will prevent the search engines from indexing your comment feeds.
   196 								</p>
   197 								<?php } ?>
   198 								<input type="checkbox" id="allfeeds" name="allfeeds" <?php if ( $options['allfeeds'] == true ) echo ' checked="checked" '; ?>/> 
   199 								<label for="allfeeds"><code>noindex</code> <strong>all</strong> RSS feeds</label><br/>
   200 								<?php if (!$options['disableexplanation']) { ?>
   201 								<p>
   202 									This will prevent the search engines from indexing <strong>all your</strong> feeds. Highly discouraged.
   203 								</p>
   204 								<?php } ?>
   205 							</td>
   206 						</tr>
   207 						<tr valign="top">
   208 							<th scope="row">Prevent indexing of</th>
   209 							<td>
   210 								<input type="checkbox" id="search" name="search" <?php if ( $options['search'] == true ) echo ' checked="checked" '; ?>/>
   211 								<label for="search">This site's search result pages</label><br/>
   212 								<?php if (!$options['disableexplanation']) { ?>
   213 								<p>
   214 									Prevents the search engines from indexing your search result pages, by a <code>noindex,follow</code> robots tag to them. The <code>follow</code> part means that search engine crawlers <em>will</em> spider the pages listed in the search results.
   215 								</p>
   216 								<?php } ?>								
   217 								<input type="checkbox" id="logininput" name="login" <?php if ( $options['login'] == true ) echo ' checked="checked" '; ?>/>
   218 								<label for="logininput">The login and register pages</label><br/>
   219 								<input type="checkbox" id="admin" name="admin" <?php if ( $options['admin'] == true ) echo ' checked="checked" '; ?>/>
   220 								<label for="admin">All admin pages</label><br/>
   221 								<?php if (!$options['disableexplanation']) { ?>
   222 								<p>
   223 									The above two options prevent the search engines from indexing your login, register and admin pages.
   224 								</p>
   225 								<?php } ?>
   226 								<input type="checkbox" id="pagedhome" name="pagedhome" <?php if ( $options['pagedhome'] == true ) echo ' checked="checked" '; ?>/>
   227 								<label for="pagedhome">Subpages of the homepage</label><br/>
   228 								<?php if (!$options['disableexplanation']) { ?>
   229 								<p>
   230 									Prevent the search engines from indexing your subpages, if you want them to only index your category and / or tag archives.
   231 								</p>
   232 								<?php } ?>
   233 								<input type="checkbox" id="noindexauthor" name="noindexauthor" <?php if ( $options['noindexauthor'] == true ) echo ' checked="checked" '; ?>/>
   234 								<label for="noindexauthor">Author archives</label><br/>								
   235 								<?php if (!$options['disableexplanation']) { ?>
   236 								<p>
   237 									By default, WordPress creates author archives for each user, usually available under <code>/author/username</code>. If you have sufficient other archives, or yours is a one person blog, there's no need and you can best disable them or prevent search engines from indexing them.
   238 								</p>
   239 								<?php } ?>
   240 								<input type="checkbox" id="noindexdate" name="noindexdate" <?php if ( $options['noindexdate'] == true ) echo ' checked="checked" '; ?>/>
   241 								<label for="noindexdate">Date-based archives</label><br/>
   242 								<?php if (!$options['disableexplanation']) { ?>
   243 								<p>
   244 									If you want to offer your users the option of crawling your site by date, but have ample other ways for the search engines to find the content on your site, I highly encourage you to prevent your date-based archives from being indexed.
   245 								</p>
   246 								<?php } ?>
   247 								<input type="checkbox" id="noindexcat" name="noindexcat" <?php if ( $options['noindexcat'] == true ) echo ' checked="checked" '; ?>/>
   248 								<label for="noindexcat">Category archives</label><br/>
   249 								<?php if (!$options['disableexplanation']) { ?>
   250 								<p>
   251 									If you're using tags as your only way of structure on your site, you would probably be better off when you prevent your categories from being indexed.
   252 								</p>
   253 								<?php } ?>
   254 								<input type="checkbox" id="noindextag" name="noindextag" <?php if ( $options['noindextag'] == true ) echo ' checked="checked" '; ?>/>
   255 								<label for="noindextag">Tag archives</label><br/>
   256 								<?php if (!$options['disableexplanation']) { ?>
   257 								<p>
   258 									Read the categories explanation above for categories and switch the words category and tag around ;)
   259 								</p>
   260 								<?php } ?>
   261 								<input type="checkbox" id="noarchive" name="noarchive" <?php if ( $options['noarchive'] == true ) echo ' checked="checked" '; ?>/>
   262 								<label for="noarchive">Add <code>noarchive</code> meta tag</label><br/>
   263 								<?php if (!$options['disableexplanation']) { ?>
   264 								<p>
   265 									Prevents archive.org and google to put copies of your pages into their archive/cache.to put copies of your pages into their archive/cache.
   266 								</p>
   267 								<?php } ?>
   268 							</td>
   269 						</tr>
   270 
   271 						<tr valign="top">
   272 							<th scope="row">DMOZ<br/> and Yahoo! Directory</th>
   273 							<td>
   274 								<input type="checkbox" id="noodp" name="noodp" <?php if ( $options['noodp'] == true ) echo ' checked="checked" '; ?>/>
   275 								<label for="noodp">Add <code>noodp</code> meta tag</label><br/>
   276 								<?php if (!$options['disableexplanation']) { ?>
   277 								<p>
   278 									Prevents all search engines from using the DMOZ description for this site in the search results.
   279 								</p>
   280 								<?php } ?>
   281 								<input type="checkbox" id="noydir" name="noydir" <?php if ( $options['noydir'] == true ) echo ' checked="checked" '; ?>/>
   282 								<label for="noydir">Add <code>noydir</code> meta robots tag</label><br/>
   283 								<?php if (!$options['disableexplanation']) { ?>
   284 								<p>
   285 									Prevents Yahoo! from using the Yahoo! directory description for this site in the search results.
   286 								</p>
   287 								<?php } ?>
   288 							</td>
   289 						</tr>
   290 						<tr>
   291 							<th scope="row" valign="top">Permalink settings</th>
   292 							<td>
   293 								<input type="checkbox" id="trailingslash" name="trailingslash" <?php if ( $options['trailingslash'] == true ) echo ' checked="checked" '; ?>/>
   294 								<label for="trailingslash">Enforce a trailing slash on all category and tag URL's</label><br/>
   295 								<?php if (!$options['disableexplanation']) { ?>
   296 								<p>
   297 									If you choose a permalink for your posts with <code>.html</code>, or anything else but a / on the end, this will force WordPress to add a trailing slash to non-post pages nonetheless.
   298 								</p>
   299 								<?php } ?>
   300 							</td>
   301 						</tr>
   302 						<tr>
   303 							<th scope="row" valign="top">Archive settings</th>
   304 							<td>
   305 								<input type="checkbox" id="disableauthor" name="disableauthor" <?php if ( $options['disableauthor'] == true ) echo ' checked="checked" '; ?>/>
   306 								<label for="disableauthor">Disable the author archives</label><br/>
   307 								<?php if (!$options['disableexplanation']) { ?>
   308 								<p>
   309 									If you're running a one author blog, the author archive will always look exactly the same as your homepage. And even though you may not link to it, others might, to do you harm. Disabling them here will make sure any link to those archives will be 301 redirected to the blog homepage.
   310 								</p>
   311 								<?php } ?>
   312 								<input type="checkbox" id="disabledate" name="disabledate" <?php if ( $options['disabledate'] == true ) echo ' checked="checked" '; ?>/>
   313 								<label for="disabledate">Disable the date-based archives</label><br/>
   314 								<?php if (!$options['disableexplanation']) { ?>
   315 								<p>
   316 									For the date based archives, the same applies: they probably look a lot like your homepage, and could thus be seen as duplicate content.
   317 								</p>
   318 								<?php } ?>
   319 								<input type="checkbox" id="redirectsearch" name="redirectsearch" <?php if ( $options['redirectsearch'] == true ) echo ' checked="checked" '; ?>/>
   320 								<label for="redirectsearch">Redirect search results pages when referrer is external</label><br/>
   321 								<?php if (!$options['disableexplanation']) { ?>
   322 								<p>
   323 									Redirect people coming to a search page on your site from elsewhere to your homepage, prevents people from linking to search results on your site.
   324 								</p>
   325 								<?php } ?>
   326 							</td>
   327 						</tr>
   328 						<tr>
   329 							<th scope="row" valign="top">Internal nofollow settings</th>
   330 							<td>
   331 								<input type="checkbox" id="nofollowcatpage" name="nofollowcatpage" <?php if ( $options['nofollowcatpage'] == true ) echo ' checked="checked" '; ?>/>
   332 								<label for="nofollowcatpage">Nofollow category listings on pages</label><br/>
   333 								<input type="checkbox" id="nofollowcatsingle" name="nofollowcatsingle" <?php if ( $options['nofollowcatsingle'] == true ) echo ' checked="checked" '; ?>/>
   334 								<label for="nofollowcatsingle">Nofollow category listings on single posts</label><br/>
   335 								<?php if (!$options['disableexplanation']) { ?>
   336 								<p>
   337 									If you're showing a category listing on all your single posts and pages, you're "leaking" quite a bit of PageRank towards these pages, whereas you probably want your single posts to rank. To prevent that from happening, check the two boxes above, and you will nofollow all the links to your categories from single posts and/or pages.
   338 								</p>
   339 								<?php } ?>
   340 								<input type="checkbox" id="nofollowindexlinks" name="nofollowindexlinks" <?php if ( $options['nofollowindexlinks'] == true ) echo ' checked="checked" '; ?>/>
   341 								<label for="nofollowindexlinks">Nofollow outbound links on the frontpage</label><br/>
   342 								<?php if (!$options['disableexplanation']) { ?>
   343 								<p>
   344 									If you want to keep the link-juice on your front page to yourself, enable this, and you will only pass link-juice from your post pages.
   345 								</p>
   346 								<?php } ?>
   347 								<input type="checkbox" id="nofollowtaglinks" name="nofollowtaglinks" <?php if ( $options['nofollowtaglinks'] == true ) echo ' checked="checked" '; ?>/>
   348 								<label for="nofollowtaglinks">Nofollow the links to your tag pages</label><br/>
   349 								<?php if (!$options['disableexplanation']) { ?>
   350 								<p>
   351 									If you've decided to keep your tag pages from being indexed, you might as well stop throwing link-juice at them on each post...
   352 								</p>
   353 								<?php } ?>
   354 								<input type="checkbox" id="nofollowmeta" name="nofollowmeta" <?php if ( $options['nofollowmeta'] == true ) echo ' checked="checked" '; ?>/>
   355 								<label for="nofollowmeta">Nofollow login and registration links</label><br/>
   356 								<?php if (!$options['disableexplanation']) { ?>
   357 								<p>
   358 									This might have happened to you: logging in to your admin panel to notice that is has become PR6... Nofollow those admin and login links, there's no use flowing PageRank to those pages!
   359 								</p>
   360 								<?php } ?>
   361 								<input type="checkbox" id="nofollowcommentlinks" name="nofollowcommentlinks" <?php if ( $options['nofollowcommentlinks'] == true ) echo ' checked="checked" '; ?>/>
   362 								<label for="nofollowcommentlinks">Nofollow comments links</label><br/>
   363 								<?php if (!$options['disableexplanation']) { ?>
   364 								<p>
   365 									Simple way to decrease the number of links on your pages: nofollow all the links pointing to comment sections.
   366 								</p>
   367 								<?php } ?>
   368 								<input type="checkbox" id="replacemetawidget" name="replacemetawidget" <?php if ( $options['replacemetawidget'] == true ) echo ' checked="checked" '; ?>/>
   369 								<label for="replacemetawidget">Replace the Meta Widget with a nofollowed one</label><br/>
   370 								<?php if (!$options['disableexplanation']) { ?>
   371 								<p>
   372 									By default the Meta widget links to your RSS feeds and to WordPress.org with a follow link, this will replace that widget by a custom one in which all these links are nofollowed.
   373 								</p>
   374 								<?php } ?>
   375 							</td>
   376 						</tr>
   377 						<tr>
   378 							<th scope="row" valign="top">Webmaster Tools</th>
   379 							<td colspan="2">
   380 								<label for="googleverify">Verify meta value for Google Webmaster Tools:</label><br/>
   381 								<input size="50" type="text" id="googleverify" name="googleverify" <?php echo 'value="'.$options['googleverify'].'" '; ?>/><br/>
   382 								<label for="yahooverify">Verify meta value for Yahoo! Site Explorer:</label><br/>
   383 								<input size="50" type="text" id="yahooverify" name="yahooverify" <?php echo 'value="'.$options['yahooverify'].'" '; ?>/><br/>
   384 								<label for="msverify">Verify meta value for Microsoft Webmaster Portal:</label><br/>
   385 								<input size="50" type="text" id="msverify" name="msverify" <?php echo 'value="'.$options['msverify'].'" '; ?>/>
   386 							</td>
   387 						</tr>
   388 					</table>
   389 					<br/>
   390 					<span class="submit" style="border: 0;"><input type="submit" name="submit" value="Save Settings" /></span>
   391 				</form>
   392 				<br/><br/>
   393 <?php if ($robots_file != false) { ?>
   394 				<h2>Robots.txt</h2>
   395 				<form action="" method="post" id="robotstxt">
   396 					<?php wp_nonce_field('robots-meta-udpaterobotstxt'); ?>
   397 					<?php
   398 						if (!is_writeable($robots_file)) {
   399 							echo "<p><em>If your robots.txt were writable, you could edit it from here.</em></p>";
   400 							$disabled = 'disabled="disabled"';
   401 						} else {
   402 							echo "<p>Edit the content of your robots.txt:</p>";
   403 							$disabled = "";
   404 							?>
   405 							<textarea cols="60" <?php echo $disabled; ?> rows="15" name="robotsnew"><?php echo $content ?></textarea><br/>
   406 							<br/>
   407 							<span class="submit" style="border: 0;"><input type="submit" name="submitrobots" value="Save changes to Robots.txt" /></span>
   408 					<?php } ?>
   409 				</form>
   410 				<br/><br/>
   411 <?php
   412 }
   413 if ($htaccess_file != false) {
   414 ?>
   415 				<h2>.htaccess</h2>
   416 				<form action="" method="post" id="htaccess">
   417 					<?php wp_nonce_field('robots-meta-udpatehtaccesstxt'); ?>
   418 					<?php
   419 						if (! is_writeable($htaccess_file)) {
   420 							echo "<p><em>If your .htaccess were writable, you could edit it from here.</em></p>";
   421 							$disabled = 'disabled="disabled"';
   422 						} else {
   423 							echo "<p>Edit the content of your .htaccess:</p>";
   424 							$disabled = "";
   425 							?>
   426 							<textarea cols="60" <?php echo $disabled; ?> rows="15" name="htaccessnew"><?php echo $contentht ?></textarea><br/>
   427 							<br/>
   428 							<span class="submit" style="border:0;"><input type="submit" name="submithtaccess" value="Save changes to .htaccess" /></span>
   429 					<?php } ?>
   430 				</form>
   431 <?php } ?>
   432 			</div>
   433 			<?php
   434 	}
   435 	} // end class RobotsMeta
   436 }
   437 
   438 function noindex_feed() {
   439 	echo '<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />'."\n";
   440 }
   441 
   442 function noindex_page() {
   443 	echo '<meta name="robots" content="noindex" />'."\n";
   444 }
   445 
   446 function meta_robots() {
   447 	$opt  = get_option('RobotsMeta');
   448 	$options = unserialize($opt);
   449 	
   450 	$meta = "";
   451 	if (is_single() || is_page()) {
   452 		global $post;
   453 		if ($post->robotsmeta != "index,follow") {
   454 			$meta = $post->robotsmeta;	
   455 		}
   456 	} else if ( (is_author() && $options['noindexauthor']) || (is_category() && $options['noindexcat']) || (is_date() && $options['noindexdate']) || (function_exists(is_tag) && is_tag() && $options['noindextag']) || (is_search() && $options['search']) ) {
   457 		$meta .= "noindex,follow";
   458 	} else if (is_home()) {
   459 		if ($options['pagedhome'] && get_query_var('paged') > 1) {
   460 			$meta .= "noindex,follow";
   461 		}
   462 	}
   463 	if ($options['noodp']) {
   464 		if ($meta != "") {
   465 			$meta .= ",";
   466 		}
   467 		$meta .= "noodp";
   468 	} 
   469 	if ($options['noydir']) {
   470 		if ($meta != "") {
   471 			$meta .= ",";
   472 		}
   473 		$meta .= "noydir";
   474 	}
   475 	if ($options['noarchive']) {
   476 		if ($meta != "") {
   477 			$meta .= ",";
   478 		}
   479 		$meta .= "noarchive";
   480 	}
   481 	if ($meta != "" && $meta != "index,follow") {
   482 		echo '<!--Meta tags added by Robots Meta: http://www.joostdevalk.nl/wordpress/meta-robots-wordpress-plugin/ -->'."\n";
   483 		echo '<meta name="robots" content="'.$meta.'" />'."\n";
   484 	}
   485 } 
   486 
   487 function add_trailingslash($url, $type) {
   488 	// trailing slashes for everything except is_single()
   489 	// Thanks to Mark Jaquith for this
   490 	if ( 'single' === $type ) {
   491 		return $url;
   492 	} else {
   493 		return trailingslashit($url);
   494 	}
   495 }
   496 
   497 function search_redirect() {
   498 	if ($_GET['s'] &&  strpos($_SERVER['HTTP_REFERER'], get_bloginfo('url')) === false) {
   499 		wp_redirect(get_bloginfo('url'),301);
   500 		exit;
   501 	}
   502 }
   503 
   504 function archive_redirect() {
   505 	global $wp_query;
   506 	
   507 	$opt  = get_option('RobotsMeta');
   508 	$options = unserialize($opt);
   509 	
   510 	if ($options['disabledate'] && $wp_query->is_date) {
   511 		wp_redirect(get_bloginfo('url'),301);
   512 		exit;
   513 	}
   514 	if ($options['disableauthor'] && $wp_query->is_author) {
   515 		wp_redirect(get_bloginfo('url'),301);
   516 		exit;
   517 	}
   518 }
   519 
   520 function nofollow_link($output) {
   521 	return str_replace('<a ','<a rel="nofollow" ',$output);
   522 }
   523 
   524 function nofollow_category_listing($output) {
   525 	$opt  = get_option('RobotsMeta');
   526 	$options = unserialize($opt);
   527 	
   528 	if ( ($options['nofollowcatsingle'] && (is_single() || is_search()) ) || ($options['nofollowcatpage'] && is_page() || is_category() || is_tag() ) ) {
   529 		$output = nofollow_link($output);
   530 		return $output;
   531 	} else {
   532 		return $output;
   533 	}
   534 }
   535 
   536 function google_verify() {
   537 	if (is_home() || (function_exists('is_frontpage') && is_frontpage()) ) {
   538 		$opt  = get_option('RobotsMeta');
   539 		$options = unserialize($opt);
   540 		echo '<meta name="verify-v1" content="'.$options['googleverify'].'" />'."\n";
   541 	}
   542 }
   543 
   544 function yahoo_verify() {
   545 	if (is_home() || (function_exists('is_frontpage') && is_frontpage()) ) {
   546 		$opt  = get_option('RobotsMeta');
   547 		$options = unserialize($opt);
   548 		echo '<meta name="y_key" content="'.$options['yahooverify'].'" />'."\n";
   549 	}
   550 }
   551 
   552 function ms_verify() {
   553 	if (is_home() || (function_exists('is_frontpage') && is_frontpage()) ) {
   554 		$opt  = get_option('RobotsMeta');
   555 		$options = unserialize($opt);
   556 		echo '<meta name="msvalidate.01" content="'.$options['msverify'].'" />'."\n";
   557 	}
   558 }
   559 
   560 function add_nofollow($matches) {
   561 	$origin = get_bloginfo('wpurl');
   562 	if ((strpos($matches[2],$origin)) === false && ( strpos($matches[1],'rel="nofollow"') === false ) && ( strpos($matches[3],'rel="nofollow"') === false ) ) {
   563 		$nofollow = ' rel="nofollow" ';
   564 	} else {
   565 		$nofollow = '';
   566 	}
   567 	return '<a href="' . $matches[2] . '"' . $nofollow . $matches[1] . $matches[3] . '>' . $matches[4] . '</a>';
   568 }
   569 
   570 function nofollow_index($output) {
   571 	// Loop through the content of each post and add a nofollow when it's on the main page or a category page.
   572 	if (is_home() || is_category()) {
   573 		$anchorPattern = '/<a (.*?)href="(.*?)"(.*?)>(.*?)<\/a>/i';
   574 		$output = preg_replace_callback($anchorPattern,'add_nofollow',$output);
   575 	}
   576 	return $output;
   577 }
   578 
   579 function nofollow_taglinks($output) {
   580 	$output = str_replace('rel="tag"','rel="nofollow tag"',$output);
   581 	return $output;
   582 }
   583 
   584 function widget_jdvmeta_init() {
   585 	if (!function_exists('register_sidebar_widget'))
   586 		return;
   587 
   588 	function wp_jdvwidget_meta($args) {
   589 		extract($args);
   590 		$options = get_option('widget_meta');
   591 		$title = empty($options['title']) ? __('Meta') : $options['title'];
   592 	?>
   593 			<?php echo $before_widget; ?>
   594 				<?php echo $before_title . $title . $after_title; ?>
   595 				<ul>
   596 				<?php wp_register(); ?>
   597 				<li><?php wp_loginout(); ?></li>
   598 				<li><a rel="nofollow" href="<?php bloginfo('rss2_url'); ?>" title="<?php echo attribute_escape(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
   599 				<li><a rel="nofollow"href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo attribute_escape(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
   600 				<li><a rel="nofollow" href="http://wordpress.org/" title="<?php echo attribute_escape(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
   601 				<?php wp_meta(); ?>
   602 				</ul>
   603 			<?php echo $after_widget; ?>
   604 	<?php
   605 	}
   606 
   607 	register_sidebar_widget('meta','wp_jdvwidget_meta');
   608 }
   609 
   610 function robotsmeta_update() {
   611 	global $wpdb;
   612 	$opt  = get_option('RobotsMeta');
   613 	$options = unserialize($opt);
   614 	if ($options['version'] < "2.3") {
   615 		echo $wpdb->get_col_info('robotsmeta');
   616 		$wpdb->query("ALTER TABLE $wpdb->posts ADD COLUMN robotsmeta varchar(64)");
   617 		$options['version'] = "2.3";
   618 	}
   619 	if ($options['version'] < "25") {
   620 		$options['version'] = "25";
   621 	}
   622 	$opt = serialize($options);
   623 	update_option('RobotsMeta', $opt);
   624 }
   625 function echo_nofollow() {
   626 	return ' rel="nofollow"';
   627 }
   628 
   629 $opt  = get_option('RobotsMeta');
   630 $options = unserialize($opt);
   631 
   632 global $wp_version;
   633 if ($wp_version >= "2.3") {
   634 	if ($options['allfeeds'] || $options['commentfeeds']) {
   635 		add_action('commentsrss2_head', 'noindex_feed');
   636 	}
   637 	if ($options['trailingslash']) {
   638 		add_filter('user_trailingslashit', 'add_trailingslash', 10, 2);
   639 	}
   640 }
   641 if ($options['allfeeds']) {
   642 	add_action('rss_head', 'noindex_feed');
   643 	add_action('rss2_head', 'noindex_feed');
   644 }
   645 
   646 add_action('wp_head', 'meta_robots');
   647 
   648 if ($options['login']) {
   649 	add_action('login_head', 'noindex_page');
   650 }
   651 if ($options['admin']) {
   652 	add_action('admin_head', 'noindex_page');
   653 }
   654 if ($options['disabledate'] || $options['disableauthor']) {
   655 	add_action('wp', 'archive_redirect');
   656 }
   657 if ($options['redirectsearch']) {
   658 	add_action('init', 'search_redirect');
   659 }
   660 if ($options['nofollowcatsingle'] || $options['nofollowcatpage']) {
   661 	add_filter('wp_list_categories','nofollow_category_listing');
   662 }
   663 if ($options['nofollowmeta']) {
   664 	add_filter('loginout','nofollow_link');
   665 	add_filter('register','nofollow_link');
   666 }
   667 if ($options['nofollowcommentlinks']) {
   668 	add_filter('comments_popup_link_attributes','echo_nofollow');
   669 }
   670 if ($options['nofollowtaglinks']) {
   671 	add_filter('the_tags','nofollow_taglinks');
   672 }
   673 if ($options['googleverify']) {
   674 	add_action('wp_head', 'google_verify');
   675 }
   676 if ($options['yahooverify']) {
   677 	add_action('wp_head', 'yahoo_verify');
   678 }
   679 if ($options['msverify']) {
   680 	add_action('wp_head', 'ms_verify');
   681 }
   682 if ($options['nofollowindexlinks']) {
   683 	add_filter('the_content','nofollow_index');
   684 }
   685 if ($options['replacemetawidget']) {
   686 	add_action('plugins_loaded', 'widget_jdvmeta_init');
   687 }
   688 
   689 add_action('admin_menu', array('RobotsMeta_Admin','add_config_page'));
   690 add_action('admin_menu', array('RobotsMeta_Admin','meta_box'));
   691 
   692 add_action('wp_insert_post', array('RobotsMeta_Admin','robotsmeta_insert_post'));
   693 if ($options['version'] < '25') {
   694 	robotsmeta_update();
   695 }
   696 ?>