Exemplo n.º 1
0
 /**
  * Shorten the amount of code required for some places
  *
  * @param mixed $object_type
  * @param mixed $object_id
  * @param mixed $url
  */
 public static function handle_subscriptions($object_type, $object_id, $url)
 {
     if (!phpbb::$user->data['is_registered']) {
         // Cannot currently handle non-registered users
         return;
     }
     $subscribe = request_var('subscribe', '');
     if ($subscribe == 'subscribe' && check_link_hash(request_var('hash', ''), 'subscribe')) {
         titania_subscriptions::subscribe($object_type, $object_id);
     } else {
         if ($subscribe == 'unsubscribe' && check_link_hash(request_var('hash', ''), 'unsubscribe')) {
             titania_subscriptions::unsubscribe($object_type, $object_id);
         }
     }
     if (titania_subscriptions::is_subscribed($object_type, $object_id)) {
         phpbb::$template->assign_vars(array('IS_SUBSCRIBED' => true, 'U_SUBSCRIBE' => titania_url::append_url($url, array('subscribe' => 'unsubscribe', 'hash' => generate_link_hash('unsubscribe')))));
     } else {
         phpbb::$template->assign_vars(array('U_SUBSCRIBE' => titania_url::append_url($url, array('subscribe' => 'subscribe', 'hash' => generate_link_hash('subscribe')))));
     }
 }
Exemplo n.º 2
0
 /**
  * Common posting stuff for post/reply/edit
  *
  * @param mixed $post_object
  * @param mixed $message_object
  */
 private function common_post($mode, $post_object, $message_object)
 {
     titania::add_lang('posting');
     phpbb::$user->add_lang('posting');
     // Submit check...handles running $post->post_data() if required
     $submit = $message_object->submit_check();
     if ($submit) {
         $error = $post_object->validate();
         if (($validate_form_key = $message_object->validate_form_key()) !== false) {
             $error[] = $validate_form_key;
         }
         // @todo use permissions for captcha
         if (!phpbb::$user->data['is_registered'] && ($validate_captcha = $message_object->validate_captcha()) !== false) {
             $error[] = $validate_captcha;
         }
         $error = array_merge($error, $message_object->error);
         if (sizeof($error)) {
             phpbb::$template->assign_var('ERROR', implode('<br />', $error));
         } else {
             // Force Queue Discussion topics to always be stickies
             if ($post_object->post_type == TITANIA_QUEUE_DISCUSSION) {
                 $post_object->topic->topic_sticky = true;
             }
             // Does the post need approval?  Never for the Queue Discussion or Queue
             if (!phpbb::$auth->acl_get('u_titania_post_approved') && $post_object->post_type != TITANIA_QUEUE_DISCUSSION && $post_object->post_type != TITANIA_QUEUE) {
                 $post_object->post_approved = false;
             }
             $post_object->submit();
             $message_object->submit($post_object->post_access);
             // Did they want to subscribe?
             if (isset($_POST['notify']) && phpbb::$user->data['is_registered']) {
                 titania_subscriptions::subscribe(TITANIA_TOPIC, $post_object->topic->topic_id);
             }
             // Unapproved posts will get a notice
             if (!$post_object->topic->get_postcount()) {
                 phpbb::$user->add_lang('posting');
                 trigger_error(phpbb::$user->lang['POST_STORED_MOD'] . '<br /><br />' . sprintf(phpbb::$user->lang['RETURN_INDEX'], '<a href="' . $post_object->topic->get_parent_url() . '">', '</a>'));
             } else {
                 if (!$post_object->post_approved) {
                     phpbb::$user->add_lang('posting');
                     trigger_error(phpbb::$user->lang['POST_STORED_MOD'] . '<br /><br />' . sprintf(phpbb::$user->lang['RETURN_TOPIC'], '<a href="' . $post_object->topic->get_url() . '">', '</a>'));
                 } else {
                     // Subscriptions
                     if ($mode == 'reply') {
                         if ($post_object->post_type == TITANIA_SUPPORT && is_object(titania::$contrib) && titania::$contrib->contrib_id == $post_object->topic->parent_id && titania::$contrib->contrib_name) {
                             // Support topic reply
                             $email_vars = array('NAME' => $post_object->topic->topic_subject, 'U_VIEW' => titania_url::append_url($post_object->topic->get_url(), array('view' => 'unread', '#' => 'unread')), 'CONTRIB_NAME' => titania::$contrib->contrib_name);
                             titania_subscriptions::send_notifications(array(TITANIA_TOPIC, TITANIA_SUPPORT), array($post_object->topic_id, $post_object->topic->parent_id), 'subscribe_notify_contrib.txt', $email_vars, $post_object->post_user_id);
                         } else {
                             $email_vars = array('NAME' => $post_object->topic->topic_subject, 'U_VIEW' => titania_url::append_url($post_object->topic->get_url(), array('view' => 'unread', '#' => 'unread')));
                             titania_subscriptions::send_notifications(TITANIA_TOPIC, $post_object->topic_id, 'subscribe_notify.txt', $email_vars, $post_object->post_user_id);
                         }
                     } else {
                         if ($mode == 'post') {
                             if ($post_object->post_type == TITANIA_SUPPORT && is_object(titania::$contrib) && titania::$contrib->contrib_id == $post_object->topic->parent_id && titania::$contrib->contrib_name) {
                                 // New support topic
                                 $email_vars = array('NAME' => $post_object->topic->topic_subject, 'U_VIEW' => $post_object->topic->get_url(), 'CONTRIB_NAME' => titania::$contrib->contrib_name);
                                 titania_subscriptions::send_notifications($post_object->post_type, $post_object->topic->parent_id, 'subscribe_notify_forum_contrib.txt', $email_vars, $post_object->post_user_id);
                             } else {
                                 $email_vars = array('NAME' => $post_object->topic->topic_subject, 'U_VIEW' => $post_object->topic->get_url());
                                 titania_subscriptions::send_notifications($post_object->post_type, $post_object->topic->parent_id, 'subscribe_notify_forum.txt', $email_vars, $post_object->post_user_id);
                             }
                         }
                     }
                 }
             }
             redirect($post_object->get_url());
         }
     } else {
         if (sizeof($message_object->error)) {
             phpbb::$template->assign_var('ERROR', implode('<br />', $message_object->error));
         }
     }
     // Do we subscribe to actual topic?
     $is_subscribed = ($mode == 'edit' || $mode == 'reply') && titania_subscriptions::is_subscribed(TITANIA_TOPIC, $post_object->topic->topic_id) ? true : false;
     phpbb::$template->assign_vars(array('S_NOTIFY_ALLOWED' => phpbb::$user->data['is_registered'] && !$is_subscribed ? true : false, 'S_NOTIFY_CHECKED' => phpbb::$user->data['is_registered'] && !$is_subscribed && phpbb::$user->data['user_notify'] && $post_object->post_type == TITANIA_SUPPORT ? ' checked=checked' : ''));
     $message_object->display();
 }