Improve search+Add OPML

Improve search so can search many words. Add the opml generator.
This commit is contained in:
Danang Probo Sayekti 2014-01-15 10:45:14 +07:00
commit 0a36dd3301
4 changed files with 100 additions and 8 deletions

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
system/includes/opml.php Normal file
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();
}
}
?>