Documentation

Post2 extends Post
in package
Uses BackwardCompatibility

This class handles posting and modifying replies and new topics.

Table of Contents

Constants

INTENT_EDIT_POST  = 2
INTENT_NEW_REPLY  = 1
INTENT_NEW_TOPIC  = 0
Constants to indicate what the user intends to do with this post.

Properties

$authorIsGuest  : bool
$becomes_approved  : bool
$can_approve  : bool
$errors  : array<string|int, mixed>
$form_message  : string
$form_subject  : string
$intent  : int
$minor_errors  : array<string|int, mixed>
$subaction  : string
$subactions  : array<string|int, mixed>
$board_list  : array<string|int, mixed>
$boards  : array<string|int, mixed>
$counter  : int
$existing_msg  : object
$locked  : bool
$moderation_action  : bool
$obj  : object
$backcompat  : array<string|int, mixed>

Methods

call()  : void
Convenience method to load() and execute() an instance of this class.
execute()  : void
Dispatcher to whichever sub-action method is necessary.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
load()  : object
Static wrapper for constructor.
post()  : void
Backward compatibility wrapper.
show()  : void
Handles showing the post screen, loading the post to be modified, and loading any post quoted.
submit()  : void
Posts or saves the message composed with Post::show().
__construct()  : mixed
Constructor. Protected to force instantiation via self::load().
checkForErrors()  : void
checkForNewReplies()  : void
checkVerification()  : void
getTopicSummary()  : void
Get the topic for display purposes.
initiateEvent()  : void
initiateNewTopic()  : void
initiatePoll()  : void
initiateReply()  : void
loadDrafts()  : void
loadEditor()  : void
Load a new editor instance.
loadNotifyPrefs()  : void
Get notification preferences for later use.
loadTopic()  : void
Loads the topic that is being replied to.
prepareEdit()  : void
prepareNewReply()  : void
prepareNewTopic()  : void
setBoards()  : void
Sets the values of $this->boards and, if applicable, $this->board_list.
setLinktree()  : void
setMessageIcons()  : void
setPageTitle()  : void
setResponsePrefix()  : void
setupPostingFields()  : void
showAttachments()  : void
showEdit()  : void
showNew()  : void
showPreview()  : void
showVerification()  : void
submitAttachments()  : void

Constants

INTENT_EDIT_POST

public mixed INTENT_EDIT_POST = 2

INTENT_NEW_REPLY

public mixed INTENT_NEW_REPLY = 1

INTENT_NEW_TOPIC

Constants to indicate what the user intends to do with this post.

public mixed INTENT_NEW_TOPIC = 0

Properties

$authorIsGuest

public bool $authorIsGuest = true

Whether the author of this post is a guest.

This might not be the same as whether the current user is a guest, because moderators can edit other people's posts.

$becomes_approved

public bool $becomes_approved = true

Whether this post will become approved upon submission.

$can_approve

public bool $can_approve = false

Whether the current user can approve posts.

$errors

public array<string|int, mixed> $errors = []

Errors encountered while trying to post.

$form_message

public string $form_message = ''

The message body string to show in the editor form.

$form_subject

public string $form_subject = ''

The subject string to show in the editor form.

$intent

public int $intent = self::INTENT_NEW_TOPIC

What is the user trying to do with this post?

$minor_errors

public array<string|int, mixed> $minor_errors = ['not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject', 'topic_locked', 'topic_unlocked', 'topic_stickied', 'topic_unstickied', 'cannot_post_attachment']

There are two error types: serious and minor. Serious errors actually tell the user that a real error has occurred, while minor errors are like warnings that let them know that something with their post isn't right.

$subaction

public string $subaction = 'submit'

The sub-action to call.

$subactions

public static array<string|int, mixed> $subactions = ['submit' => 'submit', 'show' => 'show']

Available sub-actions.

$board_list

protected array<string|int, mixed> $board_list = []

A list of categories and boards produced by MessageIndex::getBoardList(). Not used if a board was specified in the URL parameters.

$boards

protected array<string|int, mixed> $boards = []

The boards that this post can be submitted to.

If a board was specified in the URL parameters, this will contain the ID of that board. Otherwise, it will contain a list of boards that the user is allowed to post in.

$counter

protected int $counter = 0

Used by getTopicSummary() method to count previous posts.

$existing_msg

protected object $existing_msg

An instance of SMF\Msg for the existing post. Only used when editing a post.

$locked

protected bool $locked = false

Whether the current topic is locked.

$moderation_action

protected bool $moderation_action

Whether this edit is a moderation action.

$obj

protected static object $obj

An instance of this class. This is used by the load() method to prevent mulitple instantiations.

$backcompat

private static array<string|int, mixed> $backcompat = ['func_names' => ['call' => 'Post2']]

BackwardCompatibility settings for this class.

Methods

call()

Convenience method to load() and execute() an instance of this class.

public static call() : void

execute()

Dispatcher to whichever sub-action method is necessary.

public execute() : void

exportStatic()

Provides a way to export a class's public static properties and methods to global namespace.

public static exportStatic() : void

To do so:

  1. Use this trait in the class.
  2. At the END of the class's file, call its exportStatic() method.

Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.

Regarding the $backcompat items:

A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].

$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.

$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.

Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.

load()

Static wrapper for constructor.

public static load() : object
Return values
object

An instance of this class.

post()

Backward compatibility wrapper.

public static post([mixed $post_errors = [] ]) : void

Needed to allow old mods to pass $post_errors as a function parameter.

Parameters
$post_errors : mixed = []

show()

Handles showing the post screen, loading the post to be modified, and loading any post quoted.

public show() : void

Additionally handles previews of posts. Uses the Post template and language file, main sub template. Requires different permissions depending on the actions, but most notably post_new, post_reply_own, and post_reply_any. Shows options for the editing and posting of calendar events and attachments, as well as the posting of polls. Accessed from ?action=post.

submit()

Posts or saves the message composed with Post::show().

public submit() : void

Requires various permissions depending on the action. Handles attachment, post, and calendar saving. Sends off notifications, and allows for announcements and moderation. Accessed from ?action=post2.

__construct()

Constructor. Protected to force instantiation via self::load().

protected __construct() : mixed

checkForErrors()

protected checkForErrors() : void

checkForNewReplies()

protected checkForNewReplies() : void

checkVerification()

protected checkVerification() : void

getTopicSummary()

Get the topic for display purposes.

protected getTopicSummary() : void

Gets a summary of the most recent posts in a topic. Depends on the topicSummaryPosts setting. If you are editing a post, only shows posts previous to that post. Puts results into Utils::$context['previous_posts'].

initiateEvent()

protected initiateEvent() : void

initiateNewTopic()

protected initiateNewTopic() : void

initiatePoll()

protected initiatePoll() : void

initiateReply()

protected initiateReply() : void

loadDrafts()

protected loadDrafts() : void

loadEditor()

Load a new editor instance.

protected loadEditor() : void

loadNotifyPrefs()

Get notification preferences for later use.

protected loadNotifyPrefs() : void

Puts results in Utils::$context['notify'], Utils::$context['auto_notify'], and Utils::$context['notify_prefs'].

loadTopic()

Loads the topic that is being replied to.

protected loadTopic() : void

If necessary, finds the topic ID based on $_REQUEST['msg'].

prepareEdit()

protected prepareEdit() : void

prepareNewReply()

protected prepareNewReply() : void

prepareNewTopic()

protected prepareNewTopic() : void

setBoards()

Sets the values of $this->boards and, if applicable, $this->board_list.

protected setBoards() : void

setLinktree()

protected setLinktree() : void

setMessageIcons()

protected setMessageIcons() : void

setPageTitle()

protected setPageTitle() : void

setResponsePrefix()

protected setResponsePrefix() : void

setupPostingFields()

protected setupPostingFields() : void

showAttachments()

protected showAttachments() : void

showEdit()

protected showEdit() : void

showNew()

protected showNew() : void

showPreview()

protected showPreview() : void

showVerification()

protected showVerification() : void

submitAttachments()

protected submitAttachments() : void

        
On this page

Search results