includes/paths.php
changeset 607 935f3799b654
parent 605 d2d4e40ecd29
child 613 c08670a77871
equal deleted inserted replaced
605:d2d4e40ecd29 607:935f3799b654
   155   
   155   
   156   function init()
   156   function init()
   157   {
   157   {
   158     global $db, $session, $paths, $template, $plugins; // Common objects
   158     global $db, $session, $paths, $template, $plugins; // Common objects
   159     global $lang;
   159     global $lang;
       
   160     global $cache;
   160     
   161     
   161     $code = $plugins->setHook('paths_init_before');
   162     $code = $plugins->setHook('paths_init_before');
   162     foreach ( $code as $cmd )
   163     foreach ( $code as $cmd )
   163     {
   164     {
   164       eval($cmd);
   165       eval($cmd);
   165     }
   166     }
   166     
   167     
   167     $cache_enable = ( getConfig('cache_thumbs') == '1' );
   168     if ( $page_cache = $cache->fetch('page_meta') )
   168     $cache_file = ENANO_ROOT . '/cache/cache_page_meta.php';
   169     {
   169     $cache_fresh = ( file_exists($cache_file) ) ? filemtime($cache_file) + 1800 >= time() : false;
   170       $this->pages = array_merge($this->pages, $page_cache);
   170     if ( $cache_enable && $cache_fresh )
       
   171     {
       
   172       require($cache_file);
       
   173       if ( isset($page_cache) && is_array($page_cache) )
       
   174       {
       
   175         $this->pages = array_merge($this->pages, $page_cache);
       
   176       }
       
   177     }
   171     }
   178     else
   172     else
   179     {
   173     {
   180       $e = $db->sql_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
   174       $e = $db->sql_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
   181                           . '  delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
   175                           . '  delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
   190         
   184         
   191         $this->pages[$r['urlname']] = $r;
   185         $this->pages[$r['urlname']] = $r;
   192         $this->pages[] =& $this->pages[$r['urlname']];
   186         $this->pages[] =& $this->pages[$r['urlname']];
   193       }
   187       }
   194       
   188       
   195       if ( $cache_enable )
   189       $this->update_metadata_cache();
   196       {
       
   197         $this->update_metadata_cache();
       
   198       }
       
   199     }
   190     }
   200     $db->free_result();
   191     $db->free_result();
   201     if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') )
   192     if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') )
   202     {
   193     {
   203       $title = $this->parse_url(false);
   194       $title = $this->parse_url(false);
   583   
   574   
   584   function update_metadata_cache()
   575   function update_metadata_cache()
   585   {
   576   {
   586     global $db, $session, $paths, $template, $plugins; // Common objects
   577     global $db, $session, $paths, $template, $plugins; // Common objects
   587     
   578     
   588     $cache_output = <<<EOF
   579     if ( getConfig('cache_thumbs') != '1' )
   589 <?php
   580       return false;
   590 
   581     
   591 /**
       
   592  * Automatically generated cache of page metadata. Do not edit this file as it is updated every 20 minutes.
       
   593  */
       
   594 
       
   595 \$page_cache = array(
       
   596 EOF;
       
   597     $e = $db->sql_unbuffered_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
   582     $e = $db->sql_unbuffered_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
   598                           . '  delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
   583                           . '  delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
   599     if ( !$e )
   584     if ( !$e )
   600       $db->_die();
   585       $db->_die();
   601     
   586     
       
   587     $md_array = array();
       
   588     
   602     while ( $row = $db->fetchrow() )
   589     while ( $row = $db->fetchrow() )
   603     {
   590     {
   604       $row = $this->calculate_metadata_from_row($row);
   591       $row = $this->calculate_metadata_from_row($row);
   605       $key = addslashes($row['urlname']);
   592       $md_array[$row['urlname']] = $row;
   606       $row = substr(preg_replace('/^/m', '  ', Language::var_export_string($row)), 2);
   593     }
   607       $cache_output .= "\n  '$key' => $row,";
   594     
   608     }
   595     // import cache functions
   609     
   596     global $cache;
   610     $cache_output .= "\n);\n";
   597     
   611     $cache_file = ENANO_ROOT . '/cache/cache_page_meta.php';
   598     // store data (TTL 20 minutes)
   612     
   599     $cache->store('page_meta', $md_array, 20);
   613     $fh = @fopen($cache_file, 'w');
       
   614     if ( !$fh )
       
   615       return false;
       
   616     fwrite($fh, $cache_output);
       
   617     fclose($fh);
       
   618     
   600     
   619     return true;
   601     return true;
   620   }
   602   }
   621   
   603   
   622   /**
   604   /**