当前位置: 首页>>代码示例>>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;未经允许,请勿转载。