public static function createMobileSitemap() { eZDebug::writeDebug("Generating mobile sitemap ...", __METHOD__); $cli = eZCLI::instance(); if (!$isQuiet) { $cli->output("Generating mobile sitemap for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " \n"); } $ini = eZINI::instance('site.ini'); $xrowsitemapINI = eZINI::instance('xrowsitemap.ini'); // Get the Sitemap's root node $rootNode = self::rootNode(); // Settings variables if ($xrowsitemapINI->hasVariable('MobileSitemapSettings', 'ClassFilterType') and $xrowsitemapINI->hasVariable('MobileSitemapSettings', 'ClassFilterArray')) { $params2 = array('ClassFilterType' => $xrowsitemapINI->variable('MobileSitemapSettings', 'ClassFilterType'), 'ClassFilterArray' => $xrowsitemapINI->variable('MobileSitemapSettings', 'ClassFilterArray')); } $max = self::MAX_PER_FILE; $limit = 50; // Fetch the content tree $params = array('SortBy' => array(array('depth', true), array('published', true))); if (isset($params2)) { $params = array_merge($params, $params2); } $subtreeCount = eZContentObjectTreeNode::subTreeCountByNodeID($params, $rootNode->NodeID); if ($subtreeCount == 1) { $cli->output("No Items found under RootNode {$rootNode->NodeID}."); } if (!$isQuiet) { $amount = $subtreeCount + 1; // +1 is root node $cli->output("Adding {$amount} nodes to the sitemap for RootNode {$rootNode->NodeID}."); $output = new ezcConsoleOutput(); $bar = new ezcConsoleProgressbar($output, $amount); } $addPrio = false; if ($xrowsitemapINI->hasVariable('Settings', 'AddPriorityToSubtree') and $xrowsitemapINI->variable('Settings', 'AddPriorityToSubtree') == 'true') { $addPrio = true; } $sitemap = new xrowMobileSitemap(); // 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); if ($xrowsitemapINI->hasVariable('SitemapSettings', 'MobileDomainName') && $xrowsitemapINI->hasVariable('SitemapSettings', 'MobileDomainName') != '') { $mobileDomain = $xrowsitemapINI->variable('SitemapSettings', 'MobileDomainName'); } else { $mobileDomain = self::domain(); } $url = 'http://' . $mobileDomain . $url; if ($meta and $meta->sitemap_use != '0') { $extensions[] = new xrowSitemapItemFrequency($meta->change); $extensions[] = new xrowSitemapItemPriority($meta->priority); $sitemap->add($url, $extensions); } elseif ($meta === false and $xrowsitemapINI->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(); $meta = xrowMetaDataFunctions::fetchByNode($subTreeNode); $extensions = array(); $extensions[] = new xrowSitemapItemModified($subTreeNode->attribute('modified_subnode')); $url = $subTreeNode->attribute('url_alias'); eZURI::transformURI($url); $url = 'http://' . $mobileDomain . $url; if ($meta and $meta->sitemap_use != '0') { $extensions[] = new xrowSitemapItemFrequency($meta->change); $extensions[] = new xrowSitemapItemPriority($meta->priority); $sitemap->add($url, $extensions); } elseif ($meta === false and $xrowsitemapINI->variable('Settings', 'AlwaysAdd') == 'enabled') { if ($addPrio) { $rootDepth = $rootNode->attribute('depth'); $prio = 1 - ($subTreeNode->attribute('depth') - $rootDepth) / 10; if ($prio > 0) { $extensions[] = new xrowSitemapItemPriority($prio); } } $sitemap->add($url, $extensions); } if (isset($bar)) { $bar->advance(); } } eZContentObject::clearCache(); $params['Offset'] += $params['Limit']; } // write XML Sitemap to file $dir = eZSys::storageDirectory() . '/sitemap/' . self::domain(); if (!is_dir($dir)) { mkdir($dir, 0777, true); } $filename = $dir . '/' . xrowSitemap::BASENAME . '_' . self::FILETYP_MOBILE . '_' . $GLOBALS['eZCurrentAccess']['name'] . '.' . xrowSitemap::SUFFIX; $sitemap->save($filename); /** * @TODO How will this work with cluster? if ( function_exists( 'gzencode' ) and $xrowsitemapINI->variable( 'MobileSitemapSettings', 'Gzip' ) == 'enabled' ) { $content = file_get_contents( $filename ); $content = gzencode( $content ); file_put_contents( $filename . '.gz', $content ); unlink( $filename ); $filename .= '.gz'; } **/ if (!$isQuiet) { $cli->output("\n"); $cli->output("Mobile sitemap {$filename} for siteaccess " . $GLOBALS['eZCurrentAccess']['name'] . " has been generated.\n"); } }