Skip to content

Commit

Permalink
added cms directive detection
Browse files Browse the repository at this point in the history
  • Loading branch information
vn-rajeev committed Apr 23, 2015
1 parent 95a06cb commit 3d33abf
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 132 deletions.
83 changes: 74 additions & 9 deletions app/code/community/Rkt/JsCssforSb/Block/Jscss.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,82 @@ class Rkt_JsCssforSb_Block_Jscss extends Mage_Core_Block_Template
{

/**
*
* Retrieve jscss entity
*
* @param int | $id
* @return Rkt_JsCssforSb_Model_JsCss
*
*/
public function getJscssEntity($id)
* Hold jscss entities which are related to static blocks which are
* involved in the current request.
*
* @var array
*/
protected $_jscss = array();

/**
* Initialize template
*
*/
protected function _construct()
{
$this->setTemplate('rkt_jscssforsb/jscss.phtml');
}

/**
* Use to set jscss entities
*
* @param array $ids
*/
public function setActiveJsCss($ids)
{

foreach ($ids as $id) {
$model = Mage::getModel('rkt_jscssforsb/jsCss');
$this->_jscss[] = $model->load((int)$id);
unset($model);
}

return $this;
}

/**
* to get jscss enities
* @return array
*/
public function getActiveJsCss()
{
return $this->_jscss;
}

/**
* Use to get all css related to static blocks
*
* @return array $css an array of stdClass object.
*/
public function getAllStyles()
{
$css = array();
foreach ($this->_jscss as $entity) {
$cssObject = new \stdClass();
$cssObject->type = 'text/css';
$cssObject->content = trim($entity->getJscssCss());
$css[] = $cssObject;
}

return Mage::getModel('rkt_jscssforsb/jsCss')->load($id);
return $css;
}

/**
* Use to get all js related to static blocks
*
* @return array $js an array of stdClass object.
*/
public function getAllScripts()
{
$js = array(); $jscontent = array();
foreach ($this->_jscss as $entity) {
$jsObject = new \stdClass();
$jsObject->type = 'text/javascript';
$jsObject->content = trim($entity->getJscssJs());
$js[] = $jsObject;
$jscontent[] = $entity->getJscssJs();
}

return $js;
}
}
23 changes: 10 additions & 13 deletions app/code/community/Rkt/JsCssforSb/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ class Rkt_JsCssforSb_Helper_Data extends Mage_Core_Helper_Abstract
{

/**
*
* Use to trim unwanted spaces, new lines from passed data
*
* @param string $data
* @return string
*
*/
public function modifyData($data)
* Use to check whether the passed variable is a static block instance
*
* @param mixed $block
* @return boolean
*/
public function isStaticBlock($block)
{
if ($data != '') {
$trimed_data = str_replace(array(" ", "\n", "\t", "'"), array("", "", "", '"'), trim($data));
return preg_replace('/\s+/', '', $trimed_data);
if ($block instanceof Mage_Cms_Block_Block) {
return true;
} else {
return false;
}

return '';
}
}
50 changes: 50 additions & 0 deletions app/code/community/Rkt/JsCssforSb/Helper/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Rkt_JsCssforSb extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* that is bundled with this package in the file LICENSE_JSSB.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/mit-license.php
*
* @category Rkt
* @package Rkt_JsCssforSb
* @copyright Copyright (c) 2015
* @license http://opensource.org/licenses/mit-license.php MIT License
*/

/**
* CMS Page Helper
*
* @category Rkt
* @package Rkt_JsCssforSb
* @author Programmer-RKT
*/
class Rkt_JsCssforSb_Helper_Page extends Mage_Core_Helper_Abstract
{

/**
* Retrieve Template processor for Page Content
*
* @return Varien_Filter_Template
*/
public function getPageTemplateProcessor()
{
return Mage::getModel('rkt_jscssforsb/template_filter');
}

/**
* Use to find static blocks which is included in the cms page
* content section
*
* @return array
*/
public function findStaticBlocks($cmsContent)
{
$processor = $this->getPageTemplateProcessor();
$blocks = $processor->filter($cmsContent);
return $blocks;
}
}
15 changes: 15 additions & 0 deletions app/code/community/Rkt/JsCssforSb/Model/JsCss.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,24 @@
class Rkt_JsCssforSb_Model_JsCss extends Mage_Core_Model_Abstract
{

/**
* constructor
*
* @return void
*/
protected function _construct()
{
$this->_init('rkt_jscssforsb/jsCss');
}

/**
* Use to get jscss entry based on static block id
*
* @param int $id
* @return Rkt_JsCssforSb_Model_JsCss
*/
public function getJsCssByStaticBlockId($id)
{
return $this->load($id, 'block_id');
}
}
Loading

0 comments on commit 3d33abf

Please sign in to comment.