Your IP : 216.73.216.240
<?php
/*
* Module GalleryFP pour Joomla! 3.x
* Version J3.4F
* Creation date: Octobre 2015
* Author: Fabrice4821 - www.gmapfp.org
* Author email: webmaster@gmapfp.org
* License GNU/GPL
*/
defined('JPATH_PLATFORM') or die;
class JFormFieldFilesComments extends JFormField
{
protected $type = 'FilesComments';
protected function getInput()
{
if ($this->form instanceof JForm)
{
// Définition de JUri::base() sans tenir compte du paramètre $config->get('live_site') de la config principale
$uri = JUri::getInstance();
$base['prefix'] = $uri->toString(array('scheme', 'host', 'port'));
if (strpos(php_sapi_name(), 'cgi') !== false && !ini_get('cgi.fix_pathinfo') && !empty($_SERVER['REQUEST_URI']))
$script_name = $_SERVER['PHP_SELF'];
else $script_name = $_SERVER['SCRIPT_NAME'];
$base['path'] = rtrim(dirname($script_name), '/\\');
$Base_URL = $base['prefix'] . $base['path'] . '/';
$module_id = $this->form->getValue('id');
$files_dir = 'modules/mod_galleryfp/galleries/'.$module_id;
if (!$module_id) {
echo JText::_('MOD_GALLERYFP_SAVE_BEFORE');
return;
}
echo JText::sprintf('MOD_GALERIE_FP_FREE',$Base_URL.'../modules/mod_galleryfp/');
$doc = JFactory::getDocument();
$doc->addStyleSheet( $Base_URL.'../modules/mod_galleryfp/fields/filescomments.css');
$doc->addScript( $Base_URL.'../modules/mod_galleryfp/js/jquery.filedrop.js');
$doc->addScript( $Base_URL.'../modules/mod_galleryfp/js/bootbox.min.js');
$js = "
jQuery(document).ready(function ($){
$('#dropzonefp').unbind();
$('#dropzonefp').filedrop({
fallback_id: 'upload_filesfp_input', // an identifier of a standard file input element, becomes the target of \"click\" events on the dropzone
url: '".$Base_URL."../index.php?option=com_ajaxdropfilesfp&task=add', // upload handler, handles each file separately, can also be a function taking the file and returning a url
paramname: 'fpfile', // POST parameter name used on serverside to reference file, can also be a function taking the filename and returning the paramname
allowedfileextensions: ['.jpg','.jpeg','.png','.tif','.gif'], // file extensions allowed. Empty array means no restrictions
maxfiles: 25,
maxfilesize: 20, // max file size in MBs
queuefiles: 2,
data: {
module_id : $module_id,
module_type : 'gallery'
},
error: function(err, file) {
switch(err) {
case 'BrowserNotSupported':
bootbox.alert('".str_replace("'", "\'", JText::_('MOD_GALLERYFP_BROWSER_NOT_SUPPORT_HTML5'))."');
break;
case 'TooManyFiles':
// user uploaded more than 'maxfiles'
bootbox.alert('".str_replace("'", "\'", JText::_('MOD_GALLERYFP_TOO_MANY_FILES'))." !');
break;
case 'FileTooLarge':
// program encountered a file whose size is greater than 'maxfilesize'
// FileTooLarge also has access to the file which was too large
// use file.name to reference the filename of the culprit file
bootbox.alert(file.name+' ".str_replace("'", "\'", JText::_('MOD_GALLERYFP_FILE_TOO_LARGE'))." !');
break;
case 'FileTypeNotAllowed':
// The file type is not in the specified list 'allowedfiletypes'
bootbox.alert(file.name+' ".str_replace("'", "\'", JText::_('MOD_GALLERYFP_FILE_TYPE_NOT_ALLOWED'))." !');
break;
case 'FileExtensionNotAllowed':
// The file extension is not in the specified list 'allowedfileextensions'
bootbox.alert(file.name+' ".str_replace("'", "\'", JText::_('MOD_GALLERYFP_EXTENSION_TYPE_NOT_ALLOWED'))." !');
break;
default:
break;
}
},
dragOver: function() {
$(this).css('border', '3px dashed red');
// user dragging files over #dropzone
},
dragLeave: function() {
$(this).css('border', '3px dashed #BBBBBB');
// user dragging files out of #dropzone
},
drop: function() {
// user drops file
$(this).css('border', '3px dashed #BBBBBB');
},
uploadStarted: function(i, file, len){
// a file began uploading
// i = index => 0, 1, 2, 3, 4 etc
// file is the actual file of the index
// len = total files user dropped
var bar = $('<div id=\"preview\">'+
'<img src=\"\">'+
'<div class=\"progress progress-striped active\">'+
'<div class=\"bar\"></div>'+
'</div>'+
'</div>');
$('#dropzonefp').prepend(bar);
var preview = $('#preview');
var image = $('img', preview);
var reader = new FileReader();
reader.onload = function(e){
// e.target.result holds the DataURL which
// can be used as a source of the image:
image.attr('src',e.target.result);
};
// Reading the file as a DataURL. When finished,
// this will trigger the onload function above:
reader.readAsDataURL(file);
preview.appendTo('#preview');
// Associating a preview container
// with the file, using jQuery's $.data():
$.data(file,preview);
},
uploadFinished: function(i, file, response, time) {
// response is the data you got back from server in JSON format.
// alert('uploadFinished');
// console.log(response.response);
// console.log(response.datas);
$('#preview').remove();
if (response.response != true) {
bootbox.alert(response.response);
} else {
var mes_fichiers = new Array();
jQuery(\"[name=files_galleryfp]\").each(function(){mes_fichiers.push(jQuery(this).text().trim());});
if ($.inArray(file.name, mes_fichiers) == -1) {
$('#dropzonefp').append(response.datas['content']);
eval('tmp = ' + response.datas['json_data']);
FPGallery_photo = $.extend(FPGallery_photo,tmp);
} else {
bootbox.alert('".str_replace("'", "\'", JText::_('MOD_GALLERYFP_FILE_REPLACED'))." : ' + file.name);
}
}
},
progressUpdated: function(i, file, progress) {
// this function is used for large files and updates intermittently
// progress is the integer value of file being uploaded percentage to completion
$.data(file).find('.progress .bar').width(progress+'%');
},
beforeEach: function(file) {
// file is a file object
// return false to cancel upload
if(!file.type.match(/^image\//)){
bootbox.alert('".str_replace("'", "\'", JText::_('MOD_GALLERYFP_ONLY_IMAGE_ALLOWED'))." !');
return false;
};
if (Object.keys(FPGallery_photo).length > 5)
return false;
return true;
},
afterAll: function() {
// runs after all files have been uploaded or otherwise dealt with
$('#dropzonefp .progress').delay(300).fadeIn(300).hide(300, function(){
$(this).remove();
});
}
});
$('#upload_filesfp_button').on('click',function(){
$('#upload_filesfp_input').trigger('click');
return false;
});
});
function delete_file(file_name) {
jQuery.ajax({
url: '".$Base_URL."../index.php?option=com_ajaxdropfilesfp&task=delete',
data: {
module_id : $module_id,
module_type : 'gallery',
data: file_name
}
}).done(function(response) {
eval('response = ' + response);
if (response.response == 'true') {
jQuery('#' + response.datas).remove();
} else {
bootbox.alert('".str_replace("'", "\'", JText::_('MOD_GALLERYFP_DELETE_ERROR'))."');
};
});
return false;
}
";
$doc->addScriptDeclaration($js);
?>
<div id="dropzonefp" class="dropzonefp clearfix" >
<div class="drop_info"><?php echo JText::_('MOD_GALLERYFP_DROP_FILE');?>
<input type="file" id="upload_filesfp_input" multiple="">
<a href="" id="upload_filesfp_button" class="btn btn-primary"><?php echo JText::_('MOD_GALLERYFP_DROP_FILE_BP');?></a>
</div>
<?php
echo '<strong>'.JText::_($this->element['label']).'</strong> : '.JText::_($this->element['description']);
$param_json = json_decode($this->value);
if (empty($files_dir)) return;
$pic = $files_dir."/";
$doc = JFactory::getDocument();
$script = "
var file;
var lang;
var value;
function FP_change_text(el)
{
file = el.getAttribute('file');
lang = el.getAttribute('lang');
value = el.value.replace(/\\\"/g,'\\\\\"');
value = value.replace(/</gi,'?');
eval('FPGallery_photo.'+file+'.'+lang+' = \"'+value+'\"');
document.getElementById('".$this->id."').value = JSON.stringify(FPGallery_photo);
}
";
$doc->addScriptDeclaration($script);
$dirFiles = array();
// opens images folder
if ($handle = @opendir(JPATH_ROOT.'/'.$pic)) {
while (false !== ($file = readdir($handle))) {
// strips files extensions
$crap = array(".jpg", ".jpeg", ".png", ".gif", ".bmp");
$extension = substr($file, strrpos($file, '.'));
// hides folders, writes out ul of images and thumbnails from two folders
if (in_array(strtolower($extension), $crap) && $file != "." && $file != ".." && $file != "index.php" && $file != "index.html" && $file != "thumbs" && $file != "Thumbnails" && count($dirFiles)<6) {
$dirFiles[] = $file;
}
}
closedir($handle);
}
sort($dirFiles);
jimport('joomla.language.helper');
$langues = JLanguageHelper::createLanguageList('', constant('JPATH_SITE'), true, true);
//construction du json
$json = "\n".' <script type="text/javascript">'."\n".'var FPGallery_photo = {'."\n";
$json_files = array();
foreach($dirFiles as $file) {
// $json_file = '"json'.str_replace(array('.', '-', ' '), array('ùùù', 'ààà', 'ééé'), $file).'": {'."\n";
$json_file = '"json'.rtrim(strtr(base64_encode($file), '+/', '-_'), '=').'": {'."\n";
// $json_name = 'json'.str_replace(array('.', '-', ' '), array('ùùù', 'ààà', 'ééé'), $file);
$json_name = 'json'.rtrim(strtr(base64_encode($file), '+/', '-_'), '=');
$json_langage = array();
foreach ($langues as $langue) {
$json_lang = str_replace('-', '_', $langue['value']);
eval('$json_value = @$param_json->'.$json_name.'->'.$json_lang.';');
$json_langage[] = '"'.str_replace('-', '_', $langue['value']).'":'.'"'.$json_value.'"';
}
$json_file .= implode(','."\n", $json_langage);
$json_file .= '}';
$json_files[] = $json_file;
}
$json .= implode(','."\n", $json_files);
$json .= '};'."\n".'</script>'."\n";
// $doc->addScriptDeclaration($json);
echo $json;
foreach($dirFiles as $file)
{
$json_name = 'json'.rtrim(strtr(base64_encode($file), '+/', '-_'), '=');
echo '<div class="control-group span12" id="'.$json_name.'">';
echo '<div class="span3 control-group">';
echo '<label name="files_galleryfp">'.$file.' </label>';
echo '<img src="'.JURI::base().'../'.$pic.$file.'" style="height:60px" /><span onclick="jQuery(\'#'.$json_name.'\').addClass(\'alert-danger\');delete_file(\''.$file.'\');" class="icon-trash"></span>';
echo '</div>';
echo '<div class="span9 control-group">';
foreach ($langues as $langue) {
$json_lang = str_replace('-', '_', $langue['value']);
eval('$json_value = @$param_json->'.$json_name.'->'.$json_lang.';');
echo '<div class="span4 langue">';
echo $langue['value'].' <textarea name="'.$json_name.'_'.$langue['value'].'" file="'.$json_name.'" lang="'.$json_lang.'" id="'.$json_name.'_'.$langue['value'].'" onChange="FP_change_text(this)">'.$json_value.'</textarea>';
echo '</div>';
}
echo '</div>';
echo '</div>';
}
echo '<textarea style="display:none;" name="'.$this->name.'" id="' . $this->id . '"" >'.$this->value.'</textarea>';
echo '</div>'; //fermeture de dropzone
}
else return;
}
public function getLabel() {
return '';
}
}