/** * Get post counts for a topic. * * @param int $topic_id * @return string Returns counts in db storable form */ public function _get_post_count($topic_id) { $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . $this->posts_table . ' WHERE topic_id = ' . (int) $topic_id . ' AND post_access = ' . access::TEAM_LEVEL . ' AND post_deleted = 0 AND post_approved = 1'; $result = $this->db->sql_query($sql); $teams = $this->db->sql_fetchfield('cnt', $result); $this->db->sql_freeresult($result); $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . $this->posts_table . ' WHERE topic_id = ' . (int) $topic_id . ' AND post_access = ' . access::AUTHOR_LEVEL . ' AND post_deleted = 0 AND post_approved = 1'; $result = $this->db->sql_query($sql); $authors = $this->db->sql_fetchfield('cnt', $result); $this->db->sql_freeresult($result); $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . $this->posts_table . ' WHERE topic_id = ' . (int) $topic_id . ' AND post_access = ' . access::PUBLIC_LEVEL . ' AND post_deleted = 0 AND post_approved = 1'; $result = $this->db->sql_query($sql); $public = $this->db->sql_fetchfield('cnt', $result); $this->db->sql_freeresult($result); $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . $this->posts_table . ' WHERE topic_id = ' . (int) $topic_id . ' AND post_deleted <> 0'; $result = $this->db->sql_query($sql); $deleted = $this->db->sql_fetchfield('cnt', $result); $this->db->sql_freeresult($result); $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . $this->posts_table . ' WHERE topic_id = ' . (int) $topic_id . ' AND post_deleted = 0 AND post_approved = 0'; $result = $this->db->sql_query($sql); $unapproved = $this->db->sql_fetchfield('cnt', $result); $this->db->sql_freeresult($result); return count::to_db(array('teams' => $teams, 'authors' => $authors, 'public' => $public, 'deleted' => $deleted, 'unapproved' => $unapproved)); }
/** * Update postcount on the parent topic */ public function update_topic_postcount($hard_delete = false) { // shouldn't need to load through load() to delete it... if ($hard_delete && empty($this->sql_data)) { $this->sql_data = $this->__get_array(); } if ($this->post_id && empty($this->sql_data)) { throw new exception('Modifying a post requires you load it through the load() function (we require the original information).'); } // Get the current count $to_db = count::from_db($this->topic->topic_posts, false); // Revert the old count from this post if ($this->post_id) { if ($this->sql_data['post_deleted'] != 0) { $to_db['deleted']--; } else { if (!$this->sql_data['post_approved']) { $to_db['unapproved']--; } else { switch ($this->sql_data['post_access']) { case access::PUBLIC_LEVEL: $to_db['public']--; break; case access::AUTHOR_LEVEL: $to_db['authors']--; break; case access::TEAM_LEVEL: $to_db['teams']--; break; } } } } // Then recount those options for this post if we are not hard deleting it. if (!$hard_delete) { if ($this->post_deleted != 0) { $to_db['deleted']++; } else { if (!$this->post_approved) { $to_db['unapproved']++; } else { switch ($this->post_access) { case access::PUBLIC_LEVEL: $to_db['public']++; break; case access::AUTHOR_LEVEL: $to_db['authors']++; break; case access::TEAM_LEVEL: $to_db['teams']++; break; } } } } // Update the field on the topic $this->topic->topic_posts = count::to_db($to_db); }
public function delete() { $this->search_manager->delete(TITANIA_FAQ, $this->faq_id); // Update the FAQ count $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(); $flags = count::update_flags($this->faq_access); $sql = 'UPDATE ' . TITANIA_CONTRIBS_TABLE . ' SET contrib_faq_count = \'' . phpbb::$db->sql_escape(count::decrement($contrib_faq_count, $flags)) . '\' WHERE contrib_id = ' . $this->contrib_id; phpbb::$db->sql_query($sql); parent::delete(); }
/** * Sync topic approved and access states. * * @param bool $delete_empty_topic Delete the topic if it does not contain any posts. * @param array $first_post_data Array containing info about first post in the form of array(post_approved => (bool), post_deleted => (bool)). If not provided, db is queried. */ public function sync_topic_state($delete_empty_topic = false, $first_post_data = false) { if (!$this->topic_id) { return; } $counts = count::from_db($this->topic_posts, false); $visible_posts = $counts['teams'] + $counts['authors'] + $counts['public']; $total_posts = array_sum($counts); if (!$total_posts && $delete_empty_topic) { $this->delete(); } if (!$first_post_data) { $sql = 'SELECT post_deleted, post_approved FROM ' . TITANIA_POSTS_TABLE . ' WHERE topic_id = ' . (int) $this->topic_id . ' ORDER BY post_time ASC'; $result = phpbb::$db->sql_query_limit($sql, 1); $first_post_data = phpbb::$db->sql_fetchrow($result); phpbb::$db->sql_freeresult($result); if (!$first_post_data) { $this->topic_access = access::TEAM_LEVEL; $this->topic_approved = 1; return; } } // Mark the topic as unapproved if there are no visible posts and the first one is unapproved. $this->topic_approved = !$visible_posts && !$first_post_data['post_approved'] ? 0 : 1; // Adjust the topic access if ($visible_posts && !in_array($this->topic_type, array(TITANIA_QUEUE_DISCUSSION, TITANIA_QUEUE))) { $this->topic_access = access::PUBLIC_LEVEL; if (!$counts['public']) { $this->topic_access = access::AUTHOR_LEVEL; if (!$counts['authors']) { $this->topic_access = access::TEAM_LEVEL; } } } else { // If no posts are visible and first post is deleted, then only the teams have access. $this->topic_access = !$visible_posts && $first_post_data['post_deleted'] ? access::TEAM_LEVEL : $this->topic_access; } }
/** * Assign navigation tabs. * * @param string $page Current active page. * @return null */ protected function generate_navigation($page) { // Count the number of FAQ items to display $flags = count::get_flags($this->access->get_level()); $faq_count = count::from_db($this->contrib->contrib_faq_count, $flags); $is_disabled = in_array($this->contrib->contrib_status, array(TITANIA_CONTRIB_CLEANED, TITANIA_CONTRIB_DISABLED)); /** * Menu Array * * 'filename' => array( * 'title' => 'nav menu title', * 'url' => $page_url, * 'auth' => ($can_see_page) ? true : false, // Not required, always true if missing * ), */ $nav_ary = array('details' => array('title' => 'CONTRIB_DETAILS', 'url' => $this->contrib->get_url()), 'faq' => array('title' => 'CONTRIB_FAQ', 'url' => $this->contrib->get_url('faq'), 'auth' => !$this->access->is_public() || $faq_count, 'count' => $faq_count), 'support' => array('title' => 'CONTRIB_SUPPORT', 'url' => $this->contrib->get_url('support'), 'auth' => $this->ext_config->support_in_titania || $this->access->get_level() < access::PUBLIC_LEVEL), 'demo' => array('title' => 'CONTRIB_DEMO', 'url' => '', 'auth' => !empty($this->contrib->contrib_demo)), 'manage' => array('title' => 'CONTRIB_MANAGE', 'url' => $this->contrib->get_url('manage'), 'auth' => $this->is_author && $this->auth->acl_get('u_titania_post_edit_own') && !$is_disabled || $this->auth->acl_get('u_titania_mod_contrib_mod') || $this->contrib->type->acl_get('moderate'))); if ($this->contrib->contrib_demo) { $demo_menu = array(); $allowed_branches = $this->contrib->type->get_allowed_branches(true); krsort($allowed_branches); $is_external = $this->contrib->contrib_status != TITANIA_CONTRIB_APPROVED || !$this->contrib->options['demo']; foreach ($allowed_branches as $branch => $name) { $demo_url = $this->contrib->get_demo_url($branch, !$is_external); if ($demo_url) { $demo_menu[] = array('url' => $demo_url, 'title' => $name, 'external' => $is_external); } } if (sizeof($demo_menu) == 1) { $nav_ary['demo']['url'] = $demo_menu[0]['url']; $nav_ary['demo']['external'] = $demo_menu[0]['external']; } else { if (!empty($demo_menu)) { $nav_ary['demo']['sub_menu'] = $demo_menu; } else { unset($nav_ary['demo']); } } } $this->display->generate_nav($nav_ary, $page, 'details'); }