示例#1
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;
 }
示例#2
0
文件: tag.php 项目: eshiol/joomla-cms
 /**
  * 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;
 }
示例#3
0
 /**
  * Method to tokenize a text string.
  *
  * @param   string   $input   The input to tokenize.
  * @param   string   $lang    The language of the input.
  * @param   boolean  $phrase  Flag to indicate whether input could be a phrase. [optional]
  *
  * @return  array  An array of FinderIndexerToken objects.
  *
  * @since   2.5
  */
 public static function tokenize($input, $lang, $phrase = false)
 {
     static $cache;
     $store = StringHelper::strlen($input) < 128 ? md5($input . '::' . $lang . '::' . $phrase) : null;
     // Check if the string has been tokenized already.
     if ($store && isset($cache[$store])) {
         return $cache[$store];
     }
     $tokens = array();
     $quotes = html_entity_decode('&#8216;&#8217;&#39;', ENT_QUOTES, 'UTF-8');
     // Get the simple language key.
     $lang = static::getPrimaryLanguage($lang);
     /*
      * Parsing the string input into terms is a multi-step process.
      *
      * Regexes:
      *  1. Remove everything except letters, numbers, quotes, apostrophe, plus, dash, period, and comma.
      *  2. Remove plus, dash, period, and comma characters located before letter characters.
      *  3. Remove plus, dash, period, and comma characters located after other characters.
      *  4. Remove plus, period, and comma characters enclosed in alphabetical characters. Ungreedy.
      *  5. Remove orphaned apostrophe, plus, dash, period, and comma characters.
      *  6. Remove orphaned quote characters.
      *  7. Replace the assorted single quotation marks with the ASCII standard single quotation.
      *  8. Remove multiple space characters and replaces with a single space.
      */
     $input = StringHelper::strtolower($input);
     $input = preg_replace('#[^\\pL\\pM\\pN\\p{Pi}\\p{Pf}\'+-.,]+#mui', ' ', $input);
     $input = preg_replace('#(^|\\s)[+-.,]+([\\pL\\pM]+)#mui', ' $1', $input);
     $input = preg_replace('#([\\pL\\pM\\pN]+)[+-.,]+(\\s|$)#mui', '$1 ', $input);
     $input = preg_replace('#([\\pL\\pM]+)[+.,]+([\\pL\\pM]+)#muiU', '$1 $2', $input);
     $input = preg_replace('#(^|\\s)[\'+-.,]+(\\s|$)#mui', ' ', $input);
     $input = preg_replace('#(^|\\s)[\\p{Pi}\\p{Pf}]+(\\s|$)#mui', ' ', $input);
     $input = preg_replace('#[' . $quotes . ']+#mui', '\'', $input);
     $input = preg_replace('#\\s+#mui', ' ', $input);
     $input = StringHelper::trim($input);
     // Explode the normalized string to get the terms.
     $terms = explode(' ', $input);
     /*
      * If we have Unicode support and are dealing with Chinese text, Chinese
      * has to be handled specially because there are not necessarily any spaces
      * between the "words". So, we have to test if the words belong to the Chinese
      * character set and if so, explode them into single glyphs or "words".
      */
     if ($lang === 'zh') {
         // Iterate through the terms and test if they contain Chinese.
         for ($i = 0, $n = count($terms); $i < $n; $i++) {
             $charMatches = array();
             $charCount = preg_match_all('#[\\p{Han}]#mui', $terms[$i], $charMatches);
             // Split apart any groups of Chinese characters.
             for ($j = 0; $j < $charCount; $j++) {
                 $tSplit = StringHelper::str_ireplace($charMatches[0][$j], '', $terms[$i], false);
                 if (!empty($tSplit)) {
                     $terms[$i] = $tSplit;
                 } else {
                     unset($terms[$i]);
                 }
                 $terms[] = $charMatches[0][$j];
             }
         }
         // Reset array keys.
         $terms = array_values($terms);
     }
     /*
      * If we have to handle the input as a phrase, that means we don't
      * tokenize the individual terms and we do not create the two and three
      * term combinations. The phrase must contain more than one word!
      */
     if ($phrase === true && count($terms) > 1) {
         // Create tokens from the phrase.
         $tokens[] = new FinderIndexerToken($terms, $lang);
     } else {
         // Create tokens from the terms.
         for ($i = 0, $n = count($terms); $i < $n; $i++) {
             $tokens[] = new FinderIndexerToken($terms[$i], $lang);
         }
         // Create two and three word phrase tokens from the individual words.
         for ($i = 0, $n = count($tokens); $i < $n; $i++) {
             // Setup the phrase positions.
             $i2 = $i + 1;
             $i3 = $i + 2;
             // Create the two word phrase.
             if ($i2 < $n && isset($tokens[$i2])) {
                 // Tokenize the two word phrase.
                 $token = new FinderIndexerToken(array($tokens[$i]->term, $tokens[$i2]->term), $lang, $lang === 'zh' ? '' : ' ');
                 $token->derived = true;
                 // Add the token to the stack.
                 $tokens[] = $token;
             }
             // Create the three word phrase.
             if ($i3 < $n && isset($tokens[$i3])) {
                 // Tokenize the three word phrase.
                 $token = new FinderIndexerToken(array($tokens[$i]->term, $tokens[$i2]->term, $tokens[$i3]->term), $lang, $lang === 'zh' ? '' : ' ');
                 $token->derived = true;
                 // Add the token to the stack.
                 $tokens[] = $token;
             }
         }
     }
     if ($store) {
         $cache[$store] = count($tokens) > 1 ? $tokens : array_shift($tokens);
         return $cache[$store];
     } else {
         return count($tokens) > 1 ? $tokens : array_shift($tokens);
     }
 }
示例#4
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;
 }
示例#5
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;
 }
示例#6
0
 /**
  * Method to add alternative meta tags for associated menu items.
  *
  * @return  void
  *
  * @since   1.7
  */
 public function onAfterDispatch()
 {
     $doc = JFactory::getDocument();
     if ($this->app->isSite() && $this->params->get('alternate_meta', 1) && $doc->getType() == 'html') {
         $languages = $this->lang_codes;
         $homes = JLanguageMultilang::getSiteHomePages();
         $menu = $this->app->getMenu();
         $active = $menu->getActive();
         $levels = JFactory::getUser()->getAuthorisedViewLevels();
         $remove_default_prefix = $this->params->get('remove_default_prefix', 0);
         $server = JUri::getInstance()->toString(array('scheme', 'host', 'port'));
         $is_home = false;
         $currentInternalUrl = 'index.php?' . http_build_query($this->app->getRouter()->getVars());
         if ($active) {
             $active_link = JRoute::_($active->link . '&Itemid=' . $active->id);
             $current_link = JRoute::_($currentInternalUrl);
             // Load menu associations
             if ($active_link == $current_link) {
                 $associations = MenusHelper::getAssociations($active->id);
             }
             // Check if we are on the home page
             $is_home = $active->home && ($active_link == $current_link || $active_link == $current_link . 'index.php' || $active_link . '/' == $current_link);
         }
         // Load component associations.
         $option = $this->app->input->get('option');
         $cName = StringHelper::ucfirst(StringHelper::str_ireplace('com_', '', $option)) . 'HelperAssociation';
         JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php'));
         if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) {
             $cassociations = call_user_func(array($cName, 'getAssociations'));
         }
         // For each language...
         foreach ($languages as $i => &$language) {
             switch (true) {
                 // Language without frontend UI || Language without specific home menu || Language without authorized access level
                 case !array_key_exists($i, JLanguageMultilang::getSiteLangs()):
                 case !isset($homes[$i]):
                 case isset($language->access) && $language->access && !in_array($language->access, $levels):
                     unset($languages[$i]);
                     break;
                     // Home page
                 // Home page
                 case $is_home:
                     $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $homes[$i]->id);
                     break;
                     // Current language link
                 // Current language link
                 case $i == $this->current_lang:
                     $language->link = JRoute::_($currentInternalUrl);
                     break;
                     // Component association
                 // Component association
                 case isset($cassociations[$i]):
                     $language->link = JRoute::_($cassociations[$i] . '&lang=' . $language->sef);
                     break;
                     // Menu items association
                     // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison
                 // Menu items association
                 // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison
                 case isset($associations[$i]) && ($item = $menu->getItem($associations[$i])):
                     $language->link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
                     break;
                     // Too bad...
                 // Too bad...
                 default:
                     unset($languages[$i]);
             }
         }
         // If there are at least 2 of them, add the rel="alternate" links to the <head>
         if (count($languages) > 1) {
             // Remove the sef from the default language if "Remove URL Language Code" is on
             if (isset($languages[$this->default_lang]) && $remove_default_prefix) {
                 $languages[$this->default_lang]->link = preg_replace('|/' . $languages[$this->default_lang]->sef . '/|', '/', $languages[$this->default_lang]->link, 1);
             }
             foreach ($languages as $i => &$language) {
                 $doc->addHeadLink($server . $language->link, 'alternate', 'rel', array('hreflang' => $i));
             }
             // Add x-default language tag
             if ($this->params->get('xdefault', 1)) {
                 $xdefault_language = $this->params->get('xdefault_language', $this->default_lang);
                 $xdefault_language = $xdefault_language == 'default' ? $this->default_lang : $xdefault_language;
                 if (isset($languages[$xdefault_language])) {
                     // Use a custom tag because addHeadLink is limited to one URI per tag
                     $doc->addCustomTag('<link href="' . $server . $languages[$xdefault_language]->link . '" rel="alternate" hreflang="x-default" />');
                 }
             }
         }
     }
 }
示例#7
0
 /**
  * Overloaded check function
  *
  * @return  boolean  True on success, false on failure
  *
  * @see     JTable::check
  * @since   1.5
  */
 public function check()
 {
     $this->default_con = (int) $this->default_con;
     if (JFilterInput::checkAttribute(array('href', $this->webpage))) {
         $this->setError(JText::_('COM_CONTACT_WARNING_PROVIDE_VALID_URL'));
         return false;
     }
     // Check for valid name
     if (trim($this->name) == '') {
         $this->setError(JText::_('COM_CONTACT_WARNING_PROVIDE_VALID_NAME'));
         return false;
     }
     // Generate a valid alias
     $this->generateAlias();
     // Check for valid category
     if (trim($this->catid) == '') {
         $this->setError(JText::_('COM_CONTACT_WARNING_CATEGORY'));
         return false;
     }
     // Sanity check for user_id
     if (!$this->user_id) {
         $this->user_id = 0;
     }
     // 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.
      * Only process 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) {
             // Ignore blank keywords.
             if (trim($key)) {
                 $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;
 }
 /**
  * Overloaded check function
  *
  * @return boolean
  *
  * @see   JTable::check
  * @since 1.7.0
  */
 public function check()
 {
     $this->default_con = intval($this->default_con);
     if (JFilterInput::checkAttribute(['href', $this->webpage])) {
         $this->setError(JText::_('COM_CHURCHDIRECTORY_WARNING_PROVIDE_VALID_URL'));
         return false;
     }
     /** check for valid name */
     if (trim($this->name) == '') {
         $this->setError(JText::_('COM_CHURCHDIRECTORY_WARNING_PROVIDE_VALID_NAME'));
         return false;
     }
     /** check for existing name */
     /* TF removed - if same first name exists it errors - this should not be.
     				 * $query = 'SELECT id FROM #__churchdirectory_details WHERE name = ' . $this->_db->Quote($this->name) . ' AND catid = ' . (int) $this->catid;
     				$this->_db->setQuery($query);
     
     				$xid = intval($this->_db->loadResult());
     
     				if ($xid && $xid != intval($this->id))
     				{
     					$this->setError(JText::_('COM_CHURCHDIRECTORY_WARNING_SAME_NAME'));
     
     					return false;
     				}
     		*/
     if (empty($this->alias)) {
         $this->alias = $this->name;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     /** check for valid category */
     if (trim($this->catid) == '') {
         $this->setError(JText::_('COM_CHURCHDIRECTORY_WARNING_CATEGORY'));
         return false;
     }
     // Check the publish down date is not earlier than publish up.
     if (intval($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 (!empty($this->metakey)) {
         // Only process if not empty
         $bad_characters = ["\n", "\r", "\"", "<", ">"];
         $after_clean = \Joomla\String\StringHelper::str_ireplace($bad_characters, "", $this->metakey);
         $keys = explode(',', $after_clean);
         $clean_keys = [];
         foreach ($keys as $key) {
             if (trim($key)) {
                 // Ignore blank keywords
                 $clean_keys[] = trim($key);
             }
         }
         $this->metakey = implode(", ", $clean_keys);
     }
     // Clean up description -- eliminate quotes and <> brackets
     if (!empty($this->metadesc)) {
         // Only process if not empty
         $bad_characters = ["\"", "<", ">"];
         $this->metadesc = \Joomla\String\StringHelper::str_ireplace($bad_characters, "", $this->metadesc);
     }
     return true;
 }
示例#9
0
 /**
  * Overloaded check function
  *
  * @return  boolean  True on success, false on failure
  *
  * @see     JTable::check()
  * @since   11.1
  */
 public function check()
 {
     if (trim($this->title) == '') {
         $this->setError(JText::_('COM_CONTENT_WARNING_PROVIDE_VALID_NAME'));
         return false;
     }
     if (trim($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');
     }
     if (trim(str_replace('&nbsp;', '', $this->fulltext)) == '') {
         $this->fulltext = '';
     }
     /**
      * Ensure any new items have compulsory fields set. This is needed for things like
      * frontend editing where we don't show all the fields or using some kind of API
      */
     if (!$this->id) {
         // Images can be an empty json string
         if (!isset($this->images)) {
             $this->images = '{}';
         }
         // URLs can be an empty json string
         if (!isset($this->urls)) {
             $this->urls = '{}';
         }
         // Attributes (article params) can be an empty json string
         if (!isset($this->attribs)) {
             $this->attribs = '{}';
         }
         // Metadata can be an empty json string
         if (!isset($this->metadata)) {
             $this->metadata = '{}';
         }
         // If we don't have any access rules set at this point just use an empty JAccessRules class
         if (!$this->getRules()) {
             $rules = $this->getDefaultAssetValues('com_content');
             $this->setRules($rules);
         }
     }
     // Check the publish down date is not earlier than publish up.
     if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) {
         // Swap the dates.
         $temp = $this->publish_up;
         $this->publish_up = $this->publish_down;
         $this->publish_down = $temp;
     }
     // 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
         // 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);
     }
     return true;
 }