mirror of
https://github.com/danpros/htmly.git
synced 2026-04-19 03:56:21 +05:30
Improve search+Add OPML
Improve search so can search many words. Add the opml generator.
This commit is contained in:
parent
bd66a69ad5
commit
0a36dd3301
4 changed files with 100 additions and 8 deletions
|
|
@ -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 = ""
|
||||
|
||||
|
|
|
|||
|
|
@ -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> » Posts tagged: ' . $tag,
|
||||
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> » 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> » Archive for: ' . $timestamp,
|
||||
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> » 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> » <span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . $current->tagurl .'">' . $current->tag . '</a></span> » ' . $current->title,
|
||||
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a></span> » <span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . $current->tagurl .'">' . $current->tag . '</a></span> » ' . $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> » Search results for: ' . $keyword,
|
||||
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> » 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> » ' . $post->title,
|
||||
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> » ' . $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> » Profile for: ' . $bio->title,
|
||||
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> » 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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
system/includes/opml.php
Normal file
45
system/includes/opml.php
Normal 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…
Add table
Add a link
Reference in a new issue