当前位置: 首页>>代码示例>>PHP>>正文


PHP IOHelper类代码示例

本文整理汇总了PHP中IOHelper的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper类的具体用法?PHP IOHelper怎么用?PHP IOHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IOHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: safeUp

 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     Craft::log('Moving the logo from storage/logo to storage/rebrand/logo', LogLevel::Info, true);
     IOHelper::rename(craft()->path->getStoragePath() . 'logo', craft()->path->getRebrandPath() . 'logo', true);
     Craft::log('Done moving the logo from storage/logo to storage/rebrand/logo', LogLevel::Info, true);
     return true;
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:12,代码来源:m151110_000000_move_logo.php

示例2: init

 /**
  * Initializes the console app by creating the command runner.
  *
  * @return null
  */
 public function init()
 {
     // Set default timezone to UTC
     date_default_timezone_set('UTC');
     // Import all the built-in components
     foreach ($this->componentAliases as $alias) {
         Craft::import($alias);
     }
     // Attach our Craft app behavior.
     $this->attachBehavior('AppBehavior', new AppBehavior());
     // Initialize Cache and LogRouter right away (order is important)
     $this->getComponent('cache');
     $this->getComponent('log');
     // So we can try to translate Yii framework strings
     $this->coreMessages->attachEventHandler('onMissingTranslation', array('Craft\\LocalizationHelper', 'findMissingTranslation'));
     // Set our own custom runtime path.
     $this->setRuntimePath(craft()->path->getRuntimePath());
     // Attach our own custom Logger
     Craft::setLogger(new Logger());
     // No need for these.
     craft()->log->removeRoute('WebLogRoute');
     craft()->log->removeRoute('ProfileLogRoute');
     // Load the plugins
     craft()->plugins->loadPlugins();
     // Validate some basics on the database configuration file.
     craft()->validateDbConfigFile();
     // Call parent::init before the plugin console command logic so craft()->commandRunner will be available to us.
     parent::init();
     foreach (craft()->plugins->getPlugins() as $plugin) {
         $commandsPath = craft()->path->getPluginsPath() . StringHelper::toLowerCase($plugin->getClassHandle()) . '/consolecommands/';
         if (IOHelper::folderExists($commandsPath)) {
             craft()->commandRunner->addCommands(rtrim($commandsPath, '/'));
         }
     }
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:40,代码来源:ConsoleApp.php

示例3: getBearerToken

 protected function getBearerToken()
 {
     $settings = craft()->plugins->getPlugin('social')->getSettings();
     if (!$settings->twitter_consumer_key || !$settings->twitter_consumer_secret) {
         return false;
     }
     if ($this->token) {
         return $this->token;
     }
     $store = craft()->path->getStoragePath() . 'social/';
     IOHelper::ensureFolderExists($store);
     if (file_exists($store . '/twitter.bearer-token')) {
         $this->token = trim(file_get_contents($store . '/twitter.bearer-token'));
     } else {
         $curl = curl_init(self::TOKEN_URL);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_POST, true);
         curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
         curl_setopt($curl, CURLOPT_USERPWD, $settings->twitter_consumer_key . ':' . $settings->twitter_consumer_secret);
         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array('grant_type' => 'client_credentials')));
         $response = curl_exec($curl);
         $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
         if ($status == 200) {
             $decoded = json_decode($response);
             $this->token = $decoded->access_token;
         } else {
             return false;
         }
         file_put_contents($store . '/twitter.bearer-token', $this->token);
     }
     return $this->token;
 }
开发者ID:imarc,项目名称:craft-social,代码行数:32,代码来源:Social_TwitterService.php

示例4: download

 /**
  * Download zipfile.
  *
  * @param array  $files
  * @param string $filename
  *
  * @return string
  */
 public function download($files, $filename)
 {
     // Get assets
     $criteria = craft()->elements->getCriteria(ElementType::Asset);
     $criteria->id = $files;
     $criteria->limit = null;
     $assets = $criteria->find();
     // Set destination zip
     $destZip = craft()->path->getTempPath() . $filename . '_' . time() . '.zip';
     // Create zip
     $zip = new \ZipArchive();
     // Open zip
     if ($zip->open($destZip, $zip::CREATE) === true) {
         // Loop through assets
         foreach ($assets as $asset) {
             // Get asset source
             $source = $asset->getSource();
             // Get asset source type
             $sourceType = $source->getSourceType();
             // Get asset file
             $file = $sourceType->getLocalCopy($asset);
             // Add to zip
             $zip->addFromString($asset->filename, IOHelper::getFileContents($file));
             // Remove the file
             IOHelper::deleteFile($file);
         }
         // Close zip
         $zip->close();
         // Return zip destination
         return $destZip;
     }
     // Something went wrong
     throw new Exception(Craft::t('Failed to generate the zipfile'));
 }
开发者ID:boboldehampsink,项目名称:zipassets,代码行数:42,代码来源:ZipAssetsService.php

示例5: actionDownloadBackupFile

 /**
  * Returns a database backup zip file to the browser.
  *
  * @return null
  */
 public function actionDownloadBackupFile()
 {
     $fileName = craft()->request->getRequiredQuery('fileName');
     if (($filePath = IOHelper::fileExists(craft()->path->getTempPath() . $fileName . '.zip')) == true) {
         craft()->request->sendFile(IOHelper::getFileName($filePath), IOHelper::getFileContents($filePath), array('forceDownload' => true));
     }
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:12,代码来源:ToolsController.php

示例6: form

 public function form($elementId, $criteria = array())
 {
     $settings = craft()->plugins->getPlugin('comments')->getSettings();
     $oldPath = craft()->path->getTemplatesPath();
     $element = craft()->elements->getElementById($elementId);
     $criteria = array_merge($criteria, array('elementId' => $element->id, 'level' => '1'));
     $comments = craft()->comments->getCriteria($criteria);
     // Is the user providing their own templates?
     if ($settings->templateFolderOverride) {
         // Check if this file even exists
         $commentTemplate = craft()->path->getSiteTemplatesPath() . $settings->templateFolderOverride . '/comments';
         foreach (craft()->config->get('defaultTemplateExtensions') as $extension) {
             if (IOHelper::fileExists($commentTemplate . "." . $extension)) {
                 $templateFile = $settings->templateFolderOverride . '/comments';
             }
         }
     }
     // If no user templates, use our default
     if (!isset($templateFile)) {
         $templateFile = '_forms/templates/comments';
         craft()->path->setTemplatesPath(craft()->path->getPluginsPath() . 'comments/templates');
     }
     $variables = array('element' => $element, 'comments' => $comments);
     $html = craft()->templates->render($templateFile, $variables);
     craft()->path->setTemplatesPath($oldPath);
     // Finally - none of this matters if the permission to comment on this element is denied
     if (!craft()->comments_settings->checkPermissions($element)) {
         return false;
     }
     return new \Twig_Markup($html, craft()->templates->getTwig()->getCharset());
 }
开发者ID:Uxiliary,项目名称:Comments,代码行数:31,代码来源:CommentsVariable.php

示例7: processLogs

 /**
  * Saves log messages in files.
  *
  * @param array $logs list of log messages
  */
 protected function processLogs($logs)
 {
     $logFile = IOHelper::normalizePathSeparators($this->getLogPath() . '/' . $this->getLogFile());
     if (IOHelper::getFileSize($logFile) > $this->getMaxFileSize() * 1024) {
         $this->rotateFiles();
     }
     $lock = craft()->config->get('useLockWhenWritingToFile') === true;
     $fp = @fopen($logFile, 'a');
     if ($lock) {
         @flock($fp, LOCK_EX);
     }
     foreach ($logs as $log) {
         $message = LoggingHelper::redact($log[0]);
         $level = $log[1];
         $category = $log[2];
         $time = $log[3];
         $force = isset($log[4]) && $log[4] == true ? true : false;
         @fwrite($fp, $this->formatLogMessageWithForce($message, $level, $category, $time, $force));
     }
     @fwrite($fp, PHP_EOL . '******************************************************************************************************' . PHP_EOL);
     if ($lock) {
         @flock($fp, LOCK_UN);
     }
     @fclose($fp);
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:30,代码来源:FileLogRoute.php

示例8: delete

 /**
  * @return bool
  */
 public function delete()
 {
     if (!IOHelper::deleteFolder($this->getRealPath())) {
         return false;
     }
     return true;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:10,代码来源:Folder.php

示例9: getInputHtml

 public function getInputHtml($name, $value)
 {
     // Get site templates path
     $templatesPath = $siteTemplatesPath = craft()->path->getSiteTemplatesPath();
     // Check if the templates path is overriden by configuration
     // TODO: Normalize path
     $limitToSubfolder = craft()->config->get('templateselectSubfolder');
     if ($limitToSubfolder) {
         $templatesPath = $templatesPath . rtrim($limitToSubfolder, '/') . '/';
     }
     // Check if folder exists, or give error
     if (!IOHelper::folderExists($templatesPath)) {
         throw new \InvalidArgumentException('(Template Select) Folder doesn\'t exist: ' . $templatesPath);
     }
     // Get folder contents
     $templates = IOHelper::getFolderContents($templatesPath, TRUE);
     // Add placeholder for when there is no template selected
     $filteredTemplates = array('' => Craft::t('No template selected'));
     // Turn array into ArrayObject
     $templates = new \ArrayObject($templates);
     // Iterate over template list
     // * Remove full path
     // * Remove folders from list
     for ($list = $templates->getIterator(); $list->valid(); $list->next()) {
         $filename = $list->current();
         $filename = str_replace($templatesPath, '', $filename);
         $filenameIncludingSubfolder = $limitToSubfolder ? $limitToSubfolder . $filename : $filename;
         $isTemplate = preg_match("/(.html|.twig)\$/u", $filename);
         if ($isTemplate) {
             $filteredTemplates[$filenameIncludingSubfolder] = $filename;
         }
     }
     // Render field
     return craft()->templates->render('_includes/forms/select', array('name' => $name, 'value' => $value, 'options' => $filteredTemplates));
 }
开发者ID:alexrubin,项目名称:Craft-TemplateSelect,代码行数:35,代码来源:TemplateSelect_SelectFieldType.php

示例10: findInstallableRecords

 /**
  * Finds installable records from the models folder.
  *
  * @return array
  */
 public function findInstallableRecords()
 {
     $records = array();
     $recordsFolder = craft()->path->getAppPath() . 'records/';
     $recordFiles = IOHelper::getFolderContents($recordsFolder, false, ".*Record\\.php\$");
     foreach ($recordFiles as $file) {
         if (IOHelper::fileExists($file)) {
             $fileName = IOHelper::getFileName($file, false);
             $class = __NAMESPACE__ . '\\' . $fileName;
             // Ignore abstract classes and interfaces
             $ref = new \ReflectionClass($class);
             if ($ref->isAbstract() || $ref->isInterface()) {
                 Craft::log("Skipping record {$file} because it’s abstract or an interface.", LogLevel::Warning);
                 continue;
             }
             $obj = new $class('install');
             if (method_exists($obj, 'createTable')) {
                 $records[] = $obj;
             } else {
                 Craft::log("Skipping record {$file} because it doesn’t have a createTable() method.", LogLevel::Warning);
             }
         } else {
             Craft::log("Skipping record {$file} because it doesn’t exist.", LogLevel::Warning);
         }
     }
     return $records;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:32,代码来源:InstallService.php

示例11: getDisplayTemplateInfo

 /**
  * Get a display (front-end displayForm) template information.
  *
  * @param string $defaultTemplate  Which default template are we looking for?
  * @param string $overrideTemplate Which override template was given?
  *
  * @return array
  */
 public function getDisplayTemplateInfo($defaultTemplate, $overrideTemplate)
 {
     // Plugin's default template path
     $templatePath = craft()->path->getPluginsPath() . 'amforms/templates/_display/templates/';
     $settingsName = $defaultTemplate == 'email' ? 'notificationTemplate' : $defaultTemplate . 'Template';
     $templateSetting = craft()->amForms_settings->getSettingsByHandleAndType($settingsName, AmFormsModel::SettingsTemplatePaths);
     if (empty($overrideTemplate) && $templateSetting) {
         $overrideTemplate = $templateSetting->value;
     }
     // Is the override template set?
     if ($overrideTemplate) {
         // Is the value a folder, or folder with template?
         $pathParts = explode(DIRECTORY_SEPARATOR, $overrideTemplate);
         $templateFile = craft()->path->getSiteTemplatesPath() . $overrideTemplate;
         if (count($pathParts) < 2) {
             // Seems we only have a folder that will use the default template name
             $templateFile .= DIRECTORY_SEPARATOR . $defaultTemplate;
         }
         // Try to find the template for each available template extension
         foreach (craft()->config->get('defaultTemplateExtensions') as $extension) {
             if (IOHelper::fileExists($templateFile . '.' . $extension)) {
                 if (count($pathParts) > 1) {
                     // We set a specific template
                     $defaultTemplate = $pathParts[count($pathParts) - 1];
                     $templatePath = craft()->path->getSiteTemplatesPath() . str_replace(DIRECTORY_SEPARATOR . $defaultTemplate, '', implode(DIRECTORY_SEPARATOR, $pathParts));
                 } else {
                     // Only a folder was given, so still the default template template
                     $templatePath = craft()->path->getSiteTemplatesPath() . $overrideTemplate;
                 }
             }
         }
     }
     return array('path' => $templatePath, 'template' => $defaultTemplate);
 }
开发者ID:webremote,项目名称:amforms,代码行数:42,代码来源:AmFormsService.php

示例12: __construct

 public function __construct()
 {
     $this->document_root = \Craft\Craft::getPathOfAlias('webroot');
     $this->cache_dir = $this->document_root . "/cache";
     $this->cache_url = $this->makeBaseCacheUrl();
     IOHelper::ensureFolderExists($this->cache_dir);
 }
开发者ID:Hambrook,项目名称:Compressor,代码行数:7,代码来源:CompressorService.php

示例13: includeCpResources

 /**
  * Includes the plugin's resources for the Control Panel.
  */
 protected function includeCpResources()
 {
     // Prepare config
     $config = [];
     $config['iconMapping'] = craft()->config->get('iconMapping', 'redactoriconbuttons');
     $iconAdminPath = craft()->path->getConfigPath() . 'redactoriconbuttons/icons.svg';
     $iconPublicPath = craft()->config->get('iconFile', 'redactoriconbuttons');
     if (IOHelper::fileExists($iconAdminPath)) {
         $config['iconFile'] = UrlHelper::getResourceUrl('config/redactoriconbuttons/icons.svg');
     } elseif ($iconPublicPath) {
         $config['iconFile'] = craft()->config->parseEnvironmentString($iconPublicPath);
     } else {
         $config['iconFile'] = UrlHelper::getResourceUrl('redactoriconbuttons/icons/redactor-i.svg');
     }
     // Include JS
     $config = JsonHelper::encode($config);
     $js = "var RedactorIconButtons = {}; RedactorIconButtons.config = {$config};";
     craft()->templates->includeJs($js);
     craft()->templates->includeJsResource('redactoriconbuttons/redactoriconbuttons.js');
     // Include CSS
     craft()->templates->includeCssResource('redactoriconbuttons/redactoriconbuttons.css');
     // Add external spritemap support for IE9+ and Edge 12
     $ieShim = craft()->config->get('ieShim', 'redactoriconbuttons');
     if (filter_var($ieShim, FILTER_VALIDATE_BOOLEAN)) {
         craft()->templates->includeJsResource('redactoriconbuttons/lib/svg4everybody.min.js');
         craft()->templates->includeJs('svg4everybody();');
     }
 }
开发者ID:carlcs,项目名称:craft-redactoriconbuttons,代码行数:31,代码来源:RedactorIconButtonsPlugin.php

示例14: includeCustomCpResources

 /**
  * Includes resources for the Control Panel from the craft/config/diywidget/ folder.
  */
 protected function includeCustomCpResources()
 {
     $templatePaths = [];
     $folderPath = craft()->path->getConfigPath() . 'diywidget/';
     if (IOHelper::folderExists($folderPath)) {
         $filePaths = glob($folderPath . '*.{twig,html,css,js}', GLOB_BRACE);
         foreach ($filePaths as $filePath) {
             $pathInFolder = str_replace($folderPath, '', $filePath);
             $resourcePath = 'config/diywidget/' . $pathInFolder;
             switch (IOHelper::getExtension($filePath)) {
                 case 'twig':
                 case 'html':
                     $templatePaths[] = $pathInFolder;
                     break;
                 case 'css':
                     craft()->templates->includeCssResource($resourcePath);
                     break;
                 case 'js':
                     craft()->templates->includeJsResource($resourcePath);
                     break;
             }
         }
     }
     craft()->diyWidget->templatePaths = $templatePaths;
 }
开发者ID:carlcs,项目名称:craft-diywidget,代码行数:28,代码来源:DiyWidgetPlugin.php

示例15: actionPrepareForCrop

 /**
  * Prepare asset for cropping.
  */
 public function actionPrepareForCrop()
 {
     $this->requireAjaxRequest();
     $elementId = craft()->request->getParam('elementId');
     // Get the asset file
     $asset = craft()->assets->getFileById($elementId);
     $source = $asset->getSource();
     $sourceType = $source->getSourceType();
     $file = $sourceType->getLocalCopy($asset);
     try {
         // Test if we will be able to perform image actions on this image
         if (!craft()->images->checkMemoryForImage($file)) {
             IOHelper::deleteFile($file);
             $this->returnErrorJson(Craft::t('The selected image is too large.'));
         }
         // Scale to fit 500x500 for fitting in CP modal
         craft()->images->loadImage($file)->scaleToFit(500, 500, false)->saveAs($file);
         list($width, $height) = ImageHelper::getImageSize($file);
         // If the file is in the format badscript.php.gif perhaps.
         if ($width && $height) {
             $html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => $asset->url, 'width' => $width, 'height' => $height, 'fileName' => $asset->filename));
             $this->returnJson(array('html' => $html));
         }
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
 }
开发者ID:boboldehampsink,项目名称:cropassets,代码行数:30,代码来源:CropAssetsController.php


注:本文中的IOHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。