Performs new thread with first post creation and subscription.
Saves thread poll.
@return bool
@since 0.2
186829
public function podiumNew()
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            if (!$this->save()) {
                throw new Exception('Thread saving error!');
            }

            $loggedIn = User::loggedId();

            if ($this->pollAdded && Podium::getInstance()->podiumConfig->get('allow_polls')) {
                $poll = new Poll();
                $poll->thread_id = $this->id;
                $poll->question = $this->pollQuestion;
                $poll->votes = $this->pollVotes;
                $poll->hidden = $this->pollHidden;
                $poll->end_at = !empty($this->pollEnd) ? Podium::getInstance()->formatter->asTimestamp($this->pollEnd . ' 23:59:59') : null;
                $poll->author_id = $loggedIn;
                if (!$poll->save()) {
                    throw new Exception('Poll saving error!');
                }

                foreach ($this->pollAnswers as $answer) {
                    $pollAnswer = new PollAnswer();
                    $pollAnswer->poll_id = $poll->id;
                    $pollAnswer->answer = $answer;
                    if (!$pollAnswer->save()) {
                        throw new Exception('Poll Answer saving error!');
                    }
                }
                Log::info('Poll added', $poll->id, __METHOD__);
            }

            $this->forum->updateCounters(['threads' => 1]);

            $post = new Post();
            $post->content = $this->post;
            $post->thread_id = $this->id;
            $post->forum_id = $this->forum_id;
            $post->author_id = $loggedIn;
            $post->likes = 0;
            $post->dislikes = 0;
            if (!$post->save()) {
                throw new Exception('Post saving error!');
            }

            $post->markSeen();
            $this->forum->updateCounters(['posts' => 1]);
            $this->updateCounters(['posts' => 1]);

            $this->touch('new_post_at');
            $this->touch('edited_post_at');

            if ($this->subscribe) {
                $subscription = new Subscription();
                $subscription->user_id = $loggedIn;
                $subscription->thread_id = $this->id;
                $subscription->post_seen = Subscription::POST_SEEN;
                if (!$subscription->save()) {
                    throw new Exception('Subscription saving error!');
                }
            }

            $transaction->commit();
            PodiumCache::clearAfter('newThread');
            Log::info('Thread added', $this->id, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
542719
public function create()
    {
        if ($this->createStatement == null) {
            $this->createStatement = $this->connection->prepare("
            INSERT INTO User (username,mail,password,id,parent) VALUES (?,?,?,?,?)");
            $this->createStatement->bindParam(1, $this->username);
            $this->createStatement->bindParam(2, $this->mail);
            $this->createStatement->bindParam(3, $this->password);
            $this->createStatement->bindParam(4, $this->userId);
            $this->createStatement->bindParam(5, $this->parentID);
        }
        try {
            $this->createStatement->execute();
        } catch (PDOException $e) {
            return false;
        }
        $this->setInitialValues();
        return $this->exists();
    }
918328
public function newAction()
    {
        $entity = new Post();
        $form   = $this->createForm(new PostType(), $entity);

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
        );
    }
174750
public function onBeforeWrite()
    {
        // save submitter if a Member is logged in
        $currentMember = Security::getCurrentUser();
        if (!$this->SubmitterID && $currentMember) {
            $this->SubmitterID = $currentMember->ID;
        }

        parent::onBeforeWrite();
    }
917571
public function postCreate()
    {

        // Check if we should store creations in our revision history
        // Set this value to true in your model if you want to
        if(empty($this->revisionCreationsEnabled))
        {
            // We should not store creations.
            return false;
        }

        if ((!isset($this->revisionEnabled) || $this->revisionEnabled))
        {
            $revisions[] = array(
                'revisionable_type' => $this->getMorphClass(),
                'revisionable_id' => $this->getKey(),
                'key' => self::CREATED_AT,
                'old_value' => null,
                'new_value' => $this->{self::CREATED_AT},
                'user_id' => $this->getSystemUserId(),
                'created_at' => new \DateTime(),
                'updated_at' => new \DateTime(),
            );

            $revision = static::newModel();
            \DB::table($revision->getTable())->insert($revisions);
        }
    }
543049
public function threadsWithNewMessages()
    {
        return $this->threads()
            ->where(function (Builder $q) {
                $q->whereIn(Models::table('threads') . '.id', $this->unreadMessages()->pluck('thread_id'));
            })
            ->get();
    }
1215320
public function getNewestInThread()
    {
        $newest = $this;
        $next_reply = function ($message) use (&$next_reply, &$newest)
        {
            if ($message->getReplies()) {
                foreach ($message->getReplies() as $r) {
                    $next_reply($r);
                }
            }
            if ($message->getCreatedAt() > $newest->getCreatedAt()) {
                $newest = $message;
            }
        };

        $next_reply($this);
        return $newest;
    }
1250963
public function poll()
    {
        foreach($this->getDatabases() as $db)
        {
            $this->handleStatusAlerts($db);

            if ($db['status']) {
                $this->handleSizeAlerts($db);

                History::create(['type' => 'database',
                                 'meta' => $db['connection'],
                                 'record' => [],
                                 'value' => $db['size']]);
            }
        }
    }
1338185
public function podiumDelete()
    {
        $transaction = Thread::getDb()->beginTransaction();
        try {
            if (!$this->delete()) {
                throw new Exception('Thread deleting error!');
            }
            $this->forum->updateCounters([
                'threads' => -1,
                'posts'   => -$this->postsCount
            ]);
            $transaction->commit();
            PodiumCache::clearAfter('threadDelete');
            Log::info('Thread deleted', $this->id, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
558606
private function create()
    {
        $response = $this->sendRequest(
            self::METHOD_POST,
            self::$endPoints['create'],
            $this->requestData
        );
        $this->resetRequestData();
        return $response;
    }
137512
public function poll()
    {
        $this->checkForNewSchedulers();

        foreach ($this->getMissedSchedules() as $scheduler) {
            $this->notifyIfChanges($scheduler);
            $this->setNextSchedule($scheduler);
        }

        foreach ($this->getOverdueNoExitSchedules() as $history) {
            $history->output = "No finish ping received by Eyewitness";
            $history->exitcode = 1;
            $history->save();

            if ($history->scheduler->alert_on_fail || ($history->scheduler->alert_run_time_greater_than > 0)) {
                $this->eye->notifier()->alert(new Overdue(['scheduler' => $history->scheduler]));
            }
        }

        foreach ($this->getConditionalSchedules() as $scheduler) {
            if ($this->hasNotRunInGivenTimeframe($scheduler)) {
                $this->notifyIfChanges($scheduler);
            }
        }
    }
982328
public function podiumEdit($isFirstPost = false)
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            $this->edited = 1;
            $this->touch('edited_at');
            if (!$this->save()) {
                throw new Exception('Post saving error!');
            }
            if ($isFirstPost) {
                $this->thread->name = $this->topic;
                if (!$this->thread->save()) {
                    throw new Exception('Thread saving error!');
                }
            }
            $this->markSeen();
            $this->thread->touch('edited_post_at');

            $transaction->commit();
            Log::info('Post updated', $this->id, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
1094867
public function create()
    {
        if (!userHasPermission('admin:blog:post:' . $this->blog->id . ':create')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        //  Set method info
        $this->data['page']->title = 'Create New ' . ucfirst($this->data['postName']);

        // --------------------------------------------------------------------------

        //  Process POST
        if ($this->input->post()) {

            //  Are we running in preview mode?
            $bIsPreview = (bool) $this->input->post('isPreview');

            //  Only validate non-previews
            if (empty($bIsPreview)) {

                $oFormValidation = Factory::service('FormValidation');

                $oFormValidation->set_rules('is_published', '', '');
                $oFormValidation->set_rules('published', '', '');
                $oFormValidation->set_rules('title', '', 'required');
                $oFormValidation->set_rules('type', '', 'required');
                $oFormValidation->set_rules('body', '', 'required');
                $oFormValidation->set_rules('excerpt', '', '');
                $oFormValidation->set_rules('image_id', '', '');
                $oFormValidation->set_rules('video_url', '', '');
                $oFormValidation->set_rules('audio_url', '', '');
                $oFormValidation->set_rules('seo_description', '', '');
                $oFormValidation->set_rules('seo_keywords', '', '');

                if ($this->input->post('slug')) {

                    $sTable = $this->blog_post_model->getTableName();
                    $oFormValidation->set_rules(
                        'slug',
                        '',
                        'trim|alpha_dash|is_unique[' . $sTable . '.slug]'
                    );
                }

                if ($this->input->post('type') === 'PHOTO') {

                    $oFormValidation->set_rules('image_id', '', 'required');

                } elseif ($this->input->post('type') === 'VIDEO') {

                    $oFormValidation->set_rules('video_url', '', 'required');

                } elseif ($this->input->post('type') === 'AUDIO') {

                    $oFormValidation->set_rules('audio_url', '', 'required');
                }

                $oFormValidation->set_message('required', lang('fv_required'));
                $oFormValidation->set_message('alpha_dash', lang('fv_alpha_dash'));
                $oFormValidation->set_message('is_unique', 'A post using this slug already exists.');

            }

            if (!empty($bIsPreview) || $oFormValidation->run($this)) {

                //  Prepare data
                $aData                     = array();
                $aData['blog_id']          = $this->blog->id;
                $aData['title']            = $this->input->post('title');
                $aData['type']             = $this->input->post('type');
                $aData['slug']             = $this->input->post('slug');
                $aData['excerpt']          = $this->input->post('excerpt');
                $aData['image_id']         = (int) $this->input->post('image_id');
                $aData['image_id']         = $aData['image_id'] ? $aData['image_id'] : null;
                $aData['video_url']        = trim($this->input->post('video_url'));
                $aData['video_url']        = $aData['video_url'] ? $aData['video_url'] : null;
                $aData['audio_url']        = trim($this->input->post('audio_url'));
                $aData['audio_url']        = $aData['audio_url'] ? $aData['audio_url'] : null;
                $aData['body']             = $this->input->post('body');
                $aData['seo_description']  = $this->input->post('seo_description');
                $aData['seo_keywords']     = $this->input->post('seo_keywords');
                $aData['is_published']     = (bool) $this->input->post('is_published');
                $aData['published']        = $this->input->post('published');
                $aData['associations']     = $this->input->post('associations');
                $aData['gallery']          = $this->input->post('gallery');
                $aData['comments_enabled'] = $this->input->post('comments_enabled');
                $aData['comments_expire']  = $this->input->post('comments_expire');

                if (appSetting('categories_enabled', 'blog-' . $this->blog->id)) {

                    $aData['categories'] = $this->input->post('categories');
                }

                if (appSetting('tags_enabled', 'blog-' . $this->blog->id)) {

                    $aData['tags'] = $this->input->post('tags');
                }

                //  Are we running in preview mode?
                if (!empty($bIsPreview)) {

                    //  Previewing, set the preview tables and create a new one
                    $aData['blog_id'] = $this->blog->id;
                    $this->blog_post_model->usePreviewTables(true);
                    $iPostId = $this->blog_post_model->create($aData);

                } else {

                    //  Normal behaviour
                    $iPostId = $this->blog_post_model->create($aData);
                }

                if (!empty($iPostId)) {

                    //  Behave slightly differently depending on whether we're previewing or not
                    if (empty($bIsPreview)) {

                        //  Update admin changelog
                        $this->oChangeLogModel->add(
                            'created',
                            'a',
                            'blog post',
                            $iPostId,
                            $aData['title'],
                            'admin/blog/post/edit/' . $this->blog->id . '/' . $iPostId
                        );

                        $this->session->set_flashdata('success', ucfirst($this->data['postName']) . ' was created.');
                        $sRedirectUrl = 'admin/blog/post/edit/' . $this->blog->id . '/' . $iPostId;

                    } else {

                        $sRedirectUrl = $this->blog->url . '/preview/' . $iPostId;
                    }

                    redirect($sRedirectUrl);

                } else {

                    $this->data['error']  = 'An error occurred and the post could not be created. ';
                    $this->data['error'] .= $this->blog_post_model->lastError();
                }

            } else {

                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        //  Load Categories and Tags
        if (appSetting('categories_enabled', 'blog-' . $this->blog->id)) {

            $aData            = array();
            $aData['where']   = array();
            $aData['where'][] = array('column' => 'blog_id', 'value' => $this->blog->id);

            $this->data['categories'] = $this->blog_category_model->getAll(null, null, $aData);
        }

        if (appSetting('tags_enabled', 'blog-' . $this->blog->id)) {

            $aData            = array();
            $aData['where']   = array();
            $aData['where'][] = array('column' => 'blog_id', 'value' => $this->blog->id);

            $this->data['tags'] = $this->blog_tag_model->getAll(null, null, $aData);
        }

        // --------------------------------------------------------------------------

        //  Load other data
        $oCdn                            = Factory::service('Cdn', 'nails/module-cdn');
        $this->data['associations']      = $this->blog_model->getAssociations();
        $this->data['cdnUrlScaleScheme'] = $oCdn->urlScaleScheme();

        // --------------------------------------------------------------------------

        //  Load assets
        $oAsset = Factory::service('Asset');
        $oAsset->library('uploadify');
        $oAsset->library('MUSTACHE');
        $oAsset->load('moment/moment.js', 'NAILS-BOWER');
        $oAsset->load('admin.post.edit.min.js', 'nails/module-blog');

        // --------------------------------------------------------------------------

        $sInlineJs  = 'var _EDIT;';
        $sInlineJs .= '$(function()';
        $sInlineJs .= '{';
        $sInlineJs .= '    _EDIT = new NAILS_Admin_Blog_Create_Edit(\'CREATE\');';
        $sInlineJs .= '    _EDIT.init(' . $this->blog->id . ', "' . $oCdn->generateApiUploadToken() . '");';
        $sInlineJs .= '});';

        $oAsset->inline($sInlineJs, 'JS');

        // --------------------------------------------------------------------------

        Helper::loadView('edit');
    }
246912
public function tick()
    {
        $this->cleanup();

        if ((count($this->threads) < $this->queueSize) && count($this->jobs)) {
            $this->threads[] = $szal = new Thread($this->callable, $this->message_length);
            $szal->start(array_shift($this->jobs));
        }

        usleep(ThreadQueue::TICK_DELAY);
        return $this->queueSize();
    }
1333326
public static function add($thread)
    {
        if (Podium::getInstance()->user->isGuest) {
            return false;
        }
        $sub = new Subscription();
        $sub->thread_id = $thread;
        $sub->user_id = User::loggedId();
        $sub->post_seen = self::POST_SEEN;
        return $sub->save();
    }
766491
protected function Perform()
    {
        $bSuccess = true;

        $this->PreArticleListHandling();
        $this->HandleArticleList();
        $this->PostArticleListHandling();

        return $bSuccess;
    }
1238560
public function save() {
		if (!isset($this->new_album)) {
			$this->new_album = 1;
		}

		if (!isset($this->last_notified)) {
			$this->last_notified = 0;
		}

		if (!parent::save()) {
			return false;
		}

		mkdir(tp_get_img_dir($this->guid), 0755, true);

		return true;
	}