示例#1
0
 public function getPostShortContent($post, $storeId = 0)
 {
     $content = $post->getPostContent();
     if (Mage::getStoreConfig(AW_Blog_Helper_Config::XML_BLOG_USESHORTCONTENT, $storeId) && trim($post->getShortContent())) {
         $content = trim($post->getShortContent());
     } elseif ((int) Mage::getStoreConfig(AW_Blog_Helper_Config::XML_BLOG_READMORE, $storeId)) {
         $strManager = new AW_Blog_Helper_Substring(array('input' => Mage::helper('blog')->filterWYS($post->getPostContent())));
         $content = $strManager->getHtmlSubstr((int) Mage::getStoreConfig(AW_Blog_Helper_Config::XML_BLOG_READMORE));
     }
     return $content;
 }
示例#2
0
 public function getRuleDescription($content)
 {
     $maxLen = 1000;
     $showLen = 100;
     $strManager = new AW_Blog_Helper_Substring(array('input' => Mage::helper('blog')->filterWYS($content)));
     $fullContent = $strManager->getHtmlSubstr($maxLen);
     $strManager2 = new AW_Blog_Helper_Substring(array('input' => Mage::helper('blog')->filterWYS($content)));
     $content = $strManager2->getHtmlSubstr($showLen);
     $content = "<a title='" . strip_tags($fullContent) . "' alt=''>{$content}</a>";
     if ($strManager2->getSymbolsCount() == $showLen) {
         $content .= '...';
     }
     return $content;
 }
示例#3
0
 protected function _processCollection($collection, $category = false)
 {
     $route = Mage::helper('blog')->getRoute();
     foreach ($collection as $item) {
         /* Escape tags */
         AW_Blog_Helper_Data::escapeSpecialChars($item);
         if ($category) {
             if (Mage::getStoreConfig('blog/blog/categories_urls')) {
                 $item->setAddress($this->getUrl($route . '/cat/' . $this->getCat()->getIdentifier() . '/post/' . $item->getIdentifier()));
             } else {
                 $item->setAddress($this->getUrl($route . "/" . $item->getIdentifier()));
             }
         } else {
             $item->setAddress($this->getUrl($route . "/" . $item->getIdentifier()));
         }
         $item->setCreatedTime($this->formatTime($item->getCreatedTime(), Mage::getStoreConfig('blog/blog/dateformat'), true));
         $item->setUpdateTime($this->formatTime($item->getUpdateTime(), Mage::getStoreConfig('blog/blog/dateformat'), true));
         if (Mage::getStoreConfig(AW_Blog_Helper_Config::XML_BLOG_USESHORTCONTENT) && trim($item->getShortContent())) {
             $content = trim($item->getShortContent());
             $content = $this->closetags($content);
             $content .= ' <a href="' . $this->getUrl($route . "/" . $item->getIdentifier()) . '" >' . $this->__('Read More') . '</a>';
             $item->setPostContent($content);
         } elseif ((int) Mage::getStoreConfig(AW_Blog_Helper_Config::XML_BLOG_READMORE) != 0) {
             $content = $item->getPostContent();
             $strManager = new AW_Blog_Helper_Substring(array('input' => Mage::helper('blog')->filterWYS($content)));
             $content = $strManager->getHtmlSubstr((int) Mage::getStoreConfig(AW_Blog_Helper_Config::XML_BLOG_READMORE));
             if ($strManager->getSymbolsCount() == Mage::getStoreConfig(AW_Blog_Helper_Config::XML_BLOG_READMORE)) {
                 $content .= ' <a href="' . $this->getUrl($route . "/" . $item->getIdentifier()) . '" >' . $this->__('Read More') . '</a>';
             }
             $item->setPostContent($content);
         }
         $comments = Mage::getModel('blog/comment')->getCollection()->addPostFilter($item->getPostId())->addApproveFilter(2);
         $item->setCommentCount(count($comments));
         $cats = Mage::getModel('blog/cat')->getCollection()->addPostFilter($item->getPostId());
         $catUrls = array();
         foreach ($cats as $cat) {
             $catUrls[$cat->getTitle()] = Mage::getUrl($route . "/cat/" . $cat->getIdentifier());
         }
         $item->setCats($catUrls);
     }
     if ($category) {
         $this->setData('cat', $collection);
         return $this->getData('cat');
     }
     return $collection;
 }
示例#4
0
 protected function _processCollection($collection, $category = false)
 {
     /* add category to url */
     $categoryUrl = self::$_helper->isCategoryUrl();
     /* use short content for posts */
     $shortContent = self::$_helper->useShortContent();
     /* readMoreCount */
     $readMoreCount = (int) self::$_helper->readMoreCount();
     /* cache (run-time) all categories related to products */
     $this->_prepareRelatedCategories($collection);
     foreach ($collection as $item) {
         $this->_prepareData($item)->_prepareDates($item);
         /* prepare urls depnding on mode */
         if ($category && $categoryUrl) {
             $item->setAddress($this->getBlogUrl(null, array(self::$_catUriParam => $category->getIdentifier(), self::$_postUriParam => $item->getIdentifier())));
         } else {
             $item->setAddress($this->getBlogUrl($item->getIdentifier()));
         }
         /* prepare short content fields */
         if ($shortContent) {
             if ($item->getShortContent()) {
                 $item->setPostContent($item->getShortContent() . $this->_getReadMoreLink($item));
             }
         } elseif ($readMoreCount) {
             $strManager = new AW_Blog_Helper_Substring(array('input' => self::$_helper->filterWYS($item->getPostContent())));
             $content = $strManager->getHtmlSubstr($readMoreCount);
             if ($strManager->getSymbolsCount() == $readMoreCount) {
                 $content .= $this->_getReadMoreLink($item);
             }
             $item->setPostContent($content);
         }
         /* add categories the item is related to */
         $this->_addCategories($item);
     }
     return $collection;
 }
示例#5
0
 /**
  *  @test
  *  @dataProvider provider__getHtmlSubstr
  * 
  */
 public function getHtmlSubstr($data)
 {
     $strManager = new AW_Blog_Helper_Substring(array('input' => $data['string']));
     $content = $strManager->getHtmlSubstr($data['substr']);
     $this->assertEquals(mb_strtolower($content, mb_detect_encoding($content)), mb_strtolower($data['expected'], mb_detect_encoding($content)));
 }