/home
/ngvipwtf
/offscreen2023
/kirby
/vendor
/getkirby
/toolkit
/lib
/cache
/driver
/file.php
* see defaults for available parameters
*
* @param array $params
*/
public function __construct($params = array()) {
if(is_string($params)) {
$params = array('root' => $params);
}
$defaults = array(
'root' => null,
'extension' => null
);
$this->options = array_merge($defaults, $params);
// check for a valid cache directory
if(!is_dir($this->options['root'])) {
throw new Error('The cache directory does not exist', static::ERROR_MISSING_CACHE_DIRECTORY);
}
}
/**
* Returns the full path to a file for a given key
*
* @param string $key
* @return string
*/
protected function file($key) {
return $this->options['root'] . DS . $key . r($this->options['extension'], '.' . $this->options['extension']);
}
/**
* Write an item to the cache for a given number of minutes.
*
* <code>
* // Put an item in the cache for 15 minutes
* Cache::set('value', 'my value', 15);
/home
/ngvipwtf
/offscreen2023
/site
/plugins
/newsletter
/newsletter.php
use \DrewM\MailChimp\MailChimp;
use \Cache\Driver\File as Cache;
class Newsletter {
static public function api() {
return new MailChimp(c::get('mailchimp.key'));
}
static public function folders() {
return static::api()->get('campaign-folders');
}
static public function folder() {
return static::api()->get('campaign-folders/' . c::get('mailchimp.folder'));
}
static public function cache() {
return new Cache([
'root' => kirby()->roots()->cache() . '/newsletter'
]);
}
static public function campaigns() {
// store the archive for 24 hours
$expiry = (24 * 60);
$cacheId = 'campaigns';
$campaigns = static::cache()->get($cacheId);
$api = static::api();
// fetch stuff from the api
if(!$campaigns) {
// change list_id to folder_id to fetch from specific folder instead
$response = $api->get('campaigns', [
'list_id' => c::get('mailchimp.list'),
'folder_id' => c::get('mailchimp.folder'),
'sort_field' => 'send_time',
'sort_dir' => 'DESC'
/home
/ngvipwtf
/offscreen2023
/site
/plugins
/newsletter
/newsletter.php
}
// make it a kirby collection of objects to make it a bit
// nicer to use in templates
$campaigns = new Collection(array_map(function($campaign) {
return new Obj($campaign);
}, $campaigns));
return $campaigns;
}
static public function lists() {
return static::api()->get('lists');
}
static public function subscribers() {
$cacheId = 'subscribers';
$subscribers = static::cache()->get($cacheId);
if(empty($subscribers)) {
$api = static::api();
$list = $api->get('lists/' . c::get('mailchimp.list'));
if($api->success()) {
$subscribers = $list['stats']['member_count'];
static::cache()->set($cacheId, $subscribers);
}
}
return $subscribers;
}
static public function subscribe($email) {
// encode email address first
/home
/ngvipwtf
/offscreen2023
/site
/controllers
/dispatch.php
$message = '✔︎ Thank you for subscribing! Check your inbox to confirm.';
$status = 200;
} catch(Exception $e) {
$message = $e->getMessage();
$status = 400;
}
if(r::ajax()) {
die(response::json([
'status' => $status,
'message' => $message
], $status));
}
}
return [
'subscribers' => number_format(newsletter::subscribers()),
'archive' => snippet('dispatch/archive', [
'campaigns' => newsletter::campaigns(),
'limit' => 5
], true),
'message' => $message
];
};
/home
/ngvipwtf
/offscreen2023
/kirby
/core
/page.php
*
* @return array
*/
public function controller($arguments = array()) {
// first try to get a controller for the representation
$controller = null;
if($representation = $this->representation()) {
$controller = $this->kirby->registry->get('controller', $this->template() . '.' . $representation);
}
// no representation or no special controller: try the normal one
if(!$controller) $controller = $this->kirby->registry->get('controller', $this->template());
if(is_a($controller, 'Closure')) {
return (array)call_user_func_array($controller, array(
$this->site,
$this->site->children(),
$this,
$arguments
));
}
return array();
}
/**
* Converts the entire page array into
* a json string
*
* @param closure $callback Filter callback
* @return string
*/
public function toJson($callback = null) {
return json_encode($this->toArray($callback));
}
/**
* Makes it possible to echo the entire object
/home
/ngvipwtf
/offscreen2023
/kirby
/kirby
/component
/template.php
* @link http://getkirby.com
* @copyright Bastian Allgeier
* @license http://getkirby.com/license
*/
class Template extends \Kirby\Component {
/**
* Collects all template data by page
*
* @param mixed $page
* @param array $data
* @return array
*/
public function data($page, $data = []) {
if($page instanceof Page) {
$data = array_merge(
$page->templateData(),
$data,
$page->controller($data)
);
}
// apply the basic template vars
return array_merge(array(
'kirby' => $this->kirby,
'site' => $this->kirby->site(),
'pages' => $this->kirby->site()->children(),
'page' => $page
), $data);
}
/**
* Returns all available template files
*
* @return array
*/
public function files() {
$files = dir::read($this->kirby->roots()->templates());
/home
/ngvipwtf
/offscreen2023
/kirby
/kirby
/component
/template.php
* @return string
*/
public function file($name) {
return $this->kirby->roots()->templates() . DS . str_replace('/', DS, $name) . '.php';
}
/**
* Renders the template by page with the additional data
*
* @param Page|string $template
* @param array $data
* @param boolean $return
* @return string
*/
public function render($template, $data = [], $return = true) {
if($template instanceof Page) {
$page = $template;
$file = $page->templateFile();
$data = $this->data($page, $data);
} else {
$file = $template;
$data = $this->data(null, $data);
}
// check for an existing template
if(!file_exists($file)) {
throw new Exception('The template could not be found');
}
// merge and register the template data globally
$tplData = tpl::$data;
tpl::$data = array_merge(tpl::$data, $data);
// load the template
$result = tpl::load($file, null, $return);
// reset the template data
tpl::$data = $tplData;
/home
/ngvipwtf
/offscreen2023
/kirby
/kirby.php
}
return $template;
}
// return a fresh template
return $this->template($page, $data);
}
/**
* Template configuration
*
* @param Page $page
* @param array $data
* @return string
*/
public function template(Page $page, $data = array()) {
return $this->component('template')->render($page, $data);
}
public function request() {
if(!is_null($this->request)) return $this->request;
return $this->request = new Request($this);
}
public function router() {
return $this->router;
}
public function route() {
return $this->route;
}
/**
* Starts the router, renders the page and returns the response
*
* @return mixed
*/
/home
/ngvipwtf
/offscreen2023
/kirby
/kirby.php
}
}
// try to fetch the template from cache
$template = $this->cache()->get($cacheId);
// fetch fresh content if the cache is empty
if(empty($template)) {
$template = $this->template($page, $data);
// store the result for the next round
$this->cache()->set($cacheId, $template);
}
return $template;
}
// return a fresh template
return $this->template($page, $data);
}
/**
* Template configuration
*
* @param Page $page
* @param array $data
* @return string
*/
public function template(Page $page, $data = array()) {
return $this->component('template')->render($page, $data);
}
public function request() {
if(!is_null($this->request)) return $this->request;
return $this->request = new Request($this);
}
public function router() {
/home
/ngvipwtf
/offscreen2023
/kirby
/kirby
/component
/response.php
* @link http://getkirby.com
* @copyright Bastian Allgeier
* @license http://getkirby.com/license
*/
class Response extends \Kirby\Component {
/**
* Builds and return the response by various input
*
* @param mixed $response
* @return mixed
*/
public function make($response) {
if(is_string($response)) {
return $this->kirby->render(page($response));
} else if(is_array($response)) {
return $this->kirby->render(page($response[0]), $response[1]);
} else if(is_a($response, 'Page')) {
return $this->kirby->render($response);
} else if(is_a($response, 'Response')) {
return $response;
} else {
return null;
}
}
}
/home
/ngvipwtf
/offscreen2023
/kirby
/kirby.php
// check for a valid route
if(is_null($this->route)) {
header::status('500');
header::type('json');
die(json_encode(array(
'status' => 'error',
'message' => 'Invalid route or request method'
)));
}
// call the router action with all arguments from the pattern
$response = call($this->route->action(), $this->route->arguments());
// load all language variables
// this can only be loaded once the router action has been called
// otherwise the current language is not yet available
$this->localize();
// build the response
$this->response = $this->component('response')->make($response);
// store the current language in the session
if(
$this->option('language.detect') &&
$this->site()->multilang() &&
$this->site()->language()
) {
s::set('kirby_language', $this->site()->language()->code());
}
return $this->response;
}
/**
* Register a new hook
*
* @param string/array $hook The name of the hook
* @param closure $callback
*/
/home
/ngvipwtf
/offscreen2023
/index.php
<?php
define('DS', DIRECTORY_SEPARATOR);
// load kirby
require(__DIR__ . DS . 'kirby' . DS . 'bootstrap.php');
// check for a custom site.php
if(file_exists(__DIR__ . DS . 'site.php')) {
require(__DIR__ . DS . 'site.php');
} else {
$kirby = kirby();
}
// render
echo $kirby->launch();