While loop problem

Discuss the development of future releases of phpBB (phpBB 3.x minor releases) and MODing/Coding related questions.
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

While loop problem

Post by Obsidian »

Okay, I'm using a SQL query & a while loop in order to retrieve global announcements and display them on a page...

Code: Select all

<!-- BEGIN globalrow -->
<!-- IF globalrow.S_FIRST_UNREAD --><a id="unread"></a><!-- ENDIF -->
<div id="p{globalrow.POST_ID}" class="post bg2<!-- IF globalrow.S_UNREAD == 1 --> unreadpost<!-- ENDIF --><!-- IF globalrow.S_POST_REPORTED --> reported<!-- ENDIF -->">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="postbody">
      <!-- IF globalrow.S_IGNORE_POST -->
         <div class="ignore">{L_IGNORE_POST}</div>
      <!-- ELSE -->

      <h3 <!-- IF globalrow.S_FIRST_ROW -->class="first"<!-- ENDIF -->><!-- IF globalrow.POST_ICON_IMG --><img src="{T_ICONS_PATH}{globalrow.POST_ICON_IMG}" width="{globalrow.POST_ICON_IMG_WIDTH}" height="{globalrow.POST_ICON_IMG_HEIGHT}" alt="" /> <!-- ENDIF --><a href="{globalrow.U_MINI_POST}">{globalrow.POST_SUBJECT}</a></h3>
      <p class="author"><a href="{globalrow.U_MINI_POST}">{globalrow.MINI_POST_IMG}</a>{L_POST_BY_AUTHOR} <strong>{globalrow.POST_AUTHOR_FULL}</strong> {L_POSTED_ON_DATE} {globalrow.POST_DATE} </p>

      <!-- IF globalrow.S_POST_UNAPPROVED or globalrow.S_POST_REPORTED -->
         <p class="rules">
            <!-- IF globalrow.S_POST_UNAPPROVED -->{globalrow.UNAPPROVED_IMG} <a href="{globalrow.U_MCP_APPROVE}"><strong>{L_POST_UNAPPROVED}</strong></a><!-- ENDIF -->
            <!-- IF globalrow.S_POST_REPORTED -->{globalrow.REPORTED_IMG} <a href="{globalrow.U_MCP_REPORT}"><strong>{L_POST_REPORTED}</strong></a><!-- ENDIF -->
         </p>
      <!-- ENDIF -->

      <div class="content">{globalrow.MESSAGE}</div>

      <!-- IF globalrow.EDITED_MESSAGE or globalrow.EDIT_REASON -->
         <div class="notice">{globalrow.EDITED_MESSAGE}
            <!-- IF globalrow.EDIT_REASON --><br /><strong>{L_REASON}:</strong> <em>{globalrow.EDIT_REASON}</em><!-- ENDIF -->
         </div>
      <!-- ENDIF -->

      <!-- IF globalrow.BUMPED_MESSAGE --><div class="notice">{globalrow.BUMPED_MESSAGE}</div><!-- ENDIF -->
      <!-- IF globalrow.SIGNATURE --><div id="sig{globalrow.POST_ID}" class="signature">{globalrow.SIGNATURE}</div><!-- ENDIF -->
   <!-- ENDIF -->

   </div>

   <!-- IF not globalrow.S_IGNORE_POST -->
      <dl class="postprofile" id="profile{globalrow.POST_ID}">
      <dt><!-- IF globalrow.POSTER_AVATAR --><a href="{globalrow.U_POST_AUTHOR}">{globalrow.POSTER_AVATAR}</a><br /><!-- ENDIF -->{globalrow.POST_AUTHOR_FULL}</dt>

      <!-- IF globalrow.RANK_TITLE or globalrow.RANK_IMG --><dd>{globalrow.RANK_TITLE}<!-- IF globalrow.RANK_TITLE and globalrow.RANK_IMG --><br /><!-- ENDIF -->{globalrow.RANK_IMG}</dd><!-- ENDIF -->

   <dd>&nbsp;</dd>

   <!-- IF globalrow.POSTER_POSTS != '' --><dd><strong>{L_POSTS}:</strong> {globalrow.POSTER_POSTS}</dd><!-- ENDIF -->
   <!-- IF globalrow.POSTER_JOINED --><dd><strong>{L_JOINED}:</strong> {globalrow.POSTER_JOINED}</dd><!-- ENDIF -->
   <!-- IF globalrow.POSTER_FROM --><dd><strong>{L_LOCATION}:</strong> {globalrow.POSTER_FROM}</dd><!-- ENDIF -->

   <!-- IF globalrow.S_PROFILE_FIELD1 -->
      <!-- Use a construct like this to include admin defined profile fields. Replace FIELD1 with the name of your field. -->
      <dd><strong>{globalrow.PROFILE_FIELD1_NAME}:</strong> {globalrow.PROFILE_FIELD1_VALUE}</dd>
   <!-- ENDIF -->

   <!-- BEGIN custom_fields -->
      <dd><strong>{globalrow.custom_fields.PROFILE_FIELD_NAME}:</strong> {globalrow.custom_fields.PROFILE_FIELD_VALUE}</dd>
   <!-- END custom_fields -->

   </dl>
<!-- ENDIF -->
   <span class="corners-bottom"><span></span></span></div>
</div>
<div style="float: right;">{globalrow.U_VIEW_COMMENTS} &bull; <!-- IF S_USER_LOGGED_IN -->{globalrow.U_POST_COMMENT}<!-- ENDIF --></div>
<br />
<!-- END globalrow -->

<br /><br />

^^ The HTML I'm using

It seems that the while loop doesn't end the HTML segment soon enough. I'm ending up, after all of my useful chunks of data, with another chunk of the pattern that is missing all of the while loop's variables.

Here's my test of it, and the problem is obvious to me (logged in at least):

http://infernalarcade.ej.am/test/home.php


Also, this is the function I'm using (PHP)

Code: Select all

/****\
   *
   * @function      grab_global_contents
   * @description      Grabs the first global announcement and prepares to display the post in its entire form.
   * @globals         $db for queries, $user for permissions checking, $config if needed, $auth for permissions check, __
   *                $phpbb_root_path for filepath, $phpEx for PHP extension, $template for template file prep
   *
   * @param integer      $limit_amt      (Number of topics to grab)
   * @param boolean      $query_global   (Which query type to use?  Do we go for global announcements or do we go for newest topics in a certain forum?)
   * @param integer      $forum_scan   (Which forum to look in for the topics )
   *
   * @credit         (c) evil<3 ( http://www.phpbbmodders.net/ )
   *               ( A lot of code reused from the View Single Post MOD, legal under the GNU GPL v2 )
   * @function-license    http://opensource.org/licenses/gpl-license.php ( GNU Public License )
   *
   * @usage-example   grab_global_contents();
   *
\****/
   
   function grab_global_contents($limit_amt = 1, $query_global = true, $forum_scan = 0)
   {
      global $db, $auth, $user, $template;
      global $phpbb_root_path, $phpEx, $config, $cache;
      
      //Grab the newest global announcement
      if ($query_global == true)
      {
         $sql = 'SELECT *
            FROM ' . TOPICS_TABLE . "
            WHERE forum_id = 0
               AND topic_type = " . POST_GLOBAL  . "
            ORDER BY topic_time DESC
            LIMIT $limit_amt";//order by topic creation, use topic_last_post_time for last commented
      }
      else
      {
         $sql = 'SELECT *
            FROM ' . TOPICS_TABLE . "
            WHERE forum_id = $forum_scan
            ORDER BY topic_time DESC
            LIMIT $limit_amt";//order by topic creation, use topic_last_post_time for last commented
      }
      $result = $db->sql_query($sql);  //Got the data, let's go!
      while ($row = $db->sql_fetchrow($result))
      {
         //$mode         = '';  //Don't think we need the mode, do we?
         if ($query_global == true)
         {
            $forum_id      = request_var('sf', ANNOUNCEMENT_FORUM);
         }
         else
         {
            $forum_id      = $forum_scan;
         }
         $post_id      = $row['topic_first_post_id'];
         $topic_id      = $row['topic_id'];

         $sql_array = array(
            'SELECT'   => 'p.post_id, p.post_approved, f.forum_id',
            'FROM'      => array(
               POSTS_TABLE   => 'p',
            ),
            'LEFT_JOIN'   => array(
               array(
                  'FROM'   => array(FORUMS_TABLE   => 'f'),
                  'ON'   => 'f.forum_id = p.forum_id',
               ),
            ),
            'WHERE'      => 'p.post_id = ' . $post_id,
         );
         $result = $db->sql_query($db->sql_build_query('SELECT', $sql_array));
         $row = $db->sql_fetchrow($result);
         $db->sql_freeresult($result);

         $post_approved = $row['post_approved'];

         if ($forum_id && !isset($row['forum_id']))
         {
            // Make sure the forum (from given id) exists
            
            //Unnecessary?
            $sql = 'SELECT forum_id
               FROM ' . FORUMS_TABLE . '
               WHERE forum_id = ' . $forum_id;
            $result = $db->sql_query_limit($sql, 1);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            
            /*if (isset($row['forum_style']) && $auth->acl_get('f_list', $row['forum_id']))
            {
               $forum_style = $row['forum_style'];
            }
            else
            {
               // Display error
               $post_id = $forum_style = 0;
            }*/
         }
         else
         {
            $forum_id = $row['forum_id'];
            //$forum_style = $row['forum_style'];
         }

         if (!$forum_id)
         {
            // If no forum_id is given, and the user cannot view any forums, he can't view this.
            $forum_ary = $auth->acl_getf('f_read', true);
            $forum_ary = array_unique(array_keys($forum_ary));
            if (sizeof($forum_ary))
            {
               $post_id = 0;
            }
         }

         if (!$post_id)
         {
            trigger_error('NO_POST');
         }

         $display_notice = $first_unread = $post_unread = false;

         $sql_array = array(
            'SELECT'   => 'p.*, t.topic_id, t.topic_title, t.topic_replies, t.topic_status, t.topic_type, t.topic_first_post_id, t.topic_last_post_id, t.topic_bumped, f.enable_icons, u.*',
            'FROM'      => array(
               FORUMS_TABLE   => 'f',
               TOPICS_TABLE   => 't',
               POSTS_TABLE      => 'p',
               USERS_TABLE      => 'u',
            ),
            'WHERE'      => "p.post_id = $post_id
               AND t.topic_id = p.topic_id
               " . ((!$auth->acl_get('m_approve', $forum_id)) ? ' AND p.post_approved = 1' : '') . '
               AND t.topic_poster = u.user_id',
         );

         $sql_array['WHERE'] .= ' AND (f.forum_id = t.forum_id';

         /*if (!$forum_id)
         {
            // If it is a global announcement make sure to set the forum id to a postable forum
            $sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . '
               AND f.forum_type = ' . FORUM_POST . ')';
         }
         else
         {*/
            $sql_array['WHERE'] .= ' OR (t.topic_type = ' . POST_GLOBAL . "
               AND f.forum_id = $forum_id)";
         //}

         $sql_array['WHERE'] .= ')';

         // Join to forum table on topic forum_id unless topic forum_id is zero
         // whereupon we join on the forum_id passed as a parameter ... this
         // is done so navigation, forum name, etc. remain consistent with where
         // user clicked to view a global topic
         $sql = $db->sql_build_query('SELECT', $sql_array);
         $result = $db->sql_query($sql);
         $post_data = $db->sql_fetchrow($result);
         $db->sql_freeresult($result);

         $topic_id = (int) $post_data['topic_id'];

         // Grab icons
         $icons = $cache->obtain_icons();

         $poster_id = $post_data['user_id'];

         // End signature parsing, only if needed
         if ($post_data['user_sig'] && $post_data['enable_sig'])
         {
            $post_data['user_sig'] = censor_text($post_data['user_sig']);
            $post_data['user_sig'] = str_replace("\n", '<br />', $post_data['user_sig']);
            
            $post_data['user_sig'] = generate_text_for_display($post_data['user_sig'], $post_data['user_sig_bbcode_uid'], $post_data['user_sig_bbcode_bitfield'], $post_data['user_options']);

            $post_data['user_sig'] = smiley_text($post_data['user_sig']);
         }

         // Parse the message and subject
         $message = censor_text($post_data['post_text']);

         // Second parse bbcode here
         $post_data['bbcode_options'] = (($post_data['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post_data['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post_data['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
         $message = generate_text_for_display($message, $post_data['bbcode_uid'], $post_data['bbcode_bitfield'], $post_data['bbcode_options']);

         $message = str_replace("\n", '<br />', $message);

         // Always process smilies after parsing bbcodes
         $message = smiley_text($message);

         // Replace naughty words such as farty pants
         $post_data['post_subject'] = censor_text($post_data['post_subject']);

         // Editing information
         if (($post_data['post_edit_count'] && $config['display_last_edited']) || $post_data['post_edit_reason'])
         {
            $l_edit_time_total = ($post_data['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];

            if ($post_data['post_edit_reason'])
            {
               // User having edited the post also being the post author?
               if (!$post_data['post_edit_user'] || $post_data['post_edit_user'] == $poster_id)
               {
                  $display_username = get_username_string('full', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']);
               }
               else
               {
                  $display_username = get_username_string('full', $post_data['post_edit_user'], $post_edit_list[$post_data['post_edit_user']]['username'], $post_edit_list[$post_data['post_edit_user']]['user_colour']);
               }

               $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($post_data['post_edit_time']), $post_data['post_edit_count']);
            }
            else
            {
               // User having edited the post also being the post author?
               if (!$post_data['post_edit_user'] || $post_data['post_edit_user'] == $poster_id)
               {
                  $display_username = get_username_string('full', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']);
               }
               else
               {
                  $display_username = get_username_string('full', $post_data['post_edit_user'], $post_edit_list[$post_data['post_edit_user']]['username'], $post_edit_list[$post_data['post_edit_user']]['user_colour']);
               }

               $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($post_data['post_edit_time']), $post_data['post_edit_count']);
            }
         }
         else
         {
            $l_edited_by = '';
         }

         $cp_row = array();

         if ($config['load_cpf_viewtopic'])
         {
            $cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
         }

         $post_unread = (isset($topic_tracking_info[$topic_id]) && $post_data['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;

         $s_first_unread = false;
         if (!$first_unread && $post_unread)
         {
            $s_first_unread = $first_unread = true;
         }

         // Emulate user cache (we don't really need caching, since we only have one user)
         if ($poster_id == ANONYMOUS)
         {
            $post_data = array_merge($post_data, array(
               'joined'      => '',
               'posts'         => '',
               'from'         => '',

               'sig'               => '',
               'sig_bbcode_uid'      => '',
               'sig_bbcode_bitfield'   => '',

               //'online'         => false,
               'avatar'         => '',
               'rank_title'      => '',
               'rank_image'      => '',
               'rank_image_src'   => '',
               'sig'            => '',
               'posts'            => '',
               'profile'         => '',
               'pm'            => '',
               'email'            => '',
               'www'            => '',
               'icq_status_img'   => '',
               'icq'            => '',
               'aim'            => '',
               'msn'            => '',
               'yim'            => '',
               'jabber'         => '',
               'search'         => '',
               'age'            => '',

               'username'         => $post_data['username'],
               'user_colour'      => $post_data['user_colour'],

               'warnings'         => 0,
               'allow_pm'         => 0,
            ));
         }
         else
         {
            $post_data = array_merge($post_data, array(
               'joined'      => $user->format_date($post_data['user_regdate']),
               'posts'         => $post_data['user_posts'],
               'warnings'      => (isset($post_data['user_warnings'])) ? $post_data['user_warnings'] : 0,
               'from'         => (!empty($post_data['user_from'])) ? $post_data['user_from'] : '',

               'sig'               => ($post_data['user_sig'] && $config['allow_sig'] && $user->optionget('viewsigs')) ? $post_data['user_sig'] : '',
               'sig_bbcode_uid'      => (!empty($post_data['user_sig_bbcode_uid'])) ? $post_data['user_sig_bbcode_uid'] : '',
               'sig_bbcode_bitfield'   => (!empty($post_data['user_sig_bbcode_bitfield'])) ? $post_data['user_sig_bbcode_bitfield'] : '',

               'allow_pm'      => $post_data['user_allow_pm'],

               'avatar'      => ($user->optionget('viewavatars')) ? get_user_avatar($post_data['user_avatar'], $post_data['user_avatar_type'], $post_data['user_avatar_width'], $post_data['user_avatar_height']) : '',
               'age'         => '',

               'rank_title'      => '',
               'rank_image'      => '',
               'rank_image_src'   => '',

               'username'         => $post_data['username'],
               'user_colour'      => $post_data['user_colour'],

               //'online'      => false,
               'profile'      => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u=$poster_id"),
               'www'         => $post_data['user_website'],
               'aim'         => ($post_data['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=aim&amp;u=$poster_id") : '',
               'msn'         => ($post_data['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=msnm&amp;u=$poster_id") : '',
               'yim'         => ($post_data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . $post_data['user_yim'] . '&amp;.src=pg' : '',
               'jabber'      => ($post_data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=jabber&amp;u=$poster_id") : '',
               'search'      => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'search_author=' . urlencode($post_data['username']) .'&amp;showresults=posts') : '',
            ));
            
            $post_data['joined'] = $user->format_date($post_data['user_regdate']);
            
            get_user_rank($post_data['user_rank'], $post_data['user_posts'], $post_data['rank_title'], $post_data['rank_image'], $post_data['rank_image_src']);
            
            if (!empty($post_data['user_allow_viewemail']) || $auth->acl_get('a_email'))
            {
               $post_data['email'] = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;u=$poster_id") : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ? '' : 'mailto:' . $post_data['user_email']);
            }
            else
            {
               $post_data['email'] = '';
            }
            
            if (!empty($post_data['user_icq']))
            {
               $post_data['icq'] = 'http://www.icq.com/people/webmsg.php?to=' . $post_data['user_icq'];
               $post_data['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $post_data['user_icq'] . '&amp;img=5" width="18" height="18" alt="" />';
            }
            else
            {
               $post_data['icq_status_img'] = '';
               $post_data['icq'] = '';
            }
            
            if (!empty($post_data['user_birthday']))
            {
               list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $post_data['user_birthday']));
            
               if ($bday_year)
               {
                  $diff = $now['mon'] - $bday_month;
                  if ($diff == 0)
                  {
                     $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
                  }
                  else
                  {
                     $diff = ($diff < 0) ? 1 : 0;
                  }
            
                  $post_data['age'] = (int) ($now['year'] - $bday_year - $diff);
               }
            }
            else
            {
               $post_data['age'] = false;
            }
         }

         $postrow = array(
            'POST_AUTHOR_FULL'      => get_username_string('full', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),
            'POST_AUTHOR_COLOUR'   => get_username_string('colour', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),
            'POST_AUTHOR'         => get_username_string('username', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),
            'U_POST_AUTHOR'         => get_username_string('profile', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),

            'RANK_TITLE'         => $post_data['rank_title'],
            'RANK_IMG'            => $post_data['rank_image'],
            'RANK_IMG_SRC'         => $post_data['rank_image_src'],
            'POSTER_JOINED'         => $post_data['joined'],
            'POSTER_POSTS'         => $post_data['posts'],
            'POSTER_FROM'         => $post_data['from'],
            'POSTER_AVATAR'         => $post_data['avatar'],
            'POSTER_WARNINGS'      => $post_data['warnings'],
            'POSTER_AGE'         => $post_data['age'],

            'POST_DATE'            => $user->format_date($post_data['post_time']),
            'POST_SUBJECT'         => $post_data['post_subject'],
            'MESSAGE'            => $message,
            'SIGNATURE'            => ($post_data['enable_sig']) ? $post_data['sig'] : '',
            'EDITED_MESSAGE'      => $l_edited_by,
            'EDIT_REASON'         => $post_data['post_edit_reason'],
            'BUMPED_MESSAGE'      => $l_bumped_by,

            'MINI_POST_IMG'         => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
            'POST_ICON_IMG'         => ($post_data['enable_icons'] && !empty($post_data['icon_id'])) ? $icons[$post_data['icon_id']]['img'] : '',
            'POST_ICON_IMG_WIDTH'   => ($post_data['enable_icons'] && !empty($post_data['icon_id'])) ? $icons[$post_data['icon_id']]['width'] : '',
            'POST_ICON_IMG_HEIGHT'   => ($post_data['enable_icons'] && !empty($post_data['icon_id'])) ? $icons[$post_data['icon_id']]['height'] : '',
            'ICQ_STATUS_IMG'      => $post_data['icq_status_img'],
            //'ONLINE_IMG'         => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? '' : (($post_data['online']) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
            //'S_ONLINE'            => ($poster_id == ANONYMOUS || !$config['load_onlinetrack']) ? false : (($post_data['online']) ? true : false),

            'U_EDIT'         => (!$user->data['is_registered']) ? '' : ((($user->data['user_id'] == $poster_id && $auth->acl_get('f_edit', $forum_id) && ($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time'])) || $auth->acl_get('m_edit', $forum_id)) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&amp;f=$forum_id&amp;p={$post_id}") : ''),
            'U_QUOTE'         => ($auth->acl_get('f_reply', $forum_id)) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=quote&amp;f=$forum_id&amp;p={$post_id}") : '',
            'U_INFO'         => ($auth->acl_get('m_info', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=post_details&amp;f=$forum_id&amp;p=" . $post_id, true, $user->session_id) : '',
            'U_DELETE'         => (!$user->data['is_registered']) ? '' : ((($user->data['user_id'] == $poster_id && $auth->acl_get('f_delete', $forum_id) && $post_data['topic_last_post_id'] == $post_id && ($post_data['post_time'] > time() - ($config['edit_time'] * 60) || !$config['edit_time'])) || $auth->acl_get('m_delete', $forum_id)) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=delete&amp;f=$forum_id&amp;p={$post_id}") : ''),
            
            'U_PROFILE'      => $post_data['profile'],
            'U_SEARCH'      => $post_data['search'],
            'U_PM'         => ($poster_id != ANONYMOUS && $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($post_data['allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;action=quotepost&amp;p=' . $post_id) : '',
            'U_EMAIL'      => $post_data['email'],
            'U_WWW'         => $post_data['www'],
            'U_ICQ'         => $post_data['icq'],
            'U_AIM'         => $post_data['aim'],
            'U_MSN'         => $post_data['msn'],
            'U_YIM'         => $post_data['yim'],
            'U_JABBER'      => $post_data['jabber'],
            
            'U_VIEW_COMMENTS'   => '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id) . '">' . sprintf($user->lang['VIEW_COMMENTS'], $post_data['topic_replies']) . '</a>',
            'U_VIEW_COMMENT'   => '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id) . '">' . $user->lang['VIEW_COMMENT'] . '</a>',
            'U_POST_COMMENT'   => '<a href="' . append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=reply&amp;f=' . $forum_id . '&amp;t=' . $topic_id) . '">' . $user->lang['POST_COMMENT'] . '</a>',

            'U_REPORT'         => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id) : '',
            'U_MCP_REPORT'      => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $post_id, true, $user->session_id) : '',
            'U_MCP_APPROVE'      => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $post_id, true, $user->session_id) : '',
            'U_MINI_POST'      => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id),
            'U_NOTES'         => ($auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $poster_id, true, $user->session_id) : '',
            'U_WARN'         => ($auth->acl_get('m_warn') && $poster_id != $user->data['user_id'] && $poster_id != ANONYMOUS) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_post&amp;f=' . $forum_id . '&amp;p=' . $post_id, true, $user->session_id) : '',

            'POST_ID'         => $post_id,
            'POSTER_ID'         => $poster_id,

            //'S_HAS_ATTACHMENTS'   => (!empty($attachments)) ? true : false,
            'S_POST_UNAPPROVED'   => ($post_data['post_approved']) ? false : true,
            'S_POST_REPORTED'   => ($post_data['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
            'S_DISPLAY_NOTICE'   => $display_notice && $post_data['post_attachment'],
            'S_UNREAD_POST'      => $post_unread,
            'S_FIRST_UNREAD'   => $s_first_unread,
            'S_CUSTOM_FIELDS'   => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
         );

         if (isset($cp_row['row']) && sizeof($cp_row['row']))
         {
            $postrow = array_merge($postrow, $cp_row['row']);
         }

         $template->assign_block_vars('globalrow', $postrow);

         // Post data template variables
         if (!empty($cp_row['blockrow']))
         {
            foreach ($cp_row['blockrow'] as $field_data)
            {
               $template->assign_block_vars('globalrow.postrow.custom_fields', $field_data);
            }
         }

         // Send vars to template
         $template->assign_block_vars('globalrow', array(
            'FORUM_ID'       => $forum_id,
            'TOPIC_ID'       => $topic_id,
            
            'TOPIC_TITLE'      => censor_text($post_data['topic_title']),

            'QUOTE_IMG'       => $user->img('icon_post_quote', 'REPLY_WITH_QUOTE'),
            'EDIT_IMG'          => $user->img('icon_post_edit', 'EDIT_POST'),
            'DELETE_IMG'       => $user->img('icon_post_delete', 'DELETE_POST'),
            'INFO_IMG'          => $user->img('icon_post_info', 'VIEW_INFO'),
            'PROFILE_IMG'      => $user->img('icon_user_profile', 'READ_PROFILE'),
            'SEARCH_IMG'       => $user->img('icon_user_search', 'SEARCH_USER_POSTS'),
            'PM_IMG'          => $user->img('icon_contact_pm', 'SEND_PRIVATE_MESSAGE'),
            'EMAIL_IMG'       => $user->img('icon_contact_email', 'SEND_EMAIL'),
            'WWW_IMG'          => $user->img('icon_contact_www', 'VISIT_WEBSITE'),
            'ICQ_IMG'          => $user->img('icon_contact_icq', 'ICQ'),
            'AIM_IMG'          => $user->img('icon_contact_aim', 'AIM'),
            'MSN_IMG'          => $user->img('icon_contact_msnm', 'MSNM'),
            'YIM_IMG'          => $user->img('icon_contact_yahoo', 'YIM'),
            'JABBER_IMG'      => $user->img('icon_contact_jabber', 'JABBER') ,
            'REPORT_IMG'      => $user->img('icon_post_report', 'REPORT_POST'),
            'REPORTED_IMG'      => $user->img('icon_topic_reported', 'POST_REPORTED'),
            'UNAPPROVED_IMG'   => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED'),
            'WARN_IMG'         => $user->img('icon_user_warn', 'WARN_USER'),

            'U_TOPIC'            => "{$phpbb_root_path}viewtopic.$phpEx?f=$forum_id&amp;t=$topic_id",
         ));
      }
      $db->sql_freeresult($result);
   }


Soooo...yeah. I'm totally stuck.
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor

Re: While loop problem

Post by igorw »

I see a very big problem with your code.

You have got a query in a loop, this is very very bad. :D

Also, instead of this:

Code: Select all

      $sql = 'SELECT *
            FROM ' . TOPICS_TABLE . "
            WHERE forum_id = 0
               AND topic_type = " . POST_GLOBAL  . "
            ORDER BY topic_time DESC
            LIMIT $limit_amt";//order by topic creation, use topic_last_post_time for last commented

You should use $db->sql_query_limit().

Code: Select all

      $sql_array = array(
         'SELECT'   => 'p.post_id, p.post_approved, f.forum_id',
         'FROM'      => array(
            POSTS_TABLE   => 'p',
         ),
         'LEFT_JOIN'   => array(
            array(
               'FROM'   => array(FORUMS_TABLE   => 'f'),
               'ON'   => 'f.forum_id = p.forum_id',
            ),
         ),
         'WHERE'      => 'p.post_id = ' . $post_id,
      );

This is completely unneeded, since you have all data from the posts table already and you have forum_id from the posts table as well.

Same here:

Code: Select all

         //Unnecessary?
         $sql = 'SELECT forum_id
               FROM ' . FORUMS_TABLE . '
               WHERE forum_id = ' . $forum_id;
         $result = $db->sql_query_limit($sql, 1);
         $row = $db->sql_fetchrow($result);
         $db->sql_freeresult($result);


Also here:

Code: Select all

      $sql_array = array(
         'SELECT'   => 'p.*, t.topic_id, t.topic_title, t.topic_replies, t.topic_status, t.topic_type, t.topic_first_post_id, t.topic_last_post_id, t.topic_bumped, f.enable_icons, u.*',
         'FROM'      => array(
            FORUMS_TABLE   => 'f',
            TOPICS_TABLE   => 't',
            POSTS_TABLE      => 'p',
            USERS_TABLE      => 'u',
         ),
         'WHERE'      => "p.post_id = $post_id
            AND t.topic_id = p.topic_id
            " . ((!$auth->acl_get('m_approve', $forum_id)) ? ' AND p.post_approved = 1' : '') . '
            AND t.topic_poster = u.user_id',
      );

You can get the data in the first place.

Code: Select all

            // Grab icons
            $icons = $cache->obtain_icons();

Don't do this in a loop. Fetch it first.

Before you have any more or less clean code there's no sense in trying to find bugs IMO. :)
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: While loop problem

Post by Obsidian »

Okay...I guess I'll try to clean all that up. :?
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: While loop problem

Post by Obsidian »

Okay, I've cleaned up the function significantly.

Code: Select all

/****\
   *
   * @function      grab_global_contents
   * @description      Grabs the first global announcement and prepares to display the post in its entire form.
   * @globals         $db for queries, $user for permissions checking, $config if needed, $auth for permissions check, __
   *                $phpbb_root_path for filepath, $phpEx for PHP extension, $template for template file prep
   *
   * @param integer      $limit_amt      (Number of topics to grab)
   * @param boolean      $query_global   (Which query type to use?  Do we go for global announcements or do we go for newest topics in a certain forum?)
   * @param integer      $forum_scan   (Which forum to look in for the topics )
   *
   * @credit         (c) evil<3 ( http://www.phpbbmodders.net/ )
   *               ( A lot of code reused from the View Single Post MOD, legal under the GNU GPL v2 )
   * @function-license    http://opensource.org/licenses/gpl-license.php ( GNU Public License )
   *
   * @usage-example   grab_global_contents();
   *
\****/
   
   function grab_global_contents($limit_amt = 1, $query_global = true, $forum_scan = 0)
   {
      global $db, $auth, $user, $template;
      global $phpbb_root_path, $phpEx, $config, $cache;
      
      // Grab icons
      $icons = $cache->obtain_icons();
      
      //Grab the newest global announcement
         if ($query_global == true)
         {
            $forum_id      = request_var('sf', ANNOUNCEMENT_FORUM);
         }
         else
         {
            $forum_id      = $forum_scan;
         }
         
         $sql_array = array(
            'SELECT'   => 't.*, p.*, u.*',
            'FROM'      => array(
                  POSTS_TABLE      => 'p',
                  TOPICS_TABLE   => 't',
                  USERS_TABLE      => 'u',
                  
            ),
            'LEFT_JOIN'   => array(
               array(
                  'FROM'   => array(FORUMS_TABLE   => 'f'),
                  'ON'   => 'f.forum_id = p.forum_id',
               ),
            ),
            //'WHERE'      => 't.forum_id = 0',
            'WHERE'      => 't.forum_id = ' . $forum_scan . '
               AND t.topic_id = p.topic_id
               ' . ((!$auth->acl_get('m_approve', $forum_id)) ? ' AND p.post_approved = 1' : '') . '
               AND t.topic_poster = u.user_id',
            'ORDER BY'   => 't.topic_time DESC',
         );
         
         
      /*   'FROM ' . TOPICS_TABLE . "
            WHERE forum_id = 0
               AND topic_type = " . POST_GLOBAL  . "
            ORDER BY topic_time DESC
            LIMIT $limit_amt";//order by topic creation, use topic_last_post_time for last commented
      }
      else
      {
         $sql = 'SELECT *
            FROM ' . TOPICS_TABLE . "
            WHERE forum_id = $forum_scan
            ORDER BY topic_time DESC
            LIMIT $limit_amt";//order by topic creation, use topic_last_post_time for last commented
      }*/
      $result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_array), $limit_amt);
      //$result = $db->sql_query($sql); 
      
      //Got the data, let's go!
      while ($row = $db->sql_fetchrow($result))
      {
         $post_id      = $row['topic_first_post_id'];
         $topic_id      = $row['topic_id'];
         if (!$post_id)
         {
            trigger_error('NO_POST');
         }

         $post_approved = $row['post_approved'];

         if (!$forum_id)
         {
            // If no forum_id is given, and the user cannot view any forums, he can't view this.
            $forum_ary = $auth->acl_getf('f_read', true);
            $forum_ary = array_unique(array_keys($forum_ary));
            if (sizeof($forum_ary))
            {
               trigger_error('NO_POST');
            }
         }

         $display_notice = $first_unread = $post_unread = false;

         //Trick to clean up edits...we'll keep the $post_data array and just use the data from the $row array.
         $post_data = $row;

         //$topic_id = (int) $post_data['topic_id'];
         $poster_id = $post_data['user_id'];

         // End signature parsing, only if needed
         if ($post_data['user_sig'] && $post_data['enable_sig'])
         {
            $post_data['user_sig'] = censor_text($post_data['user_sig']);
            $post_data['user_sig'] = str_replace("\n", '<br />', $post_data['user_sig']);
            
            $post_data['user_sig'] = generate_text_for_display($post_data['user_sig'], $post_data['user_sig_bbcode_uid'], $post_data['user_sig_bbcode_bitfield'], $post_data['user_options']);

            $post_data['user_sig'] = smiley_text($post_data['user_sig']);
         }

         // Parse the message and subject
         $message = censor_text($post_data['post_text']);

         // Second parse bbcode here
         $post_data['bbcode_options'] = (($post_data['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post_data['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post_data['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
         $message = generate_text_for_display($message, $post_data['bbcode_uid'], $post_data['bbcode_bitfield'], $post_data['bbcode_options']);

         $message = str_replace("\n", '<br />', $message);

         // Always process smilies after parsing bbcodes
         $message = smiley_text($message);

         // Replace naughty words such as farty pants
         $post_data['post_subject'] = censor_text($post_data['post_subject']);

         // Editing information
         if (($post_data['post_edit_count'] && $config['display_last_edited']) || $post_data['post_edit_reason'])
         {
            $l_edit_time_total = ($post_data['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];

            if ($post_data['post_edit_reason'])
            {
               // User having edited the post also being the post author?
               if (!$post_data['post_edit_user'] || $post_data['post_edit_user'] == $poster_id)
               {
                  $display_username = get_username_string('full', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']);
               }
               else
               {
                  $display_username = get_username_string('full', $post_data['post_edit_user'], $post_edit_list[$post_data['post_edit_user']]['username'], $post_edit_list[$post_data['post_edit_user']]['user_colour']);
               }

               $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($post_data['post_edit_time']), $post_data['post_edit_count']);
            }
            else
            {
               // User having edited the post also being the post author?
               if (!$post_data['post_edit_user'] || $post_data['post_edit_user'] == $poster_id)
               {
                  $display_username = get_username_string('full', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']);
               }
               else
               {
                  $display_username = get_username_string('full', $post_data['post_edit_user'], $post_edit_list[$post_data['post_edit_user']]['username'], $post_edit_list[$post_data['post_edit_user']]['user_colour']);
               }

               $l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($post_data['post_edit_time']), $post_data['post_edit_count']);
            }
         }
         else
         {
            $l_edited_by = '';
         }

         $cp_row = array();

         if ($config['load_cpf_viewtopic'])
         {
            $cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
         }

         $post_unread = (isset($topic_tracking_info[$topic_id]) && $post_data['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;

         $s_first_unread = false;
         if (!$first_unread && $post_unread)
         {
            $s_first_unread = $first_unread = true;
         }

         // Emulate user cache (we don't really need caching, since we only have one user)
         if ($poster_id == ANONYMOUS)
         {
            $post_data = array_merge($post_data, array(
               'joined'      => '',
               'posts'         => '',
               'from'         => '',

               'sig'               => '',
               'sig_bbcode_uid'      => '',
               'sig_bbcode_bitfield'   => '',

               //'online'         => false,
               'avatar'         => '',
               'rank_title'      => '',
               'rank_image'      => '',
               'rank_image_src'   => '',
               'sig'            => '',
               'posts'            => '',
               'profile'         => '',
               'pm'            => '',
               'email'            => '',
               'www'            => '',
               'icq_status_img'   => '',
               'icq'            => '',
               'aim'            => '',
               'msn'            => '',
               'yim'            => '',
               'jabber'         => '',
               'search'         => '',
               'age'            => '',

               'username'         => $post_data['username'],
               'user_colour'      => $post_data['user_colour'],

               'warnings'         => 0,
               'allow_pm'         => 0,
            ));
         }
         else
         {
            $post_data = array_merge($post_data, array(
               'joined'      => $user->format_date($post_data['user_regdate']),
               'posts'         => $post_data['user_posts'],
               'warnings'      => (isset($post_data['user_warnings'])) ? $post_data['user_warnings'] : 0,
               'from'         => (!empty($post_data['user_from'])) ? $post_data['user_from'] : '',

               'sig'               => ($post_data['user_sig'] && $config['allow_sig'] && $user->optionget('viewsigs')) ? $post_data['user_sig'] : '',
               'sig_bbcode_uid'      => (!empty($post_data['user_sig_bbcode_uid'])) ? $post_data['user_sig_bbcode_uid'] : '',
               'sig_bbcode_bitfield'   => (!empty($post_data['user_sig_bbcode_bitfield'])) ? $post_data['user_sig_bbcode_bitfield'] : '',

               'allow_pm'      => $post_data['user_allow_pm'],

               'avatar'      => ($user->optionget('viewavatars')) ? get_user_avatar($post_data['user_avatar'], $post_data['user_avatar_type'], $post_data['user_avatar_width'], $post_data['user_avatar_height']) : '',
               'age'         => '',

               'rank_title'      => '',
               'rank_image'      => '',
               'rank_image_src'   => '',

               'username'         => $post_data['username'],
               'user_colour'      => $post_data['user_colour'],

               //'online'      => false,
               'profile'      => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u=$poster_id"),
               'www'         => $post_data['user_website'],
               'aim'         => ($post_data['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=aim&amp;u=$poster_id") : '',
               'msn'         => ($post_data['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=msnm&amp;u=$poster_id") : '',
               'yim'         => ($post_data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . $post_data['user_yim'] . '&amp;.src=pg' : '',
               'jabber'      => ($post_data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=jabber&amp;u=$poster_id") : '',
               'search'      => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'search_author=' . urlencode($post_data['username']) .'&amp;showresults=posts') : '',
            ));
            
            $post_data['joined'] = $user->format_date($post_data['user_regdate']);
            
            get_user_rank($post_data['user_rank'], $post_data['user_posts'], $post_data['rank_title'], $post_data['rank_image'], $post_data['rank_image_src']);
            
            if (!empty($post_data['user_allow_viewemail']) || $auth->acl_get('a_email'))
            {
               $post_data['email'] = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;u=$poster_id") : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ? '' : 'mailto:' . $post_data['user_email']);
            }
            else
            {
               $post_data['email'] = '';
            }
            
            if (!empty($post_data['user_icq']))
            {
               $post_data['icq'] = 'http://www.icq.com/people/webmsg.php?to=' . $post_data['user_icq'];
               $post_data['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $post_data['user_icq'] . '&amp;img=5" width="18" height="18" alt="" />';
            }
            else
            {
               $post_data['icq_status_img'] = '';
               $post_data['icq'] = '';
            }
            
            if (!empty($post_data['user_birthday']))
            {
               list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $post_data['user_birthday']));
            
               if ($bday_year)
               {
                  $diff = $now['mon'] - $bday_month;
                  if ($diff == 0)
                  {
                     $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
                  }
                  else
                  {
                     $diff = ($diff < 0) ? 1 : 0;
                  }
            
                  $post_data['age'] = (int) ($now['year'] - $bday_year - $diff);
               }
            }
            else
            {
               $post_data['age'] = false;
            }
         }

         $postrow = array(
            'POST_AUTHOR_FULL'      => get_username_string('full', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),
            'POST_AUTHOR_COLOUR'   => get_username_string('colour', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),
            'POST_AUTHOR'         => get_username_string('username', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),
            'U_POST_AUTHOR'         => get_username_string('profile', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),

            'RANK_TITLE'         => $post_data['rank_title'],
            'RANK_IMG'            => $post_data['rank_image'],
            'RANK_IMG_SRC'         => $post_data['rank_image_src'],
            'POSTER_JOINED'         => $post_data['joined'],
            'POSTER_POSTS'         => $post_data['posts'],
            'POSTER_FROM'         => $post_data['from'],
            'POSTER_AVATAR'         => $post_data['avatar'],
            'POSTER_WARNINGS'      => $post_data['warnings'],
            'POSTER_AGE'         => $post_data['age'],

            'POST_DATE'            => $user->format_date($post_data['post_time']),
            'POST_SUBJECT'         => $post_data['post_subject'],
            'MESSAGE'            => $message,
            'SIGNATURE'            => ($post_data['enable_sig']) ? $post_data['sig'] : '',
            'EDITED_MESSAGE'      => $l_edited_by,
            'EDIT_REASON'         => $post_data['post_edit_reason'],

            'MINI_POST_IMG'         => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
            
            'U_PROFILE'      => $post_data['profile'],
            'U_SEARCH'      => $post_data['search'],
            'U_PM'         => ($poster_id != ANONYMOUS && $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($post_data['allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;action=quotepost&amp;p=' . $post_id) : '',
            'U_EMAIL'      => $post_data['email'],
            'U_WWW'         => $post_data['www'],
            'U_ICQ'         => $post_data['icq'],
            'U_AIM'         => $post_data['aim'],
            'U_MSN'         => $post_data['msn'],
            'U_YIM'         => $post_data['yim'],
            'U_JABBER'      => $post_data['jabber'],
            
            'U_VIEW_COMMENTS'   => '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id) . '">' . sprintf($user->lang['VIEW_COMMENTS'], $post_data['topic_replies']) . '</a>',
            'U_VIEW_COMMENT'   => '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id) . '">' . $user->lang['VIEW_COMMENT'] . '</a>',
            'U_POST_COMMENT'   => '<a href="' . append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=reply&amp;f=' . $forum_id . '&amp;t=' . $topic_id) . '">' . $user->lang['POST_COMMENT'] . '</a>',

            'U_REPORT'         => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id) : '',
            'U_MCP_REPORT'      => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $post_id, true, $user->session_id) : '',
            'U_MCP_APPROVE'      => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $post_id, true, $user->session_id) : '',
            'U_MINI_POST'      => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id),
            'U_NOTES'         => ($auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $poster_id, true, $user->session_id) : '',
            //'U_WARN'         => ($auth->acl_get('m_warn') && $poster_id != $user->data['user_id'] && $poster_id != ANONYMOUS) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_post&amp;f=' . $forum_id . '&amp;p=' . $post_id, true, $user->session_id) : '',

            'POST_ID'         => $post_id,
            'POSTER_ID'         => $poster_id,

            //'S_HAS_ATTACHMENTS'   => (!empty($attachments)) ? true : false,
            'S_POST_UNAPPROVED'   => ($post_data['post_approved']) ? false : true,
            'S_POST_REPORTED'   => ($post_data['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
            'S_DISPLAY_NOTICE'   => $display_notice && $post_data['post_attachment'],
            'S_UNREAD_POST'      => $post_unread,
            'S_FIRST_UNREAD'   => $s_first_unread,
            'S_CUSTOM_FIELDS'   => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
         );

         if (isset($cp_row['row']) && sizeof($cp_row['row']))
         {
            $postrow = array_merge($postrow, $cp_row['row']);
         }

         $template->assign_block_vars('globalrow', $postrow);

         // Post data template variables
         if (!empty($cp_row['blockrow']))
         {
            foreach ($cp_row['blockrow'] as $field_data)
            {
               $template->assign_block_vars('globalrow.postrow.custom_fields', $field_data);
            }
         }

         // Send vars to template
         $template->assign_block_vars('globalrow', array(
            'FORUM_ID'       => $forum_id,
            'TOPIC_ID'       => $topic_id,
            
            'TOPIC_TITLE'      => censor_text($post_data['topic_title']),

            'U_TOPIC'            => "{$phpbb_root_path}viewtopic.$phpEx?f=$forum_id&amp;t=$topic_id",
         ));
      }
      $db->sql_freeresult($result);
   }
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: While loop problem

Post by Obsidian »

Okay, I've finally got it working. YAY!

Here it is in action (with a few other things with it) on my test board:
[url]http://infernalarcade.ej.am/test/home.php[/url]

For those that want to replicate this...

HTML code, just include it into the page you want it on.
Show Hide | Select all
<!-- BEGIN globalrow -->
<!-- IF globalrow.S_ROW_COUNT is even -->
<div id="p{globalrow.POST_ID}" class="post bg1">
<div class="inner"><span class="corners-top"><span></span></span>

<div class="postbody">

<h3 <!-- IF globalrow.S_FIRST_ROW -->class="first"<!-- ENDIF -->><!-- IF globalrow.POST_ICON_IMG --><img src="{T_ICONS_PATH}{globalrow.POST_ICON_IMG}" width="{globalrow.POST_ICON_IMG_WIDTH}" height="{globalrow.POST_ICON_IMG_HEIGHT}" alt="" /> <!-- ENDIF --><a href="{globalrow.U_MINI_POST}">{globalrow.POST_SUBJECT}</a></h3>
<p class="author"><a href="{globalrow.U_MINI_POST}">{globalrow.MINI_POST_IMG}</a>{L_POST_BY_AUTHOR} <strong>{globalrow.POST_AUTHOR_FULL}</strong> {L_POSTED_ON_DATE} {globalrow.POST_DATE} </p>

<div class="content">{globalrow.MESSAGE}</div>

<!-- IF globalrow.EDITED_MESSAGE or globalrow.EDIT_REASON -->
<div class="notice">{globalrow.EDITED_MESSAGE}
<!-- IF globalrow.EDIT_REASON --><br /><strong>{L_REASON}:</strong> <em>{globalrow.EDIT_REASON}</em><!-- ENDIF -->
</div>
<!-- ENDIF -->

<!--<!-- IF globalrow.SIGNATURE --><div id="sig{globalrow.POST_ID}" class="signature">{globalrow.SIGNATURE}</div><!-- ENDIF -->-->
<br />

</div>

<dl class="postprofile" id="profile{globalrow.POST_ID}">
<dt><!-- IF globalrow.POSTER_AVATAR --><a href="{globalrow.U_POST_AUTHOR}">{globalrow.POSTER_AVATAR}</a><br /><!-- ELSE --><a href="{globalrow.U_POST_AUTHOR}"><img src="{T_THEME_PATH}/images/no_avatar.gif" alt="" /></a><br /><!-- ENDIF -->{globalrow.POST_AUTHOR_FULL}</dt>

<!-- IF globalrow.RANK_TITLE or globalrow.RANK_IMG --><dd>{globalrow.RANK_TITLE}<!-- IF globalrow.RANK_TITLE and globalrow.RANK_IMG --><br /><!-- ENDIF -->{globalrow.RANK_IMG}</dd><!-- ENDIF -->

<dd>&nbsp;</dd>
</dl>
<span class="corners-bottom"><span></span></span></div>
</div>
<div style="float: right;"> <a href="#welcometop" class="top2">{L_BACK_TO_TOP}</a>&nbsp;&bull;&nbsp;{globalrow.U_VIEW_COMMENTS}&nbsp;<!-- IF S_USER_LOGGED_IN -->&bull;&nbsp;{globalrow.U_POST_COMMENT}<!-- ENDIF --></div>
<br /><br />
<!-- ENDIF -->
<!-- END globalrow -->

<br /><br />


PHP function code:

Show Hide | Select all
/****\
*
* @function grab_global_contents
* @description Grabs the first global announcement and prepares to display the post in its entire form.
* @globals $db for queries, $user for permissions checking, $config if needed, $auth for permissions check, __
* $phpbb_root_path for filepath, $phpEx for PHP extension, $template for template file prep
*
* @param integer $limit_amt (Number of topics to grab)
* @param boolean $query_global (Which query type to use? Do we go for global announcements or do we go for newest topics in a certain forum?)
* @param integer $forum_scan (Which forum to look in for the topics )
*
* @credit (c) 2008 sTraTo
* ( A lot of code was reused from the View Single Post MOD by evil3 - http://www.phpbbmodders.net/ )
* @function-license http://opensource.org/licenses/gpl-license.php ( GNU Public License )
*
* @usage-example grab_global_contents();
* @usage-example grab_global_contents(3);
* @usage-example grab_global_contents(3, true, 2);
*
\****/

function grab_global_contents($limit_amt = 1, $query_global = true, $forum_scan = 0)
{
global $db, $auth, $user, $template;
global $phpbb_root_path, $phpEx, $config, $cache;

// Grab icons
$icons = $cache->obtain_icons();

//Grab the newest posts
if ($query_global == true)
{
$forum_id = request_var('sf', ANNOUNCEMENT_FORUM);
}
else
{
$forum_id = $forum_scan;
}

$sql_array = array(
'SELECT' => 't.*, p.*, u.*',
'FROM' => array(
//POSTS_TABLE => 'p',
TOPICS_TABLE => 't',
//USERS_TABLE => 'u',
),
'LEFT_JOIN' => array(
array(
'FROM' => array(POSTS_TABLE => 'p'),
'ON' => 't.topic_id = p.topic_id',
),
array(
'FROM' => array(USERS_TABLE => 'u'),
'ON' => 't.topic_poster = u.user_id',
),
),
'WHERE' => 't.forum_id = ' . $db->sql_escape($forum_id) . '
AND t.topic_first_post_id = p.post_id',
'ORDER_BY' => 't.topic_time DESC',
);
//echo $forum_id;
//$limit_amt = 3;
$result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_array), $limit_amt);
//$result = $db->sql_query($sql);

//Got the data, let's go!

while ($row = $db->sql_fetchrow($result))
{

$post_id = $row['topic_first_post_id'];
$topic_id = $row['topic_id'];
if (!$post_id)
{
trigger_error('NO_POST');
}

$post_approved = $row['post_approved'];

if (!$forum_id)
{
// If no forum_id is given, and the user cannot view any forums, he can't view this.
$forum_ary = $auth->acl_getf('f_read', true);
$forum_ary = array_unique(array_keys($forum_ary));
if (sizeof($forum_ary))
{
trigger_error('NO_POST');
}
}

$display_notice = $first_unread = $post_unread = false;

//Trick to clean up edits...we'll keep the $post_data array and just use the data from the $row array.
$post_data = $row;

//$topic_id = (int) $post_data['topic_id'];
$poster_id = $post_data['user_id'];

// End signature parsing, only if needed
if ($post_data['user_sig'] && $post_data['enable_sig'])
{
$post_data['user_sig'] = censor_text($post_data['user_sig']);
$post_data['user_sig'] = str_replace("\n", '<br />', $post_data['user_sig']);

$post_data['user_sig'] = generate_text_for_display($post_data['user_sig'], $post_data['user_sig_bbcode_uid'], $post_data['user_sig_bbcode_bitfield'], $post_data['user_options']);

$post_data['user_sig'] = smiley_text($post_data['user_sig']);
}

// Parse the message and subject
$message = censor_text($post_data['post_text']);

// Second parse bbcode here
$post_data['bbcode_options'] = (($post_data['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post_data['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post_data['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
$message = generate_text_for_display($message, $post_data['bbcode_uid'], $post_data['bbcode_bitfield'], $post_data['bbcode_options']);

$message = str_replace("\n", '<br />', $message);

// Always process smilies after parsing bbcodes
$message = smiley_text($message);

// Replace naughty words such as farty pants
$post_data['post_subject'] = censor_text($post_data['post_subject']);

// Editing information
if (($post_data['post_edit_count'] && $config['display_last_edited']) || $post_data['post_edit_reason'])
{
$l_edit_time_total = ($post_data['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];

if ($post_data['post_edit_reason'])
{
// User having edited the post also being the post author?
if (!$post_data['post_edit_user'] || $post_data['post_edit_user'] == $poster_id)
{
$display_username = get_username_string('full', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']);
}
else
{
$display_username = get_username_string('full', $post_data['post_edit_user'], $post_edit_list[$post_data['post_edit_user']]['username'], $post_edit_list[$post_data['post_edit_user']]['user_colour']);
}

$l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($post_data['post_edit_time']), $post_data['post_edit_count']);
}
else
{
// User having edited the post also being the post author?
if (!$post_data['post_edit_user'] || $post_data['post_edit_user'] == $poster_id)
{
$display_username = get_username_string('full', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']);
}
else
{
$display_username = get_username_string('full', $post_data['post_edit_user'], $post_edit_list[$post_data['post_edit_user']]['username'], $post_edit_list[$post_data['post_edit_user']]['user_colour']);
}

$l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($post_data['post_edit_time']), $post_data['post_edit_count']);
}
}
else
{
$l_edited_by = '';
}

$cp_row = array();

if ($config['load_cpf_viewtopic'])
{
$cp_row = (isset($profile_fields_cache[$poster_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$poster_id]) : array();
}

$post_unread = (isset($topic_tracking_info[$topic_id]) && $post_data['post_time'] > $topic_tracking_info[$topic_id]) ? true : false;

$s_first_unread = false;
if (!$first_unread && $post_unread)
{
$s_first_unread = $first_unread = true;
}

// Emulate user cache (we don't really need caching, since we only have one user)
if ($poster_id == ANONYMOUS)
{
$post_data = array_merge($post_data, array(
'joined' => '',
'posts' => '',
'from' => '',

'sig' => '',
'sig_bbcode_uid' => '',
'sig_bbcode_bitfield' => '',

//'online' => false,
'avatar' => '',
'rank_title' => '',
'rank_image' => '',
'rank_image_src' => '',
'sig' => '',
'posts' => '',
'profile' => '',
'pm' => '',
'email' => '',
'www' => '',
'icq_status_img' => '',
'icq' => '',
'aim' => '',
'msn' => '',
'yim' => '',
'jabber' => '',
'search' => '',
'age' => '',

'username' => $post_data['username'],
'user_colour' => $post_data['user_colour'],

'warnings' => 0,
'allow_pm' => 0,
));
}
else
{
$post_data = array_merge($post_data, array(
'joined' => $user->format_date($post_data['user_regdate']),
'posts' => $post_data['user_posts'],
'warnings' => (isset($post_data['user_warnings'])) ? $post_data['user_warnings'] : 0,
'from' => (!empty($post_data['user_from'])) ? $post_data['user_from'] : '',

'sig' => ($post_data['user_sig'] && $config['allow_sig'] && $user->optionget('viewsigs')) ? $post_data['user_sig'] : '',
'sig_bbcode_uid' => (!empty($post_data['user_sig_bbcode_uid'])) ? $post_data['user_sig_bbcode_uid'] : '',
'sig_bbcode_bitfield' => (!empty($post_data['user_sig_bbcode_bitfield'])) ? $post_data['user_sig_bbcode_bitfield'] : '',

'allow_pm' => $post_data['user_allow_pm'],

'avatar' => ($user->optionget('viewavatars')) ? get_user_avatar($post_data['user_avatar'], $post_data['user_avatar_type'], $post_data['user_avatar_width'], $post_data['user_avatar_height']) : '',
'age' => '',

'rank_title' => '',
'rank_image' => '',
'rank_image_src' => '',

'username' => $post_data['username'],
'user_colour' => $post_data['user_colour'],

//'online' => false,
'profile' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=viewprofile&amp;u=$poster_id"),
'www' => $post_data['user_website'],
'aim' => ($post_data['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=aim&amp;u=$poster_id") : '',
'msn' => ($post_data['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=msnm&amp;u=$poster_id") : '',
'yim' => ($post_data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . $post_data['user_yim'] . '&amp;.src=pg' : '',
'jabber' => ($post_data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=jabber&amp;u=$poster_id") : '',
'search' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", 'search_author=' . urlencode($post_data['username']) .'&amp;showresults=posts') : '',
));

$post_data['joined'] = $user->format_date($post_data['user_regdate']);

get_user_rank($post_data['user_rank'], $post_data['user_posts'], $post_data['rank_title'], $post_data['rank_image'], $post_data['rank_image_src']);

if (!empty($post_data['user_allow_viewemail']) || $auth->acl_get('a_email'))
{
$post_data['email'] = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=email&amp;u=$poster_id") : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ? '' : 'mailto:' . $post_data['user_email']);
}
else
{
$post_data['email'] = '';
}

if (!empty($post_data['user_icq']))
{
$post_data['icq'] = 'http://www.icq.com/people/webmsg.php?to=' . $post_data['user_icq'];
$post_data['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $post_data['user_icq'] . '&amp;img=5" width="18" height="18" alt="" />';
}
else
{
$post_data['icq_status_img'] = '';
$post_data['icq'] = '';
}

if (!empty($post_data['user_birthday']))
{
list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $post_data['user_birthday']));

if ($bday_year)
{
$diff = $now['mon'] - $bday_month;
if ($diff == 0)
{
$diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
}
else
{
$diff = ($diff < 0) ? 1 : 0;
}

$post_data['age'] = (int) ($now['year'] - $bday_year - $diff);
}
}
else
{
$post_data['age'] = false;
}
}

$postrow = array(
'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),
'POST_AUTHOR_COLOUR' => get_username_string('colour', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),
'POST_AUTHOR' => get_username_string('username', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),
'U_POST_AUTHOR' => get_username_string('profile', $poster_id, $post_data['username'], $post_data['user_colour'], $post_data['post_username']),

'RANK_TITLE' => $post_data['rank_title'],
'RANK_IMG' => $post_data['rank_image'],
'RANK_IMG_SRC' => $post_data['rank_image_src'],
'POSTER_JOINED' => $post_data['joined'],
'POSTER_POSTS' => $post_data['posts'],
'POSTER_FROM' => $post_data['from'],
'POSTER_AVATAR' => $post_data['avatar'],
'POSTER_WARNINGS' => $post_data['warnings'],
'POSTER_AGE' => $post_data['age'],

'POST_DATE' => $user->format_date($post_data['post_time']),
'POST_SUBJECT' => $post_data['post_subject'],
'MESSAGE' => $message,
'SIGNATURE' => ($post_data['enable_sig']) ? $post_data['sig'] : '',
'EDITED_MESSAGE' => $l_edited_by,
'EDIT_REASON' => $post_data['post_edit_reason'],

'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),

'U_PROFILE' => $post_data['profile'],
'U_SEARCH' => $post_data['search'],
'U_PM' => ($poster_id != ANONYMOUS && $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($post_data['allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;action=quotepost&amp;p=' . $post_id) : '',
'U_EMAIL' => $post_data['email'],
'U_WWW' => $post_data['www'],
'U_ICQ' => $post_data['icq'],
'U_AIM' => $post_data['aim'],
'U_MSN' => $post_data['msn'],
'U_YIM' => $post_data['yim'],
'U_JABBER' => $post_data['jabber'],

'U_VIEW_COMMENTS' => '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id) . '">' . sprintf($user->lang['VIEW_COMMENTS'], $post_data['topic_replies']) . '</a>',
'U_VIEW_COMMENT' => '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id) . '">' . $user->lang['VIEW_COMMENT'] . '</a>',
'U_POST_COMMENT' => '<a href="' . append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=reply&amp;f=' . $forum_id . '&amp;t=' . $topic_id) . '">' . $user->lang['POST_COMMENT'] . '</a>',

'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id) : '',
'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $forum_id . '&amp;p=' . $post_id, true, $user->session_id) : '',
'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $forum_id . '&amp;p=' . $post_id, true, $user->session_id) : '',
'U_MINI_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id),
'U_NOTES' => ($auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $poster_id, true, $user->session_id) : '',
//'U_WARN' => ($auth->acl_get('m_warn') && $poster_id != $user->data['user_id'] && $poster_id != ANONYMOUS) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_post&amp;f=' . $forum_id . '&amp;p=' . $post_id, true, $user->session_id) : '',

'POST_ID' => $post_id,
'POSTER_ID' => $poster_id,

//'S_HAS_ATTACHMENTS' => (!empty($attachments)) ? true : false,
'S_POST_UNAPPROVED' => ($post_data['post_approved']) ? false : true,
'S_POST_REPORTED' => ($post_data['post_reported'] && $auth->acl_get('m_report', $forum_id)) ? true : false,
'S_DISPLAY_NOTICE' => $display_notice && $post_data['post_attachment'],
'S_UNREAD_POST' => $post_unread,
'S_FIRST_UNREAD' => $s_first_unread,
'S_CUSTOM_FIELDS' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
);

if (isset($cp_row['row']) && sizeof($cp_row['row']))
{
$postrow = array_merge($postrow, $cp_row['row']);
}

$template->assign_block_vars('globalrow', $postrow);

// Post data template variables
if (!empty($cp_row['blockrow']))
{
foreach ($cp_row['blockrow'] as $field_data)
{
$template->assign_block_vars('globalrow.postrow.custom_fields', $field_data);
}
}

// Send vars to template
$template->assign_block_vars('globalrow', array(
'FORUM_ID' => $forum_id,
'TOPIC_ID' => $topic_id,

'TOPIC_TITLE' => censor_text($post_data['topic_title']),

'U_TOPIC' => "{$phpbb_root_path}viewtopic.$phpEx?f=$forum_id&amp;t=$topic_id",
));
}
$db->sql_freeresult($result);
} //END function: grab_global_contents
carlf
New member
New member
Posts: 8
Joined: 06 Sep 2008, 01:40

Re: While loop problem

Post by carlf »

I have inserted the html code in news_body.html and uploadeded it to styles/prosilver_se/template/

I assume i need to place php code in a file called something like news_body.php and upload it to forum root?

Im a bit confused as to how the two files communicate with each other.

Thanks for any help,
Carl
User avatar
Mr. Bond
Member
Member
Posts: 89
Joined: 30 Mar 2008, 20:34
Real name: Bobby
Location: 127.0.0.1

Re: While loop problem

Post by Mr. Bond »

The php file sTraTo posted is not a full file, you'll probably want to check out some of the basic documentation - http://www.phpbb.com/mods/documentation/phpbb-documentation/template/index.php

You'll need to add the usual phpBB php file code stuff (Ripped from faq.php)

Code: Select all

<?php
/**
*
* @package phpBB3
* @version $Id: faq.php 8479 2008-03-29 00:22:48Z naderman $
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include(
$phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup(); 

// you can put code, functions etc. here :)

page_header('Your pages title');

$template->set_filenames(array(
    'body' => 'news_body.html')
);
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));

page_footer();

?>


:geek:
Twitter • Ohloh • GitHub
carlf
New member
New member
Posts: 8
Joined: 06 Sep 2008, 01:40

Re: While loop problem

Post by carlf »

Thanks, but now i am totaly confused.

I place the following code in a .php file in forum root?:

Code: Select all

$template->set_filenames(array(
   'body' => 'your_template_file.html')
);


and i place your_template_file.html in styles/template/ dir?

Thanks,
Carl
CMCDragonkai
New member
New member
Posts: 23
Joined: 06 Sep 2008, 14:59

Re: While loop problem

Post by CMCDragonkai »

Sorry if this is reviving a dead post,

(carlf, the php goes into something like index.php, and the html goes into a template file styles/template/ or whereever, see adding pages in php or google info)

I just implemented this, it worked. When I have $query_global = false

However if I leave $query_global = true

I get an error about ANNOUNCEMENT_FORUM

Code: Select all

SQL ERROR [ mysqli ]

Unknown column 'ANNOUNCEMENT_FORUM' in 'where clause' [1054]

SQL

SELECT t.*, p.*, u.* FROM (sowphpbb_topics t) LEFT JOIN sowphpbb_posts p ON (t.topic_id = p.topic_id) LEFT JOIN sowphpbb_users u ON (t.topic_poster = u.user_id) WHERE t.forum_id = ANNOUNCEMENT_FORUM AND t.topic_first_post_id = p.post_id ORDER BY t.topic_time DESC LIMIT 10



So what does this mean?

Plus, I get the forum id part, but what does this place do?

Code: Select all

$forum_id = request_var('sf', ANNOUNCEMENT_FORUM);
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor

Re: While loop problem

Post by igorw »

ANNOUNCEMENT_FORUM is a constant and needs to be defined.
CMCDragonkai
New member
New member
Posts: 23
Joined: 06 Sep 2008, 14:59

Re: While loop problem

Post by CMCDragonkai »

Oh, so that would make ANNOUNCEMENT_FORUM defined as a number? Or..?

Does it mean which forum contains the announcements? But then isn't that just the same making $query_global = false, and just specifying the number?
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: While loop problem

Post by Obsidian »

Yes, just declare the constant in the page that is using the function with the forum ID that contains the announcements.

I don't remember what the $query_global parameter was for, though... :?
/me goes to check own documentation
CMCDragonkai
New member
New member
Posts: 23
Joined: 06 Sep 2008, 14:59

Re: While loop problem

Post by CMCDragonkai »

Ok, so if the forum id was 2, and this place contained announcements, does that mean I would define ANNOUNCEMENT_FORUM as 2?
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: While loop problem

Post by Obsidian »

Exactly. ;)
CMCDragonkai
New member
New member
Posts: 23
Joined: 06 Sep 2008, 14:59

Re: While loop problem

Post by CMCDragonkai »

Cool awesome, so have you found out what $query_global is?
Post Reply