Esempio n. 1
0
 /**
  * [init description]
  * @param  [type] $app [description]
  * @return [type]      [description]
  */
 public static function init($app)
 {
     self::$app = $app;
     // init meta container
     self::$meta = new \ContainerArray(['route' => $app["route"], 'site' => $app, 'title' => $app["site.title"], 'keywords' => '', 'author' => '', 'description' => '', 'page' => null, 'assets' => new \ArrayObject([]), 'data' => new \ContainerArray([])]);
     $app["site:meta"] = self::$meta;
     $app->viewvars['meta'] = self::$meta;
     $app->viewvars['site'] = $app;
     $app->viewvars['app'] = $app;
 }
Esempio n. 2
0
/**
 * [thumb_url description]
 * @param  [type] $image   [description]
 * @param  [type] $width   [description]
 * @param  [type] $height  [description]
 * @param  array  $options [description]
 * @return [type]          [description]
 */
function thumb_url($image, $width = null, $height = null, $options = array())
{
    if ($width && is_array($height)) {
        $options = $height;
        $height = $width;
    } else {
        $height = $height ?: $width;
    }
    $options = array_merge(array("rebuild" => false, "cachefolder" => "storage:thumbs", "quality" => 100, "base64" => false, "mode" => "crop", "domain" => false), $options);
    extract($options);
    $path = copi::$app->path($image);
    $ext = pathinfo($path, PATHINFO_EXTENSION);
    $url = "data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///////wAAACH5BAEHAAIALAAAAAABAAEAAAICVAEAOw==";
    // transparent 1px gif
    if (!file_exists($path) || is_dir($path)) {
        return $url;
    }
    if (!in_array(strtolower($ext), array('png', 'jpg', 'jpeg', 'gif'))) {
        return $url;
    }
    if (!is_numeric($height)) {
        $height = $width;
    }
    if (is_null($width) && is_null($height)) {
        return copi::$app->pathToUrl($path);
    }
    if (!in_array($mode, ['crop', 'best_fit', 'resize'])) {
        $mode = 'crop';
    }
    $method = $mode == 'crop' ? 'thumbnail' : $mode;
    if ($base64) {
        try {
            $data = copi::helper("image")->take($path)->{$method}($width, $height)->base64data(null, $quality);
        } catch (Exception $e) {
            return $url;
        }
        $url = $data;
    } else {
        $filetime = filemtime($path);
        $savepath = copi::$app->path($cachefolder) . "/" . md5($path) . "_{$width}x{$height}_{$quality}_{$filetime}_{$mode}.{$ext}";
        if ($rebuild || !file_exists($savepath)) {
            try {
                copi::helper("image")->take($path)->{$method}($width, $height)->save($savepath, $quality);
            } catch (Exception $e) {
                return $url;
            }
        }
        $url = copi::$app->pathToUrl($savepath);
        if ($domain) {
            $url = rtrim(copi::$app->getSiteUrl(true), '/') . $url;
        }
    }
    return $url;
}
Esempio n. 3
0
                    $this->layout = false;
                    $this->response->body = $this->render("layouts:error/500-debug.php", ['error' => json_decode($this->response->body, true)]);
                }
            } else {
                if ($this->req_is('ajax')) {
                    $this->response->body = '{"error": "500", "message": "system error"}';
                } else {
                    $this->layout = false;
                    $this->response->body = copi::view("theme:error/500.html");
                }
            }
            break;
        case 404:
            // route | file not found
            if ($this->req_is('ajax')) {
                $this->response->body = '{"error": "404", "message":"File not found"}';
            } else {
                $this->layout = false;
                $this->response->body = copi::view("theme:error/404.html");
            }
            break;
    }
    /**
     * send some debug information
     * back to client (visible in the network panel)
     */
    if ($this['debug'] && !headers_sent()) {
        header('SITE_DURATION_TIME: ' . CP_DURATION_TIME . 'sec');
        header('SITE_MEMORY_USAGE: ' . CP_MEMORY_USAGE . 'mb');
    }
}, 100);
Esempio n. 4
0
     *
     * Anyway, have fun using Copilot!
     *
     * Greets
     * Artur
     *
     */
    $license = ['type' => 'trial'];
    $code = (string) $this->app['copilot.license'];
    $data = [];
    try {
        $data = (array) Firebase\JWT\JWT::decode($code, 'copilot', ['HS256']);
    } catch (Exception $e) {
    }
    if (isset($data['name'], $data['company'], $data['created'], $data['email'], $data['type'])) {
        $license = $data;
        $license['code'] = $code;
    }
    return (object) $license;
}]);
// REST
if (COCKPIT_REST) {
    $app->on('cockpit.rest.init', function ($routes) {
        $routes['copilot'] = 'Copilot\\Controller\\RestApi';
    });
}
// ADMIN
if (COCKPIT_ADMIN && !COCKPIT_REST) {
    copi::trigger('cockpit.bootstrap', [$this]);
    include_once __DIR__ . '/admin.php';
}
Esempio n. 5
0
<?php

define('COCOPI_FRONTEND', true);
/**
 *  Fix for PHP built in webserver to handle static files correctly
 *
 *  start local webserver: php -S localhost:8080 index.php
 */
if (PHP_SAPI == 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
    return false;
}
/**
 * bootstrap Cockpit
 */
include_once __DIR__ . '/cockpit/bootstrap.php';
/**
 * start the app engine
 */
copi::run();
Esempio n. 6
0
        echo '<script>window.COPILOT_PAGE_TYPES = ' . json_encode((object) $types) . '</script>';
        echo $this->assets('copilot:assets/js/copilot.js');
    });
    // bind admin routes /copilot/*
    $this->bindClass('Copilot\\Controller\\Update', 'copilot/update');
    $this->bindClass('Copilot\\Controller\\Utils', 'copilot/utils');
    $this->bindClass('Copilot\\Controller\\Admin', 'copilot');
    // add to modules menu
    $this('admin')->addMenuItem('modules', ['label' => 'Pages', 'icon' => 'clone', 'route' => '/copilot', 'active' => strpos($this['route'], '/copilot') === 0]);
    /**
     * listen to app search to filter pages
     */
    $this->on('cockpit.search', function ($search, $list) {
        copi::find(function ($page) use($search, $list) {
            if (stripos($page->meta('title', ''), $search) !== false) {
                $list[] = ['icon' => 'file-text-o', 'title' => $page->meta('title', $page->filename()), 'url' => $this->routeUrl('/copilot/page' . $page->relpath())];
            }
        });
    });
    // dashboard widgets
    $app->on("admin.dashboard.widgets", function ($widgets) {
        $home = copi::home();
        $pages = copi::pages('content:')->sorted();
        $license = $this->module("copilot")->getLicense()->type;
        $widgets[] = ["name" => "pages", "content" => $this->view("copilot:views/widgets/dashboard.php", compact('pages', 'home', 'license')), "area" => 'main'];
    }, 100);
    // load custom web components
    if (strpos($this['route'], '/copilot') === 0) {
        $app('admin')->data->components->append('copilot:assets/components/pagejumplist.html');
    }
});