Skip to content

Commit

Permalink
added proper documentation; added license file
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeev-k-tomy committed Apr 21, 2015
1 parent 1cf1208 commit 95a06cb
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 78 deletions.
21 changes: 21 additions & 0 deletions LICENSE_JSSB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

The MIT License (MIT)

Copyright (c) 2015 Rajeev

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 changes: 21 additions & 3 deletions app/code/community/Rkt/JsCssforSb/Block/Jscss.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
<?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
*/

/**
* Jscss Block
*
* @category Extension
* @category Rkt
* @package Rkt_JsCssforSb
* @author Programmer-RKT
*/
class Rkt_JsCssforSb_Block_Jscss extends Mage_Core_Block_Template {
class Rkt_JsCssforSb_Block_Jscss extends Mage_Core_Block_Template
{

/**
*
Expand All @@ -16,7 +33,8 @@ class Rkt_JsCssforSb_Block_Jscss extends Mage_Core_Block_Template {
* @return Rkt_JsCssforSb_Model_JsCss
*
*/
public function getJscssEntity($id){
public function getJscssEntity($id)
{

return Mage::getModel('rkt_jscssforsb/jsCss')->load($id);
}
Expand Down
33 changes: 25 additions & 8 deletions app/code/community/Rkt/JsCssforSb/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
<?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
*/

/**
* Helper
*
* @category Extension
* @category Rkt
* @package Rkt_JsCssforSb
* @author Programmer-RKT
*/
class Rkt_JsCssforSb_Helper_Data extends Mage_Core_Helper_Abstract {
class Rkt_JsCssforSb_Helper_Data extends Mage_Core_Helper_Abstract
{

/**
*
* Use to trim unwanted spaces, new lines from passed data
*
* @param string | $data
* @param string $data
* @return string
*
*/
public function modifyData($data){
if($data != '') {
$trimed_data = str_replace(array(" ","\n","\t","'"),array("","","",'"'),trim($data));

return preg_replace('/\s+/','',$trimed_data );
public function modifyData($data)
{
if ($data != '') {
$trimed_data = str_replace(array(" ", "\n", "\t", "'"), array("", "", "", '"'), trim($data));
return preg_replace('/\s+/', '', $trimed_data);
}

return '';
Expand Down
21 changes: 19 additions & 2 deletions app/code/community/Rkt/JsCssforSb/Model/Block.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
<?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
*/

/**
* Rewrite for Mage_Cms_Model_Block
*
* @category Extension
* @category Rkt
* @package Rkt_JsCssforSb
* @author Programmer-RKT
*/
class Rkt_JsCssforSb_Model_Block extends Mage_Cms_Model_Block {
class Rkt_JsCssforSb_Model_Block extends Mage_Cms_Model_Block
{

/**
* Prefix of model events names
Expand Down
25 changes: 21 additions & 4 deletions app/code/community/Rkt/JsCssforSb/Model/JsCss.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
<?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
*/

/**
* Model for jscss
*
* @category Extension
* @category Rkt
* @package Rkt_JsCssforSb
* @author Programmer-RKT
*/
class Rkt_JsCssforSb_Model_JsCss extends Mage_Core_Model_Abstract {

protected function _construct(){
class Rkt_JsCssforSb_Model_JsCss extends Mage_Core_Model_Abstract
{

protected function _construct()
{
$this->_init('rkt_jscssforsb/jsCss');
}

Expand Down
91 changes: 49 additions & 42 deletions app/code/community/Rkt/JsCssforSb/Model/Observer.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
<?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
*/

/**
* Observer that adds new fieldsets for cms -> static blocks
*
* @category Extension
* @category Rkt
* @package Rkt_JsCssforSb
* @author Programmer-RKT
*/

class Rkt_JsCssforSb_Model_Observer {
class Rkt_JsCssforSb_Model_Observer
{

/**
*
Expand All @@ -16,9 +33,9 @@ class Rkt_JsCssforSb_Model_Observer {
* @param Varien_Event_Observer | $observer
*
*/
public function addNewFieldsetForCmsBlock($observer) {

$block = $observer->getEvent()->getBlock();
public function addNewFieldsetForCmsBlock(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();

//check whether block is cms_block_form
if ($block instanceof Mage_Adminhtml_Block_Cms_Block_Edit_Form) {
Expand All @@ -28,12 +45,11 @@ public function addNewFieldsetForCmsBlock($observer) {

//get jscss values
$js_value = ''; $css_value = '';
$block_id = (int)Mage::registry('cms_block')->getBlockId();
$block_id = (int) Mage::registry('cms_block')->getBlockId();
$cms_block = $this->getJsCssEntity($block_id);

//get values if entity exist
if($cms_block){

if ($cms_block) {
$js_value = $cms_block->getJscssJs();
$css_value = $cms_block->getJscssCss();
}
Expand Down Expand Up @@ -61,7 +77,7 @@ public function addNewFieldsetForCmsBlock($observer) {
));
}

return;
return $this;
}

/**
Expand All @@ -71,18 +87,19 @@ public function addNewFieldsetForCmsBlock($observer) {
* @param Varien_Event_Observer | $observer
*
*/
public function saveJsCss($observer) {
public function saveJsCss(Varien_Event_Observer $observer)
{

//get object
$cms_block = $observer->getEvent()->getObject();

//retrieve essential datas to store
$block_id = (int)$cms_block->getBlockId();
$block_id = (int) $cms_block->getBlockId();
$js = Mage::helper('rkt_jscssforsb')->modifyData($cms_block->getJscssJs());
$css = Mage::helper('rkt_jscssforsb')->modifyData($cms_block->getJscssCss());

if($js != '' || $css != ''){
if ($js != '' || $css != '') {

//prepare data to save
$data = array(
'block_id' => $block_id,
Expand All @@ -94,19 +111,14 @@ public function saveJsCss($observer) {
$model = Mage::getModel('rkt_jscssforsb/jsCss');

//saves data if cms block is new
if(!$this->getJsCssEntity($block_id)){

if (!$this->getJsCssEntity($block_id)) {
$model->addData($data);
$model->save();
}

//saves data if entry already exist
else {

} else { //saves data if entry already exist
$exist_block = $this->getJsCssEntity($block_id);
$exist_block->addData($data);
$exist_block->save();

}
}

Expand All @@ -119,18 +131,19 @@ public function saveJsCss($observer) {
* @param Varien_Event_Observer | $observer
*
*/
public function applyJsCssToCMSBlocks($observer) {
public function applyJsCssToCMSBlocks(Varien_Event_Observer $observer) {

//set default values to variables
$flag = 0; $jscss_ids = array();
$flag = 0;
$jscss_ids = array();

$layout = $observer->getEvent()->getLayout();

foreach ($layout->getAllBlocks() as $block) {

if ($block instanceof Mage_Cms_Block_Block) {

$flag = 1;

//get cms block id
$block_identifier = $block->getBlockId();
$block_id = (int)Mage::getModel('cms/block')->getCollection()
Expand All @@ -142,33 +155,26 @@ public function applyJsCssToCMSBlocks($observer) {


//check for any entry that is correspond for cms block
if($cms_block = $this->getJsCssEntity($block_id)){

if ($cms_block = $this->getJsCssEntity($block_id)) {
//store jscss ids
$jscss_ids[] = (int)$cms_block->getJscssId();


}

}
}
//print_r($jscss_ids);die();
if($flag == 1){

if ($flag == 1) {

//create a custom block to insert js and css correspond to cms block
$new_block = $layout->createBlock(

'Rkt_JsCssforSb_Block_Jscss',
'jscss_block',
'Rkt_JsCssforSb_Block_Jscss', 'jscss_block',
array(

'template' => 'rkt_jscssforsb/jscss.phtml',
'jscss_ids' => Mage::helper('rkt_jscssforsb')->__(implode(",",$jscss_ids)),
));
'template' => 'rkt_jscssforsb/jscss.phtml',
'jscss_ids' => Mage::helper('rkt_jscssforsb')->__(implode(",", $jscss_ids)),
)
);
$layout->getBlock('content')->append($new_block);

}

}
}

/**
Expand All @@ -179,16 +185,17 @@ public function applyJsCssToCMSBlocks($observer) {
* @return boolean or Rkt_JsCssforSb_Model_JsCss | false or $item
*
*/
public function getJsCssEntity($block_id){
public function getJsCssEntity($block_id)
{

//loads collection
$collection = Mage::getModel('rkt_jscssforsb/jsCss')->getCollection()
->addFieldToSelect('*')
->addFieldToFilter('block_id', array('eq' => $block_id))
->load();
//ensure an item exist
if(count($collection->getFirstItem()->getData())){

//ensure an item exist
if (count($collection->getFirstItem()->getData())) {
return $collection->getFirstItem();
}

Expand Down
Loading

0 comments on commit 95a06cb

Please sign in to comment.