v0.2
Added some inline docs.
This commit is contained in:
parent
7d2f97f2f6
commit
c88f8e7967
|
@ -1,9 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
/*
|
|
||||||
* Pico v0.1
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Defines
|
|
||||||
define('ROOT_DIR', realpath(dirname(__FILE__)) .'/');
|
define('ROOT_DIR', realpath(dirname(__FILE__)) .'/');
|
||||||
define('CONTENT_DIR', ROOT_DIR .'content/');
|
define('CONTENT_DIR', ROOT_DIR .'content/');
|
||||||
define('LIB_DIR', ROOT_DIR .'lib/');
|
define('LIB_DIR', ROOT_DIR .'lib/');
|
||||||
|
|
39
lib/pico.php
39
lib/pico.php
|
@ -1,7 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pico
|
||||||
|
*
|
||||||
|
* @author Gilbert Pellegrom
|
||||||
|
* @link http://pico.dev7studios.com/
|
||||||
|
* @license http://opensource.org/licenses/MIT
|
||||||
|
* @version 0.2
|
||||||
|
*/
|
||||||
class Pico {
|
class Pico {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor carries out all the processing in Pico.
|
||||||
|
* Does URL routing, Markdown processing and Twig processing.
|
||||||
|
*/
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
// Get request url and script url
|
// Get request url and script url
|
||||||
|
@ -51,6 +63,12 @@ class Pico {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the content using Markdown
|
||||||
|
*
|
||||||
|
* @param string $content the raw txt content
|
||||||
|
* @return string $content the Markdown formatted content
|
||||||
|
*/
|
||||||
function parse_content($content)
|
function parse_content($content)
|
||||||
{
|
{
|
||||||
$content = str_replace('%base_url%', $this->base_url(), $content);
|
$content = str_replace('%base_url%', $this->base_url(), $content);
|
||||||
|
@ -59,6 +77,12 @@ class Pico {
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the file meta from the txt file header
|
||||||
|
*
|
||||||
|
* @param string $content the raw txt content
|
||||||
|
* @return array $headers an array of meta values
|
||||||
|
*/
|
||||||
function read_file_meta($content)
|
function read_file_meta($content)
|
||||||
{
|
{
|
||||||
$headers = array(
|
$headers = array(
|
||||||
|
@ -78,6 +102,11 @@ class Pico {
|
||||||
return $headers;
|
return $headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the config
|
||||||
|
*
|
||||||
|
* @return array $defaults an array of config values
|
||||||
|
*/
|
||||||
function get_config()
|
function get_config()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
@ -96,6 +125,11 @@ class Pico {
|
||||||
return $defaults;
|
return $defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to work out the base URL
|
||||||
|
*
|
||||||
|
* @return string the base url
|
||||||
|
*/
|
||||||
function base_url()
|
function base_url()
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
@ -110,6 +144,11 @@ class Pico {
|
||||||
return rtrim(str_replace($url, '', $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), '/');
|
return rtrim(str_replace($url, '', $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to guess the server protocol. Used in base_url()
|
||||||
|
*
|
||||||
|
* @return string the current protocol
|
||||||
|
*/
|
||||||
function get_protocol()
|
function get_protocol()
|
||||||
{
|
{
|
||||||
preg_match("|^HTTP[S]?|is",$_SERVER['SERVER_PROTOCOL'],$m);
|
preg_match("|^HTTP[S]?|is",$_SERVER['SERVER_PROTOCOL'],$m);
|
||||||
|
|
Loading…
Reference in a new issue