';
}
// Search form
function search() {
echo <<
EOF;
if(isset($_GET['search'])) {
$url = site_url() . 'search/' . $_GET['search'];
header ("Location: $url");
}
}
// The not found error
function not_found(){
error(404, render('404', null, false));
}
// Turn an array of posts into an RSS feed
function generate_rss($posts){
$feed = new Feed();
$channel = new Channel();
$channel
->title(config('blog.title'))
->description(config('blog.description'))
->url(site_url())
->appendTo($feed);
foreach($posts as $p){
$item = new Item();
$item
->title($p->title)
->pubDate($p->date)
->description($p->body)
->url($p->url)
->category($p->tag, $p->tagurl)
->appendTo($channel);
}
echo $feed;
}
// Return post, tag, archive url.
function get_path(){
$posts = get_post_sorted();
$tmp = array();
foreach($posts as $index => $v){
$post = new stdClass;
$filepath = $v['dirname'] . '/' . $v['basename'];
// Extract the date
$arr = explode('_', $filepath);
// Replaced string
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
// Author string
$str = explode('/', $replaced);
$author = $str[count($str)-3];
$post->authorurl = site_url() . 'author/' . $author;
// The post date
$post->date = strtotime(str_replace($replaced,'',$arr[0]));
// The archive per day
$post->archiveday = site_url(). 'archive/' . date('Y-m-d', $post->date) ;
// The archive per day
$post->archivemonth = site_url(). 'archive/' . date('Y-m', $post->date) ;
// The archive per day
$post->archiveyear = site_url(). 'archive/' . date('Y', $post->date) ;
// The post URL
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
// The post tag url
$post->tagurl = site_url(). 'tag/' . $arr[1];
$tmp[] = $post;
}
return $tmp;
}
// Return static page path.
function get_static_path(){
$posts = get_static_pages();
$tmp = array();
foreach($posts as $index => $v){
$post = new stdClass;
// Replaced string
$replaced = substr($v, 0, strrpos($v, '/')) . '/';
// The static page URL
$url = str_replace($replaced,'',$v);
$post->url = site_url() . str_replace('.md','',$url);
$tmp[] = $post;
}
return $tmp;
}
// Generate sitemap.xml.
function generate_sitemap($str){
echo '';
if ($str == 'index') {
echo '';
echo '' . site_url() . 'sitemap.base.xml';
echo '' . site_url() . 'sitemap.post.xml';
echo '' . site_url() . 'sitemap.static.xml';
echo '' . site_url() . 'sitemap.tag.xml';
echo '' . site_url() . 'sitemap.archive.xml';
echo '' . site_url() . 'sitemap.author.xml';
echo '';
}
elseif ($str == 'base') {
echo '';
echo '' . site_url() . 'hourly1.0';
echo '';
}
elseif ($str == 'post') {
$posts = get_path();
echo '';
foreach($posts as $p) {
echo '' . $p->url . 'monthly0.5';
}
echo '';
}
elseif ($str == 'static') {
$posts = get_static_path();
echo '';
foreach($posts as $p) {
echo '' . $p->url . 'monthly0.5';
}
echo '';
}
elseif ($str == 'tag') {
$posts = get_path();
$tag = array();
foreach($posts as $p) {
$tag[] = $p->tagurl;
}
$tag = array_unique($tag, SORT_REGULAR);
echo '';
foreach($tag as $t) {
echo '' . $t . 'weekly0.5';
}
echo '';
}
elseif ($str == 'archive') {
$posts = get_path();
$day = array();
$month = array();
$year = array();
foreach($posts as $p) {
$day[] = $p->archiveday;
$month[] = $p->archivemonth;
$year[] = $p->archiveyear;
}
$day = array_unique($day, SORT_REGULAR);
$month = array_unique($month, SORT_REGULAR);
$year = array_unique($year, SORT_REGULAR);
echo '';
foreach($day as $d) {
echo '' . $d . 'monthly0.5';
}
foreach($month as $m) {
echo '' . $m . 'monthly0.5';
}
foreach($year as $y) {
echo '' . $y . 'monthly0.5';
}
echo '';
}
elseif ($str == 'author') {
$posts = get_path();
$author = array();
foreach($posts as $p) {
$author[] = $p->authorurl;
}
$author = array_unique($author, SORT_REGULAR);
echo '';
foreach($author as $a) {
echo '' . $a . 'daily0.5';
}
echo '';
}
}
// Function to generate OPML file
function generate_opml(){
$opml_data = array(
'head' => array(
'title' => config('blog.title') . ' OPML File',
'ownerName' => config('blog.title'),
'ownerId' => config('site.url')
),
'body' => array(
array(
'text' => config('blog.title'),
'description' => config('blog.description'),
'htmlUrl' => config('site.url'),
'language' => 'unknown',
'title' => config('blog.title'),
'type' => 'rss',
'version' => 'RSS2',
'xmlUrl' => config('site.url') . '/feed/rss'
)
)
);
$opml = new OPML($opml_data);
echo $opml->render();
}
// Turn an array of posts into a JSON
function generate_json($posts){
return json_encode($posts);
}
function welcome_page() {
echo <<
Welcome to your new HTMLy-powered blog.
The next thing you will need to do is creating the first account. Please create YourUsername.ini inside admin/users folder and write down your password there:
password = YourPassword
Login to your blog admin panel at www.example.com/admin to creating your first post.
This welcome message will disappear after your first post published.