<?php /* This code is free software. Its licence is the GNU GPL (available here: http://www.gnu.org/licenses/gpl.txt). */ class NP_MetaDescription extends NucleusPlugin { function getName() { return 'Meta Description'; } function getAuthor() { return 'Jef Pober'; } function getURL() { return 'http://fuckhedz.com'; } function getVersion() { return '1.0'; } function getDescription() { return 'Provides an easy way to add a meta description tag'; } function supportsFeature($feature) { switch($feature) { case 'SqlTablePrefix': return 1; default: return 0; } } function install() { $this->createOption('indexDescription','Description for the index page','text'); $this->createOption('archivelistDescription','Description for the archive list','text'); $this->createOption('archiveDescription','Description for archive pages','text'); $this->createOption('memberDescription','Description for member detail pages (%M gets replaced by the member name)','text'); $this->createOption('searchDescription','Description for search pages (%S gets replaced by the search term)','text'); $this->createOption('itemDescription','Description for item pages (%E gets replaced by an excerpt)','text'); $this->createOption('imagepopupDescription','Description for image popups','text'); $this->createOption('otherDescription','Description for other pages (for example custom pages', 'text'); $this->createOption('excerptLenght','The maximum amount of characters for an excerpt','text','50'); $this->createOption('xhtmlOutput','Output XHML?','yesno','yes'); $this->createOption('tabAmount','Amount of tabs to go before meta tag','text','1'); } function doSkinVar($skinType) { global $memberid, $itemid; switch($skinType) { case 'index': $description = $this->getOption('indexDescription'); break; case 'archivelist': $description = $this->getOption('archivelistDescription'); break; case 'archive': $description = $this->getOption('archiveDescription'); break; case 'member': $description = str_replace('%M',$this->getMemberNameById($memberid),$this->getOption('memberDescription')); break; case 'search': $description = str_replace('%S',requestVar('query'),$this->getOption('searchDescription')); break; case 'item': $body = strip_tags($this->getItemBodyById($itemid)); $body = str_replace("\n","",$body); $body = str_replace("\r","",$body); $maxlen = $this->getOption('excerptLenght'); if (strlen($body) > $maxlen) { $body = substr($body,0,$maxlen-3) . '...'; } $description = str_replace('%E',$body,$this->getOption('itemDescription')); break; case 'imagepopup': $description = $this->getOption('imagepopupDescription'); break; case 'other': $description = $this->getOption('otherDescription'); break; } $this->makeMetaTag('description',$description); } function makeMetaTag($name,$value) { for ($i=0;$i<$this->getOption('tabAmount');$i++) { echo "\t"; } echo "<meta name=\"$name\" content=\"$value\""; if ($this->getOption('xhtmlOutput') == 'yes') { echo " />"; } else { echo ">"; } echo "\n"; } function getMemberNameById($id) { $result = sql_query('SELECT mname FROM ' . sql_table('member') . " WHERE mnumber=$id"); if ($result) { return mysql_result($result,0); } else { return false; } } function getItemBodyById($id) { $result = sql_query('SELECT ibody FROM ' . sql_table('item') . " WHERE inumber=$id"); if ($result) { return mysql_result($result,0); } else { return false; } } } ?>