/**
  * @Route("/", methods="GET")
  * @Request({"folder": "string"})
  */
 public function indexAction($folder = '')
 {
     $images = [];
     $folder = trim($folder, '/');
     $pttrn = '/\\.(jpg|jpeg|gif|png)$/i';
     $dir = App::path();
     if (!($files = glob($dir . '/' . $folder . '/*'))) {
         return [];
     }
     foreach ($files as $img) {
         // extension filter
         if (!preg_match($pttrn, $img)) {
             continue;
         }
         $data = array();
         $data['filename'] = basename($img);
         // remove extension
         $data['title'] = preg_replace('/\\.[^.]+$/', '', $data['filename']);
         // remove leading number
         $data['title'] = preg_replace('/^\\d+\\s?+/', '', $data['title']);
         // remove trailing numbers
         $data['title'] = preg_replace('/\\s?+\\d+$/', '', $data['title']);
         // replace underscores with space and add capital
         $data['title'] = ucfirst(trim(str_replace(['_', '-'], ' ', $data['title'])));
         $data['image']['src'] = $folder . '/' . basename($img);
         $data['image']['alt'] = $data['title'];
         $images[] = $data;
     }
     return $images;
 }
Example #2
0
 /**
  * Returns the path relative to the root.
  *
  * @param  string $path
  * @return string
  */
 protected function getRelativePath($path)
 {
     if (0 === strpos($path, App::path())) {
         $path = ltrim(str_replace('\\', '/', substr($path, strlen(App::path()))), '/');
     }
     return $path;
 }
 /**
  * @param string $path
  * @return string
  */
 protected function getPath($path = '')
 {
     $root = strtr(App::path(), '\\', '/');
     $path = $this->normalizePath($root . '/storage/' . $path);
     if (!is_dir($path)) {
         App::file()->makeDir($path);
     }
     return $path;
 }
Example #4
0
 /**
  * Runs Pagekit self update.
  *
  * @param $file
  * @throws \Exception
  */
 public function update($file)
 {
     try {
         $path = App::path();
         if (!file_exists($file)) {
             throw new \RuntimeException('File not found.');
         }
         $this->output->write('Preparing update...');
         $fileList = $this->getFileList($file);
         unset($fileList[array_search('.htaccess', $fileList)]);
         $fileList = array_values(array_filter($fileList, function ($file) {
             foreach ($this->ignoreFolder as $ignore) {
                 if (strpos($file, $ignore) === 0) {
                     return false;
                 }
             }
             return true;
         }));
         if ($this->isWritable($fileList, $path) !== true) {
             throw new \RuntimeException(array_reduce($fileList, function ($carry, $file) {
                 return $carry . sprintf("'%s' not writable\n", $file);
             }));
         }
         $requirements = (include "zip://{$file}#app/installer/requirements.php");
         if ($failed = $requirements->getFailedRequirements()) {
             throw new \RuntimeException(array_reduce($failed, function ($carry, $problem) {
                 return $carry . "\n" . $problem->getHelpText();
             }));
         }
         $this->output->writeln('<info>done.</info>');
         $this->output->write('Entering update mode...');
         $this->setUpdateMode(true);
         $this->output->writeln('<info>done.</info>');
         $this->output->write('Extracting files...');
         $this->extract($file, $fileList, $path);
         $this->output->writeln('<info>done.</info>');
         $this->output->write('Removing old files...');
         foreach ($this->cleanup($fileList, $path) as $file) {
             $this->writeln(sprintf('<error>\'%s\\’ could not be removed</error>', $file));
         }
         unlink($file);
         $this->output->writeln('<info>done.</info>');
         $this->output->write('Deactivating update mode...');
         $this->setUpdateMode(false);
         $this->output->writeln('<info>done.</info>');
         if (function_exists('opcache_reset')) {
             opcache_reset();
         }
     } catch (\Exception $e) {
         @unlink($file);
         throw $e;
     }
 }
Example #5
0
 /**
  * Runs Pagekit self update.
  *
  * @param $file
  */
 public function update($file)
 {
     try {
         $path = App::path();
         if (!file_exists($file)) {
             throw new \RuntimeException('File not found.');
         }
         $this->output->write('Preparing update...');
         $fileList = $this->getFileList($file);
         unset($fileList[array_search('.htaccess', $fileList)]);
         if ($this->isWritable($fileList, $path) !== true) {
             throw new \RuntimeException(array_reduce($fileList, function ($carry, $file) {
                 return $carry . sprintf("'%s' not writable\n", $file);
             }));
         }
         $this->output->writeln('<info>done.</info>');
         $this->output->write('Entering update mode...');
         $this->setUpdateMode(true);
         $this->output->writeln('<info>done.</info>');
         $this->output->write('Extracting files...');
         $this->extract($file, $fileList, $path);
         $this->output->writeln('<info>done.</info>');
         $this->output->write('Removing old files...');
         foreach ($this->cleanup($fileList, $path) as $file) {
             $this->writeln(sprintf('<error>\'%s\\’ could not be removed</error>', $file));
         }
         unlink($file);
         $this->output->writeln('<info>done.</info>');
         $this->output->write('Deactivating update mode...');
         $this->setUpdateMode(false);
         $this->output->writeln('<info>done.</info>');
         if (function_exists('opcache_reset')) {
             opcache_reset();
         }
     } catch (\Exception $e) {
         @unlink($file);
         $this->output->writeln(sprintf("\n<error>%s</error>", $e->getMessage()));
     }
 }
 /**
  * @return bool|string
  */
 public function getCachepath()
 {
     $folder = App::path() . '/' . App::module('bixie/portfolio')->config('cache_path');
     if (file_exists($folder) && is_writable($folder)) {
         //all fine, quick return
         return $folder;
     }
     //try to create user-folder
     App::file()->makeDir($folder, 0755);
     if (!file_exists($folder)) {
         //create default folder
         $folder = $this->app['path.cache'] . '/portfolio';
         if (!file_exists($folder)) {
             App::file()->makeDir($folder, 0755);
         }
     }
     if (!file_exists($folder) || !is_writable($folder)) {
         //give up
         return false;
     }
     return $folder;
 }
Example #7
0
 protected function getPath($path = '')
 {
     $root = strtr(App::path(), '\\', '/');
     $path = $this->normalizePath($root . '/' . App::request()->get('root') . '/' . App::request()->get('path') . '/' . $path);
     return 0 === strpos($path, $root) ? $path : false;
 }
Example #8
0
 /**
  * @Request({"config": "array", "option": "array", "user": "******"})
  */
 public function installAction($config = [], $option = [], $user = [])
 {
     $status = $this->checkAction($config);
     $message = $status['message'];
     $status = $status['status'];
     try {
         if ('no-connection' == $status) {
             App::abort(400, __('No database connection.'));
         }
         if ('tables-exist' == $status) {
             App::abort(400, $message);
         }
         $scripts = new PackageScripts(App::path() . '/app/system/scripts.php');
         $scripts->install();
         App::db()->insert('@system_user', ['name' => $user['username'], 'username' => $user['username'], 'password' => App::get('auth.password')->hash($user['password']), 'status' => 1, 'email' => $user['email'], 'registered' => date('Y-m-d H:i:s'), 'roles' => '2,3']);
         $option['system']['version'] = App::version();
         $option['system']['extensions'] = ['blog'];
         $option['system']['site']['theme'] = 'theme-one';
         foreach ($option as $name => $values) {
             App::config()->set($name, App::config($name)->merge($values));
         }
         if ($this->packages) {
             $installer = new PackageManager(new NullOutput());
             $installer->install($this->packages);
         }
         if (file_exists(__DIR__ . '/../../install.php')) {
             require_once __DIR__ . '/../../install.php';
         }
         if (!$this->config) {
             $configuration = new Config();
             $configuration->set('application.debug', false);
             foreach ($config as $key => $value) {
                 $configuration->set($key, $value);
             }
             $configuration->set('system.secret', App::get('auth.random')->generateString(64));
             if (!file_put_contents($this->configFile, $configuration->dump())) {
                 $status = 'write-failed';
                 App::abort(400, __('Can\'t write config.'));
             }
         }
         App::module('system/cache')->clearCache();
         $status = 'success';
     } catch (DBALException $e) {
         $status = 'db-sql-failed';
         $message = __('Database error: %error%', ['%error%' => $e->getMessage()]);
     } catch (\Exception $e) {
         $message = $e->getMessage();
     }
     return ['status' => $status, 'message' => $message];
 }
 /**
  * @param string $source
  * @param array $options
  * @return bool|mixed
  */
 protected function resizeImage($source, $options)
 {
     try {
         $cachepath = $this->getCachePath($source, $options);
         if (!file_exists($cachepath)) {
             $image = new SimpleImage(App::path() . '/' . $source);
             if (!empty($options['width']) && empty($options['height'])) {
                 $image->fit_to_width($options['width']);
             }
             if (!empty($options['height']) && empty($options['width'])) {
                 $image->fit_to_height($options['height']);
             }
             if (!empty($options['height']) && !empty($options['width'])) {
                 $image->thumbnail($options['width'], $options['height']);
             }
             $image->save($cachepath);
         }
         return trim(str_replace(App::path(), '', $cachepath), '/');
     } catch (\Exception $e) {
         return false;
     }
 }
Example #10
0
 /**
  * @param $fullpath
  * @return string
  */
 protected function basePath($fullpath)
 {
     return trim(str_replace(App::path(), '', $fullpath), '/');
 }
Example #11
0
<?php

use Pagekit\Application as App;
return ['name' => 'bixie/framework', 'type' => 'extension', 'main' => 'Bixie\\Framework\\FrameworkModule', 'fieldtypes' => 'fieldtypes', 'autoload' => ['Bixie\\Framework\\' => 'src'], 'routes' => ['/api/bixframework' => ['name' => '@bixframework/api', 'controller' => ['Bixie\\Framework\\Controller\\ImageApiController']]], 'resources' => ['bixie/framework:' => ''], 'permissions' => ['bixframework: upload files' => ['title' => 'Upload files']], 'settings' => 'settings-bixframework', 'config' => ['image_cache_path' => trim(str_replace(App::path(), '', App::get('path.storage') . '/bixframework'), '/')], 'events' => ['view.scripts' => function ($event, $scripts) use($app) {
    $scripts->register('framework-settings', 'bixie/framework:app/bundle/settings.js', '~extensions');
    $scripts->register('bixie-framework', 'bixie/framework:app/bundle/bixie-framework.js', ['vue']);
    //register fields
    $scripts->register('bixie-fieldtypes', 'bixie/framework:app/bundle/bixie-fieldtypes.js', ['vue', 'bixie-framework', 'uikit-tooltip']);
    foreach ($app->module('bixie/framework')->getFieldTypes() as $fieldType) {
        $fieldType->registerScripts($scripts);
    }
}, 'console.init' => function ($event, $console) {
    $console->add(new Bixie\Framework\Console\Commands\TranslateCommand());
}]];
Example #12
0
<?php

use Pagekit\Application as App;
use Bixie\Portfolio\Event\RouteListener;
use Bixie\Portfolio\PortfolioImageHelper;
return ['name' => 'bixie/portfolio', 'type' => 'extension', 'main' => 'Bixie\\Portfolio\\PortfolioModule', 'autoload' => ['Bixie\\Portfolio\\' => 'src'], 'nodes' => ['portfolio' => ['name' => '@portfolio', 'label' => 'Portfolio', 'controller' => 'Bixie\\Portfolio\\Controller\\SiteController', 'protected' => true, 'frontpage' => true]], 'routes' => ['/portfolio' => ['name' => '@portfolio', 'controller' => ['Bixie\\Portfolio\\Controller\\PortfolioController']], '/api/portfolio' => ['name' => '@portfolio/api', 'controller' => ['Bixie\\Portfolio\\Controller\\ProjectApiController', 'Bixie\\Portfolio\\Controller\\ImageApiController']]], 'resources' => ['bixie/portfolio:' => ''], 'widgets' => ['widgets/portfolio-projects.php'], 'menu' => ['portfolio' => ['label' => 'Portfolio', 'icon' => 'bixie/portfolio:icon.svg', 'url' => '@portfolio/project', 'access' => 'portfolio: manage portfolio', 'active' => '@portfolio/project*'], 'portfolio: project' => ['label' => 'Projects', 'parent' => 'portfolio', 'url' => '@portfolio/project', 'access' => 'portfolio: manage portfolio', 'active' => '@portfolio/project*'], 'portfolio: settings' => ['label' => 'Settings', 'parent' => 'portfolio', 'url' => '@portfolio/settings', 'access' => 'portfolio: manage settings', 'active' => '@portfolio/settings*']], 'permissions' => ['portfolio: manage portfolio' => ['title' => 'Manage portfolio'], 'portfolio: manage settings' => ['title' => 'Manage settings']], 'settings' => '@portfolio/settings', 'config' => ['portfolio_title' => 'My portfolio', 'portfolio_text' => '<p>This is an overview of my latest projects.</p>', 'portfolio_image' => '', 'projects_per_page' => 20, 'project_ordering' => 'date|DESC', 'portfolio_image_align' => 'left', 'columns' => 1, 'columns_small' => 2, 'columns_medium' => '', 'columns_large' => 4, 'columns_xlarge' => 6, 'columns_gutter' => 20, 'filter_tags' => true, 'teaser' => ['show_title' => true, 'show_subtitle' => true, 'show_intro' => true, 'show_image' => true, 'show_client' => true, 'show_tags' => true, 'show_date' => true, 'show_data' => true, 'show_readmore' => true, 'show_thumbs' => true, 'template' => 'panel', 'panel_style' => 'uk-panel-box', 'overlay' => 'uk-overlay uk-overlay-hover', 'overlay_position' => '', 'overlay_effect' => 'uk-overlay-fade', 'overlay_image_effect' => 'uk-overlay-scale', 'content_align' => 'left', 'tags_align' => 'uk-flex-center', 'title_size' => 'uk-h3', 'title_color' => '', 'read_more' => 'Read more', 'link_image' => 'uk-button', 'read_more_style' => 'uk-button', 'readmore_align' => 'uk-text-center', 'thumbsize' => ['width' => 400, 'height' => ''], 'columns' => 1, 'columns_small' => 2, 'columns_medium' => '', 'columns_large' => 4, 'columns_xlarge' => 6, 'columns_gutter' => 20], 'project' => ['image_align' => 'left', 'metadata_position' => 'content-top', 'tags_align' => 'uk-flex-center', 'tags_position' => 'sidebar', 'show_navigation' => 'bottom', 'thumbsize' => ['width' => 400, 'height' => ''], 'overlay_title_size' => 'uk-h3', 'overlay' => 'uk-overlay uk-overlay-hover', 'overlay_position' => '', 'overlay_effect' => 'uk-overlay-fade', 'overlay_image_effect' => 'uk-overlay-scale', 'columns' => 1, 'columns_small' => 2, 'columns_medium' => '', 'columns_large' => 4, 'columns_xlarge' => 6, 'columns_gutter' => 20], 'cache_path' => str_replace(App::path(), '', App::get('path.cache') . '/portfolio'), 'date_format' => 'F Y', 'markdown' => true, 'datafields' => []], 'events' => ['boot' => function ($event, $app) {
    $app->subscribe(new RouteListener());
    $app->extend('view', function ($view) use($app) {
        return $view->addHelper(new PortfolioImageHelper($app));
    });
    //todo event to clear cache?
}, 'view.scripts' => function ($event, $scripts) use($app) {
    $scripts->register('uikit-grid', 'app/assets/uikit/js/components/grid.min.js', 'uikit');
    $scripts->register('uikit-lightbox', 'app/assets/uikit/js/components/lightbox.min.js', 'uikit');
}, 'console.init' => function ($event, $console) {
    $console->add(new Bixie\Portfolio\Console\Commands\TranslateCommand());
}]];