These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Copyright (c) 2013-2016 |
||
4 | * |
||
5 | * @category Library |
||
6 | * @package Dwoo\Plugins\Functions |
||
7 | * @author Jordi Boggiano <[email protected]> |
||
8 | * @author David Sanchez <[email protected]> |
||
9 | * @copyright 2008-2013 Jordi Boggiano |
||
10 | * @copyright 2013-2016 David Sanchez |
||
11 | * @license http://dwoo.org/LICENSE Modified BSD License |
||
12 | * @version 1.3.0 |
||
13 | * @date 2016-09-19 |
||
14 | * @link http://dwoo.org/ |
||
15 | */ |
||
16 | |||
17 | namespace Dwoo\Plugins\Functions; |
||
18 | |||
19 | use Dwoo\Core; |
||
20 | |||
21 | /** |
||
22 | * Formats a date |
||
23 | * <pre> |
||
24 | * * value : the date, as a unix timestamp, mysql datetime or whatever strtotime() can parse |
||
25 | * * format : output format, see {@link http://php.net/strftime} for details |
||
26 | * * default : a default timestamp value, if the first one is empty |
||
27 | * </pre> |
||
28 | * This software is provided 'as-is', without any express or implied warranty. |
||
29 | * In no event will the authors be held liable for any damages arising from the use of this software. |
||
30 | */ |
||
31 | function PluginDateFormat(Core $dwoo, $value, $format = '%b %e, %Y', $default = null) |
||
0 ignored issues
–
show
|
|||
32 | { |
||
33 | if (!empty($value)) { |
||
34 | // convert if it's not a valid unix timestamp |
||
35 | if (preg_match('#^-?\d{1,10}$#', $value) === 0) { |
||
36 | $value = strtotime($value); |
||
37 | } |
||
38 | } elseif (!empty($default)) { |
||
39 | // convert if it's not a valid unix timestamp |
||
40 | if (preg_match('#^-?\d{1,10}$#', $default) === 0) { |
||
41 | $value = strtotime($default); |
||
42 | } else { |
||
43 | $value = $default; |
||
44 | } |
||
45 | } else { |
||
46 | return ''; |
||
47 | } |
||
48 | |||
49 | // Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin |
||
50 | if (DIRECTORY_SEPARATOR == '\\') { |
||
51 | $_win_from = array( |
||
52 | '%D', |
||
53 | '%h', |
||
54 | '%n', |
||
55 | '%r', |
||
56 | '%R', |
||
57 | '%t', |
||
58 | '%T' |
||
59 | ); |
||
60 | $_win_to = array( |
||
61 | '%m/%d/%y', |
||
62 | '%b', |
||
63 | "\n", |
||
64 | '%I:%M:%S %p', |
||
65 | '%H:%M', |
||
66 | "\t", |
||
67 | '%H:%M:%S' |
||
68 | ); |
||
69 | View Code Duplication | if (strpos($format, '%e') !== false) { |
|
70 | $_win_from[] = '%e'; |
||
71 | $_win_to[] = sprintf('%\' 2d', date('j', $value)); |
||
72 | } |
||
73 | View Code Duplication | if (strpos($format, '%l') !== false) { |
|
74 | $_win_from[] = '%l'; |
||
75 | $_win_to[] = sprintf('%\' 2d', date('h', $value)); |
||
76 | } |
||
77 | $format = str_replace($_win_from, $_win_to, $format); |
||
78 | } |
||
79 | |||
80 | return strftime($format, $value); |
||
81 | } |
||
82 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.