diff --git a/system/includes/functions.php b/system/includes/functions.php index fa726f23..b62beb3d 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -136,7 +136,7 @@ function get_draft_subpages($static = null) } return false; }); - } + } return $_draftSubpage; } @@ -209,7 +209,8 @@ function get_zip_files() } // Get images in content/images folder -function scan_images() { +function scan_images() +{ static $_images = array(); $tmp = array(); @@ -230,7 +231,7 @@ function sortfile_a($a, $b) return $a['basename'] == $b['basename'] ? 0 : (($a['basename'] > $b['basename']) ? 1 : -1); } -// usort function. +// usort function. function sortfile_d($a, $b) { return $a['basename'] == $b['basename'] ? 0 : (($a['basename'] < $b['basename']) ? 1 : -1); @@ -264,7 +265,7 @@ function rebuilt_cache($type = null) $tmp = glob('content/*/blog/*/*/*.md', GLOB_NOSORT); if (is_array($tmp)) { foreach ($tmp as $file) { - if(strpos($file, '/draft/') === false) { + if (strpos($file, '/draft/') === false) { $posts_cache[] = pathinfo($file); $pc = explode('/', $file); $ctmp[] = $pc[3]; @@ -273,7 +274,7 @@ function rebuilt_cache($type = null) } usort($posts_cache, "sortfile_d"); $posts_string = serialize($posts_cache); - file_put_contents('cache/index/index-posts.txt', print_r($posts_string, true), LOCK_EX); + file_put_contents('cache/index/index-posts.txt', print_r($posts_string, true), LOCK_EX); // Rebuilt scheduled posts index $stmp = array(); @@ -288,7 +289,7 @@ function rebuilt_cache($type = null) usort($scheduled_cache, "sortfile_d"); $scheduled_string = serialize($scheduled_cache); file_put_contents('cache/index/index-scheduled.txt', print_r($scheduled_string, true), LOCK_EX); - + // Rebuilt draft posts index $drf = array(); $drf = glob('content/*/*/*/draft/*.md', GLOB_NOSORT); @@ -302,33 +303,33 @@ function rebuilt_cache($type = null) usort($draft_cache, "sortfile_d"); $draft_string = serialize($draft_cache); file_put_contents('cache/index/index-draft.txt', print_r($draft_string, true), LOCK_EX); - + // Rebuilt category files index $ftmp = array(); $ftmp = glob('content/data/category/*.md', GLOB_NOSORT); if (is_array($ftmp)) { foreach ($ftmp as $file) { $category_cache[] = pathinfo($file); - $ctmp[] = pathinfo($file, PATHINFO_FILENAME); + $ctmp[] = pathinfo($file, PATHINFO_FILENAME); } } usort($category_cache, "sortfile_a"); $category_string = serialize($category_cache); file_put_contents('cache/index/index-category-files.txt', print_r($category_string, true), LOCK_EX); - + // Rebuilt category slug index $dirc = array(); $dirc = array_push($ctmp, 'uncategorized'); - $dirc = array_unique($ctmp, SORT_REGULAR); + $dirc = array_unique($ctmp, SORT_REGULAR); file_put_contents('cache/index/index-category.txt', print_r(serialize($dirc), true), LOCK_EX); - + // Rebuilt static page index $ptmp = array(); $ptmp = glob('content/static/*.md', GLOB_NOSORT); natsort($ptmp); if (is_array($ptmp)) { foreach ($ptmp as $file) { - if(strpos($file, '/draft/') === false) { + if (strpos($file, '/draft/') === false) { $page_cache[] = pathinfo($file); } } @@ -342,7 +343,7 @@ function rebuilt_cache($type = null) natsort($sptmp); if (is_array($sptmp)) { foreach ($sptmp as $file) { - if(strpos($file, '/draft/') === false) { + if (strpos($file, '/draft/') === false) { $subpage_cache[] = pathinfo($file); } } @@ -366,7 +367,6 @@ function rebuilt_cache($type = null) foreach (glob('cache/widget/*.cache', GLOB_NOSORT) as $file) { unlink($file); } - } // Return blog posts. @@ -391,7 +391,7 @@ function get_posts($posts, $page = 1, $perpage = 0) if (file_exists($viewsFile) && $counter == 'true') { $views = json_decode(file_get_contents($viewsFile), true); } - + foreach ($posts as $index => $v) { $post = new stdClass; @@ -407,7 +407,7 @@ function get_posts($posts, $page = 1, $perpage = 0) // Author string $str = explode('/', $dirname); $author = $str[1]; - + foreach ($cList as $a => $t) { if ($t['0'] === $str[3]) { $post->category = '' . $t['1'] . ''; @@ -484,15 +484,15 @@ function get_posts($posts, $page = 1, $perpage = 0) $tagt = get_content_tag('tag', $content); $t = explode(',', rtrim($arr[1], ',')); - if(!empty($tagt)) { + if (!empty($tagt)) { $tl = explode(',', rtrim($tagt, ',')); if (count($tl) == count($t)) { $tCom = array_combine($t, $tl); } else { - $tCom = array_combine($t, $t); + $tCom = array_combine($t, $t); } foreach ($tCom as $key => $val) { - if(!empty($val)) { + if (!empty($val)) { $tag[] = array($val, site_url() . 'tag/' . strtolower($key)); } else { $tag[] = array($key, site_url() . 'tag/' . strtolower($key)); @@ -513,7 +513,7 @@ function get_posts($posts, $page = 1, $perpage = 0) $post->tagb = implode(' » ', $bc); - $post->related = $post->categorySlug. ',' .$post->url; + $post->related = $post->categorySlug . ',' . $post->url; $more = explode('', $content); if (isset($more['1'])) { @@ -538,11 +538,11 @@ function get_posts($posts, $page = 1, $perpage = 0) } if ($counter == 'true') { - $post->views = get_views('post_' . $post->slug, $views); + $post->views = get_views('post_' . $post->slug, $views); } else { $post->views = null; } - + $post->raw = $content; $tmp[] = $post; @@ -551,14 +551,14 @@ function get_posts($posts, $page = 1, $perpage = 0) return $tmp; } -function get_pages($pages, $page = 1, $perpage = 0) +function get_pages($pages, $page = 1, $perpage = 0) { if (empty($pages)) { $pages = get_static_pages(); } $tmp = array(); - + $auto = config('toc.automatic'); $counter = config('views.counter'); @@ -569,24 +569,24 @@ function get_pages($pages, $page = 1, $perpage = 0) // Extract a specific page with results $pages = array_slice($pages, ($page - 1) * $perpage, $perpage); - + foreach ($pages as $index => $v) { $post = new stdClass; // The static page URL $fn = explode('.', $v['filename']); - + if (isset($fn[1])) { $url = $fn[1]; } else { - $url= $v['filename']; + $url = $v['filename']; } - + $post->url = site_url() . $url; $post->file = $v['dirname'] . '/' . $v['basename']; $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); - + $post->md = $v['basename']; $post->slug = $url; $post->parent = null; @@ -616,21 +616,20 @@ function get_pages($pages, $page = 1, $perpage = 0) } if ($counter == 'true') { - $post->views = get_views('page_' . $post->slug, $views); + $post->views = get_views('page_' . $post->slug, $views); } else { $post->views = null; } - + $post->raw = $content; - $tmp[] = $post; + $tmp[] = $post; } - + return $tmp; - } -function get_subpages($sub_pages, $page = 1, $perpage = 0) +function get_subpages($sub_pages, $page = 1, $perpage = 0) { if (empty($sub_pages)) { $sub_pages = get_static_subpages(); @@ -648,13 +647,13 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0) // Extract a specific page with results $sub_pages = array_slice($sub_pages, ($page - 1) * $perpage, $perpage); - + foreach ($sub_pages as $index => $v) { - + $post = new stdClass; - + $fd = str_replace(dirname($v['dirname']) . '/', '', $v['dirname']); - + $st = explode('.', $fd); if (isset($st[1])) { $static = $st[1]; @@ -664,18 +663,18 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0) // The static page URL $fn = explode('.', $v['filename']); - + if (isset($fn[1])) { $url = $fn[1]; } else { - $url= $v['filename']; + $url = $v['filename']; } - + $post->url = site_url() . $static . "/" . $url; $post->file = $v['dirname'] . '/' . $v['basename']; $post->lastMod = strtotime(date('Y-m-d H:i:s', filemtime($post->file))); - + $post->md = $v['basename']; $post->slug = $url; $post->parent = $fd; @@ -696,27 +695,26 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0) $post->readTime = ceil($word_count / 200); $toc = explode('', $post->body); - if (isset($toc['1'])) { + if (isset($toc['1'])) { $post->body = insert_toc('subpage-' . $post->slug, $toc['0'], $toc['1']); } else { if ($auto === 'true') { $post->body = automatic_toc($post->body, 'subpage-' . $post->slug); } } - + if ($counter == 'true') { - $post->views = get_views('subpage_' . $post->parentSlug .'.'. $post->slug, $views); + $post->views = get_views('subpage_' . $post->parentSlug . '.' . $post->slug, $views); } else { $post->views = null; } - + $post->raw = $content; - $tmp[] = $post; + $tmp[] = $post; } - + return $tmp; - } // Find post by year, month and name, previous, and next. @@ -767,7 +765,7 @@ function find_post($year, $month, $name) function find_page($static = null) { $pages = get_static_pages(); - + $tmp = array(); if (!empty($pages)) { @@ -776,7 +774,6 @@ function find_page($static = null) if (is_null($static)) { return get_pages($pages, 1, null); - } elseif (stripos($v['basename'], $static . '.md') !== false) { // Use the get_posts method to return @@ -813,7 +810,7 @@ function find_page($static = null) } } } - + return $tmp; } @@ -827,11 +824,10 @@ function find_subpage($static, $sub_static = null) if (!empty($sub_pages)) { foreach ($sub_pages as $index => $v) { - + if (is_null($sub_static)) { - + return get_subpages($sub_pages, 1, null); - } elseif (stripos($v['basename'], $sub_static . '.md') !== false) { // Use the get_posts method to return @@ -875,11 +871,11 @@ function find_subpage($static, $sub_static = null) // Return category page. function get_category($category, $page, $perpage, $random = null) { - + if (is_null($category)) return array(); - + $posts = get_blog_posts(); - + if ($random === true) { shuffle($posts); } @@ -916,20 +912,20 @@ function get_category_info($category = null) { $tmp = array(); - $cslug= get_category_slug(); + $cslug = get_category_slug(); if (!empty($cslug)) { asort($cslug); if (is_null($category)) { - foreach ($cslug as $key => $c){ + foreach ($cslug as $key => $c) { $ctmp = read_category_info($c); if (!empty($ctmp[0])) { $tmp[] = $ctmp[0]; } else { $tmp[] = default_category($c); - } + } } } else { - foreach ($cslug as $key => $c){ + foreach ($cslug as $key => $c) { if ($c === $category) { $ctmp = read_category_info($category); if (!empty($ctmp[0])) { @@ -938,7 +934,7 @@ function get_category_info($category = null) $tmp[] = default_category($category); } } - } + } } } else { $tmp[] = default_category($category); @@ -946,26 +942,26 @@ function get_category_info($category = null) return $tmp; } -function read_category_info($category) +function read_category_info($category) { $tmp = array(); $cFiles = get_category_files(); if (!empty($cFiles)) { foreach ($cFiles as $index => $v) { - if ($v['basename'] == $category . '.md' ) { + if ($v['basename'] == $category . '.md') { $desc = new stdClass; // The filename $filename = $v['dirname'] . '/' . $v['basename']; - - $url= $v['filename']; + + $url = $v['filename']; $desc->url = site_url() . 'category/' . $url; $desc->md = $v['basename']; - + $desc->slug = $url; $desc->count = get_categorycount($url); @@ -989,14 +985,14 @@ function read_category_info($category) if (isset($toc['1'])) { $desc->body = insert_toc('taxonomy-' . $desc->slug, $toc['0'], $toc['1']); } - + $desc->raw = $content; $tmp[] = $desc; - } + } } } - return $tmp; + return $tmp; } // Return default category @@ -1016,7 +1012,7 @@ function default_category($category = null) $desc->count = get_categorycount($desc->slug); $desc->rss = $desc->url . '/feed'; $desc->raw = $desc->body; - } else{ + } else { $desc->title = $category; $desc->url = site_url() . 'category/' . $category; $desc->slug = $category; @@ -1033,7 +1029,7 @@ function default_category($category = null) } // Return category list -function category_list($custom = null) +function category_list($custom = null) { $dir = "cache/widget"; $filename = "cache/widget/category.list.cache"; @@ -1058,7 +1054,7 @@ function category_list($custom = null) file_put_contents($filename, print_r($tmp, true), LOCK_EX); } - if(!empty($custom)) { + if (!empty($custom)) { return $cat; } @@ -1066,13 +1062,12 @@ function category_list($custom = null) foreach ($cat as $k => $v) { if ($v['2'] !== 0) { - $cList .= '
  • ' . $v['1'] . ' ('. $v['2'] .')
  • '; + $cList .= '
  • ' . $v['1'] . ' (' . $v['2'] . ')
  • '; } } $cList .= ''; return $cList; - } // Return type page. @@ -1216,7 +1211,7 @@ function get_author($name) if ($name === $profile) { // Profile URL $filename = $v['dirname'] . '/' . $v['basename']; - + $author->file = $filename; $author->url = site_url() . 'author/' . $profile; @@ -1238,13 +1233,13 @@ function get_author($name) $author->rss = $author->url . '/feed'; $toc = explode('', $author->about); - if (isset($toc['1'])) { + if (isset($toc['1'])) { $author->about = insert_toc('profile-' . $author->slug, $toc['0'], $toc['1']); } $author->body = $author->about; $author->title = $author->name; - + $author->raw = $content; $tmp[] = $author; @@ -1267,7 +1262,7 @@ function default_profile($name) $author->body = '

    ' . i18n('Author_Description') . '

    '; $author->description = i18n('Author_Description'); $author->avatar = site_url() . 'system/resources/images/logo-small.png'; - $author->url = site_url(). 'author/' . $name; + $author->url = site_url() . 'author/' . $name; $author->slug = $name; $author->file = ''; $author->rss = $author->url . '/feed'; @@ -1323,7 +1318,7 @@ function get_frontpage() // Return search page. function get_keyword($keyword, $page, $perpage) { - + if (strlen($keyword) < 3) { return array(); } @@ -1332,16 +1327,16 @@ function get_keyword($keyword, $page, $perpage) $tmp = array(); $search = array(); - + $searchFile = "content/data/search.json"; - + if (file_exists($searchFile) && config('fulltext.search') == "true") { $search = json_decode(file_get_contents($searchFile), true); } foreach ($posts as $index => $v) { $arr = explode('_', $v['filename']); - + if (isset($search['post_' . $arr[2]])) { $filter = $search['post_' . $arr[2]]; } else { @@ -1354,7 +1349,6 @@ function get_keyword($keyword, $page, $perpage) $tmp[] = $v; } } - } if (empty($tmp)) { @@ -1362,7 +1356,6 @@ function get_keyword($keyword, $page, $perpage) } return $tmp = array(get_posts($tmp, $page, $perpage), count($tmp)); - } // Get related posts base on post category. @@ -1381,12 +1374,11 @@ function get_related($tag, $custom = null, $count = null) $posts = get_category($exp[0], 1, $count + 1, true); if ($posts) $posts = $posts[0]; $related = ''; - $i = 1; - foreach ($posts as $post) { + foreach ($posts as $key => $post) { if ($post->url !== $exp[1]) { $tmp[] = $post; - if ($i++ >= $count) + if ($key + 1 >= $count) break; } } @@ -1403,11 +1395,9 @@ function get_related($tag, $custom = null, $count = null) $related .= ''; return $related; } - } else { return $tmp; } - } // Return post count. Matching $var and $str provided. @@ -1427,7 +1417,7 @@ function get_count($var, $str) } else { if (stripos($v[$str], $var) !== false) { $tmp[] = $v; - } + } } } @@ -1451,7 +1441,6 @@ function get_categorycount($var) if (strtolower($var) === strtolower($str[3])) { $tmp[] = $v; } - } return count($tmp); @@ -1474,7 +1463,6 @@ function get_typecount($var) if (strtolower($var) === strtolower($str[4])) { $tmp[] = $v; } - } return count($tmp); @@ -1497,7 +1485,6 @@ function get_profilecount($var) if (strtolower($var) === strtolower($str[1])) { $tmp[] = $v; } - } return count($tmp); @@ -1516,7 +1503,6 @@ function get_draftcount($var) if (stripos($v['dirname'], '/' . $var . '/') !== false) { $tmp[] = $v; } - } return count($tmp); } @@ -1533,11 +1519,9 @@ function get_scheduledcount($var) if (stripos($v['dirname'], '/' . $var . '/') !== false) { $tmp[] = $v; } - } - + return count($tmp); - } // Return tag count. Matching $var @@ -1571,16 +1555,16 @@ function keyword_count($keyword) $tmp = array(); $search = array(); - + $searchFile = "content/data/search.json"; - + if (file_exists($searchFile) && config('fulltext.search') == "true") { $search = json_decode(file_get_contents($searchFile), true); } foreach ($posts as $index => $v) { $arr = explode('_', $v['filename']); - + if (isset($search['post_' . $arr[2]])) { $filter = $search['post_' . $arr[2]]; } else { @@ -1593,12 +1577,10 @@ function keyword_count($keyword) $tmp[] = $v; } } - } $tmp = array_unique($tmp, SORT_REGULAR); return count($tmp); - } // Return recent posts @@ -1699,28 +1681,25 @@ function get_recent($filter, $var, $count = null, $custom = null) if (!empty($custom)) { $arr = array(); - $i = 1; - foreach ($posts as $post) { + foreach ($posts as $key => $post) { $arr[] = $post; - if ($i++ >= $count) - break; + if ($key + 1 >= $count) + break; } return $arr; } else { - $i = 1; $recent .= ''; return $recent; - } - + } } // Return popular posts lists @@ -1738,95 +1717,70 @@ function popular_posts($custom = null, $count = null) } } - if (config('views.counter') == 'true') { - if (empty($_views)) { - $filename = 'content/data/views.json'; - if (file_exists($filename)) { - $_views = json_decode(file_get_contents($filename), true); - if(is_array($_views)) { - arsort($_views); - $i = 1; - foreach ($_views as $key => $val) { - $arr = explode('post_', $key); - if (isset($arr[1])) { - foreach($posts_list as $in => $f) { - if (strpos($f['basename'], $arr[1] . '.md') !== false ) { - $tmp[] = $f; - if ($i++ >= $count) - break; - } - } - } - - } - - $dir = "cache/widget"; - $filecache = "cache/widget/popular.cache"; - $ar = array(); - $posts = array(); - - if (!is_dir($dir)) { - mkdir($dir, 0775, true); - } - - if (file_exists($filecache)) { - $posts = unserialize(file_get_contents($filecache)); - if (count($posts) < $count) { - $posts = get_posts($tmp, 1, $count); - $ar = serialize($posts); - file_put_contents($filecache, print_r($ar, true), LOCK_EX); - } - } else { - $posts = get_posts($tmp, 1, $count); - $ar = serialize($posts); - file_put_contents($filecache, print_r($ar, true), LOCK_EX); - } + if (config('views.counter') !== 'true') { + return empty($custom) ? '' : []; + } - if (empty($custom)) { - $ix = 1; - $pop .= ''; - return $pop; - } else { - $arp = array(); - $ix = 1; - foreach ($posts as $post) { - $arp[] = $post; - if ($ix++ >= $count) - break; + $tmp = []; + $filename = 'content/data/views.json'; + if (empty($_views) && file_exists($filename)) { + $_views = json_decode(file_get_contents($filename), true); + if (is_array($_views) && !empty($_views)) { + arsort($_views); // Sort views by descending order + $counted = 0; + foreach ($_views as $key => $val) { + if ($counted >= $count) { + break; + } + if (strpos($key, 'post_') === 0 && ($post_id = substr($key, 5))) { + foreach ($posts_list as $post) { + if (strpos($post['basename'], $post_id . '.md') !== false) { + $tmp[] = $post; + $counted++; + break; // Found match, move to next view } - return $arp; - } - } else { - if(empty($custom)) { - $pop .= ''; - return $pop; - } else { - return $tmp; } } - } else { - if (empty($custom)) { - $pop .= ''; - return $pop; - } else { - return $tmp; - } } } + } + + $dir = 'cache/widget'; + $filecache = 'cache/widget/popular.cache'; + $posts = []; + + if (!is_dir($dir)) { + mkdir($dir, 0775, true); + } + + if (file_exists($filecache)) { + $posts = unserialize(file_get_contents($filecache)) ?: []; + if (count($posts) < $count) { + $posts = get_posts($tmp, 1, $count); + file_put_contents($filecache, serialize($posts), LOCK_EX); + } } else { - if (empty($custom)) { - $pop .= ''; - return $pop; + $posts = get_posts($tmp, 1, $count); + file_put_contents($filecache, serialize($posts), LOCK_EX); + } + + if (empty($custom)) { + $output = ''; + return $output; } + + return array_slice($posts, 0, $count); } // Return an archive list, categorized by year and month. @@ -1851,7 +1805,7 @@ function archive_list($custom = null) foreach ($posts as $index => $v) { $arr = explode('_', $v['filename']); - + $date = $arr[0]; $data = explode('-', $date); $col[] = $data; @@ -1866,7 +1820,6 @@ function archive_list($custom = null) $ar = serialize($by_year); file_put_contents($filename, print_r($ar, true), LOCK_EX); - } else { $by_year = unserialize(file_get_contents($filename)); } @@ -1879,50 +1832,50 @@ function archive_list($custom = null) $len = count($by_year); if (empty($custom)) { - $cache_d = "cache/widget/archive.default.cache"; + $cache_d = 'cache/widget/archive.default.cache'; if (file_exists($cache_d)) { - $arch = unserialize(file_get_contents($cache_d)); - return $arch; - } else { - foreach ($by_year as $year => $months) { - if ($i == 0) { - $class = 'expanded'; - $arrow = '▼'; - } else { - $class = 'collapsed'; - $arrow = '►'; - } - $i++; - - $by_month = array_count_values($months); - # Sort the months - krsort($by_month); + return unserialize(file_get_contents($cache_d)); + } - $script = << -1){this.parentNode.className = 'collapsed';this.innerHTML = '►';} else {this.parentNode.className = 'expanded';this.innerHTML = '▼';} -EOF; - $arch .= ''; + $script = << -1) { + this.parentNode.className = 'collapsed'; + this.innerHTML = '►'; + } else { + this.parentNode.className = 'expanded'; + this.innerHTML = '▼'; + } + EOF; + + $arch .= ''; } + + file_put_contents($cache_d, serialize($arch), LOCK_EX); + return $arch; } elseif ($custom === 'month-year') { $cache_my = "cache/widget/archive.month-year.cache"; if (file_exists($cache_my)) { @@ -1935,7 +1888,7 @@ function archive_list($custom = null) krsort($by_month); foreach ($by_month as $month => $count) { $name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'F'); - $arch .= '
  • ' . $name . ' ' . $year .' ('.$count.')
  • '; + $arch .= '
  • ' . $name . ' ' . $year . ' (' . $count . ')
  • '; } } $ar = serialize($arch); @@ -1952,10 +1905,10 @@ function archive_list($custom = null) $by_month = array_count_values($months); # Sort the months krsort($by_month); - $arch .= '
  • ' . $year .' ('. count($months) .')
  • '; + $arch .= '
  • ' . $year . ' (' . count($months) . ')
  • '; } $ar = serialize($arch); - file_put_contents($cache_y, $ar, LOCK_EX); + file_put_contents($cache_y, $ar, LOCK_EX); return $arch; } } else { @@ -1977,9 +1930,9 @@ function tag_cloud($custom = null) $posts = get_blog_posts(); $tags = array(); - + $tagcloud_count = config('tagcloud.count'); - if(empty($tagcloud_count)) { + if (empty($tagcloud_count)) { $tagcloud_count = 40; } @@ -2002,7 +1955,7 @@ function tag_cloud($custom = null) $tag_collection = unserialize(file_get_contents($filename)); } - if(empty($custom)) { + if (empty($custom)) { $wrapper = ''; $cache_t = "cache/widget/tags.default.cache"; if (file_exists($cache_t)) { @@ -2025,25 +1978,24 @@ function tag_cloud($custom = null) // Font-size increment // this is the increase per tag quantity (times used) - $step = ($max_size - $min_size)/($spread); + $step = ($max_size - $min_size) / ($spread); arsort($tag_collection); $sliced_tags = array_slice($tag_collection, 0, $tagcloud_count, true); ksort($sliced_tags); foreach ($sliced_tags as $tag => $count) { $size = $min_size + (($count - $min_qty) * $step); - $wrapper .= ' '.tag_i18n($tag).' '; + $wrapper .= ' ' . tag_i18n($tag) . ' '; } $ar = serialize($wrapper); - file_put_contents($cache_t, $ar, LOCK_EX); + file_put_contents($cache_t, $ar, LOCK_EX); return $wrapper; } - } else { return $tag_collection; } } else { - if(empty($custom)) return; + if (empty($custom)) return; return $tags; } } @@ -2132,7 +2084,7 @@ function has_next($next) } } -function static_prev($prev) +function static_prev($prev) { if (!empty($prev)) { return array( @@ -2150,10 +2102,10 @@ function static_prev($prev) 'lastMod' => $prev->lastMod, 'raw' => $prev->raw ); - } + } } -function static_next($next) +function static_next($next) { if (!empty($next)) { return array( @@ -2171,7 +2123,7 @@ function static_next($next) 'lastMod' => $next->lastMod, 'raw' => $next->raw ); - } + } } // Helper function to determine whether @@ -2198,9 +2150,9 @@ function has_pagination($total, $perpage, $page = 1) function get_pagination($totalitems, $page = 1, $perpage = 10, $adjacents = 1, $pagestring = '?page=') { //defaults - if(!$adjacents) $adjacents = 1; - if(!$perpage) $perpage = 10; - if(!$page) $page = 1; + if (!$adjacents) $adjacents = 1; + if (!$perpage) $perpage = 10; + if (!$page) $page = 1; //other vars $prev = $page - 1; //previous page is page - 1 @@ -2214,101 +2166,91 @@ function get_pagination($totalitems, $page = 1, $perpage = 10, $adjacents = 1, $ */ $pagination = ''; $curpage = strtok($_SERVER["REQUEST_URI"], '?'); - - if($lastpage > 1) - { + + if ($lastpage > 1) { $pagination .= ''; } return $pagination; - } // Get the meta description function get_description($string, $char = null) { - if(empty($char)) { + if (empty($char)) { $char = config('description.char'); - if(empty($char)) { + if (empty($char)) { $char = 150; } } @@ -2320,7 +2262,6 @@ function get_description($string, $char = null) $string = substr($string, 0, strrpos($string, ' ')); return $string; } - } // Get the teaser @@ -2330,13 +2271,13 @@ function get_teaser($string, $url = null, $char = null) $more = config('read.more'); $behave = config('teaser.behave'); - if(empty($more)) { + if (empty($more)) { $more = 'Read more'; } - if(empty($char)) { + if (empty($char)) { $char = config('teaser.char'); - if(empty($char)) { + if (empty($char)) { $char = 200; } } @@ -2345,7 +2286,7 @@ function get_teaser($string, $url = null, $char = null) $readMore = explode('', $string); if (isset($readMore['1'])) { $string = replace_href($readMore['0'], 'a', 'footnote-ref', $url); - return $string . ''; + return $string . ''; } else { return $string; } @@ -2369,21 +2310,21 @@ function get_teaser($string, $url = null, $char = null) // Shorten the string function shorten($string = null, $char = null) { - if(empty($string)) { + if (empty($string)) { return; } - $string = str_replace(''. config('toc.label') .'', '', $string); + $string = str_replace('' . config('toc.label') . '', '', $string); libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->loadHTML('' . $string); $tags_to_remove = array('script', 'style'); - foreach($tags_to_remove as $tag){ + foreach ($tags_to_remove as $tag) { $element = $dom->getElementsByTagName($tag); - foreach($element as $item){ + foreach ($element as $item) { $item->parentNode->removeChild($item); } } - $string = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', mb_convert_encoding($dom->saveHTML($dom->documentElement), 'UTF-8')); + $string = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', mb_convert_encoding($dom->saveHTML($dom->documentElement), 'UTF-8')); $string = preg_replace('/\s\s+/', ' ', strip_tags($string)); $string = ltrim(rtrim($string)); $string = str_replace('', '', $string); @@ -2394,7 +2335,6 @@ function shorten($string = null, $char = null) } } return $string; - } // Get thumbnail from image and Youtube. @@ -2458,7 +2398,7 @@ function get_image($text, $width = null, $height = null) if ($imgTags->length > 0) { $imgElement = $imgTags->item(0); $imgSource = $imgElement->getAttribute('src'); - if(is_null($width)) { + if (is_null($width)) { return $imgSource; } else { return create_thumb($imgSource, $width, $height); @@ -2471,8 +2411,8 @@ function get_image($text, $width = null, $height = null) $vidThumb = '//img.youtube.com/vi/' . $fetch[1] . '/sddefault.jpg'; return $vidThumb; } - } else{ - return false; + } else { + return false; } } @@ -2484,12 +2424,12 @@ function tab($p) $tab = ''; if (isset($p->author)) { if ($user === $p->author || $role === 'editor' || $role === 'admin') { - $tab = ''; + $tab = ''; } } else { if ($p->url) { if ($role === 'editor' || $role === 'admin') { - $tab = ''; + $tab = ''; } } } @@ -2512,7 +2452,7 @@ function social($class = null) $social = ''; $social .= ''; @@ -2697,10 +2637,10 @@ function slashUrl($url) return rtrim($url, '/') . '/'; } -function parseNodes($nodes, $child = null, $class = null) +function parseNodes($nodes, $child = null, $class = null) { if (empty($child)) { - $ul = '