當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AssetFileModel類代碼示例

本文整理匯總了PHP中AssetFileModel的典型用法代碼示例。如果您正苦於以下問題:PHP AssetFileModel類的具體用法?PHP AssetFileModel怎麽用?PHP AssetFileModel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AssetFileModel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: populateFromAsset

 public static function populateFromAsset(AssetFileModel $asset)
 {
     if ($asset->kind === 'json' && strpos($asset->filename, EmbeddedAssetsPlugin::getFileNamePrefix(), 0) === 0) {
         try {
             $url = $asset->getUrl();
             if (!UrlHelper::isAbsoluteUrl($url)) {
                 $protocol = craft()->request->isSecureConnection() ? 'https' : 'http';
                 $url = UrlHelper::getUrlWithProtocol($url, $protocol);
             }
             // See http://stackoverflow.com/questions/272361/how-can-i-handle-the-warning-of-file-get-contents-function-in-php
             $rawData = @file_get_contents($url);
             if ($rawData) {
                 $data = JsonHelper::decode($rawData);
                 if ($data['__embeddedasset__']) {
                     unset($data['__embeddedasset__']);
                     $embed = new EmbeddedAssetsModel();
                     $embed->id = $asset->id;
                     foreach ($data as $key => $value) {
                         $embed->{$key} = $value;
                     }
                     return $embed;
                 }
             }
         } catch (\Exception $e) {
             return null;
         }
     }
     return null;
 }
開發者ID:jonleesmith,項目名稱:jonleesmith,代碼行數:29,代碼來源:EmbeddedAssetsModel.php

示例2: generateUrl

 /**
  * Generate a URL for a given Assets file in a Source Type.
  *
  * @param BaseAssetSourceType $sourceType
  * @param AssetFileModel      $file
  *
  * @return string
  */
 public static function generateUrl(BaseAssetSourceType $sourceType, AssetFileModel $file)
 {
     $baseUrl = $sourceType->getBaseUrl();
     $folderPath = $file->getFolder()->path;
     $fileName = $file->filename;
     $appendix = static::getUrlAppendix($sourceType, $file);
     return $baseUrl . $folderPath . $fileName . $appendix;
 }
開發者ID:jmstan,項目名稱:craft-website,代碼行數:16,代碼來源:AssetsHelper.php

示例3: __get

 /**
  * Magic getter
  *
  * @param string $name
  * @return mixed
  */
 function __get($name)
 {
     // Is it a transform handle?
     $transform = craft()->assetTransforms->getTransformByHandle($name);
     if ($transform) {
         // Duplicate this model and set it to that transform
         $model = new AssetFileModel();
         // Can't just use getAttributes() here because we'll get thrown into an infinite loop.
         foreach ($this->attributeNames() as $attributeName) {
             $model->setAttribute($attributeName, parent::getAttribute($attributeName));
         }
         $model->setTransform($transform);
         return $model;
     } else {
         return parent::__get($name);
     }
 }
開發者ID:kentonquatman,項目名稱:portfolio,代碼行數:23,代碼來源:AssetFileModel.php

示例4: _getPathsForLocalAsset

 /**
  * Get paths for a local asset
  *
  * @param AssetFileModel $image
  */
 private function _getPathsForLocalAsset(AssetFileModel $image)
 {
     $assetSourcePath = craft()->config->parseEnvironmentString($image->getSource()->settings['url']);
     if (strrpos($assetSourcePath, 'http') !== false) {
         $parsedUrl = parse_url($assetSourcePath);
         $assetSourcePath = $parsedUrl['path'];
     }
     $hashPath = craft()->imager->getSetting('hashPath');
     if ($hashPath) {
         $targetFolder = '/' . md5($assetSourcePath . $image->getFolder()->path) . '/';
     } else {
         $targetFolder = $assetSourcePath . $image->getFolder()->path;
     }
     $this->sourcePath = ImagerService::fixSlashes(craft()->config->parseEnvironmentString($image->getSource()->settings['path']) . $image->getFolder()->path);
     $this->targetPath = ImagerService::fixSlashes(craft()->imager->getSetting('imagerSystemPath') . $targetFolder) . $image->id . '/';
     $this->targetUrl = craft()->imager->getSetting('imagerUrl') . ImagerService::fixSlashes($targetFolder, true) . $image->id . '/';
     $this->sourceFilename = $this->targetFilename = $image->filename;
 }
開發者ID:aelvan,項目名稱:Imager-Craft,代碼行數:23,代碼來源:Imager_ImagePathsModel.php

示例5: __get

 /**
  * Magic getter
  *
  * @param string $name
  *
  * @throws \Exception
  * @return mixed
  */
 public function __get($name)
 {
     // Run through the BaseModel/CModel stuff first
     try {
         return parent::__get($name);
     } catch (\Exception $e) {
         // Is $name a transform handle?
         $transform = craft()->assetTransforms->getTransformByHandle($name);
         if ($transform) {
             // Duplicate this model and set it to that transform
             $model = new AssetFileModel();
             // Can't just use getAttributes() here because we'll get thrown into an infinite loop.
             foreach ($this->attributeNames() as $attributeName) {
                 $model->setAttribute($attributeName, parent::getAttribute($attributeName));
             }
             $model->setContent($this->getContent());
             $model->setTransform($transform);
             return $model;
         }
         // Fine, throw the exception
         throw $e;
     }
 }
開發者ID:amite,項目名稱:arc-va,代碼行數:31,代碼來源:AssetFileModel.php

示例6: populateElementModel

 /**
  * @inheritDoc IElementType::populateElementModel()
  *
  * @param array $row
  *
  * @return array
  */
 public function populateElementModel($row)
 {
     return AssetFileModel::populateModel($row);
 }
開發者ID:kant312,項目名稱:sop,代碼行數:11,代碼來源:AssetElementType.php

示例7: finalizeTransfer

 /**
  * Finalize a file transfer between sources for the provided file.
  *
  * @param AssetFileModel $file The assetFileModel representing the file we're finalizing the transfer for.
  *
  * @return null
  */
 public function finalizeTransfer(AssetFileModel $file)
 {
     $this->deleteSourceFile($file->getPath());
 }
開發者ID:codeforamerica,項目名稱:oakland-beta,代碼行數:11,代碼來源:BaseAssetSourceType.php

示例8: storeFile

 /**
  * Saves the record for an asset.
  *
  * @param AssetFileModel $file
  *
  * @throws \Exception
  * @return bool
  */
 public function storeFile(AssetFileModel $file)
 {
     $isNewFile = !$file->id;
     if (!$isNewFile) {
         $fileRecord = AssetFileRecord::model()->findById($file->id);
         if (!$fileRecord) {
             throw new Exception(Craft::t("No asset exists with the ID “{id}”.", array('id' => $file->id)));
         }
     } else {
         $fileRecord = new AssetFileRecord();
     }
     $fileRecord->sourceId = $file->sourceId;
     $fileRecord->folderId = $file->folderId;
     $fileRecord->filename = $file->filename;
     $fileRecord->kind = $file->kind;
     $fileRecord->size = $file->size;
     $fileRecord->width = $file->width;
     $fileRecord->height = $file->height;
     $fileRecord->dateModified = $file->dateModified;
     $fileRecord->validate();
     $file->addErrors($fileRecord->getErrors());
     if ($file->hasErrors()) {
         return false;
     }
     if ($isNewFile && !$file->getContent()->title) {
         // Give it a default title based on the file name
         $file->getContent()->title = str_replace('_', ' ', IOHelper::getFileName($file->filename, false));
     }
     $transaction = craft()->db->getCurrentTransaction() === null ? craft()->db->beginTransaction() : null;
     try {
         // Fire an 'onBeforeSaveAsset' event
         $event = new Event($this, array('asset' => $file, 'isNewAsset' => $isNewFile));
         $this->onBeforeSaveAsset($event);
         // Is the event giving us the go-ahead?
         if ($event->performAction) {
             // Save the element
             $success = craft()->elements->saveElement($file, false);
             // If it didn't work, rollback the transaction in case something changed in onBeforeSaveAsset
             if (!$success) {
                 if ($transaction !== null) {
                     $transaction->rollback();
                 }
                 return false;
             }
             // Now that we have an element ID, save it on the other stuff
             if ($isNewFile) {
                 $fileRecord->id = $file->id;
             }
             // Save the file row
             $fileRecord->save(false);
         } else {
             $success = false;
         }
         // Commit the transaction regardless of whether we saved the asset, in case something changed
         // in onBeforeSaveAsset
         if ($transaction !== null) {
             $transaction->commit();
         }
     } catch (\Exception $e) {
         if ($transaction !== null) {
             $transaction->rollback();
         }
         throw $e;
     }
     if ($success) {
         // Fire an 'onSaveAsset' event
         $this->onSaveAsset(new Event($this, array('asset' => $file, 'isNewAsset' => $isNewFile)));
         if ($this->hasEventHandler('onSaveFileContent')) {
             // Fire an 'onSaveFileContent' event (deprecated)
             $this->onSaveFileContent(new Event($this, array('file' => $file)));
         }
     }
     return $success;
 }
開發者ID:JulesVan,項目名稱:solutions-con,代碼行數:82,代碼來源:AssetsService.php

示例9: copyTransform

 /**
  * Copy a transform for a file from source location to target location.
  *
  * @param AssetFileModel $file
  * @param $source
  * @param $target
  * @return mixed
  */
 public function copyTransform(AssetFileModel $file, $source, $target)
 {
     $fileFolder = $file->getFolder();
     $basePath = $this->_getSourceFileSystemPath() . $fileFolder->fullPath;
     IOHelper::copyFile($basePath . $source . '/' . $file->filename, $basePath . $target . '/' . $file->filename);
 }
開發者ID:kentonquatman,項目名稱:portfolio,代碼行數:14,代碼來源:LocalAssetSourceType.php

示例10: _getFileSystemPath

 /**
  * Get a file's system path.
  *
  * @param AssetFileModel $file
  *
  * @return string
  */
 private function _getFileSystemPath(AssetFileModel $file)
 {
     $folder = $file->getFolder();
     $fileSourceType = craft()->assetSources->getSourceTypeById($file->sourceId);
     return $this->getSourceFileSystemPath($fileSourceType) . $folder->path . $file->filename;
 }
開發者ID:nathanedwards,項目名稱:cowfields.craft,代碼行數:13,代碼來源:LocalAssetSourceType.php

示例11: _getThumbExtension

 /**
  * Return the thumbnail extension for a file.
  *
  * @param AssetFileModel $file
  *
  * @return string
  */
 private function _getThumbExtension(AssetFileModel $file)
 {
     // For non-web-safe formats we go with jpg.
     if (!in_array(mb_strtolower(IOHelper::getExtension($file->filename)), ImageHelper::getWebSafeFormats())) {
         if ($file->getExtension() == 'svg' && craft()->images->isImagick()) {
             return 'png';
         }
         return 'jpg';
     } else {
         return $file->getExtension();
     }
 }
開發者ID:JulesVan,項目名稱:solutions-con,代碼行數:19,代碼來源:AssetTransformsService.php

示例12: transformExists

 /**
  * Return true if a transform exists at the location for a file.
  *
  * @param AssetFileModel $file
  * @param $location
  * @return mixed
  */
 public function transformExists(AssetFileModel $file, $location)
 {
     return (bool) $this->_getObjectInfo($this->_getPathPrefix() . $file->getFolder()->fullPath . $location . '/' . $file->filename);
 }
開發者ID:kentonquatman,項目名稱:portfolio,代碼行數:11,代碼來源:RackspaceAssetSourceType.php

示例13: _getThumbnails

 /**
  * Returns an array of all embedded assets thumbnails, indexed by the asset file models ID.
  * This method is used to inject the asset thumbnails into the CP front-end. Since embedded asset files are stored
  * as JSON files, there's no supported way of setting the thumbnail on the front-end for these files. The
  * alternative is to pass a list of these thumbnails to the front-end, and use JS to patch them on-top of the
  * elements system.
  *
  * @return array
  */
 private function _getThumbnails()
 {
     // TODO Redo this using the elements API so it's not depending on the DB schema
     // Escape for using in LIKE clause
     // See: http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder
     $prefix = strtr(self::getFileNamePrefix(), array('%' => '\\%', '_' => '\\_'));
     $results = craft()->db->createCommand()->select('assetfiles.*')->from('assetfiles assetfiles')->where(array('like', 'assetfiles.filename', $prefix . '%.json'))->queryAll();
     $assets = AssetFileModel::populateModels($results, 'id');
     $thumbnails = array();
     foreach ($assets as $id => $asset) {
         $embed = craft()->embeddedAssets->getEmbeddedAsset($asset);
         if ($embed) {
             $thumbnails[$id] = $embed->thumbnailUrl;
         }
     }
     return $thumbnails;
 }
開發者ID:jonleesmith,項目名稱:jonleesmith,代碼行數:26,代碼來源:EmbeddedAssetsPlugin.php

示例14: getAssetFile

 /**
  * Gets a file by its asset.
  *
  * @param AssetFileModel $asset
  *
  * @return string
  */
 protected function getAssetFile(AssetFileModel $asset)
 {
     // Check if we have this filenname cached already
     if (!isset($this->assets[$asset->id])) {
         // Get asset source
         $source = $asset->getSource();
         // Get asset source type
         $sourceType = $source->getSourceType();
         // Get asset file
         $this->assets[$asset->id] = $sourceType->getLocalCopy($asset);
     }
     return $this->assets[$asset->id];
 }
開發者ID:boboldehampsink,項目名稱:youtube,代碼行數:20,代碼來源:YouTubeService.php

示例15: _getRackspacePath

 /**
  * Get a file's S3 path.
  *
  * @param AssetFileModel $file
  *
  * @return string
  */
 private function _getRackspacePath(AssetFileModel $file)
 {
     $folder = $file->getFolder();
     return $this->_getPathPrefix() . $folder->path . $file->filename;
 }
開發者ID:kentonquatman,項目名稱:portfolio,代碼行數:12,代碼來源:RackspaceAssetSourceType.php


注:本文中的AssetFileModel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。