public static function createMFSitemap()
 {
     eZDebug::writeDebug("Generating Standard Sitemap with images ...", __METHOD__);
     $cli = $GLOBALS['cli'];
     global $cli, $isQuiet;
     if (!$isQuiet) {
         $cli->output("Generating Sitemap for Siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " \n");
     }
     $ini = eZINI::instance('site.ini');
     $googlesitemapsINI = eZINI::instance('xrowsitemap.ini');
     // Get the Sitemap's root node
     $contentINI = eZINI::instance('content.ini');
     $rootNode = eZContentObjectTreeNode::fetch($contentINI->variable('NodeSettings', 'RootNode'));
     if (!$rootNode instanceof eZContentObjectTreeNode) {
         $cli->output("Invalid RootNode for Siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " \n");
         continue;
     }
     // Settings variables
     if ($googlesitemapsINI->hasVariable('MFSitemapSettings', 'ClassFilterType') and $googlesitemapsINI->hasVariable('MFSitemapSettings', 'ClassFilterArray')) {
         $params2 = array('ClassFilterType' => $googlesitemapsINI->variable('MFSitemapSettings', 'ClassFilterType'), 'ClassFilterArray' => $googlesitemapsINI->variable('MFSitemapSettings', 'ClassFilterArray'));
     }
     $max = 49997;
     // max. amount of links in 1 sitemap
     $limit = 50;
     // Fetch the content tree
     $params = array('SortBy' => array(array('depth', true), array('published', false)));
     if (isset($params2)) {
         $params = array_merge($params, $params2);
     }
     $subtreeCount = eZContentObjectTreeNode::subTreeCountByNodeID($params, $rootNode->NodeID);
     if ($subtreeCount == 1) {
         $cli->output("No Items found under node #" . $contentINI->variable('NodeSettings', 'RootNode') . ".");
     }
     if (!$isQuiet) {
         $amount = $subtreeCount + 1;
         // +1 is root node
         $cli->output("Adding {$amount} nodes to the sitemap.");
         $output = new ezcConsoleOutput();
         $bar = new ezcConsoleProgressbar($output, $amount);
     }
     $addPrio = false;
     if ($googlesitemapsINI->hasVariable('MFSitemapSettings', 'AddPriorityToSubtree') and $googlesitemapsINI->variable('MFSitemapSettings', 'AddPriorityToSubtree') == 'true') {
         $addPrio = true;
     }
     $sitemap = new xrowSitemap();
     // Generate Sitemap
     /** START Adding the root node **/
     $object = $rootNode->object();
     $meta = xrowMetaDataFunctions::fetchByObject($object);
     $extensions = array();
     $extensions[] = new xrowSitemapItemModified($rootNode->attribute('modified_subnode'));
     $url = $rootNode->attribute('url_alias');
     eZURI::transformURI($url, true);
     if ($ini->variable('SiteAccessSettings', 'RemoveSiteAccessIfDefaultAccess') == 'enabled') {
         $url = 'http://' . xrowSitemapTools::domain() . $url;
     } else {
         $url = 'http://' . xrowSitemapTools::domain() . '/' . $GLOBALS['eZCurrentAccess']['name'] . $url;
     }
     if ($meta and $meta->googlemap != '0') {
         $extensions[] = new xrowSitemapItemFrequency($meta->change);
         $extensions[] = new xrowSitemapItemPriority($meta->priority);
         $sitemap->add($url, $extensions);
     } elseif ($meta === false and $googlesitemapsINI->variable('Settings', 'AlwaysAdd') == 'enabled') {
         if ($addPrio) {
             $extensions[] = new xrowSitemapItemPriority('1');
         }
         $sitemap->add($url, $extensions);
     }
     if (isset($bar)) {
         $bar->advance();
     }
     /** END Adding the root node **/
     $max = min($max, $subtreeCount);
     $params['Limit'] = min($max, $limit);
     $params['Offset'] = 0;
     while ($params['Offset'] < $max) {
         $nodeArray = eZContentObjectTreeNode::subTreeByNodeID($params, $rootNode->NodeID);
         foreach ($nodeArray as $subTreeNode) {
             eZContentLanguage::expireCache();
             $object = $subTreeNode->object();
             $images = array();
             $meta = xrowMetaDataFunctions::fetchByObject($object);
             $extensions = array();
             $extensions[] = new xrowSitemapItemModified($subTreeNode->attribute('modified_subnode'));
             $url = $subTreeNode->attribute('url_alias');
             eZURI::transformURI($url, true);
             if ($ini->variable('SiteAccessSettings', 'RemoveSiteAccessIfDefaultAccess') == 'enabled') {
                 $url = 'http://' . xrowSitemapTools::domain() . $url;
             } else {
                 $url = 'http://' . xrowSitemapTools::domain() . '/' . $GLOBALS['eZCurrentAccess']['name'] . $url;
             }
             if ($meta and $meta->googlemap != '0') {
                 $extensions[] = new xrowSitemapItemFrequency($meta->change);
                 $extensions[] = new xrowSitemapItemPriority($meta->priority);
             } elseif ($meta === false and $googlesitemapsINI->variable('Settings', 'AlwaysAdd') == 'enabled') {
                 if ($addPrio) {
                     $rootDepth = $rootNode->attribute('depth');
                     $prio = 1 - ($subTreeNode->attribute('depth') - $rootDepth) / 10;
                     if ($prio > 0) {
                         $extensions[] = new xrowSitemapItemPriority($prio);
                     }
                 }
             }
             $images = self::getSitemapImageItems($object);
             $sitemap->add($url, array_merge($extensions, $images));
             if (isset($bar)) {
                 $bar->advance();
             }
         }
         eZContentObject::clearCache();
         $params['Offset'] += $params['Limit'];
     }
     // write XML Sitemap to file
     $dir = eZSys::storageDirectory() . '/sitemap/' . xrowSitemapTools::domain();
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     $filename = $dir . '/' . xrowSitemap::BASENAME . '_standard_' . $GLOBALS['eZCurrentAccess']['name'] . '.' . xrowSitemap::SUFFIX;
     $sitemap->save($filename);
     if (!$isQuiet) {
         $cli->output("\n");
         $cli->output("Sitemap {$filename} for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " has been generated.\n");
     }
 }
 public static function createNewsSitemap()
 {
     eZDebug::writeDebug("Generating news sitemap ...", __METHOD__);
     $cli = eZCLI::instance();
     if (!$isQuiet) {
         $cli->output("Generating new sitemap for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " \n");
     }
     $rootNode = self::rootNode();
     $ini = eZINI::instance('xrowsitemap.ini');
     if ($ini->hasVariable('NewsSitemapSettings', 'RootNode')) {
         $rootNodeID = (int) $ini->variable('NewsSitemapSettings', 'RootNode');
         $rootNode = eZContentObjectTreeNode::fetch($rootNodeID);
         if (!$rootNode instanceof eZContentObjectTreeNode) {
             throw new Exception("Invalid RootNode " . $rootNodeID . " for Siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " \n");
         }
     }
     if ($ini->hasVariable('NewsSitemapSettings', 'ClassFilterArray')) {
         $params2 = array();
         $params2['ClassFilterArray'] = $ini->variable('NewsSitemapSettings', 'ClassFilterArray');
         $params2['ClassFilterType'] = 'include';
     }
     if ($ini->hasVariable('NewsSitemapSettings', 'Limitation')) {
         $limitation = $ini->variable('NewsSitemapSettings', 'Limitation');
     }
     if ($ini->hasVariable('NewsSitemapSettings', 'ExtraAttributeFilter')) {
         $extra_attribute_filter = array();
         $extra_attribute_filter = $ini->variable('NewsSitemapSettings', 'ExtraAttributeFilter');
     }
     // Your News Sitemap should contain only URLs for your articles published in the last two days.
     $from = time() - 172800;
     // minus 2 days
     $till = time();
     // A News Sitemap can contain no more than 1,000 URLs.
     $max = 1000;
     $limit = 50;
     // first check if it's necerssary to recreate an exisiting one
     $dir = eZSys::storageDirectory() . '/sitemap/' . self::domain();
     $filename = $dir . '/' . xrowSitemap::BASENAME . '_' . self::FILETYP_NEWS . '_' . $GLOBALS['eZCurrentAccess']['name'] . '.' . xrowSitemap::SUFFIX;
     $file = eZClusterFileHandler::instance($filename);
     if ($file->exists()) {
         #If older as 2 days
         $oldnews = $file->mtime() - 300;
         if ($file->mtime() < $from) {
             $file->delete();
         }
         #reduce 5 min because article might be published during the runtime of the cron
         $mtime = $file->mtime() - 300;
         if ($mtime > 0) {
             $params = array('IgnoreVisibility' => false, 'MainNodeOnly' => false, 'SortBy' => array(array('published', false)), 'AttributeFilter' => array('and', array('published', '>', $mtime), array('published', '<=', $till)));
             if (isset($params2)) {
                 $params = array_merge($params, $params2);
             }
             if (isset($limitation) && $limitation == 'disable') {
                 $params['Limitation'] = array();
             }
             if (isset($extra_attribute_filter)) {
                 foreach ($extra_attribute_filter as $key => $extra_attribute_filter_item) {
                     if ($ini->hasGroup($extra_attribute_filter_item)) {
                         $value = $ini->variable($extra_attribute_filter_item, 'Value');
                         array_push($params['AttributeFilter'], $value);
                     }
                 }
             }
             $subtreeCount = eZContentObjectTreeNode::subTreeCountByNodeID($params, $rootNode->NodeID);
             if ($subtreeCount == 0) {
                 eZDebug::writeDebug("No new published news", __METHOD__);
                 return;
             }
         }
     }
     $params = array('IgnoreVisibility' => false, 'MainNodeOnly' => false, 'SortBy' => array(array('published', false)), 'AttributeFilter' => array('and', array('published', '>', $from), array('published', '<=', $till)));
     if (isset($params2)) {
         $params = array_merge($params, $params2);
     }
     if (isset($limitation) && $limitation == 'disable') {
         $params['Limitation'] = array();
     }
     if (isset($extra_attribute_filter)) {
         foreach ($extra_attribute_filter as $key => $extra_attribute_filter_item) {
             if ($ini->hasGroup($extra_attribute_filter_item)) {
                 $value = $ini->variable($extra_attribute_filter_item, 'Value');
                 array_push($params['AttributeFilter'], $value);
             }
         }
     }
     $subtreeCount = eZContentObjectTreeNode::subTreeCountByNodeID($params, $rootNode->NodeID);
     $max = min($max, $subtreeCount);
     $max_all = $max;
     $params['Limit'] = $limit;
     $params['Offset'] = 0;
     $counter = 1;
     $runs = ceil($subtreeCount / $max_all);
     if (!$isQuiet) {
         $amount = $subtreeCount;
         $cli->output("Adding {$amount} nodes to the news sitemap.");
         $output = new ezcConsoleOutput();
     }
     while ($counter <= $runs) {
         eZDebug::writeDebug('Run ' . $counter . ' of ' . $runs . ' runs');
         if (!$isQuiet) {
             $cli->output('Run ' . $counter . ' of ' . $runs . ' runs');
             if ($counter == 1) {
                 $bar = new ezcConsoleProgressbar($output, $max + 1);
                 // for root node
             } else {
                 $bar = new ezcConsoleProgressbar($output, $max);
             }
         }
         // Generate Sitemap
         $sitemap = new xrowSitemap();
         while ($params['Offset'] < $max_all) {
             $nodeArray = eZContentObjectTreeNode::subTreeByNodeID($params, $rootNode->NodeID);
             foreach ($nodeArray as $node) {
                 $extensions = array();
                 $extensions[] = self::getNewsConverter()->addNews($node);
                 $imageadd = self::getImageConverter()->addImage($node);
                 if (!empty($imageadd)) {
                     $extensions = array_merge($extensions, $imageadd);
                 }
                 $url = $node->attribute('url_alias');
                 eZURI::transformURI($url, true);
                 $url = 'http://' . self::domain() . $url;
                 $sitemap->add($url, $extensions);
                 if (isset($bar)) {
                     $bar->advance();
                 }
             }
             eZContentObject::clearCache();
             $params['Offset'] += $params['Limit'];
         }
         // write XML Sitemap to file
         if (!is_dir($dir)) {
             mkdir($dir, 0777, true);
         }
         $filename = $dir . '/' . xrowSitemap::BASENAME . '_' . self::FILETYP_NEWS . '_' . $GLOBALS['eZCurrentAccess']['name'] . '.' . xrowSitemap::SUFFIX;
         if ($counter > 1) {
             $filename = $dir . '/' . xrowSitemap::BASENAME . '_' . self::FILETYP_NEWS . '_' . $GLOBALS['eZCurrentAccess']['name'] . '_' . $counter . '.' . xrowSitemap::SUFFIX;
         }
         $sitemap->save($filename);
         if (!$isQuiet) {
             $cli->output("\n");
             $cli->output("Time: " . date('d.m.Y H:i:s') . ". Action: Sitemap {$filename} for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " has been generated.\n");
         }
         $counter++;
         $max_all += $max;
         $sitemap = new xrowSitemap();
     }
 }