示例#1
0
文件: Edit.php 项目: sinfocol/gwf3
 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 '';
 }