/**
  * Method to get a list of options for a list input.
  *
  * @return	array		An array of JHtml options.
  *
  * @since   11.4
  */
 protected function getOptions()
 {
     $folder = $this->element['folder'];
     if (!empty($folder)) {
         // Get list of plugins
         $db = Factory::getDbo();
         $query = $db->getQuery(true);
         $query->select('element AS value, name AS text');
         $query->from('#__extensions');
         $query->where('folder = ' . $db->q($folder));
         $query->where('enabled = 1');
         $query->order('ordering, name');
         $db->setQuery($query);
         $options = $db->loadObjectList();
         $lang = Factory::getLanguage();
         foreach ($options as $i => $item) {
             $source = JPATH_PLUGINS . '/' . $folder . '/' . $item->value;
             $extension = 'plg_' . $folder . '_' . $item->value;
             $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, false) || $lang->load($extension . '.sys', $source, null, false, false) || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false);
             $options[$i]->text = Text::_($item->text);
         }
     } else {
         Log::add(Text::_('JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'), Log::WARNING, 'jerror');
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
 /**
  * This method processes a string and replaces all accented UTF-8 characters by unaccented
  * ASCII-7 "equivalents", whitespaces are replaced by hyphens and the string is lowercase.
  *
  * @param   string  $string  String to process
  *
  * @return  string  Processed string
  *
  * @since   11.1
  */
 public static function stringURLSafe($string)
 {
     // Remove any '-' from the string since they will be used as concatenaters
     $str = str_replace('-', ' ', $string);
     $lang = Factory::getLanguage();
     $str = $lang->transliterate($str);
     // Trim white spaces at beginning and end of alias and make lowercase
     $str = trim(String::strtolower($str));
     // Remove any duplicate whitespace, and ensure all characters are alphanumeric
     $str = preg_replace('/(\\s|[^A-Za-z0-9\\-])+/', '-', $str);
     // Trim dashes at beginning and end of alias
     $str = trim($str, '-');
     return $str;
 }
 /**
  * Allows the application to load a custom or default language.
  *
  * The logic and options for creating this object are adequately generic for default cases
  * but for many applications it will make sense to override this method and create a language,
  * if required, based on more specific needs.
  *
  * @param   JLanguage  $language  An optional language object. If omitted, the factory language is created.
  *
  * @return  JApplicationWeb This method is chainable.
  *
  * @since   11.3
  */
 public function loadLanguage(Language $language = null)
 {
     $this->language = $language === null ? Factory::getLanguage() : $language;
     return $this;
 }
 /**
  * Add unobtrusive javascript support for a calendar control.
  *
  * @return  void
  *
  * @since   11.1
  */
 public static function calendar()
 {
     // Only load once
     if (isset(self::$loaded[__METHOD__])) {
         return;
     }
     $document = Factory::getDocument();
     $tag = Factory::getLanguage()->getTag();
     Html::_('stylesheet', 'system/calendar-jos.css', array(' title' => Text::_('JLIB_HTML_BEHAVIOR_GREEN'), ' media' => 'all'), true);
     Html::_('script', $tag . '/calendar.js', false, true);
     Html::_('script', $tag . '/calendar-setup.js', false, true);
     $translation = self::_calendartranslation();
     if ($translation) {
         $document->addScriptDeclaration($translation);
     }
     self::$loaded[__METHOD__] = true;
 }
    /**
     * Displays a calendar control field
     *
     * @param   string  $value    The date value
     * @param   string  $name     The name of the text field
     * @param   string  $id       The id of the text field
     * @param   string  $format   The date format
     * @param   array   $attribs  Additional HTML attributes
     *
     * @return  string  HTML markup for a calendar field
     *
     * @since   11.1
     */
    public static function calendar($value, $name, $id, $format = '%Y-%m-%d', $attribs = null)
    {
        static $done;
        if ($done === null) {
            $done = array();
        }
        $readonly = isset($attribs['readonly']) && $attribs['readonly'] == 'readonly';
        $disabled = isset($attribs['disabled']) && $attribs['disabled'] == 'disabled';
        if (is_array($attribs)) {
            $attribs = ArrayHelper::toString($attribs);
        }
        if (!$readonly && !$disabled) {
            // Load the calendar behavior
            self::_('behavior.calendar');
            self::_('behavior.tooltip');
            // Only display the triggers once for each control.
            if (!in_array($id, $done)) {
                $document = Factory::getDocument();
                $document->addScriptDeclaration('window.addEvent(\'domready\', function() {Calendar.setup({
				// Id of the input field
				inputField: "' . $id . '",
				// Format of the input field
				ifFormat: "' . $format . '",
				// Trigger for the calendar (button ID)
				button: "' . $id . '_img",
				// Alignment (defaults to "Bl")
				align: "Tl",
				singleClick: true,
				firstDay: ' . Factory::getLanguage()->getFirstDay() . '
				});});');
                $done[] = $id;
            }
            return '<input type="text" title="' . (0 !== (int) $value ? self::_('date', $value, null, null) : '') . '" name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" ' . $attribs . ' />' . self::_('image', 'system/calendar.png', Text::_('JLIB_HTML_CALENDAR'), array('class' => 'calendar', 'id' => $id . '_img'), true);
        } else {
            return '<input type="text" title="' . (0 !== (int) $value ? self::_('date', $value, null, null) : '') . '" value="' . (0 !== (int) $value ? self::_('date', $value, 'Y-m-d H:i:s', null) : '') . '" ' . $attribs . ' /><input type="hidden" name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" />';
        }
    }
 /**
  * Method to load, setup and return a JFormField 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 JFormField object for the field or boolean false on error.
  *
  * @since   11.1
  */
 protected function loadField($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'] : 'text';
     // Load the JFormField object for the field.
     $field = $this->loadFieldType($type);
     // If the object could not be loaded, get a text field object.
     if ($field === false) {
         $field = $this->loadFieldType('text');
     }
     /*
      * Get the value for the form field if not set.
      * Default to the translated version of the 'default' attribute
      * if 'translate_default' attribute if set to 'true' or '1'
      * else the value of the 'default' attribute for the field.
      */
     if ($value === null) {
         $default = (string) $element['default'];
         if (($translate = $element['translate_default']) && ((string) $translate == 'true' || (string) $translate == '1')) {
             $lang = Factory::getLanguage();
             if ($lang->hasKey($default)) {
                 $debug = $lang->setDebug(false);
                 $default = Text::_($default);
                 $lang->setDebug($debug);
             } else {
                 $default = Text::_($default);
             }
         }
         $value = $this->getValue((string) $element['name'], $group, $default);
     }
     // Setup the JFormField object.
     $field->setForm($this);
     if ($field->setup($element, $value, $group)) {
         return $field;
     } else {
         return false;
     }
 }
 /**
  * Translate a string into the current language and stores it in the JavaScript language store.
  *
  * @param   string   $string                The JText key.
  * @param   boolean  $jsSafe                Ensure the output is JavaScript safe.
  * @param   boolean  $interpretBackSlashes  Interpret \t and \n.
  *
  * @return  string
  *
  * @since   11.1
  */
 public static function script($string = null, $jsSafe = false, $interpretBackSlashes = true)
 {
     if (is_array($jsSafe)) {
         if (array_key_exists('interpretBackSlashes', $jsSafe)) {
             $interpretBackSlashes = (bool) $jsSafe['interpretBackSlashes'];
         }
         if (array_key_exists('jsSafe', $jsSafe)) {
             $jsSafe = (bool) $jsSafe['jsSafe'];
         } else {
             $jsSafe = false;
         }
     }
     // Add the string to the array if not null.
     if ($string !== null) {
         // Normalize the key and translate the string.
         self::$strings[strtoupper($string)] = Factory::getLanguage()->_($string, $jsSafe, $interpretBackSlashes);
     }
     return self::$strings;
 }
 /**
  * Loads the plugin language file
  *
  * @param   string  $extension  The extension for which a language file should be loaded
  * @param   string  $basePath   The basepath to use
  *
  * @return  boolean  True, if the file has successfully loaded.
  *
  * @since   11.1
  */
 public function loadLanguage($extension = '', $basePath = JPATH_ADMINISTRATOR)
 {
     if (empty($extension)) {
         $extension = 'plg_' . $this->_type . '_' . $this->_name;
     }
     $lang = Factory::getLanguage();
     return $lang->load(strtolower($extension), $basePath, null, false, false) || $lang->load(strtolower($extension), JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name, null, false, false) || $lang->load(strtolower($extension), $basePath, $lang->getDefault(), false, false) || $lang->load(strtolower($extension), JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name, $lang->getDefault(), false, false);
 }