-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleblog.php
More file actions
159 lines (151 loc) · 5.9 KB
/
simpleblog.php
File metadata and controls
159 lines (151 loc) · 5.9 KB
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
<?php
/**
* Module Name: Simple Blog
* Module ID: simpleblogposts
* Description: Lists the 5 most recent SimpleBlog posts with a link to add new.
* Version: 1.0
* Default W: 8
* Default H: 4
*/
if (!defined('IN_GS')) { die('You cannot load this page directly.'); }
// Add $i18n_m for i18n lang files in Modules
$i18n_m = dash_module_i18n('simpleblog');
$uid = 'sbp_' . substr(md5(__FILE__), 0, 6);
global $live_plugins;
$posts = array();
$plugin_ok = function_exists('blog_init_db');
$db_file = defined('GSDATAOTHERPATH') ? GSDATAOTHERPATH . 'blog.db' : '';
$db_ok = $plugin_ok && $db_file && file_exists($db_file);
if ($db_ok) {
try {
$db = new SQLite3($db_file, SQLITE3_OPEN_READONLY);
$res = $db->query(
"SELECT id, title, slug, date, published
FROM posts
ORDER BY date DESC
LIMIT 5"
);
while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$posts[] = $row;
}
$db->close();
} catch (Exception $e) {
$db_ok = false;
}
}
?>
<style>
#<?php echo $uid ?> .sb-table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
#<?php echo $uid ?> .sb-table th {
text-align: left;
padding: 5px 8px;
border-bottom: 2px solid #eee;
color: #888;
font-weight: 600;
white-space: nowrap;
}
#<?php echo $uid ?> .sb-table td {
padding: 5px 8px;
border-bottom: 1px solid #f3f3f3;
vertical-align: middle;
}
#<?php echo $uid ?> .sb-table tr:last-child td { border-bottom: none; }
#<?php echo $uid ?> .sb-table tr:hover td { background: #fafafa; }
#<?php echo $uid ?> .sb-title {
font-weight: 500;
color: #333;
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#<?php echo $uid ?> .sb-date { color: #aaa; white-space: nowrap; }
#<?php echo $uid ?> .sb-actions { white-space: nowrap; }
#<?php echo $uid ?> .sb-btn {
display: inline-block;
padding: 4px 6px;
border-radius: 4px;
font-size: 11px;
text-decoration: none;
margin-left: 4px;
border: 1px solid transparent;
color: #fff;
}
#<?php echo $uid ?> .sb-btn-edit { background: #5EBD3E; }
#<?php echo $uid ?> .sb-btn-edit:hover { background: #4B9732; }
#<?php echo $uid ?> .sb-btn-new { background: #4a90d9; font-size: 12px; padding: 4px 10px; }
#<?php echo $uid ?> .sb-btn-new:hover { background: #357abd; }
#<?php echo $uid ?> .sb-badge {
display: inline-block;
padding: 2px 6px;
border-radius: 10px;
font-size: 10px;
font-weight: 600;
}
#<?php echo $uid ?> .sb-badge-pub { background: #d4edda; color: #28a745; }
#<?php echo $uid ?> .sb-badge-draft { background: #FFFF99; color: #CDA400; }
#<?php echo $uid ?> .sb-empty { color: #bbb; font-style: italic; text-align: center; padding: 16px; }
#<?php echo $uid ?> .sb-missing {
color: #856404;
background: #fff3cd;
border: 1px solid #ffeeba;
border-radius: 6px;
padding: 10px 12px;
font-size: 13px;
}
#<?php echo $uid ?> .sb-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
#<?php echo $uid ?> .sb-header h3 { margin: 0; }
</style>
<div id="<?php echo $uid ?>">
<div class="sb-header">
<h3><svg xmlns="http://www.w3.org/2000/svg" style="vertical-align:middle;" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M4 21q-.825 0-1.412-.587T2 19V3l1.675 1.675L5.325 3L7 4.675L8.675 3l1.65 1.675L12 3l1.675 1.675L15.325 3L17 4.675L18.675 3l1.65 1.675L22 3v16q0 .825-.587 1.413T20 21zm0-2h7v-6H4zm9 0h7v-2h-7zm0-4h7v-2h-7zm-9-4h16V8H4z"/></svg> <?php echo $i18n_m('sb_lang_Simple_Blog'); ?></h3>
<a class="sb-btn sb-btn-new" href="load.php?id=simpleBlog&blog_admin&tab=add_post">+ <?php echo $i18n_m('sb_lang_New_Post'); ?></a>
</div>
<?php if (!$plugin_ok): ?>
<p class="sb-missing">⚠ <?php echo $i18n_m('sb_lang_plugin_not_active'); ?>.</p>
<?php elseif (!$db_ok): ?>
<p class="sb-missing">⚠ <?php echo $i18n_m('sb_lang_no_db_found'); ?>.</p>
<?php elseif (empty($posts)): ?>
<p class="sb-empty"><?php echo $i18n_m('sb_lang_No_posts_found'); ?>.</p>
<?php else: ?>
<table class="sb-table">
<tr>
<th><?php echo $i18n_m('sb_lang_Title'); ?></th>
<th><?php echo $i18n_m('sb_lang_Date'); ?></th>
<th><?php echo $i18n_m('sb_lang_Status'); ?></th>
<th style="text-align:center;"><?php echo $i18n_m('sb_lang_Action'); ?></th>
</tr>
<?php foreach ($posts as $post):
$title = htmlspecialchars($post['title']);
$date = date('Y-m-d', $post['date']);
$editUrl = 'load.php?id=simpleBlog&blog_admin&tab=add_post&edit=' . (int)$post['id'];
?>
<tr>
<td class="sb-title" title="<?php echo $title; ?>"><?php echo $title; ?></td>
<td class="sb-date"><?php echo $date; ?></td>
<td>
<?php if ($post['published']): ?>
<span class="sb-badge sb-badge-pub"><?php echo $i18n_m('sb_lang_Published'); ?></span>
<?php else: ?>
<span class="sb-badge sb-badge-draft"><?php echo $i18n_m('sb_lang_Draft'); ?></span>
<?php endif; ?>
</td>
<td class="sb-actions" style="text-align:center;">
<a class="sb-btn sb-btn-edit" href="<?php echo $editUrl; ?>" title="Edit">
<svg xmlns="http://www.w3.org/2000/svg" style="vertical-align:middle;" width="14" height="14" viewBox="0 0 16 16"><rect width="16" height="16" fill="none"/><path fill="#fff" d="M10.529 1.764a2.621 2.621 0 1 1 3.707 3.707l-.779.779L9.75 2.543zM9.043 3.25L2.657 9.636a2.96 2.96 0 0 0-.772 1.354l-.87 3.386a.5.5 0 0 0 .61.608l3.385-.869a2.95 2.95 0 0 0 1.354-.772l6.386-6.386z"/></svg>
</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>