| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Dojo
- * @subpackage View
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @version $Id$
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- /** Zend_Dojo */
- require_once 'Zend/Dojo.php';
- /**
- * Container for Dojo View Helper
- *
- *
- * @package Zend_Dojo
- * @subpackage View
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Dojo_View_Helper_Dojo_Container
- {
- /**
- * @var Zend_View_Interface
- */
- public $view;
- /**
- * addOnLoad capture lock
- * @var bool
- */
- protected $_captureLock = false;
- /**
- * addOnLoad object on which to apply lambda
- * @var string
- */
- protected $_captureObj;
- /**
- * Base CDN url to utilize
- * @var string
- */
- protected $_cdnBase = Zend_Dojo::CDN_BASE_GOOGLE;
- /**
- * Path segment following version string of CDN path
- * @var string
- */
- protected $_cdnDojoPath = Zend_Dojo::CDN_DOJO_PATH_GOOGLE;
- /**
- * Dojo version to use from CDN
- * @var string
- */
- protected $_cdnVersion = '1.5.0';
- /**
- * Has the dijit loader been registered?
- * @var bool
- */
- protected $_dijitLoaderRegistered = false;
- /**
- * Registered programmatic dijits
- * @var array
- */
- protected $_dijits = array();
- /**
- * Dojo configuration
- * @var array
- */
- protected $_djConfig = array();
- /**
- * Whether or not dojo is enabled
- * @var bool
- */
- protected $_enabled = false;
- /**
- * Are we rendering as XHTML?
- * @var bool
- */
- protected $_isXhtml = false;
- /**
- * Arbitrary javascript to include in dojo script
- * @var array
- */
- protected $_javascriptStatements = array();
- /**
- * Dojo layers (custom builds) to use
- * @var array
- */
- protected $_layers = array();
- /**
- * Relative path to dojo
- * @var string
- */
- protected $_localPath = null;
- /**
- * Root of dojo where all dojo files are installed
- * @var string
- */
- protected $_localRelativePath = null;
- /**
- * Modules to require
- * @var array
- */
- protected $_modules = array();
- /**
- * Registered module paths
- * @var array
- */
- protected $_modulePaths = array();
- /**
- * Actions to perform on window load
- * @var array
- */
- protected $_onLoadActions = array();
- /**
- * Register the Dojo stylesheet?
- * @var bool
- */
- protected $_registerDojoStylesheet = false;
- /**
- * Style sheet modules to load
- * @var array
- */
- protected $_stylesheetModules = array();
- /**
- * Local stylesheets
- * @var array
- */
- protected $_stylesheets = array();
- /**
- * Array of onLoad events specific to Zend_Dojo integration operations
- * @var array
- */
- protected $_zendLoadActions = array();
- /**
- * Set view object
- *
- * @param Zend_Dojo_View_Interface $view
- * @return void
- */
- public function setView(Zend_View_Interface $view)
- {
- $this->view = $view;
- }
- /**
- * Enable dojo
- *
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function enable()
- {
- $this->_enabled = true;
- return $this;
- }
- /**
- * Disable dojo
- *
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function disable()
- {
- $this->_enabled = false;
- return $this;
- }
- /**
- * Is dojo enabled?
- *
- * @return bool
- */
- public function isEnabled()
- {
- return $this->_enabled;
- }
- /**
- * Add options for the Dojo Container to use
- *
- * @param array|Zend_Config Array or Zend_Config object with options to use
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function setOptions($options)
- {
- if($options instanceof Zend_Config) {
- $options = $options->toArray();
- }
- foreach($options as $key => $value) {
- $key = strtolower($key);
- switch($key) {
- case 'requiremodules':
- $this->requireModule($value);
- break;
- case 'modulepaths':
- foreach($value as $module => $path) {
- $this->registerModulePath($module, $path);
- }
- break;
- case 'layers':
- $value = (array) $value;
- foreach($value as $layer) {
- $this->addLayer($layer);
- }
- break;
- case 'cdnbase':
- $this->setCdnBase($value);
- break;
- case 'cdnversion':
- $this->setCdnVersion($value);
- break;
- case 'cdndojopath':
- $this->setCdnDojoPath($value);
- break;
- case 'localpath':
- $this->setLocalPath($value);
- break;
- case 'djconfig':
- $this->setDjConfig($value);
- break;
- case 'stylesheetmodules':
- $value = (array) $value;
- foreach($value as $module) {
- $this->addStylesheetModule($module);
- }
- break;
- case 'stylesheets':
- $value = (array) $value;
- foreach($value as $stylesheet) {
- $this->addStylesheet($stylesheet);
- }
- break;
- case 'registerdojostylesheet':
- $this->registerDojoStylesheet($value);
- break;
- case 'enable':
- if($value) {
- $this->enable();
- } else {
- $this->disable();
- }
- }
- }
- return $this;
- }
- /**
- * Specify one or multiple modules to require
- *
- * @param string|array $modules
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function requireModule($modules)
- {
- if (!is_string($modules) && !is_array($modules)) {
- require_once 'Zend/Dojo/View/Exception.php';
- throw new Zend_Dojo_View_Exception('Invalid module name specified; must be a string or an array of strings');
- }
- $modules = (array) $modules;
- foreach ($modules as $mod) {
- if (!preg_match('/^[a-z][a-z0-9._-]+$/i', $mod)) {
- require_once 'Zend/Dojo/View/Exception.php';
- throw new Zend_Dojo_View_Exception(sprintf('Module name specified, "%s", contains invalid characters', (string) $mod));
- }
- if (!in_array($mod, $this->_modules)) {
- $this->_modules[] = $mod;
- }
- }
- return $this;
- }
- /**
- * Retrieve list of modules to require
- *
- * @return array
- */
- public function getModules()
- {
- return $this->_modules;
- }
- /**
- * Register a module path
- *
- * @param string $module The module to register a path for
- * @param string $path The path to register for the module
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function registerModulePath($module, $path)
- {
- $path = (string) $path;
- if (!in_array($module, $this->_modulePaths)) {
- $this->_modulePaths[$module] = $path;
- }
- return $this;
- }
- /**
- * List registered module paths
- *
- * @return array
- */
- public function getModulePaths()
- {
- return $this->_modulePaths;
- }
- /**
- * Add layer (custom build) path
- *
- * @param string $path
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function addLayer($path)
- {
- $path = (string) $path;
- if (!in_array($path, $this->_layers)) {
- $this->_layers[] = $path;
- }
- return $this;
- }
- /**
- * Get registered layers
- *
- * @return array
- */
- public function getLayers()
- {
- return $this->_layers;
- }
- /**
- * Remove a registered layer
- *
- * @param string $path
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function removeLayer($path)
- {
- $path = (string) $path;
- $layers = array_flip($this->_layers);
- if (array_key_exists($path, $layers)) {
- unset($layers[$path]);
- $this->_layers = array_keys($layers);
- }
- return $this;
- }
- /**
- * Clear all registered layers
- *
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function clearLayers()
- {
- $this->_layers = array();
- return $this;
- }
- /**
- * Set CDN base path
- *
- * @param string $url
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function setCdnBase($url)
- {
- $this->_cdnBase = (string) $url;
- return $this;
- }
- /**
- * Return CDN base URL
- *
- * @return string
- */
- public function getCdnBase()
- {
- return $this->_cdnBase;
- }
- /**
- * Use CDN, using version specified
- *
- * @param string $version
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function setCdnVersion($version = null)
- {
- $this->enable();
- if (preg_match('/^[1-9]\.[0-9](\.[0-9])?$/', $version)) {
- $this->_cdnVersion = $version;
- }
- return $this;
- }
- /**
- * Get CDN version
- *
- * @return string
- */
- public function getCdnVersion()
- {
- return $this->_cdnVersion;
- }
- /**
- * Set CDN path to dojo (relative to CDN base + version)
- *
- * @param string $path
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function setCdnDojoPath($path)
- {
- $this->_cdnDojoPath = (string) $path;
- return $this;
- }
- /**
- * Get CDN path to dojo (relative to CDN base + version)
- *
- * @return string
- */
- public function getCdnDojoPath()
- {
- return $this->_cdnDojoPath;
- }
- /**
- * Are we using the CDN?
- *
- * @return bool
- */
- public function useCdn()
- {
- return !$this->useLocalPath();
- }
- /**
- * Set path to local dojo
- *
- * @param string $path
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function setLocalPath($path)
- {
- $this->enable();
- $this->_localPath = (string) $path;
- return $this;
- }
- /**
- * Get local path to dojo
- *
- * @return string
- */
- public function getLocalPath()
- {
- return $this->_localPath;
- }
- /**
- * Are we using a local path?
- *
- * @return bool
- */
- public function useLocalPath()
- {
- return (null === $this->_localPath) ? false : true;
- }
- /**
- * Set Dojo configuration
- *
- * @param string $option
- * @param mixed $value
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function setDjConfig(array $config)
- {
- $this->_djConfig = $config;
- return $this;
- }
- /**
- * Set Dojo configuration option
- *
- * @param string $option
- * @param mixed $value
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function setDjConfigOption($option, $value)
- {
- $option = (string) $option;
- $this->_djConfig[$option] = $value;
- return $this;
- }
- /**
- * Retrieve dojo configuration values
- *
- * @return array
- */
- public function getDjConfig()
- {
- return $this->_djConfig;
- }
- /**
- * Get dojo configuration value
- *
- * @param string $option
- * @param mixed $default
- * @return mixed
- */
- public function getDjConfigOption($option, $default = null)
- {
- $option = (string) $option;
- if (array_key_exists($option, $this->_djConfig)) {
- return $this->_djConfig[$option];
- }
- return $default;
- }
- /**
- * Add a stylesheet by module name
- *
- * @param string $module
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function addStylesheetModule($module)
- {
- if (!preg_match('/^[a-z0-9]+\.[a-z0-9_-]+(\.[a-z0-9_-]+)*$/i', $module)) {
- require_once 'Zend/Dojo/View/Exception.php';
- throw new Zend_Dojo_View_Exception('Invalid stylesheet module specified');
- }
- if (!in_array($module, $this->_stylesheetModules)) {
- $this->_stylesheetModules[] = $module;
- }
- return $this;
- }
- /**
- * Get all stylesheet modules currently registered
- *
- * @return array
- */
- public function getStylesheetModules()
- {
- return $this->_stylesheetModules;
- }
- /**
- * Add a stylesheet
- *
- * @param string $path
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function addStylesheet($path)
- {
- $path = (string) $path;
- if (!in_array($path, $this->_stylesheets)) {
- $this->_stylesheets[] = (string) $path;
- }
- return $this;
- }
- /**
- * Register the dojo.css stylesheet?
- *
- * With no arguments, returns the status of the flag; with arguments, sets
- * the flag and returns the object.
- *
- * @param null|bool $flag
- * @return Zend_Dojo_View_Helper_Dojo_Container|bool
- */
- public function registerDojoStylesheet($flag = null)
- {
- if (null === $flag) {
- return $this->_registerDojoStylesheet;
- }
- $this->_registerDojoStylesheet = (bool) $flag;
- return $this;
- }
- /**
- * Retrieve registered stylesheets
- *
- * @return array
- */
- public function getStylesheets()
- {
- return $this->_stylesheets;
- }
- /**
- * Add a script to execute onLoad
- *
- * dojo.addOnLoad accepts:
- * - function name
- * - lambda
- *
- * @param string $callback Lambda
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function addOnLoad($callback)
- {
- if (!in_array($callback, $this->_onLoadActions, true)) {
- $this->_onLoadActions[] = $callback;
- }
- return $this;
- }
- /**
- * Prepend an onLoad event to the list of onLoad actions
- *
- * @param string $callback Lambda
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function prependOnLoad($callback)
- {
- if (!in_array($callback, $this->_onLoadActions, true)) {
- array_unshift($this->_onLoadActions, $callback);
- }
- return $this;
- }
- /**
- * Retrieve all registered onLoad actions
- *
- * @return array
- */
- public function getOnLoadActions()
- {
- return $this->_onLoadActions;
- }
- /**
- * Start capturing routines to run onLoad
- *
- * @return bool
- */
- public function onLoadCaptureStart()
- {
- if ($this->_captureLock) {
- require_once 'Zend/Dojo/View/Exception.php';
- throw new Zend_Dojo_View_Exception('Cannot nest onLoad captures');
- }
- $this->_captureLock = true;
- ob_start();
- return;
- }
- /**
- * Stop capturing routines to run onLoad
- *
- * @return bool
- */
- public function onLoadCaptureEnd()
- {
- $data = ob_get_clean();
- $this->_captureLock = false;
- $this->addOnLoad($data);
- return true;
- }
- /**
- * Add a programmatic dijit
- *
- * @param string $id
- * @param array $params
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function addDijit($id, array $params)
- {
- if (array_key_exists($id, $this->_dijits)) {
- require_once 'Zend/Dojo/View/Exception.php';
- throw new Zend_Dojo_View_Exception(sprintf('Duplicate dijit with id "%s" already registered', $id));
- }
- $this->_dijits[$id] = array(
- 'id' => $id,
- 'params' => $params,
- );
- return $this;
- }
- /**
- * Set a programmatic dijit (overwrites)
- *
- * @param string $id
- * @param array $params
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function setDijit($id, array $params)
- {
- $this->removeDijit($id);
- return $this->addDijit($id, $params);
- }
- /**
- * Add multiple dijits at once
- *
- * Expects an array of id => array $params pairs
- *
- * @param array $dijits
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function addDijits(array $dijits)
- {
- foreach ($dijits as $id => $params) {
- $this->addDijit($id, $params);
- }
- return $this;
- }
- /**
- * Set multiple dijits at once (overwrites)
- *
- * Expects an array of id => array $params pairs
- *
- * @param array $dijits
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function setDijits(array $dijits)
- {
- $this->clearDijits();
- return $this->addDijits($dijits);
- }
- /**
- * Is the given programmatic dijit already registered?
- *
- * @param string $id
- * @return bool
- */
- public function hasDijit($id)
- {
- return array_key_exists($id, $this->_dijits);
- }
- /**
- * Retrieve a dijit by id
- *
- * @param string $id
- * @return array|null
- */
- public function getDijit($id)
- {
- if ($this->hasDijit($id)) {
- return $this->_dijits[$id]['params'];
- }
- return null;
- }
- /**
- * Retrieve all dijits
- *
- * Returns dijits as an array of assoc arrays
- *
- * @return array
- */
- public function getDijits()
- {
- return array_values($this->_dijits);
- }
- /**
- * Remove a programmatic dijit if it exists
- *
- * @param string $id
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function removeDijit($id)
- {
- if (array_key_exists($id, $this->_dijits)) {
- unset($this->_dijits[$id]);
- }
- return $this;
- }
- /**
- * Clear all dijits
- *
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function clearDijits()
- {
- $this->_dijits = array();
- return $this;
- }
- /**
- * Render dijits as JSON structure
- *
- * @return string
- */
- public function dijitsToJson()
- {
- require_once 'Zend/Json.php';
- return Zend_Json::encode($this->getDijits(), false, array('enableJsonExprFinder' => true));
- }
- /**
- * Create dijit loader functionality
- *
- * @return void
- */
- public function registerDijitLoader()
- {
- if (!$this->_dijitLoaderRegistered) {
- $js =<<<EOJ
- function() {
- dojo.forEach(zendDijits, function(info) {
- var n = dojo.byId(info.id);
- if (null != n) {
- dojo.attr(n, dojo.mixin({ id: info.id }, info.params));
- }
- });
- dojo.parser.parse();
- }
- EOJ;
- $this->requireModule('dojo.parser');
- $this->_addZendLoad($js);
- $this->addJavascript('var zendDijits = ' . $this->dijitsToJson() . ';');
- $this->_dijitLoaderRegistered = true;
- }
- }
- /**
- * Add arbitrary javascript to execute in dojo JS container
- *
- * @param string $js
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function addJavascript($js)
- {
- $js = trim($js);
- if (!in_array(substr($js, -1), array(';', '}'))) {
- $js .= ';';
- }
- if (in_array($js, $this->_javascriptStatements)) {
- return $this;
- }
- $this->_javascriptStatements[] = $js;
- return $this;
- }
- /**
- * Return all registered javascript statements
- *
- * @return array
- */
- public function getJavascript()
- {
- return $this->_javascriptStatements;
- }
- /**
- * Clear arbitrary javascript stack
- *
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function clearJavascript()
- {
- $this->_javascriptStatements = array();
- return $this;
- }
- /**
- * Capture arbitrary javascript to include in dojo script
- *
- * @return void
- */
- public function javascriptCaptureStart()
- {
- if ($this->_captureLock) {
- require_once 'Zend/Dojo/View/Exception.php';
- throw new Zend_Dojo_View_Exception('Cannot nest captures');
- }
- $this->_captureLock = true;
- ob_start();
- return;
- }
- /**
- * Finish capturing arbitrary javascript to include in dojo script
- *
- * @return true
- */
- public function javascriptCaptureEnd()
- {
- $data = ob_get_clean();
- $this->_captureLock = false;
- $this->addJavascript($data);
- return true;
- }
- /**
- * String representation of dojo environment
- *
- * @return string
- */
- public function __toString()
- {
- if (!$this->isEnabled()) {
- return '';
- }
- $this->_isXhtml = $this->view->doctype()->isXhtml();
- if (Zend_Dojo_View_Helper_Dojo::useDeclarative()) {
- if (null === $this->getDjConfigOption('parseOnLoad')) {
- $this->setDjConfigOption('parseOnLoad', true);
- }
- }
- if (!empty($this->_dijits)) {
- $this->registerDijitLoader();
- }
- $html = $this->_renderStylesheets() . PHP_EOL
- . $this->_renderDjConfig() . PHP_EOL
- . $this->_renderDojoScriptTag() . PHP_EOL
- . $this->_renderLayers() . PHP_EOL
- . $this->_renderExtras();
- return $html;
- }
- /**
- * Retrieve local path to dojo resources for building relative paths
- *
- * @return string
- */
- protected function _getLocalRelativePath()
- {
- if (null === $this->_localRelativePath) {
- $localPath = $this->getLocalPath();
- $localPath = preg_replace('|[/\\\\]dojo[/\\\\]dojo.js[^/\\\\]*$|i', '', $localPath);
- $this->_localRelativePath = $localPath;
- }
- return $this->_localRelativePath;
- }
- /**
- * Render dojo stylesheets
- *
- * @return string
- */
- protected function _renderStylesheets()
- {
- if ($this->useCdn()) {
- $base = $this->getCdnBase()
- . $this->getCdnVersion();
- } else {
- $base = $this->_getLocalRelativePath();
- }
- $registeredStylesheets = $this->getStylesheetModules();
- foreach ($registeredStylesheets as $stylesheet) {
- $themeName = substr($stylesheet, strrpos($stylesheet, '.') + 1);
- $stylesheet = str_replace('.', '/', $stylesheet);
- $stylesheets[] = $base . '/' . $stylesheet . '/' . $themeName . '.css';
- }
- foreach ($this->getStylesheets() as $stylesheet) {
- $stylesheets[] = $stylesheet;
- }
- if ($this->_registerDojoStylesheet) {
- $stylesheets[] = $base . '/dojo/resources/dojo.css';
- }
- if (empty($stylesheets)) {
- return '';
- }
- array_reverse($stylesheets);
- $style = '<style type="text/css">' . PHP_EOL
- . (($this->_isXhtml) ? '<!--' : '<!--') . PHP_EOL;
- foreach ($stylesheets as $stylesheet) {
- $style .= ' @import "' . $stylesheet . '";' . PHP_EOL;
- }
- $style .= (($this->_isXhtml) ? '-->' : '-->') . PHP_EOL
- . '</style>';
- return $style;
- }
- /**
- * Render DjConfig values
- *
- * @return string
- */
- protected function _renderDjConfig()
- {
- $djConfigValues = $this->getDjConfig();
- if (empty($djConfigValues)) {
- return '';
- }
- require_once 'Zend/Json.php';
- $scriptTag = '<script type="text/javascript">' . PHP_EOL
- . (($this->_isXhtml) ? '//<![CDATA[' : '//<!--') . PHP_EOL
- . ' var djConfig = ' . Zend_Json::encode($djConfigValues) . ';' . PHP_EOL
- . (($this->_isXhtml) ? '//]]>' : '//-->') . PHP_EOL
- . '</script>';
- return $scriptTag;
- }
- /**
- * Render dojo script tag
- *
- * Renders Dojo script tag by utilizing either local path provided or the
- * CDN. If any djConfig values were set, they will be serialized and passed
- * with that attribute.
- *
- * @return string
- */
- protected function _renderDojoScriptTag()
- {
- if ($this->useCdn()) {
- $source = $this->getCdnBase()
- . $this->getCdnVersion()
- . $this->getCdnDojoPath();
- } else {
- $source = $this->getLocalPath();
- }
- $scriptTag = '<script type="text/javascript" src="' . $source . '"></script>';
- return $scriptTag;
- }
- /**
- * Render layers (custom builds) as script tags
- *
- * @return string
- */
- protected function _renderLayers()
- {
- $layers = $this->getLayers();
- if (empty($layers)) {
- return '';
- }
- $enc = 'UTF-8';
- if ($this->view instanceof Zend_View_Interface
- && method_exists($this->view, 'getEncoding')
- ) {
- $enc = $this->view->getEncoding();
- }
- $html = array();
- foreach ($layers as $path) {
- $html[] = sprintf(
- '<script type="text/javascript" src="%s"></script>',
- htmlspecialchars($path, ENT_QUOTES, $enc)
- );
- }
- return implode("\n", $html);
- }
- /**
- * Render dojo module paths and requires
- *
- * @return string
- */
- protected function _renderExtras()
- {
- $js = array();
- $modulePaths = $this->getModulePaths();
- if (!empty($modulePaths)) {
- foreach ($modulePaths as $module => $path) {
- $js[] = 'dojo.registerModulePath("' . $this->view->escape($module) . '", "' . $this->view->escape($path) . '");';
- }
- }
- $modules = $this->getModules();
- if (!empty($modules)) {
- foreach ($modules as $module) {
- $js[] = 'dojo.require("' . $this->view->escape($module) . '");';
- }
- }
- $onLoadActions = array();
- // Get Zend specific onLoad actions; these will always be first to
- // ensure that dijits are created in the correct order
- foreach ($this->_getZendLoadActions() as $callback) {
- $onLoadActions[] = 'dojo.addOnLoad(' . $callback . ');';
- }
- // Get all other onLoad actions
- foreach ($this->getOnLoadActions() as $callback) {
- $onLoadActions[] = 'dojo.addOnLoad(' . $callback . ');';
- }
- $javascript = implode("\n ", $this->getJavascript());
- $content = '';
- if (!empty($js)) {
- $content .= implode("\n ", $js) . "\n";
- }
- if (!empty($onLoadActions)) {
- $content .= implode("\n ", $onLoadActions) . "\n";
- }
- if (!empty($javascript)) {
- $content .= $javascript . "\n";
- }
- if (preg_match('/^\s*$/s', $content)) {
- return '';
- }
- $html = '<script type="text/javascript">' . PHP_EOL
- . (($this->_isXhtml) ? '//<![CDATA[' : '//<!--') . PHP_EOL
- . $content
- . (($this->_isXhtml) ? '//]]>' : '//-->') . PHP_EOL
- . PHP_EOL . '</script>';
- return $html;
- }
- /**
- * Add an onLoad action related to ZF dijit creation
- *
- * This method is public, but prefixed with an underscore to indicate that
- * it should not normally be called by userland code. It is pertinent to
- * ensuring that the correct order of operations occurs during dijit
- * creation.
- *
- * @param string $callback
- * @return Zend_Dojo_View_Helper_Dojo_Container
- */
- public function _addZendLoad($callback)
- {
- if (!in_array($callback, $this->_zendLoadActions, true)) {
- $this->_zendLoadActions[] = $callback;
- }
- return $this;
- }
- /**
- * Retrieve all ZF dijit callbacks
- *
- * @return array
- */
- public function _getZendLoadActions()
- {
- return $this->_zendLoadActions;
- }
- }
|