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