本文整理汇总了PHP中JStringPunycode::urlToPunycode方法的典型用法代码示例。如果您正苦于以下问题:PHP JStringPunycode::urlToPunycode方法的具体用法?PHP JStringPunycode::urlToPunycode怎么用?PHP JStringPunycode::urlToPunycode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JStringPunycode
的用法示例。
在下文中一共展示了JStringPunycode::urlToPunycode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Stores a contact
*
* @param boolean True to update fields even if they are null.
*
* @return boolean True on success, false on failure.
*
* @since 1.6
*/
public function store($updateNulls = false)
{
// Transform the params field
if (is_array($this->params)) {
$registry = new JRegistry();
$registry->loadArray($this->params);
$this->params = (string) $registry;
}
$date = JFactory::getDate();
$user = JFactory::getUser();
if ($this->id) {
// Existing item
$this->modified = $date->toSql();
$this->modified_by = $user->get('id');
} else {
// New contact. A contact created and created_by field can be set by the user,
// so we don't touch either of these if they are set.
if (!(int) $this->created) {
$this->created = $date->toSql();
}
if (empty($this->created_by)) {
$this->created_by = $user->get('id');
}
}
// Set publish_up to null date if not set
if (!$this->publish_up) {
$this->publish_up = $this->_db->getNullDate();
}
// Set publish_down to null date if not set
if (!$this->publish_down) {
$this->publish_down = $this->_db->getNullDate();
}
// Set xreference to empty string if not set
if (!$this->xreference) {
$this->xreference = '';
}
// Store utf8 email as punycode
$this->email_to = JStringPunycode::emailToPunycode($this->email_to);
// Convert IDN urls to punycode
$this->webpage = JStringPunycode::urlToPunycode($this->webpage);
// Verify that the alias is unique
$table = JTable::getInstance('Contact', 'ContactTable');
if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) {
$this->setError(JText::_('COM_CONTACT_ERROR_UNIQUE_ALIAS'));
return false;
}
return parent::store($updateNulls);
}
示例2: store
/**
* Overload the store method for the Weblinks table.
*
* @param boolean Toggle whether null values should be updated.
*
* @return boolean True on success, false on failure.
*
* @since 1.6
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
$this->modified = $date->toSql();
if ($this->id) {
// Existing item
$this->modified_by = $user->id;
} else {
// New weblink. A weblink created and created_by field can be set by the user,
// so we don't touch either of these if they are set.
if (!(int) $this->created) {
$this->created = $date->toSql();
}
if (empty($this->created_by)) {
$this->created_by = $user->id;
}
}
// Set publish_up to null date if not set
if (!$this->publish_up) {
$this->publish_up = $this->getDbo()->getNullDate();
}
// Set publish_down to null date if not set
if (!$this->publish_down) {
$this->publish_down = $this->getDbo()->getNullDate();
}
// Verify that the alias is unique
$table = JTable::getInstance('Weblink', 'WeblinksTable');
if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) {
$this->setError(JText::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS'));
return false;
}
// Convert IDN urls to punycode
$this->url = JStringPunycode::urlToPunycode($this->url);
return parent::store($updateNulls);
}
示例3: save
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function save($data)
{
$input = JFactory::getApplication()->input;
$filter = JFilterInput::getInstance();
if (isset($data['metadata']) && isset($data['metadata']['author'])) {
$data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
}
if (isset($data['created_by_alias'])) {
$data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM');
}
if (isset($data['images']) && is_array($data['images'])) {
$registry = new Registry();
$registry->loadArray($data['images']);
$data['images'] = (string) $registry;
}
JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
// Cast catid to integer for comparison
$catid = (int) $data['catid'];
// Check if New Category exists
if ($catid > 0) {
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_content');
}
// Save New Categoryg
if ($catid == 0 && $this->canCreateCategory()) {
$table = array();
$table['title'] = $data['catid'];
$table['parent_id'] = 1;
$table['extension'] = 'com_content';
$table['language'] = $data['language'];
$table['published'] = 1;
// Create new category and get catid back
$data['catid'] = CategoriesHelper::createCategory($table);
}
if (isset($data['urls']) && is_array($data['urls'])) {
$check = $input->post->get('jform', array(), 'array');
foreach ($data['urls'] as $i => $url) {
if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) {
if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) {
$data['urls'][$i] = $check['urls'][$i];
} else {
$data['urls'][$i] = JStringPunycode::urlToPunycode($url);
}
}
}
unset($check);
$registry = new Registry();
$registry->loadArray($data['urls']);
$data['urls'] = (string) $registry;
}
// Alter the title for save as copy
if ($input->get('task') == 'save2copy') {
$origTable = clone $this->getTable();
$origTable->load($input->getInt('id'));
if ($data['title'] == $origTable->title) {
list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $title;
$data['alias'] = $alias;
} else {
if ($data['alias'] == $origTable->alias) {
$data['alias'] = '';
}
}
$data['state'] = 0;
}
// Automatic handling of alias for empty fields
if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) {
if ($data['alias'] == null) {
if (JFactory::getConfig()->get('unicodeslugs') == 1) {
$data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']);
} else {
$data['alias'] = JFilterOutput::stringURLSafe($data['title']);
}
$table = JTable::getInstance('Content', 'JTable');
if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) {
$msg = JText::_('COM_CONTENT_SAVE_WARNING');
}
list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['alias'] = $alias;
if (isset($msg)) {
JFactory::getApplication()->enqueueMessage($msg, 'warning');
}
}
}
if (parent::save($data)) {
if (isset($data['featured'])) {
$this->featured($this->getState($this->getName() . '.id'), $data['featured']);
}
return true;
}
return false;
}
示例4: save
/**
* Method to save the form data.
*
* @param array The form data.
*
* @return boolean True on success.
* @since 1.6
*/
public function save($data)
{
$app = JFactory::getApplication();
if (isset($data['images']) && is_array($data['images'])) {
$registry = new JRegistry();
$registry->loadArray($data['images']);
$data['images'] = (string) $registry;
}
if (isset($data['urls']) && is_array($data['urls'])) {
foreach ($data['urls'] as $i => $url) {
if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) {
$data['urls'][$i] = JStringPunycode::urlToPunycode($url);
}
}
$registry = new JRegistry();
$registry->loadArray($data['urls']);
$data['urls'] = (string) $registry;
}
// Alter the title for save as copy
if ($app->input->get('task') == 'save2copy') {
list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $title;
$data['alias'] = $alias;
$data['state'] = 0;
}
if (parent::save($data)) {
if (isset($data['featured'])) {
$this->featured($this->getState($this->getName() . '.id'), $data['featured']);
}
$assoc = JLanguageAssociations::isEnabled();
if ($assoc) {
$id = (int) $this->getState($this->getName() . '.id');
$item = $this->getItem($id);
// Adding self to the association
$associations = $data['associations'];
foreach ($associations as $tag => $id) {
if (empty($id)) {
unset($associations[$tag]);
}
}
// Detecting all item menus
$all_language = $item->language == '*';
if ($all_language && !empty($associations)) {
JError::raiseNotice(403, JText::_('COM_CONTENT_ERROR_ALL_LANGUAGE_ASSOCIATED'));
}
$associations[$item->language] = $item->id;
// Deleting old association for these items
$db = JFactory::getDbo();
$query = $db->getQuery(true)->delete('#__associations')->where('context=' . $db->quote('com_content.item'))->where('id IN (' . implode(',', $associations) . ')');
$db->setQuery($query);
$db->execute();
if ($error = $db->getErrorMsg()) {
$this->setError($error);
return false;
}
if (!$all_language && count($associations)) {
// Adding new association for these items
$key = md5(json_encode($associations));
$query->clear()->insert('#__associations');
foreach ($associations as $id) {
$query->values($id . ',' . $db->quote('com_content.item') . ',' . $db->quote($key));
}
$db->setQuery($query);
$db->execute();
if ($error = $db->getErrorMsg()) {
$this->setError($error);
return false;
}
}
}
return true;
}
return false;
}
示例5: filterField
//.........这里部分代码省略.........
$return = JFactory::getDate($value, $offset)->toSql();
} else {
$return = '';
}
break;
// Ensures a protocol is present in the saved field. Only use when
// the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
// Ensures a protocol is present in the saved field. Only use when
// the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
case 'URL':
if (empty($value)) {
return false;
}
// This cleans some of the more dangerous characters but leaves special characters that are valid.
$value = JFilterInput::getInstance()->clean($value, 'html');
$value = trim($value);
// <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt.
$value = str_replace(array('<', '>', '"'), '', $value);
// Check for a protocol
$protocol = parse_url($value, PHP_URL_SCHEME);
// If there is no protocol and the relative option is not specified,
// we assume that it is an external URL and prepend http://.
if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) {
$protocol = 'http';
// If it looks like an internal link, then add the root.
if (substr($value, 0) == 'index.php') {
$value = JUri::root() . $value;
}
// Otherwise we treat it is an external link.
// Put the url back together.
$value = $protocol . '://' . $value;
} elseif (!$protocol && $element['relative']) {
$host = JUri::getInstance('SERVER')->gethost();
// If it starts with the host string, just prepend the protocol.
if (substr($value, 0) == $host) {
$value = 'http://' . $value;
} else {
$value = JUri::root() . $value;
}
}
$value = JStringPunycode::urlToPunycode($value);
$return = $value;
break;
case 'TEL':
$value = trim($value);
// Does it match the NANP pattern?
if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) {
$number = (string) preg_replace('/[^\\d]/', '', $value);
if (substr($number, 0, 1) == 1) {
$number = substr($number, 1);
}
if (substr($number, 0, 2) == '+1') {
$number = substr($number, 2);
}
$result = '1.' . $number;
} elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) {
$countrycode = substr($value, 0, strpos($value, ' '));
$countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode);
$number = strstr($value, ' ');
$number = (string) preg_replace('/[^\\d]/', '', $number);
$result = $countrycode . '.' . $number;
} elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) {
if (strstr($value, 'x')) {
$xpos = strpos($value, 'x');
$value = substr($value, 0, $xpos);
}
$result = str_replace('+', '', $value);
} elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) {
$result = $value;
} else {
$value = (string) preg_replace('/[^\\d]/', '', $value);
if ($value != null && strlen($value) <= 15) {
$length = strlen($value);
// If it is fewer than 13 digits assume it is a local number
if ($length <= 12) {
$result = '.' . $value;
} else {
// If it has 13 or more digits let's make a country code.
$cclen = $length - 12;
$result = substr($value, 0, $cclen) . '.' . substr($value, $cclen);
}
} else {
$result = '';
}
}
$return = $result;
break;
default:
// Check for a callback filter.
if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) {
$return = call_user_func(explode('::', $filter), $value);
} elseif (function_exists($filter)) {
$return = call_user_func($filter, $value);
} else {
$return = JFilterInput::getInstance()->clean($value, $filter);
}
break;
}
return $return;
}
示例6: store
/**
* Overriden JTable::store to set modified data.
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
$this->modified = $date->toSql();
if ($this->id) {
// Existing item
$this->modified_by = $user->get('id');
} else {
// New newsfeed. A feed created and created_by field can be set by the user,
// so we don't touch either of these if they are set.
if (!(int) $this->created) {
$this->created = $date->toSql();
}
if (empty($this->created_by)) {
$this->created_by = $user->get('id');
}
}
// Verify that the alias is unique
$table = JTable::getInstance('Newsfeed', 'NewsfeedsTable');
if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) {
$this->setError(JText::_('COM_NEWSFEEDS_ERROR_UNIQUE_ALIAS'));
return false;
}
// Save links as punycode.
$this->link = JStringPunycode::urlToPunycode($this->link);
return parent::store($updateNulls);
}
示例7: save
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 3.0
*/
public function save($data)
{
$input = JFactory::getApplication()->input;
// Alter the name for save as copy
if ($input->get('task') == 'save2copy') {
$origTable = clone $this->getTable();
$origTable->load($input->getInt('id'));
if ($data['name'] == $origTable->name) {
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
$data['name'] = $name;
$data['alias'] = $alias;
} else {
if ($data['alias'] == $origTable->alias) {
$data['alias'] = '';
}
}
$data['published'] = 0;
}
$links = array('linka', 'linkb', 'linkc', 'linkd', 'linke');
foreach ($links as $link) {
if ($data['params'][$link]) {
$data['params'][$link] = JStringPunycode::urlToPunycode($data['params'][$link]);
}
}
return parent::save($data);
}
示例8: save
/**
* Method to save the form data.
*
* @param array The form data.
*
* @return boolean True on success.
* @since 3.0
*/
public function save($data)
{
$app = JFactory::getApplication();
// Alter the title for save as copy
if ($app->input->get('task') == 'save2copy') {
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
$data['name'] = $name;
$data['alias'] = $alias;
$data['published'] = 0;
}
$links = array('linka', 'linkb', 'linkc', 'linkd', 'linke');
foreach ($links as $link) {
if ($data['params'][$link]) {
$data['params'][$link] = JStringPunycode::urlToPunycode($data['params'][$link]);
}
}
if (parent::save($data)) {
$assoc = JLanguageAssociations::isEnabled();
if ($assoc) {
$id = (int) $this->getState($this->getName() . '.id');
$item = $this->getItem($id);
// Adding self to the association
$associations = $data['associations'];
foreach ($associations as $tag => $id) {
if (empty($id)) {
unset($associations[$tag]);
}
}
// Detecting all item menus
$all_language = $item->language == '*';
if ($all_language && !empty($associations)) {
JError::raiseNotice(403, JText::_('COM_CONTACT_ERROR_ALL_LANGUAGE_ASSOCIATED'));
}
$associations[$item->language] = $item->id;
// Deleting old association for these items
$db = JFactory::getDbo();
$query = $db->getQuery(true)->delete('#__associations')->where('context=' . $db->quote('com_contact.item'))->where('id IN (' . implode(',', $associations) . ')');
$db->setQuery($query);
$db->execute();
if ($error = $db->getErrorMsg()) {
$this->setError($error);
return false;
}
if (!$all_language && count($associations)) {
// Adding new association for these items
$key = md5(json_encode($associations));
$query->clear()->insert('#__associations');
foreach ($associations as $id) {
$query->values($id . ',' . $db->quote('com_contact.item') . ',' . $db->quote($key));
}
$db->setQuery($query);
$db->execute();
if ($error = $db->getErrorMsg()) {
$this->setError($error);
return false;
}
}
}
return true;
}
return false;
}
示例9: store
/**
* Overload the store method for the Custom_admin_view table.
*
* @param boolean Toggle whether null values should be updated.
* @return boolean True on success, false on failure.
* @since 1.6
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
if ($this->id) {
// Existing item
$this->modified = $date->toSql();
$this->modified_by = $user->get('id');
} else {
// New custom_admin_view. A custom_admin_view created and created_by field can be set by the user,
// so we don't touch either of these if they are set.
if (!(int) $this->created) {
$this->created = $date->toSql();
}
if (empty($this->created_by)) {
$this->created_by = $user->get('id');
}
}
if (isset($this->alias)) {
// Verify that the alias is unique
$table = JTable::getInstance('custom_admin_view', 'ComponentbuilderTable');
if ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0)) {
$this->setError(JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ERROR_UNIQUE_ALIAS'));
return false;
}
}
if (isset($this->url)) {
// Convert IDN urls to punycode
$this->url = JStringPunycode::urlToPunycode($this->url);
}
if (isset($this->website)) {
// Convert IDN urls to punycode
$this->website = JStringPunycode::urlToPunycode($this->website);
}
return parent::store($updateNulls);
}
示例10: urlToPunycode
/**
* Helper wrapper method for urlToPunycode
*
* @param string $uri The UTF-8 URL to transform.
*
* @return string The punycode URL.
*
* @see JUserHelper::urlToPunycode()
* @since 3.4
*/
public function urlToPunycode($uri)
{
return JStringPunycode::urlToPunycode($uri);
}
示例11: dataFilter
static function dataFilter($v, $maxlength = 0, $validation = 'string', $check_callable = 0)
{
if ($validation == '-1') {
return flexicontent_html::striptagsandcut($v, $maxlength);
}
$v = $maxlength ? substr($v, 0, $maxlength) : $v;
if ($check_callable) {
if (strpos($validation, '::') !== false && is_callable(explode('::', $validation))) {
return call_user_func(explode('::', $validation), $v);
} elseif (function_exists($validation)) {
return call_user_func($validation, $v);
}
// A callback function
}
// Do filtering
if ($validation == '1') {
$safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
} else {
if ($validation != '2') {
$noHtmlFilter = JFilterInput::getInstance();
}
}
switch ($validation) {
case '1':
// Allow safe HTML
$v = $safeHtmlFilter->clean($v, 'string');
break;
case '2':
// Filter according to user group Text Filters
$v = JComponentHelper::filterText($v);
break;
case 'URL':
case 'url':
// This cleans some of the more dangerous characters but leaves special characters that are valid.
$v = trim($noHtmlFilter->clean($v, 'HTML'));
// <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt.
$v = str_replace(array('<', '>', '"'), '', $v);
// Convert to Punycode string
$v = FLEXI_J30GE ? JStringPunycode::urlToPunycode($v) : $v;
break;
case 'EMAIL':
case 'email':
// This cleans some of the more dangerous characters but leaves special characters that are valid.
$v = trim($noHtmlFilter->clean($v, 'HTML'));
// <>" are never valid in a email ?
$v = str_replace(array('<', '>', '"'), '', $v);
// Convert to Punycode string
$v = FLEXI_J30GE ? JStringPunycode::emailToPunycode($v) : $v;
// Check for valid email (punycode is ASCII so this should work with UTF-8 too)
$email_regexp = "/^[a-zA-Z0-9.!#\$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\$/";
if (!preg_match($email_regexp, $v)) {
$v = '';
}
break;
default:
// Filter using JFilterInput
$v = $noHtmlFilter->clean($v, $validation);
break;
}
$v = trim($v);
return $v;
}
示例12: onUserBeforeSave
/**
* Method is called before user data is stored in the database
*
* @param array $user Holds the old user data.
* @param boolean $isnew True if a new user is stored.
* @param array $data Holds the new user data.
*
* @return boolean
*
* @since 3.1
* @throws InvalidArgumentException on invalid date.
*/
public function onUserBeforeSave($user, $isnew, $data)
{
// Check that the date is valid.
if (!empty($data['profile']['dob'])) {
try {
// Convert website url to punycode
$data['profile']['website'] = JStringPunycode::urlToPunycode($data['profile']['website']);
$date = new JDate($data['profile']['dob']);
$this->date = $date->format('Y-m-d H:i:s');
} catch (Exception $e) {
// Throw an exception if date is not valid.
throw new InvalidArgumentException(JText::_('PLG_USER_PROFILE_ERROR_INVALID_DOB'));
}
}
return true;
}
示例13: store
/**
* Overload the store method for the Help_document table.
*
* @param boolean Toggle whether null values should be updated.
* @return boolean True on success, false on failure.
* @since 1.6
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
if ($this->id) {
// Existing item
$this->modified = $date->toSql();
$this->modified_by = $user->get('id');
} else {
// New help_document. A help_document created and created_by field can be set by the user,
// so we don't touch either of these if they are set.
if (!(int) $this->created) {
$this->created = $date->toSql();
}
if (empty($this->created_by)) {
$this->created_by = $user->get('id');
}
}
if (isset($this->alias)) {
// Verify that the alias is unique
$table = JTable::getInstance('help_document', 'DemoTable');
if ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0)) {
$this->setError(JText::_('COM_DEMO_HELP_DOCUMENT_ERROR_UNIQUE_ALIAS'));
return false;
}
}
if (isset($this->url)) {
// Convert IDN urls to punycode
$this->url = JStringPunycode::urlToPunycode($this->url);
}
if (isset($this->website)) {
// Convert IDN urls to punycode
$this->website = JStringPunycode::urlToPunycode($this->website);
}
return parent::store($updateNulls);
}
示例14: testUrlToPunycode
/**
* Tests JStringPunycode::urlToPunycode
*
* @return void
*
* @since 3.2
*/
public function testUrlToPunycode()
{
$this->assertEquals(JStringPunycode::urlToPunycode('http://www.джумла-тест.рф'), 'http://www.xn----7sblgc4ag8bhcd.xn--p1ai', 'Tests punycode encoding a UTF8 url in Cyrillic');
$this->assertEquals(JStringPunycode::urlToPunycode('http://au-gré-de-nos-plumes.fr'), 'http://xn--au-gr-de-nos-plumes-fzb.fr', 'Tests punycode encoding a UTF8 url in French');
$this->assertEquals(JStringPunycode::urlToPunycode('http://www.джумла-тест.рф#test'), 'http://www.xn----7sblgc4ag8bhcd.xn--p1ai#test', 'Tests punycode encoding a UTF8 url in Cyrillic with an anchor (See GitHub #4362)');
}
示例15: save
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function save($data)
{
$input = JFactory::getApplication()->input;
$filter = JFilterInput::getInstance();
if (isset($data['metadata']) && isset($data['metadata']['author'])) {
$data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
}
if (isset($data['created_by_alias'])) {
$data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM');
}
if (isset($data['images']) && is_array($data['images'])) {
$registry = new Registry();
$registry->loadArray($data['images']);
$data['images'] = (string) $registry;
}
if (isset($data['urls']) && is_array($data['urls'])) {
$check = $input->post->get('jform', array(), 'array');
foreach ($data['urls'] as $i => $url) {
if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) {
if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) {
$data['urls'][$i] = $check['urls'][$i];
} else {
$data['urls'][$i] = JStringPunycode::urlToPunycode($url);
}
}
}
unset($check);
$registry = new Registry();
$registry->loadArray($data['urls']);
$data['urls'] = (string) $registry;
}
// Alter the title for save as copy
if ($input->get('task') == 'save2copy') {
$origTable = clone $this->getTable();
$origTable->load($input->getInt('id'));
if ($data['title'] == $origTable->title) {
list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $title;
$data['alias'] = $alias;
} else {
if ($data['alias'] == $origTable->alias) {
$data['alias'] = '';
}
}
$data['state'] = 0;
}
// Automatic handling of alias for empty fields
if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) {
if ($data['alias'] == null) {
if (JFactory::getConfig()->get('unicodeslugs') == 1) {
$data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']);
} else {
$data['alias'] = JFilterOutput::stringURLSafe($data['title']);
}
$table = JTable::getInstance('Content', 'JTable');
if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) {
$msg = JText::_('COM_CONTENT_SAVE_WARNING');
}
list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['alias'] = $alias;
if (isset($msg)) {
JFactory::getApplication()->enqueueMessage($msg, 'warning');
}
}
}
if (parent::save($data)) {
if (isset($data['featured'])) {
$this->featured($this->getState($this->getName() . '.id'), $data['featured']);
}
return true;
}
return false;
}