"Fossies" - the Fresh Open Source Software Archive

Member "example/example.php" (20 Jan 2013, 3034 Bytes) of package /linux/www/SitemapCreator.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 
    3 /**
    4  * Sitemap Creator Example
    5  * 
    6  * 
    7  * @link http://sitemapcreator.org/
    8  * @package SitemapCreator
    9  * @author Waleed Gadelkareem <gadelkareem@gmail.com>
   10  * @link http://gadelkareem.com/
   11  * @filesource
   12  */
   13 error_reporting( E_ALL );
   14 ini_set('display_errors', 1);
   15 set_time_limit(10000);
   16 ini_set("memory_limit", '300M');
   17 
   18 require '../SitemapCreator.class.php';
   19 
   20 if (PHP_SAPI == "cli") $lb = "\n"; 
   21 else $lb = "<br />"; 
   22 
   23 //create object
   24 $sitemap = new SitemapCreator('http://www.dmoz.org/');
   25 
   26 
   27 
   28 //Sitemap Creator creates a URL to sitemap files
   29 //For example
   30 //echo $sitemap->getSitemapURL(1) . $lb;
   31 //however you should add your formated URL
   32 $sitemap->setSitemapURL('http://www.dmoz.org/Sitemap_Creator/data/' . $sitemap->getSitemapDirName() . '/' );
   33 
   34 //Sitemap Creator creates a path to sitemaps in system tmp
   35 //For example
   36 //echo $sitemap->getSitemapPath(1) . $lb;
   37 //however you should add your writable directory path
   38 //$sitemap->setDataDir('/server/sitemaps/data');
   39 
   40 //choose to gzip compress the sitemaps
   41 //this option is useful if you will use NGINX sendfile {@link http://wiki.nginx.org/HttpCoreModule#sendfile}
   42 //$sitemap->useGzip(true);
   43 
   44 //read the sitemaps
   45 if( isset($_GET['sitemap']) ){
   46     $sitemap->readSitemap($_GET['sitemap']);
   47     exit;
   48     }
   49     
   50 //choose sitemaps options
   51 //check docs for details
   52 $sitemap->setPriority(SitemapCreator::PRIORITY_CRAWLED_FIRST);
   53 $sitemap->setFrequency(SitemapCreator::FREQUENCY_PRIORITY);
   54 $sitemap->setEntriesPerSitemap(10);
   55 $sitemap->setMinFrequency('yearly');
   56 $sitemap->setMinPriority(0.3);
   57 
   58 
   59 //all set, let start the crawler
   60 //create $sitemap->Crawler
   61 $sitemap->initCrawler(); 
   62 
   63 //set the Cralwer options
   64 //for more options check {@link http://phpcrawl.cuab.de/classreferences/index.html}
   65 $sitemap->Crawler->setPageLimit(10); // Set the page-limit to 50 for testing
   66 //if we are not calculating Frequency based on last-modified header then we can disable
   67 $sitemap->Crawler->enableLastModifiedCount(false);
   68 
   69 //start the crawling process
   70 $sitemap->Crawl();
   71 
   72 // At the end, after the process is finished, we print a short 
   73 // report (see method getProcessReport() for more information) 
   74 $report = $sitemap->crawler_reports; 
   75      
   76 echo "Summary:".$lb; 
   77 echo "Links followed: ".$report->links_followed.$lb; 
   78 echo "Documents received: ".$report->files_received.$lb; 
   79 echo "Bytes received: ".$report->bytes_received." bytes".$lb; 
   80 echo "Process runtime: ".$report->process_runtime." sec".$lb;  
   81 flush();
   82 
   83 //create sitemaps
   84 $sitemap->CreateSitemaps();
   85 
   86 echo "Sitemap Created at {$sitemap->getSitemapPath('index')} {$lb}";
   87 if( PHP_SAPI != "cli") 
   88        echo "Click <a href='{$_SERVER['PHP_SELF']}?sitemap=index' >here</a> to view your sitemap{$lb}";
   89 
   90 $results = $sitemap->Ping();     
   91 
   92 foreach( $results as $engine => $result)
   93     if( isset($result['body']) )
   94         echo "{$engine} pinged successfully{$lb}";
   95     else
   96         echo "Error pinging {$engine} : {$result['error']}{$lb}";
   97