<?php
/*
 * Software Name: Eorisis Pixels
 * Software URI: https://eorisis.com/shop/software/joomla/pixels
 * Author: Eorisis
 * Author URI: https://eorisis.com
 * Copyright: Copyright (C) 2011-2025 EORISIS. All Rights Reserved.
 * License: GNU General Public License version 2; See https://eorisis.com/gpl
 * Terms of Service: https://eorisis.com/tos
 */
namespace com_eorisis_pixels\framework\lib\core\model;
\defined('_JEXEC') or die;
\defined('EORISIS_MBSTRING') or \define('EORISIS_MBSTRING', \extension_loaded('mbstring'));

class strip
{
	public function __construct() {}

	// --------------------------------------------------

	public static function substr($string, $start, $length = null) : string
	{
		if (EORISIS_MBSTRING)
		{
			return \mb_substr((string)$string, $start, $length, 'UTF-8');
		}

		return \substr((string)$string, $start, $length);
	}

	// --------------------------------------------------

	public static function char_limit($string, int $limit, bool $keep_last_word = false, string $extra_str = '..')
	{
		if (\com_eorisis_pixels\framework\lib\core\model\math::strlen($string) <= $limit)
		{
			return $string;
		}

		$string = self::substr($string, 0, $limit);

		if ($keep_last_word)
		{
			$length = \com_eorisis_pixels\framework\lib\core\model\find::strrpos(' ', $string);
			$string = self::substr($string, 0, $length);
		}

		$string .= $extra_str;
		return $string;
	}

	// --------------------------------------------------

	public static function tags($string, array $allowed_tags = [])
	{
		if (PHP_VERSION_ID >= 70400) // >= 7.4
		{
			return \strip_tags($string, $allowed_tags);
		}

		return \strip_tags($string, \implode($allowed_tags));
	}
}
