Project

General

Profile

Bug #19662 » 9863_tsbrowser_v2.diff

Administrator Admin, 2008-12-01 13:50

View differences:

typo3/sysext/tsbrowser/class.tx_tsbrowser.php (revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2008 Steffen Kamper <info@sk-typo3.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*
* Hint: use extdeveval to insert/update function index above.
*/
require_once(PATH_t3lib . 'class.t3lib_page.php');
require_once(PATH_t3lib.'class.t3lib_tsparser.php');
$GLOBALS['LANG']->includeLLFile('EXT:tsbrowser/locallang.xml');
class tx_tsbrowser {
protected $pid;
public function renderTSbrowser($parameters, $pObj) {
if (!$parameters['e']['config']) {
return false;
}
// add header files
$pObj->pObj->doc->addStyleSheet('tsbrowser', $GLOBALS['BACK_PATH'] . t3lib_extMgm::extRelPath('tsbrowser') . 'tsbrowser.css');
$pObj->pObj->doc->loadJavascriptLib(t3lib_extMgm::extRelPath('tsbrowser') . 'tsbrowser.js');
$this->pid = t3lib_div::_GET('id');
$setting = t3lib_div::_GET('show_tsbrowser');
if ($setting && $setting != intval($GLOBALS['BE_USER']->uc['tx_tsbrowser']['show'])) {
$GLOBALS['BE_USER']->uc['tx_tsbrowser']['show'] = $setting;
$GLOBALS['BE_USER']->writeUC();
}
$strInsert = '
<div id="ts-browser">
<div id="ts-tree-container">
<input type="checkbox" class="checkbox" id="show_tsbrowser" onclick="window.location.href=window.location.href+\'&show_tsbrowser=\'+(this.checked?1:2)" value="1" ' . ($GLOBALS['BE_USER']->uc['tx_tsbrowser']['show'] == 1 ? ' checked="checked"' : '') . '/>
<label for="show_tsbrowser">' . $GLOBALS['LANG']->getLL('enableTSbrowser', 1) . '</label><br />
';
if ($GLOBALS['BE_USER']->uc['tx_tsbrowser']['show'] == 1) {
// Get TypoScript template for current page
$conf = $this->getConfigArray();
// Show TS template hierarchy
$tree = $this->showTemplate($conf);
$strInsert .= '
<label for="node-value">' . $GLOBALS['LANG']->getLL('nodeValue', 1) . ': </label>
<input id="node-value" type="text" style="width:90%;" value="" />
<div id="ts-tree">' . $tree . '</div>
</div>
';
} else {
$strInsert .= '
</div>
';
}
// insert tree in output string
$parameters['theOutput'] = preg_replace(
'/\<input type="Hidden" name="e\[config\]" value="1">/mi',
'<input type="hidden" name="e[config]" value="1">' . $strInsert,
$parameters['theOutput']
);
}
/**
* Get TS template
*
* This function creates instances of the class needed to render
* the TS template, and gets it as a multi-dimensionnal array.
*
* @return An array containing all the available TS objects
*/
protected function getConfigArray() {
// Initialize the page selector
$this->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
$this->sys_page->init(true);
// initialize the TS template
$this->tmpl = t3lib_div::makeInstance('t3lib_TStemplate');
$this->tmpl->init();
// Avoid an error
$this->tmpl->tt_track = 0;
// Get rootline for current PID
$rootline = $this->sys_page->getRootLine($this->pid);
// Start TS template
$this->tmpl->start($rootline);
return $this->tmpl->setup;
}
/**
* Show TS template hierarchy
*
* This function displays the TS template hierarchy as HTML list
* elements. Each section can be expanded/collapsed.
*
* @param $object A section of the TS template
* @param $object The path to the current object
* @return
*/
protected function showTemplate($conf, $pObj = false) {
// Storage
$htmlCode = array();
// pre-select a tag is possible with GPvar, not used at the moment
$curr = t3lib_div::GPvar('current');
// Process each object of the configuration array
foreach($conf as $key => $value) {
$str = '';
// TS object ID
$id = $pObj . $key;
$sel = (strpos($curr, $id) === 0);
$mtc = ($curr == $id);
$subKey = '';
if (substr($key, -1) == '.') {
$subKey = substr($key, 0, -1);
}
// Check if object is a container
if (is_array($value)) {
// Check if object has a content type
if (substr($key, 0, - 1) != $lastKey) {
// No content type - Process sub configuration
$subArray = $this->showTemplate($value, $id);
// Check if objects are available
if ($subArray) {
// Add container
// remuve trailing point
if ($subKey) {
$key = $subKey;
if(!is_array($conf[$subKey])) {
$v = htmlspecialchars($conf[$subKey]);
$str = $conf[$subKey] ? ' <em title="' . $v . '">[' . t3lib_div::fixed_lgd_cs($v,40) . ']</em>' : '';
}
}
$htmlCode[] = '<li class="pm ' . ($sel ? 'minus act' : 'plus') . '" ' . ($mtc ? 'id="selected"' : '') . ' name="' . $pObj . $key . '"><strong>' . $key . '</strong>' . $str . $subArray . '</li>';
}
}
} else {
if (substr($key, -1) != '.' && is_array($conf[$key . '.'])) {
$subArray = $this->showTemplate($conf[$key . '.'], $id);
} else {
// Memorize key
$lastKey = $key;
// TS object
$v = htmlspecialchars($value);
$htmlCode[] = '<li class="' . ($sel ? 'act' : '') . '" ' . ($mtc ? 'id="selected"' : '') . ' name="' . $key . '"><span>' . htmlspecialchars($key) . '</span> <em title="' . $v . '">[' . t3lib_div::fixed_lgd_cs($v,40) . ']</em></li>';
}
}
}
// Check if objects have been detected
if (count($htmlCode)) {
// insert css-class last to last li
array_push($htmlCode, preg_replace('/^<li class="/', '<li class="last ', array_pop($htmlCode)));
// Return hierarchy
return
'<ul class="' . (!$pObj ? 'tree' : '') . '">' .
implode(chr(10), $htmlCode) .
'</ul>';
}
}
}
?>
typo3/sysext/tsbrowser/ext_emconf.php (revision 0)
<?php
########################################################################
# Extension Manager/Repository config file for ext: "tsbrowser"
#
# Auto generated 29-11-2008 12:24
#
# Manual updates:
# Only the data in the array - anything else is removed by next write.
# "version" and "dependencies" must not be touched!
########################################################################
$EM_CONF[$_EXTKEY] = array(
'title' => 'Typoscript Browser',
'description' => 'shows Typoscript Browser in tstemplate_info-module',
'category' => 'module',
'author' => 'Steffen Kamper',
'author_email' => 'info@sk-typo3.de',
'shy' => '',
'dependencies' => 'tstemplate_info',
'conflicts' => '',
'priority' => '',
'module' => '',
'state' => 'stable',
'internal' => '',
'uploadfolder' => 0,
'createDirs' => '',
'modify_tables' => '',
'clearCacheOnLoad' => 0,
'lockType' => '',
'author_company' => '',
'version' => '0.0.1',
'constraints' => array(
'depends' => array(
'tstemplate_info' => '',
),
'conflicts' => array(
),
'suggests' => array(
),
),
'_md5_values_when_last_written' => 'a:6:{s:22:"class.tx_tsbrowser.php";s:4:"b4d8";s:12:"ext_icon.gif";s:4:"16ad";s:14:"ext_tables.php";s:4:"b5a8";s:13:"locallang.xml";s:4:"cb84";s:13:"tsbrowser.css";s:4:"6c6a";s:12:"tsbrowser.js";s:4:"36be";}',
'suggests' => array(
),
);
?>
typo3/sysext/tsbrowser/ext_tables.php (revision 0)
<?php
if (TYPO3_MODE=='BE') {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/tstemplate_info/class.tx_tstemplateinfo.php']['postOutputProcessingHook'][] = 'EXT:tsbrowser/class.tx_tsbrowser.php:&tx_tsbrowser->renderTSbrowser';
}
?>
typo3/sysext/tsbrowser/locallang.xml (revision 0)
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3locallang>
<meta type="array">
<description>Labels for the Typoscript Browser</description>
<type>module</type>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="moduleTitle">Typoscript Browser</label>
<label index="enableTSbrowser">enable Typoscript Browser</label>
<label index="nodeValue">Node value</label>
</languageKey>
</data>
</T3locallang>
typo3/sysext/tsbrowser/tsbrowser.css (revision 0)
/* CSS-class for the TS-tree */
#ts-browser {
margin: 15px 0;
}
#ts-tree ul, #ts-tree li {
padding: 0;
margin: 0;
list-style: none;
line-height: 16px;
}
#ts-tree li {
padding-left: 20px;
}
ul.tree {
padding-left: 2px;
}
ul.tree li {
background: 0 0 url(../../gfx/ol/join.gif) no-repeat transparent;
}
ul.tree li > span {
cursor: pointer;
}
ul.tree li > strong {
cursor: pointer;
}
ul.tree li.last {
background: 0 0 url(../../gfx/ol/joinbottom.gif) no-repeat transparent;
}
ul.tree li.act > strong {
font-style: italic;
}
ul.tree li.act > span {
font-style: italic;
}
ul.tree li.pm > strong {
margin-left: -20px;
padding-left: 20px;
}
ul.tree li.pm > ul {
margin-left: -20px !important;
padding-left: 20px !important;
background: 0 0 url(../../gfx/ol/line.gif) repeat-y transparent;
}
ul.tree li.last.pm > ul {
background: none;
}
ul.tree li.minus {
background: 0 0 url(../../gfx/ol/minus.gif) no-repeat transparent;
}
ul.tree li.plus {
background: 0 0 url(../../gfx/ol/plus.gif) no-repeat transparent;
}
ul.tree li.minus.last {
background: 0 0 url(../../gfx/ol/minusbottom.gif) no-repeat transparent;
}
ul.tree li.plus.last {
background: 0 0 url(../../gfx/ol/plusbottom.gif) no-repeat transparent;
}
ul.tree li.minus > ul {
display: block;
}
ul.tree li.plus > ul {
display: none;
}
typo3/sysext/tsbrowser/tsbrowser.js (revision 0)
var TSbrowser = Class.create({
initialize: function() {
Event.observe(window, 'load', function(){
$$('#ts-tree ul li').invoke('observe', 'click', this.clickedNode.bind(this));
}.bindAsEventListener(this));
},
/**
* display node content in text field and toggle state for plus/minus
*/
clickedNode: function(event) {
var clickedElement = Event.element(event);
var old = $('selected');
var tagName;
if (old) old.id = '';
if (clickedElement.tagName == 'EM' || clickedElement.tagName == 'SPAN') {
$('node-value').value = this.readValue(clickedElement);
}
if (clickedElement.tagName == 'STRONG') {
clickedElement.up('li').id = 'selected';
this.toggleState(clickedElement.up('li'));
}
Event.stop(event);
},
readValue: function(el) {
var str = '';
if (el.tagName == 'SPAN') {
el = el.next();
}
str = '=' + el.readAttribute('title');
while (el = el.up('li')) {
str = el.readAttribute('name') + (str.startsWith('=') ? '' : '.') + str;
if (el.hasClassName('pm')) {
break;
}
}
return str;
},
toggleState: function(el) {
if (el.hasClassName('pm')) {
el.toggleClassName('plus').toggleClassName('minus');
}
}
});
var TYPO3BackendTSbrowser = new TSbrowser();
(3-3/3)