Example #1
0
<?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}");
Example #2
0
$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.
$allowed_forums = phorum_api_user_check_access(PHORUM_USER_ALLOW_READ, PHORUM_ACCESS_LIST);
$forums = $PHORUM['DB']->get_forums($allowed_forums);
foreach ($forums as $id => $forum) {
    $forums[$id]['url'] = phorum_get_url(PHORUM_LIST_URL, $forum['forum_id']);
}
// Add forum info to the messages and clean up data.
foreach ($recent as $id => $message) {
    $recent[$id]['foruminfo'] = array('id' => $message['forum_id'], 'name' => $forums[$message['forum_id']]['name'], 'url' => $forums[$message['forum_id']]['url']);
    // Strip fields that the caller should not see in the return data.
    unset($recent[$id]['email']);
    unset($recent[$id]['ip']);
    unset($recent[$id]['meta']);
    unset($recent[$id]['msgid']);
}
// Return the results.
phorum_ajax_return(array_values($recent));
Example #3
0
<?php

/*
CALL
    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}!");
Example #4
0
        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']));
Example #5
0
        { "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);
Example #6
0
      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);
Example #7
0
    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);