Browse Source

Improve search+Add OPML

Improve search so can search many words. Add the opml generator.
pull/9/head
Danang Probo Sayekti 12 years ago
parent
commit
0a36dd3301
4 changed files with 100 additions and 8 deletions
  1. +3
    -0
      system/config.ini
  2. +17
    -6
      system/htmly.php
  3. +35
    -2
      system/includes/functions.php
  4. +45
    -0
      system/includes/opml.php

+ 3
- 0
system/config.ini View File

@ -16,6 +16,9 @@ social.tumblr = "http://www.tumblr.com"
; Custom menu link
blog.menu = ""
; Breadcrumb home text. Useful when installed on subfolder.
breadcrumb.home = "Home"
; Disqus
disqus.shortname = ""


+ 17
- 6
system/htmly.php View File

@ -7,6 +7,7 @@ date_default_timezone_set('Asia/Jakarta');
// and our functions.php file
require 'system/includes/dispatch.php';
require 'system/includes/functions.php';
require 'system/includes/opml.php';
// Load the configuration file
config('source', 'system/config.ini');
@ -70,7 +71,7 @@ get('/tag/:tag',function($tag){
'canonical' => config('site.url') . '/tag/' . $tag,
'description' => 'All posts tagged ' . $tag . ' on '. config('blog.title') . '.',
'bodyclass' => 'intag',
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> &#187; Posts tagged: ' . $tag,
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> &#187; Posts tagged: ' . $tag,
'pagination' => has_pagination($total, $perpage, $page)
));
});
@ -119,7 +120,7 @@ get('/archive/:req',function($req){
'canonical' => config('site.url') . '/archive/' . $req,
'description' => 'Archive page for: ' . $timestamp . ' on ' . config('blog.title') . '.',
'bodyclass' => 'inarchive',
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> &#187; Archive for: ' . $timestamp,
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> &#187; Archive for: ' . $timestamp,
'pagination' => has_pagination($total, $perpage, $page)
));
});
@ -158,7 +159,7 @@ get('/:year/:month/:name', function($year, $month, $name){
'canonical' => $current->url,
'description' => $description = get_description($current->body),
'bodyclass' => 'inpost',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . config('site.url') . '">Home</a></span> &#187; <span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . $current->tagurl .'">' . $current->tag . '</a></span> &#187; ' . $current->title,
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a></span> &#187; <span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . $current->tagurl .'">' . $current->tag . '</a></span> &#187; ' . $current->title,
'prev' => has_prev($prev),
'next' => has_next($next),
'type' => 'blogpost',
@ -192,7 +193,7 @@ get('/search/:keyword', function($keyword){
'canonical' => config('site.url') . '/search/' . $keyword,
'description' => 'Search results for: ' . $keyword . ' on '. config('blog.title') . '.',
'bodyclass' => 'insearch',
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> &#187; Search results for: ' . $keyword,
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> &#187; Search results for: ' . $keyword,
'pagination' => has_pagination($total, $perpage, $page)
));
@ -212,7 +213,7 @@ get('/:spage', function($spage){
'canonical' => $post->url,
'description' => $description = get_description($post->body),
'bodyclass' => 'inpage',
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> &#187; ' . $post->title,
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> &#187; ' . $post->title,
'p' => $post,
'type' => 'staticpage',
));
@ -247,7 +248,7 @@ get('/author/:profile',function($profile){
'canonical' => config('site.url') . '/author/' . $profile,
'description' => 'Profile page and all posts by ' . $bio->title . ' on ' . config('blog.title') . '.',
'bodyclass' => 'inprofile',
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> &#187; Profile for: ' . $bio->title,
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> &#187; Profile for: ' . $bio->title,
'pagination' => has_pagination($total, $perpage, $page)
));
});
@ -279,6 +280,16 @@ get('/feed/sitemap',function(){
echo generate_sitemap(get_posts(null, null, null));
});
// Generate OPML file
get('/feed/opml',function(){
header('Content-Type: text/xml');
// Generate OPML file for the RSS
echo generate_opml();
});
// If we get here, it means that
// nothing has been matched above


+ 35
- 2
system/includes/functions.php View File

@ -565,12 +565,18 @@ function get_keyword($keyword){
// Create a new instance of the markdown parser
$md = new MarkdownParser();
$words = explode(' ', $keyword);
foreach ($words as $word) {
$word = $word;
}
foreach($posts as $index => $v){
$content = $md->transformMarkdown(file_get_contents($v));
if(strpos(strtolower(strip_tags($content)), strtolower($keyword)) !== false){
if(strpos(strtolower(strip_tags($content)), strtolower($word)) !== false){
$post = new stdClass;
@ -886,7 +892,7 @@ function get_menu() {
krsort($posts);
echo '<ul>';
echo '<li><a href="' . site_url() . '">Home</a></li>';
echo '<li><a href="' . site_url() . '">' .config('breadcrumb.home'). '</a></li>';
foreach($posts as $index => $v){
// Replaced string
@ -971,6 +977,33 @@ function generate_sitemap($posts){
echo $feed;
}
// 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);

+ 45
- 0
system/includes/opml.php View File

@ -0,0 +1,45 @@
<?php
class OPML
{
private $data;
private $writer;
public function __construct($data)
{
$this->data = $data;
$this->writer = new XMLWriter();
$this->writer->openMemory();
}
public function render()
{
$this->writer->startDocument('1.0', 'UTF-8');
$this->writer->startElement('opml');
$this->writer->writeAttribute('version', '2.0');
// Header
$this->writer->startElement('head');
foreach ($this->data['head'] as $key => $value) {
$this->writer->writeElement($key, $value);
}
$this->writer->writeElement('dateModified', date("D, d M Y H:i:s T"));
$this->writer->endElement();
// Body
$this->writer->startElement('body');
foreach ($this->data['body'] as $outlines) {
$this->writer->startElement('outline');
foreach ($outlines as $key => $value) {
$this->writer->writeAttribute($key, $value);
}
$this->writer->endElement();
}
$this->writer->endElement();
$this->writer->endElement();
$this->writer->endDocument();
return $this->writer->outputMemory();
}
}
?>

Loading…
Cancel
Save