/
content.publish.php
1965 lines (1656 loc) · 81.4 KB
/
content.publish.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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @package content
*/
/**
* The Publish page is where the majority of an Authors time will
* be spent in Symphony with adding, editing and removing entries
* from Sections. This Page controls the entries table as well as
* the Entry creation screens.
*/
class contentPublish extends AdministrationPage
{
public $_errors = array();
public function sort(&$sort, &$order, $params)
{
$section = $params['current-section'];
$filters = '';
// Format the filter query string
if (isset($params['filters']) && !empty($params['filters'])) {
$filters = preg_replace('/^&/i', '', $params['filters'], 1);
$filters = '?' . trim($filters);
}
// If `?unsort` is appended to the URL, then sorting is reverted
// to 'none', aka. by 'entry-id'.
if ($params['unsort']) {
$section->setSortingField('id', false);
$section->setSortingOrder('desc');
redirect(Administration::instance()->getCurrentPageURL() . $filters);
}
// By default, sorting information are retrieved from
// the file system and stored inside the `Configuration` object
if (is_null($sort) && is_null($order)) {
$sort = $section->getSortingField();
$order = $section->getSortingOrder();
// Set the sorting in the `EntryManager` for subsequent use
EntryManager::setFetchSorting($sort, $order);
} else {
$sort = General::sanitize($sort);
// Ensure that this field is infact sortable, otherwise
// fallback to IDs
if (($field = FieldManager::fetch($sort)) instanceof Field && !$field->isSortable()) {
$sort = $section->getDefaultSortingField();
}
// If the sort order or direction differs from what is saved,
// update the config file and reload the page
if ($sort != $section->getSortingField() || $order != $section->getSortingOrder()) {
$section->setSortingField($sort, false);
$section->setSortingOrder($order);
redirect(Administration::instance()->getCurrentPageURL() . $filters);
}
// If the sort order and direction remains the same, reload the page
if ($sort == $section->getSortingField() && $order == $section->getSortingOrder()) {
redirect(Administration::instance()->getCurrentPageURL() . $filters);
}
}
}
/**
* Append filtering interface
*/
public function createFilteringInterface()
{
//Check if section has filtering enabled
$context = $this->getContext();
$handle = $context['section_handle'];
$section_id = SectionManager::fetchIDFromHandle($handle);
$section = SectionManager::fetch($section_id);
$filter = $section->get('filter');
$count = EntryManager::fetchCount($section_id);
if ($filter !== 'no' && $count > 1) {
$drawer = Widget::Drawer('filtering-' . $section_id, __('Filter Entries'), $this->createFilteringDrawer($section));
$drawer->addClass('drawer-filtering');
$this->insertDrawer($drawer);
}
}
/**
* Create filtering drawer
*/
public function createFilteringDrawer($section)
{
$this->filteringForm = Widget::Form(null, 'get', 'filtering');
$this->createFilteringDuplicator($section);
return $this->filteringForm;
}
public function createFilteringDuplicator($section)
{
$div = new XMLElement('div');
$div->setAttribute('class', 'frame filters-duplicator');
$div->setAttribute('data-interactive', 'data-interactive');
$ol = new XMLElement('ol');
$ol->setAttribute('data-add', __('Add filter'));
$ol->setAttribute('data-remove', __('Clear filter'));
$ol->setAttribute('data-empty', __('No filters applied yet.'));
$this->createFieldFilters($ol, $section);
$this->createSystemDateFilters($ol);
$div->appendChild($ol);
$this->filteringForm->appendChild($div);
}
private function createFieldFilters(&$wrapper, $section)
{
$filters = $_GET['filter'];
foreach ($section->fetchFilterableFields() as $field) {
if (!$field->canPublishFilter()) {
continue;
}
$filter = $filters[$field->get('element_name')];
// Filter data
$data = array();
$data['type'] = $field->get('element_name');
$data['name'] = $field->get('label');
$data['filter'] = $filter;
$data['instance'] = 'unique';
$data['search'] = $field->fetchSuggestionTypes();
$data['operators'] = $field->fetchFilterableOperators();
$data['comparisons'] = $this->createFilterComparisons($data);
$data['query'] = $this->getFilterQuery($data);
$data['field-id'] = $field->get('id');
// Add existing filter
if (isset($filter)) {
$this->createFilter($wrapper, $data);
}
// Add filter template
$data['instance'] = 'unique template';
$data['query'] = '';
$this->createFilter($wrapper, $data);
}
}
private function createSystemDateFilters(&$wrapper)
{
$filters = $_GET['filter'];
$dateField = new FieldDate;
$fields = array(
array(
'type' => 'system:creation-date',
'label' => __('System Creation Date')
),
array(
'type' => 'system:modification-date',
'label' => __('System Modification Date')
)
);
foreach ($fields as $field) {
$filter = $filters[$field['type']];
// Filter data
$data = array();
$data['type'] = $field['type'];
$data['name'] = $field['label'];
$data['filter'] = $filter;
$data['instance'] = 'unique';
$data['search'] = $dateField->fetchSuggestionTypes();
$data['operators'] = $dateField->fetchFilterableOperators();
$data['comparisons'] = $this->createFilterComparisons($data);
$data['query'] = $this->getFilterQuery($data);
// Add existing filter
if (isset($filter)) {
$this->createFilter($wrapper, $data);
}
// Add filter template
$data['instance'] = 'unique template';
$data['query'] = '';
$this->createFilter($wrapper, $data);
}
}
private function createFilter(&$wrapper, $data)
{
$li = new XMLElement('li');
$li->setAttribute('class', $data['instance']);
$li->setAttribute('data-type', $data['type']);
// Header
$li->appendChild(new XMLElement('header', $data['name'], array(
'data-name' => $data['name']
)));
// Settings
$div = new XMLElement('div', null, array('class' => 'two columns'));
// Comparisons
$label = Widget::Label();
$label->setAttribute('class', 'column secondary');
$select = Widget::Select($data['type'] . '-comparison', $data['comparisons'], array(
'class' => 'comparison'
));
$label->appendChild($select);
$div->appendChild($label);
// Query
$label = Widget::Label();
$label->setAttribute('class', 'column primary');
$input = Widget::Input($data['type'], General::sanitize($data['query']), 'text', array(
'placeholder' => __('Type and hit enter to apply filter…'),
'autocomplete' => 'off'
));
$input->setAttribute('class', 'filter');
$label->appendChild($input);
$this->createFilterSuggestions($label, $data);
$div->appendChild($label);
$li->appendChild($div);
$wrapper->appendChild($li);
}
private function createFilterComparisons($data)
{
// Default comparison
$comparisons = array();
// Custom field comparisons
foreach ($data['operators'] as $operator) {
$filter = trim($operator['filter']);
// Check selected state
$selected = false;
// Selected state : Comparison mode "between" (x to y)
if ($operator['title'] === 'between' && preg_match('/^(-?(?:\d+(?:\.\d+)?|\.\d+)) to (-?(?:\d+(?:\.\d+)?|\.\d+))$/i', $data['filter'] )) {
$selected = true;
// Selected state : Other comparison modes (except "is")
} elseif ((!empty($filter) && strpos($data['filter'], $filter) === 0)) {
$selected = true;
}
$comparisons[] = array(
$operator['filter'],
$selected,
__($operator['title']),
null,
null,
array('data-comparison' => $operator['title'])
);
}
return $comparisons;
}
private function createFilterSuggestions(&$wrapper, $data)
{
$ul = new XMLElement('ul');
$ul->setAttribute('class', 'suggestions');
$ul->setAttribute('data-field-id', $data['field-id']);
$ul->setAttribute('data-associated-ids', '0');
$ul->setAttribute('data-search-types', implode($data['search'], ','));
// Add help text for each filter operator
foreach ($data['operators'] as $operator) {
$this->createFilterHelp($ul, $operator);
}
$wrapper->appendChild($ul);
}
private function createFilterHelp(&$wrapper, $operator)
{
if (empty($operator['help'])) {
return;
}
$li = new XMLElement('li', __('Comparison mode') . ': ' . $operator['help'], array(
'class' => 'help',
'data-comparison' => $operator['title']
));
$wrapper->appendChild($li);
}
private function getFilterQuery($data)
{
$query = $data['filter'];
foreach ($data['operators'] as $operator) {
$filter = trim($operator['filter']);
if (!empty($filter) && strpos($data['filter'], $filter) === 0) {
$query = substr($data['filter'], strlen($operator['filter']));
}
}
return (string)$query;
}
public function build(array $context = array())
{
$section_id = SectionManager::fetchIDFromHandle($context['section_handle']);
if ($section_id) {
$context['associations'] = array(
'parent' => SectionManager::fetchParentAssociations($section_id),
'child' => SectionManager::fetchChildAssociations($section_id)
);
}
return parent::build($context);
}
public function action()
{
$this->__switchboard('action');
}
public function __switchboard($type = 'view')
{
$function = ($type == 'action' ? '__action' : '__view') . ucfirst($this->_context['page']);
if (!method_exists($this, $function)) {
// If there is no action function, just return without doing anything
if ($type == 'action') {
return;
}
Administration::instance()->errorPageNotFound();
}
// Is this request allowed by server?
if ($this->isRequestValid() === false) {
$this->pageAlert(__('This request exceeds the maximum allowed request size of %s specified by your host.', array(
ini_get('post_max_size')
)),
Alert::ERROR
);
}
$this->$function();
}
public function view()
{
$this->__switchboard();
}
public function __viewIndex()
{
if (!$section_id = SectionManager::fetchIDFromHandle($this->_context['section_handle'])) {
Administration::instance()->throwCustomError(
__('The Section, %s, could not be found.', array('<code>' . $this->_context['section_handle'] . '</code>')),
__('Unknown Section'),
Page::HTTP_STATUS_NOT_FOUND
);
} elseif (!is_writable(CONFIG)) {
$this->pageAlert(__('The Symphony configuration file, %s, is not writable. The sort order cannot be modified.', array('<code>/manifest/config.php</code>')), Alert::NOTICE);
}
$section = SectionManager::fetch($section_id);
$this->setPageType('table');
$this->setTitle(__('%1$s – %2$s', array(General::sanitize($section->get('name')), __('Symphony'))));
$filters = array();
$filter_querystring = $prepopulate_querystring = $where = $joins = null;
$current_page = (isset($_REQUEST['pg']) && is_numeric($_REQUEST['pg']) ? max(1, intval($_REQUEST['pg'])) : 1);
if (isset($_REQUEST['filter'])) {
// legacy implementation, convert single filter to an array
// split string in the form ?filter=handle:value
// @deprecated
// This should be removed in Symphony 4.0.0
if (!is_array($_REQUEST['filter'])) {
list($field_handle, $filter_value) = explode(':', $_REQUEST['filter'], 2);
$filters[$field_handle] = rawurldecode($filter_value);
} else {
$filters = $_REQUEST['filter'];
}
foreach ($filters as $handle => $value) {
// Handle multiple values through filtering. RE: #2290
if ((is_array($value) && empty($value)) || trim($value) == '') {
continue;
}
if (!is_array($value)) {
$filter_type = Datasource::determineFilterType($value);
$value = Datasource::splitFilter($filter_type, $value);
} else {
$filter_type = Datasource::FILTER_OR;
}
// Handle date meta data #2003
$handle = Symphony::Database()->cleanValue($handle);
if (in_array($handle, array('system:creation-date', 'system:modification-date'))) {
$date_joins = '';
$date_where = '';
$date = new FieldDate();
$date->buildDSRetrievalSQL($value, $date_joins, $date_where, ($filter_type == Datasource::FILTER_AND ? true : false));
// Replace the date field where with the `creation_date` or `modification_date`.
$date_where = preg_replace('/`t\d+`.date/', ($field_id !== 'system:modification-date') ? '`e`.creation_date_gmt' : '`e`.modification_date_gmt', $date_where);
$where .= $date_where;
} else {
// Handle normal fields
$field_id = FieldManager::fetchFieldIDFromElementName(
$handle,
$section->get('id')
);
$field = FieldManager::fetch($field_id);
if ($field instanceof Field) {
$field->buildDSRetrievalSQL($value, $joins, $where, ($filter_type == Datasource::FILTER_AND ? true : false));
$value = implode(',', $value);
$encoded_value = rawurlencode($value);
$filter_querystring .= sprintf("filter[%s]=%s&", $handle, $encoded_value);
// Some fields require that prepopulation be done via ID. RE: #2331
if (!is_numeric($value) && method_exists($field, 'fetchIDfromValue')) {
$encoded_value = $field->fetchIDfromValue($value);
}
$prepopulate_querystring .= sprintf("prepopulate[%d]=%s&", $field_id, $encoded_value);
} else {
unset($filters[$handle]);
}
unset($field);
}
}
$filter_querystring = preg_replace("/&$/", '', $filter_querystring);
$prepopulate_querystring = preg_replace("/&$/", '', $prepopulate_querystring);
}
Sortable::initialize($this, $entries, $sort, $order, array(
'current-section' => $section,
'filters' => ($filter_querystring ? "&" . $filter_querystring : ''),
'unsort' => isset($_REQUEST['unsort'])
));
$this->Form->setAttribute('action', Administration::instance()->getCurrentPageURL(). '?pg=' . $current_page.($filter_querystring ? "&" . $filter_querystring : ''));
// Build filtering interface
$this->createFilteringInterface();
$subheading_buttons = array(
Widget::Anchor(__('Create New'), Administration::instance()->getCurrentPageURL().'new/'.($prepopulate_querystring ? '?' . $prepopulate_querystring : ''), __('Create a new entry'), 'create button', null, array('accesskey' => 'c'))
);
// Only show the Edit Section button if the Author is a developer. #938 ^BA
if (Symphony::Author()->isDeveloper()) {
array_unshift($subheading_buttons, Widget::Anchor(__('Edit Section'), SYMPHONY_URL . '/blueprints/sections/edit/' . $section_id . '/', __('Edit Section Configuration'), 'button'));
}
$this->appendSubheading(General::sanitize($section->get('name')), $subheading_buttons);
/**
* Allows adjustments to be made to the SQL where and joins statements
* before they are used to fetch the entries for the page
*
* @delegate AdjustPublishFiltering
* @since Symphony 2.3.3
* @param string $context
* '/publish/'
* @param integer $section_id
* An array of the current columns, passed by reference
* @param string $where
* The current where statement, or null if not set
* @param string $joins
*/
Symphony::ExtensionManager()->notifyMembers('AdjustPublishFiltering', '/publish/', array('section-id' => $section_id, 'where' => &$where, 'joins' => &$joins));
// get visible columns
$visible_columns = $section->fetchVisibleColumns();
// extract the needed schema
$element_names = array_values(array_map(function ($field) {
return $field->get('element_name');
}, $visible_columns));
// Check that the filtered query fails that the filter is dropped and an
// error is logged. #841 ^BA
try {
$entries = EntryManager::fetchByPage($current_page, $section_id, Symphony::Configuration()->get('pagination_maximum_rows', 'symphony'), $where, $joins, true, false, true, $element_names);
} catch (DatabaseException $ex) {
$this->pageAlert(__('An error occurred while retrieving filtered entries. Showing all entries instead.'), Alert::ERROR);
$filter_querystring = null;
Symphony::Log()->pushToLog(sprintf(
'%s - %s%s%s',
$section->get('name') . ' Publish Index',
$ex->getMessage(),
($ex->getFile() ? " in file " . $ex->getFile() : null),
($ex->getLine() ? " on line " . $ex->getLine() : null)
),
E_NOTICE,
true
);
$entries = EntryManager::fetchByPage($current_page, $section_id, Symphony::Configuration()->get('pagination_maximum_rows', 'symphony'), null, null, true, false, true, $element_names);
}
// Flag filtering
if (isset($_REQUEST['filter'])) {
$filter_stats = new XMLElement('p', '<span>– ' . __('%d of %d entries (filtered)', array($entries['total-entries'], EntryManager::fetchCount($section_id))) . '</span>', array('class' => 'inactive'));
} else {
$filter_stats = new XMLElement('p', '<span>– ' . __('%d entries', array($entries['total-entries'])) . '</span>', array('class' => 'inactive'));
}
$this->Breadcrumbs->appendChild($filter_stats);
// Build table
$columns = array();
if (is_array($visible_columns) && !empty($visible_columns)) {
foreach ($visible_columns as $column) {
$columns[] = array(
'label' => $column->get('label'),
'sortable' => $column->isSortable(),
'handle' => $column->get('id'),
'attrs' => array(
'id' => 'field-' . $column->get('id'),
'class' => 'field-' . $column->get('type')
)
);
}
} else {
$columns[] = array(
'label' => __('ID'),
'sortable' => true,
'handle' => 'id'
);
}
$aTableHead = Sortable::buildTableHeaders($columns, $sort, $order, ($filter_querystring) ? "&" . $filter_querystring : '');
$child_sections = array();
$associated_sections = $section->fetchChildAssociations(true);
if (is_array($associated_sections) && !empty($associated_sections)) {
foreach ($associated_sections as $key => $as) {
$child_sections[$key] = SectionManager::fetch($as['child_section_id']);
$aTableHead[] = array($child_sections[$key]->get('name'), 'col');
}
}
/**
* Allows the creation of custom table columns for each entry. Called
* after all the Section Visible columns have been added as well
* as the Section Associations
*
* @delegate AddCustomPublishColumn
* @since Symphony 2.2
* @param string $context
* '/publish/'
* @param array $tableHead
* An array of the current columns, passed by reference
* @param integer $section_id
* The current Section ID
*/
Symphony::ExtensionManager()->notifyMembers('AddCustomPublishColumn', '/publish/', array('tableHead' => &$aTableHead, 'section_id' => $section->get('id')));
// Table Body
$aTableBody = array();
if (!is_array($entries['records']) || empty($entries['records'])) {
$aTableBody = array(
Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead))), 'odd')
);
} else {
$field_pool = array();
if (is_array($visible_columns) && !empty($visible_columns)) {
foreach ($visible_columns as $column) {
$field_pool[$column->get('id')] = $column;
}
}
$link_column = array_reverse($visible_columns);
$link_column = end($link_column);
reset($visible_columns);
foreach ($entries['records'] as $entry) {
$tableData = array();
// Setup each cell
if (!is_array($visible_columns) || empty($visible_columns)) {
$tableData[] = Widget::TableData(Widget::Anchor($entry->get('id'), Administration::instance()->getCurrentPageURL() . 'edit/' . $entry->get('id') . '/'));
} else {
$link = Widget::Anchor(
'',
Administration::instance()->getCurrentPageURL() . 'edit/' . $entry->get('id') . '/'.($filter_querystring ? '?' . $prepopulate_querystring : ''),
$entry->get('id'),
'content'
);
foreach ($visible_columns as $position => $column) {
$data = $entry->getData($column->get('id'));
$field = $field_pool[$column->get('id')];
$value = $field->prepareTableValue($data, ($column == $link_column) ? $link : null, $entry->get('id'));
if (!is_object($value) && (strlen(trim($value)) == 0 || $value == __('None'))) {
$value = ($position == 0 ? $link->generate() : __('None'));
}
if ($value == __('None')) {
$tableData[] = Widget::TableData($value, 'inactive field-' . $column->get('type') . ' field-' . $column->get('id'));
} else {
$tableData[] = Widget::TableData($value, 'field-' . $column->get('type') . ' field-' . $column->get('id'));
}
unset($field);
}
}
if (is_array($child_sections) && !empty($child_sections)) {
foreach ($child_sections as $key => $as) {
$field = FieldManager::fetch((int)$associated_sections[$key]['child_section_field_id']);
$parent_section_field_id = (int)$associated_sections[$key]['parent_section_field_id'];
if (!is_null($parent_section_field_id)) {
$search_value = $field->fetchAssociatedEntrySearchValue(
$entry->getData($parent_section_field_id),
$parent_section_field_id,
$entry->get('id')
);
} else {
$search_value = $entry->get('id');
}
if (!is_array($search_value)) {
$associated_entry_count = $field->fetchAssociatedEntryCount($search_value);
$tableData[] = Widget::TableData(
Widget::Anchor(
sprintf('%d →', max(0, intval($associated_entry_count))),
sprintf(
'%s/publish/%s/?filter[%s]=%s',
SYMPHONY_URL,
$as->get('handle'),
$field->get('element_name'),
rawurlencode($search_value)
),
$entry->get('id'),
'content'
)
);
}
unset($field);
}
}
/**
* Allows Extensions to inject custom table data for each Entry
* into the Publish Index
*
* @delegate AddCustomPublishColumnData
* @since Symphony 2.2
* @param string $context
* '/publish/'
* @param array $tableData
* An array of `Widget::TableData`, passed by reference
* @param integer $section_id
* The current Section ID
* @param Entry $entry_id
* The entry object, please note that this is by error and this will
* be removed in Symphony 2.4. The entry object is available in
* the 'entry' key as of Symphony 2.3.1.
* @param Entry $entry
* The entry object for this row
*/
Symphony::ExtensionManager()->notifyMembers('AddCustomPublishColumnData', '/publish/', array(
'tableData' => &$tableData,
'section_id' => $section->get('id'),
'entry_id' => $entry,
'entry' => $entry
));
$lastCol = $tableData[count($tableData) - 1];
$lastCol->appendChild(Widget::Label(__('Select Entry %d', array($entry->get('id'))), null, 'accessible', null, array(
'for' => 'entry-' . $entry->get('id')
)));
$lastCol->appendChild(Widget::Input('items['.$entry->get('id').']', $entry->get('modification_date'), 'checkbox', array(
'id' => 'entry-' . $entry->get('id')
)));
// Add a row to the body array, assigning each cell to the row
$aTableBody[] = Widget::TableRow($tableData, null, 'id-' . $entry->get('id'));
}
}
$table = Widget::Table(
Widget::TableHead($aTableHead),
null,
Widget::TableBody($aTableBody),
'selectable',
null,
array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive')
);
$this->Form->appendChild($table);
$tableActions = new XMLElement('div');
$tableActions->setAttribute('class', 'actions');
$options = array(
array(null, false, __('With Selected...')),
array('delete', false, __('Delete'), 'confirm', null, array(
'data-message' => __('Are you sure you want to delete the selected entries?')
))
);
$toggable_fields = $section->fetchToggleableFields();
if (is_array($toggable_fields) && !empty($toggable_fields)) {
$index = 2;
foreach ($toggable_fields as $field) {
$toggle_states = $field->getToggleStates();
if (is_array($toggle_states)) {
$options[$index] = array('label' => __('Set %s', array($field->get('label'))), 'options' => array());
foreach ($toggle_states as $value => $state) {
$options[$index]['options'][] = array('toggle-' . $field->get('id') . '-' . $value, false, $state);
}
}
$index++;
}
}
/**
* Allows an extension to modify the existing options for this page's
* With Selected menu. If the `$options` parameter is an empty array,
* the 'With Selected' menu will not be rendered.
*
* @delegate AddCustomActions
* @since Symphony 2.3.2
* @param string $context
* '/publish/'
* @param array $options
* An array of arrays, where each child array represents an option
* in the With Selected menu. Options should follow the same format
* expected by `Widget::__SelectBuildOption`. Passed by reference.
*/
Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/publish/', array(
'options' => &$options
));
if (!empty($options)) {
$tableActions->appendChild(Widget::Apply($options));
$this->Form->appendChild($tableActions);
}
if ($entries['total-pages'] > 1) {
$ul = new XMLElement('ul');
$ul->setAttribute('class', 'page');
// First
$li = new XMLElement('li');
if ($current_page > 1) {
$li->appendChild(Widget::Anchor(__('First'), Administration::instance()->getCurrentPageURL(). '?pg=1'.($filter_querystring ? "&" . $filter_querystring : '')));
} else {
$li->setValue(__('First'));
}
$ul->appendChild($li);
// Previous
$li = new XMLElement('li');
if ($current_page > 1) {
$li->appendChild(Widget::Anchor(__('← Previous'), Administration::instance()->getCurrentPageURL(). '?pg=' . ($current_page - 1).($filter_querystring ? "&" . $filter_querystring : '')));
} else {
$li->setValue(__('← Previous'));
}
$ul->appendChild($li);
// Summary
$li = new XMLElement('li');
$li->setAttribute('title', __('Viewing %1$s - %2$s of %3$s entries', array(
$entries['start'],
($current_page != $entries['total-pages']) ? $current_page * Symphony::Configuration()->get('pagination_maximum_rows', 'symphony') : $entries['total-entries'],
$entries['total-entries']
)));
$pgform = Widget::Form(Administration::instance()->getCurrentPageURL(), 'get', 'paginationform');
$pgmax = max($current_page, $entries['total-pages']);
$pgform->appendChild(Widget::Input('pg', null, 'text', array(
'data-active' => __('Go to page …'),
'data-inactive' => __('Page %1$s of %2$s', array((string)$current_page, $pgmax)),
'data-max' => $pgmax
)));
$li->appendChild($pgform);
$ul->appendChild($li);
// Next
$li = new XMLElement('li');
if ($current_page < $entries['total-pages']) {
$li->appendChild(Widget::Anchor(__('Next →'), Administration::instance()->getCurrentPageURL(). '?pg=' . ($current_page + 1).($filter_querystring ? "&" . $filter_querystring : '')));
} else {
$li->setValue(__('Next →'));
}
$ul->appendChild($li);
// Last
$li = new XMLElement('li');
if ($current_page < $entries['total-pages']) {
$li->appendChild(Widget::Anchor(__('Last'), Administration::instance()->getCurrentPageURL(). '?pg=' . $entries['total-pages'].($filter_querystring ? "&" . $filter_querystring : '')));
} else {
$li->setValue(__('Last'));
}
$ul->appendChild($li);
$this->Contents->appendChild($ul);
}
}
public function __actionIndex()
{
$checked = (is_array($_POST['items'])) ? array_keys($_POST['items']) : null;
if (is_array($checked) && !empty($checked)) {
/**
* Extensions can listen for any custom actions that were added
* through `AddCustomPreferenceFieldsets` or `AddCustomActions`
* delegates.
*
* @delegate CustomActions
* @since Symphony 2.3.2
* @param string $context
* '/publish/'
* @param array $checked
* An array of the selected rows. The value is usually the ID of the
* the associated object.
*/
Symphony::ExtensionManager()->notifyMembers('CustomActions', '/publish/', array(
'checked' => $checked
));
switch ($_POST['with-selected']) {
case 'delete':
/**
* Prior to deletion of entries. An array of Entry ID's is provided which
* can be manipulated. This delegate was renamed from `Delete` to `EntryPreDelete`
* in Symphony 2.3.
*
* @delegate EntryPreDelete
* @param string $context
* '/publish/'
* @param array $entry_id
* An array of Entry ID's passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('EntryPreDelete', '/publish/', array('entry_id' => &$checked));
EntryManager::delete($checked);
/**
* After the deletion of entries, this delegate provides an array of Entry ID's
* that were deleted.
*
* @since Symphony 2.3
* @delegate EntryPostDelete
* @param string $context
* '/publish/'
* @param array $entry_id
* An array of Entry ID's that were deleted.
*/
Symphony::ExtensionManager()->notifyMembers('EntryPostDelete', '/publish/', array('entry_id' => $checked));
redirect(server_safe('REQUEST_URI'));
break;
default:
list($option, $field_id, $value) = explode('-', $_POST['with-selected'], 3);
if ($option == 'toggle') {
$field = FieldManager::fetch($field_id);
$fields = array($field->get('element_name') => $value);
$section = SectionManager::fetch($field->get('parent_section'));
foreach ($checked as $entry_id) {
$entry = EntryManager::fetch($entry_id);
$existing_data = $entry[0]->getData($field_id);
$entry[0]->setData($field_id, $field->toggleFieldData(is_array($existing_data) ? $existing_data : array(), $value, $entry_id));
/**
* Just prior to editing of an Entry
*
* @delegate EntryPreEdit
* @param string $context
* '/publish/edit/'
* @param Section $section
* @param Entry $entry
* @param array $fields
*/
Symphony::ExtensionManager()->notifyMembers('EntryPreEdit', '/publish/edit/', array(
'section' => $section,
'entry' => &$entry[0],
'fields' => $fields
));
$entry[0]->commit();
/**
* Editing an entry. Entry object is provided.
*
* @delegate EntryPostEdit
* @param string $context
* '/publish/edit/'
* @param Section $section
* @param Entry $entry
* @param array $fields
*/
Symphony::ExtensionManager()->notifyMembers('EntryPostEdit', '/publish/edit/', array(
'section' => $section,
'entry' => $entry[0],
'fields' => $fields
));
}
unset($field);
redirect(server_safe('REQUEST_URI'));
}
}
}
}
public function __viewNew()
{
if (!$section_id = SectionManager::fetchIDFromHandle($this->_context['section_handle'])) {
Administration::instance()->throwCustomError(
__('The Section, %s, could not be found.', array('<code>' . $this->_context['section_handle'] . '</code>')),
__('Unknown Section'),
Page::HTTP_STATUS_NOT_FOUND
);
}
$section = SectionManager::fetch($section_id);
$this->setPageType('form');
$this->setTitle(__('%1$s – %2$s', array(General::sanitize($section->get('name')), __('Symphony'))));
// Ensure errored entries still maintain any prepopulated values [#2211]
$this->Form->setAttribute('action', $this->Form->getAttribute('action') . $this->getPrepopulateString());
$this->Form->setAttribute('enctype', 'multipart/form-data');
$sidebar_fields = $section->fetchFields(null, 'sidebar');
$main_fields = $section->fetchFields(null, 'main');
if (!empty($sidebar_fields) && !empty($main_fields)) {
$this->Form->setAttribute('class', 'two columns');
} else {
$this->Form->setAttribute('class', 'columns');
}
// Only show the Edit Section button if the Author is a developer. #938 ^BA
if (Symphony::Author()->isDeveloper()) {
$this->appendSubheading(__('Untitled'),
Widget::Anchor(__('Edit Section'), SYMPHONY_URL . '/blueprints/sections/edit/' . $section_id . '/', __('Edit Section Configuration'), 'button')
);
} else {
$this->appendSubheading(__('Untitled'));
}
// Build filtered breadcrumb [#1378}
$this->insertBreadcrumbs(array(
Widget::Anchor(General::sanitize($section->get('name')), SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/' . $this->getFilterString()),
));
$this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden'));
// If there is post data floating around, due to errors, create an entry object
if (isset($_POST['fields'])) {
$entry = EntryManager::create();