コード例 #1
0
ファイル: topic.php プロジェクト: giabmf11/Kunena-Forum
 /**
  * @param mixed $category
  * @param string $action
  *
  * @return JUri|null
  */
 public function getUri($category = null, $action = null)
 {
     $category = $category ? KunenaForumCategoryHelper::get($category) : $this->getCategory();
     $Itemid = KunenaRoute::getCategoryItemid($category);
     if (!$this->exists() || !$category->exists()) {
         return null;
     }
     if ($action instanceof KunenaForumMessage) {
         $message = $action;
         $action = 'post' . $message->id;
     }
     $uri = JUri::getInstance("index.php?option=com_kunena&view=topic&catid={$category->id}&id={$this->id}&action={$action}&Itemid={$Itemid}");
     if ($uri->getVar('action') !== null) {
         $uri->delVar('action');
         $mesid = 0;
         $limit = max(1, intval(KunenaFactory::getConfig()->messages_per_page));
         if (isset($message)) {
             $mesid = $message->id;
         } elseif ((string) $action === (string) (int) $action) {
             if ($action > 0) {
                 $uri->setVar('limitstart', $action * $limit);
             }
         } else {
             switch ($action) {
                 case 'first':
                     $mesid = $this->first_post_id;
                     break;
                 case 'last':
                     $mesid = $this->last_post_id;
                     break;
                 case 'unread':
                     // Special case, improves caching
                     $uri->setVar('layout', 'unread');
                     // $mesid = $this->lastread ? $this->lastread : $this->last_post_id;
                     break;
             }
         }
         if ($mesid) {
             if (KunenaUserHelper::getMyself()->getTopicLayout() != 'threaded' && $mesid > 0) {
                 $uri->setFragment($mesid);
                 $limitstart = intval($this->getPostLocation($mesid) / $limit) * $limit;
                 if ($limitstart) {
                     $uri->setVar('limitstart', $limitstart);
                 }
             } else {
                 $uri->setVar('mesid', $mesid);
             }
         }
     }
     return $uri;
 }