HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpprm/wp-content/themes/ronneby/inc/sb_title_allocate.php
<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
class SB_Title_Allocate {

	private static function sb_mb_substr_replace($string, $replacement, $start, $length = null, $encoding = null) {
		if ($encoding == null)
			$encoding = mb_internal_encoding();
		if ($length == null) {
			return mb_substr($string, 0, $start, $encoding) . $replacement;
		} else {
			if ($length < 0)
				$length = mb_strlen($string, $encoding) - $start + $length;
			return
					mb_substr($string, 0, $start, $encoding) .
					$replacement .
					mb_substr($string, $start + $length, mb_strlen($string, $encoding), $encoding);
		}
	}

	private static function sb_strrpos($haystack = '', $needle = '', $need_count = 1) {
		$count = 0;

		if (!empty($haystack) && !empty($needle)) {
			for ($i = mb_strlen($haystack); $i >= 0; $i--) {
				if (mb_substr($haystack, $i, 1) === $needle) {
					$count++;
				}

				if ($count === $need_count) {
					return $i;
				}
			}
		}

		return false;
	}
	
	public static function wrap_last_worlds($text, $wrap_before = '', $wrap_after = '') {
		if (empty($text))
			return $text;
		
		$text = trim(str_replace('  ', '', $text));
		
		$whitespaces = substr_count($text, ' ');
		
		if ($whitespaces > 1) {
			$text = preg_replace('/\s(\S+)\s(\S+)$/', " {$wrap_before}\$1 \$2{$wrap_after}", $text);
		} elseif($whitespaces == 1){
			$text = str_replace(' ', ' '.$wrap_before, $text).$wrap_after;
		}
		
		return $text;
	}
	
	public static function wrap_rand_letter($text, $wrap_before='', $wrap_after='') {
		if (empty($text))
			return $text;
		
		$text = trim(str_replace('  ', '', $text));
		$whitespaces = substr_count($text, ' ');
		$rand_letter = $first_whitespace = 0;
		
		if ($whitespaces == 0) {
			if (mb_strlen($text)>2) {
				$rand_letter = mt_rand(0, mb_strlen($text)-1);

				$text = self::sb_mb_substr_replace($text, $wrap_before.mb_substr($text, $rand_letter, 1).$wrap_after, $rand_letter, 1);
			}
		} elseif($whitespaces == 1) {
			$first_whitespace = mb_strpos($text, ' ');
			$rand_letter = mt_rand($first_whitespace+1, mb_strlen($text)-1);
			
			$text = self::sb_mb_substr_replace($text, $wrap_before.mb_substr($text, $rand_letter, 1).$wrap_after, $rand_letter, 1);
		} else {
			$first_whitespace = self::sb_strrpos($text, ' ', 2);
			$rand_letter = mt_rand($first_whitespace+1, mb_strlen($text)-1);
			
			if (mb_substr($text, $rand_letter, 1) == ' ') {
				$rand_letter++;
			}
			
			$text = self::sb_mb_substr_replace($text, $wrap_before.mb_substr($text, $rand_letter, 1).$wrap_after, $rand_letter, 1);
		}
		
		return $text;
	}

}