/** * Compute the files to be included * * @param string $folder folder name to search into (images, css, js, ...) * @param string $file path to file * @param boolean $relative path to file is relative to /media folder * @param boolean $detect_browser detect browser to include specific browser files * @param boolean $detect_debug detect debug to include compressed files if debug is on * * @return array files to be included * * @see JBrowser * @since 11.1 */ protected static function includeRelativeFiles($folder, $file, $relative, $detect_browser, $detect_debug) { // If http is present in filename if (strpos($file, 'http') === 0) { $includes = array($file); } else { // Extract extension and strip the file $strip = File::stripExt($file); $ext = File::getExt($file); // Prepare array of files $includes = array(); // Detect browser and compute potential files if ($detect_browser) { $navigator = Browser::getInstance(); $browser = $navigator->getBrowser(); $major = $navigator->getMajor(); $minor = $navigator->getMinor(); // Try to include files named filename.ext, filename_browser.ext, filename_browser_major.ext, filename_browser_major_minor.ext // where major and minor are the browser version names $potential = array($strip, $strip . '_' . $browser, $strip . '_' . $browser . '_' . $major, $strip . '_' . $browser . '_' . $major . '_' . $minor); } else { $potential = array($strip); } // If relative search in template directory or media directory if ($relative) { // Get the template $app = Factory::getApplication(); $template = $app->getTemplate(); // For each potential files foreach ($potential as $strip) { $files = array(); // Detect debug mode if ($detect_debug && Factory::getConfig()->get('debug')) { /* * Detect if we received a file in the format name.min.ext * If so, strip the .min part out, otherwise append -uncompressed */ if (strrpos($strip, '.min', '-4')) { $position = strrpos($strip, '.min', '-4'); $filename = str_replace('.min', '.', $strip, $position); $files[] = $filename . $ext; } else { $files[] = $strip . '-uncompressed.' . $ext; } } $files[] = $strip . '.' . $ext; /* * Loop on 1 or 2 files and break on first found. * Add the content of the MD5SUM file located in the same folder to url to ensure cache browser refresh * This MD5SUM file must represent the signature of the folder content */ foreach ($files as $file) { // If the file is in the template folder $path = JPATH_THEMES . "/{$template}/{$folder}/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::base(true) . "/templates/{$template}/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } else { // If the file contains any /: it can be in an media extension subfolder if (strpos($file, '/')) { // Divide the file extracting the extension as the first part before / list($extension, $file) = explode('/', $file, 2); // If the file yet contains any /: it can be a plugin if (strpos($file, '/')) { // Divide the file extracting the element as the first part before / list($element, $file) = explode('/', $file, 2); // Try to deal with plugins group in the media folder $path = JPATH_ROOT . "/media/{$extension}/{$element}/{$folder}/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::root(true) . "/media/{$extension}/{$element}/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } // Try to deal with classical file in a a media subfolder called element $path = JPATH_ROOT . "/media/{$extension}/{$folder}/{$element}/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::root(true) . "/media/{$extension}/{$folder}/{$element}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } // Try to deal with system files in the template folder $path = JPATH_THEMES . "/{$template}/{$folder}/system/{$element}/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::root(true) . "/templates/{$template}/{$folder}/system/{$element}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } // Try to deal with system files in the media folder $path = JPATH_ROOT . "/media/system/{$folder}/{$element}/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::root(true) . "/media/system/{$folder}/{$element}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } } else { // Try to deals in the extension media folder $path = JPATH_ROOT . "/media/{$extension}/{$folder}/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::root(true) . "/media/{$extension}/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } // Try to deal with system files in the template folder $path = JPATH_THEMES . "/{$template}/{$folder}/system/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::root(true) . "/templates/{$template}/{$folder}/system/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } // Try to deal with system files in the media folder $path = JPATH_ROOT . "/media/system/{$folder}/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::root(true) . "/media/system/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } } } else { $path = JPATH_ROOT . "/media/system/{$folder}/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::root(true) . "/media/system/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } } } } } } else { foreach ($potential as $strip) { $files = array(); // Detect debug mode if ($detect_debug && Factory::getConfig()->get('debug')) { $files[] = $strip . '-uncompressed.' . $ext; } $files[] = $strip . '.' . $ext; /* * Loop on 1 or 2 files and break on first found. * Add the content of the MD5SUM file located in the same folder to url to ensure cache browser refresh * This MD5SUM file must represent the signature of the folder content */ foreach ($files as $file) { $path = JPATH_ROOT . "/{$file}"; if (file_exists($path)) { $md5 = dirname($path) . '/MD5SUM'; $includes[] = Uri::root(true) . "/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : ''); break; } } } } } return $includes; }
/** * Add unobtrusive javascript support for a color picker. * * @return void * * @since 11.2 */ public static function colorpicker() { // Only load once if (isset(self::$loaded[__METHOD__])) { return; } // Include MooTools framework self::framework(true); Html::_('stylesheet', 'system/mooRainbow.css', array('media' => 'all'), true); Html::_('script', 'system/mooRainbow.js', false, true); Factory::getDocument()->addScriptDeclaration("window.addEvent('domready', function(){\n\t\t\t\tvar nativeColorUi = false;\n\t\t\t\tif (Browser.opera && (Browser.version >= 11.5)) {\n\t\t\t\t\tnativeColorUi = true;\n\t\t\t\t}\n\t\t\t\t\$\$('.input-colorpicker').each(function(item){\n\t\t\t\t\tif (nativeColorUi) {\n\t\t\t\t\t\titem.type = 'color';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnew MooRainbow(item, {\n\t\t\t\t\t\t\tid: item.id,\n\t\t\t\t\t\t\timgPath: '" . Uri::root(true) . "/media/system/images/mooRainbow/',\n\t\t\t\t\t\t\tonComplete: function(color) {\n\t\t\t\t\t\t\t\tthis.element.value = color.hex;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tstartColor: item.value.hexToRgb(true) ? item.value.hexToRgb(true) : [0, 0, 0]\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t"); self::$loaded[__METHOD__] = true; }
/** * Method to apply an input filter to a value based on field data. * * @param string $element The XML element object representation of the form field. * @param mixed $value The value to filter for the field. * * @return mixed The filtered value. * * @since 1.0 */ protected function filterField($element, $value) { // Make sure there is a valid SimpleXMLElement. if (!$element instanceof \SimpleXMLElement) { return false; } // Get the field filter type. $filter = (string) $element['filter']; // Process the input value based on the filter. $return = null; switch (strtoupper($filter)) { // Do nothing, thus leaving the return value as null. case 'UNSET': break; // No Filter. // No Filter. case 'RAW': $return = $value; break; // Filter the input as an array of integers. // Filter the input as an array of integers. case 'INT_ARRAY': // Make sure the input is an array. if (is_object($value)) { $value = get_object_vars($value); } $value = is_array($value) ? $value : array($value); $value = ArrayHelper::toInteger($value); $return = $value; break; // Filter safe HTML. // Filter safe HTML. case 'SAFEHTML': $filterInput = new Filter\InputFilter(null, null, 1, 1); $return = $filterInput->clean($value, 'string'); break; // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See Rule\Url for list of these. // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See Rule\Url for list of these. case 'URL': if (empty($value)) { return false; } $filterInput = new Filter\InputFilter(); $value = $filterInput->clean($value, 'html'); $value = trim($value); // Check for a protocol $protocol = parse_url($value, PHP_URL_SCHEME); // If there is no protocol and the relative option is not specified, // we assume that it is an external URL and prepend http://. if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) { $protocol = 'http'; // If it looks like an internal link, then add the root. if (substr($value, 0) == 'index.php') { $value = Uri::root() . $value; } // Otherwise we treat it is an external link. // Put the url back together. $value = $protocol . '://' . $value; } elseif (!$protocol && $element['relative']) { $host = Uri::getInstance('SERVER')->gethost(); // If it starts with the host string, just prepend the protocol. if (substr($value, 0) == $host) { $value = 'http://' . $value; } else { $value = Uri::root() . $value; } } $return = $value; break; case 'TEL': $value = trim($value); // Does it match the NANP pattern? if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) { $number = (string) preg_replace('/[^\\d]/', '', $value); if (substr($number, 0, 1) == 1) { $number = substr($number, 1); } if (substr($number, 0, 2) == '+1') { $number = substr($number, 2); } $result = '1.' . $number; } elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) { $countrycode = substr($value, 0, strpos($value, ' ')); $countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode); $number = strstr($value, ' '); $number = (string) preg_replace('/[^\\d]/', '', $number); $result = $countrycode . '.' . $number; } elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) { if (strstr($value, 'x')) { $xpos = strpos($value, 'x'); $value = substr($value, 0, $xpos); } $result = str_replace('+', '', $value); } elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) { $result = $value; } else { $value = (string) preg_replace('/[^\\d]/', '', $value); if ($value != null && strlen($value) <= 15) { $length = strlen($value); // If it is fewer than 13 digits assume it is a local number if ($length <= 12) { $result = '.' . $value; } else { // If it has 13 or more digits let's make a country code. $cclen = $length - 12; $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen); } } else { $result = ''; } } $return = $result; break; default: // Check for a callback filter. if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) { $return = call_user_func(explode('::', $filter), $value); } elseif (function_exists($filter)) { $return = call_user_func($filter, $value); } else { $filterInput = new Filter\InputFilter(); $return = $filterInput->clean($value, $filter); } break; } return $return; }