TYPO3 CMS  TYPO3_6-2
OpendocsController.php
Go to the documentation of this file.
1 <?php
3 
24 
30  protected $backendReference;
31 
32  protected $openDocs;
33 
34  protected $recentDocs;
35 
36  protected $EXTKEY = 'opendocs';
37 
43  public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
44  $GLOBALS['LANG']->includeLLFile('EXT:opendocs/locallang_opendocs.xlf');
45  $this->backendReference = $backendReference;
46  $this->loadDocsFromUserSession();
47  }
48 
54  public function checkAccess() {
55  $conf = $GLOBALS['BE_USER']->getTSConfig('backendToolbarItem.tx_opendocs.disabled');
56  return $conf['value'] != 1;
57  }
58 
64  public function loadDocsFromUserSession() {
65  list($this->openDocs, ) = $GLOBALS['BE_USER']->getModuleData('alt_doc.php', 'ses');
66  $this->recentDocs = $GLOBALS['BE_USER']->getModuleData('opendocs::recent');
67  }
68 
74  public function render() {
75  $this->addJavascriptToBackend();
76  $this->addCssToBackend();
77  $numDocs = count($this->openDocs);
78  $opendocsMenu = array();
79  $title = $GLOBALS['LANG']->getLL('toolbaritem', TRUE);
80 
81  // Toolbar item icon
82  $opendocsMenu[] = '<a href="#" class="toolbar-item">';
83  $opendocsMenu[] = '<input type="text" id="tx-opendocs-counter" disabled="disabled" value="' . $numDocs . '" />';
84  $opendocsMenu[] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-toolbar-menu-opendocs', array('title' => $title)) . '</a>';
85 
86  // Toolbar item menu and initial content
87  $opendocsMenu[] = '<div class="toolbar-item-menu" style="display: none;">';
88  $opendocsMenu[] = $this->renderMenu();
89  $opendocsMenu[] = '</div>';
90  return implode(LF, $opendocsMenu);
91  }
92 
98  public function renderMenu() {
99  $openDocuments = $this->openDocs;
100  $recentDocuments = $this->recentDocs;
101  $entries = array();
102  $content = '';
103  if (count($openDocuments)) {
104  $entries[] = '<tr><th colspan="3">' . $GLOBALS['LANG']->getLL('open_docs', TRUE) . '</th></tr>';
105  $i = 0;
106  foreach ($openDocuments as $md5sum => $openDocument) {
107  $i++;
108  $entries[] = $this->renderMenuEntry($openDocument, $md5sum, FALSE, $i == 1);
109  }
110  }
111  // If there are "recent documents" in the list, add them
112  if (count($recentDocuments)) {
113  $entries[] = '<tr><th colspan="3">' . $GLOBALS['LANG']->getLL('recent_docs', TRUE) . '</th></tr>';
114  $i = 0;
115  foreach ($recentDocuments as $md5sum => $recentDocument) {
116  $i++;
117  $entries[] = $this->renderMenuEntry($recentDocument, $md5sum, TRUE, $i == 1);
118  }
119  }
120  if (count($entries)) {
121  $content = '<table class="list" cellspacing="0" cellpadding="0" border="0">' . implode('', $entries) . '</table>';
122  } else {
123  $content = '<div class="no-docs">' . $GLOBALS['LANG']->getLL('no_docs', TRUE) . '</div>';
124  }
125  return $content;
126  }
127 
133  public function renderMenuEntry($document, $md5sum, $isRecentDoc = FALSE, $isFirstDoc = FALSE) {
134  $table = $document[3]['table'];
135  $uid = $document[3]['uid'];
137  if (!is_array($record)) {
138  // Record seems to be deleted
139  return '';
140  }
141  $label = htmlspecialchars(strip_tags(htmlspecialchars_decode($document[0])));
143  $link = $GLOBALS['BACK_PATH'] . 'alt_doc.php?' . $document[2];
144  $pageId = (int)$document[3]['uid'];
145  if ($document[3]['table'] !== 'pages') {
146  $pageId = (int)$document[3]['pid'];
147  }
148  $firstRow = '';
149  if ($isFirstDoc) {
150  $firstRow = ' first-row';
151  }
152  if (!$isRecentDoc) {
153  $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE);
154  // Open document
155  $closeIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-close');
156  $entry = '
157  <tr class="opendoc' . $firstRow . '">
158  <td class="icon">' . $icon . '</td>
159  <td class="label"><a href="#" onclick="jump(unescape(\'' . htmlspecialchars($link) . '\'), \'web_list\', \'web\', ' . $pageId . '); TYPO3BackendOpenDocs.toggleMenu(); return false;" target="content">' . $label . '</a></td>
160  <td class="close" onclick="return TYPO3BackendOpenDocs.closeDocument(\'' . $md5sum . '\');">' . $closeIcon . '</td>
161  </tr>';
162  } else {
163  // Recently used document
164  $entry = '
165  <tr class="recentdoc' . $firstRow . '">
166  <td class="icon">' . $icon . '</td>
167  <td class="label" colspan="2"><a href="#" onclick="jump(unescape(\'' . htmlspecialchars($link) . '\'), \'web_list\', \'web\', ' . $pageId . '); TYPO3BackendOpenDocs.toggleMenu(); return false;" target="content">' . $label . '</a></td>
168  </tr>';
169  }
170  return $entry;
171  }
172 
178  public function getAdditionalAttributes() {
179  return 'id="tx-opendocs-menu"';
180  }
181 
187  protected function addJavascriptToBackend() {
188  $this->backendReference->addJavascriptFile(
189  \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($this->EXTKEY) . 'Resources/Public/JavaScript/opendocs.js'
190  );
191  }
192 
198  protected function addCssToBackend() {
199  $this->backendReference->addCssFile(
200  'opendocs',
201  \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($this->EXTKEY) . '/Resources/Public/Css/opendocs.css'
202  );
203  }
204 
205  /*******************
206  *** HOOKS ***
207  *******************/
216  public function updateNumberOfOpenDocsHook(&$params, $ref) {
217  $params['JScode'] = '
218  if (top && top.TYPO3BackendOpenDocs) {
219  top.TYPO3BackendOpenDocs.updateNumberOfDocs(' . count($this->openDocs) . ', true);
220  }
221  ';
222  }
223 
224  /******************
225  *** AJAX CALLS ***
226  ******************/
234  public function closeDocument($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
236  if ($md5sum && isset($this->openDocs[$md5sum])) {
237  // Add the document to be closed to the recent documents
238  $this->recentDocs = array_merge(array($md5sum => $this->openDocs[$md5sum]), $this->recentDocs);
239  // Allow a maximum of 8 recent documents
240  if (count($this->recentDocs) > 8) {
241  $this->recentDocs = array_slice($this->recentDocs, 0, 8);
242  }
243  // Remove it from the list of the open documents, and store the status
244  unset($this->openDocs[$md5sum]);
245  list(, $docDat) = $GLOBALS['BE_USER']->getModuleData('alt_doc.php', 'ses');
246  $GLOBALS['BE_USER']->pushModuleData('alt_doc.php', array($this->openDocs, $docDat));
247  $GLOBALS['BE_USER']->pushModuleData('opendocs::recent', $this->recentDocs);
248  }
249  $this->renderAjax($params, $ajaxObj);
250  }
251 
259  public function renderAjax($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
260  $menuContent = $this->renderMenu();
261  $ajaxObj->addContent('opendocsMenu', $menuContent);
262  }
263 
264 }
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=TRUE, $unsetMovePointers=FALSE)
closeDocument($params=array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj=NULL)
$uid
Definition: server.php:36
static getSpriteIconForRecord($table, array $row, array $options=array())
renderMenuEntry($document, $md5sum, $isRecentDoc=FALSE, $isFirstDoc=FALSE)
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
renderAjax($params=array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj=NULL)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
__construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference=NULL)
if($ajaxRegistryEntry !==NULL) $ajaxObj
Definition: ajax.php:63