Skip to content

Commit

Permalink
Site app & Plugins - JString -> StringHelper (#12057)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker authored and wilsonge committed Sep 17, 2016
1 parent ef6aaf3 commit a0ca6f8
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 37 deletions.
3 changes: 2 additions & 1 deletion components/com_contact/models/rules/contactemail.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

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

JFormHelper::loadRuleClass('email');

Expand Down Expand Up @@ -47,7 +48,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
{
foreach (explode(';', $banned) as $item)
{
if ($item != '' && JString::stristr($value, $item) !== false)
if ($item != '' && StringHelper::stristr($value, $item) !== false)
{
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion components/com_contact/models/rules/contactemailmessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

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

/**
* JFormRule for com_contact to make sure the message body contains no banned word.
Expand Down Expand Up @@ -40,7 +41,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
{
foreach (explode(';', $banned) as $item)
{
if ($item != '' && JString::stristr($value, $item) !== false)
if ($item != '' && StringHelper::stristr($value, $item) !== false)
{
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion components/com_contact/models/rules/contactemailsubject.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

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

/**
* JFormRule for com_contact to make sure the subject contains no banned word.
Expand Down Expand Up @@ -40,7 +41,7 @@ public function test(SimpleXMLElement $element, $value, $group = null, Registry
{
foreach (explode(';', $banned) as $item)
{
if ($item != '' && JString::stristr($value, $item) !== false)
if ($item != '' && StringHelper::stristr($value, $item) !== false)
{
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion components/com_content/models/articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

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

/**
Expand Down Expand Up @@ -501,7 +502,7 @@ protected function getListQuery()
if ((is_object($params)) && ($params->get('filter_field') != 'hide') && ($filter = $this->getState('list.filter')))
{
// Clean filter variable
$filter = JString::strtolower($filter);
$filter = StringHelper::strtolower($filter);
$hitsFilter = (int) $filter;
$filter = $db->quote('%' . $db->escape($filter, true) . '%', false);

Expand Down
15 changes: 8 additions & 7 deletions components/com_finder/models/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

defined('_JEXEC') or die;

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

// Register dependent classes.
Expand Down Expand Up @@ -376,7 +377,7 @@ protected function getResultsTotal()
foreach ($this->includedTerms as $token => $ids)
{
// Get the mapping table suffix.
$suffix = JString::substr(md5(JString::substr($token, 0, 1)), 0, 1);
$suffix = StringHelper::substr(md5(StringHelper::substr($token, 0, 1)), 0, 1);

// Initialize the mapping group.
if (!array_key_exists($suffix, $maps))
Expand Down Expand Up @@ -523,7 +524,7 @@ protected function getResultsTotal()
do
{
// Get the map table suffix.
$suffix = JString::substr(md5(JString::substr($token, 0, 1)), 0, 1);
$suffix = StringHelper::substr(md5(StringHelper::substr($token, 0, 1)), 0, 1);

// Adjust the query to join on the appropriate mapping table.
$query = clone($base);
Expand Down Expand Up @@ -654,7 +655,7 @@ protected function getResultsData()
foreach ($this->includedTerms as $token => $ids)
{
// Get the mapping table suffix.
$suffix = JString::substr(md5(JString::substr($token, 0, 1)), 0, 1);
$suffix = StringHelper::substr(md5(StringHelper::substr($token, 0, 1)), 0, 1);

// Initialize the mapping group.
if (!array_key_exists($suffix, $maps))
Expand Down Expand Up @@ -844,7 +845,7 @@ protected function getResultsData()
do
{
// Get the map table suffix.
$suffix = JString::substr(md5(JString::substr($token, 0, 1)), 0, 1);
$suffix = StringHelper::substr(md5(StringHelper::substr($token, 0, 1)), 0, 1);

// Adjust the query to join on the appropriate mapping table.
$query = clone($base);
Expand Down Expand Up @@ -942,7 +943,7 @@ protected function getExcludedLinkIds()
foreach ($this->excludedTerms as $token => $id)
{
// Get the mapping table suffix.
$suffix = JString::substr(md5(JString::substr($token, 0, 1)), 0, 1);
$suffix = StringHelper::substr(md5(StringHelper::substr($token, 0, 1)), 0, 1);

// Initialize the mapping group.
if (!array_key_exists($suffix, $maps))
Expand Down Expand Up @@ -1125,7 +1126,7 @@ protected function populateState($ordering = null, $direction = null)
* Also, we allow this parameter to be passed in either case (lower/upper).
*/
$order = $input->getWord('filter_order', $params->get('sort_order', 'relevance'));
$order = JString::strtolower($order);
$order = StringHelper::strtolower($order);
switch ($order)
{
case 'date':
Expand Down Expand Up @@ -1156,7 +1157,7 @@ protected function populateState($ordering = null, $direction = null)
* Also, we allow this parameter to be passed in either case (lower/upper).
*/
$dirn = $input->getWord('filter_order_Dir', $params->get('sort_direction', 'desc'));
$dirn = JString::strtolower($dirn);
$dirn = StringHelper::strtolower($dirn);
switch ($dirn)
{
case 'asc':
Expand Down
10 changes: 6 additions & 4 deletions components/com_finder/views/search/tmpl/default_result.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use Joomla\String\StringHelper;

// Get the mime type class.
$mime = !empty($this->result->mime) ? 'mime-' . $this->result->mime : null;

Expand All @@ -17,21 +19,21 @@
if ($show_description)
{
// Calculate number of characters to display around the result
$term_length = JString::strlen($this->query->input);
$term_length = StringHelper::strlen($this->query->input);
$desc_length = $this->params->get('description_length', 255);
$pad_length = $term_length < $desc_length ? (int) floor(($desc_length - $term_length) / 2) : 0;

// Find the position of the search term
$pos = $term_length ? JString::strpos(JString::strtolower($this->result->description), JString::strtolower($this->query->input)) : false;
$pos = $term_length ? StringHelper::strpos(StringHelper::strtolower($this->result->description), StringHelper::strtolower($this->query->input)) : false;

// Find a potential start point
$start = ($pos && $pos > $pad_length) ? $pos - $pad_length : 0;

// Find a space between $start and $pos, start right after it.
$space = JString::strpos($this->result->description, ' ', $start > 0 ? $start - 1 : 0);
$space = StringHelper::strpos($this->result->description, ' ', $start > 0 ? $start - 1 : 0);
$start = ($space && $space < $pos) ? $space + 1 : $start;

$description = JHtml::_('string.truncate', JString::substr($this->result->description, $start), $desc_length, true);
$description = JHtml::_('string.truncate', StringHelper::substr($this->result->description, $start), $desc_length, true);
}

$route = $this->result->route;
Expand Down
19 changes: 10 additions & 9 deletions components/com_search/views/search/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

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

/**
* HTML View class for the search component
Expand Down Expand Up @@ -177,8 +178,8 @@ public function display($tpl = null)
{
// E.g. german umlauts like ä are converted to ae and so
// $pos calculated with $srow desn't match for $row
$correctPos = (JString::strlen($srow) > JString::strlen($row));
$highlighterLen = JString::strlen($hl1 . $hl2);
$correctPos = (StringHelper::strlen($srow) > StringHelper::strlen($row));
$highlighterLen = StringHelper::strlen($hl1 . $hl2);
}

foreach ($searchwords as $hlword)
Expand Down Expand Up @@ -209,7 +210,7 @@ public function display($tpl = null)
}
else
{
if (($pos = JString::strpos($srow, strtolower(SearchHelper::remove_accents($hlword)))) !== false)
if (($pos = StringHelper::strpos($srow, strtolower(SearchHelper::remove_accents($hlword)))) !== false)
{
// Iconv transliterates '€' to 'EUR'
// TODO: add other expanding translations?
Expand All @@ -219,9 +220,9 @@ public function display($tpl = null)
if ($correctPos)
{
// Calculate necessary corrections from 0 to current $pos
$ChkRow = JString::substr($row, 0, $pos);
$sChkRowLen = JString::strlen(strtolower(SearchHelper::remove_accents($ChkRow)));
$ChkRowLen = JString::strlen($ChkRow);
$ChkRow = StringHelper::substr($row, 0, $pos);
$sChkRowLen = StringHelper::strlen(strtolower(SearchHelper::remove_accents($ChkRow)));
$ChkRowLen = StringHelper::strlen($ChkRow);

// Correct $pos
$pos -= ($sChkRowLen - $ChkRowLen);
Expand Down Expand Up @@ -260,9 +261,9 @@ public function display($tpl = null)
}
else
{
$hlwordLen = JString::strlen($hlword);
$row = JString::substr($row, 0, $pos) . $hl1 . JString::substr($row, $pos, JString::strlen($hlword))
. $hl2 . JString::substr($row, $pos + JString::strlen($hlword));
$hlwordLen = StringHelper::strlen($hlword);
$row = StringHelper::substr($row, 0, $pos) . $hl1 . StringHelper::substr($row, $pos, StringHelper::strlen($hlword))
. $hl2 . StringHelper::substr($row, $pos + StringHelper::strlen($hlword));
}

$cnt++;
Expand Down
6 changes: 4 additions & 2 deletions modules/mod_articles_category/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use Joomla\String\StringHelper;

$com_path = JPATH_SITE . '/components/com_content/';
require_once $com_path . 'helpers/route.php';

Expand Down Expand Up @@ -444,7 +446,7 @@ public static function groupByDate($list, $type = 'year', $article_grouping_dire
switch ($type)
{
case 'month_year' :
$month_year = JString::substr($item->created, 0, 7);
$month_year = StringHelper::substr($item->created, 0, 7);

if (!isset($grouped[$month_year]))
{
Expand All @@ -456,7 +458,7 @@ public static function groupByDate($list, $type = 'year', $article_grouping_dire

case 'year' :
default:
$year = JString::substr($item->created, 0, 4);
$year = StringHelper::substr($item->created, 0, 4);

if (!isset($grouped[$year]))
{
Expand Down
6 changes: 4 additions & 2 deletions modules/mod_footer/mod_footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

defined('_JEXEC') or die;

use Joomla\String\StringHelper;

$app = JFactory::getApplication();
$date = JFactory::getDate();
$cur_year = JHtml::_('date', $date, 'Y');
$csite_name = $app->get('sitename');

if (is_int(JString::strpos(JText :: _('MOD_FOOTER_LINE1'), '%date%')))
if (is_int(StringHelper::strpos(JText :: _('MOD_FOOTER_LINE1'), '%date%')))
{
$line1 = str_replace('%date%', $cur_year, JText :: _('MOD_FOOTER_LINE1'));
}
Expand All @@ -23,7 +25,7 @@
$line1 = JText :: _('MOD_FOOTER_LINE1');
}

if (is_int(JString::strpos($line1, '%sitename%')))
if (is_int(StringHelper::strpos($line1, '%sitename%')))
{
$lineone = str_replace('%sitename%', $csite_name, $line1);
}
Expand Down
6 changes: 4 additions & 2 deletions modules/mod_random_image/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use Joomla\String\StringHelper;

/**
* Helper for mod_random_image
*
Expand Down Expand Up @@ -139,13 +141,13 @@ public static function getFolder(&$params)
$LiveSite = JUri::base();

// If folder includes livesite info, remove
if (JString::strpos($folder, $LiveSite) === 0)
if (StringHelper::strpos($folder, $LiveSite) === 0)
{
$folder = str_replace($LiveSite, '', $folder);
}

// If folder includes absolute path, remove
if (JString::strpos($folder, JPATH_SITE) === 0)
if (StringHelper::strpos($folder, JPATH_SITE) === 0)
{
$folder = str_replace(JPATH_BASE, '', $folder);
}
Expand Down
8 changes: 5 additions & 3 deletions plugins/content/emailcloak/emailcloak.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use Joomla\String\StringHelper;

/**
* Email cloack plugin class.
*
Expand Down Expand Up @@ -98,15 +100,15 @@ protected function _cloak(&$text, &$params)
* Check for presence of {emailcloak=off} which is explicits disables this
* bot for the item.
*/
if (JString::strpos($text, '{emailcloak=off}') !== false)
if (StringHelper::strpos($text, '{emailcloak=off}') !== false)
{
$text = JString::str_ireplace('{emailcloak=off}', '', $text);
$text = StringHelper::str_ireplace('{emailcloak=off}', '', $text);

return true;
}

// Simple performance check to determine whether bot should process further.
if (JString::strpos($text, '@') === false)
if (StringHelper::strpos($text, '@') === false)
{
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/content/pagebreak/pagebreak.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use Joomla\String\StringHelper;

jimport('joomla.utilities.utility');

/**
Expand Down Expand Up @@ -72,7 +74,7 @@ public function onContentPrepare($context, &$row, &$params, $page = 0)
}

// Simple performance check to determine whether bot should process further.
if (JString::strpos($row->text, 'class="system-pagebreak') === false)
if (StringHelper::strpos($row->text, 'class="system-pagebreak') === false)
{
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/system/languagefilter/languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
defined('_JEXEC') or die;

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

JLoader::register('MenusHelper', JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php');

Expand Down Expand Up @@ -721,7 +722,7 @@ public function onAfterDispatch()

// Load component associations.
$option = $this->app->input->get('option');
$cName = JString::ucfirst(JString::str_ireplace('com_', '', $option)) . 'HelperAssociation';
$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')))
Expand Down
6 changes: 4 additions & 2 deletions plugins/user/contactcreator/contactcreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use Joomla\String\StringHelper;

/**
* Class for Contact Creator
*
Expand Down Expand Up @@ -144,10 +146,10 @@ protected function generateAliasAndName($alias, $name, $categoryId)
{
if ($name == $table->name)
{
$name = JString::increment($name);
$name = StringHelper::increment($name);
}

$alias = JString::increment($alias, 'dash');
$alias = StringHelper::increment($alias, 'dash');
}

return array($name, $alias);
Expand Down

0 comments on commit a0ca6f8

Please sign in to comment.