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->getModeModeActive($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:
296: $this->_collection->insertValues($parent, $this->_idart, $this->_idcat, $this->_idlang, $this->_userid, $email, $realname, $forum, $forum_quote);
297:
298: $this->_messageText .= mi18n("yourArticleSaved");
299: } else {
300:
301: $this->_tpl->assign('MESSAGE', $this->_messageText);
302:
303: if ($this->_userLoggedIn) {
304: $this->_tpl->assign('INPUT_EMAIL', $this->_currentEmail . "<input type=\"hidden\" name=\"email\" value=\"$this->_currentEmail\" />");
305: $this->_tpl->assign('INPUT_REALNAME', $this->_currentRealname . "<input type=\"hidden\" name=\"realname\" value=\"$this->_currentRealname\" />");
306: $this->_tpl->assign('INPUT_FORUM', $forum);
307: } else {
308: $this->_tpl->assign('INPUT_EMAIL', "<input type=\"text\" name=\"email\" value=\"$email\" />");
309: $this->_tpl->assign('INPUT_REALNAME', "<input type=\"text\" name=\"realname\" value=\"$realname\" />");
310: $this->_tpl->assign('INPUT_FORUM', $forum);
311: $this->_tpl->assign('INPUT_FORUM_QUOTE', $forum_quote);
312: }
313:
314: if (strlen($forum_quote) > 0) {
315: $this->_tpl->assign('DISPLAY', 'display:block');
316: $this->_tpl->assign('INPUT_FORUM_QUOTE', $forum_quote);
317: } else {
318: $this->_tpl->assign('DISPLAY', 'display:none');
319: $this->_tpl->assign('INPUT_FORUM_QUOTE', '');
320: }
321:
322: $this->_tpl->assign('REALNAME', mi18n("yourName"));
323: $this->_tpl->assign('EMAIL', mi18n("yourMailAddress"));
324: $this->_tpl->assign('FORUM', mi18n("yourArticle"));
325: $this->_tpl->assign('FORUM_QUOTE', mi18n("quote"));
326: $this->_tpl->assign('IDCAT', $this->_idcat);
327: $this->_tpl->assign('IDART', $this->_idart);
328: $this->_tpl->assign('SAVE_FORUM', mi18n("saveArticle"));
329: $this->_tpl->assign('USER_FORUM_PARENT', (int) $_REQUEST['user_forum_parent']);
330:
331: $this->_tpl->assign('CANCEL_FORUM', mi18n("cancel"));
332: $this->_tpl->assign('CANCEL_LINK', "front_content.php?idart=$this->_idart");
333:
334: $this->_tpl->assign('USERID', $this->_userid);
335: $this->_tpl->assign('CONTENIDO', $contenido);
336:
337:
338: $replyId = (int) $_REQUEST['user_forum_parent'];
339: if ($replyId > 0) {
340:
341: $content = $this->_collection->selectNameAndNameByForumId($replyId);
342: $empty = (count($content) > 0) ? false : true;
343:
344: if (!$empty) {
345: $transTemplate = mi18n("answerToQuote");
346: $transTemplateAfter = mi18n("from");
347: $this->_tpl->assign('FORUM_REPLYMENT', $transTemplate . '<br/>' . $content['forum'] . "<br/><br/>" . $transTemplateAfter . ' ' . $content['realname']);
348: } else {
349: $this->_tpl->assign('FORUM_REPLYMENT', '');
350: }
351: } else {
352: $this->_tpl->assign('FORUM_REPLYMENT', '');
353: }
354:
355: $this->_generate = false;
356:
357: $this->_tpl->display('user_forum_new.tpl');
358: }
359: }
360: return $bInputOK;
361: }
362:
363: 364: 365:
366: private function _listForum() {
367: $linkText = "$this->_userid&deleting=$this->_allowDeleting&idart=$this->_idart";
368: if ($this->_generate) {
369:
370:
371: $arrUserforum = $this->_collection->getExistingforumFrontend($this->_idcat, $this->_idart, $this->_idlang, true);
372:
373: if (count($arrUserforum) == 0) {
374: $this->_tpl->assign('MESSAGE', mi18n("noCommentsYet"));
375: $this->_tpl->assign('FORUM_TEXT', mi18n("articles"));
376: $this->_tpl->assign(mi18n("writeNewEntry"));
377: if ($this->_allowedToEditForum) {
378: $link = $linkText;
379: $this->_tpl->assign('LINK_NEW_FORUM', $link);
380: } else {
381: $this->_tpl->assign('LINK_NEW_FORUM', mi18n("noPosibleInputForArticle"));
382: }
383: $this->_tpl->assign('LINKTEXT', mi18n("writeNewEntry"));
384: $this->_tpl->display('user_forum_list_empty.tpl');
385: } else {
386: $this->_tpl->assign('MESSAGE', $this->_messageText);
387: $this->_tpl->assign('AMOUNT_forum', count($arrUserforum));
388: $this->_tpl->assign('FORUM_TEXT', mi18n("articlesLabel"));
389:
390: $number = 1;
391: $tplData = array();
392:
393:
394: foreach ($arrUserforum as $key => $value) {
395:
396: $record = array();
397: $record['REALNAME'] = str_replace('\\', '', $value['realname']);
398: $record['EMAIL'] = str_replace('\\', '', $value['email']);
399: $record['NUMBER'] = $number;
400: $number++;
401:
402:
403: $arrTmp = preg_split('/ /', $value['timestamp']);
404: $arrTmp2 = preg_split('/-/', $arrTmp[0]);
405: $ts = $arrTmp2[2] . '.' . $arrTmp2[1] . '.' . $arrTmp2[0] . ' ' . mi18n("about") . ' ';
406: $ts .= substr($arrTmp[1], 0, 5) . ' ' . mi18n("clock");
407:
408: $record['AM'] = mi18n("AM");
409: $record['WROTE_ON'] = mi18n("wroteAt");
410: $record['WRITE_EMAIL'] = mi18n("emailToAuthor");
411: $record['TIMESTAMP'] = $ts;
412:
413: if (strlen($value['forum_quote']) > 0) {
414: $record['FORUM_QUOTE'] = '<div class="forum_quote">' . $value['forum_quote'] . '</div>';
415: } else {
416: $record['FORUM_QUOTE'] = '';
417: }
418:
419: $record['FORUM'] = str_replace('\\', '', $value['forum']);
420:
421: if (($value['editedby'] != '') && ($value['editedat'] != "0000-00-00 00:00:00")) {
422:
423:
424: $arrTmp = explode(' ', $value['editedat']);
425: $edittime = substr($arrTmp[1], 0, 5);
426: $arrTmp2 = explode('-', $arrTmp[0]);
427: $editdate = $arrTmp2[2] . '.' . $arrTmp2[1] . '.' . $arrTmp2[0];
428:
429:
430:
431: $tmp = mi18n("articleWasEditAt");
432:
433: $userColl = new cApiUserCollection();
434: $user = $userColl->loadItem($value['editedby'])->get('username');
435:
436: $edit_information = sprintf($tmp, $editdate, $edittime, $user);
437: $record['EDIT_INFORMATION'] = "<br /><br /><em>$edit_information</em>";
438: }
439:
440:
441: if ($this->_qoute) {
442: $record['REPLY'] = sprintf($linkText, $key);
443: } else {
444: $record['REPLY'] = NULL;
445: }
446:
447: $record['REPLY_QUOTE'] = sprintf($linkText, $key, $key);
448: $record['LIKE'] = sprintf($linkText, $key, $value['like']);
449: $record['DISLIKE'] = sprintf($linkText, $key, $value['dislike']);
450: $record['FROM'] = mi18n("from");
451: $record['OPINION'] = mi18n("sameOpinion");
452: $record['LIKE_COUNT'] = $value['like'];
453: $record['DISLIKE_COUNT'] = $value['dislike'];
454: $record['PADDING'] = $value['level'] * 20;
455: $record['LINKTEXT'] = mi18n("writeNewEntry");
456: $record['REPLYTEXT'] = mi18n("answers");
457: $record['QUOTETEXT'] = mi18n("replyQuote");
458: $record['FORMID'] = $value['id_user_forum'];
459: $record['LINKBEGIN'] = "";
460: $record['LINKEND'] = "";
461: $record['MAILTO'] = '#';
462: $record['EMAIL'] = '';
463:
464: array_push($tplData, $record);
465: }
466:
467: $this->_tpl->assign('POSTS', $tplData);
468:
469: $sTemp = mi18n("showHideArticles");
470: $sTemp = str_replace('___', count($arrUserforum), $sTemp);
471:
472: if ($this->_allowedToEditForum) {
473: $link = $linkText;
474:
475: $tplOptionList = new cTemplate();
476: $tplOptionList->set('s', 'SHOW_forum', $sTemp);
477:
478: $this->_tpl->assign('SHOW_FORUM_OPTION', $tplOptionList->generate('templates/user_forum_option_list.tpl', 1));
479: $this->_tpl->assign('LINKTEXT', mi18n("writeNewEntry"));
480: $this->_tpl->assign('LINK_NEW_FORUM', $linkText);
481: } else {
482: $this->_tpl->assign('LINK_NEW_FORUM', mi18n("noPosibleInputForArticle"));
483: }
484:
485: $this->_tpl->assign('NUM_FORUM', count($arrUserforum));
486:
487: $this->_tpl->display('user_forum_list.tpl');
488: }
489: }
490: }
491:
492: 493: 494:
495: private function _newEntry() {
496: if ($this->_allowedToEditForum) {
497: $this->_tpl->assign('MESSAGE', $this->_messageText);
498: $idquote = (int) $_REQUEST['user_forum_quote'];
499:
500: if ($idquote > 0) {
501: $content = $this->_collection->selectNameAndNameByForumId($idquote);
502: $empty = (count($content) > 0) ? false : true;
503: if (!$empty) {
504: $ar = $this->_collection->getCommentContent($idquote);
505: $transTemplate = mi18n("quoteFrom");
506: $this->_tpl->assign('INPUT_FORUM_QUOTE', $transTemplate . ' ' . $ar['name'] . "\n" . $ar['content']);
507: $this->_tpl->assign('DISPLAY', 'display:block');
508: } else {
509: $this->_tpl->assign('DISPLAY', 'display:none');
510: $this->_tpl->assign('INPUT_FORUM_QUOTE', '');
511: }
512: } else {
513: $this->_tpl->assign('DISPLAY', 'display:none');
514: $this->_tpl->assign('INPUT_FORUM_QUOTE', '');
515: }
516:
517: $replyId = (int) $_REQUEST['user_forum_parent'];
518:
519: if ($replyId > 0) {
520: $content = $this->_collection->selectNameAndNameByForumId($replyId);
521: $empty = (count($content) > 0) ? false : true;
522:
523: if (!$empty) {
524:
525: $ar = $this->_collection->getCommentContent($replyId);
526: $transTemplate = mi18n("answerToQuote");
527: $transTemplateContent = $ar['content'];
528: $transTemplateAfter = mi18n("from");
529: $transTemplateName = $ar['name'];
530: $this->_tpl->assign('FORUM_REPLYMENT', $transTemplate . '<br/>' . $transTemplateContent . "<br/><br/>" . $transTemplateAfter . ' ' . $transTemplateName);
531: } else {
532: $this->_tpl->assign('FORUM_REPLYMENT', '');
533: }
534: } else {
535: $this->_tpl->assign('FORUM_REPLYMENT', '');
536: }
537:
538: if ($this->_modMode) {
539: $this->_tpl->assign('MODEMODETEXT', mi18n('MODEMODETEXT'));
540: }
541:
542: $this->_tpl->assign('INPUT_EMAIL', "<input type=\"text\" name=\"email\" value=\"\" />");
543: $this->_tpl->assign('INPUT_REALNAME', "<input type=\"text\" name=\"realname\" value=\"\" />");
544: $this->_tpl->assign('INPUT_FORUM', '');
545: $this->_tpl->assign('REALNAME', mi18n("yourName"));
546: $this->_tpl->assign('EMAIL', mi18n("yourMailAddress"));
547: $this->_tpl->assign('FORUM', mi18n("yourArticle"));
548: $this->_tpl->assign('FORUM_QUOTE', mi18n("quote"));
549: $this->_tpl->assign('IDCAT', $this->_idcat);
550: $this->_tpl->assign('IDART', $this->_idart);
551: $this->_tpl->assign('SAVE_FORUM', mi18n("saveArticle"));
552: $this->_tpl->assign('CANCEL_FORUM', mi18n("cancel"));
553: $this->_tpl->assign('CANCEL_LINK', "front_content.php?idart=$this->_idart");
554: $this->_tpl->assign('USERID', $_REQUEST['userid']);
555: $this->_tpl->assign('DELETING', $_REQUEST['deleting']);
556: $this->_tpl->assign('CONTENIDO', $_REQUEST['contenido']);
557: $this->_tpl->assign('USER_FORUM_PARENT', (int) $_REQUEST['user_forum_parent']);
558: $this->_tpl->display('user_forum_new.tpl');
559: }
560: }
561:
562: 563: 564: 565: 566: 567: 568:
569: private function _checkCookie() {
570:
571: $ip = $REMOTE_ADDR ? $REMOTE_ADDR : $_SERVER['REMOTE_ADDR'];
572: $time = time();
573:
574: if ($_REQUEST['user_forum_action'] == 'dislike_forum' && isset($_COOKIE['cookie'][$ip][$_REQUEST['user_forum_id']][$_REQUEST['user_forum_action']])) {
575: $this->_counter = false;
576: } elseif ($_REQUEST['user_forum_action'] == 'dislike_forum' && !isset($_COOKIE['cookie'][$ip][$_REQUEST['user_forum_id']][$_REQUEST['user_forum_action']])) {
577: setcookie("cookie[" . $ip . "][" . $_REQUEST['user_forum_id'] . "][" . $_REQUEST['user_forum_action'] . "]", 1, $time + 3600);
578: $this->_counter = true;
579: }
580: if ($_REQUEST['user_forum_action'] == 'like_forum' && isset($_COOKIE['cookie'][$ip][$_REQUEST['user_forum_id']][$_REQUEST['user_forum_action']])) {
581: $this->_counter = false;
582: } elseif ($_REQUEST['user_forum_action'] == 'like_forum' && !isset($_COOKIE['cookie'][$ip][$_REQUEST['user_forum_id']][$_REQUEST['user_forum_action']])) {
583: setcookie("cookie[" . $ip . "][" . $_REQUEST['user_forum_id'] . "][" . $_REQUEST['user_forum_action'] . "]", 1, $time + 3600);
584: $this->_counter = true;
585: }
586: }
587:
588: }
589:
590:
591: $userForumArticle = new UserForumArticle();
592: $userForumArticle->receiveData($_REQUEST);
593: ?>