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