mirror of
https://github.com/danpros/htmly.git
synced 2026-04-17 19:26:08 +05:30
clean up the cache functions
This commit is contained in:
parent
63755a1add
commit
f70ce4e950
1 changed files with 1266 additions and 1441 deletions
|
|
@ -16,20 +16,11 @@ function get_post_unsorted(){
|
|||
if (empty($_unsorted)) {
|
||||
|
||||
$url = 'cache/index/index-unsorted.txt';
|
||||
if (file_exists($url)) {
|
||||
$_unsorted = unserialize(file_get_contents($url));
|
||||
}
|
||||
else {
|
||||
if(! file_exists($url)) {
|
||||
rebuilt_cache('all');
|
||||
}
|
||||
$_unsorted = unserialize(file_get_contents($url));
|
||||
}
|
||||
|
||||
if(empty($_unsorted)){
|
||||
$_unsorted = glob('content/*/blog/*.md', GLOB_NOSORT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $_unsorted;
|
||||
}
|
||||
|
||||
|
|
@ -38,38 +29,13 @@ 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 {
|
||||
if(! file_exists($url)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -80,19 +46,11 @@ function get_static_pages(){
|
|||
|
||||
if (empty($_page)) {
|
||||
$url = 'cache/index/index-page.txt';
|
||||
if (file_exists($url)) {
|
||||
$_page = unserialize(file_get_contents($url));
|
||||
}
|
||||
else {
|
||||
if(! file_exists($url)) {
|
||||
rebuilt_cache('all');
|
||||
}
|
||||
$_page = unserialize(file_get_contents($url));
|
||||
}
|
||||
|
||||
if(empty($_page)){
|
||||
$_page = glob('content/static/*.md', GLOB_NOSORT);
|
||||
}
|
||||
}
|
||||
|
||||
return $_page;
|
||||
}
|
||||
|
||||
|
|
@ -103,17 +61,11 @@ function get_author_names(){
|
|||
|
||||
if (empty($_author)) {
|
||||
$url = 'cache/index/index-author.txt';
|
||||
if (file_exists($url)) {
|
||||
$_author = unserialize(file_get_contents($url));
|
||||
}
|
||||
else {
|
||||
if(! file_exists($url)) {
|
||||
rebuilt_cache('all');
|
||||
}
|
||||
$_author = unserialize(file_get_contents($url));
|
||||
}
|
||||
if(empty($_author)){
|
||||
$_author = glob('content/*/author.md', GLOB_NOSORT);
|
||||
}
|
||||
}
|
||||
|
||||
return $_author;
|
||||
}
|
||||
|
|
@ -173,50 +125,20 @@ function rebuilt_cache($type) {
|
|||
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') {
|
||||
} 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') {
|
||||
} 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));
|
||||
|
||||
} elseif ($type === 'all') {
|
||||
rebuilt_cache('posts');
|
||||
rebuilt_cache('page');
|
||||
rebuilt_cache('author');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -296,8 +218,7 @@ function get_posts($posts, $page = 1, $perpage = 0){
|
|||
$title = rtrim(ltrim($title, ' '), ' ');
|
||||
$post->title = $title;
|
||||
$post->body = $arr[1];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$post->title = 'Untitled: ' . date('l jS \of F Y', $post->date);
|
||||
$post->body = $arr[0];
|
||||
}
|
||||
|
|
@ -330,28 +251,24 @@ function find_post($year, $month, $name){
|
|||
'current' => $ar[0],
|
||||
'prev' => $pr[0]
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return array(
|
||||
'current' => $ar[0],
|
||||
'prev' => null
|
||||
);
|
||||
}
|
||||
}
|
||||
elseif (count($posts) == $index+1) {
|
||||
} elseif (count($posts) == $index + 1) {
|
||||
return array(
|
||||
'current' => $ar[0],
|
||||
'next' => $nx[0]
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return array(
|
||||
'current' => $ar[0],
|
||||
'next' => $nx[0],
|
||||
'prev' => $pr[0]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -389,7 +306,6 @@ function get_tag($tag, $page, $perpage, $random){
|
|||
$tmp = array_unique($tmp, SORT_REGULAR);
|
||||
|
||||
return $tmp = get_posts($tmp, $page, $perpage);
|
||||
|
||||
}
|
||||
|
||||
// Return archive page.
|
||||
|
|
@ -412,7 +328,6 @@ function get_archive($req, $page, $perpage){
|
|||
}
|
||||
|
||||
return $tmp = get_posts($tmp, $page, $perpage);
|
||||
|
||||
}
|
||||
|
||||
// Return posts list on profile.
|
||||
|
|
@ -436,7 +351,6 @@ function get_profile($profile, $page, $perpage){
|
|||
}
|
||||
|
||||
return $tmp = get_posts($tmp, $page, $perpage);
|
||||
|
||||
}
|
||||
|
||||
// Return author bio.
|
||||
|
|
@ -475,8 +389,7 @@ function get_bio($author){
|
|||
$title = rtrim(ltrim($title, ' '), ' ');
|
||||
$post->title = $title;
|
||||
$post->body = $arr[1];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$post->title = $author;
|
||||
$post->body = $arr[0];
|
||||
}
|
||||
|
|
@ -488,11 +401,9 @@ function get_bio($author){
|
|||
|
||||
if (!empty($tmp) || file_exists($username)) {
|
||||
return $tmp;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
not_found();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function default_profile($author) {
|
||||
|
|
@ -504,7 +415,6 @@ function default_profile($author) {
|
|||
$profile->body = '<p>Just another HTMLy user.</p>';
|
||||
|
||||
return $tmp[] = $profile;
|
||||
|
||||
}
|
||||
|
||||
// Return static page.
|
||||
|
|
@ -540,21 +450,17 @@ function get_static_post($static){
|
|||
$title = rtrim(ltrim($title, ' '), ' ');
|
||||
$post->title = $title;
|
||||
$post->body = $arr[1];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$post->title = $static;
|
||||
$post->body = $arr[0];
|
||||
}
|
||||
|
||||
$tmp[] = $post;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
|
||||
}
|
||||
|
||||
// Return search page.
|
||||
|
|
@ -583,7 +489,6 @@ function get_keyword($keyword, $page, $perpage){
|
|||
}
|
||||
|
||||
return $tmp = get_posts($tmp, $page, $perpage);
|
||||
|
||||
}
|
||||
|
||||
// Get related posts base on post tag.
|
||||
|
|
@ -608,11 +513,11 @@ function get_related($tag) {
|
|||
echo '<div class="related"><h4>Related posts</h4><ul>';
|
||||
foreach ($tmp as $post) {
|
||||
echo '<li><a href="' . $post->url . '">' . $post->title . '</a></li>';
|
||||
if ($i++ >= $perpage) break;
|
||||
if ($i++ >= $perpage)
|
||||
break;
|
||||
}
|
||||
echo '</ul></div>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Return post count. Matching $var and $str provided.
|
||||
|
|
@ -630,7 +535,6 @@ function get_count($var, $str) {
|
|||
}
|
||||
|
||||
return count($tmp);
|
||||
|
||||
}
|
||||
|
||||
// Return seaarch result count
|
||||
|
|
@ -655,7 +559,6 @@ function keyword_count($keyword) {
|
|||
$tmp = array_unique($tmp, SORT_REGULAR);
|
||||
|
||||
return count($tmp);
|
||||
|
||||
}
|
||||
|
||||
// Return an archive list, categorized by year and month.
|
||||
|
|
@ -678,7 +581,6 @@ function archive_list() {
|
|||
$date = str_replace($replaced, '', $arr[0]);
|
||||
$data = explode('-', $date);
|
||||
$col[] = $data;
|
||||
|
||||
}
|
||||
|
||||
foreach ($col as $row) {
|
||||
|
|
@ -686,7 +588,6 @@ function archive_list() {
|
|||
$y = $row['0'];
|
||||
$m = $row['1'];
|
||||
$by_year[$y][] = $m;
|
||||
|
||||
}
|
||||
|
||||
# Most recent year first
|
||||
|
|
@ -706,8 +607,7 @@ EOF;
|
|||
if ($i == 0) {
|
||||
$class = 'expanded';
|
||||
$arrow = '▼';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$class = 'collapsed';
|
||||
$arrow = '►';
|
||||
}
|
||||
|
|
@ -732,11 +632,8 @@ EOF;
|
|||
echo '</ul>';
|
||||
echo '</li>';
|
||||
echo '</ul>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Return tag cloud.
|
||||
|
|
@ -756,7 +653,6 @@ function tag_cloud() {
|
|||
foreach ($mtag as $etag) {
|
||||
$tags[] = $etag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$tag_collection = array_count_values($tags);
|
||||
|
|
@ -768,9 +664,7 @@ function tag_cloud() {
|
|||
echo '<li class="item"><a href="' . site_url() . 'tag/' . $tag . '">' . $tag . '</a> <span class="count">(' . $count . ')</span></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Helper function to determine whether
|
||||
|
|
@ -816,19 +710,16 @@ function get_description($text) {
|
|||
|
||||
if (strlen($string) > 1) {
|
||||
return $string;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$string = preg_replace('/[^A-Za-z0-9 !@#$%^&*(),.-]/u', ' ', strip_tags($text));
|
||||
$string = rtrim(ltrim($string), $string);
|
||||
if (strlen($string) < config('description.char')) {
|
||||
return $string;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$string = substr($string, 0, config('description.char'));
|
||||
return $string = substr($string, 0, strrpos($string, ' '));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Get the teaser
|
||||
|
|
@ -838,15 +729,13 @@ function get_teaser($text, $url) {
|
|||
|
||||
if (strlen(strip_tags($text)) < config('teaser.char') || $teaserType === 'full') {
|
||||
echo $text;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$string = preg_replace('/\s\s+/', ' ', strip_tags($text));
|
||||
$string = substr($string, 0, config('teaser.char'));
|
||||
$string = substr($string, 0, strrpos($string, ' '));
|
||||
$body = $string . '...' . ' <a class="readmore" href="' . $url . '#more">more</a>';
|
||||
echo '<p>' . $body . '</p>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Get thumbnail from image and Youtube.
|
||||
|
|
@ -868,8 +757,7 @@ function get_thumbnail($text) {
|
|||
$imgElement = $imgTags->item(0);
|
||||
$imgSource = $imgElement->getAttribute('src');
|
||||
return '<div class="thumbnail" style="background-image:url(' . $imgSource . ');"></div>';
|
||||
}
|
||||
elseif ($vidTags->length > 0) {
|
||||
} elseif ($vidTags->length > 0) {
|
||||
$vidElement = $vidTags->item(0);
|
||||
$vidSource = $vidElement->getAttribute('src');
|
||||
$fetch = explode("embed/", $vidSource);
|
||||
|
|
@ -877,19 +765,15 @@ function get_thumbnail($text) {
|
|||
$vidThumb = '//img.youtube.com/vi/' . $fetch[1] . '/default.jpg';
|
||||
return '<div class="thumbnail" style="background-image:url(' . $vidThumb . ');"></div>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!empty($default)) {
|
||||
return '<div class="thumbnail" style="background-image:url(' . $default . ');"></div>';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Return edit tab on post
|
||||
|
|
@ -900,8 +784,7 @@ function tab($p) {
|
|||
if ($user === $p->author || $role === 'admin') {
|
||||
echo '<div class="tab"><a href="' . $p->url . '">View</a><a href="' . $p->url . '/edit?destination=post">Edit</a></div>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '<div class="tab"><a href="' . $p->url . '">View</a><a href="' . $p->url . '/edit?destination=post">Edit</a></div>';
|
||||
}
|
||||
}
|
||||
|
|
@ -940,7 +823,6 @@ function social(){
|
|||
}
|
||||
|
||||
echo '<a href="' . site_url() . 'feed/rss" target="_blank"><img src="' . site_url() . 'themes/default/img/rss.png" width="32" height="32" alt="RSS Feed"/></a>';
|
||||
|
||||
}
|
||||
|
||||
// Copyright
|
||||
|
|
@ -951,11 +833,9 @@ function copyright(){
|
|||
|
||||
if (!empty($blogcp)) {
|
||||
return $copyright = '<p>' . $blogcp . '</p><p>' . $credit . '</p>';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return $credit = '<p>' . $credit . '</p>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Disqus on post.
|
||||
|
|
@ -1033,7 +913,6 @@ EOF;
|
|||
if (!empty($appid) && $comment == 'facebook') {
|
||||
return $script;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Google Publisher (Google+ page).
|
||||
|
|
@ -1082,11 +961,9 @@ function menu(){
|
|||
|
||||
if ($i == 0) {
|
||||
$class = 'item first';
|
||||
}
|
||||
elseif ($i == $len - 1) {
|
||||
} elseif ($i == $len - 1) {
|
||||
$class = 'item last';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$class = 'item';
|
||||
}
|
||||
|
||||
|
|
@ -1102,32 +979,26 @@ function menu(){
|
|||
if (file_exists($file)) {
|
||||
if (strpos($req, $id) !== false) {
|
||||
echo '<li class="' . $class . ' active"><a href="' . $anc[1] . '">' . $anc[0] . '</a></li>';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '<li class="' . $class . '"><a href="' . $anc[1] . '">' . $anc[0] . '</a></li>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (rtrim($anc[1], '/') . '/' == site_url()) {
|
||||
if ($req == site_path() . '/') {
|
||||
echo '<li class="' . $class . ' active"><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></li>';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '<li class="' . $class . '"><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></li>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '<li class="' . $class . '"><a target="_blank" href="' . $anc[1] . '">' . $anc[0] . '</a></li>';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
get_menu();
|
||||
}
|
||||
}
|
||||
|
|
@ -1145,8 +1016,7 @@ function get_menu() {
|
|||
echo '<ul class="nav">';
|
||||
if ($req == site_path() . '/') {
|
||||
echo '<li class="item first active"><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></li>';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '<li class="item first"><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></li>';
|
||||
}
|
||||
|
||||
|
|
@ -1157,8 +1027,7 @@ function get_menu() {
|
|||
|
||||
if ($i == $len - 1) {
|
||||
$class = 'item last';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$class = 'item';
|
||||
}
|
||||
$i++;
|
||||
|
|
@ -1176,35 +1045,27 @@ function get_menu() {
|
|||
if (isset($arr[1])) {
|
||||
$title = str_replace('<!--t', '', $arr[0]);
|
||||
$title = rtrim(ltrim($title, ' '), ' ');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$title = str_replace('-', ' ', str_replace('.md', '', $base));
|
||||
}
|
||||
|
||||
if (strpos($req, str_replace('.md', '', $base)) !== false) {
|
||||
echo '<li class="' . $class . ' active"><a href="' . $url . '">' . ucwords($title) . '</a></li>';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '<li class="' . $class . '"><a href="' . $url . '">' . ucwords($title) . '</a></li>';
|
||||
}
|
||||
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
echo '<ul class="nav">';
|
||||
if ($req == site_path() . '/') {
|
||||
echo '<li class="item first active"><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></li>';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo '<li class="item first"><a href="' . site_url() . '">' . config('breadcrumb.home') . '</a></li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Search form
|
||||
|
|
@ -1245,15 +1106,13 @@ function generate_rss($posts){
|
|||
if (strlen(strip_tags($p->body)) < config('rss.char')) {
|
||||
$string = preg_replace('/\s\s+/', ' ', strip_tags($p->body));
|
||||
$body = $string . '...' . ' <a class="readmore" href="' . $p->url . '#more">more</a>';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$string = preg_replace('/\s\s+/', ' ', strip_tags($p->body));
|
||||
$string = substr($string, 0, config('rss.char'));
|
||||
$string = substr($string, 0, strrpos($string, ' '));
|
||||
$body = $string . '...' . ' <a class="readmore" href="' . $p->url . '#more">more</a>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$body = $p->body;
|
||||
}
|
||||
|
||||
|
|
@ -1346,13 +1205,10 @@ function get_static_path(){
|
|||
$post->url = site_url() . str_replace('.md', '', $url);
|
||||
|
||||
$tmp[] = $post;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
|
||||
}
|
||||
|
||||
// Generate sitemap.xml.
|
||||
|
|
@ -1370,16 +1226,12 @@ function generate_sitemap($str){
|
|||
echo '<sitemap><loc>' . site_url() . 'sitemap.archive.xml</loc></sitemap>';
|
||||
echo '<sitemap><loc>' . site_url() . 'sitemap.author.xml</loc></sitemap>';
|
||||
echo '</sitemapindex>';
|
||||
|
||||
}
|
||||
elseif ($str == 'base') {
|
||||
} elseif ($str == 'base') {
|
||||
|
||||
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
||||
echo '<url><loc>' . site_url() . '</loc><priority>1.0</priority></url>';
|
||||
echo '</urlset>';
|
||||
|
||||
}
|
||||
elseif ($str == 'post') {
|
||||
} elseif ($str == 'post') {
|
||||
|
||||
$posts = get_path();
|
||||
|
||||
|
|
@ -1390,9 +1242,7 @@ function generate_sitemap($str){
|
|||
}
|
||||
|
||||
echo '</urlset>';
|
||||
|
||||
}
|
||||
elseif ($str == 'static') {
|
||||
} elseif ($str == 'static') {
|
||||
|
||||
$posts = get_static_path();
|
||||
|
||||
|
|
@ -1403,13 +1253,10 @@ function generate_sitemap($str){
|
|||
foreach ($posts as $p) {
|
||||
echo '<url><loc>' . $p->url . '</loc><priority>0.5</priority></url>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</urlset>';
|
||||
|
||||
}
|
||||
elseif ($str == 'tag') {
|
||||
} elseif ($str == 'tag') {
|
||||
|
||||
$posts = get_post_unsorted();
|
||||
$tags = array();
|
||||
|
|
@ -1424,7 +1271,6 @@ function generate_sitemap($str){
|
|||
foreach ($mtag as $etag) {
|
||||
$tags[] = $etag;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach ($tags as $t) {
|
||||
|
|
@ -1440,15 +1286,11 @@ function generate_sitemap($str){
|
|||
foreach ($tag as $t) {
|
||||
echo '<url><loc>' . $t . '</loc><priority>0.5</priority></url>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</urlset>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
elseif ($str == 'archive') {
|
||||
} elseif ($str == 'archive') {
|
||||
|
||||
$posts = get_path();
|
||||
$day = array();
|
||||
|
|
@ -1459,7 +1301,6 @@ function generate_sitemap($str){
|
|||
$day[] = $p->archiveday;
|
||||
$month[] = $p->archivemonth;
|
||||
$year[] = $p->archiveyear;
|
||||
|
||||
}
|
||||
|
||||
$day = array_unique($day, SORT_REGULAR);
|
||||
|
|
@ -1481,9 +1322,7 @@ function generate_sitemap($str){
|
|||
}
|
||||
|
||||
echo '</urlset>';
|
||||
|
||||
}
|
||||
elseif ($str == 'author') {
|
||||
} elseif ($str == 'author') {
|
||||
|
||||
$posts = get_path();
|
||||
$author = array();
|
||||
|
|
@ -1501,9 +1340,7 @@ function generate_sitemap($str){
|
|||
}
|
||||
|
||||
echo '</urlset>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Function to generate OPML file
|
||||
|
|
@ -1568,14 +1405,11 @@ function Zip($source, $destination, $include_dir = false) {
|
|||
|
||||
if (is_dir($file) === true) {
|
||||
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
|
||||
}
|
||||
else if (is_file($file) === true) {
|
||||
} else if (is_file($file) === true) {
|
||||
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (is_file($source) === true) {
|
||||
} else if (is_file($source) === true) {
|
||||
$zip->addFromString(basename($source), file_get_contents($source));
|
||||
}
|
||||
|
||||
|
|
@ -1587,8 +1421,7 @@ function is_front() {
|
|||
$req = $_SERVER['REQUEST_URI'];
|
||||
if ($req == site_path() . '/' || strpos($req, site_path() . '/?page') !== false) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1598,8 +1431,7 @@ function is_index() {
|
|||
$req = $_SERVER['REQUEST_URI'];
|
||||
if (strpos($req, '/archive/') !== false || strpos($req, '/tag/') !== false || strpos($req, '/search/') !== false || $req == site_path() . '/' || strpos($req, site_path() . '/?page') !== false) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1653,18 +1485,15 @@ function head_contents($title, $description, $canonical) {
|
|||
|
||||
if ($styleImage == 'on') {
|
||||
$output .= $title . "\n" . $favicon . "\n" . $charset . "\n" . $generator . "\n" . $xua . "\n" . $viewport . "\n" . $description . "\n" . $sitemap . "\n" . $canonical . "\n" . $feed . "\n" . $lightboxcss . "\n" . $jquery . "\n" . $lightbox . "\n" . $corejs . "\n";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ($jq == 'enable') {
|
||||
$output .= $title . "\n" . $favicon . "\n" . $charset . "\n" . $generator . "\n" . $xua . "\n" . $viewport . "\n" . $description . "\n" . $sitemap . "\n" . $canonical . "\n" . $feed . "\n" . $jquery . "\n";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$output .= $title . "\n" . $favicon . "\n" . $charset . "\n" . $generator . "\n" . $xua . "\n" . $viewport . "\n" . $description . "\n" . $sitemap . "\n" . $canonical . "\n" . $feed . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
// Return toolbar
|
||||
|
|
@ -1682,7 +1511,9 @@ function toolbar() {
|
|||
EOF;
|
||||
echo '<div id="toolbar"><ul>';
|
||||
echo '<li><a href="' . $base . 'admin">Admin</a></li>';
|
||||
if ($role === 'admin') {echo '<li><a href="'.$base.'admin/posts">Posts</a></li>';}
|
||||
if ($role === 'admin') {
|
||||
echo '<li><a href="' . $base . 'admin/posts">Posts</a></li>';
|
||||
}
|
||||
echo '<li><a href="' . $base . 'admin/mine">Mine</a></li>';
|
||||
echo '<li><a href="' . $base . 'add/post">Add post</a></li>';
|
||||
echo '<li><a href="' . $base . 'add/page">Add page</a></li>';
|
||||
|
|
@ -1690,8 +1521,7 @@ EOF;
|
|||
echo '<li><a href="' . $base . 'admin/import">Import</a></li>';
|
||||
echo '<li><a href="' . $base . 'admin/backup">Backup</a></li>';
|
||||
echo '<li><a href="' . $base . 'admin/clear-cache">Clear cache</a></li>';
|
||||
if( $updater->updateAble())
|
||||
{
|
||||
if ($updater->updateAble()) {
|
||||
echo '<li><a href="' . $base . 'admin/update/now/' . $CSRF . '">Update to ' . $updater->getName() . '</a></li>';
|
||||
}
|
||||
echo '<li><a href="' . $base . 'logout">Logout</a></li>';
|
||||
|
|
@ -1712,24 +1542,19 @@ function file_cache($request) {
|
|||
}
|
||||
}
|
||||
|
||||
function generate_csrf_token()
|
||||
{
|
||||
function generate_csrf_token() {
|
||||
$_SESSION[config("site.url")]['csrf_token'] = sha1(microtime(true) . mt_rand(10000, 90000));
|
||||
}
|
||||
|
||||
function get_csrf()
|
||||
{
|
||||
if(! isset($_SESSION[config("site.url")]['csrf_token']) || empty($_SESSION[config("site.url")]['csrf_token']))
|
||||
{
|
||||
function get_csrf() {
|
||||
if (!isset($_SESSION[config("site.url")]['csrf_token']) || empty($_SESSION[config("site.url")]['csrf_token'])) {
|
||||
generate_csrf_token();
|
||||
}
|
||||
return $_SESSION[config("site.url")]['csrf_token'];
|
||||
}
|
||||
|
||||
function is_csrf_proper($csrf_token)
|
||||
{
|
||||
if($csrf_token == get_csrf())
|
||||
{
|
||||
function is_csrf_proper($csrf_token) {
|
||||
if ($csrf_token == get_csrf()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue