Index: Container.php
===================================================================
--- Container.php (revision 24461)
+++ Container.php (working copy)
@@ -52,6 +52,12 @@
protected $_captureObj;
/**
+ * Scheme (https or http)
+ * @var string
+ */
+ protected $_scheme = null;
+
+ /**
* Base CDN url to utilize
* @var string
*/
@@ -118,12 +124,6 @@
protected $_localPath = null;
/**
- * Root of dojo where all dojo files are installed
- * @var string
- */
- protected $_localRelativePath = null;
-
- /**
* Modules to require
* @var array
*/
@@ -237,6 +237,9 @@
$this->addLayer($layer);
}
break;
+ case 'secure':
+ $this->setSecure($value);
+ break;
case 'cdnbase':
$this->setCdnBase($value);
break;
@@ -400,6 +403,49 @@
}
/**
+ * Return scheme (http or https)
+ *
+ * @return string
+ */
+ protected function _getScheme()
+ {
+ if (null === $this->_scheme) {
+ if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
+ $this->_scheme = 'https';
+ } else {
+ $this->_scheme = 'http';
+ }
+ }
+ return $this->_scheme;
+ }
+
+ /**
+ * Public method for setting scheme (http or https)
+ *
+ * @param bool $value
+ * @return Zend_Dojo_View_Helper_Dojo_Container
+ */
+ public function setSecure($value)
+ {
+ $value = (bool) $value;
+ $this->_scheme = ($value) ? 'https' : 'http';
+ return $this;
+ }
+
+ /**
+ * Correct scheme of provided path (http or https)
+ *
+ * @param string $path
+ * @return string
+ */
+ protected function _prepareScheme($path)
+ {
+ $path = (string) $path;
+ $scheme = $this->_getScheme();
+ return preg_replace('#^(http://|https://)#i', $scheme . '://', $path);
+ }
+
+ /**
* Set CDN base path
*
* @param string $url
@@ -512,6 +558,37 @@
}
/**
+ * Determine and return basepath (cdn or local)
+ *
+ * @return string
+ */
+ public function getBasePath()
+ {
+ if ($this->useCdn()) {
+ $path = $this->getCdnBase() . $this->getCdnVersion();
+ } else {
+ $expr = '|[/\\\\]dojo[/\\\\]dojo.js[^/\\\\]*$|i';
+ $path = preg_replace($expr, '', $this->getLocalPath());
+ }
+ return $path;
+ }
+
+ /**
+ * Determine and return sourcepath (cdn or local)
+ *
+ * @return string
+ */
+ public function getSourcePath()
+ {
+ if ($this->useCdn()) {
+ $path = $this->getBasePath() . $this->getCdnDojoPath();
+ } else {
+ $path = $this->getLocalPath();
+ }
+ return $path;
+ }
+
+ /**
* Set Dojo configuration
*
* @param string $option
@@ -979,33 +1056,13 @@
}
/**
- * 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();
- }
+ $base = $this->_prepareScheme($this->getBasePath());
$registeredStylesheets = $this->getStylesheetModules();
foreach ($registeredStylesheets as $stylesheet) {
@@ -1015,7 +1072,7 @@
}
foreach ($this->getStylesheets() as $stylesheet) {
- $stylesheets[] = $stylesheet;
+ $stylesheets[] = $this->_prepareScheme($stylesheet);
}
if ($this->_registerDojoStylesheet) {
@@ -1071,16 +1128,9 @@
*/
protected function _renderDojoScriptTag()
{
- if ($this->useCdn()) {
- $source = $this->getCdnBase()
- . $this->getCdnVersion()
- . $this->getCdnDojoPath();
- } else {
- $source = $this->getLocalPath();
- }
-
- $scriptTag = '';
- return $scriptTag;
+ $source = $this->_prepareScheme($this->getSourcePath());
+ $tag = '';
+ return $tag;
}
/**
@@ -1104,6 +1154,7 @@
$html = array();
foreach ($layers as $path) {
+ $path = $this->_prepareScheme($path);
$html[] = sprintf(
'',
htmlspecialchars($path, ENT_QUOTES, $enc)
@@ -1121,9 +1172,16 @@
protected function _renderExtras()
{
$js = array();
+
+ $base = $this->getBasePath();
+ $this->registerModulePath('dojo', $base . '/dojo');
+ $this->registerModulePath('dijit', $base . '/dijit');
+ $this->registerModulePath('dojox', $base . '/dojox');
+
$modulePaths = $this->getModulePaths();
if (!empty($modulePaths)) {
foreach ($modulePaths as $module => $path) {
+ $path = $this->_prepareScheme($path);
$js[] = 'dojo.registerModulePath("' . $this->view->escape($module) . '", "' . $this->view->escape($path) . '");';
}
}
@@ -1202,4 +1260,4 @@
{
return $this->_zendLoadActions;
}
-}
+}
\ No newline at end of file