示例#1
0
文件: forums.php 项目: netovs/Core
/**
 * Change the displaying order for forums and folders in a certain folder.
 *
 * @param integer $folder_id
 *     The forum_id of the folder in which to change the display order.
 *
 * @param integer $forum_id
 *     The id of the forum or folder to move.
 *
 * @param string $movement
 *     This field determines the type of movement to apply to the forum
 *     or folder. This can be one of:
 *     - "up": Move the forum or folder $value positions up
 *     - "down": Move the forum or folder $value positions down
 *     - "pos": Move the forum or folder to position $value
 *     - "start": Move the forum or folder to the start of the list
 *     - "end": Move the forum or folder to the end of the list
 *
 * @param mixed $value
 *     This field specifies a value for the requested type of movement.
 *     An integer value is only needed for movements "up", "down" and "pos".
 *     For other movements, this parameter can be omitted.
 */
function phorum_api_forums_change_order($folder_id, $forum_id, $movement, $value = NULL)
{
    global $PHORUM;
    settype($folder_id, 'int');
    settype($forum_id, 'int');
    if ($value !== NULL) {
        settype($value, 'int');
    }
    // Get the forums for the specified folder.
    $forums = phorum_api_forums_by_folder_id($folder_id);
    // Prepare the forum list for easy ordering.
    $current_pos = NULL;
    $pos = 0;
    $forum_ids = array();
    foreach ($forums as $forum) {
        if ($forum['forum_id'] == $forum_id) {
            $current_pos = $pos;
        }
        $forum_ids[$pos++] = $forum['forum_id'];
    }
    $pos--;
    // to make this the last index position in the array.
    // If the forum_id is not in the folder, then return right away.
    if ($current_pos === NULL) {
        return;
    }
    switch ($movement) {
        case "up":
            $new_pos = $current_pos - $value;
            break;
        case "down":
            $new_pos = $current_pos + $value;
            break;
        case "pos":
            $new_pos = $value;
            break;
        case "start":
            $new_pos = 0;
            break;
        case "end":
            $new_pos = $pos;
            break;
        default:
            trigger_error('phorum_api_forums_change_order(): Illegal $movement ' . 'parameter "' . htmlspecialchars($movement) . '" used', E_USER_ERROR);
            return NULL;
    }
    // Keep the new position within boundaries.
    if ($new_pos < 0) {
        $new_pos = 0;
    }
    if ($new_pos > $pos) {
        $new_pos = $pos;
    }
    // No order change, then return.
    if ($new_pos == $current_pos) {
        return;
    }
    // Reorder the forum_ids array to represent the order change.
    $new_order = array();
    for ($i = 0; $i <= $pos; $i++) {
        if ($i == $current_pos) {
            continue;
        }
        if ($i == $new_pos) {
            if ($i < $current_pos) {
                $new_order[] = $forum_id;
                $new_order[] = $forum_ids[$i];
            } else {
                $new_order[] = $forum_ids[$i];
                $new_order[] = $forum_id;
            }
        } else {
            $new_order[] = $forum_ids[$i];
        }
    }
    // Loop through all the forums and update the ones that changed.
    // We have to look at them all, because the default value for
    // display order is 0 for all forums. So, in an unsorted folder,
    // all the display order values are set to 0 until you move one.
    foreach ($new_order as $display_order => $forum_id) {
        if ($forums[$forum_id]['display_order'] != $display_order) {
            $PHORUM['DB']->update_forum(array('forum_id' => $forum_id, 'display_order' => $display_order));
        }
    }
}
示例#2
0
文件: default.php 项目: samuell/Core
// Load the info for the current folder.
$folder = phorum_api_forums_get($folder_id);
// Load the list of forums and folders that are in the current folder.
$forums = phorum_api_forums_by_folder_id($folder_id, PHORUM_FLAG_INCLUDE_INACTIVE);
// Change the display order of the items in the list.
if (isset($_GET['display_up']) || isset($_GET['display_down'])) {
    if (isset($_GET['display_up'])) {
        $forum_id = (int) $_GET['display_up'];
        $movement = 'up';
    } else {
        $forum_id = (int) $_GET['display_down'];
        $movement = 'down';
    }
    phorum_api_forums_change_order($folder_id, $forum_id, $movement, 1);
    // Get a fresh forum list with updated order.
    $forums = phorum_api_forums_by_folder_id($folder_id);
}
$rows = '';
foreach ($forums as $forum_id => $forum) {
    if ($forum["folder_flag"]) {
        $visit_url = phorum_api_url(PHORUM_INDEX_URL, $forum['forum_id']);
        $type = "folder";
        $folder_edit_url = phorum_admin_build_url(array('module=editfolder', "forum_id={$forum_id}"));
        $folder_delete_url = phorum_admin_build_url(array('module=deletefolder', "forum_id={$forum_id}"));
        $actions = "<a href=\"{$folder_edit_url}\">Edit</a>&nbsp;&#149;&nbsp;<a href=\"{$folder_delete_url}\">Delete</a>&nbsp;&#149;&nbsp;<a href=\"{$visit_url}\">Visit</a>";
        $mainurl = phorum_admin_build_url(array('module=default', "parent_id={$forum_id}"));
    } else {
        $visit_url = phorum_api_url(PHORUM_LIST_URL, $forum['forum_id']);
        $type = "forum";
        $forum_edit_url = phorum_admin_build_url(array('module=editforum', "forum_id={$forum_id}"));
        $forum_delete_url = phorum_admin_build_url(array('module=deleteforum', "forum_id={$forum_id}"));