From 0a36dd3301186c3a6205d3562d8fd0e92aebfb0d Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Wed, 15 Jan 2014 10:45:14 +0700 Subject: [PATCH] Improve search+Add OPML Improve search so can search many words. Add the opml generator. --- system/config.ini | 3 +++ system/htmly.php | 23 ++++++++++++++++------ system/includes/functions.php | 37 +++++++++++++++++++++++++++++++++-- system/includes/opml.php | 45 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 system/includes/opml.php diff --git a/system/config.ini b/system/config.ini index 4227397..57f6d67 100644 --- a/system/config.ini +++ b/system/config.ini @@ -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 = "" diff --git a/system/htmly.php b/system/htmly.php index e2f4c08..738a365 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -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' => 'Home » Posts tagged: ' . $tag, + 'breadcrumb' => '' .config('breadcrumb.home'). ' » 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' => 'Home » Archive for: ' . $timestamp, + 'breadcrumb' => '' .config('breadcrumb.home'). ' » 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' => 'Home » ' . $current->tag . ' » ' . $current->title, + 'breadcrumb' => '' .config('breadcrumb.home'). ' » ' . $current->tag . ' » ' . $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' => 'Home » Search results for: ' . $keyword, + 'breadcrumb' => '' .config('breadcrumb.home'). ' » 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' => 'Home » ' . $post->title, + 'breadcrumb' => '' .config('breadcrumb.home'). ' » ' . $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' => 'Home » Profile for: ' . $bio->title, + 'breadcrumb' => '' .config('breadcrumb.home'). ' » 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 diff --git a/system/includes/functions.php b/system/includes/functions.php index 1eed207..336baf1 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -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 '