/** * save one post * @param integer $id_forum id forum of the post * @param integer $id_post id post of the current post if editing of 0 if adding * @return mixed boolean or $id_post id post of the editing post or the id of the post created */ public function save($id_forum, $id_post = 0) { $gJConfig = jApp::config(); if (jAuth::isConnected()) { $form = jForms::fill('havefnubb~posts', $id_post); $id_user = jAuth::getUserSession()->id; } elseif ($gJConfig->havefnubb['anonymous_post_authorized'] == 1) { $form = jForms::fill('havefnubb~posts_anonym', $id_post); $id_user = 0; } if (!$form or !$form->check()) { return false; } //.. if the data are ok ; we get them ! $subject = $form->getData('subject'); $message = $form->getData('message'); if (count($message) > $gJConfig->havefnubb['post_max_size'] and $gJConfig->havefnubb['post_max_size'] > 0) { jMessage::add(jLocale::get('havefnubb~main.message.exceed.maximum.size', array($gJConfig->havefnubb['post_max_size'])), 'error'); return false; } //CreateRecord object $dao = jDao::get('havefnubb~posts'); $datePost = time(); // create a post if ($id_post == 0) { jEvent::notify('HfnuPostBeforeSave', array('id' => $id_post)); $record = jDao::createRecord('havefnubb~posts'); $record->subject = $subject; $record->message = $message; $record->id_post = $id_post; $record->id_user = $id_user; $record->id_forum = $id_forum; $record->thread_id = 0; $record->status = 3; //'opened' $record->date_created = $datePost; $record->date_modified = $datePost; $record->viewed = 0; $record->ispined = 0; $record->iscensored = 0; $record->poster_ip = $_SERVER['REMOTE_ADDR']; //if the current user is a member of a moderator group // we set this post as 'read by moderator' if (jAcl2DbUserGroup::isMemberOfGroup($this->hfAdmin) or jAcl2DbUserGroup::isMemberOfGroup($this->hfModerator)) { $record->read_by_mod = 1; } else { $record->read_by_mod = 0; } $dao->insert($record); $threadDao = jDao::get('havefnubb~threads'); $threadRec = jDao::createRecord('havefnubb~threads'); $threadRec->id_user_thread = $id_user; $threadRec->status_thread = 3; //'opened' $threadRec->id_forum_thread = $id_forum; $threadRec->nb_replies = 0; $threadRec->nb_viewed = 0; $threadRec->id_first_msg = $record->id_post; $threadRec->id_last_msg = $record->id_post; $threadRec->date_created = $datePost; $threadRec->date_last_post = $datePost; $threadRec->ispined_thread = 0; $threadRec->iscensored_thread = 0; $threadDao->insert($threadRec); // now let's get the inserted id to put this one in thread_id column ! $record->thread_id = $threadRec->id_thread; $dao->update($record); $id_post = $record->id_post; $thread_id = $record->thread_id; //update Forum record $forum = jDao::get('havefnubb~forum'); $forumRec = $forum->get($id_forum); $forumRec->id_last_msg = $id_post; $forumRec->date_last_msg = $datePost; $forumRec->nb_msg = $forumRec->nb_msg + 1; $forumRec->nb_thread = $forumRec->nb_thread + 1; $forum->update($forumRec); $this->addPost($id_post, $record); jEvent::notify('HfnuPostAfterInsert', array('id' => $threadRec->id_thread, 'id_forum' => $id_forum)); } else { jEvent::notify('HfnuPostBeforeUpdate', array('id' => $id_post, 'id_forum' => $id_forum)); //remove the id_post of the array $this->deletePost($id_post); $record = $dao->get($id_post); $record->subject = $subject; $record->message = $message; $record->date_modified = time(); $thread_id = $record->thread_id; jEvent::notify('HfnuPostAfterUpdate', array('id' => $id_post, 'id_forum' => $id_forum)); // add the new record to the array $this->addPost($id_post, $record); } // in all cases (id_post = 0 or not ) // we have to update as we store the last insert id in the thread_id column $dao->update($record); jEvent::notify('HfnuPostAfterSave', array('id' => $id_post, 'id_forum' => $id_forum)); jEvent::notify('HfnuSearchEngineAddContent', array('id' => $id_post, 'datasource' => 'havefnubb~posts')); $tagStr = ''; $tagStr = str_replace('.', ' ', $form->getData("tags")); $tags = explode(",", $tagStr); //add this post as already been read jClasses::getService('havefnubb~hfnuread')->insertReadPost($record, $datePost); jClasses::getService("jtags~tags")->saveTagsBySubject($tags, 'forumscope', $id_post); //subscription management if ($form->getData('subscribe') == 1) { jClasses::getService('havefnubb~hfnusub')->subscribe($thread_id); } else { jClasses::getService('havefnubb~hfnusub')->unsubscribe($thread_id); } jForms::destroy('havefnubb~posts', $id_post); return $record; }
public function testIsMemberOfGroup() { $this->assertTrue(jAcl2DbUserGroup::isMemberOfGroup('group1')); $this->assertFalse(jAcl2DbUserGroup::isMemberOfGroup('group2')); }