Example #1
0
 /**
  * Write single entry to DB
  * @param	array	INTS
  */
 public function getData($data = array())
 {
     if (!$this->remoteDB) {
         return;
     }
     /* Init */
     $topicData = $data['parentData'];
     $forumData = $this->registry->getClass('class_forums')->getForumById($topicData['forum_id']);
     $permissionData = $this->registry->getClass('topics')->getPermissionData();
     $first = $data['offset'];
     $end = $data['limit'];
     $fields = $this->getFields();
     /* Default - just see all visible posts */
     $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('visible', 'archive_');
     /* Can we deal with hidden posts? */
     if ($this->registry->class_forums->canQueuePosts($topicData['forum_id'])) {
         if ($permissionData['softDeleteSee']) {
             /* See queued and soft deleted */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden', 'sdeleted'), 'archive_');
         } else {
             /* Otherwise, see queued and approved */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden'), 'archive_');
         }
     } else {
         /* We cannot see hidden posts */
         if ($permissionData['softDeleteSee']) {
             /* See queued and soft deleted */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('approved', 'sdeleted'), 'archive_');
         }
     }
     /* Set up */
     /* Ignored Users */
     $ignored_users = array();
     foreach ($this->member->ignored_users as $_i) {
         if ($_i['ignore_topics']) {
             $ignored_users[] = $_i['ignore_ignore_id'];
         }
     }
     /* Format */
     $this->registry->getClass('topics')->setTopicData('adCodeSet', false);
     $this->registry->getClass('topics')->setTopicData('ignoredUsers', $ignored_users);
     $posts = array();
     $cached = array();
     /* Get posts separately */
     if (IPSLib::isUsingRemoteArchiveDB()) {
         /* Get posts */
         $this->remoteDB->build(array('select' => '*', 'from' => 'forums_archive_posts', 'where' => 'archive_topic_id=' . $topicData['tid'] . $queued_query_bit, 'order' => $fields[$data['sortKey']] . ' ' . $data['sortOrder'], 'limit' => array($first, $end)));
         $ab = $this->remoteDB->execute();
         $mids = array();
         while ($p = $this->remoteDB->fetch($ab)) {
             $posts[$p['archive_id']] = $p;
             $mids[$p['archive_author_id']] = $p['archive_author_id'];
         }
         if (count($posts)) {
             /* Get cached posts */
             $this->DB->build(array('select' => 'cache_content_id, cache_content', 'from' => 'content_cache_posts', 'where' => 'cache_content_id IN (' . implode(',', array_keys($posts)) . ')'));
             $this->DB->execute();
             while ($row = $this->DB->fetch()) {
                 $cached[$row['cache_content_id']] = $row['cache_content'];
             }
             /* Get members */
             $members = IPSMember::load($mids, 'all');
             foreach ($posts as $pid => $pdata) {
                 $pdata['member_id'] = $pdata['archive_author_id'];
                 if ($data['goNative']) {
                     $pdata = $this->archiveToNativeFields($pdata);
                 }
                 if ($pdata['author_id']) {
                     $members[$pdata['author_id']]['cache_content_sig'] = $members[$pdata['author_id']]['cache_content'];
                     unset($members[$pdata['author_id']]['cache_content']);
                     $posts[$pid] = array_merge($members[$pdata['author_id']], $pdata);
                 } else {
                     $posts[$pid] = $pdata;
                 }
                 /* Cached */
                 if (isset($cached[$pid])) {
                     $posts[$pid]['cache_content'] = $cached[$pid];
                 }
             }
         }
     } else {
         /* Joins */
         $_post_joins = array(array('select' => 'm.member_id as mid,m.name,m.member_group_id,m.email,m.joined,m.posts, m.last_visit, m.last_activity,m.login_anonymous,m.title as member_title, m.warn_level, m.warn_lastwarn, m.members_display_name, m.members_seo_name, m.has_gallery, m.has_blog, m.members_bitoptions,m.mgroup_others', 'from' => array('members' => 'm'), 'where' => 'm.member_id=a.archive_author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'm.member_id=pp.pp_member_id', 'type' => 'left'));
         /* Cache? */
         if (IPSContentCache::isEnabled()) {
             if (IPSContentCache::fetchSettingValue('post')) {
                 $_post_joins[] = IPSContentCache::join('post', 'a.archive_id');
             }
             if (IPSContentCache::fetchSettingValue('sig')) {
                 $_post_joins[] = IPSContentCache::join('sig', 'm.member_id', 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
             }
         }
         /* Get posts */
         $this->remoteDB->build(array('select' => 'a.*', 'from' => array('forums_archive_posts' => 'a'), 'where' => 'archive_topic_id=' . $topicData['tid'] . $queued_query_bit, 'order' => $fields[$data['sortKey']] . ' ' . $data['sortOrder'], 'limit' => array($first, $end), 'add_join' => $_post_joins));
         $oq = $this->remoteDB->execute();
         while ($row = $this->remoteDB->fetch($oq)) {
             $row['member_id'] = $row['archive_author_id'];
             if ($data['goNative']) {
                 $row = $this->archiveToNativeFields($row);
             }
             $posts[$row['pid']] = $row;
         }
     }
     /* Return */
     return $posts;
 }
    /**
     * BBCode add/edit form
     *
     * @param	string		Type (add|edit)
     * @param	array 		BBcode info
     * @param	array 		Sections to edit in
     * @return	string		HTML
     */
    public function bbcodeForm($type, $bbcode, $sections)
    {
        //-----------------------------------------
        // Set some of the form variables
        //-----------------------------------------
        $form_code = $type == 'edit' ? 'bbcode_doedit' : 'bbcode_doadd';
        $button = $type == 'edit' ? $this->lang->words['edit_bbcode'] : $this->lang->words['addnew_bbcode'];
        $secure_key = ipsRegistry::getClass('adminFunctions')->getSecurityKey();
        $all_groups = array(0 => array('all', $this->lang->words['all_groups']));
        foreach ($this->cache->getCache('group_cache') as $group_data) {
            $all_groups[] = array($group_data['g_id'], $group_data['g_title']);
        }
        $ss_dropdown = array(0 => array('all', $this->lang->words['available_sections']));
        if (is_array($sections) and count($sections)) {
            foreach ($sections as $sect_key => $sect_value) {
                $ss_dropdown[] = array($sect_key, $sect_value);
            }
        }
        $form = array();
        $form['bbcode_title'] = $this->registry->output->formInput('bbcode_title', $this->request['bbcode_title'] ? $this->request['bbcode_title'] : $bbcode['bbcode_title']);
        $form['bbcode_desc'] = $this->registry->output->formTextarea('bbcode_desc', $this->request['bbcode_desc'] ? $this->request['bbcode_desc'] : $bbcode['bbcode_desc']);
        $form['bbcode_example'] = $this->registry->output->formTextarea('bbcode_example', $this->request['bbcode_example'] ? $this->request['bbcode_example'] : $bbcode['bbcode_example']);
        $form['bbcode_tag'] = '[ ' . $this->registry->output->formSimpleInput('bbcode_tag', $this->request['bbcode_tag'] ? $this->request['bbcode_tag'] : $bbcode['bbcode_tag'], 10) . ' ]';
        $form['bbcode_useoption'] = $this->registry->output->formYesNo('bbcode_useoption', $this->request['bbcode_useoption'] ? $this->request['bbcode_useoption'] : $bbcode['bbcode_useoption']);
        $form['bbcode_switch_option'] = $this->registry->output->formYesNo('bbcode_switch_option', $this->request['bbcode_switch_option'] ? $this->request['bbcode_switch_option'] : $bbcode['bbcode_switch_option']);
        $form['bbcode_replace'] = $this->registry->output->formTextarea('bbcode_replace', htmlspecialchars($_POST['bbcode_replace'] ? $_POST['bbcode_replace'] : $bbcode['bbcode_replace']));
        $form['bbcode_menu_option_text'] = $this->registry->output->formSimpleInput('bbcode_menu_option_text', $this->request['bbcode_menu_option_text'] ? $this->request['bbcode_menu_option_text'] : $bbcode['bbcode_menu_option_text'], 50);
        $form['bbcode_menu_content_text'] = $this->registry->output->formSimpleInput('bbcode_menu_content_text', $this->request['bbcode_menu_content_text'] ? $this->request['bbcode_menu_content_text'] : $bbcode['bbcode_menu_content_text'], 50);
        $form['bbcode_single_tag'] = $this->registry->output->formYesNo('bbcode_single_tag', $this->request['bbcode_single_tag'] ? $this->request['bbcode_single_tag'] : $bbcode['bbcode_single_tag']);
        $form['bbcode_groups'] = $this->registry->output->formMultiDropdown("bbcode_groups[]", $all_groups, $this->request['bbcode_groups'] ? $this->request['bbcode_groups'] : explode(",", $bbcode['bbcode_groups']));
        $form['bbcode_sections'] = $this->registry->output->formMultiDropdown("bbcode_sections[]", $ss_dropdown, $this->request['bbcode_sections'] ? $this->request['bbcode_sections'] : explode(",", $bbcode['bbcode_sections']));
        $form['bbcode_php_plugin'] = $this->registry->output->formInput('bbcode_php_plugin', $this->request['bbcode_php_plugin'] ? $this->request['bbcode_php_plugin'] : $bbcode['bbcode_php_plugin']);
        $form['bbcode_no_parsing'] = $this->registry->output->formYesNo('bbcode_no_parsing', $this->request['bbcode_no_parsing'] ? $this->request['bbcode_no_parsing'] : $bbcode['bbcode_no_parsing']);
        $form['bbcode_protected'] = $this->registry->output->formYesNo('bbcode_protected', $this->request['bbcode_protected'] ? $this->request['bbcode_protected'] : $bbcode['bbcode_protected']);
        $form['bbcode_custom_regex'] = $this->registry->output->formTextarea('bbcode_custom_regex', htmlspecialchars($_POST['bbcode_custom_regex'] ? $_POST['bbcode_custom_regex'] : $bbcode['bbcode_custom_regex']));
        $apps = array();
        /* Application drop down options */
        foreach (ipsRegistry::$applications as $app_dir => $app_data) {
            $apps[] = array($app_dir, $app_data['app_title']);
        }
        $form['bbcode_app'] = $this->registry->output->formDropdown('bbcode_app', $apps, $this->request['bbcode_app'] ? $this->request['bbcode_app'] : $bbcode['bbcode_app']);
        $form['bbcode_optional_option'] = $this->registry->output->formYesNo('bbcode_optional_option', $this->request['bbcode_optional_option'] ? $this->request['bbcode_optional_option'] : $bbcode['bbcode_optional_option']);
        $form['bbcode_aliases'] = $this->registry->output->formTextarea('bbcode_aliases', $this->request['bbcode_aliases'] ? $this->request['bbcode_aliases'] : $bbcode['bbcode_aliases']);
        $form['bbcode_image'] = $this->registry->output->formInput('bbcode_image', $this->request['bbcode_image'] ? $this->request['bbcode_image'] : $bbcode['bbcode_image']);
        /* Content cache is enabled? */
        if ($type == 'edit' and IPSContentCache::isEnabled()) {
            $_cacheCount = IPSContentCache::count();
            $form['drop_cache'] = $this->registry->output->formYesNo('drop_cache', $this->request['drop_cache']);
            $this->lang->words['bbcache_action'] = sprintf($this->lang->words['bbcache_action'], $_cacheCount);
        }
        $IPBHTML = "";
        //--starthtml--//
        $IPBHTML .= <<<EOF

<div class='section_title'>
\t<h2>{$this->lang->words['custom_bbcode_head']}</h2>
</div>

<form action='{$this->settings['base_url']}&amp;{$this->form_code}&amp;do={$form_code}&amp;secure_key={$secure_key}' method='post'>
<input type='hidden' name='id' value='{$bbcode['bbcode_id']}' />
EOF;
        if ($form['drop_cache']) {
            $IPBHTML .= <<<EOF

\t\t<div class='warning'>
\t\t <h4>{$this->lang->words['bbcache_title']}</h4>
\t\t {$this->lang->words['bbcache_desc']}
\t\t<p><strong>{$this->lang->words['bbcache_action']}</strong> {$form['drop_cache']}</p>
\t\t</div>
\t\t<br />
EOF;
        }
        $IPBHTML .= <<<EOF

<div class="acp-box">
\t<h3>{$button}</h3>
\t<table class='ipsTable double_pad'>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_title']}</span></td>
\t\t\t<td class='field_field'>{$form['bbcode_title']}</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_description']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_desc']} <br /><span class='desctext'>{$this->lang->words['bbcode_usedinguide']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_example']}</strong>
\t\t\t<td class='field_field'>{$form['bbcode_example']}<span class='desctext'>{$this->lang->words['bbcode_usedinguide']}<br />{$this->lang->words['bbcode_example_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_tag']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_tag']} <br /><span class='desctext'>{$this->lang->words['bbcode_tag_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_aliases']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_aliases']} <br /><span class='desctext'>{$this->lang->words['bbcode_aliases_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_singletag']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_single_tag']} <br /><span class='desctext'>{$this->lang->words['bbcode_singletag_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_useoption']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_useoption']} <br /><span class='desctext'>{$this->lang->words['bbcode_useoption_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_customregex']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_custom_regex']} <br /><span class='desctext'>{$this->lang->words['bbcode_customregex_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_optional']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_optional_option']} <br /><span class='desctext'>{$this->lang->words['bbcode_optional_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_switch']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_switch_option']} <br /><span class='desctext'>{$this->lang->words['bbcode_switch_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_noparse']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_no_parsing']} <br /><span class='desctext'>{$this->lang->words['bbcode_noparse_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_replace']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_replace']} <br /><span class='desctext'>{$this->lang->words['bbcode_replace_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_php']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_php_plugin']}<br /><span class='desctext'>{$this->lang->words['bbcode_php_info_loc']} <br />{$this->lang->words['bbcode_php_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_groups']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_groups']} <br /><span class='desctext'>{$this->lang->words['bbcode_groups_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_whereused']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_sections']} <br /><span class='desctext'>{$this->lang->words['bbcode_whereused_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_assoc_app']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_app']}</td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_image']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_image']}<br /> <span class='desctext'>{$this->lang->words['bbcode_image_info_loc']} <br />{$this->lang->words['bbcode_image_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_optdial']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_menu_option_text']} <br /><span class='desctext'>{$this->lang->words['bbcode_optdial_info']}</span></td>
\t\t</tr>
\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_contdial']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_menu_content_text']} <br /><span class='desctext'>{$this->lang->words['bbcode_contdial_info']}</span></td>
\t\t</tr>
EOF;
        if (IN_DEV) {
            $IPBHTML .= <<<EOF

\t\t<tr>
\t\t\t<td class='field_title'><strong class='title'>{$this->lang->words['bbcode_protected']}</strong></td>
\t\t\t<td class='field_field'>{$form['bbcode_protected']} <br /><span class='desctext'>{$this->lang->words['bbcode_protected_info']}</span></td>
\t\t</tr>
EOF;
        }
        $IPBHTML .= <<<EOF

\t</table>
\t<div class="acp-actionbar">
\t\t<input type='submit' value='{$button}' class="button primary" />
\t</div>
</div>\t
</form>
EOF;
        //--endhtml--//
        return $IPBHTML;
    }
Example #3
0
 /**
  * Formats / grabs extra data for results
  * Takes an array of IDS (can be IDs from anything) and returns an array of expanded data.
  *
  * @param	array 	$ids			Ids
  * @param	array	$followData		Retrieve the follow meta data
  * @return array
  */
 public function processResults($ids, $followData = array())
 {
     /* INIT */
     $sort_by = IPSSearchRegistry::get('in.search_sort_by');
     $sort_order = IPSSearchRegistry::get('in.search_sort_order');
     $search_term = IPSSearchRegistry::get('in.clean_search_term');
     $content_title_only = IPSSearchRegistry::searchTitleOnly();
     $_post_joins = array();
     $members = array();
     $results = array();
     $topicIds = array();
     $dots = array();
     $sortKey = '';
     $sortType = '';
     $_sdTids = array();
     $_sdPids = array();
     /* Set up some basic permissions */
     $permissions['PostSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedPosts(0);
     $permissions['TopicSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedTopics(0);
     $permissions['canQueue'] = $this->registry->getClass('class_forums')->canQueuePosts(0);
     $permissions['SoftDeleteReason'] = $this->registry->getClass('class_forums')->canSeeSoftDeleteReason(0);
     $permissions['SoftDeleteContent'] = $this->registry->getClass('class_forums')->canSeeSoftDeleteContent(0);
     $permissions['PostSoftDeleteRestore'] = $this->registry->getClass('class_forums')->can_Un_SoftDeletePosts(0);
     $permissions['TopicSoftDeleteRestore'] = $this->registry->getClass('class_forums')->can_Un_SoftDeleteTopics(0);
     /* Got some? */
     if (count($ids)) {
         /* Cache? */
         if (IPSContentCache::isEnabled()) {
             if (IPSContentCache::fetchSettingValue('post')) {
                 $_post_joins[] = IPSContentCache::join('post', 'p.' . $this->table['pid']);
             }
             if (IPSContentCache::fetchSettingValue('sig')) {
                 $_post_joins[] = IPSContentCache::join('sig', 'p.' . $this->table['author_id'], 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
             }
         }
         if ($this->registry->tags->isEnabled()) {
             $_post_joins[] = $this->registry->tags->getCacheJoin(array('meta_id_field' => 't.tid'));
         }
         /* Sorting */
         switch ($sort_by) {
             default:
             case 'date':
                 $sortKey = IPSSearchRegistry::get('set.returnType') == 'tids' ? 'last_post' : $this->table['post_date'];
                 $sortType = 'numerical';
                 break;
             case 'title':
                 $sortKey = 'title';
                 $sortType = 'string';
                 break;
             case 'posts':
                 $sortKey = 'posts';
                 $sortType = 'numerical';
                 break;
             case 'views':
                 $sortKey = 'views';
                 $sortType = 'numerical';
                 break;
         }
         /* Set vars */
         IPSSearch::$ask = $sortKey;
         IPSSearch::$aso = strtolower($sort_order);
         IPSSearch::$ast = $sortType;
         /* If we are search in titles only, then the ID array will be TIDs */
         if (IPSSearchRegistry::get('set.returnType') == 'tids') {
             $k = 'tid';
             $this->DB->build(array('select' => "t.*", 'from' => array('topics' => 't'), 'where' => 't.tid IN( ' . implode(',', $ids) . ')', 'add_join' => array_merge(array(array('select' => 'p.*', 'from' => array($this->table['_table_'] => 'p'), 'where' => 'p.' . $this->table['pid'] . '=t.topic_firstpost', 'type' => 'left'), array('select' => 'm.member_id, m.members_display_name, m.members_seo_name', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.' . $this->table['author_id'], 'type' => 'left')), $_post_joins)));
         } else {
             $k = $this->table['pid'];
             $this->DB->build(array('select' => "p.*", 'from' => array($this->table['_table_'] => 'p'), 'where' => 'p.' . $this->table['pid'] . ' IN( ' . implode(',', $ids) . ')', 'add_join' => array_merge(array(array('select' => 't.*', 'from' => array('topics' => 't'), 'where' => 't.tid=p.' . $this->table['topic_id'], 'type' => 'left'), array('select' => 'm.member_id, m.members_display_name, m.members_seo_name', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.' . $this->table['author_id'], 'type' => 'left')), $_post_joins)));
         }
         /* Grab data */
         $this->DB->execute();
         /* Grab the results */
         while ($row = $this->DB->fetch()) {
             $_rows[$row[$k]] = $this->searchArchives ? $this->archiveReader->archiveToNativeFields($row) : $row;
         }
         /* Get the 'follow' meta data? */
         if (count($followData)) {
             $followData = classes_like_meta::get($followData);
             /* Merge the data from the follow class into the results */
             foreach ($followData as $_formatted) {
                 $_rows[$_formatted['like_rel_id']]['_followData'] = $_formatted;
             }
         }
         /* Sort */
         if (count($_rows)) {
             usort($_rows, array("IPSSearch", "usort"));
             foreach ($_rows as $id => $row) {
                 /* Prevent member from stepping on it */
                 $row['topic_title'] = $row['title'];
                 /* Get author data? */
                 if ($k == 'tid') {
                     if (!empty($row['last_poster_id'])) {
                         $members[$row['last_poster_id']] = $row['last_poster_id'];
                     }
                 } else {
                     if (!empty($row['author_id'])) {
                         $members[$row['author_id']] = $row['author_id'];
                     }
                 }
                 /* Topic ids? */
                 if (!empty($row['topic_id'])) {
                     $topicIds[$row['topic_id']] = $row['topic_id'];
                 }
                 /* If we're using sphinx, check forum permissions again as the 15 minute delta rebuild could expose a moved topic before deltas rebuild.
                    We don't need to do this for SQL search as the results are delivered live and lets face it, we can do without the load  */
                 if ($this->settings['search_method'] != 'traditional') {
                     /* Can we read? */
                     if (!$this->registry->permissions->check('view', $this->registry->class_forums->forum_by_id[$row['forum_id']])) {
                         continue;
                     }
                     /* Can read, but is it password protected, etc? */
                     if (!$this->registry->class_forums->forumsCheckAccess($row['forum_id'], 0, 'forum', array(), true)) {
                         continue;
                     }
                 }
                 $row['cleanSearchTerm'] = urlencode($search_term);
                 $row['topicPrefix'] = $row['pinned'] ? $this->registry->getClass('output')->getTemplate('forum')->topicPrefixWrap($this->lang->words['pre_pinned']) : '';
                 $row['_isVisible'] = $this->registry->getClass('class_forums')->fetchHiddenTopicType($row) == 'visible' ? true : false;
                 $row['_isHidden'] = $this->registry->getClass('class_forums')->fetchHiddenTopicType($row) == 'hidden' ? true : false;
                 $row['_isDeleted'] = $this->registry->getClass('class_forums')->fetchHiddenTopicType($row) == 'sdelete' ? true : false;
                 $row['_p_isVisible'] = $this->registry->getClass('class_forums')->fetchHiddenType($row) == 'visible' ? true : false;
                 $row['_p_isHidden'] = $this->registry->getClass('class_forums')->fetchHiddenType($row) == 'hidden' ? true : false;
                 $row['_p_isDeleted'] = $this->registry->getClass('class_forums')->fetchHiddenType($row) == 'sdelete' ? true : false;
                 /* Hidden and we do not have permission? */
                 if ($row['_isHidden'] and !$permissions['canQueue']) {
                     continue;
                 }
                 /* Is the topic deleted? If so, then the first post will appear as such */
                 if ($row['_isDeleted'] and $permissions['TopicSoftDeleteSee']) {
                     $row['_p_isDeleted'] = true;
                     $_sdPids[$row['pid']] = $row['pid'];
                 }
                 /* Collect TIDS of soft deleted topics */
                 if ($row['_isDeleted']) {
                     if ($permissions['TopicSoftDeleteSee']) {
                         $_sdTids[$row['tid']] = $row['tid'];
                     } else {
                         continue;
                     }
                 }
                 /* Collect TIDS of soft deleted topics */
                 if ($row['_p_isDeleted']) {
                     if ($permissions['PostSoftDeleteSee']) {
                         $_sdPids[$row['pid']] = $row['pid'];
                     } else {
                         continue;
                     }
                 }
                 /* Tags */
                 if (!empty($row['tag_cache_key'])) {
                     $row['tags'] = $this->registry->tags->formatCacheJoinData($row);
                 }
                 $results[$k == 'tid' ? $row['tid'] : $row['pid']] = $this->genericizeResults($row);
             }
         }
         /* Need to load members? */
         if (count($members)) {
             $mems = IPSMember::load($members, 'all');
             $mems[0] = array();
             foreach ($results as $id => $r) {
                 $_memberIdColumn = IPSSearchRegistry::get('set.returnType') == 'tids' ? 'last_poster_id' : 'author_id';
                 if (isset($mems[$r[$_memberIdColumn]])) {
                     $mems[$r[$_memberIdColumn]]['m_posts'] = $mems[$r[$_memberIdColumn]]['posts'];
                     unset($mems[$r[$_memberIdColumn]]['last_post']);
                     if (isset($r['cache_content_sig'])) {
                         $mems[$r[$_memberIdColumn]]['cache_content'] = $r['cache_content_sig'];
                         $mems[$r[$_memberIdColumn]]['cache_updated'] = $r['cache_updated_sig'];
                     }
                     $_mem = IPSMember::buildDisplayData($mems[$r[$_memberIdColumn]], array('reputation' => 0, 'warn' => 0));
                     unset($_mem['cache_content'], $_mem['cache_updated']);
                     $results[$id]['_realPosts'] = $results[$id]['posts'];
                     $results[$id] = array_merge($results[$id], $_mem);
                     $results[$id]['posts'] = $results[$id]['_realPosts'];
                 }
             }
         }
         /* Generate 'dot' folder icon */
         if ($this->settings['show_user_posted'] and count($topicIds)) {
             $_queued = $this->registry->class_forums->fetchPostHiddenQuery(array('visible'), '');
             $this->DB->build(array('select' => 'author_id, topic_id', 'from' => 'posts', 'where' => $_queued . ' AND author_id=' . $this->memberData['member_id'] . ' AND topic_id IN(' . implode(',', $topicIds) . ')'));
             $this->DB->execute();
             while ($p = $this->DB->fetch()) {
                 $dots[$p['topic_id']] = 1;
             }
             /* Merge into results */
             foreach ($results as $id => $r) {
                 if (isset($dots[$r['topic_id']])) {
                     $results[$id]['_hasPosted'] = 1;
                 }
             }
         }
         /* Got any deleted items */
         if (count($_sdTids)) {
             $sData = IPSDeleteLog::fetchEntries($_sdTids, 'topic', false);
             if (count($sData)) {
                 foreach ($results as $id => $data) {
                     if (isset($_sdTids[$data['tid']])) {
                         $results[$id]['sData'] = $sData[$data['tid']];
                         $results[$id]['permissions'] = $permissions;
                     }
                 }
             }
         }
         /* Got any deleted items */
         if (count($_sdPids)) {
             $sData = IPSDeleteLog::fetchEntries($_sdPids, 'post', false);
             if (count($sData)) {
                 foreach ($results as $id => $data) {
                     if (isset($_sdPids[$data['pid']]) and !isset($results[$id]['sData'])) {
                         $results[$id]['sData'] = $sData[$data['pid']];
                         $results[$id]['permissions'] = $permissions;
                     }
                 }
             }
         }
     }
     return $results;
 }
Example #4
0
 /**
  * List all of the current caches
  *
  * @return	@e void		[Outputs to screen]
  */
 public function cacheOverview()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $content = "";
     $db_caches = array();
     $lib_caches = array();
     $cacheContent = array();
     $total = 0;
     //-----------------------------------------
     // Get stored caches
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'cache_store'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $db_caches[$r['cs_key']] = $r;
     }
     //-----------------------------------------
     // Get core cache list
     //-----------------------------------------
     foreach ($this->registry->_fetchCoreVariables('cache') as $cache_name => $cache_data) {
         $cache_data['cache_name'] = $cache_name;
         $cache_data['_cache_size'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value'])));
         $cache_data['_cs_init_load'] = $db_caches[$cache_name]['cs_init_load'];
         $total += IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value']));
         $lib_caches['global'][$cache_name] = $cache_data;
     }
     //-----------------------------------------
     // Get all application's cache lists
     //-----------------------------------------
     foreach (IPSLib::getEnabledApplications() as $app_dir => $app_data) {
         $_file = IPSLib::getAppDir($app_dir) . '/extensions/coreVariables.php';
         if (is_file($_file)) {
             $CACHE = array();
             require $_file;
             /*maybeLibHook*/
             foreach ($CACHE as $cache_name => $cache_data) {
                 $cache_data['cache_name'] = $cache_name;
                 $cache_data['_cache_size'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value'])));
                 $cache_data['_cs_init_load'] = $db_caches[$cache_name]['cs_init_load'];
                 $total += IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value']));
                 $lib_caches[$app_dir][$cache_name] = $cache_data;
             }
         }
     }
     foreach ($lib_caches as $app => $data) {
         ksort($lib_caches[$app]);
     }
     $total = IPSLib::sizeFormat($total);
     /* Content Cache Stuffs */
     if (IPSContentCache::isEnabled()) {
         /* Get all posts */
         $statsCache = ipsRegistry::cache()->getCache('stats');
         $cacheContent['posts'] = array('count' => intval($statsCache['total_replies'] + $statsCache['total_topics']));
         /* Get all members */
         $cacheContent['members'] = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'members'));
         /* Get cached post count */
         $cacheContent['cachedPosts'] = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'content_cache_posts'));
         /* Get cached sig count */
         $cacheContent['cachedSigs'] = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'content_cache_sigs'));
         /* Work out percentages */
         $cacheContent['postPercent'] = ($cacheContent['posts']['count'] and $cacheContent['cachedPosts']['count']) ? sprintf("%.0f", $cacheContent['cachedPosts']['count'] / $cacheContent['posts']['count'] * 100) : 0;
         $cacheContent['sigPercent'] = ($cacheContent['members']['count'] and $cacheContent['cachedSigs']['count']) ? sprintf("%.0f", $cacheContent['cachedSigs']['count'] / $cacheContent['members']['count'] * 100) : 0;
     }
     $this->registry->output->html .= $this->html->cache_entry_wrapper($lib_caches, $total, $cacheContent);
 }
 /**
  * Get Linear Topic Data
  *
  * @access	public
  * @return	array
  **/
 public function _getTopicDataLinear()
 {
     //-----------------------------------------
     // Grab the posts we'll need
     //-----------------------------------------
     $first = intval($this->request['st']) >= 0 ? intval($this->request['st']) : 0;
     $pc_join = array();
     if ($this->settings['post_order_column'] != 'post_date') {
         $this->settings['post_order_column'] = 'pid';
     }
     if ($this->settings['post_order_sort'] != 'desc') {
         $this->settings['post_order_sort'] = 'asc';
     }
     if ($this->settings['au_cutoff'] == "") {
         $this->settings['au_cutoff'] = 15;
     }
     //-----------------------------------------
     // Moderator?
     //-----------------------------------------
     $queued_query_bit = ' and queued=0';
     if ($this->registry->class_forums->canQueuePosts($this->topic['forum_id'])) {
         $queued_query_bit = '';
         if ($this->request['modfilter'] and $this->request['modfilter'] == 'invisible_posts') {
             $queued_query_bit = ' and queued=1';
         }
     }
     //-----------------------------------------
     // Using "new" mode?
     //-----------------------------------------
     if ($this->topic_view_mode == 'linearplus' and $this->topic['topic_firstpost']) {
         $this->topic['new_mode_start'] = $first + 1;
         if ($first) {
             $this->topic['new_mode_start']--;
         }
         if ($first + $this->settings['display_max_posts'] > $this->topic['posts'] + 1) {
             $this->topic['new_mode_end'] = $this->topic['posts'];
         } else {
             $this->topic['new_mode_end'] = $first + ($this->settings['display_max_posts'] - 1);
         }
         if ($first) {
             $this->pids = array(0 => $this->topic['topic_firstpost']);
         }
         //-----------------------------------------
         // Get PIDS of this page/topic
         //-----------------------------------------
         $this->DB->build(array('select' => 'pid,topic_id', 'from' => 'posts', 'where' => 'topic_id=' . $this->topic['tid'] . $queued_query_bit, 'order' => 'pid asc', 'limit' => array($first, $this->settings['display_max_posts'])));
         $this->DB->execute();
         while ($p = $this->DB->fetch()) {
             $this->pids[$p['pid']] = $p['pid'];
         }
     } else {
         //-----------------------------------------
         // Run query
         //-----------------------------------------
         $this->topic_view_mode = 'linear';
         # We don't need * but if we don't use it, it won't use the correct index
         $this->DB->build(array('select' => 'pid', 'from' => 'posts', 'where' => 'topic_id=' . $this->topic['tid'] . $queued_query_bit, 'order' => $this->settings['post_order_column'] . ' ' . $this->settings['post_order_sort'], 'limit' => array($first, $this->settings['display_max_posts'])));
         $this->DB->execute();
         while ($p = $this->DB->fetch()) {
             $this->pids[$p['pid']] = $p['pid'];
         }
     }
     //-----------------------------------------
     // Do we have any PIDS?
     //-----------------------------------------
     if (!count($this->pids)) {
         if ($first) {
             //-----------------------------------------
             // Add dummy PID, AUTO FIX
             // will catch this below...
             //-----------------------------------------
             $this->pids[] = 0;
         }
         if ($this->request['modfilter'] == 'invisible_posts') {
             $this->pids[] = 0;
         }
     }
     //-----------------------------------------
     // Attachment PIDS
     //-----------------------------------------
     $this->attach_pids = $this->pids;
     //-----------------------------------------
     // Fail safe
     //-----------------------------------------
     if (!is_array($this->pids) or !count($this->pids)) {
         $this->pids = array(0 => 0);
     }
     //-----------------------------------------
     // Joins
     //-----------------------------------------
     $_post_joins = array(array('select' => 'm.member_id as mid,m.name,m.member_group_id,m.email,m.joined,m.posts, m.last_visit, m.last_activity,m.login_anonymous,m.title,m.hide_email, m.warn_level, m.warn_lastwarn, m.members_display_name, m.members_seo_name, m.has_gallery, m.has_blog, m.members_bitoptions', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'm.member_id=pp.pp_member_id', 'type' => 'left'), array('select' => 'g.g_access_cp', 'from' => array('groups' => 'g'), 'where' => 'g.g_id=m.member_group_id', 'type' => 'left'));
     /* Add custom fields join? */
     if ($this->settings['custom_profile_topic'] == 1) {
         $_post_joins[] = array('select' => 'pc.*', 'from' => array('pfields_content' => 'pc'), 'where' => 'pc.member_id=p.author_id', 'type' => 'left');
     }
     /* Reputation system enabled? */
     if ($this->settings['reputation_enabled']) {
         /* Add the join to figure out if the user has already rated the post */
         $_post_joins[] = $this->registry->repCache->getUserHasRatedJoin('pid', 'p.pid', 'forums');
         /* Add the join to figure out the total ratings for each post */
         if ($this->settings['reputation_show_content']) {
             $_post_joins[] = $this->registry->repCache->getTotalRatingJoin('pid', 'p.pid', 'forums');
         }
     }
     /* Cache? */
     if (IPSContentCache::isEnabled()) {
         if (IPSContentCache::fetchSettingValue('post')) {
             $_post_joins[] = IPSContentCache::join('post', 'p.pid');
         }
         if (IPSContentCache::fetchSettingValue('sig')) {
             $_post_joins[] = IPSContentCache::join('sig', 'm.member_id', 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
         }
     }
     /* Ignored Users */
     $ignored_users = array();
     foreach ($this->member->ignored_users as $_i) {
         if ($_i['ignore_topics']) {
             $ignored_users[] = $_i['ignore_ignore_id'];
         }
     }
     //-----------------------------------------
     // Get posts
     //-----------------------------------------
     $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN(" . implode(',', $this->pids) . ")", 'order' => $this->settings['post_order_column'] . ' ' . $this->settings['post_order_sort'], 'add_join' => $_post_joins));
     $oq = $this->DB->execute();
     if (!$this->DB->getTotalRows()) {
         if ($first >= $this->settings['display_max_posts']) {
             //-----------------------------------------
             // AUTO FIX: Get the correct number of replies...
             //-----------------------------------------
             $this->DB->build(array('select' => 'COUNT(*) as pcount', 'from' => 'posts', 'where' => "topic_id=" . $this->topic['tid'] . " and queued !=1"));
             $newq = $this->DB->execute();
             $pcount = $this->DB->fetch($newq);
             $pcount['pcount'] = $pcount['pcount'] > 0 ? $pcount['pcount'] - 1 : 0;
             //-----------------------------------------
             // Update the post table...
             //-----------------------------------------
             if ($pcount['pcount'] > 1) {
                 $this->DB->update('topics', array('posts' => $pcount['pcount']), "tid=" . $this->topic['tid']);
             }
             $this->registry->output->silentRedirect($this->settings['base_url'] . "showtopic={$this->topic['tid']}&view=getlastpost");
         }
     }
     //-----------------------------------------
     // Render the page top
     //-----------------------------------------
     $this->topic['go_new'] = isset($this->topic['go_new']) ? $this->topic['go_new'] : '';
     //-----------------------------------------
     // Format and print out the topic list
     //-----------------------------------------
     $post_data = array();
     while ($row = $this->DB->fetch($oq)) {
         $row['member_id'] = $row['mid'];
         $return = $this->parsePostRow($row);
         $poster = $return['poster'];
         $row = $return['row'];
         $poster['member_id'] = $poster['mid'];
         /* Reputation */
         if ($this->settings['reputation_enabled']) {
             $row['pp_reputation_points'] = $row['pp_reputation_points'] ? $row['pp_reputation_points'] : 0;
             $row['has_given_rep'] = $row['has_given_rep'] ? $row['has_given_rep'] : 0;
             $row['rep_points'] = $row['rep_points'] ? $row['rep_points'] : 0;
         }
         $post_data[$row['pid']] = array('post' => $row, 'author' => $poster);
         //-----------------------------------------
         // Are we giving this bloke a good ignoring?
         //-----------------------------------------
         if (isset($ignored_users) && is_array($ignored_users) && count($ignored_users)) {
             if (in_array($poster['member_id'], $ignored_users)) {
                 if (!strstr($this->settings['cannot_ignore_groups'], ',' . $poster['member_group_id'] . ',')) {
                     $post_data[$row['pid']]['post']['_ignored'] = 1;
                     continue;
                 }
             }
         }
         //-----------------------------------------
         // What about rep, are we ignoring?
         //-----------------------------------------
         $this->memberData['_members_cache']['rep_filter'] = isset($this->memberData['_members_cache']['rep_filter']) ? $this->memberData['_members_cache']['rep_filter'] : false;
         if ($this->settings['reputation_enabled']) {
             if (!($this->settings['reputation_protected_groups'] && in_array($this->memberData['member_group_id'], explode(',', $this->settings['reputation_protected_groups']))) && $this->memberData['_members_cache']['rep_filter'] != '*') {
                 if ($this->settings['reputation_show_content'] && $post_data[$row['pid']]['post']['rep_points'] < $this->memberData['_members_cache']['rep_filter']) {
                     $post_data[$row['pid']]['post']['_repignored'] = 1;
                 }
             }
         }
         //-----------------------------------------
         // Show end first post
         //-----------------------------------------
         if ($this->topic_view_mode == 'linearplus' and $this->first_printed == 0 and $row['pid'] == $this->topic['topic_firstpost'] and $this->topic['posts'] > 0) {
             $post_data[$row['pid']]['post']['_end_first_post'] = 1;
         }
         $post_data[$row['pid']]['post']['rep_points'] = $post_data[$row['pid']]['post']['rep_points'] ? $post_data[$row['pid']]['post']['rep_points'] : 0;
     }
     //-----------------------------------------
     // Print the footer
     //-----------------------------------------
     return $post_data;
 }
Example #6
0
 /**
  * Feturn HTML block
  *
  * @param	array		Member information
  * @return	string		HTML block
  */
 public function return_html_block($member = array())
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $content = '';
     $last_x = 5;
     $forumIdsOk = array(0 => 0);
     $date_cut = '';
     //-----------------------------------------
     // Got a member?
     //-----------------------------------------
     if (!is_array($member) or !count($member)) {
         return $this->registry->getClass('output')->getTemplate('profile')->tabNoContent('err_no_posts_to_show');
     }
     //-----------------------------------------
     // Some words
     //-----------------------------------------
     $this->registry->class_localization->loadLanguageFile(array('public_topic'), 'forums');
     //-----------------------------------------
     // Can view other member's topics?
     //-----------------------------------------
     if (!$this->memberData['g_other_topics'] and $this->memberData['member_id'] != $member['member_id']) {
         return $this->registry->getClass('output')->getTemplate('profile')->tabNoContent('err_no_posts_to_show');
     }
     /* Get list of good forum IDs */
     $forumIdsOk = $this->registry->class_forums->fetchSearchableForumIds();
     //-----------------------------------------
     // Get last X posts
     //-----------------------------------------
     if (is_array($forumIdsOk) and count($forumIdsOk)) {
         /* Init vars */
         $pids = array();
         $parseAttachments = false;
         /* Set up joins */
         $_post_joins = array(array('select' => 't.*', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'), array('select' => 'm.member_group_id, m.mgroup_others', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id', 'type' => 'left'));
         /* Cache? */
         if (IPSContentCache::isEnabled()) {
             if (IPSContentCache::fetchSettingValue('post')) {
                 $_post_joins[] = IPSContentCache::join('post', 'p.pid');
             }
         }
         if ($this->settings['search_ucontent_days']) {
             $_date_cut = ($member['last_post'] ? $member['last_post'] : time()) - 86400 * intval($this->settings['search_ucontent_days']);
             $date_cut = ' AND p.post_date > ' . $_date_cut;
         }
         $_queued = $this->registry->class_forums->fetchPostHiddenQuery(array('visible'), 'p.');
         $_approved = $this->registry->getClass('class_forums')->fetchTopicHiddenQuery(array('visible'), 't.');
         /* Let's just run this if the member has posted within the cutoff period */
         if ($member['last_post'] > $_date_cut) {
             $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => $_queued . " AND " . $_approved . " AND p.author_id={$member['member_id']} AND p.new_topic=0 AND t.forum_id IN (" . implode(",", $forumIdsOk) . ") " . $date_cut, 'order' => 'p.pid DESC', 'limit' => array(0, $last_x), 'add_join' => $_post_joins));
             $o = $this->DB->execute();
             while ($row = $this->DB->fetch($o)) {
                 $pids[$row['pid']] = $row['pid'];
                 if ($row['topic_hasattach']) {
                     $parseAttachments = true;
                 }
                 if (!$row['cache_content']) {
                     IPSText::getTextClass('bbcode')->parse_smilies = $row['use_emo'];
                     IPSText::getTextClass('bbcode')->parse_html = ($row['use_html'] and $this->caches['group_cache'][$row['member_group_id']]['g_dohtml'] and $row['post_htmlstate']) ? 1 : 0;
                     IPSText::getTextClass('bbcode')->parse_nl2br = $row['post_htmlstate'] == 2 ? 1 : 0;
                     IPSText::getTextClass('bbcode')->parse_bbcode = 1;
                     IPSText::getTextClass('bbcode')->parsing_section = 'topics';
                     IPSText::getTextClass('bbcode')->parsing_mgroup = $row['member_group_id'];
                     IPSText::getTextClass('bbcode')->parsing_mgroup_others = $row['mgroup_others'];
                     $row['post'] = IPSText::getTextClass('bbcode')->preDisplayParse($row['post']);
                     IPSContentCache::update($row['pid'], 'post', $row['post']);
                 } else {
                     $row['post'] = $row['cache_content'];
                 }
                 $row['_post_date'] = ipsRegistry::getClass('class_localization')->getDate($row['post_date'], 'SHORT');
                 $row['_raw_date'] = $row['post_date'];
                 $row['_date_array'] = IPSTime::date_getgmdate($row['post_date'] + ipsRegistry::getClass('class_localization')->getTimeOffset());
                 $row['post'] .= "\n<!--IBF.ATTACHMENT_" . $row['pid'] . "-->";
                 $url = $this->registry->output->buildSEOUrl("showtopic={$row['topic_id']}&amp;view=findpost&amp;p={$row['pid']}", 'public', $row['title_seo'], 'showtopic');
                 $content .= $this->registry->getClass('output')->getTemplate('profile')->tabSingleColumn($row, $this->lang->words['profile_read_topic'], $url, $this->lang->words['profile_in_topic'] . $row['title']);
             }
             //-----------------------------------------
             // Attachments (but only if necessary)
             //-----------------------------------------
             if ($parseAttachments and !is_object($this->class_attach)) {
                 $classToLoad = IPSLib::loadLibrary(IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php', 'class_attach');
                 $this->class_attach = new $classToLoad($this->registry);
                 $this->class_attach->type = 'post';
                 $this->class_attach->init();
                 if (IPSMember::checkPermissions('download') === false) {
                     $this->settings['show_img_upload'] = 0;
                 }
                 $content = $this->class_attach->renderAttachments($content, $pids);
                 $content = $content[0]['html'];
             }
             //-----------------------------------------
             // Macros...
             //-----------------------------------------
             $content = $this->registry->output->replaceMacros($content);
         }
     }
     //-----------------------------------------
     // Return content..
     //-----------------------------------------
     return $content ? $this->registry->getClass('output')->getTemplate('profile')->tabPosts($content) : $this->registry->getClass('output')->getTemplate('profile')->tabNoContent('err_no_posts_to_show');
 }
 /**
  * Load member
  *
  * @param 	string	Member key: Either ID or email address OR array of IDs when $key_type is either ID or not set OR a list of $key_type strings (email address, name, etc)
  * @param 	string	Extra tables to load(all, none or comma delisted tables) Tables: members, pfields_content, profile_portal, groups, sessions, core_item_markers_storage, members_partial.
  *					You can also use the aliases: 'extendedProfile', 'customFields' and 'itemMarkingStorage'
  * @param	string  Key type. Leave it blank to auto-detect or specify "id", "email", "username", "displayname".
  * @return	array   Array containing member data
  * <code>
  * # Single member
  * $member = IPSMember::load( 1, 'extendedProfile,groups' );
  * $member = IPSMember::load( '*****@*****.**', 'all' );
  * $member = IPSMember::load( 'MattM', 'all', 'displayname' ); // Can also use 'username', 'email' or 'id'
  * # Multiple members
  * $members = IPSMember::load( array( 1, 2, 10 ), 'all' );
  * $members = IPSMember::load( array( 'MattM, 'JoeD', 'DaveP' ), 'all', 'displayname' );
  * </code>
  */
 public static function load($member_key, $extra_tables = 'all', $key_type = '')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $member_value = 0;
     $members = array();
     $multiple_ids = array();
     $member_field = '';
     $joins = array();
     $tables = array('pfields_content' => 0, 'profile_portal' => 0, 'groups' => 0, 'sessions' => 0, 'members_partial' => 0);
     $remap = array('extendedProfile' => 'profile_portal', 'customFields' => 'pfields_content');
     //-----------------------------------------
     // ID or email?
     //-----------------------------------------
     if (!$key_type) {
         if (is_array($member_key)) {
             $multiple_ids = array_map('intval', $member_key);
             // Bug #20908
             $member_field = 'member_id';
         } else {
             if (strstr($member_key, '@')) {
                 if (strstr($member_key, ' ')) {
                     $member_key = '';
                 }
                 $member_key = IPSText::mbsubstr($member_key, 0, 150);
                 $member_value = "'" . ipsRegistry::DB()->addSlashes(strtolower($member_key)) . "'";
                 $member_field = 'email';
             } else {
                 $member_value = intval($member_key);
                 $member_field = 'member_id';
             }
         }
     } else {
         switch ($key_type) {
             default:
             case 'id':
                 if (is_array($member_key)) {
                     $multiple_ids = $member_key;
                 } else {
                     $member_value = intval($member_key);
                 }
                 $member_field = 'member_id';
                 break;
             case 'fb_uid':
                 if (is_array($member_key)) {
                     $multiple_ids = $member_key;
                 } else {
                     $member_value = is_numeric($member_key) ? $member_key : 0;
                 }
                 $member_field = 'fb_uid';
                 if ($member_value == 0) {
                     return array();
                 }
                 break;
             case 'twitter_id':
                 if (is_array($member_key)) {
                     $multiple_ids = $member_key;
                 } else {
                     $member_value = is_numeric($member_key) ? $member_key : 0;
                 }
                 $member_field = 'twitter_id';
                 if ($member_value == 0) {
                     return array();
                 }
                 break;
             case 'email':
                 if (is_array($member_key)) {
                     array_walk($member_key, create_function('&$v,$k', '$v="\'".( ( strstr( $v, \' \' ) ) ? \'\' : ipsRegistry::DB()->addSlashes( IPSText::mbsubstr( strtolower( $v ), 0, 150 ) ) ) . "\'";'));
                     $multiple_ids = $member_key;
                 } else {
                     if (strstr($member_key, ' ')) {
                         $member_key = '';
                     }
                     $member_key = IPSText::mbsubstr($member_key, 0, 150);
                     $member_value = "'" . ipsRegistry::DB()->addSlashes(strtolower($member_key)) . "'";
                 }
                 $member_field = 'email';
                 break;
             case 'username':
                 if (is_array($member_key)) {
                     array_walk($member_key, create_function('&$v,$k', '$v="\'".ipsRegistry::DB()->addSlashes( IPSText::mbsubstr( strtolower( $v ), 0, 255 ) ) . "\'";'));
                     $multiple_ids = $member_key;
                 } else {
                     $member_key = IPSText::mbsubstr($member_key, 0, 255);
                     $member_value = "'" . ipsRegistry::DB()->addSlashes(strtolower($member_key)) . "'";
                 }
                 $member_field = 'members_l_username';
                 break;
             case 'displayname':
                 if (is_array($member_key)) {
                     array_walk($member_key, create_function('&$v,$k', '$v="\'".ipsRegistry::DB()->addSlashes( IPSText::mbsubstr( strtolower( $v ), 0, 255 ) ) . "\'";'));
                     $multiple_ids = $member_key;
                 } else {
                     $member_key = IPSText::mbsubstr($member_key, 0, 255);
                     $member_value = "'" . ipsRegistry::DB()->addSlashes(strtolower($member_key)) . "'";
                 }
                 $member_field = 'members_l_display_name';
                 break;
             case 'ipsconnect':
                 if (is_array($member_key)) {
                     $multiple_ids = $member_key;
                 } else {
                     $member_value = intval($member_key);
                 }
                 $member_field = 'ipsconnect_id';
                 break;
         }
     }
     //-----------------------------------------
     // Protected against member_id=0
     //-----------------------------------------
     if (!count($multiple_ids) or !is_array($multiple_ids)) {
         if ($member_field == 'member_id' and !$member_value) {
             return array();
         }
     }
     //-----------------------------------------
     // Sort out joins...
     //-----------------------------------------
     if ($extra_tables == 'all') {
         foreach ($tables as $_table => $_val) {
             /* Let's not load sessions or members_partial unless specifically requested */
             if ($_table == 'sessions' or $_table == 'members_partial') {
                 continue;
             }
             $tables[$_table] = 1;
         }
     } else {
         if ($extra_tables) {
             $_tables = explode(",", $extra_tables);
             foreach ($_tables as $_t) {
                 $_t = trim($_t);
                 if (isset($tables[$_t])) {
                     $tables[$_t] = 1;
                 } else {
                     if (isset(self::$remap[$_t])) {
                         if (strstr($tables[self::$remap[$_t]], ',')) {
                             $__tables = explode(',', $tables[self::$remap[$_t]]);
                             foreach ($__tables as $__t) {
                                 $tables[$__t] = 1;
                             }
                         } else {
                             $tables[self::$remap[$_t]] = 1;
                         }
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Grab used tables
     //-----------------------------------------
     $_usedTables = array();
     foreach ($tables as $_name => $_use) {
         if ($_use) {
             $_usedTables[] = $_name;
         }
     }
     //-----------------------------------------
     // Check the cache first...
     //-----------------------------------------
     if ($member_field == 'member_id' and $member_value) {
         $member = self::_fetchFromCache($member_value, $_usedTables);
         if ($member !== FALSE) {
             return $member;
         }
     } else {
         if (count($multiple_ids) and is_array($multiple_ids)) {
             $_totalUsers = count($multiple_ids);
             $_gotFromCache = 0;
             $_fromCache = array();
             foreach ($multiple_ids as $_memberValue) {
                 $member = self::_fetchFromCache($_memberValue, $_usedTables);
                 if ($member !== FALSE) {
                     $_fromCache[$member['member_id']] = $member;
                     $_gotFromCache++;
                 }
             }
             //-----------------------------------------
             // Did we find all the members in cache?
             //-----------------------------------------
             if ($_gotFromCache == $_totalUsers) {
                 return $_fromCache;
             }
         }
     }
     self::$ignoreCache = FALSE;
     //-----------------------------------------
     // Fix up joins...
     //-----------------------------------------
     if ($tables['pfields_content']) {
         $joins[] = array('select' => 'p.*', 'from' => array('pfields_content' => 'p'), 'where' => 'p.member_id=m.member_id', 'type' => 'left');
     }
     if ($tables['profile_portal']) {
         $joins[] = array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left');
     }
     if ($tables['groups']) {
         $joins[] = array('select' => 'g.*', 'from' => array('groups' => 'g'), 'where' => 'g.g_id=m.member_group_id', 'type' => 'left');
     }
     if ($tables['sessions']) {
         $joins[] = array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left');
     }
     if ($tables['core_item_markers_storage']) {
         $joins[] = array('select' => 'im.*', 'from' => array('core_item_markers_storage' => 'im'), 'where' => 'im.item_member_id=m.member_id', 'type' => 'left');
     }
     if ($tables['members_partial']) {
         $joins[] = array('select' => 'mp.*', 'from' => array('members_partial' => 'mp'), 'where' => 'mp.partial_member_id=m.member_id', 'type' => 'left');
     }
     if (IPSContentCache::isEnabled()) {
         if (IPSContentCache::fetchSettingValue('sig')) {
             $joins[] = IPSContentCache::join('sig', 'm.member_id', 'ccb', 'left', 'ccb.cache_content');
         }
     }
     //-----------------------------------------
     // Do eeet
     //-----------------------------------------
     if (count($joins)) {
         ipsRegistry::DB()->build(array('select' => 'm.*, m.member_id as my_member_id', 'from' => array('members' => 'm'), 'where' => (is_array($multiple_ids) and count($multiple_ids)) ? 'm.' . $member_field . ' IN (' . implode(',', $multiple_ids) . ')' : 'm.' . $member_field . '=' . $member_value, 'add_join' => $joins));
     } else {
         ipsRegistry::DB()->build(array('select' => '*', 'from' => 'members', 'where' => (is_array($multiple_ids) and count($multiple_ids)) ? $member_field . ' IN (' . implode(',', $multiple_ids) . ')' : $member_field . '=' . $member_value));
     }
     //-----------------------------------------
     // Execute
     //-----------------------------------------
     ipsRegistry::DB()->execute();
     while ($mem = ipsRegistry::DB()->fetch()) {
         if (isset($mem['my_member_id'])) {
             $mem['member_id'] = $mem['my_member_id'];
         }
         $mem['full'] = true;
         if (!$mem['email'] or !$mem['members_display_name'] or $mem['email'] == $mem['name'] . '@' . $mem['joined']) {
             $mem['full'] = false;
             $mem['timenow'] = $mem['joined'];
         }
         /* Clean secondary groups */
         $mem['mgroup_others'] = $mem['mgroup_others'] != '' ? IPSText::cleanPermString($mem['mgroup_others']) : '';
         //-----------------------------------------
         // Be sure we properly apply secondary permissions
         //-----------------------------------------
         if ($tables['groups']) {
             $mem = ips_MemberRegistry::setUpSecondaryGroups($mem);
             /* Unpack groups */
             $mem = IPSMember::unpackGroup($mem, TRUE, TRUE);
         }
         //-----------------------------------------
         // Unblockable
         //-----------------------------------------
         $mem['_canBeIgnored'] = self::isIgnorable($mem['member_group_id'], $mem['mgroup_others']);
         /* Bitwise Options */
         $mem = self::buildBitWiseOptions($mem);
         /* Twitter is disabled them remove twitter tokens and such */
         if ($mem['twitter_id'] && !IPSLib::twitter_enabled()) {
             $mem['twitter_token'] = '';
             $mem['twitter_secret'] = '';
             $mem['twitter_id'] = '';
         }
         /* Add to array */
         $members[$mem['member_id']] = $mem;
         //-----------------------------------------
         // Add to cache
         //-----------------------------------------
         self::_addToCache($mem, $_usedTables);
     }
     //-----------------------------------------
     // Return just a single if we only sent one id
     //-----------------------------------------
     return (is_array($multiple_ids) and count($multiple_ids)) ? $members : array_shift($members);
 }
 /**
  * Get Threaded Topic Data
  *
  * @access	public
  * @return	array
  **/
 public function _getTopicDataThreaded()
 {
     //-----------------------------------------
     // Grab the posts we'll need
     //-----------------------------------------
     $pc_join = array();
     $first = intval($this->request['start']);
     $last = $this->settings['threaded_per_page'] ? $this->settings['threaded_per_page'] : 250;
     //-----------------------------------------
     // GET meh pids
     //-----------------------------------------
     if ($first > 0) {
         // we're on a page, make sure init val is there
         $this->topics->pids[0] = $this->topics->topic['topic_firstpost'];
         $this->structured_pids[0][] = $this->topics->topic['topic_firstpost'];
     }
     $this->DB->build(array('select' => 'pid, post_parent', 'from' => 'posts', 'where' => 'topic_id=' . $this->topics->topic['tid'] . ' and queued != 1', 'order' => 'pid', 'limit' => array($first, $last)));
     $this->DB->execute();
     while ($p = $this->DB->fetch()) {
         $this->topics->pids[] = $p['pid'];
         // Force to be children of 'root' post
         if (!$p['post_parent'] and $p['pid'] != $this->topics->topic['topic_firstpost']) {
             $p['post_parent'] = $this->topics->topic['topic_firstpost'];
         }
         $this->structured_pids[$p['post_parent']][] = $p['pid'];
     }
     /* Ignored Users */
     $ignored_users = array();
     foreach ($this->member->ignored_users as $_i) {
         if ($_i['ignore_topics']) {
             $ignored_users[] = $_i['ignore_ignore_id'];
         }
     }
     //-----------------------------------------
     // Get post bodah
     //-----------------------------------------
     if (count($this->topics->pids)) {
         $this->DB->build(array('select' => 'pid, post, author_id, author_name, post_date, post_title, post_parent, topic_id, icon_id', 'from' => 'posts', 'where' => 'pid IN(' . implode(',', $this->topics->pids) . ')', 'order' => 'pid'));
         $this->DB->execute();
         while ($p = $this->DB->fetch()) {
             if (!$p['post_parent'] and $p['pid'] != $this->topics->topic['topic_firstpost']) {
                 $p['post_parent'] = $this->topics->topic['topic_firstpost'];
             }
             $this->post_cache[$p['pid']] = $p;
             $this->last_id = $p['pid'];
         }
     }
     //-----------------------------------------
     // Force root in cache
     //-----------------------------------------
     $this->post_cache[0] = array('id' => 1);
     $this->post_cache[$this->topics->topic['topic_firstpost']]['post_title'] = $this->topics->topic['title'];
     //-----------------------------------------
     // Are we viewing Posts?
     //-----------------------------------------
     $post_id = intval($this->request['pid']);
     if ($post_id && !in_array($post_id, $this->topics->pids)) {
         $this->registry->output->showError('topics_post_not_in_topic', 10358, true);
     }
     $postid_array = array(1 => $post_id);
     if ($post_id and $post_id != $this->topics->topic['topic_firstpost']) {
         $parents = $this->_threadedPostGetParents($post_id);
         if (count($parents)) {
             foreach ($parents as $pid) {
                 if ($pid != $this->topics->topic['topic_firstpost']) {
                     $postid_array[] = $pid;
                 }
             }
         }
     }
     /* Join Queries */
     $_post_joins = array(array('select' => 'm.member_id as mid,m.name,m.member_group_id,m.email,m.joined,m.posts, m.last_visit, m.last_activity,m.login_anonymous,m.title,m.hide_email, m.warn_level, m.warn_lastwarn, m.members_display_name, m.members_seo_name, m.has_gallery, m.has_blog, m.members_bitoptions', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'm.member_id=pp.pp_member_id', 'type' => 'left'));
     /* Reputation system enabled? */
     if ($this->settings['reputation_enabled']) {
         /* Add the join to figure out if the user has already rated the post */
         $_post_joins[] = $this->registry->repCache->getUserHasRatedJoin('pid', 'p.pid', 'forums');
         /* Add the join to figure out the total ratings for each post */
         if ($this->settings['reputation_show_content']) {
             $_post_joins[] = $this->registry->repCache->getTotalRatingJoin('pid', 'p.pid', 'forums');
         }
     }
     /* Cache? */
     if (IPSContentCache::isEnabled()) {
         if (IPSContentCache::fetchSettingValue('post')) {
             $_post_joins[] = IPSContentCache::join('post', 'p.pid');
         }
         if (IPSContentCache::fetchSettingValue('sig')) {
             $_post_joins[] = IPSContentCache::join('sig', 'm.member_id', 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
         }
     }
     if ($this->settings['custom_profile_topic'] == 1) {
         $_post_joins[] = array('select' => 'pc.*', 'from' => array('pfields_content' => 'pc'), 'where' => 'pc.member_id=p.author_id', 'type' => 'left');
     }
     if (count($postid_array)) {
         //-----------------------------------------
         // Get root post and children of clicked
         //-----------------------------------------
         $this->used_post_ids = ',' . implode(",", $postid_array) . ',';
         $postid_array[0] = $this->topics->topic['topic_firstpost'];
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid IN(" . implode(',', $postid_array) . ")", 'order' => 'pid asc', 'add_join' => $_post_joins));
     } else {
         //-----------------------------------------
         // Just get root
         //-----------------------------------------
         $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.pid=" . $this->topics->topic['topic_firstpost'], 'order' => 'pid asc', 'add_join' => $_post_joins));
     }
     //-----------------------------------------
     // Attachment PIDS
     //-----------------------------------------
     $this->topics->attach_pids = $postid_array;
     //-----------------------------------------
     // Render the original post
     //-----------------------------------------
     $outer = $this->DB->execute();
     //-----------------------------------------
     // Format and print out the topic list
     //-----------------------------------------
     $post_data = array();
     $num_rows = $this->DB->getTotalRows($outer);
     while ($row = $this->DB->fetch($outer)) {
         $return = $this->topics->parsePostRow($row);
         $poster = $return['poster'];
         $row = $return['row'];
         /* Reputation */
         if ($this->settings['reputation_enabled']) {
             $row['pp_reputation_points'] = $row['pp_reputation_points'] ? $row['pp_reputation_points'] : 0;
             $row['has_given_rep'] = $row['has_given_rep'] ? $row['has_given_rep'] : 0;
             $row['rep_points'] = $row['rep_points'] ? $row['rep_points'] : 0;
         }
         $post_data[$row['pid']] = array('post' => $row, 'author' => $poster);
         //-----------------------------------------
         // Are we giving this bloke a good ignoring?
         //-----------------------------------------
         if (isset($ignored_users) && is_array($ignored_users) && count($ignored_users)) {
             if (in_array($poster['member_id'], $ignored_users)) {
                 if (!strstr($this->settings['cannot_ignore_groups'], ',' . $poster['member_group_id'] . ',')) {
                     $post_data[$row['pid']]['post']['_ignored'] = 1;
                     continue;
                 }
             }
         }
         if (!$this->printed and $num_rows > 1) {
             $post_data[$row['pid']]['post']['_end_first_post'] = 1;
             $this->printed = 1;
         }
     }
     //-----------------------------------------
     // Sort out pagination
     //-----------------------------------------
     $total_replies = $this->topics->topic['posts'];
     $show_replies = count($this->structured_pids) - 1;
     $this->topics->topic['SHOW_PAGES'] = '';
     $this->topics->topic['threaded_pages'] = $this->registry->output->generatePagination(array('totalItems' => $total_replies, 'itemsPerPage' => $last, 'currentStartValue' => $this->request['start'], 'baseUrl' => "showtopic=" . $this->topics->topic['tid'], 'startValueKey' => 'start'));
     //-----------------------------------------
     // START GETTING THE OUTLINE LIST
     //-----------------------------------------
     $this->_threaded_posts[0]['child'] = $this->_threadedLoopGetChildren();
     $this->topics->topic['_threaded_posts'] = $this->_buildThreadedOutput($this->_threaded_posts[0]);
     return $post_data;
 }
Example #9
0
 /**
  * Get Topic Data
  *
  * @return	array
  */
 public function _getPosts()
 {
     /* Init */
     $topicData = $this->registry->getClass('topics')->getTopicData();
     $forumData = $this->forumClass->getForumById($topicData['forum_id']);
     $permissionData = $this->registry->getClass('topics')->getPermissionData();
     $first = $this->registry->getClass('topics')->pageToSt($this->request['page']);
     /* Default - just see all visible posts */
     $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('visible', '');
     /* Can we deal with hidden posts? */
     if ($this->registry->class_forums->canQueuePosts($topicData['forum_id'])) {
         if ($permissionData['softDeleteSee']) {
             /* See queued and soft deleted */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden', 'sdeleted'), '');
         } else {
             /* Otherwise, see queued and approved */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('visible', 'hidden'), '');
         }
         /* Specifically requesting to see queued posts only */
         if ($this->request['modfilter'] and $this->request['modfilter'] == 'invisible_posts') {
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('hidden', '');
         }
     } else {
         /* We cannot see hidden posts */
         if ($permissionData['softDeleteSee']) {
             /* See queued and soft deleted */
             $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery(array('approved', 'sdeleted'), '');
         }
     }
     /* Did we specifically want to see soft deleted posts? */
     if ($this->request['modfilter'] == 'deleted_posts' and $permissionData['softDeleteSee']) {
         $queued_query_bit = ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('sdeleted', '');
     }
     /* Data Hook Location */
     $dataHook = array('members' => array(), 'postJoins' => array());
     IPSLib::doDataHooks($dataHook, 'topicViewQuery');
     //-----------------------------------------
     // Joins
     //-----------------------------------------
     $_extraMember = is_array($dataHook['members']) && count($dataHook['members']) ? ',m.' . implode(',m.', $dataHook['members']) : '';
     $_post_joins = array(array('select' => '', 'from' => array('posts' => 'p'), 'where' => 'p.pid=z.pid'), array('select' => 'm.member_id as mid,m.name,m.member_group_id,m.email,m.joined,m.posts, m.last_visit, m.last_activity,m.login_anonymous,m.title as member_title, m.warn_level, m.warn_lastwarn, m.members_display_name, m.members_seo_name, m.member_banned, m.has_gallery, m.has_blog, m.members_bitoptions,m.mgroup_others' . $_extraMember, 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'm.member_id=pp.pp_member_id', 'type' => 'left'));
     /* Warn system enabled? */
     if ($this->settings['warn_on'] == 1) {
         $_post_joins[] = array('select' => 'w.wl_id', 'from' => array('members_warn_logs' => 'w'), 'where' => 'w.wl_content_app=\'forums\' and w.wl_content_id1=p.pid');
     }
     /* Add data hook joins */
     if (is_array($dataHook['postJoins']) && count($dataHook['postJoins'])) {
         $_post_joins = array_merge($_post_joins, $dataHook['postJoins']);
     }
     /* Add custom fields join? */
     if ($this->settings['custom_profile_topic'] == 1) {
         $_post_joins[] = array('select' => 'pc.*', 'from' => array('pfields_content' => 'pc'), 'where' => 'pc.member_id=p.author_id', 'type' => 'left');
     }
     /* Reputation system enabled? */
     if ($this->settings['reputation_enabled']) {
         /* Add the join to figure out if the user has already rated the post */
         $_post_joins[] = $this->registry->repCache->getUserHasRatedJoin('pid', 'p.pid', 'forums');
         /* Add the join to figure out the total ratings for each post */
         if ($this->settings['reputation_show_content']) {
             $_post_joins[] = $this->registry->repCache->getTotalRatingJoin('pid', 'p.pid', 'forums');
         }
     }
     /* Cache? */
     if (IPSContentCache::isEnabled()) {
         if (IPSContentCache::fetchSettingValue('post')) {
             $_post_joins[] = IPSContentCache::join('post', 'p.pid');
         }
         if (IPSContentCache::fetchSettingValue('sig')) {
             $_post_joins[] = IPSContentCache::join('sig', 'm.member_id', 'ccb', 'left', 'ccb.cache_content as cache_content_sig, ccb.cache_updated as cache_updated_sig');
         }
     }
     /* Ignored Users */
     $ignored_users = array();
     foreach ($this->member->ignored_users as $_i) {
         if ($_i['ignore_topics']) {
             $ignored_users[] = $_i['ignore_ignore_id'];
         }
     }
     //-----------------------------------------
     // Get posts
     // See http://community.invisionpower.com/resources/bugs.html/_/ip-board/big-topics-i-mean-big-topics-r36577 for an explanation why this a bit odd
     //-----------------------------------------
     $this->DB->build(array('select' => 'p.*', 'from' => array('( ****FROM**** )' => 'z'), 'add_join' => $_post_joins));
     $query = $this->DB->fetchSqlString();
     $this->DB->flushQuery();
     $this->DB->build(array('select' => 'pid, post_date', 'from' => 'posts', 'where' => 'topic_id=' . $topicData['tid'] . $queued_query_bit, 'order' => $this->settings['post_order_column'] . ' ' . $this->settings['post_order_sort'], 'limit' => array($first, $this->settings['display_max_posts'])));
     $query = str_replace('****FROM****', $this->DB->fetchSqlString(), $query) . " ORDER BY z." . $this->settings['post_order_column'] . " " . $this->settings['post_order_sort'];
     $query = str_replace($this->settings['sql_tbl_prefix'] . '(', '(', $query);
     $this->DB->flushQuery();
     $this->DB->allow_sub_select = TRUE;
     $oq = $this->DB->query($query);
     if (!$this->DB->getTotalRows()) {
         if ($first >= $this->settings['display_max_posts']) {
             //-----------------------------------------
             // AUTO FIX: Get the correct number of replies...
             //-----------------------------------------
             $this->DB->build(array('select' => 'COUNT(*) as pcount', 'from' => 'posts', 'where' => "topic_id=" . $topicData['tid'] . " and queued=0"));
             $newq = $this->DB->execute();
             $pcount = $this->DB->fetch($newq);
             $pcount['pcount'] = $pcount['pcount'] > 0 ? $pcount['pcount'] - 1 : 0;
             //-----------------------------------------
             // Update the post table...
             //-----------------------------------------
             if ($pcount['pcount'] > 1) {
                 $this->DB->update('topics', array('posts' => $pcount['pcount']), "tid=" . $topicData['tid']);
             }
             // This is now handled in app_class_forums::incorrectPageCallback to redirect to correct post */
             //$this->registry->output->silentRedirect($this->settings['base_url']."showtopic={$topicData['tid']}&view=getlastpost");
         }
     }
     //-----------------------------------------
     // Render the page top
     //-----------------------------------------
     $topicData['go_new'] = isset($topicData['go_new']) ? $topicData['go_new'] : '';
     //-----------------------------------------
     // Format and print out the topic list
     //-----------------------------------------
     $modAll = ($this->memberData['g_is_supmod'] or isset($this->memberData['forumsModeratorData'][$forumData['id']]) and ($this->memberData['forumsModeratorData'][$forumData['id']]['delete_post'] or $this->memberData['forumsModeratorData'][$forumData['id']]['split_move']));
     $this->registry->getClass('topics')->setTopicData('adCodeSet', false);
     $this->registry->getClass('topics')->setTopicData('ignoredUsers', $ignored_users);
     $posts = array();
     $this->DB->allow_sub_select = TRUE;
     while ($row = $this->DB->fetch($oq)) {
         /* Should we display the moderate checkbox for this post? */
         $row['moddable'] = FALSE;
         if ($modAll or isset($this->memberData['forumsModeratorData'][$forumData['id']]) and ($row['approved'] == 0 and $this->memberData['forumsModeratorData'][$forumData['id']]['post_q'] or $row['queued'] == 2 and $this->memberData['forumsModeratorData'][$forumData['id']]['bw_mod_un_soft_delete'] or $row['queued'] == 0 and $this->memberData['forumsModeratorData'][$forumData['id']]['bw_mod_soft_delete'])) {
             $row['moddable'] = TRUE;
         }
         /* Add to array */
         $row['member_id'] = $row['mid'];
         $posts[$row['pid']] = $row;
     }
     /* Return */
     return $posts;
 }