includes/pageprocess.php
changeset 314 474f8be55943
parent 313 854eecfada20
child 326 ab66d6d1f1f4
equal deleted inserted replaced
313:854eecfada20 314:474f8be55943
   150    */
   150    */
   151   
   151   
   152   function send( $do_stats = false )
   152   function send( $do_stats = false )
   153   {
   153   {
   154     global $db, $session, $paths, $template, $plugins; // Common objects
   154     global $db, $session, $paths, $template, $plugins; // Common objects
       
   155     global $lang;
       
   156     
   155     if ( !$this->perms->get_permissions('read') )
   157     if ( !$this->perms->get_permissions('read') )
   156     {
   158     {
   157       $this->err_access_denied();
   159       $this->err_access_denied();
   158       return false;
   160       return false;
   159     }
   161     }
   185     }
   187     }
   186     if ( $this->namespace == 'Special' || $this->namespace == 'Admin' )
   188     if ( $this->namespace == 'Special' || $this->namespace == 'Admin' )
   187     {
   189     {
   188       if ( !$this->page_exists )
   190       if ( !$this->page_exists )
   189       {
   191       {
   190         redirect( makeUrl(getConfig('main_page')), 'Can\'t find special page', 'The special or administration page you requested does not exist. You will now be transferred to the main page.', 2 );
   192         die_semicritical('Exception in PageProcessor', '<p>Special page not existent but exception not previously caught by path manager.</p>');
   191       }
   193       }
   192       $func_name = "page_{$this->namespace}_{$this->page_id}";
   194       $func_name = "page_{$this->namespace}_{$this->page_id}";
   193       if ( function_exists($func_name) )
   195       if ( function_exists($func_name) )
   194       {
   196       {
   195         return @call_user_func($func_name);
   197         return @call_user_func($func_name);
   196       }
   198       }
   197       else
   199       else
   198       {
   200       {
   199         $title = 'Page backend not found';
   201         $title = $lang->get('page_err_custompage_function_missing_title');
   200         $message = "The administration page you are looking for was properly registered using the page API, but the backend function
   202         $message = $lang->get('page_err_custompage_function_missing_body', array( 'function_name' => $fname ));
   201                     (<tt>$fname</tt>) was not found. If this is a plugin page, then this is almost certainly a bug with the plugin.";
       
   202                     
   203                     
   203         if ( $this->send_headers )
   204         if ( $this->send_headers )
   204         {
   205         {
   205           $template->tpl_strings['PAGE_NAME'] = $title;
   206           $template->tpl_strings['PAGE_NAME'] = $title;
   206           $template->header();
   207           $template->header();
   289           // Redirect page!
   290           // Redirect page!
   290           $page_to = sanitize_page_id($match[1]);
   291           $page_to = sanitize_page_id($match[1]);
   291           $page_id_data = RenderMan::strToPageID($page_to);
   292           $page_id_data = RenderMan::strToPageID($page_to);
   292           if ( count($this->redirect_stack) >= 3 )
   293           if ( count($this->redirect_stack) >= 3 )
   293           {
   294           {
   294             $this->render( (!$strict_no_headers), '<div class="usermessage"><b>The maximum number of internal redirects has been exceeded.</b></div>' );
   295             $this->render( (!$strict_no_headers), '<div class="usermessage"><b>' . $lang->get('page_err_redirects_exceeded') . '</b></div>' );
   295           }
   296           }
   296           else
   297           else
   297           {
   298           {
   298             $result = $this->_handle_redirect($page_id_data[0], $page_id_data[1]);
   299             $result = $this->_handle_redirect($page_id_data[0], $page_id_data[1]);
   299             if ( $result !== true )
   300             if ( $result !== true )
   379    */
   380    */
   380   
   381   
   381   function render($incl_inner_headers = true, $_errormsg = false)
   382   function render($incl_inner_headers = true, $_errormsg = false)
   382   {
   383   {
   383     global $db, $session, $paths, $template, $plugins; // Common objects
   384     global $db, $session, $paths, $template, $plugins; // Common objects
       
   385     global $lang;
   384     
   386     
   385     $text = $this->fetch_text();
   387     $text = $this->fetch_text();
   386     $text = preg_replace('/([\s]*)__NOBREADCRUMBS__([\s]*)/', '', $text);
   388     $text = preg_replace('/([\s]*)__NOBREADCRUMBS__([\s]*)/', '', $text);
   387     $text = preg_replace('/([\s]*)__NOTOC__([\s]*)/', '', $text);
   389     $text = preg_replace('/([\s]*)__NOTOC__([\s]*)/', '', $text);
   388     
   390     
   412                 <tr>
   414                 <tr>
   413                   <td valign="top">
   415                   <td valign="top">
   414                     <img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" />
   416                     <img alt="Cute wet-floor icon" src="'.scriptPath.'/images/redirector.png" />
   415                   </td>
   417                   </td>
   416                   <td valign="top" style="padding-left: 10px;">
   418                   <td valign="top" style="padding-left: 10px;">
   417                     <b>This page is a <i>redirector</i>.</b><br />
   419                     ' . $lang->get('page_msg_this_is_a_redirector', array( 'redirect_target' => $a )) . '
   418                     This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to.<br /><br />
       
   419                     To create a redirect page, make the <i>first characters</i> in the page content <tt>#redirect [[Page_ID]]</tt>. For more information, see the
       
   420                     Enano <a href="http://enanocms.org/Help:Wiki_formatting" onclick="window.open(this.href); return false;">Wiki formatting guide</a>.<br /><br />
       
   421                     This page redirects to ' . $a . '.
       
   422                   </td>
   420                   </td>
   423                 </tr>
   421                 </tr>
   424               </table>
   422               </table>
   425             </div>
   423             </div>
   426             <br />
   424             <br />
   954    */
   952    */
   955   
   953   
   956   function _handle_redirect($page_id, $namespace)
   954   function _handle_redirect($page_id, $namespace)
   957   {
   955   {
   958     global $db, $session, $paths, $template, $plugins; // Common objects
   956     global $db, $session, $paths, $template, $plugins; // Common objects
       
   957     global $lang;
   959     $arr_pid = array($this->page_id, $this->namespace);
   958     $arr_pid = array($this->page_id, $this->namespace);
   960     if ( $namespace == 'Special' || $namespace == 'Admin' )
   959     if ( $namespace == 'Special' || $namespace == 'Admin' )
   961     {
   960     {
   962       return 'This page redirects to a Special or Administration page, which is not allowed.';
   961       return $lang->get('page_err_redirect_to_special');
   963     }
   962     }
   964     if ( in_array($this->redirect_stack, $arr_pid) )
   963     $looped = false;
   965     {
   964     foreach ( $this->redirect_stack as $page )
   966       return 'This page infinitely redirects with another page (or another series of pages), and the infinite redirect was trapped.';
   965     {
       
   966       if ( $page[0] == $arr_pid[0] && $page[1] == $arr_pid[1] )
       
   967       {
       
   968         $looped = true;
       
   969         break;
       
   970       }
       
   971     }
       
   972     if ( $looped )
       
   973     {
       
   974       return $lang->get('page_err_redirect_infinite_loop');
   967     }
   975     }
   968     $page_id_key = $paths->nslist[ $namespace ] . sanitize_page_id($page_id);
   976     $page_id_key = $paths->nslist[ $namespace ] . sanitize_page_id($page_id);
   969     if ( !isset($paths->pages[$page_id_key]) )
   977     if ( !isset($paths->pages[$page_id_key]) )
   970     {
   978     {
   971       return 'This page redirects to another page that doesn\'t exist.';
   979       return $lang->get('page_err_redirect_to_nonexistent');
   972     }
   980     }
   973     $this->redirect_stack[] = $arr_pid;
   981     $this->redirect_stack[] = $arr_pid;
   974     
   982     
   975     
   983     
   976     // Nuke the text cache to avoid infinite loops, gah...
   984     // Nuke the text cache to avoid infinite loops, gah...
   986    */
   994    */
   987   
   995   
   988   function err_access_denied()
   996   function err_access_denied()
   989   {
   997   {
   990     global $db, $session, $paths, $template, $plugins; // Common objects
   998     global $db, $session, $paths, $template, $plugins; // Common objects
       
   999     global $lang;
       
  1000     global $email;
   991     
  1001     
   992     // Log it for crying out loud
  1002     // Log it for crying out loud
   993     $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,author,edit_summary,page_text) VALUES(\'security\', \'illegal_page\', '.time().', \''.date('d M Y h:i a').'\', \''.$db->escape($session->username).'\', \''.$db->escape($_SERVER['REMOTE_ADDR']).'\', \'' . $db->escape(serialize(array($this->page_id, $this->namespace))) . '\')');
  1003     $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,author,edit_summary,page_text) VALUES(\'security\', \'illegal_page\', '.time().', \''.date('d M Y h:i a').'\', \''.$db->escape($session->username).'\', \''.$db->escape($_SERVER['REMOTE_ADDR']).'\', \'' . $db->escape(serialize(array($this->page_id, $this->namespace))) . '\')');
   994     
  1004     
   995     $ob = '';
  1005     $ob = '';
  1020         
  1030         
  1021         $ob .= '<small>(Redirected to ' . $b . ' from ' . $a . ')<br /></small>';
  1031         $ob .= '<small>(Redirected to ' . $b . ' from ' . $a . ')<br /></small>';
  1022       }
  1032       }
  1023     }
  1033     }
  1024     
  1034     
  1025     $ob .= '<div class="error-box"><b>Access to this page is denied.</b><br />This may be because you are not logged in or you have not met certain criteria for viewing this page.</div>';
  1035     $email_link = $email->encryptEmail(getConfig('contact_email'), '', '', $lang->get('page_err_access_denied_siteadmin'));
       
  1036     
       
  1037     $ob .= "<h3>" . $lang->get('page_err_access_denied_title') . "</h3>";
       
  1038     $ob .= "<p>" . $lang->get('page_err_access_denied_body', array('site_administration' => $email_link)) . "</p>";
  1026     
  1039     
  1027     if ( $this->send_headers )
  1040     if ( $this->send_headers )
  1028     {
  1041     {
  1029       $ob .= $template->getFooter();
  1042       $ob .= $template->getFooter();
  1030     }
  1043     }