This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathAdministrationModuleFunction.php
1993 lines (1767 loc) · 82.3 KB
/
AdministrationModuleFunction.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
863
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
namespace Tx\Realurl\View;
/***************************************************************
* Copyright notice
*
* (c) 2014 Helmut Hummel <[email protected]>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the text file GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
/**
* Class AdministrationModuleFunction
*/
class AdministrationModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule
{
/**
* @var int
*/
protected $searchResultCounter = 0;
/**
* @var int
*/
protected $typo3VersionMain = 0;
/**
* @var null|\TYPO3\CMS\Core\Imaging\IconFactory
*/
protected $iconFactory = null;
/**
* @var array
*/
protected $iconMapping = array(
'gfx/zoom.gif' => 'actions-search',
'gfx/edit2.gif' => 'actions-open',
'gfx/garbage.gif' => 'actions-delete',
'gfx/napshot.gif' => 'actions-document-save',
'gfx/clip_copy.gif' => 'actions-edit-copy',
'gfx/up.gif' => 'actions-move-up',
'gfx/new_el.gif' => 'actions-document-new',
);
/**
*
*/
public function __construct()
{
$GLOBALS['LANG']->includeLLfile('EXT:realurl/Resources/Private/Language/locallang_info_module.xml');
}
/**
* Returns the menu array
*
* @return array
*/
public function modMenu()
{
$modMenu = array(
'depth' => array(
0 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_0'),
1 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_1'),
2 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_2'),
3 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_3'),
99 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_infi'),
),
'type' => array(
'pathcache' => 'ID-to-path mapping',
'decode' => 'Decode cache',
'encode' => 'Encode cache',
'uniqalias' => 'Unique Aliases',
'redirects' => 'Redirects',
'config' => 'Configuration',
'log' => 'Error Log'
)
);
$modMenu['type'] = \TYPO3\CMS\Backend\Utility\BackendUtility::unsetMenuItems($this->pObj->modTSconfig['properties'], $modMenu['type'], 'menu.realurl_type');
return $modMenu;
}
/**
* MAIN function for cache information
*
* @return string Output HTML for the module.
*/
public function main()
{
$typo3VersionArray = VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version());
$this->typo3VersionMain = $typo3VersionArray['version_main'];
if ($this->typo3VersionMain > 6) {
$this->iconFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\IconFactory');
}
if ($this->pObj->id) {
$result = $this->createModuleContentForPage();
} else {
$result = '<p>' . $GLOBALS['LANG']->getLL('no_page_id') . '</p>';
}
return $result;
}
/**
* Enter description here ...
*/
protected function createModuleContentForPage()
{
$this->addModuleStyles();
$result = $this->getFunctionMenu() . ' ';
switch ($this->pObj->MOD_SETTINGS['type']) {
case 'pathcache':
$this->edit_save();
$result .= $this->getDepthSelector();
$moduleContent = $this->renderModule($this->initializeTree());
$result .= $this->renderSearchForm();
$result .= $moduleContent;
break;
case 'encode':
$result .= $this->getDepthSelector();
$result .= $this->encodeView($this->initializeTree());
break;
case 'decode':
$result .= $this->getDepthSelector();
$result .= $this->decodeView($this->initializeTree());
break;
case 'uniqalias':
$this->edit_save_uniqAlias();
$result .= $this->uniqueAlias();
break;
case 'config':
$result .= $this->getDepthSelector();
$result .= $this->configView();
break;
case 'redirects':
$result .= $this->redirectView();
break;
case 'log':
$result .= $this->logView();
break;
}
return $result;
}
/**
* Obtains function selection menu.
*
* @return string
*/
protected function getFunctionMenu()
{
return $GLOBALS['LANG']->getLL('function') . ' ' .
\TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu($this->pObj->id, 'SET[type]',
$this->pObj->MOD_SETTINGS['type'], $this->pObj->MOD_MENU['type']);
}
/**
* Adds module-specific styles to the output.
*
* @return void
*/
protected function addModuleStyles()
{
$this->pObj->doc->inDocStyles .= '
TABLE.c-list TR TD { white-space: nowrap; vertical-align: top; }
TABLE#tx-realurl-pathcacheTable TD { vertical-align: top; }
FIELDSET { border: none; padding: 16px 0; }
FIELDSET DIV { clear: left; border-collapse: collapse; margin-bottom: 5px; }
FIELDSET DIV LABEL { display: block; float: left; width: 100px; }
' . \Tx\Realurl\ViewHelpers\PageBrowserViewHelper::getInlineStyles();
}
/**
* Creates depth selector HTML for the page tree.
*
* @return string
*/
protected function getDepthSelector()
{
return $GLOBALS['LANG']->getLL('depth') .
\TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu($this->pObj->id, 'SET[depth]', $this->pObj->MOD_SETTINGS['depth'], $this->pObj->MOD_MENU['depth']);
}
/**
* Initializes the page tree.
*
* @return \TYPO3\CMS\Backend\Tree\View\PageTreeView
*/
protected function initializeTree()
{
$tree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PageTreeView');
/** @var \TYPO3\CMS\Backend\Tree\View\PageTreeView $tree */
$tree->addField('nav_title', true);
$tree->addField('alias', true);
$tree->addField('tx_realurl_pathsegment', true);
$tree->init('AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1));
$treeStartingPoint = intval($this->pObj->id);
$treeStartingRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $treeStartingPoint);
\TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL('pages', $treeStartingRecord);
// Creating top icon; the current page
$tree->tree[] = array(
'row' => $treeStartingRecord,
'HTML' => $tree->getIcon($treeStartingRecord)
);
// Create the tree from starting point:
if ($this->pObj->MOD_SETTINGS['depth'] > 0) {
$tree->getTree($treeStartingPoint, $this->pObj->MOD_SETTINGS['depth'], '');
}
return $tree;
}
/****************************
*
* Path Cache rendering:
*
****************************/
/**
* Rendering the information
*
* @param array The Page tree data
* @return string HTML for the information table.
*/
public function renderModule(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree)
{
// Initialize:
$searchPath = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pathPrefixSearch'));
$cmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('cmd');
$entry = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('entry');
$searchForm_replace = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('_replace');
$searchForm_delete = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('_delete');
$trackSameUrl = array();
$this->searchResultCounter = 0;
// Traverse tree:
$output = '';
$cc=0;
foreach ($tree->tree as $row) {
// Get all pagepath entries for page:
$pathCacheInfo = $this->getPathCache($row['row']['uid']);
// Row title:
$rowTitle = $row['HTML'] . \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('pages', $row['row'], true);
$cellAttrib = ($row['row']['_CSSCLASS'] ? ' class="' . $row['row']['_CSSCLASS'] . '"' : '');
// Add at least one empty element:
if (!count($pathCacheInfo)) {
// Add title:
$tCells = array();
$tCells[]='<td nowrap="nowrap"' . $cellAttrib . '>' . $rowTitle . '</td>';
// Empty row:
$tCells[]='<td colspan="10" align="center"> </td>';
// Compile Row:
$output.= '
<tr class="bgColor' . ($cc%2 ? '-20':'-10') . '">
' . implode('
', $tCells) . '
</tr>';
$cc++;
} else {
foreach ($pathCacheInfo as $c => $inf) {
// Init:
$deletedEntry = false;
$hash = $inf['pagepath'] . '|' . $inf['rootpage_id'] . '|' . $inf['language_id']; // MP is not a part of this because the path itself should be different simply because the MP makes a different path! (see UriGeneratorAndResolver::pagePathtoID())
// Add icon/title and ID:
$tCells = array();
if (!$c) {
$tCells[]='<td nowrap="nowrap" rowspan="' . count($pathCacheInfo) . '"' . $cellAttrib . '>' . $rowTitle . '</td>';
$tCells[]='<td rowspan="' . count($pathCacheInfo) . '">' . $inf['page_id'] . '</td>';
}
// Add values from alternative field used to generate URL:
$baseRow = $row['row']; // page row as base.
$onClick = \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick('&edit[pages][' . $row['row']['uid'] . ']=edit&columnsOnly=title,nav_title,alias,tx_realurl_pathsegment', $this->pObj->doc->backPath);
$editIcon = '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' .
$this->getIcon('gfx/edit2.gif', 'width="11" height="12"', $this->pObj->doc->backPath) .
'</a>';
$onClick = \TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($row['row']['uid'], $this->pObj->doc->backPath, '', '', '', '');
$editIcon.= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' .
$this->getIcon('gfx/zoom.gif', 'width="12" height="12"', $this->pObj->doc->backPath) .
'</a>';
if ($inf['language_id']>0) { // For alternative languages, show another list of fields, form page overlay record:
$editIcon = '';
list($olRec) = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $row['row']['uid'], ' AND sys_language_uid=' . intval($inf['language_id']));
if (is_array($olRec)) {
$baseRow = array_merge($baseRow, $olRec);
$onClick = \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick('&edit[pages_language_overlay][' . $olRec['uid'] . ']=edit&columnsOnly=title,nav_title', $this->pObj->doc->backPath);
$editIcon = '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' .
$this->getIcon('gfx/edit2.gif', 'width="11" height="12"', $this->pObj->doc->backPath) .
'</a>';
$onClick = \TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($row['row']['uid'], $this->pObj->doc->backPath, '', '', '', '&L=' . $olRec['sys_language_uid']);
$editIcon.= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' .
$this->getIcon('gfx/zoom.gif', 'width="12" height="12"', $this->pObj->doc->backPath) .
'</a>';
} else {
$baseRow = array();
}
}
$tCells[]='<td>' . $editIcon . '</td>';
// Sources for segment:
$sources = count($baseRow) ? implode(' | ', array($baseRow['tx_realurl_pathsegment'], $baseRow['alias'], $baseRow['nav_title'], $baseRow['title'])) : '';
$tCells[]='<td nowrap="nowrap">' . htmlspecialchars($sources) . '</td>';
// Show page path:
if (strcmp($searchPath, '') && \TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($inf['pagepath'], $searchPath) && !$inf['expire']) {
// Delete entry:
if ($searchForm_delete) {
$this->deletePathCacheEntry($inf['cache_id']);
$deletedEntry = true;
$pagePath = '[DELETED]';
} elseif ($searchForm_replace) {
$replacePart = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('pathPrefixReplace'));
$this->editPathCacheEntry($inf['cache_id'],
$replacePart . substr($inf['pagepath'], strlen($searchPath)));
$pagePath =
'<span class="typo3-red">' .
htmlspecialchars($replacePart) .
'</span>' .
htmlspecialchars(substr($inf['pagepath'], strlen($searchPath)));
} else {
$pagePath =
'<span class="typo3-red">' .
htmlspecialchars(substr($inf['pagepath'], 0, strlen($searchPath))) .
'</span>' .
htmlspecialchars(substr($inf['pagepath'], strlen($searchPath)));
$this->searchResultCounter++;
}
} else {
// Delete entries:
if ($cmd==='edit' && (!strcmp($entry, $inf['cache_id']) || !strcmp($entry, 'ALL'))) {
$pagePath = '<input type="text" name="edit[' . $inf['cache_id'] . ']" value="' . htmlspecialchars($inf['pagepath']) . '" size="40" />';
if ($cmd==='edit' && $entry!='ALL') {
$pagePath.= $this->saveCancelButtons();
}
} else {
$pagePath = htmlspecialchars($inf['pagepath']);
}
}
$tCells[]='<td' . ($inf['expire'] ? ' style="font-style: italic; color:#999999;"' : '') . '>' . $pagePath . '</td>';
if ($deletedEntry) {
$tCells[]='<td> </td>';
} else {
$tCells[]='<td>' .
'<a href="' . $this->linkSelf('&cmd=delete&entry=' . $inf['cache_id']) . '">' .
$this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete') .
'</a>' .
'<a href="' . $this->linkSelf('&cmd=edit&entry=' . $inf['cache_id']) . '">' .
$this->getIcon('gfx/edit2.gif', 'width="12" height="12"', $this->pObj->doc->backPath, 'Edit') .
'</a>' .
'<a href="' . $this->linkSelf('&pathPrefixSearch=' . rawurlencode($inf['pagepath'])) . '">' .
$this->getIcon('gfx/napshot.gif', 'width="12" height="12"', $this->pObj->doc->backPath, 'Use for search') .
'</a>' .
'<a href="' . $this->linkSelf('&cmd=copy&entry=' . $inf['cache_id']) . '">' .
$this->getIcon('gfx/clip_copy.gif', 'width="12" height="12"', $this->pObj->doc->backPath, 'Copy entry') .
'</a>' .
'</td>';
}
$tCells[]='<td' . ($inf['expire'] && $inf['expire']<time() ? ' style="color: red;"':'') . '>' .
($inf['expire'] ? htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::dateTimeAge($inf['expire'], -1)) : '') .
($inf['expire'] ?
'<a href="' . $this->linkSelf('&cmd=raiseExpire&entry=' . $inf['cache_id']) . '">' .
$this->getIcon('gfx/up.gif', 'width="14" height="14"', $this->pObj->doc->backPath, 'Set expire time to 30 days') .
'</a>' : '') .
'</td>';
// Set error msg:
$error = '';
if (!strcmp($inf['pagepath'], '')) {
if ($row['row']['uid']!=$this->pObj->id) { // Show error of "Empty" only for levels under the root. Yes, we cannot know that the pObj->id is the true root of the site, but at least any SUB page should probably have a path string!
$error = $this->pObj->doc->icons(2) . 'Empty';
}
} elseif (isset($trackSameUrl[$hash])) {
$error = $this->pObj->doc->icons(2) . 'Already used on page ID ' . $trackSameUrl[$hash];
} else {
$error = ' ';
}
$tCells[]='<td>' . $error . '</td>';
$tCells[]='<td>' . htmlspecialchars($inf['language_id']) . '</td>';
$tCells[]='<td>' . htmlspecialchars($inf['mpvar']) . '</td>';
$tCells[]='<td>' . htmlspecialchars($inf['rootpage_id']) . '</td>';
#$tCells[]='<td nowrap="nowrap">'.htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::datetime($inf['expire'])).' / '.htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::calcAge($inf['expire']-time())).'</td>';
$trackSameUrl[$hash] = $inf['page_id'];
// Compile Row:
$rowClass = 'bgColor' . ($cc%2 ? '-20':'-10');
$output.= '
<tr class="' . $rowClass . '">
' . implode('
', $tCells) . '
</tr>';
$cc++;
}
}
}
// Create header:
$tCells = array();
$tCells[]='<td>Title:</td>';
$tCells[]='<td>ID:</td>';
$tCells[]='<td> </td>';
$tCells[]='<td>PathSegment | Alias | NavTitle | Title:</td>';
$tCells[]='<td>Pagepath:</td>';
$tCells[]='<td>' .
'<a href="' . $this->linkSelf('&cmd=delete&entry=ALL') . '" onclick="return confirm(\'Are you sure you want to flush all cached page paths?\');">' .
$this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath) .
'</a>' .
'<a href="' . $this->linkSelf('&cmd=edit&entry=ALL') . '">' .
$this->getIcon('gfx/edit2.gif', 'width="11" height="12"', $this->pObj->doc->backPath) .
'</a>' .
'</td>';
$tCells[]='<td>Expires:' .
'<a href="' . $this->linkSelf('&cmd=flushExpired') . '">' .
$this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Flush all expired') .
'</a>' .
'</td>';
$tCells[]='<td>Errors:</td>';
$tCells[]='<td>Lang:</td>';
$tCells[]='<td>&MP:</td>';
$tCells[]='<td>RootPage ID:</td>';
#$tCells[]='<td>Expire:</td>';
$output = '
<tr class="bgColor5 tableheader">
' . implode('
', $tCells) . '
</tr>' . $output;
// Compile final table and return:
$output = '
<table border="0" cellspacing="1" cellpadding="0" id="tx-realurl-pathcacheTable" class="lrPadding c-list">' . $output . '
</table>';
if ($cmd==='edit' && $entry=='ALL') {
$output.= $this->saveCancelButtons();
}
return $output;
}
/**
* Fetch path caching information for page.
*
* @param int Page ID
* @return array Path Cache records
*/
public function getPathCache($pageId)
{
$showLanguage = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('showLanguage');
$cmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('cmd');
$entry = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('entry');
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*',
'tx_realurl_pathcache',
'page_id=' . intval($pageId) .
((string)$showLanguage!=='' ? ' AND language_id=' . intval($showLanguage) : ''),
'',
'language_id,expire'
);
// Traverse result:
$output = array();
while (false != ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
// Delete entries:
if ($cmd==='delete' && (!strcmp($entry, $row['cache_id']) || !strcmp($entry, 'ALL'))) {
$this->deletePathCacheEntry($row['cache_id']);
// Raise expire times:
} elseif ($cmd==='raiseExpire' && !strcmp($entry, $row['cache_id'])) {
$this->raiseExpirePathCacheEntry($row);
$output[] = $row;
} elseif ($cmd==='flushExpired' && $row['expire'] && $row['expire']<time()) {
$this->deletePathCacheEntry($row['cache_id']);
} elseif ($cmd==='copy' && (!strcmp($entry, $row['cache_id']))) {
$output[] = $this->copyPathCacheEntry($row);
$output[] = $row;
} else { // ... or add:
$output[] = $row;
}
}
$GLOBALS['TYPO3_DB']->sql_free_result($res);
return $output;
}
/**
* Links to the module script and sets necessary parameters (only for path cache display)
*
* @param string $parameters Additional GET vars
* @return string script + query
*/
public function linkSelf($parameters)
{
return htmlspecialchars(BackendUtility::getModuleUrl(
'web_info',
array(
'id' => $this->pObj->id,
'showLanguage' => \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('showLanguage'),
)
) . $parameters);
}
/**
* Create search form
*
* @return string HTML
*/
public function renderSearchForm()
{
$output = '<fieldset>';
$output .= $this->getLanguageSelector();
$output .= '<div>' . $this->getSearchField() . '</div>';
$output .= $this->getReplaceAndDeleteFields();
$output.= '<input type="hidden" name="id" value="' . $this->pObj->id . '" />';
$output.= '</fieldset>';
return $output;
}
/**
* Obtains fields for replace/delete.
*
* @return string
*/
private function getReplaceAndDeleteFields()
{
$output = '';
if ($this->searchResultCounter && !\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('_replace') && !\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('_delete')) {
$output .= '<div><label for="pathPrefixReplace">Replace with:</label> <input type="text" name="pathPrefixReplace" value="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pathPrefixSearch')) . '" />';
$output .= '<input type="submit" name="_replace" value="Replace" /> or <input type="submit" name="_delete" value="Delete" /></div>';
$output .= '<div><b>' . sprintf('Found: %d result(s).', $this->searchResultCounter) . '</b></div>';
}
return $output;
}
/**
* Enter description here ...
* @param output
*/
protected function getSearchField()
{
$output = '<label for="pathPrefixSearch">' . $GLOBALS['LANG']->getLL('search_path', true) .
'</label> <input type="text" name="pathPrefixSearch" id="pathPrefixSearch" value="' .
htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pathPrefixSearch')) . '" />' .
'<input type="submit" name="_" value="' .
$GLOBALS['LANG']->getLL('look_up', true) . '" />';
return $output;
}
/**
* Generates language selector.
*
* @return string
*/
protected function getLanguageSelector()
{
$languages = $this->getSystemLanguages();
$options = array();
$showLanguage = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('showLanguage');
foreach ($languages as $language) {
$selected = $showLanguage === $language['uid'] ? ' selected="selected"' : '';
$options[] = '<option value="' . $language['uid'] . '"' . $selected . '>' .
htmlspecialchars($language['title']) . '</option>';
}
return '<div><label for="showLanguage">' . $GLOBALS['LANG']->getLL('language', true) .
'</label> <select name="showLanguage">' . implode('', $options) . '</select></div>';
}
/**
* Obtains system languages.
*
* @return array
*/
protected function getSystemLanguages()
{
$languages = (array)\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordsByField('sys_language', 'pid', 0, '', '', 'title');
$defaultLanguageLabel = $this->getDefaultLanguageName();
array_unshift($languages, array('uid' => 0, 'title' => $defaultLanguageLabel));
array_unshift($languages, array('uid' => '', 'title' => $GLOBALS['LANG']->getLL('all_languages')));
return $languages;
}
/**
* Obtains the name of the default language.
*
* @return string
*/
protected function getDefaultLanguageName()
{
$tsConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($this->pObj->id);
if (isset($tsConfig['mod.']['SHARED.']['defaultLanguageLabel'])) {
$label = $tsConfig['mod.']['SHARED.']['defaultLanguageLabel'];
} else {
$label = $GLOBALS['LANG']->getLL('default_language');
}
return $label;
}
/**
* Deletes an entry in pathcache table
*
* @param int Path Cache id (cache_id)
* @return void
*/
public function deletePathCacheEntry($cache_id)
{
$GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_realurl_pathcache', 'cache_id=' . intval($cache_id));
}
/**
* Deletes an entry in pathcache table
*
* @param int Path Cache id (cache_id)
* @return void
*/
public function raiseExpirePathCacheEntry(&$row)
{
$row['expire'] = time()+30*24*3600;
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_realurl_pathcache', 'expire>0 AND cache_id=' . intval($row['cache_id']), array('expire' => $row['expire']));
}
/**
* Copies an entry in pathcache table
*
* @param array Record to copy, passed by reference, will be updated.
* @return array New record.
*/
public function copyPathCacheEntry(&$oEntry)
{
// Select old record:
$cEntry = $oEntry;
unset($cEntry['cache_id']);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_realurl_pathcache', $cEntry);
$cEntry['cache_id'] = $GLOBALS['TYPO3_DB']->sql_insert_id();
// Update the old record with expire time:
if (!$oEntry['expire']) {
$oEntry['expire'] = time()+30*24*3600;
$field_values = array(
'expire' => $oEntry['expire'],
);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_realurl_pathcache', 'cache_id=' . intval($oEntry['cache_id']), $field_values);
}
return $cEntry;
}
/**
* Changes the "pagepath" value of an entry in the pathcache table
*
* @param int Path Cache id (cache_id)
* @param string New value for the pagepath
* @return void
*/
public function editPathCacheEntry($cache_id, $value)
{
$field_values = array(
'pagepath' => $value
);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_realurl_pathcache', 'cache_id=' . intval($cache_id), $field_values);
// Look up the page id so we can clear the encodeCache entries:
list($page_id_rec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('page_id', 'tx_realurl_pathcache', 'cache_id=' . intval($cache_id));
$this->clearDEncodeCache('page_' . $page_id_rec['page_id']); // Encode cache
$this->clearDEncodeCache('page_' . $page_id_rec['page_id'], true); // Decode cache
}
/**
* Will look for submitted pagepath cache entries to save
*
* @return void
*/
public function edit_save()
{
if (\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('_edit_save')) {
$editArray = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('edit');
foreach ($editArray as $cache_id => $value) {
$this->editPathCacheEntry($cache_id, trim($value));
}
}
}
/**
* Save / Cancel buttons
*
* @param string Extra code.
* @return string Form elements
*/
public function saveCancelButtons($extra='')
{
$output = '<input type="submit" name="_edit_save" value="Save" /> ';
$output .= '<input type="submit" name="_edit_cancel" value="Cancel" />';
$output .= $extra;
return $output;
}
/**************************
*
* Decode view
*
**************************/
/**
* Rendering the decode-cache content
*
* @param array The Page tree data
* @return string HTML for the information table.
*/
public function decodeView(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree)
{
// Delete entries:
$cmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cmd');
$subcmd = '';
if ($cmd === 'deleteDC') {
$subcmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('entry');
$this->clearDEncodeCache($subcmd, true);
}
// Traverse tree:
$output = '';
$cc=0;
$countDisplayed = 0;
foreach ($tree->tree as $row) {
// Select rows:
$displayRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_realurl_urldecodecache', 'page_id=' . intval($row['row']['uid']), '', 'spurl');
// Row title:
$rowTitle = $row['HTML'] . \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('pages', $row['row'], true);
// Add at least one empty element:
if (!count($displayRows) || $subcmd==='displayed') {
// Add title:
$tCells = array();
$tCells[]='<td nowrap="nowrap">' . $rowTitle . '</td>';
// Empty row:
$tCells[]='<td colspan="6" align="center"> </td>';
// Compile Row:
$output.= '
<tr class="bgColor' . ($cc%2 ? '-20':'-10') . '">
' . implode('
', $tCells) . '
</tr>';
$cc++;
if ($subcmd==='displayed') {
foreach ($displayRows as $c => $inf) {
$this->clearDEncodeCache('urlhash_' . $inf['url_hash'], true);
}
}
} else {
foreach ($displayRows as $c => $inf) {
// Add icon/title and ID:
$tCells = array();
if (!$c) {
$tCells[]='<td nowrap="nowrap" rowspan="' . count($displayRows) . '">' . $rowTitle . '</td>';
$tCells[]='<td nowrap="nowrap" rowspan="' . count($displayRows) . '">' . $row['row']['uid'] . '</td>';
$tCells[]='<td rowspan="' . count($displayRows) . '">' .
'<a href="' . $this->linkSelf('&cmd=deleteDC&entry=page_' . intval($row['row']['uid'])) . '">' .
$this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete entries for page') .
'</a>' .
'</td>';
}
// Path:
$tCells[]='<td>' . htmlspecialchars($inf['spurl']) . '</td>';
// Get vars:
$queryValues = unserialize($inf['content']);
$queryParams = '?id=' . $queryValues['id'] .
(is_array($queryValues['GET_VARS']) ? \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $queryValues['GET_VARS']) : '');
$tCells[]='<td>' . htmlspecialchars($queryParams) . '</td>';
// Delete:
$tCells[]='<td>' .
'<a href="' . $this->linkSelf('&cmd=deleteDC&entry=urlhash_' . rawurlencode($inf['url_hash'])) . '">' .
$this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete entry') .
'</a>' .
'</td>';
// Timestamp:
$tCells[]='<td>' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::datetime($inf['tstamp'])) . ' / ' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::calcAge(time()-$inf['tstamp'])) . '</td>';
// Compile Row:
$output.= '
<tr class="bgColor' . ($cc%2 ? '-20':'-10') . '">
' . implode('
', $tCells) . '
</tr>';
$cc++;
$countDisplayed++;
}
}
}
list($count_allInTable) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('count(*) AS count', 'tx_realurl_urldecodecache', '');
// Create header:
$tCells = array();
$tCells[]='<td>Title:</td>';
$tCells[]='<td>ID:</td>';
$tCells[]='<td> </td>';
$tCells[]='<td>Path:</td>';
$tCells[]='<td>GET variables:</td>';
$tCells[]='<td> </td>';
$tCells[]='<td>Timestamp:</td>';
$output = '
<tr class="bgColor5 tableheader">
' . implode('
', $tCells) . '
</tr>' . $output;
// Compile final table and return:
$output = '<br/><br/>
Displayed entries: <b>' . $countDisplayed . '</b> ' .
'<a href="' . $this->linkSelf('&cmd=deleteDC&entry=displayed') . '">' .
$this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete displayed entries') .
'</a>' .
'<br/>
Total entries in decode cache: <b>' . $count_allInTable['count'] . '</b> ' .
'<a href="' . $this->linkSelf('&cmd=deleteDC&entry=all') . '">' .
$this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete WHOLE decode cache!') .
'</a>' .
'<br/>
<table border="0" cellspacing="1" cellpadding="0" id="tx-realurl-pathcacheTable" class="lrPadding c-list">' . $output . '
</table>';
return $output;
}
/**************************
*
* Encode view
*
**************************/
/**
* Rendering the encode-cache content
*
* @param array The Page tree data
* @return string HTML for the information table.
*/
public function encodeView(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree)
{
// Delete entries:
$cmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cmd');
$subcmd = '';
if ($cmd === 'deleteEC') {
$subcmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('entry');
$this->clearDEncodeCache($subcmd);
}
// Traverse tree:
$cc = 0;
$countDisplayed = 0;
$output = '';
$duplicates = array();
foreach ($tree->tree as $row) {
// Select rows:
$displayRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_realurl_urlencodecache', 'page_id=' . intval($row['row']['uid']), '', 'content');
// Row title:
$rowTitle = $row['HTML'] . \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('pages', $row['row'], true);
// Add at least one empty element:
if (!count($displayRows) || $subcmd==='displayed') {
// Add title:
$tCells = array();
$tCells[]='<td nowrap="nowrap">' . $rowTitle . '</td>';
$tCells[]='<td nowrap="nowrap"> </td>';
// Empty row:
$tCells[]='<td colspan="7" align="center"> </td>';
// Compile Row:
$output.= '
<tr class="bgColor' . ($cc%2 ? '-20':'-10') . '">
' . implode('
', $tCells) . '
</tr>';
$cc++;
if ($subcmd==='displayed') {
foreach ($displayRows as $c => $inf) {
$this->clearDEncodeCache('urlhash_' . $inf['url_hash']);
}
}
} else {
foreach ($displayRows as $c => $inf) {
// Add icon/title and ID:
$tCells = array();
if (!$c) {
$tCells[]='<td nowrap="nowrap" rowspan="' . count($displayRows) . '">' . $rowTitle . '</td>';
$tCells[]='<td nowrap="nowrap" rowspan="' . count($displayRows) . '">' . $row['row']['uid'] . '</td>';
$tCells[]='<td rowspan="' . count($displayRows) . '">' .
'<a href="' . $this->linkSelf('&cmd=deleteEC&entry=page_' . intval($row['row']['uid'])) . '">' .
$this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete entries for page') .
'</a>' .
'</td>';
}
// Get vars:
$tCells[]='<td>' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($inf['origparams'], 100)) . '</td>';
// Internal Extras:
$tCells[]='<td>' . ($inf['internalExtras'] ? \TYPO3\CMS\Core\Utility\GeneralUtility::arrayToLogString(unserialize($inf['internalExtras'])) : ' ') . '</td>';
// Path:
$tCells[]='<td>' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($inf['content'], 100)) . '</td>';
// Delete:
$tCells[]='<td>' .
'<a href="' . $this->linkSelf('&cmd=deleteEC&entry=urlhash_' . rawurlencode($inf['url_hash'])) . '">' .
$this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete entry!') .
'</a>' .
'</td>';
// Error:
$eMsg = ($duplicates[$inf['content']] && $duplicates[$inf['content']] !== $row['row']['uid'] ? $this->pObj->doc->icons(2) . 'Already used on page ID ' . $duplicates[$inf['content']] . '<br/>' : '');
if (count($GLOBALS['TYPO3_DB']->exec_SELECTgetRows('url_hash', 'tx_realurl_redirects', 'url_hash=' . intval(\TYPO3\CMS\Core\Utility\GeneralUtility::md5int($inf['content']))))) {
$eMsg.= $this->pObj->doc->icons(3) . 'Also a redirect!';
}
$tCells[]='<td>' . $eMsg . '</td>';
// Timestamp:
$tCells[]='<td>' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::datetime($inf['tstamp'])) . ' / ' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::calcAge(time()-$inf['tstamp'])) . '</td>';
// Compile Row:
$output.= '
<tr class="bgColor' . ($cc%2 ? '-20':'-10') . '">
' . implode('
', $tCells) . '
</tr>';
$cc++;
$countDisplayed++;