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; }