[Customisation Database Commits] r254 - in /trunk/titania: contributions/index.php contributions/support.php includes/constants.php includes/core/cache.php includes/functions_display.php includes/objects/contribution.php includes/objects/topic.php

Nathan Guse exreaction at phpbb.com
Thu Jun 25 06:38:03 UTC 2009


Author: exreaction
Date: Thu Jun 25 06:38:02 2009
New Revision: 254

Log:
More work on the topic/post backend

Modified:
    trunk/titania/contributions/index.php
    trunk/titania/contributions/support.php
    trunk/titania/includes/constants.php
    trunk/titania/includes/core/cache.php
    trunk/titania/includes/functions_display.php
    trunk/titania/includes/objects/contribution.php
    trunk/titania/includes/objects/topic.php

Modified: trunk/titania/contributions/index.php
==============================================================================
*** trunk/titania/contributions/index.php (original)
--- trunk/titania/contributions/index.php Thu Jun 25 06:38:02 2009
***************
*** 38,44 ****
  // 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::$author->user_id == phpbb::$user->data['user_id'] || isset(titania::$contrib->coauthors[phpbb::$user->data['user_id']]))
  	{
  		titania::$access_level = TITANIA_ACCESS_AUTHORS;
  	}
--- 38,44 ----
  // 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;
  	}

Modified: trunk/titania/contributions/support.php
==============================================================================
*** trunk/titania/contributions/support.php (original)
--- trunk/titania/contributions/support.php Thu Jun 25 06:38:02 2009
***************
*** 16,29 ****
--- 16,51 ----
  	exit;
  }
  
+ $action = request_var('action', '');
+ 
  switch ($action)
  {
  	case 'post' :
+ 		titania::page_header('CONTRIB_SUPPORT_ADD');
+ 		titania::page_footer(true, 'contributions/contribution_support_post.html');
  	break;
  
  	case 'edit' :
+ 		titania::page_header('CONTRIB_SUPPORT_EDIT');
+ 		titania::page_footer(true, 'contributions/contribution_support_post.html');
  	break;
  
  	case 'delete' :
+ 		if (confirm_box(true))
+ 		{
+ 
+ 		}
+ 		else
+ 		{
+ 			confirm_box(false, 'CONTRIB_SUPPORT_DELETE');
+ 		}
+ 		redirect(titania::$contrib->get_url() . '/support');
+ 	break;
+ 
+ 	default :
+ 		titania_display_forums('contrib', titania::$contrib);
+ 
+ 		titania::page_header('CONTRIB_SUPPORT');
+ 		titania::page_footer(true, 'contributions/contribution_support.html');
  	break;
  }
\ No newline at end of file

Modified: trunk/titania/includes/constants.php
==============================================================================
*** trunk/titania/includes/constants.php (original)
--- trunk/titania/includes/constants.php Thu Jun 25 06:38:02 2009
***************
*** 32,42 ****
--- 32,44 ----
  define('TITANIA_CONTRIB_FAQ_TABLE',				$table_prefix . 'contrib_faq');
  define('TITANIA_CONTRIB_IN_CATEGORIES_TABLE',	$table_prefix . 'contrib_in_categories');
  define('TITANIA_CONTRIB_TAGS_TABLE',			$table_prefix . 'contrib_tags');
+ define('TITANIA_POSTS_TABLE',					$table_prefix . 'posts');
  define('TITANIA_QUEUE_TABLE',					$table_prefix . 'queue');
  define('TITANIA_RATINGS_TABLE',					$table_prefix . 'ratings');
  define('TITANIA_REVISIONS_TABLE',				$table_prefix . 'revisions');
  define('TITANIA_TAG_FIELDS_TABLE',				$table_prefix . 'tag_fields');
  define('TITANIA_TAG_TYPES_TABLE',				$table_prefix . 'tag_types');
+ define('TITANIA_TOPICS_TABLE',					$table_prefix . 'topics');
  define('TITANIA_WATCH_TABLE',					$table_prefix . 'watch');
  
  // Contribution revision status

Modified: trunk/titania/includes/core/cache.php
==============================================================================
*** trunk/titania/includes/core/cache.php (original)
--- trunk/titania/includes/core/cache.php Thu Jun 25 06:38:02 2009
***************
*** 101,104 ****
--- 101,229 ----
  
  		return (isset($parent_list[$category_id])) ? $parent_list[$category_id] : array();
  	}
+ 
+ 	/**
+ 	* Get the contrib authors for the specified contribution id
+ 	*
+ 	* @param int $contrib_id The contribution ID
+ 	*
+ 	* @return array|bool Array of author user_id's if the item exists, boolean false if the contrib item does not exist.
+ 	*/
+ 	public function get_contrib_authors($contrib_id)
+ 	{
+ 		$contrib_id = (int) $contrib_id;
+ 
+ 		// We shall group contributions by id in groups of 1000
+ 		$contrib_block_name = '_titania_contribs_' . floor($contrib_id / 1000);
+ 
+ 		$contrib_block = $this->get($contrib_block_name);
+ 
+ 		if ($contrib_block !== false)
+ 		{
+ 			if (isset($contrib_block[$contrib_id]))
+ 			{
+ 				return $contrib_block[$contrib_id];
+ 			}
+ 		}
+ 		else
+ 		{
+ 			// Else the cache file did not exist and we need to start over
+ 			$contrib_block = array();
+ 		}
+ 
+ 		$contrib_block[$contrib_id] = array();
+ 
+ 		// Need to get the authors for the selected contrib
+ 		$sql = 'SELECT contrib_user_id FROM ' . TITANIA_CONTRIBS_TABLE . '
+ 			WHERE contrib_id = ' . $contrib_id;
+ 		phpbb::$db->sql_query($sql);
+ 		$user_id = phpbb::$db->sql_fetchfield('contrib_user_id');
+ 		phpbb::$db->sql_freeresult();
+ 
+ 		if (!$user_id) // Contrib does not exist
+ 		{
+ 			$contrib_block[$contrib_id] = false;
+ 
+ 			// Store the updated cache data
+ 			$this->put($contrib_block_name, $contrib_block);
+ 
+ 			return false;
+ 		}
+ 
+ 		$contrib_block[$contrib_id][] = $user_id;
+ 
+ 		// Now get the co-authors
+ 		$sql = 'SELECT user_id FROM ' . TITANIA_CONTRIB_COAUTHORS_TABLE . '
+ 			WHERE contrib_id = ' . $contrib_id;
+ 		$result = phpbb::$db->sql_query($sql);
+ 		while ($row = phpbb::$db->sql_fetchrow($result))
+ 		{
+ 			$contrib_block[$contrib_id][] = $row['user_id'];
+ 		}
+ 		phpbb::$db->sql_freeresult($result);
+ 
+ 		// Store the updated cache data
+ 		$this->put($contrib_block_name, $contrib_block);
+ 
+ 		return $contrib_block[$contrib_id];
+ 	}
+ 
+ 	/**
+ 	* Get the author contribs for the specified user id
+ 	*
+ 	* @param int $user_id The user ID
+ 	*
+ 	* @return array Array of contrib_id's
+ 	*/
+ 	public function get_author_contribs($user_id)
+ 	{
+ 		$author_id = (int) $author_id;
+ 
+ 		// We shall group authors by id in groups of 2500
+ 		$author_block_name = '_titania_authors_' . floor($user_id / 2500);
+ 
+ 		$author_block = $this->get($author_block_name);
+ 
+ 		if ($author_block !== false)
+ 		{
+ 			if (isset($author_block[$user_id]))
+ 			{
+ 				return $author_block[$user_id];
+ 			}
+ 		}
+ 		else
+ 		{
+ 			// Else the cache file did not exist and we need to start over
+ 			$author_block = array();
+ 		}
+ 
+ 		$author_block[$user_id] = array();
+ 
+ 		// Need to get the contribs for the selected author
+ 		$sql = 'SELECT contrib_id FROM ' . TITANIA_CONTRIBS_TABLE . '
+ 			WHERE contrib_user_id = ' . $user_id;
+ 		$result = phpbb::$db->sql_query($sql);
+ 
+ 		while ($row = phpbb::$db->sql_fetchrow($result))
+ 		{
+ 			$author_block[$user_id][] = $row['contrib_id'];
+ 		}
+ 
+ 		phpbb::$db->sql_freeresult($result);
+ 
+ 		// Now get the lists where the user is a co-author
+ 		$sql = 'SELECT contrib_id FROM ' . TITANIA_CONTRIB_COAUTHORS_TABLE . '
+ 			WHERE user_id = ' . $user_id;
+ 		$result = phpbb::$db->sql_query($sql);
+ 		while ($row = phpbb::$db->sql_fetchrow($result))
+ 		{
+ 			$author_block[$user_id][] = $row['contrib_id'];
+ 		}
+ 		phpbb::$db->sql_freeresult($result);
+ 
+ 		// Store the updated cache data
+ 		$this->put($author_block_name, $author_block);
+ 
+ 		return $author_block[$user_id];
+ 	}
  }

Modified: trunk/titania/includes/functions_display.php
==============================================================================
*** trunk/titania/includes/functions_display.php (original)
--- trunk/titania/includes/functions_display.php Thu Jun 25 06:38:02 2009
***************
*** 81,86 ****
--- 81,88 ----
  		$category->__set_array($row);
  
  		phpbb::$template->assign_block_vars($blockname, $category->assign_display(true));
+ 
+ 		unset($category);
  	}
  	phpbb::$db->sql_freeresult($result);
  }
***************
*** 138,143 ****
--- 140,246 ----
  
  			'S_CONTRIB_TYPE'			=> $row['contrib_type'],
  		));
+ 
+ 		unset($contrib);
+ 	}
+ 	phpbb::$db->sql_freeresult($result);
+ }
+ 
+ /**
+ * Display "forum" like section for support/tracker/etc
+ *
+ * @param string $type The type (support, review, queue, tracker, author_support, author_tracker) author_ for displaying posts from the areas the given author is involved in (either an author/co-author)
+ * @param object|boolean $object The object (for contrib related (support, review, queue, tracker) and author_ modes)
+ * @param object|boolean $sort The sort object (includes/tools/sort.php)
+ * @param array $options Extra options (limit, category (for tracker))
+ */
+ function titania_display_forums($type, $object = false, $sort = false, $options = array('limit' => 10))
+ {
+ 	titania::load_object('topic');
+ 
+ 	$start = request_var('start', 0);
+ 	$limit = request_var('limit', ((isset($options['limit'])) ? (int) $options['limit'] : 10));
+ 
+ 	$sql_ary = array(
+ 		'SELECT' => '*',
+ 		'FROM'		=> array(
+ 			TITANIA_TOPICS_TABLE => 't',
+ 		),
+ 		'WHERE' => 'topic_access >= ' . titania::$access_level,
+ 		'ORDER_BY'	=> 'topic_sticky DESC',
+ 	);
+ 
+ 	// Sort options
+ 	if ($sort !== false)
+ 	{
+ 		$sql_ary['ORDER_BY'] .= ', ' . $sort->get_order_by();
+ 	}
+ 	else
+ 	{
+ 		$sql_ary['ORDER_BY'] .= ', topic_last_post_time DESC';
+ 	}
+ 
+ 	// If they are not moderators we need to add some more checks
+ 	if (!phpbb::$auth->acl_get('titania_post_mod'))
+ 	{
+ 		$sql_ary['WHERE'] .= ' AND topic_deleted = 0';
+ 		$sql_ary['WHERE'] .= ' AND topic_approved = 1';
+ 	}
+ 
+ 	// type specific things
+ 	switch ($type)
+ 	{
+ 		case 'tracker' :
+ 			$sql_ary['WHERE'] .= ' AND topic_type = ' . TITANIA_POST_TRACKER;
+ 
+ 			if (isset($options['category']))
+ 			{
+ 				$sql_ary['WHERE'] .= ' AND topic_category = ' . (int) $options['category'];
+ 			}
+ 		break;
+ 
+ 		case 'queue' :
+ 			$sql_ary['WHERE'] .= ' AND topic_type = ' . TITANIA_POST_QUEUE;
+ 		break;
+ 
+ 		case 'review' :
+ 			$sql_ary['WHERE'] .= ' AND topic_type = ' . TITANIA_POST_REVIEW;
+ 		break;
+ 
+ 		case 'author_support' :
+ 			$sql_ary['WHERE'] .= ' AND topic_type = ' . TITANIA_POST_DEFAULT;
+ 			$sql_ary['WHERE'] .= ' AND ' . phpbb::$db->sql_in_set('contrib_id', titania::$cache->get_author_contribs($object->user_id));
+ 		break;
+ 
+ 		case 'author_tracker' :
+ 			$sql_ary['WHERE'] .= ' AND topic_type = ' . TITANIA_POST_TRACKER;
+ 			$sql_ary['WHERE'] .= ' AND ' . phpbb::$db->sql_in_set('contrib_id', titania::$cache->get_author_contribs($object->user_id));
+ 		break;
+ 
+ 		case 'support' :
+ 		default :
+ 			$sql_ary['WHERE'] .= ' AND topic_type = ' . TITANIA_POST_DEFAULT;
+ 		break;
+ 	}
+ 
+ 	// Main SQL Query
+ 	$sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
+ 
+ 	// Count SQL Query
+ 	$sql_ary['SELECT'] = 'COUNT(topic_id) AS cnt';
+ 	$count_sql = phpbb::$db->sql_build_query('SELECT', $sql_ary);
+ 	phpbb::$db->sql_query($count_sql);
+ 	$count = phpbb::$db->sql_fetchfield('cnt');
+ 	phpbb::$db->sql_freeresult();
+ 
+ 	$result = phpbb::$db->sql_query_limit($sql, $limit, $start);
+ 	while ($row = phpbb::$db->sql_fetchrow($result))
+ 	{
+ 		$topic = new titania_topic($row['topic_type']);
+ 
+ 		phpbb::$template->assign_block_vars('topics', $topic->assign_details());
+ 
+ 		unset($topic);
  	}
  	phpbb::$db->sql_freeresult($result);
  }
\ No newline at end of file

Modified: trunk/titania/includes/objects/contribution.php
==============================================================================
*** trunk/titania/includes/objects/contribution.php (original)
--- trunk/titania/includes/objects/contribution.php Thu Jun 25 06:38:02 2009
***************
*** 63,68 ****
--- 63,77 ----
  	public $rating;
  
  	/**
+ 	* is_author (true when visiting user is the author)
+ 	* is_active_coauthor (true when visiting user is an active co-author)
+ 	* is_coauthor (true when visiting user is a non-active co-author)
+ 	*/
+ 	public $is_author = false;
+ 	public $is_active_coauthor = false;
+ 	public $is_coauthor = false;
+ 
+ 	/**
  	 * Constructor class for the contribution object
  	 */
  	public function __construct()
***************
*** 190,195 ****
--- 199,218 ----
  		}
  		phpbb::$db->sql_freeresult($result);
  
+ 		// Check author/co-author status
+ 		if ($this->contrib_user_id == phpbb::$user->data['user_id'])
+ 		{
+ 			$this->is_author = true;
+ 		}
+ 		else if (isset($this->coauthors[phpbb::$user->data['user_id']]))
+ 		{
+ 			$this->is_coauthor = true;
+ 
+ 			if ($this->coauthors[phpbb::$user->data['user_id']]['active'])
+ 			{
+ 				$this->is_active_coauthor = true;
+ 			}
+ 		}
  		return true;
  	}
  

Modified: trunk/titania/includes/objects/topic.php
==============================================================================
*** trunk/titania/includes/objects/topic.php (original)
--- trunk/titania/includes/objects/topic.php Thu Jun 25 06:38:02 2009
***************
*** 54,77 ****
  			'topic_id'				=> array('default' => 0),
  			'topic_type'			=> array('default' => 0), // Post Type, TITANIA_POST_ constants
  			'topic_access'			=> array('default' => TITANIA_ACCESS_PUBLIC), // Access level, TITANIA_ACCESS_ constants
  
  			'topic_status'			=> array('default' => 0), // Topic Status, use tags from the DB
  			'topic_sticky'			=> array('default' => false),
  			'topic_locked'			=> array('default' => false),
  			'topic_approved'		=> array('default' => true),
  			'topic_reported'		=> array('default' => false), // True if any posts in the topic are reported
  			'topic_deleted'			=> array('default' => false), // True if the topic is soft deleted
  
- 			'topic_user_id'			=> array('default' => (int) phpbb::$user->data['user_id']),
- 
  			'topic_time'			=> array('default' => (int) titania::$time),
  
  			'topic_posts'			=> array('default' => ''), // Post count; separated by : between access levels ('10:9:8' = 10 team; 9 Mod Author; 8 Public)
  
  			'topic_subject'			=> array('default' => ''),
  
  			'topic_last_post_id'			=> array('default' => 0),
  			'topic_last_post_user_id'		=> array('default' => 0),
  			'topic_last_post_user_colour'	=> array('default' => ''),
  			'topic_last_post_time'			=> array('default' => (int) titania::$time),
  			'topic_last_post_subject'		=> array('default' => ''),
--- 54,84 ----
  			'topic_id'				=> array('default' => 0),
  			'topic_type'			=> array('default' => 0), // Post Type, TITANIA_POST_ constants
  			'topic_access'			=> array('default' => TITANIA_ACCESS_PUBLIC), // Access level, TITANIA_ACCESS_ constants
+ 			'topic_category'		=> array('default' => 0), // Category for the topic. For the Tracker
  
  			'topic_status'			=> array('default' => 0), // Topic Status, use tags from the DB
+ 			'topic_assigned'		=> array('default' => ''), // Topic assigned status; u- for user, g- for group (followed by the id).  For the tracker
  			'topic_sticky'			=> array('default' => false),
  			'topic_locked'			=> array('default' => false),
  			'topic_approved'		=> array('default' => true),
  			'topic_reported'		=> array('default' => false), // True if any posts in the topic are reported
  			'topic_deleted'			=> array('default' => false), // True if the topic is soft deleted
  
  			'topic_time'			=> array('default' => (int) titania::$time),
  
  			'topic_posts'			=> array('default' => ''), // Post count; separated by : between access levels ('10:9:8' = 10 team; 9 Mod Author; 8 Public)
  
  			'topic_subject'			=> array('default' => ''),
  
+ 			'topic_first_post_id'			=> array('default' => 0),
+ 			'topic_first_post_user_id'		=> array('default' => 0),
+ 			'topic_first_post_username'		=> array('default' => ''),
+ 			'topic_first_post_user_colour'	=> array('default' => ''),
+ 			'topic_first_post_time'			=> array('default' => (int) titania::$time),
+ 
  			'topic_last_post_id'			=> array('default' => 0),
  			'topic_last_post_user_id'		=> array('default' => 0),
+ 			'topic_last_post_username'		=> array('default' => ''),
  			'topic_last_post_user_colour'	=> array('default' => ''),
  			'topic_last_post_time'			=> array('default' => (int) titania::$time),
  			'topic_last_post_subject'		=> array('default' => ''),
***************
*** 180,183 ****
--- 187,294 ----
  
  		return $postcount[$access_level];
  	}
+ 
+ 	/**
+ 	* Get the URL to this topic
+ 	*
+ 	* @param bool $ugly True to force the use of ugly (normal) URLs, false to use the pretty URLs if we can.  Use ugly URLs for editing and things like that
+ 	*/
+ 	public function get_url($ugly = false)
+ 	{
+ 		if ($ugly == false && !empty(titania::$contrib))
+ 		{
+ 			// We are *probably* visiting a contrib page
+ 			$url = titania::$contrib->get_url();
+ 		}
+ 		else if ($ugly == false && !empty(titania::$author))
+ 		{
+ 			// We are *probably* viewing the author's page
+ 			$url = titania::$author->get_url();
+ 		}
+ 		else
+ 		{
+ 			// The ugly URL
+ 			switch ($this->topic_type)
+ 			{
+ 				case TITANIA_POST_TRACKER :
+ 					return titania_sid('contributions/index', "page=tracker&c={$this->contrib_id}&id={$this->topic_id}");
+ 				break;
+ 
+ 				case TITANIA_POST_QUEUE :
+ 					return titania_sid('contributions/queue', "page=queue&c={$this->contrib_id}" . $post_url . $action_url);
+ 				break;
+ 
+ 				case TITANIA_POST_REVIEW :
+ 					return titania_sid('contributions/review', "page=review&c={$this->contrib_id}&id={$this->topic_id}");
+ 				break;
+ 
+ 				default :
+ 					return titania_sid('contributions/support', "page=support&c={$this->contrib_id}&id={$this->topic_id}");
+ 				break;
+ 			}
+ 		}
+ 
+ 		switch ($this->topic_type)
+ 		{
+ 			case TITANIA_POST_TRACKER :
+ 				$url .= '/tracker/' . $this->topic_id;
+ 			break;
+ 
+ 			case TITANIA_POST_QUEUE :
+ 				$url .= '/queue/' . $this->topic_id;
+ 			break;
+ 
+ 			case TITANIA_POST_REVIEW :
+ 				$url .= '/review/' . $this->topic_id;
+ 			break;
+ 
+ 			default :
+ 				$url .= '/support/' . $this->topic_id;
+ 			break;
+ 		}
+ 
+ 		return $url;
+ 	}
+ 
+ 	/**
+ 	* Assign details
+ 	*
+ 	* A little different from those in other classes, this one only returns the info ready for output
+ 	*/
+ 	public function assign_details()
+ 	{
+ 		$details = array(
+ 			'TOPIC_ID'						=> $this->topic_id,
+ 			'TOPIC_TYPE'					=> $this->topic_type,
+ 			'TOPIC_ACCESS'					=> $this->topic_access,
+ 			'TOPIC_STATUS'					=> $this->topic_status, // @todo build a function for outputting this
+ 			'TOPIC_STICKY'					=> $this->topic_sticky,
+ 			'TOPIC_LOCKED'					=> $this->topic_locked,
+ 			'TOPIC_APPROVED'				=> $this->topic_approved,
+ 			'TOPIC_REPORTED'				=> $this->topic_reported,
+ 			'TOPIC_DELETED'					=> $this->topic_deleted, // @todo output this to be something useful
+ 			'TOPIC_ASSIGNED'				=> $this->topic_assigned, // @todo output this to be something useful
+ 			'TOPIC_TIME'					=> phpbb::$user->format_date($this->topic_time),
+ 			'TOPIC_POSTCOUNT'				=> $this->get_postcount(titania::$access_level),
+ 			'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),
+ 			'TOPIC_FIRST_POST_TIME'			=> phpbb::$user->format_date($this->topic_first_post_time),
+ 
+ 			'TOPIC_LAST_POST_ID'			=> $this->topic_first_post_id,
+ 			'TOPIC_LAST_POST_USER_ID'		=> $this->topic_first_post_user_id,
+ 			'TOPIC_LAST_POST_USER_COLOUR'	=> $this->topic_first_post_user_colour,
+ 			'TOPIC_LAST_POST_USER_FULL'		=> get_username_string('full', $this->topic_first_post_user_id, $this->topic_first_post_username, $this->topic_first_post_user_colour),
+ 			'TOPIC_LAST_POST_TIME'			=> phpbb::$user->format_date($this->topic_first_post_time),
+ 			'TOPIC_LAST_POST_SUBJECT'		=> censor_text($this->topic_last_post_subject),
+ 
+ 			'U_VIEW_TOPIC'					=> $this->get_url(),
+ 			'U_VIEW_LAST_POST'				=> $this->get_url(true) . "&p={$this->last_post_id}#{$this->last_post_id}",
+ 		);
+ 
+ 		return $details;
+ 	}
  }




More information about the customisationdb-commits mailing list