⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 galleryresources.class.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 3 页
字号:
                          return( $info );                    }                /**         * adds a resource to the gallery when the resource is already stored on disk, instead of         * it coming from an upload as it usually happens. This method is better than 		 * GalleryResources::addResource() when instead of dealing with uploaded files, the file		 * is already in disk and all that is left to do is to add it to the database.         *         * @param ownerId         * @param albumId         * @param description         * @param fullFilePath The real path where the file is stored. This is expected to be		 * its final and permanent destination		 * @return It will return one of the following constants:		 * - GALLERY_ERROR_RESOURCE_TOO_BIG		 * - GALLERY_ERROR_RESOURCE_FORBIDDEN_EXTENSION		 * - GALLERY_ERROR_QUOTA_EXCEEDED		 * - GALLERY_ERROR_ADDING_RESOURCE		 * - GALLERY_ERROR_UPLOADS_NOT_ENABLED		 * or the identifier of the resource that was just added if the operation succeeded.         */        function addResourceFromDisk( $ownerId, $albumId, $description, $fullFilePath )        {            // check if quotas are enabled, and if this file would make us go            // over the quota            lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcequotas.class.php" );                        if( GalleryResourceQuotas::isBlogOverResourceQuota( $ownerId, File::getSize( $fullFilePath ))) {                return GALLERY_ERROR_QUOTA_EXCEEDED;            }                        // get the metadata            lt_include( PLOG_CLASS_PATH."class/gallery/getid3/getid3.php" );                        $getId3 = new GetID3();            $metadata = $getId3->analyze( $fullFilePath );            // nifty helper method from the getid3 package            getid3_lib::CopyTagsToComments($metadata);                                      $resourceType = $this->_getResourceType( $fullFilePath, $metadata );            $info = $this->_filterMetadata( $metadata, $resourceType );            					                // set the flags            $flags = 0;            if( $resourceType == GALLERY_RESOURCE_IMAGE )                $flags = $flags|GALLERY_RESOURCE_PREVIEW_AVAILABLE;                // add the record to the database            $fileName = basename( $fullFilePath );			$duplicated = $this->isDuplicatedFilename( $fileName );            $filePath = "";        			$resourceId = $this->addResourceToDatabase( $ownerId, $albumId, $description, $flags, $resourceType, $filePath, $fileName, $info );            if( !$resourceId )                return false;			if( $duplicated ) {				//				// :TODO:				// ugly...				//				$newFilePath = dirname( $fullFilePath)."/".$resourceId."-".basename( $fullFilePath );								File::rename( $fullFilePath, $newFilePath );				$fullFilePath = $newFilePath;			}                // and finally move the file to the right place in disk            // move the file to disk		    lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );                        $storage = new GalleryResourceStorage();            $resFile = $storage->storeFile( $resourceId, 			                                $ownerId, 											$fullFilePath,                                            RESOURCE_STORAGE_STORE_MOVE );                        // if the file cannot be read, we will also remove the record from the            // database so that we don't screw up            $fileReadable = File::isReadable( $resFile );            if( !$resFile || $resFile < 0 || !$fileReadable ) {                // if something went wrong, we should not keep the record in the db                $query = "DELETE FROM ".$this->getPrefix()."gallery_resources                          WHERE id = $resourceId";                    $this->Execute( $query );                                return $resFile;            }                // and finally, we can generate the thumbnail only if the file is an image, of course :)            if( $resourceType == GALLERY_RESOURCE_IMAGE ) {            	lt_include( PLOG_CLASS_PATH."class/gallery/resizers/gallerythumbnailgenerator.class.php" );                            GalleryThumbnailGenerator::generateResourceThumbnail( $resFile, $resourceId, $ownerId );				GalleryThumbnailGenerator::generateResourceMediumSizeThumbnail( $resFile, $resourceId, $ownerId );				// call this method only if the settings are right				lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );				$config =& Config::getConfig();				$previewHeight = $config->getValue( "final_size_thumbnail_height", 0 );				$previewWidth  = $config->getValue( "final_size_thumbnail_width", 0 );								if( $previewHeight != 0 && $previewWidth != 0 ) {					GalleryThumbnailGenerator::generateResourceFinalSizeThumbnail( $resFile, $resourceId, $ownerId );					// we have to recalculate the metadata because the image could be different... This is a bit cumbersome					// and repeats code. We know, thanks.					$getId3 = new GetID3();					$metadata = $getId3->analyze( $resFile );					getid3_lib::CopyTagsToComments($metadata);            					$info = $this->_filterMetadata( $metadata, $resourceType );					// and finally update the resource again						$resource = $this->getResource( $resourceId );					$resource->setMetadata( $info );								$this->updateResource( $resource );									}			}                        // return the id of the resource we just added            return $resourceId;                }        /**         * retrieves a resource, given its filename and its owner         *         * @param ownerId         * @param fileName         * @return Returns a GalleryResource object containing the given resource         * or false if the resource doesn't exist.         */        function getResourceFile( $ownerId, $fileName, $albumId = -1 )        {        	$resource = $this->get( "file_name", $fileName, CACHE_RESOURCES_BY_NAME );			if( !$resource )				return false;				        	if( $resource->getOwnerId() != $ownerId )        		return false;        	if( $albumId != -1 )        		if( $resource->getAlbumId() != $albumId )        			return false;        			            return( $resource );        }        /**         * updates a resource in the database.         *         * @param resource A GalleryResource object with the information of the         * resource we'd like to update.		 * @return Returns true if successful or false otherwise         */        function updateResource( $resource )         {			// loads the previous version of this object			$prevVersion = $this->getResource( $resource->getId());						        	if( $result = $this->update( $resource )) {        		// if update ok, reset the caches				$this->_cache->removeData( $resource->getId(), CACHE_RESOURCES );				$this->_cache->removeData( $resource->getOwnerId(), CACHE_RESOURCES_USER );				$this->_cache->removeData( $resource->getFileName(), CACHE_RESOURCES_BY_NAME );				// and update the album counters... must substract 1 from the previous album				// and must add one to the new album				$albums = new GalleryAlbums();				$album = $resource->getAlbum();				$album->setNumResources( $album->getNumResources() + 1 );				$albums->updateAlbum( $album );								// update the counters of the previous album				$prevAlbum = $prevVersion->getAlbum();				$prevAlbum->setNumResources( $prevAlbum->getNumResources() - 1 );				$albums->updateAlbum( $prevAlbum );		        	}        	        	return( $result );        }        /**         * removes a resource from the database and disk         *         * @param resourceId The identifier of the resource we'd like to remove         * @param ownerId Identifier of the owner of the resource. Optional.         * @return Returns true if resource deleted ok or false otherwise.         */        function deleteResource( $resourceId, $ownerId = -1 )        {        	// first, get information about the resource            $resource = $this->getResource( $resourceId, $ownerId );                        if( empty( $resource ) )            	return false;  	        if( $ownerId > -1 )	         	if( $resource->getOwnerId() != $ownerId )	           		return false;             	        	            $this->delete( "id", $resourceId );	        $this->_cache->removeData( $resource->getId(), CACHE_RESOURCES );			$this->_cache->removeData( $resource->getOwnerId(), CACHE_RESOURCES_USER );			$this->_cache->removeData( $resource->getFileName(), CACHE_RESOURCES_BY_NAME );			// update the counters			lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );			$albums = new GalleryAlbums();			$album = $resource->getAlbum();			$album->setNumResources( $album->getNumResources() - 1 );			$albums->updateAlbum( $album );			        // proceed and remove the file from disk			lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );        	$storage = new GalleryResourceStorage();            return $storage->remove( $resource );            	        }        /**         * Removes all the resource from the given ownerId         *         * @param ownerId The blog identifier         */        function deleteUserResources( $ownerId )        {            $userResources = $this->getUserResources( $ownerId,                                    					  GALLERY_NO_ALBUM,                                    					  GALLERY_RESOURCE_ANY,								   					  "",                                   					  -1);            // remove resources belong to the owner one by one            foreach( $userResources as $resource ) {                $this->deleteResource( $resource->getId(), $resource->getOwnerId() );            }            return true;        }		/**		 * returns true if the given filename already exists in the db		 *		 * @param fileName		 * @return true if the filename already exists or false otherwise		 */        function isDuplicatedFilename( $fileName )        {        	$query = "SELECT COUNT(id) AS total FROM ".$this->getPrefix()."gallery_resources                      WHERE file_name = '$fileName'";            $result = $this->Execute( $query );            $row = $result->FetchRow();            if( $row["total"] == 0 )            	$result = false;            else            	$result = true;			return( $result );        }				/**		 * @see Model::getSearchConditions()		 */		function getSearchConditions( $searchTerms )		{			$query = "file_name LIKE '%".Db::qstr( $searchTerms )."%'";						// search the text via the existing FULLTEXT index			$db =& Db::getDb();			if( $db->isFullTextSupported()) {							$query .= " OR MATCH(normalized_description) AGAINST ('{$searchTerms}')";				}			else {				$query .= " OR normalized_description LIKE '%".Db::qstr( $searchTerms )."%'";			}						return( $query );		}		        /**         * @private         */        function mapRow( $row )        {        	$res = new GalleryResource( $row["owner_id"],                                        $row["album_id"],                                        $row["description"],                                        $row["flags"],                                        $row["resource_type"],                                        $row["file_path"],                                        $row["file_name"],                                        unserialize($row["metadata"]),                                        $row["date"],										$row["thumbnail_format"],										unserialize($row["properties"]),                                        $row["id"] );			$res->setFileSize( $row["file_size"] );             return $res;        }    }?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -