Sodala,
ich hab es glaube ich hinbekommen, allerdings weiß ich nicht, wie gut der Code ist, oder ob das Schwachstellen offenbart (außer meinem PHP Skills), hab es über den generatePage Hook gelöst (den ich sowieso für ein anderes Problem brauche...
config.php
PHP-Code:
$GLOBALS['TL_HOOKS']['generatePage'][] = array('neckarpixel\npsystem', 'npGeneratePage');
dca/tl_content.php
PHP-Code:
$GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][] = 'addUnique';
/* Palettes */
$GLOBALS['TL_DCA']['tl_content']['palettes']['download'] = str_replace(',titleText',',titleText,addUnique',$GLOBALS['TL_DCA']['tl_content']['palettes']['download']);
/* Subpalettes */
$GLOBALS['TL_DCA']['tl_content']['subpalettes']['addUnique'] = 'uniqueID';
/* FIELDS */
// UNIQUE DOWNLOAD ID
$GLOBALS['TL_DCA']['tl_content']['fields']['addUnique'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['addUnique'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'w50 w12', 'submitOnChange' => true),
'sql' => "char(1) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_content']['fields']['uniqueID'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['uniqueID'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('maxlength'=>200,'tl_class'=>'w50', 'mandatory' => true, 'unique' => true, 'spaceToUnderscore' => true, 'doNotCopy' => true, 'rgxp' =>'alias'),
'sql' => "varchar(255) NOT NULL default ''"
);
classes/npsystem.php
PHP-Code:
/**
* Namespace
*/
namespace neckarpixel;
class npsystem {
public function npGeneratePage( $objPage, $objLayout, $objPageRegular){
// Send the file to the browser and do not send a 404 header (see #4632)
if (\Input::get('dl')) {
$file = \Input::get('dl');
if($objElement = \ContentModel::findBy('uniqueID', $file)) {
$objFile = \FilesModel::findByUuid($objElement->singleSRC);
\Controller::sendFileToBrowser($objFile->path);
}
}
}
ce_download.html im templates ordner
PHP-Code:
<?php $this->extend('block_searchable'); ?>
<?php $this->block('content'); ?>
<?php
$strDownload = $this->href;
if($this->addUnique) :
$strHref = \Environment::get('request');
// Remove an existing file parameter (see #5683)
if (preg_match('/(&(amp;)?|\?)file=/', $strHref))
{
$strHref = preg_replace('/(&(amp;)?|\?)file=[^&]+/', '', $strHref);
}
$strHref .= ((\Config::get('disableAlias') || strpos($strHref, '?') !== false) ? '&' : '?') . 'dl=' . $this->uniqueID;
$strDownload = $strHref;
endif;?>
<a href="<?= $strDownload ?>" title="<?= $this->title ?>"><i class="icon-download"></i><span class="desc"><?= $this->link ?> <span class="size"><?= strtoupper($this->extension) . ' | ' . $this->filesize ?></span></span></a>
<?php $this->endblock(); ?>
Es funktioniert, das ist gerade die Hauptsache. Jemand ein Idee, ob man das besser lösen könnte?
grüße
Lesezeichen