Example #1
0
 public function Show()
 {
     // Load into <head> needed js only once and only if upload feature is enabled
     if (!(bool) $this->Params->get("uploaddisplay")) {
         return "";
     }
     if (!isset($GLOBALS[$GLOBALS["ext_name"] . '_upload_js_loaded'])) {
         $placeholders = $values = array();
         $placeholders[] = '{%BROWSE_FILES%}';
         $placeholders[] = '{%FLOAT%}';
         $placeholders[] = '{%JCANCEL%}';
         $placeholders[] = '{%FAILED%}';
         $placeholders[] = '{%SUCCESS%}';
         $placeholders[] = '{%Action%}';
         $values[] = JTEXT::_($GLOBALS["COM_NAME"] . '_BROWSE_FILES');
         $values[] = $GLOBALS["left"];
         $values[] = JTEXT::_('JCANCEL');
         $values[] = JTEXT::_($GLOBALS["COM_NAME"] . '_FAILED');
         $values[] = JTEXT::_($GLOBALS["COM_NAME"] . '_SUCCESS');
         // Use "/" instead of "DS", since this string is used on client side in Javascript createUploader function
         $values[] = JURI::base(true) . '/components/' . $GLOBALS["com_name"] . '/lib/file-uploader.php';
         // Show main uploader javascript in <head> section as a source
         $this->js_load("fileuploader-min.js", 1, 0, $placeholders, $values);
         $GLOBALS[$GLOBALS["ext_name"] . '_upload_js_loaded'] = true;
     }
     $id = $this->GetId();
     //$cid = ((bool)$this->Application->mid) ? 0 : $this->GetComponentId();
     $result = '<div style="clear:both;">' . '<label ' . 'style="' . '">' . $this->Params->get('upload') . ". " . JTEXT::_($GLOBALS["COM_NAME"] . '_FILE_SIZE_LIMIT') . " " . $this->human_readable($this->Params->get("uploadmax_file_size") * 1024) . '</label>' . '<div id="foxupload_' . $id . '" ' . '></div>' . PHP_EOL . "<script language=\"javascript\" type=\"text/javascript\">createUploader('foxupload_{$id}', " . $this->Application->cid . ", " . $this->Application->mid . ");</script>" . '<noscript>' . '<input ' . 'type="file" ' . 'name="foxstdupload"' . " />" . '</noscript>';
     $jsession = JFactory::getSession();
     $fsession = new FSession($jsession->getId(), $this->Application->cid, $this->Application->mid);
     $data = $fsession->Load('filelist');
     // Read the list from the session
     if ($data) {
         $filelist = explode("|", $data);
     } else {
         $filelist = array();
     }
     if (count($filelist)) {
         // Previuosly completed uploads
         $result .= '<ul class="qq-upload-list">';
         foreach ($filelist as &$file) {
             $result .= '<li class="qq-upload-success" style="background-position:' . $GLOBALS["left"] . ';">' . '<span class="qq-upload-file" style="float:' . $GLOBALS["left"] . '">' . substr($file, 14) . '</span>' . '<span class="qq-upload-success-text" style="background-position:' . $GLOBALS["left"] . ';">' . JTEXT::_($GLOBALS["COM_NAME"] . '_SUCCESS') . '</span>' . '</li>';
         }
         $result .= '</ul>' . PHP_EOL;
     }
     // Close row container
     $result .= "</div>" . PHP_EOL;
     return $result;
 }
Example #2
0
 public function Show()
 {
     if (!(bool) $this->Params->get("uploaddisplay")) {
         return "";
     }
     $id = $this->GetId();
     //$cid = ((bool)$this->Application->mid) ? 0 : $this->GetComponentId();
     $action = JRoute::_("index.php?option=" . $GLOBALS["com_name"] . "&view=loader" . "&owner=" . $this->Application->owner . "&id=" . $this->Application->oid . "&root=none" . "&filename=none" . "&type=uploader");
     $label = "";
     $span = "";
     // Label beside: generates a label
     if ((bool) $this->Params->get("labelsdisplay")) {
         $label = '<label class="control-label">' . $this->Params->get('upload') . '</label>';
     } else {
         $span = '<span class="help-block">' . $this->Params->get('upload') . '</span>';
     }
     $result = '<div class="control-group">' . $label . '<div class="controls">' . $span . '<div id="foxupload_' . $id . '"></div>' . '<span class="help-block">' . JText::_($GLOBALS["COM_NAME"] . '_FILE_SIZE_LIMIT') . " " . $this->human_readable($this->Params->get("uploadmax_file_size") * 1024) . '</span>' . '</div>' . "<script language=\"javascript\" type=\"text/javascript\">" . "jQuery(document).ready(function () {" . "if (typeof Joomla == 'undefined')" . "{" . "\tJoomla = {};" . "\tJoomla.JText =" . "\t{" . "\t\tstrings:{}," . "\t\t'_':function (key, def)" . "\t\t{" . "\t\t\treturn typeof this.strings[key.toUpperCase()] !== 'undefined' ? this.strings[key.toUpperCase()] : def;" . "\t\t}," . "\t\tload:function (object)" . "\t\t{" . "\t\t\tfor (var key in object)" . "\t\t\t{" . "\t\t\t\tthis.strings[key.toUpperCase()] = object[key];" . "\t\t\t}" . "\t\t\treturn this;" . "\t\t}" . "\t};" . "}" . "Joomla.JText.load(" . "{" . "\"COM_FOXCONTACT_BROWSE_FILES\":'" . JText::_("COM_FOXCONTACT_BROWSE_FILES") . "'," . "\"JCANCEL\":'" . JText::_("JCANCEL") . "'," . "\"COM_FOXCONTACT_FAILED\":'" . JText::_("COM_FOXCONTACT_FAILED") . "'," . "\"COM_FOXCONTACT_SUCCESS\":'" . JText::_("COM_FOXCONTACT_SUCCESS") . "'," . "\"COM_FOXCONTACT_NO_RESULTS_MATCH\":'" . JText::_("COM_FOXCONTACT_NO_RESULTS_MATCH") . "'" . "}" . ");" . "CreateUploadButton('foxupload_{$id}', '{$action}', " . $this->Application->cid . ", " . $this->Application->mid . ", '" . $this->Application->owner . "', " . $this->Application->oid . ");" . "});" . "</script>" . '<noscript>' . '<input ' . 'type="file" ' . 'name="foxstdupload"' . " />" . '</noscript>' . "</div>" . PHP_EOL;
     // control-group
     $jsession = JFactory::getSession();
     $fsession = new FSession($jsession->getId(), $this->Application->cid, $this->Application->mid);
     $data = $fsession->Load('filelist');
     // Read the list from the session
     if ($data) {
         $filelist = explode("|", $data);
     } else {
         $filelist = array();
     }
     // List of files
     $result .= '<div class="control-group">' . '<div class="controls">';
     // Previuosly completed uploads
     $result .= '<ul id="uploadlist-' . $this->Application->owner . $this->Application->oid . '" class="qq-upload-list">';
     foreach ($filelist as &$file) {
         $result .= '<li class="qq-upload-success">' . '<span class="qq-upload-file">' . $this->format_filename(substr($file, 14)) . '</span>' . '<span class="qq-upload-success-text">' . JTEXT::_($GLOBALS["COM_NAME"] . '_SUCCESS') . '</span>' . '</li>';
     }
     $result .= '</ul>' . PHP_EOL;
     $result .= '</div>' . '</div>' . PHP_EOL;
     // control-group
     return $result;
 }
Example #3
0
 protected function DoUpload()
 {
     //Retrieve file details from uploaded file, sent from upload form
     $file = JRequest::getVar('foxstdupload', NULL, 'files', 'array');
     // $file is null when a browser with javascipt didn't send $_FILES at all
     // $file['error'] is UPLOAD_ERR_NO_FILE when a browser without javascipt sent $_FILES empty
     if (!$this->Submitted || !$file || $file['error'] == UPLOAD_ERR_NO_FILE) {
         return true;
     }
     $upload_directory = JPATH_SITE . "/components/" . $GLOBALS["com_name"] . "/uploads/";
     if (!is_writable($upload_directory)) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_DIR_NOT_WRITABLE'), FoxMessageBoard::error);
         return false;
     }
     // Check for http $_FILES upload errors
     if ($file['error']) {
         // case 1 UPLOAD_ERR_INI_SIZE: 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
         // case 2 UPLOAD_ERR_FORM_SIZE: 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
         // case 3 UPLOAD_ERR_PARTIAL: 'The uploaded file was only partially uploaded';
         // case 4 UPLOAD_ERR_NO_FILE: 'No file was uploaded';
         // case 6 UPLOAD_ERR_NO_TMP_DIR: 'Missing a temporary folder';
         // case 7 UPLOAD_ERR_CANT_WRITE: 'Failed to write file to disk';
         // case 8 UPLOAD_ERR_EXTENSION: 'File upload stopped by extension';
         $this->MessageBoard->Add(JText::sprintf($GLOBALS["COM_NAME"] . '_ERR_UPLOAD', $file['error']), FoxMessageBoard::error);
         return false;
     }
     // Check file size
     $size = $file['size'];
     if ($size == 0) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_FILE_EMPTY'), FoxMessageBoard::error);
         return false;
     }
     $max_filesize = intval($this->Params->get("uploadmax_file_size", "0")) * KB;
     if ($size > $max_filesize) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_FILE_TOO_LARGE'), FoxMessageBoard::error);
         return false;
     }
     $mimetype = new FMimeType();
     if (!$mimetype->Check($file['tmp_name'], $this->Params)) {
         // Noo need to delete the file uploaded
         //unlink($file['tmp_name']);
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_MIME') . " [" . $mimetype->Mimetype . "]", FoxMessageBoard::error);
         return false;
     }
     //Import filesystem libraries. Perhaps not necessary, but does not hurt
     jimport('joomla.filesystem.file');
     //Clean up filename to get rid of strange characters like spaces and others
     $filename = JFile::makeSafe($file['name']);
     // Assign a random unique id to the file name, to avoid that lamers can force the server to execute their uploaded shit
     $filename = uniqid() . "-" . $filename;
     $dest = $upload_directory . $filename;
     // Todo: This attempt doesn't intercept the exception
     /*
     try
     {
     JFile::upload($file['tmp_name'], $dest);
     }
     catch (Exception $e)
     {
     //$e->getMessage()
     return false;
     }
     */
     if (!JFile::upload($file['tmp_name'], $dest)) {
         return false;
     }
     // Upload successful. Add an element to the uploads list
     $jsession =& JFactory::getSession();
     $fsession = new FSession($jsession->getId(), $this->Application->cid, $this->Application->mid);
     // session_id, cid, mid
     // Store the answer in the session
     $data = $fsession->Load('filelist');
     // Read the list from the session
     if ($data) {
         $filelist = explode("|", $data);
     } else {
         $filelist = array();
     }
     $filelist[] = $filename;
     // Append this file to the list
     $data = implode("|", $filelist);
     $fsession->Save($data, "filelist");
     return true;
 }
Example #4
0
 public function HandleUpload($uploadDirectory)
 {
     $this->DebugLog->Write("HandleUpload() started");
     if (!is_writable($uploadDirectory)) {
         $this->DebugLog->Write("Directory " . $uploadDirectory . " is not writable");
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_DIR_NOT_WRITABLE'));
     }
     $this->DebugLog->Write("Directory " . $uploadDirectory . " is ok");
     // Check file size
     $size = $this->get_file_size();
     if ($size == 0) {
         $this->DebugLog->Write("File size is 0");
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_FILE_EMPTY'));
     }
     $this->DebugLog->Write("File size is > 0");
     // uploadmax_file_size defaults to 0 to prevent hack attempts
     $max = $this->Params->get("uploadmax_file_size", 0) * KB;
     // and < max limit
     if ($size > $max) {
         $this->DebugLog->Write("File size too large ({$size} > {$max})");
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_FILE_TOO_LARGE'));
     }
     $this->DebugLog->Write("File size ({$size} / {$max}) is ok");
     // Clean file name
     $filename = preg_replace("/[^\\w\\.-_]/", "_", $this->get_file_name());
     // Assign a random unique id to the file name, to avoid that lamers can force the server to execute their uploaded shit
     $filename = uniqid() . "-" . $filename;
     $full_filename = $uploadDirectory . $filename;
     if (!$this->save_file($full_filename)) {
         $this->DebugLog->Write("Error saving file");
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_SAVE_FILE'));
     }
     $this->DebugLog->Write("File saved");
     $mimetype = new FMimeType();
     if (!$mimetype->Check($full_filename, $this->Params)) {
         // Delete the file uploaded
         unlink($full_filename);
         $this->DebugLog->Write("File type [" . $mimetype->Mimetype . "] is not allowed. Allowed types are:" . PHP_EOL . print_r($mimetype->Allowed, true));
         return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_MIME') . " [" . $mimetype->Mimetype . "]");
     }
     $this->DebugLog->Write("File type [" . $mimetype->Mimetype . "] is allowed");
     $cid = JFactory::getApplication()->input->get("cid", NULL);
     $mid = JFactory::getApplication()->input->get("mid", NULL);
     $owner = JFactory::getApplication()->input->get("owner", NULL);
     $id = JFactory::getApplication()->input->get("id", NULL);
     $jsession = JFactory::getSession();
     $fsession = new FSession($jsession->getId(), $cid, $mid);
     // Store the answer in the session
     $data = $fsession->Load('filelist');
     // Read the list from the session
     if ($data) {
         $filelist = explode("|", $data);
     } else {
         $filelist = array();
     }
     $filelist[] = $filename;
     // Append this file to the list
     $data = implode("|", $filelist);
     $fsession->Save($data, "filelist");
     $this->Log->Write("File " . $filename . " uploaded succesful.");
     $this->DebugLog->Write("File uploaded succesful.");
     return array("success" => true);
 }
Example #5
0
	// Fields properties
	$captcha['show'] = (bool)$params->get("stdcaptchadisplay");
	// $captcha['label'] = $params->get("stdcaptcha");
	$captcha['src'] = JURI::base(true) . '/components/com_foxcontact/lib/captcha-drawer.php?cid=0&mid=' . $module->id;
	$captcha['transparent'] = JURI::base(true) . '/media/com_foxcontact/images/transparent.gif';
	//$captcha['id'] = 'fcaptcha_mid_' . $module->id;
	$captcha['width'] = $params->get("stdcaptchawidth", "");
	$captcha['height'] = $params->get("stdcaptchaheight", "");

	$upload['show'] = (bool)$params->get("uploaddisplay");
	$direction = intval(JFactory::getLanguage()->get('rtl', 0));
	$style['float'] = $direction ? "right" : "left";
	$upload['label'] = $params->get("upload");
	$jsession = JFactory::getSession();
	$fsession = new FSession($jsession->getId(), 0, $module->id);
	$data = $fsession->Load('filelist');  // Read the list from the session
	if ($data) $upload['filelist'] = explode("|", $data);
	else $upload['filelist'] = array();

	if (intval($params->get("top_textdisplay", "0"))) $toptext = $params->get("top_text", "");	
	else $toptext = "";
	if (!empty($toptext)) $toptext = '<div class="foxmessage" style="clear:both;">' . $toptext . '</div>';

	if (intval($params->get("bottom_textdisplay", "0"))) $bottomtext = $params->get("bottom_text", "");	
	else $bottomtext = "";
	if (!empty($bottomtext)) $bottomtext = '<div class="foxmessage" style="clear:both;">' . $bottomtext . '</div>';

	$page_subheading = $params->get("page_subheading", "");

	// Module xml
	$xml = JFactory::getXML(JPATH_SITE . DS . 'modules' . DS . $app->scope . DS . $app->scope . '.xml');