Example #1
0
 public function render($cache = false, $params = array())
 {
     // If no error object is set return null
     if (!isset($this->_error)) {
         return;
     }
     // Set the status header
     MResponse::setHeader('status', $this->_error->getCode() . ' ' . str_replace("\n", ' ', $this->_error->getMessage()));
     $file = 'error.php';
     // Check template
     $directory = isset($params['directory']) ? $params['directory'] : 'templates';
     $template = isset($params['template']) ? MFilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';
     if (!file_exists($directory . '/' . $template . '/' . $file)) {
         $template = 'system';
     }
     // Set variables
     $this->baseurl = MURI::base(true);
     $this->template = $template;
     $this->debug = isset($params['debug']) ? $params['debug'] : false;
     $this->error = $this->_error;
     // Load
     $data = $this->_loadTemplate($directory . '/' . $template, $file);
     parent::render();
     return $data;
 }
Example #2
0
 public static function administrator($file, $folder = '/images/', $altFile = null, $altFolder = '/images/', $alt = null, $attribs = null, $asTag = true)
 {
     // Deprecation warning.
     MLog::add('MImage::administrator is deprecated.', MLog::WARNING, 'deprecated');
     $app = MFactory::getApplication();
     if (is_array($attribs)) {
         $attribs = MArrayHelper::toString($attribs);
     }
     $cur_template = $app->getTemplate();
     // Strip HTML.
     $alt = html_entity_decode($alt, ENT_COMPAT, 'UTF-8');
     if ($altFile) {
         $image = $altFolder . $altFile;
     } elseif ($altFile == -1) {
         $image = '';
     } else {
         if (file_exists(MPATH_ADMINISTRATOR . '/templates/' . $cur_template . '/images/' . $file)) {
             $image = 'templates/' . $cur_template . '/images/' . $file;
         } else {
             // Compatibility with previous versions.
             if (substr($folder, 0, 14) == "/administrator") {
                 $image = substr($folder, 15) . $file;
             } else {
                 $image = $folder . $file;
             }
         }
     }
     if (substr($image, 0, 1) == "/") {
         $image = substr_replace($image, '', 0, 1);
     }
     // Prepend the base path.
     $image = MURI::base(true) . '/' . $image;
     // Outputs actual HTML <img> tag.
     if ($asTag) {
         $image = '<img src="' . $image . '" alt="' . $alt . '" ' . $attribs . ' />';
     }
     return $image;
 }
Example #3
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)) {
         // Access Control Rules.
         case 'RULES':
             $return = array();
             foreach ((array) $value as $action => $ids) {
                 // Build the rules array.
                 $return[$action] = array();
                 foreach ($ids as $id => $p) {
                     if ($p !== '') {
                         $return[$action][$id] = $p == '1' || $p == 'true' ? true : false;
                     }
                 }
             }
             break;
             // Do nothing, thus leaving the return value as null.
         // 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);
             MArrayHelper::toInteger($value);
             $return = $value;
             break;
             // Filter safe HTML.
         // Filter safe HTML.
         case 'SAFEHTML':
             $return = MFilterInput::getInstance(null, null, 1, 1)->clean($value, 'string');
             break;
             // Convert a date to UTC based on the server timezone offset.
         // Convert a date to UTC based on the server timezone offset.
         case 'SERVER_UTC':
             if (intval($value) > 0) {
                 // Get the server timezone setting.
                 $offset = MFactory::getConfig()->get('offset');
                 // Return an SQL formatted datetime string in UTC.
                 $return = MFactory::getDate($value, $offset)->toSql();
             } else {
                 $return = '';
             }
             break;
             // Convert a date to UTC based on the user timezone offset.
         // Convert a date to UTC based on the user timezone offset.
         case 'USER_UTC':
             if (intval($value) > 0) {
                 // Get the user timezone setting defaulting to the server timezone setting.
                 $offset = MFactory::getUser()->getParam('timezone', MFactory::getConfig()->get('offset'));
                 // Return a MySQL formatted datetime string in UTC.
                 $return = MFactory::getDate($value, $offset)->toSql();
             } else {
                 $return = '';
             }
             break;
             // Ensures a protocol is present in the saved field. Only use when
             // the only permitted protocols requre '://'. See MFormRuleUrl for list of these.
         // Ensures a protocol is present in the saved field. Only use when
         // the only permitted protocols requre '://'. See MFormRuleUrl for list of these.
         case 'URL':
             if (empty($value)) {
                 return false;
             }
             $value = MFilterInput::getInstance()->clean($value, 'html');
             $value = trim($value);
             // <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt.
             $value = str_replace(array('<', '>', '"'), '', $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 = MURI::root() . $value;
                 }
                 // Otherwise we treat it is an external link.
                 // Put the url back together.
                 $value = $protocol . '://' . $value;
             } elseif (!$protocol && $element['relative']) {
                 $host = MURI::getInstance('SERVER')->gethost();
                 // If it starts with the host string, just prepend the protocol.
                 if (substr($value, 0) == $host) {
                     $value = 'http://' . $value;
                 } else {
                     $value = MURI::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 {
                 $return = MFilterInput::getInstance()->clean($value, $filter);
             }
             break;
     }
     return $return;
 }
Example #4
0
 protected function getInput()
 {
     $assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
     $authorField = $this->element['created_by_field'] ? (string) $this->element['created_by_field'] : 'created_by';
     $asset = $this->form->getValue($assetField) ? $this->form->getValue($assetField) : (string) $this->element['asset_id'];
     if ($asset == '') {
         $asset = MRequest::getCmd('option');
     }
     $link = (string) $this->element['link'];
     if (!self::$initialised) {
         // Load the modal behavior script.
         MHtml::_('behavior.modal');
         // Build the script.
         $script = array();
         $script[] = '	function jInsertFieldValue(value, id) {';
         $script[] = '		var old_value = document.id(id).value;';
         $script[] = '		if (old_value != value) {';
         $script[] = '			var elem = document.id(id);';
         $script[] = '			elem.value = value;';
         $script[] = '			elem.fireEvent("change");';
         $script[] = '			if (typeof(elem.onchange) === "function") {';
         $script[] = '				elem.onchange();';
         $script[] = '			}';
         $script[] = '			jMediaRefreshPreview(id);';
         $script[] = '		}';
         $script[] = '	}';
         $script[] = '	function jMediaRefreshPreview(id) {';
         $script[] = '		var value = document.id(id).value;';
         $script[] = '		var img = document.id(id + "_preview");';
         $script[] = '		if (img) {';
         $script[] = '			if (value) {';
         $script[] = '				img.src = "' . MURI::root() . '" + value;';
         $script[] = '				document.id(id + "_preview_empty").setStyle("display", "none");';
         $script[] = '				document.id(id + "_preview_img").setStyle("display", "");';
         $script[] = '			} else { ';
         $script[] = '				img.src = ""';
         $script[] = '				document.id(id + "_preview_empty").setStyle("display", "");';
         $script[] = '				document.id(id + "_preview_img").setStyle("display", "none");';
         $script[] = '			} ';
         $script[] = '		} ';
         $script[] = '	}';
         $script[] = '	function jMediaRefreshPreviewTip(tip)';
         $script[] = '	{';
         $script[] = '		tip.setStyle("display", "block");';
         $script[] = '		var img = tip.getElement("img.media-preview");';
         $script[] = '		var id = img.getProperty("id");';
         $script[] = '		id = id.substring(0, id.length - "_preview".length);';
         $script[] = '		jMediaRefreshPreview(id);';
         $script[] = '	}';
         // Add the script to the document head.
         MFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
         self::$initialised = true;
     }
     // Initialize variables.
     $html = array();
     $attr = '';
     // Initialize some field attributes.
     $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
     $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
     // Initialize JavaScript field attributes.
     $attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
     // The text field.
     $html[] = '<div class="fltlft">';
     $html[] = '	<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . ' readonly="readonly"' . $attr . ' />';
     $html[] = '</div>';
     $directory = (string) $this->element['directory'];
     if ($this->value && file_exists(MPATH_ROOT . '/' . $this->value)) {
         $folder = explode('/', $this->value);
         array_shift($folder);
         array_pop($folder);
         $folder = implode('/', $folder);
     } elseif (file_exists(MPATH_ROOT . '/' . MComponentHelper::getParams('com_media')->get('image_path', 'images') . '/' . $directory)) {
         $folder = $directory;
     } else {
         $folder = '';
     }
     // The button.
     $html[] = '<div class="button2-left">';
     $html[] = '	<div class="blank">';
     $html[] = '		<a class="modal" title="' . MText::_('MLIB_FORM_BUTTON_SELECT') . '"' . ' href="' . ($this->element['readonly'] ? '' : ($link ? $link : 'index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=' . $asset . '&amp;author=' . $this->form->getValue($authorField)) . '&amp;fieldid=' . $this->id . '&amp;folder=' . $folder) . '"' . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">';
     $html[] = MText::_('MLIB_FORM_BUTTON_SELECT') . '</a>';
     $html[] = '	</div>';
     $html[] = '</div>';
     $html[] = '<div class="button2-left">';
     $html[] = '	<div class="blank">';
     $html[] = '		<a title="' . MText::_('MLIB_FORM_BUTTON_CLEAR') . '"' . ' href="#" onclick="';
     $html[] = 'jInsertFieldValue(\'\', \'' . $this->id . '\');';
     $html[] = 'return false;';
     $html[] = '">';
     $html[] = MText::_('MLIB_FORM_BUTTON_CLEAR') . '</a>';
     $html[] = '	</div>';
     $html[] = '</div>';
     // The Preview.
     $preview = (string) $this->element['preview'];
     $showPreview = true;
     $showAsTooltip = false;
     switch ($preview) {
         case 'false':
         case 'none':
             $showPreview = false;
             break;
         case 'true':
         case 'show':
             break;
         case 'tooltip':
         default:
             $showAsTooltip = true;
             $options = array('onShow' => 'jMediaRefreshPreviewTip');
             MHtml::_('behavior.tooltip', '.hasTipPreview', $options);
             break;
     }
     if ($showPreview) {
         if ($this->value && file_exists(MPATH_ROOT . '/' . $this->value)) {
             $src = MURI::root() . $this->value;
         } else {
             $src = '';
         }
         $attr = array('id' => $this->id . '_preview', 'class' => 'media-preview', 'style' => 'max-width:160px; max-height:100px;');
         $img = MHtml::image($src, MText::_('MLIB_FORM_MEDIA_PREVIEW_ALT'), $attr);
         $previewImg = '<div id="' . $this->id . '_preview_img"' . ($src ? '' : ' style="display:none"') . '>' . $img . '</div>';
         $previewImgEmpty = '<div id="' . $this->id . '_preview_empty"' . ($src ? ' style="display:none"' : '') . '>' . MText::_('MLIB_FORM_MEDIA_PREVIEW_EMPTY') . '</div>';
         $html[] = '<div class="media-preview fltlft">';
         if ($showAsTooltip) {
             $tooltip = $previewImgEmpty . $previewImg;
             $options = array('title' => MText::_('MLIB_FORM_MEDIA_PREVIEW_SELECTED_IMAGE'), 'text' => MText::_('MLIB_FORM_MEDIA_PREVIEW_TIP_TITLE'), 'class' => 'hasTipPreview');
             $html[] = MHtml::tooltip($tooltip, $options);
         } else {
             $html[] = ' ' . $previewImgEmpty;
             $html[] = ' ' . $previewImg;
         }
         $html[] = '</div>';
     }
     return implode("\n", $html);
 }
Example #5
0
 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 = MFile::stripExt($file);
         $ext = MFile::getExt($file);
         // Detect browser and compute potential files
         if ($detect_browser) {
             $navigator = MBrowser::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 = MFactory::getApplication();
             $template = $app->getTemplate();
             // Prepare array of files
             $includes = array();
             // For each potential files
             foreach ($potential as $strip) {
                 $files = array();
                 // Detect debug mode
                 if ($detect_debug && MFactory::getConfig()->get('debug')) {
                     $files[] = $strip . '-uncompressed.' . $ext;
                 }
                 $files[] = $strip . '.' . $ext;
                 // Loop on 1 or 2 files and break on first found
                 foreach ($files as $file) {
                     // If the file is in the template folder
                     if (file_exists(MPATH_THEMES . "/{$template}/{$folder}/{$file}")) {
                         $includes[] = MURI::base(true) . "/templates/{$template}/{$folder}/{$file}";
                         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
                                 if (file_exists(MPATH_ROOT . "/media/{$extension}/{$element}/{$folder}/{$file}")) {
                                     $includes[] = MURL_WP_CNT . "/miwi/media/{$extension}/{$element}/{$folder}/{$file}";
                                     break;
                                 } elseif (file_exists(MPATH_ROOT . "/media/{$extension}/{$folder}/{$element}/{$file}")) {
                                     $includes[] = MURL_WP_CNT . "/miwi/media/{$extension}/{$folder}/{$element}/{$file}";
                                     break;
                                 } elseif (file_exists(MPATH_THEMES . "/{$template}/{$folder}/system/{$element}/{$file}")) {
                                     $includes[] = MURL_WP_CNT . "/miwi/templates/{$template}/{$folder}/system/{$element}/{$file}";
                                     break;
                                 } elseif (file_exists(MPATH_ROOT . "/media/system/{$folder}/{$element}/{$file}")) {
                                     $includes[] = MURL_WP_CNT . "/miwi/media/system/{$folder}/{$element}/{$file}";
                                     break;
                                 }
                             } elseif (file_exists(MPATH_ROOT . "/media/{$extension}/{$folder}/{$file}")) {
                                 $includes[] = MURL_WP_CNT . "/miwi/media/{$extension}/{$folder}/{$file}";
                                 break;
                             } elseif (file_exists(MPATH_THEMES . "/{$template}/{$folder}/system/{$file}")) {
                                 $includes[] = MURL_WP_CNT . "/miwi/templates/{$template}/{$folder}/system/{$file}";
                                 break;
                             } elseif (file_exists(MPATH_ROOT . "/media/system/{$folder}/{$file}")) {
                                 $includes[] = MURL_WP_CNT . "/miwi/media/system/{$folder}/{$file}";
                                 break;
                             }
                         } elseif (file_exists(MPATH_ROOT . "/media/system/{$folder}/{$file}")) {
                             $includes[] = MURL_WP_CNT . "/miwi/media/system/{$folder}/{$file}";
                             break;
                         }
                     }
                 }
             }
         } else {
             $includes = array();
             foreach ($potential as $strip) {
                 // Detect debug mode
                 if ($detect_debug && MFactory::getConfig()->get('debug') && file_exists(MPATH_ROOT . "/{$strip}-uncompressed.{$ext}")) {
                     $includes[] = MURI::root(false) . "/{$strip}-uncompressed.{$ext}";
                 } elseif (file_exists(MPATH_ROOT . "/{$strip}.{$ext}")) {
                     $includes[] = MURI::root(false) . "/{$strip}.{$ext}";
                 }
             }
         }
     }
     return $includes;
 }