コード例 #1
0
ファイル: Config.php プロジェクト: askoxyz/elsa
 public static function get($key)
 {
     $config = new FrontMatter(ELSA . '/config.yml');
     if (!empty($config->fetch($key))) {
         return $config->fetch($key);
     }
     return false;
 }
コード例 #2
0
 public function testSetup()
 {
     $page = new FrontMatter($this->sampleFile);
     # Test predefined variables to see if most custom yaml / content variables work
     $this->assertEquals($this->sampleContent, $page->fetch('content'));
     $this->assertEquals($this->sampleTitle, $page->fetch('title'));
     $this->assertEquals($this->sampleUri, $page->fetch('uri'));
 }
コード例 #3
0
ファイル: Content.php プロジェクト: askoxyz/elsa
 public function get()
 {
     $content = [];
     $count = 1;
     // initial object creation
     foreach (glob(ELSA . '/content/' . $this->folder . '/*.' . $this->extension) as $contentItem) {
         // parse content
         $frontmatter = new FrontMatter($contentItem);
         $parsedown = new ParsedownExtra();
         $meta = [];
         $type = preg_match('/content\\/(.*)\\//', $contentItem, $match);
         $type = $match[1];
         foreach ($frontmatter->fetchMeta() as $key => $value) {
             $meta[$key] = $value;
         }
         // compose
         $content[$count]['id'] = (int) @explode('_', array_pop(explode('/', $contentItem)))[0];
         $content[$count]['slug'] = @explode('.', explode('_', array_pop(explode('/', $contentItem)))[1])[0];
         $content[$count]['content'] = $parsedown->text($frontmatter->fetchContent());
         $content[$count]['content_raw'] = $frontmatter->fetchContent();
         $content[$count]['type'] = $type;
         $content[$count]['meta'] = $meta;
         $count++;
     }
     // order
     usort($content, function ($a, $b) {
         // id desc
         if ($this->orderby === 'id' && $this->order === 'desc') {
             return $b['id'] - $a['id'];
         }
         // id asc
         if ($this->orderby === 'id' && $this->order === 'asc') {
             return $a['id'] - $b['id'];
         }
         // timestamp desc
         if ($this->orderby === 'timestamp' && $this->order === 'desc') {
             return $b['meta']['timestamp'] - $a['meta']['timestamp'];
         }
         // timestamp asc
         if ($this->orderby === 'timestamp' && $this->order === 'asc') {
             return $a['meta']['timestamp'] - $b['meta']['timestamp'];
         }
     });
     // convert to objects
     $content = json_decode(json_encode($content));
     // with slug ...
     if ($this->slug) {
         // find the content we want
         foreach ($content as $contentItem) {
             if ($contentItem->slug === $this->slug) {
                 return $contentItem;
                 break;
             }
         }
     }
     return $content;
 }
コード例 #4
0
 public static function show_news($folder = 'posts', $template = 'templates')
 {
     $m = new Mustache_Engine();
     $files = glob("{$folder}/*.md");
     /** /
         usort($files, function($a, $b) {
             return filemtime($a) < filemtime($b);
         });
         /**/
     $html = '';
     foreach ($files as $file) {
         $route = substr($file, strlen($folder) + 1, -3);
         $page = new FrontMatter($file);
         $title = $page->fetch('title') != '' ? $page->fetch('title') : $route;
         $date = $page->fetch('date');
         $author = $page->fetch('author');
         $description = $page->fetch('description') == '' ? '' : $page->fetch('description');
         $data[] = array('title' => $title, 'route' => $route, 'author' => $author, 'description' => $description, 'date' => $date);
     }
     /**/
     function date_compare($a, $b)
     {
         $t1 = strtotime($a['date']);
         $t2 = strtotime($b['date']);
         return $t1 - $t2;
     }
     usort($data, 'date_compare');
     $data = array_reverse($data);
     /**/
     $template = file_get_contents('templates/show_news.tpl');
     $data['files'] = $data;
     return $m->render($template, $data);
     return $html;
 }
コード例 #5
0
ファイル: index.php プロジェクト: n00dles/ogma-docs
<?php

require_once 'config.php';
// enable error temporarily in case there are startup errors
if (DEBUG === true) {
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(-1);
}
require_once 'config.php';
require_once 'lib' . DS . 'core.php';
$system = new Core();
$nav = $system->nav;
$uri = Core::getMyUrl();
$pagedetails = $system->getPage($uri);
$nav = $system->nav;
Filters::addFilter('content', 'Shortcodes::doShortcode');
//Core::debugArray($system->pages);
$option = new FrontMatter(Core::getRootPath() . DS . 'pages' . DS . Core::$language . $pagedetails['file']);
$markdownContent = new ParsedownExtra();
$content = $option->fetch('content');
$content2 = $markdownContent->text($content);
$content = Filters::execFilter('content', $content2);
$title = $option->fetch('title') != '' ? $option->fetch('title') : SITETITLE;
$template = $option->fetch('template');
$author = $option->fetch('author');
$keywords = $option->fetch('keywords');
$description = $option->fetch('description');
$filepath = DS . 'pages' . DS . Core::$language . $pagedetails['file'];
$themeurl = '/theme/' . THEME;
require_once 'theme/' . THEME . '/' . $template;
コード例 #6
0
ファイル: dropbox.php プロジェクト: betsyzhang/chyrp
 static function admin_manage_dropbox($admin)
 {
     if (!Visitor::current()->group->can("add_post", "add_draft")) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to create posts."));
     }
     if (empty($_POST)) {
         return $admin->display("manage_dropbox");
     }
     $config = Config::current();
     if (!isset($config->module_dropbox["oauth_token"])) {
         Flash::notice(__("You need to authorize Dropbox first.", "dropbox"), "/admin/?action=dropbox_settings");
     }
     $data = json_decode(file_get_contents("http://chyrp.net/api/1/dropboxsync.php?keys"), true);
     $app_key = $data["key"];
     $app_secret = $data["secret"];
     $storage = new \Dropbox\OAuth\Storage\Session();
     $OAuth = new \Dropbox\OAuth\Consumer\Curl($app_key, $app_secret, $storage);
     $dropbox = new \Dropbox\API($OAuth);
     $delta = $dropbox->delta();
     $delta = $delta["body"];
     if ($delta->cursor != $config->module_dropbox["cursor"]) {
         if (count($delta->entries) > 0) {
             foreach ($delta->entries as $entry) {
                 $tmpfname = tempnam("/tmp", "md");
                 $file = $dropbox->getFile(ltrim($entry[0], "/"), $tmpfname);
                 $post = new FrontMatter($file["name"]);
                 $date = explode(".", ltrim($entry[0], "/"));
                 $values = array("title" => $post->fetch("title"), "body" => $post->fetch("content"));
                 # Set defaults
                 fallback($clean, oneof($post->fetch("slug"), strtolower(str_replace(" ", "-", $post->fetch("title")))));
                 fallback($url, Post::check_url($clean));
                 fallback($pinned, oneof($post->fetch("pinned"), 0));
                 fallback($status, oneof($post->fetch("status"), "public"));
                 fallback($date, oneof(datetime($post->fetch("date")), datetime($date[0])));
                 $post = Post::add($values, $clean, $url, "text", 1, $pinned, $status, datetime($post->fetch("date")), datetime($post->fetch("date")), false);
             }
         }
         $set = array($config->set("module_dropbox", array("oauth_token_secret" => $config->module_dropbox['oauth_token_secret'], "oauth_token" => $config->module_dropbox['oauth_token'], "uid" => $config->module_dropbox['uid'], "cursor" => $delta->cursor)));
         if (!in_array(false, $set)) {
             Flash::notice(__("Post imported successfully.", "dropbox"), "/admin/?action=manage_posts");
         }
     }
 }