CMD_Parse::form()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Contains template string replace tools
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   Template
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\template;
17
18
/**
19
 * Contains template string replace tools
20
 *
21
 * @category  Core
22
 * @package   Template
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
abstract class CMD_Parse
30
{
31
    /**
32
     * Store view driver for boxes
33
     **/
34
    private static $_view = null;
35
36
    /**
37
     * Enhance problem details for unknown calls
38
     *
39
     * @param string $name      Method name
40
     * @param array  $arguments Method parameters
41
     *
42
     * @throws \Exception
43
     *
44
     * @return void
45
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
46
47
    public static function __callStatic($name, array $arguments)
48
    {
49
        unset($arguments);
50
51
        throw new \Exception('Command unknown: ' . $name);
52
    }
53
54
    /**
55
     * Include prepared boxes
56
     *
57
     * @param array $part Placeholder cmd and key, maybe even more
58
     * @param array $data Array with data to use in the template
59
     *
60
     * @return string
61
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
62
63
    public static function box(array $part, array $data)
64
    {
65
        // Get settings if not done yet
66
        if (self::$_view == '') {
67
68
            $loader      = \csphere\core\service\Locator::get();
69
            self::$_view = $loader->load('view');
70
        }
71
72
        // Set box params for this box
73
        \csphere\core\http\Input::setBox($part['params']);
74
75
        // Clear current box to not end in an infinite loop
76
        self::$_view->clear();
77
78
        \csphere\core\router\Sandbox::full($part['key']);
79
80
        $box = self::$_view->box();
81
82
        // Add box name as div if not declined
83
        if (!isset($data['nodiv'])) {
84
85
            //$div = '<div class="' . $part['name'] . '">';
86
            //$box = $div . $box . '</div>';
87
        }
88
89
        return $box;
90
    }
91
92
    /**
93
     * Datetime replaces extendable by zone
94
     *
95
     * @param array $part Placeholder cmd and key, maybe even more
96
     * @param array $data Array with data to use in the template
97
     *
98
     * @return string
99
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
100
101
    public static function datetime(array $part, array $data)
102
    {
103
        $part = \csphere\core\template\Parse::sub($part, $data);
104
105
        // Data must be an unix timestamp of type integer
106
        $unix = (int)$part['data'];
107
108
        $result=\csphere\core\date\Unixtime::string($unix, true, true);
109
110
        return $result;
111
    }
112
113
    /**
114
     * Date replaces extendable by zone
115
     *
116
     * @param array $part Placeholder cmd and key, maybe even more
117
     * @param array $data Array with data to use in the template
118
     *
119
     * @return string
120
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
121
122
    public static function date(array $part, array $data)
123
    {
124
        $part = \csphere\core\template\Parse::sub($part, $data);
125
126
        // Data must be an unix timestamp of type integer
127
        $unix = (int)$part['data'];
128
129
        $result=\csphere\core\date\Unixtime::string($unix, true, false);
130
131
        return $result;
132
    }
133
134
    /**
135
     * Time replaces extendable by zone
136
     *
137
     * @param array $part Placeholder cmd and key, maybe even more
138
     * @param array $data Array with data to use in the template
139
     *
140
     * @return string
141
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
142
143
    public static function time(array $part, array $data)
144
    {
145
        $part = \csphere\core\template\Parse::sub($part, $data);
146
147
        // Data must be an unix timestamp of type integer
148
        $unix = (int)$part['data'];
149
150
        $result=\csphere\core\date\Unixtime::string($unix, false, true);
151
152
        return $result;
153
    }
154
155
    /**
156
     * Debug info for template data
157
     *
158
     * @param array $part Placeholder cmd and key, maybe even more
159
     * @param array $data Array with data to use in the template
160
     *
161
     * @return string
162
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
163
164
    public static function debug(array $part, array $data)
165
    {
166
        // Get target array data
167
        $key = explode('.', $part['key']);
168
169
        foreach ($key AS $target) {
170
171
            $data = isset($data[$target]) ? $data[$target] : null;
172
        }
173
174
        // Generate output and format it
175
        if ($data != null) {
176
            ob_start();
177
            var_dump($data);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($data); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
178
            $content = ob_get_clean();
179
            $content = nl2br($content, false);
180
181
        } else {
182
183
            $content = 'Error: No data found';
184
        }
185
186
        $info   = 'Debug info for "' . $part['key'] . '":<br>' . "\n";
187
        $result = $info . '<pre>' . $content . '</pre>';
188
189
        return $result;
190
    }
191
192
    /**
193
     * Placeholder right before form ends
194
     *
195
     * @param array $part Placeholder cmd and key, maybe even more
196
     * @param array $data Array with data to use in the template
197
     *
198
     * @return string
199
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
200
201
    public static function form(array $part, array $data)
202
    {
203
        unset($part, $data);
204
205
        // Add hidden input to catch form submit
206
        $result = '<input type="hidden" name="csphere_form" value="1">';
207
208
        return $result;
209
    }
210
}
211