Model for posts.

Models don't share that much, so most implementations will be adding methods onto this class. This class simply provides helper methods for common actions.

package XenForo_Post

 Methods

Constructor.

__construct() 
Inherited

Use create() statically unless you know what you're doing.

inherited_from \XenForo_Model::__construct()

Adds a join to the set of fetch options.

addFetchOptionJoin(array $fetchOptions, integer $join) 
Inherited

Join should be one of the constants.

inherited_from \XenForo_Model::addFetchOptionJoin()

Parameters

$fetchOptions

array

$join

integer

Adds the canInlineMod value to the provided post and returns the specific list of inline mod actions that are allowed on this post.

addInlineModOptionToPost(array $post, array $thread, array $forum, array $nodePermissions, array $viewingUser) : array

Parameters

$post

array

Post info

$thread

array

Thread the post is in

$forum

array

Forum the thread/post is in

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

arrayList of allowed inline mod actions, format: [action] => true

Adds the equivalent of a limit clause using position-based limits.

addPositionLimit(string $table, integer $limit, integer $offset, string $column) : string
Inherited

It no limit value is specified, nothing will be returned.

This must be added within a WHERE clause. If a clause is required, it will begin with "AND", so ensure there is a condition before it.

inherited_from \XenForo_Model::addPositionLimit()

Parameters

$table

string

Name of the table alias to prefix. May be blank for no table reference.

$limit

integer

Number of records to limit to; ignored if <= 0

$offset

integer

Offset from the start of the records. 0+

$column

string

Name of the column that is storing the position

Returns

stringPosition limit clause if needed

Sends an alert to members directly quoted in a post

alertQuotedMembers(array $post) 

Parameters

$post

array

Ensures that a valid cut-off operator is passed.

assertValidCutOffOperator(string $operator) 
Inherited

inherited_from \XenForo_Model::assertValidCutOffOperator()

Parameters

$operator

string

Determines if the post can be approved or unapproved with the given permissions.

canApproveUnapprovePost(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check post viewing permissions.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the post can be deleted with the given permissions.

canDeletePost(array $post, array $thread, array $forum, string $deleteType, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check post viewing permissions.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$deleteType

string

The type of deletion requested (soft or hard)

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the post can be edited with the given permissions.

canEditPost(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check post viewing permissions.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the post can be liked with the given permissions.

canLikePost(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check post viewing permissions.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the post can be merged with another with the given permissions.

canMergePost(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check post viewing permissions.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the post can be moved to a new thread with the given permissions.

canMovePost(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check post viewing permissions.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Checks that the viewing user may report the specified post

canReportPost(array $post, array $thread, array $forum, boolean $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

Parameters

$post

array

$thread

array

$forum

array

$errorPhraseKey

boolean

string

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the post can be undeleted with the given permissions.

canUndeletePost(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check post viewing permissions.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if an attachment on this post can be viewed.

canViewAttachmentOnPost(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check post viewing permissions.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the specified user can view IP addresses

canViewIps(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

Parameters

$post

array

$thread

array

$forum

array

$errorPhraseKey

string

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the post can be viewed with the given permissions.

canViewPost(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check thread/forum viewing permissions fully.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the post can be viewed with the given permissions.

canViewPostAndContainer(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

TThis will check that any parent container can be viewed as well.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Determines if the post can be warning with the given permissions.

canWarnPost(array $post, array $thread, array $forum, string $errorPhraseKey, array $nodePermissions, array $viewingUser) : boolean

This does not check post viewing permissions.

Parameters

$post

array

Info about the post

$thread

array

Info about the thread this post is in

$forum

array

Info about the forum the thread is in

$errorPhraseKey

string

Returned phrase key for a specific error

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

boolean

Counts the number of visible posts in the specified thread.

countVisiblePostsInThread(integer $threadId) : integer

This is the reply count + 1.

Parameters

$threadId

integer

Returns

integer

Factory method to get the named model.

create(string $class) : \XenForo_Model
Inherited

The class must exist or be autoloadable or an exception will be thrown.

inherited_from \XenForo_Model::create()

Parameters

$class

string

Class to load

Returns

Helper to delete the specified post, via a soft or hard delete.

deletePost(integer $postId, string $deleteType, array $options, array $forum) : \XenForo_DataWriter_DiscussionMessage_Post

Parameters

$postId

integer

ID of the post to delete

$deleteType

string

Type of deletion (soft or hard)

$options

array

Deletion options.

$forum

array

The forum containing this post

Returns

\XenForo_DataWriter_DiscussionMessage_PostThe DW used to delete the post

Fetches results from the database with each row keyed according to preference.

fetchAllKeyed(string $sql, string $key, mixed $bind, string $nullPrefix) : array
Inherited

The 'key' parameter provides the column name with which to key the result. For example, calling fetchAllKeyed('SELECT item_id, title, date FROM table', 'item_id') would result in an array keyed by item_id: [$itemId] => array('item_id' => $itemId, 'title' => $title, 'date' => $date)

Note that the specified key must exist in the query result, or it will be ignored.

inherited_from \XenForo_Model::fetchAllKeyed()

Parameters

$sql

string

SQL to execute

$key

string

Column with which to key the results array

$bind

mixed

Parameters for the SQL

$nullPrefix

string

If the key is null, prefix the counter with this

Returns

array

Gets the attachments that belong to the given posts, and merges them in with their parent post (in the attachments key).

getAndMergeAttachmentsIntoPosts(array $posts) : array

The attachments key will not be set if no attachments are found for the post.

Parameters

$posts

array

Returns

arrayPosts, with attachments added where necessary

Gets a list of SQL conditions in the format for a clause.

getConditionsForClause(array $sqlConditions) : string
Inherited

This always returns a value that can be used in a clause such as WHERE.

inherited_from \XenForo_Model::getConditionsForClause()

Parameters

$sqlConditions

array

Returns

string

Gets the specified field from a content type, if specified for that type.

getContentTypeField(string $contentType, string $fieldName) : string | false
Inherited

inherited_from \XenForo_Model::getContentTypeField()

Parameters

$contentType

string

$fieldName

string

Returns

stringfalse

Gets the value of the specified field for each content type that has that field.

getContentTypesWithField(string $fieldName) : array
Inherited

inherited_from \XenForo_Model::getContentTypesWithField()

Parameters

$fieldName

string

Returns

arrayFormat: [content type] => field value

Gets the latest post in the specified thread.

getLastPostInThread(integer $threadId, array $fetchOptions) : array | false

Parameters

$threadId

integer

$fetchOptions

array

Collection of options that relate to fetching

Returns

arrayfalse

Gets the specified model object from the cache.

getModelFromCache(string $class) : \XenForo_Model
Inherited

If it does not exist, it will be instantiated.

inherited_from \XenForo_Model::getModelFromCache()

Parameters

$class

string

Name of the class to load

Returns

Returns the newest posts for a specified thread, after the specified date.

getNewestPostsInThreadAfterDate(integer $threadId, integer $postDate, array $fetchOptions) : array

Posts are returned newest first.

Parameters

$threadId

integer

$postDate

integer

$fetchOptions

array

Returns

array

Gets the next post in a thread, post after the specified date.

getNextPostInThread(integer $threadId, integer $postDate, array $fetchOptions, array $ignoredUserIds) : array | false

This is useful for finding the first unread post in a thread, for example.

Parameters

$threadId

integer

$postDate

integer

Finds first post posted after this

$fetchOptions

array

Collection of options that relate to fetching

$ignoredUserIds

Returns

arrayfalse

Returns the ID of the next post in the given thread after the specified position

getNextPostInThreadByPosition(integer $threadId, integer $position, array $fetchOptions) : array

Parameters

$threadId

integer

$position

integer

$fetchOptions

array

Returns

array

Gets the order by clause for an SQL query.

getOrderByClause(array $choices, array $fetchOptions, string $defaultOrderSql) : string
Inherited

inherited_from \XenForo_Model::getOrderByClause()

Parameters

$choices

array

$fetchOptions

array

$defaultOrderSql

string

Returns

stringOrder by clause or empty string

Gets permission-based options that apply to post fetching functions.

getPermissionBasedPostFetchOptions(array $thread, array $forum, array $nodePermissions, array $viewingUser) : array

Parameters

$thread

array

Thread the posts will belong to

$forum

array

Forum the thread belongs to

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

arrayKeys: deleted/moderated (both booleans)

Gets the named post.

getPostById(integer $postId, array $fetchOptions) : array | false

Parameters

$postId

integer

$fetchOptions

Returns

arrayfalse

Gets post IDs in the specified range.

getPostIdsInRange(integer $start, integer $limit) : array

The IDs returned will be those immediately after the "start" value (not including the start), up to the specified limit.

Parameters

$start

integer

IDs greater than this will be returned

$limit

integer

Number of posts to return

Returns

arrayList of IDs

Gets the message state for a newly inserted post by the viewing user.

getPostInsertMessageState(array $thread, array $forum, array $nodePermissions, array $viewingUser) : string

Parameters

$thread

array

Thread info, may be empty for a new thread

$forum

array

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

stringMessage state (visible, moderated, deleted)

From a list of post IDs, gets info about the posts, their threads, and the forums the threads are in.

getPostsAndParentData(array $postIds, integer $permissionCombinationId) : array

If a permission combination ID is passed, the forums will retrieve permission info.

Parameters

$postIds

array

List of post IDs

$permissionCombinationId

integer

Permission combination ID that will be retrieved with the forums.

Returns

arrayFormat: [0] => list of posts, [1] => list of threads, [2] => list of forums

Gets the specified posts.

getPostsByIds(array $postIds, array $fetchOptions) : array

Parameters

$postIds

array

$fetchOptions

array

Collection of options that relate to fetching

Returns

arrayFormat: [post id] => info

Fetches basic information about all posts made by $userId, except those in threads started by $userId

getPostsByUserInOthersThreads(integer $userId) : array

Parameters

$userId

integer

Returns

array

Returns all posts for a specified thread.

getPostsInThread(integer $threadId, array $fetchOptions) : array

Fetch options may limit posts returned.

Parameters

$threadId

integer

$fetchOptions

array

Collection of options that relate to fetching

Returns

array

Gets simple information about all posts in a thread.

getPostsInThreadSimple(integer $threadId, boolean $includeMessage) : array

This does not include the actual contents of a message unless specifically requested.

Parameters

$threadId

integer

$includeMessage

boolean

If true, includes message contents

Returns

arrayFormat: [post id] => info

Gets the quote text for the specified post.

getQuoteTextForPost(array $post, integer $maxQuoteDepth) : string

Parameters

$post

array

$maxQuoteDepth

integer

Max depth of quoted text (-1 for unlimited)

Returns

string

Checks whether a post is marked as deleted

isDeleted(array $post) : boolean

Parameters

$post

array

Returns

boolean

Checks whether a post is marked as moderated

isModerated(array $post) : boolean

Parameters

$post

array

Returns

boolean

Applies a limit clause to the provided query if a limit value is specified.

limitQueryResults(string $query, integer $limit, integer $offset) : string
Inherited

If the limit value is 0 or less, no clause is applied.

inherited_from \XenForo_Model::limitQueryResults()

Parameters

$query

string

SQL query to run

$limit

integer

Number of records to limit to; ignored if <= 0

$offset

integer

Offset from the start of the records. 0+

Returns

stringQuery with limit applied if necessary

Merges specified posts (from given threads) into a target post and updates the text.

mergePosts(array $posts, array $threads, integer $targetPostId, string $newMessage, array $options) : boolean

The target post must be in the list of given posts.

Parameters

$posts

array

$threads

array

$targetPostId

integer

$newMessage

string

$options

array

Returns

boolean

Moves the specified posts (in the given threads) to a new thread.

movePostsToNewThread(array $posts, array $sourceThreads, array $newThread, array $options) : array | false

The new thread will be created in this function.

Parameters

$posts

array

$sourceThreads

array

$newThread

array

Information about the new thread; first/last/poster info filled in automatically

$options

array

Options to control behavior

Returns

arrayfalseNew thread ID or false

Prepares the limit-related fetching options that can be applied to various queries.

prepareLimitFetchOptions(array $fetchOptions) : array
Inherited

Includes: limit, offset, page, and perPage.

inherited_from \XenForo_Model::prepareLimitFetchOptions()

Parameters

$fetchOptions

array

Unprepared options

Returns

arrayLimit options; keys: limit, offset

Prepares a post for display, generally within the context of a thread.

preparePost(array $post, array $thread, array $forum, array $nodePermissions, array $viewingUser) : array

Parameters

$post

array

Post to prepare

$thread

array

Thread post is in

$forum

array

Forum thread/post is in

$nodePermissions

arraynull

$viewingUser

arraynull

Returns

arrayPrepared version of post

Checks the 'join' key of the incoming array for the presence of the FETCH_x bitfields in this class and returns SQL snippets to join the specified tables if required

preparePostJoinOptions(array $fetchOptions) : array

Parameters

$fetchOptions

array

containing a 'join' integer key build from this class's FETCH_x bitfields

Returns

arrayContaining 'selectFields' and 'joinTables' keys. Example: selectFields = ', user.*, foo.title'; joinTables = ' INNER JOIN foo ON (foo.id = other.id) '

Prepares state related fetch limits, based on the list of conditions.

prepareStateLimitFromConditions(array $fetchOptions, string $table, string $stateField, string $userField) : string
Inherited

Looks for keys "deleted" and "moderated".

inherited_from \XenForo_Model::prepareStateLimitFromConditions()

Parameters

$fetchOptions

array

$table

string

Name of the table to prefix the state and user fields with

$stateField

string

Name of the field that holds the state

$userField

string

Name of the field that holds the user ID

Returns

stringSQL condition to limit state

Recalculates the position of all posts in the thread, and returns info relating to the thread: firstPostId, firstPostDate, firstPostState, lastPostId, visibleCount.

recalculatePostPositionsInThread(integer $threadId) : array

Parameters

$threadId

integer

Returns

array

Reset an entry or the entire local cache.

resetLocalCacheData($name) 
Inherited

This can be used if you know when some cached data has expired.

inherited_from \XenForo_Model::resetLocalCacheData()

Parameters

$name

Sets whether we're allowed to read values from the cache on a model-level.

setAllowCachedRead($allowCachedRead) 
Inherited

This may be controllable on an individual level basis, if the implementation allows it.

inherited_from \XenForo_Model::setAllowCachedRead()

Parameters

$allowCachedRead

boolean

Injects a local cache value.

setLocalCacheData(string $name, $value) 
Inherited

This should only be used if you know what you're doing or for testing purposes!

Note that you cannot get the existing data via the public interface. If you think you need the set data, use a new object. It defaults to empty. :)

inherited_from \XenForo_Model::setLocalCacheData()

Parameters

$name

string

$value

Standardizes a set of node permissions and a user ID to always have appropriate data.

standardizeNodePermissionsAndUserId(integer $nodeId, array | null $permissions, integer | null $userId) 
Inherited

If an invalid permission set or user ID is provided, the current visitor's will be used.

inherited_from \XenForo_Model::standardizeNodePermissionsAndUserId()

Parameters

$nodeId

integer

Node permissions are for

$permissions

arraynull

Permissions for node or null to use current visitor's permissions

$userId

integernull

User permissions belong to or null to use current visitor

Standardizes a permission combination and user ID to always have appropriate data.

standardizePermissionCombinationIdAndUserId(integer | null $permissionCombinationId, integer | null $userId) 
Inherited

If null, users current visitor's values.

inherited_from \XenForo_Model::standardizePermissionCombinationIdAndUserId()

Parameters

$permissionCombinationId

integernull

Permission combination ID or null to use current visitor

$userId

integernull

User permissions belong to or null to use current visitor

Standardizes a set of permissions and a user ID to always have appropriate data.

standardizePermissionsAndUserId(array | null $permissions, integer | null $userId) 
Inherited

If an invalid permission set or user ID is provided, the current visitor's will be used.

inherited_from \XenForo_Model::standardizePermissionsAndUserId()

Parameters

$permissions

arraynull

Global pPermissions or null to use current visitor's permissions

$userId

integernull

User permissions belong to or null to use current visitor

Standardizes a viewing user reference array.

standardizeViewingUserReference(array $viewingUser) 
Inherited

This array must contain all basic user info (preferably all user info) and include global permissions in a "permissions" key. If not an array or missing a user_id, the visitor's values will be used.

inherited_from \XenForo_Model::standardizeViewingUserReference()

Parameters

$viewingUser

arraynull

Standardizes the viewing user reference for the specific node.

standardizeViewingUserReferenceForNode(integer $nodeId, array $viewingUser, array $nodePermissions) 
Inherited

inherited_from \XenForo_Model::standardizeViewingUserReferenceForNode()

Parameters

$nodeId

integer

$viewingUser

arraynull

Viewing user; if null, use visitor

$nodePermissions

arraynull

Permissions for this node; if null, use visitor's

Helper to unserialize permissions in a list of items.

unserializePermissionsInList(array $items, string $serializedKey, string $targetKey) : array
Inherited

inherited_from \XenForo_Model::unserializePermissionsInList()

Parameters

$items

array

List of items

$serializedKey

string

Key where serialized permissions are

$targetKey

string

Key where unserialized permissions will go

Returns

arrayList of items with permissions unserialized

_getAttachmentModel()

_getAttachmentModel() : \XenForo_Model_Attachment

Helper method to get the cache object.

_getCache(boolean $forceCachedRead) : \Zend_Cache_Core | \Zend_Cache_Frontend | false
Inherited

If cache reads are disabled, this will return false.

inherited_from \XenForo_Model::_getCache()

Parameters

$forceCachedRead

boolean

If true, the global "allow cached read" value is ignored

Returns

\Zend_Cache_Core\Zend_Cache_Frontendfalse

Gets the data registry model.

_getDataRegistryModel() : \XenForo_Model_DataRegistry
Inherited

inherited_from \XenForo_Model::_getDataRegistryModel()

Returns

Helper method to get the database object.

_getDb() : \Zend_Db_Adapter_Abstract
Inherited

inherited_from \XenForo_Model::_getDb()

Returns

\Zend_Db_Adapter_Abstract

Gets the named entry from the local cache.

_getLocalCacheData(string $name) : mixed
Inherited

inherited_from \XenForo_Model::_getLocalCacheData()

Parameters

$name

string

Returns

mixed

_getThreadModel()

_getThreadModel() : \XenForo_Model_Thread

_getUserModel()

_getUserModel() : \XenForo_Model_User

 Properties

 

Controls whether a cached read is allowed.

$_allowCachedRead : boolean
Inherited

If not, it should be retrieved from the source.

inherited_from \XenForo_Model::$$_allowCachedRead
 

Cache object

$_cache : \Zend_Cache_Core | \Zend_Cache_Frontend
Inherited

inherited_from \XenForo_Model::$$_cache
 

Database object

$_db : \Zend_Db_Adapter_Abstract
Inherited

inherited_from \XenForo_Model::$$_db
 

Stores local, instance-specific cached data for each model.

$_localCacheData : array
Inherited

This data is generally treated as canonical, even if {$_allowCachedRead} is false.

inherited_from \XenForo_Model::$$_localCacheData
 

Standard approach to caching other model objects for the lifetime of the model.

$_modelCache : array
Inherited

inherited_from \XenForo_Model::$$_modelCache

 Constants

 

FETCH_DELETION_LOG

FETCH_DELETION_LOG 

 

FETCH_FORUM

FETCH_FORUM 

 

FETCH_THREAD

FETCH_THREAD 

 

FETCH_USER

FETCH_USER 

 

FETCH_USER_OPTIONS

FETCH_USER_OPTIONS