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


PHP Utils::download方法代码示例

本文整理汇总了PHP中Grav\Common\Utils::download方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::download方法的具体用法?PHP Utils::download怎么用?PHP Utils::download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grav\Common\Utils的用法示例。


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

示例1: fallbackUrl

 /**
  * This attempts to find media, other files, and download them
  * @param $page
  * @param $path
  */
 protected function fallbackUrl($page, $path)
 {
     /** @var Uri $uri */
     $uri = $this['uri'];
     /** @var Config $config */
     $config = $this['config'];
     $uri_extension = $uri->extension();
     $fallback_types = $config->get('system.media.allowed_fallback_types', null);
     $supported_types = $config->get('media');
     // Check whitelist first, then ensure extension is a valid media type
     if (!empty($fallback_types) && !in_array($uri_extension, $fallback_types)) {
         return;
     } elseif (!array_key_exists($uri_extension, $supported_types)) {
         return;
     }
     $path_parts = pathinfo($path);
     $page = $this['pages']->dispatch($path_parts['dirname'], true);
     if ($page) {
         $media = $page->media()->all();
         $parsed_url = parse_url(urldecode($uri->basename()));
         $media_file = $parsed_url['path'];
         // if this is a media object, try actions first
         if (isset($media[$media_file])) {
             $medium = $media[$media_file];
             foreach ($uri->query(null, true) as $action => $params) {
                 if (in_array($action, ImageMedium::$magic_actions)) {
                     call_user_func_array(array(&$medium, $action), explode(',', $params));
                 }
             }
             Utils::download($medium->path(), false);
         }
         // unsupported media type, try to download it...
         if ($uri_extension) {
             $extension = $uri_extension;
         } else {
             if (isset($path_parts['extension'])) {
                 $extension = $path_parts['extension'];
             } else {
                 $extension = null;
             }
         }
         if ($extension) {
             $download = true;
             if (in_array(ltrim($extension, '.'), $config->get('system.media.unsupported_inline_types', []))) {
                 $download = false;
             }
             Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download);
         }
     }
 }
开发者ID:antunes145,项目名称:antunes145.github.io,代码行数:55,代码来源:Grav.php

示例2: taskBackup

 /**
  * Handle the backup action
  *
  * @return bool True if the action was performed.
  */
 protected function taskBackup()
 {
     $param_sep = $this->grav['config']->get('system.param_sep', ':');
     if (!$this->authorizeTask('backup', ['admin.maintenance', 'admin.super'])) {
         return;
     }
     $download = $this->grav['uri']->param('download');
     if ($download) {
         Utils::download(base64_decode(urldecode($download)), true);
     }
     $log = JsonFile::instance($this->grav['locator']->findResource("log://backup.log", true, true));
     try {
         $backup = ZipBackup::backup();
     } catch (\Exception $e) {
         $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.AN_ERROR_OCCURRED') . '. ' . $e->getMessage()];
         return true;
     }
     $download = urlencode(base64_encode($backup));
     $url = rtrim($this->grav['uri']->rootUrl(true), '/') . '/' . trim($this->admin->base, '/') . '/task' . $param_sep . 'backup/download' . $param_sep . $download . '/admin-nonce' . $param_sep . Utils::getNonce('admin-form');
     $log->content(['time' => time(), 'location' => $backup]);
     $log->save();
     $this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.YOUR_BACKUP_IS_READY_FOR_DOWNLOAD') . '. <a href="' . $url . '" class="button">' . $this->admin->translate('PLUGIN_ADMIN.DOWNLOAD_BACKUP') . '</a>', 'toastr' => ['timeOut' => 0, 'closeButton' => true]];
     return true;
 }
开发者ID:clee03,项目名称:metal,代码行数:29,代码来源:controller.php

示例3: taskBackup

 /**
  * Handle the backup action
  *
  * @return bool True if the action was performed.
  */
 protected function taskBackup()
 {
     if (!$this->authoriseTask('backup', ['admin.maintenance', 'admin.super'])) {
         return;
     }
     $download = $this->grav['uri']->param('download');
     if ($download) {
         Utils::download(base64_decode(urldecode($download)), true);
     }
     $log = JsonFile::instance($this->grav['locator']->findResource("log://backup.log", true, true));
     try {
         $backup = ZipBackup::backup();
     } catch (\Exception $e) {
         $this->admin->json_response = ['status' => 'error', 'message' => 'An error occured. ' . $e->getMessage()];
         return true;
     }
     $download = urlencode(base64_encode($backup));
     $url = rtrim($this->grav['uri']->rootUrl(true), '/') . '/' . trim($this->admin->base, '/') . '/task:backup/download:' . $download;
     $log->content(['time' => time(), 'location' => $backup]);
     $log->save();
     $this->admin->json_response = ['status' => 'success', 'message' => 'Your backup is ready for download. <a href="' . $url . '" class="button">Download backup</a>', 'toastr' => ['timeOut' => 0, 'closeButton' => true]];
     return true;
 }
开发者ID:spiridonovn,项目名称:grav-plugin-admin,代码行数:28,代码来源:controller.php

示例4: fallbackUrl

 /**
  * This attempts to fine media, other files, and download them
  * @param $page
  * @param $path
  */
 protected function fallbackUrl($page, $path)
 {
     /** @var Uri $uri */
     $uri = $this['uri'];
     $path_parts = pathinfo($path);
     $page = $this['pages']->dispatch($path_parts['dirname'], true);
     if ($page) {
         $media = $page->media()->all();
         $parsed_url = parse_url(urldecode($uri->basename()));
         $media_file = $parsed_url['path'];
         // if this is a media object, try actions first
         if (isset($media[$media_file])) {
             $medium = $media[$media_file];
             foreach ($uri->query(null, true) as $action => $params) {
                 if (in_array($action, ImageMedium::$magic_actions)) {
                     call_user_func_array(array(&$medium, $action), explode(',', $params));
                 }
             }
             Utils::download($medium->path(), false);
         }
         // unsupported media type, try to download it...
         $extension = $uri->extension() ?: isset($path_parts['extension']) ? $path_parts['extension'] : null;
         if ($extension) {
             $download = true;
             if (in_array(ltrim($extension, '.'), $this['config']->get('system.media.unsupported_inline_types'))) {
                 $download = false;
             }
             Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), $download);
         }
     }
 }
开发者ID:rikusv,项目名称:grav,代码行数:36,代码来源:Grav.php

示例5: load

 protected static function load(array $values)
 {
     $container = new static($values);
     $container['grav'] = $container;
     $container['debugger'] = new Debugger();
     $container['debugger']->startTimer('_init', 'Initialize');
     $container->register(new LoggerServiceProvider());
     $container->register(new ErrorServiceProvider());
     $container['uri'] = function ($c) {
         return new Uri($c);
     };
     $container['task'] = function ($c) {
         return !empty($_POST['task']) ? $_POST['task'] : $c['uri']->param('task');
     };
     $container['events'] = function ($c) {
         return new EventDispatcher();
     };
     $container['cache'] = function ($c) {
         return new Cache($c);
     };
     $container['plugins'] = function ($c) {
         return new Plugins();
     };
     $container['themes'] = function ($c) {
         return new Themes($c);
     };
     $container['twig'] = function ($c) {
         return new Twig($c);
     };
     $container['taxonomy'] = function ($c) {
         return new Taxonomy($c);
     };
     $container['pages'] = function ($c) {
         return new Page\Pages($c);
     };
     $container['assets'] = function ($c) {
         return new Assets();
     };
     $container['page'] = function ($c) {
         /** @var Pages $pages */
         $pages = $c['pages'];
         /** @var Uri $uri */
         $uri = $c['uri'];
         $path = rtrim($uri->path(), '/');
         $path = $path ?: '/';
         $page = $pages->dispatch($path);
         if (!$page || !$page->routable()) {
             $path_parts = pathinfo($path);
             $page = $c['pages']->dispatch($path_parts['dirname'], true);
             if ($page) {
                 $media = $page->media()->all();
                 $parsed_url = parse_url(urldecode($uri->basename()));
                 $media_file = $parsed_url['path'];
                 // if this is a media object, try actions first
                 if (isset($media[$media_file])) {
                     $medium = $media[$media_file];
                     foreach ($uri->query(null, true) as $action => $params) {
                         if (in_array($action, ImageMedium::$magic_actions)) {
                             call_user_func_array(array(&$medium, $action), explode(',', $params));
                         }
                     }
                     Utils::download($medium->path(), false);
                 } else {
                     Utils::download($page->path() . DIRECTORY_SEPARATOR . $uri->basename(), true);
                 }
             }
             // If no page found, fire event
             $event = $c->fireEvent('onPageNotFound');
             if (isset($event->page)) {
                 $page = $event->page;
             } else {
                 throw new \RuntimeException('Page Not Found', 404);
             }
         }
         return $page;
     };
     $container['output'] = function ($c) {
         return $c['twig']->processSite($c['uri']->extension());
     };
     $container['browser'] = function ($c) {
         return new Browser();
     };
     $container['base_url_absolute'] = function ($c) {
         return $c['config']->get('system.base_url_absolute') ?: $c['uri']->rootUrl(true);
     };
     $container['base_url_relative'] = function ($c) {
         return $c['config']->get('system.base_url_relative') ?: $c['uri']->rootUrl(false);
     };
     $container['base_url'] = function ($c) {
         return $c['config']->get('system.absolute_urls') ? $c['base_url_absolute'] : $c['base_url_relative'];
     };
     $container->register(new StreamsServiceProvider());
     $container->register(new ConfigServiceProvider());
     $container['debugger']->stopTimer('_init');
     return $container;
 }
开发者ID:re-pe,项目名称:grav,代码行数:96,代码来源:Grav.php


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