20080203_opendocs_commited.patch

Administrator Admin, 2008-02-03 16:39

Download (16.4 kB)

 
typo3/sysext/opendocs/class.tx_opendocs.php (revision 3036)
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
	 * @return	void
58
	 */
59
	public function __construct() {
60
		global $BE_USER;
61

  
62
		list($this->openDocs,) = $BE_USER->getModuleData('alt_doc.php','ses');
63
		$this->recentDocs = $BE_USER->getModuleData('opendocs::recent');
64
	}
65

  
66

  
67
	/**
68
	 * sets the backend reference
69
	 *
70
	 * @param	TYPO3backend	backend object reference
71
	 * @return	void
72
	 */
73
	public function setBackend(&$backendReference) {
74
		$this->backendReference = $backendReference;
75
	}
76

  
77

  
78
	/**
79
	 * renders the toolbar item and the empty menu
80
	 *
81
	 * @return	void
82
	 */
83
	public function render() {
84

  
85
		$this->addJavascriptToBackend();
86
		$this->addCssToBackend();
87

  
88
			// return the toolbar item and an empty UL
89
		$output  = '<a href="#" class="toolbar-item">';
90
		$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="" />';
91
		$output .= '</a>';
92
		$output .= '<ul class="toolbar-item-menu" style="display: none;"></ul>';
93
		return $output;
94
	}
95

  
96

  
97
	/**
98
	 * returns the opened documents list as an array
99
	 *
100
	 * @return	array	all open documents as list-items
101
	 */
102
	public function getOpenDocuments() {
103
		$docs = array();
104

  
105
			// Traverse the list of open documents:
106
		if (is_array($this->openDocs)) {	
107
			foreach($this->openDocs as $md5k => $lnk) {
108
				$docs[] = '<li><a target="content" href="'.htmlspecialchars('alt_doc.php?'.$lnk[2]).'">'.htmlspecialchars(strip_tags(t3lib_div::htmlspecialchars_decode($lnk[0]))).'</a></li>';
109
			}
110
		}
111
		return $docs;
112
	}
113

  
114

  
115
	/**
116
	 * returns the recent documents list as an array
117
	 *
118
	 * @return	array	all recent documents as list-items
119
	 */
120
	public function getRecentDocuments() {
121
		$docs = array();
122

  
123
		if (is_array($this->recentDocs)) {
124
			$docs[] = '<li class="menu-item-div">'.$GLOBALS['LANG']->getLL('recent_docs',1).'</li>';
125

  
126
				// Traverse the list of open documents:
127
			foreach($this->recentDocs as $md5k => $lnk) {
128
				$docs[] = '<li><a target="content" href="'.htmlspecialchars('alt_doc.php?'.$lnk[2]).'">'.htmlspecialchars(strip_tags(t3lib_div::htmlspecialchars_decode($lnk[0]))).'</a></li>';
129
			}
130
		}
131
		return $docs;
132
	}
133

  
134

  
135

  
136
	/**
137
	 * returns additional attributes for the list item in the toolbar
138
	 *
139
	 * @return	string		list item HTML attibutes
140
	 */
141
	public function getAdditionalAttributes() {
142
		return ' id="open-documents-menu"';
143
	}
144

  
145

  
146
	/**
147
	 * adds the neccessary javascript to the backend
148
	 *
149
	 * @return	void
150
	 */
151
	private function addJavascriptToBackend() {
152
		$this->backendReference->addJavascriptFile(t3lib_extMgm::extRelPath($this->EXTKEY).'opendocs.js');
153
	}
154

  
155

  
156
	/**
157
	 * adds the neccessary CSS to the backend
158
	 *
159
	 * @return	void
160
	 */
161
	private function addCssToBackend() {
162
		$this->backendReference->addCssFile('opendocs', t3lib_extMgm::extRelPath($this->EXTKEY).'opendocs.css');
163
	}
164

  
165

  
166

  
167

  
168
	/**
169
	 * returns the opened documents list for the AJAX call formatted as HTML list
170
	 *
171
	 * @return	string		list item HTML attibutes
172
	 */
173
	public function renderBackendMenuContents($params, &$ajaxObj) {
174
		$itms = $this->getOpenDocuments();
175
		$itmsRecent = $this->getRecentDocuments();
176

  
177

  
178
			// if there are "recent documents" in the list, add them 
179
		if (count($itmsRecent)) {
180
			$itms = array_merge($itms, $itmsRecent);
181
		}
182

  
183

  
184
		if (count($itms)) {
185
			$ajaxObj->addContent('opendocs', implode('', $itms));
186
		} else {
187
			$ajaxObj->addContent('opendocs', '<li>'.$GLOBALS['LANG']->getLL('no_docs',1).'</li>');
188
		}
189
	}
190
}
191

  
192
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['EXT:opendocs/class.tx_opendocs.php']) {
193
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['EXT:opendocs/class.tx_opendocs.php']);
194
}
195
?>
typo3/sysext/opendocs/ext_tables.php (working copy)
1 1
<?php
2
if (!defined ('TYPO3_MODE')) 	die ('Access denied.');
2
if (!defined('TYPO3_MODE')) 	die('Access denied.');
3 3

  
4
if (TYPO3_MODE=='BE')	{
5
	t3lib_extMgm::addModule('user','doc','after:ws',t3lib_extMgm::extPath($_EXTKEY).'mod/');
4

  
5
if (TYPO3_MODE == 'BE') {
6

  
7
		// register top module
8
	$GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'][] = t3lib_extMgm::extPath('opendocs').'registerToolbarItem.php';
9

  
10

  
11
		// register AJAX call
12
	$GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['tx_opendocs::backendmenu'] = t3lib_extMgm::extPath('opendocs').'class.tx_opendocs.php:tx_opendocs->renderBackendMenuContents';
13

  
14

  
15
		// register menu module if option is wanted
16
	$_EXTCONF = unserialize($_EXTCONF);
17
	if ($_EXTCONF['enableModule']) {
18
		t3lib_extMgm::addModule('user', 'doc', 'after:ws', t3lib_extMgm::extPath($_EXTKEY).'mod/');
19
	}
6 20
}
7 21
?>
typo3/sysext/opendocs/opendocs.css (revision 3036)
1
#open-documents-menu {
2
	width: 30px;
3
}
4

  
5
#open-documents-menu img {
6
	margin: 1px 0 0;
7
}
8

  
9
#open-documents-menu ul {
10
	width: 185px;
11
	position: absolute;
12
	list-style: none;
13
	padding: 2px 0px 0px;
14
	margin: 0px;
15
	background-color: #f9f9f9;
16
	border: 1px solid #abb2bc;
17
	border-top: none;
18
}
19

  
20
#open-documents-menu li {
21
	text-align: left;
22
	float: none;
23
	vertical-align: middle;
24
	line-height: 14px;
25
	font-size: 11px;
26
	padding: 1px 1px 1px 0;
27
}
28

  
29
#open-documents-menu li img {
30
	float: left;
31
	padding-right: 3px;
32
}
33

  
34
#open-documents-menu li a {
35
	text-decoration: none;
36
	vertical-align: middle;
37
	display: block;
38
	padding: 1px 1px 1px 4px;
39
	font-size: 11px;
40
}
41

  
42
#open-documents-menu li a:hover {
43
	background: #f0f0f0;
44
}
45
#open-documents-menu li.menu-item-div {
46
	border-top: 1px solid #abb2bc;
47
	font-weight: bold;
48
	padding: 2px 0 2px 3px;
49
}
typo3/sysext/opendocs/opendocs.js (revision 3036)
1
/***************************************************************
2
*  Copyright notice
3
*
4
*  (c) 2008 Benjamin Mack <mack@xnos.org>
5
*  All rights reserved
6
*
7
*  This script is part of the TYPO3 project. The TYPO3 project is
8
*  free software; you can redistribute it and/or modify
9
*  it under the terms of the GNU General Public License as published by
10
*  the Free Software Foundation; either version 2 of the License, or
11
*  (at your option) any later version.
12
*
13
*  The GNU General Public License can be found at
14
*  http://www.gnu.org/copyleft/gpl.html.
15
*  A copy is found in the textfile GPL.txt and important notices to the license
16
*  from the author is found in LICENSE.txt distributed with these scripts.
17
*
18
*
19
*  This script is distributed in the hope that it will be useful,
20
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
*  GNU General Public License for more details.
23
*
24
*  This copyright notice MUST APPEAR in all copies of the script!
25
***************************************************************/
26
/**
27
 * class to handle the open documents menu, loads the open documents dynamically
28
 */
29
var OpenDocs = Class.create({
30
	ajaxScript: 'ajax.php',
31
	ajaxID: 'tx_opendocs::backendmenu',
32
	menuItem: 'open-documents-menu',
33
	menu: null,		// the <ul> tag
34
	toolbarItem: null,	// the <a> tag
35

  
36

  
37
	/**
38
	 * registers for resize event listener and executes on DOM ready
39
	 */
40
	initialize: function() {
41
		Event.observe(window, 'load', function() {
42
			this.getMenu();
43
			Event.observe(window,        'resize', this.positionMenu.bindAsEventListener(this));
44
			Event.observe(this.menuItem, 'click',    this.toggleMenu.bindAsEventListener(this));
45
		}.bindAsEventListener(this));
46
	},
47

  
48

  
49
	getMenu: function() {
50
		this.menu = $$('#' + this.menuItem + ' ul')[0];
51
		this.toolbarItem = $$('#'+this.menuItem+' a')[0];
52
	},
53

  
54

  
55
	/**
56
	 * positions the menu below the toolbar icon
57
	 */
58
	positionMenu: function() {
59
		var calculatedOffset = 0;
60
		var ownWidth         = this.menu.getWidth();
61
		var parentWidth      = $(this.menuItem).getWidth();
62
		var parentSiblings   = $(this.menuItem).previousSiblings();
63

  
64
		parentSiblings.each(function(toolbarItem) {
65
			calculatedOffset += toolbarItem.getWidth()-1;
66
		});
67
		calculatedOffset = calculatedOffset - ownWidth + parentWidth;
68
		this.menu.setStyle({ left: calculatedOffset-2 + 'px' });
69
	},
70

  
71

  
72
	/**
73
	 * toggles the visibility of the menu and places it under the toolbar icon
74
	 */
75
	toggleMenu: function() {
76
		this.toolbarItem.blur();
77
		if(!this.toolbarItem.hasClassName('toolbar-item-active')) {
78
			this.showMenu();
79
		} else {
80
			this.hideMenu();
81
		}
82
	},
83

  
84

  
85
	/**
86
	 * displays the menu and does the AJAX call to the TYPO3 backend
87
	 */
88
	showMenu: function() {
89
		new Ajax.Request(this.ajaxScript, {
90
			parameters: 'ajaxID=' + this.ajaxID,
91
			onSuccess: function(xhr) {
92
				this.menu.innerHTML = xhr.responseText;
93
				Effect.Appear(this.menu, {duration: 0.2});
94
			}.bind(this)
95
		});
96
		this.positionMenu();
97
		this.toolbarItem.addClassName('toolbar-item-active');
98
		TYPO3BackendToolbarManager.hideOthers(this.toolbarItem);
99
	},
100

  
101

  
102
	/**
103
	 * hides the menu
104
	 */
105
	hideMenu: function() {
106
		Effect.Fade(this.menu, {duration: 0.1});
107
		this.toolbarItem.removeClassName('toolbar-item-active');
108
	}
109
});
110

  
111
var TYPO3BackendOpenDocs = new OpenDocs();
typo3/sysext/opendocs/locallang_opendocs.xml (revision 3036)
1
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2
<T3locallang>
3
	<meta type="array">
4
		<description>Standard Document Module labels</description>
5
		<type>module</type>
6
		<fileId>EXT:opendocs/locallang_opendocs.xml</fileId>
7
		<labelContext type="array">
8
		</labelContext>
9
	</meta>
10
	<data type="array">
11
		<languageKey index="default" type="array">
12
			<label index="toolbaritem">Open and Recently Edited Documents</label>
13
			<label index="open_docs">Opened Documents</label>
14
			<label index="recent_docs">Recently Edited Documents</label>
15
			<label index="no_docs">There are no open documents</label>
16
		</languageKey>
17
	</data>
18
</T3locallang>
typo3/sysext/opendocs/registerToolbarItem.php (revision 3036)
1
<?php
2

  
3
if (!defined ('TYPO3_MODE')) 	die ('Access denied.');
4

  
5
if(TYPO3_MODE=='BE') {
6

  
7
		// first include the class file
8
	include(t3lib_extMgm::extPath('opendocs').'class.tx_opendocs.php');
9

  
10
		// now register the class as toolbar item
11
	$GLOBALS['TYPO3backend']->addToolbarItem('opendocs', 'tx_opendocs');
12
}
13

  
14
?>
typo3/sysext/opendocs/ext_emconf.php (working copy)
25 25
	'uploadfolder' => 0,
26 26
	'createDirs' => '',
27 27
	'modify_tables' => '',
28
	'clearCacheOnLoad' => 0,
28
	'clearCacheOnLoad' => 1,
29 29
	'lockType' => '',
30 30
	'author' => 'Benjamin Mack',
31 31
	'author_email' => 'mack@xnos.org',
......
48 48
	),
49 49
);
50 50

  
51
?>
51
?>
typo3/sysext/opendocs/ext_conf_template.txt (revision 3036)
1
  # cat=basic/enable; type=boolean; label=Enable Open Documents module: Enables, additionally to the menu in the top bar the old module "Open Documents" / "Doc" in the module menu as a submodule of User.
2
enableModule = 0
typo3/alt_doc.php (working copy)
1453 1453
	function closeDocument($code=0)	{
1454 1454
		global $BE_USER;
1455 1455

  
1456
			// If current document is found in docHandler, then unset it, possibly unset it ALL and finally, write it to the session data:
1457
		if (isset($this->docHandler[$this->storeUrlMd5]))	{
1456
			// If current document is found in docHandler, 
1457
			// then unset it, possibly unset it ALL and finally, write it to the session data
1458
		if (isset($this->docHandler[$this->storeUrlMd5])) {
1459

  
1460
				// add the closing document to the recent documents
1461
			$recentDocs = $BE_USER->getModuleData('opendocs::recent');
1462
			if (!is_array($recentDocs)) {
1463
				$recentDocs = array();
1464
			}
1465
			$closedDoc = $this->docHandler[$this->storeUrlMd5];
1466
			$recentDocs = array_merge(array($this->storeUrlMd5 => $closedDoc), $recentDocs);
1467
			if (count($recentDocs) > 8) {
1468
				$recentDocs = array_slice($recentDocs, 0, 8);
1469
			}
1470

  
1471
				// remove it from the list of the open documents
1458 1472
			unset($this->docHandler[$this->storeUrlMd5]);
1459
			if ($code=='3')	$this->docHandler=array();
1460
			$BE_USER->pushModuleData('alt_doc.php',array($this->docHandler,$this->docDat[1]));
1473
			if ($code == '3') {
1474
				$recentDocs = array_merge($this->docHandler, $recentDocs);
1475
				$this->docHandler = array();
1476
			}
1477
			$BE_USER->pushModuleData('opendocs::recent', $recentDocs);
1478
			$BE_USER->pushModuleData('alt_doc.php', array($this->docHandler, $this->docDat[1]));
1461 1479
		}
1462 1480

  
1481

  
1463 1482
			// If ->returnEditConf is set, then add the current content of editconf to the ->retUrl variable: (used by other scripts, like wizard_add, to know which records was created or so...)
1464 1483
		if ($this->returnEditConf && $this->retUrl!='dummy.php')	{
1465 1484
			$this->retUrl.='&returnEditConf='.rawurlencode(serialize($this->editconf));