Fixed bug #17167: Cache ExtDirect::getAPI calls
[Packages/TYPO3.CMS.git] / typo3 / classes / class.livesearch.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Michael Klapper <michael.klapper@aoemedia.de>
6 * (c) 2010-2011 Jeff Segars <jeff@webempoweredchurch.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 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28
29 /**
30 * Adds backend live search. to the toolbar
31 *
32 * @author Michael Klapper <michael.klapper@aoemedia.de>
33 * @author Jeff Segars <jeff@webempoweredchurch.org>
34 * @package TYPO3
35 * @subpackage t3lib
36 */
37 class LiveSearch implements backend_toolbarItem {
38
39 /**
40 * reference back to the backend object
41 *
42 * @var TYPO3backend
43 */
44 protected $backendReference;
45
46 /**
47 * constructor
48 *
49 * @param TYPO3backend TYPO3 backend object reference
50 */
51 public function __construct(TYPO3backend &$backendReference = null) {
52 $this->backendReference = $backendReference;
53 }
54
55 /**
56 * checks whether the user has access to this toolbar item
57 *
58 * @return boolean true if user has access, false if not
59 */
60 public function checkAccess() {
61 // LiveSearch module is enabled for everybody
62 return true;
63 }
64
65 /**
66 * Creates the selector for workspaces
67 *
68 * @return string workspace selector as HTML select
69 */
70 public function render() {
71 $this->addJavascriptToBackend();
72 return '<div class="live-search-wrapper">
73 <span title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:search') .'" class="t3-icon t3-icon-apps t3-icon-apps-toolbar t3-icon-toolbar-menu-search">&nbsp;</span>
74 <input id="live-search-box" />
75 </div>';
76 }
77
78 /**
79 * adds the necessary JavaScript to the backend
80 *
81 * @return void
82 */
83 protected function addJavascriptToBackend() {
84 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
85 $pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.LiveSearchActions&' . TYPO3_version, 'text/javascript', $compress = FALSE);
86
87 $this->backendReference->addJavascriptFile('js/livesearch.js');
88 }
89
90 /**
91 * returns additional attributes for the list item in the toolbar
92 *
93 * @return string list item HTML attibutes
94 */
95 public function getAdditionalAttributes() {
96 return ' id="live-search-menu"';
97 }
98
99 }
100
101 ?>