From: Ken N. <ke...@co...> - 2005-05-16 19:13:12
|
Over the past couple of months, I have noticed search engines crawling the site and concentrating on the calendar. Each search engine crawls each calendar entry (year / month /day) regardless of whether or not there is content. This uses up a considerable amount of bandwidth which I would like to conserve. Currently, I have two solutions available... To disallow search engine bots access to the calendar via the robots.txt file, or to set the robot meta tag to either "noindex, nofollow" or "index, nofollow." I want calendar events crawled, but I want them restricted so disallowing via robots.txt or the robot meta tag of "noindex, nofollow" are not viable solutions. The problem with "index, nofollow" is that search engines will not crawl other appropriate pages from links on a page the search engine robot does crawl. The solution I believe is appropriate is to have the meta tag variables global which can be set by the module (as needed / desired). This can be accomplished ala the addPageTitle function in Layout.php. Following is a patch of Layout.php (for phpWebsite v0.10.1) which will enable modules to set meta tags (with the exception of generator and content-type). The added functions are: setKeywordsTag setDescriptionTag setRobotTag setAuthorTag setOwnerTag Of course, to implement the changes in a module, a field (column) would have to be created in the mod's db for each metatag which would be changed in the module or hard-coded in. I will work on a calendar-specific hack over the next few days. One of the reasons I worked on this was to 1) see how easy / difficult it would be to implement in the current version of phpWebsite and 2) to bring attention to the issue before the release of phpWebsite v1.0. As always, any and all comments are welcomed. I am not the world's most proficient coder, so if anyone sees an easier solution, please let me know. Ken Nordquist ***** start patch ***** --- Layout.php.old 2005-05-15 20:43:09.000000000 -0400 +++ Layout.php 2005-05-16 07:36:19.000000000 -0400 @@ -10,6 +10,7 @@ * Controls the layout and themes * * @version $Id: Layout.php,v 1.72 2005/03/07 14:05:42 steven Exp $ + * changed to allow meta tag(s) to be changed per module (172-2 patch) * @author Matthew McNaney <ma...@NO...> * @package phpWebSite */ @@ -498,17 +499,56 @@ } } + function setKeywordsTag($keywords_tag) { + $title = strip_tags($keywords_tag); + $GLOBALS['keywords_tag'] = $keywords_tag; + } + + function setDescriptionTag($description_tag) { + $title = strip_tags($description_tag); + $GLOBALS['description_tag'] = $description_tag; + } + + function setRobotTag($robot_tag) { + $title = strip_tags($robot_tag); + $GLOBALS['robot_tag'] = $robot_tag; + } + + function setAuthorTag($author_tag) { + $title = strip_tags($author_tag); + $GLOBALS['author_tag'] = $author_tag; + } + + function setOwnerTag($owner_tag) { + $title = strip_tags($owner_tag); + $GLOBALS['owner_tag'] = $owner_tag; + } + + function getMetaTags(){ $metatags = '<meta name="generator" content="phpWebSite" /> '; + if (isset($GLOBALS['keywords_tag'])) { + $metatags .= '<meta name="keywords" content="'.$GLOBALS["keywords_tag"].'" /> +'; + } else { + if ($this->meta_keywords) $metatags .= '<meta name="keywords" content="'.$this->meta_keywords.'" /> '; +} + + + if (isset($GLOBALS['description_tag'])) { + $metatags .= '<meta name="description" content="'.$GLOBALS["description_tag"].'" /> +'; + } else { if ($this->meta_description) $metatags .= '<meta name="description" content="'.$this->meta_description.'" /> '; +} if (isset($GLOBALS['block_robot'])) { $robot = '00'; @@ -516,6 +556,29 @@ $robot = &$this->meta_robots; } + if (isset($GLOBALS['robot_tag'])) { + switch ($GLOBALS['robot_tag']){ + case '00': + $metatags .= '<meta name="robots" content="noindex, nofollow" /> +'; + break; + + case '01': + $metatags .= '<meta name="robots" content="noindex, follow" /> +'; + break; + + case '10': + $metatags .= '<meta name="robots" content="index, nofollow" /> +'; + break; + + case '11': + $metatags .= '<meta name="robots" content="index, follow" /> +'; + break; + } + } else { if ($this->meta_robots){ switch ($robot){ @@ -540,19 +603,38 @@ break; } } + } + + if (isset($GLOBALS['author_tag'])) { + $metatags .= '<meta name="author" content="'.$GLOBALS["author_tag"].'" /> +'; + } else { if ($this->meta_author) $metatags .= '<meta name="author" content="'.$this->meta_author.'" /> '; +} - if ($this->meta_owner) - $metatags .= '<meta name="owner" content="'.$this->meta_owner.'" /> + if (isset($GLOBALS['owner_tag'])) { + $metatags .= '<meta name="owner" content="'.$GLOBALS["owner_tag"].'" /> +'; + } else { + if ($this->meta_owner) + $metatags .= '<meta name="owner" content="'.$this->meta_owner.'" /> '; + } if ($this->meta_content) $metatags .= '<meta http-equiv="content-type" content="text/html; charset=' . $this->meta_content.'" /> '; + // set meta tag globals to "null" so they do not affect other pages + $GLOBALS["keywords_tag"] = ''; + $GLOBALS['description_tag'] = ''; + $GLOBALS['robot_tag'] = ''; + $GLOBALS['author_tag'] = ''; + $GLOBALS['owner_tag'] = ''; + return $metatags; } ***** end patch ***** |
From: Greg M. <drk...@co...> - 2005-05-17 03:58:03
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ken Nordquist wrote: > As always, any and all comments are welcomed. I am not the world's most > proficient coder, so if anyone sees an easier solution, please let me > know. > > Ken Nordquist > > ***** start patch ***** LOL...isn't this the point we all say, "We love you man!" Come over here so we can all give you a big old smooch. >:-> Most evil grin. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFCiWu8xyxe5L6mr7IRAl+DAJkBR8QcquMUSId/5Iz4iHjOsqgOCACgjdrL wA+eOHJc0yjp3ME5T3c7g2s= =eNLt -----END PGP SIGNATURE----- |
From: Eloi G. <el...@re...> - 2005-05-17 17:35:18
|
Ken Nordquist wrote: >The solution I believe is appropriate is to have the meta tag variables >global which can be set by the module (as needed / desired). This can >be accomplished ala the addPageTitle function in Layout.php. Following >is a patch of Layout.php (for phpWebsite v0.10.1) which will enable >modules to set meta tags (with the exception of generator and >content-type). The added functions are: > setKeywordsTag > setDescriptionTag > setRobotTag > setAuthorTag > setOwnerTag > > Why don't you just set the $_SESSION['OBJ_layout']->meta_vars array elements? -Eloi- |