Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
plugins.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Form
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 JFormHelper::loadFieldClass('list');
13 
14 /**
15  * Form Field class for the Joomla Framework.
16  *
17  * @package Joomla.Platform
18  * @subpackage Form
19  * @since 11.4
20  */
22 {
23  /**
24  * The field type.
25  *
26  * @var string
27  * @since 11.4
28  */
29  protected $type = 'Plugins';
30 
31  /**
32  * The path to folder for plugins.
33  *
34  * @var string
35  * @since 3.2
36  */
37  protected $folder;
38 
39  /**
40  * Method to get certain otherwise inaccessible properties from the form field object.
41  *
42  * @param string $name The property name for which to the the value.
43  *
44  * @return mixed The property value or null.
45  *
46  * @since 3.2
47  */
48  public function __get($name)
49  {
50  switch ($name)
51  {
52  case 'folder':
53  return $this->$name;
54  }
55 
56  return parent::__get($name);
57  }
58 
59  /**
60  * Method to set certain otherwise inaccessible properties of the form field object.
61  *
62  * @param string $name The property name for which to the the value.
63  * @param mixed $value The value of the property.
64  *
65  * @return void
66  *
67  * @since 3.2
68  */
69  public function __set($name, $value)
70  {
71  switch ($name)
72  {
73  case 'folder':
74  $this->$name = (string) $value;
75  break;
76 
77  default:
78  parent::__set($name, $value);
79  }
80  }
81 
82  /**
83  * Method to attach a JForm object to the field.
84  *
85  * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
86  * @param mixed $value The form field value to validate.
87  * @param string $group The field name group control value. This acts as as an array container for the field.
88  * For example if the field has name="foo" and the group value is set to "bar" then the
89  * full field name would end up being "bar[foo]".
90  *
91  * @return boolean True on success.
92  *
93  * @see JFormField::setup()
94  * @since 3.2
95  */
96  public function setup(SimpleXMLElement $element, $value, $group = null)
97  {
98  $return = parent::setup($element, $value, $group);
99 
100  if ($return)
101  {
102  $this->folder = (string) $this->element['folder'];
103  }
104 
105  return $return;
106  }
107 
108  /**
109  * Method to get a list of options for a list input.
110  *
111  * @return array An array of JHtml options.
112  *
113  * @since 11.4
114  */
115  protected function getOptions()
116  {
117  $folder = $this->folder;
118 
119  if (!empty($folder))
120  {
121  // Get list of plugins
122  $db = JFactory::getDbo();
123  $query = $db->getQuery(true)
124  ->select('element AS value, name AS text')
125  ->from('#__extensions')
126  ->where('folder = ' . $db->quote($folder))
127  ->where('enabled = 1')
128  ->order('ordering, name');
129  $db->setQuery($query);
130 
131  $options = $db->loadObjectList();
132 
133  $lang = JFactory::getLanguage();
134 
135  foreach ($options as $i => $item)
136  {
137  $source = JPATH_PLUGINS . '/' . $folder . '/' . $item->value;
138  $extension = 'plg_' . $folder . '_' . $item->value;
139  $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, false)
140  || $lang->load($extension . '.sys', $source, null, false, false)
141  || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false)
142  || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false);
143  $options[$i]->text = JText::_($item->text);
144  }
145  }
146  else
147  {
148  JLog::add(JText::_('JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'), JLog::WARNING, 'jerror');
149  }
150 
151  // Merge any additional options in the XML definition.
152  $options = array_merge(parent::getOptions(), $options);
153 
154  return $options;
155  }
156 }