/
app_helper.php
360 lines (309 loc) · 10.7 KB
/
app_helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
/**
* Comment Template.
*
* @todo -c Implement .this needs to be sorted out.
*
* Copyright (c) 2009 Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://www.dogmatic.co.za
* @package sort
* @subpackage sort.comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.5a
*/
class AppHelper extends Helper
{
var $rowClassCounter = 0;
var $paginationCounterFormat = 'Page %page% of %pages%.';
var $errors = array();
var $wysiwyg = 'fck';
var $helpers = array( 'Html', 'Design', 'Core.Wysiwyg', 'Core.Gravatar' );
/**
* create some bread crumbs.
*
* Creates some bread crumbs.
*
* @todo -cAppHelper Implement AppHelper.
* - generate some links
*
* @param array $here is $this from the view.
*/
function breadcrumbs( $view = array(), $seperator = ' :: ' )
{
if ( empty( $view ) )
{
return false;
}
$breadcrumbs = array(
$view->params['prefix'],
$view->params['plugin'],
$view->name
);
return implode( $seperator, $breadcrumbs );
}
/**
* switch the class for table rows
*
* @param integer $i the number of the row
* @param string $class1 class 1 highlight
* @param string $class2 class 2 highlight
* @return string the class
*/
function rowClass( $class1 = 'bg', $class2 = '' )
{
return ( ( $this->rowClassCounter++ % 2 ) ? $class1 : $class2 );
}
function adminPageHead( $view )
{
if ( empty( $view ) )
{
return false;
}
return '<div class="top-bar"><h1>'.__( $view->name, true ).'</h1>'.
'<div class="breadcrumbs">'.$this->breadcrumbs( $view ).'</div></div>';
}
/**
* creates table headers for admin.
*
* if the format is just array( 'head1', 'head2' ... ) it will output a
* normal table with TH that have no classes/styles applied. you can
* also pass things like array ( 'head1' => array( 'class' => 'something' ) )
* to get out put like <th class="something">head1</th>
*
* @param array $data an array of items for the head.
*/
function adminTableHeader( $data )
{
$out = '<tr>';
foreach( $data as $field => $params )
{
$atributes = '';
if ( is_int( $field ) && !is_array( $params ) )
{
$field = $params;
$params = '';
}
else
{
foreach( $params as $type => $param )
{
$atributes = '';
$atributes .= $type.'="'.$param.'" ';
}
$atributes .= $atributes;
}
if ( $atributes != '' )
{
$params = $atributes;
}
$out .= '<th '.$params.'>'.$field.'</th>';
}
$out .= '</tr>';
return $out;
}
/**
* creates the header images for the admin table headers.
*/
function adminTableHeadImages()
{
return $this->Html->image(
'admin/bg-th-left.gif',
array(
'width' => '8px',
'height' => '7px',
'class' => 'left'
)
).
$this->Html->image(
'admin/bg-th-right.gif',
array(
'width' => '8px',
'height' => '7px',
'class' => 'right'
)
);
}
function adminIndexHead( $view = array(), $pagintion = array(), $filterOptions = array(), $massActions = null )
{
if ( empty( $view ) )
{
$this->errors[] = 'I need the view.';
return false;
}
App::import( 'Helper', 'FilterHelper' );
$filters = $this->Design->niceBox( 'filter', FilterHelper::clear( $filterOptions ) );
return $this->Design->niceBox( 'adminTopBar', $this->adminPageHead( $view ).$massActions ).$filters;
}
function adminOtherHead( $view = array() )
{
if ( empty( $view ) )
{
$this->errors[] = 'I need the view.';
return false;
}
$out = '<div class="adminTopBar">';
$out .= $this->adminPageHead( $view );
$out .= '<div class="main-actions">';
$out .= $this->Html->link(
'Index',
array(
'action' => 'index'
)
).' ';
$out .= $this->Html->link(
'Add',
array(
'action' => 'add'
)
);
$out .= '</div>';
$out .= '</div><div class="clr"> </div>';
return $out;
}
function ordering( $id = null, $order = null )
{
if ( !$id )
{
$this->errors[] = 'You need an id to move something';
return false;
}
if ( !$order )
{
$this->errors[] = 'The order was not passed';
}
$out = $this->Html->link( $order, array( '#' => $order ) );
$out .= $this->Html->link(
$this->Html->image(
$this->Image->getRelativePath( 'actions', 'arrow-up' ),
array(
'alt' => __( 'Up', true ),
'title' => __( 'Move up', true ),
'width' => '16px',
'class' => 'arrow-up'
)
),
array(
'action' => 'reorder',
$id,
'direction' => 'up',
'amount' => 1
),
array(
'escape' => false,
)
);
$out .= $this->Html->link(
$this->Html->image(
$this->Image->getRelativePath( 'actions', 'arrow-down' ),
array(
'alt' => __( 'Down', true ),
'title' => __( 'Move down', true ),
'width' => '16px',
'class' => 'arrow-down'
)
),
array(
'action' => 'reorder',
$id,
'direction' => 'down',
'amount' => 1
),
array(
'escape' => false,
)
);
return $out;
}
function paginationCounter( $pagintion )
{
if ( empty( $pagintion ) )
{
$this->errors[] = 'You did not pass the pagination object.';
return false;
}
$out = '';
$out .= $pagintion->counter( array( 'format' => __( $this->paginationCounterFormat, true ) ) );
$out .= '';
return $out;
}
function wysiwyg( $id = null, $toolbar = 'Basic' )
{
if ( !$id )
{
$this->errors[] = 'No field specified for the wysiwyg editor';
return false;
}
if ( !Configure::read( 'Wysiwyg.editor' ) )
{
$this->errors[] = 'There is no editor configured';
return false;
}
$editor = ( Configure::read( 'Wysiwyg.editor' ) ) ? Configure::read( 'Wysiwyg.editor' ) : 'text';
return $this->Wysiwyg->$editor( $id, $toolbar );
}
function gravatar( $email = null, $options = array() )
{
if ( !$email )
{
$this->errors[] = 'no email specified for the gravatar.';
return false;
}
return $this->Gravatar->image( $email, $options );
}
function niceBox( $class = '', $content = false )
{
$out = '<div class="niceBox '.$class.'"><div class="top"><div class="top"><div class="top"></div></div></div>';
$out .= '<div class="middle">';
if ( $content )
{
$out .= $content.'<div class="clr"></div>';
}
$out .= '</div>';
if ( $content )
{
$out .= $this->niceBoxEnd();
}
return $out;
}
function niceBoxEnd()
{
return '<div class="bottom"><div class="bottom"><div class="bottom"></div></div></div></div>';
}
function massActionButtons( $buttons = null, $niceBox = false )
{
if ( !$buttons )
{
$this->errors[] = 'No buttons set';
return false;
}
$out = '';
foreach( $buttons as $button )
{
$imagePath = $this->Image->getRelativePath( array( 'actions' ), $button );
if ( !$imagePath )
{
$imagePath = __( Inflector::humanize( $button ), true );
}
$out .= $this->Form->submit(
$imagePath,
array(
'value' => strtolower( str_replace( array( '-', ' ' ), '_', $button ) ),
'name' => 'action',
'title' => __( Inflector::humanize( $button ), true )
)
);
}
if ( $niceBox )
{
return $this->Design->niceBox( 'massActions', $out );
}
return '<div class="massActions">'.$out.'</div>';
}
}
?>