Use str_starts_with/str_ends_with

This commit is contained in:
fiwswe 2023-09-15 16:25:49 +02:00
parent a5fdb4ca67
commit 1b2deed915
12 changed files with 18 additions and 18 deletions

View File

@ -254,7 +254,7 @@ class GitToolCLI extends CLI
*/
private function cloneExtension($ext, $repo)
{
if (substr($ext, 0, 9) == 'template:') {
if (str_starts_with($ext, 'template:')) {
$target = fullpath(tpl_incdir() . '../' . substr($ext, 9));
} else {
$target = DOKU_PLUGIN . $ext;

View File

@ -110,7 +110,7 @@ if ($conf['allowdebug'] && $ACT == 'debug') {
if (
!$INFO['exists'] &&
($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/', $ID)) &&
($ACT == 'show' || (!is_array($ACT) && substr($ACT, 0, 7) == 'export_'))
($ACT == 'show' || (!is_array($ACT) && str_starts_with($ACT, 'export_')))
) {
header('HTTP/1.0 404 Not Found');
}

View File

@ -56,7 +56,7 @@ if (preg_match('/^\/_media\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
die('Access denied');
}
if (substr($_SERVER['SCRIPT_NAME'], -4) == '.php') {
if (str_ends_with($_SERVER['SCRIPT_NAME'], '.php')) {
# php scripts
require $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'];
} else {

View File

@ -489,7 +489,7 @@ class DokuCssFile
if (preg_match('#^(/|data:|https?://)#', $match[3])) { // not a relative url? - no adjustment required
return $match[0];
} elseif (substr($match[3], -5) == '.less') { // a less file import? - requires a file system location
} elseif (str_ends_with($match[3], '.less')) { // a less file import? - requires a file system location
if ($match[3][0] != '/') {
$match[3] = $this->getRelativePath() . '/' . $match[3];
}

View File

@ -95,7 +95,7 @@ $evt = new Event('MEDIA_RESIZE', $data);
if ($evt->advise_before()) {
if (
$MIME != 'image/svg+xml' &&
(substr($MIME, 0, 5) == 'image') &&
str_starts_with($MIME, 'image') &&
($WIDTH || $HEIGHT)
) {
if ($HEIGHT && $WIDTH) {

View File

@ -127,7 +127,7 @@ function js_out()
// load files
foreach ($files as $file) {
if (!file_exists($file)) continue;
$ismin = (substr($file, -7) == '.min.js');
$ismin = str_ends_with($file, '.min.js');
$debugjs = ($conf['allowdebug'] && strpos($file, DOKU_INC . 'lib/scripts/') !== 0);
echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
@ -197,7 +197,7 @@ function js_load($file)
$idata = '';
if (file_exists($ifile)) {
$ismin = (substr($ifile, -7) == '.min.js');
$ismin = str_ends_with($ifile, '.min.js');
if ($ismin) $idata .= "\n/* BEGIN NOCOMPRESS */\n";
$idata .= io_readFile($ifile);
if ($ismin) $idata .= "\n/* END NOCOMPRESS */\n";

View File

@ -659,7 +659,7 @@ class admin_plugin_acl extends AdminPlugin
foreach ($set as $who => $perm) {
echo '<tr>';
echo '<td>';
if (substr($where, -1) == '*') {
if (str_ends_with($where, '*')) {
echo '<span class="aclns">' . hsc($where) . '</span>';
$ispage = false;
} else {

View File

@ -678,7 +678,7 @@ class auth_plugin_authpdo extends AuthPlugin
$hasnextrowset = true;
$currentsql = $sql;
while ($hasnextrowset) {
if (strtolower(substr($currentsql, 0, 6)) == 'select') {
if (str_starts_with(strtolower($currentsql), 'select')) {
$result = $sth->fetchAll();
} else {
$result = $sth->rowCount();

View File

@ -178,9 +178,9 @@ class Setting
*/
public function getType()
{
if (substr($this->getKey(), 0, 10) == 'plugin' . Configuration::KEYMARKER) {
if (str_starts_with($this->getKey(), 'plugin' . Configuration::KEYMARKER)) {
return 'plugin';
} elseif (substr($this->getKey(), 0, 7) == 'tpl' . Configuration::KEYMARKER) {
} elseif (str_starts_with($this->getKey(), 'tpl' . Configuration::KEYMARKER)) {
return 'template';
} else {
return 'dokuwiki';

View File

@ -77,7 +77,7 @@ class helper_plugin_extension_extension extends Plugin
$this->base = $id;
if (substr($id, 0, 9) == 'template:') {
if (str_starts_with($id, 'template:')) {
$this->base = substr($id, 9);
$this->is_template = true;
} else {
@ -794,7 +794,7 @@ class helper_plugin_extension_extension extends Plugin
if ($dh = @opendir($path . $type . '/')) {
while (false !== ($cp = readdir($dh))) {
if ($cp == '.' || $cp == '..' || strtolower(substr($cp, -4)) != '.php') continue;
if ($cp == '.' || $cp == '..' || !str_ends_with(strtolower($cp), '.php')) continue;
$plugin = plugin_load($type, $this->base . '_' . substr($cp, 0, -4));
if ($plugin instanceof PluginInterface) break;
@ -1184,7 +1184,7 @@ class helper_plugin_extension_extension extends Plugin
private function decompress($file, $target)
{
// decompression library doesn't like target folders ending in "/"
if (substr($target, -1) == "/") $target = substr($target, 0, -1);
if (str_ends_with($target, '/')) $target = substr($target, 0, -1);
$ext = $this->guessArchiveType($file);
if (in_array($ext, ['tar', 'bz', 'gz'])) {

View File

@ -160,7 +160,7 @@ class admin_plugin_logviewer extends AdminPlugin
if ($size >= self::MAX_READ_SIZE) {
array_shift($lines); // Discard the first line
while ($lines !== [] && (substr($lines[0], 0, 2) === ' ')) {
while ($lines !== [] && str_starts_with($lines[0], ' ')) {
array_shift($lines); // Discard indented lines
}
@ -186,10 +186,10 @@ class admin_plugin_logviewer extends AdminPlugin
echo "<dl>";
for ($i = 0; $i < $numberOfLines; $i++) {
$line = $lines[$i];
if (substr($line, 0, 2) === ' ') {
if (str_starts_with($line, ' ')) {
// lines indented by two spaces are details, aggregate them
echo '<dd>';
while (substr($line, 0, 2) === ' ') {
while (str_starts_with($line, ' ')) {
echo hsc(substr($line, 2)) . '<br />';
$i++;
$line = $lines[$i] ?? '';

View File

@ -297,7 +297,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
}
//only search txt files if 'all' option not set
if ($opts['all'] || substr($file, -4) == '.txt') {
if ($opts['all'] || str_ends_with($file, '.txt')) {
$size = filesize($base . '/' . $file);
$date = filemtime($base . '/' . $file);
$data['file_count']++;