示例#1
0
 public function loadGoogleFonts()
 {
     $data = new \stdClass();
     $file = JsonFile::instance($this->google_fonts);
     $fonts = $file->content()['items'];
     $file->free();
     $data->categories = [];
     $data->subsets = [];
     // create list of unique categories and subsets
     array_walk($fonts, function (&$item) use($data) {
         if (!in_array($item->category, $data->categories)) {
             $data->categories[] = $item->category;
         }
         $data->subsets = array_unique(array_merge($data->subsets, $item->subsets));
     });
     asort($data->categories);
     asort($data->subsets);
     $data->families = $fonts;
     $data->local_families = $this->loadLocalFonts();
     if (count($data->local_families)) {
         array_unshift($data->categories, 'local-fonts');
     }
     $data->count = count($data->families);
     return $data;
 }
示例#2
0
 /**
  * @return int|null|void
  */
 protected function serve()
 {
     $this->progress = new ProgressBar($this->output);
     $this->progress->setFormat('Archiving <cyan>%current%</cyan> files [<green>%bar%</green>] %elapsed:6s% %memory:6s%');
     Grav::instance()['config']->init();
     $destination = $this->input->getArgument('destination') ? $this->input->getArgument('destination') : null;
     $log = JsonFile::instance(Grav::instance()['locator']->findResource("log://backup.log", true, true));
     $backup = ZipBackup::backup($destination, [$this, 'output']);
     $log->content(['time' => time(), 'location' => $backup]);
     $log->save();
     $this->output->writeln('');
     $this->output->writeln('');
 }
示例#3
0
 public function index()
 {
     throw new \Exception('Deprecated');
     $options = ['compare' => 'Filename', 'pattern' => '|\\.json|', 'filters' => ['key' => '|\\.json|'], 'key' => 'SubPathname', 'value' => 'Pathname'];
     /** @var UniformResourceLocator $locator */
     $locator = $this->container['locator'];
     $files = Folder::all($locator->findResource('gantry-theme://layouts/presets'), $options);
     $response = ['layouts'];
     foreach ($files as $name => $structure) {
         $content = JsonFile::instance($structure)->content();
         $response['layouts'][$name] = $content;
     }
     $response['html'] = $this->container['admin.theme']->render('@gantry-admin/layouts/picker.html.twig', ['presets' => $response]);
     return new JsonResponse($response);
 }
示例#4
0
 /**
  * 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;
 }
示例#5
0
 /**
  * Search in the logs when was the latest backup made
  *
  * @return array Array containing the latest backup information
  */
 public function lastBackup()
 {
     $file = JsonFile::instance($this->grav['locator']->findResource("log://backup.log"));
     $content = $file->content();
     if (empty($content)) {
         return ['days' => '&infin;', 'chart_fill' => 100, 'chart_empty' => 0];
     }
     $backup = new \DateTime();
     $backup->setTimestamp($content['time']);
     $diff = $backup->diff(new \DateTime());
     $days = $diff->days;
     $chart_fill = $days > 30 ? 100 : round($days / 30 * 100);
     return ['days' => $days, 'chart_fill' => $chart_fill, 'chart_empty' => 100 - $chart_fill];
 }
 /**
  * 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;
 }