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