PHP Class Agora_Driver, horde

Copyright 2003-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Author: Marko Djukic ([email protected])
Author: Jan Schneider ([email protected])
Author: Duck ([email protected])
Show file Open project: horde/horde Class Usage Examples

Public Properties

Property Type Description
$_forum array Current forum data
$_forum_id string Current forum ID

Protected Properties

Property Type Description
$_cache Horde_Cache Cache object
$_charset string Charset
$_db Horde_Db_Adapter The database connection object.
$_forums_table string Scope theads table name
$_scope string The forums scope.
$_threads_table string Scope theads table name

Public Methods

Method Description
__construct ( $scope, $params ) Constructor
_forumSequence ( integer $forum_id, string $type = 'message', integer | string $diff = '+' ) Increments or decrements a forum's message count.
allowAttachments ( ) : boolean Checks if attachments are allowed in messages for the current forum.
convertFromDriver ( mixed $value ) : mixed Converts a value from the driver's charset to the default charset.
convertToDriver ( mixed $value ) : mixed Converts a value from the default charset to the driver's charset.
countForums ( ) Returns the number of forums.
countMessages ( ) : integer Returns the number of all messages (threads and replies) in a forum
countThreads ( integer $thread_root ) : integer Returns the number of replies on a thread, or threads in a forum
dateFormat ( integer $timestamp ) : string Formats time according to user preferences.
deleteForum ( integer $forum_id ) : boolean Deletes a forum, any subforums that are present and all messages contained in the forum and subforums.
deleteMessage ( integer $message_id ) : string Deletes a message and all replies.
deleteThread ( integer $thread_id ) Deletes an entire message thread.
formatBody ( string $body ) Formats a message body.
formatSize ( integer $filesize ) : string Formats file size.
getAttachmentLink ( $message_id ) Constructs message attachments link.
getBanned ( ) Get banned users from the current forum
getBareForums ( ) : array Get forums ids and titles
getForm ( $vars, $title, $editing = false, $new_forum = false )
getForum ( integer $forum_id ) : array Fetches a forum data.
getForums ( integer $root_forum, boolean $formatted = true, string $sort_by = 'forum_name', integer $sort_dir, boolean $add_scope = false, string $from, string $count ) : mixed Fetches a list of forums.
getMessage ( integer $message_id ) Fetches a message.
getModerateList ( string $sort_by, integer $sort_dir ) Fetches a list of messages awaiting moderation. Selects all messages, irrespective of the thread root, which have the 'moderate' flag set in the attributes.
getThreadActions ( )
getThreadRoot ( $message_id )
getThreads ( integer $thread_root, boolean $all_levels = false, string $sort_by = 'message_timestamp', integer $sort_dir, boolean $message_view = false, string $link_back = '', string $base_url = null, string $from = null, string $count = null, boolean $nofollow = false ) Returns a list of threads.
getThreadsUi ( array $threads, array $col_headers, boolean $bodies = false, string $template_file = false ) : string Returns a table showing the specified message list.
hasPermission ( integer $perm = Horde_Perms::READ, integer $forum_id = null, string $scope = null ) : boolean Finds out if the user has the specified rights to the messages forum.
isHot ( $views, $last_post ) Returns true if the message is hot.
isNew ( $thread_id, $last_post ) Returns true, has new posts since user last visit
isThreadLocked ( $message_id ) : boolean
logView ( $thread_id ) : boolean Logs a message view.
mergeThread ( $thread_from, integer $message_id ) Merges two threads.
moderate ( string $action, array $ids ) Approves one or more ids.
moveThread ( integer $thread_id, integer $forum_id ) Moves a thread to another forum.
newForum ( string $forum_name, $owner ) : integer Creates a new forum.
replyMessage ( mixed $message ) : array Returns a hash with all information necessary to reply to a message.
saveForum ( array $info ) : integer Saves a forum, either creating one if no forum ID is given or updating an existing one.
saveMessage ( array $info ) : mixed Saves the message.
search ( array $filter, string $sort_by = 'message_subject', integer $sort_dir, string $from, string $count ) : array Searches forums for matching threads or posts.
setThreadLock ( $message_id, $lock )
splitThread ( integer $message_id ) Splits a thread on message id.
updateBan ( string $user, integer $forum_id = null, string $action = 'add' ) Ban user on a specific forum.
updateModerator ( string $moderator, integer $forum_id = null, string $action = 'add' ) Updates forum moderators.

Protected Methods

Method Description
_formatForums ( integer $forums ) : array | Traversable Fetches a list of forums.
_formatThreads ( array | Traversable $messages, string $sort_by = 'message_modifystamp', boolean $format = false, integer $thread_root ) Formats a message body.
_getCache ( $key, $thread ) Get cache value
_getForums ( integer $root_forum, boolean $formatted = true, string $sort_by = 'forum_name', integer $sort_dir, boolean $add_scope = false, string $from, string $count ) : mixed Fetches a list of forums.
_setCache ( $key, $value, $thread ) Set cache value

Private Methods

Method Description
_getCacheKey ( $key, $thread ) Append namespace to cache key
_lastInForum ( integer $forum_id, integer $message_id, string $message_author = '', integer $message_timestamp ) Update lastMessage in a Forum
_lastInThread ( integer $thread_id, integer $message_id, string $message_author = '', integer $message_timestamp ) Update lastMessage in Thread
_sequence ( integer $thread_id, integer | string $diff = '+' ) Increments or decrements a thread's message count.
_updateCacheState ( $thread ) Increment namespace

Method Details

__construct() public method

Constructor
public __construct ( $scope, $params )

_formatForums() protected method

Fetches a list of forums.
protected _formatForums ( integer $forums ) : array | Traversable
$forums integer Forums to format
return array | Traversable An array of forums.

_formatThreads() protected method

Formats a message body.
protected _formatThreads ( array | Traversable $messages, string $sort_by = 'message_modifystamp', boolean $format = false, integer $thread_root )
$messages array | Traversable Messages to format
$sort_by string List format order
$format boolean Format messages body
$thread_root integer Thread root

_forumSequence() public method

Increments or decrements a forum's message count.
public _forumSequence ( integer $forum_id, string $type = 'message', integer | string $diff = '+' )
$forum_id integer Forum to update
$type string What to increment message, thread or view.
$diff integer | string Incremental or decremental step, either a positive or negative integer, or a plus or minus sign.

_getCache() protected method

Get cache value
protected _getCache ( $key, $thread )

_getForums() protected method

Fetches a list of forums.
protected _getForums ( integer $root_forum, boolean $formatted = true, string $sort_by = 'forum_name', integer $sort_dir, boolean $add_scope = false, string $from, string $count ) : mixed
$root_forum integer The first level forum.
$formatted boolean Whether to return the list formatted or raw.
$sort_by string The column to sort by.
$sort_dir integer Sort direction, 0 = ascending, 1 = descending.
$add_scope boolean Add parent forum if forum for another scopelication.
$from string The forum to start listing at.
$count string The number of forums to return.
return mixed An array of forums or PEAR_Error on failure.

_setCache() protected method

Set cache value
protected _setCache ( $key, $value, $thread )

allowAttachments() public method

Checks if attachments are allowed in messages for the current forum.
public allowAttachments ( ) : boolean
return boolean Whether attachments allowed or not.

convertFromDriver() public method

Converts a value from the driver's charset to the default charset.
public convertFromDriver ( mixed $value ) : mixed
$value mixed A value to convert.
return mixed The converted value.

convertToDriver() public method

Converts a value from the default charset to the driver's charset.
public convertToDriver ( mixed $value ) : mixed
$value mixed A value to convert.
return mixed The converted value.

countForums() public method

Returns the number of forums.
public countForums ( )

countMessages() public method

Returns the number of all messages (threads and replies) in a forum
public countMessages ( ) : integer
return integer The number of messages in forum or PEAR_Error on failure.

countThreads() public method

Returns the number of replies on a thread, or threads in a forum
public countThreads ( integer $thread_root ) : integer
$thread_root integer Thread to count.
return integer The number of messages in thread or PEAR_Error on failure.

dateFormat() public method

Formats time according to user preferences.
public dateFormat ( integer $timestamp ) : string
$timestamp integer Message timestamp.
return string Formatted date.

deleteForum() public method

Deletes a forum, any subforums that are present and all messages contained in the forum and subforums.
public deleteForum ( integer $forum_id ) : boolean
$forum_id integer The ID of the forum to delete.
return boolean True on success.

deleteMessage() public method

Deletes a message and all replies.
public deleteMessage ( integer $message_id ) : string
$message_id integer The ID of the message to delete.
return string Thread ID on success.

deleteThread() public method

Deletes an entire message thread.
public deleteThread ( integer $thread_id )
$thread_id integer The ID of the thread to delete. If not specified will delete all the threads for the current forum.

formatBody() public method

Formats a message body.
public formatBody ( string $body )
$body string Text to format.

formatSize() public method

Formats file size.
public formatSize ( integer $filesize ) : string
$filesize integer
return string Formatted filesize.

getBanned() public method

Get banned users from the current forum
public getBanned ( )

getBareForums() public method

Get forums ids and titles
public getBareForums ( ) : array
return array An array of forums and form names.

getForm() public method

public getForm ( $vars, $title, $editing = false, $new_forum = false )

getForum() public method

Fetches a forum data.
public getForum ( integer $forum_id ) : array
$forum_id integer The ID of the forum to fetch.
return array The forum hash or a PEAR_Error on failure.

getForums() public method

Fetches a list of forums.
public getForums ( integer $root_forum, boolean $formatted = true, string $sort_by = 'forum_name', integer $sort_dir, boolean $add_scope = false, string $from, string $count ) : mixed
$root_forum integer The first level forum.
$formatted boolean Whether to return the list formatted or raw.
$sort_by string The column to sort by.
$sort_dir integer Sort direction, 0 = ascending, 1 = descending.
$add_scope boolean Add parent forum if forum for another scopelication.
$from string The forum to start listing at.
$count string The number of forums to return.
return mixed An array of forums or PEAR_Error on failure.

getMessage() public method

Fetches a message.
public getMessage ( integer $message_id )
$message_id integer The ID of the message to fetch.

getModerateList() public method

Fetches a list of messages awaiting moderation. Selects all messages, irrespective of the thread root, which have the 'moderate' flag set in the attributes.
public getModerateList ( string $sort_by, integer $sort_dir )
$sort_by string The column by which to sort.
$sort_dir integer The direction by which to sort: 0 - ascending 1 - descending

getThreadActions() public method

public getThreadActions ( )

getThreadRoot() public method

public getThreadRoot ( $message_id )

getThreads() public method

Returns a list of threads.
public getThreads ( integer $thread_root, boolean $all_levels = false, string $sort_by = 'message_timestamp', integer $sort_dir, boolean $message_view = false, string $link_back = '', string $base_url = null, string $from = null, string $count = null, boolean $nofollow = false )
$thread_root integer Message at which to start the thread. If null get all forum threads
$all_levels boolean Show all child levels or just one level.
$sort_by string The column by which to sort.
$sort_dir integer The direction by which to sort: 0 - ascending 1 - descending
$message_view boolean
$link_back string A url to pass to the reply script which will be returned to after an insertion of a post. Useful in cases when this thread view is used in blocks to return to the original page rather than to Agora.
$base_url string An alternative URL where edit/delete links point to. Mainly for api usage. Takes "%p" as a placeholder for the parent message ID.
$from string The thread to start listing at.
$count string The number of threads to return.
$nofollow boolean Whether to set the 'rel="nofollow"' attribute on linked URLs in the messages.

getThreadsUi() public method

Returns a table showing the specified message list.
public getThreadsUi ( array $threads, array $col_headers, boolean $bodies = false, string $template_file = false ) : string
$threads array A hash with the thread messages as returned by {@link Agora_Driver::getThreads}.
$col_headers array A hash with the column headers.
$bodies boolean Display the message bodies?
$template_file string Template to use.
return string The rendered message table.

hasPermission() public method

Finds out if the user has the specified rights to the messages forum.
public hasPermission ( integer $perm = Horde_Perms::READ, integer $forum_id = null, string $scope = null ) : boolean
$perm integer The permission level needed for access.
$forum_id integer Forum to check permissions for.
$scope string Application scope to use.
return boolean True if the user has the specified permissions.

isHot() public method

Returns true if the message is hot.
public isHot ( $views, $last_post )

isNew() public method

Returns true, has new posts since user last visit
public isNew ( $thread_id, $last_post )

isThreadLocked() public method

public isThreadLocked ( $message_id ) : boolean
return boolean

logView() public method

Logs a message view.
public logView ( $thread_id ) : boolean
return boolean True, if the view was logged, false if the message was aleredy seen

mergeThread() public method

Merges two threads.
public mergeThread ( $thread_from, integer $message_id )
$message_id integer The ID of the message to merge to.

moderate() public method

Approves one or more ids.
public moderate ( string $action, array $ids )
$action string Whether to 'approve' or 'delete' messages.
$ids array Array of message IDs.

moveThread() public method

Moves a thread to another forum.
public moveThread ( integer $thread_id, integer $forum_id )
$thread_id integer The ID of the thread to move.
$forum_id integer The ID of the destination forum.

newForum() public method

Creates a new forum.
public newForum ( string $forum_name, $owner ) : integer
$forum_name string Forum name.
return integer ID of the new generated forum.

replyMessage() public method

Returns a hash with all information necessary to reply to a message.
public replyMessage ( mixed $message ) : array
$message mixed The ID of the parent message to reply to, or arry of its data.
return array A hash with all relevant information.

saveForum() public method

Saves a forum, either creating one if no forum ID is given or updating an existing one.
public saveForum ( array $info ) : integer
$info array The forum information to save consisting of: forum_id forum_author forum_parent_id forum_name forum_moderated forum_description forum_attachments
return integer The forum ID on success.

saveMessage() public method

Saves the message.
public saveMessage ( array $info ) : mixed
$info array Array containing all the message data to save.
return mixed Message ID on success or PEAR_Error on failure.

setThreadLock() public method

public setThreadLock ( $message_id, $lock )

splitThread() public method

Splits a thread on message id.
public splitThread ( integer $message_id )
$message_id integer The ID of the message to split at.

updateBan() public method

Ban user on a specific forum.
public updateBan ( string $user, integer $forum_id = null, string $action = 'add' )
$user string Moderator username.
$forum_id integer Forum to add moderator to.
$action string Action to peform ('add' or 'delete').

updateModerator() public method

Updates forum moderators.
public updateModerator ( string $moderator, integer $forum_id = null, string $action = 'add' )
$moderator string Moderator username.
$forum_id integer Forum to add moderator to.
$action string Action to peform ('add' or 'delete').

Property Details

$_cache protected property

Cache object
protected Horde_Cache $_cache
return Horde_Cache

$_charset protected property

Charset
protected string $_charset
return string

$_db protected property

The database connection object.
protected Horde_Db_Adapter $_db
return Horde_Db_Adapter

$_forum public property

Current forum data
public array $_forum
return array

$_forum_id public property

Current forum ID
public string $_forum_id
return string

$_forums_table protected property

Scope theads table name
protected string $_forums_table
return string

$_scope protected property

The forums scope.
protected string $_scope
return string

$_threads_table protected property

Scope theads table name
protected string $_threads_table
return string