1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') or die('Illegal call');
17:
18:
19: if (cRegistry::isBackendEditMode()) {
20: echo "CMS_USERFORUM[2]";
21: }
22:
23: 24: 25: 26:
27: class UserForumArticle {
28:
29: 30: 31: 32:
33: protected $_qoute = true;
34:
35: 36: 37: 38:
39: protected $_messageText = '';
40:
41: 42: 43: 44:
45: protected $_generate = true;
46:
47: 48: 49: 50:
51: protected $_allowDeleting;
52:
53: 54: 55: 56:
57: protected $_userLoggedIn;
58:
59: 60: 61: 62:
63: protected $_allowedToEditForum;
64:
65: 66: 67: 68:
69: protected $_modMode;
70:
71: 72: 73: 74: 75:
76: protected $_tpl;
77:
78: 79: 80: 81: 82:
83: protected $_currentEmail;
84:
85: 86: 87: 88: 89:
90: protected $_currentRealname;
91:
92: 93: 94: 95: 96: 97: 98:
99: protected $_counter;
100:
101: 102: 103: 104: 105:
106: protected $_idart;
107:
108: 109: 110: 111: 112:
113: protected $_idcat;
114:
115: 116: 117: 118: 119:
120: protected $_idlang;
121:
122: 123: 124: 125: 126:
127: protected $_userid;
128:
129: 130: 131: 132: 133:
134: protected $_collection;
135:
136: 137: 138:
139: public function __construct() {
140: $this->_tpl = cSmartyFrontend::getInstance();
141: $this->_messageText = '';
142: $this->_generate = true;
143: $this->_idart = cRegistry::getArticleId();
144: $this->_idcat = cRegistry::getCategoryId();
145: $this->_idlang = cRegistry::getLanguageId();
146: $this->_collection = new ArticleForumCollection();
147: $this->_qoute = ($this->_collection->getQuoteState($this->_idart));
148: $this->_modMode = ($this->_collection->getModModeActive($this->_idart));
149: }
150:
151: 152: 153: 154: 155:
156: public function receiveData(array $request) {
157: $this->_checkCookie();
158:
159: $auth = cRegistry::getAuth();
160: $this->_allowDeleting = (stristr($auth->auth['perm'], 'admin') === FALSE) ? false : true;
161: $bAllowAnonymousforum = (getEffectiveSetting('user_forum', 'allow_anonymous_forum', '1') == '1') ? true : false;
162:
163: $this->_getUser($auth->auth['uid']);
164: $this->_allowedToEditForum = ($bAllowAnonymousforum || $this->_userLoggedIn && !$bAllowAnonymousforum) ? true : false;
165:
166: switch ($_REQUEST['user_forum_action']) {
167:
168: case 'like_forum':
169: $this->_incrementLike();
170: $this->_listForum();
171: break;
172:
173: case 'dislike_forum':
174: $this->_incrementDislike();
175: $this->_listForum();
176: break;
177:
178: case 'new_forum':
179: $this->_newEntry();
180: break;
181:
182: case 'save_new_forum':
183: if ($this->_modMode && $this->_saveForum()) {
184: echo '<br />';
185: echo mi18n("FEEDBACK");
186: }
187: $this->_listForum();
188: break;
189: default:
190: $this->_listForum();
191: break;
192: }
193: }
194:
195: 196: 197: 198:
199: private function _getUser($userid) {
200: if (($userid != '') && ($userid != 'nobody')) {
201: $this->_userLoggedIn = true;
202: $user = $this->_collection->selectUser($userid);
203: $this->_currentEmail = $user['email'];
204: $this->_currentRealname = $user['realname'];
205: } else {
206: $this->_userLoggedIn = false;
207: $this->_userid = '';
208: }
209: }
210:
211: 212: 213:
214: private function _incrementLike() {
215: $form_id = (int) $_REQUEST['user_forum_id'];
216: if ($form_id > 0 && $this->_counter) {
217: $this->_collection->incrementLike($form_id);
218: }
219: }
220:
221: 222: 223:
224: private function _incrementDislike() {
225: $form_id = (int) $_REQUEST['user_forum_id'];
226: if ($form_id > 0 && $this->_counter) {
227: $this->_collection->incrementDislike($form_id);
228: }
229: }
230:
231: 232: 233:
234: private function _saveForum() {
235: $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
236:
237:
238: if ($this->_allowedToEditForum) {
239:
240: $this->_userid = $_REQUEST['userid'];
241: $this->_allowDeleting = $_REQUEST['deleting'];
242: $contenido = $_REQUEST['contenido'];
243: $bInputOK = true;
244:
245: $email = trim($_REQUEST['email']);
246: $realname = trim($_REQUEST['realname']);
247: $forum = trim($_REQUEST['forum']);
248: $parent = (int) $_REQUEST['user_forum_parent'];
249: $forum_quote = trim($_REQUEST['forum_quote']);
250:
251: $this->_getUser($this->_userid);
252:
253:
254: if ($this->_userLoggedIn) {
255: if ($forum == '') {
256: $this->_messageText .= mi18n("enterYourArticle") . '<br />';
257: $bInputOK = false;
258: }
259: } else {
260:
261: if ($email == '') {
262: $this->_messageText .= mi18n("enterYourMail") . '<br />';
263: $bInputOK = false;
264: }
265: if ($email != '') {
266: if (!preg_match($regex, $email)) {
267: $this->_messageText .= mi18n("enterValidMail") . '<br />';
268: $bInputOK = false;
269: }
270: }
271:
272: if ($realname == '') {
273: $this->_messageText .= mi18n("enterYourName") . '<br />';
274: $bInputOK = false;
275: }
276:
277: if ($forum == '') {
278: $this->_messageText .= mi18n("enterYourArticle") . '<br />';
279: $bInputOK = false;
280: }
281: }
282:
283: if ($bInputOK) {
284:
285: $ar = array(
286: 'NEWENTRY' => mi18n("NEWENTRY"),
287: 'NEWENTRYTEXT' => mi18n("NEWENTRYTEXT"),
288: 'COMMENT' => mi18n("COMMENT"),
289: 'USER' => mi18n("USER"),
290: 'EMAIL' => mi18n("EMAILADR"),
291: 'ARTICLE' => mi18n("INARTICLE")
292: );
293: $this->_collection->languageSync($ar);
294:
295: $this->_collection->insertValues($parent, $this->_idart, $this->_idcat, $this->_idlang, $this->_userid, $email, $realname, $forum, $forum_quote);
296:
297: $this->_messageText .= mi18n("yourArticleSaved");
298: } else {
299:
300:
301: $this->_tpl->assign('MESSAGE', $this->_messageText);
302:
303: if ($this->_userLoggedIn) {
304:
305: $this->_currentEmail = conHtmlSpecialChars($this->_currentEmail);
306: $this->_currentRealname = conHtmlSpecialChars($this->_currentRealname);
307: $this->_tpl->assign('INPUT_EMAIL', $this->_currentEmail . "<input type=\"hidden\" name=\"email\" value=\"$this->_currentEmail\" />");
308: $this->_tpl->assign('INPUT_REALNAME', $this->_currentRealname . "<input type=\"hidden\" name=\"realname\" value=\"$this->_currentRealname\" />");
309: $this->_tpl->assign('INPUT_FORUM', $forum);
310: } else {
311:
312: $email = conHtmlSpecialChars($email);
313: $realname = conHtmlSpecialChars($realname);
314: $this->_tpl->assign('INPUT_EMAIL', "<input type=\"text\" name=\"email\" value=\"$email\" />");
315: $this->_tpl->assign('INPUT_REALNAME', "<input type=\"text\" name=\"realname\" value=\"$realname\" />");
316: $this->_tpl->assign('INPUT_FORUM', $forum);
317: $this->_tpl->assign('INPUT_FORUM_QUOTE', $forum_quote);
318: }
319:
320: if (strlen($forum_quote) > 0) {
321: $this->_tpl->assign('DISPLAY', 'display:block');
322: $this->_tpl->assign('INPUT_FORUM_QUOTE', $forum_quote);
323: } else {
324: $this->_tpl->assign('DISPLAY', 'display:none');
325: $this->_tpl->assign('INPUT_FORUM_QUOTE', '');
326: }
327:
328: $this->_tpl->assign('REALNAME', mi18n("yourName"));
329: $this->_tpl->assign('EMAIL', mi18n("yourMailAddress"));
330: $this->_tpl->assign('FORUM', mi18n("yourArticle"));
331: $this->_tpl->assign('FORUM_QUOTE', mi18n("quote"));
332: $this->_tpl->assign('IDCAT', $this->_idcat);
333: $this->_tpl->assign('IDART', $this->_idart);
334: $this->_tpl->assign('SAVE_FORUM', mi18n("saveArticle"));
335: $this->_tpl->assign('USER_FORUM_PARENT', (int) $_REQUEST['user_forum_parent']);
336:
337: $this->_tpl->assign('CANCEL_FORUM', mi18n("cancel"));
338: $this->_tpl->assign('CANCEL_LINK', "front_content.php?idart=$this->_idart");
339:
340: $this->_tpl->assign('USERID', $this->_userid);
341: $this->_tpl->assign('CONTENIDO', $contenido);
342:
343:
344: $replyId = (int) $_REQUEST['user_forum_parent'];
345: if ($replyId > 0) {
346:
347: $content = $this->_collection->selectNameAndNameByForumId($replyId);
348: $empty = (count($content) > 0) ? false : true;
349:
350: if (!$empty) {
351: $transTemplate = mi18n("answerToQuote");
352: $transTemplateAfter = mi18n("from");
353: $this->_tpl->assign('FORUM_REPLYMENT', conHtmlSpecialChars($transTemplate) . '<br/>' . conHtmlSpecialChars($content['forum']) . "<br/><br/>" . conHtmlSpecialChars($transTemplateAfter) . ' ' . conHtmlSpecialChars($content['realname']));
354: } else {
355: $this->_tpl->assign('FORUM_REPLYMENT', '');
356: }
357: } else {
358: $this->_tpl->assign('FORUM_REPLYMENT', '');
359: }
360:
361: $this->_generate = false;
362:
363: $this->_tpl->display('user_forum_new.tpl');
364: }
365: }
366: return $bInputOK;
367: }
368:
369: 370: 371:
372: private function _listForum() {
373: $linkText = "$this->_userid&deleting=$this->_allowDeleting&idart=$this->_idart";
374: if ($this->_generate) {
375:
376:
377: $arrUserforum = $this->_collection->getExistingforumFrontend($this->_idcat, $this->_idart, $this->_idlang, true);
378:
379: if (count($arrUserforum) == 0) {
380: $this->_tpl->assign('MESSAGE', mi18n("noCommentsYet"));
381: $this->_tpl->assign('FORUM_TEXT', mi18n("articles"));
382: $this->_tpl->assign(conHtmlSpecialChars(mi18n("writeNewEntry")));
383: if ($this->_allowedToEditForum) {
384: $link = $linkText;
385: $this->_tpl->assign('LINK_NEW_FORUM', $link);
386: } else {
387: $this->_tpl->assign('LINK_NEW_FORUM', mi18n("noPosibleInputForArticle"));
388: }
389: $this->_tpl->assign('LINKTEXT', mi18n("writeNewEntry"));
390: $this->_tpl->display('user_forum_list_empty.tpl');
391: } else {
392: $this->_tpl->assign('MESSAGE', $this->_messageText);
393: $this->_tpl->assign('AMOUNT_forum', count($arrUserforum));
394: $this->_tpl->assign('FORUM_TEXT', mi18n("articlesLabel"));
395:
396: $number = 1;
397: $tplData = array();
398:
399:
400: foreach ($arrUserforum as $key => $value) {
401:
402: $record = array();
403: $record['REALNAME'] = str_replace('\\', '', $value['realname']);
404: $record['EMAIL'] = str_replace('\\', '', $value['email']);
405: $record['NUMBER'] = $number;
406: $number++;
407:
408:
409: $arrTmp = preg_split('/ /', $value['timestamp']);
410: $arrTmp2 = preg_split('/-/', $arrTmp[0]);
411: $ts = $arrTmp2[2] . '.' . $arrTmp2[1] . '.' . $arrTmp2[0] . ' ' . mi18n("about") . ' ';
412: $ts .= substr($arrTmp[1], 0, 5) . ' ' . mi18n("clock");
413:
414: $record['AM'] = mi18n("AM");
415: $record['WROTE_ON'] = mi18n("wroteAt");
416: $record['WRITE_EMAIL'] = mi18n("emailToAuthor");
417: $record['TIMESTAMP'] = $ts;
418:
419: if (strlen($value['forum_quote']) > 0) {
420: $record['FORUM_QUOTE'] = '<div class="forum_quote">' . $value['forum_quote'] . '</div>';
421: } else {
422: $record['FORUM_QUOTE'] = '';
423: }
424:
425: $record['FORUM'] = str_replace('\\', '', $value['forum']);
426:
427: if (($value['editedby'] != '') && ($value['editedat'] != "0000-00-00 00:00:00")) {
428:
429:
430: $arrTmp = explode(' ', $value['editedat']);
431: $edittime = substr($arrTmp[1], 0, 5);
432: $arrTmp2 = explode('-', $arrTmp[0]);
433: $editdate = $arrTmp2[2] . '.' . $arrTmp2[1] . '.' . $arrTmp2[0];
434:
435:
436:
437: $tmp = mi18n("articleWasEditAt");
438:
439: $userColl = new cApiUserCollection();
440: $user = $userColl->loadItem($value['editedby'])->get('username');
441:
442: $edit_information = sprintf($tmp, $editdate, $edittime, conHtmlSpecialChars($user));
443: $record['EDIT_INFORMATION'] = "<br /><br /><em>$edit_information</em>";
444: }
445:
446:
447: if ($this->_qoute) {
448: $record['REPLY'] = sprintf($linkText, $key);
449: } else {
450: $record['REPLY'] = NULL;
451: }
452:
453: $record['REPLY_QUOTE'] = sprintf($linkText, $key, $key);
454: $record['LIKE'] = sprintf($linkText, $key, $value['like']);
455: $record['DISLIKE'] = sprintf($linkText, $key, $value['dislike']);
456: $record['FROM'] = mi18n("from");
457: $record['OPINION'] = mi18n("sameOpinion");
458: $record['LIKE_COUNT'] = $value['like'];
459: $record['DISLIKE_COUNT'] = $value['dislike'];
460: $record['PADDING'] = $value['level'] * 20;
461: $record['LINKTEXT'] = mi18n("writeNewEntry");
462: $record['REPLYTEXT'] = mi18n("answers");
463: $record['QUOTETEXT'] = mi18n("replyQuote");
464: $record['FORMID'] = $value['id_user_forum'];
465: $record['LINKBEGIN'] = "";
466: $record['LINKEND'] = "";
467: $record['MAILTO'] = '#';
468: $record['EMAIL'] = '';
469:
470: array_push($tplData, $record);
471: }
472:
473: $this->_tpl->assign('POSTS', $tplData);
474:
475: $sTemp = mi18n("showHideArticles");
476: $sTemp = str_replace('___', count($arrUserforum), $sTemp);
477:
478: if ($this->_allowedToEditForum) {
479: $link = $linkText;
480:
481: $tplOptionList = new cTemplate();
482: $tplOptionList->set('s', 'SHOW_forum', $sTemp);
483:
484: $this->_tpl->assign('SHOW_FORUM_OPTION', $tplOptionList->generate('templates/user_forum_option_list.tpl', 1));
485: $this->_tpl->assign('LINKTEXT', mi18n("writeNewEntry"));
486: $this->_tpl->assign('LINK_NEW_FORUM', $linkText);
487: } else {
488: $this->_tpl->assign('LINK_NEW_FORUM', mi18n("noPosibleInputForArticle"));
489: }
490:
491: $this->_tpl->assign('NUM_FORUM', count($arrUserforum));
492:
493: $this->_tpl->display('user_forum_list.tpl');
494: }
495: }
496: }
497:
498: 499: 500:
501: private function _newEntry() {
502: if ($this->_allowedToEditForum) {
503: $this->_tpl->assign('MESSAGE', $this->_messageText);
504: $idquote = (int) $_REQUEST['user_forum_quote'];
505:
506: if ($idquote > 0) {
507: $content = $this->_collection->selectNameAndNameByForumId($idquote);
508: $empty = (count($content) > 0) ? false : true;
509: if (!$empty) {
510: $ar = $this->_collection->getCommentContent($idquote);
511: $transTemplate = mi18n("quoteFrom");
512: $this->_tpl->assign('INPUT_FORUM_QUOTE', $transTemplate . ' ' . $ar['name'] . "\n" . $ar['content']);
513: $this->_tpl->assign('DISPLAY', 'display:block');
514: } else {
515: $this->_tpl->assign('DISPLAY', 'display:none');
516: $this->_tpl->assign('INPUT_FORUM_QUOTE', '');
517: }
518: } else {
519: $this->_tpl->assign('DISPLAY', 'display:none');
520: $this->_tpl->assign('INPUT_FORUM_QUOTE', '');
521: }
522:
523: $replyId = (int) $_REQUEST['user_forum_parent'];
524:
525: if ($replyId > 0) {
526: $content = $this->_collection->selectNameAndNameByForumId($replyId);
527: $empty = (count($content) > 0) ? false : true;
528:
529: if (!$empty) {
530:
531: $ar = $this->_collection->getCommentContent($replyId);
532: $transTemplate = mi18n("answerToQuote");
533: $transTemplateContent = $ar['content'];
534: $transTemplateAfter = mi18n("from");
535: $transTemplateName = $ar['name'];
536: $this->_tpl->assign('FORUM_REPLYMENT', conHtmlSpecialChars($transTemplate) . '<br/>' . $transTemplateContent . "<br/><br/>" . conHtmlSpecialChars($transTemplateAfter) . ' ' . conHtmlSpecialChars($transTemplateName));
537: } else {
538: $this->_tpl->assign('FORUM_REPLYMENT', '');
539: }
540: } else {
541: $this->_tpl->assign('FORUM_REPLYMENT', '');
542: }
543:
544: if ($this->_modMode) {
545: $this->_tpl->assign('MODEMODETEXT', mi18n('MODEMODETEXT'));
546: }
547:
548: $this->_tpl->assign('INPUT_EMAIL', "<input type=\"text\" name=\"email\" value=\"\" tabindex=\"2\" />");
549: $this->_tpl->assign('INPUT_REALNAME', "<input type=\"text\" name=\"realname\" value=\"\" tabindex=\"1\" />");
550: $this->_tpl->assign('INPUT_FORUM', '');
551: $this->_tpl->assign('REALNAME', mi18n("yourName"));
552: $this->_tpl->assign('EMAIL', mi18n("yourMailAddress"));
553: $this->_tpl->assign('FORUM', mi18n("yourArticle"));
554: $this->_tpl->assign('FORUM_QUOTE', mi18n("quote"));
555: $this->_tpl->assign('IDCAT', $this->_idcat);
556: $this->_tpl->assign('IDART', $this->_idart);
557: $this->_tpl->assign('SAVE_FORUM', mi18n("saveArticle"));
558: $this->_tpl->assign('CANCEL_FORUM', mi18n("cancel"));
559: $this->_tpl->assign('CANCEL_LINK', "front_content.php?idart=$this->_idart");
560: $this->_tpl->assign('USERID', $_REQUEST['userid']);
561: $this->_tpl->assign('DELETING', $_REQUEST['deleting']);
562: $this->_tpl->assign('CONTENIDO', $_REQUEST['contenido']);
563: $this->_tpl->assign('USER_FORUM_PARENT', (int) $_REQUEST['user_forum_parent']);
564: $this->_tpl->display('user_forum_new.tpl');
565: }
566: }
567:
568: 569: 570: 571: 572: 573: 574:
575: private function _checkCookie() {
576: $ip = $_SERVER['REMOTE_ADDR'];
577: $time = time();
578:
579: if ($_REQUEST['user_forum_action'] == 'dislike_forum' && isset($_COOKIE['cookie'][$ip][$_REQUEST['user_forum_id']][$_REQUEST['user_forum_action']])) {
580: $this->_counter = false;
581: } elseif ($_REQUEST['user_forum_action'] == 'dislike_forum' && !isset($_COOKIE['cookie'][$ip][$_REQUEST['user_forum_id']][$_REQUEST['user_forum_action']])) {
582: setcookie("cookie[" . $ip . "][" . $_REQUEST['user_forum_id'] . "][" . $_REQUEST['user_forum_action'] . "]", 1, $time + 3600);
583: $this->_counter = true;
584: }
585: if ($_REQUEST['user_forum_action'] == 'like_forum' && isset($_COOKIE['cookie'][$ip][$_REQUEST['user_forum_id']][$_REQUEST['user_forum_action']])) {
586: $this->_counter = false;
587: } elseif ($_REQUEST['user_forum_action'] == 'like_forum' && !isset($_COOKIE['cookie'][$ip][$_REQUEST['user_forum_id']][$_REQUEST['user_forum_action']])) {
588: setcookie("cookie[" . $ip . "][" . $_REQUEST['user_forum_id'] . "][" . $_REQUEST['user_forum_action'] . "]", 1, $time + 3600);
589: $this->_counter = true;
590: }
591: }
592:
593: }
594:
595:
596: $userForumArticle = new UserForumArticle();
597: $userForumArticle->receiveData($_REQUEST);
598: ?>