CMS  Version 3.9
blog_archives.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4 Blog Archives Module
5 
6 @author Sonja Hubbard for Sonjara, Inc.
7 
8 Lists every month this year in which there were blog posts, followed by every previous year in which there were blog posts.
9 Months/years are linked to blog page with month and/or year constraint passed in query string.
10 
11 SELECT DATE_FORMAT(publish_date,'%M %Y')
12  FROM article where (published=1) and (article_type="Sonjara Blog") and (DATE_FORMAT(publish_date,'%Y') = DATE_FORMAT(curdate(),'%Y'))
13  GROUP BY DATE_FORMAT(publish_date,'%M %Y')
14 
15 SELECT DATE_FORMAT(publish_date,'%Y')
16  FROM article where (published=1) and (article_type="Sonjara Blog") and (DATE_FORMAT(publish_date,'%Y') < DATE_FORMAT(curdate(),'%Y'))
17  GROUP BY DATE_FORMAT(publish_date,'%Y')
18 
19 *****************************************************************/
20 
21 Fakoli::using("blog");
22 $id = $_GET["blog"];
24 
25 if (!$blog)
26 {
27  throw new FakoliException("Unknown Blog");
28 }
29 
30 if (!$blog->published)
31 {
32  redirect("/index");
33  return;
34 }
35 
37 
38 $published_this_year = " AND (DATE_FORMAT(publish_date,'%Y') = DATE_FORMAT(curdate(),'%Y')) GROUP BY publish_date";
39 $published_last_year = " AND (DATE_FORMAT(publish_date,'%Y') < DATE_FORMAT(curdate(),'%Y')) GROUP BY publish_date";
40 
41 $articlesThisYear = Query::create(Article, "WHERE published=1 AND publish_date <= curdate() AND article_type='{$article_type}'" . $published_this_year . " ORDER BY publish_date DESC")
42  ->filter(new InclusionFilter(publish_date))
43  ->execute();
44 
45 $articlesBeforeThisYear = Query::create(Article, "WHERE published=1 AND article_type='{$article_type}'" . $published_last_year . " ORDER BY publish_date DESC")
46  ->filter(new InclusionFilter(publish_date))
47  ->execute();
48 
49 $blogMonths = array();
50 foreach($articlesThisYear as $article)
51 {
52  $date = new DateTime($article->publish_date);
53  $blogMonths[] = $date->format('Y-m');
54 }
55 
56 $blogYears = array();
58 {
59  $date = new DateTime($article->publish_date);
60  $blogYears[] = $date->format('Y');
61 }
62 
63 $uniqueMonths = array_unique($blogMonths);
64 $uniqueYears = array_unique($blogYears);
65 
66 if (count($uniqueMonths) > 0 OR count($uniqueYears) > 0)
67 {
68  if (count($uniqueMonths) > 0)
69  {
70  echo "<h3>Recent Articles</h3>";
71  echo "<ul class='recent_articles'>";
72 
73  foreach($uniqueMonths as $month)
74  {
75  $month_name = date( 'F', mktime(0, 0, 0, substr($month,5,2)) ) . " " . substr($month,0,4);
76  echo "<li><a href='" . $blogname . "?year=" . substr($month,0,4) . "&month=" . substr($month,5,2) . "'>$month_name</a></li>";
77  }
78  }
79 
80  echo "</ul>";
81 
82  if (count($uniqueYears) > 0)
83  {
84  echo "<h3>Archives</h3>";
85  echo "<ul class='recent_articles'>";
86 
87  foreach($uniqueYears as $year)
88  {
89  echo "<li><a href='" . $blogname . "?year=" . substr($year,0,4) . "'>$year</a></li>";
90  }
91 
92  echo "</ul>";
93  }
94 }
95 
96 ?>
$article
$article publish_date
if(! $blog) if(! $blog->published) $article_type
$articlesBeforeThisYear
$published_last_year
$published_this_year
$blog
foreach($articlesThisYear as $article) $blogYears
$uniqueYears
$articlesThisYear
$blogMonths
foreach($articlesBeforeThisYear as $article) $uniqueMonths
Defines the Article class.
Definition: article.inc:45
static findByIdentifier($identifier)
Definition: blog.inc:155
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
$date
Definition: event_list.inc:51
$month
Definition: blog.inc:39
$year
Definition: blog.inc:38