/** * Method to get the field option groups. * * @return array The field option objects as a nested array in groups. * * @since 11.1 * @throws UnexpectedValueException */ protected function getGroups() { $groups = array(); $label = 0; foreach ($this->element->children() as $element) { switch ($element->getName()) { // The element is an <option /> case 'option': // Initialize the group if necessary. if (!isset($groups[$label])) { $groups[$label] = array(); } // Create a new option object based on the <option /> element. $tmp = Html::_('select.option', $element['value'] ? (string) $element['value'] : trim((string) $element), Text::alt(trim((string) $element), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)), 'value', 'text', (string) $element['disabled'] == 'true'); // Set some option attributes. $tmp->class = (string) $element['class']; // Set some JavaScript option attributes. $tmp->onclick = (string) $element['onclick']; // Add the option. $groups[$label][] = $tmp; break; // The element is a <group /> // The element is a <group /> case 'group': // Get the group label. if ($groupLabel = (string) $element['label']) { $label = Text::_($groupLabel); } // Initialize the group if necessary. if (!isset($groups[$label])) { $groups[$label] = array(); } // Iterate through the children and build an array of options. foreach ($element->children() as $option) { // Only add <option /> elements. if ($option->getName() != 'option') { continue; } // Create a new option object based on the <option /> element. $tmp = Html::_('select.option', $option['value'] ? (string) $option['value'] : Text::_(trim((string) $option)), Text::_(trim((string) $option)), 'value', 'text', (string) $option['disabled'] == 'true'); // Set some option attributes. $tmp->class = (string) $option['class']; // Set some JavaScript option attributes. $tmp->onclick = (string) $option['onclick']; // Add the option. $groups[$label][] = $tmp; } if ($groupLabel) { $label = count($groups); } break; // Unknown element type. // Unknown element type. default: throw new UnexpectedValueException(sprintf('Unsupported element %s in JFormFieldGroupedList', $element->getName()), 500); } } reset($groups); return $groups; }
/** * Method to get the field input markup for check boxes. * * @return string The field input markup. * * @since 1.0 */ protected function getInput() { $html = array(); // Initialize some field attributes. $class = $this->element['class'] ? ' class="checkboxes ' . (string) $this->element['class'] . '"' : ' class="checkboxes"'; $checkedOptions = explode(',', (string) $this->element['checked']); // Start the checkbox field output. $html[] = '<fieldset id="' . $this->id . '"' . $class . '>'; // Get the field options. $options = $this->getOptions(); // Build the checkbox field output. $html[] = '<ul>'; foreach ($options as $i => $option) { // Initialize some option attributes. if (!isset($this->value) || empty($this->value)) { $checked = in_array((string) $option->value, (array) $checkedOptions) ? ' checked="checked"' : ''; } else { $value = !is_array($this->value) ? explode(',', $this->value) : $this->value; $checked = in_array((string) $option->value, $value) ? ' checked="checked"' : ''; } $class = !empty($option->class) ? ' class="' . $option->class . '"' : ''; $disabled = !empty($option->disable) ? ' disabled="disabled"' : ''; // Initialize some JavaScript option attributes. $onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : ''; $html[] = '<li>'; $html[] = '<input type="checkbox" id="' . $this->id . $i . '" name="' . $this->name . '"' . ' value="' . htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>'; $html[] = '<label for="' . $this->id . $i . '"' . $class . '>' . Text::_($option->text) . '</label>'; $html[] = '</li>'; } $html[] = '</ul>'; // End the checkbox field output. $html[] = '</fieldset>'; return implode($html); }
/** * Method to get the list of database options. * * This method produces a drop down list of available databases supported * by JDatabaseDriver classes that are also supported by the application. * * @return array The field option objects. * * @since 1.0 * @see Joomla\Database\DatabaseDriver */ protected function getOptions() { // This gets the connectors available in the platform and supported by the server. $available = DatabaseDriver::getConnectors(); /** * This gets the list of database types supported by the application. * This should be entered in the form definition as a comma separated list. * If no supported databases are listed, it is assumed all available databases * are supported. */ $supported = $this->element['supported']; if (!empty($supported)) { $supported = explode(',', $supported); foreach ($supported as $support) { if (in_array($support, $available)) { $options[$support] = Text::_(ucfirst($support)); } } } else { foreach ($available as $support) { $options[$support] = Text::_(ucfirst($support)); } } // This will come into play if an application is installed that requires // a database that is not available on the server. if (empty($options)) { $options[''] = Text::_('JNONE'); } return $options; }
/** * Method to get the field label markup for a spacer. * Use the label text or name from the XML element as the spacer or * Use a hr="true" to automatically generate plain hr markup * * @return string The field label markup. * * @since 1.0 */ protected function getLabel() { $html = array(); $class = $this->element['class'] ? (string) $this->element['class'] : ''; $html[] = '<span class="spacer">'; $html[] = '<span class="before"></span>'; $html[] = '<span class="' . $class . '">'; if ((string) $this->element['hr'] == 'true') { $html[] = '<hr class="' . $class . '" />'; } else { $label = ''; // Get the label text from the XML element, defaulting to the element name. $text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name']; $text = $this->translateLabel ? Text::_($text) : $text; // Build the class for the label. $class = !empty($this->description) ? 'hasTip' : ''; $class = $this->required == true ? $class . ' required' : $class; // Add the opening label tag and main attributes attributes. $label .= '<label id="' . $this->id . '-lbl" class="' . $class . '"'; // If a description is specified, use it to build a tooltip. if (!empty($this->description)) { $label .= ' title="' . htmlspecialchars(trim($text, ':') . '::' . ($this->translateDescription ? Text::_($this->description) : $this->description), ENT_COMPAT, 'UTF-8') . '"'; } // Add the label text and closing tag. $label .= '>' . $text . '</label>'; $html[] = $label; } $html[] = '</span>'; $html[] = '<span class="after"></span>'; $html[] = '</span>'; return implode('', $html); }
/** * 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; }
/** * Method to check the current record to save * * @return boolean True on success * * @since 11.1 */ public function check() { // Validate the title. if (trim($this->title) == '') { $this->setError(Text::_('JLIB_DATABASE_ERROR_VIEWLEVEL')); return false; } return true; }
/** * Return the most recent error message for the database connector. * * @param boolean $showSQL True to display the SQL statement sent to the database as well as the error. * * @return string The error message for the most recent query. * * @since 11.1 * @deprecated 13.3 */ public function stderr($showSQL = false) { Log::add('JDatabase::stderr() is deprecated.', Log::WARNING, 'deprecated'); if ($this->errorNum != 0) { return Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $this->errorNum, $this->errorMsg) . ($showSQL ? "<br />SQL = <pre>{$this->sql}</pre>" : ''); } else { return Text::_('JLIB_DATABASE_FUNCTION_NOERROR'); } }
/** * Overloaded check function * * @return boolean True if the object is ok * * @see JTable::check * @since 11.1 */ public function check() { // Check for valid name if (trim($this->name) == '' || trim($this->element) == '') { $this->setError(Text::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_EXTENSION')); return false; } return true; }
/** * Simple Javascript email Cloaker * * By default replaces an email with a mailto link with email cloaked * * @param string $mail The -mail address to cloak. * @param boolean $mailto True if text and mailing address differ * @param string $text Text for the link * @param boolean $email True if text is an e-mail address * * @return string The cloaked email. * * @since 11.1 */ public static function cloak($mail, $mailto = true, $text = '', $email = true) { // Convert text $mail = self::_convertEncoding($mail); // Split email by @ symbol $mail = explode('@', $mail); $mail_parts = explode('.', $mail[1]); // Random number $rand = rand(1, 100000); $replacement = "\n <script type='text/javascript'>"; $replacement .= "\n <!--"; $replacement .= "\n var prefix = 'ma' + 'il' + 'to';"; $replacement .= "\n var path = 'hr' + 'ef' + '=';"; $replacement .= "\n var addy" . $rand . " = '" . @$mail[0] . "' + '@';"; $replacement .= "\n addy" . $rand . " = addy" . $rand . " + '" . implode("' + '.' + '", $mail_parts) . "';"; if ($mailto) { // Special handling when mail text is different from mail address if ($text) { if ($email) { // Convert text $text = self::_convertEncoding($text); // Split email by @ symbol $text = explode('@', $text); $text_parts = explode('.', $text[1]); $replacement .= "\n var addy_text" . $rand . " = '" . @$text[0] . "' + '@' + '" . implode("' + '.' + '", @$text_parts) . "';"; } else { $replacement .= "\n var addy_text" . $rand . " = '" . $text . "';"; } $replacement .= "\n document.write('<a ' + path + '\\'' + prefix + ':' + addy" . $rand . " + '\\'>');"; $replacement .= "\n document.write(addy_text" . $rand . ");"; $replacement .= "\n document.write('<\\/a>');"; } else { $replacement .= "\n document.write('<a ' + path + '\\'' + prefix + ':' + addy" . $rand . " + '\\'>');"; $replacement .= "\n document.write(addy" . $rand . ");"; $replacement .= "\n document.write('<\\/a>');"; } } else { $replacement .= "\n document.write(addy" . $rand . ");"; } $replacement .= "\n //-->"; $replacement .= '\\n </script>'; // XHTML compliance no Javascript text handling $replacement .= "<script type='text/javascript'>"; $replacement .= "\n <!--"; $replacement .= "\n document.write('<span style=\\'display: none;\\'>');"; $replacement .= "\n //-->"; $replacement .= "\n </script>"; $replacement .= Text::_('JLIB_HTML_CLOAKING'); $replacement .= "\n <script type='text/javascript'>"; $replacement .= "\n <!--"; $replacement .= "\n document.write('</');"; $replacement .= "\n document.write('span>');"; $replacement .= "\n //-->"; $replacement .= "\n </script>"; return $replacement; }
/** * Method to get the field options. * * @return array The field option objects. * * @since 11.1 */ protected function getOptions() { $options = array(); // Convert to name => name array. foreach (Cache::getStores() as $store) { $options[] = Html::_('select.option', $store, Text::_('JLIB_FORM_VALUE_CACHE_' . $store), 'value', 'text'); } $options = array_merge(parent::getOptions(), $options); return $options; }
/** * Method to get the session handler field options. * * @return array The field option objects. * * @since 11.1 */ protected function getOptions() { $options = array(); // Get the options from JSession. foreach (Session::getStores() as $store) { $options[] = Html::_('select.option', $store, Text::_('JLIB_FORM_VALUE_SESSION_' . $store), 'value', 'text'); } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
/** * Constructor. * * @param array &$options Log object options. * * @since 12.2 */ public function __construct(array &$options) { // Call the parent constructor. parent::__construct($options); // Throw an exception if there is not a valid callback if (isset($this->options['callback']) && is_callable($this->options['callback'])) { $this->callback = $this->options['callback']; } else { throw new Exception(Text::_('JLogLoggerCallback created without valid callback function.')); } }
/** * Method to check the current record to save * * @return boolean True on success * * @since 11.1 */ public function check() { // Validate the title. if (trim($this->title) == '') { $this->setError(Text::_('JLIB_DATABASE_ERROR_USERGROUP_TITLE')); return false; } // Check for a duplicate parent_id, title. // There is a unique index on the (parent_id, title) field in the table. $db = $this->_db; $query = $db->getQuery(true)->select('COUNT(title)')->from($this->_tbl)->where('title = ' . $db->quote(trim($this->title)))->where('parent_id = ' . (int) $this->parent_id)->where('id <> ' . (int) $this->id); $db->setQuery($query); if ($db->loadResult() > 0) { $this->setError(Text::_('JLIB_DATABASE_ERROR_USERGROUP_TITLE_EXISTS')); return false; } return true; }
/** * Overrides Table::store to check unique fields. * * @param boolean $updateNulls True to update fields even if they are null. * * @return boolean True on success. * * @since 11.4 */ public function store($updateNulls = false) { // Verify that the sef field is unique $table = Table::getInstance('Language', 'JTable'); if ($table->load(array('sef' => $this->sef)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) { $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_SEF')); return false; } // Verify that the image field is unique if ($table->load(array('image' => $this->image)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) { $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_IMAGE')); return false; } // Verify that the language code is unique if ($table->load(array('lang_code' => $this->lang_code)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0)) { $this->setError(Text::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_LANG_CODE')); return false; } return parent::store($updateNulls); }
/** * Function to convert a static time into a relative measurement * * @param string $date The date to convert * @param string $unit The optional unit of measurement to return * if the value of the diff is greater than one * @param string $time An optional time to compare to, defaults to now * * @return string The converted time string * * @since 11.3 */ public static function relative($date, $unit = null, $time = null) { if (is_null($time)) { // Get now $time = Factory::getDate('now'); } // Get the difference in seconds between now and the time $diff = strtotime($time) - strtotime($date); // Less than a minute if ($diff < 60) { return Text::_('JLIB_HTML_DATE_RELATIVE_LESSTHANAMINUTE'); } // Round to minutes $diff = round($diff / 60); // 1 to 59 minutes if ($diff < 60 || $unit == 'minute') { return Text::plural('JLIB_HTML_DATE_RELATIVE_MINUTES', $diff); } // Round to hours $diff = round($diff / 60); // 1 to 23 hours if ($diff < 24 || $unit == 'hour') { return Text::plural('JLIB_HTML_DATE_RELATIVE_HOURS', $diff); } // Round to days $diff = round($diff / 24); // 1 to 6 days if ($diff < 7 || $unit == 'day') { return Text::plural('JLIB_HTML_DATE_RELATIVE_DAYS', $diff); } // Round to weeks $diff = round($diff / 7); // 1 to 4 weeks if ($diff <= 4 || $unit == 'week') { return Text::plural('JLIB_HTML_DATE_RELATIVE_WEEKS', $diff); } // Over a month, return the absolute time return Html::_('date', $date); }
/** * Method to get the field label markup. * * @return string The field label markup. * * @since 1.0 */ protected function getLabel() { $label = ''; if ($this->hidden) { return $label; } // Get the label text from the XML element, defaulting to the element name. $text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name']; $text = $this->translateLabel ? Text::_($text) : $text; // Build the class for the label. $class = !empty($this->description) ? 'hasTip' : ''; $class = $this->required == true ? $class . ' required' : $class; $class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class; // Add the opening label tag and main attributes attributes. $label .= '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '"'; // If a description is specified, use it to build a tooltip. if (!empty($this->description)) { $label .= ' title="' . htmlspecialchars(trim($text, ':') . '::' . ($this->translateDescription ? Text::_($this->description) : $this->description), ENT_COMPAT, 'UTF-8') . '"'; } // Add the label text and closing tag. if ($this->required) { $label .= '>' . $text . '<span class="star"> *</span></label>'; } else { $label .= '>' . $text . '</label>'; } return $label; }
/** * Get the array of images associate with specific permissions * * @return array An associative array of permissions and images * * @since 11.1 */ protected static function _getImagesArray() { $images['allow-l'] = '<label class="icon-16-allow" title="' . Text::_('JLIB_RULES_ALLOWED') . '">' . Text::_('JLIB_RULES_ALLOWED') . '</label>'; $images['deny-l'] = '<label class="icon-16-deny" title="' . Text::_('JLIB_RULES_DENIED') . '">' . Text::_('JLIB_RULES_DENIED') . '</label>'; $images['allow'] = '<a class="icon-16-allow" title="' . Text::_('JLIB_RULES_ALLOWED') . '"> </a>'; $images['deny'] = '<a class="icon-16-deny" title="' . Text::_('JLIB_RULES_DENIED') . '"> </a>'; $images['allow-i'] = '<a class="icon-16-allowinactive" title="' . Text::_('JRULE_ALLOWED_INHERITED') . '"> </a>'; $images['deny-i'] = '<a class="icon-16-denyinactive" title="' . Text::_('JRULE_DENIED_INHERITED') . '"> </a>'; return $images; }
/** * Quickly delete a folder of files * * @param string $path The path to the folder to delete. * * @return boolean True on success. * * @since 11.1 */ protected function _deleteFolder($path) { // Sanity check if (!$path || !is_dir($path) || empty($this->_root)) { // Bad programmer! Bad Bad programmer! Log::add('\\Joomla\\Cache\\Storage\\File::_deleteFolder ' . Text::_('JLIB_FILESYSTEM_ERROR_DELETE_BASE_DIRECTORY'), Log::WARNING, 'jerror'); return false; } $path = $this->_cleanPath($path); // Check to make sure path is inside cache folder, we do not want to delete Joomla root! $pos = strpos($path, $this->_cleanPath($this->_root)); if ($pos === false || $pos > 0) { Log::add('\\Joomla\\Cache\\Storage\\File::_deleteFolder' . Text::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path), Log::WARNING, 'jerror'); return false; } // Remove all the files in folder if they exist; disable all filtering $files = $this->_filesInFolder($path, '.', false, true, array(), array()); if (!empty($files) && !is_array($files)) { if (@unlink($files) !== true) { return false; } } elseif (!empty($files) && is_array($files)) { foreach ($files as $file) { $file = $this->_cleanPath($file); // In case of restricted permissions we zap it one way or the other // as long as the owner is either the webserver or the ftp if (@unlink($file)) { // Do nothing } else { $filename = basename($file); Log::add('\\Joomla\\Cache\\Storage\\File::_deleteFolder' . Text::sprintf('JLIB_FILESYSTEM_DELETE_FAILED', $filename), Log::WARNING, 'jerror'); return false; } } } // Remove sub-folders of folder; disable all filtering $folders = $this->_folders($path, '.', false, true, array(), array()); foreach ($folders as $folder) { if (is_link($folder)) { // Don't descend into linked directories, just delete the link. if (@unlink($folder) !== true) { return false; } } elseif ($this->_deleteFolder($folder) !== true) { return false; } } // In case of restricted permissions we zap it one way or the other // as long as the owner is either the webserver or the ftp if (@rmdir($path)) { $ret = true; } else { Log::add('\\Joomla\\Cache\\Storage\\File::_deleteFolder' . Text::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_DELETE', $path), Log::WARNING, 'jerror'); $ret = false; } return $ret; }
/** * Method to get the field input markup for Access Control Lists. * Optionally can be associated with a specific component and section. * * TODO: Add access check. * * @return string The field input markup. * * @since 11.1 */ protected function getInput() { Html::_('behavior.tooltip'); // Initialise some field attributes. $section = $this->element['section'] ? (string) $this->element['section'] : ''; $component = $this->element['component'] ? (string) $this->element['component'] : ''; $assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id'; // Get the actions for the asset. $actions = Access::getActionsFromFile(JPATH_ADMINISTRATOR . '/components/' . $component . '/access.xml', "/access/section[@name='" . $section . "']/"); // Iterate over the children and add to the actions. foreach ($this->element->children() as $el) { if ($el->getName() == 'action') { $actions[] = (object) array('name' => (string) $el['name'], 'title' => (string) $el['title'], 'description' => (string) $el['description']); } } // Get the explicit rules for this asset. if ($section == 'component') { // Need to find the asset id by the name of the component. $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select($db->quoteName('id')); $query->from($db->quoteName('#__assets')); $query->where($db->quoteName('name') . ' = ' . $db->quote($component)); $db->setQuery($query); $assetId = (int) $db->loadResult(); } else { // Find the asset id of the content. // Note that for global configuration, com_config injects asset_id = 1 into the form. $assetId = $this->form->getValue($assetField); } // Use the compact form for the content rules (deprecated). /* @todo remove code: if (!empty($component) && $section != 'component') { return Html::_('rules.assetFormWidget', $actions, $assetId, $assetId ? null : $component, $this->name, $this->id); } */ // Full width format. // Get the rules for just this asset (non-recursive). $assetRules = Access::getAssetRules($assetId); // Get the available user groups. $groups = $this->getUserGroups(); // Build the form control. $curLevel = 0; // Prepare output $html = array(); $html[] = '<div id="permissions-sliders" class="pane-sliders">'; $html[] = '<p class="rule-desc">' . Text::_('JLIB_RULES_SETTINGS_DESC') . '</p>'; $html[] = '<ul id="rules">'; // Start a row for each user group. foreach ($groups as $group) { $difLevel = $group->level - $curLevel; if ($difLevel > 0) { $html[] = '<li><ul>'; } elseif ($difLevel < 0) { $html[] = str_repeat('</ul></li>', -$difLevel); } $html[] = '<li>'; $html[] = '<div class="panel">'; $html[] = '<h3 class="pane-toggler title"><a href="javascript:void(0);"><span>'; $html[] = str_repeat('<span class="level">|–</span> ', $curLevel = $group->level) . $group->text; $html[] = '</span></a></h3>'; $html[] = '<div class="pane-slider content pane-hide">'; $html[] = '<div class="mypanel">'; $html[] = '<table class="group-rules">'; $html[] = '<thead>'; $html[] = '<tr>'; $html[] = '<th class="actions" id="actions-th' . $group->value . '">'; $html[] = '<span class="acl-action">' . Text::_('JLIB_RULES_ACTION') . '</span>'; $html[] = '</th>'; $html[] = '<th class="settings" id="settings-th' . $group->value . '">'; $html[] = '<span class="acl-action">' . Text::_('JLIB_RULES_SELECT_SETTING') . '</span>'; $html[] = '</th>'; // The calculated setting is not shown for the root group of global configuration. $canCalculateSettings = $group->parent_id || !empty($component); if ($canCalculateSettings) { $html[] = '<th id="aclactionth' . $group->value . '">'; $html[] = '<span class="acl-action">' . Text::_('JLIB_RULES_CALCULATED_SETTING') . '</span>'; $html[] = '</th>'; } $html[] = '</tr>'; $html[] = '</thead>'; $html[] = '<tbody>'; foreach ($actions as $action) { $html[] = '<tr>'; $html[] = '<td headers="actions-th' . $group->value . '">'; $html[] = '<label class="hasTip" for="' . $this->id . '_' . $action->name . '_' . $group->value . '" title="' . htmlspecialchars(Text::_($action->title) . '::' . Text::_($action->description), ENT_COMPAT, 'UTF-8') . '">'; $html[] = Text::_($action->title); $html[] = '</label>'; $html[] = '</td>'; $html[] = '<td headers="settings-th' . $group->value . '">'; $html[] = '<select name="' . $this->name . '[' . $action->name . '][' . $group->value . ']" id="' . $this->id . '_' . $action->name . '_' . $group->value . '" title="' . Text::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP', Text::_($action->title), trim($group->text)) . '">'; $inheritedRule = Access::checkGroup($group->value, $action->name, $assetId); // Get the actual setting for the action for this group. $assetRule = $assetRules->allow($action->name, $group->value); // Build the dropdowns for the permissions sliders // The parent group has "Not Set", all children can rightly "Inherit" from that. $html[] = '<option value=""' . ($assetRule === null ? ' selected="selected"' : '') . '>' . Text::_(empty($group->parent_id) && empty($component) ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED') . '</option>'; $html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . Text::_('JLIB_RULES_ALLOWED') . '</option>'; $html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . Text::_('JLIB_RULES_DENIED') . '</option>'; $html[] = '</select>  '; // If this asset's rule is allowed, but the inherited rule is deny, we have a conflict. if ($assetRule === true && $inheritedRule === false) { $html[] = Text::_('JLIB_RULES_CONFLICT'); } $html[] = '</td>'; // Build the Calculated Settings column. // The inherited settings column is not displayed for the root group in global configuration. if ($canCalculateSettings) { $html[] = '<td headers="aclactionth' . $group->value . '">'; // This is where we show the current effective settings considering currrent group, path and cascade. // Check whether this is a component or global. Change the text slightly. if (Access::checkGroup($group->value, 'core.admin') !== true) { if ($inheritedRule === null) { $html[] = '<span class="icon-16-unset">' . Text::_('JLIB_RULES_NOT_ALLOWED') . '</span>'; } elseif ($inheritedRule === true) { $html[] = '<span class="icon-16-allowed">' . Text::_('JLIB_RULES_ALLOWED') . '</span>'; } elseif ($inheritedRule === false) { if ($assetRule === false) { $html[] = '<span class="icon-16-denied">' . Text::_('JLIB_RULES_NOT_ALLOWED') . '</span>'; } else { $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">' . Text::_('JLIB_RULES_NOT_ALLOWED_LOCKED') . '</span></span>'; } } } elseif (!empty($component)) { $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . Text::_('JLIB_RULES_ALLOWED_ADMIN') . '</span></span>'; } else { // Special handling for groups that have global admin because they can't be denied. // The admin rights can be changed. if ($action->name === 'core.admin') { $html[] = '<span class="icon-16-allowed">' . Text::_('JLIB_RULES_ALLOWED') . '</span>'; } elseif ($inheritedRule === false) { // Other actions cannot be changed. $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">' . Text::_('JLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span></span>'; } else { $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . Text::_('JLIB_RULES_ALLOWED_ADMIN') . '</span></span>'; } } $html[] = '</td>'; } $html[] = '</tr>'; } $html[] = '</tbody>'; $html[] = '</table></div>'; $html[] = '</div></div>'; $html[] = '</li>'; } $html[] = str_repeat('</ul></li>', $curLevel); $html[] = '</ul><div class="rule-notes">'; if ($section == 'component' || $section == null) { $html[] = Text::_('JLIB_RULES_SETTING_NOTES'); } else { $html[] = Text::_('JLIB_RULES_SETTING_NOTES_ITEM'); } $html[] = '</div></div>'; // Get the JInput object $input = Factory::getApplication()->input; $js = "window.addEvent('domready', function(){ new Fx.Accordion(\$\$('div#permissions-sliders.pane-sliders .panel h3.pane-toggler')," . "\$\$('div#permissions-sliders.pane-sliders .panel div.pane-slider'), {onActive: function(toggler, i) {toggler.addClass('pane-toggler-down');" . "toggler.removeClass('pane-toggler');i.addClass('pane-down');i.removeClass('pane-hide');Cookie.write('jpanesliders_permissions-sliders" . $component . "',\$\$('div#permissions-sliders.pane-sliders .panel h3').indexOf(toggler));}," . "onBackground: function(toggler, i) {toggler.addClass('pane-toggler');toggler.removeClass('pane-toggler-down');i.addClass('pane-hide');" . "i.removeClass('pane-down');}, duration: 300, display: " . $input->cookie->get('jpanesliders_permissions-sliders' . $component, 0, 'integer') . ", show: " . $input->cookie->get('jpanesliders_permissions-sliders' . $component, 0, 'integer') . ", alwaysHide:true, opacity: false}); });"; Factory::getDocument()->addScriptDeclaration($js); return implode("\n", $html); }
/** * Internal method to translate the JavaScript Calendar * * @return string JavaScript that translates the object * * @since 11.1 */ protected static function _calendartranslation() { static $jsscript = 0; // Guard clause, avoids unnecessary nesting if ($jsscript) { return false; } $jsscript = 1; // To keep the code simple here, run strings through JText::_() using array_map() $callback = array('JText', '_'); $weekdays_full = array_map($callback, array('SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY')); $weekdays_short = array_map($callback, array('SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN')); $months_long = array_map($callback, array('JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER')); $months_short = array_map($callback, array('JANUARY_SHORT', 'FEBRUARY_SHORT', 'MARCH_SHORT', 'APRIL_SHORT', 'MAY_SHORT', 'JUNE_SHORT', 'JULY_SHORT', 'AUGUST_SHORT', 'SEPTEMBER_SHORT', 'OCTOBER_SHORT', 'NOVEMBER_SHORT', 'DECEMBER_SHORT')); // This will become an object in Javascript but define it first in PHP for readability $text = array('INFO' => Text::_('JLIB_HTML_BEHAVIOR_ABOUT_THE_CALENDAR'), 'ABOUT' => "DHTML Date/Time Selector\n" . "(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" . "For latest version visit: http://www.dynarch.com/projects/calendar/\n" . "Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." . "\n\n" . Text::_('JLIB_HTML_BEHAVIOR_DATE_SELECTION') . Text::_('JLIB_HTML_BEHAVIOR_YEAR_SELECT') . Text::_('JLIB_HTML_BEHAVIOR_MONTH_SELECT') . Text::_('JLIB_HTML_BEHAVIOR_HOLD_MOUSE'), 'ABOUT_TIME' => "\n\n" . "Time selection:\n" . "- Click on any of the time parts to increase it\n" . "- or Shift-click to decrease it\n" . "- or click and drag for faster selection.", 'PREV_YEAR' => Text::_('JLIB_HTML_BEHAVIOR_PREV_YEAR_HOLD_FOR_MENU'), 'PREV_MONTH' => Text::_('JLIB_HTML_BEHAVIOR_PREV_MONTH_HOLD_FOR_MENU'), 'GO_TODAY' => Text::_('JLIB_HTML_BEHAVIOR_GO_TODAY'), 'NEXT_MONTH' => Text::_('JLIB_HTML_BEHAVIOR_NEXT_MONTH_HOLD_FOR_MENU'), 'SEL_DATE' => Text::_('JLIB_HTML_BEHAVIOR_SELECT_DATE'), 'DRAG_TO_MOVE' => Text::_('JLIB_HTML_BEHAVIOR_DRAG_TO_MOVE'), 'PART_TODAY' => Text::_('JLIB_HTML_BEHAVIOR_TODAY'), 'DAY_FIRST' => Text::_('JLIB_HTML_BEHAVIOR_DISPLAY_S_FIRST'), 'WEEKEND' => "0,6", 'CLOSE' => Text::_('JLIB_HTML_BEHAVIOR_CLOSE'), 'TODAY' => Text::_('JLIB_HTML_BEHAVIOR_TODAY'), 'TIME_PART' => Text::_('JLIB_HTML_BEHAVIOR_SHIFT_CLICK_OR_DRAG_TO_CHANGE_VALUE'), 'DEF_DATE_FORMAT' => "%Y-%m-%d", 'TT_DATE_FORMAT' => Text::_('JLIB_HTML_BEHAVIOR_TT_DATE_FORMAT'), 'WK' => Text::_('JLIB_HTML_BEHAVIOR_WK'), 'TIME' => Text::_('JLIB_HTML_BEHAVIOR_TIME')); return 'Calendar._DN = ' . json_encode($weekdays_full) . ';' . ' Calendar._SDN = ' . json_encode($weekdays_short) . ';' . ' Calendar._FD = 0;' . ' Calendar._MN = ' . json_encode($months_long) . ';' . ' Calendar._SMN = ' . json_encode($months_short) . ';' . ' Calendar._TT = ' . json_encode($text) . ';'; }
/** * Returns a UL list of actions with check boxes * * @param string $name The name of the checkbox controls array * @param array $selected An array of the checked boxes * @param string $component The component the permissions apply to * @param string $section The section (within a component) the permissions apply to * * @return string * * @see JAccess * @since 11.1 */ public static function actions($name, $selected, $component, $section = 'global') { static $count; $count++; $actions = AuthorizationAccess::getActionsFromFile(JPATH_ADMINISTRATOR . '/components/' . $component . '/access.xml', "/access/section[@name='" . $section . "']/"); $html = array(); $html[] = '<ul class="checklist access-actions">'; for ($i = 0, $n = count($actions); $i < $n; $i++) { $item =& $actions[$i]; // Setup the variable attributes. $eid = $count . 'action_' . $item->id; $checked = in_array($item->id, $selected) ? ' checked="checked"' : ''; // Build the HTML for the item. $html[] = ' <li>'; $html[] = ' <input type="checkbox" name="' . $name . '[]" value="' . $item->id . '" id="' . $eid . '"'; $html[] = ' ' . $checked . ' />'; $html[] = ' <label for="' . $eid . '">'; $html[] = ' ' . Text::_($item->title); $html[] = ' </label>'; $html[] = ' </li>'; } $html[] = '</ul>'; return implode("\n", $html); }
/** * Method to create a checked out icon with optional overlib in a grid. * * @param object &$row The row object * @param boolean $overlib True if an overlib with checkout information should be created. * * @return string HTMl for the icon and overlib * * @since 11.1 */ protected static function _checkedOut(&$row, $overlib = true) { $hover = ''; if ($overlib) { $text = addslashes(htmlspecialchars($row->editor, ENT_COMPAT, 'UTF-8')); $date = Html::_('date', $row->checked_out_time, Text::_('DATE_FORMAT_LC1')); $time = Html::_('date', $row->checked_out_time, 'H:i'); $hover = '<span class="editlinktip hasTip" title="' . Text::_('JLIB_HTML_CHECKED_OUT') . '::' . $text . '<br />' . $date . '<br />' . $time . '">'; } $checked = $hover . Html::_('image', 'admin/checked_out.png', null, null, true) . '</span>'; return $checked; }
/** * Test for Form::getInput method. * * @return void */ public function testGetInput() { $form = new JFormInspector('form1'); $this->assertThat($form->load(JFormDataHelper::$loadFieldDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $this->assertThat($form->getInput('title', null, 'The Title'), $this->equalTo('<input type="text" name="title" id="title_id" value="The Title" class="inputbox required"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field.'); $this->assertThat($form->getInput('show_title', 'params', '0'), $this->equalTo('<fieldset id="params_show_title" class="radio">' . '<input type="radio" id="params_show_title0" name="params[show_title]" value="1"/>' . '<label for="params_show_title0">' . Text::_('JYes') . '</label>' . '<input type="radio" id="params_show_title1" name="params[show_title]" value="0" checked="checked"/>' . '<label for="params_show_title1">' . Text::_('JNo') . '</label>' . '</fieldset>'), 'Line:' . __LINE__ . ' The method should return a radio list.'); $form = new JFormInspector('form1', array('control' => 'jform')); $this->assertThat($form->load(JFormDataHelper::$loadFieldDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $this->assertThat($form->getInput('colours', 'params', 'blue'), $this->equalTo('<select id="jform_params_colours" name="jform[params][colours][]" multiple="multiple">' . "\n" . ' <option value="red">Red</option>' . "\n" . ' <option value="blue" selected="selected">Blue</option>' . "\n" . ' <option value="green">Green</option>' . "\n" . ' <option value="yellow">Yellow</option>' . "\n" . '</select>' . "\n"), 'Line:' . __LINE__ . ' XML string should load successfully.'); // Test translate default $this->assertThat($form->getInput('translate_default'), $this->equalTo('<input type="text" name="jform[translate_default]" id="jform_translate_default" value="DEFAULT_KEY"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field whose value is untranslated since the DEFAULT_KEY does not exist in the language.'); $lang = Language::getInstance(); $debug = $lang->setDebug(true); $this->assertThat($form->getInput('translate_default'), $this->equalTo('<input type="text" name="jform[translate_default]" id="jform_translate_default" value="??DEFAULT_KEY??"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field whose value is marked untranslated.'); $lang->load('form_test', __DIR__); $this->assertThat($form->getInput('translate_default'), $this->equalTo('<input type="text" name="jform[translate_default]" id="jform_translate_default" value="My Default"/>'), 'Line:' . __LINE__ . ' The method should return a simple input text field whose value is translated.'); $lang->setDebug($debug); }
public function uploadLogo() { if ($_FILES['logo']['error']) { return false; } //uploading image $allowedImageTypes = array("image/pjpeg", "image/jpeg", "image/jpg", "image/png", "image/x-png", "image/gif"); if (!in_array($_FILES['logo']['type'], $allowedImageTypes)) { $this->setError(Text::_('INSTL_ERROR_LOGO_FILE_TYPE')); return false; } else { if (!JFile::upload($_FILES['logo']['tmp_name'], JPATH_ROOT . '/uploads/logo/' . JFile::makeSafe($_FILES['logo']['name']))) { $this->setError(Text::_('INSTL_ERROR_UPLOAD_LOGO')); return false; } } return true; }
/** * Constructor * * @since 11.1 */ public function __construct() { $isLoaded = Helper::importPlugin('authentication'); if (!$isLoaded) { Log::add(Text::_('JLIB_USER_ERROR_AUTHENTICATION_LIBRARIES'), Log::WARNING, 'jerror'); } }
/** * Moves an uploaded file to a destination folder * * @param string $src The name of the php (temporary) uploaded file * @param string $dest The path (including filename) to move the uploaded file to * @param boolean $use_streams True to use streams * * @return boolean True on success * * @since 11.1 */ public static function upload($src, $dest, $use_streams = false) { // Ensure that the path is valid and clean $dest = Path::clean($dest); // Create the destination directory if it does not exist $baseDir = dirname($dest); if (!file_exists($baseDir)) { Folder::create($baseDir); } if ($use_streams) { $stream = Factory::getStream(); if (!$stream->upload($src, $dest)) { Log::add(Text::sprintf('JLIB_FILESYSTEM_ERROR_UPLOAD', $stream->getError()), Log::WARNING, 'jerror'); return false; } return true; } else { $FTPOptions = ClientHelper::getCredentials('ftp'); $ret = false; if ($FTPOptions['enabled'] == 1) { // Connect the FTP client $ftp = ClientFtp::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']); // Translate path for the FTP account $dest = Path::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/'); // Copy the file to the destination directory if (is_uploaded_file($src) && $ftp->store($src, $dest)) { unlink($src); $ret = true; } else { Log::add(Text::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR02'), Log::WARNING, 'jerror'); } } else { if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) { // Short circuit to prevent file permission errors if (Path::setPermissions($dest)) { $ret = true; } else { Log::add(Text::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR01'), Log::WARNING, 'jerror'); } } else { Log::add(Text::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR02'), Log::WARNING, 'jerror'); } } return $ret; } }
?> " type="password" id="adminPassword" name="password" placeholder="<?php echo Text::_('INSTL_PLHD_ADMIN_PASSWORD'); ?> " class="form-control"> </div> </div> <br/> <div class="pull-left"> <a href="#database" data-toggle="tab" data-showtab="database" class="btn btn-danger"><i class="glyphicon glyphicon-chevron-left"></i> <?php echo Text::_('INSTL_BACK'); ?> </a> </div> <div class="pull-right"> <a href="#" onclick="validateAdmin();" class="btn btn-success"><?php echo Text::_('INSTL_BTN_INSTALL'); ?> </a> </div> <div class="clearfix"></div> </div> </div> </form> </div> </div> </div>
/** * Checks for a form token in the request. * * Use in conjunction with JHtml::_('form.token') or JSession::getFormToken. * * @param string $method The request method in which to look for the token key. * * @return boolean True if found and valid, false otherwise. * * @since 12.1 */ public static function checkToken($method = 'post') { $token = self::getFormToken(); $app = Factory::getApplication(); if (!$app->input->{$method}->get($token, '', 'alnum')) { $session = Factory::getSession(); if ($session->isNew()) { // Redirect to login screen. $app->redirect(Route::_('index.php'), Text::_('JLIB_ENVIRONMENT_SESSION_EXPIRED')); $app->close(); } else { return false; } } else { return true; } }
/** * Translates month number to a string. * * @param integer $month The numeric month of the year. * @param boolean $abbr If true, return the abbreviated month string * * @return string The month of the year. * * @since 1.1 */ public function monthToString($month, $abbr = false) { switch ($month) { case 1: return $abbr ? Text::_('JANUARY_SHORT') : Text::_('JANUARY'); case 2: return $abbr ? Text::_('FEBRUARY_SHORT') : Text::_('FEBRUARY'); case 3: return $abbr ? Text::_('MARCH_SHORT') : Text::_('MARCH'); case 4: return $abbr ? Text::_('APRIL_SHORT') : Text::_('APRIL'); case 5: return $abbr ? Text::_('MAY_SHORT') : Text::_('MAY'); case 6: return $abbr ? Text::_('JUNE_SHORT') : Text::_('JUNE'); case 7: return $abbr ? Text::_('JULY_SHORT') : Text::_('JULY'); case 8: return $abbr ? Text::_('AUGUST_SHORT') : Text::_('AUGUST'); case 9: return $abbr ? Text::_('SEPTEMBER_SHORT') : Text::_('SEPTEMBER'); case 10: return $abbr ? Text::_('OCTOBER_SHORT') : Text::_('OCTOBER'); case 11: return $abbr ? Text::_('NOVEMBER_SHORT') : Text::_('NOVEMBER'); case 12: return $abbr ? Text::_('DECEMBER_SHORT') : Text::_('DECEMBER'); } }
/** * Validation and filtering * * @return boolean True if satisfactory * * @since 11.1 */ public function check() { // Set user id to null istead of 0, if needed if ($this->id === 0) { $this->id = null; } // Validate user information if (trim($this->name) == '') { $this->setError(Text::_('JLIB_DATABASE_ERROR_PLEASE_ENTER_YOUR_NAME')); return false; } if (trim($this->username) == '') { $this->setError(Text::_('JLIB_DATABASE_ERROR_PLEASE_ENTER_A_USER_NAME')); return false; } if (preg_match("#[<>\"'%;()&]#i", $this->username) || strlen(utf8_decode($this->username)) < 2) { $this->setError(Text::sprintf('JLIB_DATABASE_ERROR_VALID_AZ09', 2)); return false; } if (trim($this->email) == "" || !Helper::isEmailAddress($this->email)) { $this->setError(Text::_('JLIB_DATABASE_ERROR_VALID_MAIL')); return false; } // Set the registration timestamp if (empty($this->registerDate) || $this->registerDate == $this->_db->getNullDate()) { $this->registerDate = Factory::getDate()->toSql(); } // Set the lastvisitDate timestamp if (empty($this->lastvisitDate)) { $this->lastvisitDate = $this->_db->getNullDate(); } // Check for existing username $query = $this->_db->getQuery(true); $query->select($this->_db->quoteName('id')); $query->from($this->_db->quoteName('#__users')); $query->where($this->_db->quoteName('username') . ' = ' . $this->_db->quote($this->username)); $query->where($this->_db->quoteName('id') . ' != ' . (int) $this->id); $this->_db->setQuery($query); $xid = (int) $this->_db->loadResult(); if ($xid && $xid != (int) $this->id) { $this->setError(Text::_('JLIB_DATABASE_ERROR_USERNAME_INUSE')); return false; } // Check for existing email $query->clear(); $query->select($this->_db->quoteName('id')); $query->from($this->_db->quoteName('#__users')); $query->where($this->_db->quoteName('email') . ' = ' . $this->_db->quote($this->email)); $query->where($this->_db->quoteName('id') . ' != ' . (int) $this->id); $this->_db->setQuery($query); $xid = (int) $this->_db->loadResult(); if ($xid && $xid != (int) $this->id) { $this->setError(Text::_('JLIB_DATABASE_ERROR_EMAIL_INUSE')); return false; } // Check for root_user != username $config = Factory::getConfig(); $rootUser = $config->get('root_user'); if (!is_numeric($rootUser)) { $query->clear(); $query->select($this->_db->quoteName('id')); $query->from($this->_db->quoteName('#__users')); $query->where($this->_db->quoteName('username') . ' = ' . $this->_db->quote($rootUser)); $this->_db->setQuery($query); $xid = (int) $this->_db->loadResult(); if ($rootUser == $this->username && (!$xid || $xid && $xid != (int) $this->id) || $xid && $xid == (int) $this->id && $rootUser != $this->username) { $this->setError(Text::_('JLIB_DATABASE_ERROR_USERNAME_CANNOT_CHANGE')); return false; } } return true; }