예제 #1
0
파일: newflags.php 프로젝트: samuell/Core
/**
 * Mark forums, threads or messages as read for the active Phorum user.
 *
 * @param mixed $markread_ids
 *     This parameter provides the ids of the items that have to be marked
 *     read. It can be either a single item id (depending on the $mode
 *     parameter either vroot, message_id, thread_id or forum_id) or an array
 *     of item ids.
 *
 * @param integer $mode
 *     This determines whether messages, threads or forums are marked
 *     read. Possible values for this parameter are:
 *     {@link PHORUM_MARKREAD_MESSAGES},
 *     {@link PHORUM_MARKREAD_THREADS},
 *     {@link PHORUM_MARKREAD_FORUMS},
 *     {@link PHORUM_MARKREAD_VROOTS}
 */
function phorum_api_newflags_markread($markread_ids, $mode = PHORUM_MARKREAD_MESSAGES)
{
    global $PHORUM;
    // No newflags for anonymous users.
    if (!$PHORUM['user']['user_id']) {
        return $messages;
    }
    // Make sure that the $markread_ids parameter is an array of integers.
    if (!is_array($markread_ids)) {
        $markread_ids = array((int) $markread_ids);
    } else {
        foreach ($markread_ids as $key => $val) {
            $markread_ids[$key] = (int) $val;
        }
    }
    $orig_forum_id = $PHORUM['forum_id'];
    // An array to keep track of the forums for which we need to invalidate
    // the cache later on.
    $processed_forum_ids = array();
    // Handle marking vroots read.
    if ($mode == PHORUM_MARKREAD_VROOTS) {
        foreach ($markread_ids as $vroot) {
            $forums = phorum_api_forums_by_vroot($vroot, PHORUM_FLAG_FORUMS);
            foreach ($forums as $forum) {
                $forum_id = $forum['forum_id'];
                $PHORUM['forum_id'] = $forum_id;
                $PHORUM['DB']->newflag_allread($forum_id);
                $processed_forum_ids[$forum_id] = $forum_id;
            }
        }
    } elseif ($mode == PHORUM_MARKREAD_FORUMS) {
        foreach ($markread_ids as $forum_id) {
            $PHORUM['forum_id'] = $forum_id;
            $PHORUM['DB']->newflag_allread($forum_id);
            $processed_forum_ids[$forum_id] = $forum_id;
        }
    } elseif ($mode == PHORUM_MARKREAD_THREADS) {
        // Retrieve the data for the threads to mark read.
        $threads = $PHORUM['DB']->get_message($markread_ids, 'message_id', TRUE);
        // Process the threads.
        $markread = array();
        foreach ($threads as $thread) {
            // In case this was no thread or broken thread data.
            if ($thread['parent_id'] != 0 || empty($thread['meta']['message_ids'])) {
                continue;
            }
            // Fetch the user's newflags for the thread's forum, so we
            // can limit the messages to mark read to the actual unread
            // messages in the thread.
            $forum_id = $thread['forum_id'];
            if (!isset($PHORUM['user']['newflags'][$forum_id])) {
                $PHORUM['forum_id'] = $forum_id;
                $newflags = phorum_api_newflags_by_forum($forum_id);
            } else {
                $newflags = $PHORUM['user']['newflags'][$forum_id];
            }
            // Find out what message_ids are unread in the thread.
            // If we have no newflags for the forum (yet), then consider
            // all the messages in the thread as new.
            $markread = array();
            foreach ($thread['meta']['message_ids'] as $mid) {
                if (empty($newflags) || !isset($newflags[$mid]) && $mid > $newflags['min_id']) {
                    $markread[] = array('id' => $mid, 'forum_id' => $forum_id);
                }
            }
            $processed_forum_ids[$forum_id] = $forum_id;
            $PHORUM['forum_id'] = $forum_id;
        }
        // Mark the messages in the thread(s) as read.
        $PHORUM['DB']->newflag_add_read($markread);
    } elseif ($mode == PHORUM_MARKREAD_MESSAGES) {
        // Retrieve the data for the messages to mark read.
        $messages = $PHORUM['DB']->get_message($markread_ids);
        // Process the messages.
        $markread = array();
        foreach ($messages as $message) {
            $markread[] = array('id' => $message['message_id'], 'forum_id' => $message['forum_id']);
            $processed_forum_ids[$message['forum_id']] = $message['forum_id'];
            $PHORUM['forum_id'] = $message['forum_id'];
        }
        // Mark the messages read in the database.
        $PHORUM['DB']->newflag_add_read($markread);
    }
    // Invalidate cached forum newflags data.
    foreach ($processed_forum_ids as $forum_id) {
        unset($PHORUM['user']['newflags'][$forum_id]);
        if ($PHORUM['cache_newflags']) {
            $cachekey = $forum_id . '-' . $PHORUM['user']['user_id'];
            phorum_api_cache_remove('newflags', $cachekey);
            phorum_api_cache_remove('newflags_index', $cachekey);
        }
    }
    $PHORUM['forum_id'] = $orig_forum_id;
}
예제 #2
0
파일: search.php 프로젝트: netovs/Core
 $search_request_data = array('search' => $phorum_search, 'author' => $phorum_author, 'offset' => $start, 'length' => $PHORUM["list_length"], 'match_type' => $PHORUM["args"]["match_type"], 'match_dates' => $PHORUM["args"]["match_dates"], 'match_forum' => $PHORUM["args"]["match_forum"], 'match_threads' => $PHORUM["args"]["match_threads"], 'results' => array(), 'raw_body' => 0, 'totals' => 0, 'continue' => 1);
 if (isset($PHORUM["hooks"]["search_action"])) {
     $search_request_data = phorum_api_hook('search_action', $search_request_data);
 }
 // only continue if our hook was either not run or didn't return a stop request
 if ($search_request_data['continue']) {
     $arr = $PHORUM['DB']->search($phorum_search, $phorum_author, $PHORUM["args"]["match_threads"], $offset, $PHORUM["list_length"], $PHORUM["args"]["match_type"], $PHORUM["args"]["match_dates"], $PHORUM["args"]["match_forum"]);
     $raw_body = 0;
 } else {
     $arr['rows'] = $search_request_data['results'];
     $arr['count'] = $search_request_data['totals'];
     $raw_body = $search_request_data['raw_body'];
 }
 if (count($arr["rows"])) {
     $match_number = $start + 1;
     $forums = phorum_api_forums_by_vroot($PHORUM["vroot"], PHORUM_FLAG_INCLUDE_INACTIVE);
     if (!$raw_body) {
         $arr["rows"] = phorum_api_format_messages($arr["rows"]);
     }
     foreach ($arr["rows"] as $key => $row) {
         $arr["rows"][$key]["number"] = $match_number;
         $arr["rows"][$key]["URL"]["READ"] = phorum_api_url(PHORUM_FOREIGN_READ_URL, $row["forum_id"], $row["thread"], $row["message_id"]);
         // strip HTML & BB Code
         if (!$raw_body) {
             $body = phorum_api_format_strip($arr["rows"][$key]["body"]);
             $arr["rows"][$key]["short_body"] = mb_substr($body, 0, 400, $PHORUM["DATA"]["HCHARSET"]);
         }
         $arr["rows"][$key]["raw_datestamp"] = $row["datestamp"];
         $arr["rows"][$key]["datestamp"] = phorum_api_format_relative_date($row["datestamp"]);
         $forum_ids[$row["forum_id"]] = $row["forum_id"];
         $match_number++;
예제 #3
0
파일: feed.php 프로젝트: netovs/Core
/**
 * Collect the data that is used for the feed and pass this information
 * on to the requested output adapter.
 *
 * @param string $adapter
 *     The output adapter to use. The adapters that are available are:
 *     - rss
 *     - atom
 *     - html
 *     - js
 *
 * @param integer $source_type
 *     The type of source. This is one of:
 *     - {@link PHORUM_FEED_VROOT}
 *     - {@link PHORUM_FEED_FORUM}
 *     - {@link PHORUM_FEED_THREAD}
 *
 * @param integer $id
 *     This parameter has a different meaning for each $source_type:
 *     - For {@link PHORUM_FEED_VROOT}: the forum_id of the (v)root.
 *     - For {@link PHORUM_FEED_FORUM}: the forum_id of the forum.
 *     - For {@link PHORUM_FEED_THREAD}: the message_id of the thread.
 *
 * @param integer $count
 *     The number of messages to include in the feed.
 *
 * @param boolean $replies
 *     TRUE to include reply messages in the feed, FALSE otherwise.
 *     This parameter is forced to TRUE for {@link PHORUM_FEED_THREAD}.
 */
function phorum_api_feed($adapter, $source_type, $id, $count, $replies)
{
    global $PHORUM;
    settype($id, 'int');
    settype($count, 'int');
    settype($source_type, 'int');
    $replies = $replies ? 1 : 0;
    $adapter = basename($adapter);
    if (!preg_match('/^[a-z][\\w_]*$/', $adapter)) {
        trigger_error('phorum_api_feed(): Illegal feed adapter name ' . '"' . htmlspecialchars($adapter) . '" used', E_USER_ERROR);
    }
    if (!file_exists(PHORUM_PATH . '/include/api/feed/' . $adapter . '.php')) {
        trigger_error('phorum_api_feed(): Unknown feed adapter ' . '"' . htmlspecialchars($adapter) . '" used', E_USER_ERROR);
    }
    // ----------------------------------------------------------------------
    // Prepare the data for the requested feed type
    // ----------------------------------------------------------------------
    // Prepare data for handling a vroot feed.
    if ($source_type === PHORUM_FEED_VROOT) {
        $forums = phorum_api_forums_by_vroot($id);
        $thread_id = NULL;
        $forum_ids = array_keys($forums);
        $cache_part = implode(',', array_keys($forums));
    } elseif ($source_type === PHORUM_FEED_FORUM) {
        if ($PHORUM['forum_id'] == $id) {
            $forum = $PHORUM;
            // contains all required data already
        } else {
            $forum = phorum_api_forums_by_forum_id($id);
            if (empty($forum)) {
                trigger_error("phorum_api_feed(): Forum for forum_id \"{$id}\" not found.", E_USER_ERROR);
            }
        }
        $forums = array($id => $forum);
        $thread_id = NULL;
        $forum_ids = array_keys($forums);
        $cache_part = $forum['forum_id'];
    } elseif ($source_type === PHORUM_FEED_THREAD) {
        // When a feed for a thread is requested, we always include the
        // reply messages for that thread in the feed.
        $replies = 1;
        // Retrieve the thread starter message.
        $thread = $PHORUM['DB']->get_message($id);
        if (empty($thread)) {
            trigger_error("phorum_api_feed(): Thread for message_id \"{$id}\" not found.", E_USER_ERROR);
        }
        if (!empty($thread['parent_id'])) {
            trigger_error("phorum_api_feed(): Message for message_id \"{$id}\" is not " . "the start message of a thread.", E_USER_ERROR);
        }
        $thread_id = $id;
        $forum_ids = NULL;
        $cache_part = $id;
    } else {
        trigger_error("phorum_api_feed(): Illegal value \"{$source_type}\" used " . "for parameter \$source_type.", E_USER_ERROR);
    }
    // ----------------------------------------------------------------------
    // Retrieve the data for the requested feed
    // ----------------------------------------------------------------------
    $data = NULL;
    $content_type = NULL;
    // Try to retrieve the data from cache.
    if (!empty($PHORUM['cache_rss'])) {
        // Build the cache key that uniquely identifies the requested feed.
        $cache_key = $PHORUM['user']['user_id'] . '|' . $adapter . '|' . $source_type . '|' . $cache_part . '|' . $replies . '|' . $count;
        $cache = phorum_api_cache_get('feed', $cache_key);
        if (!empty($cache)) {
            list($data, $content_type) = $cache;
        }
    }
    // No data from cache. Load the recent threads / messages
    // directly from the database and generate the feed data.
    if (empty($data)) {
        // ----------------------------------------------------------------
        // Retrieve the messages to show
        // ----------------------------------------------------------------
        $messages = $PHORUM['DB']->get_recent_messages($count, 0, $forum_ids, $thread_id, $replies ? LIST_RECENT_MESSAGES : LIST_RECENT_THREADS);
        // Temporarily, remove the user list from the messages array.
        $users = $messages['users'];
        unset($messages['users']);
        // Apply the "read" hook(s) to the messages.
        if (isset($PHORUM['hooks']['read'])) {
            $messages = phorum_api_hook('read', $messages);
        }
        // Apply formatting to the messages.
        $messages = phorum_api_format_messages($messages);
        // Put the array of users back in the messages array.
        $messages['users'] = $users;
        // ----------------------------------------------------------------
        // Setup the feed URL, title and description based on
        // the type of feed that was requested.
        // ----------------------------------------------------------------
        if ($source_type === PHORUM_FEED_VROOT) {
            $feed_url = phorum_api_url(PHORUM_INDEX_URL);
            $feed_title = strip_tags($PHORUM['DATA']['TITLE']);
            $feed_description = !empty($PHORUM['description']) ? $PHORUM['description'] : '';
        }
        if ($source_type === PHORUM_FEED_FORUM) {
            $feed_url = phorum_api_url(PHORUM_LIST_URL);
            /**
             * @todo The formatting of the forum base feed data should
             *       be based on the data in $forum and not the common.php
             *       $PHORUM contents. This is left as is for now, because
             *       the wrong data will only be shown for threads that
             *       were moved to a different forum.
             */
            $feed_title = strip_tags($PHORUM['DATA']['TITLE'] . ' - ' . $PHORUM['DATA']['NAME']);
            $feed_description = strip_tags($PHORUM['DATA']['DESCRIPTION']);
        }
        if ($source_type === PHORUM_FEED_THREAD) {
            // Retrieve the information for the forum to which the thread
            // belongs. Normally, this should be in $PHORUM already, but
            // let's make sure that the caller is using the correct forum id
            // in the URL here (since the thread might have been moved to
            // a different forum).
            $forum_id = $thread['forum_id'];
            if ($PHORUM['forum_id'] == $forum_id) {
                $forum = $PHORUM;
                // contains all required data already
            } else {
                $forum = phorum_api_forums_by_forum_id($forum_id);
                if (empty($forum)) {
                    trigger_error("phorum_api_feed(): Forum for forum_id \"{$id}\" not found.", E_USER_ERROR);
                }
            }
            $forums = array($forum_id => $forum);
            $feed_url = phorum_api_url(PHORUM_FOREIGN_READ_URL, $thread['forum_id'], $thread_id, $thread_id);
            $feed_title = strip_tags($thread['subject']);
            $feed_description = strip_tags($thread['body']);
        }
        // ----------------------------------------------------------------
        // All data has been collected. Now the feed is generated.
        // ----------------------------------------------------------------
        require_once PHORUM_PATH . '/include/api/feed/' . $adapter . '.php';
        $adapter_function = 'phorum_api_feed_' . $adapter;
        list($data, $content_type) = $adapter_function($messages, $forums, $feed_url, $feed_title, $feed_description, $replies);
        // Store the feed data in the cache for future use.
        if (!empty($PHORUM['cache_rss'])) {
            phorum_api_cache_put('feed', $cache_key, array($data, $content_type, 600));
        }
    }
    // ----------------------------------------------------------------------
    // Output the feed data to the client
    // ----------------------------------------------------------------------
    header("Content-Type: {$content_type}");
    print $data;
    /*
     * [hook]
     *     feed_sent
     *
     * [description]
     *     This hook is called whenever the feed has been sent to the client
     *     (regardless of the cache setting). This can be used to add internal
     *     server side tracking code.
     *
     * [category]
     *     Feed
     *
     * [when]
     *     Feed sent to the client
     *
     * [input]
     *     None
     *
     * [output]
     *     None
     *
     * [example]
     *     <hookcode>
     *     function phorum_mod_foo_feed_after () 
     *     {
     *       # E.g. do server side tracking
     *       @file_get_contents('your tracking service');
     *     }
     *     </hookcode>
     */
    phorum_api_hook('feed_sent');
    // Exit explicitly here, for not giving back control to portable and
    // embedded Phorum setups.
    exit(0);
}
예제 #4
0
파일: subthreads.php 프로젝트: samuell/Core
// the number of days to show
if (isset($_POST['subdays']) && is_numeric($_POST['subdays'])) {
    $subdays = $_POST['subdays'];
} elseif (isset($PHORUM['args']['subdays']) && !empty($PHORUM["args"]['subdays']) && is_numeric($PHORUM["args"]['subdays'])) {
    $subdays = $PHORUM['args']['subdays'];
} else {
    $subdays = phorum_api_user_get_setting('cc_subscriptions_subdays');
}
if ($subdays === NULL) {
    $subdays = 2;
}
$PHORUM['DATA']['SELECTED'] = $subdays;
// Store current selection for the user.
phorum_api_user_save_settings(array("cc_subscriptions_subdays" => $subdays));
// reading all forums for the current vroot
$forums = phorum_api_forums_by_vroot($PHORUM['vroot']);
// reading all subscriptions to messages in the current vroot.
$forum_ids = array($PHORUM["vroot"]);
foreach ($forums as $forum) {
    $forum_ids[] = $forum["forum_id"];
}
$subscr_array = phorum_api_user_list_subscriptions($PHORUM['user']['user_id'], $subdays, $forum_ids);
// storage for newflags
$PHORUM['user']['newinfo'] = array();
// go through all subscriptions
$subscr_array_final = array();
unset($subscr_array["forum_ids"]);
foreach ($subscr_array as $id => $data) {
    $data['forum'] = $forums[$data['forum_id']]['name'];
    $data['raw_datestamp'] = $data["modifystamp"];
    $data['datestamp'] = phorum_api_format_date($PHORUM["short_date_time"], $data["modifystamp"]);