1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Pages;
13
14 use ICanBoogie\ActiveRecord\Query;
15
16 use Icybee\ManageBlock\Options;
17
18 class ManageBlock extends \Icybee\Modules\Nodes\ManageBlock
19 {
20 static protected function add_assets(\Brickrouge\Document $document)
21 {
22 parent::add_assets($document);
23
24 $document->css->add('manage.css');
25 $document->js->add('manage.js');
26 }
27
28 public function __construct(Module $module, array $attributes=array())
29 {
30 parent::__construct
31 (
32 $module, $attributes + array
33 (
34 self::T_COLUMNS_ORDER => array
35 (
36 'title', 'url', 'is_navigation_excluded', 'is_online', 'uid', 'updated_at'
37 ),
38
39 self::T_ORDER_BY => null
40 )
41 );
42 }
43
44 45 46 47 48 49 50
51 protected function get_available_columns()
52 {
53 return array_merge(parent::get_available_columns(), array(
54
55 'title' => __CLASS__ . '\TitleColumn',
56 'url' => __CLASS__ . '\URLColumn',
57 'is_navigation_excluded' => __CLASS__ . '\IsNavigationExcluded'
58 ));
59 }
60
61 62 63 64 65
66 protected function get_available_jobs()
67 {
68 return array_merge(parent::get_available_jobs(), array
69 (
70 'copy' => 'Copier'
71 ));
72 }
73
74 protected function render_jobs(array $jobs)
75 {
76 $html = parent::render_jobs($jobs);
77
78 return <<<EOT
79 $html
80
81 <div data-actionbar-context="update-tree">
82 <i class="icon-sitemap context-icon"></i><button class="btn" data-action="cancel">Annuler</button>
83 <button class="btn btn-primary" data-action="save">Enregistrer les modifications</button>
84 </div>
85
86 EOT;
87 }
88
89 protected $mode = 'tree';
90
91 protected function get_mode()
92 {
93 return $this->mode;
94 }
95
96 protected $expand_highlight;
97
98 99 100 101 102 103
104 protected function update_options(Options $options, array $modifiers)
105 {
106 $options = parent::update_options($options, $modifiers);
107
108 if (!isset($options->expanded))
109 {
110 $options->expanded = array();
111 }
112
113 if (isset($modifiers['expand']) || isset($modifiers['collapse']))
114 {
115 $expanded = array_flip($options->expanded);
116
117 if (isset($modifiers['expand']))
118 {
119 $nid = $this->expand_highlight = filter_var($modifiers['expand'], FILTER_VALIDATE_INT);
120 $expanded[$nid] = true;
121 }
122
123 if (isset($modifiers['collapse']))
124 {
125 unset($expanded[filter_var($modifiers['collapse'], FILTER_VALIDATE_INT)]);
126 }
127
128 $options->expanded = array_keys($expanded);
129 }
130
131 if ($options->order_by == 'title')
132 {
133 $options->order_by = null;
134 }
135
136 if ($options->filters || $options->order_by || $options->search)
137 {
138 $this->mode = 'flat';
139 }
140
141 return $options;
142 }
143
144 145 146 147 148 149
150 protected function fetch_records(Query $query)
151 {
152 global $core;
153
154 if ($this->mode !== 'tree')
155 {
156 return parent::fetch_records($query);
157 }
158
159 $expanded = array_flip($this->options->expanded);
160
161 return $query->model->blueprint($core->site_id)->subset(null, null, function(BlueprintNode $node) use($expanded) {
162
163 return !(!$node->parentid || isset($expanded[$node->parentid]));
164
165 })->ordered_records;
166 }
167
168 169 170
171 protected function render_controls()
172 {
173 if ($this->mode !== 'tree')
174 {
175 return parent::render_controls();
176 }
177
178 $count = $this->t(':count pages', array(':count' => $this->count));
179
180
181
182 return <<<EOT
183 <div class="listview-controls">
184 $count
185 </div>
186 EOT;
187 }
188
189 protected function render_rows(array $rows)
190 {
191 $view_ids = $this->module->model('contents')
192 ->select('pageid, content')
193 ->where('contentid = "body" AND editor = "view"')
194 ->pairs;
195
196 $rendered_rows = parent::render_rows($rows);
197 $records = array_values($this->records);
198
199 foreach ($rendered_rows as $i => $row)
200 {
201 $row->add_class('entry');
202 $row->add_class('draggable');
203
204 $record = $records[$i];
205 $nid = $record->nid;
206
207 if ($this->expand_highlight && $record->parentid == $this->expand_highlight)
208 {
209 $row->add_class('volatile-highlight');
210 }
211
212 if (isset($view_ids[$nid]))
213 {
214 $row->add_class('view');
215 }
216
217 if ($record->pattern)
218 {
219 $row->add_class('pattern');
220 }
221
222 if ($record->locationid)
223 {
224 $row->add_class('location');
225 }
226
227 $row['id'] = "nid:{$nid}";
228 }
229
230 return $rendered_rows;
231 }
232 }
233
234 namespace Icybee\Modules\Pages\ManageBlock;
235
236 use ICanBoogie\Routing\Pattern;
237
238 use Brickrouge\Element;
239 use Brickrouge\Text;
240
241 use Icybee\ManageBlock\Column;
242 use Icybee\ManageBlock\BooleanColumn;
243
244 class TitleColumn extends \Icybee\Modules\Nodes\ManageBlock\TitleColumn
245 {
246 public function render_cell($record)
247 {
248 $rc = '';
249
250 if ($this->manager->mode == 'tree')
251 {
252 $rc .= str_repeat('<div class="indentation"> </div>', $record->depth);
253 $rc .= '<div class="handle"><i class="icon-move"></i></div>';
254
255 if (0)
256 {
257 $rc .= new Text
258 (
259 array
260 (
261 Element::LABEL => 'w',
262 Element::LABEL_POSITION => 'before',
263 'name' => 'weights[' . $record->nid . ']',
264 'value' => $record->weight,
265 'size' => 3,
266 'style' => 'border: none; background: transparent; color: green'
267 )
268 );
269
270 $rc .= ' ';
271
272 $rc .= new Text
273 (
274 array
275 (
276 Element::LABEL => 'p',
277 Element::LABEL_POSITION => 'before',
278 'name' => 'parents[' . $record->nid . ']',
279 'value' => $record->parentid,
280 'size' => 3,
281 'style' => 'border: none; background: transparent; color: green'
282 )
283 );
284 }
285 else
286 {
287 288 289 290 291 292 293 294 295 296 297 298 299
300
301 $rc .= new Element
302 (
303 'input', array
304 (
305 'name' => 'parents[' . $record->nid . ']',
306 'type' => 'hidden',
307 'value' => $record->parentid
308 )
309 );
310 }
311 }
312
313 $rc .= parent::render_cell($record);
314
315 if (0)
316 {
317 $rc .= ' <small style="color: green">:' . $record->nid . '</small>';
318 }
319
320 if ($this->manager->mode == 'tree' && $record->has_child)
321 {
322 $expanded = in_array($record->nid, $this->manager->options->expanded);
323
324 $rc .= ' <a class="treetoggle" href="?' . ($expanded ? 'collapse' : 'expand') . '=' . $record->nid . '">' . ($expanded ? '-' : "+{$record->descendents_count}") . '</a>';
325 }
326
327
328
329
330
331 $now = time();
332 $updated_at = strtotime($record->updated_at);
333
334 if ($now - $updated_at < 7200)
335 {
336 $rc .= ' <sup style="vertical-align: text-top; color: red;">Récemment modifié</sup>';
337 }
338
339 return $rc;
340 }
341 }
342
343 344 345
346 class URLColumn extends \Icybee\Modules\Nodes\ManageBlock\URLColumn
347 {
348 public function render_cell($record)
349 {
350 global $core;
351
352 $t = $this->manager->t;
353 $options = $this->manager->options;
354 $pattern = $record->url_pattern;
355
356 if ($options->search || $options->filters)
357 {
358 if (Pattern::is_pattern($pattern))
359 {
360 return;
361 }
362
363 $url = $record->url;
364
365
366
367 if ($record->location)
368 {
369 $location = $record->location;
370 $title = $t('This page is redirected to: !title (!url)', array('!title' => $location->title, '!url' => $location->url));
371
372 return <<<EOT
373 <span class="small">
374 <i class="icon-mail-forward" title="$title"></i>
375 <a href="$url">$url</a>
376 </span>
377 EOT;
378 }
379
380 return <<<EOT
381 <span class="small"><a href="$url">$url</a></span>
382 EOT;
383 }
384
385 $rc = '';
386 $location = $record->location;
387
388 if ($location)
389 {
390 $rc .= '<span class="icon-mail-forward" title="' . $t('This page is redirected to: !title (!url)', array('!title' => $location->title, '!url' => $location->url)) . '"></span>';
391 }
392 else if (!Pattern::is_pattern($pattern))
393 {
394 $url = ($core->site_id == $record->siteid) ? $record->url : $record->absolute_url;
395
396 $title = $t('Go to the page: !url', array('!url' => $url));
397
398 $rc .= '<a href="' . $url . '" title="' . $title . '" target="_blank"><i class="icon-external-link"></i></a>';
399 }
400
401 return $rc;
402 }
403 }
404
405 406 407
408 class IsNavigationExcluded extends BooleanColumn
409 {
410 public function __construct(\Icybee\ManageBlock $manager, $id, array $options=array())
411 {
412 parent::__construct
413 (
414 $manager, $id, $options + array
415 (
416 'title' => null,
417 'filters' => array
418 (
419 'options' => array
420 (
421 '=1' => 'Excluded from navigation',
422 '=0' => 'Included in navigation'
423 )
424 ),
425
426 'sortable' => false
427 )
428 );
429 }
430
431 public function render_cell($record)
432 {
433 return new Element
434 (
435 'i', array
436 (
437 'class' => 'icon-sitemap trigger ' . ($record->is_navigation_excluded ? 'on' : ''),
438 'data-nid' => $record->nid,
439 'title' => "Inclure ou exclure la page du menu de navigation principal"
440 )
441 );
442 }
443 }