Redirect to a post in particular
@param $post_id
@return mixed
@throws RunBBException
338390
public function redirectToPost($post_id)
    {
        $post_id = Container::get('hooks')->fire('model.topic.redirect_to_post', $post_id);

        $result['select'] = ['topic_id', 'posted'];

        $result = DB::forTable('posts')
                      ->select_many($result['select'])
                      ->where('id', $post_id);
        $result = Container::get('hooks')->fireDB('model.topic.redirect_to_post_query', $result);
        $result = $result->find_one();

        if (!$result) {
            throw new  RunBBException(__('Bad request'), 404);
        }

        $post['topic_id'] = $result['topic_id'];
        $posted = $result['posted'];

        // Determine on which page the post is located (depending on $forum_user['disp_posts'])
        $num_posts = DB::forTable('posts')
                        ->where('topic_id', $post['topic_id'])
                        ->where_lt('posted', $posted)
                        ->count('id');

        $num_posts = Container::get('hooks')->fire('model.topic.redirect_to_post_num', $num_posts);

        $post['get_p'] = ceil(($num_posts + 1) / User::get()->disp_posts);

        $post = Container::get('hooks')->fire('model.topic.redirect_to_post', $post);

        return $post;
    }
1363604
public function voteMinus($post_id)
    {
        $this->checkId($post_id);

        return $this->vote($post_id, self::VOTE_MINUS);
    }
1014913
protected function processPageId($page_id) {
    $page_ids = array_keys($this->getVisiblePages());

    // Redirect to default page (first page) if no page or invalid page is
    // requested.
    if (empty($page_id) || !in_array($page_id, $page_ids)) {
      $page_id = reset($page_ids);
    }

    return $page_id;
  }
170640
public function getLastVersion($post_id)
	{
		$qb = $this->createQueryBuilder('p');
		
		$qb->where('p.original=:post_id')
			->orderBy('p.createdAt', 'DESC')
			->setParameter(':post_id', $post_id);
		
		$result = $qb->getQuery()->setMaxResults(1)->getResult(Query::HYDRATE_OBJECT);
		
		if ( is_null($result) ) {
			$qb2 = $this->createQueryBuilder('p');
			$qb2->where('p.id=:post_id')->setParameter(':post_id', $post_id);
			
			$result = $qb->getQuery()->getResult(Query::HYDRATE_OBJECT);
		}
		
		return $result;
	}
686201
public function save_post($post_id, \WP_Post $post ){
        // Skip auto save
        if( wp_is_post_revision($post) || wp_is_post_autosave($post) ){
            return;
        }
        // Check Nonce
        if( !$this->verify_nonce() ){
            return;
        }
        // O.K., let's save
        foreach( $this->loop_fields() as $field ){
            try{
                if( is_wp_error($field) ){
                    /** @var \WP_Error $field */
                    throw new \Exception($field->get_error_message(), $field->get_error_code());
                }
                if( !$this->is_override_field($field->name) ){
                    /** @var \WPametu\UI\Field\Base $field */
                    $field->update($this->input->post($field->name), $post);
                }
            }catch ( \Exception $e ){
                $this->prg->addErrorMessage($e->getMessage());
            }

        }
    }
1313266
public function getCommentsForPost($post_id)
    {
        $this->checkId($post_id);

        return $this->adapter->get(sprintf('/comments/%d', $post_id));
    }
954057
public function flagPost($postId, $flag)
	{
		$token = $this->oauth->getToken();

		// Set parameters.
		$parameters = array(
			'oauth_token' => $token['key'],
		);

		// Set the success response code.
		$this->oauth->setOption('success_code', 204);

		// Set the API base
		$base = '/v1/posts/' . $postId . '/category/code';

		// Build xml.
		$xml = '<code>' . $flag . '</code>';

		// Build the request path.
		$path = $this->getOption('api.url') . $base;

		$header['Content-Type'] = 'text/xml';

		// Send the request.
		$response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);

		return $response;
	}
1185190
private function getPost($postid)
    {
        $post = $this->getDoctrine()->getManager()->getRepository('VeonikBlogBundle:AbstractPost')
            ->createQueryBuilder('p')
            ->addSelect('c')
            ->leftJoin('p.comments', 'c')
            ->where('p.id = :post_id')
            ->setParameters(array(
                'post_id' => $postid
            ))
            ->getQuery()
            ->getOneOrNullResult();

        if (!$post) {
            throw $this->createNotFoundException('Unable to locate Post');
        }

        return $post;
    }
391673
private function get_tags( $post_id ) {
		$tag_data = get_the_tags( $post_id );
		$tag_arr  = [];
		if ( $tag_data ) {
			foreach ( $tag_data as $tag ) {
				array_push( $tag_arr, $tag->slug );
			}
		}

		return $tag_arr;
	}
745268
private function loopBody(int $post_id, int $count): string
    {
        $post = $this->post($post_id);

        return

        $this->openPostTag($post, $count).
        $this->thumb('side', $post, $count).
        $this->openHeader($post, $count).
        $this->postInfo('title', 'before', $post, $count).
        $this->title($post, $count).
        $this->postInfo('title', 'after', $post, $count).
        $this->closeHeader($post, $count).
        $this->thumb('top', $post, $count).
        $this->content($post, $count).
        $this->excerpt($post, $count).
        $this->openFooter($post, $count).
        $this->postInfo('excerpt', 'after', $post, $count).
        $this->closeFooter($post, $count).
        $this->closePostTag($post, $count);
    }
1231962
public function actionIndexPost($id=NULL)
	{
		if ($id === NULL)
			return $this->createNewPost();
		else
			return $this->updatePost($id);
	}
1059444
public function run($id)
    {
        $model = $this->getModel($id);
        
        if ($model->restore()) {
            $this->addSuccessFlash();
        }

        return $this->redirect($model);
    }
47964
private function redirect(string $redirect, int $categoryID, int $postTypeID)
    {
        $adminPrefix = Config::get('project')['adminPrefix'];
        if($redirect == 'save') {
            $redirectUrl = "/".$adminPrefix."/".App::getLocale()."/post-type/categoryupdate/".$categoryID;
            $view = 'categoryupdate';
            $redirectID = $categoryID;
        }else if($redirect == 'close') {
            $redirectUrl = "/".$adminPrefix."/".App::getLocale()."/post-type/categorylist/".$postTypeID;
            $view = 'categorylist';
            $redirectID = $postTypeID;
        }else{
            $redirectUrl = "/".$adminPrefix."/".App::getLocale()."/post-type/categorycreate/".$postTypeID;
            $view = 'categorycreate';
            $redirectID = $postTypeID;
        }

        return[
            "url" => $redirectUrl,
            "view" => $view,
            "id" => $redirectID
        ];
    }
1333662
public function save_meta( $post_id, $post ) {

		$this->post = $post;
		$data       = $this->get_data();

		if ( ! $this->is_active() || empty( $data ) ) {
			return;
		}

		// save compiled data
		update_post_meta( $post_id, $this->slug, $data );
		$data = call_user_func_array( 'array_merge', $data );

		foreach ( $data as $meta_key => $meta_value ) {

			$this->save_meta_data( $meta_key, $meta_value );
		}

	}
1345420
protected function _post($id = null)
    {
        $subject = $this->_subject();
        $subject->set(['id' => $id]);

        $entity = $this->_findRecord($id, $subject);

        $event = $this->_trigger('beforeDelete', $subject);
        if ($event->isStopped()) {
            return $this->_stopped($subject);
        }

        $method = $this->getConfig('deleteMethod');
        if ($this->_table()->$method($entity)) {
            $this->_success($subject);
        } else {
            $this->_error($subject);
        }

        return $this->_redirect($subject, ['action' => 'index']);
    }
751734
public function postupdateNotExist($post_id)
    {
        if ($this->countPostUpdates($post_id) == 0)
        {
            DB::table('posts')
                ->where('id', '=', $post_id)
                ->update(['postupdate' => 0])
            ;
        }
    }
948146
public function delete_data( $post_id ) {
		$table = $this->get_related_table_name();
		$this->delete_misc( $post_id );

		return $this->app->db->delete( $table, [
			'post_id' => $post_id,
		] );
	}