protected function _preSaveEntry(array &$entry, array $data, $action)
 {
     $entry = array('name' => iaUtil::checkPostParam('name'), 'item' => iaUtil::checkPostParam('item'), 'collapsible' => iaUtil::checkPostParam('collapsible'), 'collapsed' => iaUtil::checkPostParam('collapsed'), 'tabview' => iaUtil::checkPostParam('tabview'), 'tabcontainer' => iaUtil::checkPostParam('tabcontainer'));
     iaUtil::loadUTF8Functions('ascii', 'bad', 'validation');
     if (iaCore::ACTION_ADD == $action) {
         if (!utf8_is_ascii($entry['name'])) {
             $this->addMessage('ascii_required');
         } else {
             $entry['name'] = strtolower($entry['name']);
         }
         if (!$this->getMessages() && !preg_match('/^[a-z0-9\\-_]{2,50}$/', $entry['name'])) {
             $this->addMessage('name_is_incorrect');
         }
         if (empty($data['item'])) {
             $this->addMessage('at_least_one_item_should_be_checked');
         }
         $entry['order'] = $this->_iaDb->getMaxOrder(iaField::getTableGroups()) + 1;
     }
     foreach ($this->_iaCore->languages as $code => $language) {
         if ($data['titles'][$code]) {
             if (!utf8_is_valid($data['titles'][$code])) {
                 $data['titles'][$code] = utf8_bad_replace($data['titles'][$code]);
             }
         } else {
             $this->addMessage($language['title'] . ': ' . iaLanguage::get('title_incorrect'), false);
         }
         if ($data['description'][$code]) {
             if (!utf8_is_valid($data['description'][$code])) {
                 $data['description'][$code] = utf8_bad_replace($data['description'][$code]);
             }
         }
     }
     return !$this->getMessages();
 }
Exemple #2
0
function encode_mail_text($str)
{
    if (utf8_is_ascii($str)) {
        return $str;
    }
    return '=?UTF-8?B?' . base64_encode($str) . '?=';
}
 public function titleAlias($title)
 {
     $result = iaSanitize::tags($title);
     $this->iaCore->factory('util');
     iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
     utf8_is_ascii($result) || ($result = utf8_to_ascii($result));
     $result = preg_replace('#' . self::ALIAS_SUFFIX . '$#i', '', $result);
     $result = iaSanitize::alias($result);
     $result = substr($result, 0, 150);
     // the DB scheme applies this limitation
     $result .= self::ALIAS_SUFFIX;
     return $result;
 }
 public function url($action, $data = array(), $generate = false)
 {
     $data['action'] = $action;
     $data['alias'] = isset($data['artist_alias']) ? $data['artist_alias'] : $data['title_alias'];
     if (!isset($this->patterns[$action])) {
         $action = 'view';
     }
     if ($generate) {
         $iaUtil = $iaCore->factory('core', 'util');
         if (!defined('IA_NOUTF')) {
             iaUtf8::loadUTF8Core();
             iaUtf8::loadUTF8Util('ascii', 'validation', 'bad', 'utf8_to_ascii');
         }
         if (!utf8_is_ascii($data['alias'])) {
             $data['alias'] = $iaCore->convertStr(utf8_to_ascii($data['alias']));
         }
     }
     $url = iaDb::printf($this->patterns[$action], $data);
     return self::get('url') . $url;
 }
 public function url($action, $data = array(), $generate = false)
 {
     $data['action'] = $action;
     $data['alias'] = isset($data['genre_alias']) ? $data['genre_alias'] : $data['title_alias'];
     if (!isset($this->patterns[$action])) {
         $action = 'view';
     }
     if ($generate) {
         iaCore::util();
         if (!defined('IA_NOUTF')) {
             iaUtf8::loadUTF8Core();
             iaUtf8::loadUTF8Util('ascii', 'validation', 'bad', 'utf8_to_ascii');
         }
         if (!utf8_is_ascii($data['alias'])) {
             $data['alias'] = $iaCore->convertStr(utf8_to_ascii($data['alias']));
         }
     }
     $url = iaDb::printf($this->patterns[$action], $data);
     return $this->iaCore->packagesData[self::PACKAGE_NAME]['url'] . $url;
 }
     if (!$member_id) {
         $error = true;
         $messages[] = iaLanguage::get('album_incorrect_account');
     } else {
         $data['member_id'] = $member_id;
     }
 } else {
     $data['member_id'] = iaUsers::getIdentity()->id;
 }
 if (!defined('IA_NOUTF')) {
     iaUtf8::loadUTF8Core();
     iaUtf8::loadUTF8Util('ascii', 'validation', 'bad', 'utf8_to_ascii');
 }
 // validate title_alias
 $data['title_alias'] = !empty($_POST['title_alias']) ? $_POST['title_alias'] : $_POST['title'];
 if (!utf8_is_ascii($data['title_alias'])) {
     $data['title_alias'] = utf8_to_ascii($data['title_alias']);
 }
 $data['title_alias'] = iaSanitize::convertStr($data['title_alias']);
 // check for duplicate title_alias in case a new album is added or title_alias has been updated
 if (!isset($item['title_alias']) || isset($item['title_alias']) && $data['title_alias'] != $item['title_alias']) {
     if ($iaAlbum->existsAlias($data['title_alias'])) {
         $error = true;
         $messages[] = iaLanguage::get('album_already_exists');
     }
 }
 if (!$error) {
     $iaCore->startHook("phpAdminBeforeAlbumSubmit");
     if (!empty($_POST['artist'])) {
         $artist_info = $iaArtist->getArtistByTitle($_POST['artist']);
         $data['id_artist'] = $artist_info['id'];
Exemple #7
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)
 {
     // Import library dependencies.
     jimport('phputf8.utils.ascii');
     // 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 && !utf8_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 a 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();
 }
Exemple #8
0
 /**
  * @dataProvider providerUtf8IsAscii
  */
 public function testUtf8IsAscii($ord, $rv)
 {
     $this->assertEquals(utf8_is_ascii($ord), $rv);
 }
Exemple #9
0
/**
 * Takes an array of integers representing the Unicode characters and returns
 * a UTF-8 string.
 *
 * @param  array $unicode The array of Unicode code points
 * @param  bool  $strict  Should the function throw an error if something goes wrong
 * @return string The UTF-8 encoded string or false on failure
 */
function utf8_from_unicode($unicode, $strict = false)
{
    $rv = '';
    $count = count($unicode);
    for ($i = 0; $i < $count; $i++) {
        $cp = $unicode[$i];
        if (utf8_is_ascii($cp)) {
            $rv .= chr($cp);
            continue;
        }
        if (!unicode_is_valid($cp)) {
            if ($strict) {
                $msg = unicode_is_surrogate($cp) ? 'Illegal surrogate in UTF-8' : 'Codepoint out of Unicode range';
                trigger_error(sprintf('utf8_from_unicode: %s at index: %d, value: 0x%X', $msg, $i, $cp));
                return false;
            }
            continue;
        }
        $seqlen = utf8_sequence_length($cp);
        $rv .= chr(utf8_encode_identifier($cp, $seqlen));
        $offset = $seqlen - 2;
        do {
            $rv .= chr(utf8_encode_trail($cp, $offset));
        } while ($offset--);
    }
    return $rv;
}
Exemple #10
0
 protected function _preSaveEntry(array &$entry, array $data, $action)
 {
     $this->_iaCore->startHook('adminAddMemberValidation');
     $iaAcl = $this->_iaCore->factory('acl');
     $iaField = $this->_iaCore->factory('field');
     $fields = iaField::getAcoFieldsList(iaCore::ADMIN, $this->_itemName);
     // below is the hacky way to force the script to upload files to the appropriate user's folder
     // FIXME
     $activeUser = iaUsers::getIdentity(true);
     $_SESSION[iaUsers::SESSION_KEY] = array('id' => $this->getEntryId(), 'username' => $data['username']);
     list($entry, $error, $this->_messages, ) = $iaField->parsePost($fields, $entry);
     $_SESSION[iaUsers::SESSION_KEY] = $activeUser;
     //
     if ($iaAcl->isAccessible($this->getName(), 'usergroup')) {
         if (isset($data['usergroup_id'])) {
             $entry['usergroup_id'] = array_key_exists($data['usergroup_id'], $this->_userGroups) ? $data['usergroup_id'] : iaUsers::MEMBERSHIP_REGULAR;
         }
     } elseif (iaCore::ACTION_ADD == $action) {
         $entry['usergroup_id'] = iaUsers::MEMBERSHIP_REGULAR;
     }
     if ($error) {
         return false;
     }
     $stmt = '`email` = :email';
     if (iaCore::ACTION_EDIT == $action) {
         if (isset($entry['status']) && $entry['status'] == $this->_iaDb->one('status', iaDb::convertIds((int) $this->getEntryId()))) {
             unset($entry['status']);
         }
         $stmt .= ' AND `id` != ' . (int) $this->getEntryId();
     }
     if ($this->_iaDb->exists($stmt, $entry)) {
         $this->addMessage('error_duplicate_email');
     }
     if ($this->_iaDb->exists('`username` = :username AND `id` != :id', array('username' => $entry['username'], 'id' => $this->getEntryId()))) {
         $this->addMessage('username_already_taken');
     }
     if ($iaAcl->checkAccess($this->getName(), 'password') || iaCore::ACTION_ADD == $action) {
         $this->_password = trim($data['_password']);
         if ($this->_password || !empty($data['_password2'])) {
             $entry['password'] = $this->getHelper()->encodePassword($this->_password);
             iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
             if (empty($entry['password'])) {
                 $this->addMessage('error_password_empty');
             } elseif (!utf8_is_ascii($entry['password'])) {
                 $this->addMessage(iaLanguage::get('password') . ': ' . iaLanguage::get('ascii_required'));
             } elseif ($entry['password'] != $this->getHelper()->encodePassword($data['_password2'])) {
                 $this->addMessage('error_password_match');
             }
         }
     }
     if (empty($data['_password']) && iaCore::ACTION_ADD == $action) {
         $this->addMessage('error_password_empty');
     }
     return !$this->getMessages();
 }
Exemple #11
0
 private function _getJsonUrl(array $params)
 {
     iaUtil::loadUTF8Functions('ascii', 'utf8_to_ascii');
     $name = $params['name'];
     $name = utf8_is_ascii($name) ? $name : utf8_to_ascii($name);
     $name = preg_replace('#[^a-z0-9-_]#iu', '', $name);
     $url = $params['url'];
     $url = utf8_is_ascii($url) ? $url : utf8_to_ascii($url);
     $url = preg_replace('#[^a-z0-9-_]#iu', '', $url);
     $url = $url ? $url : $name;
     if (is_numeric($params['parent']) && $params['parent']) {
         $parentPage = $this->getById($params['parent']);
         $parentAlias = empty($parentPage['alias']) ? $parentPage['name'] . IA_URL_DELIMITER : $parentPage['alias'];
         $url = $parentAlias . (IA_URL_DELIMITER == substr($parentAlias, -1, 1) ? '' : IA_URL_DELIMITER) . $url;
     }
     $url .= $params['ext'];
     $exists = $this->_iaDb->exists('`alias` = :url AND `name` != :name', array('url' => $url, 'name' => $name));
     $url = IA_URL . $url;
     return array('url' => $url, 'exists' => $exists);
 }
Exemple #12
0
    /**
     * Redirects user to a given URL
     *
     * Uses JavaScript redirection if headers are already sent. Otherwise sends a 303 header.
     *
     * @param $url string A fully qualified URL
     */
    protected function _redirect($url)
    {
        // Strip out any line breaks.
        $url = preg_split("/[\r\n]/", $url);
        $url = $url[0];

        // If the headers have been sent, then we cannot send an additional location header
        // so we will output a javascript redirect statement.
        if (headers_sent())
        {
            echo "<script>document.location.href='" . htmlspecialchars($url) . "';</script>\n";
        }
        else
        {
            jimport('phputf8.utils.ascii');

            $document   = JFactory::getDocument();
            $user_agent = null;

            if (isset($_SERVER['HTTP_USER_AGENT'])) {
                $user_agent = $_SERVER['HTTP_USER_AGENT'];
            }

            if ((stripos($user_agent, 'MSIE') !== false || stripos($user_agent, 'Trident') !== false)
                && !utf8_is_ascii($url))
            {
                // MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
                echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />'
                    . '<script>document.location.href=\'' . htmlspecialchars($url) . '\';</script></head></html>';
            }
            else
            {
                // All other browsers, use the more efficient HTTP header method
                header('HTTP/1.1 303 See other');
                header('Location: ' . $url);
                header('Content-Type: text/html; charset=' . $document->getCharset());
            }
        }

        JFactory::getApplication()->close();
    }
Exemple #13
0
/**
 * This function may return boolean false, but may also return a non-boolean 0
 * which evaluates to false. Use the === operator for testing the return value
 * of this function.
 *
 * @param  string $str The UTF-8 encoded string
 * @param  int    $i   The current position of the string
 * @param  int    $rcp If passed, this will be set to the Unicode code point
 *                     for the character
 * @return string The character or false on the start of the string
 */
function utf8_get_last_char($str, &$i = null, &$rcp = null)
{
    if ($i === null) {
        $i = strlen($str) - 1;
    }
    while (isset($str[$i])) {
        $n = $i--;
        // Save current position and move to the previous octet
        $char = $str[$n++];
        // Move to the next octet at once
        $ord = ord($char);
        if (utf8_is_ascii($ord)) {
            $rcp = $ord;
            return $char;
        }
        if (utf8_is_identifier($ord, $seqlen)) {
            $cp = utf8_decode_identifier($ord, $seqlen);
            $offset = $seqlen - 2;
            // Check for exists the last octet of the sequence at once
            if (!isset($str[$n + $offset])) {
                continue;
            }
            do {
                $ord = ord($str[$n]);
                if (!utf8_is_trail($ord)) {
                    continue 2;
                    // Skip this sequence
                }
                $cp |= utf8_decode_trail($ord, $offset);
                $char .= $str[$n++];
            } while ($offset--);
            if (unicode_is_valid($cp) && utf8_sequence_length($cp) == $seqlen) {
                $rcp = $cp;
                return $char;
            }
        }
    }
    return false;
}
 /**
  * Tests whether a string contains only 7bit ASCII bytes.
  *
  * You might use this to conditionally check whether a string needs handling as UTF-8 or not, potentially offering performance
  * benefits by using the native PHP equivalent if it's just ASCII e.g.;
  *
  * <code>
  * if (StringHelper::is_ascii($someString))
  * {
  *     // It's just ASCII - use the native PHP version
  *     $someString = strtolower($someString);
  * }
  * else
  * {
  *     $someString = StringHelper::strtolower($someString);
  * }
  * </code>
  *
  * @param   string  $str  The string to test.
  *
  * @return  boolean True if the string is all ASCII
  *
  * @since   1.3.0
  */
 public static function is_ascii($str)
 {
     return utf8_is_ascii($str);
 }
Exemple #15
0
 /**
  * Tests whether a string contains only 7bit ASCII bytes.
  * You might use this to conditionally check whether a string
  * needs handling as UTF-8 or not, potentially offering performance
  * benefits by using the native PHP equivalent if it's just ASCII e.g.;
  *
  * <code>
  * if (String::is_ascii($someString))
  * {
  *     // It's just ASCII - use the native PHP version
  *     $someString = strtolower($someString);
  * }
  * else
  * {
  *     $someString = String::strtolower($someString);
  * }
  * </code>
  *
  * @param   string  $str  The string to test.
  *
  * @return  boolean True if the string is all ASCII
  *
  * @since   1.3.0
  */
 public static function is_ascii($str)
 {
     if (!function_exists('utf8_is_ascii')) {
         require_once __DIR__ . '/phputf8/utils/ascii.php';
     }
     return utf8_is_ascii($str);
 }
 /**
  * Converts text to well-formed URL, replaces all non alpha-numeric / underscore symbols to separator
  *
  * @param string $string text to be converted
  * @param string $separator separator symbol used for the conversion
  *
  * @return string
  */
 public static function alias($string, $separator = '-')
 {
     iaCore::instance()->factory('util')->loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
     $string = html_entity_decode($string);
     $string = str_replace(array('&', "'"), array('and', ''), $string);
     $urlEncoded = false;
     if (!utf8_is_ascii($string)) {
         if (iaCore::instance()->get('alias_urlencode', false)) {
             $string = preg_replace('#[^0-9\\p{L}]+#ui', $separator, $string);
             $urlEncoded = true;
         } else {
             $string = utf8_to_ascii($string);
         }
     }
     $string = $urlEncoded ? $string : preg_replace('#[^a-z0-9_]+#i', $separator, $string);
     $string = trim($string, $separator);
     return $string;
 }
 /**
  * Redirect to another URL.
  *
  * Optionally enqueues a message in the system message queue (which will be displayed
  * the next time a page is loaded) using the enqueueMessage method. If the headers have
  * not been sent the redirect will be accomplished using a "301 Moved Permanently"
  * 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   string   $msg      An optional message to display on redirect.
  * @param   string   $msgType  An optional message type. Defaults to message.
  * @param   boolean  $moved    True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.
  *
  * @return  void  Calls exit().
  *
  * @since   11.1
  * @deprecated  4.0
  *
  * @see     JApplication::enqueueMessage()
  */
 public function redirect($url, $msg = '', $msgType = 'message', $moved = false)
 {
     // Check for relative internal links.
     if (preg_match('#^index2?\\.php#', $url)) {
         $url = JUri::base() . $url;
     }
     // Strip out any line breaks.
     $url = preg_split("/[\r\n]/", $url);
     $url = $url[0];
     /*
      * If we don't start with a http we need to fix this before we proceed.
      * We could validly start with something else (e.g. ftp), though this would
      * be unlikely and isn't supported by this API.
      */
     if (!preg_match('#^http#i', $url)) {
         $uri = JUri::getInstance();
         $prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         if ($url[0] == '/') {
             // We just need the prefix since we have a path relative to the root.
             $url = $prefix . $url;
         } else {
             // It's relative to where we are now, so lets add that.
             $parts = explode('/', $uri->toString(array('path')));
             array_pop($parts);
             $path = implode('/', $parts) . '/';
             $url = $prefix . $path . $url;
         }
     }
     // If the message exists, enqueue it.
     if (trim($msg)) {
         $this->enqueueMessage($msg, $msgType);
     }
     // Persist messages if they exist.
     if (count($this->_messageQueue)) {
         $session = JFactory::getSession();
         $session->set('application.queue', $this->_messageQueue);
     }
     // If the headers have been sent, then we cannot send an additional location header
     // so we will output a javascript redirect statement.
     if (headers_sent()) {
         echo "<script>document.location.href='" . str_replace("'", "&apos;", $url) . "';</script>\n";
     } else {
         $document = JFactory::getDocument();
         jimport('phputf8.utils.ascii');
         if ($this->client->engine == JApplicationWebClient::TRIDENT && !utf8_is_ascii($url)) {
             // MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
             echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />' . '<script>document.location.href=\'' . str_replace("'", "&apos;", $url) . '\';</script></head></html>';
         } else {
             // All other browsers, use the more efficient HTTP header method
             header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
             header('Location: ' . $url);
             header('Content-Type: text/html; charset=' . $document->getCharset());
         }
     }
     $this->close();
 }
 /**
  * Tests whether a string contains only 7bit ASCII bytes.
  * You might use this to conditionally check whether a string
  * needs handling as UTF-8 or not, potentially offering performance
  * benefits by using the native PHP equivalent if it's just ASCII e.g.;
  *
  * <code>
  * if (String::is_ascii($someString))
  * {
  *     // It's just ASCII - use the native PHP version
  *     $someString = strtolower($someString);
  * }
  * else
  * {
  *     $someString = String::strtolower($someString);
  * }
  * </code>
  *
  * @param   string  $str  The string to test.
  *
  * @return  boolean True if the string is all ASCII
  *
  * @since   1.0
  */
 public static function is_ascii($str)
 {
     require_once __DIR__ . '/phputf8/utils/ascii.php';
     return utf8_is_ascii($str);
 }
Exemple #19
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   boolean  $moved  True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function redirect($url, $moved = false)
 {
     // Import library dependencies.
     jimport('phputf8.utils.ascii');
     // Check for relative internal links.
     if (preg_match('#^index\\.php#', $url)) {
         $url = $this->get('uri.base.full') . $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='{$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 && !utf8_is_ascii($url)) {
             $html = '<html><head>';
             $html .= '<meta http-equiv="content-type" content="text/html; charset=' . $this->charSet . '" />';
             $html .= '<script>document.location.href=\'' . $url . '\';</script>';
             $html .= '</head><body></body></html>';
             echo $html;
         } else {
             // All other cases use the more efficient HTTP header for redirection.
             $this->header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
             $this->header('Location: ' . $url);
             $this->header('Content-Type: text/html; charset=' . $this->charSet);
         }
     }
     // Close the application after the redirect.
     $this->close();
 }
Exemple #20
0
 function isUTF8($str)
 {
     if (is_array($str)) {
         foreach ($str as $s) {
             if (!$this->isUTF8($s)) {
                 return false;
             }
         }
         return true;
     } elseif (is_string($str)) {
         if (function_exists('mb_detect_encoding')) {
             return mb_detect_encoding($str) == 'UTF-8';
         } else {
             jimport('phputf8.utils.ascii');
             return utf8_is_ascii($str);
         }
     } else {
         return false;
     }
 }
 /**
  * Redirect to another URL.
  *
  * Optionally enqueues a message in the system message queue (which will be displayed
  * the next time a page is loaded) using the enqueueMessage method. If the headers have
  * not been sent the redirect will be accomplished using a "301 Moved Permanently"
  * 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   string   $msg      An optional message to display on redirect.
  * @param   string   $msgType  An optional message type. Defaults to message.
  * @param   boolean  $moved    True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.
  *
  * @return  void  Calls exit().
  *
  * @since   11.1
  *
  * @see     JApplication::enqueueMessage()
  */
 public function redirect($url, $msg = '', $msgType = 'message', $moved = false)
 {
     // Check for relative internal links.
     if (preg_match('#^index2?\\.php#', $url)) {
         $url = JURI::base() . $url;
     }
     // Strip out any line breaks.
     $url = preg_split("/[\r\n]/", $url);
     $url = $url[0];
     // If we don't start with a http we need to fix this before we proceed.
     // We could validly start with something else (e.g. ftp), though this would
     // be unlikely and isn't supported by this API.
     if (!preg_match('#^http#i', $url)) {
         $uri = JURI::getInstance();
         $prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         if ($url[0] == '/') {
             // We just need the prefix since we have a path relative to the root.
             $url = $prefix . $url;
         } else {
             // It's relative to where we are now, so lets add that.
             $parts = explode('/', $uri->toString(array('path')));
             array_pop($parts);
             $path = implode('/', $parts) . '/';
             $url = $prefix . $path . $url;
         }
     }
     // If the message exists, enqueue it.
     if (trim($msg)) {
         $this->enqueueMessage($msg, $msgType);
     }
     // Persist messages if they exist.
     if (count($this->_messageQueue)) {
         $session = JFactory::getSession();
         $session->set('application.queue', $this->_messageQueue);
     }
     // If the headers have been sent, then we cannot send an additional location header
     // so we will output a javascript redirect statement.
     if (headers_sent()) {
         echo "<script>document.location.href='" . htmlspecialchars($url) . "';</script>\n";
     } else {
         $document = JFactory::getDocument();
         jimport('joomla.environment.browser');
         $navigator = JBrowser::getInstance();
         jimport('phputf8.utils.ascii');
         if ($navigator->isBrowser('msie') && !utf8_is_ascii($url)) {
             // MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
             echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />' . '<script>document.location.href=\'' . htmlspecialchars($url) . '\';</script></head></html>';
         } elseif (!$moved and $navigator->isBrowser('konqueror')) {
             // WebKit browser (identified as konqueror by Joomla!) - Do not use 303, as it causes subresources
             // reload (https://bugs.webkit.org/show_bug.cgi?id=38690)
             echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />' . '<meta http-equiv="refresh" content="0; url=' . htmlspecialchars($url) . '" /></head></html>';
         } else {
             // All other browsers, use the more efficient HTTP header method
             header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
             header('Location: ' . $url);
             header('Content-Type: text/html; charset=' . $document->getCharset());
         }
     }
     $this->close();
 }
     $messages[] = iaLanguage::get('error_gb_email');
 }
 // checking email
 if (isset($_POST['aurl']) && !empty($_POST['aurl']) && 'http://' != $_POST['aurl']) {
     $entry['author_url'] = $_POST['aurl'];
     if (!iaValidate::isUrl($entry['author_url'])) {
         $error = true;
         $messages[] = iaLanguage::get('error_url');
     }
 }
 // checking body
 $entry['body'] = $_POST['message'];
 if (!utf8_is_valid($entry['body'])) {
     $entry['body'] = utf8_bad_replace($entry['body']);
 }
 $length = utf8_is_ascii($entry['body']) ? strlen($entry['body']) : utf8_strlen($entry['body']);
 if ($iaCore->get('gb_min_chars') > 0) {
     if ($length < $iaCore->get('gb_min_chars')) {
         $error = true;
         $messages[] = iaLanguage::getf('error_min_gb', array('length' => $iaCore->get('gb_min_chars')));
     }
 }
 if ($iaCore->get('gb_max_chars') > 0) {
     if ($length > $iaCore->get('gb_max_chars')) {
         $error = true;
         $messages[] = iaLanguage::getf('error_max_gb', array('length' => $iaCore->get('gb_max_chars')));
     }
 }
 if (empty($entry['body'])) {
     $error = true;
     $messages[] = iaLanguage::get('error_gb');