Results 1 to 10 of 10

Thread: Catching spiders

  1. #1
    Join Date
    Sep 2005
    Location
    Poland - Warsaw
    Posts
    342

    Default Catching spiders

    I have used scipts from one of polish forum to write that block - I am not good porgrammer so forgive my mistakes:

    1.

    create empty file named: robot.db and make it writeable (chmod 666 robot.db). That file must be in your root directory (where index.php exists).

    2.

    File in blocks/ directory called blocks.spiders.php

    Code:
    <?php
    
    /**
     *
     * INDEXU
     * Copyright(C), Nicecoder, 2000-2006, All Rights Reserved.
     *
     * INDEXU(tm) is protected by Indonesia and International copyright laws.
     * Unauthorized use or distribution of INDEXU(tm) is strictly prohibited,
     * violators will be prosecuted. To obtain a license for using INDEXU(tm),
     * please register at Nicecoder home page at http://www.nicecoder.com
     *
     * Author:
     *    Dody Rachmat Wicaksono (dody@nicecoder.com)
     *    M. Zuber (zubby@nicecoder.com)
     *
     */
    
    //	robot script - Copyright (C) 2006 Yuriy Hatala (yuriy@myth.org.ua)
    
    
      function block_spiders($params) {
        global $theme_path, $active_theme;
    		
    		  if (!$params['template']) {
        $params['template'] = 'block.spiders.html';
      }
    		
    		 $flExists = FALSE;
     
     $RobotDB = "robot.db";
     $RobotArray = array("googlebot", "msnbot", "yahoo");
     
     $CurrentPage = md5($_SERVER['REQUEST_URI']);
     $CurrentBot  = strtolower($_SERVER['HTTP_USER_AGENT']);
     
     if (preg_match(sprintf("/%s/", join("|", $RobotArray)), $CurrentBot))
     {
     	foreach ($RobotArray as $key => $value)
     	{ if (preg_match(sprintf("/%s/", $value), $CurrentBot)) { break; } }
     	
     	if (file_exists($RobotDB) && (is_readable($RobotDB) && is_writable($RobotDB)))
     	{
     		$DBHandle = fopen($RobotDB, "r+");
     		if (is_resource($DBHandle) && flock($DBHandle, LOCK_EX))
     		{
     			$Line = fgets($DBHandle, 61);
     			while (!feof($DBHandle))
     			{
     				$PageInfo = unpack("A32Page/Vgooglebot/Vmsnbot/Vyahoo", base64_decode($Line));
     				if (preg_match(sprintf("/%s/", $CurrentPage), $PageInfo['Page']))
     				{
     					$flExists = TRUE;
     					$CurrentPos = ftell($DBHandle);
     					fseek($DBHandle, 0, SEEK_END);
     				}
     				$Line = fgets($DBHandle, 61);
     			}
     		 			
     			if (!$flExists)
     			{
     				fseek($DBHandle, 0, SEEK_END);
     				$PageInfo = array_merge($CurrentPage, array('googlebot' => 0, 'msnbot' => 0, 'yahoo' => 0));
     			}
     			else { fseek($DBHandle, ($CurrentPos - 60), SEEK_SET); }
     			
     			$PageInfo[ $RobotArray[$key] ] = $PageInfo[ $RobotArray[$key] ] + 1;
     			// print_r($PageInfo);
     			
    			fwrite($DBHandle, base64_encode(pack("A*VVV", $CurrentPage, $PageInfo['googlebot'], $PageInfo['msnbot'], $PageInfo['yahoo'])));
     			flock($DBHandle, LOCK_UN);
     		}
     		fclose($DBHandle);
     	}
     }
     else
     {
         if (file_exists($RobotDB) && is_readable($RobotDB))
         {
             $DBHandle = fopen($RobotDB, "r");
             if (is_resource($DBHandle))
             {
                 $Line = fgets($DBHandle, 61);
                 while (!feof($DBHandle))
                 {
                     $PageInfo = unpack("A32Page/Vgooglebot/Vmsnbot/Vyahoo", base64_decode($Line));
                     if (preg_match(sprintf("/%s/", $CurrentPage), $PageInfo['Page']))
                     {
                         $flExists = TRUE;
                         $CurrentPos = ftell($DBHandle);
                         fseek($DBHandle, 0, SEEK_END);
                     }
                     $Line = fgets($DBHandle, 61);
                 }
             }
             fclose($DBHandle);
             if (!$flExists) { $PageInfo = array('googlebot' => 0, 'msnbot' => 0, 'yahoo' => 0); }
         }
     }
    
    
        $tpl = new Template;
    
        $google_spider = $PageInfo['googlebot'];
        $yahoo_spider = $PageInfo['yahoo'];
    		$msn_spider = $PageInfo['msnbot'];
    
        $tpl->assign("Gspider", $google_spider);
        $tpl->assign("Yspider", $yahoo_spider);
        $tpl->assign("Mspider", $msn_spider);
        $tpl->display("blocks/" . $params['template']);
     
      }
    
    ?>
    3.

    File theme/your-skin/blocks/ called blocks.spiders.html

    Code:
        <div class="header"><div>Spiders</div></div>
        <div class="box">
         Google: <%$Gspider%><br />
         Yahoo: <%$Yspider%><br />
         MSN: <%$Mspider%><br />
        </div>
    and put the <%block_spiders%> anywhere you want in your index.html file

    Darmowy Katalog Stron :: Linksor.com - there is a demo here - look at PAJAKI (polish word) 3rd menu on the left.

  2. #2
    Join Date
    May 2002
    Posts
    91

    Default

    Well forgive me linksor.com, but it doesnt work for me on 5.3.0

    I am little confused about the blocks and / or block naming of your files.

    All I got was a smarty error

    Could you please take a look about your post above and check it for errors? Would be nice to have that function on my site, too.

    Thanks in advance

  3. #3
    Join Date
    Aug 2001
    Location
    Indonesia
    Posts
    3,732

    Default

    You may misplaced the files, please check again.

    The php file should be in
    /blocks/blocks.spiders.php

    The template file should be in
    /theme/kosmos/blocks/blocks.spiders.html

    You may need to change 'kosmos' to your template folder/name

  4. #4
    Join Date
    May 2002
    Posts
    91

    Default

    hmmmmm...... well then....

    PHP Code:
    [B]Fatal error[/B]: Smarty error: [in /mypath/themes/kosmos/index.html line 67]: syntax errorunrecognized tag 'blocks_spiders' (Smarty_Compiler.class.phpline 580in /mypath/lib/smarty/Smarty.class.php on line 1088 
    Any Idea?

    Thanks Dody for your help

  5. #5
    Join Date
    Sep 2005
    Location
    Poland - Warsaw
    Posts
    342

    Default

    May be this is the problem:

    Code:
    $params['template'] = 'block.spiders.html';
    change to (added s letter)

    Code:
    $params['template'] = 'blocks.spiders.html';

  6. #6
    Join Date
    May 2002
    Posts
    91

    Default

    No luck

    Here is what I did:

    1. Created a file called robot.db in root, changemod to 666 (and tried 777, too)

    2. Created the blocks.spiders.php in my blocks/ directory and did change what linksor adviced, renamed the in line 26
    $params['template'] = 'block.spiders.html';
    from block.spiders.html to blocks.spiders.html

    3. Created a new File in my themes directory /blocks/blocks.spiders.html with the given Code by linksor. And yes Dody, I am using the standard kosmos Theme. Do I have to put that theme name anywhere in the PHP - File?

    4. Under the Who is online Block I did put this line:
    <%block_spiders%>

    First I got a smarty error again, but after reloading, no error anymore, but at the place where I did put the <%block_spiders%> is simply nothing to see, just white space

    Any ideas? Any help is appreciated.
    Thanks in advance

  7. #7
    Join Date
    Aug 2001
    Location
    Indonesia
    Posts
    3,732

    Default

    Lets wait until linksor release in a zip file

  8. #8
    Join Date
    May 2002
    Posts
    91

    Default

    Good Idea Would be great!

  9. #9
    Join Date
    Sep 2005
    Location
    Poland - Warsaw
    Posts
    342

    Default

    Here's my ZIP file

    PHP should be in blocks/ directory
    HTML should be in theme/blocks/ directory

    what I have in index.html file is:

    Code:
    <%block_pagerank_stat minimum_pr="1"%>
    <%block_spiders%>
    <%block_whos_online%>
    it is working on my zgred.pl and linksor.com dir's.

    edited: probably you must change template to KOSMO theme - I have used here a lot of DIV's - remove DIV's - may be that will help !
    Attached Files Attached Files

  10. #10
    Join Date
    Jul 2006
    Posts
    62

    Default

    Hi

    Just added the <%block_spiders%> to index page but getting this error below,

    Warning: Smarty error: unable to read resource: "blocks/block.spiders.html" in /home/ukcarper/public_html/lib/smarty/Smarty.class.php on line 1088

    Any ideas.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •