-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update copyrights, fix DateTime helper
- Loading branch information
Showing
13 changed files
with
74 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ | |
* Yii2 Custom array helper | ||
* | ||
* @category Helpers | ||
* @version 1.4.8 | ||
* @version 1.5.0 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]> | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019 - 2021 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
*/ | ||
|
@@ -250,6 +250,28 @@ public static function diff($array1, $array2) { | |
return $array; | ||
} | ||
|
||
|
||
/** | ||
* Add or remove (if already exists) a key=>value pair to an array | ||
* | ||
* @param $array1 | ||
* @param $array2 | ||
* @return array|null | ||
*/ | ||
public static function update($array, $findKey, $findValue) { | ||
|
||
foreach($array as $key => $value) { | ||
|
||
if ($key == $findKey && $value == $findValue) { | ||
unset($array[$key]); | ||
return $array; | ||
} | ||
} | ||
|
||
$array[$findKey] = $findValue; | ||
return $array; | ||
} | ||
|
||
/** | ||
* Merges multidimensional arrays. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ | |
* Yii2 Date and Time helper | ||
* | ||
* @category Helpers | ||
* @version 1.4.8 | ||
* @version 1.5.0 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]> | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019 - 2021 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
*/ | ||
|
@@ -286,33 +286,42 @@ public static function diff($datetime1 = null, $datetime2 = null, $options = []) | |
//@TODO: https://www.yiiframework.com/doc/api/2.0/yii-i18n-formatter#asRelativeTime()-detail | ||
|
||
static::initI18N('app/helpers'); | ||
$default = ['layout' => '<span class="{class}">{datetime}</span>', 'inpastClass' => 'field-inpast-datetime', 'futureClass' => 'field-future-datetime' | ||
$default = [ | ||
'layout' => '<span class="{class}">{datetime}</span>', | ||
'inpastClass' => 'field-inpast-datetime', | ||
'futureClass' => 'field-future-datetime' | ||
]; | ||
$options = array_merge($default, $options); | ||
|
||
if (!$datetime1) | ||
return; | ||
|
||
$date = new \DateTime(); | ||
|
||
if ($datetime2) | ||
$datenow = new \DateTime($datetime2); | ||
else | ||
$datenow = new \DateTime("now"); | ||
$datenow = $date->createFromFormat('Y-m-d H:i:s', $datetime2); | ||
|
||
$dateend = new \DateTime($datetime1); | ||
$interval = $datenow->diff($dateend); | ||
$content = $datetime1; | ||
if (!is_null($datenow)) { | ||
$dateend = new \DateTime($datetime1); | ||
$interval = $datenow->diff($dateend); | ||
|
||
$content = Yii::t('app/helpers', '{y, plural, =0{} =1{# year} one{# year} few{# years} many{# years} other{# years}}{y, plural, =0{} =1{, } other{, }}{m, plural, =0{} =1{# month} one{# month} few{# months} many{# months} other{# months}}{m, plural, =0{} =1{, } other{, }}{d, plural, =0{} =1{# day} one{# day} few{# days} many{# days} other{# days}}{d, plural, =0{} =1{, } other{, }}{h, plural, =0{} =1{# hour} one{# hour} few{# hours} many{# hours} other{# hours}}{h, plural, =0{} =1{, } other{, }}{i, plural, =0{} =1{# minute} one{# minute} few{# minutes} many{# minutes} other{# minutes}}{i, plural, =0{} =1{, } other{, }}{s, plural, =0{} =1{# second} one{# second} few{# seconds} many{# seconds} other{# seconds}}{invert, plural, =0{ left} =1{ ago} other{}}', | ||
$interval | ||
); | ||
$content = Yii::t('app/helpers', '{y, plural, =0{} =1{# year} one{# year} few{# years} many{# years} other{# years}}{y, plural, =0{} =1{, } other{, }}{m, plural, =0{} =1{# month} one{# month} few{# months} many{# months} other{# months}}{m, plural, =0{} =1{, } other{, }}{d, plural, =0{} =1{# day} one{# day} few{# days} many{# days} other{# days}}{d, plural, =0{} =1{, } other{, }}{h, plural, =0{} =1{# hour} one{# hour} few{# hours} many{# hours} other{# hours}}{h, plural, =0{} =1{, } other{, }}{i, plural, =0{} =1{# minute} one{# minute} few{# minutes} many{# minutes} other{# minutes}}{i, plural, =0{} =1{, } other{, }}{s, plural, =0{} =1{# second} one{# second} few{# seconds} many{# seconds} other{# seconds}}{invert, plural, =0{ left} =1{ ago} other{}}', | ||
$interval | ||
); | ||
} | ||
|
||
$layout = $options['layout']; | ||
if ($interval->invert == 1) | ||
$layout = str_replace('{class}', $options['inpastClass'], $layout); | ||
else | ||
$layout = str_replace('{class}', $options['futureClass'], $layout); | ||
|
||
return str_replace('{datetime}', $content, $layout); | ||
|
||
if (!empty($layout)) { | ||
if ($interval->invert == 1) | ||
$layout = str_replace('{class}', $options['inpastClass'], $layout); | ||
else | ||
$layout = str_replace('{class}', $options['futureClass'], $layout); | ||
|
||
return str_replace('{datetime}', $content, $layout); | ||
} else { | ||
return $content; | ||
} | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ | |
* Yii2 Extend DB schema | ||
* | ||
* @category Helpers | ||
* @version 1.4.8 | ||
* @version 1.5.0 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]> | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019 - 2021 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ | |
* Yii2 Exchange Rates | ||
* | ||
* @category Helpers | ||
* @version 1.4.8 | ||
* @version 1.5.0 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]> | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019 - 2021 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ | |
* Yii2 Custom file helper | ||
* | ||
* @category Helpers | ||
* @version 1.4.8 | ||
* @version 1.5.0 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]> | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019 - 2021 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
* Yii2 IP address helper | ||
* | ||
* @category Helpers | ||
* @version 1.4.8 | ||
* @version 1.5.0 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]>, Jonavon Wilcox <[email protected]>, Manuel Kasper <[email protected]> | ||
* @see https://gist.github.com/stibiumz/5e6a92a195c50c875649, https://gist.github.com/jonavon/2028872, http://m0n0.ch/wall, https://www.experts-exchange.com/questions/23903322/Need-PHP-code-for-calculating-subnets.html | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019-2020 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2019-2023 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2003-2004 Manuel Kasper <[email protected]> | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
|
@@ -2536,7 +2536,7 @@ public static function getReservedSubnets() { | |
public static function whois($host, $flags = null, $asHtml = true) { | ||
|
||
$zone = array_slice(explode(".", trim($host)), -1)[0]; | ||
if (isset(self::WHOIS_SERVERS[$zone])) { | ||
if (!is_null(self::WHOIS_SERVERS[$zone])) { | ||
$servers = self::WHOIS_SERVERS[$zone]; | ||
foreach ($servers as $server) { | ||
if ($info = self::whoisQuery($server, trim($host))) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ | |
* Yii2 keyboard layout helper | ||
* | ||
* @category Helpers | ||
* @version 1.4.8 | ||
* @version 1.5.0 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]> | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019 - 2021 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
*/ | ||
|
@@ -79,7 +79,7 @@ public static function getKeyboardLayout($locale = null, $format = false) { | |
$chars = preg_split('!!u', self::$layouts[$locale], null, PREG_SPLIT_NO_EMPTY); | ||
if ($format == 1) { | ||
return $chars; | ||
} elseif ($format == 2 && is_countable($chars)) { | ||
} elseif ($format == 2 && is_array($chars)) { | ||
$keycodes = []; | ||
foreach ($chars as $char) { | ||
$keycodes[] = \ord($char); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ | |
* Yii2 String Helper | ||
* | ||
* @category Helpers | ||
* @version 1.4.8 | ||
* @version 1.5.0 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]> | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019 - 2021 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ | |
* Yii2 Text Analyzer | ||
* | ||
* @category Helpers | ||
* @version 1.4.8 | ||
* @version 1.5.0 | ||
* @author Alexsander Vyshnyvetskyy <[email protected]> | ||
* @link https://github.com/wdmg/yii2-helpers | ||
* @copyright Copyright (c) 2019 - 2021 W.D.M.Group, Ukraine | ||
* @copyright Copyright (c) 2019 - 2023 W.D.M.Group, Ukraine | ||
* @license https://opensource.org/licenses/MIT Massachusetts Institute of Technology (MIT) License | ||
* | ||
*/ | ||
|