/** * Sync posts. * * @param string $mode * @param int|bool $start For indexing * @param int|bool $limit For indexing */ public function posts($mode, $start = false, $limit = false) { switch ($mode) { case 'index': $data = array(); $post = new \titania_post(); $sql = 'SELECT p.*, t.topic_id, t.topic_type, t.topic_subject_clean, t.parent_id, q.queue_type, c.contrib_type FROM ' . $this->posts_table . ' p, ' . $this->topics_table . ' t LEFT JOIN ' . TITANIA_QUEUE_TABLE . ' q ON (t.parent_id = q.queue_id AND t.topic_type = ' . TITANIA_QUEUE . ') LEFT JOIN ' . $this->contribs_table . ' c ON (t.parent_id = c.contrib_id AND t.topic_type <> ' . TITANIA_QUEUE . ') WHERE t.topic_id = p.topic_id ORDER BY p.post_id ASC'; if ($start === false || $limit === false) { $result = $this->db->sql_query($sql); } else { $result = $this->db->sql_query_limit($sql, (int) $limit, (int) $start); } while ($row = $this->db->sql_fetchrow($result)) { $post->__set_array($row); $post->topic->__set_array($row); $data[] = array('object_type' => $post->post_type, 'object_id' => $post->post_id, 'parent_id' => $post->topic->parent_id, 'title' => $post->post_subject, 'text' => $post->post_text, 'text_uid' => $post->post_text_uid, 'text_bitfield' => $post->post_text_bitfield, 'text_options' => $post->post_text_options, 'author' => $post->post_user_id, 'date' => $post->post_time, 'url' => serialize($post->get_url_params()), 'approved' => $post->post_approved, 'access_level' => $post->post_access, 'parent_contrib_type' => (int) ($post->post_type == TITANIA_QUEUE) ? $row['queue_type'] : $row['contrib_type']); } $this->db->sql_freeresult($result); $this->search_manager->mass_index($data); break; } }