forked from EQdkpPlus/plugin-shoutbox
/
archive.php
170 lines (146 loc) · 6.2 KB
/
archive.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
<?php
/* Project: EQdkp-Plus
* Package: Shoutbox Plugin
* Link: http://eqdkp-plus.eu
*
* Copyright (C) 2006-2015 EQdkp-Plus Developer Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// EQdkp required files/vars
define('EQDKP_INC', true);
define('PLUGIN', 'shoutbox');
$eqdkp_root_path = './../../';
include_once('includes/common.php');
/*+----------------------------------------------------------------------------
| ShoutboxArchive
+--------------------------------------------------------------------------*/
class ShoutboxArchive extends page_generic{
/**
* Constructor
*/
public function __construct(){
// plugin installed?
if (!$this->pm->check('shoutbox', PLUGIN_INSTALLED))
message_die($this->user->lang('sb_plugin_not_installed'));
$handler = array(
'sb_delete' => array('process' => 'delete', 'csrf' => true, 'check' => 'a_shoutbox_delete'),
);
parent::__construct('u_shoutbox_view', $handler);
$this->process();
}
/**
* delete
* Delete entries
*/
public function delete(){
$messages = array();
$rc = register('ShoutboxClass')->deleteShoutboxEntry($this->in->get('delete_id', 0));
if ($rc !== false)
$messages[] = $this->user->lang('sb_delete_success');
$this->display($messages);
}
/**
* display
* Display the page
*
* @param array $messages Array of Messages to output
*/
public function display($messages=array()){
// -- Messages ------------------------------------------------------------
if ($messages){
foreach($messages as $name)
$this->core->message($name, $this->user->lang('shoutbox'), 'green');
}
// -- get all shoutbox id's -----------------------------------------------
$shoutbox_ids = $this->pdh->get('shoutbox', 'id_list', array());
$shoutbox_out = array();
// -- build 2D array with [year][month] -----------------------------------
$date_array = array();
foreach ($shoutbox_ids as $shoutbox_id){
$shoutbox_date = $this->pdh->get('shoutbox', 'date', array($shoutbox_id));
$shoutbox_date_year = $this->time->date('Y', $shoutbox_date);
$shoutbox_date_month = $this->time->date('m', $shoutbox_date);
$date_array[$shoutbox_date_year][$shoutbox_date_month][] = $shoutbox_id;
}
// -- output date select on left side -------------------------------------
foreach ($date_array as $year => $months){
$this->tpl->assign_block_vars('year_row', array(
'YEAR' => $year
));
foreach ($months as $month => $ids){
$this->tpl->assign_block_vars('year_row.month_row', array(
'MONTH' => $this->time->date('F', $this->time->mktime(0, 0, 0, $month, 1, $year)),
'COUNT' => count($ids),
'LINK_VIEW' => $this->root_path.'plugins/shoutbox/archive.php'.$this->SID.'&year='.$year.'&month='.$month
));
}
}
// -- year/month select? --------------------------------------------------
$page_title = '';
if ($this->in->exists('year') && $this->in->exists('month')){
// add all shoutbox entries within date/month to the output array
$shoutbox_out = $date_array[$this->in->get('year')][$this->in->get('month')];
$page_title = $this->time->date('F', $this->time->mktime(0, 0, 0, $this->in->get('month'), 1, $this->in->get('year'))).' '.$this->in->get('year');
}
// -- id? -----------------------------------------------------------------
else if ($this->in->exists('id')){
$shoutbox_out[] = $this->in->get('id');
}
// -- last month ----------------------------------------------------------
else if (count($shoutbox_ids) > 0){
// show the last month only
$shoutbox_date = $this->pdh->get('shoutbox', 'date', array($shoutbox_ids[0]));
$shoutbox_date_year = $this->time->date('Y', $shoutbox_date);
$shoutbox_date_month = $this->time->date('m', $shoutbox_date);
$shoutbox_out = $date_array[$shoutbox_date_year][$shoutbox_date_month];
$page_title = $this->time->date('F', $this->time->mktime(0, 0, 0, $shoutbox_date_month, 1, $shoutbox_date_year)).' '.$shoutbox_date_year;
}
// -- output filtered data ------------------------------------------------
foreach ($shoutbox_out as $shoutbox_id){
// show a new date row if it's not the same as the last one
$shoutbox_date = $this->pdh->get('shoutbox', 'date', array($shoutbox_id));
// output
$this->tpl->assign_block_vars('shoutbox_row', array(
'ID' => $shoutbox_id,
'NAME' => $this->pdh->geth('shoutbox', 'usermembername', array($shoutbox_id)),
'USERAVATAR' => $this->pdh->geth('shoutbox', 'useravatar', array($shoutbox_id)),
'DATE' => $this->time->date($this->user->style['date'], $shoutbox_date),
'TIME' => $this->time->date($this->user->style['time'], $shoutbox_date),
'MESSAGE' => $this->pdh->geth('shoutbox', 'text', array($shoutbox_id)),
'S_AVATAR' => ($this->pdh->geth('shoutbox', 'useravatar', array($shoutbox_id)) !== false),
));
}
// -- Template ----------------------------------------------------------------
$this->tpl->assign_vars(array(
// Form
'S_YEAR' => $this->in->get('year', ''),
'S_MONTH' => $this->in->get('month', ''),
'S_SB_SEARCH' => $this->in->get('search', ''),
'S_COUNT' => count($shoutbox_out),
'S_PAGE_TITLE' => ($page_title != '') ? '» '.$page_title : '',
// Admin
'CAN_DELETE' => $this->user->check_auth('a_shoutbox_delete', false),
));
// -- EQDKP ---------------------------------------------------------------
$this->core->set_vars(array (
'page_title' => $this->user->lang('sb_shoutbox_archive').' '.$page_title,
'template_path' => $this->pm->get_data('shoutbox', 'template_path'),
'template_file' => 'archive.html',
'display' => true
));
}
}
register('ShoutboxArchive');
?>