PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/typo3conf/ext/realurl/modfunc1/class.tx_realurl_modfunc1.php

https://github.com/moodley/fdummy
PHP | 1975 lines | 1219 code | 297 blank | 459 comment | 143 complexity | 0b6ff1c7d9e527f9ccc06304220385cc MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2004-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
  6. * (c) 2005-2010 Dmitry Dulepov (dmitry@typo3.org)
  7. * All rights reserved
  8. *
  9. * This script is part of the TYPO3 project. The TYPO3 project is
  10. * free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * The GNU General Public License can be found at
  16. * http://www.gnu.org/copyleft/gpl.html.
  17. *
  18. * This script is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * This copyright notice MUST APPEAR in all copies of the script!
  24. ***************************************************************/
  25. /**
  26. * Speaking Url management extension
  27. *
  28. * $Id: class.tx_realurl_modfunc1.php 63822 2012-06-25 09:29:36Z dmitry $
  29. *
  30. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  31. */
  32. /**
  33. * [CLASS/FUNCTION INDEX of SCRIPT]
  34. *
  35. *
  36. *
  37. * 78: class tx_realurl_modfunc1 extends t3lib_extobjbase
  38. * 89: function modMenu()
  39. * 113: function main()
  40. *
  41. * SECTION: Path Cache rendering:
  42. * 215: function renderModule($tree)
  43. * 435: function getPathCache($pageId)
  44. * 471: function linkSelf($addParams)
  45. * 480: function renderSearchForm()
  46. * 524: function deletePathCacheEntry($cache_id)
  47. * 535: function editPathCacheEntry($cache_id,$value)
  48. * 547: function edit_save()
  49. * 562: function saveCancelButtons($extra='')
  50. *
  51. * SECTION: Decode view
  52. * 593: function decodeView($tree)
  53. *
  54. * SECTION: Encode view
  55. * 698: function encodeView($tree)
  56. *
  57. * SECTION: Unique Alias
  58. * 806: function uniqueAlias()
  59. * 939: function editUniqAliasEntry($cache_id,$value)
  60. * 951: function edit_save_uniqAlias()
  61. *
  62. * TOTAL FUNCTIONS: 15
  63. * (This index is automatically created/updated by the extension "extdeveval")
  64. *
  65. */
  66. require_once(PATH_t3lib.'class.t3lib_pagetree.php');
  67. require_once(PATH_t3lib.'class.t3lib_extobjbase.php');
  68. $GLOBALS['LANG']->includeLLfile('EXT:realurl/modfunc1/locallang.xml');
  69. require_once(t3lib_extMgm::extPath('realurl', 'modfunc1/class.tx_realurl_pagebrowser.php'));
  70. /**
  71. * Speaking Url management extension
  72. *
  73. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  74. * @package TYPO3
  75. * @subpackage tx_realurl
  76. */
  77. class tx_realurl_modfunc1 extends t3lib_extobjbase {
  78. // Internal, dynamic:
  79. var $searchResultCounter = 0;
  80. /**
  81. * Returns the menu array
  82. *
  83. * @return array
  84. */
  85. function modMenu() {
  86. return array (
  87. 'depth' => array(
  88. 0 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_0'),
  89. 1 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_1'),
  90. 2 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_2'),
  91. 3 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_3'),
  92. 99 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_infi'),
  93. ),
  94. 'type' => array(
  95. 'pathcache' => 'ID-to-path mapping',
  96. 'decode' => 'Decode cache',
  97. 'encode' => 'Encode cache',
  98. 'uniqalias' => 'Unique Aliases',
  99. 'redirects' => 'Redirects',
  100. 'config' => 'Configuration',
  101. 'log' => 'Error Log'
  102. )
  103. );
  104. }
  105. /**
  106. * MAIN function for cache information
  107. *
  108. * @return string Output HTML for the module.
  109. */
  110. function main() {
  111. if ($this->pObj->id) {
  112. $result = $this->createModuleContentForPage();
  113. }
  114. else {
  115. $result = '<p>' . $GLOBALS['LANG']->getLL('no_page_id') . '</p>';
  116. }
  117. return $result;
  118. }
  119. /**
  120. * Enter description here ...
  121. */
  122. protected function createModuleContentForPage() {
  123. $this->addModuleStyles();
  124. $result = $this->getFunctionMenu() . ' ';
  125. switch ($this->pObj->MOD_SETTINGS['type']) {
  126. case 'pathcache':
  127. $this->edit_save();
  128. $result .= $this->getDepthSelector();
  129. $moduleContent = $this->renderModule($this->initializeTree());
  130. $result .= $this->renderSearchForm();
  131. $result .= $moduleContent;
  132. break;
  133. case 'encode':
  134. $result .= $this->getDepthSelector();
  135. $result .= $this->encodeView($this->initializeTree());
  136. break;
  137. case 'decode':
  138. $result .= $this->getDepthSelector();
  139. $result .= $this->decodeView($this->initializeTree());
  140. break;
  141. case 'uniqalias':
  142. $this->edit_save_uniqAlias();
  143. $result .= $this->uniqueAlias();
  144. break;
  145. case 'config':
  146. $result .= $this->getDepthSelector();
  147. $result .= $this->configView();
  148. break;
  149. case 'redirects':
  150. $result .= $this->redirectView();
  151. break;
  152. case 'log':
  153. $result .= $this->logView();
  154. break;
  155. }
  156. return $result;
  157. }
  158. /**
  159. * Obtains function selection menu.
  160. *
  161. * @return string
  162. */
  163. protected function getFunctionMenu() {
  164. return $GLOBALS['LANG']->getLL('function') . ' ' .
  165. t3lib_BEfunc::getFuncMenu($this->pObj->id, 'SET[type]',
  166. $this->pObj->MOD_SETTINGS['type'], $this->pObj->MOD_MENU['type'],
  167. 'index.php');
  168. }
  169. /**
  170. * Adds module-specific styles to the output.
  171. *
  172. * @return void
  173. */
  174. protected function addModuleStyles() {
  175. $this->pObj->doc->inDocStyles .= '
  176. TABLE.c-list TR TD { white-space: nowrap; vertical-align: top; }
  177. TABLE#tx-realurl-pathcacheTable TD { vertical-align: top; }
  178. FIELDSET { border: none; padding: 16px 0; }
  179. FIELDSET DIV { clear: left; border-collapse: collapse; margin-bottom: 5px; }
  180. FIELDSET DIV LABEL { display: block; float: left; width: 100px; }
  181. ' . tx_realurl_pagebrowser::getInlineStyles();
  182. }
  183. /**
  184. * Creates depth selector HTML for the page tree.
  185. *
  186. * @return string
  187. */
  188. protected function getDepthSelector() {
  189. return $GLOBALS['LANG']->getLL('depth') .
  190. t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth'],'index.php');
  191. }
  192. /**
  193. * Initializes the page tree.
  194. *
  195. * @return t3lib_pageTree
  196. */
  197. protected function initializeTree() {
  198. $tree = t3lib_div::makeInstance('t3lib_pageTree');
  199. /** @var t3lib_pageTree $tree */
  200. $tree->addField('nav_title', true);
  201. $tree->addField('alias', true);
  202. $tree->addField('tx_realurl_pathsegment', true);
  203. $tree->init('AND '.$GLOBALS['BE_USER']->getPagePermsClause(1));
  204. $treeStartingPoint = intval($this->pObj->id);
  205. $treeStartingRecord = t3lib_BEfunc::getRecord('pages', $treeStartingPoint);
  206. t3lib_BEfunc::workspaceOL('pages',$treeStartingRecord);
  207. // Creating top icon; the current page
  208. $tree->tree[] = array(
  209. 'row' => $treeStartingRecord,
  210. 'HTML' => t3lib_iconWorks::getIconImage('pages', $treeStartingRecord, $GLOBALS['BACK_PATH'], 'align="top"')
  211. );
  212. // Create the tree from starting point:
  213. if ($this->pObj->MOD_SETTINGS['depth'] > 0) {
  214. $tree->getTree($treeStartingPoint, $this->pObj->MOD_SETTINGS['depth'], '');
  215. }
  216. return $tree;
  217. }
  218. /****************************
  219. *
  220. * Path Cache rendering:
  221. *
  222. ****************************/
  223. /**
  224. * Rendering the information
  225. *
  226. * @param array The Page tree data
  227. * @return string HTML for the information table.
  228. */
  229. function renderModule(t3lib_pageTree $tree) {
  230. // Initialize:
  231. $searchPath = trim(t3lib_div::_GP('pathPrefixSearch'));
  232. $cmd = t3lib_div::_GET('cmd');
  233. $entry = t3lib_div::_GET('entry');
  234. $searchForm_replace = t3lib_div::_POST('_replace');
  235. $searchForm_delete = t3lib_div::_POST('_delete');
  236. $trackSameUrl = array();
  237. $this->searchResultCounter = 0;
  238. // Traverse tree:
  239. $output = '';
  240. $cc=0;
  241. foreach($tree->tree as $row) {
  242. // Get all pagepath entries for page:
  243. $pathCacheInfo = $this->getPathCache($row['row']['uid']);
  244. // Row title:
  245. $rowTitle = $row['HTML'].t3lib_BEfunc::getRecordTitle('pages',$row['row'],TRUE);
  246. $cellAttrib = ($row['row']['_CSSCLASS'] ? ' class="'.$row['row']['_CSSCLASS'].'"' : '');
  247. // Add at least one empty element:
  248. if (!count($pathCacheInfo)) {
  249. // Add title:
  250. $tCells = array();
  251. $tCells[]='<td nowrap="nowrap"'.$cellAttrib.'>'.$rowTitle.'</td>';
  252. // Empty row:
  253. $tCells[]='<td colspan="10" align="center">&nbsp;</td>';
  254. // Compile Row:
  255. $output.= '
  256. <tr class="bgColor'.($cc%2 ? '-20':'-10').'">
  257. '.implode('
  258. ',$tCells).'
  259. </tr>';
  260. $cc++;
  261. } else {
  262. foreach($pathCacheInfo as $c => $inf) {
  263. // Init:
  264. $deletedEntry = FALSE;
  265. $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 tx_realurl_advanced::pagePathtoID())
  266. // Add icon/title and ID:
  267. $tCells = array();
  268. if (!$c) {
  269. $tCells[]='<td nowrap="nowrap" rowspan="'.count($pathCacheInfo).'"'.$cellAttrib.'>'.$rowTitle.'</td>';
  270. $tCells[]='<td rowspan="'.count($pathCacheInfo).'">'.$inf['page_id'].'</td>';
  271. }
  272. // Add values from alternative field used to generate URL:
  273. $baseRow = $row['row']; // page row as base.
  274. $onClick = t3lib_BEfunc::editOnClick('&edit[pages]['.$row['row']['uid'].']=edit&columnsOnly=title,nav_title,alias,tx_realurl_pathsegment',$this->pObj->doc->backPath);
  275. $editIcon = '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
  276. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' title="" alt="" />'.
  277. '</a>';
  278. $onClick = t3lib_BEfunc::viewOnClick($row['row']['uid'],$this->pObj->doc->backPath,'','','','');
  279. $editIcon.= '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
  280. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
  281. '</a>';
  282. if ($inf['language_id']>0) { // For alternative languages, show another list of fields, form page overlay record:
  283. $editIcon = '';
  284. list($olRec) = t3lib_BEfunc::getRecordsByField('pages_language_overlay','pid',$row['row']['uid'],' AND sys_language_uid='.intval($inf['language_id']));
  285. if (is_array($olRec)) {
  286. $baseRow = array_merge($baseRow,$olRec);
  287. $onClick = t3lib_BEfunc::editOnClick('&edit[pages_language_overlay]['.$olRec['uid'].']=edit&columnsOnly=title,nav_title',$this->pObj->doc->backPath);
  288. $editIcon = '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
  289. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' title="" alt="" />'.
  290. '</a>';
  291. $onClick = t3lib_BEfunc::viewOnClick($row['row']['uid'],$this->pObj->doc->backPath,'','','','&L='.$olRec['sys_language_uid']);
  292. $editIcon.= '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
  293. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
  294. '</a>';
  295. } else {
  296. $baseRow = array();
  297. }
  298. }
  299. $tCells[]='<td>'.$editIcon.'</td>';
  300. // Sources for segment:
  301. $sources = count($baseRow) ? implode(' | ',array($baseRow['tx_realurl_pathsegment'], $baseRow['alias'], $baseRow['nav_title'], $baseRow['title'])) : '';
  302. $tCells[]='<td nowrap="nowrap">'.htmlspecialchars($sources).'</td>';
  303. // Show page path:
  304. if (strcmp($searchPath,'') && t3lib_div::isFirstPartOfStr($inf['pagepath'],$searchPath) && !$inf['expire']) {
  305. // Delete entry:
  306. if ($searchForm_delete) {
  307. $this->deletePathCacheEntry($inf['cache_id']);
  308. $deletedEntry = TRUE;
  309. $pagePath = '[DELETED]';
  310. } elseif ($searchForm_replace) {
  311. $replacePart = trim(t3lib_div::_POST('pathPrefixReplace'));
  312. $this->editPathCacheEntry($inf['cache_id'],
  313. $replacePart.substr($inf['pagepath'],strlen($searchPath)));
  314. $pagePath =
  315. '<span class="typo3-red">'.
  316. htmlspecialchars($replacePart).
  317. '</span>'.
  318. htmlspecialchars(substr($inf['pagepath'],strlen($searchPath)));
  319. } else {
  320. $pagePath =
  321. '<span class="typo3-red">'.
  322. htmlspecialchars(substr($inf['pagepath'],0,strlen($searchPath))).
  323. '</span>'.
  324. htmlspecialchars(substr($inf['pagepath'],strlen($searchPath)));
  325. $this->searchResultCounter++;
  326. }
  327. } else {
  328. // Delete entries:
  329. if ($cmd==='edit' && (!strcmp($entry,$inf['cache_id']) || !strcmp($entry,'ALL'))) {
  330. $pagePath = '<input type="text" name="edit['.$inf['cache_id'].']" value="'.htmlspecialchars($inf['pagepath']).'" size="40" />';
  331. if ($cmd==='edit' && $entry!='ALL') {
  332. $pagePath.= $this->saveCancelButtons();
  333. }
  334. } else {
  335. $pagePath = htmlspecialchars($inf['pagepath']);
  336. }
  337. }
  338. $tCells[]='<td'.($inf['expire'] ? ' style="font-style: italic; color:#999999;"' : '').'>'.$pagePath.'</td>';
  339. if ($deletedEntry) {
  340. $tCells[]='<td>&nbsp;</td>';
  341. } else {
  342. $tCells[]='<td>'.
  343. '<a href="'.$this->linkSelf('&cmd=delete&entry='.$inf['cache_id']).'">'.
  344. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete" alt="" />'.
  345. '</a>'.
  346. '<a href="'.$this->linkSelf('&cmd=edit&entry='.$inf['cache_id']).'">'.
  347. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' title="Edit" alt="" />'.
  348. '</a>'.
  349. '<a href="'.$this->linkSelf('&pathPrefixSearch='.rawurlencode($inf['pagepath'])).'">'.
  350. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/napshot.gif','width="12" height="12"').' title="Use for search" alt="" />'.
  351. '</a>'.
  352. '<a href="'.$this->linkSelf('&cmd=copy&entry='.$inf['cache_id']).'">'.
  353. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/clip_copy.gif','width="12" height="12"').' title="Copy entry" alt="" />'.
  354. '</a>'.
  355. '</td>';
  356. }
  357. $tCells[]='<td'.($inf['expire'] && $inf['expire']<time() ? ' style="color: red;"':'').'>'.
  358. ($inf['expire'] ? htmlspecialchars(t3lib_BEfunc::dateTimeAge($inf['expire'],-1)) : '').
  359. ($inf['expire'] ?
  360. '<a href="'.$this->linkSelf('&cmd=raiseExpire&entry='.$inf['cache_id']).'">'.
  361. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/up.gif','width="14" height="14"').' title="Set expire time to 30 days" alt="" />'.
  362. '</a>' : '').
  363. '</td>';
  364. // Set error msg:
  365. $error = '';
  366. if (!strcmp($inf['pagepath'],'')) {
  367. 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!
  368. $error = $this->pObj->doc->icons(2).'Empty';
  369. }
  370. } elseif (isset($trackSameUrl[$hash])) {
  371. $error = $this->pObj->doc->icons(2).'Already used on page ID '.$trackSameUrl[$hash];
  372. } else {
  373. $error = '&nbsp;';
  374. }
  375. $tCells[]='<td>'.$error.'</td>';
  376. $tCells[]='<td>'.htmlspecialchars($inf['language_id']).'</td>';
  377. $tCells[]='<td>'.htmlspecialchars($inf['mpvar']).'</td>';
  378. $tCells[]='<td>'.htmlspecialchars($inf['rootpage_id']).'</td>';
  379. #$tCells[]='<td nowrap="nowrap">'.htmlspecialchars(t3lib_BEfunc::datetime($inf['expire'])).' / '.htmlspecialchars(t3lib_BEfunc::calcAge($inf['expire']-time())).'</td>';
  380. $trackSameUrl[$hash] = $inf['page_id'];
  381. // Compile Row:
  382. $rowClass = 'bgColor'.($cc%2 ? '-20':'-10');
  383. $output.= '
  384. <tr class="'.$rowClass.'">
  385. '.implode('
  386. ',$tCells).'
  387. </tr>';
  388. $cc++;
  389. }
  390. }
  391. }
  392. // Create header:
  393. $tCells = array();
  394. $tCells[]='<td>Title:</td>';
  395. $tCells[]='<td>ID:</td>';
  396. $tCells[]='<td>&nbsp;</td>';
  397. $tCells[]='<td>PathSegment | Alias | NavTitle | Title:</td>';
  398. $tCells[]='<td>Pagepath:</td>';
  399. $tCells[]='<td>'.
  400. '<a href="'.$this->linkSelf('&cmd=delete&entry=ALL').'" onclick="return confirm(\'Are you sure you want to flush all cached page paths?\');">'.
  401. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' alt="" />'.
  402. '</a>'.
  403. '<a href="'.$this->linkSelf('&cmd=edit&entry=ALL').'">'.
  404. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' title="" alt="" />'.
  405. '</a>'.
  406. '</td>';
  407. $tCells[]='<td>Expires:'.
  408. '<a href="'.$this->linkSelf('&cmd=flushExpired').'">'.
  409. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Flush all expired" alt="" />'.
  410. '</a>'.
  411. '</td>';
  412. $tCells[]='<td>Errors:</td>';
  413. $tCells[]='<td>Lang:</td>';
  414. $tCells[]='<td>&MP:</td>';
  415. $tCells[]='<td>RootPage ID:</td>';
  416. #$tCells[]='<td>Expire:</td>';
  417. $output = '
  418. <tr class="bgColor5 tableheader">
  419. '.implode('
  420. ',$tCells).'
  421. </tr>'.$output;
  422. // Compile final table and return:
  423. $output = '
  424. <table border="0" cellspacing="1" cellpadding="0" id="tx-realurl-pathcacheTable" class="lrPadding c-list">'.$output.'
  425. </table>';
  426. if ($cmd==='edit' && $entry=='ALL') {
  427. $output.= $this->saveCancelButtons();
  428. }
  429. return $output;
  430. }
  431. /**
  432. * Fetch path caching information for page.
  433. *
  434. * @param integer Page ID
  435. * @return array Path Cache records
  436. */
  437. function getPathCache($pageId) {
  438. $showLanguage = t3lib_div::_GP('showLanguage');
  439. $cmd = t3lib_div::_GET('cmd');
  440. $entry = t3lib_div::_GET('entry');
  441. $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
  442. '*',
  443. 'tx_realurl_pathcache',
  444. 'page_id='.intval($pageId).
  445. ((string)$showLanguage!=='' ? ' AND language_id='.intval($showLanguage) : ''),
  446. '',
  447. 'language_id,expire'
  448. );
  449. // Traverse result:
  450. $output = array();
  451. while (false != ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
  452. // Delete entries:
  453. if ($cmd==='delete' && (!strcmp($entry,$row['cache_id']) || !strcmp($entry,'ALL'))) {
  454. $this->deletePathCacheEntry($row['cache_id']);
  455. // Raise expire times:
  456. } elseif ($cmd==='raiseExpire' && !strcmp($entry,$row['cache_id'])) {
  457. $this->raiseExpirePathCacheEntry($row);
  458. $output[] = $row;
  459. } elseif ($cmd==='flushExpired' && $row['expire'] && $row['expire']<time()) {
  460. $this->deletePathCacheEntry($row['cache_id']);
  461. } elseif ($cmd==='copy' && (!strcmp($entry,$row['cache_id']))) {
  462. $output[] = $this->copyPathCacheEntry($row);
  463. $output[] = $row;
  464. } else { // ... or add:
  465. $output[] = $row;
  466. }
  467. }
  468. $GLOBALS['TYPO3_DB']->sql_free_result($res);
  469. return $output;
  470. }
  471. /**
  472. * Links to the module script and sets necessary parameters (only for pathcache display)
  473. *
  474. * @param string Additional GET vars
  475. * @return string script + query
  476. */
  477. function linkSelf($addParams) {
  478. return htmlspecialchars('index.php?id='.$this->pObj->id.'&showLanguage='.rawurlencode(t3lib_div::_GP('showLanguage')).$addParams);
  479. }
  480. /**
  481. * Create search form
  482. *
  483. * @return string HTML
  484. */
  485. function renderSearchForm() {
  486. $output = '<fieldset>';
  487. $output .= $this->getLanguageSelector();
  488. $output .= '<div>' . $this->getSearchField() . '</div>';
  489. $output .= $this->getReplaceAndDeleteFields();
  490. $output.= '<input type="hidden" name="id" value="' . $this->pObj->id . '" />';
  491. $output.= '</fieldset>';
  492. return $output;
  493. }
  494. /**
  495. * Obtains fields for replace/delete.
  496. *
  497. * @return string
  498. */
  499. private function getReplaceAndDeleteFields() {
  500. $output = '';
  501. if ($this->searchResultCounter && !t3lib_div::_POST('_replace') && !t3lib_div::_POST('_delete')) {
  502. $output .= '<div><label for="pathPrefixReplace">Replace with:</label> <input type="text" name="pathPrefixReplace" value="'.htmlspecialchars(t3lib_div::_GP('pathPrefixSearch')).'" />';
  503. $output .= '<input type="submit" name="_replace" value="Replace" /> or <input type="submit" name="_delete" value="Delete" /></div>';
  504. $output .= '<div><b>'.sprintf('Found: %d result(s).',$this->searchResultCounter).'</b></div>';
  505. }
  506. return $output;
  507. }
  508. /**
  509. * Enter description here ...
  510. * @param output
  511. */
  512. protected function getSearchField() {
  513. $output = '<label for="pathPrefixSearch">' . $GLOBALS['LANG']->getLL('search_path', true) .
  514. '</label> <input type="text" name="pathPrefixSearch" id="pathPrefixSearch" value="' .
  515. htmlspecialchars(t3lib_div::_GP('pathPrefixSearch')).'" />' .
  516. '<input type="submit" name="_" value="' .
  517. $GLOBALS['LANG']->getLL('look_up', true) . '" />';
  518. return $output;
  519. }
  520. /**
  521. * Generates language selector.
  522. *
  523. * @return string
  524. */
  525. protected function getLanguageSelector() {
  526. $languages = $this->getSystemLanguages();
  527. $options = array();
  528. $showLanguage = t3lib_div::_GP('showLanguage');
  529. foreach ($languages as $language) {
  530. $selected = $showLanguage === $language['uid'] ? ' selected="selected"' : '';
  531. $options[] = '<option value="' . $language['uid'] . '"' . $selected . '>' .
  532. htmlspecialchars($language['title']) . '</option>';
  533. }
  534. return '<div><label for="showLanguage">' . $GLOBALS['LANG']->getLL('language', true) .
  535. '</label> <select name="showLanguage">' . implode('', $options).'</select></div>';
  536. }
  537. /**
  538. * Obtains system languages.
  539. *
  540. * @return array
  541. */
  542. protected function getSystemLanguages() {
  543. $languages = (array)t3lib_BEfunc::getRecordsByField('sys_language','pid',0,'','','title');
  544. $defaultLanguageLabel = $this->getDefaultLanguageName();
  545. array_unshift($languages, array('uid' => 0, 'title' => $defaultLanguageLabel));
  546. array_unshift($languages, array('uid' => '', 'title' => $GLOBALS['LANG']->getLL('all_languages')));
  547. return $languages;
  548. }
  549. /**
  550. * Obtains the name of the default language.
  551. *
  552. * @return string
  553. */
  554. protected function getDefaultLanguageName() {
  555. $tsConfig = t3lib_BEfunc::getPagesTSconfig($this->pObj->id);
  556. if (isset($tsConfig['mod.']['SHARED.']['defaultLanguageLabel'])) {
  557. $label = $tsConfig['mod.']['SHARED.']['defaultLanguageLabel'];
  558. }
  559. else {
  560. $label = $GLOBALS['LANG']->getLL('default_language');
  561. }
  562. return $label;
  563. }
  564. /**
  565. * Deletes an entry in pathcache table
  566. *
  567. * @param integer Path Cache id (cache_id)
  568. * @return void
  569. */
  570. function deletePathCacheEntry($cache_id) {
  571. $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_realurl_pathcache','cache_id='.intval($cache_id));
  572. }
  573. /**
  574. * Deletes an entry in pathcache table
  575. *
  576. * @param integer Path Cache id (cache_id)
  577. * @return void
  578. */
  579. function raiseExpirePathCacheEntry(&$row) {
  580. $row['expire'] = time()+30*24*3600;
  581. $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_realurl_pathcache','expire>0 AND cache_id='.intval($row['cache_id']),array('expire' => $row['expire']));
  582. }
  583. /**
  584. * Copies an entry in pathcache table
  585. *
  586. * @param array Record to copy, passed by reference, will be updated.
  587. * @return array New record.
  588. */
  589. function copyPathCacheEntry(&$oEntry) {
  590. // Select old record:
  591. $cEntry = $oEntry;
  592. unset($cEntry['cache_id']);
  593. $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_realurl_pathcache',$cEntry);
  594. $cEntry['cache_id'] = $GLOBALS['TYPO3_DB']->sql_insert_id();
  595. // Update the old record with expire time:
  596. if (!$oEntry['expire']) {
  597. $oEntry['expire'] = time()+30*24*3600;
  598. $field_values = array(
  599. 'expire' => $oEntry['expire'],
  600. );
  601. $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_realurl_pathcache','cache_id='.intval($oEntry['cache_id']), $field_values);
  602. }
  603. return $cEntry;
  604. }
  605. /**
  606. * Changes the "pagepath" value of an entry in the pathcache table
  607. *
  608. * @param integer Path Cache id (cache_id)
  609. * @param string New value for the pagepath
  610. * @return void
  611. */
  612. function editPathCacheEntry($cache_id,$value) {
  613. $field_values = array(
  614. 'pagepath' => $value
  615. );
  616. $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_realurl_pathcache','cache_id='.intval($cache_id), $field_values);
  617. // Look up the page id so we can clear the encodeCache entries:
  618. list($page_id_rec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('page_id', 'tx_realurl_pathcache','cache_id='.intval($cache_id));
  619. $this->clearDEncodeCache('page_'.$page_id_rec['page_id']); // Encode cache
  620. $this->clearDEncodeCache('page_'.$page_id_rec['page_id'],TRUE); // Decode cache
  621. }
  622. /**
  623. * Will look for submitted pagepath cache entries to save
  624. *
  625. * @return void
  626. */
  627. function edit_save() {
  628. if (t3lib_div::_POST('_edit_save')) {
  629. $editArray = t3lib_div::_POST('edit');
  630. foreach($editArray as $cache_id => $value) {
  631. $this->editPathCacheEntry($cache_id,trim($value));
  632. }
  633. }
  634. }
  635. /**
  636. * Save / Cancel buttons
  637. *
  638. * @param string Extra code.
  639. * @return string Form elements
  640. */
  641. function saveCancelButtons($extra='') {
  642. $output = '<input type="submit" name="_edit_save" value="Save" /> ';
  643. $output .= '<input type="submit" name="_edit_cancel" value="Cancel" />';
  644. $output .= $extra;
  645. return $output;
  646. }
  647. /**************************
  648. *
  649. * Decode view
  650. *
  651. **************************/
  652. /**
  653. * Rendering the decode-cache content
  654. *
  655. * @param array The Page tree data
  656. * @return string HTML for the information table.
  657. */
  658. function decodeView(t3lib_pageTree $tree) {
  659. // Delete entries:
  660. $cmd = t3lib_div::_GP('cmd');
  661. $subcmd = '';
  662. if ($cmd === 'deleteDC') {
  663. $subcmd = t3lib_div::_GP('entry');
  664. $this->clearDEncodeCache($subcmd,TRUE);
  665. }
  666. // Traverse tree:
  667. $output = '';
  668. $cc=0;
  669. $countDisplayed = 0;
  670. foreach($tree->tree as $row) {
  671. // Select rows:
  672. $displayRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*','tx_realurl_urldecodecache','page_id='.intval($row['row']['uid']),'','spurl');
  673. // Row title:
  674. $rowTitle = $row['HTML'].t3lib_BEfunc::getRecordTitle('pages',$row['row'],TRUE);
  675. // Add at least one empty element:
  676. if (!count($displayRows) || $subcmd==='displayed') {
  677. // Add title:
  678. $tCells = array();
  679. $tCells[]='<td nowrap="nowrap">'.$rowTitle.'</td>';
  680. // Empty row:
  681. $tCells[]='<td colspan="6" align="center">&nbsp;</td>';
  682. // Compile Row:
  683. $output.= '
  684. <tr class="bgColor'.($cc%2 ? '-20':'-10').'">
  685. '.implode('
  686. ',$tCells).'
  687. </tr>';
  688. $cc++;
  689. if ($subcmd==='displayed') {
  690. foreach($displayRows as $c => $inf) {
  691. $this->clearDEncodeCache('urlhash_'.$inf['url_hash'],TRUE);
  692. }
  693. }
  694. } else {
  695. foreach($displayRows as $c => $inf) {
  696. // Add icon/title and ID:
  697. $tCells = array();
  698. if (!$c) {
  699. $tCells[]='<td nowrap="nowrap" rowspan="'.count($displayRows).'">'.$rowTitle.'</td>';
  700. $tCells[]='<td nowrap="nowrap" rowspan="'.count($displayRows).'">'.$row['row']['uid'].'</td>';
  701. $tCells[]='<td rowspan="'.count($displayRows).'">'.
  702. '<a href="'.$this->linkSelf('&cmd=deleteDC&entry=page_'.intval($row['row']['uid'])).'">'.
  703. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete entries for page" alt="" />'.
  704. '</a>'.
  705. '</td>';
  706. }
  707. // Path:
  708. $tCells[]='<td>'.htmlspecialchars($inf['spurl']).'</td>';
  709. // Get vars:
  710. $queryValues = unserialize($inf['content']);
  711. $queryParams = '?id='.$queryValues['id'].
  712. (is_array($queryValues['GET_VARS']) ? t3lib_div::implodeArrayForUrl('',$queryValues['GET_VARS']) : '');
  713. $tCells[]='<td>'.htmlspecialchars($queryParams).'</td>';
  714. // Delete:
  715. $tCells[]='<td>'.
  716. '<a href="'.$this->linkSelf('&cmd=deleteDC&entry=urlhash_'.intval($inf['url_hash'])).'">'.
  717. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete entry" alt="" />'.
  718. '</a>'.
  719. '</td>';
  720. // Timestamp:
  721. $tCells[]='<td>'.htmlspecialchars(t3lib_BEfunc::datetime($inf['tstamp'])).' / '.htmlspecialchars(t3lib_BEfunc::calcAge(time()-$inf['tstamp'])).'</td>';
  722. // Compile Row:
  723. $output.= '
  724. <tr class="bgColor'.($cc%2 ? '-20':'-10').'">
  725. '.implode('
  726. ',$tCells).'
  727. </tr>';
  728. $cc++;
  729. $countDisplayed++;
  730. }
  731. }
  732. }
  733. list($count_allInTable) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('count(*) AS count','tx_realurl_urldecodecache','');
  734. // Create header:
  735. $tCells = array();
  736. $tCells[]='<td>Title:</td>';
  737. $tCells[]='<td>ID:</td>';
  738. $tCells[]='<td>&nbsp;</td>';
  739. $tCells[]='<td>Path:</td>';
  740. $tCells[]='<td>GET variables:</td>';
  741. $tCells[]='<td>&nbsp;</td>';
  742. $tCells[]='<td>Timestamp:</td>';
  743. $output = '
  744. <tr class="bgColor5 tableheader">
  745. '.implode('
  746. ',$tCells).'
  747. </tr>'.$output;
  748. // Compile final table and return:
  749. $output = '<br/><br/>
  750. Displayed entries: <b>'.$countDisplayed.'</b> '.
  751. '<a href="'.$this->linkSelf('&cmd=deleteDC&entry=displayed').'">'.
  752. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete displayed entries" alt="" />'.
  753. '</a>'.
  754. '<br/>
  755. Total entries in decode cache: <b>'.$count_allInTable['count'].'</b> '.
  756. '<a href="'.$this->linkSelf('&cmd=deleteDC&entry=all').'">'.
  757. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete WHOLE decode cache!" alt="" />'.
  758. '</a>'.
  759. '<br/>
  760. <table border="0" cellspacing="1" cellpadding="0" id="tx-realurl-pathcacheTable" class="lrPadding c-list">'.$output.'
  761. </table>';
  762. return $output;
  763. }
  764. /**************************
  765. *
  766. * Encode view
  767. *
  768. **************************/
  769. /**
  770. * Rendering the encode-cache content
  771. *
  772. * @param array The Page tree data
  773. * @return string HTML for the information table.
  774. */
  775. function encodeView(t3lib_pageTree $tree) {
  776. // Delete entries:
  777. $cmd = t3lib_div::_GP('cmd');
  778. $subcmd = '';
  779. if ($cmd === 'deleteEC') {
  780. $subcmd = t3lib_div::_GP('entry');
  781. $this->clearDEncodeCache($subcmd);
  782. }
  783. // Traverse tree:
  784. $cc = 0;
  785. $countDisplayed = 0;
  786. $output = '';
  787. $duplicates = array();
  788. foreach($tree->tree as $row) {
  789. // Select rows:
  790. $displayRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*','tx_realurl_urlencodecache','page_id='.intval($row['row']['uid']),'','content');
  791. // Row title:
  792. $rowTitle = $row['HTML'].t3lib_BEfunc::getRecordTitle('pages',$row['row'],TRUE);
  793. // Add at least one empty element:
  794. if (!count($displayRows) || $subcmd==='displayed') {
  795. // Add title:
  796. $tCells = array();
  797. $tCells[]='<td nowrap="nowrap">'.$rowTitle.'</td>';
  798. $tCells[]='<td nowrap="nowrap">&nbsp;</td>';
  799. // Empty row:
  800. $tCells[]='<td colspan="7" align="center">&nbsp;</td>';
  801. // Compile Row:
  802. $output.= '
  803. <tr class="bgColor'.($cc%2 ? '-20':'-10').'">
  804. '.implode('
  805. ',$tCells).'
  806. </tr>';
  807. $cc++;
  808. if ($subcmd==='displayed') {
  809. foreach($displayRows as $c => $inf) {
  810. $this->clearDEncodeCache('urlhash_'.$inf['url_hash']);
  811. }
  812. }
  813. } else {
  814. foreach($displayRows as $c => $inf) {
  815. // Add icon/title and ID:
  816. $tCells = array();
  817. if (!$c) {
  818. $tCells[]='<td nowrap="nowrap" rowspan="'.count($displayRows).'">'.$rowTitle.'</td>';
  819. $tCells[]='<td nowrap="nowrap" rowspan="'.count($displayRows).'">'.$row['row']['uid'].'</td>';
  820. $tCells[]='<td rowspan="'.count($displayRows).'">'.
  821. '<a href="'.$this->linkSelf('&cmd=deleteEC&entry=page_'.intval($row['row']['uid'])).'">'.
  822. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete entries for page" alt="" />'.
  823. '</a>'.
  824. '</td>';
  825. }
  826. // Get vars:
  827. $tCells[]='<td>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($inf['origparams'], 100)).'</td>';
  828. // Internal Extras:
  829. $tCells[]='<td>'.($inf['internalExtras'] ? t3lib_div::arrayToLogString(unserialize($inf['internalExtras'])) : '&nbsp;').'</td>';
  830. // Path:
  831. $tCells[]='<td>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($inf['content'],100)).'</td>';
  832. // Delete:
  833. $tCells[]='<td>'.
  834. '<a href="'.$this->linkSelf('&cmd=deleteEC&entry=urlhash_'.intval($inf['url_hash'])).'">'.
  835. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete entry" alt="" />'.
  836. '</a>'.
  837. '</td>';
  838. // Error:
  839. $eMsg = ($duplicates[$inf['content']] && $duplicates[$inf['content']] !== $row['row']['uid'] ? $this->pObj->doc->icons(2).'Already used on page ID '.$duplicates[$inf['content']].'<br/>' : '');
  840. if (count($GLOBALS['TYPO3_DB']->exec_SELECTgetRows('url_hash','tx_realurl_redirects','url_hash='.intval(t3lib_div::md5int($inf['content']))))) {
  841. $eMsg.= $this->pObj->doc->icons(3).'Also a redirect!';
  842. }
  843. $tCells[]='<td>'.$eMsg.'</td>';
  844. // Timestamp:
  845. $tCells[]='<td>'.htmlspecialchars(t3lib_BEfunc::datetime($inf['tstamp'])).' / '.htmlspecialchars(t3lib_BEfunc::calcAge(time()-$inf['tstamp'])).'</td>';
  846. // Compile Row:
  847. $output.= '
  848. <tr class="bgColor'.($cc%2 ? '-20':'-10').'">
  849. '.implode('
  850. ',$tCells).'
  851. </tr>';
  852. $cc++;
  853. $countDisplayed++;
  854. if (!isset($duplicates[$inf['content']])) {
  855. $duplicates[$inf['content']] = $row['row']['uid'];
  856. }
  857. }
  858. }
  859. }
  860. list($count_allInTable) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('count(*) AS count','tx_realurl_urlencodecache','');
  861. // Create header:
  862. $tCells = array();
  863. $tCells[]='<td>Title:</td>';
  864. $tCells[]='<td>ID:</td>';
  865. $tCells[]='<td>&nbsp;</td>';
  866. $tCells[]='<td>Host | GET variables:</td>';
  867. $tCells[]='<td>Internal Extras:</td>';
  868. $tCells[]='<td>Path:</td>';
  869. $tCells[]='<td>&nbsp;</td>';
  870. $tCells[]='<td>Errors:</td>';
  871. $tCells[]='<td>Timestamp:</td>';
  872. $output = '
  873. <tr class="bgColor5 tableheader">
  874. '.implode('
  875. ',$tCells).'
  876. </tr>'.$output;
  877. // Compile final table and return:
  878. $output = '
  879. <br/>
  880. <br/>
  881. Displayed entries: <b>'.$countDisplayed.'</b> '.
  882. '<a href="'.$this->linkSelf('&cmd=deleteEC&entry=displayed').'">'.
  883. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete displayed entries" alt="" />'.
  884. '</a>'.
  885. '<br/>
  886. Total entries in encode cache: <b>'.$count_allInTable['count'].'</b> '.
  887. '<a href="'.$this->linkSelf('&cmd=deleteEC&entry=all').'">'.
  888. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete WHOLE encode cache!" alt="" />'.
  889. '</a>'.
  890. '<br/>
  891. <table border="0" cellspacing="1" cellpadding="0" id="tx-realurl-pathcacheTable" class="lrPadding c-list">'.$output.'
  892. </table>';
  893. return $output;
  894. }
  895. /**
  896. *
  897. */
  898. function clearDEncodeCache($cmd, $decodeCache=FALSE) {
  899. $table = $decodeCache ? 'tx_realurl_urldecodecache' : 'tx_realurl_urlencodecache';
  900. list($keyword,$id) = explode('_', $cmd);
  901. switch((string)$keyword) {
  902. case 'all':
  903. $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, '');
  904. break;
  905. case 'page':
  906. $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, 'page_id='.intval($id));
  907. break;
  908. case 'urlhash':
  909. $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, 'url_hash='.intval($id));
  910. break;
  911. default:
  912. break;
  913. }
  914. }
  915. /*****************************
  916. *
  917. * Unique Alias
  918. *
  919. *****************************/
  920. /**
  921. * Shows the mapping between aliases and unique IDs of arbitrary tables
  922. *
  923. * @return string HTML
  924. */
  925. function uniqueAlias() {
  926. $tableName = t3lib_div::_GP('table');
  927. $cmd = t3lib_div::_GET('cmd');
  928. $entry = t3lib_div::_GET('entry');
  929. $search = t3lib_div::_POST('search');
  930. // Select rows:
  931. $overviewRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('tablename,count(*) as number_of_rows','tx_realurl_uniqalias','','tablename','','','tablename');
  932. if ($tableName && isset($overviewRows[$tableName])) { // Show listing of single table:
  933. // Some Commands:
  934. if ($cmd==='delete') {
  935. if ($entry==='ALL') {
  936. $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_realurl_uniqalias','tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tableName,'tx_realurl_uniqalias'));
  937. } else {
  938. $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_realurl_uniqalias','tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tableName,'tx_realurl_uniqalias').' AND uid='.intval($entry));
  939. }
  940. }
  941. if ($cmd==='flushExpired') {
  942. $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_realurl_uniqalias','tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tableName,'tx_realurl_uniqalias').' AND expire>0 AND expire<'.intval(time()));
  943. }
  944. // Select rows:
  945. $tableContent = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
  946. '*',
  947. 'tx_realurl_uniqalias',
  948. 'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($tableName,'tx_realurl_uniqalias').
  949. ($search ? ' AND (value_id='.$GLOBALS['TYPO3_DB']->fullQuoteStr($search,$tableName).' OR value_alias LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($search,$tableName).'%\')':''),
  950. '',
  951. 'value_id, lang, expire'
  952. );
  953. $cc = 0; $field_id = $field_alias = $output = '';
  954. $duplicates = array();
  955. foreach($tableContent as $aliasRecord) {
  956. // Add data:
  957. $tCells = array();
  958. $tCells[]='<td>'.htmlspecialchars($aliasRecord['value_id']).'</td>';
  959. if ((string)$cmd==='edit' && ($entry==='ALL' || !strcmp($entry,$aliasRecord['uid']))) {
  960. $tCells[]='<td>'.
  961. '<input type="text" name="edit['.$aliasRecord['uid'].']" value="'.htmlspecialchars($aliasRecord['value_alias']).'" />'.
  962. ($entry!=='ALL' ? $this->saveCancelButtons('') : '').
  963. '</td>';
  964. } else {
  965. $tCells[]='<td'.($aliasRecord['expire'] ? ' style="font-style: italic; color:#999999;"' : '').'>'.htmlspecialchars($aliasRecord['value_alias']).'</td>';
  966. }
  967. $tCells[]='<td>'.htmlspecialchars($aliasRecord['lang']).'</td>';
  968. $tCells[]='<td'.($aliasRecord['expire'] && $aliasRecord['expire']<time() ? ' style="color: red;"':'').'>'.htmlspecialchars(t3lib_BEfunc::dateTimeAge($aliasRecord['expire'])).'</td>';
  969. $tCells[]='<td>'.
  970. // Edit link:
  971. '<a href="'.$this->linkSelf('&table='.rawurlencode($tableName).'&cmd=edit&entry='.$aliasRecord['uid']).'">'.
  972. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' title="" alt="" />'.
  973. '</a>'.
  974. // Delete link:
  975. '<a href="'.$this->linkSelf('&table='.rawurlencode($tableName).'&cmd=delete&entry='.$aliasRecord['uid']).'">'.
  976. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="" alt="" />'.
  977. '</a>'.
  978. '</td>';
  979. $tCells[]='<td>'.
  980. (isset($duplicates[$aliasRecord['value_alias']]) ? $this->pObj->doc->icons(2).'Already used by ID '.$duplicates[$aliasRecord['value_alias']] :'&nbsp;').
  981. '</td>';
  982. $field_id = $aliasRecord['field_id'];
  983. $field_alias = $aliasRecord['field_alias'];
  984. // Compile Row:
  985. $output .= '
  986. <tr class="bgColor'.($cc%2 ? '-20':'-10').'">
  987. '.implode('
  988. ',$tCells).'
  989. </tr>';
  990. $cc++;
  991. $duplicates[$aliasRecord['value_alias']] = $aliasRecord['value_id'];
  992. }
  993. // Create header:
  994. $tCells = array();
  995. $tCells[]='<td>ID (Field: '.$field_id.')</td>';
  996. $tCells[]='<td>Alias (Field: '.$field_alias.'):</td>';
  997. $tCells[]='<td>Lang:</td>';
  998. $tCells[]='<td>Expire:'.
  999. (!$search ? '<a href="'.$this->linkSelf('&table='.rawurlencode($tableName).'&cmd=flushExpired').'">'.
  1000. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Flush expired" alt="" />'.
  1001. '</a>' : '').
  1002. '</td>';
  1003. $tCells[]='<td>'.
  1004. (!$search ? '<a href="'.$this->linkSelf('&table='.rawurlencode($tableName).'&cmd=edit&entry=ALL').'">'.
  1005. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' title="Edit all" alt="" />'.
  1006. '</a>'.
  1007. '<a href="'.$this->linkSelf('&table='.rawurlencode($tableName).'&cmd=delete&entry=ALL').'" onclick="return confirm(\'Delete all?\');">'.
  1008. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete all" alt="" />'.
  1009. '</a>' : '').
  1010. '</td>';
  1011. $tCells[]='<td>Error:</td>';
  1012. $output = '
  1013. <tr class="bgColor5 tableheader">
  1014. '.implode('
  1015. ',$tCells).'
  1016. </tr>'.$output;
  1017. // Compile final table and return:
  1018. $output = '
  1019. <br/>
  1020. Table: <b>'.htmlspecialchars($tableName).'</b><br/>
  1021. Aliases: <b>'.htmlspecialchars(count($tableContent)).'</b><br/>
  1022. Search: <input type="text" name="search" value="'.htmlspecialchars($search).'" /><input type="submit" name="_" value="Search" />
  1023. <input type="hidden" name="table" value="'.htmlspecialchars($tableName).'" />
  1024. <input type="hidden" name="id" value="'.htmlspecialchars($this->pObj->id).'" />
  1025. <br/><br/>
  1026. <table border="0" cellspacing="1" cellpadding="0" id="tx-realurl-pathcacheTable" class="lrPadding c-list">'.$output.'
  1027. </table>';
  1028. if ($entry==='ALL') {
  1029. $output.= $this->saveCancelButtons('<input type="hidden" name="table" value="'.htmlspecialchars($tableName).'" /><input type="hidden" name="id" value="'.htmlspecialchars($this->pObj->id).'" />');
  1030. }
  1031. } else { // Create overview:
  1032. $cc=0;
  1033. $output='';
  1034. if (count($overviewRows)) {
  1035. foreach($overviewRows as $aliasRecord) {
  1036. // Add data:
  1037. $tCells = array();
  1038. $tCells[]='<td><a href="'.$this->linkSelf('&table='.rawurlencode($aliasRecord['tablename'])).'">'.$aliasRecord['tablename'].'</a></td>';
  1039. $tCells[]='<td>'.$aliasRecord['number_of_rows'].'</td>';
  1040. // Compile Row:
  1041. $output.= '
  1042. <tr class="bgColor'.($cc%2 ? '-20':'-10').'">
  1043. '.implode('
  1044. ',$tCells).'
  1045. </tr>';
  1046. $cc++;
  1047. }
  1048. // Create header:
  1049. $tCells = array();
  1050. $tCells[]='<td>Table:</td>';
  1051. $tCells[]='<td>Aliases:</td>';
  1052. $output = '
  1053. <tr class="bgColor5 tableheader">
  1054. '.implode('
  1055. ',$tCells).'
  1056. </tr>'.$output;
  1057. // Compile final table and return:
  1058. $output = '
  1059. <table border="0" cellspacing="1" cellpadding="0" id="tx-realurl-pathcacheTable" class="lrPadding c-list">'.$output.'
  1060. </table>';
  1061. }
  1062. }
  1063. return $output;
  1064. }
  1065. /**
  1066. * Changes the "alias" value of an entry in the unique alias table
  1067. *
  1068. * @param integer UID of unique alias
  1069. * @param string New value for the alias
  1070. * @return void
  1071. */
  1072. function editUniqAliasEntry($cache_id,$value) {
  1073. $field_values = array(
  1074. 'value_alias' => $value
  1075. );
  1076. $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_realurl_uniqalias','uid='.intval($cache_id), $field_values);
  1077. }
  1078. /**
  1079. * Will look for submitted unique alias entries to save
  1080. *
  1081. * @return void
  1082. */
  1083. function edit_save_uniqAlias() {
  1084. if (t3lib_div::_POST('_edit_save')) {
  1085. $editArray = t3lib_div::_POST('edit');
  1086. foreach($editArray as $cache_id => $value) {
  1087. $this->editUniqAliasEntry($cache_id,trim($value));
  1088. }
  1089. }
  1090. }
  1091. /*****************************
  1092. *
  1093. * Configuration view:
  1094. *
  1095. *****************************/
  1096. /**
  1097. * Shows configuration of the extension.
  1098. *
  1099. * @return string HTML
  1100. */
  1101. function configView() {
  1102. global $TYPO3_CONF_VARS;
  1103. // Include array browser:
  1104. require_once(PATH_t3lib . 'class.t3lib_arraybrowser.php');
  1105. // Initialize array browser:
  1106. $arrayBrowser = t3lib_div::makeInstance('t3lib_arrayBrowser');
  1107. /** @var t3lib_arrayBrowser $arrayBrowser */
  1108. $arrayBrowser->expAll = TRUE;
  1109. $arrayBrowser->fixedLgd = FALSE;
  1110. $arrayBrowser->dontLinkVar = TRUE;
  1111. // Create the display code:
  1112. $theVar = $TYPO3_CONF_VARS['EXTCONF']['realurl'];
  1113. $tree = $arrayBrowser->tree($theVar, '', '');
  1114. $tree = '<hr/>
  1115. <b>$TYPO3_CONF_VARS[\'EXTCONF\'][\'realurl\']</b>
  1116. <br/>
  1117. <span class="nobr">'.$tree.'</span>';
  1118. return $tree;
  1119. }
  1120. /*****************************
  1121. *
  1122. * Log view:
  1123. *
  1124. *****************************/
  1125. /**
  1126. * View error log
  1127. *
  1128. * @return string HTML
  1129. */
  1130. function logView() {
  1131. $cmd = t3lib_div::_GP('cmd');
  1132. if ($cmd==='deleteAll') {
  1133. $GLOBALS['TYPO3_DB']->exec_DELETEquery(
  1134. 'tx_realurl_errorlog',
  1135. ''
  1136. );
  1137. }
  1138. $list = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
  1139. '*',
  1140. 'tx_realurl_errorlog',
  1141. '',
  1142. '',
  1143. 'counter DESC, tstamp DESC',
  1144. 100
  1145. );
  1146. if (is_array($list)) {
  1147. $output=''; $cc = 0;
  1148. foreach($list as $rec) {
  1149. $host = '';
  1150. if ($rec['rootpage_id'] != 0) {
  1151. if (isset($hostCacheName[$rec['rootpage_id']])) {
  1152. $host = $hostCacheName[$rec['rootpage_id']];
  1153. }
  1154. else {
  1155. $hostCacheName[$rec['rootpage_id']] = $host = $this->getHostName($rec['rootpage_id']);
  1156. }
  1157. }
  1158. // Add data:
  1159. $tCells = array();
  1160. $tCells[]='<td>'.$rec['counter'].'</td>';
  1161. $tCells[]='<td>'.t3lib_BEfunc::dateTimeAge($rec['tstamp']).'</td>';
  1162. $tCells[]='<td><a href="'.htmlspecialchars($host.'/'.$rec['url']).'" target="_blank">'.($host ? $host . '/' : '') . htmlspecialchars($rec['url']).'</a>'.
  1163. ' <a href="'.$this->linkSelf('&cmd=new&data[0][source]='.rawurlencode($rec['url']).'&SET[type]=redirects').'">'.
  1164. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/napshot.gif','width="12" height="12"').' title="Set as redirect" alt="" />'.
  1165. '</a>'.
  1166. '</td>';
  1167. $tCells[]='<td>'.htmlspecialchars($rec['error']).'</td>';
  1168. $tCells[]='<td>'.
  1169. ($rec['last_referer'] ? '<a href="'.htmlspecialchars($rec['last_referer']).'" target="_blank">'.htmlspecialchars($rec['last_referer']).'</a>' : '&nbsp;').
  1170. '</td>';
  1171. $tCells[]='<td>'.t3lib_BEfunc::datetime($rec['cr_date']).'</td>';
  1172. // Compile Row:
  1173. $output.= '
  1174. <tr class="bgColor'.($cc%2 ? '-20':'-10').'">
  1175. '.implode('
  1176. ',$tCells).'
  1177. </tr>';
  1178. $cc++;
  1179. }
  1180. // Create header:
  1181. $tCells = array();
  1182. $tCells[]='<td>Counter:</td>';
  1183. $tCells[]='<td>Last time:</td>';
  1184. $tCells[]='<td>URL:</td>';
  1185. $tCells[]='<td>Error:</td>';
  1186. $tCells[]='<td>Last Referer:</td>';
  1187. $tCells[]='<td>First time:</td>';
  1188. $output = '
  1189. <tr class="bgColor5 tableheader">
  1190. '.implode('
  1191. ',$tCells).'
  1192. </tr>'.$output;
  1193. // Compile final table and return:
  1194. $output = '
  1195. <br/>
  1196. <a href="'.$this->linkSelf('&cmd=deleteAll').'">'.
  1197. '<img'.t3lib_iconWorks::skinImg($this->pObj->doc->backPath,'gfx/garbage.gif','width="11" height="12"').' title="Delete All" alt="" />'.
  1198. ' Flush log</a>
  1199. <br/>
  1200. <table border="0" cellspacing="1" cellpadding="0" id="tx-realurl-pathcacheTable" class="lrPadding c-list">'.$output.'
  1201. </table>';
  1202. return $output;
  1203. }
  1204. }
  1205. function getHostName($rootpage_id) {
  1206. foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] as $host => $config) {
  1207. if ($host != '_DEFAULT') {
  1208. $hostName = $host;
  1209. while ($config !== false && !is_array($config)) {
  1210. $host = $config;
  1211. $config = (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$host]) ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$host] : false);
  1212. }
  1213. if (is_array($config) && isset($config['pagePath']) && isset($config['pagePath']['rootpage_id']) && $config['pagePath']['rootpage_id'] == $rootpage_id) {
  1214. return 'http://' . $hostName;
  1215. }
  1216. }
  1217. }
  1218. return '';
  1219. }
  1220. /*****************************
  1221. *
  1222. * Redirect view:
  1223. *
  1224. *****************************/
  1225. /**
  1226. * Redirect view
  1227. *
  1228. * @return string HTML
  1229. */
  1230. function redirectView() {
  1231. $output = $this->pObj->doc->spacer(12);
  1232. $output .= $this->processRedirectActions();
  1233. list($sortingParameter, $sortingDirection) = $this->getRedirectViewSortingParameters();
  1234. $output .= $this->getRedirectsSearch();
  1235. $output .= $this->getRedirectViewHeader($sortingDirection);
  1236. $output .= $this->getRedirectsTableContent($sortingParameter, $sortingDirection);
  1237. return $output;
  1238. }
  1239. protected function getRedirectsSearch() {
  1240. $result = $this->getSearchField();
  1241. if (t3lib_div::_GP('pathPrefixSearch')) {
  1242. $result .= ' <input type="reset" name="_" value="' .
  1243. $GLOBALS['LANG']->getLL('show_all', true) . '" ' .
  1244. 'onclick="document.getElementById(\'pathPrefixSearch\').value=\'\';document.forms[0].submit()" ' .
  1245. '/>';
  1246. }
  1247. $result .= '<input type="hidden" name="id" value="' . $this->pObj->id . '" />';
  1248. return $result;
  1249. }
  1250. /**
  1251. * Creates a list of redirect entries.
  1252. *
  1253. * @param string $sortingParameter
  1254. * @param string $sortingDirection
  1255. * @return string
  1256. */
  1257. protected function getRedirectsTableContent($sortingParameter, $sortingDirection) {
  1258. $itemCounter = 0;
  1259. $page = max(1, intval(t3lib_div:

Large files files are truncated, but you can click here to view the full file