Skip to content
Snippets Groups Projects
Commit 4156b250 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #73233 improve file manager php file rendering

parent c8965435
Branches
Tags
3 merge requests!2660Master,!2655Dev#73233 planif contractuel minsoc formulaire gerer le rendu cote front,!2637Dev#73233 planif contractuel minsoc formulaire gerer le rendu cote front
Pipeline #4055 passed with stage
in 34 minutes and 45 seconds
......@@ -304,6 +304,19 @@ class Class_FileManager extends Class_Entity {
}
public function isDownloadable() {
if(!$this->isFile())
return false;
return !$this->isPhp();
}
public function isPhp() {
return 'php' == strtolower($this->getExtension());
}
public function isDot() {
return $this->getDot();
}
......
......@@ -111,7 +111,7 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
'caption' => function($model) {
return $this->_view->tag('i', '', ['class' => 'fa fa-download']) . $this->_view->tag('span', $this->_('Télécharger'));
},
'condition' => 'isFile',
'condition' => 'isDownloadable',
'label' => $this->_('Télécharger "%s"', $model->getName()),
'anchorOptions' => array_filter(['download' => $model->getName(),
'title' => $this->_('Télécharger "%s"', $model->getName())])],
......
......@@ -25,9 +25,7 @@ class ZendAfi_View_Helper_Admin_FileManager_File extends ZendAfi_View_Helper_Bas
if(!$settings)
$settings = (new Class_Entity)->setSelectFile(false);
$url = $file->getUrl();
$dt = [
$dl = [
$this->_tag('dt', $this->_('Nom :')),
$this->_tag('dd', $file->getName()),
......@@ -51,12 +49,17 @@ class ZendAfi_View_Helper_Admin_FileManager_File extends ZendAfi_View_Helper_Bas
];
if($file->isPhp())
return $this->_renderPhpFile($file, $dl);
$url = $file->getUrl();
if($file->isFile())
$dt = array_merge($dt,
$dl = array_merge($dl,
[$this->_tag('dt', $this->_('URL publique :')),
$this->_tag('dd', $url)]);
$dl = $this->_tag('dl', implode(array_filter($dt)));
$dl = $this->_tag('dl', implode(array_filter($dl)));
$url_reload = $url . '?version='. time(); // force reload image
......@@ -83,4 +86,24 @@ class ZendAfi_View_Helper_Admin_FileManager_File extends ZendAfi_View_Helper_Bas
['style' => 'padding: 1em;',
'class' => 'browser']);
}
protected function _renderPhpFile($file, $dl) {
$dl = $this->_tag('dl', implode(array_filter($dl)));
$models = ($models = $file->getModels())
? $this->view->FileManager_Models($models)
: '';
$preview = $this->_tag('h3' ,
$this->_('Contenu du fichier'))
. $this->_tag('pre',
$file->getContent());
return $this->_tag('div',
implode([$dl,
$models,
$preview]),
['style' => 'padding: 1em;',
'class' => 'browser']);
}
}
\ No newline at end of file
......@@ -551,3 +551,94 @@ class AdvancedSearch_AdvancedSearchValidCustomFormsSelectedAndPublishedTest
$this->assertXPath('//script[contains(@src, "public/opac/js/tabify.js")]');
}
}
class AdvancedSearch_AdvancedSearchFileManagerPhpFileDispatchTest extends Admin_AbstractControllerTestCase {
protected
$_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$userfiles_dir = (new Class_FileManager)
->setId('userfiles')
->setDir(true)
->setName('userfiles')
->setPath('userfiles');
$php_file = (new Class_FileManager)
->setId('userfiles/form.php')
->setDir(false)
->setExtension('php')
->setRealpath('userfiles/form.php')
->setName('userfiles/form.php')
->setPath('userfiles/form.php');
$disk = $this->mock()
->whenCalled('diskSpaceInfo')
->answers((new Class_Entity)
->setFree('2 GO')
->setUsed('153 GO')
->setTotal('155 GO')
->setPercent('99%')
->whenCalledDo('isFull', function(){return false;}))
->whenCalled('clearCache')
->answers(true)
->whenCalled('isOversized')
->answers(false)
->whenCalled('directoriesAt')
->with('userfiles')
->answers([])
->whenCalled('filesAt')
->with('userfiles')
->answers([$php_file])
->whenCalled('directoryAt')
->with('userfiles')
->answers($userfiles_dir)
->whenCalled('directoryAt')
->with('userfiles/form.php')
->answers(null)
->whenCalled('filesAt')
->with('userfiles')
->answers([])
->whenCalled('fileAt')
->with('userfiles/form.php')
->answers($php_file)
->whenCalled('getContent')
->with('userfiles/form.php')
->answers('<?php echo "toto"; ?>');
Class_FileManager::setFileSystem($disk);
$this->dispatch('/admin/file-manager/index?browser=userfiles%2Fform.php&focused_browser=browser', true);
}
public function tearDown() {
Class_FileManager::reset();
parent::tearDown();
}
/** @test */
public function shouldRenderPhpContent() {
$this->assertXPathContentContains('//pre', 'echo "toto";');
}
/** @test */
public function downloadLinkShouldNotBePresent() {
$this->assertNotXPath('//a[contains(@href, "userfiles/form.php")][@download]');
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment