Файловый менеджер - Редактировать - /home/lmsyaran/public_html/pusher/form.php.tar
Назад
home/lmsyaran/public_html/libraries/fof/form/form.php 0000644 00000037543 15117103376 0017011 0 ustar 00 <?php /** * @package FrameworkOnFramework * @subpackage form * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // Protect from unauthorized access defined('FOF_INCLUDED') or die; if (version_compare(JVERSION, '2.5.0', 'lt')) { jimport('joomla.form.form'); jimport('joomla.form.formfield'); jimport('joomla.form.formrule'); } /** * FOFForm is an extension to JForm which support not only edit views but also * browse (record list) and read (single record display) views based on XML * forms. * * @package FrameworkOnFramework * @since 2.0 */ class FOFForm extends JForm { /** * The model attached to this view * * @var FOFModel */ protected $model; /** * The view used to render this form * * @var FOFView */ protected $view; /** * Method to get an instance of a form. * * @param string $name The name of the form. * @param string $data The name of an XML file or string to load as the form definition. * @param array $options An array of form options. * @param bool $replace Flag to toggle whether form fields should be replaced if a field * already exists with the same group/name. * @param bool|string $xpath An optional xpath to search for the fields. * * @return object FOFForm instance. * * @since 2.0 * @throws InvalidArgumentException if no data provided. * @throws RuntimeException if the form could not be loaded. */ public static function getInstance($name, $data = null, $options = array(), $replace = true, $xpath = false) { // Reference to array with form instances $forms = &self::$forms; // Only instantiate the form if it does not already exist. if (!isset($forms[$name])) { $data = trim($data); if (empty($data)) { throw new InvalidArgumentException(sprintf('FOFForm::getInstance(name, *%s*)', gettype($data))); } // Instantiate the form. $forms[$name] = new FOFForm($name, $options); // Load the data. if (substr(trim($data), 0, 1) == '<') { if ($forms[$name]->load($data, $replace, $xpath) == false) { throw new RuntimeException('FOFForm::getInstance could not load form'); } } else { if ($forms[$name]->loadFile($data, $replace, $xpath) == false) { throw new RuntimeException('FOFForm::getInstance could not load file ' . $data . '.xml'); } } } return $forms[$name]; } /** * Returns the value of an attribute of the form itself * * @param string $attribute The name of the attribute * @param mixed $default Optional default value to return * * @return mixed * * @since 2.0 */ public function getAttribute($attribute, $default = null) { $value = $this->xml->attributes()->$attribute; if (is_null($value)) { return $default; } else { return (string) $value; } } /** * Loads the CSS files defined in the form, based on its cssfiles attribute * * @return void * * @since 2.0 */ public function loadCSSFiles() { // Support for CSS files $cssfiles = $this->getAttribute('cssfiles'); if (!empty($cssfiles)) { $cssfiles = explode(',', $cssfiles); foreach ($cssfiles as $cssfile) { FOFTemplateUtils::addCSS(trim($cssfile)); } } // Support for LESS files $lessfiles = $this->getAttribute('lessfiles'); if (!empty($lessfiles)) { $lessfiles = explode(',', $lessfiles); foreach ($lessfiles as $def) { $parts = explode('||', $def, 2); $lessfile = $parts[0]; $alt = (count($parts) > 1) ? trim($parts[1]) : null; FOFTemplateUtils::addLESS(trim($lessfile), $alt); } } } /** * Loads the Javascript files defined in the form, based on its jsfiles attribute * * @return void * * @since 2.0 */ public function loadJSFiles() { $jsfiles = $this->getAttribute('jsfiles'); if (empty($jsfiles)) { return; } $jsfiles = explode(',', $jsfiles); foreach ($jsfiles as $jsfile) { FOFTemplateUtils::addJS(trim($jsfile)); } } /** * Returns a reference to the protected $data object, allowing direct * access to and manipulation of the form's data. * * @return JRegistry The form's data registry * * @since 2.0 */ public function getData() { return $this->data; } /** * Attaches a FOFModel to this form * * @param FOFModel &$model The model to attach to the form * * @return void */ public function setModel(FOFModel &$model) { $this->model = $model; } /** * Returns the FOFModel attached to this form * * @return FOFModel */ public function &getModel() { return $this->model; } /** * Attaches a FOFView to this form * * @param FOFView &$view The view to attach to the form * * @return void */ public function setView(FOFView &$view) { $this->view = $view; } /** * Returns the FOFView attached to this form * * @return FOFView */ public function &getView() { return $this->view; } /** * Method to get an array of FOFFormHeader objects in the headerset. * * @return array The array of FOFFormHeader objects in the headerset. * * @since 2.0 */ public function getHeaderset() { $fields = array(); $elements = $this->findHeadersByGroup(); // If no field elements were found return empty. if (empty($elements)) { return $fields; } // Build the result array from the found field elements. foreach ($elements as $element) { // Get the field groups for the element. $attrs = $element->xpath('ancestor::headers[@name]/@name'); $groups = array_map('strval', $attrs ? $attrs : array()); $group = implode('.', $groups); // If the field is successfully loaded add it to the result array. if ($field = $this->loadHeader($element, $group)) { $fields[$field->id] = $field; } } return $fields; } /** * Method to get an array of <header /> elements from the form XML document which are * in a control group by name. * * @param mixed $group The optional dot-separated form group path on which to find the fields. * Null will return all fields. False will return fields not in a group. * @param boolean $nested True to also include fields in nested groups that are inside of the * group for which to find fields. * * @return mixed Boolean false on error or array of SimpleXMLElement objects. * * @since 2.0 */ protected function &findHeadersByGroup($group = null, $nested = false) { $false = false; $fields = array(); // Make sure there is a valid JForm XML document. if (!($this->xml instanceof SimpleXMLElement)) { return $false; } // Get only fields in a specific group? if ($group) { // Get the fields elements for a given group. $elements = &$this->findHeader($group); // Get all of the field elements for the fields elements. foreach ($elements as $element) { // If there are field elements add them to the return result. if ($tmp = $element->xpath('descendant::header')) { // If we also want fields in nested groups then just merge the arrays. if ($nested) { $fields = array_merge($fields, $tmp); } // If we want to exclude nested groups then we need to check each field. else { $groupNames = explode('.', $group); foreach ($tmp as $field) { // Get the names of the groups that the field is in. $attrs = $field->xpath('ancestor::headers[@name]/@name'); $names = array_map('strval', $attrs ? $attrs : array()); // If the field is in the specific group then add it to the return list. if ($names == (array) $groupNames) { $fields = array_merge($fields, array($field)); } } } } } } elseif ($group === false) { // Get only field elements not in a group. $fields = $this->xml->xpath('descendant::headers[not(@name)]/header | descendant::headers[not(@name)]/headerset/header '); } else { // Get an array of all the <header /> elements. $fields = $this->xml->xpath('//header'); } return $fields; } /** * Method to get a header field represented as a FOFFormHeader object. * * @param string $name The name of the header field. * @param string $group The optional dot-separated form group path on which to find the field. * @param mixed $value The optional value to use as the default for the field. * * @return mixed The FOFFormHeader object for the field or boolean false on error. * * @since 2.0 */ public function getHeader($name, $group = null, $value = null) { // Make sure there is a valid FOFForm XML document. if (!($this->xml instanceof SimpleXMLElement)) { return false; } // Attempt to find the field by name and group. $element = $this->findHeader($name, $group); // If the field element was not found return false. if (!$element) { return false; } return $this->loadHeader($element, $group, $value); } /** * Method to get a header field represented as an XML element object. * * @param string $name The name of the form field. * @param string $group The optional dot-separated form group path on which to find the field. * * @return mixed The XML element object for the field or boolean false on error. * * @since 2.0 */ protected function findHeader($name, $group = null) { $element = false; $fields = array(); // Make sure there is a valid JForm XML document. if (!($this->xml instanceof SimpleXMLElement)) { return false; } // Let's get the appropriate field element based on the method arguments. if ($group) { // Get the fields elements for a given group. $elements = &$this->findGroup($group); // Get all of the field elements with the correct name for the fields elements. foreach ($elements as $element) { // If there are matching field elements add them to the fields array. if ($tmp = $element->xpath('descendant::header[@name="' . $name . '"]')) { $fields = array_merge($fields, $tmp); } } // Make sure something was found. if (!$fields) { return false; } // Use the first correct match in the given group. $groupNames = explode('.', $group); foreach ($fields as &$field) { // Get the group names as strings for ancestor fields elements. $attrs = $field->xpath('ancestor::headerfields[@name]/@name'); $names = array_map('strval', $attrs ? $attrs : array()); // If the field is in the exact group use it and break out of the loop. if ($names == (array) $groupNames) { $element = &$field; break; } } } else { // Get an array of fields with the correct name. $fields = $this->xml->xpath('//header[@name="' . $name . '"]'); // Make sure something was found. if (!$fields) { return false; } // Search through the fields for the right one. foreach ($fields as &$field) { // If we find an ancestor fields element with a group name then it isn't what we want. if ($field->xpath('ancestor::headerfields[@name]')) { continue; } // Found it! else { $element = &$field; break; } } } return $element; } /** * Method to load, setup and return a FOFFormHeader object based on field data. * * @param string $element The XML element object representation of the form field. * @param string $group The optional dot-separated form group path on which to find the field. * @param mixed $value The optional value to use as the default for the field. * * @return mixed The FOFFormHeader object for the field or boolean false on error. * * @since 2.0 */ protected function loadHeader($element, $group = null, $value = null) { // Make sure there is a valid SimpleXMLElement. if (!($element instanceof SimpleXMLElement)) { return false; } // Get the field type. $type = $element['type'] ? (string) $element['type'] : 'field'; // Load the JFormField object for the field. $field = $this->loadHeaderType($type); // If the object could not be loaded, get a text field object. if ($field === false) { $field = $this->loadHeaderType('field'); } // Setup the FOFFormHeader object. $field->setForm($this); if ($field->setup($element, $value, $group)) { return $field; } else { return false; } } /** * Method to remove a header from the form definition. * * @param string $name The name of the form field for which remove. * @param string $group The optional dot-separated form group path on which to find the field. * * @return boolean True on success, false otherwise. * * @throws UnexpectedValueException */ public function removeHeader($name, $group = null) { // Make sure there is a valid JForm XML document. if (!($this->xml instanceof SimpleXMLElement)) { throw new UnexpectedValueException(sprintf('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. $element = $this->findHeader($name, $group); // If the element exists remove it from the form definition. if ($element instanceof SimpleXMLElement) { $dom = dom_import_simplexml($element); $dom->parentNode->removeChild($dom); return true; } return false; } /** * Proxy for {@link FOFFormHelper::loadFieldType()}. * * @param string $type The field type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return mixed FOFFormField object on success, false otherwise. * * @since 2.0 */ protected function loadFieldType($type, $new = true) { return FOFFormHelper::loadFieldType($type, $new); } /** * Proxy for {@link FOFFormHelper::loadHeaderType()}. * * @param string $type The field type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return mixed FOFFormHeader object on success, false otherwise. * * @since 2.0 */ protected function loadHeaderType($type, $new = true) { return FOFFormHelper::loadHeaderType($type, $new); } /** * Proxy for {@link FOFFormHelper::loadRuleType()}. * * @param string $type The rule type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return mixed JFormRule object on success, false otherwise. * * @see FOFFormHelper::loadRuleType() * @since 2.0 */ protected function loadRuleType($type, $new = true) { return FOFFormHelper::loadRuleType($type, $new); } /** * Proxy for {@link FOFFormHelper::addFieldPath()}. * * @param mixed $new A path or array of paths to add. * * @return array The list of paths that have been added. * * @since 2.0 */ public static function addFieldPath($new = null) { return FOFFormHelper::addFieldPath($new); } /** * Proxy for {@link FOFFormHelper::addHeaderPath()}. * * @param mixed $new A path or array of paths to add. * * @return array The list of paths that have been added. * * @since 2.0 */ public static function addHeaderPath($new = null) { return FOFFormHelper::addHeaderPath($new); } /** * Proxy for FOFFormHelper::addFormPath(). * * @param mixed $new A path or array of paths to add. * * @return array The list of paths that have been added. * * @see FOFFormHelper::addFormPath() * @since 2.0 */ public static function addFormPath($new = null) { return FOFFormHelper::addFormPath($new); } /** * Proxy for FOFFormHelper::addRulePath(). * * @param mixed $new A path or array of paths to add. * * @return array The list of paths that have been added. * * @see FOFFormHelper::addRulePath() * @since 2.0 */ public static function addRulePath($new = null) { return FOFFormHelper::addRulePath($new); } } home/lmsyaran/public_html/joomla35/libraries/fof/form/form.php 0000644 00000037543 15117156251 0020442 0 ustar 00 <?php /** * @package FrameworkOnFramework * @subpackage form * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // Protect from unauthorized access defined('FOF_INCLUDED') or die; if (version_compare(JVERSION, '2.5.0', 'lt')) { jimport('joomla.form.form'); jimport('joomla.form.formfield'); jimport('joomla.form.formrule'); } /** * FOFForm is an extension to JForm which support not only edit views but also * browse (record list) and read (single record display) views based on XML * forms. * * @package FrameworkOnFramework * @since 2.0 */ class FOFForm extends JForm { /** * The model attached to this view * * @var FOFModel */ protected $model; /** * The view used to render this form * * @var FOFView */ protected $view; /** * Method to get an instance of a form. * * @param string $name The name of the form. * @param string $data The name of an XML file or string to load as the form definition. * @param array $options An array of form options. * @param bool $replace Flag to toggle whether form fields should be replaced if a field * already exists with the same group/name. * @param bool|string $xpath An optional xpath to search for the fields. * * @return object FOFForm instance. * * @since 2.0 * @throws InvalidArgumentException if no data provided. * @throws RuntimeException if the form could not be loaded. */ public static function getInstance($name, $data = null, $options = array(), $replace = true, $xpath = false) { // Reference to array with form instances $forms = &self::$forms; // Only instantiate the form if it does not already exist. if (!isset($forms[$name])) { $data = trim($data); if (empty($data)) { throw new InvalidArgumentException(sprintf('FOFForm::getInstance(name, *%s*)', gettype($data))); } // Instantiate the form. $forms[$name] = new FOFForm($name, $options); // Load the data. if (substr(trim($data), 0, 1) == '<') { if ($forms[$name]->load($data, $replace, $xpath) == false) { throw new RuntimeException('FOFForm::getInstance could not load form'); } } else { if ($forms[$name]->loadFile($data, $replace, $xpath) == false) { throw new RuntimeException('FOFForm::getInstance could not load file ' . $data . '.xml'); } } } return $forms[$name]; } /** * Returns the value of an attribute of the form itself * * @param string $attribute The name of the attribute * @param mixed $default Optional default value to return * * @return mixed * * @since 2.0 */ public function getAttribute($attribute, $default = null) { $value = $this->xml->attributes()->$attribute; if (is_null($value)) { return $default; } else { return (string) $value; } } /** * Loads the CSS files defined in the form, based on its cssfiles attribute * * @return void * * @since 2.0 */ public function loadCSSFiles() { // Support for CSS files $cssfiles = $this->getAttribute('cssfiles'); if (!empty($cssfiles)) { $cssfiles = explode(',', $cssfiles); foreach ($cssfiles as $cssfile) { FOFTemplateUtils::addCSS(trim($cssfile)); } } // Support for LESS files $lessfiles = $this->getAttribute('lessfiles'); if (!empty($lessfiles)) { $lessfiles = explode(',', $lessfiles); foreach ($lessfiles as $def) { $parts = explode('||', $def, 2); $lessfile = $parts[0]; $alt = (count($parts) > 1) ? trim($parts[1]) : null; FOFTemplateUtils::addLESS(trim($lessfile), $alt); } } } /** * Loads the Javascript files defined in the form, based on its jsfiles attribute * * @return void * * @since 2.0 */ public function loadJSFiles() { $jsfiles = $this->getAttribute('jsfiles'); if (empty($jsfiles)) { return; } $jsfiles = explode(',', $jsfiles); foreach ($jsfiles as $jsfile) { FOFTemplateUtils::addJS(trim($jsfile)); } } /** * Returns a reference to the protected $data object, allowing direct * access to and manipulation of the form's data. * * @return JRegistry The form's data registry * * @since 2.0 */ public function getData() { return $this->data; } /** * Attaches a FOFModel to this form * * @param FOFModel &$model The model to attach to the form * * @return void */ public function setModel(FOFModel &$model) { $this->model = $model; } /** * Returns the FOFModel attached to this form * * @return FOFModel */ public function &getModel() { return $this->model; } /** * Attaches a FOFView to this form * * @param FOFView &$view The view to attach to the form * * @return void */ public function setView(FOFView &$view) { $this->view = $view; } /** * Returns the FOFView attached to this form * * @return FOFView */ public function &getView() { return $this->view; } /** * Method to get an array of FOFFormHeader objects in the headerset. * * @return array The array of FOFFormHeader objects in the headerset. * * @since 2.0 */ public function getHeaderset() { $fields = array(); $elements = $this->findHeadersByGroup(); // If no field elements were found return empty. if (empty($elements)) { return $fields; } // Build the result array from the found field elements. foreach ($elements as $element) { // Get the field groups for the element. $attrs = $element->xpath('ancestor::headers[@name]/@name'); $groups = array_map('strval', $attrs ? $attrs : array()); $group = implode('.', $groups); // If the field is successfully loaded add it to the result array. if ($field = $this->loadHeader($element, $group)) { $fields[$field->id] = $field; } } return $fields; } /** * Method to get an array of <header /> elements from the form XML document which are * in a control group by name. * * @param mixed $group The optional dot-separated form group path on which to find the fields. * Null will return all fields. False will return fields not in a group. * @param boolean $nested True to also include fields in nested groups that are inside of the * group for which to find fields. * * @return mixed Boolean false on error or array of SimpleXMLElement objects. * * @since 2.0 */ protected function &findHeadersByGroup($group = null, $nested = false) { $false = false; $fields = array(); // Make sure there is a valid JForm XML document. if (!($this->xml instanceof SimpleXMLElement)) { return $false; } // Get only fields in a specific group? if ($group) { // Get the fields elements for a given group. $elements = &$this->findHeader($group); // Get all of the field elements for the fields elements. foreach ($elements as $element) { // If there are field elements add them to the return result. if ($tmp = $element->xpath('descendant::header')) { // If we also want fields in nested groups then just merge the arrays. if ($nested) { $fields = array_merge($fields, $tmp); } // If we want to exclude nested groups then we need to check each field. else { $groupNames = explode('.', $group); foreach ($tmp as $field) { // Get the names of the groups that the field is in. $attrs = $field->xpath('ancestor::headers[@name]/@name'); $names = array_map('strval', $attrs ? $attrs : array()); // If the field is in the specific group then add it to the return list. if ($names == (array) $groupNames) { $fields = array_merge($fields, array($field)); } } } } } } elseif ($group === false) { // Get only field elements not in a group. $fields = $this->xml->xpath('descendant::headers[not(@name)]/header | descendant::headers[not(@name)]/headerset/header '); } else { // Get an array of all the <header /> elements. $fields = $this->xml->xpath('//header'); } return $fields; } /** * Method to get a header field represented as a FOFFormHeader object. * * @param string $name The name of the header field. * @param string $group The optional dot-separated form group path on which to find the field. * @param mixed $value The optional value to use as the default for the field. * * @return mixed The FOFFormHeader object for the field or boolean false on error. * * @since 2.0 */ public function getHeader($name, $group = null, $value = null) { // Make sure there is a valid FOFForm XML document. if (!($this->xml instanceof SimpleXMLElement)) { return false; } // Attempt to find the field by name and group. $element = $this->findHeader($name, $group); // If the field element was not found return false. if (!$element) { return false; } return $this->loadHeader($element, $group, $value); } /** * Method to get a header field represented as an XML element object. * * @param string $name The name of the form field. * @param string $group The optional dot-separated form group path on which to find the field. * * @return mixed The XML element object for the field or boolean false on error. * * @since 2.0 */ protected function findHeader($name, $group = null) { $element = false; $fields = array(); // Make sure there is a valid JForm XML document. if (!($this->xml instanceof SimpleXMLElement)) { return false; } // Let's get the appropriate field element based on the method arguments. if ($group) { // Get the fields elements for a given group. $elements = &$this->findGroup($group); // Get all of the field elements with the correct name for the fields elements. foreach ($elements as $element) { // If there are matching field elements add them to the fields array. if ($tmp = $element->xpath('descendant::header[@name="' . $name . '"]')) { $fields = array_merge($fields, $tmp); } } // Make sure something was found. if (!$fields) { return false; } // Use the first correct match in the given group. $groupNames = explode('.', $group); foreach ($fields as &$field) { // Get the group names as strings for ancestor fields elements. $attrs = $field->xpath('ancestor::headerfields[@name]/@name'); $names = array_map('strval', $attrs ? $attrs : array()); // If the field is in the exact group use it and break out of the loop. if ($names == (array) $groupNames) { $element = &$field; break; } } } else { // Get an array of fields with the correct name. $fields = $this->xml->xpath('//header[@name="' . $name . '"]'); // Make sure something was found. if (!$fields) { return false; } // Search through the fields for the right one. foreach ($fields as &$field) { // If we find an ancestor fields element with a group name then it isn't what we want. if ($field->xpath('ancestor::headerfields[@name]')) { continue; } // Found it! else { $element = &$field; break; } } } return $element; } /** * Method to load, setup and return a FOFFormHeader object based on field data. * * @param string $element The XML element object representation of the form field. * @param string $group The optional dot-separated form group path on which to find the field. * @param mixed $value The optional value to use as the default for the field. * * @return mixed The FOFFormHeader object for the field or boolean false on error. * * @since 2.0 */ protected function loadHeader($element, $group = null, $value = null) { // Make sure there is a valid SimpleXMLElement. if (!($element instanceof SimpleXMLElement)) { return false; } // Get the field type. $type = $element['type'] ? (string) $element['type'] : 'field'; // Load the JFormField object for the field. $field = $this->loadHeaderType($type); // If the object could not be loaded, get a text field object. if ($field === false) { $field = $this->loadHeaderType('field'); } // Setup the FOFFormHeader object. $field->setForm($this); if ($field->setup($element, $value, $group)) { return $field; } else { return false; } } /** * Method to remove a header from the form definition. * * @param string $name The name of the form field for which remove. * @param string $group The optional dot-separated form group path on which to find the field. * * @return boolean True on success, false otherwise. * * @throws UnexpectedValueException */ public function removeHeader($name, $group = null) { // Make sure there is a valid JForm XML document. if (!($this->xml instanceof SimpleXMLElement)) { throw new UnexpectedValueException(sprintf('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. $element = $this->findHeader($name, $group); // If the element exists remove it from the form definition. if ($element instanceof SimpleXMLElement) { $dom = dom_import_simplexml($element); $dom->parentNode->removeChild($dom); return true; } return false; } /** * Proxy for {@link FOFFormHelper::loadFieldType()}. * * @param string $type The field type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return mixed FOFFormField object on success, false otherwise. * * @since 2.0 */ protected function loadFieldType($type, $new = true) { return FOFFormHelper::loadFieldType($type, $new); } /** * Proxy for {@link FOFFormHelper::loadHeaderType()}. * * @param string $type The field type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return mixed FOFFormHeader object on success, false otherwise. * * @since 2.0 */ protected function loadHeaderType($type, $new = true) { return FOFFormHelper::loadHeaderType($type, $new); } /** * Proxy for {@link FOFFormHelper::loadRuleType()}. * * @param string $type The rule type. * @param boolean $new Flag to toggle whether we should get a new instance of the object. * * @return mixed JFormRule object on success, false otherwise. * * @see FOFFormHelper::loadRuleType() * @since 2.0 */ protected function loadRuleType($type, $new = true) { return FOFFormHelper::loadRuleType($type, $new); } /** * Proxy for {@link FOFFormHelper::addFieldPath()}. * * @param mixed $new A path or array of paths to add. * * @return array The list of paths that have been added. * * @since 2.0 */ public static function addFieldPath($new = null) { return FOFFormHelper::addFieldPath($new); } /** * Proxy for {@link FOFFormHelper::addHeaderPath()}. * * @param mixed $new A path or array of paths to add. * * @return array The list of paths that have been added. * * @since 2.0 */ public static function addHeaderPath($new = null) { return FOFFormHelper::addHeaderPath($new); } /** * Proxy for FOFFormHelper::addFormPath(). * * @param mixed $new A path or array of paths to add. * * @return array The list of paths that have been added. * * @see FOFFormHelper::addFormPath() * @since 2.0 */ public static function addFormPath($new = null) { return FOFFormHelper::addFormPath($new); } /** * Proxy for FOFFormHelper::addRulePath(). * * @param mixed $new A path or array of paths to add. * * @return array The list of paths that have been added. * * @see FOFFormHelper::addRulePath() * @since 2.0 */ public static function addRulePath($new = null) { return FOFFormHelper::addRulePath($new); } } home/lmsyaran/public_html/joomla35/libraries/cms/html/form.php 0000644 00000003265 15117313637 0020450 0 ustar 00 <?php /** * @package Joomla.Libraries * @subpackage HTML * * @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('JPATH_PLATFORM') or die; use Joomla\Utilities\ArrayHelper; /** * Utility class for form elements * * @since 1.5 */ abstract class JHtmlForm { /** * Array containing information for loaded files. * * @var array * * @since 3.8.0 */ protected static $loaded = array(); /** * Displays a hidden token field to reduce the risk of CSRF exploits * * Use in conjunction with JSession::checkToken() * * @param array $attribs Input element attributes. * * @return string A hidden input field with a token * * @see JSession::checkToken() * @since 1.5 */ public static function token(array $attribs = array()) { $attributes = ''; if ($attribs !== array()) { $attributes .= ' ' . ArrayHelper::toString($attribs); } return '<input type="hidden" name="' . JSession::getFormToken() . '" value="1"' . $attributes . ' />'; } /** * Add CSRF form token to Joomla script options that developers can get it by Javascript. * * @param string $name The script option key name. * * @return void * * @since 3.8.0 */ public static function csrf($name = 'csrf.token') { if (isset(static::$loaded[__METHOD__][$name])) { return; } /** @var JDocumentHtml $doc */ $doc = JFactory::getDocument(); if (!$doc instanceof JDocumentHtml || $doc->getType() !== 'html') { return; } $doc->addScriptOptions($name, JSession::getFormToken()); static::$loaded[__METHOD__][$name] = true; } } home/lmsyaran/public_html/libraries/fof/view/form.php 0000644 00000006334 15120010316 0016773 0 ustar 00 <?php /** * @package FrameworkOnFramework * @subpackage view * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @note This file has been modified by the Joomla! Project and no longer reflects the original work of its author. */ // Protect from unauthorized access defined('FOF_INCLUDED') or die; /** * FrameworkOnFramework Form class. It preferably renders an XML view template * instead of a traditional PHP-based view template. * * @package FrameworkOnFramework * @since 2.0 */ class FOFViewForm extends FOFViewHtml { /** @var FOFForm The form to render */ protected $form; /** * Displays the view * * @param string $tpl The template to use * * @return boolean|null False if we can't render anything */ public function display($tpl = null) { $model = $this->getModel(); // Get the form $this->form = $model->getForm(); $this->form->setModel($model); $this->form->setView($this); // Get the task set in the model $task = $model->getState('task', 'browse'); // Call the relevant method $method_name = 'on' . ucfirst($task); if (method_exists($this, $method_name)) { $result = $this->$method_name($tpl); } else { $result = $this->onDisplay(); } // Bail out if we're told not to render anything if ($result === false) { return; } // Show the view // -- Output HTML before the view template $this->preRender(); // -- Try to load a view template; if not exists render the form directly $basePath = FOFPlatform::getInstance()->isBackend() ? 'admin:' : 'site:'; $basePath .= $this->config['option'] . '/'; $basePath .= $this->config['view'] . '/'; $path = $basePath . $this->getLayout(); if ($tpl) { $path .= '_' . $tpl; } $viewTemplate = $this->loadAnyTemplate($path); // If there was no template file found, display the form if ($viewTemplate instanceof Exception) { $viewTemplate = $this->getRenderedForm(); } // -- Output the view template echo $viewTemplate; // -- Output HTML after the view template $this->postRender(); } /** * Returns the HTML rendering of the FOFForm attached to this view. Very * useful for customising a form page without having to meticulously hand- * code the entire form. * * @return string The HTML of the rendered form */ public function getRenderedForm() { $html = ''; $renderer = $this->getRenderer(); if ($renderer instanceof FOFRenderAbstract) { // Load CSS and Javascript files defined in the form $this->form->loadCSSFiles(); $this->form->loadJSFiles(); // Get the form's HTML $html = $renderer->renderForm($this->form, $this->getModel(), $this->input); } return $html; } /** * The event which runs when we are displaying the Add page * * @param string $tpl The view sub-template to use * * @return boolean True to allow display of the view */ protected function onAdd($tpl = null) { // Hide the main menu JRequest::setVar('hidemainmenu', true); // Get the model $model = $this->getModel(); // Assign the item and form to the view $this->item = $model->getItem(); return true; } } home/lmsyaran/public_html/joomla35/components/com_config/model/form.php 0000644 00000021104 15120111571 0022311 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_config * * @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; /** * Prototype form model. * * @see JForm * @see JFormField * @see JFormRule * @since 3.2 */ abstract class ConfigModelForm extends ConfigModelCms { /** * Array of form objects. * * @var array * @since 3.2 */ protected $forms = array(); /** * Method to checkin a row. * * @param integer $pk The numeric id of the primary key. * * @return boolean False on failure or error, true otherwise. * * @since 3.2 * @throws RuntimeException */ public function checkin($pk = null) { // Only attempt to check the row in if it exists. if ($pk) { $user = JFactory::getUser(); // Get an instance of the row to checkin. $table = $this->getTable(); if (!$table->load($pk)) { throw new RuntimeException($table->getError()); } // Check if this is the user has previously checked out the row. if ($table->checked_out > 0 && $table->checked_out != $user->get('id') && !$user->authorise('core.admin', 'com_checkin')) { throw new RuntimeException($table->getError()); } // Attempt to check the row in. if (!$table->checkin($pk)) { throw new RuntimeException($table->getError()); } } return true; } /** * Method to check-out a row for editing. * * @param integer $pk The numeric id of the primary key. * * @return boolean False on failure or error, true otherwise. * * @since 3.2 */ public function checkout($pk = null) { // Only attempt to check the row in if it exists. if ($pk) { $user = JFactory::getUser(); // Get an instance of the row to checkout. $table = $this->getTable(); if (!$table->load($pk)) { throw new RuntimeException($table->getError()); } // Check if this is the user having previously checked out the row. if ($table->checked_out > 0 && $table->checked_out != $user->get('id')) { throw new RuntimeException(JText::_('JLIB_APPLICATION_ERROR_CHECKOUT_USER_MISMATCH')); } // Attempt to check the row out. if (!$table->checkout($user->get('id'), $pk)) { throw new RuntimeException($table->getError()); } } return true; } /** * Abstract method for getting the form from the model. * * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return mixed A JForm object on success, false on failure * * @since 3.2 */ abstract public function getForm($data = array(), $loadData = true); /** * Method to get a form object. * * @param string $name The name of the form. * @param string $source The form source. Can be XML string if file flag is set to false. * @param array $options Optional array of options for the form creation. * @param boolean $clear Optional argument to force load a new form. * @param string $xpath An optional xpath to search for the fields. * * @return mixed JForm object on success, False on error. * * @see JForm * @since 3.2 */ protected function loadForm($name, $source = null, $options = array(), $clear = false, $xpath = false) { // Handle the optional arguments. $options['control'] = ArrayHelper::getValue($options, 'control', false); // Create a signature hash. $hash = sha1($source . serialize($options)); // Check if we can use a previously loaded form. if (isset($this->_forms[$hash]) && !$clear) { return $this->_forms[$hash]; } // Get the form. // Register the paths for the form -- failing here $paths = new SplPriorityQueue; $paths->insert(JPATH_COMPONENT_ADMINISTRATOR . '/model/form', 'normal'); $paths->insert(JPATH_COMPONENT_ADMINISTRATOR . '/model/field', 'normal'); $paths->insert(JPATH_COMPONENT . '/model/form', 'normal'); $paths->insert(JPATH_COMPONENT . '/model/field', 'normal'); $paths->insert(JPATH_COMPONENT . '/model/rule', 'normal'); // Legacy support to be removed in 4.0. -- failing here $paths->insert(JPATH_COMPONENT . '/models/forms', 'normal'); $paths->insert(JPATH_COMPONENT . '/models/fields', 'normal'); $paths->insert(JPATH_COMPONENT . '/models/rules', 'normal'); // Solution until JForm supports splqueue JForm::addFormPath(JPATH_COMPONENT . '/models/forms'); JForm::addFieldPath(JPATH_COMPONENT . '/models/fields'); JForm::addFormPath(JPATH_COMPONENT_ADMINISTRATOR . '/model/form'); JForm::addFieldPath(JPATH_COMPONENT_ADMINISTRATOR . '/model/field'); JForm::addFormPath(JPATH_COMPONENT . '/model/form'); JForm::addFieldPath(JPATH_COMPONENT . '/model/field'); try { $form = JForm::getInstance($name, $source, $options, false, $xpath); if (isset($options['load_data']) && $options['load_data']) { // Get the data for the form. $data = $this->loadFormData(); } else { $data = array(); } // Allow for additional modification of the form, and events to be triggered. // We pass the data because plugins may require it. $this->preprocessForm($form, $data); // Load the data into the form after the plugins have operated. $form->bind($data); } catch (Exception $e) { JFactory::getApplication()->enqueueMessage($e->getMessage()); return false; } // Store the form for later. $this->_forms[$hash] = $form; return $form; } /** * Method to get the data that should be injected in the form. * * @return array The default data is an empty array. * * @since 3.2 */ protected function loadFormData() { return array(); } /** * Method to allow derived classes to preprocess the data. * * @param string $context The context identifier. * @param mixed &$data The data to be processed. It gets altered directly. * * @return void * * @since 3.2 */ protected function preprocessData($context, &$data) { // Get the dispatcher and load the users plugins. $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('content'); // Trigger the data preparation event. $results = $dispatcher->trigger('onContentPrepareData', array($context, $data)); // Check for errors encountered while preparing the data. if (count($results) > 0 && in_array(false, $results, true)) { JFactory::getApplication()->enqueueMessage($dispatcher->getError(), 'error'); } } /** * Method to allow derived classes to preprocess the form. * * @param JForm $form A JForm object. * @param mixed $data The data expected for the form. * @param string $group The name of the plugin group to import (defaults to "content"). * * @return void * * @see JFormField * @since 3.2 * @throws Exception if there is an error in the form event. */ protected function preprocessForm(JForm $form, $data, $group = 'content') { // Import the appropriate plugin group. JPluginHelper::importPlugin($group); // Get the dispatcher. $dispatcher = JEventDispatcher::getInstance(); // Trigger the form preparation event. $results = $dispatcher->trigger('onContentPrepareForm', array($form, $data)); // Check for errors encountered while preparing the form. if (count($results) && in_array(false, $results, true)) { // Get the last error. $error = $dispatcher->getError(); if (!($error instanceof Exception)) { throw new Exception($error); } } } /** * Method to validate the form data. * * @param JForm $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the field group to validate. * * @return mixed Array of filtered data if valid, false otherwise. * * @see JFormRule * @see JFilterInput * @since 3.2 */ public function validate($form, $data, $group = null) { // Filter and validate the form data. $data = $form->filter($data); $return = $form->validate($data, $group); // Check for an error. if ($return instanceof Exception) { JFactory::getApplication()->enqueueMessage($return->getMessage(), 'error'); return false; } // Check the validation results. if ($return === false) { // Get the validation messages from the form. foreach ($form->getErrors() as $message) { if ($message instanceof Exception) { $message = $message->getMessage(); } JFactory::getApplication()->enqueueMessage($message, 'error'); } return false; } return $data; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.33 | Генерация страницы: 0.08 |
proxy
|
phpinfo
|
Настройка