Example #1
0
    public function _get_post_count($topic_id)
    {
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_access = ' . TITANIA_ACCESS_TEAMS . '
				AND post_deleted = 0
				AND post_approved = 1';
        $result = phpbb::$db->sql_query($sql);
        $teams = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_access = ' . TITANIA_ACCESS_AUTHORS . '
				AND post_deleted = 0
				AND post_approved = 1';
        $result = phpbb::$db->sql_query($sql);
        $authors = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_access = ' . TITANIA_ACCESS_PUBLIC . '
				AND post_deleted = 0
				AND post_approved = 1';
        $result = phpbb::$db->sql_query($sql);
        $public = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_deleted <> 0';
        $result = phpbb::$db->sql_query($sql);
        $deleted = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_deleted = 0
				AND post_approved = 0';
        $result = phpbb::$db->sql_query($sql);
        $unapproved = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        return titania_count::to_db(array('teams' => $teams, 'authors' => $authors, 'public' => $public, 'deleted' => $deleted, 'unapproved' => $unapproved));
    }
Example #2
0
 /**
  * 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 = titania_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 TITANIA_ACCESS_PUBLIC:
                         $to_db['public']--;
                         break;
                     case TITANIA_ACCESS_AUTHORS:
                         $to_db['authors']--;
                         break;
                     case TITANIA_ACCESS_TEAMS:
                         $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 TITANIA_ACCESS_PUBLIC:
                         $to_db['public']++;
                         break;
                     case TITANIA_ACCESS_AUTHORS:
                         $to_db['authors']++;
                         break;
                     case TITANIA_ACCESS_TEAMS:
                         $to_db['teams']++;
                         break;
                 }
             }
         }
     }
     // Update the field on the topic
     $this->topic->topic_posts = titania_count::to_db($to_db);
 }
Example #3
0
 /**
  * Prepare the count to go to the db field
  */
 public static function to_db($data)
 {
     self::reset_fields();
     self::$fields = array_merge(self::$fields, $data);
     $to_db = array();
     foreach (self::$fields as $field_name => $field_value) {
         $to_db[] = $field_name . ':' . $field_value;
     }
     return implode(':', $to_db);
 }
Example #4
0
    public function delete()
    {
        titania_search::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 = titania_count::update_flags($this->faq_access);
        $sql = 'UPDATE ' . TITANIA_CONTRIBS_TABLE . '
			SET contrib_faq_count = \'' . phpbb::$db->sql_escape(titania_count::decrement($contrib_faq_count, $flags)) . '\'
			WHERE contrib_id = ' . $this->contrib_id;
        phpbb::$db->sql_query($sql);
        parent::delete();
    }
Example #5
0
 /**
  * Assign details
  *
  * A little different from those in other classes, this one only returns the info ready for output
  */
 public function assign_details()
 {
     // Tracking check
     $last_read_mark = titania_tracking::get_track(TITANIA_TOPIC, $this->topic_id, true);
     $last_read_mark = max($last_read_mark, titania_tracking::find_last_read_mark($this->additional_unread_fields, $this->topic_type, $this->parent_id));
     $this->unread = $this->topic_last_post_time > $last_read_mark ? true : false;
     $folder_img = $folder_alt = '';
     $this->topic_folder_img($folder_img, $folder_alt);
     // To find out if we have any posts that need approval
     $approved = titania_count::from_db($this->topic_posts, titania_count::get_flags(TITANIA_ACCESS_PUBLIC, false, false));
     $total = titania_count::from_db($this->topic_posts, titania_count::get_flags(TITANIA_ACCESS_PUBLIC, false, true));
     $details = array('TOPIC_ID' => $this->topic_id, 'TOPIC_TYPE' => $this->topic_type, 'TOPIC_ACCESS' => $this->topic_access, 'TOPIC_STATUS' => $this->topic_status, 'TOPIC_STICKY' => $this->topic_sticky, 'TOPIC_LOCKED' => $this->topic_locked, 'POSTS_APPROVED' => phpbb::$auth->acl_get('u_titania_mod_post_mod') && $total > $approved ? false : true, 'TOPIC_APPROVED' => phpbb::$auth->acl_get('u_titania_mod_post_mod') ? $this->topic_approved : true, 'TOPIC_REPORTED' => phpbb::$auth->acl_get('u_titania_mod_post_mod') ? $this->topic_reported : false, 'TOPIC_ASSIGNED' => $this->topic_assigned, 'TOPIC_REPLIES' => $this->get_postcount() - 1, 'TOPIC_VIEWS' => $this->topic_views, 'TOPIC_SUBJECT' => censor_text($this->topic_subject), 'TOPIC_FIRST_POST_ID' => $this->topic_first_post_id, 'TOPIC_FIRST_POST_USER_ID' => $this->topic_first_post_user_id, 'TOPIC_FIRST_POST_USER_COLOUR' => $this->topic_first_post_user_colour, 'TOPIC_FIRST_POST_USER_FULL' => get_username_string('full', $this->topic_first_post_user_id, $this->topic_first_post_username, $this->topic_first_post_user_colour, false, phpbb::append_sid('memberlist', 'mode=viewprofile')), 'TOPIC_FIRST_POST_TIME' => phpbb::$user->format_date($this->topic_first_post_time), 'TOPIC_LAST_POST_ID' => $this->topic_last_post_id, 'TOPIC_LAST_POST_USER_ID' => $this->topic_last_post_user_id, 'TOPIC_LAST_POST_USER_COLOUR' => $this->topic_last_post_user_colour, 'TOPIC_LAST_POST_USER_FULL' => get_username_string('full', $this->topic_last_post_user_id, $this->topic_last_post_username, $this->topic_last_post_user_colour, false, phpbb::append_sid('memberlist', 'mode=viewprofile')), 'TOPIC_LAST_POST_TIME' => phpbb::$user->format_date($this->topic_last_post_time), 'TOPIC_LAST_POST_SUBJECT' => censor_text($this->topic_last_post_subject), 'U_NEWEST_POST' => $this->unread ? titania_url::append_url($this->get_url(), array('view' => 'unread', '#' => 'unread')) : '', 'U_VIEW_TOPIC' => $this->get_url(), 'U_VIEW_LAST_POST' => titania_url::append_url($this->get_url(), array('p' => $this->topic_last_post_id, '#p' => $this->topic_last_post_id)), 'S_UNREAD_TOPIC' => $this->unread ? true : false, 'S_ACCESS_TEAMS' => $this->topic_access == TITANIA_ACCESS_TEAMS ? true : false, 'S_ACCESS_AUTHORS' => $this->topic_access == TITANIA_ACCESS_AUTHORS ? true : false, 'FOLDER_IMG' => phpbb::$user->img($folder_img, $folder_alt), 'FOLDER_IMG_SRC' => phpbb::$user->img($folder_img, $folder_alt, false, '', 'src'), 'FOLDER_IMG_ALT' => phpbb::$user->lang[$folder_alt], 'FOLDER_IMG_WIDTH' => phpbb::$user->img($folder_img, '', false, '', 'width'), 'FOLDER_IMG_HEIGHT' => phpbb::$user->img($folder_img, '', false, '', 'height'));
     // Hooks
     titania::$hook->call_hook_ref(array(__CLASS__, __FUNCTION__), $details, $this);
     return $details;
 }
Example #6
0
/**
* Load contribution
*
* Call this AFTER you have loaded the main object (like the FAQ item if requested for example)
*
* @param mixed $contrib contrib_id (always send if you have loaded an item for this contrib!)
*/
function load_contrib($contrib_id = false)
{
    $contrib = request_var('id', 0) ? request_var('id', 0) : utf8_normalize_nfc(request_var('c', '', true));
    $type = request_var('type', '');
    // Load the contribution
    titania::$contrib = new titania_contribution();
    if (!titania::$contrib->load($contrib)) {
        trigger_error('CONTRIB_NOT_FOUND');
    }
    // Make sure the contrib requested is the same as the contrib loaded
    if ($contrib_id !== false && $contrib_id != titania::$contrib->contrib_id || $type != titania_types::$types[titania::$contrib->contrib_type]->url) {
        // Mismatch, redirect
        redirect(titania::$contrib->get_url(basename(request_var('page', 'details'))));
    }
    // Put the author in titania::$author
    titania::$author = titania::$contrib->author;
    // Check to see if the currently accessing user is an author
    if (titania::$access_level == TITANIA_ACCESS_PUBLIC && phpbb::$user->data['is_registered'] && !phpbb::$user->data['is_bot']) {
        if (titania::$contrib->is_author || titania::$contrib->is_active_coauthor) {
            titania::$access_level = TITANIA_ACCESS_AUTHORS;
        }
    }
    // Count the number of FAQ items to display
    $flags = titania_count::get_flags(titania::$access_level);
    $faq_count = titania_count::from_db(titania::$contrib->contrib_faq_count, $flags);
    /**
     * 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' => titania::$contrib->get_url()), 'faq' => array('title' => 'CONTRIB_FAQ', 'url' => titania::$contrib->get_url('faq'), 'auth' => titania::$access_level != TITANIA_ACCESS_PUBLIC || $faq_count ? true : false, 'count' => $faq_count), 'support' => array('title' => 'CONTRIB_SUPPORT', 'url' => titania::$contrib->get_url('support'), 'auth' => titania::$config->support_in_titania || titania::$access_level < TITANIA_ACCESS_PUBLIC ? true : false), 'manage' => array('title' => 'CONTRIB_MANAGE', 'url' => titania::$contrib->get_url('manage'), 'auth' => (titania::$contrib->is_author || titania::$contrib->is_active_coauthor) && phpbb::$auth->acl_get('u_titania_post_edit_own') && !in_array(titania::$contrib->contrib_status, array(TITANIA_CONTRIB_CLEANED, TITANIA_CONTRIB_DISABLED)) || phpbb::$auth->acl_get('u_titania_mod_contrib_mod') || titania_types::$types[titania::$contrib->contrib_type]->acl_get('moderate')));
    // Display nav menu
    $page = request_var('page', '');
    titania::generate_nav($nav_ary, $page, 'details');
    // Search for a category with the same name as the contrib type.  This is a bit ugly, but there really isn't any better option
    $categories_ary = titania::$cache->get_categories();
    foreach ($categories_ary as $category_id => $category_row) {
        $category_row['category_name'] = isset(phpbb::$user->lang[$category_row['category_name']]) ? phpbb::$user->lang[$category_row['category_name']] : $category_row['category_name'];
        if ($category_row['category_name'] == titania_types::$types[titania::$contrib->contrib_type]->lang || $category_row['category_name'] == titania_types::$types[titania::$contrib->contrib_type]->langs) {
            $category_object = new titania_category();
            $category_object->__set_array($categories_ary[$category_id]);
            // Generate the main breadcrumbs
            titania::generate_breadcrumbs(array($category_object->category_name => titania_url::build_url($category_object->get_url())));
            break;
        }
    }
    titania::generate_breadcrumbs(array(titania::$contrib->contrib_name => titania::$contrib->get_url()));
    if ($page) {
        titania::generate_breadcrumbs(array($nav_ary[$page]['title'] => $nav_ary[$page]['url']));
    }
}