/** * 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; }