Fixes issue preventing CMS AJAX from returning arrays

This commit is contained in:
Samuel Georges 2015-04-28 19:31:19 +10:00
parent 0cacb4cbdd
commit cacec27d25
3 changed files with 20 additions and 14 deletions

View File

@ -8,7 +8,7 @@ class Backend extends Facade
* Get the registered name of the component.
*
* Resolves to:
* - Backend\Classes\BackendHelper
* - Backend\Helpers\Backend
*
* @return string
*/

View File

@ -210,7 +210,6 @@ class Controller
/*
* Post-processing
*/
$result = $this->postProcessResult($page, $url, $result);
/*
@ -234,7 +233,7 @@ class Controller
* Renders a page in its entirety, including component initialization.
* AJAX will be disabled for this process.
* @param string $pageFile Specifies the CMS page file name to run.
* @param array $parameters Routing parameters.
* @param array $parameters Routing parameters.
* @param \Cms\Classes\Theme $theme Theme object
*/
public static function render($pageFile, $parameters = [], $theme = null)
@ -429,8 +428,8 @@ class Controller
* Run page functions
*/
CmsException::mask($this->page, 300);
$response = (($result = $this->pageObj->onStart()) ||
($result = $this->page->runComponents()) ||
$response = (($result = $this->pageObj->onStart()) ||
($result = $this->page->runComponents()) ||
($result = $this->pageObj->onEnd())) ? $result : null;
CmsException::unmask();
@ -471,7 +470,7 @@ class Controller
{
$html = MediaViewHelper::instance()->processHtml($html);
$holder = (object)['html'=>$html];
$holder = (object) ['html' => $html];
Event::fire('cms.page.postprocess', [$this, $url, $page, $holder]);

View File

@ -19,11 +19,14 @@ class MediaViewHelper
*/
public function processHtml($html)
{
if (!is_string($html)) {
return $html;
}
$mediaTags = $this->extractMediaTags($html);
foreach ($mediaTags as $tagInfo) {
$pattern = preg_quote($tagInfo['declaration']);
$generatedMarkup = $this->generateMediaTagaMarkup($tagInfo['type'], $tagInfo['src']);
$html = mb_ereg_replace($pattern, $generatedMarkup, $html);
}
@ -42,7 +45,7 @@ class MediaViewHelper
if (preg_match_all('/\<figure\s+[^\>]+\>[^\<]*\<\/figure\>/i', $html, $matches)) {
foreach ($matches[0] as $mediaDeclaration) {
foreach ($tagDefinitions as $type=>$pattern) {
foreach ($tagDefinitions as $type => $pattern) {
$nameMatch = [];
if (preg_match($pattern, $mediaDeclaration, $nameMatch)) {
$result[] = [
@ -62,20 +65,23 @@ class MediaViewHelper
{
$partialName = $type == 'audio' ? 'oc-audio-player' : 'oc-video-player';
if ($this->playerPartialExists($partialName))
return Controller::getController()->renderPartial($partialName, ['src'=>$src]);
if ($this->playerPartialExists($partialName)) {
return Controller::getController()->renderPartial($partialName, ['src' => $src]);
}
return $this->getDefaultPlayerMarkup($type, $src);
}
protected function playerPartialExists($name)
{
if (array_key_exists($name, $this->playerPartialFlags))
if (array_key_exists($name, $this->playerPartialFlags)) {
return $this->playerPartialFlags[$name];
}
$controller = Controller::getController();
if (!$controller)
if (!$controller) {
throw new Phpr_ApplicationException('Media tags can only be processed for front-end requests.');
}
$partial = Partial::loadCached($controller->getTheme(), $name);
@ -85,10 +91,11 @@ class MediaViewHelper
protected function getDefaultPlayerMarkup($type, $src)
{
switch ($type) {
case 'video' :
case 'video':
return '<video src="'.e($src).'" controls></video>';
break;
case 'audio' :
case 'audio':
return '<audio src="'.e($src).'" controls></audio>';
break;
}