The call will return an error if one of the arguments is not in the right format. AUTHOR Maurice Makaay <*****@*****.**> */ if (!defined('PHORUM')) { return; } require_once PHORUM_PATH . '/include/api/newflags.php'; require_once PHORUM_PATH . '/include/api/format/messages.php'; // Process the arguments. $count = phorum_ajax_getarg('count', 'int>0', NULL); $forum_id = phorum_ajax_getarg('forum_id', 'int', 0); $thread_id = phorum_ajax_getarg('thread_id', 'int', 0); $threads_only = phorum_ajax_getarg('threads_only', 'boolean', 0); $format = phorum_ajax_getarg('format', 'string', 'html'); // Retrieve the recent messages. $recent = $PHORUM['DB']->get_recent_messages($count, 0, $forum_id, $thread_id, $threads_only); unset($recent["users"]); // Add newflag info to the messages. if ($PHORUM["DATA"]["LOGGEDIN"]) { $type = $threads_only ? PHORUM_NEWFLAGS_BY_THREAD : PHORUM_NEWFLAGS_BY_MESSAGE; $recent = phorum_api_newflags_apply_to_messages($recent, $type); } // Format the messages. $recent = phorum_api_format_messages($recent); // Apply the list hook to the messages. if (isset($PHORUM["hooks"]["list"])) { $recent = phorum_api_hook("list", $recent); } // Retrieve information about the forums for the active user.
<?php /* FUNCTION helloworld - the obligatory hello world example ARGUMENTS [who] The name of the person to greet. By default, "world" will be greeted. EXAMPLE JSON REQUESTS { "call": "helloworld" } { "call": "helloworld", "who": "John Doe" } RETURN VALUE The string "hello, world" or "hello, [who]". Why? Ask that question to Brian Kernighan. He thought it was a good idea. ERRORS none AUTHOR Maurice Makaay <*****@*****.**> */ if (!defined("PHORUM")) { return; } $who = phorum_ajax_getarg('who', 'string', 'world'); phorum_ajax_return("hello, {$who}");
} elseif (isset($PHORUM['args']['call'])) { // Set the Ajax arguments. $PHORUM['ajax_args'] = $PHORUM['args']; } // Check if we got a valid Ajax request. The request should contain at // least a "call" field in the Ajax arguments. if (empty($PHORUM['ajax_args']) || !isset($PHORUM['ajax_args']['call'])) { phorum_ajax_error('Illegal Ajax request'); } $ajax_call = basename($PHORUM['ajax_args']['call']); // try to get some session-id if there isn't already a user loaded through // the regular ways if (empty($PHORUM['user']['user_id'])) { // check if we got a session-id in the ajax args and if we got one // try to load a user with that data $ajax_session_id = phorum_ajax_getarg(PHORUM_SESSION_LONG_TERM, 'string', 0); if (!empty($ajax_session_id)) { $PHORUM['use_cookies'] = PHORUM_USE_COOKIES; $PHORUM['args'][PHORUM_SESSION_LONG_TERM] = $ajax_session_id; phorum_api_user_session_restore(PHORUM_FORUM_SESSION); } } /** * [hook] * ajax_<call> * * [availability] * Phorum 5 >= 5.2.8 * * [description] * This hook allows module writers to implement calls for the
The type of formatting to apply to the message. This can be one of "html" (default), "text" and "collapsed". EXAMPLE JSON REQUESTS { call : "format", body : "[b]Some text to format[/b]"} RETURN VALUE An object containing the formatted subject and body. For above example, this would be: { body : "<b>Some text to format</b>", subject : "" } ERRORS The call will return an error if one of the arguments is not in the right format. AUTHOR Maurice Makaay <*****@*****.**> */ if (!defined('PHORUM')) { return; } require_once PHORUM_PATH . '/include/api/format/messages.php'; // Process the arguments. $subject = phorum_ajax_getarg('subject', 'string', ''); $body = phorum_ajax_getarg('body', 'string', ''); // Format the strings. $data = phorum_api_format_messages(array(1 => array('message_id' => 1, 'subject' => $subject, 'body' => $body))); // Apply the read hook to the messages. if (isset($PHORUM["hooks"]["read"])) { $data = phorum_api_hook("read", $data); } // Return the results. phorum_ajax_return(array('subject' => $data[1]['subject'], 'body' => $data[1]['body']));
Mark a couple of threads and messages read: { "call": "markread", "threads": [ 4, 13, 96 ], "messages": [ 1, 55, 321 ] } RETURN VALUE A true value in case marking the items read was successful. ERRORS The call will return an error if the messages / threads array is not in the right format. AUTHOR Maurice Makaay <*****@*****.**> */ if (!defined('PHORUM')) { return; } // This call only makes sense for logged in users. // For anonymous users, we'll ignore the call and pretend it was successful. if (!$PHORUM['DATA']['LOGGEDIN']) { ajax_return(TRUE); } // Load the newflags API, which handles marking messages as read. require_once './include/api/newflags.php'; // Mark messages, threads and/or forums as read. foreach (array('messages' => PHORUM_MARKREAD_MESSAGES, 'threads' => PHORUM_MARKREAD_THREADS, 'forums' => PHORUM_MARKREAD_FORUMS) as $arg => $mode) { $items = phorum_ajax_getarg($arg, 'array:int>0', array()); if (!empty($items)) { phorum_api_newflags_markread($items, $mode); } } // We return TRUE (unless some error occured in the previous code). phorum_ajax_return(TRUE);
{ call : "getforumsettings", forum_id : 10 } Retrieve the default forum settings: { call : "getforumsettings", forum_id : 0 } RETURN VALUE An object containing the settings data for a forum. ERRORS The call will return an error if no forum exists for the provided forum_id or if the active user does not have read access for the forum. AUTHOR Maurice Makaay <*****@*****.**> */ if (!defined('PHORUM')) { return; } require_once PHORUM_PATH . '/include/api/forums.php'; // Process the arguments. $forum_id = phorum_ajax_getarg('forum_id', 'int'); // For forum_id = 0, we return the default settings. if ($forum_id == 0) { phorum_ajax_return($PHORUM['default_forum_options']); } // Retrieve and return the forum data. No permission checking is needed. // The forum_id parameter is checked from common.php already. $data = phorum_api_forums_get($forum_id); if (!$data) { phorum_ajax_error("Forum {$forum_id} does not exist"); } phorum_ajax_return($data);
FUNCTION checkpm - check for availability of new unread private messages. ARGUMENTS [user_id] The user_id of the user to check for. If this user_id is not provided, the user_id of the logged in user will be used instead. If no user is logged in, the call will return zero by default. EXAMPLE JSON REQUESTS { "call": "checkpm" } { "call": "checkpm", "user_id": 1234 } RETURN VALUE The call will return zero if there are no unread private messages or if no user_id is known. The call will return one if there are unread private messages. ERRORS The call will return an error if the user_id is not in the right format. AUTHOR Maurice Makaay <*****@*****.**> */ if (!defined('PHORUM')) { return; } $user_id = phorum_ajax_getarg('user_id', 'int>0', 0); if ($user_id == 0 && isset($PHORUM["user"]["user_id"])) { $user_id = $PHORUM["user"]["user_id"]; } $hasnew = $user_id == 0 ? 0 : phorum_db_pm_checknew($user_id) ? 1 : 0; phorum_ajax_return($hasnew);
Mark a full vroot read: { call : "markread", vroots : [ 10 ] } RETURN VALUE A true value in case marking the items read was successful. ERRORS The call will return an error if the messages / threads / forums / vroots array is not in the right format. AUTHOR Maurice Makaay <*****@*****.**> */ if (!defined('PHORUM')) { return; } // This call only makes sense for logged in users. // For anonymous users, we'll ignore the call and pretend it was successful. if (!$PHORUM['DATA']['LOGGEDIN']) { phorum_ajax_return(TRUE); } // Load the newflags API, which handles marking messages as read. require_once './include/api/newflags.php'; // Mark messages, threads and/or forums as read. foreach (array('messages' => PHORUM_MARKREAD_MESSAGES, 'threads' => PHORUM_MARKREAD_THREADS, 'forums' => PHORUM_MARKREAD_FORUMS, 'vroots' => PHORUM_MARKREAD_VROOTS) as $arg => $mode) { $check = $arg === 'vroots' ? 'array:int>=0' : 'array:int>0'; $items = phorum_ajax_getarg($arg, $check, array()); if (!empty($items)) { phorum_api_newflags_markread($items, $mode); } } // We return TRUE (unless some error occured in the previous code). phorum_ajax_return(TRUE);