예제 #1
0
 }
 /**
  * Enter description here...
  *
  * @author Povstyanoy
  * @param  array $slugs Array of action unnamed parameters array["pass"];
  * @return array $out
  *
  *         "forum" => id
  *         "topic" => id
  *         "post" => id
  */
 function findIdBySlug($slugs)
 {
     App::import('Model', 'Forumtopic');
     App::import('Model', 'Forumpost');
     $forumtopic = new Forumtopic();
     $forumpost = new Forumpost();
     //$slug = implode("/", $slugs);
     $out = array("Forum" => null, "Topic" => null, "Post" => null);
     if (empty($slugs)) {
         return $out;
     }
     //Find a post
     $post_id = (int) $slugs[count($slugs) - 1];
     // slug contain ID of post
     if ($post_id > 0) {
         // delete post from array
         unset($slugs[count($slugs) - 1]);
         $post = $forumpost->find('first', array('conditions' => array('Forumpost.is_deleted <> 1', 'Forumpost.id' => $post_id)));
         if (!empty($post['Forumpost']['id'])) {
             $out['Post'] = $post['Forumpost']['id'];
         }
     }
     //eof
     //if (!empty($out['Post'])) {
     $topic_slug = $slugs[count($slugs) - 1];
     //} else {
     //	$topic_slug = $slugs[ count($slugs) - 1 ];
     //}
     $forumtopic->contain();
     $topic_id = $forumtopic->find('first', array('conditions' => array('Forumtopic.is_deleted <> 1', 'Forumtopic.slug' => $topic_slug)));
     if (!empty($topic_id)) {
         $out['Topic'] = $topic_id['Forumtopic']['id'];
     }
     if (!empty($out['Topic'])) {
         unset($slugs[count($slugs) - 1]);
     }
     $forum_slug = $slugs[count($slugs) - 1];
     $this->contain();
     $forumbranch = $this->find('first', array('conditions' => array('Forumbranch.is_deleted <> 1', 'Forumbranch.slug' => $forum_slug)));
     if (!empty($forumbranch)) {
         $out['Forum'] = $forumbranch['Forumbranch']['id'];
     }
     return $out;
 /**
  * Generate the sequence of a slug field for nation page!!!
  *
  * @author Povstyanoy
  * @param array $slug
  * @return string
  */
 function generatetopicurl($slug = null)
 {
     $objTopic = new Forumtopic();
     $objTopic->contain();
     $topic = $objTopic->find('first', array('conditions' => array('Forumtopic.slug' => $slug)));
     $objBranch = new Forumbranch();
     $forum_path = $objBranch->getpath($topic['Forumtopic']['forumbranch_id']);
     if (empty($forum_path)) {
         return "";
     }
     $slugs = array();
     foreach ($forum_path as $index => $branch) {
         $slugs[$index] = $branch['Forumbranch']['slug'];
     }
     //last topic is not a link
     array_push($slugs, $slug);
     $forumurl = implode("/", $slugs);
     return $forumurl;
 }