Commit 648a056d authored by sgalinsk's avatar sgalinsk

[TASK] Unify line endings and some more cleanups


git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/pmkshadowbox/trunk@85415 735d13b6-9817-0410-8766-e36946ffe9aa
parent ce687bfb
<?php
/***************************************************************
* Copyright notice
*
* (c) 2011 Peter Klein <pmk@io.dk>
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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_pmkshadowbox_printsave
*/
class tx_pmkshadowbox_printsave {
/**
* Main function
*
* @return void
*/
public function main() {
$image = $this->cleanGPValue(t3lib_div::_GET('image'));
// Check if the requested file has an valid image file extension
$allowedExtensions = t3lib_div::trimExplode(
',', (strlen(
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
) > 0 ? $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] : 'gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai'), 1
);
$imageInfo = pathinfo($image);
if (!in_array(
strtolower($imageInfo['extension']), $allowedExtensions
)
) {
die('You are trying to download/print a file, which you don\'t have access to.');
}
if (!is_file(
t3lib_div::getFileAbsFileName(str_replace(t3lib_div::getIndpEnv('TYPO3_SITE_URL'), '', $image))
)
) {
die('File not found!');
}
switch ($this->cleanGPValue(t3lib_div::_GET('mode'))) {
case 'print':
$this->print_image($image);
break;
case 'save':
$this->force_download($image);
break;
default:
break;
}
}
/**
* @param string $filename
* @return void
*/
function print_image($filename) {
echo '<html>
<head>
<title>Print</title>
<script type="text/javascript">
function printit(){
try {
window.print();
}
catch(err) {
return;
}
window.close();
}
window.onload = printit;
</script>
</head>
<body style="margin:0;padding:0;">
<img src="' . $filename . '" style="border:none;cursor:pointer;" onclick="self.close()">
</body>
</html>';
}
/**
* @param string $filename
* @param string $mimetype
* @return bool
*/
public function force_download($filename, $mimetype = '') {
$filename = str_replace(t3lib_div::getIndpEnv('TYPO3_SITE_URL'), PATH_site, $filename);
if (!file_exists($filename)) {
return FALSE;
}
// Mimetype not set?
if (empty($mimetype)) {
$file_extension = strtolower(substr(strrchr($filename, "."), 1));
switch ($file_extension) {
case "pdf":
$mimetype = "application/pdf";
break;
case "exe":
$mimetype = "application/octet-stream";
break;
case "zip":
$mimetype = "application/zip";
break;
case "doc":
$mimetype = "application/msword";
break;
case "xls":
$mimetype = "application/vnd.ms-excel";
break;
case "ppt":
$mimetype = "application/vnd.ms-powerpoint";
break;
case "gif":
$mimetype = "image/gif";
break;
case "png":
$mimetype = "image/png";
break;
case "jpeg":
case "jpg":
$mimetype = "image/jpg";
break;
default:
$mimetype = "application/force-download";
}
}
// Make sure there's nothing else left
$this->ob_clean_all();
// Start sending headers
header('Pragma: public'); // required
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', FALSE); // required for certain browsers
header('Content-Transfer-Encoding: binary');
header('Content-Type: ' . $mimetype);
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename="' . basename($filename) . '";');
// Send data
readfile($filename);
exit;
}
/**
* @return bool
*/
private function ob_clean_all() {
$ob_active = ob_get_length() !== FALSE;
while ($ob_active) {
ob_end_clean();
$ob_active = ob_get_length() !== FALSE;
}
return TRUE;
}
/**
* Clean GET/POST values to prevent XSS/PoC attacks
*
* @param string $value
* @param int $htmlspecialchars
* @return mixed|string
*/
private function cleanGPValue($value, $htmlspecialchars = 1) {
// Remove HTML tags in value
$value = strip_tags($value);
// Decode URL-encoded chars
$value = rawurldecode($value);
// Remove all characters with ascii value below 32
$value = preg_replace('/[\x{00}-\x{1F}]/iu', '', $value);
//$value = preg_replace('/\W/si', '', $value);
// Convert special characters to HTML entities
return $htmlspecialchars ? htmlspecialchars($value) : $value;
}
}
if (defined(
'TYPO3_MODE'
) && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/pmkshadowbox/classes/class.tx_pmkshadowbox_printsave.php']
) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/pmkshadowbox/classes/class.tx_pmkshadowbox_printsave.php']);
}
// Make instance:
$output = t3lib_div::makeInstance('tx_pmkshadowbox_printsave');
$output->main();
<?php
/***************************************************************
* Copyright notice
*
* (c) 2011 Peter Klein <pmk@io.dk>
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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_pmkshadowbox_printsave
*/
class tx_pmkshadowbox_printsave {
/**
* Main function
*
* @return void
*/
public function main() {
$image = $this->cleanGPValue(t3lib_div::_GET('image'));
// Check if the requested file has an valid image file extension
$allowedExtensions = t3lib_div::trimExplode(
',', (strlen(
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
) > 0 ? $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] : 'gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai'), 1
);
$imageInfo = pathinfo($image);
if (!in_array(
strtolower($imageInfo['extension']), $allowedExtensions
)
) {
die('You are trying to download/print a file, which you don\'t have access to.');
}
if (!is_file(
t3lib_div::getFileAbsFileName(str_replace(t3lib_div::getIndpEnv('TYPO3_SITE_URL'), '', $image))
)
) {
die('File not found!');
}
switch ($this->cleanGPValue(t3lib_div::_GET('mode'))) {
case 'print':
$this->print_image($image);
break;
case 'save':
$this->force_download($image);
break;
default:
break;
}
}
/**
* @param string $filename
* @return void
*/
function print_image($filename) {
echo '<html>
<head>
<title>Print</title>
<script type="text/javascript">
function printit(){
try {
window.print();
}
catch(err) {
return;
}
window.close();
}
window.onload = printit;
</script>
</head>
<body style="margin:0;padding:0;">
<img src="' . $filename . '" style="border:none;cursor:pointer;" onclick="self.close()">
</body>
</html>';
}
/**
* @param string $filename
* @param string $mimetype
* @return bool
*/
public function force_download($filename, $mimetype = '') {
$filename = str_replace(t3lib_div::getIndpEnv('TYPO3_SITE_URL'), PATH_site, $filename);
if (!file_exists($filename)) {
return FALSE;
}
// Mimetype not set?
if (empty($mimetype)) {
$file_extension = strtolower(substr(strrchr($filename, "."), 1));
switch ($file_extension) {
case "pdf":
$mimetype = "application/pdf";
break;
case "exe":
$mimetype = "application/octet-stream";
break;
case "zip":
$mimetype = "application/zip";
break;
case "doc":
$mimetype = "application/msword";
break;
case "xls":
$mimetype = "application/vnd.ms-excel";
break;
case "ppt":
$mimetype = "application/vnd.ms-powerpoint";
break;
case "gif":
$mimetype = "image/gif";
break;
case "png":
$mimetype = "image/png";
break;
case "jpeg":
case "jpg":
$mimetype = "image/jpg";
break;
default:
$mimetype = "application/force-download";
}
}
// Make sure there's nothing else left
$this->ob_clean_all();
// Start sending headers
header('Pragma: public'); // required
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', FALSE); // required for certain browsers
header('Content-Transfer-Encoding: binary');
header('Content-Type: ' . $mimetype);
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename="' . basename($filename) . '";');
// Send data
readfile($filename);
exit;
}
/**
* @return bool
*/
private function ob_clean_all() {
$ob_active = ob_get_length() !== FALSE;
while ($ob_active) {
ob_end_clean();
$ob_active = ob_get_length() !== FALSE;
}
return TRUE;
}
/**
* Clean GET/POST values to prevent XSS/PoC attacks
*
* @param string $value
* @param int $htmlspecialchars
* @return mixed|string
*/
private function cleanGPValue($value, $htmlspecialchars = 1) {
// Remove HTML tags in value
$value = strip_tags($value);
// Decode URL-encoded chars
$value = rawurldecode($value);
// Remove all characters with ascii value below 32
$value = preg_replace('/[\x{00}-\x{1F}]/iu', '', $value);
//$value = preg_replace('/\W/si', '', $value);
// Convert special characters to HTML entities
return $htmlspecialchars ? htmlspecialchars($value) : $value;
}
}
if (defined(
'TYPO3_MODE'
) && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/pmkshadowbox/classes/class.tx_pmkshadowbox_printsave.php']
) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/pmkshadowbox/classes/class.tx_pmkshadowbox_printsave.php']);
}
// Make instance:
$output = t3lib_div::makeInstance('tx_pmkshadowbox_printsave');
$output->main();
?>
\ No newline at end of file
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
// post processing hook to clear any existing cache files if the clear cache button is used
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'][] =
'EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_cache.php:&tx_pmkshadowbox_cache->clearCachePostProc';
// Hook for adding "IMAGE_NUM_CURRENT" register value in tt_news
if (t3lib_extMgm::isLoaded('tt_news')) {
$TYPO3_CONF_VARS['EXTCONF']['tt_news']['extraItemMarkerHook'][] =
'EXT:pmkshadowbox/classes/class.tx_ttnews_imageMarkerHook.php:&tx_ttnews_imageMarker';
}
// Register Clear Cache Menu hook
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions']['clearShadowboxBuilds'] =
'EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_clearcachemenu.php:&tx_pmkshadowbox_clearcachemenu';
// Register Ajax call
$TYPO3_CONF_VARS['BE']['AJAX']['pmkshadowbox::clearShadowboxBuilds'] =
'EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_cache.php:&tx_pmkshadowbox_cache->clear';
// Register eID script for saving and printing SB content.
$TYPO3_CONF_VARS['FE']['eID_include']['pmkshadowbox'] = 'EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_printsave.php';
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
// post processing hook to clear any existing cache files if the clear cache button is used
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'][] =
'EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_cache.php:&tx_pmkshadowbox_cache->clearCachePostProc';
// Hook for adding "IMAGE_NUM_CURRENT" register value in tt_news
if (t3lib_extMgm::isLoaded('tt_news')) {
$TYPO3_CONF_VARS['EXTCONF']['tt_news']['extraItemMarkerHook'][] =
'EXT:pmkshadowbox/classes/class.tx_ttnews_imageMarkerHook.php:&tx_ttnews_imageMarker';
}
// Register Clear Cache Menu hook
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions']['clearShadowboxBuilds'] =
'EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_clearcachemenu.php:&tx_pmkshadowbox_clearcachemenu';
// Register Ajax call
$TYPO3_CONF_VARS['BE']['AJAX']['pmkshadowbox::clearShadowboxBuilds'] =
'EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_cache.php:&tx_pmkshadowbox_cache->clear';
// Register eID script for saving and printing SB content.
$TYPO3_CONF_VARS['FE']['eID_include']['pmkshadowbox'] = 'EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_printsave.php';
?>
\ No newline at end of file
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
t3lib_extMgm::addStaticFile('pmkshadowbox', 'static/PMK_Shadowbox/', 'Shadowbox - Base');
t3lib_extMgm::addStaticFile(
'pmkshadowbox', 'static/PMK_Shadowbox_ClickEnlarge/', 'Shadowbox - tt_content (Click Enlarge)'
);
t3lib_extMgm::addStaticFile('pmkshadowbox', 'static/PMK_Shadowbox_tt_news/', 'Shadowbox - tt_news');
t3lib_extMgm::addStaticFile('pmkshadowbox', 'static/PMK_Shadowbox_tt_products/', 'Shadowbox - tt_products');
?>
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
t3lib_extMgm::addStaticFile('pmkshadowbox', 'static/PMK_Shadowbox/', 'Shadowbox - Base');
t3lib_extMgm::addStaticFile(
'pmkshadowbox', 'static/PMK_Shadowbox_ClickEnlarge/', 'Shadowbox - tt_content (Click Enlarge)'
);
t3lib_extMgm::addStaticFile('pmkshadowbox', 'static/PMK_Shadowbox_tt_news/', 'Shadowbox - tt_news');
t3lib_extMgm::addStaticFile('pmkshadowbox', 'static/PMK_Shadowbox_tt_products/', 'Shadowbox - tt_products');
?>
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3locallang>
<meta type="array">
<type>module</type>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="clearCacheTitle">Clear Shadowbox Builds</label>
</languageKey>
<languageKey index="de" type="array">
<label index="clearCacheTitle">Shadowbox-Builds entfernen</label>
</languageKey>
<languageKey index="dk" type="array">
<label index="clearCacheTitle">Nulstil Shadowbox Builds</label>
</languageKey>
</data>
</T3locallang>
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3locallang>
<meta type="array">
<type>module</type>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="clearCacheTitle">Clear Shadowbox Builds</label>
</languageKey>
<languageKey index="de" type="array">
<label index="clearCacheTitle">Shadowbox-Builds entfernen</label>
</languageKey>
<languageKey index="dk" type="array">
<label index="clearCacheTitle">Nulstil Shadowbox Builds</label>
</languageKey>
</data>
</T3locallang>
\ No newline at end of file
This diff is collapsed.
# Shadowbox Build Generation
#
# Note: This header data part must always executed before the other ones. Otherwise
# the register value can't be accessed and we are missing the build path information.
includeLibs.shadowboxBuild = EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_build.php
page.headerData.1230 = LOAD_REGISTER
page.headerData.1230 {
buildDirectory {
stdWrap.preUserFunc = tx_pmkshadowbox_build->build
stdWrap.preUserFunc {
useSizzle = {$plugin.pmkshadowbox.useSizzle}
players = {$plugin.pmkshadowbox.players}
adapter = {$plugin.pmkshadowbox.adapter}
skinModificationDirectory = {$plugin.pmkshadowbox.skinModificationDirectory}
language.data = TSFE:lang
languageFallback = {$plugin.pmkshadowbox.fallbackLanguage}
flashPlayer = {$plugin.pmkshadowbox.flashPlayer}
flashPlayerYT = {$plugin.pmkshadowbox.flashPlayerYT}
flashExpressInstallScript = {$plugin.pmkshadowbox.flashExpressInstallScript}
}
}
}
# javascript inclusion
page.headerData.1231 = TEXT
page.headerData.1231 {
dataWrap = <script type="text/javascript" src="{TSFE:absRefPrefix}{register:buildDirectory}shadowbox.js"></script>
}
# css inclusion
page.headerData.1232 = TEXT
page.headerData.1232 {
dataWrap = <link type="text/css" media="all" rel="stylesheet" href="{TSFE:absRefPrefix}{register:buildDirectory}shadowbox.css" />
}
page.headerData.1233 = COA
page.headerData.1233 {
wrap (
<script type="text/javascript">
/* <![CDATA[ */
|
/* ]]> */
</script>
)
10 = TEXT
10 {
value (
function shadowBoxInit() {
Shadowbox.init({
animate: {$plugin.pmkshadowbox.animate},
animateFade: {$plugin.pmkshadowbox.animateFade},
animSequence: '{$plugin.pmkshadowbox.animSequence}',
autoplayMovies: {$plugin.pmkshadowbox.autoplayMovies},
continuous: {$plugin.pmkshadowbox.continuous},
counterLimit: {$plugin.pmkshadowbox.counterLimit},
counterType: '{$plugin.pmkshadowbox.counterType}',
displayCounter: {$plugin.pmkshadowbox.displayCounter},
displayNav: {$plugin.pmkshadowbox.displayNav},
enableKeys: {$plugin.pmkshadowbox.enableKeys},
fadeDuration: {$plugin.pmkshadowbox.fadeDuration},
flashParams: {$plugin.pmkshadowbox.flashParams},
flashVars: {$plugin.pmkshadowbox.flashVars},
flashVersion: '{$plugin.pmkshadowbox.flashVersion}',
handleOversize: '{$plugin.pmkshadowbox.handleOversize}',
handleUnsupported: '{$plugin.pmkshadowbox.handleUnsupported}',
initialHeight: {$plugin.pmkshadowbox.initialHeight},
initialWidth: {$plugin.pmkshadowbox.initialWidth},
modal: {$plugin.pmkshadowbox.modal},
onChange: {$plugin.pmkshadowbox.onChange},
onClose: {$plugin.pmkshadowbox.onClose},
onFinish: {$plugin.pmkshadowbox.onFinish},
onOpen: {$plugin.pmkshadowbox.onOpen},
overlayColor: '{$plugin.pmkshadowbox.overlayColor}',
overlayOpacity: {$plugin.pmkshadowbox.overlayOpacity},
resizeDuration: {$plugin.pmkshadowbox.resizeDuration},
showOverlay: {$plugin.pmkshadowbox.showOverlay},
showMovieControls: {$plugin.pmkshadowbox.showMovieControls},
skipSetup: {$plugin.pmkshadowbox.skipSetup},
slideshowDelay: {$plugin.pmkshadowbox.slideshowDelay},
viewportPadding: {$plugin.pmkshadowbox.viewportPadding},
preserveAspectWhileResizing: {$plugin.pmkshadowbox.preserveAspectWhileResizing},
troubleElements: {$plugin.pmkshadowbox.troubleElements}
});
}
)
}
20 = TEXT
20 {
dataWrap = Shadowbox.path = '{TSFE:absRefPrefix}{register:buildDirectory}';
}
30 = TEXT
30 {
value = shadowBoxInit();
}
# image map initialisation
40 = TEXT
40 {
value (
Shadowbox.onReady = function() {
var shadowBoxElements = document.getElementsByTagName('area');
if (shadowBoxElements.length) {
Shadowbox.setup(shadowBoxElements, {$plugin.pmkshadowbox.imageMapOptions});
}
}
)
override = ;
override.if.isTrue = {$plugin.pmkshadowbox.skipImageMapSetup}
}
}
# Code for printing shadowbox HTML (iframe) content.
[globalVar = GP:print = 2]
page.headerData.1229 = TEXT
page.headerData.1229.value (
<script type="text/javascript">
/* <![CDATA[ */
function printIframeContent() {
try {
window.print();
} catch (err) {
return;
}
window.close();
}
if (window.addEventListener) {
window.addEventListener('load', printIframeContent, false);
} else if (window.attachEvent) {
window.attachEvent('onload', printIframeContent);
}
/* ]]> */
</script>
)
[global]
// Include all js in footer
[globalVar = LIT:1 = {$plugin.pmkshadowbox.includeJsInFooter}]
page.footerData.1231 < page.headerData.1231
page.headerData.1231 >
page.footerData.1233 < page.headerData.1233
page.headerData.1233 >
# Shadowbox Build Generation
#
# Note: This header data part must always executed before the other ones. Otherwise
# the register value can't be accessed and we are missing the build path information.
includeLibs.shadowboxBuild = EXT:pmkshadowbox/classes/class.tx_pmkshadowbox_build.php
page.headerData.1230 = LOAD_REGISTER
page.headerData.1230 {
buildDirectory {
stdWrap.preUserFunc = tx_pmkshadowbox_build->build
stdWrap.preUserFunc {
useSizzle = {$plugin.pmkshadowbox.useSizzle}
players = {$plugin.pmkshadowbox.players}
adapter = {$plugin.pmkshadowbox.adapter}
skinModificationDirectory = {$plugin.pmkshadowbox.skinModificationDirectory}
language.data = TSFE:lang
languageFallback = {$plugin.pmkshadowbox.fallbackLanguage}
flashPlayer = {$plugin.pmkshadowbox.flashPlayer}
flashPlayerYT = {$plugin.pmkshadowbox.flashPlayerYT}
flashExpressInstallScript = {$plugin.pmkshadowbox.flashExpressInstallScript}
}
}
}
# javascript inclusion
page.headerData.1231 = TEXT
page.headerData.1231 {
dataWrap = <script type="text/javascript" src="{TSFE:absRefPrefix}{register:buildDirectory}shadowbox.js"></script>
}
# css inclusion
page.headerData.1232 = TEXT
page.headerData.1232 {
dataWrap = <link type="text/css" media="all" rel="stylesheet" href="{TSFE:absRefPrefix}{register:buildDirectory}shadowbox.css" />
}
page.headerData.1233 = COA
page.headerData.1233 {
wrap (
<script type="text/javascript">
/* <![CDATA[ */