| Current Path : /home/juvelize/www/components/com_ajaxdropfilesfp/ |
| Current File : /home/juvelize/www/components/com_ajaxdropfilesfp/ajaxdropfilesfp.php |
<?php
/*
* Composant AjaxDropFilesFP pour Joomla! 3.x
* Version J3.2P
* Creation date: Octobre 2015
* Author: Fabrice4821 - www.gmapfp.org
* Author email: webmaster@gmapfp.org
* License GNU/GPL
*/
defined('_JEXEC') or die;
jimport( 'joomla.filesystem.folder' );
jimport( 'joomla.filesystem.file' );
// Reference global application object
$app = JFactory::getApplication();
$input = $app->input;
// Load language file for module
$lang = JFactory::getLanguage();
$task = $input->get('task', '');
$module_id = $input->getInt('module_id', '');
$module_type = $input->getString('module_type', 'aplayer');
switch ($module_type) {
case 'aplayer':
$lang->load('mod_aplayerfp', JPATH_BASE, null, false, true);
$file_dir = 'modules/mod_aplayerfp/audio/'.$module_id;
$allowed_ext = array('ogg','mp3','wav');
break;
case 'gallery':
$file_dir = 'modules/mod_galleryfp/galleries/'.$module_id;
$allowed_ext = array('jpeg','jpg','png','gif','tif');
break;
}
if ($task == 'add') {
$data_info = '';
if(!file_exists(JPATH_ROOT.'/'.$file_dir)){
JFolder::create(JPATH_ROOT.'/'.$file_dir);
$data = '<html><body bgcolor="#FFFFFF"></body></html>';
JFile::write(JPATH_ROOT.'/'.$file_dir.'/index.html', $data);
}
if(strtolower($_SERVER['REQUEST_METHOD']) != 'post'){
exit_upload(JText::_('COM_AJAXDROPFILESFP_CTRL_FILES_WRONG_HTTP_RESPONSE'));
}
if(array_key_exists('fpfile',$_FILES) && $_FILES['fpfile']['error'] == 0 ){
$fpfile = $_FILES['fpfile'];
if(!in_array(strtolower(JFile::getExt($fpfile['name'])),$allowed_ext)){
exit_upload(JText::_('COM_AJAXDROPFILESFP_CTRL_FILES_WRONG_FILE_EXTENSION').' : '.strtolower(JFile::getExt($fpfile['name'])));
}
if(!JFile::upload($fpfile['tmp_name'], JPATH_ROOT.'/'.$file_dir.'/'.$fpfile['name'])){
exit_upload(JText::_('COM_AJAXDROPFILESFP_CTRL_FILES_CANT_MOVE_FILE'));
}
if ($module_type == 'aplayer') {
function calcul_time($the_time) {
$minutes = '00' . floor($the_time / 60);
$minutes = substr($minutes,-2);
$secondes = '00' . ($the_time % 60);
$secondes = substr($secondes,-2);
return $minutes.JText::_('MOD_APLAYERFP_MINUTES') . ' ' . $secondes.JText::_('MOD_APLAYERFP_SECONDES');
}
require_once(JPATH_ROOT.'/modules/mod_aplayerfp/fields/getid3/getid3.php');
$getID3 = new getID3;
$getID3->option_md5_data = true;
$getID3->option_md5_data_source = true;
$getID3->encoding = 'UTF-8';
$info = $getID3->analyze(JPATH_ROOT.'/'.$file_dir.'/'.$fpfile['name']);
$result = array();
$result['album'] = (isset($info['id3v2']['comments']['album']) ? $info['id3v2']['comments']['album'][0] : '');
$result['title'] = (isset($info['id3v2']['comments']['title']) ? $info['id3v2']['comments']['title'][0] : '');
$result['format_name'] = (isset($info['audio']['dataformat']) ? $info['audio']['dataformat'] : '');
$result['channels'] = (isset($info['audio']['channelmode']) ? $info['audio']['channelmode'] : '');
$result['bitrate'] = (isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : '');
$result['playing_time'] = (isset($info['playtime_seconds']) ? calcul_time(round($info['playtime_seconds'])) : '');
$result['comment'] = (isset($info['id3v2']['comments']['comment']) ? $info['id3v2']['comments']['comment'][0] : '');
$data_info = '<table class="table-info">'."\n";
$data_info .= '<body>'."\n";
$data_info .= '<tr>'."\n";
$data_info .= '<td class="titre">'.JText::_('MOD_APLAYERFP_FILE_NAME').' : </td>'."\n";
$data_info .= '<td class="info">'.$result['title'].'</td>'."\n";
$data_info .= '</tr>'."\n";
$data_info .= '<tr>'."\n";
$data_info .= '<td class="titre">'.JText::_('MOD_APLAYERFP_ALBUM').' : </td>'."\n";
$data_info .= '<td class="info">'.$result['album'].'</td>'."\n";
$data_info .= '</tr>'."\n";
$data_info .= '<tr>'."\n";
$data_info .= '<td class="titre">'.JText::_('MOD_APLAYERFP_CHANNELS').' : </td>'."\n";
$data_info .= '<td class="info">'.$result['channels'].'</td>'."\n";
$data_info .= '</tr>'."\n";
$data_info .= '<tr>'."\n";
$data_info .= '<td class="titre">'.JText::_('MOD_APLAYERFP_FORMAT_NAME').' : </td>'."\n";
$data_info .= '<td class="info">'.$result['format_name'].'</td>'."\n";
$data_info .= '</tr>'."\n";
$data_info .= '<tr>'."\n";
$data_info .= '<td class="titre">'.JText::_('MOD_APLAYERFP_SAMPLE_RATE').' : </td>'."\n";
$data_info .= '<td class="info">'.$result['bitrate'].'</td>'."\n";
$data_info .= '</tr>'."\n";
$data_info .= '<tr>'."\n";
$data_info .= '<td class="titre">'.JText::_('MOD_APLAYERFP_PLAYING_TIME').' : </td>'."\n";
$data_info .= '<td class="info">'.$result['playing_time'].'</td>'."\n";
$data_info .= '</tr>'."\n";
$data_info .= '<tr>'."\n";
$data_info .= '<td class="titre">'.JText::_('MOD_APLAYERFP_COMMENT').' : </td>'."\n";
$data_info .= '<td class="info">'.$result['comment'].'</td>'."\n";
$data_info .= '</tr>'."\n";
$data_info .= '</tbody>'."\n";
$data_info .= '</table>';
}
if ($module_type == 'gallery') {
jimport('joomla.language.helper');
$langues = JLanguageHelper::createLanguageList('', constant('JPATH_SITE'), true, true);
$json_name = 'json'.rtrim(strtr(base64_encode($fpfile['name']), '+/', '-_'), '=');
$data_info = '<div class="control-group span12" id="'.$json_name.'">';
$data_info .= '<div class="span3 control-group">';
$data_info .= '<label name="files_galleryfp">'.$fpfile['name'].' </label>';
$data_info .= '<img src="'.JURI::base().$file_dir.'/'.$fpfile['name'].'" style="height:60px" /><span onclick="jQuery(\'#'.$json_name.'\').addClass(\'alert-danger\');delete_file(\''.$fpfile['name'].'\');" class="icon-trash"></span>';
$data_info .= '</div>';
$data_info .= '<div class="span9 control-group">';
foreach ($langues as $langue) {
$json_lang = str_replace('-', '_', $langue['value']);
eval('$json_value = @$param_json->'.$json_name.'->'.$json_lang.';');
$data_info .= '<div class="span4 langue">';
$data_info .= $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>';
$data_info .= '</div>';
}
$data_info .= '</div>';
$data_info .= '</div>';
$json_file = '{"json'.rtrim(strtr(base64_encode($fpfile['name']), '+/', '-_'), '=').'": {'."\n";
$json_name = 'json'.rtrim(strtr(base64_encode($fpfile['name']), '+/', '-_'), '=');
$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 .= '}}';
$data_info = array('content' => $data_info, 'json_data' => $json_file);
}
}
exit_upload(true, $data_info);
}
if ($task == 'delete') {
if ($module_type == 'aplayer') {
$data = explode(',', $input->getString('data', ''));
if (substr($data[0], 1) == md5($data[1])) {
if (JFile::delete(JPATH_ROOT.'/'.$file_dir.$data[2].'/'.$data[1])) echo "true";
else echo "erreur";
} else echo "chkdsk false !";
}
if ($module_type == 'gallery') {
$data = explode(',', $input->getString('data', ''));
if (JFile::delete(JPATH_ROOT.'/'.$file_dir.'/'.$data[0])) {
$json_name = 'json'.rtrim(strtr(base64_encode($data[0]), '+/', '-_'), '=');
exit_upload('true', $json_name);
} else
exit_upload('false', $json_name);
}
JFactory::getApplication()->close();
}
function exit_upload($status,$datas='') {
$response = array('response'=>$status,'datas'=>$datas);
echo json_encode($response);
JFactory::getApplication()->close();
}