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