Ejemplo n.º 1
0
	/**
	 * @param int|array $keys
	 * @return bool
	 */
	public function load( $keys = null )
	{
		if ( is_array( $keys ) ) {
			return false;
		}

		$this->_category->load( (int) $keys );

		if ( ! $this->_category->exists() ) {
			$this->_category->set( 'id', 0 );
		}

		$this->category( $this->_category );

		return true;
	}
Ejemplo n.º 2
0
 /**
  * @param   KunenaForumCategory $instance
  * @internal
  */
 public static function register($instance)
 {
     if ($instance->exists()) {
         $instance->level = isset(self::$_instances[$instance->parent_id]) ? self::$_instances[$instance->parent_id]->level + 1 : 0;
         self::$_instances[$instance->id] = $instance;
         if (!isset(self::$_tree[(int) $instance->id])) {
             self::$_tree[$instance->id] = array();
             self::$_tree[$instance->parent_id][$instance->id] =& self::$_tree[$instance->id];
         }
     } else {
         unset(self::$_instances[$instance->id]);
         unset(self::$_tree[$instance->id], self::$_tree[$instance->parent_id][$instance->id]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Checks if user has moderator permissions in the category.
  *
  * If no category is given or it doesn't exist, check will be done against global moderator permissions.
  *
  * @param KunenaForumCategory $category
  *
  * @return bool
  */
 public function isModerator(KunenaForumCategory $category = null)
 {
     return KunenaAccess::getInstance()->isModerator($this, $category && $category->exists() ? $category->id : null);
 }
Ejemplo n.º 4
0
 protected static function loadCategories()
 {
     KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     $db = JFactory::getDBO();
     $query = "SELECT * FROM #__kunena_categories ORDER BY ordering, name";
     $db->setQuery($query);
     $results = (array) $db->loadAssocList();
     KunenaError::checkDatabaseError();
     self::$_instances = array();
     self::$_tree = array();
     if (empty($results)) {
         KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
         return;
     }
     foreach ($results as $category) {
         $instance = new KunenaForumCategory($category);
         $instance->exists(true);
         self::$_instances[$instance->id] = $instance;
         if (!isset(self::$_tree[(int) $instance->id])) {
             self::$_tree[$instance->id] = array();
         }
         self::$_tree[$instance->parent_id][$instance->id] =& self::$_tree[(int) $instance->id];
     }
     unset($results);
     // TODO: remove this by adding level into table
     $heap = array(0);
     while (($parent = array_shift($heap)) !== null) {
         foreach (self::$_tree[$parent] as $id => $children) {
             if (!empty($children)) {
                 array_push($heap, $id);
             }
             self::$_instances[$id]->level = $parent ? self::$_instances[$parent]->level + 1 : 0;
         }
     }
     KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
 }
Ejemplo n.º 5
0
 /**
  * @param                     $row
  * @param KunenaForumCategory $category
  * @param                     $subject
  *
  * @return bool|KunenaForumTopic
  */
 protected function createTopic($row, KunenaForumCategory $category, $subject)
 {
     if (!$category->exists()) {
         $this->debug("showPlugin: Topic creation failed: forum category doesn't exist!");
         return false;
     }
     $this->debug("showPlugin: Create topic!");
     $add_snippet = $this->params->get('add_article_snippet');
     $textwords = implode(' ', array_slice(explode(' ', $row->fulltext), 0, 10));
     if (empty($textwords)) {
         $textwords = implode(' ', array_slice(explode(' ', $row->introtext), 0, 10));
     }
     $snippet = strip_tags($textwords) . "..." . "\n\n";
     $type = $this->params->get('bbcode');
     switch ($type) {
         case 'full':
         case 'intro':
         case 'link':
             if ($add_snippet) {
                 $contents = $snippet . "[article={$type}]{$row->id}[/article]";
             } else {
                 $contents = "[article={$type}]{$row->id}[/article]";
             }
             break;
         default:
             if ($add_snippet) {
                 $contents = $snippet . "[article]{$row->id}[/article]";
             } else {
                 $contents = "[article]{$row->id}[/article]";
             }
     }
     $topic_owner = $this->params->get('topic_owner', $row->created_by);
     // save the ID for later use
     $user = KunenaUserHelper::get($topic_owner);
     $email = $user->email;
     // get real email
     $params = array('email' => $email, 'subject' => $subject, 'message' => $contents);
     $safefields = array('category_id' => intval($category->id));
     list($topic, $message) = $category->newTopic($params, $topic_owner, $safefields);
     // Set time of message published by the plugin in the Unix timestamp format
     if (isset($row->publish_up) && $row->publish_up != '0000-00-00 00:00:00') {
         $message->time = JFactory::getDate($row->publish_up)->toUnix();
         // start puglishing date of the article
     } else {
         if (isset($row->created) && $row->created != '0000-00-00 00:00:00') {
             $message->time = JFactory::getDate($row->created)->toUnix();
             // created date of the article
         } else {
             $message->time = JFactory::getDate()->toUnix();
             // current date and time
         }
     }
     /** @var KunenaForumTopic $topic */
     /** @var KunenaForumMessage $message */
     $success = $message->save();
     if (!$success) {
         $this->app->enqueueMessage($message->getError(), 'error');
         return false;
     }
     // Create a reference
     $this->createReference($row, $topic->id);
     return $topic;
 }
	/**
	 * Test delete()
	 *
	 * @param KunenaForumCategory $category
	 * @depends testRemoveModerator
	 */
	public function testDelete(KunenaForumCategory $category) {
		$this->assertTrue($category->delete(), $category->getError());
		$this->assertFalse($category->exists(), 'Check that deleted category does not exist');
		$this->assertNull($category->id, 'Check that deleted category id is null');
	}
Ejemplo n.º 7
0
 /**
  * Assign user as moderator or resign him.
  *
  * @param KunenaForumCategory $category
  * @param mixed $user
  * @param bool $status
  *
  * @return bool
  *
  * @example if ($category->authorise('admin')) $category->setModerator($user, true);
  */
 public function setModerator($category, $user = null, $status = true)
 {
     // Check if category exists
     if ($category && !$category->exists()) {
         return false;
     }
     $category_id = $category ? $category->id : 0;
     $status = intval($status);
     // Check if user exists
     $user = KunenaUserHelper::get($user);
     if (!$user->exists()) {
         return false;
     }
     $success = true;
     $usercategory = KunenaForumCategoryUserHelper::get($category_id, $user);
     if ($usercategory->role == 0 && $status || $usercategory->role == 1 && !$status) {
         $usercategory->role = $status;
         $success = $usercategory->save();
         // Clear role cache
         $this->clearCache();
         // Change user moderator status
         $moderator = $this->getModeratorStatus($user);
         if ($user->moderator != !empty($moderator)) {
             $user->moderator = intval(!empty($moderator));
             $success = $user->save();
         }
     }
     return $success;
 }
Ejemplo n.º 8
0
 /**
  * @param                     $row
  * @param KunenaForumCategory $category
  * @param                     $subject
  *
  * @return bool|KunenaForumTopic
  */
 protected function createTopic($row, KunenaForumCategory $category, $subject)
 {
     if (!$category->exists()) {
         $this->debug("showPlugin: Topic creation failed: forum category doesn't exist!");
         return false;
     }
     $this->debug("showPlugin: Create topic!");
     $type = $this->params->get('bbcode');
     switch ($type) {
         case 'full':
         case 'intro':
         case 'link':
             $contents = "[article={$type}]{$row->id}[/article]";
             break;
         default:
             $contents = "[article]{$row->id}[/article]";
     }
     $params = array('subject' => $subject, 'message' => $contents);
     $safefields = array('category_id' => intval($category->id));
     list($topic, $message) = $category->newTopic($params, $this->params->get('topic_owner', $row->created_by), $safefields);
     /** @var KunenaForumTopic $topic */
     /** @var KunenaForumMessage $message */
     $message->time = JFactory::getDate(isset($row->publish_up) ? $row->publish_up : 'now')->toUnix();
     $success = $message->save();
     if (!$success) {
         $this->app->enqueueMessage($message->getError(), 'error');
         return false;
     }
     // Create a reference
     $this->createReference($row, $topic->id);
     return $topic;
 }