/
matrix_blog.php
199 lines (168 loc) · 4.93 KB
/
matrix_blog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/* The Matrix Blog
*/
# thisfile
$thisfile = basename(__FILE__, ".php");
# language
i18n_merge($thisfile) || i18n_merge($thisfile, 'en_US');
# requires
require_once(GSPLUGINPATH.$thisfile.'/php/class.php');
# class instantiation
$mblog = new MatrixBlog; // instantiate class
# register plugin
register_plugin(
$mblog->info('id'), // id
$mblog->info('title'), // name
$mblog->info('version'), // version
$mblog->info('author'), // author
$mblog->info('url'), // url
$mblog->info('desc'), // description
$mblog->info('page'), // page type - on which admin tab to display
array($mblog, 'admin') // administration function
);
# activate actions/filters
# front-end
add_action('error-404', array($mblog, 'display')); // display for plugin
# back-end
add_action($mblog->info('page').'-sidebar', 'createSideMenu' , array($mblog->info('id'), $mblog->info('sidebar'))); // sidebar link
add_action('search-index', array($mblog, 'searchIndex'));
add_filter('search-item', array($mblog, 'searchItem'));
add_filter('search-display', array($mblog, 'searchDisplay'));
# public functions
# get config
function mblog_config($prop) {
global $mblog;
$config = $mblog->getConfig();
if (isset($config[$prop])) return $config[$prop];
else return null;
}
# breadcrumbs
function mblog_show_breadcrumbs($showHome=false, $delim=' • ') {
global $mblog;
echo $mblog->getBreadcrumbs($showHome, $delim);
}
# get image url
function mblog_get_img_url($img) {
global $mblog;
echo $mblog->getImageURL($img['image']);
}
# get thumb url
function mblog_get_thumb_url($thumb) {
global $mblog;
echo $mblog->getThumbURL($thumb['image']);
}
# get entry field properties
function mblog_get_field($entry, $field) {
if (isset($entry[$field])) echo $entry[$field];
}
# get field date
function mblog_get_field_date($entry, $field, $format='r') {
if (isset($entry[$field])) echo date($format, strtotime($entry[$field]));
}
# get entry url
function mblog_get_entry_url($entry) {
global $mblog;
echo $mblog->getEntryURL($entry);
}
# return field properties
function mblog_return_field($entry, $field) {
if (isset($entry[$field])) return $entry[$field];
}
# get entry languages
function mblog_get_entry_langs($entry) {
global $mblog;
$mblog->getEntryLangs($entry['slug']);
}
# get tags
function mblog_get_tags($entry, $delim) {
global $mblog;
$mblog->getTags($entry['tags'], $delim);
}
# get category
function mblog_get_category($entry) {
global $mblog;
echo $mblog->getCategory($entry['category']);
}
# get category URL
function mblog_get_category_url($entry) {
global $mblog;
echo $mblog->getCategoryURL($entry['category']);
}
# get author name
function mblog_get_author_name($entry) {
global $mblog;
if (isset ($entry['author'])) {
echo $mblog->getAuthorName($entry['author']);
}
elseif (isset($entry['USR'])) {
echo $mblog->getAuthorName($entry['USR']);
}
else return null;
}
# get author url
function mblog_get_author_url($entry) {
global $mblog;
if (isset ($entry['author'])) {
echo $mblog->getAuthorURL($entry['author']);
}
elseif (isset($entry['USR'])) {
echo $mblog->getAuthorURL($entry['USR']);
}
else return null;
}
# get author email
function mblog_get_author_email($author) {
global $mblog;
if (isset ($author['EMAIL'])) {
echo $author['EMAIL'];
}
else return null;
}
# get author bio
function mblog_get_author_bio($author) {
global $mblog;
$mblog->getAuthorBio($author);
}
# get latest entries
function mblog_get_author_latest($author, $max=5) {
global $mblog;
$mblog->showLatestEntries($author['USR'], $max);
}
# search form
function mblog_show_search_form() {
global $mblog;
$mblog->searchForm();
}
# archive
function mblog_show_archive() {
global $mblog;
$mblog->showArchiveMenu();
}
# categories dropdown
function mblog_show_categories() {
global $mblog;
$mblog->showCategoriesMenu();
}
# show comment field
function mblog_get_comment_field($comment, $field) {
if (isset($comment[$field])) echo $comment[$field];
}
# get gravatar
function mblog_get_comment_gravatar($comment) {
global $mblog;
echo $mblog->getGravatar($comment['email']);
}
# show latest comments
function mblog_get_entry_comments($entry) {
global $mblog;
$mblog->displayComments($entry['id']);
}
# show latest comments
function mblog_show_latest_comments($max=5) {
global $mblog;
$mblog->showLatestComments($max);
}
# show sidebar
function mblog_show_sidebar() {
include(GSPLUGINPATH.MatrixBlog::FILE.'/php/display/sidebar.php');
}