forked from XoopsModules25x/adslight
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreplies.php
160 lines (144 loc) · 7.54 KB
/
replies.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
<?php declare(strict_types=1);
/*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
*
* 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.
*/
/**
* @copyright XOOPS Project (https://xoops.org)
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
* @author XOOPS Development Team
* @author Pascal Le Boustouller: original author (pascal.e-xoops@perso-search.com)
* @author Luc Bizet (www.frxoops.org)
* @author jlm69 (www.jlmzone.com)
* @author mamba (www.xoops.org)
*/
use Xmf\Request;
use XoopsModules\Adslight\{
Tree
};
/** @var Helper $helper */
require_once __DIR__ . '/header.php';
global $xoopsModule, $xoopsDB, $xoopsConfig, $xoTheme;
$myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
$moduleId = $xoopsModule->getVar('mid');
$groups = $GLOBALS['xoopsUser'] instanceof \XoopsUser ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
/** @var \XoopsGroupPermHandler $grouppermHandler */
$grouppermHandler = xoops_getHandler('groupperm');
$perm_itemid = Request::getInt('item_id', 0, 'POST');
//If no access
if (!$grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $moduleId)) {
$helper->redirect('index.php', 3, _NOPERM);
}
$mytree = new Tree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid');
$lid = Request::getInt('lid', 0, 'GET');
$GLOBALS['xoopsOption']['template_main'] = 'adslight_replies.tpl';
require_once XOOPS_ROOT_PATH . '/header.php';
$GLOBALS['xoopsTpl']->assign('nav_main', '<a href="index.php">' . _ADSLIGHT_MAIN . '</a>');
$show = 1;
$min = Request::getInt('min', 0, 'GET');
if (!isset($max)) {
$max = $min + $show;
}
$orderby = 'date_created Desc';
$GLOBALS['xoopsTpl']->assign('lid', $lid);
$sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('adslight_replies') . ' WHERE lid=' . $xoopsDB->escape($lid);
$countresult = $xoopsDB->query($sql);
if (!$xoopsDB->isResultSet($countresult)) {
\trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
}
[$trow] = $xoopsDB->fetchRow($countresult);
$trows = $trow;
$pagenav = '';
if ($trows < '1') {
$GLOBALS['xoopsTpl']->assign('has_replies', false);
$GLOBALS['xoopsTpl']->assign('no_more_replies', _ADSLIGHT_NO_REPLIES);
}
if ($trows > '0') {
$GLOBALS['xoopsTpl']->assign('has_replies', true);
$GLOBALS['xoopsTpl']->assign('last_head', _ADSLIGHT_THE . ' ' . $helper->getConfig('adslight_newcount') . ' ' . _ADSLIGHT_LASTADD);
$GLOBALS['xoopsTpl']->assign('last_head_title', _ADSLIGHT_TITLE);
$GLOBALS['xoopsTpl']->assign('last_head_price', _ADSLIGHT_PRICE);
$GLOBALS['xoopsTpl']->assign('last_head_date', _ADSLIGHT_DATE);
$GLOBALS['xoopsTpl']->assign('last_head_local', _ADSLIGHT_LOCAL2);
$GLOBALS['xoopsTpl']->assign('last_head_views', _ADSLIGHT_VIEW);
$GLOBALS['xoopsTpl']->assign('last_head_photo', _ADSLIGHT_PHOTO);
$GLOBALS['xoopsTpl']->assign('min', $min);
$sql = 'SELECT r_lid, lid, title, date_created, submitter, message, tele, email, r_usid FROM ' . $xoopsDB->prefix('adslight_replies') . ' WHERE lid=' . $xoopsDB->escape($lid) . " ORDER BY {$orderby}";
$result = $xoopsDB->query($sql, $show, $min);
if (!$xoopsDB->isResultSet($result)) {
\trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR);
}
if ($trows > '1') {
$GLOBALS['xoopsTpl']->assign('has_replies', true);
$GLOBALS['xoopsTpl']->assign('show_nav', true);
$GLOBALS['xoopsTpl']->assign('lang_sortby', _ADSLIGHT_SORTBY);
$GLOBALS['xoopsTpl']->assign('lang_title', _ADSLIGHT_TITLE);
$GLOBALS['xoopsTpl']->assign('lang_titleatoz', _ADSLIGHT_TITLEATOZ);
$GLOBALS['xoopsTpl']->assign('lang_titleztoa', _ADSLIGHT_TITLEZTOA);
$GLOBALS['xoopsTpl']->assign('lang_date', _ADSLIGHT_DATE);
$GLOBALS['xoopsTpl']->assign('lang_dateold', _ADSLIGHT_DATEOLD);
$GLOBALS['xoopsTpl']->assign('lang_datenew', _ADSLIGHT_DATENEW);
$GLOBALS['xoopsTpl']->assign('lang_popularity', _ADSLIGHT_POPULARITY);
$GLOBALS['xoopsTpl']->assign('lang_popularityleast', _ADSLIGHT_POPULARITYLTOM);
$GLOBALS['xoopsTpl']->assign('lang_popularitymost', _ADSLIGHT_POPULARITYMTOL);
$GLOBALS['xoopsTpl']->assign('lang_cursortedby', _ADSLIGHT_CURSORTEDBY . $orderby);
}
while ([$r_lid, $lid, $title, $date_created, $submitter, $message, $tele, $email, $r_usid] = $xoopsDB->fetchRow($result)) {
$useroffset = '';
if ($GLOBALS['xoopsUser']) {
$timezone = $GLOBALS['xoopsUser']->timezone();
$useroffset = isset($timezone) ? $GLOBALS['xoopsUser']->timezone() : $xoopsConfig['default_TZ'];
}
$GLOBALS['xoopsTpl']->assign('submitter', " <a href='" . XOOPS_URL . "/userinfo.php?uid={$r_usid}'>{$submitter}</a>");
$date_created = ($useroffset * 3600) + $date_created;
$date_created = formatTimestamp($date_created, 's');
$GLOBALS['xoopsTpl']->assign('title', "<a href='viewads.php?lid={$lid}'>{$title}</a>");
$GLOBALS['xoopsTpl']->assign('title_head', _ADSLIGHT_REPLY_TITLE);
$GLOBALS['xoopsTpl']->assign('date_head', _ADSLIGHT_REPLIED_ON);
$GLOBALS['xoopsTpl']->assign('submitter_head', _ADSLIGHT_REPLIED_BY);
$GLOBALS['xoopsTpl']->assign('message_head', _ADSLIGHT_REPLY_MESSAGE);
$GLOBALS['xoopsTpl']->assign('email_head', _ADSLIGHT_EMAIL);
$GLOBALS['xoopsTpl']->assign('tele_head', _ADSLIGHT_TEL);
$GLOBALS['xoopsTpl']->assign('email', "<a href ='mailto:{$email}'>{$email}</a>");
$GLOBALS['xoopsTpl']->assign('delete_reply', "<a href='modify.php?op=DelReply&r_lid={$r_lid}'>" . _ADSLIGHT_DELETE_REPLY . '</a>');
$GLOBALS['xoopsTpl']->append('items', [
'id' => $lid,
'title' => htmlspecialchars($title, ENT_QUOTES | ENT_HTML5),
'date_created' => $date_created,
'message' => $myts->displayTarea($message),
'tele' => htmlspecialchars($tele, ENT_QUOTES | ENT_HTML5),
]);
}
$lid = Request::getInt('lid', 0, 'GET');
//Calculates how many pages exist. Which page one should be on, etc...
$linkpages = ceil($trows / $show);
//Page Numbering
if (1 !== (int)$linkpages && 0 !== (int)$linkpages) {
$prev = $min - $show;
if ($prev >= 0) {
$pagenav .= "<a href='replies.php?lid={$lid}&min={$prev}&show={$show}'><strong><u>«</u></strong></a> ";
}
$counter = 1;
$currentpage = $max / $show;
while ($counter <= $linkpages) {
$mintemp = ($show * $counter) - $show;
if ($counter === $currentpage) {
$pagenav .= "<strong>({$counter})</strong> ";
} else {
$pagenav .= "<a href='replies.php?lid={$lid}&min={$mintemp}&show={$show}'>{$counter}</a> ";
}
++$counter;
}
if ($trows > $max) {
$pagenav .= "<a href='replies.php?lid={$lid}&min={$max}&show={$show}'>";
$pagenav .= '<strong><u>»</u></strong></a>';
}
$GLOBALS['xoopsTpl']->assign('nav_page', '<strong>' . _ADSLIGHT_REPLY . "</strong> {$pagenav}");
}
}
require_once XOOPS_ROOT_PATH . '/footer.php';