mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
fix Modifier
This commit is contained in:
@@ -13,8 +13,8 @@ namespace Fenom;
|
||||
* Collection of modifiers
|
||||
* @author Ivan Shalganov <a.cobest@gmail.com>
|
||||
*/
|
||||
class Modifier {
|
||||
|
||||
class Modifier
|
||||
{
|
||||
/**
|
||||
* Date format
|
||||
*
|
||||
@@ -22,11 +22,15 @@ class Modifier {
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public static function dateFormat($date, $format = "%b %e, %Y") {
|
||||
public static function dateFormat($date, $format = "%b %e, %Y")
|
||||
{
|
||||
if (is_string($date) && !is_numeric($date)) {
|
||||
$date = strtotime($date);
|
||||
if(!$date) $date = time();
|
||||
if (!$date) {
|
||||
$date = time();
|
||||
}
|
||||
}
|
||||
|
||||
return strftime($format, $date);
|
||||
}
|
||||
|
||||
@@ -35,11 +39,13 @@ class Modifier {
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public static function date($date, $format = "Y m d") {
|
||||
public static function date($date, $format = "Y m d")
|
||||
{
|
||||
if (is_string($date) && !is_numeric($date)) {
|
||||
$date = strtotime($date);
|
||||
if (!$date) $date = time();
|
||||
}
|
||||
|
||||
return date($format, $date);
|
||||
}
|
||||
|
||||
@@ -50,7 +56,8 @@ class Modifier {
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public static function escape($text, $type = 'html') {
|
||||
public static function escape($text, $type = 'html')
|
||||
{
|
||||
switch (strtolower($type)) {
|
||||
case "url":
|
||||
return urlencode($text);
|
||||
@@ -68,7 +75,8 @@ class Modifier {
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public static function unescape($text, $type = 'html') {
|
||||
public static function unescape($text, $type = 'html')
|
||||
{
|
||||
switch (strtolower($type)) {
|
||||
case "url":
|
||||
return urldecode($text);
|
||||
@@ -89,7 +97,8 @@ class Modifier {
|
||||
* @param bool $middle
|
||||
* @return string
|
||||
*/
|
||||
public static function truncate($string, $length = 80, $etc = '...', $by_words = false, $middle = false) {
|
||||
public static function truncate($string, $length = 80, $etc = '...', $by_words = false, $middle = false)
|
||||
{
|
||||
if ($middle) {
|
||||
if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) {
|
||||
if (count($match) == 3) {
|
||||
@@ -109,6 +118,7 @@ class Modifier {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
@@ -119,7 +129,8 @@ class Modifier {
|
||||
* @param bool $to_line strip line ends
|
||||
* @return string
|
||||
*/
|
||||
public static function strip($str, $to_line = false) {
|
||||
public static function strip($str, $to_line = false)
|
||||
{
|
||||
$str = trim($str);
|
||||
if ($to_line) {
|
||||
return preg_replace('#[\s]+#ms', ' ', $str);
|
||||
@@ -133,7 +144,8 @@ class Modifier {
|
||||
* @param mixed $item
|
||||
* @return int
|
||||
*/
|
||||
public static function length($item) {
|
||||
public static function length($item)
|
||||
{
|
||||
if (is_string($item)) {
|
||||
return strlen(preg_replace('#[\x00-\x7F]|[\x80-\xDF][\x00-\xBF]|[\xE0-\xEF][\x00-\xBF]{2}#s', ' ', $item));
|
||||
} elseif (is_array($item)) {
|
||||
@@ -146,15 +158,16 @@ class Modifier {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $value
|
||||
* @param $list
|
||||
* @return bool
|
||||
*/
|
||||
public static function in($value, $list) {
|
||||
public static function in($value, $list)
|
||||
{
|
||||
if (is_array($list)) {
|
||||
return in_array($value, $list);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user