Use str_starts_with/str_ends_with

This commit is contained in:
fiwswe 2023-09-14 22:32:18 +02:00
parent fa4b9dc1e9
commit 6c16a3a9aa
33 changed files with 99 additions and 98 deletions

View File

@ -134,7 +134,7 @@ class Subscribe extends AbstractUserAction
}
$target = $params['target'];
$valid_styles = ['every', 'digest'];
if (substr($target, -1, 1) === ':') {
if (str_ends_with($target, ':')) {
// Allow “list” subscribe style since the target is a namespace.
$valid_styles[] = 'list';
}

View File

@ -351,7 +351,7 @@ class PluginController
if (is_dir($typedir)) {
if ($dp = opendir($typedir)) {
while (false !== ($component = readdir($dp))) {
if (strpos($component, '.') === 0 || strtolower(substr($component, -4)) !== '.php') continue;
if (strpos($component, '.') === 0 || str_ends_with(strtolower($component), '.php')) continue;
if (is_file($typedir . $component)) {
$plugins[] = $plugin . '_' . substr($component, 0, -4);
}

View File

@ -97,7 +97,7 @@ abstract class RemotePlugin extends Plugin
{
$types = explode('|', $hint);
foreach ($types as $t) {
if (substr($t, -2) === '[]') {
if (str_ends_with($t, '[]')) {
return 'array';
}
if ($t === 'boolean') {

View File

@ -108,7 +108,7 @@ class MediaFile
/** @return bool */
public function isImage()
{
return (substr($this->mime, 0, 6) === 'image/');
return (str_starts_with($this->mime, 'image/'));
}
/**

View File

@ -489,7 +489,7 @@ class HTTPClient
if (
isset($this->resp_headers['content-encoding']) &&
$this->resp_headers['content-encoding'] == 'gzip' &&
strlen($r_body) > 10 && substr($r_body, 0, 3) == "\x1f\x8b\x08"
strlen($r_body) > 10 && str_starts_with($r_body, "\x1f\x8b\x08")
) {
$this->resp_body = @gzinflate(substr($r_body, 10));
if ($this->resp_body === false) {

View File

@ -143,23 +143,24 @@ class JpegMeta {
if(!is_array($fields)) $fields = array($fields);
$info = false;
foreach($fields as $field){
if(strtolower(substr($field,0,5)) == 'iptc.'){
$lower_field = strtolower($field);
if(str_starts_with($lower_field, 'iptc.')){
$info = $this->getIPTCField(substr($field,5));
}elseif(strtolower(substr($field,0,5)) == 'exif.'){
}elseif(str_starts_with($lower_field, 'exif.')){
$info = $this->getExifField(substr($field,5));
}elseif(strtolower(substr($field,0,4)) == 'xmp.'){
}elseif(str_starts_with($lower_field, 'xmp.')){
$info = $this->getXmpField(substr($field,4));
}elseif(strtolower(substr($field,0,5)) == 'file.'){
}elseif(str_starts_with($lower_field, 'file.')){
$info = $this->getFileField(substr($field,5));
}elseif(strtolower(substr($field,0,5)) == 'date.'){
}elseif(str_starts_with($lower_field, 'date.')){
$info = $this->getDateField(substr($field,5));
}elseif(strtolower($field) == 'simple.camera'){
}elseif($lower_field == 'simple.camera'){
$info = $this->getCamera();
}elseif(strtolower($field) == 'simple.raw'){
}elseif($lower_field == 'simple.raw'){
return $this->getRawInfo();
}elseif(strtolower($field) == 'simple.title'){
}elseif($lower_field == 'simple.title'){
$info = $this->getTitle();
}elseif(strtolower($field) == 'simple.shutterspeed'){
}elseif($lower_field == 'simple.shutterspeed'){
$info = $this->getShutterSpeed();
}else{
$info = $this->getExifField($field);
@ -201,9 +202,10 @@ class JpegMeta {
* @return bool success or fail
*/
function setField($field, $value) {
if(strtolower(substr($field,0,5)) == 'iptc.'){
$lower_field = strtolower($field);
if(str_starts_with($lower_field, 'iptc.')){
return $this->setIPTCField(substr($field,5),$value);
}elseif(strtolower(substr($field,0,5)) == 'exif.'){
}elseif(str_starts_with($lower_field, 'exif.')){
return $this->setExifField(substr($field,5),$value);
}else{
return $this->setExifField($field,$value);
@ -220,9 +222,10 @@ class JpegMeta {
* @return bool
*/
function deleteField($field) {
if(strtolower(substr($field,0,5)) == 'iptc.'){
$lower_field = strtolower($field);
if(str_starts_with($lower_field, 'iptc.')){
return $this->deleteIPTCField(substr($field,5));
}elseif(strtolower(substr($field,0,5)) == 'exif.'){
}elseif(str_starts_with($lower_field, 'exif.')){
return $this->deleteExifField(substr($field,5));
}else{
return $this->deleteExifField($field);
@ -425,7 +428,7 @@ class JpegMeta {
}
// make sure datetimes are in correct format
if(strlen($field) >= 8 && strtolower(substr($field, 0, 8)) == 'datetime') {
if(strlen($field) >= 8 && str_starts_with(strtolower($field), 'datetime')) {
if(strlen($value) < 8 || $value[4] != ':' || $value[7] != ':') {
$value = date('Y:m:d H:i:s', strtotime($value));
}
@ -2638,7 +2641,7 @@ class JpegMeta {
if (isset($IPTCNames[$label])) {
$type = $IPTCNames[$label];
}
elseif (substr($label, 0, 7) == "IPTC_0x") {
elseif (str_starts_with($label, 'IPTC_0x')) {
$type = hexdec(substr($label, 7, 2));
}

View File

@ -583,8 +583,7 @@ class Mailer
} else {
$prefix = '[' . $conf['mailprefix'] . ']';
}
$len = strlen($prefix);
if (substr($this->headers['Subject'], 0, $len) !== $prefix) {
if (!str_starts_with($this->headers['Subject'], $prefix)) {
$this->headers['Subject'] = $prefix . ' ' . $this->headers['Subject'];
}

View File

@ -174,7 +174,7 @@ class Lists extends AbstractRewriter
protected function interpretSyntax($match, &$type)
{
if (substr($match, -1) == '*') {
if (str_ends_with($match, '*')) {
$type = 'u';
} else {
$type = 'o';

View File

@ -226,7 +226,7 @@ class Lexer
*/
protected function isSpecialMode($mode)
{
return (strncmp($mode, "_", 1) == 0);
return str_starts_with($mode, '_');
}
/**
@ -264,7 +264,7 @@ class Lexer
// modes starting with plugin_ are all handled by the same
// handler but with an additional parameter
if (substr($handler, 0, 7) == 'plugin_') {
if (str_starts_with($handler, 'plugin_')) {
[$handler, $plugin] = sexplode('_', $handler, 2, '');
return $this->handler->$handler($content, $is_match, $pos, $plugin);
}

View File

@ -178,7 +178,7 @@ class ParallelRegex
$pattern .= '(?';
break;
default:
if (substr($elt, 0, 1) == '\\')
if (str_starts_with($elt, '\\'))
$pattern .= $elt;
else $pattern .= str_replace('/', '\/', $elt);
}

View File

@ -36,7 +36,7 @@ class PassHash
$magic = '';
//determine the used method and salt
if (substr($hash, 0, 2) == 'U$') {
if (str_starts_with($hash, 'U$')) {
// This may be an updated password from user_update_7000(). Such hashes
// have 'U' added as the first character and need an extra md5().
$hash = substr($hash, 1);
@ -80,10 +80,10 @@ class PassHash
} elseif (preg_match('/^\$2(a|y)\$(.{2})\$/', $hash, $m)) {
$method = 'bcrypt';
$salt = $hash;
} elseif (substr($hash, 0, 6) == '{SSHA}') {
} elseif (str_starts_with($hash, '{SSHA}')) {
$method = 'ssha';
$salt = substr(base64_decode(substr($hash, 6)), 20);
} elseif (substr($hash, 0, 6) == '{SMD5}') {
} elseif (str_starts_with($hash, '{SMD5}')) {
$method = 'lsmd5';
$salt = substr(base64_decode(substr($hash, 6)), 16);
} elseif (preg_match('/^:B:(.+?):.{32}$/', $hash, $m)) {

View File

@ -404,7 +404,7 @@ class Api
*/
public function argumentWarningHandler($errno, $errstr)
{
if (substr($errstr, 0, 17) == 'Missing argument ') {
if (str_starts_with($errstr, 'Missing argument ')) {
throw new RemoteException('Method does not exist - wrong parameter count.', -32603);
}
}

View File

@ -467,12 +467,12 @@ class Indexer
if ($dir !== false) {
while (($f = readdir($dir)) !== false) {
if (
substr($f, -4) == '.idx' &&
(substr($f, 0, 1) == 'i' ||
substr($f, 0, 1) == 'w' ||
substr($f, -6) == '_w.idx' ||
substr($f, -6) == '_i.idx' ||
substr($f, -6) == '_p.idx')
str_ends_with($f, '.idx') &&
(str_starts_with($f, 'i') ||
str_starts_with($f, 'w') ||
str_ends_with($f, '_w.idx') ||
str_ends_with($f, '_i.idx') ||
str_ends_with($f, '_p.idx'))
)
@unlink($conf['indexdir'] . "/$f");
}
@ -697,11 +697,11 @@ class Indexer
$caret = '^';
$dollar = '$';
// check for wildcards
if (substr($xval, 0, 1) == '*') {
if (str_starts_with($xval, '*')) {
$xval = substr($xval, 1);
$caret = '';
}
if (substr($xval, -1, 1) == '*') {
if (str_ends_with($xval, '*')) {
$xval = substr($xval, 0, -1);
$dollar = '';
}
@ -777,12 +777,12 @@ class Indexer
$wlen = wordlen($word);
// check for wildcards
if (substr($xword, 0, 1) == '*') {
if (str_starts_with($xword, '*')) {
$xword = substr($xword, 1);
$caret = '';
--$wlen;
}
if (substr($xword, -1, 1) == '*') {
if (str_ends_with($xword, '*')) {
$xword = substr($xword, 0, -1);
$dollar = '';
--$wlen;
@ -1068,7 +1068,7 @@ class Indexer
protected function saveIndexKey($idx, $suffix, $id, $line)
{
global $conf;
if (substr($line, -1) != "\n")
if (!str_ends_with($line, "\n"))
$line .= "\n";
$fn = $conf['indexdir'] . '/' . $idx . $suffix;
$fh = @fopen($fn . '.tmp', 'w');

View File

@ -67,7 +67,7 @@ class BulkSubscriptionSender extends SubscriptionSender
continue;
}
if (substr($target, -1, 1) === ':') {
if (str_ends_with($target, ':')) {
// subscription target is a namespace, get all changes within
$changes = getRecentsSince($lastupdate, null, getNS($target));
} else {

View File

@ -288,7 +288,7 @@ class SubscriberManager
protected function file($id)
{
$meta_fname = '.mlist';
if ((substr($id, -1, 1) === ':')) {
if (str_ends_with($id, ':')) {
$meta_froot = getNS($id);
$meta_fname = '/' . $meta_fname;
} else {

View File

@ -88,7 +88,7 @@ class Admin extends Ui
protected function showSecurityCheck()
{
global $conf;
if (substr($conf['savedir'], 0, 2) !== './') return;
if (!str_starts_with($conf['savedir'], './')) return;
$img = DOKU_URL . $conf['savedir'] .
'/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png';
echo '<div id="security__check" data-src="' . $img . '"></div>';

View File

@ -115,7 +115,7 @@ class Display
{
if ($this->relativeDisplay !== null) {
$id = $this->mediaFile->getId();
if (substr($id, 0, strlen($this->relativeDisplay)) === $this->relativeDisplay) {
if (str_starts_with($id, $this->relativeDisplay)) {
$id = substr($id, strlen($this->relativeDisplay));
}
return ltrim($id, ':');

View File

@ -27,9 +27,8 @@ class PhpString
$path = substr($path, $rpos + 1);
}
$suflen = strlen($suffix);
if ($suflen && (substr($path, -$suflen) === $suffix)) {
$path = substr($path, 0, -$suflen);
if (str_ends_with($path, $suffix)) {
$path = substr($path, 0, -strlen($suffix));
}
return $path;

View File

@ -475,7 +475,7 @@ function idfilter($id, $ue = true)
if ($conf['useslash'] && $conf['userewrite']) {
$id = strtr($id, ':', '/');
} elseif (
strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' &&
str_starts_with(strtoupper(PHP_OS), 'WIN') &&
$conf['userewrite'] &&
strpos($INPUT->server->str('SERVER_SOFTWARE'), 'Microsoft-IIS') === false
) {
@ -1248,14 +1248,14 @@ function con($pre, $text, $suf, $pretty = false)
{
if ($pretty) {
if (
$pre !== '' && substr($pre, -1) !== "\n" &&
substr($text, 0, 1) !== "\n"
$pre !== '' && !str_ends_with($pre, "\n") &&
!str_starts_with($text, "\n")
) {
$pre .= "\n";
}
if (
$suf !== '' && substr($text, -1) !== "\n" &&
substr($suf, 0, 1) !== "\n"
$suf !== '' && !str_ends_with($text, "\n") &&
!str_starts_with($suf, "\n")
) {
$text .= "\n";
}
@ -1786,7 +1786,7 @@ function license_img($type)
$try = [];
$try[] = 'lib/images/license/' . $type . '/' . $conf['license'] . '.png';
$try[] = 'lib/images/license/' . $type . '/' . $conf['license'] . '.gif';
if (substr($conf['license'], 0, 3) == 'cc-') {
if (str_starts_with($conf['license'], 'cc-')) {
$try[] = 'lib/images/license/' . $type . '/cc.png';
}
foreach ($try as $src) {
@ -2031,7 +2031,7 @@ function inlineSVG($file, $maxsize = 2048)
$content = preg_replace('/<!DOCTYPE .*?>/i', '', $content); // doc type
$content = preg_replace('/>\s+</s', '><', $content); // newlines between tags
$content = trim($content);
if (substr($content, 0, 5) !== '<svg ') return false;
if (!str_starts_with($content, '<svg ')) return false;
return $content;
}

View File

@ -227,7 +227,7 @@ function linesToHash($lines, $lower = false)
{
$conf = [];
// remove BOM
if (isset($lines[0]) && substr($lines[0], 0, 3) === pack('CCC', 0xef, 0xbb, 0xbf))
if (isset($lines[0]) && str_starts_with($lines[0], pack('CCC', 0xef, 0xbb, 0xbf)))
$lines[0] = substr($lines[0], 3);
foreach ($lines as $line) {
//ignore comments (except escaped ones)
@ -487,7 +487,7 @@ function conf_decodeString($str)
function array_merge_with_removal($current, $new)
{
foreach ($new as $val) {
if (substr($val, 0, 1) == DOKU_CONF_NEGATION) {
if (str_starts_with($val, DOKU_CONF_NEGATION)) {
$idx = array_search(trim(substr($val, 1)), $current);
if ($idx !== false) {
unset($current[$idx]);

View File

@ -158,7 +158,7 @@ function checkFileStatus(&$media, &$file, $rev = '', $width = 0, $height = 0)
return [412, 'Precondition Failed'];
}
//handle external images
if (strncmp($MIME, 'image/', 6) == 0) $file = media_get_from_URL($media, $EXT, $CACHE);
if (str_starts_with($MIME, 'image/')) $file = media_get_from_URL($media, $EXT, $CACHE);
if (!$file) {
//download failed - redirect to original URL
return [302, $media];

View File

@ -575,13 +575,13 @@ function ft_snippet_re_preprocess($term)
$BR = '\b';
}
if (substr($term, 0, 2) == '\\*') {
if (str_starts_with($term, '\\*')) {
$term = substr($term, 2);
} else {
$term = $BL . $term;
}
if (substr($term, -2, 2) == '\\*') {
if (str_ends_with($term, '\\*')) {
$term = substr($term, 0, -2);
} else {
$term .= $BR;

View File

@ -339,7 +339,7 @@ function http_status($code = 200, $text = '')
$server_protocol = $INPUT->server->str('SERVER_PROTOCOL', false);
if (substr(PHP_SAPI, 0, 3) == 'cgi' || defined('SIMPLE_TEST')) {
if (str_starts_with(PHP_SAPI, 'cgi') || defined('SIMPLE_TEST')) {
header("Status: {$code} {$text}", true);
} elseif ($server_protocol == 'HTTP/1.1' || $server_protocol == 'HTTP/1.0') {
header($server_protocol . " {$code} {$text}", true, $code);

View File

@ -307,7 +307,7 @@ function idx_listIndexLengths()
return [];
$idx = [];
while (($f = readdir($dir)) !== false) {
if (substr($f, 0, 1) == 'i' && substr($f, -4) == '.idx') {
if (str_starts_with($f, 'i') && str_ends_with($f, '.idx')) {
$i = substr($f, 1, -4);
if (is_numeric($i))
$idx[] = (int)$i;

View File

@ -37,7 +37,7 @@ function checkUpdateMessages()
$cf = getCacheName($updateVersion, '.updmsg');
$lm = @filemtime($cf);
$is_http = substr(DOKU_MESSAGEURL, 0, 5) != 'https';
$is_http = !str_starts_with(DOKU_MESSAGEURL, 'https');
// check if new messages needs to be fetched
if ($lm < time() - (60 * 60 * 24) || $lm < @filemtime(DOKU_INC . DOKU_SCRIPT)) {
@ -52,7 +52,7 @@ function checkUpdateMessages()
$http = new DokuHTTPClient();
$http->timeout = 12;
$resp = $http->get(DOKU_MESSAGEURL . $updateVersion);
if (is_string($resp) && ($resp == "" || substr(trim($resp), -1) == '%')) {
if (is_string($resp) && ($resp == '' || str_ends_with(trim($resp), '%'))) {
// basic sanity check that this is either an empty string response (ie "no messages")
// or it looks like one of our messages, not WiFi login or other interposed response
io_saveFile($cf, $resp);

View File

@ -553,7 +553,7 @@ function is_ssl()
*/
function isWindows()
{
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
}
/**
@ -601,7 +601,7 @@ function fullpath($path, $exists = false)
{
static $run = 0;
$root = '';
$iswin = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' || !empty($GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS']));
$iswin = (isWindows() || !empty($GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS']));
// find the (indestructable) root of the path - keeps windows stuff intact
if ($path[0] == '/') {

View File

@ -117,13 +117,13 @@ function io_readFile($file, $clean = true)
{
$ret = '';
if (file_exists($file)) {
if (substr($file, -3) == '.gz') {
if (str_ends_with($file, '.gz')) {
if (!DOKU_HAS_GZIP) return false;
$ret = gzfile($file);
if (is_array($ret)) {
$ret = implode('', $ret);
}
} elseif (substr($file, -4) == '.bz2') {
} elseif (str_ends_with($file, '.bz2')) {
if (!DOKU_HAS_BZIP) return false;
$ret = bzfile($file);
} else {
@ -255,13 +255,13 @@ function _io_saveFile($file, $content, $append)
$mode = ($append) ? 'ab' : 'wb';
$fileexists = file_exists($file);
if (substr($file, -3) == '.gz') {
if (str_ends_with($file, '.gz')) {
if (!DOKU_HAS_GZIP) return false;
$fh = @gzopen($file, $mode . '9');
if (!$fh) return false;
gzwrite($fh, $content);
gzclose($fh);
} elseif (substr($file, -4) == '.bz2') {
} elseif (str_ends_with($file, '.bz2')) {
if (!DOKU_HAS_BZIP) return false;
if ($append) {
$bzcontent = bzfile($file);
@ -352,10 +352,10 @@ function io_replaceInFile($file, $oldline, $newline, $regex = false, $maxlines =
io_lock($file);
// load into array
if (substr($file, -3) == '.gz') {
if (str_ends_with($file, '.gz')) {
if (!DOKU_HAS_GZIP) return false;
$lines = gzfile($file);
} elseif (substr($file, -4) == '.bz2') {
} elseif (str_ends_with($file, '.bz2')) {
if (!DOKU_HAS_BZIP) return false;
$lines = bzfile($file, true);
} else {
@ -773,7 +773,7 @@ function io_grep($file, $pattern, $max = 0, $backref = false)
$line = '';
while (!feof($fh)) {
$line .= fgets($fh, 4096); // read full line
if (substr($line, -1) != "\n") continue;
if (!str_ends_with($line, "\n")) continue;
// check if line matches
if (preg_match($pattern, $line, $match)) {
@ -805,7 +805,7 @@ function io_getSizeFile($file)
{
if (!file_exists($file)) return 0;
if (substr($file, -3) == '.gz') {
if (str_ends_with($file, '.gz')) {
$fp = @fopen($file, "rb");
if ($fp === false) return 0;
fseek($fp, -4, SEEK_END);
@ -813,7 +813,7 @@ function io_getSizeFile($file)
fclose($fp);
$array = unpack("V", $buffer);
$uncompressedsize = end($array);
} elseif (substr($file, -4) == '.bz2') {
} elseif (str_ends_with($file, '.bz2')) {
if (!DOKU_HAS_BZIP) return 0;
$bz = bzopen($file, "r");
if ($bz === false) return 0;

View File

@ -15,6 +15,7 @@ spl_autoload_register('load_autoload');
// require all the common libraries
// for a few of these order does matter
require_once(DOKU_INC . 'inc/defines.php');
require_once(DOKU_INC . 'inc/compatibility.php'); // load early so we can use it everywhere
require_once(DOKU_INC . 'inc/actions.php');
require_once(DOKU_INC . 'inc/changelog.php');
require_once(DOKU_INC . 'inc/common.php');
@ -36,7 +37,6 @@ require_once(DOKU_INC . 'inc/template.php');
require_once(DOKU_INC . 'inc/toolbar.php');
require_once(DOKU_INC . 'inc/utf8.php');
require_once(DOKU_INC . 'inc/auth.php');
require_once(DOKU_INC . 'inc/compatibility.php');
require_once(DOKU_INC . 'inc/deprecated.php');
require_once(DOKU_INC . 'inc/legacy.php');
@ -87,7 +87,7 @@ function load_autoload($name)
$name = str_replace('\\', '/', $name);
// test mock namespace
if (substr($name, 0, 19) === 'dokuwiki/test/mock/') {
if (str_starts_with($name, 'dokuwiki/test/mock/')) {
$file = DOKU_INC . '_test/mock/' . substr($name, 19) . '.php';
if (file_exists($file)) {
require $file;
@ -96,7 +96,7 @@ function load_autoload($name)
}
// tests namespace
if (substr($name, 0, 14) === 'dokuwiki/test/') {
if (str_starts_with($name, 'dokuwiki/test/')) {
$file = DOKU_INC . '_test/tests/' . substr($name, 14) . '.php';
if (file_exists($file)) {
require $file;
@ -105,7 +105,7 @@ function load_autoload($name)
}
// plugin namespace
if (substr($name, 0, 16) === 'dokuwiki/plugin/') {
if (str_starts_with($name, 'dokuwiki/plugin/')) {
$name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
$file = DOKU_PLUGIN . substr($name, 16) . '.php';
if (file_exists($file)) {
@ -119,7 +119,7 @@ function load_autoload($name)
}
// template namespace
if (substr($name, 0, 18) === 'dokuwiki/template/') {
if (str_starts_with($name, 'dokuwiki/template/')) {
$name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
$file = DOKU_INC . 'lib/tpl/' . substr($name, 18) . '.php';
if (file_exists($file)) {
@ -133,7 +133,7 @@ function load_autoload($name)
}
// our own namespace
if (substr($name, 0, 9) === 'dokuwiki/') {
if (str_starts_with($name, 'dokuwiki/')) {
$file = DOKU_INC . 'inc/' . substr($name, 9) . '.php';
if (file_exists($file)) {
require $file;

View File

@ -658,7 +658,7 @@ function media_contentcheck($file, $mime)
}
}
}
if (substr($mime, 0, 6) == 'image/') {
if (str_starts_with($mime, 'image/')) {
$info = @getimagesize($file);
if ($mime == 'image/gif' && $info[2] != 1) {
return -1; // uploaded content did not match the file extension
@ -668,7 +668,7 @@ function media_contentcheck($file, $mime)
return -1;
}
# fixme maybe check other images types as well
} elseif (substr($mime, 0, 5) == 'text/') {
} elseif (str_starts_with($mime, 'text/')) {
global $TEXT;
$TEXT = io_readFile($file);
if (checkwordblock()) {

View File

@ -81,7 +81,7 @@ function getID($param = 'id', $clean = true)
}
// Namespace autolinking from URL
if (substr($id, -1) == ':' || ($conf['useslash'] && substr($id, -1) == '/')) {
if (str_ends_with($id, ':') || ($conf['useslash'] && str_ends_with($id, '/'))) {
if (page_exists($id . $conf['start'])) {
// start page inside namespace
$id .= $conf['start'];
@ -676,7 +676,7 @@ function prettyprint_id($id)
if (!$id || $id === ':') {
return '*';
}
if ((substr($id, -1, 1) === ':')) {
if (str_ends_with($id, ':')) {
$id .= '*';
}
return hsc($id);

View File

@ -153,7 +153,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer
foreach ($this->footnotes as $id => $footnote) {
// check its not a placeholder that indicates actual footnote text is elsewhere
if (substr($footnote, 0, 5) != "@@FNT") {
if (!str_starts_with($footnote, "@@FNT")) {
// open the footnote and set the anchor and backlink
$this->doc .= '<div class="fn">';
$this->doc .= '<sup><a href="#fnt__' . $id . '" id="fn__' . $id . '" class="fn_bot">';
@ -680,10 +680,10 @@ class Doku_Renderer_xhtml extends Doku_Renderer
$this->doc .= '</a></dt>' . DOKU_LF . '<dd>';
}
if ($text[0] == "\n") {
if (str_starts_with($text, "\n")) {
$text = substr($text, 1);
}
if (substr($text, -1) == "\n") {
if (str_ends_with($text, "\n")) {
$text = substr($text, 0, -1);
}
@ -1203,7 +1203,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer
$link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
[$ext, $mime] = mimetype($src, false);
if (substr($mime, 0, 5) == 'image' && $render) {
if (str_starts_with($mime, 'image') && $render) {
$link['url'] = ml(
$src,
[
@ -1297,7 +1297,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer
$link['url'] = ml($src, ['cache' => $cache]);
[$ext, $mime] = mimetype($src, false);
if (substr($mime, 0, 5) == 'image' && $render) {
if (str_starts_with($mime, 'image') && $render) {
// link only jpeg images
// if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
} elseif (($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) {
@ -1627,7 +1627,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer
public function _formatLink($link)
{
//make sure the url is XHTML compliant (skip mailto)
if (substr($link['url'], 0, 7) != 'mailto:') {
if (!str_starts_with($link['url'], 'mailto:')) {
$link['url'] = str_replace('&', '&amp;', $link['url']);
$link['url'] = str_replace('&amp;amp;', '&amp;', $link['url']);
}
@ -1681,7 +1681,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer
$ret = '';
[$ext, $mime] = mimetype($src);
if (substr($mime, 0, 5) == 'image') {
if (str_starts_with($mime, 'image')) {
// first get the $title
if (!is_null($title)) {
$title = $this->_xmlEntities($title);

View File

@ -311,7 +311,7 @@ function search_list(&$data, $base, $file, $type, $lvl, $opts)
//we do nothing with directories
if ($type == 'd') return false;
//only search txt files
if (substr($file, -4) == '.txt') {
if (str_ends_with($file, '.txt')) {
//check ACL
$id = pathID($file);
if (auth_quickaclcheck($id) < AUTH_READ) {
@ -343,7 +343,7 @@ function search_pagename(&$data, $base, $file, $type, $lvl, $opts)
//we do nothing with directories
if ($type == 'd') return true;
//only search txt files
if (substr($file, -4) != '.txt') return true;
if (!str_ends_with($file, '.txt')) return true;
//simple stringmatching
if (!empty($opts['query'])) {
@ -395,7 +395,7 @@ function search_allpages(&$data, $base, $file, $type, $lvl, $opts)
}
//only search txt files
if (substr($file, -4) != '.txt') return true;
if (!str_ends_with($file, '.txt')) return true;
$item = [];
$item['id'] = pathID($file);
@ -555,7 +555,7 @@ function search_universal(&$data, $base, $file, $type, $lvl, $opts)
} else {
if (empty($opts['listfiles'])) return $return;
if (empty($opts['skipacl']) && $item['perm'] < AUTH_READ) return $return;
if (!empty($opts['pagesonly']) && (substr($file, -4) != '.txt')) return $return;
if (!empty($opts['pagesonly']) && !str_ends_with($file, '.txt')) return $return;
if (empty($opts['showhidden']) && isHiddenPage($item['id'])) return $return;
if (!empty($opts['filematch']) && !preg_match('/' . $opts['filematch'] . '/', $file)) return $return;
if (!empty($opts['idmatch']) && !preg_match('/' . $opts['idmatch'] . '/', $item['id'])) return $return;

View File

@ -150,7 +150,7 @@ function tpl_toc($return = false)
if (is_array($TOC)) {
// if a TOC was prepared in global scope, always use it
$toc = $TOC;
} elseif (($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
} elseif (($ACT == 'show' || str_starts_with($ACT, 'export')) && !$REV && $INFO['exists']) {
// get TOC from metadata, render if neccessary
$meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
$tocok = $meta['internal']['toc'] ?? true;
@ -1711,7 +1711,7 @@ function tpl_getMediaFile($search, $abs = false, &$imginfo = null, $fallback = t
$ismedia = false;
// loop through candidates until a match was found:
foreach ($search as $img) {
if (substr($img, 0, 1) == ':') {
if (str_starts_with($img, ':')) {
$file = mediaFN($img);
$ismedia = true;
} else {