Example #1
0
 public function newsToForum(GWF_News $news, $visible = true)
 {
     if (false === ($poster = $news->getUser())) {
         return GWF_HTML::error('News_Edit', 'News_Edit::newsToForum(): Nobody as Poster');
     }
     // Get News root.
     if (false === ($news_root = $this->getNewsForumRoot())) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $root_id = $news_root->getID();
     $lang_roots = array();
     foreach ($news->getTranslations() as $t) {
         if (false === ($lang = GWF_Language::getByID($t['newst_langid']))) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         if (false === ($lang_board = $this->getNewsForumLangCached($lang, $root_id))) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
         $iso = $lang->getISO();
         $tid = (int) $t['newst_threadid'];
         $lang_roots[$iso] = $lang_board;
         $bid = $lang_board->getID();
         $thread = GWF_ForumThread::getByID($tid);
         $title = $t['newst_title'];
         $message = $t['newst_message'];
         $gid = 0;
         $options = GWF_ForumThread::GUEST_VIEW;
         $options |= $visible ? 0 : GWF_ForumThread::INVISIBLE;
         if (!$visible) {
             if ($thread !== false) {
                 $thread->setVisible($visible);
             }
         } else {
             if ($thread === false) {
                 if (false === ($thread = GWF_ForumThread::newThread($poster, $title, $message, $options, $bid, $gid))) {
                     return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
                 }
             } else {
                 if (false === ($post = $thread->getFirstPost())) {
                     return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
                 }
                 if (false === $post->saveVar('post_message', $message)) {
                     return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
                 }
             }
             $thread->setVisible($visible);
         }
         $tid = $thread === false ? 0 : $thread->getID();
         $langid = $lang->getID();
         $newsid = $news->getID();
         // Save threadid
         if (false === GDO::table('GWF_NewsTranslation')->update("newst_threadid={$tid}", "newst_langid={$langid} AND newst_newsid={$newsid}")) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     // Set Boards Visible
     $news_root->setVisible($visible);
     foreach ($lang_roots as $iso => $board) {
         $board->setVisible($visible);
     }
     return '';
 }
Example #2
0
 private static function sendNewsletter(Module_News $module, GWF_News $item)
 {
     $ft = $item->getFirstTranslation();
     $ts = $item->getTranslations();
     $first_id = (int) $ft['newst_langid'];
     $newsid = $item->getID();
     $sender_mail = $module->cfgSender();
     $micros = $module->cfgSleepMillis() * 1000;
     //		$newsletter = GDO::table('GWF_Newsletter');
     $db = gdo_db();
     $nlt = GWF_TABLE_PREFIX . 'newsletter';
     $query = "SELECT * FROM {$nlt}";
     if (false === ($result = $db->queryRead($query))) {
         return;
     }
     //		self::log('Sender email is: '.$sender_mail);
     //		$recs = $newsletter->selectAll();
     //		$recs = $newsletter->queryAll();
     while (false !== ($row = $db->fetchAssoc($result))) {
         //		foreach ($recs as $rec)
         //		{
         //			$rec instanceof GWF_Newsletter;
         $rec = new GWF_Newsletter($row);
         if ($rec->hasBeenMailed($newsid)) {
             continue;
         }
         $langid = $rec->getVar('nl_langid');
         $uselid = $first_id;
         foreach ($ts as $tlid => $t) {
             if ($langid === $tlid) {
                 $uselid = $tlid;
                 break;
             }
         }
         $iso = GWF_Language::getISOByID($uselid);
         $receive_mail = $rec->getVar('nl_email');
         self::notice("Sending EMail to {$receive_mail} ({$iso})");
         $title = GWF_HTML::display($ts[$uselid]['newst_title']);
         $message = GWF_Message::display($ts[$uselid]['newst_message'], true, false, false);
         $username = GWF_HTML::display($rec->getUsername());
         $unsign = $unsign = $rec->getUnsignAnchor();
         $body = $module->langISO($iso, 'newsletter_wrap', array($username, $unsign, $title, $message));
         $mail = new GWF_Mail();
         $mail->setSender($sender_mail);
         $mail->setReceiver($receive_mail);
         $mail->setSubject($module->langISO($iso, 'newsletter_title'));
         $mail->setBody($body);
         //			if (GWF_DEBUG_EMAIL) {
         //				$success = true;
         //			}
         //			else
         //			{
         if (false !== ($user = $rec->getUser())) {
             $success = $mail->sendToUser($user);
         }
         //			}
         //			else if ($rec->isHTML()) {
         //				$success = $mail->sendAsHTML();
         //			} else {
         //				$success = $mail->sendAsText();
         //			}
         if (!$success) {
             self::error("Can not send email to {$receive_mail}.");
             return;
         } else {
             $rec->setBeenMailed($newsid);
         }
         usleep($micros);
         //			return;
     }
     $db->free($result);
     $item->saveOption(GWF_News::MAILED, true);
 }