Пример #1
0
 public static function getUploader($id = 'uploader', $settings = array())
 {
     $jrequest = JFactory::getApplication()->input;
     $settings = array_merge(self::$settings, $settings);
     $debug = $settings['debug'];
     $config = JFactory::getConfig();
     $doc = JFactory::getDocument();
     $doc->addStyleSheet('//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css');
     $doc->addStyleSheet(JURI::root(true) . '/components/com_djcatalog2/assets/upload/jquery.ui.plupload/css/jquery.ui.plupload.css');
     JHTML::_('behavior.framework', true);
     $version = new JVersion();
     if (version_compare($version->getShortVersion(), '3.0.0', '<')) {
         $doc->addScript('//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js');
         $doc->addScript(JURI::root(true) . '/components/com_djcatalog2/assets/upload/jquery.noconflict.js');
     } else {
         JHtml::_('bootstrap.framework');
     }
     $doc->addScript('//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js');
     $doc->addScript('//bp.yahooapis.com/2.4.21/browserplus-min.js');
     $doc->addScript(JURI::root(true) . '/components/com_djcatalog2/assets/upload/plupload.full.js');
     $doc->addScript(JURI::root(true) . '/components/com_djcatalog2/assets/upload/jquery.ui.plupload/jquery.ui.plupload.js');
     $component = $jrequest->get('option');
     $url = $settings['url'];
     if (!$url) {
         $url = JURI::base(true) . '/index.php?option=' . $component . '&task=multiupload&tmpl=component';
     }
     $js = "\t\t\t\n\t\t\tjQuery(function(){\n\t\t\t\t\n\t\t\t\tplupload.addI18n({\n\t\t\t\t\t'Select files' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_HEADER')) . "',\n\t\t\t\t\t'Add files to the upload queue and click the start button.' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_DESC')) . "',\n\t\t\t\t\t'Filename' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_FILENAME')) . "',\n\t\t\t\t\t'Status' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_STATUS')) . "',\n\t\t\t\t\t'Size' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_SIZE')) . "',\n\t\t\t\t\t'Add Files' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_ADD_FILES')) . "',\n\t\t\t\t\t'Stop current upload' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_STOP_CURRENT_UPLOAD')) . "',\n\t\t\t\t\t'Start uploading queue' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_START_UPLOADING_QUEUE')) . "',\n\t\t\t\t\t'Uploaded %d/%d files': '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_UPLOADED_N_FILES')) . "',\n\t\t\t\t\t'N/A' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_NA')) . "',\n\t\t\t\t\t'Drag files here.' : '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_DRAG_AND_DROP_TEXT')) . "',\n\t\t\t\t\t'Stop Upload': '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_STOP_UPLOAD')) . "',\n\t\t\t\t\t'Start Upload': '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_START_UPLOAD')) . "',\n\t\t\t\t\t'%d files queued': '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_N_FILES_QUEUED')) . "',\n\t\t\t\t\t'File extension error.': '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_EXT_ERROR')) . "',\n\t\t\t\t\t'File size error.': '" . addslashes(JText::_('COM_DJCATALOG2_UPLOADER_SIZE_ERROR')) . "'\n\t\t\t\t});\n\t\t\t});\n\t\t";
     if (self::$scripts_included == false) {
         $doc->addScriptDeclaration($js);
         self::$scripts_included = true;
     }
     $js = 'jQuery(function(){ ';
     if ($debug) {
         $js .= "\n\t\t\t\tfunction eventlog() {\n\t\t\t\t\tvar str = '';\t\t\t\n\t\t\t\t\tplupload.each(arguments, function(arg) {\n\t\t\t\t\t\tvar row = '';\t\t\t\n\t\t\t\t\t\tif (typeof(arg) != 'string') {\n\t\t\t\t\t\t\tplupload.each(arg, function(value, key) {\n\t\t\t\t\t\t\t\t// Convert items in File objects to human readable form\n\t\t\t\t\t\t\t\tif (arg instanceof plupload.File) {\n\t\t\t\t\t\t\t\t\t// Convert status to human readable\n\t\t\t\t\t\t\t\t\tswitch (value) {\n\t\t\t\t\t\t\t\t\t\tcase plupload.QUEUED:\n\t\t\t\t\t\t\t\t\t\t\tvalue = 'QUEUED';\n\t\t\t\t\t\t\t\t\t\t\tbreak;\t\t\t\n\t\t\t\t\t\t\t\t\t\tcase plupload.UPLOADING:\n\t\t\t\t\t\t\t\t\t\t\tvalue = 'UPLOADING';\n\t\t\t\t\t\t\t\t\t\t\tbreak;\t\t\t\n\t\t\t\t\t\t\t\t\t\tcase plupload.FAILED:\n\t\t\t\t\t\t\t\t\t\t\tvalue = 'FAILED';\n\t\t\t\t\t\t\t\t\t\t\tbreak;\t\t\t\n\t\t\t\t\t\t\t\t\t\tcase plupload.DONE:\n\t\t\t\t\t\t\t\t\t\t\tvalue = 'DONE';\n\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\t\t\t\n\t\t\t\t\t\t\t\tif (typeof(value) != 'function') {\n\t\t\t\t\t\t\t\t\trow += (row ? ', ': '') + key + '=' + value;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\t\t\t\n\t\t\t\t\t\t\tstr += row + ' ';\n\t\t\t\t\t\t} else { \n\t\t\t\t\t\t\tstr += arg + ' ';\n\t\t\t\t\t\t}\n\t\t\t\t\t});\t\t\t\n\t\t\t\t\tconsole.log(str);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t";
     }
     $js .= "\n\t\t\t\tvar uploader{$id} = jQuery('#{$id}').plupload({\n\t\t\t\t\t// General settings\n\t\t\t\t\truntimes : 'gears,browserplus,html5,silverlight,flash,html4',\n\t\t\t\t\turl : '{$url}',\n\t\t\t\t\tmax_file_size : '" . $settings['max_file_size'] . "',\n\t\t\t\t\tchunk_size : '" . $settings['chunk_size'] . "',\n\t\t\t\t\tunique_names : true,";
     if ($settings['resize']) {
         $js .= "\n\t\t\t\t\t// Resize images on clientside if we can\n\t\t\t\t\tresize : {width : " . $settings['width'] . ", height : " . $settings['height'] . ", quality : " . $settings['quality'] . "},";
     }
     $js .= "\n\t\t\t\t\t// Specify what files to browse for\n\t\t\t\t\tfilters : [\n\t\t\t\t\t\t{title : 'Allowed files', extensions : '" . $settings['filter'] . "'}\n\t\t\t\t\t],\n\n\t\t\t\t\t// Flash settings\n\t\t\t\t\tflash_swf_url : '" . JURI::root(true) . "/components/{$component}/assets/upload/plupload.flash.swf',\n\n\t\t\t\t\t// Silverlight settings\n\t\t\t\t\tsilverlight_xap_url : '" . JURI::root(true) . "/components/{$component}/assets/upload/plupload.silverlight.xap',";
     if ($debug) {
         $js .= "\n\t\t\t\t\t// PreInit events, bound before any internal events\n\t\t\t\t\tpreinit: {\n\t\t\t\t\t\tInit: function(up, info) {\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[Init]', 'Info:', info, 'Features:', up.features);" : "") . "\n\t\t\t\t\t\t},\n\t\t\t\t\t\tUploadFile: function(up, file) {\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[UploadFile]', file);" : "") . "\n\t\t\t\n\t\t\t\t\t\t\t// You can override settings before the file is uploaded\n\t\t\t\t\t\t\t// up.settings.url = 'upload.php?id=' + file.id;\n\t\t\t\t\t\t\t// up.settings.multipart_params = {param1: 'value1', param2: 'value2'};\n\t\t\t\t\t\t}\n\t\t\t\t\t},";
     }
     $js .= "\n\t\t\t\t\t// Post init events, bound after the internal events\n\t\t\t\t\tinit: {\n\t\t\t\t\t\tFilesAdded: function(up, files) {\n\t\t\t\t\t\t\t// Called when files are added to queue\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[FilesAdded]');" : "") . "\n\t\t\t\t\t\t\t" . ($settings['onAddedEvent'] ? $settings['onAddedEvent'] . '(up,files);' : '');
     if ($debug) {
         $js .= "\n\t\t\t\t\t\t\tplupload.each(files, function(file) {\n\t\t\t\t\t\t\t\teventlog('  File:', file);\n\t\t\t\t\t\t\t});";
     }
     $js .= "\n\t\t\t\t\t\t},\n\t\t\t\t\t\tFileUploaded: function(up, file, info) {\n\t\t\t\t\t\t\t// Called when a file has finished uploading\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[FileUploaded] File:', file, 'Info:', info);" : "") . "\n\t\t\t\t\t\t\t" . ($settings['onUploadedEvent'] ? 'return ' . $settings['onUploadedEvent'] . '(up,file,info);' : '') . "\n\t\t\t\t\t\t}";
     if ($debug) {
         $js .= ",\t\t\t\t\n\t\t\t\t\t\tRefresh: function(up) {\n\t\t\t\t\t\t\t// Called when upload shim is moved\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[Refresh]');" : "") . "\n\t\t\t\t\t\t},\n\t\t\t\t\t\tStateChanged: function(up) {\n\t\t\t\t\t\t\t// Called when the state of the queue is changed\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[StateChanged]', up.state == plupload.STARTED ? 'STARTED': 'STOPPED');" : "") . "\n\t\t\t\t\t\t},\n\t\t\t\t\t\tQueueChanged: function(up) {\n\t\t\t\t\t\t\t// Called when the files in queue are changed by adding/removing files\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[QueueChanged]');" : "") . "\n\t\t\t\t\t\t},\n\t\t\t\t\t\tUploadProgress: function(up, file) {\n\t\t\t\t\t\t\t// Called while a file is being uploaded\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[UploadProgress]', 'File:', file, 'Total:', up.total);" : "") . "\n\t\t\t\t\t\t},\n\t\t\t\t\t\tFilesRemoved: function(up, files) {\n\t\t\t\t\t\t\t// Called when files where removed from queue\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[FilesRemoved]');" : "") . "\n\t\t\t\n\t\t\t\t\t\t\tplupload.each(files, function(file) {\n\t\t\t\t\t\t\t\t" . ($debug ? "eventlog('  File:', file);" : "") . "\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t},\t\t\t\t\t\t\n\t\t\t\t\t\tChunkUploaded: function(up, file, info) {\n\t\t\t\t\t\t\t// Called when a file chunk has finished uploading\n\t\t\t\t\t\t\t" . ($debug ? "eventlog('[ChunkUploaded] File:', file, 'Info:', info);" : "") . "\n\t\t\t\t\t\t},\n\t\t\t\t\t\tError: function(up, args) {\n\t\t\t\t\t\t\t// Called when a error has occured\n\t\t\t\n\t\t\t\t\t\t\t// Handle file specific error and general error\n\t\t\t\t\t\t\tif (args.file) {\n\t\t\t\t\t\t\t\t" . ($debug ? "eventlog('[error]', args, 'File:', args.file);" : "") . "\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t" . ($debug ? "eventlog('[error]', args);" : "") . "\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}";
     }
     $js .= "\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t";
     $doc->addScriptDeclaration($js);
     $html = '<div id="' . $id . '"><p>You browser doesn\'t support Gears, BrowserPlus, HTML5, Flash, Silverlight and even HTML4! Please upgrade your browser!</p></div>';
     return $html;
 }
Пример #2
0
 public function multiupload()
 {
     // todo: secure upload from injections
     $user = JFactory::getUser();
     if (!$user->authorise('core.manage', 'com_djcatalog2')) {
         echo JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN');
         exit(0);
     }
     DJCatalog2UploadHelper::upload();
     return true;
 }
Пример #3
0
?>
" class="djc_uploader_item_simple" style="display:none;">
				<td colspan="4">
					<input type="file" name="<?php 
echo $prefix;
?>
_file_upload[]" />
				</td>
			</tr>
			<tr>
				<td colspan="4">
					<?php 
if ($multiple_upload) {
    ?>
						<?php 
    echo DJCatalog2UploadHelper::getUploader($uploader_id, $settings);
    ?>
					<?php 
} else {
    ?>
						<button id="add_<?php 
    echo $suffix;
    ?>
_button" class="btn button" onclick="DJCatalog2UPAddUploader('<?php 
    echo $suffix;
    ?>
', '<?php 
    echo $wrapper_id;
    ?>
'); return false;"><?php 
    echo JText::_('COM_DJCATALOG2_ADD_FILE_LINK');