Пример #1
0
 /**
  * Loads a set of content objects into the cached tree.
  *
  * @param boolean $loadprops If true, load the properties of those content objects
  * @param boolean $onlyexpanded Not implemented
  * @param boolean $loadcontent If false, only create the nodes in the tree, 
  *                             don't load the content objects
  * @return mixed The cached tree of content
  */
 function &GetAllContentAsHierarchy($loadprops, $onlyexpanded = null, $loadcontent = false)
 {
     debug_buffer('', 'starting tree');
     require_once dirname(dirname(__FILE__)) . '/Tree/Tree.php';
     $nodes = array();
     global $gCms;
     $db =& $gCms->GetDb();
     $cachefilename = TMP_CACHE_LOCATION . '/contentcache.php';
     $usecache = true;
     if (isset($onlyexpanded) || isset($CMS_ADMIN_PAGE)) {
         #$usecache = false;
     }
     $loadedcache = false;
     if ($usecache) {
         if (isset($gCms->variables['pageinfo']) && file_exists($cachefilename)) {
             $pageinfo =& $gCms->variables['pageinfo'];
             //debug_buffer('content cache file exists... file: ' . filemtime($cachefilename) . ' content:' . $pageinfo->content_last_modified_date);
             if (isset($pageinfo->content_last_modified_date) && $pageinfo->content_last_modified_date < filemtime($cachefilename)) {
                 debug_buffer('file needs loading');
                 $handle = fopen($cachefilename, "r");
                 $data = fread($handle, filesize($cachefilename));
                 fclose($handle);
                 $tree = unserialize(substr($data, 16));
                 #$variables =& $gCms->variables;
                 #$variables['contentcache'] =& $tree;
                 if (strtolower(get_class($tree)) == 'tree') {
                     $loadedcache = true;
                 } else {
                     $loadedcache = false;
                 }
             }
         }
     }
     if (!$loadedcache) {
         $query = "SELECT id_hierarchy FROM " . cms_db_prefix() . "content ORDER BY hierarchy";
         $dbresult =& $db->Execute($query);
         if ($dbresult && $dbresult->RecordCount() > 0) {
             while ($row = $dbresult->FetchRow()) {
                 $nodes[] = $row['id_hierarchy'];
             }
         }
         $tree = new Tree();
         debug_buffer('', 'Start Loading Children into Tree');
         $tree = Tree::createFromList($nodes, '.');
         debug_buffer('', 'End Loading Children into Tree');
     }
     if (!$loadedcache && $usecache) {
         debug_buffer("Serializing...");
         $handle = fopen($cachefilename, "w");
         fwrite($handle, '<?php return; ?>' . serialize($tree));
         fclose($handle);
     }
     if ($loadcontent) {
         ContentOperations::LoadChildrenIntoTree(-1, $tree, false, true);
     }
     debug_buffer('', 'ending tree');
     return $tree;
 }