Beispiel #1
4
 /**
  * Get the wizard base uri from the current path.
  *
  * @return  string
  */
 public function uriFromPath()
 {
     $path = kirby::instance()->path();
     // Check if the current path includes the progress indicator
     if (preg_match('#/\\d$#', $path)) {
         // Strip numeric value indicating the progress
         $parts = explode('/', $path);
         array_pop($parts);
         $path = implode('/', $parts);
     }
     return $this->uri = $path;
 }
Beispiel #2
0
 public function parse()
 {
     if (!$this->field) {
         return '';
     }
     $text = $this->field->value;
     // pre filters
     foreach (static::$pre as $filter) {
         $text = call_user_func_array($filter, array($this, $text));
     }
     // tagsify
     $text = preg_replace_callback('!(?=[^\\]])\\([a-z0-9_-]+:.*?\\)!is', array($this, 'tag'), $text);
     // markdownify
     if (kirby()->option('markdown')) {
         $text = call(kirby::instance()->option('markdown.parser'), $text);
     }
     // smartypantsify
     if (kirby()->option('smartypants')) {
         $text = str_replace('"', '"', $text);
         $text = call(kirby::instance()->option('smartypants.parser'), $text);
     }
     // post filters
     foreach (static::$post as $filter) {
         $text = call_user_func_array($filter, array($this, $text));
     }
     return $text;
 }
 public function __construct($path)
 {
     $this->kirby = kirby::instance();
     if (is_a($path, 'Media')) {
         parent::__construct($path->root(), $path->url());
     } else {
         parent::__construct(url::isAbsolute($path) ? null : $this->kirby->roots()->index() . DS . ltrim($path, DS), url::makeAbsolute($path));
     }
 }
Beispiel #4
0
 public function __construct()
 {
     $root = kirby::instance()->roots()->accounts();
     foreach (dir::read($root) as $file) {
         // skip invalid account files
         if (f::extension($file) != 'php') {
             continue;
         }
         $user = new User(f::name($file));
         $this->append($user->username(), $user);
     }
 }
 public function __construct(User $user)
 {
     // store the parent user object
     $this->user = $user;
     // this should rather be coming from the user object
     $this->kirby = kirby::instance();
     // try to find the avatar
     if ($file = f::resolve($this->kirby->roots()->avatars() . DS . $user->username(), ['jpg', 'jpeg', 'gif', 'png'])) {
         $filename = f::filename($file);
     } else {
         $filename = $user->username() . '.jpg';
         $file = $this->kirby->roots()->avatars() . DS . $filename;
     }
     parent::__construct($file, $this->kirby->urls()->avatars() . '/' . $filename);
 }
function jade($template)
{
    $templates = kirby::instance()->roots()->templates();
    // Closure to recursively get the modification time from jade templates and
    // their super templates (determeined by pre-parsing 'extends' statements).
    $getChangeTime = function ($template, $time) use(&$getChangeTime, $templates) {
        $file = "{$templates}/{$template}.jade";
        $t = @filectime($file);
        if ($t === false) {
            die("Can't open jade file '{$file}'");
        }
        if ($t > $time) {
            $time = $t;
        }
        $fp = fopen($file, 'r');
        // Find all the lines of the template that contains an valid statements,
        // and see there are any 'extends' or 'include' statements to determine
        // dependencies.
        while (true) {
            $line = fgets($fp);
            if ($line === false) {
                break;
            }
            $line = trim($line);
            if (!$line || !strncmp($line, '//', 2)) {
                continue;
            }
            if (!strncmp($line, 'extends ', 8) || !strncmp($line, 'include ', 8)) {
                $time = $getChangeTime(substr($line, 8), $time);
            }
        }
        fclose($fp);
        return $time;
    };
    $time = $getChangeTime($template, 0);
    static $jade = null;
    if (!isset($jade) || !$jade) {
        $jade = new Jade\Jade(true);
    }
    $cache = kirby::instance()->roots()->cache() . DS . "{$template}.jade.php";
    $t = @filectime($cache);
    // Now get the modification time from the cached file, and regenerate if
    // the jade template or any of its dependencies have changed.
    if ($t === false || $t < $time) {
        file_put_contents($cache, $jade->render("{$templates}/{$template}.jade"));
    }
    return $cache;
}
Beispiel #7
0
function snippet_detect($file, $data = array(), $return = false)
{
    if (is_object($data)) {
        $data = array('item' => $data);
    }
    // If the session variable is not found, set the default value (e.g 'mobile')
    $device_class = s::get('device_class', 'mobile');
    // Embed the device class specific snippet
    if ($device_class == 'mobile') {
        // Embed the mobile snippet (`mobile` is the default snippet, without the device specific `.postfix`, e.g. footer.php)
        return tpl::load(kirby::instance()->roots()->snippets() . DS . $file . '.php', $data, $return);
    } else {
        // Embed the device class specific snippet (e.g. `footer.desktop.php`)
        return tpl::load(kirby::instance()->roots()->snippets() . DS . $file . '.' . $device_class . '.php', $data, $return);
    }
}
Beispiel #8
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $roles = kirby::instance()->option('roles');
     // set the default set of roles, if roles are not configured
     if (empty($roles)) {
         $roles = array(array('id' => 'admin', 'name' => 'Admin', 'default' => true, 'panel' => true), array('id' => 'editor', 'name' => 'Editor', 'panel' => true));
     }
     foreach ($roles as $role) {
         $role = new Role($role);
         $this->data[$role->id()] = $role;
     }
     // check for a valid admin role
     if (!isset($this->data['admin'])) {
         throw new Exception('There must be an admin role');
     }
     // check for a valid default role
     if (!$this->findDefault()) {
         $this->data['admin']->default = true;
     }
 }
Beispiel #9
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $roles = kirby::instance()->option('roles');
     // set the default set of roles, if roles are not configured
     if (empty($roles)) {
         $roles = array(array('id' => 'admin', 'name' => 'Admin', 'default' => true), array('id' => 'editor', 'name' => 'Editor', 'permissions' => array('panel.access' => true, 'panel.site.update' => false, 'panel.page.create' => true, 'panel.page.update' => true, 'panel.page.move' => true, 'panel.page.sort' => true, 'panel.page.hide' => true, 'panel.page.delete' => true, 'panel.file.upload' => true, 'panel.file.replace' => true, 'panel.file.update' => true, 'panel.file.delete' => true, 'panel.user.add' => false, 'panel.user.edit' => false, 'panel.user.role' => false, 'panel.user.delete' => false)));
     }
     foreach ($roles as $role) {
         $role = new Role($role);
         $this->data[$role->id()] = $role;
     }
     // check for a valid admin role
     if (!isset($this->data['admin'])) {
         throw new Exception('There must be an admin role');
     }
     // check for a valid default role
     if (!$this->findDefault()) {
         $this->data['admin']->default = true;
     }
 }
Beispiel #10
0
/**
 * Helper to create correct text file names for content files
 *
 * @param string $uri
 * @param string $template
 * @param string $lang
 * @return string
 */
function textfile($uri, $template = null, $lang = null)
{
    if (is_null($template)) {
        $template = $this->intendedTemplate();
    }
    $curi = '';
    $parts = str::split($uri, '/');
    $parent = site();
    foreach ($parts as $p) {
        if ($parent and $child = $parent->children()->find($p)) {
            $curi .= '/' . $child->dirname();
            $parent = $child;
        } else {
            $curi .= '/' . $p;
            $parent = null;
        }
    }
    $uri = ltrim($curi, '/');
    $root = kirby::instance()->roots()->content();
    $ext = kirby::instance()->option('content.file.extension', 'txt');
    return $root . DS . r(!empty($uri), str_replace('/', DS, $uri) . DS) . $template . r($lang, '.' . $lang) . '.' . $ext;
}
Beispiel #11
0
<?php

ob_start();
$q = call(kirby::instance()->option('smartypants.parser'), get('q'));
$words = implode('|', explode(' ', $q));
$pages = $site->search(get('q'), 'title|text')->filter(function ($page) {
    return $page->visible() || $page->intendedTemplate() == 'news' || $page->intendedTemplate() == 'event' || $page->intendedTemplate() == 'annual-report';
});
$url = function ($page) {
    return $page->article()->empty() ? $page->intendedTemplate() === 'external' ? $page->external() : $page->url() . '?' . http_build_query(['matches' => get('q')]) : $page->article()->toFile()->url();
};
$target = function ($page) {
    return !$page->article()->empty() || $page->intendedTemplate() === 'external' ? '_blank' : '_self';
};
foreach ($pages as $page) {
    ?>
<article>
  <a class="link-list__link" href="<?php 
    echo $url($page);
    ?>
" target="<?php 
    echo $target($page);
    ?>
">
    <?php 
    if ($page->parents()->count() > 0) {
        ?>
    <header class="link-list__meta">
      <?php 
        echo implode(' > ', $page->parents()->flip()->map(function ($page) {
            return $page->title()->html();
Beispiel #12
0
 /**
  * Creates a new user
  *
  * @param array $user
  * @return User
  */
 public static function create($data = array())
 {
     // sanitize the given data for the new user
     $data = static::sanitize($data, 'insert');
     // validate the dataset
     static::validate($data, 'insert');
     // create the file root
     $file = kirby::instance()->roots()->accounts() . DS . $data['username'] . '.php';
     // check for an existing username
     if (file_exists($file)) {
         throw new Exception('The username is taken');
     }
     // create a new hash for the password
     if (!empty($data['password'])) {
         $data['password'] = password::hash($data['password']);
     }
     static::save($file, $data);
     // return the created user project
     return new static($data['username']);
 }
Beispiel #13
0
 /**
  * Returns the full path to the intended template file
  * This template file may not exist.
  *
  * @return string
  */
 public function intendedTemplateFile()
 {
     return kirby::instance()->roots()->templates() . DS . $this->intendedTemplate() . '.php';
 }
Beispiel #14
0
/**
 * Compile less to css and then call css.handler
 *
 * @param string $url
 * @param string $media
 * @return string
 */
function less()
{
    return call(kirby::instance()->option('less.handler'), func_get_args());
}
Beispiel #15
0
 public function users()
 {
     return kirby::instance()->site()->users()->filterBy('role', $this->id);
 }
 public function defaults()
 {
     $defaults = array('url' => false, 'timezone' => 'UTC', 'license' => null, 'rewrite' => true, 'error' => 'error', 'home' => 'home', 'locale' => 'en_US.UTF8', 'routes' => array(), 'headers' => array(), 'languages' => array(), 'roles' => array(), 'cache' => false, 'debug' => 'env', 'ssl' => false, 'cache.driver' => 'file', 'cache.options' => array(), 'cache.ignore' => array(), 'cache.autoupdate' => true, 'date.handler' => 'date', 'tinyurl.enabled' => true, 'tinyurl.folder' => 'x', 'markdown' => true, 'markdown.extra' => false, 'markdown.breaks' => true, 'smartypants' => false, 'smartypants.attr' => 1, 'smartypants.doublequote.open' => '&#8220;', 'smartypants.doublequote.close' => '&#8221;', 'smartypants.space.emdash' => ' ', 'smartypants.space.endash' => ' ', 'smartypants.space.colon' => '&#160;', 'smartypants.space.semicolon' => '&#160;', 'smartypants.space.marks' => '&#160;', 'smartypants.space.frenchquote' => '&#160;', 'smartypants.space.thousand' => '&#160;', 'smartypants.space.unit' => '&#160;', 'smartypants.skip' => 'pre|code|kbd|script|style|math', 'kirbytext.video.class' => 'video', 'kirbytext.video.width' => false, 'kirbytext.video.height' => false, 'kirbytext.image.figure' => true, 'content.file.extension' => 'txt', 'content.file.ignore' => array(), 'content.file.normalize' => false, 'thumbs.driver' => 'gd', 'thumbs.filename' => '{safeName}-{hash}.{extension}', 'thumbs.destination' => false);
     // default markdown parser callback
     $defaults['markdown.parser'] = function ($text) {
         // initialize the right markdown class
         $parsedown = kirby::instance()->option('markdown.extra') ? new ParsedownExtra() : new Parsedown();
         // set markdown auto-breaks
         $parsedown->setBreaksEnabled(kirby::instance()->option('markdown.breaks'));
         // parse it!
         return $parsedown->text($text);
     };
     // default smartypants parser callback
     $defaults['smartypants.parser'] = function ($text) {
         $parser = new SmartyPantsTypographer_Parser(kirby::instance()->option('smartypants.attr', 1));
         return $parser->transform($text);
     };
     // css handler
     $defaults['css.handler'] = function ($url, $media = null) {
         $kirby = kirby::instance();
         if (is_array($url)) {
             $css = array();
             foreach ($url as $u) {
                 $css[] = call($kirby->option('css.handler'), array($u, $media));
             }
             return implode(PHP_EOL, $css) . PHP_EOL;
         }
         // auto template css files
         if ($url == '@auto') {
             $file = $kirby->site()->page()->template() . '.css';
             $root = $kirby->roots()->autocss() . DS . $file;
             $url = $kirby->urls()->autocss() . '/' . $file;
             if (!file_exists($root)) {
                 return false;
             }
         }
         return html::tag('link', null, array('rel' => 'stylesheet', 'href' => url($url), 'media' => $media));
     };
     // js handler
     $defaults['js.handler'] = function ($src, $async = false) {
         $kirby = kirby::instance();
         if (is_array($src)) {
             $js = array();
             foreach ($src as $s) {
                 $js[] = call($kirby->option('js.handler'), array($s, $async));
             }
             return implode(PHP_EOL, $js) . PHP_EOL;
         }
         // auto template css files
         if ($src == '@auto') {
             $file = $kirby->site()->page()->template() . '.js';
             $root = $kirby->roots()->autojs() . DS . $file;
             $src = $kirby->urls()->autojs() . '/' . $file;
             if (!file_exists($root)) {
                 return false;
             }
         }
         return html::tag('script', '', array('src' => url($src), 'async' => $async));
     };
     return $defaults;
 }
Beispiel #17
0
 public function testInstance()
 {
     $kirby = $this->kirbyInstance();
     $this->assertEquals($kirby, kirby::instance());
 }
Beispiel #18
0
 /**
  * Creates a new page object
  *
  * @param string $uri
  * @param string $template
  * @param array $data
  */
 public static function create($uri, $template, $data = array())
 {
     if (!is_string($template) or empty($template)) {
         throw new Exception('Please pass a valid template name as second argument');
     }
     // try to create the new directory
     $uri = static::createDirectory($uri);
     // create the path for the textfile
     $file = textfile($uri, $template);
     // try to store the data in the text file
     if (!data::write($file, $data, 'kd')) {
         throw new Exception('The page file could not be created');
     }
     // get the new page object
     $page = page($uri);
     if (!is_a($page, 'Page')) {
         throw new Exception('The new page object could not be found');
     }
     kirby::instance()->cache()->flush();
     return $page;
 }
Beispiel #19
0
 /**
  * Returns the absolute URL for the file
  *
  * @return string
  */
 public function url()
 {
     return kirby::instance()->urls()->content() . '/' . $this->page->diruri() . '/' . $this->filename;
 }