/** * Return an Ajax result to the caller. * * The data will be sent to the client in the JSON encoding format, * using UTF-8 as the character set. * * When JSONP is used for communicating to Phorum's Ajax script, then * a JSONP callback is done with the JSON encoded $data as the response data. * * @param mixed $data * The data to return in the body. */ function phorum_ajax_return($data) { global $PHORUM; header("Content-Type: text/plain; charset=UTF-8"); $return = phorum_api_json_encode($data); if ($PHORUM['ajax_jsonp'] === NULL) { print $return; } else { print $PHORUM['ajax_jsonp'] . "({$return});"; } exit(0); }
/** * Return an Ajax result to the caller. * * The data will be sent to the client in the JSON encoding format, * using UTF-8 as the character set. * * @param mixed $data * The data to return in the body. */ function phorum_ajax_return($data) { global $PHORUM; header("Content-Type: text/plain; charset=UTF-8"); print phorum_api_json_encode($data); exit(0); }
/** * This function implements the JavaScript output adapter for the Feed API. * * @param array $messages * An array of messages to include in the feed. * * @param array $forums * An array of related forums. * * @param string $url * The URL that points to the feed's target. * * @param string $title * The title to use for the feed. * * @param string $description * The description to use for the feed. * * @param bool $replies * Whether or not this is a feed that includes reply messages. * If not, then it will only contain thread starter messages. * * @return array * An array containing two elements: * - The generated feed data (JavaScript code) * - The Content-Type header to use for the feed. */ function phorum_api_feed_js($messages, $forums, $url, $title, $description, $replies) { global $PHORUM; $feed = array('title' => $title, 'description' => $description, 'modified' => phorum_api_format_date($PHORUM['short_date'], time())); // Lookup the plain text usernames for the authenticated authors. $users = $messages['users']; unset($messages['users']); unset($users[0]); $users = phorum_api_user_get_display_name($users, '', PHORUM_FLAG_PLAINTEXT); foreach ($messages as $message) { $author = !empty($users[$message['user_id']]) ? $users[$message['user_id']] : $message['author']; // Created date. $fmt = $PHORUM['short_date']; $created = phorum_api_format_date($fmt, $message['datestamp']); // Updated date. if ($message['parent_id']) { if (!empty($message['meta']['edit_date'])) { $modified = $message['meta']['edit_date']; } else { $modified = $message['datestamp']; } } else { $modified = $message['modifystamp']; } $modified = phorum_api_format_date($fmt, $modified); $url = htmlspecialchars(phorum_api_url(PHORUM_FOREIGN_READ_URL, $message['forum_id'], $message['thread'], $message['message_id'])); $item = array('title' => strip_tags($message['subject']), 'author' => $author, 'category' => $forums[$message['forum_id']]['name'], 'created' => $created, 'modified' => $modified, 'url' => $url, 'description' => $message['body']); if ($message["thread_count"]) { $replies = $message["thread_count"] - 1; $item["replies"] = $replies; } $feed["items"][] = $item; } // this is where we convert the array into js $buffer = 'phorum_feed = ' . phorum_api_json_encode($feed); return array($buffer, 'text/javascript'); }