1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
14:
15: 16: 17: 18: 19: 20: 21: 22:
23: class ArticleForumCollection extends ItemCollection {
24:
25: 26: 27: 28:
29: protected $cfg = 0;
30:
31: 32: 33: 34:
35: protected $db = 0;
36:
37: 38: 39: 40:
41: protected $item = 0;
42:
43:
44: 45: 46: 47:
48: protected $languageSync = 0;
49:
50: 51: 52: 53:
54: protected $idContentType = 0;
55:
56: 57:
58: public function __construct() {
59:
60: date_default_timezone_set('Europe/Berlin');
61: $this->db = cRegistry::getDb();
62: $this->cfg = cRegistry::getConfig();
63:
64: parent::__construct($this->cfg['tab']['user_forum'], 'id_user_forum');
65: $this->_setItemClass('ArticleForum');
66: $this->item = new ArticleForumItem();
67: $this->idContentType = $this->getIdUserForumContenType();
68: }
69:
70: 71: 72: 73:
74: public function getAllCommentedArticles() {
75:
76: $idclient = cRegistry::getClientId();
77:
78:
79: $this->db->query("-- ArticleForumCollection->getAllCommentedArticles()
80: SELECT DISTINCT
81: art_lang.title
82: , art_lang.idart
83: , f.idcat
84: FROM
85: `{$this->cfg['tab']['art_lang']}` AS art_lang
86: , `$this->table` AS f
87: WHERE
88: art_lang.idart = f.idart
89: AND art_lang.idlang = f.idlang
90: AND idclient = " . $idclient . "
91: ORDER BY
92: id_user_forum ASC
93: ;");
94:
95: $data = array();
96: while ($this->db->nextRecord()) {
97: array_push($data, $this->db->toArray());
98: }
99:
100: return $data;
101: }
102:
103: 104: 105: 106: 107: 108: 109: 110: 111:
112: public function deleteHierarchy($keyPost, $level, $idart, $idcat, $lang) {
113: $comments = $this->_getCommentHierarchy($idcat, $idart, $lang);
114:
115: $arri = array();
116:
117: foreach ($comments as $key => $com) {
118: $com['key'] = $key;
119: $arri[] = $com;
120: }
121: $idEntry = 0;
122: $id_user_forum = array();
123: $lastLevel = 0;
124: for ($i = 0; $i < count($arri); $i++) {
125:
126: if ($arri[$i]['key'] == $keyPost) {
127: $idEntry = $arri[$i]['id_user_forum'];
128: if ($arri[$i]['level'] < $arri[$i + 1]['level']) {
129:
130: for ($j = $i + 1; $j < $arri[$j]; $j++) {
131: if ($arri[$i]['level'] < $arri[$j]['level']) {
132: $id_user_forum[] = $arri[$j]['id_user_forum'];
133: }
134: }
135: }
136: }
137: }
138:
139: if (empty($id_user_forum)) {
140: $this->deleteBy('id_user_forum', $idEntry);
141: } else {
142: $this->deleteBy('id_user_forum', $idEntry);
143: foreach ($id_user_forum as $com) {
144: $this->deleteBy('id_user_forum', $com);
145: }
146: }
147: }
148:
149: 150: 151: 152: 153: 154: 155: 156:
157: protected function ($id_cat, $id_art, $id_lang) {
158: $this->query();
159: while (false != $field = $this->next()) {
160: $arrUsers[$field->get('userid')]['email'] = $field->get('email');
161: $arrUsers[$field->get('userid')]['realname'] = $field->get('realname');
162: }
163: $arrforum = array();
164: $this->getTreeLevel($id_cat, $id_art, $id_lang, $arrUsers, $arrforum);
165: $result = array();
166: $this->normalizeArray($arrforum, $result);
167:
168: return $result;
169: }
170:
171: 172: 173: 174: 175: 176:
177: public function normalizeArray($arrforum, &$result, $level = 0) {
178: if (is_array($arrforum)) {
179: foreach ($arrforum as $key => $value) {
180: $value['level'] = $level;
181: unset($value['children']);
182: $result[$key] = $value;
183: $this->normalizeArray($arrforum[$key]['children'], $result, $level + 1);
184: }
185: }
186: }
187:
188: 189: 190: 191: 192: 193: 194: 195: 196: 197:
198: public function getTreeLevel($id_cat, $id_art, $id_lang, &$arrUsers, &$arrforum, $parent = 0, $frontend = false) {
199: $db = cRegistry::getDb();
200: if ($frontend) {
201:
202: $db->query("-- ArticleForumCollection->getTreeLevel()
203: SELECT
204: *
205: FROM
206: `{$this->cfg['tab']['user_forum']}`
207: WHERE
208: idart = $id_art
209: AND idcat = $id_cat
210: AND idlang = $id_lang
211: AND id_user_forum_parent = $parent
212: AND online = 1
213: ORDER BY
214: timestamp DESC
215: ;");
216: } else {
217:
218: $db->query("-- ArticleForumCollection->getTreeLevel()
219: SELECT
220: *
221: FROM
222: `{$this->cfg['tab']['user_forum']}`
223: WHERE
224: idart = $id_art
225: AND idcat = $id_cat
226: AND idlang = $id_lang
227: AND id_user_forum_parent = $parent
228: ORDER BY
229: timestamp DESC
230: ;");
231: }
232:
233: while ($db->nextRecord()) {
234: $arrforum[$db->f('id_user_forum')]['userid'] = $db->f('userid');
235:
236: if (array_key_exists($db->f('userid'), $arrUsers)) {
237: $arrforum[$db->f('id_user_forum')]['email'] = $arrUsers[$db->f('userid')]['email'];
238: $arrforum[$db->f('id_user_forum')]['realname'] = $arrUsers[$db->f('userid')]['realname'];
239: } else {
240: $arrforum[$db->f('id_user_forum')]['email'] = $db->f('email');
241: $arrforum[$db->f('id_user_forum')]['realname'] = $db->f('realname');
242: }
243: $arrforum[$db->f('id_user_forum')]['forum'] = str_replace(chr(13) . chr(10), '<br />', $db->f('forum'));
244: $arrforum[$db->f('id_user_forum')]['forum_quote'] = str_replace(chr(13) . chr(10), '<br />', $db->f('forum_quote'));
245: $arrforum[$db->f('id_user_forum')]['timestamp'] = $db->f('timestamp');
246: $arrforum[$db->f('id_user_forum')]['like'] = $db->f('like');
247: $arrforum[$db->f('id_user_forum')]['dislike'] = $db->f('dislike');
248:
249: $arrforum[$db->f('id_user_forum')]['editedat'] = $db->f('editedat');
250: $arrforum[$db->f('id_user_forum')]['editedby'] = $db->f('editedby');
251:
252:
253: $arrforum[$db->f('id_user_forum')]['idcat'] = $db->f('idcat');
254: $arrforum[$db->f('id_user_forum')]['idart'] = $db->f('idart');
255: $arrforum[$db->f('id_user_forum')]['id_user_forum'] = $db->f('id_user_forum');
256: $arrforum[$db->f('id_user_forum')]['online'] = $db->f('online');
257: $arrforum[$db->f('id_user_forum')]['editedat'] = $db->f('editedat');
258: $arrforum[$db->f('id_user_forum')]['editedby'] = $db->f('editedby');
259:
260: $this->getTreeLevel($id_cat, $id_art, $id_lang, $arrUsers, $arrforum[$db->f('id_user_forum')]['children'], $db->f('id_user_forum'), $frontend);
261: }
262: }
263:
264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274:
275: public function updateValues($id_user_forum, $name, $email, $like, $dislike, $forum, $online) {
276: $uuid = cRegistry::getAuth()->isAuthenticated();
277:
278: $this->item->loadByPrimaryKey($id_user_forum);
279:
280: if ($this->item->getField('realname') == $name && $this->item->getField('email') == $email && $this->item->getField('forum') == $forum) {
281:
282:
283:
284: if ($this->item->getField('editedat') === "0000-00-00 00:00:00") {
285:
286: $timeStamp = "0000-00-00 00:00:00";
287: } else {
288: $timeStamp = $this->item->getField('editedat');
289: }
290: } else {
291:
292: $timeStamp = date('Y-m-d H:i:s', time());
293: }
294:
295: if (preg_match('/\D/', $like)) {
296: $like = $this->item->getField('like');
297: }
298:
299: if (preg_match('/\D/', $dislike)) {
300: $dislike = $this->item->getField('dislike');
301: }
302:
303:
304:
305:
306:
307:
308:
309:
310: $fields = array(
311: 'realname' => $name,
312: 'editedby' => $uuid,
313: 'email' => $email,
314: 'forum' => $forum,
315: 'editedat' => $timeStamp,
316: 'like' => $like,
317: 'dislike' => $dislike,
318: 'online' => $online,
319:
320: 'moderated' => 1
321: );
322:
323: $whereClauses = array(
324: 'id_user_forum' => $id_user_forum
325: );
326: $statement = $this->db->buildUpdate($this->table, $fields, $whereClauses);
327: $this->db->query($statement);
328: }
329:
330: 331: 332: 333: 334: 335: 336:
337: public function toggleOnlineState($onlineState, $id_user_forum, $idart = NULL) {
338:
339:
340: $onlineState = ($onlineState == 0) ? 1 : 0;
341:
342: if (isset($idart)) {
343: $fields = array(
344: 'online' => $onlineState,
345: 'moderated' => 1,
346: );
347: } else {
348: $fields = array(
349: 'online' => $onlineState
350: );
351: }
352:
353: $whereClauses = array(
354: 'id_user_forum' => (int)$id_user_forum
355: );
356: $statement = $this->db->buildUpdate($this->table, $fields, $whereClauses);
357: $this->db->query($statement);
358: }
359:
360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372:
373: public function mailToModerator($realname, $email, $forum, $idart, $lang, $forum_quote = 0) {
374:
375:
376: $ar = $this->getArticleTitle($idart, $lang);
377:
378: $mail = new cMailer();
379: $mail->setCharset('UTF-8');
380:
381:
382: $message = $this->languageSync['NEWENTRYTEXT'] . " " . $this->languageSync['ARTICLE'] . $ar[0]["title"] . "\n" . "\n";
383: $message .= $this->languageSync['USER'] . ' : ' . $realname . "\n";
384: $message .= $this->languageSync['EMAIL'] . ' : ' . $email . "\n" . "\n";
385: $message .= $this->languageSync['COMMENT'] . ' : ' . "\n" . $forum . "\n";
386: if ($forum_quote != 0) {
387: $message .= UserForum::i18n('QUOTE') . ' : ' . $forum_quote . "\n";
388: }
389:
390:
391: if ($this->getModEmail($idart) != NULL) {
392: $mail->sendMail(getEffectiveSetting("userforum", "mailfrom"), $this->getModEmail($idart), $this->languageSync['NEWENTRY'], $message);
393: }
394: }
395:
396: 397: 398: 399: 400: 401: 402:
403: public function getArticleTitle($idart, $idlang) {
404: $this->db->query("-- ArticleForumCollection->getArticleTitle()
405: SELECT DISTINCT
406: title
407: FROM
408: `{$this->cfg['tab']['art_lang']}` AS art_lang
409: WHERE
410: idart = $idart
411: AND idlang = $idlang
412: ;");
413:
414: $data = array();
415: while ($this->db->nextRecord()) {
416: array_push($data, $this->db->toArray());
417: }
418:
419: return $data;
420: }
421:
422: 423: 424:
425: public function getExistingforum() {
426: $userColl = new cApiUserCollection();
427: $userColl->query();
428:
429: $arrUsers = array();
430:
431: while (($field = $userColl->next()) != false) {
432: $arrUsers[$field->get('user_id')]['email'] = $field->get('email');
433: $arrUsers[$field->get('user_id')]['realname'] = $field->get('realname');
434: }
435:
436: return $arrUsers;
437: }
438:
439: 440: 441: 442: 443: 444:
445: function selectNameAndNameByForumId($idquote) {
446: $ar = array();
447: $this->item->loadByPrimaryKey($this->db->escape($idquote));
448: $ar[] = $this->item->get('realname');
449:
450: return $ar;
451: }
452:
453: 454: 455: 456: 457:
458: public function selectUser($userid) {
459: return $this->item->loadByPrimaryKey($this->db->escape($userid));
460: }
461:
462: 463: 464: 465: 466: 467:
468: public function incrementLike($forum_user_id) {
469: $db = cRegistry::getDb();
470:
471: $this->item->loadByPrimaryKey($db->escape($forum_user_id));
472: $ar = $this->item->toArray();
473: $current = $ar['like'];
474:
475: $current += 1;
476:
477: $fields = array(
478: 'like' => $current
479: );
480: $whereClauses = array(
481: 'id_user_forum' => $forum_user_id
482: );
483:
484: $statement = $this->db->buildUpdate($this->table, $fields, $whereClauses);
485: $this->db->query($statement);
486: }
487:
488: 489: 490: 491: 492: 493:
494: public function incrementDislike($forum_user_id) {
495: $db = cRegistry::getDb();
496:
497: $this->item->loadByPrimaryKey($db->escape($forum_user_id));
498: $ar = $this->item->toArray();
499: $current = $ar['dislike'];
500:
501: $current += 1;
502:
503: $fields = array(
504: 'dislike' => $current
505: );
506: $whereClauses = array(
507: 'id_user_forum' => $forum_user_id
508: );
509:
510: $statement = $this->db->buildUpdate($this->table, $fields, $whereClauses);
511: $this->db->query($statement);
512: }
513:
514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526:
527: public function insertValues($parent, $idart, $idcat, $lang, $userid, $email, $realname, $forum, $forum_quote) {
528: $db = cRegistry::getDb();
529:
530:
531: $modCheck = $this->getModModeActive($idart);
532: $online = $modCheck ? 0 : 1;
533:
534:
535: $fields = array(
536: 'id_user_forum' => NULL,
537: 'id_user_forum_parent' => $db->escape($parent),
538: 'idart' => $db->escape($idart),
539: 'idcat' => $db->escape($idcat),
540: 'idlang' => $db->escape($lang),
541: 'userid' => $db->escape($userid),
542: 'email' => $db->escape($email),
543: 'realname' => $db->escape($realname),
544: 'forum' => ($forum),
545: 'forum_quote' => ($forum_quote),
546: 'idclient' => cRegistry::getClientId(),
547: 'like' => 0,
548: 'dislike' => 0,
549: 'editedat' => NULL,
550: 'editedby' => NULL,
551: 'timestamp' => date('Y-m-d H:i:s'),
552: 'online' => $online
553: );
554:
555: $db->insert($this->table, $fields);
556:
557:
558:
559:
560: if ($modCheck) {
561: $this->mailToModerator($realname, $email, $forum, $idart, $lang, $forum_quote = 0);
562: }
563: }
564:
565: 566: 567: 568: 569:
570: public function ($idart) {
571: $this->deleteBy('idart', (int)$idart);
572: }
573:
574: 575: 576: 577: 578: 579: 580: 581: 582:
583: public function getExistingforumFrontend($id_cat, $id_art, $id_lang, $frontend) {
584: $userColl = new cApiUserCollection();
585: $userColl->query();
586:
587: while (($field = $userColl->next()) != false) {
588: $arrUsers[$field->get('user_id')]['email'] = $field->get('email');
589: $arrUsers[$field->get('user_id')]['realname'] = $field->get('realname');
590: }
591:
592: $arrforum = array();
593: $this->getTreeLevel($id_cat, $id_art, $id_lang, $arrUsers, $arrforum, 0, $frontend);
594:
595: $result = array();
596: $this->normalizeArray($arrforum, $result);
597:
598: return $result;
599: }
600:
601: 602: 603: 604: 605: 606: 607:
608: public function getModEmail($idart) {
609: $data = $this->readXML();
610: for ($i = 0; $i < count($data); $i++) {
611: if ($data[$i]['idart'] == $idart) {
612: return $data[$i]["email"];
613: }
614: }
615:
616: return NULL;
617: }
618:
619: 620: 621: 622: 623: 624: 625:
626: public function getModModeActive($idart) {
627: $data = $this->readXML();
628: for ($i = 0; $i < count($data); $i++) {
629: if ($data[$i]['idart'] == $idart) {
630: if ($data[$i]["modactive"] === 'false') {
631: return false;
632: }
633: }
634: }
635:
636: return true;
637: }
638:
639: 640: 641: 642: 643: 644: 645:
646: public function getQuoteState($idart) {
647:
648: $data = $this->readXML();
649: for ($i = 0; $i < count($data); $i++) {
650: if ($data[$i]['idart'] == $idart) {
651: if ($data[$i]["subcomments"] === 'false') {
652: return false;
653: }
654: }
655: }
656:
657: return true;
658: }
659:
660: 661: 662: 663: 664: 665: 666:
667: public function readXML() {
668:
669: $idtype = $this->idContentType;
670:
671: $array = array();
672:
673: try {
674: $this->db->query("-- ArticleForumCollection->readXML()
675: SELECT
676: art_lang.idart
677: , content.value
678: FROM
679: `{$this->cfg['tab']['art_lang']}` AS art_lang
680: , `{$this->cfg['tab']['content']}` AS content
681: WHERE
682: art_lang.idartlang = content.idartlang
683: AND content.idtype = $idtype
684: ;");
685:
686: $data = array();
687: while ($this->db->nextRecord()) {
688: array_push($data, $this->db->toArray());
689: }
690:
691: $array = array();
692: for ($i = 0; $i < count($data); $i++) {
693: $array[$i] = cXmlBase::xmlStringToArray($data[$i]['value']);
694:
695: $array[$i]['idart'] = $data[$i]['idart'];
696: }
697: } catch (Exception $e) {
698:
699: }
700:
701: return $array;
702: }
703:
704: 705: 706: 707: 708: 709: 710:
711: public function languageSync(array &$str) {
712: $this->languageSync = $str;
713: }
714:
715: 716: 717: 718:
719: public function getlanguageSync() {
720: if ($this->languageSync != 0) {
721: return $this->languageSync;
722: } else {
723: return array();
724: }
725: }
726:
727: 728: 729: 730: 731: 732:
733: public function ($id_user_forum) {
734: $item = $this->loadItem($id_user_forum);
735:
736: return array(
737: 'name' => $item->get("realname"),
738: 'content' => $item->get("forum")
739: );
740: }
741:
742: 743: 744: 745:
746: protected function getIdUserForumContenType() {
747: $this->db->query("-- ArticleForumCollection->getIdUserForumContenType()
748: SELECT
749: idtype
750: FROM
751: `{$this->cfg['tab']['type']}`
752: WHERE
753: type = 'CMS_USERFORUM'
754: ;");
755: if ($this->db->nextRecord()) {
756: return $this->db->f('idtype');
757: } else {
758: return false;
759: }
760: }
761:
762:
763: public function () {
764:
765: $comments = array();
766:
767: $idlang = cRegistry::getLanguageId();
768: $idclient = cRegistry::getClientId();
769:
770: $db = cRegistry::getDb();
771: $db->query("-- ArticleForumCollection->getUnmoderatedComments()
772: SELECT
773: *
774: FROM
775: `{$this->cfg['tab']['user_forum']}`
776: WHERE
777: moderated = 0
778: AND idclient = $idclient
779: AND idlang = $idlang
780: AND online = 0
781: ORDER BY
782: timestamp DESC
783: ;");
784:
785: while ($db->nextRecord()) {
786:
787:
788: $modCheck = $this->getModModeActive($db->f('idart'));
789: if(isset($modCheck)) {
790: $comments[] = $db->getRecord();
791: }
792: }
793: return $comments;
794: }
795: }
796:
797: ?>