Пример #1
0
 public function __invoke($article_id = null)
 {
     $this->articleId = $article_id;
     $article_id = $this->articleId;
     $session = $this->getSession();
     $article = ArticleModel::getPortalArticle($article_id);
     if (!$article) {
         $session->addFlash('error', '文章不存在');
         return new RedirectResponse($this->generateUrl('portal_homepage'));
     }
     $category_id = $article->categoryId;
     $category = CategoryModel::getPortalCategory($category_id);
     if (!$category) {
         $session->addFlash('error', '分类不存在');
         return new RedirectResponse($this->generateUrl('portal_homepage'));
     }
     $parent_category = $category->getDirectParentNode();
     if ($parent_category->isRootNode()) {
         $parent_category = null;
     }
     // 面包屑导航
     $breadcrumb = $category->getNodeSinglePath();
     unset($breadcrumb[0]);
     $breadcrumb = array_values($breadcrumb);
     // 边栏导航
     /** @var CategoryModel $top_nav */
     $top_nav = $breadcrumb[0];
     $side_nav = $top_nav->getDirectChildNodes();
     return $this->render('article/index.html.twig', array('breadcrumb' => $breadcrumb, 'side_nav' => $side_nav, 'category' => $category, 'parent_category' => $parent_category, 'article' => $article));
 }
Пример #2
0
 protected function handle()
 {
     $session = $this->getSession();
     $article_id = $this->articleId;
     $article = ArticleModel::getPortalArticle($article_id);
     if (!$article) {
         $session->addFlash('error', '文章不存在');
         return new RedirectResponse($this->generateUrl('admin_portal_article_manage'));
     }
     $article->publishTimestamp = time();
     ArticleModel::savePortalArticle($article);
     $session->addFlash('success', '操作成功');
     return new RedirectResponse($this->generateUrl('admin_portal_article_manage'));
 }
Пример #3
0
 protected function handle()
 {
     $article_id = $this->articleId;
     $article = ArticleModel::getPortalArticle($article_id);
     if (!$article) {
         throw new \Exception('文章不存在');
     }
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $session = $this->getSession();
         try {
             ArticleModel::deletePortalArticle($article_id);
             $session->addFlash('success', '删除成功');
         } catch (\Exception $e) {
             $session->addFlash('error', $e->getMessage());
         }
         return new RedirectResponse($this->generateUrl('admin_portal_article_manage'));
     }
     return $this->render('article/delete-article.html.twig', array('article' => $article));
 }
Пример #4
0
 public function __invoke($category_id = null)
 {
     $session = $this->getSession();
     $category = CategoryModel::getPortalCategory($category_id);
     if (!$category) {
         $session->addFlash('error', '分类不存在');
         return new RedirectResponse($this->generateUrl('portal_homepage'));
     }
     //        $parent_category = $category->getDirectParentNode();
     //        if ($parent_category->isRootNode()) {
     //            $parent_category = null;
     //        }
     switch ($category->categoryType) {
         case 'article':
         case 'article-menu':
             // 文章列表
             // 面包屑导航
             $breadcrumb = $category->getNodeSinglePath();
             unset($breadcrumb[0]);
             $breadcrumb = array_values($breadcrumb);
             // 边栏导航
             /** @var CategoryModel $top_nav */
             $top_nav = $breadcrumb[0];
             $side_nav = $top_nav->getDirectChildNodes();
             // 文章内容
             $article_id = $category->categoryDesc;
             $article_id = intval($article_id);
             $article = ArticleModel::getPortalArticle($article_id);
             if (!$article) {
                 $session->addFlash('error', '文章不存在');
                 return new RedirectResponse($this->generateUrl('portal_homepage'));
             }
             return $this->render('category/article.html.twig', array('breadcrumb' => $breadcrumb, 'side_nav' => $side_nav, 'category' => $category, 'parent_category' => $top_nav, 'article' => $article));
             break;
         case 'menu':
             // 面包屑导航
             $breadcrumb = $category->getNodeSinglePath();
             unset($breadcrumb[0]);
             $breadcrumb = array_values($breadcrumb);
             // 边栏导航
             /** @var CategoryModel $top_nav */
             $top_nav = $breadcrumb[0];
             $side_nav = $top_nav->getDirectChildNodes();
             $category = $side_nav[0];
             // 内容列表
             $request = $this->getRequest();
             $page = $request->query->get('page');
             if (!$page) {
                 $page = 1;
             }
             $size = 20;
             $pager = ArticleModel::listPortalArticles($page, $size, function (QueryBuilder $qb) use($category) {
                 /** @var CategoryModel $category */
                 $qb->andWhere($qb->expr()->eq('category_id', ':category_id'))->setParameter(':category_id', $category->categoryId);
                 $qb->andWhere($qb->expr()->gt('publish_timestamp', 0));
             });
             return $this->render('category/index.html.twig', array('breadcrumb' => $breadcrumb, 'side_nav' => $side_nav, 'pager' => $pager, 'category' => $category, 'parent_category' => $top_nav));
             break;
         case 'page':
             $breadcrumb = $category->getNodeSinglePath();
             unset($breadcrumb[0]);
             $breadcrumb = array_values($breadcrumb);
             // 边栏导航
             /** @var CategoryModel $top_nav */
             $top_nav = $breadcrumb[0];
             $side_nav = $top_nav->getDirectChildNodes();
             $category = $side_nav[0];
             return $this->render($category->categoryDesc, array('breadcrumb' => $breadcrumb, 'side_nav' => $side_nav, 'category' => $category, 'parent_category' => $top_nav));
             break;
         case 'link':
             return new RedirectResponse($category->categoryDesc);
             break;
         default:
             $session->addFlash('error', '错误的分类类型');
             return new RedirectResponse($this->generateUrl('portal_homepage'));
             break;
     }
 }
Пример #5
0
 protected function handle()
 {
     $tree = CategoryModel::getTree();
     $session = $this->getSession();
     $article_id = $this->articleId;
     $article = ArticleModel::getPortalArticle($article_id);
     if (!$article) {
         $session->addFlash('error', '文章不存在');
         return new RedirectResponse($this->generateUrl('admin_portal_article_manage'));
     }
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $posts = $request->request;
         $title = $posts->get('title');
         $content = $posts->get('content');
         $thumbnails = $posts->get('thumbnails');
         $category_id = $posts->get('category_id');
         $category_valid = false;
         foreach ($tree as $category) {
             if ($category->categoryId == $category_id) {
                 $category_valid = true;
             }
         }
         if (!$category_valid) {
             throw new \Exception("文章分类不能为空");
         }
         if (empty($thumbnails)) {
             $thumbnails = array();
         }
         $reset_thumbnails = $posts->get('reset_thumbnails');
         $cdn_url = $this->getContainer()->getParameter('cdn_url');
         $cdn_url = str_replace('/', '\\/', $cdn_url);
         try {
             if (empty($title)) {
                 throw new \Exception('标题不能为空');
             }
             $article->title = $title;
             $new_thumbnails = array();
             $pattern = "/<\\s*img\\s+[^>]*?src\\s*=\\s*(\\'|\")({$cdn_url}.*?)\\1[^>]*?\\/?\\s*>/i";
             preg_match_all($pattern, $content, $new_thumbnails);
             $new_thumbnails = $new_thumbnails[0];
             foreach ($new_thumbnails as $key => $thumbnail) {
                 $matches = array();
                 preg_match('/src=\\"(.*?)\\"/', $thumbnail, $matches);
                 $new_thumbnails[$key] = $matches[1];
             }
             if ($reset_thumbnails) {
                 $thumbnails = $new_thumbnails;
             }
             $article->content = $content;
             $article->thumbnails = implode('<>', $thumbnails);
             $article->categoryId = $category_id;
             ArticleModel::savePortalArticle($article);
             $session->addFlash('success', '操作成功');
             return new RedirectResponse($this->generateUrl('admin_portal_article_edit', array('article_id' => $article_id)));
         } catch (\Exception $e) {
             $session->addFlash('error', $e->getMessage());
             return new RedirectResponse($this->generateUrl('admin_portal_article_edit', array('article_id' => $article_id)));
         }
     }
     return $this->render('article/edit-article.html.twig', array('article' => $article, 'tree' => $tree));
 }