modified the interface for toolbarItems so that the reference to the backend Object...
[Packages/TYPO3.CMS.git] / typo3 / sysext / opendocs / class.tx_opendocs.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 Benjamin Mack <mack@xnos.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 // load the language file
29 $GLOBALS['LANG']->includeLLFile('EXT:opendocs/locallang_opendocs.xml');
30
31 require_once(PATH_typo3.'interfaces/interface.backend_toolbaritem.php');
32
33
34 /**
35 * Adding a list of all open documents of a user to the backend.php
36 *
37 * @author Benjamin Mack <mack@xnos.org>
38 * @package TYPO3
39 * @subpackage opendocs
40 */
41 class tx_opendocs implements backend_toolbarItem {
42
43 /**
44 * reference back to the backend object
45 *
46 * @var TYPO3backend
47 */
48 private $backendReference;
49 private $openDocs;
50 private $recentDocs;
51 private $EXTKEY = 'opendocs';
52
53
54 /**
55 * constructor, loads the documents from the user control
56 *
57 * @param TYPO3backend TYPO3 backend object reference
58 */
59 public function __construct(TYPO3backend &$backendReference = null) {
60 $this->backendReference = $backendReference;
61
62 list($this->openDocs,) = $GLOBALS['BE_USER']->getModuleData('alt_doc.php','ses');
63 $this->recentDocs = $GLOBALS['BE_USER']->getModuleData('opendocs::recent');
64 }
65
66 /**
67 * checks whether the user has access to this toolbar item
68 *
69 * @return boolean true if user has access, false if not
70 */
71 public function checkAccess() {
72 // FIXME - needs proper access check
73 return true;
74 }
75
76 /**
77 * renders the toolbar item and the empty menu
78 *
79 * @return void
80 */
81 public function render() {
82 $this->addJavascriptToBackend();
83 $this->addCssToBackend();
84
85 // return the toolbar item and an empty UL
86 $output = '<a href="#" class="toolbar-item">';
87 $output .= '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], t3lib_extMgm::extRelPath($this->EXTKEY).'opendocs.png', 'width="23" height="14"').' title="'.$GLOBALS['LANG']->getLL('toolbaritem',1).'" alt="" />';
88 $output .= '</a>';
89 $output .= '<ul class="toolbar-item-menu" style="display: none;"></ul>';
90
91 return $output;
92 }
93
94
95 /**
96 * returns the opened documents list as an array
97 *
98 * @return array all open documents as list-items
99 */
100 public function getOpenDocuments() {
101 $docs = array();
102
103 // Traverse the list of open documents:
104 if (is_array($this->openDocs)) {
105 foreach($this->openDocs as $md5k => $lnk) {
106 $docs[] = '<li><a target="content" href="'.htmlspecialchars('alt_doc.php?'.$lnk[2]).'">'.htmlspecialchars(strip_tags(t3lib_div::htmlspecialchars_decode($lnk[0]))).'</a></li>';
107 }
108 }
109 return $docs;
110 }
111
112
113 /**
114 * returns the recent documents list as an array
115 *
116 * @return array all recent documents as list-items
117 */
118 public function getRecentDocuments() {
119 $docs = array();
120
121 if (is_array($this->recentDocs)) {
122 $docs[] = '<li class="menu-item-div">'.$GLOBALS['LANG']->getLL('recent_docs',1).'</li>';
123
124 // Traverse the list of open documents:
125 foreach($this->recentDocs as $md5k => $lnk) {
126 $docs[] = '<li><a target="content" href="'.htmlspecialchars('alt_doc.php?'.$lnk[2]).'">'.htmlspecialchars(strip_tags(t3lib_div::htmlspecialchars_decode($lnk[0]))).'</a></li>';
127 }
128 }
129 return $docs;
130 }
131
132
133
134 /**
135 * returns additional attributes for the list item in the toolbar
136 *
137 * @return string list item HTML attibutes
138 */
139 public function getAdditionalAttributes() {
140 return ' id="open-documents-menu"';
141 }
142
143
144 /**
145 * adds the neccessary javascript to the backend
146 *
147 * @return void
148 */
149 private function addJavascriptToBackend() {
150 $this->backendReference->addJavascriptFile(t3lib_extMgm::extRelPath($this->EXTKEY).'opendocs.js');
151 }
152
153
154 /**
155 * adds the neccessary CSS to the backend
156 *
157 * @return void
158 */
159 private function addCssToBackend() {
160 $this->backendReference->addCssFile('opendocs', t3lib_extMgm::extRelPath($this->EXTKEY).'opendocs.css');
161 }
162
163
164
165
166 /**
167 * returns the opened documents list for the AJAX call formatted as HTML list
168 *
169 * @return string list item HTML attibutes
170 */
171 public function renderBackendMenuContents($params, &$ajaxObj) {
172 $itms = $this->getOpenDocuments();
173 $itmsRecent = $this->getRecentDocuments();
174
175
176 // if there are "recent documents" in the list, add them
177 if (count($itmsRecent)) {
178 $itms = array_merge($itms, $itmsRecent);
179 }
180
181
182 if (count($itms)) {
183 $ajaxObj->addContent('opendocs', implode('', $itms));
184 } else {
185 $ajaxObj->addContent('opendocs', '<li>'.$GLOBALS['LANG']->getLL('no_docs',1).'</li>');
186 }
187 }
188 }
189
190 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['EXT:opendocs/class.tx_opendocs.php']) {
191 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['EXT:opendocs/class.tx_opendocs.php']);
192 }
193 ?>