includes/paths.php
changeset 377 bb3e6c3bd4f4
parent 372 5bd429428101
child 380 73444271fd1c
equal deleted inserted replaced
376:66732bd4532c 377:bb3e6c3bd4f4
    70     $session->register_acl_type('edit_cat',               AUTH_WIKIMODE, 'perm_edit_cat',               Array('read'),                                            'Article|User|Project|Template|File|Help|System|Category');
    70     $session->register_acl_type('edit_cat',               AUTH_WIKIMODE, 'perm_edit_cat',               Array('read'),                                            'Article|User|Project|Template|File|Help|System|Category');
    71     $session->register_acl_type('even_when_protected',    AUTH_DISALLOW, 'perm_even_when_protected',    Array('edit_page', 'rename', 'mod_comments', 'edit_cat'), 'Article|User|Project|Template|File|Help|System|Category');
    71     $session->register_acl_type('even_when_protected',    AUTH_DISALLOW, 'perm_even_when_protected',    Array('edit_page', 'rename', 'mod_comments', 'edit_cat'), 'Article|User|Project|Template|File|Help|System|Category');
    72     $session->register_acl_type('upload_files',           AUTH_DISALLOW, 'perm_upload_files',           Array('create_page'),                                     'Article|User|Project|Template|File|Help|System|Category|Special');
    72     $session->register_acl_type('upload_files',           AUTH_DISALLOW, 'perm_upload_files',           Array('create_page'),                                     'Article|User|Project|Template|File|Help|System|Category|Special');
    73     $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');
    73     $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');
    74     $session->register_acl_type('create_page',            AUTH_WIKIMODE, 'perm_create_page',            Array(),                                                  'Article|User|Project|Template|File|Help|System|Category|Special');
    74     $session->register_acl_type('create_page',            AUTH_WIKIMODE, 'perm_create_page',            Array(),                                                  'Article|User|Project|Template|File|Help|System|Category|Special');
    75     $session->register_acl_type('php_in_pages',           AUTH_DISALLOW, 'perm_php_in_pages',           Array('edit_page'),                                       'Article|User|Project|Template|File|Help|System|Category|Admin');
    75     $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');
       
    76     $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');
    76     $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'));
    77     $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'));
    77     
    78     
    78     // DO NOT add new admin pages here! Use a plugin to call $paths->addAdminNode();
    79     // DO NOT add new admin pages here! Use a plugin to call $paths->addAdminNode();
    79     $this->addAdminNode('adm_cat_general',    'adm_page_general_config', 'GeneralConfig');
    80     $this->addAdminNode('adm_cat_general',    'adm_page_general_config', 'GeneralConfig');
    80     $this->addAdminNode('adm_cat_general',    'adm_page_file_uploads',   'UploadConfig');
    81     $this->addAdminNode('adm_cat_general',    'adm_page_file_uploads',   'UploadConfig');
   100     }
   101     }
   101     
   102     
   102     $this->wiki_mode = (int)getConfig('wiki_mode')=='1';
   103     $this->wiki_mode = (int)getConfig('wiki_mode')=='1';
   103     $this->template_cache = Array();
   104     $this->template_cache = Array();
   104   }
   105   }
       
   106   function parse_url($sanitize = true)
       
   107   {
       
   108     $title = '';
       
   109     if( isset($_GET['title']) )
       
   110     {
       
   111       $title = $_GET['title'];
       
   112     }
       
   113     elseif( isset($_SERVER['PATH_INFO']) )
       
   114     {
       
   115       $title = substr($_SERVER['PATH_INFO'], ( strpos($_SERVER['PATH_INFO'], '/') ) + 1 );
       
   116     }
       
   117     else
       
   118     {
       
   119       // This method really isn't supported because apache has a habit of passing dots as underscores, thus corrupting the request
       
   120       // If you really want to try it, the URI format is yoursite.com/?/Page_title
       
   121       if ( count($_GET) > 0 )
       
   122       {
       
   123         list($getkey) = array_keys($_GET);
       
   124         if ( substr($getkey, 0, 1) == '/' )
       
   125         {
       
   126           $title = substr($getkey, 1);
       
   127         }
       
   128       }
       
   129     }
       
   130     return ( $sanitize ) ? sanitize_page_id($title) : $title;
       
   131   }
   105   function init()
   132   function init()
   106   {
   133   {
   107     global $db, $session, $paths, $template, $plugins; // Common objects
   134     global $db, $session, $paths, $template, $plugins; // Common objects
   108     
   135     
   109     $code = $plugins->setHook('paths_init_before');
   136     $code = $plugins->setHook('paths_init_before');
   146       
   173       
   147     }
   174     }
   148     $db->free_result();
   175     $db->free_result();
   149     if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') )
   176     if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') )
   150     {
   177     {
   151       if( isset($_GET['title']) )
   178       $title = $this->parse_url(false);
   152       {
   179       if ( empty($title) )
   153         if ( $_GET['title'] == '' && getConfig('main_page') != '' )
   180       {
   154         {
   181         $this->main_page();
   155           $this->main_page();
   182       }
   156         }
   183       if ( strstr($title, ' ') || strstr($title, '+') || strstr($title, '%20') )
   157         if(strstr($_GET['title'], ' '))
   184       {
   158         {
   185         $title = sanitize_page_id($title);
   159           $loc = urldecode(rawurldecode($_SERVER['REQUEST_URI']));
   186         redirect(makeUrl($title), '', '', 0);
   160           $loc = str_replace(' ', '_', $loc);
   187       }
   161           $loc = str_replace('+', '_', $loc);
   188       $title = sanitize_page_id($title);
   162           $loc = str_replace('%20', '_', $loc);
   189       // We've got the title, pull the namespace from it
   163           redirect($loc, 'Redirecting...', 'Space detected in the URL, please wait whilst you are redirected', 0);
   190       $namespace = 'Article';
   164           exit;
   191       $page_id = $title;
   165         }
   192       foreach ( $this->nslist as $ns => $prefix )
   166         $url_namespace_special = substr($_GET['title'], 0, strlen($this->nslist['Special']) );
   193       {
   167         $url_namespace_template = substr($_GET['title'], 0, strlen($this->nslist['Template']) );
   194         $prefix_len = strlen($prefix);
   168         if($url_namespace_special == $this->nslist['Special'] || $url_namespace_template == $this->nslist['Template'] )
   195         if ( substr($title, 0, $prefix_len) == $prefix )
   169         {
   196         {
   170           $ex = explode('/', $_GET['title']);
   197           $page_id = substr($title, $prefix_len);
   171           $this->page = $ex[0];
   198           $namespace = $ns;
   172         }
   199         }
   173         else
   200       }
   174         {
   201       $this->namespace = $namespace;
   175           $this->page = $_GET['title'];
   202       $this->fullpage = $title;
   176         }
   203       if ( $namespace == 'Special' || $namespace == 'Admin' )
   177         $this->fullpage = $_GET['title'];
   204       {
   178       }
   205         list($page_id) = explode('/', $page_id);
   179       elseif( isset($_SERVER['PATH_INFO']) )
   206       }
   180       {
   207       $this->page = $this->nslist[$namespace] . $page_id;
   181         $pi = explode('/', $_SERVER['PATH_INFO']);
   208       $this->page_id = $page_id;
   182         
   209       // die("All done setting parameters. What we've got:<br/>namespace: $namespace<br/>fullpage: $this->fullpage<br/>page: $this->page<br/>page_id: $this->page_id");
   183         if( !isset($pi[1]) || (isset($pi[1]) && $pi[1] == '' && getConfig('main_page') != '') )
       
   184         {
       
   185           $this->main_page();
       
   186         }
       
   187         if( strstr($pi[1], ' ') )
       
   188         {
       
   189           $loc = str_replace(' ', '_', urldecode(rawurldecode($_SERVER['REQUEST_URI'])));
       
   190           $loc = str_replace('+', '_', $loc);
       
   191           $loc = str_replace('%20', '_', $loc);
       
   192           redirect($loc, 'Redirecting...', 'Please wait whilst you are redirected', 3);
       
   193           exit;
       
   194         }
       
   195         unset($pi[0]);
       
   196         if( substr($pi[1], 0, strlen($this->nslist['Special'])) == $this->nslist['Special'] || substr($pi[1], 0, strlen($this->nslist['Template'])) == $this->nslist['Template'] )
       
   197         {
       
   198           $pi2 = $pi[1];
       
   199         }
       
   200         else
       
   201         {
       
   202           $pi2 = implode('/', $pi);
       
   203         }
       
   204         $this->page = $pi2;
       
   205         $this->fullpage = implode('/', $pi);
       
   206       }
       
   207       else
       
   208       {
       
   209         $k = array_keys($_GET);
       
   210         foreach($k as $c)
       
   211         {
       
   212           if(substr($c, 0, 1) == '/')
       
   213           {
       
   214             $this->page = substr($c, 1, strlen($c));
       
   215             
       
   216             // Bugfix for apache somehow passing dots as underscores
       
   217             global $mime_types;
       
   218             
       
   219             $exts = array_keys($mime_types);
       
   220             $exts = '(' . implode('|', $exts) . ')';
       
   221             
       
   222             if ( preg_match( '#_'.$exts.'#i', $this->page ) )
       
   223             {
       
   224               $this->page = preg_replace( '#_'.$exts.'#i', '.\\1', $this->page );
       
   225             }
       
   226             
       
   227             $this->fullpage = $this->page;
       
   228             
       
   229             if(substr($this->page, 0, strlen($this->nslist['Special']))==$this->nslist['Special'] || substr($this->page, 0, strlen($this->nslist['Template']))==$this->nslist['Template'])
       
   230             {
       
   231               $ex = explode('/', $this->page);
       
   232               $this->page = $ex[0];
       
   233             }
       
   234             if(strstr($this->page, ' '))
       
   235             {
       
   236               $loc = str_replace(' ', '_', urldecode(rawurldecode($_SERVER['REQUEST_URI'])));
       
   237               $loc = str_replace('+', '_', $loc);
       
   238               $loc = str_replace('%20', '_', $loc);
       
   239               redirect($loc, 'Redirecting...', 'Space in the URL detected, please wait whilst you are redirected', 0);
       
   240               exit;
       
   241             }
       
   242             break;
       
   243           }
       
   244         }
       
   245         if(!$this->page && !($this->page == '' && getConfig('main_page') == ''))
       
   246         {
       
   247           $this->main_page();
       
   248         }
       
   249       }
       
   250     }
   210     }
   251     else
   211     else
   252     {
   212     {
   253       // Starting up Enano with the API from a page that wants to do its own thing. Generate
   213       // Starting up Enano with the API from a page that wants to do its own thing. Generate
   254       // metadata for an anonymous page and avoid redirection at all costs.
   214       // metadata for an anonymous page and avoid redirection at all costs.
   467     
   427     
   468     return $message;
   428     return $message;
   469   }
   429   }
   470   function get_pageid_from_url()
   430   function get_pageid_from_url()
   471   {
   431   {
   472     if(isset($_GET['title']))
   432     return $this->parse_url();
   473     {
       
   474       if( $_GET['title'] == '' && getConfig('main_page') != '' )
       
   475       {
       
   476         $this->main_page();
       
   477       }
       
   478       if(strstr($_GET['title'], ' '))
       
   479       {
       
   480         $loc = urldecode(rawurldecode($_SERVER['REQUEST_URI']));
       
   481         $loc = str_replace(' ', '_', $loc);
       
   482         $loc = str_replace('+', '_', $loc);
       
   483         header('Location: '.$loc);
       
   484         exit;
       
   485       }
       
   486       $ret = $_GET['title'];
       
   487       if ( substr($ret, 0, strlen($this->nslist['Special'])) === $this->nslist['Special'] ||
       
   488            substr($ret, 0, strlen($this->nslist['Admin'])) === $this->nslist['Admin'] )
       
   489       {
       
   490         list($ret) = explode('/', $ret);
       
   491       }
       
   492     }
       
   493     elseif(isset($_SERVER['PATH_INFO']))
       
   494     {
       
   495       $pi = explode('/', $_SERVER['PATH_INFO']);
       
   496       
       
   497       if(!isset($pi[1]) || (isset($pi[1]) && $pi[1] == ''))
       
   498       {
       
   499         return false;
       
   500       }
       
   501       
       
   502       if(strstr($pi[1], ' '))
       
   503       {
       
   504         $loc = urldecode(rawurldecode($_SERVER['REQUEST_URI']));
       
   505         $loc = str_replace(' ', '_', $loc);
       
   506         $loc = str_replace('+', '_', $loc);
       
   507         header('Location: '.$loc);
       
   508         exit;
       
   509       }
       
   510       if( !( substr($pi[1], 0, strlen($this->nslist['Special'])) == $this->nslist['Special'] ) )
       
   511       {
       
   512         unset($pi[0]);
       
   513         $pi[1] = implode('/', $pi);
       
   514       }
       
   515       $ret = $pi[1];
       
   516     }
       
   517     else
       
   518     {
       
   519       $k = array_keys($_GET);
       
   520       foreach($k as $c)
       
   521       {
       
   522         if(substr($c, 0, 1) == '/')
       
   523         {
       
   524           $ret = substr($c, 1, strlen($c));
       
   525           if(substr($ret, 0, strlen($this->nslist['Special'])) == $this->nslist['Special'] ||
       
   526              substr($ret, 0, strlen($this->nslist['Admin'])) == $this->nslist['Admin'])
       
   527           {
       
   528             $ret = explode('/', $ret);
       
   529             $ret = $ret[0];
       
   530           }
       
   531           break;
       
   532         }
       
   533       }
       
   534     }
       
   535     
       
   536     return ( isset($ret) ) ? $ret : false;
       
   537   }
   433   }
   538   // Parses a (very carefully formed) array into Javascript code compatible with the Tigra Tree Menu used in the admin menu
   434   // Parses a (very carefully formed) array into Javascript code compatible with the Tigra Tree Menu used in the admin menu
   539   function parseAdminTree() 
   435   function parseAdminTree() 
   540   {
   436   {
   541     global $lang;
   437     global $lang;
   578         'pageid'=>$url
   474         'pageid'=>$url
   579       );
   475       );
   580   }
   476   }
   581   function getParam($id = 0)
   477   function getParam($id = 0)
   582   {
   478   {
   583     // using !empty here is a bugfix for IIS 5.x on Windows 2000 Server
   479     $title = $this->parse_url(false);
   584     // It may affect other IIS versions as well
   480     $regex = '/^' . str_replace('/', '\\/', preg_quote($this->nslist[$this->namespace])) . '\\/?/';
   585     if(isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO']))
   481     $title = preg_replace($regex, '', $title);
   586     {
   482     $title = explode('/', $title);
   587       $pi = explode('/', $_SERVER['PATH_INFO']);
   483     $id = $id + 1;
   588       $id = $id + 2;
   484     return ( isset($title[$id]) ) ? $title[$id] : false;
   589       return isset($pi[$id]) ? $pi[$id] : false;
       
   590     }
       
   591     else if( isset($_GET['title']) )
       
   592     {
       
   593       $pi = explode('/', $_GET['title']);
       
   594       $id = $id + 1;
       
   595       return isset($pi[$id]) ? $pi[$id] : false;
       
   596     }
       
   597     else
       
   598     {
       
   599       $k = array_keys($_GET);
       
   600       foreach($k as $c)
       
   601       {
       
   602         if(substr($c, 0, 1) == '/')
       
   603         {
       
   604           // Bugfix for apache somehow passing dots as underscores
       
   605           global $mime_types;
       
   606           $exts = array_keys($mime_types);
       
   607           $exts = '(' . implode('|', $exts) . ')';
       
   608           if ( preg_match( '#_'.$exts.'#i', $c ) )
       
   609             $c = preg_replace( '#_'.$exts.'#i', '.\\1', $c );
       
   610           
       
   611           $pi = explode('/', $c);
       
   612           $id = $id + 2;
       
   613           return isset($pi[$id]) ? $pi[$id] : false;
       
   614         }
       
   615       }
       
   616       return false;
       
   617     }
       
   618   }
   485   }
   619   
   486   
   620   function getAllParams()
   487   function getAllParams()
   621   {
   488   {
   622     // using !empty here is a bugfix for IIS 5.x on Windows 2000 Server
   489     $title = $this->parse_url(false);
   623     // It may affect other IIS versions as well
   490     $regex = '/^' . str_replace('/', '\\/', preg_quote($this->nslist[$this->namespace])) . '\\/?/';
   624     if(isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO']))
   491     $title = preg_replace($regex, '', $title);
   625     {
   492     $title = explode('/', $title);
   626       $pi = explode('/', $_SERVER['PATH_INFO']);
   493     unset($title[0]);
   627       unset($pi[0], $pi[1]);
   494     return implode('/', $title);
   628       return implode('/', $pi);
       
   629     }
       
   630     else if( isset($_GET['title']) )
       
   631     {
       
   632       $pi = explode('/', $_GET['title']);
       
   633       unset($pi[0]);
       
   634       return implode('/', $pi);
       
   635     }
       
   636     else
       
   637     {
       
   638       $k = array_keys($_GET);
       
   639       foreach($k as $c)
       
   640       {
       
   641         if(substr($c, 0, 1) == '/')
       
   642         {
       
   643           // Bugfix for apache somehow passing dots as underscores
       
   644           global $mime_types;
       
   645           $exts = array_keys($mime_types);
       
   646           $exts = '(' . implode('|', $exts) . ')';
       
   647           if ( preg_match( '#_'.$exts.'#i', $c ) )
       
   648             $c = preg_replace( '#_'.$exts.'#i', '.\\1', $c );
       
   649           
       
   650           $pi = explode('/', $c);
       
   651           unset($pi[0], $pi[1]);
       
   652           return implode('/', $pi);
       
   653         }
       
   654       }
       
   655       return false;
       
   656     }
       
   657   }
   495   }
   658   
   496   
   659   /**
   497   /**
   660    * Creates a new namespace in memory
   498    * Creates a new namespace in memory
   661    * @param string $id the namespace ID
   499    * @param string $id the namespace ID