includes/pageprocess.php
changeset 22 d0314575e2f0
parent 21 663fcf528726
child 24 9ecc94c4c7f5
equal deleted inserted replaced
21:663fcf528726 22:d0314575e2f0
   462     else
   462     else
   463     {
   463     {
   464       $page_name = ( isset($paths->pages[$this->page_id]) ) ? $paths->pages[$this->page_id]['name'] : $this->page_id;
   464       $page_name = ( isset($paths->pages[$this->page_id]) ) ? $paths->pages[$this->page_id]['name'] : $this->page_id;
   465     }
   465     }
   466     
   466     
   467     if ( $page_name == str_replace('_', ' ', $this->page_id) || $page_name == $paths->nslist['User'] . str_replace('_', ' ', $this->page_id) )
   467     $target_username = strtr($page_name, 
   468     {
   468       Array(
   469       $target_username = strtr($page_name, 
   469         '_' => ' ',
   470         Array(
   470         '<' => '&lt;',
   471           '_' => ' ',
   471         '>' => '&gt;'
   472           '<' => '&lt;',
   472         ));
   473           '>' => '&gt;'
   473     
   474           ));
   474     $target_username = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $target_username);
   475       $target_username = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $target_username);
   475     
       
   476     if ( ( $page_name == str_replace('_', ' ', $this->page_id) || $page_name == $paths->nslist['User'] . str_replace('_', ' ', $this->page_id) ) || !$this->page_exists )
       
   477     {
   476       $page_name = "$target_username's user page";
   478       $page_name = "$target_username's user page";
   477     }
   479     }
   478     else
   480     else
   479     {
   481     {
   480       // User has a custom title for their userpage
   482       // User has a custom title for their userpage
   481       $page_name = $paths->pages[ $paths->nslist[$this->namespace] . $this->page_id ]['name'];
   483       $page_name = $paths->pages[ $paths->nslist[$this->namespace] . $this->page_id ]['name'];
   482     }
   484     }
   483     
   485     
   484     $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($page_name);
   486     $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($page_name);
   485     
   487     
       
   488     $q = $db->sql_query('SELECT u.username, u.user_id AS authoritative_uid, u.real_name, u.email, u.reg_time, x.*, COUNT(c.comment_id) AS n_comments
       
   489                            FROM '.table_prefix.'users u
       
   490                            LEFT JOIN '.table_prefix.'users_extra AS x
       
   491                              ON ( u.user_id = x.user_id OR x.user_id IS NULL ) 
       
   492                            LEFT JOIN '.table_prefix.'comments AS c
       
   493                              ON ( ( c.user_id=u.user_id AND c.approved=1 ) OR ( c.comment_id IS NULL AND c.approved IS NULL ) )
       
   494                            WHERE u.username=\'' . $db->escape($target_username) . '\'
       
   495                            GROUP BY u.user_id;');
       
   496     if ( !$q )
       
   497       $db->_die();
       
   498     
       
   499     $user_exists = true;
       
   500     
       
   501     if ( $db->numrows() < 1 )
       
   502     {
       
   503       $user_exists = false;
       
   504     }
       
   505     else
       
   506     {
       
   507       $userdata = $db->fetchrow();
       
   508       if ( $userdata['authoritative_uid'] == 1 )
       
   509       {
       
   510         // Hide data for anonymous user
       
   511         $user_exists = false;
       
   512         unset($userdata);
       
   513       }
       
   514     }
       
   515     
   486     $this->header();
   516     $this->header();
   487     
   517     
   488     // if ( $send_headers )
   518     // if ( $send_headers )
   489     // {
   519     // {
   490       display_page_headers();
   520     //  display_page_headers();
   491     // }
   521     // }
   492    
   522    
   493     // Start left sidebar: basic user info, latest comments
   523     // Start left sidebar: basic user info, latest comments
   494     
   524     
       
   525     if ( $user_exists ):
       
   526     
   495     echo '<table border="0" cellspacing="4" cellpadding="0" style="width: 100%;">';
   527     echo '<table border="0" cellspacing="4" cellpadding="0" style="width: 100%;">';
   496     echo '<tr><td style="width: 150px;">';
   528     echo '<tr><td style="width: 150px;" valign="top">';
   497     
   529     
   498     echo '<div class="tblholder">
   530     echo '<div class="tblholder">
   499             <table border="0" cellspacing="1" cellpadding="4">';
   531             <table border="0" cellspacing="1" cellpadding="4">';
   500     
   532     
       
   533     //
   501     // Main part of sidebar
   534     // Main part of sidebar
       
   535     //
       
   536     
       
   537     // Basic user info
       
   538     
       
   539     echo '<tr><th class="subhead">All about ' . htmlspecialchars($target_username) . '</th></tr>';
       
   540     echo '<tr><td class="row3">Joined: ' . date('F d, Y h:i a', $userdata['reg_time']) . '</td></tr>';
       
   541     echo '<tr><td class="row1">Total comments: ' . $userdata['n_comments'] . '</td></tr>';
       
   542     
       
   543     if ( !empty($userdata['real_name']) )
       
   544     {
       
   545       echo '<tr><td class="row3">Real name: ' . htmlspecialchars($userdata['real_name']) . '</td></tr>';
       
   546     }
       
   547     
       
   548     // Comments
       
   549     
       
   550     echo '<tr><th class="subhead">' . htmlspecialchars($target_username) . '\'s latest comments</th></tr>';
       
   551     $q = $db->sql_query('SELECT page_id, namespace, subject, time FROM '.table_prefix.'comments WHERE name=\'' . $db->escape($target_username) . '\' AND approved=1 ORDER BY time DESC LIMIT 5;');
       
   552     if ( !$q )
       
   553       $db->_die();
       
   554     
       
   555     $comments = Array();
       
   556     $no_comments = false;
       
   557     
       
   558     if ( $row = $db->fetchrow() )
       
   559     {
       
   560       do 
       
   561       {
       
   562         $row['time'] = date('F d, Y', $row['time']);
       
   563         $comments[] = $row;
       
   564       }
       
   565       while ( $row = $db->fetchrow() );
       
   566     }
       
   567     else
       
   568     {
       
   569       $no_comments = true;
       
   570     }
       
   571     
       
   572     echo '<tr><td class="row3">';
       
   573     echo '<div style="border: 1px solid #000000; padding: 0px; margin: 0; max-height: 200px; clip: rect(0px,auto,auto,0px); overflow: auto; background-color: transparent;" class="tblholder">';
       
   574     
       
   575     echo '<table border="0" cellspacing="1" cellpadding="4">';
       
   576     $class = 'row1';
       
   577     
       
   578     $tpl = '<tr>
       
   579               <td class="{CLASS}">
       
   580                 <a href="{PAGE_LINK}" <!-- BEGINNOT page_exists -->class="wikilink-nonexistent"<!-- END page_exists -->>{PAGE}</a><br />
       
   581                 <small>Posted {DATE}<br /></small>
       
   582                 <b><a href="{COMMENT_LINK}">{SUBJECT}</a></b>
       
   583               </td>
       
   584             </tr>';
       
   585     $parser = $template->makeParserText($tpl);
       
   586     
       
   587     if ( count($comments) > 0 )
       
   588     {
       
   589       foreach ( $comments as $comment )
       
   590       {
       
   591         $c_page_id = $paths->nslist[ $comment['namespace'] ] . sanitize_page_id($comment['page_id']);
       
   592         if ( isset($paths->pages[ $c_page_id ]) )
       
   593         {
       
   594           $parser->assign_bool(array(
       
   595             'page_exists' => true
       
   596             ));
       
   597           $page_title = $paths->pages[ $c_page_id ]['name'];
       
   598         }
       
   599         else
       
   600         {
       
   601           $parser->assign_bool(array(
       
   602             'page_exists' => false
       
   603             ));
       
   604           $page_title = htmlspecialchars(dirtify_page_id($c_page_id));
       
   605         }
       
   606         $parser->assign_vars(array(
       
   607             'CLASS' => $class,
       
   608             'PAGE_LINK' => makeUrlNS($comment['namespace'], sanitize_page_id($comment['page_id'])),
       
   609             'PAGE' => $page_title,
       
   610             'SUBJECT' => $comment['subject'],
       
   611             'DATE' => $comment['time'],
       
   612             'COMMENT_LINK' => makeUrlNS($comment['namespace'], sanitize_page_id($comment['page_id']), 'do=comments', true)
       
   613           ));
       
   614         $class = ( $class == 'row3' ) ? 'row1' : 'row3';
       
   615         echo $parser->run();
       
   616       }
       
   617     }
       
   618     else
       
   619     {
       
   620       echo '<tr><td class="' . $class . '">This user has not posted any comments.</td></tr>';
       
   621     }
       
   622     echo '</table>';
       
   623     
       
   624     echo '</div>';
       
   625     echo '</td></tr>';
   502             
   626             
   503     echo '  </table>
   627     echo '  </table>
   504           </div>';
   628           </div>';
   505     
   629     
   506     echo '</td><td>';
   630     echo '</td><td valign="top" style="padding: 0 10px;">';
       
   631     
       
   632     else:
       
   633     
       
   634     // Nothing for now
       
   635     
       
   636     endif;
   507     
   637     
   508     // User's own content
   638     // User's own content
   509     
   639     
   510     $send_headers = $this->send_headers;
   640     $send_headers = $this->send_headers;
   511     $this->send_headers = false;
   641     $this->send_headers = false;
   514     {
   644     {
   515       $this->render();
   645       $this->render();
   516     }
   646     }
   517     else
   647     else
   518     {
   648     {
   519       $this->err_page_not_existent();
   649       $this->err_page_not_existent(true);
   520     }
   650     }
   521     
   651     
   522     // Right sidebar
   652     // Right sidebar
   523     
   653     
   524     echo '</td><td style="width: 150px;">';
   654     if ( $user_exists ):
       
   655     
       
   656     echo '</td><td style="width: 150px;" valign="top">';
   525     
   657     
   526     echo '<div class="tblholder">
   658     echo '<div class="tblholder">
   527             <table border="0" cellspacing="1" cellpadding="4">';
   659             <table border="0" cellspacing="1" cellpadding="4">';
   528     
   660     
       
   661     //
   529     // Main part of sidebar
   662     // Main part of sidebar
   530             
   663     //
       
   664     
       
   665     // Contact information
       
   666     
       
   667     echo '<tr><th class="subhead">Get in touch</th></tr>';
       
   668     
       
   669     $class = 'row3';
       
   670     
       
   671     if ( $userdata['email_public'] == 1 )
       
   672     {
       
   673       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
   674       global $email;
       
   675       $email_link = $email->encryptEmail($userdata['email']);
       
   676       echo '<tr><td class="'.$class.'">E-mail address: ' . $email_link . '</td></tr>';
       
   677     }
       
   678     
       
   679     $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
   680     if ( $session->user_logged_in )
       
   681     {
       
   682       echo '<tr><td class="'.$class.'">Send ' . htmlspecialchars($target_username) . ' a <a href="' . makeUrlNS('Special', 'PrivateMessages/Compose/to/' . $this->page_id, false, true) . '">Private Message</a>!</td></tr>';
       
   683     }
       
   684     else
       
   685     {
       
   686       echo '<tr><td class="'.$class.'">You could send ' . htmlspecialchars($target_username) . ' a private message if you were <a href="' . makeUrlNS('Special', 'Login/' . $paths->nslist[$this->namespace] . $this->page_id) . '">logged in</a>.</td></tr>';
       
   687     }
       
   688     
       
   689     if ( !empty($userdata['user_aim']) )
       
   690     {
       
   691       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
   692       echo '<tr><td class="'.$class.'">AIM: ' . htmlspecialchars($userdata['user_aim']) . '</td></tr>';
       
   693     }
       
   694     
       
   695     if ( !empty($userdata['user_yahoo']) )
       
   696     {
       
   697       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
   698       echo '<tr><td class="'.$class.'">Yahoo! IM: ' . htmlspecialchars($userdata['user_yahoo']) . '</td></tr>';
       
   699     }
       
   700     
       
   701     if ( !empty($userdata['user_msn']) )
       
   702     {
       
   703       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
   704       $email_link = $email->encryptEmail($userdata['user_msn']);
       
   705       echo '<tr><td class="'.$class.'">WLM: ' . $email_link . '</td></tr>';
       
   706     }
       
   707     
       
   708     if ( !empty($userdata['user_xmpp']) )
       
   709     {
       
   710       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
   711       $email_link = $email->encryptEmail($userdata['user_xmpp']);
       
   712       echo '<tr><td class="'.$class.'">XMPP/Jabber: ' . $email_link . '</td></tr>';
       
   713     }
       
   714     
       
   715     // Real life
       
   716     
       
   717     echo '<tr><th class="subhead">' . htmlspecialchars($target_username) . ' in real life</th></tr>';
       
   718     
       
   719     if ( !empty($userdata['user_location']) )
       
   720     {
       
   721       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
   722       echo '<tr><td class="'.$class.'">Location: ' . htmlspecialchars($userdata['user_location']) . '</td></tr>';
       
   723     }
       
   724     
       
   725     if ( !empty($userdata['user_job']) )
       
   726     {
       
   727       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
   728       echo '<tr><td class="'.$class.'">Job/occupation: ' . htmlspecialchars($userdata['user_job']) . '</td></tr>';
       
   729     }
       
   730     
       
   731     if ( !empty($userdata['user_hobbies']) )
       
   732     {
       
   733       $class = ( $class == 'row1' ) ? 'row3' : 'row1';
       
   734       echo '<tr><td class="'.$class.'">Enjoys: ' . htmlspecialchars($userdata['user_hobbies']) . '</td></tr>';
       
   735     }
       
   736     
   531     echo '  </table>
   737     echo '  </table>
   532           </div>';
   738           </div>';
   533           
   739           
   534     echo '</tr></table>';
   740     echo '</tr></table>';
   535     
   741     
       
   742     else:
       
   743     
       
   744     echo '<p>Additional information: user "' . htmlspecialchars($target_username) . '" does not exist.</p>';
       
   745     
       
   746     endif;
       
   747     
   536     // if ( $send_headers )
   748     // if ( $send_headers )
   537     // {
   749     // {
   538       display_page_footers();
   750     //  display_page_footers();
   539     // }
   751     // }
   540     
   752     
   541     $this->send_headers = $send_headers;
   753     $this->send_headers = $send_headers;
   542     unset($send_headers);
   754     unset($send_headers);
   543     
   755     
   599   /**
   811   /**
   600    * Tell the user the page doesn't exist, and present them with their options.
   812    * Tell the user the page doesn't exist, and present them with their options.
   601    * @access private
   813    * @access private
   602    */
   814    */
   603    
   815    
   604   function err_page_not_existent()
   816   function err_page_not_existent($userpage = false)
   605   {
   817   {
   606     global $db, $session, $paths, $template, $plugins; // Common objects
   818     global $db, $session, $paths, $template, $plugins; // Common objects
   607     
   819     
   608     $this->header();
   820     $this->header();
   609     header('HTTP/1.1 404 Not Found');
   821     header('HTTP/1.1 404 Not Found');
   610     echo '<h3>There is no page with this title yet.</h3>
   822     if ( $userpage )
   611            <p>You have requested a page that doesn\'t exist yet.';
   823     {
       
   824       echo '<h3>There is no page with this title yet.</h3>
       
   825              <p>This user has not created his or her user page yet.';
       
   826     }
       
   827     else
       
   828     {
       
   829       echo '<h3>There is no page with this title yet.</h3>
       
   830              <p>You have requested a page that doesn\'t exist yet.';
       
   831     }
   612     if ( $session->get_permissions('create_page') )
   832     if ( $session->get_permissions('create_page') )
   613     {
   833     {
   614       echo ' You can <a href="'.makeUrlNS($this->namespace, $this->page_id, 'do=edit', true).'" onclick="ajaxEditor(); return false;">create this page</a>, or return to the <a href="'.makeUrl(getConfig('main_page')).'">homepage</a>.';
   834       echo ' You can <a href="'.makeUrlNS($this->namespace, $this->page_id, 'do=edit', true).'" onclick="ajaxEditor(); return false;">create this page</a>, or return to the <a href="'.makeUrl(getConfig('main_page')).'">homepage</a>.';
   615     }
   835     }
   616     else
   836     else