Пример #1
0
/**
 * This function can be used to (recursively) update forum_path fields.
 *
 * The function is internally used by Phorum to update the paths that are
 * stored in the "forum_path" field of the forums table. Under normal
 * circumstances, this function will be called when appropriate by the
 * {@link phorum_api_forums_save()} function.
 *
 * @param array $forum
 *     A forum data array. The forum_path will be updated for this forum.
 *     The array requires at least the fields: forum_id, parent_id,
 *     folder_flag and vroot.
 *
 * @param boolean $recurse
 *     If this parameter is set to TRUE (the default), then recursive
 *     path updates will be done. The function will walk down the folder/forum
 *     tree to update all paths.
 *
 * @return mixed
 *     On failure trigger_error() will be called. If some error handler
 *     does not stop script execution, this function will return NULL.
 *     On success, an updated $forum array will be returned.
 */
function phorum_api_forums_update_path($forum, $recurse = TRUE)
{
    global $PHORUM;
    // Check if the parent_id is valid.
    $parent = phorum_api_forums_get($forum['parent_id'], PHORUM_FLAG_INCLUDE_INACTIVE);
    // Check if the parent was found.
    if ($parent === NULL) {
        trigger_error('phorum_api_forums_save(): parent_id ' . htmlspecialchars($forum['parent_id']) . ' points to a folder ' . 'that does not exist.', E_USER_ERROR);
        return NULL;
    }
    // Check if the parent is a folder.
    if (!$parent['folder_flag']) {
        trigger_error('phorum_api_forums_save(): parent_id ' . htmlspecialchars($forum['parent_id']) . ' does not point to ' . 'a folder. You can only put forums/folders inside folders.', E_USER_ERROR);
        return NULL;
    }
    // If this is not a vroot folder, then the $forum needs to inherit
    // its vroot from its parent. We'll silently fix inconsitencies
    // in this info here.
    if (!$forum['folder_flag'] || $forum['vroot'] != $forum['forum_id']) {
        $forum['vroot'] = $parent['vroot'];
    }
    // Check if the vroot is valid.
    if ($forum['vroot'] != 0) {
        // Retrieve the info from the vroot.
        $vroot = phorum_api_forums_get($forum['vroot'], NULL, NULL, NULL, PHORUM_FLAG_INCLUDE_INACTIVE);
        // Check if the vroot was found.
        if ($vroot === NULL) {
            trigger_error('phorum_api_forums_save(): vroot ' . htmlspecialchars($forum['vroot']) . ' points to a folder ' . 'that does not exist.', E_USER_ERROR);
            return NULL;
        }
        // Check if the vroot is a folder.
        if (!$vroot['folder_flag']) {
            trigger_error('phorum_api_forums_save(): vroot ' . htmlspecialchars($forum['vroot']) . ' does not point ' . 'to a folder. Only folders can be vroots.', E_USER_ERROR);
            return NULL;
        }
        // Check if the vroot folder is setup as a vroot.
        if ($vroot['vroot'] != $vroot['forum_id']) {
            trigger_error('phorum_api_forums_save(): vroot ' . htmlspecialchars($forum['vroot']) . ' points to a folder ' . 'that is  not setup as a vroot folder.', E_USER_ERROR);
            return NULL;
        }
    }
    // Rebuild the forum_path for this forum.
    $path = phorum_api_forums_build_path($forum['forum_id']);
    $forum['forum_path'] = $path;
    $PHORUM['DB']->update_forum(array('vroot' => $forum['vroot'], 'forum_id' => $forum['forum_id'], 'forum_path' => $forum['forum_path']));
    // Cascade path updates down the forum tree. This is only
    // applicable to folders and if recursion is enabled.
    if ($forum['folder_flag'] && $recurse) {
        // Find the forums and folders that are contained by this folder.
        $childs = phorum_api_forums_by_parent_id($forum['forum_id']);
        // Handle recursion for the child forums and folders.
        if (!empty($childs)) {
            foreach ($childs as $child) {
                if (!phorum_api_forums_update_path($child)) {
                    return NULL;
                }
            }
        }
    }
    return $forum;
}
Пример #2
0
<?php

if (!defined("PHORUM_ADMIN")) {
    return;
}
require_once './include/api/forums.php';
// Rebuild the forum-paths for each and every forum in the tree.
$forums = phorum_api_forums_build_path();
unset($forums[0]);
foreach ($forums as $fid => $forumpath) {
    $PHORUM['DB']->update_forum(array('forum_id' => $fid, 'forum_path' => $forumpath));
}