/** * Sync contribs * * @param string $mode The mode (validated) * @param int $contrib_id Contrib id to limit to * @param int|bool $start & $limit start and limit for indexing (only indexing!) */ public function contribs($mode, $contrib_id = false, $start = false, $limit = false) { switch ($mode) { case 'validated': $sql = 'SELECT contrib_id, contrib_status FROM ' . TITANIA_CONTRIBS_TABLE . ($contrib_id ? ' AND contrib_id = ' . (int) $contrib_id : ''); $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { $sql = 'SELECT COUNT(revision_id) AS cnt FROM ' . TITANIA_REVISIONS_TABLE . ' WHERE contrib_id = ' . $row['contrib_id'] . ' AND revision_status = ' . TITANIA_REVISION_APPROVED; $result1 = phpbb::$db->sql_query($sql); $cnt = phpbb::$db->sql_fetchfield('cnt', $result1); phpbb::$db->sql_freeresult($result1); if ($cnt > 0 && $row['contrib_status'] == TITANIA_CONTRIB_NEW || $cnt == 0 && $row['contrib_status'] == TITANIA_CONTRIB_APPROVED) { $sql = 'UPDATE ' . TITANIA_CONTRIBS_TABLE . ' SET contrib_status = ' . ($cnt > 0 ? TITANIA_CONTRIB_APPROVED : TITANIA_CONTRIB_NEW) . ' WHERE contrib_id = ' . $row['contrib_id']; phpbb::$db->sql_query($sql); } } phpbb::$db->sql_freeresult($result); break; case 'faq_count': $contribs = array(); $sql = 'SELECT faq_access, contrib_id FROM ' . TITANIA_CONTRIB_FAQ_TABLE; $result = phpbb::$db->sql_query($sql); while ($row = phpbb::$db->sql_fetchrow($result)) { $flags = titania_count::update_flags($row['faq_access']); $contribs[$row['contrib_id']] = titania_count::increment(isset($contribs[$row['contrib_id']]) ? $contribs[$row['contrib_id']] : '', $flags); } phpbb::$db->sql_freeresult($result); foreach ($contribs as $contrib_id => $count) { $sql = 'UPDATE ' . TITANIA_CONTRIBS_TABLE . ' SET contrib_faq_count = \'' . phpbb::$db->sql_escape($count) . '\' WHERE contrib_id = ' . $contrib_id; phpbb::$db->sql_query($sql); } break; case 'index': $data = array(); $sql = 'SELECT * FROM ' . TITANIA_CONTRIBS_TABLE . ' ORDER BY contrib_id ASC'; if ($start === false || $limit === false) { $result = phpbb::$db->sql_query($sql); } else { $result = phpbb::$db->sql_query_limit($sql, (int) $limit, (int) $start); } while ($row = phpbb::$db->sql_fetchrow($result)) { $data[] = array('object_type' => TITANIA_CONTRIB, 'object_id' => $row['contrib_id'], 'title' => $row['contrib_name'], 'text' => $row['contrib_desc'], 'text_uid' => $row['contrib_desc_uid'], 'text_bitfield' => $row['contrib_desc_bitfield'], 'text_options' => $row['contrib_desc_options'], 'author' => $row['contrib_user_id'], 'date' => $row['contrib_last_update'], 'url' => titania_types::$types[$row['contrib_type']]->url . '/' . $row['contrib_name_clean'], 'approved' => (!titania::$config->require_validation || !titania_types::$types[$row['contrib_type']]->require_validation) && $row['contrib_status'] == TITANIA_CONTRIB_NEW || in_array($row['contrib_status'], array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) ? true : false); } phpbb::$db->sql_freeresult($result); titania_search::mass_index($data); break; } }
/** * Update data or submit new faq * * @return void */ public function submit() { // Get the FAQ count to update it $sql = 'SELECT contrib_faq_count FROM ' . TITANIA_CONTRIBS_TABLE . ' WHERE contrib_id = ' . $this->contrib_id; phpbb::$db->sql_query($sql); $contrib_faq_count = phpbb::$db->sql_fetchfield('contrib_faq_count'); phpbb::$db->sql_freeresult(); // If already submitted we need to decrement first if ($this->faq_id) { if (empty($this->sql_data)) { throw new exception('Modifying a FAQ entry requires you load it through the load() function (we require the original information).'); } $original_flags = titania_count::update_flags($this->sql_data['faq_access']); $contrib_faq_count = titania_count::decrement($contrib_faq_count, $original_flags); } // Update the FAQ count $flags = titania_count::update_flags($this->faq_access); $sql = 'UPDATE ' . TITANIA_CONTRIBS_TABLE . ' SET contrib_faq_count = \'' . phpbb::$db->sql_escape(titania_count::increment($contrib_faq_count, $flags)) . '\' WHERE contrib_id = ' . $this->contrib_id; phpbb::$db->sql_query($sql); // Submit this FAQ item parent::submit(); // Index titania_search::index(TITANIA_FAQ, $this->faq_id, array('title' => $this->faq_subject, 'text' => $this->faq_text, 'text_uid' => $this->faq_text_uid, 'text_bitfield' => $this->faq_text_bitfield, 'text_options' => $this->faq_text_options, 'author' => 0, 'date' => 0, 'url' => titania_url::unbuild_url($this->get_url()), 'access_level' => $this->faq_access)); }