forked from rica-carv/eforum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe_shortcode.php
More file actions
321 lines (268 loc) · 13.5 KB
/
e_shortcode.php
File metadata and controls
321 lines (268 loc) · 13.5 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php
/*
* Copyright (c) e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
*
* Featurebox shortcode batch class - shortcodes available site-wide. ie. equivalent to multiple .sc files.
*/
if (!defined('e107_INIT')) { exit; }
//e107::lan('eforum'); // English_menu.php or {LANGUAGE}_menu.php
////e107::includeLan(e_PLUGIN.'eforum/languages/'.e_LANGUAGE);
class eforum_shortcodes extends e_shortcode// must match the plugin's folder name. ie. [PLUGIN_FOLDER]_shortcodes
{
public $override = true; // when set to true, existing core/plugin shortcodes matching methods below will be overridden.
protected $forumObj;
protected $tp;
function __construct(){
/*
parent::__construct();
$this->e107 = e107::getInstance();
*/
include_once(e_PLUGIN . "forum/forum_class.php");
$this->forumObj = new e107forum();
// $this->scn = e107::getScBatch('news');
// $this->scf = e107::getScBatch('forum');
$this->tp = e107::getParser();
// $this->forumsc = e107::getScBatch('forum',TRUE);
// $this->menu['foruminfo'] = e107::getmenu()->isLoaded("foruminfo");
// O breadcrumb passou para o e_parse do eforum
}
// ###########################################
// ##### FORUM PLUGIN OVERRIDE SHORTCODES #####
// ###########################################
// Possivelmente pode sair se este pull for aprovado no github e107 https://github.com/e107inc/e107/pull/5415
function sc_post_content($parm = null)
{
$tp = e107::getParser();
$pref = e107::getPref();
$post = strip_tags($tp->toHTML(e107::getScBatch('view', 'forum')->var['post_entry'], true, 'emotes_off, no_make_clickable', '', $pref['menu_wordwrap']));
// $post = $tp->text_truncate($post, varset($this->param['nfp_characters'], 120), varset($this->param['nfp_postfix'], '...'));
$post = $tp->truncate($post, varset($this->param['nfp_characters'], (intval($parm['truncate'])??120)), varset($this->param['nfp_postfix'], '...'));
// var_dump(intval($parm['truncate'])??120);
return $post;
}
function sc_newflag($parms) // Forum template
{
$sc = e107::getScBatch('forum');
////////////////////////// MUDAR, já cá tenho o forum sem ser preciso a global..... ainda não...
// global $forum;
// var_dump ($forum);
// $forumList = $forum->forumGetForumList();
//----- $newflag_list = $forum->forumGetUnreadForums();
$newflag_list = $this->forumObj->forumGetUnreadForums();
// $newflag_list = array(1,2,3,4,5);
//var_dump ($sc->var['forum_replies']);
// var_dump ($sc->var['forum_id']);
/*
echo "<pre>";
var_dump ($newflag_list);
var_dump ($parms);
echo "</pre>";
*/
if(USER && is_array($newflag_list) && in_array($sc->var['forum_id'], $newflag_list))
{
$url = $sc->sc_lastpost(array('type'=>'url'));
return ($parms['class']?'forum_newmess':"<a href='".$url."'>".defset('IMAGE_new').'</a>');
}
elseif(empty($sc->var['forum_replies']) && defined('IMAGE_noreplies'))
{
return ($parms['class']?false:defset('IMAGE_noreplies'));
}
return ($parms['class']?false:defset('IMAGE_nonew'));
}
///
/// EM TESTE, PARA VER SE VALE A PENA TRAZER O DO TEMA
///
/*
function sc_iconkey($template, $force = false)
{
return "sdlkfldsfjklsdjfklsdfjaljflksj";
}
*/
///
/// PARA SAIR SE APROVAREM O PULL https://github.com/e107inc/e107/pull/5414
///
/* ----------------------------
function sc_quickreply()
{
// echo "<hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr>#######################<hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr><hr>";
//
global $forum, $forum_quickreply, $thread, $FORUM_VIEWTOPIC_TEMPLATE;
// Define which tinymce4 template should be used, depending if the current user is registered or a guest
if(!deftrue('e_TINYMCE_TEMPLATE'))
{
define('e_TINYMCE_TEMPLATE', (USER ? 'member' : 'public')); // allow images / videos.
}
// if($forum->checkPerm($this->var['thread_forum_id'], 'post') && $this->var['thread_active'])
if($forum->checkPerm($thread->threadInfo['thread_forum_id'], 'post') && $thread->threadInfo['thread_active'])
{
//XXX Show only on the last page??
if(!vartrue($forum_quickreply))
{
// $ajaxInsert = ($thread->pages == $thread->page || $thread->pages == 0) ? 1 : 0;
// $ajaxInsert = 1;
// echo "AJAX-INSERT=".$ajaxInsert ."(".$thread->pages." vs ".$thread->page.")";
//Orphan $frm variable???? $frm = e107::getForm();
$urlParms = array('f' => 'rp', 'id' => $this->var['thread_id'], 'post' => $this->var['thread_id']);
// $url = e107::url('forum', 'post', null, array('query' => $urlParms)); // ."?f=rp&id=".$thread->threadInfo['thread_id']."&post=".$thread->threadInfo['thread_id'];
$vars = array(
'QR_URL' => e107::url('forum', 'post', null, array('query' => $urlParms)),
'QR_TOKEN' => e_TOKEN,
'QR_AJAX' => ($thread->pages == $thread->page || $thread->pages == 0) ? 1 : 0,
'QR_THID' => $this->var['thread_id'],
'QR_THFORUMID' => $this->var['thread_forum_id']
);
$qr = e107::getPlugPref('forum', 'quickreply', 'default');
if($qr == 'default')
{
$template = e107::getParser()->parseTemplate($FORUM_VIEWTOPIC_TEMPLATE['quickreply'], true, $vars);
}
else
{
$pref = (array) e107::pref('forum');
$editor = varset($pref['editor'], null);
$editor = is_null($editor) ? 'default' : $editor;
$textarea = e107::getForm()->bbarea('post', '', 'forum', 'forum', 'medium', array('id' => 'forum-quickreply-text', 'wysiwyg' => $editor));
$template = preg_replace("~(?s)<textarea.*?</textarea>~", $textarea, $FORUM_VIEWTOPIC_TEMPLATE['quickreply']);
// return $text;
}
return e107::getParser()->parseTemplate($template, true, $vars);
// Preview should be reserved for the full 'Post reply' page. <input type='submit' name='fpreview' value='" . Preview . "' />
}
//---- else
//---- {
return $forum_quickreply;
//---- }
}
}
---------------------------------------------*/
// Customizei para os dois tipos (botões em ecras largos e lista em pequenos), até eventualmente posso customizar para tres tipos de ecrans....
// mas vai ser dificil templatizar....
// Provavelmente tenho de propor isto no gihub.....
function sc_postoptions($parms=null)
{
$sc = e107::getScBatch('view', 'forum');
// $tp = e107::getParser();
var_dump($sc->postInfo['post_thread']);
$threadID = !empty($sc->postInfo['post_thread']) ? $sc->postInfo['post_thread'] : 0;
$postID = !empty($sc->postInfo['post_id']) ? $sc->postInfo['post_id'] : 0;
$page= (varset($_GET['p']) ? (int)$_GET['p'] : 1);
// {EMAILITEM} {PRINTITEM} {REPORTIMG}{EDITIMG}{QUOTEIMG}
$textbut = "<div class='btn-toolbar d-none d-md-flex'>";
$text = '<div class="btn-group pull-right float-right float-end d-md-none">
<button class="btn btn-default btn-secondary btn-sm btn-small dropdown-toggle" data-toggle="dropdown" data-bs-toggle="dropdown">
' . LAN_FORUM_8013 . '
';
if(defined('BOOTSTRAP') && BOOTSTRAP !== 4)
{
$text .= '<span class="caret"></span>';
}
$text .= '</button><ul class="dropdown-menu pull-right dropdown-menu-end float-right text-right text-end">';
if ($parms['what']=='thread' || !$parms['what']) {
$textbut .= "<div class='btn-group me-2 justify-content-center'>";
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-default text-nowrap' role='button'" .
$temptext =" href='" . e_HTTP . "print.php?plugin:forum." . $threadID . "'>" . $this->tp->toGlyph('fa-print') . LAN_FORUM_2045 . "</a>";
$text .="<a class='dropdown-item'" . $temptext ."</li>"; // FIXME
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-default text-nowrap' role='button'" .
// O sc {GLYPH=edit} nem squer dá aqui... tenho de chamar a função...
$temptext = " href='" . e_HTTP . "email.php?plugin:forum." . $threadID . "'>" . $this->tp->toGlyph('fa-envelope') . LAN_FORUM_2044 . "</a>";
$text .= "<a class='dropdown-item'" . $temptext ."</li>";
$textbut .= "</div>";
}
if ($parms['what']=='post' || !$parms['what']) {
$textbut .= "<div class='btn-group justify-content-center'>";
if(USER) // Report
{
$urlReport = e107::url('forum', 'post') . "?f=report&id=" . $threadID . "&post=" . $postID;
// $urlReport = $this->e107->url->create('forum/thread/report', "id={$threadID}&post={$postID}");
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-warning text-nowrap' role='button'" .
$temptext = " href='" . $urlReport . "'>" . $this->tp->toGlyph('fa-flag') . LAN_FORUM_2046 . "</a>";
$text .= "<a class='dropdown-item'".$temptext."</li>";
}
// Edit
if((USER && isset($sc->postInfo['post_user']) && $sc->postInfo['post_user'] == USERID && $sc->var['thread_active']))
{
//$url = e107::url('forum', 'post') . "?f=edit&id=" . $threadID . "&post=" . $postID;
$url = e107::url('forum', 'post') . "?f=edit&id=" . $threadID . "&post=" . $postID . "&p=".$page;
//$url = e107::getUrl()->create('forum/thread/edit', array('id' => $threadID, 'post'=>$postID));
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-default text-nowrap' role='button'" .
$temptext = " href='" . $url . "'>" . $this->tp->toGlyph('fa-edit') . LAN_EDIT . "</a>";
$text .= "<a class='dropdown-item'".$temptext."</li>";
}
// Delete own post, if it is the last in the thread
if($sc->thisIsTheLastPost && USER && $sc->thread->threadInfo['thread_lastuser'] == USERID && !defset('MODERATOR'))
{
/* only show delete button when post is not the initial post of the topic
* AND if this post is the last post in the thread */
if($sc->var['thread_active'] && empty($sc->postInfo['thread_start']))
{
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-danger text-nowrap' role='button'" .
$temptext = " href='" . e_REQUEST_URI . "' data-forum-action='deletepost' data-confirm='" . LAN_JSCONFIRM . "' data-forum-post='" . $postID . "'>" . $this->tp->toGlyph('fa-trash') . LAN_DELETE . "</a>";
$text .= "<a class='dropdown-item'".$temptext."</li>";
}
}
if(isset($sc->postInfo['post_forum']) && $this->forumObj->checkperm($sc->postInfo['post_forum'], 'post'))
{
$url = e107::url('forum', 'post') . "?f=quote&id=" . $threadID . "&post=" . $postID;
//$url = e107::getUrl()->create('forum/thread/quote', array('id' => $threadID, 'post'=>$postID));
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-default text-nowrap' role='button'" .
$temptext = " href='" . $url . "'>" . $this->tp->toGlyph('fa-share-alt') . LAN_FORUM_2041 . "</a>";
$text .= "<a class='dropdown-item'".$temptext."</li>";
// $text .= "<li class='text-right float-right'><a href='".e107::getUrl()->create('forum/thread/quote', array('id' => $postID))."'>".LAN_FORUM_2041." ".$this->tp->toGlyph('share-alt')."</a></li>";
}
$textbut .= "</div><div class='btn-group me-2 justify-content-center'>";
if(defset('MODERATOR'))
{
$textbut .= "</div><div class='btn-group justify-content-center'>";
$text .= "<li role='presentation' class='divider'><hr class='dropdown-divider'></li>";
$type = ($sc->postInfo['thread_start']) ? 'thread' : 'Post';
// print_a($sc->postInfo);
// Edit
if((USER && isset($sc->postInfo['post_user']) && $sc->postInfo['post_user'] != USERID && $sc->var['thread_active']))
{
//$url = e107::url('forum', 'post') . "?f=edit&id=" . $threadID . "&post=" . $postID;
$url = e107::url('forum', 'post') . "?f=edit&id=" . $threadID . "&post=" . $postID . "&p=".$page;
// $url = e107::getUrl()->create('forum/thread/edit', array('id' => $threadID, 'post'=>$postID));
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-default text-nowrap' role='button'" .
$temptext = " href='" . $url . "'>" . $this->tp->toGlyph('fa-edit') . LAN_EDIT . "</a>";
$text .= "<a class='dropdown-item'" . $temptext . "</li>";
}
// only show delete button when post is not the initial post of the topic
// if(!$this->forum->threadDetermineInitialPost($postID))
if(empty($sc->postInfo['thread_start']))
{
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-danger text-nowrap' role='button'" .
$temptext = " href='" . e_REQUEST_URI . "' data-forum-action='deletepost' data-confirm='" . LAN_JSCONFIRM . "' data-forum-post='" . $postID . "'>" . $this->tp->toGlyph('fa-trash') . LAN_DELETE . "</a>";
$text .= "<a class='dropdown-item'" . $temptext . "</li>";
}
// Move
if($type == 'thread')
{
$url = e107::url('forum', 'move', array('thread_id' => $threadID));
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-default text-nowrap' role='button'" .
$temptext = " href='" . $url . "'>" . $this->tp->toGlyph('fa-arrows') . LAN_FORUM_2042 . "</a>";
$text .= "<a class='dropdown-item'" . $temptext . "</li>";
}
elseif(e_DEVELOPER === true) //TODO
{
$text .= "<li class='text-right text-end float-right'>";
$textbut .= "<a class='btn btn-default text-nowrap' role='button'" .
$temptext = " href='" . e107::url('forum', 'split', array('thread_id' => $threadID, 'post_id' => $postID)) . "'>" . $this->tp->toGlyph('fa-cut') . LAN_FORUM_2043 . "</a>";
$text .= "<a class='dropdown-item'" . $temptext . "</li>";
}
$textbut .= '</div>';
}
}
$textbut .= '</div>';
$text .= '</ul></div>';
return $textbut.$text;
}
}