diff --git a/system/includes/functions.php b/system/includes/functions.php index 6bb5667..80b6b99 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -229,11 +229,11 @@ function rebuilt_cache($type) rebuilt_cache('author'); rebuilt_cache('category'); } - + foreach (glob('cache/widget/*.cache', GLOB_NOSORT) as $file) { unlink($file); } - + } // Return blog posts. @@ -247,7 +247,7 @@ function get_posts($posts, $page = 1, $perpage = 0) // Extract a specific page with results $posts = array_slice($posts, ($page - 1) * $perpage, $perpage); - + $catC = category_list(true); foreach ($posts as $index => $v) { @@ -270,14 +270,14 @@ function get_posts($posts, $page = 1, $perpage = 0) $post->category = '' . $category->title . ''; $post->categoryb = '' . $category->title . ''; } else { - + foreach ($catC as $k => $v) { if ($v['0'] === $str[count($str) - 3]) { $post->category = '' . $v['1'] . ''; $post->categoryb = '' . $v['1'] . ''; } } - + } $type = $str[count($str) - 2]; $post->ct = $str[count($str) - 3]; @@ -285,7 +285,7 @@ function get_posts($posts, $page = 1, $perpage = 0) // The post author + author url $post->author = $author; $post->authorUrl = site_url() . 'author/' . $author; - + $post->type = $type; $dt = str_replace($replaced, '', $arr[0]); @@ -298,13 +298,13 @@ function get_posts($posts, $page = 1, $perpage = 0) // The archive per day $post->archive = site_url() . 'archive/' . date('Y-m', $post->date); - + if (config('permalink.type') == 'post') { $post->url = site_url() . 'post/' . str_replace('.md', '', $arr[2]); } else { $post->url = site_url() . date('Y/m', $post->date) . '/' . str_replace('.md', '', $arr[2]); } - + $post->file = $filepath; $content = file_get_contents($filepath); @@ -316,15 +316,15 @@ function get_posts($posts, $page = 1, $perpage = 0) $post->link = get_content_tag('link', $content); $post->quote = get_content_tag('quote', $content); $post->audio = get_content_tag('audio', $content); - + $tag = array(); $url = array(); $bc = array(); $rel = array(); - + $tagt = get_content_tag('tag', $content); $t = explode(',', rtrim($arr[1], ',')); - + if(!empty($tagt)) { $tl = explode(',', rtrim($tagt, ',')); $tCom = array_combine($t, $tl); @@ -334,13 +334,13 @@ function get_posts($posts, $page = 1, $perpage = 0) } else { $tag[] = array($key, site_url() . 'tag/' . strtolower($key)); } - } + } } else { foreach ($t as $tt) { $tag[] = array($tt, site_url() . 'tag/' . strtolower($tt)); } } - + foreach ($tag as $a) { $url[] = ''; $bc[] = '' . $a[0] . ''; @@ -349,14 +349,14 @@ function get_posts($posts, $page = 1, $perpage = 0) $post->tag = implode(' ', $url); $post->tagb = implode(' » ', $bc); - + $post->related = rtrim($arr[1], ','); - + $more = explode('', $content); if (isset($more['1'])) { $content = $more['0'] . '
' . "\n\n" . '' . $more['1']; } - + // Get the contents and convert it to HTML $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); @@ -386,7 +386,7 @@ function find_post($year, $month, $name) foreach ($posts as $index => $v) { $arr = explode('_', $v['basename']); - if ((strpos($arr[0], "$year-$month") !== false && strtolower($arr[2]) === strtolower($name . '.md')) || ($year === NULL && strtolower($arr[2]) === strtolower($name . '.md'))) { + if (strpos($arr[0], "$year-$month") !== false && strtolower($arr[2]) === strtolower($name . '.md') || strtolower($arr[2]) === strtolower($name . '.md')) { // Use the get_posts method to return // a properly parsed object @@ -473,13 +473,13 @@ function get_category($category, $page, $perpage) $posts = get_post_sorted(); $tmp = array(); - + if (empty($perpage)) { - $perpage = 10; + $perpage = 10; } foreach ($posts as $index => $v) { - + $filepath = $v['dirname'] . '/' . $v['basename']; // Extract the date @@ -491,7 +491,7 @@ function get_category($category, $page, $perpage) // Author string $str = explode('/', $replaced); $cat = $str[count($str) - 3]; - + if (strtolower($category) === strtolower($cat)) { $tmp[] = $v; } @@ -500,7 +500,7 @@ function get_category($category, $page, $perpage) if (empty($tmp)) { not_found(); } - + $tmp = array_unique($tmp, SORT_REGULAR); return $tmp = get_posts($tmp, $page, $perpage); @@ -525,9 +525,9 @@ function get_category_info($category) // The static page URL $url= str_replace($replaced, '', $v); - + $desc->url = site_url() . 'category/' . str_replace('.md', '', $url); - + $desc->md = str_replace('.md', '', $url); $desc->file = $v; @@ -537,7 +537,7 @@ function get_category_info($category) // Extract the title and body $desc->title = get_content_tag('t', $content, $category); - + // Get the contents and convert it to HTML $desc->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); @@ -547,11 +547,11 @@ function get_category_info($category) } } } - + if (strtolower($category) == 'uncategorized') { return default_category(); } - + return $tmp; } @@ -573,19 +573,19 @@ function default_category() // Return category list function category_list($custom = null) { - + $dir = "cache/widget"; $filename = "cache/widget/category.list.cache"; $tmp = array(); $cat = array(); $list = array(); - + if (is_dir($dir) === false) { mkdir($dir, 0775, true); } - + if (file_exists($filename)) { - $cat = unserialize(file_get_contents($filename)); + $cat = unserialize(file_get_contents($filename)); } else { $arr = get_category_info(null); foreach ($arr as $a) { @@ -596,21 +596,21 @@ function category_list($custom = null) { $tmp = serialize($cat); file_put_contents($filename, print_r($tmp, true)); } - + if(!empty($custom)) { return $cat; } - + echo ''; - + } // Return type page. @@ -619,13 +619,13 @@ function get_type($type, $page, $perpage) $posts = get_post_sorted(); $tmp = array(); - + if (empty($perpage)) { - $perpage = 10; + $perpage = 10; } foreach ($posts as $index => $v) { - + $filepath = $v['dirname'] . '/' . $v['basename']; // Extract the date @@ -637,7 +637,7 @@ function get_type($type, $page, $perpage) // Author string $str = explode('/', $replaced); $tp = $str[count($str) - 2]; - + if (strtolower($type) === strtolower($tp)) { $tmp[] = $v; } @@ -646,7 +646,7 @@ function get_type($type, $page, $perpage) if (empty($tmp)) { not_found(); } - + $tmp = array_unique($tmp, SORT_REGULAR); return $tmp = get_posts($tmp, $page, $perpage); @@ -680,7 +680,7 @@ function get_tag($tag, $page, $perpage, $random) if (empty($tmp)) { not_found(); } - + $tmp = array_unique($tmp, SORT_REGULAR); return $tmp = get_posts($tmp, $page, $perpage); @@ -766,7 +766,7 @@ function get_author($name) if (!empty($names)) { foreach ($names as $index => $v) { - + $author = new stdClass; // Replaced string @@ -786,7 +786,7 @@ function get_author($name) // Extract the title and body $author->name = get_content_tag('t', $content, $author); - + // Get the contents and convert it to HTML $author->about = MarkdownExtra::defaultTransform(remove_html_comments($content)); @@ -844,7 +844,7 @@ function get_static_post($static) // Extract the title and body $post->title = get_content_tag('t', $content, $static); - + // Get the contents and convert it to HTML $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); @@ -890,7 +890,7 @@ function get_static_sub_post($static, $sub_static) // Extract the title and body $post->title = get_content_tag('t', $content, $sub_static); - + // Get the contents and convert it to HTML $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); @@ -910,7 +910,7 @@ function get_static_sub_post($static, $sub_static) function get_frontpage() { $front = new stdClass; - + $filename = 'content/data/frontpage/frontpage.md'; if (file_exists($filename)) { @@ -924,7 +924,7 @@ function get_frontpage() $front->url = site_url() . 'front'; $front->body = 'Welcome to our website.'; } - + return $front; } @@ -951,8 +951,8 @@ function get_keyword($keyword, $page, $perpage) return $tmp; } - return $tmp = get_posts($tmp, $page, $perpage); - + return $tmp = get_posts($tmp, $page, $perpage); + } // Get related posts base on post tag. @@ -976,7 +976,7 @@ function get_related($tag, $custom = null, $count = null) $tmp[] = $post; } } - + if (empty($custom)) { $total = count($tmp); @@ -991,15 +991,15 @@ function get_related($tag, $custom = null, $count = null) break; } echo ''; - + } else { echo ''; } - + } else { return $tmp; } - + } // Return post count. Matching $var and $str provided. @@ -1028,7 +1028,7 @@ function get_categorycount($var) $tmp = array(); foreach ($posts as $index => $v) { - + $filepath = $v['dirname'] . '/' . $v['basename']; // Extract the date @@ -1056,7 +1056,7 @@ function get_typecount($var) $tmp = array(); foreach ($posts as $index => $v) { - + $filepath = $v['dirname'] . '/' . $v['basename']; // Extract the date @@ -1085,7 +1085,7 @@ function get_draftcount($var) $tmp = array(); foreach ($posts as $index => $v) { - + $filepath = $v['dirname'] . '/' . $v['basename']; // Extract the date @@ -1097,7 +1097,7 @@ function get_draftcount($var) // Author string $str = explode('/', $replaced); $cat = $str[count($str) - 3]; - + if (stripos($cat, "$var") !== false) { $tmp[] = $v; } @@ -1112,7 +1112,7 @@ function get_tagcount($var, $str) $posts = get_post_sorted(); $tmp = array(); - + foreach ($posts as $index => $v) { $arr = explode('_', $v[$str]); $mtag = explode(',', rtrim($arr[1], ',')); @@ -1159,33 +1159,33 @@ function recent_posts($custom = null, $count = null) $count = 5; } } - + $dir = "cache/widget"; $filename = "cache/widget/recent.cache"; $tmp = array(); $posts = array(); - + if (is_dir($dir) === false) { mkdir($dir, 0775, true); } - + if (file_exists($filename)) { $posts = unserialize(file_get_contents($filename)); if (count($posts) != $count) { $posts = get_posts(null, 1, $count); $tmp = serialize($posts); file_put_contents($filename, print_r($tmp, true)); - } + } } else { $posts = get_posts(null, 1, $count); $tmp = serialize($posts); file_put_contents($filename, print_r($tmp, true)); } - + if (!empty($custom)) { - return $posts; + return $posts; } else { - + echo '