public static function processPosts($posts) { $urls = ""; $keys = []; foreach ($posts as $i => $post) { if (array_key_exists('share', $post) && $post['share'] !== null && $post['share'] !== "") { $urls .= $post['share'] . ","; array_push($keys, $i); } else { $ct = cockpit("cockpit")->markdown($post['Content']); $posts[$i]['Content'] = explode('</p>', $ct)[0]; } } $urls = trim($urls, ","); if (strlen($urls) > 4) { $shares = json_decode(file_get_contents("http://api.embed.ly/1/extract?key=" . EMBEDLY_CONFIG . "&urls=" . $urls), true); foreach ($shares as $i => $share) { $posts[$keys[$i]]['embed'] = $shares[$i]; } } usort($posts, function ($a, $b) { return $b['created'] - $a['created']; }); return $posts; }
public function saveconfig() { $return = ["message" => 'Saving settings failed', "status" => 'danger']; $settings = $this->param("settings", false); if (cockpit("printdesigner")->saveConfig($settings)) { $return = ["message" => 'Settings saved', "status" => 'success']; } return json_encode($return); }
public function getErrorPage($pageName) { $errorPage = cockpit('collections')->collection('Error Pages')->findOne(["name" => $pageName]); if (!sizeof($errorPage)) { throw new Exception("Unable to load {$pageName}."); } try { $errorPageTemplate = new Templates($this->cabin); $errorPageTemplate->renderPage($errorPage, get_markdown($errorPage["content"])); } catch (Exception $e) { echo $e->getMessage(), "\n"; } }
function thumbnail($image, $width = null, $height = null, $options = array()) { if ($width && is_array($height)) { $options = $height; $height = $width; } else { $height = $height ?: $width; } $url = cockpit("mediamanager")->thumbnail($image, $width, $height, $options); // generate attributes list $attributes = \Lime\fetch_from_array($options, 'attrs', []); if (is_array($attributes)) { $tmp = []; $attributes = array_merge(['alt' => $image], $attributes); foreach ($attributes as $key => $val) { $tmp[] = $key . '="' . $val . '"'; } $attributes = implode(' ', $tmp); } echo '<img src="' . $url . '" ' . $attributes . '>'; }
<?php $options = ["rebuild" => false, "cachefolder" => "cache:thumbs", "quality" => 100, "base64" => false, "mode" => "best_fit"]; ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link href='http://fonts.googleapis.com/css?family=Inconsolata:400,700' rel='stylesheet' type='text/css'> <?php cockpit("cockpit")->assets(["js/jquery-2.1.1.js", "js/imagesloaded.pkgd.min.js", "js/packery.pkgd.min.js", "js/intense.min.js", "js/spin.min.js", "js/script.js", "css/reset.css", "css/style.css"], 'style'); ?> </head> <body> <?php region('header'); ?> <div class="content"> <div class="content-wrapper grid"> <?php foreach (gallery('home') as $image) { ?> <?php $thumburl = thumbnail_url($image["path"], 1280, $options); ?> <div class="item">
function region_field($region, $field, $key = null, $default = null) { return cockpit('regions')->region_field($region, $field, $key, $default); }
function getSessionToken() { return cockpit("printdesigner")->getSessionToken(); }
$app->get('/blog/page/{page}/', $blog); $app->get('/blog/{postslug}/', function ($postslug) use($app) { $data = collection("posts")->findOne(["Title_slug" => $postslug]); if ($data === null) { $app->abort(404, "Post '{$postslug}' does not exist."); } return $app['twig']->render('post.twig', array('data' => $data)); }); $app->get('/portfolio/', function () use($app) { $data = gallery("Portfolio"); d($data); return $app['twig']->render('gallery.twig', array('data' => $data)); }); $app->get('/cv/', function () use($app) { $content = Cms::curlGet(CV_URL . ".md"); $content = cockpit("cockpit")->markdown($content); $content = Cms::cleanHtml($content); $data = ["Title" => "Curriculum Vitae", "Subtitle" => "Lorem ipsum", "content" => "<section class='cv'>" . $content . "</section>"]; d($data); return $app['twig']->render('page.twig', array('data' => $data)); }); $app->get('/{pageslug}/', function ($pageslug) use($app) { $data = collection("Pages")->findOne(["Title" => $pageslug]); if ($data === null) { $data = collection("Pages")->findOne(["Title_slug" => $pageslug]); } if ($data === null) { $app->abort(404, "Page '{$pageslug}' does not exist."); } return $app['twig']->render('page.twig', array('data' => $data)); });
$sqlitesupport = false; // check whether sqlite is supported try { if (extension_loaded('pdo')) { $test = new PDO('sqlite::memory:'); $sqlitesupport = true; } } catch (Exception $e) { } // misc checks $checks = array("Php version >= 5.4.0" => version_compare(PHP_VERSION, '5.4.0') >= 0, "PDO extension loaded with Sqlite support" => $sqlitesupport, 'Data folder is writable: /storage/data' => is_writable(__DIR__ . '/../storage/data'), 'Cache folder is writable: /storage/cache' => is_writable(__DIR__ . '/../storage/cache'), 'Cache folder is writable: /storage/cache/assets' => is_writable(__DIR__ . '/../storage/cache/assets'), 'Cache folder is writable: /storage/cache/thumbs' => is_writable(__DIR__ . '/../storage/cache/thumbs')); foreach ($checks as $info => $check) { if (!$check) { include __DIR__ . "/fail.php"; exit; } } require __DIR__ . '/../bootstrap.php'; $app = cockpit(); // check whether cockpit is already installed try { if ($app->db->getCollection("cockpit/accounts")->count()) { header('Location: ' . $app->baseUrl('/')); exit; } } catch (Exception $e) { } $account = ["user" => "admin", "name" => "", "email" => "*****@*****.**", "active" => 1, "group" => "admin", "password" => $app->hash("admin"), "i18n" => "en"]; $app->db->insert("cockpit/accounts", $account); include __DIR__ . "/success.php";
require_once __DIR__ . '/config.php'; require_once __DIR__ . '/functions.php'; $app = new Silex\Application(); $app['debug'] = true; $app->register(new Silex\Provider\TwigServiceProvider(), unserialize(TWIG_CONFIG)); $app['twig'] = $app->share($app->extend('twig', function (Twig_Environment $twig, Silex\Application $app) { $twig->addGlobal('globals', unserialize(TWIG_GLOBALS)); $filter = new Twig_SimpleFilter('form', function ($string) { return form($string); }); $twig->addFilter($filter); $click = new Twig_SimpleFilter('clickable', function ($string) { return Twitter::clickable($string); }); $twig->addFilter($click); $markdown = new Twig_SimpleFilter('md', function ($string) { return cockpit("cockpit")->markdown($string); }); $twig->addFilter($markdown); $thumb = new Twig_SimpleFilter('thumb', function ($string) { return cockpit("mediamanager")->thumbnail($string, "300", "100"); }); $twig->addFilter($thumb); $crop = new Twig_SimpleFilter('crop', function ($string, $size) { $par = explode(",", $size); return cockpit("mediamanager")->thumbnail($string, $par[0], $par[1]); }); $twig->addFilter($crop); return $twig; })); return $app;
echo ' {"status":false,"message":"Provide organization _id!"} '; } } // Get Organization if ($_POST["organization"]) { if (@$_POST["_id"]) { $organization = cockpit('collections:findOne', 'organizations', ['_id' => $_POST["_id"]]); echo json_encode($organization); } else { echo ' {"status":false,"message":"Provide organization _id!"} '; } } // Donate if ($_POST["Action"] == "Donate") { if (@$_POST["need_id"]) { $need = cockpit('collections:findOne', 'needs', ['_id' => $_POST["need_id"]]); $Donation = ["donator" => $_POST["donator_id"], "need" => $_POST["need_id"], "message" => $_POST["message"]]; cockpit('collections:save_entry', 'donations', $Donation); echo ' {"status":true,"message":"Thank you for your donation!"} '; } else { echo ' {"status":false,"message":"Provide donator_id and need_id!"} '; } }
function generate() { return cockpit('robots')->generate(); }
function collection_populate_one($collection, $item) { return cockpit('collections')->populateOne($collection, $item); }
<?php $options = ["rebuild" => false, "cachefolder" => "cache:thumbs", "quality" => 100, "base64" => false, "mode" => "best_fit"]; $items = collection('posts')->find()->toArray(); ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link href='http://fonts.googleapis.com/css?family=Inconsolata:400,700' rel='stylesheet' type='text/css'> <?php cockpit("cockpit")->assets(["css/reset.css", "css/style.css", "css/about.css"], 'style-about'); ?> </head> <body> <?php region('header'); ?> <div class="content"> <div class="content-wrapper about"> <?php thumbnail($items[0]["media"], 350, $options); ?> <h2><?php echo $items[0]['title']; ?> </h2> <?php
function gallery($name) { return cockpit("galleries")->gallery($name); }
function collection_populate($collection, $resultset) { return cockpit("collections")->populate($collection, $resultset); }
// Register Twig $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views')); // Register UrlGenerator $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); $app->get('/', function () use($app) { $collections = cockpit('collections:collections', []); $galleries = cockpit('galleries:galleries', []); return $app['twig']->render('index.html.twig', ['collections' => $collections, 'galleries' => $galleries]); })->bind('home'); $app->get('/collection/{col}', function ($col) use($app) { $entries = collection($col)->find()->toArray(); foreach ($entries as &$entry) { $text = $entry['diary']; $html = MarkdownExtra::defaultTransform($text); $entry['diary'] = $html; } return $app['twig']->render('entries.html.twig', ['collection' => $col, 'entries' => $entries]); })->bind('collection'); $app->get('/gallery/{gal}', function ($gal) use($app) { $images = cockpit("galleries")->gallery($gal); foreach ($images as &$img) { $image = $img['path']; $imgurl = cockpit('mediamanager:thumbnail', $image, 200, 200); $img['cache'] = $imgurl; $path = $img['path']; $url = str_replace('site:', 'http://' . $app['request']->getHost() . '/', $path); $img['url'] = $url; } return $app['twig']->render('gallery.html.twig', ['images' => $images, 'gal' => $gal]); })->bind('gallery'); $app->run();
<?php //include cockpit include_once 'cockpit/bootstrap.php'; $app = new Lime\App(); // bind routes $app->bind("/", function () use($app) { return $app->render('views/index.php'); }); $app->bind("/posts", function () use($app) { // $posts = collection('Posts')->find(["public"=>true])->sort(["created"=>1])->toArray(); //get posts with related categories $posts = cockpit('collections')->populate('Posts', cockpit('collections')->find('Posts'))->toArray(); return $app->render('views/posts.php', ['posts' => $posts]); }); $app->bind("/pages", function () use($app) { $posts = collection('Pages')->find(["public" => true])->sort(["created" => 1])->toArray(); return $app->render('views/pages.php', ['pages' => $posts]); }); $app->bind("/projects", function () use($app) { //get projects with related categories $posts = cockpit('collections')->populate('Projects', cockpit('collections')->find('Projects'))->toArray(); return $app->render('views/projects.php', ['projects' => $posts]); }); // $app->bind("/article/:title_slug", function($params) use($app) { // $post = collection('blog')->findOne(["title_slug"=>$params['title_slug']]); // return $app->render('views/article.php', ['post' => $post]); // }); $app->run();
$app->route('/galleries/gallery/' . $gallery['_id']); ?> "> <i class="uk-icon-map-marker"></i> <?php echo $gallery["name"]; ?> <?php if (count($gallery["images"])) { ?> <div class="uk-margin-small-top"> <?php foreach (array_slice($gallery["images"], 0, 6) as $image) { ?> <div class="uk-thumbnail uk-rounded uk-thumb-small"> <img src="<?php echo cockpit("mediamanager")->thumbnail($image['path'], 25, 25); ?> " width="25" height="25" title="<?php echo $image['path']; ?> "> </div> <?php } ?> </div> <?php } ?> </a> </li>
function get_path_to($path) { return cockpit()->path($path); }
function get_url_to($path) { return cockpit()->pathToUrl($content); }
<?php require_once "cp/bootstrap.php"; cockpit("robots")->generate();
function collection($name) { return cockpit("collections")->collection($name); }
function form($name, $options = []) { cockpit("forms")->form($name, $options); }
<?php require_once "cp/bootstrap.php"; cockpit("sitemap")->generate_sitemap();
}); // mailer service $app->service("mailer", function () use($app, $config) { $options = isset($config['mailer']) ? $config['mailer'] : []; $mailer = new \Mailer(isset($options["transport"]) ? $options['transport'] : 'mail', $options); return $mailer; }); // set cache path $tmppath = $app->path('cache:tmp'); $app("cache")->setCachePath($tmppath); $app->renderer->setCachePath($tmppath); // i18n $app("i18n")->locale = isset($config['i18n']) ? $config['i18n'] : 'en'; // load modules $app->loadModules([COCKPIT_DIR . '/modules/core', COCKPIT_DIR . '/modules/addons']); // load custom global bootstrap if ($custombootfile = $app->path('custom:bootstrap.php')) { include $custombootfile; } } // shorthand modules method call e.g. cockpit('regions:render', 'test'); if (func_num_args() > 1) { $arguments = func_get_args(); list($module, $method) = explode(':', $arguments[0]); array_splice($arguments, 0, 1); return call_user_func_array([$app->module($module), $method], $arguments); } return $module ? $app->module($module) : $app; } $cockpit = cockpit();
function cockpit_js_lib($token = null) { echo cockpit("restservice")->js_lib($token); }
function cockpit_js_lib() { echo cockpit("restservice")->js_lib(); }
public function getUrl() { $rewrites = cockpit('collections')->collection('Rewrites')->findOne(["rewrite" => $this->requestUrl]); return $rewrites; }
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link href='http://fonts.googleapis.com/css?family=Inconsolata:400,700' rel='stylesheet' type='text/css'> <?php cockpit("cockpit")->assets(["css/reset.css", "css/style.css"], 'style'); ?> </head> <body> <?php region('header'); ?> <div class="content"> <div class="content-wrapper"> todo : un formulaire </div> </div> </body> </html>