Skip to content

Commit

Permalink
Updates to release v1.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Sep 26, 2018
1 parent 8cf709d commit 48ded42
Show file tree
Hide file tree
Showing 83 changed files with 216 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Licensing
---------

It should also be made clear that **all code contributed to yii2-helpers** must be
licensable under the [BSD-3 license][licensing]. Code that cannot be released
licensable under the [BSD-3-Clause license][licensing]. Code that cannot be released
under this license **cannot be accepted** into the project.

[issue-search]: https://github.com/kartik-v/yii2-helpers/search?q=&type=Issues
Expand Down
45 changes: 29 additions & 16 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
Change Log: `yii2-helpers`
==========================

## Version 1.3.7

**Date:** 26-Sep-2018

- Enhancements to support Bootstrap v4.x.
- Move all source code to `src` directory.
- (enh #44): Secure `userIP` function.
- (enh #43): Update Vietnamese Translations.
- (enh #42): Update Hungarian Translations.
- (enh #41): Update German Translations.
- (enh #40): Fixed `a moment ago` readout.
- (enh #39): Update Greek Translations.

## Version 1.3.6

**Date:** 26-Nov-2016

- (enh #33): Update Italian Translations.
- (enh #35): Add Slovak Translations.
- (enh #36): Update Russian Translations.
- (enh #37): Update Finnish Translations.
- (bug #38): Fix buttonGroup `item` parsing when set as Closure.
- (enh #37): Update Finnish Translations.
- (enh #36): Update Russian Translations.
- (enh #35): Add Slovak Translations.
- (enh #33): Update Italian Translations.
- Update message config to include all default standard translation files.
- Add github contribution and issue/PR logging templates.
- Add branch alias for dev-master latest release.
Expand All @@ -19,9 +32,9 @@ Change Log: `yii2-helpers`

**Date:** 12-Dec-2015

- (enh #27): Add Ukranian Translations.
- (enh #28): Add Italian Translations.
- (enh #29): Code style and formatting enhancements.
- (enh #28): Add Italian Translations.
- (enh #27): Add Ukranian Translations.

## Version 1.3.3

Expand All @@ -44,23 +57,23 @@ Change Log: `yii2-helpers`

**Date:** 15-Jun-2015

- (enh #15): Initialize i18N for getBrowser method.
- (enh #16): Add Russian translation messages.
- (enh #17, #18): Update Russian translation messages.
- (enh #19): Add Portuguese Brazilian translation messages.
- (bug #21): Remove duplicate browsers in list.
- (enh #22): Add Spanish translations.
- (bug #21): Remove duplicate browsers in list.
- (enh #19): Add Portuguese Brazilian translation messages.
- (enh #17, #18): Update Russian translation messages.
- (enh #16): Add Russian translation messages.
- (enh #15): Initialize i18N for getBrowser method.

## Version 1.3.0

**Date:** 23-Jan-2015

- (enh #7): Implement translations.
- (enh #8): Convert days, months, ones, tens, triplets to static methods
- (enh #9): Add/Enhance new methods for `dayList`, `monthList` and `dateList`.
- (enh #10): Enhance `timeList` method to include ranges and intervals.
- (enh #11): Add French Translations and fix `genCalList`.
- (enh #12): Completed French Translations.
- (enh #11): Add French Translations and fix `genCalList`.
- (enh #10): Enhance `timeList` method to include ranges and intervals.
- (enh #9): Add/Enhance new methods for `dayList`, `monthList` and `dateList`.
- (enh #8): Convert days, months, ones, tens, triplets to static methods
- (enh #7): Implement translations.

## Version 1.2.0

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
yii2-helpers
============

[![Latest Stable Version](https://img.shields.io/packagist/v/kartik-v/yii2-helpers.svg)](https://packagist.org/packages/kartik-v/yii2-helpers)
[![Latest Stable Version](https://poser.pugx.org/kartik-v/yii2-helpers/v/stable)](https://packagist.org/packages/kartik-v/yii2-helpers)
[![Latest Unstable Version](https://poser.pugx.org/kartik-v/yii2-helpers/v/unstable)](https://packagist.org/packages/kartik-v/yii2-helpers)
[![License](https://poser.pugx.org/kartik-v/yii2-helpers/license)](https://packagist.org/packages/kartik-v/yii2-helpers)
[![Total Downloads](https://poser.pugx.org/kartik-v/yii2-helpers/downloads)](https://packagist.org/packages/kartik-v/yii2-helpers)
[![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-helpers/d/monthly)](https://packagist.org/packages/kartik-v/yii2-helpers)
Expand All @@ -12,7 +13,7 @@ This extension is a collection of useful helper functions for Yii Framework 2.0.
### Html Class
[```VIEW DEMO```](http://demos.krajee.com/helper-functions/html)

This class extends the [Yii Html Helper](https://github.com/yiisoft/yii2/blob/master/framework/helpers/Html.php) to incorporate additional HTML markup functionality and features available in [Bootstrap 3.0](http://getbootstrap.com/). The helper functions available in this class are:
This class extends the [Yii Html Helper](https://github.com/yiisoft/yii2/blob/master/framework/helpers/Html.php) to incorporate additional HTML markup functionality and features available in [Bootstrap 3.x / 4.x](http://getbootstrap.com/). The helper functions available in this class are:
- Icon
- Label
- Badge
Expand Down Expand Up @@ -92,4 +93,4 @@ echo Enum::properize('Chris');

## License

**yii2-helpers** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.
**yii2-helpers** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"homepage": "http://www.krajee.com/"
}
],
"minimum-stability": "stable",
"require": {
"kartik-v/yii2-krajee-base": ">=1.9",
"yiisoft/yii2-bootstrap": "*"
},
"autoload": {
"psr-4": {
"kartik\\helpers\\": ""
"kartik\\helpers\\": "src"
}
},
"extra": {
Expand Down
90 changes: 36 additions & 54 deletions Enum.php → src/Enum.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2013 - 2016
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2013 - 2018
* @package yii2-helpers
* @version 1.3.6
* @version 1.3.7
*/

namespace kartik\helpers;
Expand Down Expand Up @@ -34,7 +34,7 @@ class Enum extends Inflector
'day' => 86400,
'hour' => 3600,
'minute' => 60,
'second' => 1
'second' => 1,
];

/**
Expand Down Expand Up @@ -69,7 +69,7 @@ public static function isEmpty($var)
* ~~~
*
* @param string $needle the value to search
* @param array $haystack the array to scan
* @param array $haystack the array to scan
*
* @return boolean
*/
Expand Down Expand Up @@ -109,7 +109,7 @@ public static function properize($string)
* ~~~
*
* @param string $fromTime start date time
* @param boolean $human if true returns an approximate human friendly output. If set to `false`, will attempt an
* @param boolean $human if true returns an approximate human friendly output. If set to `false`, will attempt an
* exact conversion of time intervals.
* @param string $toTime end date time (defaults to current system time)
* @param string $append the string to append for the converted elapsed time. Defaults to ' ago'.
Expand Down Expand Up @@ -144,7 +144,7 @@ public static function initI18N()
Yii::$app->i18n->translations['kvenum*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => "@kvenum/messages",
'forceTranslation' => true
'forceTranslation' => true,
];
}

Expand All @@ -160,7 +160,7 @@ public static function initI18N()
* ~~~
*
* @param integer $interval time interval in seconds
* @param string $append the string to append for the converted elapsed time. Defaults to `' ago'`.
* @param string $append the string to append for the converted elapsed time. Defaults to `' ago'`.
* @param boolean $human if true returns an approximate human friendly output. If set to `false`, will attempt an
* exact conversion of time intervals.
*
Expand All @@ -179,7 +179,7 @@ public static function timeInterval($interval, $append = null, $human = true)
if ($interval <= 0) {
$elapsed = Yii::t('kvenum', 'a moment');
} elseif ($interval < 60) {
$elapsed = Yii::t('kvenum', '{n, plural, one{one second} other{# seconds}}', [ 'n' => $interval]);
$elapsed = Yii::t('kvenum', '{n, plural, one{one second} other{# seconds}}', ['n' => $interval]);
} elseif ($interval >= 60 && $interval < $intervals['hour']) {
$interval = floor($interval / $intervals['minute']);
$elapsed = Yii::t('kvenum', '{n, plural, one{one minute} other{# minutes}}', ['n' => $interval]);
Expand Down Expand Up @@ -211,7 +211,7 @@ public static function timeInterval($interval, $append = null, $human = true)
* Example Output:
* 1 year 5 months 3 days ago
*
* @param integer $time elapsed number of seconds
* @param integer $time elapsed number of seconds
* @param array $intervals configuration of time intervals in seconds
*
* @return string
Expand Down Expand Up @@ -240,7 +240,7 @@ protected static function time2String($time, $intervals)
* echo Enum::formatBytes(17328347842.25, 3); // returns: 16.138 GB
* ~~~
*
* @param double $bytes number of bytes
* @param double $bytes number of bytes
* @param integer $precision the number of decimal places to round off
*
* @return string
Expand Down Expand Up @@ -359,7 +359,7 @@ public static function ones()
' ' . Yii::t('kvenum', 'sixteen'),
' ' . Yii::t('kvenum', 'seventeen'),
' ' . Yii::t('kvenum', 'eighteen'),
' ' . Yii::t('kvenum', 'nineteen')
' ' . Yii::t('kvenum', 'nineteen'),
];
}

Expand Down Expand Up @@ -391,7 +391,7 @@ public static function tens()
' ' . Yii::t('kvenum', 'sixty'),
' ' . Yii::t('kvenum', 'seventy'),
' ' . Yii::t('kvenum', 'eighty'),
' ' . Yii::t('kvenum', 'ninety')
' ' . Yii::t('kvenum', 'ninety'),
];
}

Expand Down Expand Up @@ -451,7 +451,7 @@ public static function days()
Yii::t('kvenum', 'Wednesday'),
Yii::t('kvenum', 'Thursday'),
Yii::t('kvenum', 'Friday'),
Yii::t('kvenum', 'Saturday')
Yii::t('kvenum', 'Saturday'),
];
}

Expand Down Expand Up @@ -527,8 +527,8 @@ public static function yearList($from, $to = null, $keys = false, $desc = true)
* Generate a month or day array list for Gregorian calendar
*
* @param string $unit whether 'day' or 'month'
* @param boolean $abbr whether to return abbreviated day or month
* @param integer $start the first day or month to set. Defaults to `1`.
* @param boolean $abbr whether to return abbreviated day or month
* @param integer $start the first day or month to set. Defaults to `1`.
* @param string $case whether 'upper', lower', or null. If null, then the initcap case will be used.
*
* @return array list of days or months
Expand Down Expand Up @@ -572,8 +572,8 @@ protected static function genCalList($unit = 'day', $abbr = false, $start = 1, $
* print_r(Enum::monthList(true, 4, 'upper'));
* ~~~
*
* @param boolean $abbr whether to return abbreviated month
* @param integer $start the first month to set. Defaults to `1` for `January`.
* @param boolean $abbr whether to return abbreviated month
* @param integer $start the first month to set. Defaults to `1` for `January`.
* @param string $case whether 'upper', lower', or null. If null, then the initcap case will be used.
*
* @return array list of months
Expand All @@ -586,8 +586,8 @@ public static function monthList($abbr = false, $start = 1, $case = null)
/**
* Generate a day array list for Gregorian calendar
*
* @param boolean $abbr whether to return abbreviated day
* @param integer $start the first day to set. Defaults to `1` for `Sunday`.
* @param boolean $abbr whether to return abbreviated day
* @param integer $start the first day to set. Defaults to `1` for `Sunday`.
* @param string $case whether 'upper', lower', or null. If null, then the initcap case will be used.
*
* @return array list of days
Expand All @@ -607,9 +607,9 @@ public static function dayList($abbr = false, $start = 1, $case = null)
* print_r(Enum::dateList(1, 10));
* ~~~
*
* @param integer $from the start day, defaults to 1
* @param integer $to the end day, defaults to 31
* @param integer $interval the date interval, defaults to 1.
* @param integer $from the start day, defaults to 1
* @param integer $to the end day, defaults to 31
* @param integer $interval the date interval, defaults to 1.
* @param boolean $intervalFromZero whether to start incrementing intervals from zero if $from = 1.
* @param boolean $showLast whether to show the last date (set in $to) even if it does not match interval.
*
Expand Down Expand Up @@ -651,11 +651,11 @@ public static function dateList($from = 1, $to = 31, $interval = 1, $intervalFro
* echo implode(', ', Enum::timeList('sec', 5));
* ~~~
*
* @param string $unit the time unit ('hour', 'min', 'sec', 'ms')
* @param string $unit the time unit ('hour', 'min', 'sec', 'ms')
* @param integer $interval the time interval.
* @param integer $from the time from (defaults to 23 for hour
* @param integer $to the time to (defaults to 1).
* @param boolean $padZero whether to pad zeros to the left of each time unit value.
* @param boolean $padZero whether to pad zeros to the left of each time unit value.
*
* @return array
* @throws InvalidConfigException if $unit passed is invalid
Expand Down Expand Up @@ -734,7 +734,7 @@ public static function boolList($false = null, $true = null)
* echo Enum::array2table($data);
* ~~~
*
* @param array $array the associative array to be converted
* @param array $array the associative array to be converted
* @param boolean $transpose whether to show keys as rows instead of columns. This parameter should be used only
* for a single dimensional associative array. If used for a multidimensional array, the sub array will be imploded
* as text.
Expand Down Expand Up @@ -787,7 +787,7 @@ public static function array2table(
}

if (!isset($array[0]) || !is_array($array[0])) {
$array = array($array);
$array = [$array];
}
// Take the keys from the first row as the headings
foreach (array_keys($array[0]) as $heading) {
Expand Down Expand Up @@ -894,32 +894,14 @@ public static function getType($var)
*/
public static function userIP($filterLocal = true)
{
$ipSources = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
];
foreach ($ipSources as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
if ($filterLocal) {
$checkFilter = filter_var(
$ip,
FILTER_VALIDATE_IP,
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
);
if ($checkFilter !== false) {
return $ip;
}
} else {
return $ip;
}
}
$ip = Yii::$app->request->getUserIP();
if ($filterLocal) {
$checkFilter = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
if ($checkFilter !== false) {
return $ip;
}
} else {
return $ip;
}
return 'Unknown';
}
Expand All @@ -934,8 +916,8 @@ public static function userIP($filterLocal = true)
* ~~~
*
* @param boolean $common show common browsers only
* @param array $browsers the list of browsers
* @param string $agent user agent
* @param array $browsers the list of browsers
* @param string $agent user agent
*
* @return array the browser information
*/
Expand Down Expand Up @@ -988,7 +970,7 @@ public static function getBrowser($common = false, $browsers = [], $agent = null
'code' => 'other',
'name' => Yii::t('kvenum', 'Other'),
'version' => "?",
'platform' => Yii::t('kvenum', 'Unknown')
'platform' => Yii::t('kvenum', 'Unknown'),
];
$ios = Yii::t('kvenum', 'iOS');
$unix = Yii::t('kvenum', 'Unix');
Expand Down
Loading

0 comments on commit 48ded42

Please sign in to comment.