Forums / Developer / PreviewCache script / Comment43551

Author Topic

Lydie Soler

Monday 30 January 2006 8:23:12 am

Comment43551

*redacted*

#!/usr/bin/env php
<?php
//
// Created on: <12-Jul-2005 14:08:11>
// Created by: Redacted 2024
//
// 
//
//
// This file may be distributed and/or modified under the terms of the
// "GNU General Public License" version 2 as published by the Free
// Software Foundation and appearing in the file LICENSE.GPL included in
// the packaging of this file.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
//

include_once( 'lib/ezutils/classes/ezcli.php' );
include_once( 'kernel/classes/ezscript.php' );
include_once( 'kernel/content/ezcontentfunctioncollection.php');
include_once( 'kernel/content/ezcontentoperationcollection.php');
include_once( "kernel/classes/datatypes/ezuser/ezuser.php" );
include_once( 'kernel/classes/eznodeviewfunctions.php' );
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );

$cli =& eZCLI::instance();
$script =& eZScript::instance( array( 'description' => ( "Exponential PreViewCacher\n" .
                                                         "\n" .
                                                         "./bin/php/ezcc.php -s news" ),
                                      'use-session' => false,
                                      'use-modules' => true,
                                      'use-extensions' => true ) );

$options = $script->getOptions( "[node:][depth:][limit:][class:][delay:]",
                                "",
                                array( 'node'  => "Node (default 2)",
                                    'depth' => "Depth (e.g. --depth=3)",
                                       'limit' => "Limit (e.g. --limit=100)",
                                       'class' => "class filter (e.g --class=folder or --class=2)",
                                       'delay' => "delay in seconds between each page request" ) );
$sys =& eZSys::instance();
$delay = 0;
$node = 2;

if ( $options['siteaccess'] )
{
    $sys->clearAccessPath();
    $sys->addAccessPath( $options['siteaccess'] );
}

if ( $options['node'] )
{
    $node = $options['node'] ;
}

if ( $options['depth'] )
{
    $depth = $options['depth'] ;
}

if ( $options['limit'] )
{
    $limit = $options['limit'] ;
}

if ( $options['class'] )
{
   $classFilterType = 'include';
   $classFilterArray = $options['class'] ;
}

if ( $options['delay'] )
{
   $delay = $options['delay'] ;
}

$script->startup();
$script->initialize();

if ( $options['siteaccess'] )
{
 include_once( 'kernel/common/template.php' );
    $tpl =& templateInit();

 $nodelist = eZContentObjectTreeNode::subTree( array( 'Depth' => $depth, 'Limit' => $limit, 'ClassFilterType' => $classFilterType, ClassFilterArray => array( $classFilterArray )  ), $node );
    $script->setShowVerboseOutput( true );
 $cli->output(  "Crawling " . count($nodelist). " nodes..." );
 foreach ($nodelist as $node)
 {

   $time_start = microtime(true);
   $sys->setServerVariable('REQUEST_URI','/content/view/full/'.$node->attribute( 'node_id' ));
   
   $ini =& eZINI::instance("site.ini");
   $siteURL = $ini->variable("SiteSettings","SiteURL");
   
   
   //$status=shell_exec("index.php"); doesn"t work at all
   //$status=shell_exec("php index.php"); seems to work but doesn't seems to...
   $status = fclose(fopen('http://'.$siteURL.'/content/view/full/'.$node->attribute( 'node_id' ),"r"));
   $time_end = microtime(true);

   $text = false;
   if ( $status )
               $text = "Crawled node: " . $cli->stylize( 'node', $node->attribute( 'url_alias' )) . "\t" . $cli->stylize($node->attribute( 'node_id' ) . "\t" . preg_replace('/^0?(\S+) (\S+)$/X', '$2$1', $time_end - $time_start."s" ) );
      
         else
               $text = "Failed to crawl node: " . $cli->stylize( 'node', $node->attribute( 'node_id' ) );
            $script->iterate( $cli, $status, $text );

            if ($delay)
            {
             sleep($delay);
            }
 }

}
else
{
  $cli->output(  "Please specify a siteaccess name, e.g.: -s plain" );
}

$script->shutdown();

?>