示例#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;
 function generate_last_post_urls($lastpost_id = null)
 {
     $objBranch = new Forumbranch();
     App::import('Model', 'Forumpost');
     $objPost = new Forumpost();
     $objPost->contain('Forumtopic');
     $lastpost = $objPost->read(null, $lastpost_id);
     $forum_id = $lastpost['Forumtopic']['forumbranch_id'];
     $forum_path = $objBranch->getpath($forum_id);
     if (empty($forum_path)) {
         return "";
     }
     $slugs = array();
     foreach ($forum_path as $index => $branch) {
         $slugs[$index] = $branch['Forumbranch']['slug'];
     }
     array_push($slugs, $lastpost['Forumtopic']['slug']);
     return implode("/", $slugs);
 }