Пример #1
0
 /**
  * Detect is this page are frontpage?
  *
  * @return  boolean Is frontpage?
  */
 public static function isHome()
 {
     $langPath = null;
     $tag = null;
     $lang = \JFactory::getLanguage();
     // For multi language
     if (\JPluginHelper::isEnabled('system', 'languagefilter')) {
         $tag = $lang->getTag();
         $langCodes = \JLanguageHelper::getLanguages('lang_code');
         $langPath = $langCodes[$tag]->sef;
     }
     $uri = \JUri::getInstance();
     $root = $uri::root(true);
     // Get site route
     $route = StringHelper::substr($uri->getPath(), StringHelper::strlen($root));
     // Remove index.php
     $route = str_replace('index.php', '', $route);
     // If Multiple language enabled, we check first part of URI is language code or not.
     if ($langPath) {
         $params = ExtensionHelper::getParams('plg_system_languagefilter');
         if ($tag == $lang->getDefault() && $params->get('remove_default_prefix', 0)) {
             $langPath = '';
         }
         // If route equals lang path, means it is home route.
         if (trim($route, '/') == $langPath && !$uri->getVar('option')) {
             return true;
         }
     } else {
         if (!trim($route, '/') && !$uri->getVar('option')) {
             return true;
         }
     }
     return false;
 }
Пример #2
0
 /**
  * Method to test for a banned subject
  *
  * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  * @param   mixed             $value    The form field value to validate.
  * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  *                                      For example if the field has name="foo" and the group value is set to "bar" then the
  *                                      full field name would end up being "bar[foo]".
  * @param   Registry          $input    An optional Registry object with the entire data set to validate against the entire form.
  * @param   JForm             $form     The form object for which the field is being tested.
  *
  * @return  boolean  True if the value is valid, false otherwise
  */
 public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, JForm $form = null)
 {
     $params = JComponentHelper::getParams('com_contact');
     $banned = $params->get('banned_subject');
     if ($banned) {
         foreach (explode(';', $banned) as $item) {
             if ($item != '' && StringHelper::stristr($value, $item) !== false) {
                 return false;
             }
         }
     }
     return true;
 }
Пример #3
0
 /**
  * Method to get a DatabaseQuery object for retrieving the data set from a database.
  *
  * @return  DatabaseQuery  A DatabaseQuery object to retrieve the data set.
  *
  * @since   1.0
  */
 protected function getListQuery()
 {
     $db = $this->getDb();
     $query = $db->getQuery(true);
     $query->select(array('id', 'username'));
     $query->from('#__users');
     $filter = $this->state->get('filter.search-user');
     if ($filter) {
         // Clean filter variable
         $filter = $db->quote('%' . $db->escape(StringHelper::strtolower($filter), true) . '%', false);
         $query->where($db->quoteName('username') . ' LIKE ' . $filter);
     }
     return $query;
 }
Пример #4
0
 /**
  * setMeta
  *
  * @param object $article
  *
  * @return  void
  */
 public static function setMeta($article)
 {
     $app = \JFactory::getApplication();
     if ($app->isAdmin()) {
         return;
     }
     if (!static::$firstArticle) {
         return;
     }
     $config = \JFactory::getConfig();
     $ezset = \Ezset::getInstance();
     // Get menu meta, if nonexists, use article meta
     if (isset($article->params) && $article->params instanceof \JRegistry && isset($article->metadesc)) {
         $ezset->data->metaDesc = $article->params->get('menu-meta_description', $article->metadesc);
     }
     if (\Ezset::isHome()) {
         $ezset->data->metaDesc = $config->get('MetaDesc');
     } elseif (!$ezset->data->metaDesc) {
         // Get meta from article content
         $metaDesc = $article->text;
         // Remove script tags
         $metaDesc = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $metaDesc);
         $metaDesc = preg_replace('#<style(.*?)>(.*?)</style>#is', '', $metaDesc);
         $metaDesc = strip_tags($metaDesc);
         // Filter plugin like:{rsform 1}
         $metaDesc = preg_replace('/\\{.*\\}/', '', $metaDesc);
         // Remove line
         $metaDesc = str_replace("\r\n", '', $metaDesc);
         $metaDesc = str_replace("&nbsp;", '', $metaDesc);
         $metaDesc = trim($metaDesc);
         $metaDesc = StringHelper::substr($metaDesc, 0, $ezset->params->get('maxMetaChar', 250));
         // Remove latest word
         $metaDesc = trim($metaDesc);
         $metaDesc = explode(' ', $metaDesc);
         $latestWord = array_pop($metaDesc);
         if (strlen($latestWord) > 10) {
             $metaDesc[] = $latestWord;
         }
         // Rebuild paragraph
         $metaDesc = implode(' ', $metaDesc);
         $ezset->data->metaDesc = $metaDesc;
         // Find category name
         if (property_exists($article, 'catid')) {
             $category = \JTable::getInstance('Category');
             $category->load($article->catid);
             $ezset->data->catName = $category->title;
         }
     }
     static::$firstArticle = false;
 }
	/**
	 * Method to test the value.
	 *
	 * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
	 * @param   mixed             $value    The form field value to validate.
	 * @param   string            $group    The field name group control value. This acts as as an array container for the field.
	 *                                      For example if the field has name="foo" and the group value is set to "bar" then the
	 *                                      full field name would end up being "bar[foo]".
	 * @param   Registry          $input    An optional JRegistry object with the entire data set to validate against the entire form.
	 * @param   JForm             $form     The form object for which the field is being tested.
	 *
	 * @return  boolean  True if the value is valid, false otherwise.
	 *
	 * @since    1.5
	 */
	public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, JForm $form = null)
	{
		$params = JComponentHelper::getParams('com_churchdirectory');
		$banned = $params->get('banned_subject');

		foreach (explode(';', $banned) as $item)
		{
			if (\Joomla\String\StringHelper::stristr($item, $value) !== false)
			{
				return false;
			}
		}

		return true;
	}
Пример #6
0
 /**
  * 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
  * @param   string  $language  Language to transilterate to
  *
  * @return  string  Processed string
  *
  * @since   11.1
  */
 public static function stringURLSafe($string, $language = '')
 {
     // Remove any '-' from the string since they will be used as concatenaters
     $str = str_replace('-', ' ', $string);
     // Transliterate on the language requested (fallback to current language if not specified)
     $lang = $language == '' || $language == '*' ? JFactory::getLanguage() : JLanguage::getInstance($language);
     $str = $lang->transliterate($str);
     // Trim white spaces at beginning and end of alias and make lowercase
     $str = trim(StringHelper::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;
 }
Пример #7
0
 /**
  * Overloaded check method to ensure data integrity.
  *
  * @return  boolean  True on success.
  */
 public function check()
 {
     // Check for valid name.
     if (trim($this->name) == '') {
         $this->setError(JText::_('COM_NEWSFEEDS_WARNING_PROVIDE_VALID_NAME'));
         return false;
     }
     if (empty($this->alias)) {
         $this->alias = $this->name;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     // Check the publish down date is not earlier than publish up.
     if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) {
         $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
         return false;
     }
     // Clean up keywords -- eliminate extra spaces between phrases
     // and cr (\r) and lf (\n) characters from string if not empty
     if (!empty($this->metakey)) {
         // Array of characters to remove
         $bad_characters = array("\n", "\r", "\"", "<", ">");
         // Remove bad characters
         $after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);
         // Create array using commas as delimiter
         $keys = explode(',', $after_clean);
         $clean_keys = array();
         foreach ($keys as $key) {
             if (trim($key)) {
                 // Ignore blank keywords
                 $clean_keys[] = trim($key);
             }
         }
         // Put array back together delimited by ", "
         $this->metakey = implode(", ", $clean_keys);
     }
     // Clean up description -- eliminate quotes and <> brackets
     if (!empty($this->metadesc)) {
         // Only process if not empty
         $bad_characters = array("\"", "<", ">");
         $this->metadesc = StringHelper::str_ireplace($bad_characters, "", $this->metadesc);
     }
     return true;
 }
	/**
	 * Method to test the email address and optionally check for uniqueness.
	 *
	 * @param   SimpleXMLElement  &$element  The SimpleXMLElement object representing the <field /> tag for the form field object.
	 * @param   mixed             $value     The form field value to validate.
	 * @param   string            $group     The field name group control value. This acts as as an array container for the field.
	 *                                       For example if the field has name="foo" and the group value is set to "bar" then the
	 *                                       full field name would end up being "bar[foo]".
	 * @param   JRegistry         &$input    An optional JRegistry object with the entire data set to validate against the entire form.
	 * @param   JForm             &$form     The form object for which the field is being tested.
	 *
	 * @return  boolean  True if the value is valid, false otherwise.
	 *
	 * @since    1.5
	 */
	public function test(& $element, $value, $group = null, &$input = null, &$form = null)
	{
		if (!parent::test($element, $value, $group, $input, $form))
		{
			return false;
		}

		$params = JComponentHelper::getParams('com_churchdirectory');
		$banned = $params->get('banned_email');

		foreach (explode(';', $banned) as $item)
		{
			if (\Joomla\String\StringHelper::stristr($item, $value) !== false)
			{
				return false;
			}
		}

		return true;
	}
Пример #9
0
 /**
  * Returns an array of options
  *
  * @param   string   $query  SQL with 'ordering' AS value and 'name field' AS text
  * @param   integer  $chop   The length of the truncated headline
  *
  * @return  array  An array of objects formatted for JHtml list processing
  *
  * @since   1.5
  */
 public static function genericordering($query, $chop = 30)
 {
     $db = JFactory::getDbo();
     $options = array();
     $db->setQuery($query);
     $items = $db->loadObjectList();
     if (empty($items)) {
         $options[] = JHtml::_('select.option', 1, JText::_('JOPTION_ORDER_FIRST'));
         return $options;
     }
     $options[] = JHtml::_('select.option', 0, '0 ' . JText::_('JOPTION_ORDER_FIRST'));
     for ($i = 0, $n = count($items); $i < $n; $i++) {
         $items[$i]->text = JText::_($items[$i]->text);
         if (StringHelper::strlen($items[$i]->text) > $chop) {
             $text = StringHelper::substr($items[$i]->text, 0, $chop) . "...";
         } else {
             $text = $items[$i]->text;
         }
         $options[] = JHtml::_('select.option', $items[$i]->value, $items[$i]->value . '. ' . $text);
     }
     $options[] = JHtml::_('select.option', $items[$i - 1]->value + 1, $items[$i - 1]->value + 1 . ' ' . JText::_('JOPTION_ORDER_LAST'));
     return $options;
 }
Пример #10
0
 /**
  * Method to change the title & alias.
  *
  * @param   integer  $category_id  The id of the parent.
  * @param   string   $alias        The alias.
  * @param   string   $name         The title.
  *
  * @return  array  Contains the modified title and alias.
  *
  * @since   3.1
  */
 protected function generateNewTitle($category_id, $alias, $name)
 {
     // Alter the title & alias
     $table = $this->getTable();
     while ($table->load(array('alias' => $alias, 'catid' => $category_id))) {
         if ($name == $table->name) {
             $name = StringHelper::increment($name);
         }
         $alias = StringHelper::increment($alias, 'dash');
     }
     return array($name, $alias);
 }
Пример #11
0
 /**
  * Sets an inflected word in the cache.
  *
  * @param   string  $singular  The singular form of the word.
  * @param   string  $plural    The plural form of the word. If omitted, it is assumed the singular and plural are identical.
  *
  * @return  void
  *
  * @since   1.0
  */
 private function setCache($singular, $plural = null)
 {
     $singular = StringHelper::strtolower($singular);
     if ($plural === null) {
         $plural = $singular;
     } else {
         $plural = StringHelper::strtolower($plural);
     }
     $this->cache[$singular] = $plural;
 }
Пример #12
0
 /**
  * Method to change the title & alias.
  *
  * @param   integer  $parent_id  The id of the parent.
  * @param   string   $alias      The alias.
  * @param   string   $title      The title.
  *
  * @return  array    Contains the modified title and alias.
  *
  * @since   1.7
  */
 protected function generateNewTitle($parent_id, $alias, $title)
 {
     // Alter the title & alias
     $table = $this->getTable();
     while ($table->load(array('alias' => $alias, 'parent_id' => $parent_id))) {
         $title = StringHelper::increment($title);
         $alias = StringHelper::increment($alias, 'dash');
     }
     return array($title, $alias);
 }
Пример #13
0
 /**
  * Function to convert a sef route to an internal URI
  *
  * @param   JUri  &$uri  The sef URI
  *
  * @return  string  Internal URI
  *
  * @since   3.2
  * @deprecated  4.0  Attach your logic as rule to the main parse stage
  */
 protected function parseSefRoute(&$uri)
 {
     $route = $uri->getPath();
     // Remove the suffix
     if ($this->app->get('sef_suffix')) {
         if ($suffix = pathinfo($route, PATHINFO_EXTENSION)) {
             $route = str_replace('.' . $suffix, '', $route);
         }
     }
     // Get the variables from the uri
     $vars = $uri->getQuery(true);
     // Handle an empty URL (special case)
     if (empty($route)) {
         // If route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately
         if (isset($vars['option']) || isset($vars['Itemid'])) {
             return $this->parseRawRoute($uri);
         }
         $item = $this->menu->getDefault($this->app->getLanguage()->getTag());
         // If user not allowed to see default menu item then avoid notices
         if (is_object($item)) {
             // Set the information in the request
             $vars = $item->query;
             // Get the itemid
             $vars['Itemid'] = $item->id;
             // Set the active menu item
             $this->menu->setActive($vars['Itemid']);
             $this->setVars($vars);
         }
         return $vars;
     }
     // Parse the application route
     $segments = explode('/', $route);
     if (count($segments) > 1 && $segments[0] == 'component') {
         $vars['option'] = 'com_' . $segments[1];
         $vars['Itemid'] = null;
         $route = implode('/', array_slice($segments, 2));
     } else {
         // Get menu items.
         $items = $this->menu->getMenu();
         $found = false;
         $route_lowercase = StringHelper::strtolower($route);
         $lang_tag = $this->app->getLanguage()->getTag();
         // Iterate through all items and check route matches.
         foreach ($items as $item) {
             if ($item->route && StringHelper::strpos($route_lowercase . '/', $item->route . '/') === 0 && $item->type != 'menulink') {
                 // Usual method for non-multilingual site.
                 if (!$this->app->getLanguageFilter()) {
                     // Exact route match. We can break iteration because exact item was found.
                     if ($item->route == $route_lowercase) {
                         $found = $item;
                         break;
                     }
                     // Partial route match. Item with highest level takes priority.
                     if (!$found || $found->level < $item->level) {
                         $found = $item;
                     }
                 } elseif ($item->language == '*' || $item->language == $lang_tag) {
                     // Exact route match.
                     if ($item->route == $route_lowercase) {
                         $found = $item;
                         // Break iteration only if language is matched.
                         if ($item->language == $lang_tag) {
                             break;
                         }
                     }
                     // Partial route match. Item with highest level or same language takes priority.
                     if (!$found || $found->level < $item->level || $item->language == $lang_tag) {
                         $found = $item;
                     }
                 }
             }
         }
         if (!$found) {
             $found = $this->menu->getDefault($lang_tag);
         } else {
             $route = substr($route, strlen($found->route));
             if ($route) {
                 $route = substr($route, 1);
             }
         }
         if ($found) {
             $vars['Itemid'] = $found->id;
             $vars['option'] = $found->component;
         }
     }
     // Set the active menu item
     if (isset($vars['Itemid'])) {
         $this->menu->setActive($vars['Itemid']);
     }
     // Set the variables
     $this->setVars($vars);
     // Parse the component route
     if (!empty($route) && isset($this->_vars['option'])) {
         $segments = explode('/', $route);
         if (empty($segments[0])) {
             array_shift($segments);
         }
         // Handle component route
         $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->_vars['option']);
         if (count($segments)) {
             $crouter = $this->getComponentRouter($component);
             $vars = $crouter->parse($segments);
             $this->setVars($vars);
         }
     } else {
         // Set active menu item
         if ($item = $this->menu->getActive()) {
             $vars = $item->query;
         }
     }
     return $vars;
 }
Пример #14
0
 /**
  * Transliterate function
  *
  * This method processes a string and replaces all accented UTF-8 characters by unaccented
  * ASCII-7 "equivalents".
  *
  * @param   string  $string  The string to transliterate.
  *
  * @return  string  The transliteration of the string.
  *
  * @since   11.1
  */
 public function transliterate($string)
 {
     if ($this->transliterator !== null) {
         return call_user_func($this->transliterator, $string);
     }
     $string = JLanguageTransliterate::utf8_latin_to_ascii($string);
     $string = StringHelper::strtolower($string);
     return $string;
 }
Пример #15
0
 /**
  * Overloaded check function
  *
  * @return  boolean  True on success, false on failure
  *
  * @see     JTable::check()
  * @since   3.1
  */
 public function check()
 {
     if (trim($this->core_title) == '') {
         $this->setError(JText::_('JLIB_CMS_WARNING_PROVIDE_VALID_NAME'));
         return false;
     }
     if (trim($this->core_alias) == '') {
         $this->core_alias = $this->core_title;
     }
     $this->core_alias = JApplicationHelper::stringURLSafe($this->core_alias);
     if (trim(str_replace('-', '', $this->core_alias)) == '') {
         $this->core_alias = JFactory::getDate()->format('Y-m-d-H-i-s');
     }
     // Not Null sanity check
     if (empty($this->core_images)) {
         $this->core_images = '{}';
     }
     if (empty($this->core_urls)) {
         $this->core_urls = '{}';
     }
     // Check the publish down date is not earlier than publish up.
     if ($this->core_publish_down > $this->_db->getNullDate() && $this->core_publish_down < $this->core_publish_up) {
         // Swap the dates.
         $temp = $this->core_publish_up;
         $this->core_publish_up = $this->core_publish_down;
         $this->core_publish_down = $temp;
     }
     // Clean up keywords -- eliminate extra spaces between phrases
     // and cr (\r) and lf (\n) characters from string
     if (!empty($this->core_metakey)) {
         // Only process if not empty
         // Array of characters to remove
         $bad_characters = array("\n", "\r", "\"", "<", ">");
         // Remove bad characters
         $after_clean = StringHelper::str_ireplace($bad_characters, "", $this->core_metakey);
         // Create array using commas as delimiter
         $keys = explode(',', $after_clean);
         $clean_keys = array();
         foreach ($keys as $key) {
             if (trim($key)) {
                 // Ignore blank keywords
                 $clean_keys[] = trim($key);
             }
         }
         // Put array back together delimited by ", "
         $this->core_metakey = implode(", ", $clean_keys);
     }
     return true;
 }
Пример #16
0
 /**
  * Method to construct the token object.
  *
  * @param   mixed   $term    The term as a string for words or an array for phrases.
  * @param   string  $lang    The simple language identifier.
  * @param   string  $spacer  The space separator for phrases. [optional]
  *
  * @since   2.5
  */
 public function __construct($term, $lang, $spacer = ' ')
 {
     $this->language = $lang;
     // Tokens can be a single word or an array of words representing a phrase.
     if (is_array($term)) {
         // Populate the token instance.
         $this->term = implode($spacer, $term);
         $this->stem = implode($spacer, array_map(array('FinderIndexerHelper', 'stem'), $term, array($lang)));
         $this->numeric = false;
         $this->common = false;
         $this->phrase = true;
         $this->length = StringHelper::strlen($this->term);
         /*
          * Calculate the weight of the token.
          *
          * 1. Length of the token up to 30 and divide by 30, add 1.
          * 2. Round weight to 4 decimal points.
          */
         $this->weight = ($this->length >= 30 ? 30 : $this->length) / 30 + 1;
         $this->weight = round($this->weight, 4);
     } else {
         // Populate the token instance.
         $this->term = $term;
         $this->stem = FinderIndexerHelper::stem($this->term, $lang);
         $this->numeric = is_numeric($this->term) || (bool) preg_match('#^[0-9,.\\-\\+]+$#', $this->term);
         $this->common = $this->numeric ? false : FinderIndexerHelper::isCommon($this->term, $lang);
         $this->phrase = false;
         $this->length = StringHelper::strlen($this->term);
         /*
          * Calculate the weight of the token.
          *
          * 1. Length of the token up to 15 and divide by 15.
          * 2. If common term, divide weight by 8.
          * 3. If numeric, multiply weight by 1.5.
          * 4. Round weight to 4 decimal points.
          */
         $this->weight = ($this->length >= 15 ? 15 : $this->length) / 15;
         $this->weight = $this->common == true ? $this->weight / 8 : $this->weight;
         $this->weight = $this->numeric == true ? $this->weight * 1.5 : $this->weight;
         $this->weight = round($this->weight, 4);
     }
 }
Пример #17
0
 /**
  * Cloak all emails in text from spambots via Javascript.
  *
  * @param   string  &$text    The string to be cloaked.
  * @param   mixed   &$params  Additional parameters. Parameter "mode" (integer, default 1)
  *                             replaces addresses with "mailto:" links if nonzero.
  *
  * @return  boolean  True on success.
  */
 protected function _cloak(&$text, &$params)
 {
     /*
      * Check for presence of {emailcloak=off} which is explicits disables this
      * bot for the item.
      */
     if (StringHelper::strpos($text, '{emailcloak=off}') !== false) {
         $text = StringHelper::str_ireplace('{emailcloak=off}', '', $text);
         return true;
     }
     // Simple performance check to determine whether bot should process further.
     if (StringHelper::strpos($text, '@') === false) {
         return true;
     }
     $mode = $this->params->def('mode', 1);
     // Example: any@example.org
     $searchEmail = '([\\w\\.\\-\\+]+\\@(?:[a-z0-9\\.\\-]+\\.)+(?:[a-zA-Z0-9\\-]{2,10}))';
     // Example: any@example.org?subject=anyText
     $searchEmailLink = $searchEmail . '([?&][\\x20-\\x7f][^"<>]+)';
     // Any Text
     $searchText = '((?:[\\x20-\\x7f]|[\\xA1-\\xFF]|[\\xC2-\\xDF][\\x80-\\xBF]|[\\xE0-\\xEF][\\x80-\\xBF]{2}|[\\xF0-\\xF4][\\x80-\\xBF]{3})[^<>]+)';
     // Any Image link
     $searchImage = "(<img[^>]+>)";
     // Any Text with <span or <strong
     $searchTextSpan = '(<span[^>]+>|<span>|<strong>|<strong><span[^>]+>|<strong><span>)' . $searchText . '(</span>|</strong>|</span></strong>)';
     // Any address with <span or <strong
     $searchEmailSpan = '(<span[^>]+>|<span>|<strong>|<strong><span[^>]+>|<strong><span>)' . $searchEmail . '(</span>|</strong>|</span></strong>)';
     /*
      * Search and fix derivatives of link code <a href="http://mce_host/ourdirectory/email@example.org"
      * >email@example.org</a>. This happens when inserting an email in TinyMCE, cancelling its suggestion to add
      * the mailto: prefix...
      */
     $pattern = $this->_getPattern($searchEmail, $searchEmail);
     $pattern = str_replace('"mailto:', '"http://mce_host([\\x20-\\x7f][^<>]+/)', $pattern);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[3][0];
         $mailText = $regs[5][0];
         // Check to see if mail text is different from mail addy
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = $this->_addAttributesToEmail($replacement, $regs[1][0], $regs[4][0]);
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search and fix derivatives of link code <a href="http://mce_host/ourdirectory/email@example.org"
      * >anytext</a>. This happens when inserting an email in TinyMCE, cancelling its suggestion to add
      * the mailto: prefix...
      */
     $pattern = $this->_getPattern($searchEmail, $searchText);
     $pattern = str_replace('"mailto:', '"http://mce_host([\\x20-\\x7f][^<>]+/)', $pattern);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[3][0];
         $mailText = $regs[5][0];
         // Check to see if mail text is different from mail addy
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = $this->_addAttributesToEmail($replacement, $regs[1][0], $regs[4][0]);
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@example.org"
      * >email@example.org</a>
      */
     $pattern = $this->_getPattern($searchEmail, $searchEmail);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0];
         $mailText = $regs[4][0];
         // Check to see if mail text is different from mail addy
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = $this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]);
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@amail.com"
      * ><anyspan >email@amail.com</anyspan></a>
      */
     $pattern = $this->_getPattern($searchEmail, $searchEmailSpan);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0];
         $mailText = $regs[4][0] . $regs[5][0] . $regs[6][0];
         // Check to see if mail text is different from mail addy
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@amail.com">
      * <anyspan >anytext</anyspan></a>
      */
     $pattern = $this->_getPattern($searchEmail, $searchTextSpan);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0];
         $mailText = $regs[4][0] . addslashes($regs[5][0]) . $regs[6][0];
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@example.org">
      * anytext</a>
      */
     $pattern = $this->_getPattern($searchEmail, $searchText);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0];
         $mailText = addslashes($regs[4][0]);
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = $this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]);
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@example.org">
      * <img anything></a>
      */
     $pattern = $this->_getPattern($searchEmail, $searchImage);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0];
         $mailText = $regs[4][0];
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@example.org">
      * <img anything>email@example.org</a>
      */
     $pattern = $this->_getPattern($searchEmail, $searchImage . $searchEmail);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0];
         $mailText = $regs[4][0] . $regs[5][0];
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@example.org">
      * <img anything>any text</a>
      */
     $pattern = $this->_getPattern($searchEmail, $searchImage . $searchText);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0];
         $mailText = $regs[4][0] . addslashes($regs[5][0]);
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@example.org?
      * subject=Text">email@example.org</a>
      */
     $pattern = $this->_getPattern($searchEmailLink, $searchEmail);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0] . $regs[3][0];
         $mailText = $regs[5][0];
         // Needed for handling of Body parameter
         $mail = str_replace('&amp;', '&', $mail);
         // Check to see if mail text is different from mail addy
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = $this->_addAttributesToEmail($replacement, $regs[1][0], $regs[4][0]);
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@example.org?
      * subject=Text">anytext</a>
      */
     $pattern = $this->_getPattern($searchEmailLink, $searchText);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0] . $regs[3][0];
         $mailText = addslashes($regs[5][0]);
         // Needed for handling of Body parameter
         $mail = str_replace('&amp;', '&', $mail);
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = $this->_addAttributesToEmail($replacement, $regs[1][0], $regs[4][0]);
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@amail.com?subject= Text"
      * ><anyspan >email@amail.com</anyspan></a>
      */
     $pattern = $this->_getPattern($searchEmailLink, $searchEmailSpan);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0] . $regs[3][0];
         $mailText = $regs[4][0] . $regs[5][0] . $regs[6][0] . $regs[7][0];
         // Check to see if mail text is different from mail addy
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code <a href="mailto:email@amail.com?subject= Text">
      * <anyspan >anytext</anyspan></a>
      */
     $pattern = $this->_getPattern($searchEmailLink, $searchTextSpan);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[2][0] . $regs[3][0];
         $mailText = $regs[4][0] . $regs[5][0] . addslashes($regs[6][0]) . $regs[7][0];
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[3][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code
      * <a href="mailto:email@amail.com?subject=Text"><img anything></a>
      */
     $pattern = $this->_getPattern($searchEmailLink, $searchImage);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[1][0] . $regs[2][0] . $regs[3][0];
         $mailText = $regs[5][0];
         // Needed for handling of Body parameter
         $mail = str_replace('&amp;', '&', $mail);
         // Check to see if mail text is different from mail addy
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[4][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code
      * <a href="mailto:email@amail.com?subject=Text"><img anything>email@amail.com</a>
      */
     $pattern = $this->_getPattern($searchEmailLink, $searchImage . $searchEmail);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[1][0] . $regs[2][0] . $regs[3][0];
         $mailText = $regs[4][0] . $regs[5][0] . $regs[6][0];
         // Needed for handling of Body parameter
         $mail = str_replace('&amp;', '&', $mail);
         // Check to see if mail text is different from mail addy
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[4][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for derivatives of link code
      * <a href="mailto:email@amail.com?subject=Text"><img anything>any text</a>
      */
     $pattern = $this->_getPattern($searchEmailLink, $searchImage . $searchText);
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[1][0] . $regs[2][0] . $regs[3][0];
         $mailText = $regs[4][0] . $regs[5][0] . addslashes($regs[6][0]);
         // Needed for handling of Body parameter
         $mail = str_replace('&amp;', '&', $mail);
         // Check to see if mail text is different from mail addy
         $replacement = JHtml::_('email.cloak', $mail, $mode, $mailText, 0);
         // Ensure that attributes is not stripped out by email cloaking
         $replacement = html_entity_decode($this->_addAttributesToEmail($replacement, $regs[1][0], $regs[4][0]));
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
     }
     /*
      * Search for plain text email addresses, such as email@example.org but not within HTML tags:
      * <img src="..." title="*****@*****.**"> or <input type="text" placeholder="*****@*****.**">
      * The negative lookahead '(?![^<]*>)' is used to exclude this kind of occurrences
      */
     $pattern = '~(?![^<>]*>)' . $searchEmail . '~i';
     while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
         $mail = $regs[1][0];
         $replacement = JHtml::_('email.cloak', $mail, $mode);
         // Replace the found address with the js cloaked email
         $text = substr_replace($text, $replacement, $regs[1][1], strlen($mail));
     }
     return true;
 }
Пример #18
0
 /**
  * clearView
  *
  * @param string     $context
  * @param object     $article
  * @param \JRegistry $params
  *
  * @return  void
  */
 public static function clearView($context, $article, $params = null)
 {
     $input = \JFactory::getApplication()->input;
     if ($input->get('layout') != 'blog' && $input->get('view') != 'featured') {
         return;
     }
     $es = \Ezset::getInstance();
     $html = new Dom();
     $imgW = $es->params->get('blogViewImgWidth', 150);
     $maxChar = $es->params->get('blogViewMaxChar', 250);
     $default = $es->params->get('blogViewImgDefault');
     $crop = (bool) $es->params->get('blogViewImgCrop', true);
     $allowTags = $es->params->get('blogViewTagsAllow');
     $doc = \JFactory::getDocument();
     $text = $article->introtext;
     $mainImg = null;
     if ($doc->getType() != 'html') {
         return;
     }
     $thumb = new \Windwalker\Image\Thumb();
     if ($default) {
         $thumb->setDefaultImage($default);
     }
     // Clean Tags
     if ($es->params->get('blogViewClearly', 0)) {
         // If first image = main image, delete this paragraph.
         $html = $html->load($text);
         /** @var \PHPHtmlParser\Dom\Collection|\PHPHtmlParser\Dom\HtmlNode[] $imgs */
         $imgs = $html->find('img');
         if ($imgs->count()) {
             $mainImg = $imgs[0]->src;
             // Is img in p tag?
             /** @var \PHPHtmlParser\Dom\HtmlNode $p */
             $p = $imgs[0]->getParent();
             // If image has anchor, get parent.
             if ($p->getTag() != 'p') {
                 $p = $p->getParent();
             }
             // remove first img
             $p->setInnerHtml(str_replace($p->firstChild()->outerHtml(), '', $p->innerHtml()));
             if (!trim($p->innerHtml())) {
                 $p->setOuterHtml('');
             }
             $text = (string) $html;
         }
         if ($es->params->get('blogViewCleanTags', 0)) {
             $text = strip_tags($text, $allowTags);
             if (!$allowTags) {
                 $text = StringHelper::substr($text, 0, $maxChar);
             }
         }
     }
     // Handle Image
     if ($crop) {
         $imageUrl = $thumb->resize($mainImg, $imgW, $imgW, $crop);
     } else {
         $imageUrl = $thumb->resize($mainImg, $imgW, 999);
     }
     // Article Link
     $link = JContentHelper::getArticleLink($article->id, $article->catid, 0);
     $data = array('link' => $link, 'image_width' => $imgW, 'image_url' => $imageUrl, 'article' => $article, 'text' => $text);
     // Set layout
     $layout = with(new FileLayout('ezset.article.blog.clearview'))->render($data);
     $article->introtext = $layout;
 }
Пример #19
0
 /**
  * This method implements unicode slugs instead of transliteration.
  *
  * @param   string  $string  String to process
  *
  * @return  string  Processed string
  *
  * @since   1.0
  */
 public static function stringUrlUnicodeSlug($string)
 {
     // Replace double byte whitespaces by single byte (East Asian languages)
     $str = preg_replace('/\\xE3\\x80\\x80/', ' ', $string);
     // Remove any '-' from the string as they will be used as concatenator.
     // Would be great to let the spaces in but only Firefox is friendly with this
     $str = str_replace('-', ' ', $str);
     // Replace forbidden characters by whitespaces
     $str = preg_replace('#[:\\#\\*"@+=;!><&\\.%()\\]\\/\'\\\\|\\[]#', " ", $str);
     // Delete all '?'
     $str = str_replace('?', '', $str);
     // Trim white spaces at beginning and end of alias and make lowercase
     $str = trim(StringHelper::strtolower($str));
     // Remove any duplicate whitespace and replace whitespaces by hyphens
     $str = preg_replace('#\\x20+#', '-', $str);
     return $str;
 }
Пример #20
0
 /**
  * Method to parse a language/locale key and return a simple language string.
  *
  * @param   string  $lang  The language/locale key. For example: en-GB
  *
  * @return  string  The simple language string. For example: en
  *
  * @since   2.5
  */
 public static function getPrimaryLanguage($lang)
 {
     static $data;
     // Only parse the identifier if necessary.
     if (!isset($data[$lang])) {
         if (is_callable(array('Locale', 'getPrimaryLanguage'))) {
             // Get the language key using the Locale package.
             $data[$lang] = Locale::getPrimaryLanguage($lang);
         } else {
             // Get the language key using string position.
             $data[$lang] = StringHelper::substr($lang, 0, StringHelper::strpos($lang, '-'));
         }
     }
     return $data[$lang];
 }
Пример #21
0
 /**
  * Utility function to sort an array of objects on a given field
  *
  * @param   array  $a              An array of objects
  * @param   mixed  $k              The key (string) or an array of keys to sort on
  * @param   mixed  $direction      Direction (integer) or an array of direction to sort in [1 = Ascending] [-1 = Descending]
  * @param   mixed  $caseSensitive  Boolean or array of booleans to let sort occur case sensitive or insensitive
  * @param   mixed  $locale         Boolean or array of booleans to let sort occur using the locale language or not
  *
  * @return  array  The sorted array of objects
  *
  * @since   1.0
  */
 public static function sortObjects(array $a, $k, $direction = 1, $caseSensitive = true, $locale = false)
 {
     if (!is_array($locale) || !is_array($locale[0])) {
         $locale = array($locale);
     }
     $sortCase = (array) $caseSensitive;
     $sortDirection = (array) $direction;
     $key = (array) $k;
     $sortLocale = $locale;
     usort($a, function ($a, $b) use($sortCase, $sortDirection, $key, $sortLocale) {
         for ($i = 0, $count = count($key); $i < $count; $i++) {
             if (isset($sortDirection[$i])) {
                 $direction = $sortDirection[$i];
             }
             if (isset($sortCase[$i])) {
                 $caseSensitive = $sortCase[$i];
             }
             if (isset($sortLocale[$i])) {
                 $locale = $sortLocale[$i];
             }
             $va = $a->{$key[$i]};
             $vb = $b->{$key[$i]};
             if ((is_bool($va) || is_numeric($va)) && (is_bool($vb) || is_numeric($vb))) {
                 $cmp = $va - $vb;
             } elseif ($caseSensitive) {
                 $cmp = StringHelper::strcmp($va, $vb, $locale);
             } else {
                 $cmp = StringHelper::strcasecmp($va, $vb, $locale);
             }
             if ($cmp > 0) {
                 return $direction;
             }
             if ($cmp < 0) {
                 return -$direction;
             }
         }
         return 0;
     });
     return $a;
 }
Пример #22
0
 /**
  * Method to be called by another php script. Processes for XSS and
  * specified bad code.
  *
  * @param   mixed   $source  Input string/array-of-string to be 'cleaned'
  * @param   string  $type    The return type for the variable:
  *                           INT:       An integer, or an array of integers,
  *                           UINT:      An unsigned integer, or an array of unsigned integers,
  *                           FLOAT:     A floating point number, or an array of floating point numbers,
  *                           BOOLEAN:   A boolean value,
  *                           WORD:      A string containing A-Z or underscores only (not case sensitive),
  *                           ALNUM:     A string containing A-Z or 0-9 only (not case sensitive),
  *                           CMD:       A string containing A-Z, 0-9, underscores, periods or hyphens (not case sensitive),
  *                           BASE64:    A string containing A-Z, 0-9, forward slashes, plus or equals (not case sensitive),
  *                           STRING:    A fully decoded and sanitised string (default),
  *                           HTML:      A sanitised string,
  *                           ARRAY:     An array,
  *                           PATH:      A sanitised file path, or an array of sanitised file paths,
  *                           TRIM:      A string trimmed from normal, non-breaking and multibyte spaces
  *                           USERNAME:  Do not use (use an application specific filter),
  *                           RAW:       The raw string is returned with no filtering,
  *                           unknown:   An unknown filter will act like STRING. If the input is an array it will return an
  *                                      array of fully decoded and sanitised strings.
  *
  * @return  mixed  'Cleaned' version of input parameter
  *
  * @since   11.1
  */
 public function clean($source, $type = 'string')
 {
     // Strip Unicode Supplementary Characters when requested to do so
     if ($this->stripUSC) {
         // Alternatively: preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xE2\xAF\x91", $source) but it'd be slower.
         $source = $this->stripUSC($source);
     }
     // Handle the type constraint cases
     switch (strtoupper($type)) {
         case 'INT':
         case 'INTEGER':
             $pattern = '/[-+]?[0-9]+/';
             if (is_array($source)) {
                 $result = array();
                 // Itterate through the array
                 foreach ($source as $eachString) {
                     preg_match($pattern, (string) $eachString, $matches);
                     $result[] = isset($matches[0]) ? (int) $matches[0] : 0;
                 }
             } else {
                 preg_match($pattern, (string) $source, $matches);
                 $result = isset($matches[0]) ? (int) $matches[0] : 0;
             }
             break;
         case 'UINT':
             $pattern = '/[-+]?[0-9]+/';
             if (is_array($source)) {
                 $result = array();
                 // Itterate through the array
                 foreach ($source as $eachString) {
                     preg_match($pattern, (string) $eachString, $matches);
                     $result[] = isset($matches[0]) ? abs((int) $matches[0]) : 0;
                 }
             } else {
                 preg_match($pattern, (string) $source, $matches);
                 $result = isset($matches[0]) ? abs((int) $matches[0]) : 0;
             }
             break;
         case 'FLOAT':
         case 'DOUBLE':
             $pattern = '/[-+]?[0-9]+(\\.[0-9]+)?([eE][-+]?[0-9]+)?/';
             if (is_array($source)) {
                 $result = array();
                 // Itterate through the array
                 foreach ($source as $eachString) {
                     preg_match($pattern, (string) $eachString, $matches);
                     $result[] = isset($matches[0]) ? (double) $matches[0] : 0;
                 }
             } else {
                 preg_match($pattern, (string) $source, $matches);
                 $result = isset($matches[0]) ? (double) $matches[0] : 0;
             }
             break;
         case 'BOOL':
         case 'BOOLEAN':
             if (is_array($source)) {
                 $result = array();
                 // Iterate through the array
                 foreach ($source as $eachString) {
                     $result[] = (bool) $eachString;
                 }
             } else {
                 $result = (bool) $source;
             }
             break;
         case 'WORD':
             $pattern = '/[^A-Z_]/i';
             if (is_array($source)) {
                 $result = array();
                 // Iterate through the array
                 foreach ($source as $eachString) {
                     $result[] = (string) preg_replace($pattern, '', $eachString);
                 }
             } else {
                 $result = (string) preg_replace($pattern, '', $source);
             }
             break;
         case 'ALNUM':
             $pattern = '/[^A-Z0-9]/i';
             if (is_array($source)) {
                 $result = array();
                 // Iterate through the array
                 foreach ($source as $eachString) {
                     $result[] = (string) preg_replace($pattern, '', $eachString);
                 }
             } else {
                 $result = (string) preg_replace($pattern, '', $source);
             }
             break;
         case 'CMD':
             $pattern = '/[^A-Z0-9_\\.-]/i';
             if (is_array($source)) {
                 $result = array();
                 // Iterate through the array
                 foreach ($source as $eachString) {
                     $cleaned = (string) preg_replace($pattern, '', $eachString);
                     $result[] = ltrim($cleaned, '.');
                 }
             } else {
                 $result = (string) preg_replace($pattern, '', $source);
                 $result = ltrim($result, '.');
             }
             break;
         case 'BASE64':
             $pattern = '/[^A-Z0-9\\/+=]/i';
             if (is_array($source)) {
                 $result = array();
                 // Iterate through the array
                 foreach ($source as $eachString) {
                     $result[] = (string) preg_replace($pattern, '', $eachString);
                 }
             } else {
                 $result = (string) preg_replace($pattern, '', $source);
             }
             break;
         case 'STRING':
             if (is_array($source)) {
                 $result = array();
                 // Iterate through the array
                 foreach ($source as $eachString) {
                     $result[] = (string) $this->remove($this->decode((string) $eachString));
                 }
             } else {
                 $result = (string) $this->remove($this->decode((string) $source));
             }
             break;
         case 'HTML':
             if (is_array($source)) {
                 $result = array();
                 // Iterate through the array
                 foreach ($source as $eachString) {
                     $result[] = (string) $this->remove((string) $eachString);
                 }
             } else {
                 $result = (string) $this->remove((string) $source);
             }
             break;
         case 'ARRAY':
             $result = (array) $source;
             break;
         case 'PATH':
             $pattern = '/^[A-Za-z0-9_\\/-]+[A-Za-z0-9_\\.-]*([\\\\\\/][A-Za-z0-9_-]+[A-Za-z0-9_\\.-]*)*$/';
             if (is_array($source)) {
                 $result = array();
                 // Itterate through the array
                 foreach ($source as $eachString) {
                     preg_match($pattern, (string) $eachString, $matches);
                     $result[] = isset($matches[0]) ? (string) $matches[0] : '';
                 }
             } else {
                 preg_match($pattern, $source, $matches);
                 $result = isset($matches[0]) ? (string) $matches[0] : '';
             }
             break;
         case 'TRIM':
             if (is_array($source)) {
                 $result = array();
                 // Iterate through the array
                 foreach ($source as $eachString) {
                     $cleaned = (string) trim($eachString);
                     $cleaned = StringHelper::trim($cleaned, chr(0xe3) . chr(0x80) . chr(0x80));
                     $result[] = StringHelper::trim($cleaned, chr(0xc2) . chr(0xa0));
                 }
             } else {
                 $result = (string) trim($source);
                 $result = StringHelper::trim($result, chr(0xe3) . chr(0x80) . chr(0x80));
                 $result = StringHelper::trim($result, chr(0xc2) . chr(0xa0));
             }
             break;
         case 'USERNAME':
             $pattern = '/[\\x00-\\x1F\\x7F<>"\'%&]/';
             if (is_array($source)) {
                 $result = array();
                 // Iterate through the array
                 foreach ($source as $eachString) {
                     $result[] = (string) preg_replace($pattern, '', $eachString);
                 }
             } else {
                 $result = (string) preg_replace($pattern, '', $source);
             }
             break;
         case 'RAW':
             $result = $source;
             break;
         default:
             // Are we dealing with an array?
             if (is_array($source)) {
                 foreach ($source as $key => $value) {
                     // Filter element for XSS and other 'bad' code etc.
                     if (is_string($value)) {
                         $source[$key] = $this->_remove($this->_decode($value));
                     }
                 }
                 $result = $source;
             } else {
                 // Or a string?
                 if (is_string($source) && !empty($source)) {
                     // Filter source for XSS and other 'bad' code etc.
                     $result = $this->_remove($this->_decode($source));
                 } else {
                     // Not an array or string... return the passed parameter
                     $result = $source;
                 }
             }
             break;
     }
     return $result;
 }
Пример #23
0
 /**
  * Method to change the title.
  *
  * @param   integer  $category_id  The id of the category.
  * @param   string   $alias        The alias.
  * @param   string   $title        The title.
  *
  * @return  string  New title.
  *
  * @since   1.7.1
  */
 protected function generateNewTitle($category_id, $alias, $title)
 {
     // Alter the title
     $table = $this->getTable();
     while ($table->load(array('title' => $title))) {
         $title = StringHelper::increment($title);
     }
     return $title;
 }
Пример #24
0
 /**
  * Converts an object into a JSON formatted string.
  *
  * @param   object  $object   Data source object.
  * @param   array   $options  Options used by the formatter.
  *
  * @return  string  JSON formatted string.
  *
  * @since   1.0
  */
 public function objectToString($object, $options = array())
 {
     return StringHelper::unicode_to_utf8(json_encode($object));
 }
Пример #25
0
 /**
  * Plugin that adds a pagebreak into the text and truncates text at that point
  *
  * @param   string   $context  The context of the content being passed to the plugin.
  * @param   object   &$row     The article object.  Note $article->text is also available
  * @param   mixed    &$params  The article params
  * @param   integer  $page     The 'page' number
  *
  * @return  mixed  Always returns void or true
  *
  * @since   1.6
  */
 public function onContentPrepare($context, &$row, &$params, $page = 0)
 {
     $canProceed = $context == 'com_content.article';
     if (!$canProceed) {
         return;
     }
     $style = $this->params->get('style', 'pages');
     // Expression to search for.
     $regex = '#<hr(.*)class="system-pagebreak"(.*)\\/>#iU';
     $input = JFactory::getApplication()->input;
     $print = $input->getBool('print');
     $showall = $input->getBool('showall');
     if (!$this->params->get('enabled', 1)) {
         $print = true;
     }
     if ($print) {
         $row->text = preg_replace($regex, '<br />', $row->text);
         return true;
     }
     // Simple performance check to determine whether bot should process further.
     if (StringHelper::strpos($row->text, 'class="system-pagebreak') === false) {
         return true;
     }
     $view = $input->getString('view');
     $full = $input->getBool('fullview');
     if (!$page) {
         $page = 0;
     }
     if ($params->get('intro_only') || $params->get('popup') || $full || $view != 'article') {
         $row->text = preg_replace($regex, '', $row->text);
         return;
     }
     // Load plugin language files only when needed (ex: not needed if no system-pagebreak class exists).
     $this->loadLanguage();
     // Find all instances of plugin and put in $matches.
     $matches = array();
     preg_match_all($regex, $row->text, $matches, PREG_SET_ORDER);
     if ($showall && $this->params->get('showall', 1)) {
         $hasToc = $this->params->get('multipage_toc', 1);
         if ($hasToc) {
             // Display TOC.
             $page = 1;
             $this->_createToc($row, $matches, $page);
         } else {
             $row->toc = '';
         }
         $row->text = preg_replace($regex, '<br />', $row->text);
         return true;
     }
     // Split the text around the plugin.
     $text = preg_split($regex, $row->text);
     if (!isset($text[$page])) {
         throw new Exception(JText::_('JERROR_PAGE_NOT_FOUND'), 404);
     }
     // Count the number of pages.
     $n = count($text);
     // We have found at least one plugin, therefore at least 2 pages.
     if ($n > 1) {
         $title = $this->params->get('title', 1);
         $hasToc = $this->params->get('multipage_toc', 1);
         // Adds heading or title to <site> Title.
         if ($title) {
             if ($page) {
                 if ($page && @$matches[$page - 1][2]) {
                     $attrs = JUtility::parseAttributes($matches[$page - 1][1]);
                     if (@$attrs['title']) {
                         $row->page_title = $attrs['title'];
                     }
                 }
             }
         }
         // Reset the text, we already hold it in the $text array.
         $row->text = '';
         if ($style == 'pages') {
             // Display TOC.
             if ($hasToc) {
                 $this->_createToc($row, $matches, $page);
             } else {
                 $row->toc = '';
             }
             // Traditional mos page navigation
             $pageNav = new JPagination($n, $page, 1);
             // Page counter.
             $row->text .= '<div class="pagenavcounter">';
             $row->text .= $pageNav->getPagesCounter();
             $row->text .= '</div>';
             // Page text.
             $text[$page] = str_replace('<hr id="system-readmore" />', '', $text[$page]);
             $row->text .= $text[$page];
             // $row->text .= '<br />';
             $row->text .= '<div class="pager">';
             // Adds navigation between pages to bottom of text.
             if ($hasToc) {
                 $this->_createNavigation($row, $page, $n);
             }
             // Page links shown at bottom of page if TOC disabled.
             if (!$hasToc) {
                 $row->text .= $pageNav->getPagesLinks();
             }
             $row->text .= '</div>';
         } else {
             $t[] = $text[0];
             $t[] = (string) JHtml::_($style . '.start', 'article' . $row->id . '-' . $style);
             foreach ($text as $key => $subtext) {
                 if ($key >= 1) {
                     $match = $matches[$key - 1];
                     $match = (array) JUtility::parseAttributes($match[0]);
                     if (isset($match['alt'])) {
                         $title = stripslashes($match['alt']);
                     } elseif (isset($match['title'])) {
                         $title = stripslashes($match['title']);
                     } else {
                         $title = JText::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $key + 1);
                     }
                     $t[] = (string) JHtml::_($style . '.panel', $title, 'article' . $row->id . '-' . $style . $key);
                 }
                 $t[] = (string) $subtext;
             }
             $t[] = (string) JHtml::_($style . '.end');
             $row->text = implode(' ', $t);
         }
     }
     return true;
 }
Пример #26
0
 /**
  * Common function to process the filters for a query based on the model state
  *
  * @param   DatabaseQuery  $query  DatabaseQuery object
  *
  * @return  DatabaseQuery
  *
  * @since   1.0
  */
 private function processStateFilter(DatabaseQuery $query)
 {
     $db = $this->getDb();
     $filter = $this->getProject()->project_id;
     if ($filter) {
         $query->where($db->quoteName('a.project_id') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.search');
     if ($filter) {
         $query = $this->processSearchFilter($query, $filter);
     }
     $filter = $this->state->get('filter.status');
     if ($filter) {
         $query->where($db->quoteName('a.status') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.state');
     // State == 2 means "all".
     if (is_numeric($filter) && 2 != $filter) {
         $query->where($db->quoteName('s.closed') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.priority');
     if ($filter) {
         $query->where($db->quoteName('a.priority') . ' = ' . (int) $filter);
     }
     $filter = $this->state->get('filter.user');
     if ($filter && is_numeric($filter)) {
         $username = $this->state->get('username');
         switch ($filter) {
             case 1:
                 $query->where($db->quoteName('a.opened_by') . ' = ' . $db->quote($username));
                 break;
             case 2:
                 // Join over the activities.
                 $query->join('LEFT', '#__activities AS ac ON a.issue_number = ac.issue_number');
                 $query->where($db->quoteName('ac.user') . ' = ' . $db->quote($username));
                 $query->where($db->quoteName('ac.project_id') . ' = ' . (int) $this->getProject()->project_id);
                 $query->group('a.issue_number');
                 break;
         }
     }
     $filter = $this->state->get('filter.created_by');
     if ($filter) {
         // Clean filter variable
         $filter = $db->quote('%' . $db->escape(StringHelper::strtolower($filter), true) . '%', false);
         $query->where($db->quoteName('a.opened_by') . ' LIKE ' . $filter);
     }
     $filter = $this->state->get('filter.category');
     if ($filter && is_numeric($filter)) {
         $categoryModel = new CategoryModel($db);
         // If the category filter equals -1, that means we want issues without category.
         if ($filter == -1) {
             $issues = $categoryModel->getIssueIdsWithCategory();
         } else {
             $issues = $categoryModel->getIssueIdsByCategory($filter);
         }
         if ($issues != null) {
             $issueId = array();
             foreach ($issues as $issue) {
                 $issueId[] = $issue->issue_id;
             }
             $issueId = implode(', ', $issueId);
         } else {
             $issueId = 0;
         }
         // Handle the no category filter
         if ($filter == -1) {
             $query->where($db->quoteName('a.id') . ' NOT IN (' . $issueId . ')');
         } else {
             $query->where($db->quoteName('a.id') . ' IN (' . $issueId . ')');
         }
     }
     $filter = $this->state->get('filter.label');
     if ($filter && is_numeric($filter)) {
         $query->where('FIND_IN_SET(' . $filter . ', ' . $db->quoteName('a.labels') . ')');
     }
     $filter = $this->state->get('filter.tests');
     if ($filter && is_numeric($filter)) {
         // Common query elements
         $query->leftJoin($db->quoteName('#__issues_tests', 'it') . 'ON a.id = it.item_id')->where($db->quoteName('a.has_code') . ' = 1')->group('a.issue_number');
         switch ($filter) {
             case 1:
                 $query->where($db->quoteName('it.result') . ' = 1')->having('COUNT(it.item_id) = 1');
                 break;
             case 2:
                 $query->where($db->quoteName('it.result') . ' = 1')->having('COUNT(it.item_id) > 1');
                 break;
             case 3:
                 $query->having('COUNT(it.item_id) = 0');
                 break;
         }
     }
     $filter = $this->state->get('filter.easytest');
     if ($filter && is_numeric($filter)) {
         $query->where($db->quoteName('a.easy') . ' = ' . (int) $filter);
     }
     return $query;
 }
Пример #27
0
 /**
  * Method to generate the title of group on Save as Copy action
  *
  * @param   integer  $parentId  The id of the parent.
  * @param   string   $title     The title of group
  *
  * @return  string  Contains the modified title.
  *
  * @since   3.3.7
  */
 protected function generateGroupTitle($parentId, $title)
 {
     // Alter the title & alias
     $table = $this->getTable();
     while ($table->load(array('title' => $title, 'parent_id' => $parentId))) {
         if ($title == $table->title) {
             $title = StringHelper::increment($title);
         }
     }
     return $title;
 }
Пример #28
0
 /**
  * Overloaded check method to ensure data integrity.
  *
  * @return  boolean  True on success.
  *
  * @since   3.1
  * @throws  UnexpectedValueException
  */
 public function check()
 {
     // Check for valid name.
     if (trim($this->title) == '') {
         throw new UnexpectedValueException(sprintf('The title is empty'));
     }
     if (empty($this->alias)) {
         $this->alias = $this->title;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     // Check the publish down date is not earlier than publish up.
     if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) {
         throw new UnexpectedValueException(sprintf('End publish date is before start publish date.'));
     }
     // Clean up keywords -- eliminate extra spaces between phrases
     // and cr (\r) and lf (\n) characters from string
     if (!empty($this->metakey)) {
         // Only process if not empty
         // Define array of characters to remove
         $bad_characters = array("\n", "\r", "\"", "<", ">");
         // Remove bad characters
         $after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);
         // Create array using commas as delimiter
         $keys = explode(',', $after_clean);
         $clean_keys = array();
         foreach ($keys as $key) {
             if (trim($key)) {
                 // Ignore blank keywords
                 $clean_keys[] = trim($key);
             }
         }
         // Put array back together delimited by ", "
         $this->metakey = implode(", ", $clean_keys);
     }
     // Clean up description -- eliminate quotes and <> brackets
     if (!empty($this->metadesc)) {
         // Only process if not empty
         $bad_characters = array("\"", "<", ">");
         $this->metadesc = StringHelper::str_ireplace($bad_characters, "", $this->metadesc);
     }
     // Not Null sanity check
     $date = JFactory::getDate();
     if (empty($this->params)) {
         $this->params = '{}';
     }
     if (empty($this->metadesc)) {
         $this->metadesc = '';
     }
     if (empty($this->metakey)) {
         $this->metakey = '';
     }
     if (empty($this->metadata)) {
         $this->metadata = '{}';
     }
     if (empty($this->urls)) {
         $this->urls = '{}';
     }
     if (empty($this->images)) {
         $this->images = '{}';
     }
     if (!(int) $this->checked_out_time) {
         $this->checked_out_time = $date->toSql();
     }
     if (!(int) $this->modified_time) {
         $this->modified_time = $date->toSql();
     }
     if (!(int) $this->modified_time) {
         $this->modified_time = $date->toSql();
     }
     if (!(int) $this->publish_up) {
         $this->publish_up = $date->toSql();
     }
     if (!(int) $this->publish_down) {
         $this->publish_down = $date->toSql();
     }
     return true;
 }
Пример #29
0
 /**
  * Redirect to another URL.
  *
  * If the headers have not been sent the redirect will be accomplished using a "301 Moved Permanently"
  * or "303 See Other" code in the header pointing to the new location. If the headers have already been
  * sent this will be accomplished using a JavaScript statement.
  *
  * @param   string   $url     The URL to redirect to. Can only be http/https URL.
  * @param   integer  $status  The HTTP 1.1 status code to be provided. 303 is assumed by default.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function redirect($url, $status = 303)
 {
     // Check for relative internal links.
     if (preg_match('#^index\\.php#', $url)) {
         // We changed this from "$this->get('uri.base.full') . $url" due to the inability to run the system tests with the original code
         $url = JUri::base() . $url;
     }
     // Perform a basic sanity check to make sure we don't have any CRLF garbage.
     $url = preg_split("/[\r\n]/", $url);
     $url = $url[0];
     /*
      * Here we need to check and see if the URL is relative or absolute.  Essentially, do we need to
      * prepend the URL with our base URL for a proper redirect.  The rudimentary way we are looking
      * at this is to simply check whether or not the URL string has a valid scheme or not.
      */
     if (!preg_match('#^[a-z]+\\://#i', $url)) {
         // Get a JUri instance for the requested URI.
         $uri = JUri::getInstance($this->get('uri.request'));
         // Get a base URL to prepend from the requested URI.
         $prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         // We just need the prefix since we have a path relative to the root.
         if ($url[0] == '/') {
             $url = $prefix . $url;
         } else {
             $parts = explode('/', $uri->toString(array('path')));
             array_pop($parts);
             $path = implode('/', $parts) . '/';
             $url = $prefix . $path . $url;
         }
     }
     // If the headers have already been sent we need to send the redirect statement via JavaScript.
     if ($this->checkHeadersSent()) {
         echo "<script>document.location.href='" . str_replace("'", "&apos;", $url) . "';</script>\n";
     } else {
         // We have to use a JavaScript redirect here because MSIE doesn't play nice with utf-8 URLs.
         if ($this->client->engine == JApplicationWebClient::TRIDENT && !StringHelper::is_ascii($url)) {
             $html = '<html><head>';
             $html .= '<meta http-equiv="content-type" content="text/html; charset=' . $this->charSet . '" />';
             $html .= '<script>document.location.href=\'' . str_replace("'", "&apos;", $url) . '\';</script>';
             $html .= '</head><body></body></html>';
             echo $html;
         } else {
             // Check if we have a boolean for the status variable for compatability with old $move parameter
             // @deprecated 4.0
             if (is_bool($status)) {
                 $status = $status ? 301 : 303;
             }
             // Now check if we have an integer status code that maps to a valid redirect. If we don't then set a 303
             // @deprecated 4.0 From 4.0 if no valid status code is given an InvalidArgumentException will be thrown
             if (!is_int($status) || is_int($status) && !isset($this->responseMap[$status])) {
                 $status = 303;
             }
             // All other cases use the more efficient HTTP header for redirection.
             $this->header($this->responseMap[$status]);
             $this->header('Location: ' . $url);
             $this->header('Content-Type: text/html; charset=' . $this->charSet);
         }
     }
     // Close the application after the redirect.
     $this->close();
 }
Пример #30
0
 /**
  * Load controller file
  *
  * @param   string $class Class name
  */
 private function controller($class)
 {
     if (!strstr(strtolower($class), 'controller')) {
         return;
     }
     $class = str_replace('\\', '/', $class);
     $file = explode('/', $class);
     $file = strtolower(array_pop($file));
     $path = JPATH_SITE . '/libraries/fabrik/fabrik/Controllers/' . \Joomla\String\StringHelper::ucfirst($file) . '.php';
     if (file_exists($path)) {
         require_once $path;
     }
 }