Roll back the changes from #852 in the name of KISS
The page vars are just that, view variables, if used incorrectly (relaxed) they can leech out
This commit is contained in:
parent
d827ce686a
commit
8c6a58981e
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
* **Build 260** (2015-05-16)
|
* **Build 260** (2015-05-16)
|
||||||
- The `|page` filter now supports passing an empty string to generate a link to the current page.
|
- The `|page` filter now supports passing an empty string to generate a link to the current page.
|
||||||
- Component variables set with `$this->page` no longer leech in to other component partials.
|
|
||||||
|
|
||||||
* **Build 258** (2015-05-09)
|
* **Build 258** (2015-05-09)
|
||||||
- The hotkey for full screen mode is now Cmd+Shift+F or Ctrl+Shift+F in Windows.
|
- The hotkey for full screen mode is now Cmd+Shift+F or Ctrl+Shift+F in Windows.
|
||||||
|
|
|
||||||
|
|
@ -155,14 +155,6 @@ class CmsCompoundObject extends CmsObject
|
||||||
return isset($this->settings[$key]);
|
return isset($this->settings[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the Twig content string
|
|
||||||
*/
|
|
||||||
public function getTwigContent()
|
|
||||||
{
|
|
||||||
return $this->markup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs components defined in the settings
|
* Runs components defined in the settings
|
||||||
* Process halts if a component returns a value
|
* Process halts if a component returns a value
|
||||||
|
|
@ -430,26 +422,6 @@ class CmsCompoundObject extends CmsObject
|
||||||
Cache::forget($key);
|
Cache::forget($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns Twig node tree generated from the object's markup.
|
|
||||||
* This method is used by the system internally and shouldn't
|
|
||||||
* participate in the front-end request processing.
|
|
||||||
* @link http://twig.sensiolabs.org/doc/internals.html Twig internals
|
|
||||||
* @param mixed $markup Specifies the markup content.
|
|
||||||
* Use FALSE to load the content from the markup section.
|
|
||||||
* @return Twig_Node_Module A node tree
|
|
||||||
*/
|
|
||||||
public function getTwigNodeTree($markup = false)
|
|
||||||
{
|
|
||||||
$loader = new TwigLoader();
|
|
||||||
$twig = new Twig_Environment($loader, []);
|
|
||||||
$twig->addExtension(new CmsTwigExtension());
|
|
||||||
$twig->addExtension(new SystemTwigExtension);
|
|
||||||
|
|
||||||
$stream = $twig->tokenize($markup === false ? $this->markup : $markup, 'getTwigNodeTree');
|
|
||||||
return $twig->parse($stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the settings array.
|
* Parses the settings array.
|
||||||
* Child classes can override this method in order to update
|
* Child classes can override this method in order to update
|
||||||
|
|
@ -532,4 +504,72 @@ class CmsCompoundObject extends CmsObject
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Twig
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Twig content string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTwigContent()
|
||||||
|
{
|
||||||
|
return $this->markup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns Twig node tree generated from the object's markup.
|
||||||
|
* This method is used by the system internally and shouldn't
|
||||||
|
* participate in the front-end request processing.
|
||||||
|
* @link http://twig.sensiolabs.org/doc/internals.html Twig internals
|
||||||
|
* @param mixed $markup Specifies the markup content.
|
||||||
|
* Use FALSE to load the content from the markup section.
|
||||||
|
* @return Twig_Node_Module A node tree
|
||||||
|
*/
|
||||||
|
public function getTwigNodeTree($markup = false)
|
||||||
|
{
|
||||||
|
$loader = new TwigLoader();
|
||||||
|
$twig = new Twig_Environment($loader, []);
|
||||||
|
$twig->addExtension(new CmsTwigExtension());
|
||||||
|
$twig->addExtension(new SystemTwigExtension);
|
||||||
|
|
||||||
|
$stream = $twig->tokenize($markup === false ? $this->markup : $markup, 'getTwigNodeTree');
|
||||||
|
return $twig->parse($stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Visibility
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the visible attributes for the object.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getVisible()
|
||||||
|
{
|
||||||
|
return $this->visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the visible attributes for the object.
|
||||||
|
* @param array $visible
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setVisible(array $visible)
|
||||||
|
{
|
||||||
|
$this->visible = $visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add visible attributes for the object.
|
||||||
|
* @param array|string|null $attributes
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addVisible($attributes = null)
|
||||||
|
{
|
||||||
|
$attributes = is_array($attributes) ? $attributes : func_get_args();
|
||||||
|
|
||||||
|
$this->visible = array_merge($this->visible, $attributes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,14 +113,24 @@ class CodeBase extends Extendable implements ArrayAccess
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used as a helper for accessing controller variables/components
|
* This object is referenced as $this->page in Cms\Classes\ComponentBase,
|
||||||
* easier in the page code, eg. $this->foo instead of $this['foo']
|
* so to avoid $this->page->page this method will proxy there. This is also
|
||||||
|
* used as a helper for accessing controller variables/components easier
|
||||||
|
* in the page code, eg. $this->foo instead of $this['foo']
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __get($name)
|
public function __get($name)
|
||||||
{
|
{
|
||||||
return $this[$name];
|
if (($value = $this->page->{$name}) !== null) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists($name, $this->controller->vars)) {
|
||||||
|
return $this[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ use Event;
|
||||||
use Config;
|
use Config;
|
||||||
use Cms\Classes\CodeBase;
|
use Cms\Classes\CodeBase;
|
||||||
use Cms\Classes\CmsException;
|
use Cms\Classes\CmsException;
|
||||||
use Cms\Classes\ComponentPage;
|
|
||||||
use October\Rain\Extension\Extendable;
|
use October\Rain\Extension\Extendable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,7 +69,7 @@ abstract class ComponentBase extends Extendable
|
||||||
protected $controller;
|
protected $controller;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Cms\Classes\ComponentPage Page proxy object.
|
* @var Cms\Classes\PageCode Page object object.
|
||||||
*/
|
*/
|
||||||
protected $page;
|
protected $page;
|
||||||
|
|
||||||
|
|
@ -86,8 +85,8 @@ abstract class ComponentBase extends Extendable
|
||||||
public function __construct(CodeBase $cmsObject = null, $properties = [])
|
public function __construct(CodeBase $cmsObject = null, $properties = [])
|
||||||
{
|
{
|
||||||
if ($cmsObject !== null) {
|
if ($cmsObject !== null) {
|
||||||
|
$this->page = $cmsObject;
|
||||||
$this->controller = $cmsObject->controller;
|
$this->controller = $cmsObject->controller;
|
||||||
$this->page = new ComponentPage($cmsObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->properties = $this->validateProperties($properties);
|
$this->properties = $this->validateProperties($properties);
|
||||||
|
|
@ -112,15 +111,6 @@ abstract class ComponentBase extends Extendable
|
||||||
return plugins_path() . $this->dirName;
|
return plugins_path() . $this->dirName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get any variables set via $this->page, exclusively for this component.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getVars()
|
|
||||||
{
|
|
||||||
return $this->page->vars;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executed when this component is first initialized, before AJAX requests.
|
* Executed when this component is first initialized, before AJAX requests.
|
||||||
*/
|
*/
|
||||||
|
|
@ -143,36 +133,6 @@ abstract class ComponentBase extends Extendable
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Dynamically handle calls into the controller instance.
|
|
||||||
* @param string $method
|
|
||||||
* @param array $parameters
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function __call($method, $parameters)
|
|
||||||
{
|
|
||||||
if (method_exists($this, $method)) {
|
|
||||||
return call_user_func_array([$this, $method], $parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method_exists($this->controller, $method)) {
|
|
||||||
return call_user_func_array([$this->controller, $method], $parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new CmsException(Lang::get('cms::lang.component.method_not_found', [
|
|
||||||
'name' => get_class($this),
|
|
||||||
'method' => $method
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the component's alias, used by __SELF__
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->alias;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a requested partial in context of this component,
|
* Renders a requested partial in context of this component,
|
||||||
* see Cms\Classes\Controller@renderPartial for usage.
|
* see Cms\Classes\Controller@renderPartial for usage.
|
||||||
|
|
@ -287,4 +247,38 @@ abstract class ComponentBase extends Extendable
|
||||||
|
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Magic methods
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamically handle calls into the controller instance.
|
||||||
|
* @param string $method
|
||||||
|
* @param array $parameters
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __call($method, $parameters)
|
||||||
|
{
|
||||||
|
if (method_exists($this, $method)) {
|
||||||
|
return call_user_func_array([$this, $method], $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method_exists($this->controller, $method)) {
|
||||||
|
return call_user_func_array([$this->controller, $method], $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new CmsException(Lang::get('cms::lang.component.method_not_found', [
|
||||||
|
'name' => get_class($this),
|
||||||
|
'method' => $method
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the component's alias, used by __SELF__
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->alias;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,130 +0,0 @@
|
||||||
<?php namespace Cms\Classes;
|
|
||||||
|
|
||||||
use ArrayAccess;
|
|
||||||
use Cms\Classes\CodeBase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The 'page' object when referenced in a component.
|
|
||||||
*
|
|
||||||
* @package october\cms
|
|
||||||
* @author Alexey Bobkov, Samuel Georges
|
|
||||||
*/
|
|
||||||
class ComponentPage implements ArrayAccess
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \Cms\Classes\CodeBase The CMS object the component is bound to.
|
|
||||||
*/
|
|
||||||
public $cmsObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Cms\Classes\controller Specifies the CMS controller
|
|
||||||
*/
|
|
||||||
public $controller;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array A list of variables to pass to the component.
|
|
||||||
*/
|
|
||||||
public $vars = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the object instance.
|
|
||||||
* @param \Cms\Classes\CodeBase $cmsObject The bound CMS object.
|
|
||||||
*/
|
|
||||||
public function __construct(CodeBase $cmsObject)
|
|
||||||
{
|
|
||||||
$this->cmsObject = $cmsObject;
|
|
||||||
$this->controller = $cmsObject->controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ArrayAccess implementation
|
|
||||||
*/
|
|
||||||
public function offsetSet($offset, $value)
|
|
||||||
{
|
|
||||||
$this->vars[$offset] = $value;
|
|
||||||
$this->controller->vars[$offset] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ArrayAccess implementation
|
|
||||||
*/
|
|
||||||
public function offsetExists($offset)
|
|
||||||
{
|
|
||||||
return isset($this->vars[$offset]) || isset($this->controller->vars[$offset]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ArrayAccess implementation
|
|
||||||
*/
|
|
||||||
public function offsetUnset($offset)
|
|
||||||
{
|
|
||||||
unset($this->vars[$offset]);
|
|
||||||
unset($this->controller->vars[$offset]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ArrayAccess implementation
|
|
||||||
*/
|
|
||||||
public function offsetGet($offset)
|
|
||||||
{
|
|
||||||
if (isset($this->vars[$offset])) {
|
|
||||||
return $this->vars[$offset];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($this->controller->vars[$offset])) {
|
|
||||||
return $this->controller->vars[$offset];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dynamically handle calls into the controller instance.
|
|
||||||
* @param string $method
|
|
||||||
* @param array $parameters
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function __call($method, $parameters)
|
|
||||||
{
|
|
||||||
return call_user_func_array([$this->cmsObject, $method], $parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This object is referenced as $this->page in Cms\Classes\ComponentBase,
|
|
||||||
* so to avoid $this->page->page this method will proxy there. This is also
|
|
||||||
* used as a helper for accessing controller variables/components easier
|
|
||||||
* in the page code, eg. $this->foo instead of $this['foo']
|
|
||||||
* @param string $name
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __get($name)
|
|
||||||
{
|
|
||||||
if (($value = $this->cmsObject->page->{$name}) !== null) {
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this[$name];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will set a property as a proxy to Cms\Classes\CodeBase.
|
|
||||||
* @param string $name
|
|
||||||
* @param mixed $value
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __set($name, $value)
|
|
||||||
{
|
|
||||||
return $this->cmsObject->{$name} = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This will check if a variable isset as a proxy to Cms\Classes\CodeBase.
|
|
||||||
* @param string $name
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __isset($name)
|
|
||||||
{
|
|
||||||
return isset($this->cmsObject->{$name});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -945,17 +945,15 @@ class Controller
|
||||||
*/
|
*/
|
||||||
public function renderComponent($name, $parameters = [])
|
public function renderComponent($name, $parameters = [])
|
||||||
{
|
{
|
||||||
$componentVars = [];
|
|
||||||
if ($componentObj = $this->findComponentByName($name)) {
|
if ($componentObj = $this->findComponentByName($name)) {
|
||||||
$componentObj->id = uniqid($name);
|
$componentObj->id = uniqid($name);
|
||||||
$componentObj->setProperties(array_merge($componentObj->getProperties(), $parameters));
|
$componentObj->setProperties(array_merge($componentObj->getProperties(), $parameters));
|
||||||
$componentVars = $componentObj->getVars();
|
|
||||||
if ($result = $componentObj->onRender()) {
|
if ($result = $componentObj->onRender()) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->renderPartial($name.'::default', $componentVars, false);
|
return $this->renderPartial($name.'::default', [], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -1136,6 +1134,16 @@ class Controller
|
||||||
return $_url;
|
return $_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts supplied file to a URL relative to the media library.
|
||||||
|
* @param string $file Specifies the media-relative file
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function mediaUrl($file = null)
|
||||||
|
{
|
||||||
|
return MediaLibrary::url($file);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a routing parameter.
|
* Returns a routing parameter.
|
||||||
* @param string Routing parameter name.
|
* @param string Routing parameter name.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue