[Customisation Database Commits] r615 - in /trunk/titania: contributions/support.php includes/objects/post.php includes/overlords/posts.php includes/tools/posting.php
Nathan Guse
exreaction at phpbb.com
Sat Feb 20 02:25:35 GMT 2010
Author: exreaction
Date: Sat Feb 20 02:25:35 2010
New Revision: 615
Log:
Use our posting file for the support page
Some fixes for permissions
Modified:
trunk/titania/contributions/support.php
trunk/titania/includes/objects/post.php
trunk/titania/includes/overlords/posts.php
trunk/titania/includes/tools/posting.php
Modified: trunk/titania/contributions/support.php
==============================================================================
*** trunk/titania/contributions/support.php (original)
--- trunk/titania/contributions/support.php Sat Feb 20 02:25:35 2010
***************
*** 68,252 ****
// Output the simple info on the contrib
titania::$contrib->assign_details(true);
! $action = request_var('action', '');
!
! switch ($action)
! {
! case 'post' :
! case 'reply' :
! case 'edit' :
! titania::add_lang('posting');
! phpbb::$user->add_lang('posting');
!
! if ($action != 'edit' && (($action == 'post' && !phpbb::$auth->acl_get('u_titania_topic')) || ($action == 'reply' && (!$topic_id || !phpbb::$auth->acl_get('u_titania_post')))))
! {
! titania::needs_auth();
! }
!
! if ($action == 'post')
! {
! $topic = new titania_topic(TITANIA_SUPPORT, titania::$contrib);
! $post = new titania_post(TITANIA_SUPPORT, $topic);
! $post->topic->contrib_id = titania::$contrib->contrib_id;
! }
! else if ($action == 'reply')
! {
! $post = new titania_post(TITANIA_SUPPORT, $topic);
! }
! else
! {
! $post = new titania_post(TITANIA_SUPPORT, $topic, $post_id);
! if ($post->load() === false)
! {
! trigger_error('NO_POST');
! }
! }
!
! // Load the message object
! $message = new titania_message($post);
! $message->set_auth(array(
! 'bbcode' => phpbb::$auth->acl_get('u_titania_bbcode'),
! 'smilies' => phpbb::$auth->acl_get('u_titania_smilies'),
! 'lock' => ($action == 'edit' && $post->post_user_id != phpbb::$user->data['user_id'] && phpbb::$auth->acl_get('m_titania_post_mod')) ? true : false,
! 'sticky_topic' => (($action == 'post' || ($action == 'edit' && $post_id == $post->topic->topic_first_post_id)) && (phpbb::$auth->acl_get('m_titania_post_mod') || titania::$contrib->is_author || titania::$contrib->is_active_coauthor)) ? true : false,
! 'lock_topic' => (phpbb::$auth->acl_get('m_titania_post_mod') || (phpbb::$auth->acl_get('u_titania_post_mod_own') && $post->topic->topic_first_post_user_id == phpbb::$user->data['user_id'])) ? true : false,
! 'attachments' => phpbb::$auth->acl_get('u_titania_post_attach'),
! ));
! $message->set_settings(array(
! 'display_captcha' => (!phpbb::$user->data['is_registered']) ? true : false,
! 'subject_default_override' => ($action == 'reply') ? 'Re: ' . $topic->topic_subject : false,
! 'attachments_group' => TITANIA_ATTACH_EXT_SUPPORT,
! ));
!
! // Submit check...handles running $post->post_data() if required
! $submit = $message->submit_check();
!
! if ($submit)
! {
! $error = $post->validate();
!
! if (($validate_form_key = $message->validate_form_key()) !== false)
! {
! $error[] = $validate_form_key;
! }
!
! // @todo use permissions for captcha
! if (!phpbb::$user->data['is_registered'] && ($validate_captcha = $message->validate_captcha()) !== false)
! {
! $error[] = $validate_captcha;
! }
!
! if (sizeof($error))
! {
! phpbb::$template->assign_var('ERROR', implode('<br />', $error));
! }
! else
! {
! $post->submit();
!
! $message->submit($post->post_access);
!
! redirect($post->get_url());
! }
! }
!
! $message->display();
!
! switch ($action)
! {
! case 'post' :
! phpbb::$template->assign_vars(array(
! 'S_POST_ACTION' => titania_url::append_url(titania::$contrib->get_url('support'), array('action' => $action)),
! 'L_POST_A' => phpbb::$user->lang['POST_TOPIC'],
! ));
! titania::page_header('NEW_TOPIC');
! break;
! case 'reply' :
! phpbb::$template->assign_vars(array(
! 'S_POST_ACTION' => $topic->get_url('reply'),
! 'L_POST_A' => phpbb::$user->lang['POST_REPLY'],
! ));
! titania::page_header('POST_REPLY');
! break;
! case 'edit' :
! phpbb::$template->assign_vars(array(
! 'S_POST_ACTION' => $post->get_url('edit', false),
! 'L_POST_A' => phpbb::$user->lang['EDIT_POST'],
! ));
! titania::page_header('EDIT_POST');
! break;
! }
!
! titania::page_footer(true, 'contributions/contribution_support_post.html');
! break;
!
! case 'delete' :
! case 'undelete' :
! phpbb::$user->add_lang('posting');
!
! $post = new titania_post(TITANIA_SUPPORT, $topic, $post_id);
! if ($post->load() === false)
! {
! trigger_error('NO_POST');
! }
!
! if (titania::confirm_box(true))
! {
! if ($action == 'delete')
! {
! $redirect_post_id = posts_overlord::next_prev_post_id($post->topic_id, $posts->post_id);
!
! // Delete the post (let's not allow hard deleting for now)
! $post->soft_delete();
!
! // try a nice redirect, back to the position where the post was deleted from
! if ($redirect_post_id)
! {
! redirect(titania_url::append_url($topic->get_url(), array('p' => $redirect_post_id, '#p' => $redirect_post_id)));
! }
!
! redirect($topic->get_url());
! }
! else
! {
! $post->undelete();
!
! redirect($post->get_url());
! }
! }
! else
! {
! titania::confirm_box(false, (($action == 'delete') ? 'DELETE_POST' : 'UNDELETE_POST'), $post->get_url($action));
! }
! redirect($post->get_url());
! break;
!
! default :
! phpbb::$user->add_lang('viewforum');
! if ($topic_id)
! {
! posts_overlord::display_topic_complete($topic);
! titania::page_header(phpbb::$user->lang['CONTRIB_SUPPORT'] . ' - ' . censor_text($topic->topic_subject));
! if (phpbb::$auth->acl_get('u_titania_post'))
! {
! phpbb::$template->assign_var('U_POST_REPLY', titania_url::append_url($topic->get_url(), array('action' => 'reply')));
! }
! }
! else
! {
! topics_overlord::display_forums_complete('support', titania::$contrib);
! titania::page_header('CONTRIB_SUPPORT');
! if (phpbb::$auth->acl_get('u_titania_topic'))
! {
! phpbb::$template->assign_var('U_POST_TOPIC', titania_url::append_url(titania::$contrib->get_url('support'), array('action' => 'post')));
! }
! }
! titania::page_footer(true, 'contributions/contribution_support.html');
! break;
}
--- 68,100 ----
// Output the simple info on the contrib
titania::$contrib->assign_details(true);
! // Handle replying/editing/etc
! $posting_helper = new titania_posting(TITANIA_ATTACH_EXT_SUPPORT);
! $posting_helper->act('contributions/contribution_support_post.html', titania::$contrib, TITANIA_SUPPORT);
! phpbb::$user->add_lang('viewforum');
! if ($topic_id)
! {
! posts_overlord::display_topic_complete($topic);
! titania::page_header(phpbb::$user->lang['CONTRIB_SUPPORT'] . ' - ' . censor_text($topic->topic_subject));
! if (phpbb::$auth->acl_get('u_titania_post'))
! {
! phpbb::$template->assign_var('U_POST_REPLY', titania_url::append_url($topic->get_url(), array('action' => 'reply')));
! }
! }
! else
! {
! topics_overlord::display_forums_complete('support', titania::$contrib);
! titania::page_header('CONTRIB_SUPPORT');
! if (phpbb::$auth->acl_get('u_titania_topic'))
! {
! phpbb::$template->assign_var('U_POST_TOPIC', titania_url::append_url(titania::$contrib->get_url('support'), array('action' => 'post')));
! }
}
+
+ titania::page_footer(true, 'contributions/contribution_support.html');
\ No newline at end of file
Modified: trunk/titania/includes/objects/post.php
==============================================================================
*** trunk/titania/includes/objects/post.php (original)
--- trunk/titania/includes/objects/post.php Sat Feb 20 02:25:35 2010
***************
*** 244,264 ****
* Check if the current user has permission to do something
*
* @param string $option The auth option to check ('post', 'edit', 'soft_delete', 'hard_delete')
- * @param object $contrib The contrib object this is for (false to use titania::$contrib)
*
* @return bool True if they have permission False if not
*/
! public function acl_get($option, $contrib = false)
{
- if ($contrib === false && isset($this->topic->contrib) && is_object($this->topic->contrib))
- {
- $contrib = $this->topic->contrib;
- }
- else if ($contrib === false)
- {
- $contrib = titania::$contrib;
- }
-
// First check anonymous/bots for things they can *never* do
$no_anon = array('edit', 'soft_delete', 'undelete', 'hard_delete');
$no_bot = array('post', 'edit', 'soft_delete', 'undelete', 'hard_delete');
--- 244,254 ----
* Check if the current user has permission to do something
*
* @param string $option The auth option to check ('post', 'edit', 'soft_delete', 'hard_delete')
*
* @return bool True if they have permission False if not
*/
! public function acl_get($option)
{
// First check anonymous/bots for things they can *never* do
$no_anon = array('edit', 'soft_delete', 'undelete', 'hard_delete');
$no_bot = array('post', 'edit', 'soft_delete', 'undelete', 'hard_delete');
***************
*** 267,279 ****
return false;
}
$is_poster = ($this->post_user_id == phpbb::$user->data['user_id']) ? true : false; // Poster
! $is_author = ($contrib && ($contrib->is_author || $contrib->is_active_coauthor)) ? true : false; // Contribution author
$is_deleter = ($this->post_delete_user == phpbb::$user->data['user_id']) ? true : false;
switch ($option)
{
case 'post' :
if (phpbb::$auth->acl_get('u_titania_post') || // Can post
($is_author && phpbb::$auth->acl_get('u_titania_post_mod_own')) || // Is contrib author and can moderate own
phpbb::$auth->acl_get('m_titania_post_mod')) // Can moderate posts
--- 257,276 ----
return false;
}
+ // Can never do anything if the topic access level is greater than current access level
+ if (is_object($this->topic) && $this->topic->topic_access < titania::$access_level)
+ {
+ return false;
+ }
+
$is_poster = ($this->post_user_id == phpbb::$user->data['user_id']) ? true : false; // Poster
! $is_author = (is_object($this->topic) && is_object($this->topic->contrib) && ($this->topic->contrib->is_author || $this->topic->contrib->is_active_coauthor)) ? true : false; // Contribution author
$is_deleter = ($this->post_delete_user == phpbb::$user->data['user_id']) ? true : false;
switch ($option)
{
case 'post' :
+ case 'reply' :
if (phpbb::$auth->acl_get('u_titania_post') || // Can post
($is_author && phpbb::$auth->acl_get('u_titania_post_mod_own')) || // Is contrib author and can moderate own
phpbb::$auth->acl_get('m_titania_post_mod')) // Can moderate posts
***************
*** 283,290 ****
break;
case 'edit' :
! if (($is_poster && phpbb::$auth->acl_get('u_titania_post_edit_own')) || // Is poster and can edit own
! ($is_author && phpbb::$auth->acl_get('u_titania_post_mod_own')) || // Is contrib author and can moderate own
phpbb::$auth->acl_get('m_titania_post_mod')) // Can moderate posts
{
return true;
--- 280,287 ----
break;
case 'edit' :
! if (($is_poster && !$this->post_locked && $this->post_access >= titania::$access_level && phpbb::$auth->acl_get('u_titania_post_edit_own')) || // Is poster and can edit own
! ($is_author && !$this->post_locked && $this->post_access >= titania::$access_level && phpbb::$auth->acl_get('u_titania_post_mod_own')) || // Is contrib author and can moderate own
phpbb::$auth->acl_get('m_titania_post_mod')) // Can moderate posts
{
return true;
***************
*** 292,303 ****
break;
case 'delete' :
! return ($this->post_deleted) ? $this->acl_get('hard_delete', $contrib) : $this->acl_get('soft_delete', $contrib);
break;
case 'soft_delete' :
! if (($is_poster && phpbb::$auth->acl_get('u_titania_post_delete_own')) || // Is poster and can delete own
! ($is_author && phpbb::$auth->acl_get('u_titania_post_mod_own')) || // Is contrib author and can moderate own
phpbb::$auth->acl_get('m_titania_post_mod')) // Can moderate posts
{
return true;
--- 289,300 ----
break;
case 'delete' :
! return ($this->post_deleted) ? $this->acl_get('hard_delete') : $this->acl_get('soft_delete');
break;
case 'soft_delete' :
! if (($is_poster && !$this->post_locked && $this->post_access >= titania::$access_level && phpbb::$auth->acl_get('u_titania_post_delete_own')) || // Is poster and can delete own
! ($is_author && !$this->post_locked && $this->post_access >= titania::$access_level && phpbb::$auth->acl_get('u_titania_post_mod_own')) || // Is contrib author and can moderate own
phpbb::$auth->acl_get('m_titania_post_mod')) // Can moderate posts
{
return true;
***************
*** 305,312 ****
break;
case 'undelete' :
! if (($is_poster && $is_deleter && phpbb::$auth->acl_get('u_titania_post_delete_own')) || // Is poster and can delete own and did delete their own
! ($is_author && $is_deleter && phpbb::$auth->acl_get('u_titania_post_mod_own')) || // Is contrib author and can moderate own and did delete the message
phpbb::$auth->acl_get('m_titania_post_mod')) // Can moderate posts
{
return true;
--- 302,309 ----
break;
case 'undelete' :
! if (($is_poster && $is_deleter && !$this->post_locked && $this->post_access >= titania::$access_level && phpbb::$auth->acl_get('u_titania_post_delete_own')) || // Is poster and can delete own and did delete their own
! ($is_author && $is_deleter && !$this->post_locked && $this->post_access >= titania::$access_level && phpbb::$auth->acl_get('u_titania_post_mod_own')) || // Is contrib author and can moderate own and did delete the message
phpbb::$auth->acl_get('m_titania_post_mod')) // Can moderate posts
{
return true;
Modified: trunk/titania/includes/overlords/posts.php
==============================================================================
*** trunk/titania/includes/overlords/posts.php (original)
--- trunk/titania/includes/overlords/posts.php Sat Feb 20 02:25:35 2010
***************
*** 45,51 ****
$sql .= " ({$prefix}post_access >= " . titania::$access_level . " OR {$prefix}post_user_id = " . phpbb::$user->data['user_id'] . ')';
! if (phpbb::$auth->acl_get('m_titania_post_mod'))
{
$sql .= " AND {$prefix}post_approved = 1";
$sql .= " AND ({$prefix}post_deleted = 0 OR {$prefix}post_deleted = " . phpbb::$user->data['user_id'] . ')';
--- 45,51 ----
$sql .= " ({$prefix}post_access >= " . titania::$access_level . " OR {$prefix}post_user_id = " . phpbb::$user->data['user_id'] . ')';
! if (!phpbb::$auth->acl_get('m_titania_post_mod'))
{
$sql .= " AND {$prefix}post_approved = 1";
$sql .= " AND ({$prefix}post_deleted = 0 OR {$prefix}post_deleted = " . phpbb::$user->data['user_id'] . ')';
Modified: trunk/titania/includes/tools/posting.php
==============================================================================
*** trunk/titania/includes/tools/posting.php (original)
--- trunk/titania/includes/tools/posting.php Sat Feb 20 02:25:35 2010
***************
*** 78,83 ****
--- 78,88 ----
*/
public function post($contrib, $post_type, $s_post_action)
{
+ if (!phpbb::$auth->acl_get('u_titania_topic'))
+ {
+ titania::needs_auth();
+ }
+
// Setup the post object we'll use
$post_object = new titania_post($post_type);
$post_object->topic->contrib = $contrib;
***************
*** 115,138 ****
*/
public function reply($topic_id)
{
! // Load the stuff we need
! $topic = new titania_topic();
! $topic->topic_id = (int) $topic_id;
!
! if ($topic->load() === false)
{
! trigger_error('NO_TOPIC');
}
! $topic->contrib = new titania_contribution;
! if (!$topic->contrib->load($topic->contrib_id))
! {
! trigger_error('NO_CONTRIB');
! }
$post_object = new titania_post($topic->topic_type, $topic);
! // @todo check permissions/auth level/etc
// Load the message object
$message_object = new titania_message($post_object);
--- 120,140 ----
*/
public function reply($topic_id)
{
! if (!phpbb::$auth->acl_get('u_titania_post'))
{
! titania::needs_auth();
}
! // Load the stuff we need
! $topic = $this->load_topic($topic_id);
$post_object = new titania_post($topic->topic_type, $topic);
! // Check permissions
! if (!$post_object->acl_get('reply'))
! {
! titania::needs_auth();
! }
// Load the message object
$message_object = new titania_message($post_object);
***************
*** 166,196 ****
*/
public function edit($post_id)
{
! // Load the stuff we need
! $post_object = new titania_post();
! $post_object->post_id = (int) $post_id;
!
! if ($post_object->load() === false)
{
! trigger_error('NO_POST');
}
! $post_object->topic = new titania_topic();
! $post_object->topic->topic_id = $post_object->topic_id;
!
! if ($post_object->topic->load() === false)
! {
! trigger_error('NO_TOPIC');
! }
! $post_object->topic->contrib = new titania_contribution;
! if (!$post_object->topic->contrib->load($post_object->topic->contrib_id))
{
! trigger_error('NO_CONTRIB');
}
- // @todo check permissions/auth level/etc
-
// Load the message object
$message_object = new titania_message($post_object);
$message_object->set_auth(array(
--- 168,187 ----
*/
public function edit($post_id)
{
! if (!phpbb::$auth->acl_get('u_titania_post'))
{
! titania::needs_auth();
}
! // Load the stuff we need
! $post_object = $this->load_post($post_id);
! // Check permissions
! if (!$post_object->acl_get('edit'))
{
! titania::needs_auth();
}
// Load the message object
$message_object = new titania_message($post_object);
$message_object->set_auth(array(
***************
*** 288,312 ****
phpbb::$user->add_lang('posting');
// Load the stuff we need
! $post_object = new titania_post();
! $post_object->post_id = (int) $post_id;
!
! if ($post_object->load() === false)
! {
! trigger_error('NO_POST');
! }
!
! $post_object->topic = new titania_topic();
! $post_object->topic->topic_id = (int) $topic_id;
! if ($post_object->topic->load() === false)
{
! trigger_error('NO_TOPIC');
}
- $post_object->topic->contrib = new titania_contribution;
- $post_object->topic->contrib->load($post_object->topic->contrib_id);
-
if (titania::confirm_box(true))
{
if (!$undelete)
--- 279,292 ----
phpbb::$user->add_lang('posting');
// Load the stuff we need
! $post_object = $this->load_post($post_id);
! // Check permissions
! if ((!$undelete && !$post_object->acl_get('delete')) || ($undelete && !$post_object->acl_get('undelete')))
{
! titania::needs_auth();
}
if (titania::confirm_box(true))
{
if (!$undelete)
***************
*** 335,340 ****
--- 315,384 ----
{
titania::confirm_box(false, ((!$undelete) ? 'DELETE_POST' : 'UNDELETE_POST'), $post_object->get_url($action));
}
+
redirect($post_object->get_url(false, true));
}
+
+ /**
+ * Quick load a post
+ *
+ * @param mixed $post_id
+ * @return object
+ */
+ public function load_post($post_id)
+ {
+ $post = new titania_post();
+ $post->post_id = $post_id;
+
+ if ($post->load() === false)
+ {
+ trigger_error('NO_POST');
+ }
+
+ $post->topic = $this->load_topic($post->topic_id);
+
+ return $post;
+ }
+
+ /**
+ * Quick load a topic
+ *
+ * @param mixed $topic_id
+ * @return object
+ */
+ public function load_topic($topic_id)
+ {
+ topics_overlord::load_topic($topic_id);
+ $topic = topics_overlord::get_topic_object($topic_id);
+
+ if ($topic === false)
+ {
+ trigger_error('NO_TOPIC');
+ }
+
+ if (!is_object($topic->contrib))
+ {
+ $topic->contrib = $this->load_contrib($topic->contrib_id);
+ }
+
+ return $topic;
+ }
+
+ /**
+ * Quick load a contrib
+ *
+ * @param mixed $contrib_id
+ * @return object
+ */
+ public function load_contrib($contrib_id)
+ {
+ $contrib = new titania_contribution;
+
+ if ($contrib->load($contrib_id) === false)
+ {
+ trigger_error('NO_CONTRIB');
+ }
+
+ return $contrib;
+ }
}
\ No newline at end of file
More information about the customisationdb-commits
mailing list