Пример #1
0
 public function recountThankyou()
 {
     //Only perform this action if upgrading form previous version
     $version = $this->getVersion();
     if (version_compare($version->version, '2.0.0-BETA2', ">")) {
         return true;
     }
     // If the migration is from previous version thant 1.6.0 doesn't need to recount
     if (version_compare($version->version, '1.6.0', "<")) {
         return true;
     }
     KunenaForumMessageThankyouHelper::recount();
     return true;
 }
Пример #2
0
 public function getMessages()
 {
     if ($this->messages === false) {
         $layout = $this->getState('layout');
         $threaded = $layout == 'indented' || $layout == 'threaded';
         $this->messages = KunenaForumMessageHelper::getMessagesByTopic($this->getState('item.id'), $this->getState('list.start'), $this->getState('list.limit'), $this->getState('list.direction'), $this->getState('hold'), $threaded);
         // Get thankyous for all messages in the page
         $thankyous = KunenaForumMessageThankyouHelper::getByMessage($this->messages);
         // First collect ids and users
         $userlist = array();
         $this->threaded = array();
         $location = $this->getState('list.start');
         foreach ($this->messages as $message) {
             $message->replynum = ++$location;
             if ($threaded) {
                 // Threaded ordering
                 if (isset($this->messages[$message->parent])) {
                     $this->threaded[$message->parent][] = $message->id;
                 } else {
                     $this->threaded[0][] = $message->id;
                 }
             }
             $userlist[intval($message->userid)] = intval($message->userid);
             $userlist[intval($message->modified_by)] = intval($message->modified_by);
             $thankyou_list = $thankyous[$message->id]->getList();
             $message->thankyou = array();
             if (!empty($thankyou_list)) {
                 $message->thankyou = $thankyou_list;
             }
         }
         if (!isset($this->messages[$this->getState('item.mesid')]) && !empty($this->messages)) {
             $this->setState('item.mesid', reset($this->messages)->id);
         }
         if ($threaded) {
             if (!isset($this->messages[$this->topic->first_post_id])) {
                 $this->messages = $this->getThreadedOrdering(0, array('edge'));
             } else {
                 $this->messages = $this->getThreadedOrdering();
             }
         }
         // Prefetch all users/avatars to avoid user by user queries during template iterations
         KunenaUserHelper::loadUsers($userlist);
         // Get attachments
         KunenaForumMessageAttachmentHelper::getByMessage($this->messages);
     }
     return $this->messages;
 }
Пример #3
0
 /**
  * @param null $identifier
  * @param bool $reload
  *
  * @return KunenaForumMessageThankyou
  */
 public static function getInstance($identifier = null, $reload = false)
 {
     return KunenaForumMessageThankyouHelper::get($identifier, $reload);
 }
Пример #4
0
 /**
  * Method to delete the KunenaForumMessage object from the database.
  *
  * @return bool	True on success
  */
 public function delete()
 {
     if (!$this->exists()) {
         return true;
     }
     if (!parent::delete()) {
         return false;
     }
     $this->hold = 1;
     $attachments = $this->getAttachments();
     foreach ($attachments as $attachment) {
         if (!$attachment->delete()) {
             $this->setError($attachment->getError());
         }
     }
     $db = JFactory::getDBO();
     // Delete thank yous
     $queries[] = "DELETE FROM #__kunena_thankyou WHERE postid={$db->quote($this->id)}";
     // Delete message
     $queries[] = "DELETE FROM #__kunena_messages_text WHERE mesid={$db->quote($this->id)}";
     // Cascade changes into other tables
     $this->update();
     foreach ($queries as $query) {
         $db->setQuery($query);
         $db->query();
         KunenaError::checkDatabaseError();
     }
     KunenaForumMessageThankyouHelper::recount();
     return true;
 }
Пример #5
0
 /**
  * Method to delete the KunenaForumTopic object from the database.
  *
  * @param bool $recount
  *
  * @return bool	True on success.
  */
 public function delete($recount = true)
 {
     if (!$this->exists()) {
         return true;
     }
     if (!parent::delete()) {
         return false;
     }
     // Clear authentication cache
     $this->_authfcache = $this->_authccache = $this->_authcache = array();
     // NOTE: shadow topic doesn't exist, DO NOT DELETE OR CHANGE ANY EXTERNAL INFORMATION
     if ($this->moved_id == 0) {
         $db = JFactory::getDBO();
         // Delete user topics
         $queries[] = "DELETE FROM #__kunena_user_topics WHERE topic_id={$db->quote($this->id)}";
         // Delete user read
         $queries[] = "DELETE FROM #__kunena_user_read WHERE topic_id={$db->quote($this->id)}";
         // Delete poll (users)
         $queries[] = "DELETE FROM #__kunena_polls_users WHERE pollid={$db->quote($this->poll_id)}";
         // Delete poll (options)
         $queries[] = "DELETE FROM #__kunena_polls_options WHERE pollid={$db->quote($this->poll_id)}";
         // Delete poll
         $queries[] = "DELETE FROM #__kunena_polls WHERE id={$db->quote($this->poll_id)}";
         // Delete thank yous
         $queries[] = "DELETE t FROM #__kunena_thankyou AS t INNER JOIN #__kunena_messages AS m ON m.id=t.postid WHERE m.thread={$db->quote($this->id)}";
         // Delete all messages
         $queries[] = "DELETE m, t FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON m.id=t.mesid WHERE m.thread={$db->quote($this->id)}";
         foreach ($queries as $query) {
             $db->setQuery($query);
             $db->query();
             KunenaError::checkDatabaseError();
         }
         // FIXME: add recount statistics
         if ($recount) {
             KunenaUserHelper::recount();
             KunenaForumCategoryHelper::recount();
             KunenaAttachmentHelper::cleanup();
             KunenaForumMessageThankyouHelper::recount();
         }
     }
     return true;
 }
Пример #6
0
	public static function cleanup()
	{
		self::$_instances = array();
	}
Пример #7
0
 /**
  * Delete this category and all related information from the database.
  *
  * @return bool	True on success
  */
 public function delete()
 {
     if (!$this->exists()) {
         return true;
     }
     if (!parent::delete()) {
         return false;
     }
     $access = KunenaAccess::getInstance();
     $access->clearCache();
     $db = JFactory::getDBO();
     $queries[] = "DELETE FROM #__kunena_aliases WHERE type='catid' AND item={$db->quote($this->id)}";
     // Delete user topics
     $queries[] = "DELETE FROM #__kunena_user_topics WHERE category_id={$db->quote($this->id)}";
     // Delete user categories
     $queries[] = "DELETE FROM #__kunena_user_categories WHERE category_id={$db->quote($this->id)}";
     // Delete user read
     $queries[] = "DELETE FROM #__kunena_user_read WHERE category_id={$db->quote($this->id)}";
     // Delete thank yous
     $queries[] = "DELETE t FROM #__kunena_thankyou AS t INNER JOIN #__kunena_messages AS m ON m.id=t.postid WHERE m.catid={$db->quote($this->id)}";
     // Delete poll users
     $queries[] = "DELETE p FROM #__kunena_polls_users AS p INNER JOIN #__kunena_topics AS tt ON tt.poll_id=p.pollid WHERE tt.category_id={$db->quote($this->id)} AND tt.moved_id=0";
     // Delete poll options
     $queries[] = "DELETE p FROM #__kunena_polls_options AS p INNER JOIN #__kunena_topics AS tt ON tt.poll_id=p.pollid WHERE tt.category_id={$db->quote($this->id)} AND tt.moved_id=0";
     // Delete polls
     $queries[] = "DELETE p FROM #__kunena_polls AS p INNER JOIN #__kunena_topics AS tt ON tt.poll_id=p.id WHERE tt.category_id={$db->quote($this->id)} AND tt.moved_id=0";
     // Delete messages
     $queries[] = "DELETE m, t FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON m.id=t.mesid WHERE m.catid={$db->quote($this->id)}";
     // TODO: delete attachments
     // TODO: delete keywords
     // Delete topics
     $queries[] = "DELETE FROM #__kunena_topics WHERE category_id={$db->quote($this->id)}";
     foreach ($queries as $query) {
         $db->setQuery($query);
         $db->query();
         KunenaError::checkDatabaseError();
     }
     KunenaUserHelper::recount();
     KunenaForumMessageThankyouHelper::recount();
     $this->id = null;
     KunenaForumCategoryHelper::register($this);
     return true;
 }
Пример #8
0
 /**
  * Prepare messages for display.
  *
  * @param   int  $mesid  Selected message Id.
  *
  * @return  void
  */
 protected function prepareMessages($mesid)
 {
     // Get thank yous for all messages in the page
     $thankyous = KunenaForumMessageThankyouHelper::getByMessage($this->messages);
     // First collect ids and users.
     $threaded = $this->layout == 'indented' || $this->layout == 'threaded';
     $userlist = array();
     $this->threaded = array();
     $location = $this->pagination->limitstart;
     foreach ($this->messages as $message) {
         $message->replynum = ++$location;
         if ($threaded) {
             // Threaded ordering
             if (isset($this->messages[$message->parent])) {
                 $this->threaded[$message->parent][] = $message->id;
             } else {
                 $this->threaded[0][] = $message->id;
             }
         }
         $userlist[(int) $message->userid] = (int) $message->userid;
         $userlist[(int) $message->modified_by] = (int) $message->modified_by;
         $thankyou_list = $thankyous[$message->id]->getList();
         $message->thankyou = array();
         if (!empty($thankyou_list)) {
             $message->thankyou = $thankyou_list;
         }
     }
     if (!isset($this->messages[$mesid]) && !empty($this->messages)) {
         $this->message = reset($this->messages);
     }
     if ($threaded) {
         if (!isset($this->messages[$this->topic->first_post_id])) {
             $this->messages = $this->getThreadedOrdering(0, array('edge'));
         } else {
             $this->messages = $this->getThreadedOrdering();
         }
     }
     // Prefetch all users/avatars to avoid user by user queries during template iterations
     KunenaUserHelper::loadUsers($userlist);
     // Prefetch attachments.
     KunenaAttachmentHelper::getByMessage($this->messages);
 }
Пример #9
0
 protected function setThankyou($type)
 {
     if (!JRequest::checkToken('get')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->redirectBack();
     }
     $message = KunenaForumMessageHelper::get($this->mesid);
     if (!$message->authorise($type)) {
         $this->app->enqueueMessage($message->getError());
         $this->redirectBack();
     }
     $category = KunenaForumCategoryHelper::get($this->catid);
     $thankyou = KunenaForumMessageThankyouHelper::get($this->mesid);
     $activityIntegration = KunenaFactory::getActivityIntegration();
     if ($type == 'thankyou') {
         if (!$thankyou->save($this->me)) {
             $this->app->enqueueMessage($thankyou->getError());
             $this->redirectBack();
         }
         $activityIntegration->onAfterThankyou($this->me->userid, $message->userid, $message);
     } else {
         $userid = JRequest::getInt('userid', '0');
         if (!$thankyou->delete($userid)) {
             $this->app->enqueueMessage($thankyou->getError());
             $this->redirectBack();
         }
         $activityIntegration->onAfterUnThankyou($userid, $this->me->userid, $message);
     }
     $this->setRedirect($message->getUrl($category->exists() ? $category->id : $message->catid, false));
 }
Пример #10
0
	public function getThankyou() {
		return KunenaForumMessageThankyouHelper::get($this->id);
	}