// autoset controllers
if (empty($this->addController)) {
- $this->addController = StringUtil::replace(array('AddForm', 'EditForm'), 'Add', $className);
+ $this->addController = str_replace(array('AddForm', 'EditForm'), 'Add', $className);
}
if (empty($this->editController)) {
- $this->editController = StringUtil::replace(array('AddForm', 'EditForm'), 'Edit', $className);
+ $this->editController = str_replace(array('AddForm', 'EditForm'), 'Edit', $className);
}
if (empty($this->listController)) {
- $this->listController = StringUtil::replace(array('AddForm', 'EditForm'), 'List', $className);
+ $this->listController = str_replace(array('AddForm', 'EditForm'), 'List', $className);
}
parent::__run();
if (isset($_POST['className'])) $this->className = StringUtil::trim($_POST['className']);
if (isset($_POST['description'])) $this->description = StringUtil::trim($_POST['description']);
- if (isset($_POST['startMinute'])) $this->startMinute = StringUtil::replace(' ', '', $_POST['startMinute']);
- if (isset($_POST['startHour'])) $this->startHour = StringUtil::replace(' ', '', $_POST['startHour']);
- if (isset($_POST['startDom'])) $this->startDom = StringUtil::replace(' ', '', $_POST['startDom']);
- if (isset($_POST['startMonth'])) $this->startMonth = StringUtil::replace(' ', '', $_POST['startMonth']);
- if (isset($_POST['startDow'])) $this->startDow = StringUtil::replace(' ', '', $_POST['startDow']);
+ if (isset($_POST['startMinute'])) $this->startMinute = str_replace(' ', '', $_POST['startMinute']);
+ if (isset($_POST['startHour'])) $this->startHour = str_replace(' ', '', $_POST['startHour']);
+ if (isset($_POST['startDom'])) $this->startDom = str_replace(' ', '', $_POST['startDom']);
+ if (isset($_POST['startMonth'])) $this->startMonth = str_replace(' ', '', $_POST['startMonth']);
+ if (isset($_POST['startDow'])) $this->startDow = str_replace(' ', '', $_POST['startDow']);
}
/**
$this->language = LanguageEditor::create(array(
'languageName' => $this->languageName,
- 'languageCode' => StringUtil::toLowerCase($this->languageCode)
+ 'languageCode' => mb_strtolower($this->languageCode)
));
$languageEditor = new LanguageEditor($this->sourceLanguage);
$languageEditor->copy($this->language);
* @see wcf\acp\form\LanguageAddForm::validateLanguageCode()
*/
protected function validateLanguageCode() {
- if ($this->language->languageCode != StringUtil::toLowerCase($this->languageCode)) {
+ if ($this->language->languageCode != mb_strtolower($this->languageCode)) {
parent::validateLanguageCode();
}
}
$editor = new LanguageEditor($this->language);
$editor->update(array(
'languageName' => $this->languageName,
- 'languageCode' => StringUtil::toLowerCase($this->languageCode)
+ 'languageCode' => mb_strtolower($this->languageCode)
));
LanguageFactory::getInstance()->clearCache();
$this->saved();
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->languageID));
while ($row = $statement->fetchArray()) {
- $row['packageNameLength'] = StringUtil::length(WCF::getLanguage()->get($row['packageName']));
+ $row['packageNameLength'] = mb_strlen(WCF::getLanguage()->get($row['packageName']));
$this->packages[] = new Package(null, $row);
if ($row['packageNameLength'] > $this->packageNameLength) {
$this->packageNameLength = $row['packageNameLength'];
if (!empty($this->url)) {
// append session
- if (StringUtil::indexOf($this->url, '?') !== false) $this->url .= SID_ARG_2ND_NOT_ENCODED;
+ if (mb_strpos($this->url, '?') !== false) $this->url .= SID_ARG_2ND_NOT_ENCODED;
else $this->url .= SID_ARG_1ST;
HeaderUtil::redirect($this->url);
}
public function readData() {
parent::readData();
- if (empty($_POST) && StringUtil::indexOf(WCF::getSession()->requestURI, 'MasterPassword') === false) {
+ if (empty($_POST) && mb_strpos(WCF::getSession()->requestURI, 'MasterPassword') === false) {
$this->url = WCF::getSession()->requestURI;
}
}
}
// check password security
- if (StringUtil::length($this->masterPassword) < 8) {
+ if (mb_strlen($this->masterPassword) < 8) {
throw new UserInputException('masterPassword', 'notSecure');
}
// digits
parent::save();
// get style filename
- $filename = str_replace(' ', '-', preg_replace('/[^a-z0-9 _-]/', '', StringUtil::toLowerCase($this->style->styleName)));
+ $filename = str_replace(' ', '-', preg_replace('/[^a-z0-9 _-]/', '', mb_strtolower($this->style->styleName)));
// send headers
header('Content-Type: application/x-gzip; charset=utf-8');
// validate synonyms
foreach ($this->synonyms as $key => $synonym) {
- if (StringUtil::toLowerCase($synonym) == StringUtil::toLowerCase($this->name)) {
+ if (mb_strtolower($synonym) == mb_strtolower($this->name)) {
unset($this->synonyms[$key]);
}
}
// validate user title
try {
- if (StringUtil::length($this->userTitle) > USER_TITLE_MAX_LENGTH) {
+ if (mb_strlen($this->userTitle) > USER_TITLE_MAX_LENGTH) {
throw new UserInputException('userTitle', 'tooLong');
}
if (!StringUtil::executeWordFilter($this->userTitle, USER_FORBIDDEN_TITLES)) {
}
// check confirm input
- if (StringUtil::toLowerCase($email) != StringUtil::toLowerCase($confirmEmail)) {
+ if (mb_strtolower($email) != mb_strtolower($confirmEmail)) {
throw new UserInputException('confirmEmail', 'notEqual');
}
}
* @see wcf\acp\form\UserAddForm::validateUsername()
*/
protected function validateUsername($username) {
- if (StringUtil::toLowerCase($this->user->username) != StringUtil::toLowerCase($username)) {
+ if (mb_strtolower($this->user->username) != mb_strtolower($username)) {
parent::validateUsername($username);
}
}
* @see wcf\acp\form\UserAddForm::validateEmail()
*/
protected function validateEmail($email, $confirmEmail) {
- if (StringUtil::toLowerCase($this->user->email) != StringUtil::toLowerCase($email)) {
+ if (mb_strtolower($this->user->email) != mb_strtolower($email)) {
parent::validateEmail($email, $this->confirmEmail);
}
}
// autoset controllers
if (empty($this->addController)) {
- $this->addController = StringUtil::replace('ListPage', 'Add', $className);
+ $this->addController = str_replace('ListPage', 'Add', $className);
}
if (empty($this->editController)) {
- $this->editController = StringUtil::replace('ListPage', 'Edit', $className);
+ $this->editController = str_replace('ListPage', 'Edit', $className);
}
parent::__run();
foreach ($this->logFiles as $logFile) {
$contents = file_get_contents($logFile);
- if (StringUtil::indexOf($contents, '<<<<<<<<'.$this->exceptionID.'<<<<') !== false) {
+ if (mb_strpos($contents, '<<<<<<<<'.$this->exceptionID.'<<<<') !== false) {
$fileNameRegex->match($logFile);
$matches = $fileNameRegex->getMatches();
$this->logFile = $matches[0];
if ($this->user->enableGravatar) {
// try to use cached gravatar
- $cachedFilename = sprintf(Gravatar::GRAVATAR_CACHE_LOCATION, md5(StringUtil::toLowerCase($this->user->email)), $this->size);
+ $cachedFilename = sprintf(Gravatar::GRAVATAR_CACHE_LOCATION, md5(mb_strtolower($this->user->email)), $this->size);
if (file_exists(WCF_DIR.$cachedFilename) && filemtime(WCF_DIR.$cachedFilename) > (TIME_NOW - (Gravatar::GRAVATAR_CACHE_EXPIRE * 86400))) {
@header('Content-Type: image/png');
@readfile(WCF_DIR.$cachedFilename);
}
// try to download new version
- $gravatarURL = sprintf(Gravatar::GRAVATAR_BASE, md5(StringUtil::toLowerCase($this->user->email)), $this->size, '404');
+ $gravatarURL = sprintf(Gravatar::GRAVATAR_BASE, md5(mb_strtolower($this->user->email)), $this->size, '404');
try {
$tmpFile = FileUtil::downloadFileFromHttp($gravatarURL, 'gravatar');
copy($tmpFile, WCF_DIR.$cachedFilename);
if (empty($this->className)) {
$className = get_called_class();
- if (StringUtil::substring($className, -6) == 'Action') {
- $this->className = StringUtil::substring($className, 0, -6).'Editor';
+ if (mb_substr($className, -6) == 'Action') {
+ $this->className = mb_substr($className, 0, -6).'Editor';
}
}
if (empty($this->className)) {
$className = get_called_class();
- if (StringUtil::substring($className, -4) == 'List') {
- $this->className = StringUtil::substring($className, 0, -4);
+ if (mb_substr($className, -4) == 'List') {
+ $this->className = mb_substr($className, 0, -4);
}
}
$output = $this->html;
foreach ($regex->getMatches() as $name => $value) {
- $output = StringUtil::replace('{$'.$name.'}', $value, $output);
+ $output = str_replace('{$'.$name.'}', $value, $output);
}
return $output;
}
foreach ($options as $item) {
if ($item{0} == '!') {
if (!empty($disableOptions)) $disableOptions .= ',';
- $disableOptions .= "'".StringUtil::substring($item, 1)."' ";
+ $disableOptions .= "'".mb_substr($item, 1)."' ";
}
else {
if (!empty($enableOptions)) $enableOptions .= ',';
$options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($this->selectOptions)));
foreach ($options as $option) {
$key = $value = $option;
- if (StringUtil::indexOf($option, ':') !== false) {
+ if (mb_strpos($option, ':') !== false) {
$optionData = explode(':', $option);
$key = array_shift($optionData);
$value = implode(':', $optionData);
$options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($this->enableOptions)));
$key = -1;
foreach ($options as $option) {
- if (StringUtil::indexOf($option, ':') !== false) {
+ if (mb_strpos($option, ':') !== false) {
$optionData = explode(':', $option);
$key = array_shift($optionData);
$value = implode(':', $optionData);
* @return boolean
*/
public static function checkFromversion($currentVersion, $fromversion) {
- if (StringUtil::indexOf($fromversion, '*') !== false) {
+ if (mb_strpos($fromversion, '*') !== false) {
// from version with wildcard
// use regular expression
- $fromversion = StringUtil::replace('\*', '.*', preg_quote($fromversion, '!'));
+ $fromversion = str_replace('\*', '.*', preg_quote($fromversion, '!'));
if (preg_match('!^'.$fromversion.'$!i', $currentVersion)) {
return true;
}
*/
public function getHighlightedURL() {
$host = parse_url($this->serverURL, PHP_URL_HOST);
- return StringUtil::replace($host, '<strong>'.$host.'</strong>', $this->serverURL);
+ return str_replace($host, '<strong>'.$host.'</strong>', $this->serverURL);
}
}
// copy preview image
if ($this->styleEditor->image) {
// get extension
- $fileExtension = StringUtil::substring($this->styleEditor->image, StringUtil::lastIndexOf($this->styleEditor->image, '.'));
+ $fileExtension = mb_substr($this->styleEditor->image, mb_strrpos($this->styleEditor->image, '.'));
// copy existing preview image
if (@copy(WCF_DIR.'images/'.$this->styleEditor->image, WCF_DIR.'images/stylePreview-'.$newStyle->styleID.$fileExtension)) {
if (!empty($data['templates'])) {
$templateGroupName = $originalTemplateGroupName = $data['name'];
$templateGroupFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templateGroupName);
- if (empty($templateGroupFolderName)) $templateGroupFolderName = 'generic'.StringUtil::substring(StringUtil::getRandomID(), 0, 8);
+ if (empty($templateGroupFolderName)) $templateGroupFolderName = 'generic'.mb_substr(StringUtil::getRandomID(), 0, 8);
$originalTemplateGroupFolderName = $templateGroupFolderName;
// get unique template pack name
TemplateEditor::create(array(
'application' => Package::getAbbreviation($package),
'packageID' => $row['packageID'],
- 'templateName' => StringUtil::replace('.tpl', '', $template['filename']),
+ 'templateName' => str_replace('.tpl', '', $template['filename']),
'templateGroupID' => $styleData['templateGroupID']
));
}
// import preview image
if (!empty($data['image'])) {
- $fileExtension = StringUtil::substring($data['image'], StringUtil::lastIndexOf($data['image'], '.'));
+ $fileExtension = mb_substr($data['image'], mb_strrpos($data['image'], '.'));
$index = $tar->getIndexByFilename($data['image']);
if ($index !== false) {
$filename = WCF_DIR.'images/stylePreview-'.$style->styleID.$fileExtension;
// search
if ($useRegex) $matches = (intval(preg_match('/'.$search.'/s'.(!$caseSensitive ? 'i' : ''), $template->getSource())) !== 0);
else {
- if ($caseSensitive) $matches = (StringUtil::indexOf($template->getSource(), $search) !== false);
- else $matches = (StringUtil::indexOfIgnoreCase($template->getSource(), $search) !== false);
+ if ($caseSensitive) $matches = (mb_strpos($template->getSource(), $search) !== false);
+ else $matches = (mb_strripos($template->getSource(), $search) !== false);
}
if (($matches && !$invertSearch) || (!$matches && $invertSearch)) {
$newSource = preg_replace('/'.$search.'/s'.(!$caseSensitive ? 'i' : ''), $replace, $template->getSource(), -1, $matches);
}
else {
- if ($caseSensitive) $newSource = StringUtil::replace($search, $replace, $template->getSource(), $matches);
+ if ($caseSensitive) $newSource = str_replace($search, $replace, $template->getSource(), $matches);
else $newSource = StringUtil::replaceIgnoreCase($search, $replace, $template->getSource(), $matches);
}
foreach ($accessibleGroups as $group) {
$groupName = $group->getName();
if (!in_array($groupName, $excludedSearchValues)) {
- $pos = StringUtil::indexOfIgnoreCase($groupName, $searchString);
+ $pos = mb_strripos($groupName, $searchString);
if ($pos !== false && $pos == 0) {
$list[] = array(
'label' => $groupName,
// save case sensitive usernames
$caseSensitiveUsernames = array();
foreach ($usernames as &$username) {
- $tmp = StringUtil::toLowerCase($username);
+ $tmp = mb_strtolower($username);
$caseSensitiveUsernames[$tmp] = $username;
$username = $tmp;
}
// check cache
foreach ($usernames as $index => $username) {
foreach (self::$userProfiles as $user) {
- if (StringUtil::toLowerCase($user->username) === $username) {
+ if (mb_strtolower($user->username) === $username) {
$users[$username] = $user;
unset($usernames[$index]);
}
$userList->readObjects();
foreach ($userList as $user) {
- $users[StringUtil::toLowerCase($user->username)] = $user;
+ $users[mb_strtolower($user->username)] = $user;
self::$userProfiles[$user->userID] = $user;
}
return '';
}
- return StringUtil::substring($this->authData, 0, StringUtil::indexOf($this->authData, ':'));
+ return mb_substr($this->authData, 0, mb_strpos($this->authData, ':'));
}
/**
// validate user title
if ($userTitle !== null) {
try {
- if (StringUtil::length($userTitle) > USER_TITLE_MAX_LENGTH) {
+ if (mb_strlen($userTitle) > USER_TITLE_MAX_LENGTH) {
throw new UserInputException('__userTitle', 'tooLong');
}
if (!StringUtil::executeWordFilter($userTitle, USER_FORBIDDEN_TITLES)) {
if (!isset($this->url[$size])) {
// try to use cached gravatar
- $cachedFilename = sprintf(self::GRAVATAR_CACHE_LOCATION, md5(StringUtil::toLowerCase($this->gravatar)), $size);
+ $cachedFilename = sprintf(self::GRAVATAR_CACHE_LOCATION, md5(mb_strtolower($this->gravatar)), $size);
if (file_exists(WCF_DIR.$cachedFilename) && filemtime(WCF_DIR.$cachedFilename) > (TIME_NOW - (self::GRAVATAR_CACHE_EXPIRE * 86400))) {
$this->url[$size] = WCF::getPath().$cachedFilename;
}
* @return boolean
*/
public static function test($email) {
- $gravatarURL = sprintf(self::GRAVATAR_BASE, md5(StringUtil::toLowerCase($email)), 80, '404');
+ $gravatarURL = sprintf(self::GRAVATAR_BASE, md5(mb_strtolower($email)), 80, '404');
try {
$tmpFile = FileUtil::downloadFileFromHttp($gravatarURL, 'gravatar');
@unlink($tmpFile);
// user name
if (WCF::getSession()->getPermission('user.profile.canRename') && $this->username != WCF::getUser()->username) {
- if (StringUtil::toLowerCase($this->username) != StringUtil::toLowerCase(WCF::getUser()->username)) {
+ if (mb_strtolower($this->username) != mb_strtolower(WCF::getUser()->username)) {
if (WCF::getUser()->lastUsernameChange + WCF::getSession()->getPermission('user.profile.renamePeriod') * 86400 > TIME_NOW) {
throw new UserInputException('username', 'alreadyRenamed');
}
}
// checks if only letter case has changed
- if (StringUtil::toLowerCase($this->email) != StringUtil::toLowerCase(WCF::getUser()->email)) {
+ if (mb_strtolower($this->email) != mb_strtolower(WCF::getUser()->email)) {
// check for valid email (one @ etc.)
if (!UserRegistrationUtil::isValidEmail($this->email)) {
throw new UserInputException('email', 'notValid');
}
// checks confirm input
- if (StringUtil::toLowerCase($this->email) != StringUtil::toLowerCase($this->confirmEmail)) {
+ if (mb_strtolower($this->email) != mb_strtolower($this->confirmEmail)) {
throw new UserInputException('confirmEmail', 'notEqual');
}
}
// user name
if (WCF::getSession()->getPermission('user.profile.canRename') && $this->username != WCF::getUser()->username) {
- if (StringUtil::toLowerCase($this->username) != StringUtil::toLowerCase(WCF::getUser()->username)) {
+ if (mb_strtolower($this->username) != mb_strtolower(WCF::getUser()->username)) {
$updateParameters['lastUsernameChange'] = TIME_NOW;
$updateParameters['oldUsername'] = $userEditor->username;
}
// email
if (WCF::getSession()->getPermission('user.profile.canChangeEmail') && $this->email != WCF::getUser()->email && $this->email != WCF::getUser()->newEmail) {
- if (REGISTER_ACTIVATION_METHOD == 0 || REGISTER_ACTIVATION_METHOD == 2 || StringUtil::toLowerCase($this->email) == StringUtil::toLowerCase(WCF::getUser()->email)) {
+ if (REGISTER_ACTIVATION_METHOD == 0 || REGISTER_ACTIVATION_METHOD == 2 || mb_strtolower($this->email) == mb_strtolower(WCF::getUser()->email)) {
// update email
$updateParameters['email'] = $this->email;
$success[] = 'wcf.user.changeEmail.success';
* Gets the redirect url.
*/
protected function checkURL() {
- if (empty($this->url) || StringUtil::indexOf($this->url, 'index.php/Login/') !== false) {
+ if (empty($this->url) || mb_strpos($this->url, 'index.php/Login/') !== false) {
$this->url = LinkHandler::getInstance()->getLink();
}
// append missing session id
else if (SID_ARG_1ST != '' && !preg_match('/(?:&|\?)s=[a-z0-9]{40}/', $this->url)) {
- if (StringUtil::indexOf($this->url, '?') !== false) $this->url .= SID_ARG_2ND_NOT_ENCODED;
+ if (mb_strpos($this->url, '?') !== false) $this->url .= SID_ARG_2ND_NOT_ENCODED;
else $this->url .= SID_ARG_1ST;
}
}
throw new UserInputException('subject');
}
- if (StringUtil::length($this->subject) > 255) {
+ if (mb_strlen($this->subject) > 255) {
throw new UserInputException('subject', 'tooLong');
}
}
// check text length
- if ($this->maxTextLength != 0 && StringUtil::length($this->text) > $this->maxTextLength) {
+ if ($this->maxTextLength != 0 && mb_strlen($this->text) > $this->maxTextLength) {
throw new UserInputException('text', 'tooLong');
}
parent::readParameters();
// letter
- if (isset($_REQUEST['letter']) && StringUtil::length($_REQUEST['letter']) == 1 && StringUtil::indexOf(self::$availableLetters, $_REQUEST['letter']) !== false) {
+ if (isset($_REQUEST['letter']) && mb_strlen($_REQUEST['letter']) == 1 && mb_strpos(self::$availableLetters, $_REQUEST['letter']) !== false) {
$this->letter = $_REQUEST['letter'];
}
self::getTPL()->registerPrefilter(array('event', 'hascontent', 'lang'));
self::getTPL()->assign(array(
'__wcf' => $this,
- '__wcfVersion' => StringUtil::substring(sha1(WCF_VERSION), 0, 8)
+ '__wcfVersion' => mb_substr(sha1(WCF_VERSION), 0, 8)
));
}
$path = FileUtil::removeLeadingSlash($path);
$baseHref = self::getTPL()->get('baseHref');
- if (!empty($path) && StringUtil::indexOf($path, '?') !== 0) {
+ if (!empty($path) && mb_strpos($path, '?') !== 0) {
$baseHref .= 'index.php/';
}
// write configuration to config.inc.php
$file = new File(WCF_DIR.'config.inc.php');
$file->write("<?php\n");
- $file->write("\$dbHost = '".StringUtil::replace("'", "\\'", $dbHost)."';\n");
+ $file->write("\$dbHost = '".str_replace("'", "\\'", $dbHost)."';\n");
$file->write("\$dbPort = ".$dbPort.";\n");
- $file->write("\$dbUser = '".StringUtil::replace("'", "\\'", $dbUser)."';\n");
- $file->write("\$dbPassword = '".StringUtil::replace("'", "\\'", $dbPassword)."';\n");
- $file->write("\$dbName = '".StringUtil::replace("'", "\\'", $dbName)."';\n");
- $file->write("\$dbClass = '".StringUtil::replace("'", "\\'", $dbClass)."';\n");
+ $file->write("\$dbUser = '".str_replace("'", "\\'", $dbUser)."';\n");
+ $file->write("\$dbPassword = '".str_replace("'", "\\'", $dbPassword)."';\n");
+ $file->write("\$dbName = '".str_replace("'", "\\'", $dbName)."';\n");
+ $file->write("\$dbClass = '".str_replace("'", "\\'", $dbClass)."';\n");
$file->write("if (!defined('WCF_N')) define('WCF_N', $dbNumber);\n?>");
$file->close();
$sql = file_get_contents(TMP_DIR.'setup/db/install.sql');
// installation number value 'n' (WCF_N) must be reflected in the executed sql queries
- $sql = StringUtil::replace('wcf1_', 'wcf'.$dbNumber.'_', $sql);
+ $sql = str_replace('wcf1_', 'wcf'.$dbNumber.'_', $sql);
// get all tablenames which should be created
preg_match_all("%CREATE\s+TABLE\s+(\w+)%", $sql, $matches);
$sql = $sqlData[$offset];
// installation number value 'n' (WCF_N) must be reflected in the executed sql queries
- $sql = StringUtil::replace('wcf1_', 'wcf'.WCF_N.'_', $sql);
+ $sql = str_replace('wcf1_', 'wcf'.WCF_N.'_', $sql);
// execute sql queries
$parser = new SQLParser($sql);
}
else {
// regular file
- $fileInserts[] = StringUtil::replace(WCF_DIR, '', $file);
+ $fileInserts[] = str_replace(WCF_DIR, '', $file);
}
}
file_put_contents(WCF_DIR.'__wcfSetupPerformance.log', "\tRead files: " . round(microtime(true) - $start, 3) . "\n", FILE_APPEND);
$otherPackages = array();
$tar = new Tar(SETUP_FILE);
foreach ($tar->getContentList() as $file) {
- if ($file['type'] != 'folder' && StringUtil::indexOf($file['filename'], 'install/packages/') === 0) {
+ if ($file['type'] != 'folder' && mb_strpos($file['filename'], 'install/packages/') === 0) {
$packageFile = basename($file['filename']);
// ignore any files which aren't an archive
// get package name
$tar = new Tar(SETUP_FILE);
foreach ($tar->getContentList() as $file) {
- if ($file['type'] != 'folder' && StringUtil::indexOf($file['filename'], 'install/packages/') === 0) {
+ if ($file['type'] != 'folder' && mb_strpos($file['filename'], 'install/packages/') === 0) {
$packageFile = basename($file['filename']);
$packageName = preg_replace('!\.(tar\.gz|tgz|tar)$!', '', $packageFile);
$optionList = new ACLOptionList();
if (!empty($categoryName)) {
if (StringUtil::endsWith($categoryName, '.*')) {
- $categoryName = StringUtil::substring($categoryName, 0, -1) . '%';
+ $categoryName = mb_substr($categoryName, 0, -1) . '%';
$optionList->getConditionBuilder()->add("acl_option.categoryName LIKE ?", array($categoryName));
}
else {
protected function buildTag($string) {
$tag = array('name' => '', 'closing' => false, 'source' => $string);
- if (StringUtil::substring($string, 1, 1) == '/') {
+ if (mb_substr($string, 1, 1) == '/') {
// closing tag
- $tag['name'] = StringUtil::toLowerCase(StringUtil::substring($string, 2, StringUtil::length($string) - 3));
+ $tag['name'] = mb_strtolower(mb_substr($string, 2, mb_strlen($string) - 3));
$tag['closing'] = true;
}
else {
// opening tag
// split tag and attributes
preg_match("!^\[([a-z0-9]+)=?(.*)]$!si", $string, $match);
- $tag['name'] = StringUtil::toLowerCase($match[1]);
+ $tag['name'] = mb_strtolower($match[1]);
// build attributes
if (!empty($match[2])) {
// remove quotes
for ($i = 0, $j = count($matches[1]); $i < $j; $i++) {
- if (StringUtil::substring($matches[1][$i], 0, 1) == "'" && StringUtil::substring($matches[1][$i], -1) == "'") {
- $matches[1][$i] = StringUtil::replace("\'", "'", $matches[1][$i]);
- $matches[1][$i] = StringUtil::replace("\\\\", "\\", $matches[1][$i]);
+ if (mb_substr($matches[1][$i], 0, 1) == "'" && mb_substr($matches[1][$i], -1) == "'") {
+ $matches[1][$i] = str_replace("\'", "'", $matches[1][$i]);
+ $matches[1][$i] = str_replace("\\\\", "\\", $matches[1][$i]);
- $matches[1][$i] = StringUtil::substring($matches[1][$i], 1, -1);
+ $matches[1][$i] = mb_substr($matches[1][$i], 1, -1);
}
}
// fetch highlighter-classname
$className = '\wcf\system\bbcode\highlighter\PlainHighlighter';
if ($this->codeType) {
- $className = '\wcf\system\bbcode\highlighter\\'.StringUtil::firstCharToUpperCase(StringUtil::toLowerCase($this->codeType)).'Highlighter';
+ $className = '\wcf\system\bbcode\highlighter\\'.StringUtil::firstCharToUpperCase(mb_strtolower($this->codeType)).'Highlighter';
- switch (StringUtil::substring($className, strlen('\wcf\system\bbcode\highlighter\\'))) {
+ switch (mb_substr($className, strlen('\wcf\system\bbcode\highlighter\\'))) {
case 'ShellHighlighter':
$className = '\wcf\system\bbcode\highlighter\BashHighlighter';
break;
}
else {
// try to guess highlighter
- if (StringUtil::indexOf($content, '<?php') !== false) {
+ if (mb_strpos($content, '<?php') !== false) {
$className = '\wcf\system\bbcode\highlighter\PhpHighlighter';
}
- else if (StringUtil::indexOf($content, '<html') !== false) {
+ else if (mb_strpos($content, '<html') !== false) {
$className = '\wcf\system\bbcode\highlighter\HtmlHighlighter';
}
- else if (StringUtil::indexOf($content, '<?xml') === 0) {
+ else if (mb_strpos($content, '<?xml') === 0) {
$className = '\wcf\system\bbcode\highlighter\XmlHighlighter';
}
- else if ( StringUtil::indexOf($content, 'SELECT') === 0
- || StringUtil::indexOf($content, 'UPDATE') === 0
- || StringUtil::indexOf($content, 'INSERT') === 0
- || StringUtil::indexOf($content, 'DELETE') === 0) {
+ else if ( mb_strpos($content, 'SELECT') === 0
+ || mb_strpos($content, 'UPDATE') === 0
+ || mb_strpos($content, 'INSERT') === 0
+ || mb_strpos($content, 'DELETE') === 0) {
$className = '\wcf\system\bbcode\highlighter\SqlHighlighter';
}
- else if (StringUtil::indexOf($content, 'import java.') !== false) {
+ else if (mb_strpos($content, 'import java.') !== false) {
$className = '\wcf\system\bbcode\highlighter\JavaHighlighter';
}
- else if ( StringUtil::indexOf($content, "---") !== false
- && StringUtil::indexOf($content, "\n+++") !== false) {
+ else if ( mb_strpos($content, "---") !== false
+ && mb_strpos($content, "\n+++") !== false) {
$className = '\wcf\system\bbcode\highlighter\DiffHighlighter';
}
- else if (StringUtil::indexOf($content, "\n#include ") !== false) {
+ else if (mb_strpos($content, "\n#include ") !== false) {
$className = '\wcf\system\bbcode\highlighter\CHighlighter';
}
- else if (StringUtil::indexOf($content, '#!/usr/bin/perl') === 0) {
+ else if (mb_strpos($content, '#!/usr/bin/perl') === 0) {
$className = '\wcf\system\bbcode\highlighter\PerlHighlighter';
}
- else if (StringUtil::indexOf($content, 'def __init__(self') !== false) {
+ else if (mb_strpos($content, 'def __init__(self') !== false) {
$className = '\wcf\system\bbcode\highlighter\PythonHighlighter';
}
else if (Regex::compile('^#!/bin/(ba|z)?sh')->match($content)) {
$className = '\wcf\system\bbcode\highlighter\BashHighlighter';
}
- else if (StringUtil::indexOf($content, '\\documentclass') !== false) {
+ else if (mb_strpos($content, '\\documentclass') !== false) {
$className = '\wcf\system\bbcode\highlighter\TexHighlighter';
}
else if (Regex::compile('[-\\+\\.,\\[\\]\\>\\<]{9}')->match($content)) {
if (is_numeric($attributes[0])) {
$this->startLineNumber = intval($attributes[0]);
}
- else if (StringUtil::indexOf($attributes[0], '.') === false) {
+ else if (mb_strpos($attributes[0], '.') === false) {
$this->codeType = $attributes[0];
}
else {
case 2:
if (is_numeric($attributes[0])) {
$this->startLineNumber = intval($attributes[0]);
- if (StringUtil::indexOf($attributes[1], '.') === false) {
+ if (mb_strpos($attributes[1], '.') === false) {
$this->codeType = $attributes[1];
}
else {
$i = -1;
// find an unused codeID
do {
- $codeID = StringUtil::substring(StringUtil::getHash($code), 0, 6).(++$i ? '_'.$i : '');
+ $codeID = mb_substr(StringUtil::getHash($code), 0, 6).(++$i ? '_'.$i : '');
}
while (isset(self::$codeIDs[$codeID]));
// remove search operators
$keywordString = preg_replace('/[\+\-><()~]+/', '', $keywordString);
- if (StringUtil::substring($keywordString, 0, 1) == '"' && StringUtil::substring($keywordString, -1) == '"') {
+ if (mb_substr($keywordString, 0, 1) == '"' && mb_substr($keywordString, -1) == '"') {
// phrases search
- $keywordString = StringUtil::trim(StringUtil::substring($keywordString, 1, -1));
+ $keywordString = StringUtil::trim(mb_substr($keywordString, 1, -1));
if (!empty($keywordString)) {
$this->keywords = array_merge($this->keywords, array(StringUtil::encodeHTML($keywordString)));
if (empty($this->keywords)) return $text;
$keywordPattern = '('.implode('|', $this->keywords).')';
- $keywordPattern = StringUtil::replace('\*', '\w*', $keywordPattern);
+ $keywordPattern = str_replace('\*', '\w*', $keywordPattern);
return preg_replace('+(?<!&|&\w{1}|&\w{2}|&\w{3}|&\w{4}|&\w{5}|&\w{6})'.$keywordPattern.'(?![^<]*>)+i', '<span class="highlight">\\1</span>', $text);
}
}
* @see wcf\system\bbcode\IBBCode::getParsedTag()
*/
public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) {
- if (StringUtil::indexOf($content, '[*]') !== false) {
+ if (mb_strpos($content, '[*]') !== false) {
// get list elements
$listElements = preg_split('/\[\*\]/', StringUtil::trim($content), -1, PREG_SPLIT_NO_EMPTY);
* Handles pre-parsing of email addresses.
*/
protected function parseEmails() {
- if (StringUtil::indexOf($this->text, '@') === false) return;
+ if (mb_strpos($this->text, '@') === false) return;
static $emailPattern = null;
if ($emailPattern === null) {
$text = preg_replace_callback($urlPattern, array($this, 'parseURLsCallback'), $text);
// parse emails
- if (StringUtil::indexOf($text, '@') !== false) {
+ if (mb_strpos($text, '@') !== false) {
$text = preg_replace($emailPattern, '<a href="mailto:\\0">\\0</a>', $text);
}
public function highlight($data) {
$lines = explode("\n", $data);
foreach ($lines as $key => $val) {
- if (in_array(StringUtil::substring($val, 0, 1), $this->info) || in_array($val, $this->splitter)) {
+ if (in_array(mb_substr($val, 0, 1), $this->info) || in_array($val, $this->splitter)) {
$lines[$key] = '<span class="hlComments">'.StringUtil::encodeHTML($val).'</span>';
}
- else if (in_array(StringUtil::substring($val, 0, 1), $this->add)) {
+ else if (in_array(mb_substr($val, 0, 1), $this->add)) {
$lines[$key] = '<span class="hlAdded">'.StringUtil::encodeHTML($val).'</span>';
}
- else if (in_array(StringUtil::substring($val, 0, 1), $this->delete)) {
+ else if (in_array(mb_substr($val, 0, 1), $this->delete)) {
$lines[$key] = '<span class="hlRemoved">'.StringUtil::encodeHTML($val).'</span>';
}
else {
public function highlight($code) {
// add starting php tag
$phpTagsAdded = false;
- if (StringUtil::indexOf($code, '<?') === false) {
+ if (mb_strpos($code, '<?') === false) {
$phpTagsAdded = true;
$code = '<?php '.$code.' ?>';
}
public function setURL($url, $appendSession = false) {
// append session id
if ($appendSession) {
- if (StringUtil::indexOf($url, '?') === false) {
+ if (mb_strpos($url, '?') === false) {
$url .= SID_ARG_1ST;
}
else {
protected function getCacheName(ICacheBuilder $cacheBuilder, array $parameters = array()) {
$className = explode('\\', get_class($cacheBuilder));
$application = array_shift($className);
- $cacheName = StringUtil::replace('CacheBuilder', '', array_pop($className));
+ $cacheName = str_replace('CacheBuilder', '', array_pop($className));
if (!empty($parameters)) {
$cacheName .= '-' . $this->getCacheIndex($parameters);
}
$token = $user->notificationMailToken;
if (!$token) {
// generate token if not present
- $token = StringUtil::substring(StringUtil::getHash(serialize(array($user->userID, StringUtil::getRandomID()))), 0, 20);
+ $token = mb_substr(StringUtil::getHash(serialize(array($user->userID, StringUtil::getRandomID()))), 0, 20);
$editor = new UserEditor($user);
$editor->update(array('notificationMailToken' => $token));
}
$statementParameters = array();
foreach ($spiders as $spider) {
- $identifier = StringUtil::toLowerCase($spider->getAttribute('ident'));
+ $identifier = mb_strtolower($spider->getAttribute('ident'));
$name = $xpath->query('ns:name', $spider)->item(0);
$info = $xpath->query('ns:url', $spider)->item(0);
$userList->readObjects();
$users = array();
foreach ($userList as $user) {
- $users[StringUtil::toLowerCase($user->username)] = $user;
+ $users[mb_strtolower($user->username)] = $user;
}
$text = $userRegex->replace($text, new Callback(function ($matches) use ($users) {
*/
public static function getUsername($match) {
// remove escaped single quotation mark
- $match = StringUtil::replace("''", "'", $match);
+ $match = str_replace("''", "'", $match);
// remove single quotation marks
if ($match{0} == "'") {
- $match = StringUtil::substring($match, 1, -1);
+ $match = mb_substr($match, 1, -1);
}
- return StringUtil::toLowerCase($match);
+ return mb_strtolower($match);
}
}
*/
public function __construct($fieldName, $errorMessage = 'empty', array $variables = array()) {
$this->errorMessage = $errorMessage;
- if (StringUtil::indexOf($this->errorMessage, '.') === false) {
+ if (mb_strpos($this->errorMessage, '.') === false) {
$this->errorMessage = WCF::getLanguage()->get('wcf.global.form.error.'.$this->errorMessage);
}
else {
$variables = array();
foreach ($_REQUEST as $key => $value) {
- if (StringUtil::indexOf($key, $this->getName().'_') !== false) {
- $key = StringUtil::replace($this->getName().'_', '', $key);
+ if (mb_strpos($key, $this->getName().'_') !== false) {
+ $key = str_replace($this->getName().'_', '', $key);
$variables[$key] = $value;
}
}
$known[] = $row['smileyCode'];
foreach ($known as $smileyCode) {
- $this->knownCodes[StringUtil::toLowerCase($smileyCode)] = $row['smileyID'];
+ $this->knownCodes[mb_strtolower($smileyCode)] = $row['smileyID'];
}
}
}
if (!@copy($additionalData['fileLocation'], WCF_DIR.$data['smileyPath'])) return 0;
// check smileycode
- if (isset($this->knownCodes[StringUtil::toLowerCase($data['smileyCode'])])) return $this->knownCodes[StringUtil::toLowerCase($data['smileyCode'])];
+ if (isset($this->knownCodes[mb_strtolower($data['smileyCode'])])) return $this->knownCodes[mb_strtolower($data['smileyCode'])];
$data['packageID'] = 1;
if (!isset($data['aliases'])) $data['aliases'] = '';
if (!empty($data['aliases'])) {
$aliases = explode("\n", StringUtil::unifyNewlines($data['aliases']));
foreach ($aliases as $key => $alias) {
- if (isset($this->knownCodes[StringUtil::toLowerCase($alias)])) unset($aliases[$key]);
+ if (isset($this->knownCodes[mb_strtolower($alias)])) unset($aliases[$key]);
}
$data['aliases'] = implode("\n", $aliases);
}
$smiley = SmileyEditor::create($data);
// add smileyCode + aliases to knownCodes
- $this->knownCodes[StringUtil::toLowerCase($data['smileyCode'])] = $smiley->smileyID;
+ $this->knownCodes[mb_strtolower($data['smileyCode'])] = $smiley->smileyID;
foreach ($aliases as $alias) {
- $this->knownCodes[StringUtil::toLowerCase($alias)] = $smiley->smileyID;
+ $this->knownCodes[mb_strtolower($alias)] = $smiley->smileyID;
}
return $smiley->smileyID;
// resolve duplicates
$existingUser = User::getUserByUsername($data['username']);
if ($existingUser->userID) {
- if (ImportHandler::getInstance()->getUserMergeMode() == 1 || (ImportHandler::getInstance()->getUserMergeMode() == 3 && StringUtil::toLowerCase($existingUser->email) != StringUtil::toLowerCase($data['email']))) {
+ if (ImportHandler::getInstance()->getUserMergeMode() == 1 || (ImportHandler::getInstance()->getUserMergeMode() == 3 && mb_strtolower($existingUser->email) != mb_strtolower($data['email']))) {
// rename user
$data['username'] = self::resolveDuplicate($data['username']);
}
*/
public function addDir($name, $date = TIME_NOW) {
// replace backward slashes with forward slashes in the dirname
- $name = StringUtil::replace("\\", "/", $name);
+ $name = str_replace("\\", "/", $name);
$name = FileUtil::addTrailingSlash($name);
// construct the general header information for the directory
*/
public function addFile($data, $name, $date = TIME_NOW) {
// replace backward slashes with forward slashes in the filename
- $name = StringUtil::replace("\\", "/", $name);
+ $name = str_replace("\\", "/", $name);
// calculate the size of the file being uncompressed
$sizeUncompressed = strlen($data);
*/
protected function init() {
// get words which should be censored
- $censoredWords = explode("\n", StringUtil::unifyNewlines(StringUtil::toLowerCase(CENSORED_WORDS)));
+ $censoredWords = explode("\n", StringUtil::unifyNewlines(mb_strtolower(CENSORED_WORDS)));
// format censored words
$this->censoredWords = ArrayUtil::trim($censoredWords);
$this->matches = $this->words = array();
// string to lower case
- $text = StringUtil::toLowerCase($text);
+ $text = mb_strtolower($text);
// ignore bbcode tags
$text = preg_replace('~\[/?[a-z]+[^\]]*\]~i', '', $text);
continue 2;
}
// check for asterisk matches ("*badword*" == "FooBadwordBar")
- else if (StringUtil::indexOf($censoredWord, '*') !== false) {
- $censoredWord = StringUtil::replace('\*', '.*', preg_quote($censoredWord));
+ else if (mb_strpos($censoredWord, '*') !== false) {
+ $censoredWord = str_replace('\*', '.*', preg_quote($censoredWord));
if (preg_match('!^'.$censoredWord.'$!', $word)) {
// store censored word
if (isset($this->matches[$word])) {
}
}
// check for partial matches ("~badword~" == "bad-word")
- else if (StringUtil::indexOf($censoredWord, '~') !== false) {
- $censoredWord = StringUtil::replace('~', '', $censoredWord);
- if (($position = StringUtil::indexOf($censoredWord, $word)) !== false) {
+ else if (mb_strpos($censoredWord, '~') !== false) {
+ $censoredWord = str_replace('~', '', $censoredWord);
+ if (($position = mb_strpos($censoredWord, $word)) !== false) {
if ($position > 0) {
// look behind
- if (!$this->lookBehind($i - 1, StringUtil::substring($censoredWord, 0, $position))) {
+ if (!$this->lookBehind($i - 1, mb_substr($censoredWord, 0, $position))) {
continue;
}
}
- if ($position + StringUtil::length($word) < StringUtil::length($censoredWord)) {
+ if ($position + mb_strlen($word) < mb_strlen($censoredWord)) {
// look ahead
- if (($newIndex = $this->lookAhead($i + 1, StringUtil::substring($censoredWord, $position + StringUtil::length($word))))) {
+ if (($newIndex = $this->lookAhead($i + 1, mb_substr($censoredWord, $position + mb_strlen($word))))) {
$i = $newIndex;
}
else {
*/
protected function lookBehind($index, $search) {
if (isset($this->words[$index])) {
- if (StringUtil::indexOf($this->words[$index], $search) === (StringUtil::length($this->words[$index]) - StringUtil::length($search))) {
+ if (mb_strpos($this->words[$index], $search) === (mb_strlen($this->words[$index]) - mb_strlen($search))) {
return true;
}
- else if (StringUtil::indexOf($search, $this->words[$index]) === (StringUtil::length($search) - StringUtil::length($this->words[$index]))) {
- return $this->lookBehind($index - 1, 0, (StringUtil::length($search) - StringUtil::length($this->words[$index])));
+ else if (mb_strpos($search, $this->words[$index]) === (mb_strlen($search) - mb_strlen($this->words[$index]))) {
+ return $this->lookBehind($index - 1, 0, (mb_strlen($search) - mb_strlen($this->words[$index])));
}
}
*/
protected function lookAhead($index, $search) {
if (isset($this->words[$index])) {
- if (StringUtil::indexOf($this->words[$index], $search) === 0) {
+ if (mb_strpos($this->words[$index], $search) === 0) {
return $index;
}
- else if (StringUtil::indexOf($search, $this->words[$index]) === 0) {
- return $this->lookAhead($index + 1, StringUtil::substring($search, StringUtil::length($this->words[$index])));
+ else if (mb_strpos($search, $this->words[$index]) === 0) {
+ return $this->lookAhead($index + 1, mb_substr($search, mb_strlen($this->words[$index])));
}
}
* @return string
*/
public function renderQuote(IMessage $message, $text) {
- $escapedUsername = StringUtil::replace(array("\\", "'"), array("\\\\", "\'"), $message->getUsername());
- $escapedLink = StringUtil::replace(array("\\", "'"), array("\\\\", "\'"), $message->getLink());
+ $escapedUsername = str_replace(array("\\", "'"), array("\\\\", "\'"), $message->getUsername());
+ $escapedLink = str_replace(array("\\", "'"), array("\\\\", "\'"), $message->getLink());
return "[quote='".$escapedUsername."','".$escapedLink."']".$text."[/quote]";
}
* @see wcf\system\option\IOptionType::getData()
*/
public function getData(Option $option, $newValue) {
- $number = StringUtil::replace(WCF::getLanguage()->get('wcf.global.thousandsSeparator'), '', $newValue);
- $number = StringUtil::replace(WCF::getLanguage()->get('wcf.global.decimalPoint'), '.', $number);
+ $number = str_replace(WCF::getLanguage()->get('wcf.global.thousandsSeparator'), '', $newValue);
+ $number = str_replace(WCF::getLanguage()->get('wcf.global.decimalPoint'), '.', $number);
if (!preg_match('~^(?:\d*)\.?\d+~', $number, $matches)) return 0;
$number = $matches[0];
if (preg_match('/[kmgt]i?b$/i', $newValue, $multiplier)) {
- switch (StringUtil::toLowerCase($multiplier[0])) {
+ switch (mb_strtolower($multiplier[0])) {
case 'tb':
$number *= 1000;
case 'gb':
foreach ($optionData as $item) {
if ($item{0} == '!') {
if (!empty($disableOptions)) $disableOptions .= ',';
- $disableOptions .= "{ value: '".$key."', option: '".StringUtil::substring($item, 1)."' }";
+ $disableOptions .= "{ value: '".$key."', option: '".mb_substr($item, 1)."' }";
}
else {
if (!empty($enableOptions)) $enableOptions .= ',';
public function validate(Option $option, $newValue) {
$newValue = $this->getContent($option, $newValue);
- if ($option->minlength !== null && $option->minlength > StringUtil::length($newValue)) {
+ if ($option->minlength !== null && $option->minlength > mb_strlen($newValue)) {
throw new UserInputException($option->optionName, 'tooShort');
}
- if ($option->maxlength !== null && $option->maxlength < StringUtil::length($newValue)) {
+ if ($option->maxlength !== null && $option->maxlength < mb_strlen($newValue)) {
throw new UserInputException($option->optionName, 'tooLong');
}
}
$options = OptionUtil::parseSelectOptions($option->selectOptions);
// multiselect
- if (StringUtil::indexOf($value, "\n") !== false) {
+ if (mb_strpos($value, "\n") !== false) {
$values = explode("\n", $value);
$result = array();
foreach ($values as $value) {
$this->package = null;
if ($package->isApplication) {
- $host = StringUtil::replace(RouteHandler::getProtocol(), '', RouteHandler::getHost());
+ $host = str_replace(RouteHandler::getProtocol(), '', RouteHandler::getHost());
$path = RouteHandler::getPath(array('acp'));
// insert as application
$packageDir->setName('packageDir');
$packageDir->setLabel(WCF::getLanguage()->get('wcf.acp.package.packageDir.input'));
- $defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator(StringUtil::substring(WCF_DIR, 0, -4)));
+ $defaultPath = FileUtil::addTrailingSlash(FileUtil::unifyDirSeparator(mb_substr(WCF_DIR, 0, -4)));
// check if there is already an application
$sql = "SELECT COUNT(*) AS count
FROM wcf".WCF_N."_package
// validate functions
if (isset($requirements['functions'])) {
foreach ($requirements['functions'] as $function) {
- $function = StringUtil::toLowerCase($function);
+ $function = mb_strtolower($function);
$passed = self::functionExists($function);
if (!$passed) {
if (!empty($blacklist)) {
$blacklist = explode(',', $blacklist);
foreach ($blacklist as $disabledFunction) {
- $disabledFunction = StringUtil::toLowerCase(StringUtil::trim($disabledFunction));
+ $disabledFunction = mb_strtolower(StringUtil::trim($disabledFunction));
if ($function == $disabledFunction) {
return false;
protected static function compareSetting($setting, $value, $compareValue) {
if ($compareValue === false) return false;
- $value = StringUtil::toLowerCase($value);
+ $value = mb_strtolower($value);
$trueValues = array('1', 'on', 'true');
$falseValues = array('0', 'off', 'false');
*/
protected static function convertShorthandByteValue($value) {
// convert into bytes
- $lastCharacter = StringUtil::substring($value, -1);
+ $lastCharacter = mb_substr($value, -1);
switch ($lastCharacter) {
// gigabytes
case 'g':
* @return string
*/
protected function getToken() {
- return StringUtil::substring(StringUtil::getRandomID(), 0, 8);
+ return mb_substr(StringUtil::getRandomID(), 0, 8);
}
/**
foreach ($packageList as $package) {
$abbreviation = Package::getAbbreviation($package->package);
- $queries = StringUtil::replace($abbreviation.'1_', $abbreviation.WCF_N.'_', $queries);
+ $queries = str_replace($abbreviation.'1_', $abbreviation.WCF_N.'_', $queries);
}
// check queries
// encode certain characters
if (!empty($url)) {
- $url = StringUtil::replace(array('[', ']'), array('%5B', '%5D'), $url);
+ $url = str_replace(array('[', ']'), array('%5B', '%5D'), $url);
}
$url = $routeURL . $url;
if ($landingPage !== null && RouteHandler::getInstance()->isDefaultController()) {
// check if redirect URL matches current URL
$redirectURL = $landingPage->getLink();
- $relativeRoute = StringUtil::replace(RouteHandler::getHost(), '', $redirectURL);
+ $relativeRoute = str_replace(RouteHandler::getHost(), '', $redirectURL);
if ($relativeRoute == preg_replace('~index.php$~i', '', $_SERVER['REQUEST_URI']) || $relativeRoute == preg_replace('~([?&]s=[a-f0-9]{40})~', '', $_SERVER['REQUEST_URI'])) {
$routeData['controller'] = $landingPage->getController();
$tmp = '';
$controlCharacterOrSpace = false;
$chars = array('+', '-', '*');
- for ($i = 0, $length = StringUtil::length($q); $i < $length; $i++) {
+ for ($i = 0, $length = mb_strlen($q); $i < $length; $i++) {
$char = $q[$i];
if ($inQuotes) {
case 'wcf\system\database\PostgreSQLDatabase':
// replace * with :*
- $q = StringUtil::replace('*', ':*', $q);
+ $q = str_replace('*', ':*', $q);
$fulltextCondition->add("fulltextIndex".($subjectOnly ? "SubjectOnly" : '')." @@ to_tsquery(?)", array($q));
break;
// remove search operators
$keywordString = preg_replace('/[\+\-><()~\*]+/', '', $keywordString);
- if (StringUtil::substring($keywordString, 0, 1) == '"' && StringUtil::substring($keywordString, -1) == '"') {
+ if (mb_substr($keywordString, 0, 1) == '"' && mb_substr($keywordString, -1) == '"') {
// phrases search
- $keywordString = StringUtil::trim(StringUtil::substring($keywordString, 1, -1));
+ $keywordString = StringUtil::trim(mb_substr($keywordString, 1, -1));
if (!empty($keywordString)) {
$this->searchQuery = $keywordString;
// replace newlines with spaces
$text = Regex::compile("\s+")->replace($text, ' ');
- if (StringUtil::length($text) > static::MAX_LENGTH) {
+ if (mb_strlen($text) > static::MAX_LENGTH) {
if ($this->searchQuery) {
// phrase search
if (!is_array($this->searchQuery)) {
- $start = StringUtil::indexOfIgnoreCase($text, $this->searchQuery);
+ $start = mb_strripos($text, $this->searchQuery);
if ($start !== false) {
- $end = $start + StringUtil::length($this->searchQuery);
- $shiftStartBy = $shiftEndBy = round((static::MAX_LENGTH - StringUtil::length($this->searchQuery)) / 2);
+ $end = $start + mb_strlen($this->searchQuery);
+ $shiftStartBy = $shiftEndBy = round((static::MAX_LENGTH - mb_strlen($this->searchQuery)) / 2);
// shiftStartBy is negative when search query length is over max length
if ($shiftStartBy < 0) {
}
// shift abstract end
- if ($end + $shiftEndBy > StringUtil::length($text) - 1) {
- $shiftStartBy = $end + $shiftEndBy - StringUtil::length($text) - 1;
+ if ($end + $shiftEndBy > mb_strlen($text) - 1) {
+ $shiftStartBy = $end + $shiftEndBy - mb_strlen($text) - 1;
$shiftEndBy = 0;
if ($shiftStartBy > $start) {
$start = 0;
$newText = '';
if ($start > 0) $newText .= StringUtil::HELLIP;
- $newText .= StringUtil::substring($text, $start, $end - $start);
- if ($end < StringUtil::length($text) - 1) $newText .= StringUtil::HELLIP;
+ $newText .= mb_substr($text, $start, $end - $start);
+ if ($end < mb_strlen($text) - 1) $newText .= StringUtil::HELLIP;
return $newText;
}
}
$shiftLength = static::MAX_LENGTH;
// find first match of each keyword
foreach ($this->searchQuery as $keyword) {
- $start = StringUtil::indexOfIgnoreCase($text, $keyword);
+ $start = mb_strripos($text, $keyword);
if ($start !== false) {
- $shiftLength -= StringUtil::length($keyword);
- $matches[$keyword] = array('start' => $start, 'end' => $start + StringUtil::length($keyword));
+ $shiftLength -= mb_strlen($keyword);
+ $matches[$keyword] = array('start' => $start, 'end' => $start + mb_strlen($keyword));
}
}
}
$start = 0;
- $end = StringUtil::length($text) - 1;
+ $end = mb_strlen($text) - 1;
$newText = '';
$i = 0;
$length = count($matches);
}
if ($position['start'] > $start) $newText .= StringUtil::HELLIP;
- $newText .= StringUtil::substring($text, $position['start'], $position['end'] - $position['start']);
+ $newText .= mb_substr($text, $position['start'], $position['end'] - $position['start']);
if ($i == $length - 1 && $position['end'] < $end) $newText .= StringUtil::HELLIP;
$start = $position['end'];
}
// no search query or no matches
- return StringUtil::substring($text, 0, static::MAX_LENGTH) . StringUtil::HELLIP;
+ return mb_substr($text, 0, static::MAX_LENGTH) . StringUtil::HELLIP;
}
return $text;
$directories = array();
$files = array();
foreach ($tar->getContentList() as $index => $file) {
- if (empty($this->folder) || StringUtil::indexOf($file['filename'], $this->folder) === 0) {
+ if (empty($this->folder) || mb_strpos($file['filename'], $this->folder) === 0) {
if (!empty($this->folder)) {
- $file['filename'] = StringUtil::replace($this->folder, '', $file['filename']);
+ $file['filename'] = str_replace($this->folder, '', $file['filename']);
}
// remove leading slash
if (empty($tag)) continue;
// enforce max length
- if (StringUtil::length($tag) > TAGGING_MAX_TAG_LENGTH) {
- $tag = StringUtil::substring($tag, 0, TAGGING_MAX_TAG_LENGTH);
+ if (mb_strlen($tag) > TAGGING_MAX_TAG_LENGTH) {
+ $tag = mb_substr($tag, 0, TAGGING_MAX_TAG_LENGTH);
}
// find existing tag
* @return string
*/
public function getPluginClassName($type, $tag) {
- return $this->pluginNamespace.StringUtil::firstCharToUpperCase($tag).StringUtil::firstCharToUpperCase(StringUtil::toLowerCase($type)).'TemplatePlugin';
+ return $this->pluginNamespace.StringUtil::firstCharToUpperCase($tag).StringUtil::firstCharToUpperCase(mb_strtolower($type)).'TemplatePlugin';
}
/**
// compile the template tags into php-code
$compiledTags = array();
for ($i = 0, $j = count($templateTags); $i < $j; $i++) {
- $this->currentLineNo += StringUtil::countSubstring($textBlocks[$i], "\n");
+ $this->currentLineNo += mb_substr_count($textBlocks[$i], "\n");
$compiledTags[] = $this->compileTag($templateTags[$i], $identifier, $metaData);
- $this->currentLineNo += StringUtil::countSubstring($templateTags[$i], "\n");
+ $this->currentLineNo += mb_substr_count($templateTags[$i], "\n");
}
// throw error messages for unclosed tags
if (preg_match('~^(/?\w+)~', $tag, $match)) {
// build in function or plugin
$tagCommand = $match[1];
- $tagArgs = StringUtil::substring($tag, StringUtil::length($tagCommand));
+ $tagArgs = mb_substr($tag, mb_strlen($tagCommand));
switch ($tagCommand) {
case 'if':
$phpCode .= "if (count(".$args['from'].") > 0) {\n";
if (isset($args['key'])) {
- $phpCode .= "foreach (".$args['from']." as ".(StringUtil::substring($args['key'], 0, 1) != '$' ? "\$this->v[".$args['key']."]" : $args['key'])." => ".(StringUtil::substring($args['item'], 0, 1) != '$' ? "\$this->v[".$args['item']."]" : $args['item']).") {\n";
+ $phpCode .= "foreach (".$args['from']." as ".(mb_substr($args['key'], 0, 1) != '$' ? "\$this->v[".$args['key']."]" : $args['key'])." => ".(mb_substr($args['item'], 0, 1) != '$' ? "\$this->v[".$args['item']."]" : $args['item']).") {\n";
}
else {
- $phpCode .= "foreach (".$args['from']." as ".(StringUtil::substring($args['item'], 0, 1) != '$' ? "\$this->v[".$args['item']."]" : $args['item']).") {\n";
+ $phpCode .= "foreach (".$args['from']." as ".(mb_substr($args['item'], 0, 1) != '$' ? "\$this->v[".$args['item']."]" : $args['item']).") {\n";
}
if (!empty($foreachProp)) {
// reinserts strings
foreach (StringStack::getStack('singleQuote') as $hash => $value) {
- if (StringUtil::indexOf($string, $hash) !== false) {
- $string = StringUtil::replace($hash, $value, $string);
+ if (mb_strpos($string, $hash) !== false) {
+ $string = str_replace($hash, $value, $string);
}
}
foreach (StringStack::getStack('doubleQuote') as $hash => $value) {
- if (StringUtil::indexOf($string, $hash) !== false) {
- $string = StringUtil::replace($hash, $value, $string);
+ if (mb_strpos($string, $hash) !== false) {
+ $string = str_replace($hash, $value, $string);
}
}
throw new SystemException($this->formatSyntaxError('syntax error in tag {'.($elseif ? 'elseif' : 'if').'}', $this->currentIdentifier, $this->currentLineNo));
}
- $leftParenthesis = StringUtil::countSubstring($values[$i], '(');
- $rightParenthesis = StringUtil::countSubstring($values[$i], ')');
+ $leftParenthesis = mb_substr_count($values[$i], '(');
+ $rightParenthesis = mb_substr_count($values[$i], ')');
if ($leftParenthesis > $rightParenthesis) {
$leftParentheses += $leftParenthesis - $rightParenthesis;
- $value = StringUtil::substring($values[$i], $leftParenthesis - $rightParenthesis);
+ $value = mb_substr($values[$i], $leftParenthesis - $rightParenthesis);
$result .= str_repeat('(', $leftParenthesis - $rightParenthesis);
- if (str_replace('(', '', StringUtil::substring($values[$i], 0, $leftParenthesis - $rightParenthesis)) != '') {
+ if (str_replace('(', '', mb_substr($values[$i], 0, $leftParenthesis - $rightParenthesis)) != '') {
throw new SystemException($this->formatSyntaxError('syntax error in tag {'.($elseif ? 'elseif' : 'if').'}', $this->currentIdentifier, $this->currentLineNo));
}
}
else if ($leftParenthesis < $rightParenthesis) {
$leftParentheses += $leftParenthesis - $rightParenthesis;
- $value = StringUtil::substring($values[$i], 0, $leftParenthesis - $rightParenthesis);
+ $value = mb_substr($values[$i], 0, $leftParenthesis - $rightParenthesis);
- if ($leftParentheses < 0 || str_replace(')', '', StringUtil::substring($values[$i], $leftParenthesis - $rightParenthesis)) != '') {
+ if ($leftParentheses < 0 || str_replace(')', '', mb_substr($values[$i], $leftParenthesis - $rightParenthesis)) != '') {
throw new SystemException($this->formatSyntaxError('syntax error in tag {'.($elseif ? 'elseif' : 'if').'}', $this->currentIdentifier, $this->currentLineNo));
}
}
$encodeHTML = false;
$formatNumeric = false;
if ($tag[0] == '@') {
- $tag = StringUtil::substring($tag, 1);
+ $tag = mb_substr($tag, 1);
}
else if ($tag[0] == '#') {
- $tag = StringUtil::substring($tag, 1);
+ $tag = mb_substr($tag, 1);
$formatNumeric = true;
}
else {
* @return string
*/
public function replacePHPTags($string) {
- if (StringUtil::indexOf($string, '<?') !== false) {
- $string = StringUtil::replace('<?php', '@@PHP_START_TAG@@', $string);
- $string = StringUtil::replace('<?', '@@PHP_SHORT_START_TAG@@', $string);
- $string = StringUtil::replace('?>', '@@PHP_END_TAG@@', $string);
- $string = StringUtil::replace('@@PHP_END_TAG@@', "<?php echo '?>'; ?>\n", $string);
- $string = StringUtil::replace('@@PHP_SHORT_START_TAG@@', "<?php echo '<?'; ?>\n", $string);
- $string = StringUtil::replace('@@PHP_START_TAG@@', "<?php echo '<?php'; ?>\n", $string);
+ if (mb_strpos($string, '<?') !== false) {
+ $string = str_replace('<?php', '@@PHP_START_TAG@@', $string);
+ $string = str_replace('<?', '@@PHP_SHORT_START_TAG@@', $string);
+ $string = str_replace('?>', '@@PHP_END_TAG@@', $string);
+ $string = str_replace('@@PHP_END_TAG@@', "<?php echo '?>'; ?>\n", $string);
+ $string = str_replace('@@PHP_SHORT_START_TAG@@', "<?php echo '<?'; ?>\n", $string);
+ $string = str_replace('@@PHP_START_TAG@@', "<?php echo '<?php'; ?>\n", $string);
}
return $string;
$phpCode = "<?php\n";
$phpCode .= "\$_length".$hash." = count(".$tagArgs['from'].");\n";
$phpCode .= "\$_i".$hash." = 0;\n";
- $phpCode .= "foreach (".$tagArgs['from']." as ".(isset($tagArgs['key']) ? (StringUtil::substring($tagArgs['key'], 0, 1) != '$' ? "\$this->v[".$tagArgs['key']."]" : $tagArgs['key'])." => " : '').(StringUtil::substring($tagArgs['item'], 0, 1) != '$' ? "\$this->v[".$tagArgs['item']."]" : $tagArgs['item']).") { ?>";
+ $phpCode .= "foreach (".$tagArgs['from']." as ".(isset($tagArgs['key']) ? (mb_substr($tagArgs['key'], 0, 1) != '$' ? "\$this->v[".$tagArgs['key']."]" : $tagArgs['key'])." => " : '').(mb_substr($tagArgs['item'], 0, 1) != '$' ? "\$this->v[".$tagArgs['item']."]" : $tagArgs['item']).") { ?>";
return $phpCode;
}
* @return string final link
*/
protected static function insertPageNumber($link, $pageNo) {
- $startPos = StringUtil::indexOf($link, '%d');
- if ($startPos !== null) $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2);
+ $startPos = mb_strpos($link, '%d');
+ if ($startPos !== null) $link = mb_substr($link, 0, $startPos) . $pageNo . mb_substr($link, $startPos + 2);
return $link;
}
foreach ($substrings as $substring) {
if (!empty($result)) $result .= ' ';
- $length = StringUtil::length($substring);
+ $length = mb_strlen($substring);
if ($length > $width) {
$j = ceil($length / $width);
for ($i = 0; $i < $j; $i++) {
if ($i) $result .= $break;
- if ($width * ($i + 1) > $length) $result .= StringUtil::substring($substring, $width * $i);
- else $result .= StringUtil::substring($substring, $width * $i, $width);
+ if ($width * ($i + 1) > $length) $result .= mb_substr($substring, $width * $i);
+ else $result .= mb_substr($substring, $width * $i, $width);
}
}
else {
* @return string
*/
public function getFileExtension() {
- if (($position = StringUtil::lastIndexOf($this->getFilename(), '.')) !== false) {
- return StringUtil::toLowerCase(StringUtil::substring($this->getFilename(), $position + 1));
+ if (($position = mb_strrpos($this->getFilename(), '.')) !== false) {
+ return mb_strtolower(mb_substr($this->getFilename(), $position + 1));
}
return '';
$token = $user->notificationMailToken;
if (!$token) {
// generate token if not present
- $token = StringUtil::substring(StringUtil::getHash(serialize(array($user->userID, StringUtil::getRandomID()))), 0, 20);
+ $token = mb_substr(StringUtil::getHash(serialize(array($user->userID, StringUtil::getRandomID()))), 0, 20);
$editor = new UserEditor($user);
$editor->update(array('notificationMailToken' => $token));
}
*/
protected function sendMail(User $user) {
try {
- $mail = new Mail(array($user->username => $user->email), $this->mailData['subject'], StringUtil::replace('{$username}', $user->username, $this->mailData['text']), $this->mailData['from']);
+ $mail = new Mail(array($user->username => $user->email), $this->mailData['subject'], str_replace('{$username}', $user->username, $this->mailData['text']), $this->mailData['from']);
if ($this->mailData['enableHTML']) $mail->setContentType('text/html');
$mail->setLanguage($user->getLanguage());
$mail->send();
// calculate values based upon each expression
$values = array();
foreach ($fields as $fieldName => $fieldValue) {
- $fieldValue = StringUtil::toLowerCase($fieldValue);
+ $fieldValue = mb_strtolower($fieldValue);
// Names can also be used for the "month" and "day of week" fields.
// Use the first three letters of the particular day or month (case
$values = array();
// examinate first char
- $char = StringUtil::substring($fieldValue, 0, 1);
+ $char = mb_substr($fieldValue, 0, 1);
// could be a single value, range or list
if (is_numeric($char)) {
else if ($char == '*') {
$step = 1;
- if (StringUtil::indexOf($fieldValue, '/') !== false) {
+ if (mb_strpos($fieldValue, '/') !== false) {
$rangeData = explode('/', $fieldValue);
$step = $rangeData[1];
}
* @return array
*/
protected static function getListItems($fieldValue) {
- if (StringUtil::indexOf($fieldValue, ',') !== false) {
+ if (mb_strpos($fieldValue, ',') !== false) {
return explode(',', $fieldValue);
}
*/
protected static function getRanges($value) {
// this is a single value
- if (StringUtil::indexOf($value, '-') === false) {
+ if (mb_strpos($value, '-') === false) {
return array($value);
}
$step = 1;
- if (StringUtil::indexOf($value, '/') !== false) {
+ if (mb_strpos($value, '/') !== false) {
$data = explode('/', $value);
$step = $data[1];
$value = $data[0];
if (count($compareSlash) == 2) $compare['1'] = $compareSlash['0'];
// see if digits or names are being given.
- $left = array_search(StringUtil::toLowerCase($compare['0']), $namesArr);
- $right = array_search(StringUtil::toLowerCase($compare['1']), $namesArr);
+ $left = array_search(mb_strtolower($compare['0']), $namesArr);
+ $right = array_search(mb_strtolower($compare['1']), $namesArr);
if (!$left) $left = $compare['0'];
if (!$right) $right = $compare['1'];
// now check the values.
*/
public static function setCookie($name, $value = '', $expire = 0) {
$application = ApplicationHandler::getInstance()->getActiveApplication();
- $addDomain = (StringUtil::indexOf($application->cookieDomain, '.') === false || StringUtil::endsWith($application->cookieDomain, '.lan') || StringUtil::endsWith($application->cookieDomain, '.local')) ? false : true;
+ $addDomain = (mb_strpos($application->cookieDomain, '.') === false || StringUtil::endsWith($application->cookieDomain, '.lan') || StringUtil::endsWith($application->cookieDomain, '.local')) ? false : true;
@header('Set-Cookie: '.rawurlencode(COOKIE_PREFIX.$name).'='.rawurlencode($value).($expire ? '; expires='.gmdate('D, d-M-Y H:i:s', $expire).' GMT; max-age='.($expire - TIME_NOW) : '').'; path='.$application->cookiePath.($addDomain ? '; domain='.$application->cookieDomain : '').(RouteHandler::secureConnection() ? '; secure' : '').'; HttpOnly', false);
}
$options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($selectOptions)));
foreach ($options as $option) {
$key = $value = $option;
- if (StringUtil::indexOf($option, ':') !== false) {
+ if (mb_strpos($option, ':') !== false) {
$optionData = explode(':', $option);
$key = array_shift($optionData);
$value = implode(':', $optionData);
$options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($enableOptions)));
$key = -1;
foreach ($options as $option) {
- if (StringUtil::indexOf($option, ':') !== false) {
+ if (mb_strpos($option, ':') !== false) {
$optionData = explode(':', $option);
$key = array_shift($optionData);
$value = implode(':', $optionData);
* @return string
*/
protected static function getSalt($salt) {
- $salt = StringUtil::substring($salt, 0, 22);
+ $salt = mb_substr($salt, 0, 22);
return '$' . self::BCRYPT_TYPE . '$' . self::BCRYPT_COST . '$' . $salt;
}
* @return boolean
*/
protected static function phpbb3($username, $password, $salt, $dbHash) {
- if (StringUtil::length($dbHash) !== 34) {
+ if (mb_strlen($dbHash) !== 34) {
return self::secureCompare(md5($password), $dbHash);
}
* @return boolean
*/
protected static function smf1($username, $password, $salt, $dbHash) {
- return self::secureCompare($dbHash, sha1(StringUtil::toLowerCase($username) . $password));
+ return self::secureCompare($dbHash, sha1(mb_strtolower($username) . $password));
}
/**
public static function reinsertStrings($string, $type = 'default') {
if (isset(self::$stringStack[$type])) {
foreach (self::$stringStack[$type] as $hash => $value) {
- if (StringUtil::indexOf($string, $hash) !== false) {
- $string = StringUtil::replace($hash, $value, $string);
+ if (mb_strpos($string, $hash) !== false) {
+ $string = str_replace($hash, $value, $string);
unset(self::$stringStack[$type][$hash]);
}
}
$string = self::unifyNewlines($string);
// escape backslash
- $string = self::replace("\\", "\\\\", $string);
+ $string = str_replace("\\", "\\\\", $string);
// escape singe quote
- $string = self::replace("'", "\'", $string);
+ $string = str_replace("'", "\'", $string);
// escape new lines
- $string = self::replace("\n", '\n', $string);
+ $string = str_replace("\n", '\n', $string);
// escape slashes
- $string = self::replace("/", '\/', $string);
+ $string = str_replace("/", '\/', $string);
return $string;
}
$string = self::encodeHTML($string);
// single quotes must be encoded as HTML entity
- $string = self::replace("\'", "'", $string);
+ $string = str_replace("\'", "'", $string);
return $string;
}
* @return string
*/
public static function formatNegative($number) {
- return self::replace('-', self::MINUS, $number);
+ return str_replace('-', self::MINUS, $number);
}
/**
* Alias to php ucfirst() function with multibyte support.
*/
public static function firstCharToUpperCase($string) {
- return self::toUpperCase(self::substring($string, 0, 1)).self::substring($string, 1);
+ return mb_strtoupper(mb_substr($string, 0, 1)).mb_substr($string, 1);
}
/**
* Alias to php lcfirst() function with multibyte support.
*/
public static function firstCharToLowerCase($string) {
- return self::toLowerCase(self::substring($string, 0, 1)).self::substring($string, 1);
+ return mb_strtolower(mb_substr($string, 0, 1)).mb_substr($string, 1);
}
/**
* only ASCII characters, please use str_ireplace() instead.
*/
public static function replaceIgnoreCase($search, $replace, $subject, &$count = 0) {
- $startPos = self::indexOf(self::toLowerCase($subject), self::toLowerCase($search));
+ $startPos = mb_strpos(mb_strtolower($subject), mb_strtolower($search));
if ($startPos === false) return $subject;
else {
- $endPos = $startPos + self::length($search);
+ $endPos = $startPos + mb_strlen($search);
$count++;
- return self::substring($subject, 0, $startPos) . $replace . self::replaceIgnoreCase($search, $replace, self::substring($subject, $endPos), $count);
+ return mb_substr($subject, 0, $startPos) . $replace . self::replaceIgnoreCase($search, $replace, mb_substr($subject, $endPos), $count);
}
}
*/
public static function startsWith($haystack, $needle, $ci = false) {
if ($ci) {
- $haystack = self::toLowerCase($haystack);
- $needle = self::toLowerCase($needle);
+ $haystack = mb_strtolower($haystack);
+ $needle = mb_strtolower($needle);
}
// using substring and === is MUCH faster for long strings then using indexOf.
- return self::substring($haystack, 0, self::length($needle)) === $needle;
+ return mb_substr($haystack, 0, mb_strlen($needle)) === $needle;
}
/**
*/
public static function endsWith($haystack, $needle, $ci = false) {
if ($ci) {
- $haystack = self::toLowerCase($haystack);
- $needle = self::toLowerCase($needle);
+ $haystack = mb_strtolower($haystack);
+ $needle = mb_strtolower($needle);
}
- $length = self::length($needle);
+ $length = mb_strlen($needle);
if ($length === 0) return true;
- return (self::substring($haystack, $length * -1) === $needle);
+ return (mb_substr($haystack, $length * -1) === $needle);
}
/**
*/
public static function unescape($string, $chars = '"') {
for ($i = 0, $j = strlen($chars); $i < $j; $i++) {
- $string = self::replace('\\'.$chars[$i], $chars[$i], $string);
+ $string = str_replace('\\'.$chars[$i], $chars[$i], $string);
}
return $string;
*/
public static function encodeAllChars($string) {
$result = '';
- for ($i = 0, $j = self::length($string); $i < $j; $i++) {
- $char = self::substring($string, $i, 1);
+ for ($i = 0, $j = mb_strlen($string); $i < $j; $i++) {
+ $char = mb_substr($string, $i, 1);
$result .= '&#'.self::getCharValue($char).';';
}
* @return boolean
*/
public static function executeWordFilter($word, $filter) {
- $word = self::toLowerCase($word);
+ $word = mb_strtolower($word);
if ($filter != '') {
- $forbiddenNames = explode("\n", self::toLowerCase(self::unifyNewlines($filter)));
+ $forbiddenNames = explode("\n", mb_strtolower(self::unifyNewlines($filter)));
foreach ($forbiddenNames as $forbiddenName) {
- if (self::indexOf($forbiddenName, '*') !== false) {
- $forbiddenName = self::replace('\*', '.*', preg_quote($forbiddenName, '/'));
+ if (mb_strpos($forbiddenName, '*') !== false) {
+ $forbiddenName = str_replace('\*', '.*', preg_quote($forbiddenName, '/'));
if (preg_match('/^'.$forbiddenName.'$/s', $word)) {
return false;
}
return '';
}
- if (self::length($string) > $length) {
- $length -= self::length($etc);
+ if (mb_strlen($string) > $length) {
+ $length -= mb_strlen($etc);
if (!$breakWords) {
- $string = preg_replace('/\\s+?(\\S+)?$/', '', self::substring($string, 0, $length + 1));
+ $string = preg_replace('/\\s+?(\\S+)?$/', '', mb_substr($string, 0, $length + 1));
}
- return self::substring($string, 0, $length).$etc;
+ return mb_substr($string, 0, $length).$etc;
}
else {
return $string;
* @return string truncated string
*/
public static function truncateHTML($string, $length = 500, $etc = self::HELLIP, $breakWords = false) {
- if (self::length(self::stripHTML($string)) <= $length) {
+ if (mb_strlen(self::stripHTML($string)) <= $length) {
return $string;
}
$openTags = array();
$truncatedString = '';
// initalize length counter with the ending length
- $totalLength = self::length($etc);
+ $totalLength = mb_strlen($etc);
preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $string, $tags, PREG_SET_ORDER);
// get length of the content without entities. If the content is too long, keep entities intact
$decodedContent = self::decodeHTML($tag[3]);
- $contentLength = self::length($decodedContent);
+ $contentLength = mb_strlen($decodedContent);
if ($contentLength + $totalLength > $length) {
if (!$breakWords) {
if (preg_match('/^(.{1,'.($length - $totalLength).'}) /s', $decodedContent, $match)) {
foreach ($entities[0] as $entity) {
if ($entity[1] + 1 - $entitiesLength <= $left) {
$left--;
- $entitiesLength += self::length($entity[0]);
+ $entitiesLength += mb_strlen($entity[0]);
}
else {
break;
}
}
}
- $truncatedString .= self::substring($tag[3], 0, $left + $entitiesLength);
+ $truncatedString .= mb_substr($tag[3], 0, $left + $entitiesLength);
break;
}
else {
// use URL and remove protocol and www subdomain
$title = preg_replace('~^(?:https?|ftps?)://(?:www\.)?~i', '', $url);
- if (self::length($title) > 60) {
- $title = self::substring($title, 0, 30) . self::HELLIP . self::substring($title, -25);
+ if (mb_strlen($title) > 60) {
+ $title = mb_substr($title, 0, 30) . self::HELLIP . mb_substr($title, -25);
}
if (!$encodeTitle) $title = self::encodeHTML($title);
$substrings = explode($break, $string);
foreach ($substrings as $substring) {
- $length = self::length($substring);
+ $length = mb_strlen($substring);
if ($length > $width) {
$j = ceil($length / $width);
for ($i = 0; $i < $j; $i++) {
if (!empty($result)) $result .= $break;
- if ($width * ($i + 1) > $length) $result .= self::substring($substring, $width * $i);
- else $result .= self::substring($substring, $width * $i, $width);
+ if ($width * ($i + 1) > $length) $result .= mb_substr($substring, $width * $i);
+ else $result .= mb_substr($substring, $width * $i, $width);
}
}
else {
public static function isValidUsername($name) {
if (!UserUtil::isValidUsername($name)) return false;
- $length = StringUtil::length($name);
+ $length = mb_strlen($name);
if ($length < REGISTER_USERNAME_MIN_LENGTH || $length > REGISTER_USERNAME_MAX_LENGTH) return false;
if (!self::checkForbiddenUsernames($name)) return false;
*/
public static function isSecurePassword($password) {
if (REGISTER_ENABLE_PASSWORD_SECURITY_CHECK) {
- if (StringUtil::length($password) < REGISTER_PASSWORD_MIN_LENGTH) return false;
+ if (mb_strlen($password) < REGISTER_PASSWORD_MIN_LENGTH) return false;
if (REGISTER_PASSWORD_MUST_CONTAIN_DIGIT && !preg_match('![0-9]+!', $password)) return false;
if (REGISTER_PASSWORD_MUST_CONTAIN_LOWER_CASE && !preg_match('![a-z]+!', $password)) return false;
*/
public static function isValidUsername($name) {
// minimum length is 3 characters, maximum length is 255 characters
- if (StringUtil::length($name) < 3 || StringUtil::length($name) > 255) {
+ if (mb_strlen($name) < 3 || mb_strlen($name) > 255) {
return false;
}
// check long words
$words = preg_split('!\s+!', $name, -1, PREG_SPLIT_NO_EMPTY);
foreach ($words as $word) {
- if (StringUtil::length($word) > 20) {
+ if (mb_strlen($word) > 20) {
return false;
}
}
$REQUEST_URI = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $REQUEST_URI);
}
- return StringUtil::substring(FileUtil::unifyDirSeparator($REQUEST_URI), 0, 255);
+ return mb_substr(FileUtil::unifyDirSeparator($REQUEST_URI), 0, 255);
}
private function __construct() { }
// build file path upon namespace and filename
$tmp = explode(' ', $this->schema);
- $this->schema = WCF_DIR.'xsd/'.StringUtil::substring(sha1($tmp[0]), 0, 8) . '_' . basename($tmp[1]);
+ $this->schema = WCF_DIR.'xsd/'.mb_substr(sha1($tmp[0]), 0, 8) . '_' . basename($tmp[1]);
if (!file_exists($this->schema) || !is_readable($this->schema)) {
throw new SystemException("Could not read XML schema definition located at '".$this->schema."'.");