コード例 #1
0
 public function user_navigation()
 {
     $view = new XView(Navigation_View);
     $view->title = 'Craiglist | ' . 'Main Page';
     $model = new CategoryModel();
     $view->categories = $model->getCategoryTree(-1);
     $model = new ArticleModel();
     $view->total_groups = ceil($model->getCount() / $this->items_per_group);
     $this->__common($view);
 }
コード例 #2
0
 public function make()
 {
     $view = new XView(Category_Create);
     $view->title = 'Article | Make';
     $view->categories = CategoryModel::getCategoryFullList();
     $this->__common($view);
 }
コード例 #3
0
 public static function getCategoryTree($parent = -1)
 {
     $query = mysql_query("SELECT *, (SELECT COUNT(id) FROM categories AS sub WHERE sub.parent_id = prime.id) AS count FROM categories AS prime WHERE parent_id='{$parent}'") or die(mysql_error());
     $i = 0;
     $categories = array();
     while ($row = mysql_fetch_assoc($query)) {
         $category = new Category($row['id'], $row['name']);
         $category->set('subcategory_count', $row['count']);
         $category->set('prime', $parent);
         $category->articles = ArticleModel::getArticleListByCategory($row['id']);
         $categories[$i] = $category;
         if ($row['count'] > 0) {
             $categories[$i]->categories = CategoryModel::getCategoryTree($row['id']);
         } else {
             $categories[$i]->categories = array();
         }
         $i++;
     }
     return $categories;
 }
コード例 #4
0
 public function make()
 {
     session_start();
     $isLoggedIn = Authentification::isLoggedIn();
     $view->isLoggedIn = $isLoggedIn;
     if (!$view->isLoggedIn) {
         $view = new XView(No_Access_View);
         $view->title = 'Access denied | Make';
         $this->__common($view);
         return;
     }
     $view = new XView(Article_Create);
     $view->title = 'Article | Make';
     if (isset($_POST['submit_post'])) {
         ArticleModel::newArticle($_POST['title'], $_POST['content'], $_SESSION['id'], $_POST['category']);
         $article_id = mysql_insert_id();
         $tags = explode(',', $_POST['tags']);
         $TagList = TagModel::getTagList();
         $filteredTagList = array();
         foreach ($TagList as $tag) {
             for ($j = 0; $j < count($tags); $j++) {
                 if ($tag->name == trim($tags[$j])) {
                     TagModel::bindArticleById($tag->id, $article_id);
                 }
             }
         }
         if (isset($_FILES)) {
             ArticleModel::saveImage($article_id);
         }
         header('Location: ' . SERVER_ROOT_URL . '/article/index/');
     }
     $taglist = array();
     foreach (TagModel::getTagList() as $tag) {
         $taglist[] = $tag->name;
     }
     $view->taglist = $taglist;
     $view->categories = CategoryModel::getCategoryFullList();
     $this->__common($view);
 }