2 /***************************************************************
5 * (c) 2008 Benjamin Mack <mack@xnos.org>
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 require_once(PATH_typo3
. 'interfaces/interface.backend_toolbaritem.php');
30 // load the language file
31 $GLOBALS['LANG']->includeLLFile('EXT:opendocs/locallang_opendocs.xml');
35 * Adding a list of all open documents of a user to the backend.php
37 * @author Benjamin Mack <benni@typo3.org>
38 * @author Ingo Renner <ingo@typo3.org>
40 * @subpackage opendocs
42 class tx_opendocs
implements backend_toolbarItem
{
45 * reference back to the backend object
49 protected $backendReference;
52 protected $recentDocs;
53 protected $EXTKEY = 'opendocs';
57 * constructor, loads the documents from the user control
59 * @param TYPO3backend TYPO3 backend object reference
61 public function __construct(TYPO3backend
&$backendReference = null) {
62 $this->backendReference
= $backendReference;
63 $this->loadDocsFromUserSession();
67 * checks whether the user has access to this toolbar item
69 * @return boolean true if user has access, false if not
71 public function checkAccess() {
72 $conf = $GLOBALS['BE_USER']->getTSConfig('backendToolbarItem.tx_opendocs.disabled');
73 return ($conf['value'] == 1 ?
false : true);
77 * loads the opened and recently opened documents from the user
81 public function loadDocsFromUserSession() {
82 list($this->openDocs
, ) = $GLOBALS['BE_USER']->getModuleData('alt_doc.php', 'ses');
83 $this->recentDocs
= $GLOBALS['BE_USER']->getModuleData('opendocs::recent');
87 * renders the toolbar item and the initial menu
89 * @return string the toolbar item including the initial menu content as HTML
91 public function render() {
92 $this->addJavascriptToBackend();
93 $this->addCssToBackend();
94 $numDocs = count($this->openDocs
);
95 $opendocsMenu = array();
96 $title = $GLOBALS['LANG']->getLL('toolbaritem', true);
99 $opendocsMenu[] = '<a href="#" class="toolbar-item">';
100 $opendocsMenu[] = '<input type="text" id="tx-opendocs-counter" disabled="disabled" value="' . $numDocs . '" />';
101 $opendocsMenu[] = '<img' . t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'], t3lib_extMgm
::extRelPath($this->EXTKEY
) . 'opendocs.png', 'width="23" height="16"') . ' alt="' . $title . '" title="' . $title . '" /></a>';
103 // toolbar item menu and initial content
104 $opendocsMenu[] = '<div class="toolbar-item-menu" style="display: none;">';
105 $opendocsMenu[] = $this->renderMenu();
106 $opendocsMenu[] = '</div>';
108 return implode("\n", $opendocsMenu);
112 * renders the pure contents of the menu
114 * @return string the menu's content
116 public function renderMenu() {
117 $openDocuments = $this->openDocs
;
118 $recentDocuments = $this->recentDocs
;
122 if (count($openDocuments)) {
123 $entries[] = '<tr><th colspan="3">' . $GLOBALS['LANG']->getLL('open_docs', true) . '</th></tr>';
126 foreach ($openDocuments as $md5sum => $openDocument) {
128 $entries[] = $this->renderMenuEntry($openDocument, $md5sum, false, ($i == 1));
132 // if there are "recent documents" in the list, add them
133 if (count($recentDocuments)) {
134 $entries[] = '<tr><th colspan="3">' . $GLOBALS['LANG']->getLL('recent_docs', true) . '</th></tr>';
137 foreach ($recentDocuments as $md5sum => $recentDocument) {
139 $entries[] = $this->renderMenuEntry($recentDocument, $md5sum, true, ($i == 1));
143 if (count($entries)) {
144 $content = '<table class="list" cellspacing="0" cellpadding="0" border="0">' . implode('', $entries) . '</table>';
146 $content = '<div class="no-docs">' . $GLOBALS['LANG']->getLL('no_docs', true) . '</div>';
153 * returns the recent documents list as an array
155 * @return array all recent documents as list-items
157 public function renderMenuEntry($document, $md5sum, $isRecentDoc = false, $isFirstDoc = false) {
158 $table = $document[3]['table'];
159 $uid = $document[3]['uid'];
160 $record = t3lib_BEfunc
::getRecordWSOL($table, $uid);
161 $label = htmlspecialchars(strip_tags(t3lib_div
::htmlspecialchars_decode($document[0])));
162 $icon = t3lib_iconWorks
::getIconImage($table, $record, $GLOBALS['BACK_PATH']);
163 $link = $GLOBALS['BACK_PATH'] . 'alt_doc.php?' . $document[2];
167 $firstRow = ' first-row';
171 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:rm.closeDoc', true);
174 $closeIcon = '<img' . t3lib_iconWorks
::skinImg($GLOBALS['BACK_PATH'], 'gfx/closedok.gif', 'width="16" height="16"') . ' title="' . $title . '" alt="' . $title . '" />';
177 <tr id="opendocs-' . $table . '-' . $uid . '" class="opendoc' . $firstRow . '">
178 <td class="icon">' . $icon . '</td>
179 <td class="label"><a href="' . $link . '" target="content" onclick="TYPO3BackendOpenDocs.toggleMenu();">' . $label . '</a></td>
180 <td class="close" onclick="return TYPO3BackendOpenDocs.closeDocument(\'' . $md5sum . '\');">' . $closeIcon . '</td>
183 // recently used document
185 <tr id="opendocs-' . $table . '-' . $uid . '" class="recentdoc' . $firstRow . '">
186 <td class="icon">' . $icon . '</td>
187 <td class="label" colspan="2"><a href="' . $link . '" target="content" onclick="TYPO3BackendOpenDocs.toggleMenu();">' . $label . '</a></td>
195 * returns additional attributes for the list item in the toolbar
197 * @return string list item HTML attibutes
199 public function getAdditionalAttributes() {
200 return ' id="tx-opendocs-menu"';
204 * adds the neccessary javascript to the backend
208 protected function addJavascriptToBackend() {
209 $this->backendReference
->addJavascriptFile(t3lib_extMgm
::extRelPath($this->EXTKEY
) . 'opendocs.js');
213 * adds the neccessary CSS to the backend
217 protected function addCssToBackend() {
218 $this->backendReference
->addCssFile('opendocs', t3lib_extMgm
::extRelPath($this->EXTKEY
) . 'opendocs.css');
227 * called as a hook in t3lib_BEfunc::setUpdateSignal, calls a JS function to change
228 * the number of opened documents
230 * @param array $params
231 * @param unknown_type $ref
232 * @return string list item HTML attibutes
234 public function updateNumberOfOpenDocsHook(&$params, &$ref) {
235 $params['JScode'] = '
236 if (top && top.TYPO3BackendOpenDocs) {
237 top.TYPO3BackendOpenDocs.updateNumberOfDocs(' . count($this->openDocs
) . ', true);
248 * closes a document in the session and
250 * @param array array of parameters from the AJAX interface, currently unused
251 * @param TYPO3AJAX object of type TYPO3AJAX
252 * @return string list item HTML attibutes
254 public function closeDocument($params = array(), TYPO3AJAX
&$ajaxObj = null) {
255 $md5sum = t3lib_div
::_GP('md5sum');
257 if ($md5sum && isset($this->openDocs
[$md5sum])) {
259 // add the document to be closed to the recent documents
260 $this->recentDocs
= array_merge(
261 array($md5sum => $this->openDocs
[$md5sum]),
265 // allow a maximum of 8 recent documents
266 if (count($this->recentDocs
) > 8) {
267 $this->recentDocs
= array_slice($this->recentDocs
, 0, 8);
270 // remove it from the list of the open documents, and store the status
271 unset($this->openDocs
[$md5sum]);
272 list(, $docDat) = $GLOBALS['BE_USER']->getModuleData('alt_doc.php', 'ses');
273 $GLOBALS['BE_USER']->pushModuleData('alt_doc.php', array($this->openDocs
, $docDat));
274 $GLOBALS['BE_USER']->pushModuleData('opendocs::recent', $this->recentDocs
);
277 $this->renderAjax($params, $ajaxObj);
281 * renders the menu so that it can be returned as response to an AJAX call
283 * @param array array of parameters from the AJAX interface, currently unused
284 * @param TYPO3AJAX object of type TYPO3AJAX
287 public function renderAjax($params = array(), TYPO3AJAX
&$ajaxObj = null) {
288 $menuContent = $this->renderMenu();
290 $ajaxObj->addContent('opendocsMenu', $menuContent);
296 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/opendocs/class.tx_opendocs.php']) {
297 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/opendocs/class.tx_opendocs.php']);