function singleFileUpload(&$errUploadMsg, $file, $post) { $app = JFactory::getApplication();; JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' ); jimport('joomla.client.helper'); $user = JFactory::getUser(); $ftp = JClientHelper::setCredentialsFromRequest('ftp'); $path = PhocaDownloadPath::getPathSet(); $folder = $app->input->get( 'folder', '', '', 'path' ); $format = $app->input->get( 'format', 'html', '', 'cmd'); $return = $app->input->get( 'return-url', null, 'post', 'base64' ); $viewBack = $app->input->get( 'viewback', '', 'post', 'string' ); //$catid = $app->input->get( 'catid', '', '', 'int' ); $paramsC = JComponentHelper::getParams('com_phocadownload') ; $overwriteExistingFiles = $paramsC->get( 'overwrite_existing_files', 0 ); // USER RIGHT - UPLOAD - - - - - - - - - - - // 2, 2 means that user access will be ignored in function getUserRight for display Delete button $rightDisplayUpload = 0; $catAccess = PhocaDownloadAccess::getCategoryAccess((int)$post['catidfiles']); if (!empty($catAccess)) { $rightDisplayUpload = PhocaDownloadAccess::getUserRight('uploaduserid', $catAccess->uploaduserid, 2, $user->getAuthorisedViewLevels(), 1, 0); } // - - - - - - - - - - - - - - - - - - - - - - /*$post['sectionid'] = $this->getSection((int)$post['catidfiles']); if(!$post['sectionid']) { $errUploadMsg = JText::_('COM_PHOCADOWNLOAD_WRONG_SECTION'); return false; }*/ //$userFolder = substr(md5($user->username),0, 10); $userFolder = PhocaDownloadUtils::cleanFolderUrlName(htmlspecialchars(strip_tags($user->username))); if ($rightDisplayUpload == 1) { // Make the filename safe if (isset($file['name'])) { $file['name'] = JFile::makeSafe($file['name']); } if($file['tmp_name'] == '') { $errUploadMsg = JText::_("COM_PHOCADOWNLOAD_ERROR_SERVER_NOT_ABLE_TO_STORE_FILE_TEMP_FOLDER"); return false; } if (isset($file['name'])) { $filepath = JPath::clean($path['orig_abs_user_upload']. DS. $userFolder . DS.$file['name']); $filepathUserFolder = JPath::clean($path['orig_abs_user_upload']. DS. $userFolder); if (!PhocaDownloadFileUpload::canUpload( $file, $errUploadMsg, 'file', 2 )) { if ($errUploadMsg == 'COM_PHOCADOWNLOAD_WARNUSERFILESTOOLARGE') { $errUploadMsg = JText::_($errUploadMsg) . ' ('.PhocaDownloadFile::getFileSizeReadable($file['size']).')'; } else { $errUploadMsg = JText::_($errUploadMsg); } return false; } if (JFile::exists($filepath) && $overwriteExistingFiles == 0) { $errUploadMsg = JText::_("COM_PHOCADOWNLOAD_FILE_ALREADY_EXISTS"); return false; } // Overwrite file and add no new item to database $fileExists = 0; if (JFile::exists($filepath) && $overwriteExistingFiles == 1) { $fileExists = 1; } if (!JFile::upload($file['tmp_name'], $filepath, false, true)) { $errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_UPLOAD_FILE"); return false; } else { // Saving file name into database with relative path if (!JFile::exists($filepathUserFolder . DS ."index.html")) { $data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>"; JFile::write($filepathUserFolder . DS ."index.html", $data); } $file['namepap'] = $file['name']; $file['name'] = 'userupload/'.$userFolder.'/' . $file['name']; $succeeded = false; // ================================================= // Make a copy for play and preview $papCopy = $paramsC->get( 'pap_copy', 0 ); if ($papCopy == 1 || $papCopy == 3) { $canPlay = PhocaDownloadFile::canPlay($file['namepap']); $canPreview = PhocaDownloadFile::canPreview($file['namepap']); $filepathPAP = JPath::clean($path['orig_abs_user_upload_pap']. DS. $userFolder . DS.$file['namepap']); $filepathUserFolderPAP = JPath::clean($path['orig_abs_user_upload_pap']. DS. $userFolder); if ($canPlay || $canPreview) { $uploadPAP = 1;// upload file for preview and play if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 0) { //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_FILE_ALREADY_EXISTS"); //return false; $uploadPAP = 0; // don't upload if it exists, it is not main file, don't do false and exit } // Overwrite file and add no new item to database $fileExistsPAP = 0; if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 1) { $fileExistsPAP = 1; } if ($uploadPAP == 0) { } else { if (!JFolder::exists($filepathUserFolderPAP)) { if (JFolder::create($filepathUserFolderPAP)) { $data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>"; JFile::write($filepathUserFolderPAP . DS ."index.html", $data); } // else { //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_CREATE_FOLDER"); //return false; //} } if (!JFile::copy($filepath, $filepathPAP)) { //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_UPLOAD_FILE"); //return false; } else { // Saving file name into database with relative path if (!JFile::exists($filepathUserFolderPAP . DS ."index.html")) { $data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>"; JFile::write($filepathUserFolderPAP . DS ."index.html", $data); } if ($canPlay == 1) { $post['filename_play'] = 'userupload/'.$userFolder.'/' . $file['namepap']; } else if ($canPreview == 1) { $post['filename_preview'] = 'userupload/'.$userFolder.'/' . $file['namepap']; } } } } } // ============================================== if ($this->_save($post, $file['name'], $errUploadMsg, $fileExists)) { return true; } else { return false; } } } else { $errUploadMsg = JText::_("COM_PHOCADOWNLOAD_WARNFILETYPE"); $redirectUrl = $return; return false; } } else { $errUploadMsg = JText::_("COM_PHOCADOWNLOAD_NOT_AUTHORISED_TO_UPLOAD"); return false; } return false; }
function save($data) { //$data['filesize'] = PhocaDownloadUtils::getFileSize($data['filename'], 0); if ($data['alias'] == '') { $data['alias'] = $data['title']; } //$data['alias'] = PhocaDownloadText::get AliasName($data['alias']); // Initialise variables; $dispatcher = JDispatcher::getInstance(); $table = $this->getTable(); $pk = (!empty($data['id'])) ? $data['id'] : (int)$this->getState($this->getName().'.id'); $isNew = true; // Include the content plugins for the on save events. JPluginHelper::importPlugin('content'); // Load the row if saving an existing record. if ($pk > 0) { $table->load($pk); $isNew = false; } // ================================================= // Make a copy for play and preview $paramsC = JComponentHelper::getParams('com_phocadownload') ; $papCopy = $paramsC->get( 'pap_copy', 0 ); $overwriteExistingFiles = $paramsC->get( 'overwrite_existing_files', 0 ); $path = PhocaDownloadPath::getPathSet(); if ($papCopy == 2 || $papCopy == 3) { $canPlay = PhocaDownloadFile::canPlay($data['filename']); $canPreview = PhocaDownloadFile::canPreview($data['filename']); $filepath = JPath::clean($path['orig_abs_ds'] . DS.$data['filename']); $filepathPAP = JPath::clean($path['orig_abs_pap_ds'] . DS.$data['filename']); $filepathPAPFolder = JPath::clean($path['orig_abs_pap_ds'] . DS. PhocaDownloadFile::getFolderFromTheFile($data['filename'])); if ($canPlay || $canPreview) { $uploadPAP = 1;// upload file for preview and play if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 0) { //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_FILE_ALREADY_EXISTS"); //return false; $uploadPAP = 0; // don't upload if it exists, it is not main file, don't do false and exit if ($canPlay == 1) { // set new file only no other is set if ($data['filename_play'] != '') { $uploadPAP = 0; } else { $data['filename_play'] = $data['filename']; } } else if ($canPreview == 1) { // set new file only no other is set if ($data['filename_preview'] != '') { $uploadPAP = 0; } else { $data['filename_preview'] = $data['filename']; } } } // Overwrite file and add no new item to database $fileExistsPAP = 0; if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 1) { $fileExistsPAP = 1; if ($canPlay == 1) { // set new file only no other is set or it is the same like currect - to overwrite updated version of the same file if ($data['filename_play'] == '' || $data['filename_play'] == $data['filename']) { $data['filename_play'] = $data['filename']; } else { $uploadPAP = 0; } } else if ($canPreview == 1) { // set new file only no other is set or it is the same like currect - to overwrite updated version of the same file if ($data['filename_preview'] == '' || $data['filename_preview'] == $data['filename']) { $data['filename_preview'] = $data['filename']; } else { $uploadPAP = 0; } } } if ($uploadPAP == 0) { } else { if (!JFolder::exists($filepathPAPFolder)) { if (JFolder::create($filepathPAPFolder)) { $dataFile = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>"; JFile::write($filepathPAPFolder . DS ."index.html", $dataFile); } // else { //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_CREATE_FOLDER"); //return false; //} } if (!JFile::copy($filepath, $filepathPAP)) { //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_UPLOAD_FILE"); //return false; } else { if ($canPlay == 1) { $data['filename_play'] = $data['filename']; } else if ($canPreview == 1) { $data['filename_preview'] = $data['filename']; } } } } } // ============================================== // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Date - - - - - $nullDate = $this->_db->getNullDate(); $config = JFactory::getConfig(); $tzoffset = $config->get('offset'); //$date = JFactory::getDate($table->date, $tzoffset); //$table->date = $date->toSql(); // Append time if not added to publish date //if (strlen(trim($table->publish_up)) <= 10) { // $table->publish_up .= ' 00:00:00'; //} //$date = JFactory::getDate($table->publish_up, $tzoffset); //$table->publish_up = $date->toSql(); if ($table->id) { // Test Solution add date when it is removed if (!intval($table->date)) { $date = JFactory::getDate(); $table->date = $date->toSql(); } } else { if (!intval($table->date)) { $date = JFactory::getDate(); $table->date = $date->toSql(); } } if(intval($table->publish_up) == 0) { $table->publish_up = JFactory::getDate()->toSql(); } // Handle never unpublish date if (trim($table->publish_down) == JText::_('Never') || trim( $table->publish_down ) == '') { $table->publish_down = $nullDate; } else { if (strlen(trim( $table->publish_down )) <= 10) { $table->publish_down .= ' 00:00:00'; } //$date = JFactory::getDate($table->publish_down, $tzoffset); $date = JFactory::getDate($table->publish_down); $table->publish_down = $date->toSql(); } // - - - - - - // if new item, order last in appropriate group if (!$table->id) { $where = 'catid = ' . (int) $table->catid ; $table->ordering = $table->getNextOrder( $where ); } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onContentBeforeSave event. /* $result = $dispatcher->trigger($this->event_before_save, array($this->option.'.'.$this->name, $table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } */ // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } // Store to ref table if (!isset($data['tags'])) { $data['tags'] = array(); } if ((int)$table->id > 0) { PhocaDownloadTag::storeTags($data['tags'], (int)$table->id); } // Clean the cache. $cache = JFactory::getCache($this->option); $cache->clean(); // Trigger the onContentAfterSave event. //$dispatcher->trigger($this->event_after_save, array($this->option.'.'.$this->name, $table, $isNew)); $pkName = $table->getKeyName(); if (isset($table->$pkName)) { $this->setState($this->getName().'.id', $table->$pkName); } $this->setState($this->getName().'.new', $isNew); return true; }
protected function _copyPreviewAndPlay($filename, $storedfilename, $storedfoldername, $path, $overwriteExistingFiles) { $o['filename_play'] = ''; $o['filename_preview'] = ''; $canPlay = PhocaDownloadFile::canPlay($filename); $canPreview = PhocaDownloadFile::canPreview($filename); $filepathPAP = JPath::clean($path['orig_abs_pap_ds'] . $storedfilename); //$filepathUserFolderPAP = JPath::clean($path['orig_abs_pap_ds']. $storedfoldername); $filepath = JPath::clean($path['orig_abs_ds'] . $storedfilename); $filepathPAPFolder = JPath::clean($path['orig_abs_pap_ds'] . DS . PhocaDownloadFile::getFolderFromTheFile($storedfilename)); if ($canPlay || $canPreview) { $uploadPAP = 1; // upload file for preview and play if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 0) { //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_FILE_ALREADY_EXISTS"); //return false; $uploadPAP = 0; // don't upload if it exists, it is not main file, don't do false and exit if ($canPlay == 1) { $o['filename_play'] = $storedfilename; } else { if ($canPreview == 1) { $o['filename_preview'] = $storedfilename; } } } // Overwrite file and add no new item to database $fileExistsPAP = 0; if (JFile::exists($filepathPAP) && $overwriteExistingFiles == 1) { $fileExistsPAP = 1; if ($canPlay == 1) { $o['filename_play'] = $storedfilename; } else { if ($canPreview == 1) { $o['filename_preview'] = $storedfilename; } } } if ($uploadPAP == 0) { } else { // First create folder if not exists if (!JFolder::exists($filepathPAPFolder)) { if (JFolder::create($filepathPAPFolder)) { $data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>"; JFile::write($filepathPAPFolder . DS . "index.html", $data); } // else { //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_CREATE_FOLDER"); //return false; //} } if (!JFile::copy($filepath, $filepathPAP)) { //$errUploadMsg = JText::_("COM_PHOCADOWNLOAD_UNABLE_TO_UPLOAD_FILE"); //return false; } else { // Saving file name into database with relative path /*if (!JFile::exists($filepathUserFolderPAP . DS ."index.html")) { $data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>"; JFile::write($filepathUserFolderPAP . DS ."index.html", $data); }*/ if ($canPlay == 1) { //$image->filename_play = $storedfilename; $o['filename_play'] = $storedfilename; } else { if ($canPreview == 1) { //$image->filename_preview = $storedfilename; $o['filename_preview'] = $storedfilename; } } } } } return $o; }