createBlogOption('CounterValue', 'Value of your counter', 'text', '0'); $this->createOption('FeedCounterValue', 'Value of you feedcounter', 'text', '0'); } // --------- do...-Functions ------------------------------ function doSkinVar($skinType, $counterType = 'visits', $counterMode = 'textual', $counterUpdate = 'count') { global $blog; $currentBlog = $blog->blogid; //countertype must be 'visits' or 'feeds' //but may be 'visits', 'feeds', 'textual', 'graphical' for compatibility //and to provide a shorter way to put the counter in the skin if (($counterType == 'textual')||($counterType == 'graphical')) { $counterMode = $counterType; $counterType = 'visits'; } if ($counterType == '') { $counterType = 'visits'; } //now we are sure that countertype is visits of feeds //and countermode is textual or graphics or nodisplay switch ($counterType) { // visitcounter case 'visits': // first check if there is a session (there is if the session variable // has a value) if (!$_SESSION['CounterValue']) { //There is no session $counterValue = $this->getBlogOption($currentBlog, 'CounterValue'); if ($counterUpdate != 'nocount') { //if the UA is not a bot and we may count, update the counter by one $ua = $_SERVER['HTTP_USER_AGENT']; if (!$this->_isBot($ua)) { $counterValue++; $this->setBlogOption($currentBlog, 'CounterValue', $counterValue); } } $_SESSION['CounterValue'] = $counterValue; } else { //we have a session, retreive the counter value $counterValue = $_SESSION['CounterValue']; } break; // feedcounter case 'feeds': //Feeds don't work with sessions (as far as I know) //so we don't have to use session stuff $counterValue = $this->getOption('FeedCounterValue'); if ($counterUpdate != 'nocount') { //if the UA is not a bot and we may count, update the counter by one $ua = $_SERVER['HTTP_USER_AGENT']; if (!$this->_isBot($ua)) { $counterValue++; $this->setOption('FeedCounterValue', $counterValue); } } break; //something's wrong default: $counterValue = 'Invalid countervalue'; break; } //now we can display the counter; switch ($counterMode) { //user wants a graphical counter case 'graphical': //display the graphical counter for ($i = 0; $i < strlen($counterValue); $i++) { $counterDigit = substr($counterValue, $i, 1); echo 'HitCounter: '.$counterDigit.''; } break; //user wants a graphical counter case 'textual': //display the textual counter echo $counterValue; break; } } // --------- Various Functions ---------------------------- function _isBot($ua) { $list[0] = 'googlebot'; $list[1] = 'altavista'; $list[2] = 'infoseek'; $list[3] = 'lycos'; $list[4] = 'muscatferret'; $list[5] = 'hotbot'; $list[6] = 'ultraseek'; $list[7] = 'webcrawler'; $list[8] = 'yahoo'; $list[9] = 'msnbot'; $list[10] = 'scooter'; $list[11] = 'technoratibot'; $list[12] = 'blogsharesbot'; $list[13] = 'ia_archiver'; $list[14] = 'qweerybot'; $list[15] = 'nitleblogspider'; $list[16] = 'gigabot'; $list[17] = 'mozdex'; for ($i=0;$i