includes/paths.php
changeset 593 4f9bec0d65c1
parent 592 27377179fe58
child 605 d2d4e40ecd29
equal deleted inserted replaced
592:27377179fe58 593:4f9bec0d65c1
   114     }
   114     }
   115     
   115     
   116     $this->wiki_mode = ( getConfig('wiki_mode') == '1' ) ? 1 : 0;
   116     $this->wiki_mode = ( getConfig('wiki_mode') == '1' ) ? 1 : 0;
   117     $this->template_cache = Array();
   117     $this->template_cache = Array();
   118   }
   118   }
       
   119   
   119   function parse_url($sanitize = true)
   120   function parse_url($sanitize = true)
   120   {
   121   {
   121     $title = '';
   122     $title = '';
   122     if ( isset($_GET['title']) )
   123     if ( isset($_GET['title']) )
   123     {
   124     {
   148         }
   149         }
   149       }
   150       }
   150     }
   151     }
   151     return ( $sanitize ) ? sanitize_page_id($title) : $title;
   152     return ( $sanitize ) ? sanitize_page_id($title) : $title;
   152   }
   153   }
       
   154   
   153   function init()
   155   function init()
   154   {
   156   {
   155     global $db, $session, $paths, $template, $plugins; // Common objects
   157     global $db, $session, $paths, $template, $plugins; // Common objects
   156     global $lang;
   158     global $lang;
   157     
   159     
   159     foreach ( $code as $cmd )
   161     foreach ( $code as $cmd )
   160     {
   162     {
   161       eval($cmd);
   163       eval($cmd);
   162     }
   164     }
   163     
   165     
   164     $e = $db->sql_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
   166     $cache_enable = ( getConfig('cache_thumbs') == '1' );
   165                         . '  delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
   167     $cache_file = ENANO_ROOT . '/cache/cache_page_meta.php';
   166     if( !$e )
   168     $cache_fresh = ( file_exists($cache_file) ) ? filemtime($cache_file) + 1800 >= time() : false;
   167     {
   169     if ( $cache_enable && $cache_fresh )
   168       $db->_die('The error seems to have occured while selecting the page information. File: includes/paths.php; line: '.__LINE__);
   170     {
   169     }
   171       require($cache_file);
   170     while($r = $db->fetchrow())
   172       if ( isset($page_cache) && is_array($page_cache) )
   171     {
   173       {
       
   174         $this->pages = array_merge($this->pages, $page_cache);
       
   175       }
       
   176     }
       
   177     else
       
   178     {
       
   179       $e = $db->sql_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
       
   180                           . '  delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
   172       
   181       
   173       $r['urlname_nons'] = $r['urlname'];
   182       if( !$e )
   174       if ( isset($this->nslist[$r['namespace']]) )
   183       {
   175       {
   184         $db->_die('The error seems to have occured while selecting the page information. File: includes/paths.php; line: '.__LINE__);
   176         $r['urlname'] = $this->nslist[$r['namespace']] . $r['urlname']; // Applies the User:/File:/etc prefixes to the URL names
   185       }
   177       }
   186       while($r = $db->fetchrow())
   178       else
   187       {
   179       {
   188         $r = $this->calculate_metadata_from_row($r);
   180         $ns_char = substr($this->nslist['Special'], -1);
   189         
   181         $r['urlname'] = $r['namespace'] . $ns_char . $r['urlname'];
   190         $this->pages[$r['urlname']] = $r;
       
   191         $this->pages[] =& $this->pages[$r['urlname']];
   182       }
   192       }
   183       
   193       
   184       if ( $r['delvotes'] == null)
   194       if ( $cache_enable )
   185       {
   195       {
   186         $r['delvotes'] = 0;
   196         $this->update_metadata_cache();
   187       }
   197       }
   188       if ( $r['protected'] == 0 || $r['protected'] == 1 )
       
   189       {
       
   190         $r['really_protected'] = (int)$r['protected'];
       
   191       }
       
   192       else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '1')
       
   193       {
       
   194         $r['really_protected'] = 1;
       
   195       }
       
   196       else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '0' )
       
   197       {
       
   198         $r['really_protected'] = 0;
       
   199       }
       
   200       
       
   201       $this->pages[$r['urlname']] = $r;
       
   202       $this->pages[] =& $this->pages[$r['urlname']];
       
   203       
       
   204     }
   198     }
   205     $db->free_result();
   199     $db->free_result();
   206     if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') )
   200     if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') )
   207     {
   201     {
   208       $title = $this->parse_url(false);
   202       $title = $this->parse_url(false);
   399       eval($cmd);
   393       eval($cmd);
   400     }
   394     }
   401    
   395    
   402     profiler_log('Paths and CMS core initted');
   396     profiler_log('Paths and CMS core initted');
   403     $session->init_permissions();
   397     $session->init_permissions();
   404     profiler_log('Default ACL set retrieved');
       
   405   }
   398   }
   406   
   399   
   407   function add_page($flags)
   400   function add_page($flags)
   408   {
   401   {
   409     global $lang;
   402     global $lang;
   579     {
   572     {
   580       // echo '<b>Warning:</b> pathManager::create_namespace: Namespace ID "'.$prefix.'" is already taken<br />';
   573       // echo '<b>Warning:</b> pathManager::create_namespace: Namespace ID "'.$prefix.'" is already taken<br />';
   581       return false;
   574       return false;
   582     }
   575     }
   583     $this->nslist[$id] = $prefix;
   576     $this->nslist[$id] = $prefix;
       
   577   }
       
   578   
       
   579   /**
       
   580    * Updates the cache containing all page metadata.
       
   581    */
       
   582   
       
   583   function update_metadata_cache()
       
   584   {
       
   585     global $db, $session, $paths, $template, $plugins; // Common objects
       
   586     
       
   587     $cache_output = <<<EOF
       
   588 <?php
       
   589 
       
   590 /**
       
   591  * Automatically generated cache of page metadata. Do not edit this file as it is updated every 20 minutes.
       
   592  */
       
   593 
       
   594 \$page_cache = array(
       
   595 EOF;
       
   596     $e = $db->sql_unbuffered_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
       
   597                           . '  delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
       
   598     if ( !$e )
       
   599       $db->_die();
       
   600     
       
   601     while ( $row = $db->fetchrow() )
       
   602     {
       
   603       $row = $this->calculate_metadata_from_row($row);
       
   604       $key = addslashes($row['urlname']);
       
   605       $row = substr(preg_replace('/^/m', '  ', Language::var_export_string($row)), 2);
       
   606       $cache_output .= "\n  '$key' => $row,";
       
   607     }
       
   608     
       
   609     $cache_output .= "\n);\n";
       
   610     $cache_file = ENANO_ROOT . '/cache/cache_page_meta.php';
       
   611     
       
   612     $fh = @fopen($cache_file, 'w');
       
   613     if ( !$fh )
       
   614       return false;
       
   615     fwrite($fh, $cache_output);
       
   616     fclose($fh);
       
   617     
       
   618     return true;
       
   619   }
       
   620   
       
   621   /**
       
   622    * Takes a result row from the pages table and calculates correct values for it.
       
   623    * @param array
       
   624    * @return array
       
   625    */
       
   626   
       
   627   function calculate_metadata_from_row($r)
       
   628   {
       
   629     $r['urlname_nons'] = $r['urlname'];
       
   630     if ( isset($this->nslist[$r['namespace']]) )
       
   631     {
       
   632       $r['urlname'] = $this->nslist[$r['namespace']] . $r['urlname']; // Applies the User:/File:/etc prefixes to the URL names
       
   633     }
       
   634     else
       
   635     {
       
   636       $ns_char = substr($this->nslist['Special'], -1);
       
   637       $r['urlname'] = $r['namespace'] . $ns_char . $r['urlname'];
       
   638     }
       
   639     
       
   640     if ( $r['delvotes'] == null)
       
   641     {
       
   642       $r['delvotes'] = 0;
       
   643     }
       
   644     if ( $r['protected'] == 0 || $r['protected'] == 1 )
       
   645     {
       
   646       $r['really_protected'] = (int)$r['protected'];
       
   647     }
       
   648     else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '1')
       
   649     {
       
   650       $r['really_protected'] = 1;
       
   651     }
       
   652     else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '0' )
       
   653     {
       
   654       $r['really_protected'] = 0;
       
   655     }
       
   656     return $r;
   584   }
   657   }
   585   
   658   
   586   /**
   659   /**
   587    * Registers a handler to manually process a namespace instead of the default PageProcessor behavior.
   660    * Registers a handler to manually process a namespace instead of the default PageProcessor behavior.
   588    * The first and only parameter passed to the processing function will be the PageProcessor instance.
   661    * The first and only parameter passed to the processing function will be the PageProcessor instance.