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"
];
23
$blog
=
Blog::findByIdentifier
(
$id
);
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
36
$article_type
=
$blog
->title;
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();
57
foreach
(
$articlesBeforeThisYear
as
$article
)
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
Definition:
article_form.inc:39
publish_date
$article publish_date
Definition:
article_form.inc:49
$article_type
if(! $blog) if(! $blog->published) $article_type
Definition:
blog_archives.inc:36
$articlesBeforeThisYear
$articlesBeforeThisYear
Definition:
blog_archives.inc:45
$published_last_year
$published_last_year
Definition:
blog_archives.inc:39
$published_this_year
$published_this_year
Definition:
blog_archives.inc:38
$blog
$blog
Definition:
blog_archives.inc:23
$blogYears
foreach($articlesThisYear as $article) $blogYears
Definition:
blog_archives.inc:56
$uniqueYears
$uniqueYears
Definition:
blog_archives.inc:64
$articlesThisYear
$articlesThisYear
Definition:
blog_archives.inc:41
$blogMonths
$blogMonths
Definition:
blog_archives.inc:49
$id
$id
Definition:
blog_archives.inc:22
$uniqueMonths
foreach($articlesBeforeThisYear as $article) $uniqueMonths
Definition:
blog_archives.inc:63
Article
Defines the Article class.
Definition:
article.inc:45
Blog\findByIdentifier
static findByIdentifier($identifier)
Definition:
blog.inc:155
FakoliException
FakoliException is the base exception class for all Fakoli errors.
Definition:
core.inc:53
Fakoli\using
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition:
core.inc:116
$date
$date
Definition:
event_list.inc:51
$month
$month
Definition:
blog.inc:39
$year
$year
Definition:
blog.inc:38
code
cms.sonjara.com
cms
components
blog
modules
blog_archives.inc
Generated on Tue Mar 23 2021 15:36:12 for CMS by
1.9.1