Exemplo n.º 1
0
	function _save($data, $filename, &$errSaveMsg, $fileExists = 0) {
	
		$user 	= JFactory::getUser();
		$fileId = false;
		if ($fileExists == 1) {
			// We not only owerwrite the file but we must update it
			if (isset($filename) && $filename != '') {
				
				$db = JFactory::getDBO();
				
				$query = 'SELECT a.id AS id'
				.' FROM #__phocadownload AS a'
			    .' WHERE a.filename = '.$db->Quote($filename);

				$db->setQuery($query, 0, 1);
				$fileId = $db->loadObject();
				
				if (!$db->query()) {
					$this->setError($db->getErrorMsg());
					return false;
				}
			}
		}

		$row = $this->getTable('phocadownload');
		
		if (isset($fileId->id) && (int)$fileId->id > 0) {
			$data['id'] = (int)$fileId->id;
		}
		
	

		$data['filesize'] 	= PhocaDownloadFile::getFileSize($filename, 0);
		
		$data['userid']			= $user->id;
		$data['author_email']	= $data['email'];
		$data['author_url']		= $data['website'];
		
		$data['token']			= PhocaDownloadUtils::getToken($data['title'].$filename);
		//$data['token']			= PhocaDownloadUtils::getToken($data['title'].$data['filename']);
		
		// Bind the form fields to the Phoca gallery table
		if (!$row->bind($data)) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}
		
		

		// Create the timestamp for the date
		//$row->date 			= gmdate('Y-m-d H:i:s');
		//$row->publish_up	= gmdate('Y-m-d H:i:s');
		//$jnow		=JFactory::getDate();
		/*$jnowU		= $jnow->toUnix();
		if (isset($jnowU)) {
			$jnowU = (int)$jnowU - 2; // to not display pending because of 1 second
		}*/
		
		$unow		= time();
		$unow		= $unow - 2;//Frontend will display pending if standard $jnow->toSql(); will be used
		$jnow		= JFactory::getDate($unow);// the class JDate construct works with unix date
		$now		= $jnow->toSql();
		
		$row->date 			= $now;
		$row->publish_up	= $now; //date('Y-m-d H:i:s', $jnowU);
		$row->publish_down	= null;
		$row->filename	= $filename;
		$row->catid		= $data['catidfiles'];
		
		// Lang
		$userLang			= PhocaDownloadUser::getUserLang();
		$row->language		= $userLang['lang'];


		// if new item, order last in appropriate group
		if (!$row->id) {
			$where = 'catid = ' . (int) $row->catid ;
			$row->ordering = $row->getNextOrder( $where );
		}

		// Make sure the Phoca gallery table is valid
		if (!$row->check()) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}

		// Store the Phoca gallery table to the database
		if (!$row->store()) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}
		
		PhocaDownloadLog::log($row->id, 2);
		
		return true;
	}
Exemplo n.º 2
0
 protected function _addAllFilesFromFolder(&$existingImages, $category_id, $fullPath, $rel_path, $data = array())
 {
     $count = 0;
     $fileList = JFolder::files($fullPath);
     natcasesort($fileList);
     // Iterate over the files if they exist
     //file - abc.img, file_no - folder/abc.img
     // Make a copy for play and preview (1) --------
     if (isset($data['pap_copy_m']) && $data['pap_copy_m'] == 1) {
         $path = PhocaDownloadPath::getPathSet();
         $storedfoldername = ltrim(str_replace(DS, '/', JPath::clean($rel_path)), '/');
         $paramsC = JComponentHelper::getParams('com_phocadownload');
         $overwriteExistingFiles = $paramsC->get('overwrite_existing_files', 0);
     }
     // ------------------------------------------------
     if ($fileList !== false) {
         foreach ($fileList as $filename) {
             $storedfilename = ltrim(str_replace(DS, '/', JPath::clean($rel_path . DS . $filename)), '/');
             //$ext = strtolower(JFile::getExt($filename));
             if (JFile::exists($fullPath . DS . $filename) && substr($filename, 0, 1) != '.' && strtolower($filename) !== 'index.html' && !$this->_FileExist($existingImages, $storedfilename, $category_id)) {
                 $row =& $this->getTable('phocadownload');
                 $datam = array();
                 $datam['published'] = $data['published'];
                 $datam['catid'] = $category_id;
                 $datam['filename'] = $storedfilename;
                 $datam['approved'] = $data['approved'];
                 $datam['language'] = $data['language'];
                 if ($data['title'] != '') {
                     $datam['title'] = $data['title'];
                 } else {
                     $datam['title'] = PhocaDownloadFile::getTitleFromFilenameWithoutExt($filename);
                 }
                 if ($data['alias'] != '') {
                     $datam['alias'] = $data['alias'];
                 } else {
                     $datam['alias'] = $data['alias'];
                     //PhocaDownloadFile::get AliasName($datam['title']);
                 }
                 $datam['token'] = PhocaDownloadUtils::getToken($datam['title'] . $datam['filename']);
                 $image = new JObject();
                 // Make a copy for play and preview (2)
                 if (isset($data['pap_copy_m']) && $data['pap_copy_m'] == 1) {
                     $o = $this->_copyPreviewAndPlay($filename, $storedfilename, $storedfoldername, $path, $overwriteExistingFiles);
                     $datam['filename_play'] = $o['filename_play'];
                     $datam['filename_preview'] = $o['filename_preview'];
                 }
                 // Save
                 // Bind the form fields to the Phoca download table
                 if (!$row->bind($datam)) {
                     $this->setError($this->_db->getErrorMsg());
                     return false;
                 }
                 // Create the timestamp for the date
                 $row->date = gmdate('Y-m-d H:i:s');
                 // if new item, order last in appropriate group
                 if (!$row->id) {
                     $where = 'catid = ' . (int) $row->catid;
                     $row->ordering = $row->getNextOrder($where);
                 }
                 // Make sure the Phoca download table is valid
                 if (!$row->check()) {
                     $this->setError($this->_db->getErrorMsg());
                     return false;
                 }
                 // Store the Phoca download table to the database
                 if (!$row->store()) {
                     $this->setError($this->_db->getErrorMsg());
                     return false;
                 }
                 // --------------------------------------------
                 /*if ($this->firstImageFolder == '') {
                 			$this->setFirstImageFolder($row->filename);
                 		}*/
                 $image->filename = $storedfilename;
                 $image->catid = $category_id;
                 $existingImages[] =& $image;
                 $count++;
             }
         }
     }
     //	$this->setfileCount($count);
     return $count;
 }