abstract class vB_Library_Content extends vB_Library

vB_Library_Content

Traits

Constants

ACTION_ADD

ACTION_UPDATE

ACTION_VIEW

ACTION_DELETE

ACTION_APPROVE

ACTION_PUBLISH

CACHELEVEL_NODE

CACHELEVEL_CONTENT

CACHELEVEL_FULLCONTENT

Properties

static protected $instance from vB_Library
protected $contenttype
protected $contenttypeid
protected $tablename
protected $index_fields
protected $textCountChange
protected $inheritViewPerms
protected $inlist
protected $showSignature
protected $doFloodCheck
protected $assertor
protected $nodeApi
protected $nodeLibrary
static protected $cacheNodes Whether we are caching node content
protected $channelTypeId
protected $cannotDelete
protected $qryAfterAdd
protected $allCanview
protected bool $includeInUserPostCount If true, then creating a node of this content type will increment the user's post count. If false, it will not. Generally, this should be true for topic starters and replies, and false for everything else.
static protected $defaultNodeOptions
protected bool $doIncompleteNodeCleanup

Methods

__sleep()

No description

__wakeup()

No description

__construct()

No description

static vB_PageCache
instance($class)

Returns singleton instance of self.

static 
getLibraryClassNameInternal($controller)

No description

static 
getContentInstance($contenttypeid)

No description

static 
clearCache()

No description

reloadOptions()

Reload options from datastore. Currently only used by unit tests.

fetchContentType()

No description

getAllCanView()

No description

fetchContentTypeId()

No description

int
getTextCountChange()

Returns textCountChange property

int
getInlist()

Returns inlist property

add(mixed $data, array $options = array())

Adds a new node.

beforeCommit($nodeid, $data, $options, $cacheEvents, $nodevals)

Called by the first child class just before the commit happens.

afterAdd(int $nodeid, mixed $data, mixed $options, mixed $cacheEvents, mixed $nodevals)

Operations to be done after adding a node. Putting actions here allow child classes to minimize time keeping transaction open.

sendModeratorNotification($nodeid)

Sends emails to moderators configured in admincp

needsFloodCheck($data, $options)

No description

checkFloodAndThrowException($data)

No description

string|boolean
duplicateCheck(array $data)

Checks accidental duplicate posting

updateNodeOptions($nodeid, $data)

Sets node options from individual fields.

incrementUserPostCount(array $node)

Increments the number of posts for a user. This function will also update user's "lastpost" field

decrementUserPostCount(array $node, (unpublish|unapprove) $action = '')

Decrements the number of posts for a user

resetCountCalled()

Reset the called array- this makes sure we only increment/decrement user post counts once for a given node This is only needed by the unit tests.

boolean
countInUserPostCount(array $node, (unpublish|unapprove) $action = '')

Checks if the current node should be counted in the user post count for the author.

boolean
shouldChangeUserPostCountForChildNodes(array $node, (unpublish|unapprove) $action = '')

Checks whether or not we should adjust user post count for descendant nodes

boolean
delete(array|int $nodeids)

Permanently deletes a node

deleteChildren(array $childrenIds)

Delete the records without updating the parent info. It is used when deleting a whole channel and it's children need to be removed

bool
isPublished(mixed $data)

Is this record in a published state based on the times?

update(int $nodeid, array $data)

updates a record

static mixed
getContentApi(int $contenttypeid)

Returns a content api of the appropriate type

static mixed
getContentLib(int $contenttypeid)

Returns a content api of the appropriate type

int
getContent($nodeids)

Returns the node content as an associative array

Array[Int]
getBareContent(integer $nodeids)

Returns the node content plus the channel routeid and title, and starter route and title the as an associative array Caller MUST ensure that $nodeids are of the correct content type.

array
getFullContent($nodeids)

Returns the node content plus the channel routeid and title, and starter route and title the as an associative array

array
getRawContent($nodeids)

Prepares basic content. Used by both getBareContent and getFullContent.

bool
getCanEdit(int $node, int $userContext = null, mixed $channelPerms = array())

Determines whether the current user can edit a node

bool
getCanDelete(mixed $node, int $userContext = null, mixed $channelPerms = array(), bool $hard = false)

Determines whether the current user can soft-delete or hard-delete

bool
getCanModerate(mixed $node, object $userContext = null, mixed $channelPerms = array(), int $nodeid = 0)

Determines whether the current user can moderate

Array
assembleContent(Array $content)

Assembles the response for detailed content

getIndexableFromNode($node, $include_attachments = true)

No description

array
getIndexableContent($nodeId, $include_attachments = true)

The classes that inherit this should implement this function It should return the content that should be indexed If there is a title field, the array key for that field should be 'title', the rest of the text can have any key

int
getStarter(int $nodeid)

Gets the conversation starter for a node. If the node is a channel it returns the channelid.

array
getConversationParent(int $nodeid)

Gets the conversation starter for a node. If the node is a channel it returns the channel record.

bool
isVisitorMessage(int $nodeid)

determines whether a specific node is a visitor message

bool
isComment(int $nodeid, array $node = null)

Determines whether a specific node is a comment on a thread reply or not

getIndexableContentForAttachments($nodeId)

Get the indexable content for attachments. Separate this so that child classes can rewrite getIndexableContent entirely without having to copy as much code

Array
fetchTableName()

returns the tables used by this content type.

static array('found'
fetchFromCache(array|int $nodeids, integer $level)

This attempts to get the cached data for nodes

static void
writeToCache($nodes, $level)

writes new cached data for nodes

verifyPrefixid($prefixid)

No description

verifyPostIconid(int $posticonid)

Verifies that the post iconid is valid

changeContentType($nodeid, $oldcontentType, $newcontentType)

No description

string
getDuplicateHash(array $data)

Calculates the CRC based on the indexable content

fillContentTableData($node)

No description

none
removePrivateDataFromNode(array $node)

Examines the node record returned from the node library and determines if any information needs to be removed before passing beyond the API layer.

bool
checkComplete(array $node)

This function checks to see if a node is valid, and if not it deletes or fixes it.

boolean
getCannotDelete()

Whether this type can be deleted. Infractions, for example, cannot be.

bool
getNodeClean(integer $node)

Checks to see if the node has all the required data.

bool
incompleteNodeCleanup(mixed $node)

This cleans up for a node that was found to be incomplete by deleting the child nodes and subsidiary table records. It is often overridden in child classes.

setDoIncompleteNodeCleanup(bool $value)

Sets the $doIncompleteNodeCleanup flag

handleAttachments($type, $nodeid, $data, $options = array())

This function needs to be implemented by sub classes that want to handle attachments. See the text library implementation for the full description.

mergeContentInfo($result, $content)

No description

bool
validate($data, $action = self::ACTION_ADD, $nodeid = false, $nodes = false, $userid = null)

Validates that the current can create a node with these values

Details

in vB_Trait_NoSerialize at line 15
__sleep()

in vB_Trait_NoSerialize at line 20
__wakeup()

at line 128
protected __construct()

in vB_Library at line 35
static vB_PageCache instance($class)

Returns singleton instance of self.

Parameters

$class

Return Value

vB_PageCache
  • Reference to singleton instance of the cache handler

in vB_Library at line 52
static protected getLibraryClassNameInternal($controller)

Parameters

$controller

in vB_Library at line 91
static getContentInstance($contenttypeid)

Parameters

$contenttypeid

in vB_Library at line 99
static clearCache()

at line 158
reloadOptions()

Reload options from datastore. Currently only used by unit tests.

at line 163
fetchContentType()

at line 172
getAllCanView()

at line 177
fetchContentTypeId()

at line 186
int getTextCountChange()

Returns textCountChange property

Return Value

int

at line 195
int getInlist()

Returns inlist property

Return Value

int

at line 252
add(mixed $data, array $options = array())

Adds a new node.

Parameters

mixed $data Array of field => value pairs which define the record. Data-types & key names: int 'parentid' Nodeid of the parent, i.e. node this attachment is being added under. int 'userid' Optional. Userid of the user who is adding this record. If not provided, it will use the current session's user. string 'authorname' Optional. Name of the user who is adding this record. If not provided, it will use the username of userid above. string 'ipaddress' Optional. IP of request. Will be fetched from current request if skipped. ??? 'protected' ??? int 'starter' ??? int 'routeid' ??? ??? 'prefixid' ??? ??? 'iconid' ??? int 'created' Optional. Unix timestamp of creation date. If skipped it will use the value returned by vB::getRequest()->getTimeNow() (TIMENOW). int 'publishdate' Optional. Unix timestampe of publish date. If skipped, it will use TIMENOW. If 'publish_now' is provided, publishdate will be overwritten by TIMENOW mixed 'publish_now' Optional. If not empty, publishdate will be overwritten by TIMENOW ??? 'viewperms' ??? ??? 'featured' Optional. ???(purpose/description)??? Will only be used if the CURRENT USER has the moderatorpermissions.cansetfeatured channel permission. string 'title' ??? string 'htmltitle' ??? string 'urlident' ??? int 'setfor' Only used by visitor messages. Userid of intended visitor message recipient. ??? ??? ??? Can also contain node fields. see vB_Library_Node::getNodeFields() or the node table structure for these fields
array $options Array of options for the content being created. Understands skipTransaction, skipFloodCheck, floodchecktime, many subclasses have skipNotification.

@return mixed       array with nodeid (int), success (bool), cacheEvents (array of strings), nodeVals (array of field => value).

Exceptions

vB_Exception_Api('need_parent_node') If required $data['parentid'] is empty.
vB_Exception_Api('invalid_request') If parent is closed and CURRENT USER lacks the moderatorpermissions.canmoderateposts channel permission.
vB_Exception_Api('invalid_request') If parent is a category channel and this is not a channel
vB_Exception_Api('cannot_reply_to_redirect') If parent is a "Redirect" content type
vB_Exception_Api('invalid_route_contact_vbulletin_support') If there is no parent routenew record for the ('vB5_Route_Conversation', 'vB5_Route_Article') classes.
vB_Exception_Api('postfloodcheck') If CURRENT USER is not an administrator and the user failed the flood check.
vB_Exception_Api('invalid_data') If not enough data was provided to add anything to the node table.
vB_Exception_Api('invalid_data') If this is a visitor message and $data['setfor'] was invalid
vB_Exception_Api('invalid_data') If adding a record to the node tabled failed

at line 852
protected beforeCommit($nodeid, $data, $options, $cacheEvents, $nodevals)

Called by the first child class just before the commit happens.

This is for logic that needs to be in the transaction, but relies on the child class having finished all of its processing (the flow is that content::add gets called first and then the child does it's thing, primary because the child needs the nodeid for the created node record).

Takes the same parameters as afterAdd

Parameters

$nodeid
$data
$options
$cacheEvents
$nodevals

at line 877
protected afterAdd(int $nodeid, mixed $data, mixed $options, mixed $cacheEvents, mixed $nodevals)

Operations to be done after adding a node. Putting actions here allow child classes to minimize time keeping transaction open.

Parameters

int $nodeid
mixed $data Array of data being added
mixed $options Array of options for the content being created- passed from add() Understands skipNotification(s), skipUpdateLastContent.
mixed $cacheEvents Array of strings- cache events to be called
mixed $nodevals Array of field => value pairs representing the node table field values passed to create the record. Currently most are not used but all are passed.

at line 1132
protected sendModeratorNotification($nodeid)

Sends emails to moderators configured in admincp

Parameters

$nodeid

at line 1322
protected needsFloodCheck($data, $options)

Parameters

$data
$options

at line 1334
protected checkFloodAndThrowException($data)

Parameters

$data

at line 1366
protected string|boolean duplicateCheck(array $data)

Checks accidental duplicate posting

Parameters

array $data

Return Value

string|boolean hash or false if check skipped

at line 1399
protected updateNodeOptions($nodeid, $data)

Sets node options from individual fields.

@param int

Parameters

$nodeid
$data

at line 1435
incrementUserPostCount(array $node)

Increments the number of posts for a user. This function will also update user's "lastpost" field

When creating items, this is called from the content library, For all other state changes (approve, undelete, etc) it is called from the node library

Parameters

array $node Array of node information for the affected node

at line 1492
decrementUserPostCount(array $node, (unpublish|unapprove) $action = '')

Decrements the number of posts for a user

When hard-deleting items, this is called from the content library, For all other state changes (unapprove, soft-delete, etc) it is called from the node library

Parameters

array $node Array of node information for the affected node
(unpublish|unapprove) $action Pass one of these strings when decrementUserPostCount is called after unpublishing or unapproving a post

at line 1541
resetCountCalled()

Reset the called array- this makes sure we only increment/decrement user post counts once for a given node This is only needed by the unit tests.

at line 1554
protected boolean countInUserPostCount(array $node, (unpublish|unapprove) $action = '')

Checks if the current node should be counted in the user post count for the author.

Parameters

array $node The node
(unpublish|unapprove) $action The action that was just carried out on the node

Return Value

boolean Whether or not the node should be counted in user post count.

at line 1605
protected boolean shouldChangeUserPostCountForChildNodes(array $node, (unpublish|unapprove) $action = '')

Checks whether or not we should adjust user post count for descendant nodes

Parameters

array $node The node
(unpublish|unapprove) $action The action that was just carried out on the node

Return Value

boolean Whether or not the child nodes should be handled

at line 1653
boolean delete(array|int $nodeids)

Permanently deletes a node

Parameters

array|int $nodeids

Return Value

boolean

at line 1805
deleteChildren(array $childrenIds)

Delete the records without updating the parent info. It is used when deleting a whole channel and it's children need to be removed

Parameters

array $childrenIds
  • list of node ids

at line 1822
bool isPublished(mixed $data)

Is this record in a published state based on the times?

Parameters

mixed $data

Return Value

bool

at line 1850
update(int $nodeid, array $data)

updates a record

Parameters

int $nodeid
array $data information to update the content with

@return boolean

at line 2366
static mixed getContentApi(int $contenttypeid)

Returns a content api of the appropriate type

Parameters

int $contenttypeid the content type id

Return Value

mixed content api object

at line 2377
static mixed getContentLib(int $contenttypeid)

Returns a content api of the appropriate type

Parameters

int $contenttypeid the content type id

Return Value

mixed content api object

at line 2395
int getContent($nodeids)

Returns the node content as an associative array

Parameters

$nodeids

Return Value

int

at line 2410
Array[Int] getBareContent(integer $nodeids)

Returns the node content plus the channel routeid and title, and starter route and title the as an associative array Caller MUST ensure that $nodeids are of the correct content type.

Parameters

integer $nodeids The id in the primary table.

Return Value

Array[Int] Requested data, keyed by the nodeid.

at line 2439
array getFullContent($nodeids)

Returns the node content plus the channel routeid and title, and starter route and title the as an associative array

Parameters

$nodeids

Return Value

array Nodeid-keyed array of node content, including node.*, channel & starter id, title, route and other common data, and content-specific data. see $this->getRawContent()

at line 2473
protected array getRawContent($nodeids)

Prepares basic content. Used by both getBareContent and getFullContent.

Parameters

$nodeids

Return Value

array Nodeid-keyed array of node & content data, including node table data. Keys depend on the particular node's contenttype, but a few common ones include: node.*, channelroute, channeltitle, channelid, starterroute, startertitle, etc. See vBForum:getFullContent.

Exceptions

throw new vB_Exception_Api('incorrect_content_class_called') If any node in $nodeids is not of $this's contenttype.

at line 2598
bool getCanEdit(int $node, int $userContext = null, mixed $channelPerms = array())

Determines whether the current user can edit a node

Parameters

int $node The nodeid
int $userContext optional usercontext
mixed $channelPerms optional array of channel permissions data, which if available prevents a userContext Call

Return Value

bool

at line 2724
bool getCanDelete(mixed $node, int $userContext = null, mixed $channelPerms = array(), bool $hard = false)

Determines whether the current user can soft-delete or hard-delete

Parameters

mixed $node The node
int $userContext Optional usercontext
mixed $channelPerms Optional array of channel permissions data, which if available prevents a userContext Call
bool $hard Optional flag - false get can soft delete, true get can hard delete

Return Value

bool

at line 2880
bool getCanModerate(mixed $node, object $userContext = null, mixed $channelPerms = array(), int $nodeid = 0)

Determines whether the current user can moderate

Parameters

mixed $node The node
object $userContext optional usercontext
mixed $channelPerms optional array of channel permissions data, which if available prevents a userContext Call
int $nodeid optional nodeid,

Return Value

bool

at line 2959
Array assembleContent(Array $content)

Assembles the response for detailed content

Parameters

Array $content getRawContent() response array. Each element is a nodeid-keyed array. Each subarray must have the following data at minimum: nodeid, channelid, contenttypeid, starter, showopen, userid, setfor (if VM), nodeoptions

Return Value

Array Nodeid-keyed array of the $content data, plus additional data such as contenttypeclass, createpermissions, moderatorperms, channeltype, permissions, etc, @TODO: complete this list Also the expanded nodeoptions of: allow_post, moderate_comments, approve_membership, invite_only, autoparselinks, disablesmilies, disable_bbcode, hide_title, hide_author, hide_publishdate, display_fullincategory, display_pageviews, hide_comment_count

at line 3516
getIndexableFromNode($node, $include_attachments = true)

Parameters

$node
$include_attachments

at line 3540
array getIndexableContent($nodeId, $include_attachments = true)

The classes that inherit this should implement this function It should return the content that should be indexed If there is a title field, the array key for that field should be 'title', the rest of the text can have any key

Parameters

$nodeId
$include_attachments

Return Value

array $indexableContent

at line 3586
int getStarter(int $nodeid)

Gets the conversation starter for a node. If the node is a channel it returns the channelid.

Parameters

int $nodeid

Return Value

int The conversation starter's nodeid

at line 3619
array getConversationParent(int $nodeid)

Gets the conversation starter for a node. If the node is a channel it returns the channel record.

Parameters

int $nodeid

Return Value

array The starter node array

at line 3640
bool isVisitorMessage(int $nodeid)

determines whether a specific node is a visitor message

Parameters

int $nodeid

Return Value

bool

at line 3657
bool isComment(int $nodeid, array $node = null)

Determines whether a specific node is a comment on a thread reply or not

Parameters

int $nodeid Node ID
array $node Node information

Return Value

bool

at line 3681
protected getIndexableContentForAttachments($nodeId)

Get the indexable content for attachments. Separate this so that child classes can rewrite getIndexableContent entirely without having to copy as much code

Parameters

$nodeId

at line 3702
Array fetchTableName()

returns the tables used by this content type.

Return Value

Array

at line 3719
static array('found' fetchFromCache(array|int $nodeids, integer $level)

This attempts to get the cached data for nodes

Parameters

array|int $nodeids
integer $level -- one of the constants for level of data

Return Value

array('found' => array of node values per the constant, 'notfound' => array of nodeids);

at line 3796
static void writeToCache($nodes, $level)

writes new cached data for nodes

Note that this is affected by the 'cache_node_data' admin option. If that is not true then this function does nothing.

Parameters

$nodes
$level

Return Value

void

at line 3816
protected verifyPrefixid($prefixid)

Parameters

$prefixid

at line 3840
protected verifyPostIconid(int $posticonid)

Verifies that the post iconid is valid

Parameters

int $posticonid post icon ID

at line 3854
protected changeContentType($nodeid, $oldcontentType, $newcontentType)

Parameters

$nodeid
$oldcontentType
$newcontentType

at line 3894
protected string getDuplicateHash(array $data)

Calculates the CRC based on the indexable content

Parameters

array $data

Return Value

string

at line 3930
protected fillContentTableData($node)

Parameters

$node

at line 3953
none removePrivateDataFromNode(array $node)

Examines the node record returned from the node library and determines if any information needs to be removed before passing beyond the API layer.

This is part of the library layer because its needed for a number of API classes that return node data in various forms.

Parameters

array $node the node array to be cleaned.

Return Value

none

at line 3974
bool checkComplete(array $node)

This function checks to see if a node is valid, and if not it deletes or fixes it.

Parameters

array $node -- node array

Return Value

bool

at line 3996
boolean getCannotDelete()

Whether this type can be deleted. Infractions, for example, cannot be.

Return Value

boolean

at line 4008
protected bool getNodeClean(integer $node)

Checks to see if the node has all the required data.

Parameters

integer $node the nodeid to be checked

Return Value

bool

at line 4036
protected bool incompleteNodeCleanup(mixed $node)

This cleans up for a node that was found to be incomplete by deleting the child nodes and subsidiary table records. It is often overridden in child classes.

Parameters

mixed $node Node record, which may have missing child table data.

Return Value

bool Whether the node has been cleaned up

at line 4095
setDoIncompleteNodeCleanup(bool $value)

Sets the $doIncompleteNodeCleanup flag

Parameters

bool $value Flag value

at line 4105
protected handleAttachments($type, $nodeid, $data, $options = array())

This function needs to be implemented by sub classes that want to handle attachments. See the text library implementation for the full description.

Parameters

$type
$nodeid
$data
$options

at line 4108
mergeContentInfo($result, $content)

Parameters

$result
$content

at line 4127
bool validate($data, $action = self::ACTION_ADD, $nodeid = false, $nodes = false, $userid = null)

Validates that the current can create a node with these values

Note that if an array is passed it returns true only if all nodes pass the constraint.

Parameters

$data
$action
$nodeid
$nodes
$userid

Return Value

bool