Source for file legacy.php
Documentation is available at legacy.php
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Base class for a Joomla View
* Class holding methods for displaying presentation data.
* The base path of the view
* The set of search directories for resources (templates)
protected $_path =
array('template' =>
array(), 'helper' =>
array());
* The name of the default template source file.
* The output of the template script.
protected $_escape =
'htmlspecialchars';
* Charset to use in escaping mechanisms; defaults to urf8 (UTF-8)
* @param array $config A named configuration array for object construction.<br/>
* name: the name (optional) of the view (defaults to the view class name suffix).<br/>
* charset: the character set to use for display<br/>
* escape: the name (optional) of the function to use for escaping strings<br/>
* base_path: the parent path (optional) of the views directory (defaults to the component folder)<br/>
* template_plath: the path (optional) of the layout directory (defaults to base_path + /views/ + view name<br/>
* helper_path: the path (optional) of the helper files (defaults to base_path + /helpers/)<br/>
* layout: the layout (optional) to use to display the view<br/>
$this->_name =
$config['name'];
// Set the charset (used by the variable escaping functions)
JLog::add('Setting a custom charset for escaping is deprecated. Override JViewLegacy::escape() instead.', JLog::WARNING, 'deprecated');
// User-defined escaping callback
// Set a base path for use by the view
// Set the default template search path
$this->_setPath('template', $config['template_path']);
elseif (is_dir(JPATH_COMPONENT .
'/view'))
// Set the default helper search path
$this->_setPath('helper', $config['helper_path']);
* Execute and display a template script.
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
* @return mixed A string if successful, otherwise a Error object.
* @see JViewLegacy::loadTemplate()
public function display($tpl =
null)
if ($result instanceof
Exception)
* Assigns variables to the view script via differing strategies.
* This method is overloaded; you can assign all the properties of
* an object, an associative array, or a single value by name.
* You are not allowed to set variables that begin with an underscore;
* these are either private properties for JView or private variables
* within the template script itself.
* $view->var1 = 'something';
* // Assign by name and value
* $view->assign('var1', 'something');
* $view->assign('var2', 'else');
* // Assign by assoc-array
* $ary = array('var1' => 'something', 'var2' => 'else');
* $obj->var1 = 'something';
* @return boolean True on success, false on failure.
* @deprecated 13.3 Use native PHP syntax.
JLog::add(__METHOD__ .
' is deprecated. Use native PHP syntax.', JLog::WARNING, 'deprecated');
// Get the arguments; there may be 1 or 2.
// Assign public properties
if (substr($key, 0, 1) !=
'_')
// Assign by associative array
foreach ($arg0 as $key =>
$val)
if (substr($key, 0, 1) !=
'_')
// Assign by string name and mixed value.
// We use array_key_exists() instead of isset() because isset()
// fails if the value is set to null.
// $arg0 was not object, array, or string.
* Assign variable for the view (by reference).
* You are not allowed to set variables that begin with an underscore;
* these are either private properties for JView or private variables
* within the template script itself.
* // Assign by name and value
* $view->assignRef('var1', $ref);
* @param string $key The name for the reference in the view.
* @param mixed &$val The referenced variable.
* @return boolean True on success, false on failure.
* @deprecated 13.3 Use native PHP syntax.
JLog::add(__METHOD__ .
' is deprecated. Use native PHP syntax.', JLog::WARNING, 'deprecated');
* Escapes a value for output in a view script.
* If escaping mechanism is either htmlspecialchars or htmlentities, uses
* {@link $_encoding} setting.
* @param mixed $var The output to escape.
* @return mixed The escaped value.
* Method to get data from a registered model or a property of the view
* @param string $property The name of the method to call on the model or the property to get
* @param string $default The name of the model to reference or the default value [optional]
* @return mixed The return value of the method
public function get($property, $default =
null)
// If $model is null we use the default model
// First check to make sure the model requested exists
// Model exists, let's build the method name
$method =
'get' .
ucfirst($property);
// Does the method exist?
// The method exists, let's call it and return what we get
$result =
$this->_models[$model]->$method();
// Degrade to JObject::get
$result =
parent::get($property, $default);
* Method to get the model object
* @param string $name The name of the model (optional)
* @return mixed JModelLegacy object
* @return string The layout name
* Get the layout template.
* @return string The layout template name
* Method to get the view name
* The model name by default parsed using the classname, or it can be set
* by passing a $config['name'] in the class constructor
* @return string The name of the model
$viewpos =
strpos($classname, 'View');
throw
new Exception(JText::_('JLIB_APPLICATION_ERROR_VIEW_GET_NAME'), 500);
* Method to add a model to the view. We support a multiple model single
* view system by which models are referenced by classname. A caveat to the
* classname referencing is that any classname prepended by JModel will be
* referenced by the name without JModel, eg. JModelCategory is just
* @param JModelLegacy $model The model to add to the view.
* @param boolean $default Is this the default model?
* @return object The added model.
public function setModel($model, $default =
false)
* Sets the layout name to use
* @param string $layout The layout name or a string in format <template>:<layout file>
* @return string Previous value.
if (strpos($layout, ':') ===
false)
// Convert parameter to array based on :
* Allows a different extension for the layout files to be used
* @param string $value The extension.
* @return string Previous value
* Sets the _escape() callback.
* @param mixed $spec The callback for _escape() to use.
* @deprecated 13.3 Override JViewLegacy::escape() instead.
JLog::add(__METHOD__ .
' is deprecated. Override JViewLegacy::escape() instead.', JLog::WARNING, 'deprecated');
* Adds to the stack of view script paths in LIFO order.
* @param mixed $path A directory path or an array of paths.
* Adds to the stack of helper script paths in LIFO order.
* @param mixed $path A directory path or an array of paths.
* Load a template file -- first look in the templates folder for an override
* @param string $tpl The name of the template source file; automatically searches the template paths and compiles as needed.
* @return string The output of the the template script.
// Create the template file name based on the layout
$file = isset
($tpl) ?
$layout .
'_' .
$tpl :
$layout;
$tpl = isset
($tpl) ?
preg_replace('/[^A-Z0-9_\.-]/i', '', $tpl) :
$tpl;
// Load the language file for the template
$lang->load('tpl_' .
$template, JPATH_BASE, null, false, true)
||
$lang->load('tpl_' .
$template, JPATH_THEMES .
"/$template", null, false, true);
// Change the template folder if alternative layout is in different template
if (isset
($layoutTemplate) &&
$layoutTemplate !=
'_' &&
$layoutTemplate !=
$template)
// Load the template script
// If alternate layout can't be found, fall back to default layout
$filetofind =
$this->_createFileName('', array('name' =>
'default' .
(isset
($tpl) ?
'_' .
$tpl :
$tpl)));
// Unset so as not to introduce into template scope
// Never allow a 'this' property
// Start capturing output into a buffer
// Include the requested template filename in the local scope
// (this will execute the view logic).
// Done with the requested template; get the buffer and
throw
new Exception(JText::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $file), 500);
* @param string $hlp The name of the helper source file automatically searches the helper paths and compiles as needed.
// Load the template script
// Include the requested template filename in the local scope
* Sets an entire array of search paths for templates or resources.
* @param string $type The type of path to set, typically 'template'.
* @param mixed $path The new search path, or an array of search paths. If null or false, resets to the current directory only.
protected function _setPath($type, $path)
// Clear out the prior search dirs
$this->_path[$type] =
array();
// Actually add the user-specified directories
// Always add the fallback directories as last resort
// Set the alternative template search dir
$component =
preg_replace('/[^A-Z0-9_\.-]/i', '', $component);
$fallback =
JPATH_THEMES .
'/' .
$app->getTemplate() .
'/html/' .
$component .
'/' .
$this->getName();
* Adds to the search path for templates and resources.
* @param string $type The type of path to add.
* @param mixed $path The directory or stream, or an array of either, to search.
protected function _addPath($type, $path)
// Loop through the path directories
// No surrounding spaces allowed!
// Add trailing separators as needed
if (substr($dir, -
1) !=
DIRECTORY_SEPARATOR)
$dir .=
DIRECTORY_SEPARATOR;
// Add to the top of the search dirs
* Create the filename for a resource
* @param string $type The resource type to create the filename for
* @param array $parts An associative array of filename information
* @return string The filename
* Returns the form object
* @return mixed A JForm object on success, false on failure
$this->form =
$this->get('Form');
Documentation generated on Tue, 19 Nov 2013 15:06:51 +0100 by phpDocumentor 1.4.3