Skip to content

Commit

Permalink
[BUGFIX] Fixed subdir wizzard and preview by adding FAL compatibility…
Browse files Browse the repository at this point in the history
…. Outsourced FAL path check to new static function.
  • Loading branch information
derhansen committed May 10, 2014
1 parent 91eb334 commit 67cb0b5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/class.tx_chgallery_tca.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php/** * ************************************************************ * Copyright notice * * (c) 2007 Georg Ringer (just2b) <http://www.just2b.com> * 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 tx_chgallery_tca { /** * Set the DB TCA field with an userfunction to allow dynamic manipulation * * @param array $PA: * @param array $fobj: * @return The TCA field */ function user_chgallerydescr ($PA, $fobj) { // set the correct path, needed for global installation, thx Clemens $this->correctWizardPath = t3lib_extMgm::extRelPath('chgallery') . "wizard/"; // get the correct tables which are allowed > tsconfig chgallery.tables $pid = $this->getStorageFolderPid($PA['row']['pid']); $uid = $PA['row']['uid']; $pid = $PA['row']['pid']; if (is_numeric($uid)) { $link = '==> <a onclick="this.blur();vHWin=window.open(\'../typo3conf/ext/chgallery/wizard/index.php?&P[params]=&P[exampleImg]=&P[table]=tt_content&P[uid]='.$uid.'&P[pid]='.$pid.'&P[field]=pi_flexform&P[md5ID]=ID24e035d4e1&P[returnUrl]=%2Ftypo3%2Falt_doc.php%3F%26returnUrl%3D%252Ftypo3%252Fsysext%252Fcms%252Flayout%252Fdb_layout.php%253Fid%253D'.$pid.'%26edit%5Btt_content%5D%5B'.$uid.'%5D%3Dedit&P[formName]=editform&P[itemName]=data%5Btt_content%5D%5B'.$uid.'%5D%5Bpi_flexform%5D%5Bdata%5D%5BsDEF%5D%5BlDEF%5D%5Bdescription%5D%5BvDEF%5D_hr&P[fieldChangeFunc][typo3form.fieldGet]=typo3form.fieldGet%28%27data%5Btt_content%5D%5B'.$uid.'%5D%5Bpi_flexform%5D%5Bdata%5D%5BsDEF%5D%5BlDEF%5D%5Bdescription%5D%5BvDEF%5D%27%2C%27%27%2C%27%27%2C0%2C%27%27%29%3B&P[fieldChangeFunc][TBE_EDITOR_fieldChanged]=TBE_EDITOR.fieldChanged%28%27tt_content%27%2C%27'.$uid.'%27%2C%27pi_flexform%27%2C%27data%5Btt_content%5D%5B'.$uid.'%5D%5Bpi_flexform%5D%27%29%3B&P[fieldChangeFunc][alert]=\'+\'&P[currentValue]=\'+TBE_EDITOR.rawurlencode(document.editform[\'data[tt_content]['.$uid.'][pi_flexform][data][sDEF][lDEF][description][vDEF]_hr\'].value,200)+\'&P[currentSelectedValues]=\'+TBE_EDITOR.curSelected(\'data[tt_content]['.$uid.'][pi_flexform][data][sDEF][lDEF][description][vDEF]_hr_list\'),\'popUpID24e035d4e1\',\'height=600,width=550,status=1,menubar=1,scrollbars=1\');vHWin.focus();return false;" href="#"><img width="16" height="16" border="0" title="Image Description Wizard" alt="Image Description Wizard" src="../typo3conf/ext/chgallery/wizard/wizard.gif"/></a> ';#?P[table]=tt_content&P[uid]='.$uid.'&P[pid]='.$pid.'& $onclick = "this.blur();vHWin=window.open('../typo3conf/ext/chgallery/wizard/index.php?P[field]=pi_flexform&P[table]=tt_content&P[uid]=$uid&P[pid]=$pid','popUpID5a0ca3a2f5','height=600,width=550,status=1,menubar=1,scrollbars=1');vHWin.focus();return false;"; $link = '<a onclick="'.$onclick.'" href="#"><strong>Click here</strong> => <img width="16" height="16" border="0" title="Image Description Wizard" alt="Image Description Wizard" src="../typo3conf/ext/chgallery/wizard/wizard.gif"/></a>'; return $link; } else { return '<strong>Save at least once to be able to use the wizard</strong>'; } } /** * Get a preview of the plugin in the last tab of the plugin. * Just output, nothing is saved to anywhere * * @param array $PA: * @param array $fobj: * @return The TCA field */ function user_chgallerypreview ($PA, $fobj) { $uid = $PA['row']['uid']; $pid = $PA['row']['pid']; if (is_numeric($uid) && is_array($flexformArray = t3lib_div::xml2array($PA['row']['pi_flexform'])) ) { $fileTypes = 'gif,jpg,png'; // read the flexform settings and transform it to array $flexformArray = $flexformArray['data']['sDEF']['lDEF']; // get all the infos we need $path = trim($flexformArray['path']['vDEF']); $mode = trim($flexformArray['show']['vDEF']); $sort = trim($flexformArray['categoryOrder']['vDEF']); $languageid = $PA['row']['sys_language_uid']; if ($path!='' && is_dir(PATH_site.$path)) { $content.= '<h3>Path: '.$path.' <small>Mode: '.$mode.'</small></h3>'; $this->languagePrefix = ($languageid>0) ? '-'.$languageid : ''; $level = ($mode =='LIST') ? 1 : 0; $imageList = t3lib_div::getAllFilesAndFoldersInPath (array(), PATH_site.$path, $fileTypes, 0, $level, 1); // correct sorting array_multisort($imageList, SORT_ASC); $directoryList = array(); // get each dir in an array foreach ($imageList as $key=>$singleImage) { // get the correct path if ($mode=='LIST') { $fileName = str_replace(PATH_site, '', $singleImage); $directory = dirname(str_replace($path, '', $fileName)); } else { $fileName = basename($singleImage); $directory = $path; } // Files of a directory title if ($directory!='.') { $desc = $this->getSingleDescription($singleImage); $desc = $desc ? ' - <i>'.$desc.'</i>' : ''; $directoryList[$directory] .= basename($fileName).$desc.'<br />'; } } // ouput every directory including a header to toggle all images of the directory foreach ($directoryList as $key=>$value) { if ($mode == 'LIST') { $content.= '<div style="font:weight:bold;background:#eee;border:1px solid #333;margin-top:10px;padding:2px 5px;"> '.$key.' </div>'; } $content.= '<div style="padding:0 5px;margin:5px;"> '.$value.' </div>'; } } } else { return '<strong>Save at least once to be able to use the preview</strong>'; } return $content; } /** * Get the description of a file which is saved in a txt file with the same name. * * @param string $file The file * @return string The description */ function getSingleDescription($file) { $file = $file.$this->languagePrefix.'.txt'; if (is_file($file)) { $text = file_get_contents($file); } return $text; } /** * Negative PID values is pointing to a page on the same level as the current. * * @param int $pid: The pid of the record * @return The real pid of a (new) record */ function getStorageFolderPid($pid) { if ($pid<0) { $pidRow = t3lib_BEfunc::getRecord('tt_content',abs($pid),'pid'); $pid = $pidRow['pid']; } return $pid; }}if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/chgallery/lib/class.tx_chgallery_tca.php']) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/chgallery/lib/class.tx_chgallery_tca.php']);}?>
<?php/** * ************************************************************ * Copyright notice * * (c) 2007 Georg Ringer (just2b) <http://www.just2b.com> * 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! * **************************************************************/require_once(t3lib_extMgm::extPath('chgallery').'lib/class.tx_chgallery_utility.php');class tx_chgallery_tca { /** * Set the DB TCA field with an userfunction to allow dynamic manipulation * * @param array $PA: * @param array $fobj: * @return The TCA field */ function user_chgallerydescr ($PA, $fobj) { // set the correct path, needed for global installation, thx Clemens $this->correctWizardPath = t3lib_extMgm::extRelPath('chgallery') . "wizard/"; // get the correct tables which are allowed > tsconfig chgallery.tables $pid = $this->getStorageFolderPid($PA['row']['pid']); $uid = $PA['row']['uid']; $pid = $PA['row']['pid']; if (is_numeric($uid)) { $link = '==> <a onclick="this.blur();vHWin=window.open(\'../typo3conf/ext/chgallery/wizard/index.php?&P[params]=&P[exampleImg]=&P[table]=tt_content&P[uid]='.$uid.'&P[pid]='.$pid.'&P[field]=pi_flexform&P[md5ID]=ID24e035d4e1&P[returnUrl]=%2Ftypo3%2Falt_doc.php%3F%26returnUrl%3D%252Ftypo3%252Fsysext%252Fcms%252Flayout%252Fdb_layout.php%253Fid%253D'.$pid.'%26edit%5Btt_content%5D%5B'.$uid.'%5D%3Dedit&P[formName]=editform&P[itemName]=data%5Btt_content%5D%5B'.$uid.'%5D%5Bpi_flexform%5D%5Bdata%5D%5BsDEF%5D%5BlDEF%5D%5Bdescription%5D%5BvDEF%5D_hr&P[fieldChangeFunc][typo3form.fieldGet]=typo3form.fieldGet%28%27data%5Btt_content%5D%5B'.$uid.'%5D%5Bpi_flexform%5D%5Bdata%5D%5BsDEF%5D%5BlDEF%5D%5Bdescription%5D%5BvDEF%5D%27%2C%27%27%2C%27%27%2C0%2C%27%27%29%3B&P[fieldChangeFunc][TBE_EDITOR_fieldChanged]=TBE_EDITOR.fieldChanged%28%27tt_content%27%2C%27'.$uid.'%27%2C%27pi_flexform%27%2C%27data%5Btt_content%5D%5B'.$uid.'%5D%5Bpi_flexform%5D%27%29%3B&P[fieldChangeFunc][alert]=\'+\'&P[currentValue]=\'+TBE_EDITOR.rawurlencode(document.editform[\'data[tt_content]['.$uid.'][pi_flexform][data][sDEF][lDEF][description][vDEF]_hr\'].value,200)+\'&P[currentSelectedValues]=\'+TBE_EDITOR.curSelected(\'data[tt_content]['.$uid.'][pi_flexform][data][sDEF][lDEF][description][vDEF]_hr_list\'),\'popUpID24e035d4e1\',\'height=600,width=550,status=1,menubar=1,scrollbars=1\');vHWin.focus();return false;" href="#"><img width="16" height="16" border="0" title="Image Description Wizard" alt="Image Description Wizard" src="../typo3conf/ext/chgallery/wizard/wizard.gif"/></a> ';#?P[table]=tt_content&P[uid]='.$uid.'&P[pid]='.$pid.'& $onclick = "this.blur();vHWin=window.open('../typo3conf/ext/chgallery/wizard/index.php?P[field]=pi_flexform&P[table]=tt_content&P[uid]=$uid&P[pid]=$pid','popUpID5a0ca3a2f5','height=600,width=550,status=1,menubar=1,scrollbars=1');vHWin.focus();return false;"; $link = '<a onclick="'.$onclick.'" href="#"><strong>Click here</strong> => <img width="16" height="16" border="0" title="Image Description Wizard" alt="Image Description Wizard" src="../typo3conf/ext/chgallery/wizard/wizard.gif"/></a>'; return $link; } else { return '<strong>Save at least once to be able to use the wizard</strong>'; } } /** * Get a preview of the plugin in the last tab of the plugin. * Just output, nothing is saved to anywhere * * @param array $PA: * @param array $fobj: * @return The TCA field */ function user_chgallerypreview ($PA, $fobj) { $uid = $PA['row']['uid']; $pid = $PA['row']['pid']; if (is_numeric($uid) && is_array($flexformArray = t3lib_div::xml2array($PA['row']['pi_flexform'])) ) { $fileTypes = 'gif,jpg,png'; // read the flexform settings and transform it to array $flexformArray = $flexformArray['data']['sDEF']['lDEF']; // get all the infos we need $path = trim($flexformArray['path']['vDEF']); $mode = trim($flexformArray['show']['vDEF']); $sort = trim($flexformArray['categoryOrder']['vDEF']); $languageid = $PA['row']['sys_language_uid']; $path = tx_chgallery_utility::convertFalPath($path); if ($path!='' && is_dir(PATH_site.$path)) { $content.= '<h3>Path: '.$path.' <small>Mode: '.$mode.'</small></h3>'; $this->languagePrefix = ($languageid>0) ? '-'.$languageid : ''; $level = ($mode =='LIST') ? 1 : 0; $imageList = t3lib_div::getAllFilesAndFoldersInPath (array(), PATH_site.$path, $fileTypes, 0, $level, 1); // correct sorting array_multisort($imageList, SORT_ASC); $directoryList = array(); // get each dir in an array foreach ($imageList as $key=>$singleImage) { // get the correct path if ($mode=='LIST') { $fileName = str_replace(PATH_site, '', $singleImage); $directory = dirname(str_replace($path, '', $fileName)); } else { $fileName = basename($singleImage); $directory = $path; } // Files of a directory title if ($directory!='.') { $desc = $this->getSingleDescription($singleImage); $desc = $desc ? ' - <i>'.$desc.'</i>' : ''; $directoryList[$directory] .= basename($fileName).$desc.'<br />'; } } // ouput every directory including a header to toggle all images of the directory foreach ($directoryList as $key=>$value) { if ($mode == 'LIST') { $content.= '<div style="font:weight:bold;background:#eee;border:1px solid #333;margin-top:10px;padding:2px 5px;"> '.$key.' </div>'; } $content.= '<div style="padding:0 5px;margin:5px;"> '.$value.' </div>'; } } } else { return '<strong>Save at least once to be able to use the preview</strong>'; } return $content; } /** * Get the description of a file which is saved in a txt file with the same name. * * @param string $file The file * @return string The description */ function getSingleDescription($file) { $file = $file.$this->languagePrefix.'.txt'; if (is_file($file)) { $text = file_get_contents($file); } return $text; } /** * Negative PID values is pointing to a page on the same level as the current. * * @param int $pid: The pid of the record * @return The real pid of a (new) record */ function getStorageFolderPid($pid) { if ($pid<0) { $pidRow = t3lib_BEfunc::getRecord('tt_content',abs($pid),'pid'); $pid = $pidRow['pid']; } return $pid; }}if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/chgallery/lib/class.tx_chgallery_tca.php']) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/chgallery/lib/class.tx_chgallery_tca.php']);}?>
Expand Down
53 changes: 53 additions & 0 deletions lib/class.tx_chgallery_utility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/***************************************************************
* Copyright notice
*
* (c) 2014 Torben Hansen <[email protected]>, Skyfillers GmbH
*
* 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 3 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 tx_chgallery_utility {

/**
* If the given path is a FAL path and the storage is local, then the basepath is appended to the path
* so it can be used with general file functions in this extension.
*
* @param $path
* @return string
*/
public static function convertFalPath($path) {
if (preg_match('/^file:(\d+):(.*)$/', $path, $matches)) {
/** @var $storageRepository \TYPO3\CMS\Core\Resource\StorageRepository */
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
/** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
$storage = $storageRepository->findByUid(intval($matches[1]));
$storageRecord = $storage->getStorageRecord();
$storageConfiguration = $storage->getConfiguration();
if ($storageRecord['driver'] === 'Local') {
$basePath = rtrim($storageConfiguration['basePath'], '/') . '/';
$path = $basePath . substr($matches[2], 1);
}
}
return $path;
}
}

?>
15 changes: 3 additions & 12 deletions pi1/class.tx_chgallery_pi1.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

require_once(t3lib_extMgm::extPath('chgallery').'lib/class.tx_chgallery_utility.php');

/**
* Plugin 'Simple gallery' for the 'chgallery' extension.
*
Expand Down Expand Up @@ -927,18 +929,7 @@ function init($conf) {
function checkPath($path) {
$path = trim($path);

if (preg_match('/^file:(\d+):(.*)$/', $path, $matches)) {
/** @var $storageRepository \TYPO3\CMS\Core\Resource\StorageRepository */
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
/** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
$storage = $storageRepository->findByUid(intval($matches[1]));
$storageRecord = $storage->getStorageRecord();
$storageConfiguration = $storage->getConfiguration();
if ($storageRecord['driver'] === 'Local') {
$basePath = rtrim($storageConfiguration['basePath'], '/') . '/';
$path = $basePath . substr($matches[2], 1);
}
}
$path = tx_chgallery_utility::convertFalPath($path);

if (!t3lib_div::validPathStr($path)) {
return '';
Expand Down
4 changes: 4 additions & 0 deletions wizard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$MCONF['script']='index.php';

require_once ($BACK_PATH.'init.php');
require_once(t3lib_extMgm::extPath('chgallery').'lib/class.tx_chgallery_utility.php');
$LANG->includeLLFile('EXT:chgallery/wizard/locallang.xml');

// ....(But no access check here...)
Expand Down Expand Up @@ -224,6 +225,9 @@ function getSingleDescription($file) {
*/
function checkPath($path) {
$path = trim($path);

$path = tx_chgallery_utility::convertFalPath($path);

if (!t3lib_div::validPathStr($path)) {
return '';
}
Expand Down
4 changes: 4 additions & 0 deletions wizard/subdir.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$MCONF['script']='subdir.php';

require_once ($BACK_PATH.'init.php');
require_once(t3lib_extMgm::extPath('chgallery').'lib/class.tx_chgallery_utility.php');
$LANG->includeLLFile('EXT:chgallery/wizard/locallang.xml');

// ....(But no access check here...)
Expand Down Expand Up @@ -222,6 +223,9 @@ function getFullDir($path, $sort='') {
*/
function checkPath($path) {
$path = trim($path);

$path = tx_chgallery_utility::convertFalPath($path);

if (!t3lib_div::validPathStr($path)) {
return '';
}
Expand Down

0 comments on commit 67cb0b5

Please sign in to comment.