Exemplo n.º 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));
 }
Exemplo n.º 2
0
 protected function handle()
 {
     /** @var CategoryModel[] $tree */
     $tree = CategoryModel::getTree();
     /** @var CategoryModel $root_node */
     $root_node = CategoryModel::getRootNode();
     $categories = array();
     foreach ($tree as $category) {
         $categories[$category->categoryId] = $category;
     }
     $request = $this->getRequest();
     $category_id = $request->query->get('category_id');
     if (!$category_id || $category_id == $root_node->categoryId) {
         $category_id = null;
     }
     $page = $request->query->get('page');
     if (!$page) {
         $page = 1;
     }
     $size = 10;
     $pager = ArticleModel::listPortalArticles($page, $size, function (QueryBuilder $qb) use($category_id) {
         if ($category_id) {
             $qb->andWhere($qb->expr()->eq('category_id', ':category_id'))->setParameter(':category_id', $category_id);
         }
         $qb->addOrderBy('create_timestamp', 'DESC');
     });
     $pager->setQuery(array('category_id' => $category_id));
     return $this->render('article/manage-article.html.twig', array('tree' => $tree, 'pager' => $pager, 'categories' => $categories));
 }
Exemplo n.º 3
0
 public function __invoke()
 {
     $homepage_node = CategoryModel::getRootNode();
     $category_id = $homepage_node->categoryId;
     $articles_pager = ArticleModel::listPortalArticles(1, 3, function (QueryBuilder $qb) use($category_id) {
         $qb->andWhere($qb->expr()->eq('category_id', ':category_id'))->setParameter(':category_id', $category_id);
         $qb->andWhere($qb->expr()->gt('publish_timestamp', 0));
         $qb->addOrderBy('publish_timestamp', 'desc');
     });
     return $this->render('homepage/index.html.twig', array('pager' => $articles_pager));
 }
Exemplo n.º 4
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'));
 }
Exemplo n.º 5
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));
 }
Exemplo n.º 6
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;
     }
 }
Exemplo n.º 7
0
 protected function handle()
 {
     /** @var CategoryModel[] $tree */
     $tree = CategoryModel::getTree();
     $session = $this->getSession();
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $posts = $request->request;
         $title = $posts->get('title');
         $content = $posts->get('content');
         $category_id = $posts->get('category_id');
         $op = $posts->get('op');
         $cdn_url = $this->getContainer()->getParameter('cdn_url');
         $cdn_url = str_replace('/', '\\/', $cdn_url);
         try {
             if (empty($title)) {
                 throw new \Exception('标题不能为空');
             }
             $category_valid = false;
             foreach ($tree as $category) {
                 if ($category->categoryId == $category_id) {
                     $category_valid = true;
                 }
             }
             if (!$category_valid) {
                 throw new \Exception("文章分类不能为空");
             }
             $article = new ArticleModel();
             $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];
             }
             $thumbnails = $new_thumbnails;
             $summary = strip_tags($content);
             $article->title = $title;
             $article->summary = $summary;
             $article->content = $content;
             $article->thumbnails = implode('<>', $thumbnails);
             $now = time();
             $article->createTimestamp = $now;
             if ($op == 'submit-publish') {
                 $article->publishTimestamp = $now;
             }
             $article->userId = 0;
             // 官方发布
             $article->categoryId = $category_id;
             ArticleModel::createPortalArticle($article);
             $session->addFlash('success', '操作成功');
             return new RedirectResponse($this->generateUrl('admin_portal_article_manage'));
         } catch (\Exception $e) {
             $session->addFlash('error', $e->getMessage());
             return new RedirectResponse($this->generateUrl('admin_portal_article_add'));
         }
     }
     return $this->render('article/add-article.html.twig', array('tree' => $tree));
 }
Exemplo n.º 8
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));
 }
Exemplo n.º 9
0
 /**
  * 保存
  * @param ArticleModel $portal_article
  * @return ArticleModel
  * @throws \Exception
  */
 public static function savePortalArticle(ArticleModel $portal_article)
 {
     return self::editPortalArticle($portal_article->toArray());
 }