*/ class stBlogFrontendActions extends stActions { public function executeShow() { $this->smarty = new stSmarty('stBlogFrontend'); $config = stConfig::getInstance(sfContext::getInstance(), 'stBlogBackend'); if($config->get('active')==0) { return $this->redirect('/'); } $this->config = $config; if (!$this->process301Redirects()) { $this->getUser()->setParameter('status-404', true); return $this->forward404(); //return $this->forward('stBlogFrontend', 'list'); } if (!$this->processFriendlyUrl()) { $this->getUser()->setParameter('status-404', true); return $this->forward404(); //return $this->forward('stBlogFrontend', 'list'); } } public function executeList() { if ($this->getUser()->hasParameter('status-404')) { $this->getResponse()->setStatusCode(404); $this->getResponse()->setHttpHeader('Status', '404 Not Found'); } $c = new Criteria(); $c -> add(BlogCategoryPeer::ACTIVE, 1); $c->addJoin(BlogHasBlogCategoryPeer::BLOG_CATEGORY_ID, BlogCategoryPeer::ID); $c->addGroupByColumn('blog_category_id'); if ($categorys = BlogCategoryPeer::doSelectWithI18n($c)) { $this->categorys = $categorys; } $blog_category = null; if($this->getRequestParameter('category')) { $this->getUser()->setAttribute("blog_category_id", $this->getRequestParameter('category')); $blog_category_id = $this->getRequestParameter('category'); $blog_category = BlogCategoryPeer::retrieveByPK($blog_category_id); } elseif ($this->hasRequestParameter('url')) { $blog_category = BlogCategoryPeer::retrieveByUrl($this->getRequestParameter('url')); } $this->blog_category = $blog_category; $this->processCategory301Redirects(); $this->smarty = new stSmarty('stBlogFrontend'); $config = stConfig::getInstance(sfContext::getInstance(), 'stBlogBackend'); $blogs_count = $config->get('list_number'); if($config->get('active')==0) { return $this->redirect('/'); } $this->config = $config; $c = new Criteria(); $c->add(BlogPeer::ACTIVE, 1); if($blog_category) { $c->addJoin(BlogHasBlogCategoryPeer::BLOG_ID, BlogPeer::ID); $c->add(BlogHasBlogCategoryPeer::BLOG_CATEGORY_ID, $blog_category->getId()); } $c->setLimit($blogs_count); $c->addDescendingOrderByColumn(BlogPeer::CREATED_AT); $this->blogPagerInit($c); $page = $this->blog_pager->getPage(); $pagecanonical = $page; $url = $this->getRequestParameter('url'); if ($blog_category) { if($pagecanonical == "1"){ $pagecanonical = $url; }else{ $pagecanonical = $url."/".$page; } $this->getResponse()->setCanonicalLink(st_url_for('stBlogFrontend/list?url='.$pagecanonical, true, null, stLanguage::getInstance($this->getContext())->getDomain())); }else{ if($pagecanonical == "1"){ $pagecanonical = ""; } $this->getResponse()->setCanonicalLink(st_url_for('stBlogFrontend/'.$pagecanonical, true, null, stLanguage::getInstance($this->getContext())->getDomain())); } if (!$blog_category) { $this->getResponse()->setTitle($config->get('list_all_name', null, true)); $this->getResponse()->addMeta('description', strip_tags($config->get('list_all_description', null, true))); $this->getResponse()->addMeta('keywords', $config->get('list_all_keywords', null, true)); } } protected function blogPagerInit(Criteria $c) { $config = stConfig::getInstance(sfContext::getInstance(), 'stBlogBackend'); $this->blog_pager = new stPropelPager('Blog', $config->get('list_number')); $c = clone $c; $this->blog_pager->setPage($this->getRequestParameter('page')); $this->blog_pager->setCriteria($c); $this->blog_pager->setPeerMethod('doSelect'); $this->blog_pager->init(); } protected function process301Redirects() { if ($this->hasRequestParameter('blog_id')) { sfLoader::loadHelpers(array('Helper','stUrl')); $blog_id = $this->getRequestParameter('blog_id'); $blog = BlogPeer::retrieveByPK($blog_id); if (is_null($blog)) { return false; } $blog->setCulture($this->getUser()->getCulture()); return $this->redirect(st_url_for('stBlogFrontend/show?url='.$blog->getFriendlyUrl(), true), 301); } return true; } protected function processCategory301Redirects() { if ($this->hasRequestParameter('category') && $this->blog_category) { $url_params = array( 'module' => 'stBlogFrontend', 'action' => 'list', 'url' => $this->blog_category->getUrl(), ); if ($this->hasRequestParameter('page')) { $url_params['page'] = $this->getRequestParameter('page'); } return $this->redirect($url_params, 301); } elseif (strpos($this->getRequest()->getUri(), '/blog/list')) { return $this->redirect(sfRouting::getInstance()->getCurrentInternalUri(), 301); } } protected function processFriendlyUrl() { if ($this->getRequest()->hasParameter('url')) { $config = stConfig::getInstance(sfContext::getInstance(), 'stBlogBackend'); $url = $this->getRequest()->getParameter('url'); $this->getResponse()->setCanonicalLink(st_url_for('stBlogFrontend/show?url='. $url, true, null, stLanguage::getInstance($this->getContext())->getDomain())); $blog = BlogPeer::retrieveByUrl($url); if (!$blog) { $this->getUser()->setParameter('status-404', true); return $this->forward404(); } $this->blog = $blog; $c = new Criteria(); $c->add(BlogHasBlogCategoryPeer::BLOG_ID, $blog->getId()); $c->add(BlogHasBlogCategoryPeer::BLOG_CATEGORY_MAIN, 1); $blogHasBlogCategory = BlogHasBlogCategoryPeer::doSelectOne($c); if ($blogHasBlogCategory){ $blog_category = BlogCategoryPeer::retrieveByPK($blogHasBlogCategory->getBlogCategoryId()); $this->blog_category = $blog_category; $c = new Criteria(); $c->add(BlogPeer::ACTIVE, 1); $c->addJoin(BlogHasBlogCategoryPeer::BLOG_ID, BlogPeer::ID); $c->add(BlogHasBlogCategoryPeer::BLOG_CATEGORY_ID, $blogHasBlogCategory->getBlogCategoryId()); if ($config->get('post_number')!="") { $c->setLimit($config->get('post_number')); } $c->addDescendingOrderByColumn(BlogPeer::CREATED_AT); $this->blogs = BlogPeer::doSelect($c); } $c = new Criteria(); $c -> add(BlogCategoryPeer::ACTIVE, 1); $c->addJoin(BlogHasBlogCategoryPeer::BLOG_CATEGORY_ID, BlogCategoryPeer::ID); $c->addGroupByColumn('blog_category_id'); if ($categorys = BlogCategoryPeer::doSelectWithI18n($c)) { $this->categorys = $categorys; } $c = new Criteria(); $c -> add(ProductPeer::ACTIVE, 1); $c->add(BlogHasProductPeer::BLOG_ID, $blog->getId()); $c->addJoin(BlogHasProductPeer::PRODUCT_ID, ProductPeer::ID); $c->addAscendingOrderByColumn(BlogHasProductPeer::ID); $products = ProductPeer::doSelectWithI18n($c); $this->products = $products; /* echo "
";
print_r($products);
echo "";*/
$recommends_array = json_decode($blog->getRecommend(), true);
if ($recommends_array) {
foreach ($recommends_array as $item) {
$c = new Criteria();
$c->add(BlogPeer::ID, $item['id']);
$blog_post = BlogPeer::doSelectOne($c);
if ($blog_post) {
$recommends[] = $blog_post;
}
}
$this->recommends = $recommends;
}
/*echo "";
print_r($recommends);
echo "";*/
if ($this->blog && $this->blog->getActive())
{
$this->blog->setCulture($this->getUser()->getCulture());
$this->getUser()->setParameter('selected', $this->blog, 'soteshop/stBlog');
if ($url != $this->blog->getFriendlyUrl())
{
sfLoader::loadHelpers(array('Helper','stUrl'));
$r = sfRouting::getInstance();
list(,$redirect) = $this->getController()->convertUrlStringToParameters($r->getCurrentInternalUri());
$redirect['url'] = $this->blog->getFriendlyUrl();
$this->redirect(st_url_for($redirect, true) , 301);
}
}
else
{
return false;
}
}
return true;
}
}