includes/paths.php
changeset 571 66e14e61613e
parent 567 7f196509bf78
child 590 03a60844c7c5
equal deleted inserted replaced
570:4d0d5dae61e5 571:66e14e61613e
    15  * @package Enano
    15  * @package Enano
    16  * @subpackage PathManager
    16  * @subpackage PathManager
    17  * @see http://enanocms.org/Help:API_Documentation
    17  * @see http://enanocms.org/Help:API_Documentation
    18  */
    18  */
    19  
    19  
    20 class pathManager {
    20 class pathManager
    21   var $pages, $custom_page, $cpage, $page, $fullpage, $page_exists, $page_id, $namespace, $nslist, $admin_tree, $wiki_mode, $page_protected, $template_cache, $anonymous_page;
    21 {
       
    22   public $pages, $custom_page, $cpage, $page, $fullpage, $page_exists, $page_id, $namespace, $nslist, $admin_tree, $wiki_mode, $page_protected, $template_cache, $anonymous_page;
       
    23   
       
    24   /**
       
    25    * List of custom processing functions for namespaces. This is protected so trying to do anything with it will throw an error.
       
    26    * @access private
       
    27    * @var array
       
    28    */
       
    29   
       
    30   protected $namespace_processors;
       
    31   
    22   function __construct()
    32   function __construct()
    23   {
    33   {
    24     global $db, $session, $paths, $template, $plugins; // Common objects
    34     global $db, $session, $paths, $template, $plugins; // Common objects
    25     
    35     
    26     $GLOBALS['paths'] =& $this;
    36     $GLOBALS['paths'] =& $this;
    74     $session->register_acl_type('upload_new_version',     AUTH_WIKIMODE, 'perm_upload_new_version',     Array('upload_files'),                                    'Article|User|Project|Template|File|Help|System|Category|Special');
    84     $session->register_acl_type('upload_new_version',     AUTH_WIKIMODE, 'perm_upload_new_version',     Array('upload_files'),                                    'Article|User|Project|Template|File|Help|System|Category|Special');
    75     $session->register_acl_type('create_page',            AUTH_WIKIMODE, 'perm_create_page',            Array(),                                                  'Article|User|Project|Template|File|Help|System|Category|Special');
    85     $session->register_acl_type('create_page',            AUTH_WIKIMODE, 'perm_create_page',            Array(),                                                  'Article|User|Project|Template|File|Help|System|Category|Special');
    76     $session->register_acl_type('html_in_pages',          AUTH_DISALLOW, 'perm_html_in_pages',          Array('edit_page'),                                       'Article|User|Project|Template|File|Help|System|Category|Admin');
    86     $session->register_acl_type('html_in_pages',          AUTH_DISALLOW, 'perm_html_in_pages',          Array('edit_page'),                                       'Article|User|Project|Template|File|Help|System|Category|Admin');
    77     $session->register_acl_type('php_in_pages',           AUTH_DISALLOW, 'perm_php_in_pages',           Array('edit_page', 'html_in_pages'),                      'Article|User|Project|Template|File|Help|System|Category|Admin');
    87     $session->register_acl_type('php_in_pages',           AUTH_DISALLOW, 'perm_php_in_pages',           Array('edit_page', 'html_in_pages'),                      'Article|User|Project|Template|File|Help|System|Category|Admin');
    78     $session->register_acl_type('custom_user_title',      AUTH_DISALLOW, 'perm_custom_user_title',      Array(),                                                  'User|Special');
    88     $session->register_acl_type('custom_user_title',      AUTH_DISALLOW, 'perm_custom_user_title',      Array(),                                                  'User|Special');
    79     $session->register_acl_type('edit_acl',               AUTH_DISALLOW, 'perm_edit_acl',               Array('read', 'post_comments', 'edit_comments', 'edit_page', 'view_source', 'mod_comments', 'history_view', 'history_rollback', 'history_rollback_extra', 'protect', 'rename', 'clear_logs', 'vote_delete', 'vote_reset', 'delete_page', 'set_wiki_mode', 'password_set', 'password_reset', 'mod_misc', 'edit_cat', 'even_when_protected', 'upload_files', 'upload_new_version', 'create_page', 'php_in_pages'));
    89     $session->register_acl_type('edit_acl',               AUTH_DISALLOW, 'perm_edit_acl',               Array());
    80     
    90     
    81     // DO NOT add new admin pages here! Use a plugin to call $paths->addAdminNode();
    91     // DO NOT add new admin pages here! Use a plugin to call $paths->addAdminNode();
    82     $this->addAdminNode('adm_cat_general',    'adm_page_general_config', 'GeneralConfig', scriptPath . '/images/icons/applets/generalconfig.png');
    92     $this->addAdminNode('adm_cat_general',    'adm_page_general_config', 'GeneralConfig', scriptPath . '/images/icons/applets/generalconfig.png');
    83     $this->addAdminNode('adm_cat_general',    'adm_page_file_uploads',   'UploadConfig', scriptPath . '/images/icons/applets/uploadconfig.png');
    93     $this->addAdminNode('adm_cat_general',    'adm_page_file_uploads',   'UploadConfig', scriptPath . '/images/icons/applets/uploadconfig.png');
    84     $this->addAdminNode('adm_cat_general',    'adm_page_file_types',     'UploadAllowedMimeTypes', scriptPath . '/images/icons/applets/uploadallowedmimetypes.png');
    94     $this->addAdminNode('adm_cat_general',    'adm_page_file_types',     'UploadAllowedMimeTypes', scriptPath . '/images/icons/applets/uploadallowedmimetypes.png');
   568     {
   578     {
   569       // echo '<b>Warning:</b> pathManager::create_namespace: Namespace ID "'.$prefix.'" is already taken<br />';
   579       // echo '<b>Warning:</b> pathManager::create_namespace: Namespace ID "'.$prefix.'" is already taken<br />';
   570       return false;
   580       return false;
   571     }
   581     }
   572     $this->nslist[$id] = $prefix;
   582     $this->nslist[$id] = $prefix;
       
   583   }
       
   584   
       
   585   /**
       
   586    * Registers a handler to manually process a namespace instead of the default PageProcessor behavior.
       
   587    * The first and only parameter passed to the processing function will be the PageProcessor instance.
       
   588    * @param string Namespace to process
       
   589    * @param mixed Function address. Either a function name or an array of the form array(0 => mixed (string:class name or object), 1 => string:method)
       
   590    */
       
   591   
       
   592   function register_namespace_processor($namespace, $function)
       
   593   {
       
   594     if ( isset($this->namespace_processors[$namespace]) )
       
   595     {
       
   596       $processorname = ( is_string($this->namespace_processors[$namespace]) ) ?
       
   597         $this->namespace_processors[$namespace] :
       
   598         ( is_object($this->namespace_processors[$namespace][0]) ? get_class($this->namespace_processors[$namespace][0]) : $this->namespace_processors[$namespace][0] ) . '::' .
       
   599           $this->namespace_processors[$namespace][1];
       
   600           
       
   601       trigger_error("Namespace \"$namespace\" is already being processed by $processorname - replacing caller", E_USER_WARNING);
       
   602     }
       
   603     if ( !is_string($function) )
       
   604     {
       
   605       if ( !is_array($function) )
       
   606         return false;
       
   607       if ( count($function) != 2 )
       
   608         return false;
       
   609       if ( !is_string($function[0]) && !is_object($function[0]) )
       
   610         return false;
       
   611       if ( !is_string($function[1]) )
       
   612         return false;
       
   613     }
       
   614     
       
   615     // security: don't allow Special or Admin namespaces to be overridden
       
   616     if ( $namespace == 'Special' || $namespace == 'Admin' )
       
   617     {
       
   618       trigger_error("Security manager denied attempt to override processor for $namespace", E_USER_ERROR);
       
   619     }
       
   620     
       
   621     $this->namespace_processors[$namespace] = $function;
       
   622   }
       
   623   
       
   624   /**
       
   625    * Returns a namespace processor if one exists, otherwise returns false.
       
   626    * @param string Namespace
       
   627    * @return mixed
       
   628    */
       
   629   
       
   630   function get_namespace_processor($namespace)
       
   631   {
       
   632     return ( isset($this->namespace_processors[$namespace]) ) ? $this->namespace_processors[$namespace] : false;
   573   }
   633   }
   574   
   634   
   575   /**
   635   /**
   576    * Fetches the page texts for searching
   636    * Fetches the page texts for searching
   577    */
   637    */
   827       return 'E: Can\'t find page metadata';
   887       return 'E: Can\'t find page metadata';
   828     }
   888     }
   829     $row = $db->fetchrow();
   889     $row = $db->fetchrow();
   830     $db->free_result();
   890     $db->free_result();
   831     $search = new Searcher();
   891     $search = new Searcher();
   832     $search->buildIndex(Array("ns={$namespace};pid={$page_id}"=>$row['page_text'] . ' ' . $this->pages[$idstring]['name']));
   892     
       
   893     // if the page shouldn't be indexed, send a blank set of strings to the indexing engine
       
   894     if ( $this->pages[$idstring]['visible'] == 0 )
       
   895     {
       
   896       $search->buildIndex(Array("ns={$namespace};pid={$page_id}"=>''));
       
   897     }
       
   898     else
       
   899     {
       
   900       $search->buildIndex(Array("ns={$namespace};pid={$page_id}"=>$row['page_text'] . ' ' . $this->pages[$idstring]['name']));
       
   901     }
       
   902     
   833     $new_index = $search->index;
   903     $new_index = $search->index;
   834     
   904     
   835     if ( ENANO_DBLAYER == 'MYSQL' )
   905     if ( ENANO_DBLAYER == 'MYSQL' )
   836     {
   906     {
   837       $keys = array_keys($search->index);
   907       $keys = array_keys($search->index);