decir/viewtopic.php
changeset 0 0417a5a0c7be
child 1 6f8b7c6fac02
equal deleted inserted replaced
-1:000000000000 0:0417a5a0c7be
       
     1 <?php
       
     2 /*
       
     3  * Decir
       
     4  * Version 0.1
       
     5  * Copyright (C) 2007 Dan Fuhry
       
     6  * viewtopic.php - Shows individual posts
       
     7  *
       
     8  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
       
     9  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
       
    10  *
       
    11  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
       
    12  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
       
    13  */
       
    14 
       
    15 require('common.php');
       
    16 require('bbcode.php');
       
    17 
       
    18 global $whos_online;
       
    19 
       
    20 $template->header();
       
    21 
       
    22 if ( strtolower($paths->getParam(0)) == 'post' || isset($_GET['pid']) )
       
    23 {
       
    24   $pid = ( $n = $paths->getParam(1) ) ? $n : ( ( isset($_GET['pid']) ) ? $_GET['pid'] : 0 );
       
    25   $pid = intval($pid);
       
    26   
       
    27   if(empty($pid))
       
    28   {
       
    29     echo '<p>Invalid topic ID</p>';
       
    30     $template->footer();
       
    31     return;
       
    32   }
       
    33   
       
    34   $q = $db->sql_query('SELECT topic_id FROM '.table_prefix.'decir_posts WHERE post_id='.$pid.';');
       
    35   if ( !$q )
       
    36     $db->_die();
       
    37   
       
    38   $row = $db->fetchrow();
       
    39 }
       
    40 else
       
    41 {
       
    42   $tid = ( $n = $paths->getParam(1) ) ? $n : ( ( isset($_GET['tid']) ) ? $_GET['tid'] : 0 );
       
    43   $tid = intval($tid);
       
    44   
       
    45   if(empty($tid))
       
    46   {
       
    47     echo '<p>Invalid topic ID</p>';
       
    48     $template->footer();
       
    49     return;
       
    50   }
       
    51 }
       
    52 
       
    53 $q = $db->sql_query('SELECT forum_id,topic_id FROM '.table_prefix.'decir_topics WHERE topic_id='.$tid.';');
       
    54 
       
    55 if ( !$q )
       
    56   $db->_die();
       
    57 
       
    58 $topic_exists = true;
       
    59 
       
    60 if ( $db->numrows() > 0 )
       
    61 {
       
    62   $row = $db->fetchrow();
       
    63   $forum_id = $row['forum_id'];
       
    64   $topic_id = $row['topic_id'];
       
    65   $topic_exists = true;
       
    66 }
       
    67 else
       
    68 {
       
    69   $topic_exists = false;
       
    70 }
       
    71 
       
    72 $post_template = <<<TPLCODE
       
    73 <a name="{POST_ID}" id="{POST_ID}"></a>
       
    74 <div class="post tblholder">
       
    75   <table border="0" cellspacing="1" cellpadding="4" style="width: 100%;">
       
    76     <tr>
       
    77       <th colspan="2" style="text-align: left;">Posted: {TIMESTAMP}</th>
       
    78     </tr>
       
    79     <tr>
       
    80       <td class="row3" valign="top">
       
    81         {POST_TEXT}
       
    82       </td>
       
    83       <td class="row1" style="width: 120px;" valign="top">
       
    84         <div class="menu">
       
    85           {USER_LINK}
       
    86           <ul>
       
    87             <li><a>View profile</a></li>
       
    88             <li><a>Visit homepage</a></li>
       
    89             <li><a href="{QUOTE_LINK}">Quote this post</a></li>
       
    90             <li><a>Vote to ban this user</a></li>
       
    91             <li><a>Send private message</a></li>
       
    92             <li><a>View all messages posted by {USERNAME}</a></li>
       
    93           </ul>
       
    94         </div>
       
    95         <span class="menuclear"></span>
       
    96         {USER_TITLE}<br />
       
    97         <br />
       
    98         Joined: {REG_TIME}
       
    99         <!-- BEGIN whos_online_support -->
       
   100           <br />
       
   101           <!-- BEGIN user_is_online -->
       
   102           <span style="color: #007900;"><b>Online</b></span>
       
   103           <!-- BEGINELSE user_is_online -->
       
   104           <span style="color: #666666;">Offline</span>
       
   105           <!-- END user_is_online -->
       
   106         <!-- END whos_online_support -->
       
   107       </td>
       
   108     </tr>
       
   109   </table>
       
   110 </div>
       
   111 TPLCODE;
       
   112 
       
   113 $sql = 'SELECT p.post_id,p.poster_name,p.poster_id,u.username,p.timestamp,u.user_level,u.reg_time,t.post_text,t.bbcode_uid FROM '.table_prefix.'decir_posts AS p
       
   114           LEFT JOIN '.table_prefix.'users AS u
       
   115             ON u.user_id=poster_id
       
   116           LEFT JOIN '.table_prefix.'decir_posts_text AS t
       
   117             ON p.post_id=t.post_id
       
   118           WHERE p.topic_id='.$tid.'
       
   119           ORDER BY p.timestamp ASC;';
       
   120 
       
   121 $q = $db->sql_query($sql);
       
   122 if ( !$q )
       
   123   $db->_die();
       
   124 
       
   125 if ( $db->numrows() < 1 )
       
   126 {
       
   127   die_friendly('Error', '<p>The topic you requested does not exist.</p>');
       
   128 }
       
   129 
       
   130 $parser = $template->makeParserText($post_template);
       
   131 
       
   132 while ( $row = $db->fetchrow() )
       
   133 {
       
   134   $poster_name = ( $row['poster_id'] == 1 ) ? $row['poster_name'] : $row['username'];
       
   135   $datetime = date('F d, Y h:i a', $row['timestamp']);
       
   136   $post_text = render_bbcode($row['post_text'], $row['bbcode_uid']);
       
   137   $regtime = date('F Y', $row['reg_time']);
       
   138   
       
   139   $user_color = '#0000AA';
       
   140   switch ( $row['user_level'] )
       
   141   {
       
   142     case USER_LEVEL_ADMIN: $user_color = '#AA0000'; break;
       
   143     case USER_LEVEL_MOD:   $user_color = '#00AA00'; break;
       
   144   }
       
   145   if ( $row['poster_id'] > 1 )
       
   146   {
       
   147     $user_link = "<a style='color: $user_color; background-color: transparent; display: inline; padding: 0;' href='".makeUrlNS('User', str_replace(' ', '_', $poster_name))."'><big>$poster_name</big></a>";
       
   148   }
       
   149   else
       
   150   {
       
   151     $user_link = '<big>'.$poster_name.'</big>';
       
   152   }
       
   153   $quote_link = makeUrlNS('Special', 'Forum/New/Quote/' . $row['post_id'], false, true);
       
   154   $user_title = 'Anonymous user';
       
   155   switch ( $row['user_level'] )
       
   156   {
       
   157     case USER_LEVEL_ADMIN: $user_title = 'Administrator'; break;
       
   158     case USER_LEVEL_MOD:   $user_title = 'Moderator'; break;
       
   159     case USER_LEVEL_MEMBER:$user_title = 'Member'; break;
       
   160     case USER_LEVEL_GUEST: $user_title = 'Guest'; break;
       
   161   }
       
   162   $parser->assign_vars(Array(
       
   163       'POST_ID' => (string)$row['post_id'],
       
   164       'USERNAME' => $poster_name,
       
   165       'USER_LINK' => $user_link,
       
   166       'REG_TIME' => $regtime,
       
   167       'TIMESTAMP' => $datetime,
       
   168       'POST_TEXT' => $post_text,
       
   169       'USER_TITLE' => $user_title,
       
   170       'QUOTE_LINK' => $quote_link
       
   171     ));
       
   172   // Decir can integrate with the Who's Online plugin
       
   173   $who_support = $plugins->loaded('WhosOnline');
       
   174   $user_online = false;
       
   175   if ( $who_support && in_array($row['username'], $whos_online['users']) )
       
   176   {
       
   177     $user_online = true;
       
   178   }
       
   179   elseif ( $row['poster_id'] < 2 )
       
   180   {
       
   181     $who_support = false;
       
   182   }
       
   183   $parser->assign_bool(Array(
       
   184       'whos_online_support' => $who_support,
       
   185       'user_is_online' => $user_online
       
   186     ));
       
   187   echo $parser->run();
       
   188 }
       
   189 
       
   190 $db->free_result();
       
   191 
       
   192 if ( $topic_exists )
       
   193 {
       
   194   $can_post_replies = false;
       
   195   $can_post_topics  = false;
       
   196   
       
   197   $forum_perms = $session->fetch_page_acl('DecirForum', $forum_id);
       
   198   $topic_perms = $session->fetch_page_acl('DecirTopic', $topic_id);
       
   199   
       
   200   if ( $forum_perms->get_permissions('decir_post') )
       
   201     $can_post_topics = true;
       
   202   
       
   203   if ( $topic_perms->get_permissions('decir_reply') )
       
   204     $can_post_replies = true;
       
   205   
       
   206   echo '<p>';
       
   207   if ( $can_post_topics )
       
   208   {
       
   209     echo '<a href="' . makeUrlNS('Special', 'Forum/New/Topic/' . $forum_id) . '">Post new topic</a>';
       
   210   }
       
   211   if ( $can_post_topics && $can_post_replies )
       
   212   {
       
   213     echo '&nbsp;&nbsp;|&nbsp;&nbsp;';
       
   214   }
       
   215   if ( $can_post_replies )
       
   216   {
       
   217     echo '<a href="' . makeUrlNS('Special', 'Forum/New/Reply/' . $topic_id) . '">Add reply</a>';
       
   218   }
       
   219   echo '</p>';
       
   220 }
       
   221 
       
   222 $template->footer();
       
   223