Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase out JString calls in libraries #12058

Merged
merged 1 commit into from
Sep 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libraries/cms/html/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('JPATH_PLATFORM') or die;

use Joomla\String\StringHelper;

/**
* Utility class for creating different select lists
*
Expand Down Expand Up @@ -105,9 +107,9 @@ public static function genericordering($query, $chop = 30)
{
$items[$i]->text = JText::_($items[$i]->text);

if (JString::strlen($items[$i]->text) > $chop)
if (StringHelper::strlen($items[$i]->text) > $chop)
{
$text = JString::substr($items[$i]->text, 0, $chop) . "...";
$text = StringHelper::substr($items[$i]->text, 0, $chop) . "...";
}
else
{
Expand Down
24 changes: 13 additions & 11 deletions libraries/cms/html/string.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('JPATH_PLATFORM') or die;

use Joomla\String\StringHelper;

/**
* HTML helper class for rendering manipulated strings.
*
Expand Down Expand Up @@ -45,21 +47,21 @@ public static function truncate($text, $length = 0, $noSplit = true, $allowHtml
// Deal with spacing issues in the input.
$text = str_replace('>', '> ', $text);
$text = str_replace(array(' ', ' '), ' ', $text);
$text = JString::trim(preg_replace('#\s+#mui', ' ', $text));
$text = StringHelper::trim(preg_replace('#\s+#mui', ' ', $text));

// Strip the tags from the input and decode entities.
$text = strip_tags($text);
$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');

// Remove remaining extra spaces.
$text = str_replace(' ', ' ', $text);
$text = JString::trim(preg_replace('#\s+#mui', ' ', $text));
$text = StringHelper::trim(preg_replace('#\s+#mui', ' ', $text));
}

// Whether or not allowing HTML, truncate the item text if it is too long.
if ($length > 0 && JString::strlen($text) > $length)
if ($length > 0 && StringHelper::strlen($text) > $length)
{
$tmp = trim(JString::substr($text, 0, $length));
$tmp = trim(StringHelper::substr($text, 0, $length));

if (substr($tmp, 0, 1) == '<' && strpos($tmp, '>') === false)
{
Expand All @@ -70,8 +72,8 @@ public static function truncate($text, $length = 0, $noSplit = true, $allowHtml
if ($noSplit)
{
// Find the position of the last space within the allowed length.
$offset = JString::strrpos($tmp, ' ');
$tmp = JString::substr($tmp, 0, $offset + 1);
$offset = StringHelper::strrpos($tmp, ' ');
$tmp = StringHelper::substr($tmp, 0, $offset + 1);

// If there are no spaces and the string is longer than the maximum
// we need to just use the ellipsis. In that case we are done.
Expand All @@ -80,9 +82,9 @@ public static function truncate($text, $length = 0, $noSplit = true, $allowHtml
return '...';
}

if (JString::strlen($tmp) > $length - 3)
if (StringHelper::strlen($tmp) > $length - 3)
{
$tmp = trim(JString::substr($tmp, 0, JString::strrpos($tmp, ' ')));
$tmp = trim(StringHelper::substr($tmp, 0, StringHelper::strrpos($tmp, ' ')));
}
}

Expand Down Expand Up @@ -276,14 +278,14 @@ public static function truncateComplex($html, $maxLength = 0, $noSplit = true)
public static function abridge($text, $length = 50, $intro = 30)
{
// Abridge the item text if it is too long.
if (JString::strlen($text) > $length)
if (StringHelper::strlen($text) > $length)
{
// Determine the remaining text length.
$remainder = $length - ($intro + 3);

// Extract the beginning and ending text sections.
$beg = JString::substr($text, 0, $intro);
$end = JString::substr($text, JString::strlen($text) - $remainder);
$beg = StringHelper::substr($text, 0, $intro);
$end = StringHelper::substr($text, StringHelper::strlen($text) - $remainder);

// Build the resulting string.
$text = $beg . '...' . $end;
Expand Down
6 changes: 4 additions & 2 deletions libraries/cms/router/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('JPATH_PLATFORM') or die;

use Joomla\String\StringHelper;

/**
* Class to create and parse routes for the site application
*
Expand Down Expand Up @@ -311,13 +313,13 @@ protected function parseSefRoute(&$uri)
$items = $this->menu->getMenu();

$found = false;
$route_lowercase = JString::strtolower($route);
$route_lowercase = StringHelper::strtolower($route);
$lang_tag = $this->app->getLanguage()->getTag();

// Iterate through all items and check route matches.
foreach ($items as $item)
{
if ($item->route && JString::strpos($route_lowercase . '/', $item->route . '/') === 0 && $item->type != 'menulink')
if ($item->route && StringHelper::strpos($route_lowercase . '/', $item->route . '/') === 0 && $item->type != 'menulink')
{
// Usual method for non-multilingual site.
if (!$this->app->getLanguageFilter())
Expand Down
3 changes: 2 additions & 1 deletion libraries/cms/table/corecontent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('JPATH_PLATFORM') or die;

use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;

/**
Expand Down Expand Up @@ -139,7 +140,7 @@ public function check()
$bad_characters = array("\n", "\r", "\"", "<", ">");

// Remove bad characters
$after_clean = JString::str_ireplace($bad_characters, "", $this->core_metakey);
$after_clean = StringHelper::str_ireplace($bad_characters, "", $this->core_metakey);

// Create array using commas as delimiter
$keys = explode(',', $after_clean);
Expand Down
3 changes: 2 additions & 1 deletion libraries/joomla/filter/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('JPATH_PLATFORM') or die;

use Joomla\Filter\OutputFilter;
use Joomla\String\StringHelper;

/**
* JFilterOutput
Expand Down Expand Up @@ -72,7 +73,7 @@ public static function stringURLSafe($string, $language = '')
$str = $lang->transliterate($str);

// Trim white spaces at beginning and end of alias and make lowercase
$str = trim(JString::strtolower($str));
$str = trim(StringHelper::strtolower($str));

// Remove any duplicate whitespace, and ensure all characters are alphanumeric
$str = preg_replace('/(\s|[^A-Za-z0-9\-])+/', '-', $str);
Expand Down
9 changes: 6 additions & 3 deletions libraries/joomla/form/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

defined('JPATH_PLATFORM') or die;

use Joomla\String\Normalise;
use Joomla\String\StringHelper;

/**
* Abstract Form Field class for the Joomla Platform.
*
Expand Down Expand Up @@ -343,15 +346,15 @@ public function __construct($form = null)
// Detect the field type if not set
if (!isset($this->type))
{
$parts = JStringNormalise::fromCamelCase(get_called_class(), true);
$parts = Normalise::fromCamelCase(get_called_class(), true);

if ($parts[0] == 'J')
{
$this->type = JString::ucfirst($parts[count($parts) - 1], '_');
$this->type = StringHelper::ucfirst($parts[count($parts) - 1], '_');
}
else
{
$this->type = JString::ucfirst($parts[0], '_') . JString::ucfirst($parts[count($parts) - 1], '_');
$this->type = StringHelper::ucfirst($parts[0], '_') . StringHelper::ucfirst($parts[count($parts) - 1], '_');
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion libraries/joomla/form/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('JPATH_PLATFORM') or die;

use Joomla\String\StringHelper;

jimport('joomla.filesystem.path');

/**
Expand Down Expand Up @@ -169,7 +171,7 @@ protected static function loadClass($entity, $type)
list($prefix, $type) = explode('.', $type);
}

$class = JString::ucfirst($prefix, '_') . 'Form' . JString::ucfirst($entity, '_') . JString::ucfirst($type, '_');
$class = StringHelper::ucfirst($prefix, '_') . 'Form' . StringHelper::ucfirst($entity, '_') . StringHelper::ucfirst($type, '_');

if (class_exists($class))
{
Expand Down
10 changes: 6 additions & 4 deletions libraries/joomla/form/rule/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
defined('JPATH_PLATFORM') or die;

use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
use Joomla\Uri\UriHelper;

/**
* Form Rule class for the Joomla Platform.
Expand Down Expand Up @@ -45,7 +47,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
return true;
}

$urlParts = JString::parse_url($value);
$urlParts = UriHelper::parse_url($value);

// See http://www.w3.org/Addressing/URL/url-spec.txt
// Use the full list or optionally specify a list of permitted schemes.
Expand Down Expand Up @@ -76,7 +78,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
return false;
}
// The best we can do for the rest is make sure that the path exists and is valid UTF-8.
if (!array_key_exists('path', $urlParts) || !JString::valid((string) $urlParts['path']))
if (!array_key_exists('path', $urlParts) || !StringHelper::valid((string) $urlParts['path']))
{
return false;
}
Expand All @@ -103,7 +105,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry

// The best we can do for the rest is make sure that the strings are valid UTF-8
// and the port is an integer.
if (array_key_exists('host', $urlParts) && !JString::valid((string) $urlParts['host']))
if (array_key_exists('host', $urlParts) && !StringHelper::valid((string) $urlParts['host']))
{
return false;
}
Expand All @@ -113,7 +115,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
return false;
}

if (array_key_exists('path', $urlParts) && !JString::valid((string) $urlParts['path']))
if (array_key_exists('path', $urlParts) && !StringHelper::valid((string) $urlParts['path']))
{
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion libraries/joomla/language/language.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('JPATH_PLATFORM') or die;

use Joomla\String\StringHelper;

/**
* Allows for quoting in language .ini files.
*/
Expand Down Expand Up @@ -398,7 +400,7 @@ public function transliterate($string)
}

$string = JLanguageTransliterate::utf8_latin_to_ascii($string);
$string = JString::strtolower($string);
$string = StringHelper::strtolower($string);

return $string;
}
Expand Down
6 changes: 4 additions & 2 deletions libraries/joomla/string/punycode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('JPATH_PLATFORM') or die;

use Joomla\Uri\UriHelper;

JLoader::register('idna_convert', JPATH_LIBRARIES . '/idna_convert/idna_convert.class.php');

/**
Expand Down Expand Up @@ -65,7 +67,7 @@ public static function fromPunycode($punycodeString)
*/
public static function urlToPunycode($uri)
{
$parsed = JString::parse_url($uri);
$parsed = UriHelper::parse_url($uri);

if (!isset($parsed['host']) || $parsed['host'] == '')
{
Expand Down Expand Up @@ -136,7 +138,7 @@ public static function urlToUTF8($uri)
return;
}

$parsed = JString::parse_url($uri);
$parsed = UriHelper::parse_url($uri);

if (!isset($parsed['host']) || $parsed['host'] == '')
{
Expand Down
5 changes: 3 additions & 2 deletions libraries/joomla/utilities/arrayhelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

defined('JPATH_PLATFORM') or die;

use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;

/**
Expand Down Expand Up @@ -395,11 +396,11 @@ protected static function _sortObjects(&$a, &$b)
}
elseif ($caseSensitive)
{
$cmp = JString::strcmp($va, $vb, $locale);
$cmp = StringHelper::strcmp($va, $vb, $locale);
}
else
{
$cmp = JString::strcasecmp($va, $vb, $locale);
$cmp = StringHelper::strcasecmp($va, $vb, $locale);
}

if ($cmp > 0)
Expand Down
5 changes: 3 additions & 2 deletions libraries/legacy/model/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('JPATH_PLATFORM') or die;

use Joomla\Registry\Registry;
use Joomla\String\StringHelper;

/**
* Prototype admin model.
Expand Down Expand Up @@ -864,8 +865,8 @@ protected function generateNewTitle($category_id, $alias, $title)

while ($table->load(array('alias' => $alias, 'catid' => $category_id)))
{
$title = JString::increment($title);
$alias = JString::increment($alias, 'dash');
$title = StringHelper::increment($title);
$alias = StringHelper::increment($alias, 'dash');
}

return array($title, $alias);
Expand Down
3 changes: 2 additions & 1 deletion libraries/legacy/table/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('JPATH_PLATFORM') or die;

use Joomla\Registry\Registry;
use Joomla\String\StringHelper;

/**
* Content table
Expand Down Expand Up @@ -254,7 +255,7 @@ public function check()
$bad_characters = array("\n", "\r", "\"", "<", ">");

// Remove bad characters
$after_clean = JString::str_ireplace($bad_characters, "", $this->metakey);
$after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);

// Create array using commas as delimiter
$keys = explode(',', $after_clean);
Expand Down