From 3d3c76ac95fd5a4ac0788aeae61bfd0acd160419 Mon Sep 17 00:00:00 2001 From: Kanti Date: Mon, 28 Jul 2014 17:23:51 +0200 Subject: [PATCH 1/6] Useabilty improvement archive var includes the month only --- system/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/includes/functions.php b/system/includes/functions.php index 23f9aad..1ed6b1d 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -261,7 +261,7 @@ function get_posts($posts, $page = 1, $perpage = 0){ $post->date = strtotime($timestamp); // The archive per day - $post->archive = site_url(). 'archive/' . date('Y-m-d', $post->date) ; + $post->archive = site_url(). 'archive/' . date('Y-m', $post->date) ; // The post URL $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); From 63755a1addef39ef6f40e66856da36f5905913a2 Mon Sep 17 00:00:00 2001 From: Kanti Date: Mon, 28 Jul 2014 20:26:34 +0200 Subject: [PATCH 2/6] Updated Comopser --- vendor/composer/installed.json | 94 +++++++++++----------- vendor/suin/php-rss-writer/README.md | 14 +++- .../php-rss-writer/Source/Suin/RSSWriter/Item.php | 27 +++++++ .../Source/Suin/RSSWriter/ItemInterface.php | 9 +++ .../Tests/Suin/RSSWriter/ItemTest.php | 16 +++- 5 files changed, 111 insertions(+), 49 deletions(-) diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index ce376d8..f5adc76 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1,51 +1,4 @@ [ - { - "name": "suin/php-rss-writer", - "version": "1.2", - "version_normalized": "1.2.0.0", - "source": { - "type": "git", - "url": "git://github.com/suin/php-rss-writer.git", - "reference": "1.2" - }, - "dist": { - "type": "zip", - "url": "https://github.com/suin/php-rss-writer/zipball/1.2", - "reference": "1.2", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "time": "2012-08-23 00:45:18", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "Suin\\RSSWriter": "Source" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "suin", - "email": "suinyeze@gmail.com", - "homepage": "https://www.facebook.com/suinyeze", - "role": "Developer, Renaming Specialist" - } - ], - "description": "Yet another simple RSS writer library for PHP 5.3 or later.", - "homepage": "https://github.com/suin/php-rss-writer", - "keywords": [ - "feed", - "generator", - "rss", - "writer" - ] - }, { "name": "michelf/php-markdown", "version": "dev-lib", @@ -98,5 +51,52 @@ "keywords": [ "markdown" ] + }, + { + "name": "suin/php-rss-writer", + "version": "1.3", + "version_normalized": "1.3.0.0", + "source": { + "type": "git", + "url": "https://github.com/suin/php-rss-writer.git", + "reference": "82812ff988bb470f746d24e153cdc138e8838ff3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/suin/php-rss-writer/zipball/82812ff988bb470f746d24e153cdc138e8838ff3", + "reference": "82812ff988bb470f746d24e153cdc138e8838ff3", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "time": "2014-03-12 06:05:28", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Suin\\RSSWriter": "Source" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "suin", + "email": "suinyeze@gmail.com", + "homepage": "https://www.facebook.com/suinyeze", + "role": "Developer, Renaming Specialist" + } + ], + "description": "Yet another simple RSS writer library for PHP 5.3 or later.", + "homepage": "https://github.com/suin/php-rss-writer", + "keywords": [ + "feed", + "generator", + "rss", + "writer" + ] } ] diff --git a/vendor/suin/php-rss-writer/README.md b/vendor/suin/php-rss-writer/README.md index fb58cb1..5c7fa7f 100644 --- a/vendor/suin/php-rss-writer/README.md +++ b/vendor/suin/php-rss-writer/README.md @@ -2,6 +2,8 @@ `\Suin\RSSWriter` is yet another simple RSS writer library for PHP 5.3 or later. This component is Licensed under MIT license. +This library can also be used to publish Podcasts. + The build status of the current master branch is tracked by Travis CI: [![Build Status](https://secure.travis-ci.org/suin/php-rss-writer.png?branch=master)](http://travis-ci.org/suin/php-rss-writer) @@ -18,6 +20,7 @@ $channel ->url('http://blog.example.com') ->appendTo($feed); +// RSS item $item = new Item(); $item ->title("Blog Entry Title") @@ -25,6 +28,15 @@ $item ->url('http://blog.example.com/2012/08/21/blog-entry/') ->appendTo($channel); +// Podcast item +$item = new Item(); +$item + ->title("Some Podcast Entry") + ->description("
Podcast body
") + ->url('http://podcast.example.com/2012/08/21/podcast-entry/') + ->enclosure('http://link-to-audio-file.com/2013/08/21/podcast.mp3', 4889, 'audio/mpeg') + ->appendTo($channel); + echo $feed; ``` @@ -81,4 +93,4 @@ If you want to know APIs, please see `FeedInterface`, `ChannelInterface` and `It ## License -MIT license \ No newline at end of file +MIT license diff --git a/vendor/suin/php-rss-writer/Source/Suin/RSSWriter/Item.php b/vendor/suin/php-rss-writer/Source/Suin/RSSWriter/Item.php index cf991c0..9ee7ee4 100644 --- a/vendor/suin/php-rss-writer/Source/Suin/RSSWriter/Item.php +++ b/vendor/suin/php-rss-writer/Source/Suin/RSSWriter/Item.php @@ -20,6 +20,8 @@ class Item implements \Suin\RSSWriter\ItemInterface protected $isPermalink; /** @var int */ protected $pubDate; + /** @var array */ + protected $enclosure; /** * Set item title @@ -90,6 +92,19 @@ class Item implements \Suin\RSSWriter\ItemInterface return $this; } + /** + * Set enclosure + * @param var $url Url to media file + * @param int $length Length in bytes of the media file + * @param var $type Media type, default is audio/mpeg + * @return $this + */ + public function enclosure($url, $length = 0, $type = 'audio/mpeg') + { + $this->enclosure = array('url' => $url, 'length' => $length, 'type' => $type); + return $this; + } + /** * Append item to the channel * @param \Suin\RSSWriter\ChannelInterface $channel @@ -137,6 +152,18 @@ class Item implements \Suin\RSSWriter\ItemInterface $xml->addChild('pubDate', date(DATE_RSS, $this->pubDate)); } + + if (is_array($this->enclosure) && (count($this->enclosure) == 3)) + { + $element = $xml->addChild('enclosure'); + $element->addAttribute('url', $this->enclosure['url']); + $element->addAttribute('type', $this->enclosure['type']); + + if ($this->enclosure['length']) + { + $element->addAttribute('length', $this->enclosure['length']); + } + } return $xml; } } diff --git a/vendor/suin/php-rss-writer/Source/Suin/RSSWriter/ItemInterface.php b/vendor/suin/php-rss-writer/Source/Suin/RSSWriter/ItemInterface.php index 7584528..d25bc94 100644 --- a/vendor/suin/php-rss-writer/Source/Suin/RSSWriter/ItemInterface.php +++ b/vendor/suin/php-rss-writer/Source/Suin/RSSWriter/ItemInterface.php @@ -51,6 +51,15 @@ interface ItemInterface */ public function pubDate($pubDate); + /** + * Set enclosure + * @param var $url Url to media file + * @param int $length Length in bytes of the media file + * @param var $type Media type, default is audio/mpeg + * @return $this + */ + public function enclosure($url, $length = 0, $type = 'audio/mpeg'); + /** * Append item to the channel * @param \Suin\RSSWriter\ChannelInterface $channel diff --git a/vendor/suin/php-rss-writer/Tests/Suin/RSSWriter/ItemTest.php b/vendor/suin/php-rss-writer/Tests/Suin/RSSWriter/ItemTest.php index dbf30c8..b9bfd14 100644 --- a/vendor/suin/php-rss-writer/Tests/Suin/RSSWriter/ItemTest.php +++ b/vendor/suin/php-rss-writer/Tests/Suin/RSSWriter/ItemTest.php @@ -88,6 +88,15 @@ class ItemTest extends \XoopsUnit\TestCase $this->assertSame($item, $item->appendTo($channel)); } + public function testEnclosure() + { + $url = uniqid(); + $enclosure = array('url' => $url, 'length' => 0, 'type' => 'audio/mpeg'); + $item = new Item(); + $this->assertSame($item, $item->enclosure($url)); + $this->assertAttributeSame($enclosure, 'enclosure', $item); + } + public function testAsXML() { $now = time(); @@ -104,6 +113,10 @@ class ItemTest extends \XoopsUnit\TestCase 'guid' => "http://inessential.com/2002/09/01.php#a2", 'isPermalink' => true, 'pubDate' => $now, + 'enclosure' => array( + 'url' => 'http://link-to-audio-file.com/test.mp3', + 'length' => 4992, + 'type' => 'audio/mpeg') ); $item = new Item(); @@ -122,6 +135,7 @@ class ItemTest extends \XoopsUnit\TestCase {$data['categories'][1][0]} {$data['guid']} {$nowString} + "; $this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML()); @@ -133,7 +147,7 @@ class ItemTest extends \XoopsUnit\TestCase $nowString = date(DATE_RSS, $now); $data = array( - 'title' => "日本語", + 'title' => "Venice Film Festival", 'url' => 'http://nytimes.com/2004/12/07FEST.html', 'description' => "Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.", ); From f70ce4e9506a4b60f431a182a3016a5ac3a0c382 Mon Sep 17 00:00:00 2001 From: Kanti Date: Tue, 29 Jul 2014 17:44:13 +0200 Subject: [PATCH 3/6] clean up the cache functions --- system/includes/functions.php | 2707 +++++++++++++++++++---------------------- 1 file changed, 1266 insertions(+), 1441 deletions(-) diff --git a/system/includes/functions.php b/system/includes/functions.php index 1ed6b1d..7595454 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -9,960 +9,840 @@ use \Suin\RSSWriter\Channel; use \Suin\RSSWriter\Item; // Get blog post path. Unsorted. Mostly used on widget. -function get_post_unsorted(){ - - static $_unsorted = array(); - - if(empty($_unsorted)){ - - $url = 'cache/index/index-unsorted.txt'; - if (file_exists($url)) { - $_unsorted = unserialize(file_get_contents($url)); - } - else { - rebuilt_cache('all'); - $_unsorted = unserialize(file_get_contents($url)); - } - - if(empty($_unsorted)){ - $_unsorted = glob('content/*/blog/*.md', GLOB_NOSORT); - } - - } - - return $_unsorted; +function get_post_unsorted() { + + static $_unsorted = array(); + + if (empty($_unsorted)) { + + $url = 'cache/index/index-unsorted.txt'; + if(! file_exists($url)) { + rebuilt_cache('all'); + } + $_unsorted = unserialize(file_get_contents($url)); + } + return $_unsorted; } // Get blog post with more info about the path. Sorted by filename. -function get_post_sorted(){ - - static $_sorted = array(); - - $url = 'cache/index/index-sorted.txt'; - if (file_exists($url)) { - $_sorted = unserialize(file_get_contents($url)); - } - else { - rebuilt_cache('all'); - $_sorted = unserialize(file_get_contents($url)); - } - - if(empty($_sorted)){ - - $url = 'cache/index/index-sorted.txt'; - if (file_exists($url)) { - $_sorted = unserialize(file_get_contents($url)); - } - else { - rebuilt_cache('all'); - $_sorted = unserialize(file_get_contents($url)); - } - - if(empty($_sorted)){ - $tmp = array(); - $tmp = glob('content/*/blog/*.md', GLOB_NOSORT); - if (is_array($tmp)) { - foreach($tmp as $file) { - $_sorted[] = pathinfo($file); - } - } - usort($_sorted, "sortfile"); - } - } - - return $_sorted; +function get_post_sorted() { + + static $_sorted = array(); + + if (empty($_sorted)) { + $url = 'cache/index/index-sorted.txt'; + if(! file_exists($url)) { + rebuilt_cache('all'); + } + $_sorted = unserialize(file_get_contents($url)); + } + return $_sorted; } // Get static page path. Unsorted. -function get_static_pages(){ - - static $_page = array(); - - if(empty($_page)){ - $url = 'cache/index/index-page.txt'; - if (file_exists($url)) { - $_page = unserialize(file_get_contents($url)); - } - else { - rebuilt_cache('all'); - $_page = unserialize(file_get_contents($url)); - } - - if(empty($_page)){ - $_page = glob('content/static/*.md', GLOB_NOSORT); - } - } - - return $_page; +function get_static_pages() { + + static $_page = array(); + + if (empty($_page)) { + $url = 'cache/index/index-page.txt'; + if(! file_exists($url)) { + rebuilt_cache('all'); + } + $_page = unserialize(file_get_contents($url)); + } + return $_page; } // Get author bio path. Unsorted. -function get_author_names(){ - - static $_author = array(); - - if(empty($_author)){ - $url = 'cache/index/index-author.txt'; - if (file_exists($url)) { - $_author = unserialize(file_get_contents($url)); - } - else { - rebuilt_cache('all'); - $_author = unserialize(file_get_contents($url)); - } - if(empty($_author)){ - $_author = glob('content/*/author.md', GLOB_NOSORT); - } - } - - return $_author; +function get_author_names() { + + static $_author = array(); + + if (empty($_author)) { + $url = 'cache/index/index-author.txt'; + if(! file_exists($url)) { + rebuilt_cache('all'); + } + $_author = unserialize(file_get_contents($url)); + } + + return $_author; } // Get backup file. -function get_zip_files(){ +function get_zip_files() { - static $_zip = array(); + static $_zip = array(); - if(empty($_zip)){ + if (empty($_zip)) { - // Get the names of all the - // zip files. + // Get the names of all the + // zip files. - $_zip = glob('backup/*.zip'); - } + $_zip = glob('backup/*.zip'); + } - return $_zip; + return $_zip; } // usort function. Sort by filename. function sortfile($a, $b) { - return $a['filename'] == $b['filename'] ? 0 : ( $a['filename'] < $b['filename'] ) ? 1 : -1; + return $a['filename'] == $b['filename'] ? 0 : ( $a['filename'] < $b['filename'] ) ? 1 : -1; } // usort function. Sort by date. function sortdate($a, $b) { - return $a->date == $b->date ? 0 : ( $a->date < $b->date ) ? 1 : -1; + return $a->date == $b->date ? 0 : ( $a->date < $b->date ) ? 1 : -1; } // Rebuilt cache index function rebuilt_cache($type) { - $dir = 'cache/index'; - $posts_cache_sorted = array(); - $posts_cache_unsorted = array(); - $page_cache = array(); - $author_cache = array(); - - if(is_dir($dir) === false) { - mkdir($dir, 0777, true); - } - - if($type === 'posts') { - $posts_cache_unsorted = glob('content/*/blog/*.md', GLOB_NOSORT); - $string = serialize($posts_cache_unsorted); - file_put_contents('cache/index/index-unsorted.txt', print_r($string, true)); - - $tmp= array(); - $tmp = glob('content/*/blog/*.md', GLOB_NOSORT); - - if (is_array($tmp)) { - foreach($tmp as $file) { - $posts_cache_sorted[] = pathinfo($file); - } - } - usort($posts_cache_sorted, "sortfile"); - $string = serialize($posts_cache_sorted); - file_put_contents('cache/index/index-sorted.txt', print_r($string, true)); - - } - - elseif ($type === 'page') { - - $page_cache = glob('content/static/*.md', GLOB_NOSORT); - $string = serialize($page_cache); - file_put_contents('cache/index/index-page.txt', print_r($string, true)); - - } - - elseif ($type === 'author') { - - $author_cache = glob('content/*/author.md', GLOB_NOSORT); - $string = serialize($author_cache); - file_put_contents('cache/index/index-author.txt', print_r($string, true)); - - } - - elseif ($type === 'all') { - - $posts_cache_unsorted = glob('content/*/blog/*.md', GLOB_NOSORT); - $string = serialize($posts_cache_unsorted); - file_put_contents('cache/index/index-unsorted.txt', print_r($string, true)); - - $tmp= array(); - $tmp = glob('content/*/blog/*.md', GLOB_NOSORT); - if (is_array($tmp)) { - foreach($tmp as $file) { - $posts_cache_sorted[] = pathinfo($file); - } - } - usort($posts_cache_sorted, "sortfile"); - $string = serialize($posts_cache_sorted); - file_put_contents('cache/index/index-sorted.txt', print_r($string, true)); - - $page_cache = glob('content/static/*.md', GLOB_NOSORT); - $string = serialize($page_cache); - file_put_contents('cache/index/index-page.txt', print_r($string, true)); - - $author_cache = glob('content/*/author.md', GLOB_NOSORT); - $string = serialize($author_cache); - file_put_contents('cache/index/index-author.txt', print_r($string, true)); - - } + $dir = 'cache/index'; + $posts_cache_sorted = array(); + $posts_cache_unsorted = array(); + $page_cache = array(); + $author_cache = array(); + + if (is_dir($dir) === false) { + mkdir($dir, 0777, true); + } + + if ($type === 'posts') { + $posts_cache_unsorted = glob('content/*/blog/*.md', GLOB_NOSORT); + $string = serialize($posts_cache_unsorted); + file_put_contents('cache/index/index-unsorted.txt', print_r($string, true)); + + $tmp = array(); + $tmp = glob('content/*/blog/*.md', GLOB_NOSORT); + + if (is_array($tmp)) { + foreach ($tmp as $file) { + $posts_cache_sorted[] = pathinfo($file); + } + } + usort($posts_cache_sorted, "sortfile"); + $string = serialize($posts_cache_sorted); + file_put_contents('cache/index/index-sorted.txt', print_r($string, true)); + } elseif ($type === 'page') { + + $page_cache = glob('content/static/*.md', GLOB_NOSORT); + $string = serialize($page_cache); + file_put_contents('cache/index/index-page.txt', print_r($string, true)); + } elseif ($type === 'author') { + + $author_cache = glob('content/*/author.md', GLOB_NOSORT); + $string = serialize($author_cache); + file_put_contents('cache/index/index-author.txt', print_r($string, true)); + } elseif ($type === 'all') { + rebuilt_cache('posts'); + rebuilt_cache('page'); + rebuilt_cache('author'); + } } // Return blog posts. -function get_posts($posts, $page = 1, $perpage = 0){ - - if(empty($posts)) { - $posts = get_post_sorted(); - } - - $tmp = array(); - - // Extract a specific page with results - $posts = array_slice($posts, ($page-1) * $perpage, $perpage); - - 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]; - - // The post author + author url - $post->author = $author; - $post->authorurl = site_url() . 'author/' . $author; - - $dt = str_replace($replaced,'',$arr[0]); - $t = str_replace('-', '', $dt); - $time = new DateTime($t); - $timestamp= $time->format("Y-m-d H:i:s"); - - // The post date - $post->date = strtotime($timestamp); - - // The archive per day - $post->archive = site_url(). 'archive/' . date('Y-m', $post->date) ; - - // The post URL - $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); - - $tag = array(); - $url = array(); - $bc = array(); - - $t = explode(',', $arr[1]); - foreach($t as $tt) { - $tag[] = array($tt, site_url(). 'tag/' . $tt); - } - - foreach($tag as $a) { - $url[] = ''. $a[0] .''; - $bc[] = ''. $a[0] .''; - } - - $post->tag = implode(', ', $url); - - $post->tagb = implode(' » ', $bc); - - $post->file = $filepath; - - // Get the contents and convert it to HTML - $content = MarkdownExtra::defaultTransform(file_get_contents($filepath)); - - // Extract the title and body - $arr = explode('t-->', $content); - if(isset($arr[1])) { - $title = str_replace('', $content); + if (isset($arr[1])) { + $title = str_replace('', $content); - if(isset($arr[1])) { - $title = str_replace('', $content); + if (isset($arr[1])) { + $title = str_replace('', $content); - if(isset($arr[1])) { - $title = str_replace('', $content); + if (isset($arr[1])) { + $title = str_replace('', $content); - if(isset($arr[1])) { - $title = str_replace('', $content); + if (isset($arr[1])) { + $title = str_replace('