当前位置: 首页>>代码示例>>PHP>>正文


PHP JStringPunycode::toPunycode方法代码示例

本文整理汇总了PHP中JStringPunycode::toPunycode方法的典型用法代码示例。如果您正苦于以下问题:PHP JStringPunycode::toPunycode方法的具体用法?PHP JStringPunycode::toPunycode怎么用?PHP JStringPunycode::toPunycode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JStringPunycode的用法示例。


在下文中一共展示了JStringPunycode::toPunycode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: isEmailAddress

 /**
  * Verifies that the string is in a proper email address format.
  *
  * @param   string  $email  String to be verified.
  *
  * @return  boolean  True if string has the correct format; false otherwise.
  *
  * @since   11.1
  */
 public static function isEmailAddress($email)
 {
     // Split the email into a local and domain
     $atIndex = strrpos($email, "@");
     $domain = substr($email, $atIndex + 1);
     $local = substr($email, 0, $atIndex);
     // Check Length of domain
     $domainLen = strlen($domain);
     if ($domainLen < 1 || $domainLen > 255) {
         return false;
     }
     /*
      * Check the local address
      * We're a bit more conservative about what constitutes a "legal" address, that is, a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-
      * The first and last character in local cannot be a period ('.')
      * Also, period should not appear 2 or more times consecutively
      */
     $allowed = 'a-zA-Z0-9.!#$%&’*+\\/=?^_`{|}~-';
     $regex = "/^[{$allowed}][\\.{$allowed}]{0,63}\$/";
     if (!preg_match($regex, $local) || substr($local, -1) == '.' || $local[0] == '.' || preg_match('/\\.\\./', $local)) {
         return false;
     }
     // No problem if the domain looks like an IP address, ish
     $regex = '/^[0-9\\.]+$/';
     if (preg_match($regex, $domain)) {
         return true;
     }
     // Check Lengths
     $localLen = strlen($local);
     if ($localLen < 1 || $localLen > 64) {
         return false;
     }
     // Check the domain
     $domain_array = explode(".", rtrim($domain, '.'));
     $regex = '/^[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$/';
     foreach ($domain_array as $domain) {
         // Convert domain to punycode
         $domain = JStringPunycode::toPunycode($domain);
         // Must be something
         if (!$domain) {
             return false;
         }
         // Check for invalid characters
         if (!preg_match($regex, $domain)) {
             return false;
         }
         // Check for a dash at the beginning of the domain
         if (strpos($domain, '-') === 0) {
             return false;
         }
         // Check for a dash at the end of the domain
         $length = strlen($domain) - 1;
         if (strpos($domain, '-', $length) === $length) {
             return false;
         }
     }
     return true;
 }
开发者ID:adjaika,项目名称:J3Base,代码行数:67,代码来源:helper.php

示例2: toPunycode

 /**
  * Helper wrapper method for toPunycode
  *
  * @param   string  $utfString  The UTF-8 string to transform.
  *
  * @return string  The punycode string.
  *
  * @see     JUserHelper::toPunycode()
  * @since   3.4
  */
 public function toPunycode($utfString)
 {
     return JStringPunycode::toPunycode($utfString);
 }
开发者ID:deenison,项目名称:joomla-cms,代码行数:14,代码来源:punycode.php

示例3: upload

 /**
  * Upload a file
  *
  * @return  void
  *
  * @since   1.5
  */
 public function upload()
 {
     $params = JComponentHelper::getParams('com_media');
     // Check for request forgeries
     if (!JSession::checkToken('request')) {
         $response = array('status' => '0', 'message' => JText::_('JINVALID_TOKEN'), 'error' => JText::_('JINVALID_TOKEN'));
         echo json_encode($response);
         return;
     }
     // Get the user
     $user = JFactory::getUser();
     JLog::addLogger(array('text_file' => 'upload.error.php'), JLog::ALL, array('upload'));
     // Get some data from the request
     $file = $this->input->files->get('Filedata', '', 'array');
     $folder = $this->input->get('folder', '', 'path');
     // Instantiate the media helper
     $mediaHelper = new JHelperMedia();
     if ($_SERVER['CONTENT_LENGTH'] > $params->get('upload_maxsize', 0) * 1024 * 1024 || $_SERVER['CONTENT_LENGTH'] > $mediaHelper->toBytes(ini_get('upload_max_filesize')) || $_SERVER['CONTENT_LENGTH'] > $mediaHelper->toBytes(ini_get('post_max_size')) || $_SERVER['CONTENT_LENGTH'] > $mediaHelper->toBytes(ini_get('memory_limit'))) {
         $response = array('status' => '0', 'message' => JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE'), 'error' => JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE'));
         echo json_encode($response);
         return;
     }
     // Set FTP credentials, if given
     JClientHelper::setCredentialsFromRequest('ftp');
     if (isset($file['name'])) {
         // Make the filename safe
         $file['name'] = JFile::makeSafe($file['name']);
         // We need a URL safe name
         $fileparts = pathinfo(COM_MEDIA_BASE . '/' . $folder . '/' . $file['name']);
         // Transform filename to punycode
         $fileparts['filename'] = JStringPunycode::toPunycode($fileparts['filename']);
         $tempExt = !empty($fileparts['extension']) ? strtolower($fileparts['extension']) : '';
         // Transform filename to punycode, then neglect otherthan non-alphanumeric characters & underscores. Also transform extension to lowercase
         $safeFileName = preg_replace(array("/[\\s]/", "/[^a-zA-Z0-9_]/"), array("_", ""), $fileparts['filename']) . '.' . $tempExt;
         // Create filepath with safe-filename
         $files['final'] = $fileparts['dirname'] . DIRECTORY_SEPARATOR . $safeFileName;
         $file['name'] = $safeFileName;
         $filepath = JPath::clean($files['final']);
         if (!$mediaHelper->canUpload($file, 'com_media')) {
             JLog::add('Invalid: ' . $filepath, JLog::INFO, 'upload');
             $response = array('status' => '0', 'message' => JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'), 'error' => JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'));
             echo json_encode($response);
             return;
         }
         // Trigger the onContentBeforeSave event.
         JPluginHelper::importPlugin('content');
         $dispatcher = JEventDispatcher::getInstance();
         $object_file = new JObject($file);
         $object_file->filepath = $filepath;
         $result = $dispatcher->trigger('onContentBeforeSave', array('com_media.file', &$object_file, true));
         if (in_array(false, $result, true)) {
             // There are some errors in the plugins
             JLog::add('Errors before save: ' . $object_file->filepath . ' : ' . implode(', ', $object_file->getErrors()), JLog::INFO, 'upload');
             $response = array('status' => '0', 'message' => JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors)), 'error' => JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
             echo json_encode($response);
             return;
         }
         if (JFile::exists($object_file->filepath)) {
             // File exists
             JLog::add('File exists: ' . $object_file->filepath . ' by user_id ' . $user->id, JLog::INFO, 'upload');
             $response = array('status' => '0', 'message' => JText::_('COM_MEDIA_ERROR_FILE_EXISTS'), 'error' => JText::_('COM_MEDIA_ERROR_FILE_EXISTS'), 'location' => str_replace(JPATH_ROOT, '', $filepath));
             echo json_encode($response);
             return;
         } elseif (!$user->authorise('core.create', 'com_media')) {
             // File does not exist and user is not authorised to create
             JLog::add('Create not permitted: ' . $object_file->filepath . ' by user_id ' . $user->id, JLog::INFO, 'upload');
             $response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_CREATE_NOT_PERMITTED'), 'message' => JText::_('COM_MEDIA_ERROR_CREATE_NOT_PERMITTED'));
             echo json_encode($response);
             return;
         }
         if (!JFile::upload($object_file->tmp_name, $object_file->filepath)) {
             // Error in upload
             JLog::add('Error on upload: ' . $object_file->filepath, JLog::INFO, 'upload');
             $response = array('status' => '0', 'message' => JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'), 'error' => JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'));
             echo json_encode($response);
             return;
         } else {
             // Trigger the onContentAfterSave event.
             $dispatcher->trigger('onContentAfterSave', array('com_media.file', &$object_file, true));
             JLog::add($folder, JLog::INFO, 'upload');
             $returnUrl = str_replace(JPATH_ROOT, '', $object_file->filepath);
             $response = array('status' => '1', 'message' => JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', $returnUrl), 'error' => JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', $returnUrl), 'location' => str_replace('\\', '/', $returnUrl));
             echo json_encode($response);
             return;
         }
     } else {
         $response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_BAD_REQUEST'), 'message' => JText::_('COM_MEDIA_ERROR_BAD_REQUEST'));
         echo json_encode($response);
         return;
     }
 }
开发者ID:adjaika,项目名称:J3Base,代码行数:98,代码来源:file.json.php

示例4: testToPunycode

 /**
  * Tests JStringPunycode::toPunycode
  *
  * @return  void
  *
  * @since   3.2
  */
 public function testToPunycode()
 {
     $this->assertEquals(JStringPunycode::toPunycode('http://www.джумла-тест.рф'), 'http://www.xn----7sblgc4ag8bhcd.xn--p1ai', 'Tests idna_convert encoding a UTF8 url in Cyrillic');
     $this->assertEquals(JStringPunycode::toPunycode('http://au-gré-de-nos-plumes.fr'), 'http://xn--au-gr-de-nos-plumes-fzb.fr', 'Tests idna_convert encoding a UTF8 url in French');
 }
开发者ID:n3t,项目名称:joomla-cms,代码行数:12,代码来源:JStringPunycodeTest.php


注:本文中的JStringPunycode::toPunycode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。