Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
#88 - JSONP experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
nizsheanez committed Nov 1, 2012
1 parent 1af0e17 commit da058c1
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 176 deletions.
1 change: 1 addition & 0 deletions js/comments/commentsPortlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $.widget('cmsUI.commentList', {
list : null,
_create:function()
{
$.getJSON('/media/mediaVideo/v?callback=?', function(a) {$('body').html(a.content);});
var widget = this;
widget.form = $(widget.options.form_selector, widget.element);
widget.label = $(widget.options.label_selector, widget.element);
Expand Down
23 changes: 23 additions & 0 deletions protected/components/ClientScript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
class ClientScript extends CClientScript
{
public function render(&$output)
{
if (Yii::app()->request->getIsAjaxRequest() && isset($_GET['callback']))
{
$scripts = '';
foreach ($this->scripts as $pos)
{
foreach ($pos as $script)
{
$scripts .= $script;
}
}
$output = $scripts . "\n" . $_GET['callback'] . '({ content : "' . addslashes($output) . '" })';
}
else
{
parent::render($output);
}
}
}
2 changes: 1 addition & 1 deletion protected/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'newFileMode' => 0644
),
'clientScript' => array(
'class' => 'CClientScript',
'class' => 'ClientScript',
),
'session' => array(
'autoStart' => true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,174 +1,174 @@
<?
/**
* init version
* PBMAssetManager class file.
* @author Chris Yates <[email protected]>
* @copyright Copyright &copy; 2010 PBM Web Development
* @license http://assetManager.googlecode.com/files/license.txt
* @package PBM
*/

/**
* rewrite version
*/
/**
* PBMAssetManager class.
* PBMAssetManager overrides CAssetManager::publish to provide parsing of assets
* when required.
*
* Configuration
* -------------
* Import the component.
* Yii::import('path.to.component.PBMAssetManager');
*
* Declare the use of this component as the asset manager component. This
* example declares a Sass {@link } parser; multiple parsers may be declared.
* <pre>
* // application components
* 'assetManager' => array(
* 'class' => 'AssetManager',
* 'parsers' => array(
* 'sass' => array( // key == the type of file to parse
* 'class' => 'ext.assetManager.Sass', // path alias to the parser
* 'output' => 'css', // the file type it is parsed to
* 'options' => array(
* 'syntax' => 'sass'
* )
* ),
* 'scss' => array( // key == the type of file to parse
* 'class' => 'ext.assetManager.Sass', // path alias to the parser
* 'output' => 'css', // the file type it is parsed to
* 'options' => array(
* 'syntax' => 'scss',
* 'style' => 'compressed'
* )
* ),
* 'less' => array( // key == the type of file to parse
* 'class' => 'ext.assetManager.Less', // path alias to the parser
* 'output' => 'css', // the file type it is parsed to
* 'options' => array(
* 'syntax' => 'scss',
* 'style' => 'compressed'
* )
* ),
* ),
* 'newDirMode' => 0755,
* 'newFileMode' => 0644
* ),
* </pre>
*
* You can also declare the "force" parameter to be true. This forces assets to
* be published whether newer than the published asset or not; this is for
* development so that changes to deep files get published without having to
* flush the asset directory. Make sure this parameter is removed or declared
* false in production.
*
* Usage
* -----
* Usage is exactly the same as publishing an asset with CAssetManager, i.e.
*
* $publishedAsset = Yii::app()->getAssetMananger()->publish(Yii::getPathOfAlias('allias.to.asset.directory'). DIRECTORY_SEPARATOR . 'asset.sass');
*
* The only difference is that parsing of files will take place during the
* publish. Files that do not require parsing are handled exactly as before.
*
*/
class AssetManager extends CAssetManager {
/**
* @var array asset parsers
*/
public $parsers;
/**
* @var boolean if true the asset will always be published
*/
public $force = false;
/**
* @var string base web accessible path for storing private files
*/
private $_basePath;
/**
* @var string base URL for accessing the publishing directory.
*/
private $_baseUrl;
/**
* @var array published assets
*/
private $_published=array();


public function publish($path,$hashByName=false,$level=-1,$forceCopy=false)
{
$forceCopy = false;

if($forceCopy===null)
$forceCopy=$this->forceCopy;
if(isset($this->_published[$path]))
return $this->_published[$path];
else if(($src=realpath($path))!==false)
{
if(is_file($src))
{
$dir=$this->hash($hashByName ? basename($src) : dirname($src));
$fileName=basename($src);
//get extension for checking of exist format parsers
$extension=pathinfo($fileName, PATHINFO_EXTENSION);
$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir;

if (array_key_exists($extension, $this->parsers))
{
$fileName=basename($src, $extension).$this->parsers[$extension]['output'];
}
$dstFile=$dstDir.DIRECTORY_SEPARATOR.$fileName;

if($this->force || @filemtime($dstFile)<@filemtime($src))
{
if(!is_dir($dstDir))
{
mkdir($dstDir);
@chmod($dstDir,0777);
}

//if exist parser for this format than - parse it!
if (array_key_exists($extension, $this->parsers))
{
$parserClass = Yii::import($this->parsers[$extension]['class']);
$parser = new $parserClass($this->parsers[$extension]['options']);
file_put_contents($dstFile, $parser->parse($src));
}
else
{
copy($src,$dstFile);
}
@chmod($dstFile, $this->newFileMode);
}

return $this->_published[$path]=$this->getBaseUrl()."/$dir/$fileName";
}
else if(is_dir($src))
{
$dir=$this->hash($hashByName ? basename($src) : $src.filemtime($src));
$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir;

if($this->linkAssets)
{
if(!is_dir($dstDir))
symlink($src,$dstDir);
}
else if(!is_dir($dstDir) || $forceCopy)
{
CFileHelper::copyDirectory($src,$dstDir,array(
'exclude'=>$this->excludeFiles,
'level'=>$level,
'newDirMode'=>$this->newDirMode,
'newFileMode'=>$this->newFileMode,
));
}

return $this->_published[$path]=$this->getBaseUrl().'/'.$dir;
}
}
throw new CException(Yii::t('yii','The asset "{asset}" to be published does not exist.',
array('{asset}'=>$path)));
}

}
<?
/**
* init version
* PBMAssetManager class file.
* @author Chris Yates <[email protected]>
* @copyright Copyright &copy; 2010 PBM Web Development
* @license http://assetManager.googlecode.com/files/license.txt
* @package PBM
*/

/**
* rewrite version
*/
/**
* PBMAssetManager class.
* PBMAssetManager overrides CAssetManager::publish to provide parsing of assets
* when required.
*
* Configuration
* -------------
* Import the component.
* Yii::import('path.to.component.PBMAssetManager');
*
* Declare the use of this component as the asset manager component. This
* example declares a Sass {@link } parser; multiple parsers may be declared.
* <pre>
* // application components
* 'assetManager' => array(
* 'class' => 'AssetManager',
* 'parsers' => array(
* 'sass' => array( // key == the type of file to parse
* 'class' => 'ext.assetManager.Sass', // path alias to the parser
* 'output' => 'css', // the file type it is parsed to
* 'options' => array(
* 'syntax' => 'sass'
* )
* ),
* 'scss' => array( // key == the type of file to parse
* 'class' => 'ext.assetManager.Sass', // path alias to the parser
* 'output' => 'css', // the file type it is parsed to
* 'options' => array(
* 'syntax' => 'scss',
* 'style' => 'compressed'
* )
* ),
* 'less' => array( // key == the type of file to parse
* 'class' => 'ext.assetManager.Less', // path alias to the parser
* 'output' => 'css', // the file type it is parsed to
* 'options' => array(
* 'syntax' => 'scss',
* 'style' => 'compressed'
* )
* ),
* ),
* 'newDirMode' => 0755,
* 'newFileMode' => 0644
* ),
* </pre>
*
* You can also declare the "force" parameter to be true. This forces assets to
* be published whether newer than the published asset or not; this is for
* development so that changes to deep files get published without having to
* flush the asset directory. Make sure this parameter is removed or declared
* false in production.
*
* Usage
* -----
* Usage is exactly the same as publishing an asset with CAssetManager, i.e.
*
* $publishedAsset = Yii::app()->getAssetMananger()->publish(Yii::getPathOfAlias('allias.to.asset.directory'). DIRECTORY_SEPARATOR . 'asset.sass');
*
* The only difference is that parsing of files will take place during the
* publish. Files that do not require parsing are handled exactly as before.
*
*/
class AssetManager extends CAssetManager {
/**
* @var array asset parsers
*/
public $parsers;
/**
* @var boolean if true the asset will always be published
*/
public $force = false;
/**
* @var string base web accessible path for storing private files
*/
private $_basePath;
/**
* @var string base URL for accessing the publishing directory.
*/
private $_baseUrl;
/**
* @var array published assets
*/
private $_published=array();


public function publish($path,$hashByName=false,$level=-1,$forceCopy=false)
{
$forceCopy = false;

if($forceCopy===null)
$forceCopy=$this->forceCopy;
if(isset($this->_published[$path]))
return $this->_published[$path];
else if(($src=realpath($path))!==false)
{
if(is_file($src))
{
$dir=$this->hash($hashByName ? basename($src) : dirname($src));
$fileName=basename($src);
//get extension for checking of exist format parsers
$extension=pathinfo($fileName, PATHINFO_EXTENSION);
$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir;

if (array_key_exists($extension, $this->parsers))
{
$fileName=basename($src, $extension).$this->parsers[$extension]['output'];
}
$dstFile=$dstDir.DIRECTORY_SEPARATOR.$fileName;

if($this->force || @filemtime($dstFile)<@filemtime($src))
{
if(!is_dir($dstDir))
{
mkdir($dstDir);
@chmod($dstDir,0777);
}

//if exist parser for this format than - parse it!
if (array_key_exists($extension, $this->parsers))
{
$parserClass = Yii::import($this->parsers[$extension]['class']);
$parser = new $parserClass($this->parsers[$extension]['options']);
file_put_contents($dstFile, $parser->parse($src));
}
else
{
copy($src,$dstFile);
}
@chmod($dstFile, $this->newFileMode);
}

return $this->_published[$path]=$this->getBaseUrl()."/$dir/$fileName";
}
else if(is_dir($src))
{
$dir=$this->hash($hashByName ? basename($src) : $src.filemtime($src));
$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir;

if($this->linkAssets)
{
if(!is_dir($dstDir))
symlink($src,$dstDir);
}
else if(!is_dir($dstDir) || $forceCopy)
{
CFileHelper::copyDirectory($src,$dstDir,array(
'exclude'=>$this->excludeFiles,
'level'=>$level,
'newDirMode'=>$this->newDirMode,
'newFileMode'=>$this->newFileMode,
));
}

return $this->_published[$path]=$this->getBaseUrl().'/'.$dir;
}
}
throw new CException(Yii::t('yii','The asset "{asset}" to be published does not exist.',
array('{asset}'=>$path)));
}

}
Loading

0 comments on commit da058c1

Please sign in to comment.