From b59d9ffd552b07cf1c24b0f50884b4f2d72ae50a Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Sun, 16 Feb 2014 22:07:12 +0700 Subject: [PATCH] Dynamic heading Dynamic heading for themer, there is is_index function. --- system/includes/functions.php | 217 +++++++++++++++++++++++------------------ themes/clean/css/style.css | 6 +- themes/clean/layout.html.php | 7 +- themes/default/css/style.css | 3 +- themes/default/layout.html.php | 6 +- themes/logs/css/style.css | 2 +- themes/logs/layout.html.php | 6 +- 7 files changed, 142 insertions(+), 105 deletions(-) diff --git a/system/includes/functions.php b/system/includes/functions.php index 58afa8d..273946b 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -438,7 +438,7 @@ function get_keyword($keyword, $page, $perpage){ $arr = explode('_', $v['filename']); $filter = $arr[1] .' '. $arr[2]; foreach($words as $word) { - if(strpos($filter, strtolower($word)) !== false) { + if(stripos($filter, $word) !== false) { $tmp[] = $v; } } @@ -533,72 +533,76 @@ function archive_list() { $by_year = array(); $col = array(); - foreach($posts as $index => $v){ + if(!empty($posts)) { - $arr = explode('_', $v); + foreach($posts as $index => $v){ - // Replaced string - $str = $arr[0]; - $replaced = substr($str, 0,strrpos($str, '/')) . '/'; + $arr = explode('_', $v); + + // Replaced string + $str = $arr[0]; + $replaced = substr($str, 0,strrpos($str, '/')) . '/'; + + $date = str_replace($replaced,'',$arr[0]); + $data = explode('-', $date); + $col[] = $data; + + } - $date = str_replace($replaced,'',$arr[0]); - $data = explode('-', $date); - $col[] = $data; + foreach ($col as $row){ - } - - foreach ($col as $row){ - - $y = $row['0']; - $m = $row['1']; - $by_year[$y][] = $m; + $y = $row['0']; + $m = $row['1']; + $by_year[$y][] = $m; - } - - # Most recent year first - krsort($by_year); - # Iterate for display - $script = << -1){this.parentNode.className = 'collapsed';this.innerHTML = '►';} else {this.parentNode.className = 'expanded';this.innerHTML = '▼';} + } + + # Most recent year first + krsort($by_year); + # Iterate for display + $script = << -1){this.parentNode.className = 'collapsed';this.innerHTML = '►';} else {this.parentNode.className = 'expanded';this.innerHTML = '▼';} EOF; - echo <<ul.archivegroup{padding:0;margin:0;}.archivegroup .expanded ul{display:block;}.archivegroup .collapsed ul{display:none;}.archivegroup li.expanded,.archivegroup li.collapsed{list-style:none;} - + echo <<ul.archivegroup{padding:0;margin:0;}.archivegroup .expanded ul{display:block;}.archivegroup .collapsed ul{display:none;}.archivegroup li.expanded,.archivegroup li.collapsed{list-style:none;} + EOF; - echo '

Archive

'; - $i = 0; - $len = count($by_year); - foreach ($by_year as $year => $months){ - if ($i == 0) { - $class = 'expanded'; - $arrow = '▼'; - } - else { - $class = 'collapsed'; - $arrow = '►'; - } - $i++; - - echo '
    '; - echo '
  • '; - echo '' . $arrow . ' '; - echo '' . $year . ' '; - echo '(' . count($months) . ')'; - echo '
      '; - - $by_month = array_count_values($months); - # Sort the months - krsort($by_month); - foreach ($by_month as $month => $count){ - $name = date('F', mktime(0,0,0,$month,1,2010)); - echo '
    • ' . $name . ''; - echo ' (' . $count . ')
    • '; - } + echo '

      Archive

      '; + $i = 0; + $len = count($by_year); + foreach ($by_year as $year => $months){ + if ($i == 0) { + $class = 'expanded'; + $arrow = '▼'; + } + else { + $class = 'collapsed'; + $arrow = '►'; + } + $i++; + + echo '
        '; + echo '
      • '; + echo '' . $arrow . ' '; + echo '' . $year . ' '; + echo '(' . count($months) . ')'; + echo '
          '; + + $by_month = array_count_values($months); + # Sort the months + krsort($by_month); + foreach ($by_month as $month => $count){ + $name = date('F', mktime(0,0,0,$month,1,2010)); + echo '
        • ' . $name . ''; + echo ' (' . $count . ')
        • '; + } - echo '
        '; - echo '
      • '; - echo '
      '; - + echo '
    '; + echo '
  • '; + echo '
'; + + } + } } @@ -609,27 +613,31 @@ function tag_cloud() { $posts = get_post_unsorted(); $tags = array(); - foreach($posts as $index => $v){ + if(!empty($posts)) { - $arr = explode('_', $v); + foreach($posts as $index => $v){ - $data = $arr[1]; - $mtag = explode(',', $data); - foreach($mtag as $etag) { - $tags[] = $etag; + $arr = explode('_', $v); + + $data = $arr[1]; + $mtag = explode(',', $data); + foreach($mtag as $etag) { + $tags[] = $etag; + } + } - } - - $tag_collection = array_count_values($tags); - ksort($tag_collection); + $tag_collection = array_count_values($tags); + ksort($tag_collection); + + echo '

Tags

'; + echo '
    '; + foreach ($tag_collection as $tag => $count){ + echo '
  • ' . $tag . ' (' . $count . ')
  • '; + } + echo '
'; - echo '

Tags

'; - echo '
    '; - foreach ($tag_collection as $tag => $count){ - echo '
  • ' . $tag . ' (' . $count . ')
  • '; } - echo '
'; } @@ -1237,36 +1245,39 @@ function generate_sitemap($str){ $posts = get_post_unsorted(); $tags = array(); - foreach($posts as $index => $v){ - - $arr = explode('_', $v); + if(!empty($posts)) { + foreach($posts as $index => $v){ - $data = $arr[1]; - $mtag = explode(',', $data); - foreach($mtag as $etag) { - $tags[] = $etag; + $arr = explode('_', $v); + + $data = $arr[1]; + $mtag = explode(',', $data); + foreach($mtag as $etag) { + $tags[] = $etag; + } + } - } - - foreach($tags as $t) { - $tag[] = site_url() . 'tag/' . $t; - } - - echo ''; - - if(isset($tag)) { - - $tag = array_unique($tag, SORT_REGULAR); + foreach($tags as $t) { + $tag[] = site_url() . 'tag/' . $t; + } + + echo ''; + + if(isset($tag)) { + + $tag = array_unique($tag, SORT_REGULAR); + + foreach($tag as $t) { + echo '' . $t . '0.5'; + } - foreach($tag as $t) { - echo '' . $t . '0.5'; } + + echo ''; } - echo ''; - } elseif ($str == 'archive') { @@ -1369,6 +1380,20 @@ function is_front() { } } +// TRUE if the current page is an index page like frontpage, tag index, archive index and search index. +function is_index() { + $req = $_SERVER['REQUEST_URI']; + if(strpos($req, 'archive') !== false || strpos($req, 'tag') !== false || strpos($req, 'search') !== false){ + return true; + } + elseif($req == site_path() . '/') { + return true; + } + else { + return false; + } +} + // Return blog title function blog_title() { return config('blog.title'); diff --git a/themes/clean/css/style.css b/themes/clean/css/style.css index daf0bfe..85305a7 100644 --- a/themes/clean/css/style.css +++ b/themes/clean/css/style.css @@ -56,19 +56,19 @@ h1{ margin: 0.5em 0; } -h1.blog-title { +h1.blog-title, h2.blog-title { text-transform:uppercase; font: 20px 'Open Sans Condensed', sans-serif; margin-bottom: 1em; line-height: 1.3; } -h1.blog-title a { +h1.blog-title a, h2.blog-title a { color:#4f4f4f; text-decoration: none; } -h1.blog-title a:hover { +h1.blog-title a:hover, h2.blog-title a:hover { color: #389dc1; } diff --git a/themes/clean/layout.html.php b/themes/clean/layout.html.php index 6276036..072c80d 100644 --- a/themes/clean/layout.html.php +++ b/themes/clean/layout.html.php @@ -17,8 +17,11 @@