/app/code/community/AW/Blog/Block/Blog.php

https://bitbucket.org/acidel/buykoala · PHP · 137 lines · 84 code · 26 blank · 27 comment · 26 complexity · 1ec74759f4aa5ecb02de6dc2f6c348a5 MD5 · raw file

  1. <?php
  2. /**
  3. * aheadWorks Co.
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the EULA
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://ecommerce.aheadworks.com/AW-LICENSE-COMMUNITY.txt
  11. *
  12. * =================================================================
  13. * MAGENTO EDITION USAGE NOTICE
  14. * =================================================================
  15. * This package designed for Magento COMMUNITY edition
  16. * aheadWorks does not guarantee correct work of this extension
  17. * on any other Magento edition except Magento COMMUNITY edition.
  18. * aheadWorks does not provide extension support in case of
  19. * incorrect edition usage.
  20. * =================================================================
  21. *
  22. * @category AW
  23. * @package AW_Blog
  24. * @version 1.1.1
  25. * @copyright Copyright (c) 2010-2012 aheadWorks Co. (http://www.aheadworks.com)
  26. * @license http://ecommerce.aheadworks.com/AW-LICENSE-COMMUNITY.txt
  27. */
  28. class AW_Blog_Block_Blog extends AW_Blog_Block_Abstract {
  29. public function getPosts() {
  30. $collection = parent::_prepareCollection();
  31. if ($tag = $this->getRequest()->getParam('tag')) {
  32. $collection->addTagFilter(urldecode($tag));
  33. }
  34. parent::_processCollection($collection);
  35. return $collection;
  36. }
  37. public function getTagsHtml($post) {
  38. if (trim($post->getTags())) {
  39. $this->setTemplate('aw_blog/line_tags.phtml');
  40. $this->setPost($post);
  41. return $this->toHtml();
  42. }
  43. return;
  44. }
  45. public function getPages() {
  46. echo parent::getPagesCollection('list');
  47. }
  48. public function getRecent() {
  49. if (Mage::getStoreConfig(AW_Blog_Helper_Config::XML_RECENT_SIZE) != 0) {
  50. $collection = Mage::getModel('blog/blog')->getCollection()
  51. ->addPresentFilter()
  52. ->addStoreFilter(Mage::app()->getStore()->getId())
  53. ->setOrder('created_time ', 'desc');
  54. $route = Mage::helper('blog')->getRoute();
  55. Mage::getSingleton('blog/status')->addEnabledFilterToCollection($collection);
  56. $collection->setPageSize(Mage::getStoreConfig(AW_Blog_Helper_Config::XML_RECENT_SIZE));
  57. $collection->setCurPage(1);
  58. foreach ($collection as $item) {
  59. $item->setAddress($this->getUrl($route . "/" . $item->getIdentifier()));
  60. }
  61. return $collection;
  62. } else {
  63. return false;
  64. }
  65. }
  66. public function getCategories() {
  67. $collection = Mage::getModel('blog/cat')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId())->setOrder('sort_order ', 'asc');
  68. $route = Mage::helper('blog')->getRoute();
  69. foreach ($collection as $item) {
  70. $item->setAddress($this->getUrl($route . "/cat/" . $item->getIdentifier()));
  71. }
  72. return $collection;
  73. }
  74. protected function _prepareLayout() {
  75. $route = Mage::helper('blog')->getRoute();
  76. $isBlogPage = Mage::app()->getFrontController()->getAction()->getRequest()->getModuleName() == 'blog';
  77. // show breadcrumbs
  78. if ($isBlogPage && Mage::getStoreConfig('blog/blog/blogcrumbs') && ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'))) {
  79. $breadcrumbs->addCrumb('home', array('label' => Mage::helper('blog')->__('Home'), 'title' => Mage::helper('blog')->__('Go to Home Page'), 'link' => Mage::getBaseUrl()));
  80. ;
  81. if ($tag = @urldecode($this->getRequest()->getParam('tag'))) {
  82. $breadcrumbs->addCrumb('blog', array('label' => Mage::getStoreConfig('blog/blog/title'), 'title' => Mage::helper('blog')->__('Return to ' . Mage::getStoreConfig('blog/blog/title')), 'link' => Mage::getUrl($route)));
  83. $breadcrumbs->addCrumb('blog_tag', array('label' => Mage::helper('blog')->__('Tagged with "%s"', Mage::helper('blog')->convertSlashes($tag)), 'title' => Mage::helper('blog')->__('Tagged with "%s"', $tag)));
  84. } else {
  85. $breadcrumbs->addCrumb('blog', array('label' => Mage::getStoreConfig('blog/blog/title')));
  86. }
  87. }
  88. }
  89. public function _toHtml() {
  90. if (Mage::helper('blog')->getEnabled()) {
  91. $isLeft = ($this->getParentBlock() === $this->getLayout()->getBlock('left'));
  92. $isRight = ($this->getParentBlock() === $this->getLayout()->getBlock('right'));
  93. $isBlogPage = Mage::app()->getFrontController()->getAction()->getRequest()->getModuleName() == 'blog';
  94. $leftAllowed = ($isBlogPage && Mage::getStoreConfig('blog/menu/left') == 2) || (Mage::getStoreConfig('blog/menu/left') == 1);
  95. $rightAllowed = ($isBlogPage && Mage::getStoreConfig('blog/menu/right') == 2) || (Mage::getStoreConfig('blog/menu/right') == 1);
  96. if (!$leftAllowed && $isLeft) {
  97. return '';
  98. }
  99. if (!$rightAllowed && $isRight) {
  100. return '';
  101. }
  102. try {
  103. if (Mage::getModel('widget/template_filter'))
  104. $processor = Mage::getModel('widget/template_filter');
  105. return $processor->filter(parent::_toHtml());
  106. } catch (Exception $ex) {
  107. return parent::_toHtml();
  108. }
  109. }
  110. }
  111. }