Example #1
0
 /**
  * Correctly associate any forums with their correct parent ids. This is automagically run after importing
  * forums.
  */
 function cleanup()
 {
     global $db;
     $query = $db->query("\n\t\t\tSELECT f.fid, f2.fid as updatefid, f.import_fid\n\t\t\tFROM " . TABLE_PREFIX . "forums f\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "forums f2 ON (f2.import_fid=f.import_pid)\n\t\t\tWHERE f.import_pid != '0' AND f.pid = '0'\n\t\t");
     while ($forum = $db->fetch_array($query)) {
         $db->update_query("forums", array('pid' => $forum['updatefid'], 'parentlist' => make_parent_list($forum['import_fid'])), "fid='{$forum['fid']}'", 1);
     }
 }
function acp_rebuild_forum_counters()
{
    global $db, $mybb, $lang;
    $query = $db->simple_select("forums", "COUNT(*) as num_forums");
    $num_forums = $db->fetch_field($query, 'num_forums');
    $page = intval($mybb->input['page']);
    $per_page = intval($mybb->input['forumcounters']);
    $start = ($page - 1) * $per_page;
    $end = $start + $per_page;
    $query = $db->simple_select("forums", "fid", '', array('order_by' => 'fid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
    while ($forum = $db->fetch_array($query)) {
        $update['parentlist'] = make_parent_list($forum['fid']);
        $db->update_query("forums", $update, "fid='{$forum['fid']}'");
        rebuild_forum_counters($forum['fid']);
    }
    check_proceed($num_forums, $end, ++$page, $per_page, "forumcounters", "do_rebuildforumcounters", $lang->success_rebuilt_forum_counters);
}
Example #3
0
/**
 * Builds a CSV parent list for a particular forum.
 *
 * @param int The forum ID
 * @param string Optional separator - defaults to comma for CSV list
 * @return string The built parent list
 */
function make_parent_list($fid, $navsep = ",")
{
    global $pforumcache, $db;
    if (!$pforumcache) {
        $query = $db->simple_select("forums", "name, fid, pid", "", array("order_by" => "disporder, pid"));
        while ($forum = $db->fetch_array($query)) {
            $pforumcache[$forum['fid']][$forum['pid']] = $forum;
        }
    }
    reset($pforumcache);
    reset($pforumcache[$fid]);
    foreach ($pforumcache[$fid] as $key => $forum) {
        if ($fid == $forum['fid']) {
            if ($pforumcache[$forum['pid']]) {
                $navigation = make_parent_list($forum['pid'], $navsep) . $navigation;
            }
            if ($navigation) {
                $navigation .= $navsep;
            }
            $navigation .= $forum['fid'];
        }
    }
    return $navigation;
}
Example #4
0
 $update_array = array("name" => $db->escape_string($mybb->input['title']), "description" => $db->escape_string($mybb->input['description']), "linkto" => $db->escape_string($mybb->input['linkto']), "type" => $db->escape_string($type), "pid" => $pid, "disporder" => $mybb->get_input('disporder', MyBB::INPUT_INT), "active" => $mybb->get_input('active', MyBB::INPUT_INT), "open" => $mybb->get_input('open', MyBB::INPUT_INT), "allowhtml" => $mybb->get_input('allowhtml', MyBB::INPUT_INT), "allowmycode" => $mybb->get_input('allowmycode', MyBB::INPUT_INT), "allowsmilies" => $mybb->get_input('allowsmilies', MyBB::INPUT_INT), "allowimgcode" => $mybb->get_input('allowimgcode', MyBB::INPUT_INT), "allowvideocode" => $mybb->get_input('allowvideocode', MyBB::INPUT_INT), "allowpicons" => $mybb->get_input('allowpicons', MyBB::INPUT_INT), "allowtratings" => $mybb->get_input('allowtratings', MyBB::INPUT_INT), "usepostcounts" => $mybb->get_input('usepostcounts', MyBB::INPUT_INT), "usethreadcounts" => $mybb->get_input('usethreadcounts', MyBB::INPUT_INT), "requireprefix" => $mybb->get_input('requireprefix', MyBB::INPUT_INT), "password" => $db->escape_string($mybb->input['password']), "showinjump" => $mybb->get_input('showinjump', MyBB::INPUT_INT), "style" => $mybb->get_input('style', MyBB::INPUT_INT), "overridestyle" => $mybb->get_input('overridestyle', MyBB::INPUT_INT), "rulestype" => $mybb->get_input('rulestype', MyBB::INPUT_INT), "rulestitle" => $db->escape_string($mybb->input['rulestitle']), "rules" => $db->escape_string($mybb->input['rules']), "defaultdatecut" => $mybb->get_input('defaultdatecut', MyBB::INPUT_INT), "defaultsortby" => $db->escape_string($mybb->input['defaultsortby']), "defaultsortorder" => $db->escape_string($mybb->input['defaultsortorder']));
 $db->update_query("forums", $update_array, "fid='{$fid}'");
 if ($pid != $forum_data['pid']) {
     // Update the parentlist of this forum.
     $db->update_query("forums", array("parentlist" => make_parent_list($fid)), "fid='{$fid}'");
     // Rebuild the parentlist of all of the subforums of this forum
     switch ($db->type) {
         case "sqlite":
         case "pgsql":
             $query = $db->simple_select("forums", "fid", "','||parentlist||',' LIKE '%,{$fid},%'");
             break;
         default:
             $query = $db->simple_select("forums", "fid", "CONCAT(',',parentlist,',') LIKE '%,{$fid},%'");
     }
     while ($child = $db->fetch_array($query)) {
         $db->update_query("forums", array("parentlist" => make_parent_list($child['fid'])), "fid='{$child['fid']}'");
     }
 }
 $inherit = $mybb->input['default_permissions'];
 foreach ($mybb->input as $id => $permission) {
     // Make sure we're only skipping inputs that don't start with "fields_" and aren't fields_default_ or fields_inherit_
     if (strpos($id, 'fields_') === false || (strpos($id, 'fields_default_') !== false || strpos($id, 'fields_inherit_') !== false)) {
         continue;
     }
     list(, $gid) = explode('fields_', $id);
     if ($mybb->input['fields_default_' . $gid] == $permission && $mybb->input['fields_inherit_' . $gid] == 1) {
         $inherit[$gid] = 1;
         continue;
     }
     $inherit[$gid] = 0;
     // If it isn't an array then it came from the javascript form
Example #5
0
 /**
 Create new forums for an IC group based on the given attributes
 */
 public function create_groupforums($gid, $settings)
 {
     $idarray = array();
     // Configure Prefix & Region
     $prefixquery = $this->db->simple_select('threadprefixes', '*', 'pid = ' . $settings['prefix']);
     $prefix = $this->db->fetch_array($prefixquery);
     $forumarray = explode(',', $prefix['forums']);
     $forums = '';
     if (!empty($prefix['forums'])) {
         foreach ($forumarray as $forum) {
             if ($forum != $settings['region']) {
                 $forums .= $forum . ',';
             }
         }
     }
     // Create the IC Forum for the group
     $forum = Creation::IC_FORUM;
     $forum['name'] = $settings['title'];
     $forum['description'] = 'This pack claims the territory of <strong>' . $prefix['prefix'] . '</strong>.
     If you aren\'\'t a member of this pack, posting in this forum means you\'\'re trespassing!';
     $forum['pid'] = $settings['region'];
     $this->db->insert_query('forums', $forum);
     $fid = $this->db->insert_id();
     $idarray['fid'] = $fid;
     $this->db->update_query('forums', array('parentlist' => make_parent_list($fid)), 'fid = ' . $fid);
     // Update the prefix with the new forum
     $this->db->update_query('threadprefixes', array('forums' => $forums . $fid), 'pid = ' . $settings['prefix']);
     //Move existing prefixed threads to new board
     $threadquery = $this->db->simple_select('threads', '*', 'fid = ' . $forum['pid'] . ' AND prefix = ' . $settings['prefix']);
     while ($thread = $this->db->fetch_array($threadquery)) {
         $threadstring .= $thread['tid'];
     }
     if (!empty($threadstring)) {
         $this->db->update_query('threads', array('fid' => $fid), 'tid IN (' . $threadstring . ')');
         $this->db->update_query('posts', array('fid' => $fid), 'tid IN (' . $threadstring . ')');
         update_forum_lastpost($fid);
     }
     $moid = 0;
     // Create the Members only subforum
     $moforum = Creation::OOC_FORUM;
     $moforum['name'] = $settings['title'] . ' Members Only';
     $moforum['description'] = '';
     $moforum['pid'] = $fid;
     $this->db->insert_query('forums', $moforum);
     $mofid = $this->db->insert_id();
     $idarray['mofid'] = $mofid;
     $this->db->update_query('forums', array('parentlist' => make_parent_list($fid) . ',' . $mofid), 'fid = ' . $mofid);
     // Set permissions for other groups to noread
     // Get array of all current groups
     $othergroups = array();
     $groupquery = $this->db->simple_select('usergroups g left join ' . TABLE_PREFIX . 'icgroups i on g.gid = i.gid', '*, g.gid', 'g.gid NOT IN (' . $gid . ',' . Groups::ADMIN . ')');
     while ($og = $this->db->fetch_array($groupquery)) {
         $othergroups[] = $og;
     }
     $mopermissions = Creation::FORUM_PERM_NOREAD;
     if (!empty($othergroups)) {
         foreach ($othergroups as $othergroup) {
             if (!empty($mofid)) {
                 $mopermissions['fid'] = $mofid;
                 $mopermissions['gid'] = $othergroup['gid'];
                 $this->db->insert_query('forumpermissions', $mopermissions);
             }
         }
     }
     // Set permissions to read
     $momemberpermissions = Creation::FORUM_PERM_READWRITE;
     $momemberpermissions['fid'] = $mofid;
     $momemberpermissions['gid'] = $gid;
     $this->db->insert_query('forumpermissions', $momemberpermissions);
     $momemberpermissions['gid'] = Groups::ADMIN;
     $this->db->insert_query('forumpermissions', $momemberpermissions);
     $this->cache->update_forums();
     $this->cache->update_forumpermissions();
     $this->cache->update_threadprefixes();
     return $idarray;
 }
Example #6
0
 /**
  * Insert a new Forum into Database
  *
  * @param array $data Array with keys according to database layout, which holds the data of the forum
  * @param array $permissions Array with Permission entries (structure: array( 'canview' => array( 'usergroupid' => 1 ) )) (an example)
  * @param array $default_permissions Array which defines, if default permissions shall be used (structure: array( usergroupid => 0 / 1 )
  * 								  	 Can be left empty, then this function will take care of it
  * @return $data with more values, like fid and parentlist
  */
 function createForum($data, $permissions = array(), $default_permissions = array())
 {
     require_once MYBB_ADMIN_DIR . 'inc/functions.php';
     if (!isset($data['name'])) {
         $this->_errorAndDie('A new forum needs to have a name and a type');
     }
     $data['type'] = 'f';
     // Let's leave the parentlist creation to the script and let's not trust the dev :)
     if ($data['parentlist'] != '') {
         $data['parentlist'] = '';
     }
     // If there is no defined Parent ID, parent ID will be set to 0
     if (!isset($data['pid']) || $data['pid'] < 0) {
         $data['pid'] = 0;
     } else {
         $data['pid'] = intval($data['pid']);
     }
     if (!empty($permissions)) {
         if (!isset($permissions['canview']) || empty($permissions['canview']) || (!isset($permissions['canpostthreads']) || empty($permissions['canpostthreads'])) || (!isset($permissions['canpostreplys']) || empty($permissions['canpostreplys'])) || (!isset($permissions['canpostpolls']) || empty($permissions['canpostpolls'])) || (!isset($permissions['canpostattachments']) || empty($permissions['canpostattachments']))) {
             $this->_errorAndDie('The $permissions Parameter does not have the correct format. It requires following keys: <i>canview, canpostthreads, canpostreplys, canpostpolls and canpostattachments</i>');
         }
         /**
          * If no default permissions are given, we will initiate them, default: yes
          * Since there is the possibility of additional usergroups, we will get the usergroups from the permissions array!
          * The structure of the inherit array is: keys = groupid
          * If the value of an inherit array item is 1, this means that the default_permissions shall be used
          */
         if (empty($default_permissions)) {
             foreach ($permissions['canview'] as $gid) {
                 $default_permissions[$gid] = 1;
             }
         }
     }
     $data['fid'] = $this->db->insert_query("forums", $data);
     $data['parentlist'] = make_parent_list($data['fid']);
     $this->db->update_query("forums", array("parentlist" => $data['parentlist']), 'fid=\'' . $data['fid'] . '\'');
     $this->cache->update_forums();
     if (!empty($permissions)) {
         $inherit = $default_permissions;
         /**
          * $permissions['canview'][1] = 1 OR $permissions['canview'][1] = 0
          * --> $permissions[$name][$gid] = yes / no
          */
         $canview = $permissions['canview'];
         $canpostthreads = $permissions['canpostthreads'];
         $canpostpolls = $permissions['canpostpolls'];
         $canpostattachments = $permissions['canpostattachments'];
         $canpostreplies = $permissions['canpostreplys'];
         save_quick_perms($data['fid']);
     }
     return $data;
 }
 /**
  * Generic creation of a forum.
  * In MyBB a category is a special forum. Categories and forums only differ in the type: c for category and f for forum
  */
 private function createCategoryOrForum($data, $permissions = array(), $default_permissions = array())
 {
     require_once MYBB_ADMIN_DIR . 'inc/functions.php';
     if (!trim($data['name'])) {
         $errors[] = $lang->error_missing_title;
     }
     $pid = (int) $data['pid'];
     $type = $data['type'] == 'c' ? 'c' : 'f';
     if (!$errors) {
         if ($pid < 0) {
             $pid = 0;
         }
         $defaults = array('description' => '', 'linkto' => '', 'disporder' => '', 'active' => 1, 'open' => 1, 'allowhtml' => 0, 'allowmycode' => 1, 'allowsmilies' => 1, 'allowimgcode' => 1, 'allowvideocode' => 1, 'allowpicons' => 1, 'allowtratings' => 1, 'usepostcounts' => 1, 'usethreadcounts' => 1, 'requireprefix' => 0, 'password' => '', 'showinjump' => 1, 'style' => 0, 'overridestyle' => 0, 'rulestype' => 0, 'rulestitle' => '', 'rules' => '', 'defaultdatecut' => 0, 'defaultsortby' => '', 'defaultsortorder' => '');
         $data = array_merge($defaults, $data);
         $insert_array = array("name" => $this->dbEscape($data['name']), "description" => $this->dbEscape($data['description']), "linkto" => $this->dbEscape($data['linkto']), "type" => $this->dbEscape($type), "pid" => $pid, "parentlist" => '', "disporder" => (int) $data['disporder'], "active" => (int) $data['active'], "open" => (int) $data['open'], "allowhtml" => (int) $data['allowhtml'], "allowmycode" => (int) $data['allowmycode'], "allowsmilies" => (int) $data['allowsmilies'], "allowimgcode" => (int) $data['allowimgcode'], "allowvideocode" => (int) $data['allowvideocode'], "allowpicons" => (int) $data['allowpicons'], "allowtratings" => (int) $data['allowtratings'], "usepostcounts" => (int) $data['usepostcounts'], "usethreadcounts" => (int) $data['usethreadcounts'], "requireprefix" => (int) $data['requireprefix'], "password" => $this->dbEscape($data['password']), "showinjump" => (int) $data['showinjump'], "style" => (int) $data['style'], "overridestyle" => (int) $data['overridestyle'], "rulestype" => (int) $data['rulestype'], "rulestitle" => $this->dbEscape($data['rulestitle']), "rules" => $this->dbEscape($data['rules']), "defaultdatecut" => (int) $data['defaultdatecut'], "defaultsortby" => $this->dbEscape($data['defaultsortby']), "defaultsortorder" => $this->dbEscape($data['defaultsortorder']));
         $fid = $this->db->insert_query("forums", $insert_array);
         $parentlist = make_parent_list($fid);
         $this->db->update_query("forums", array("parentlist" => $parentlist), "fid='{$fid}'");
         $insert_array['fid'] = $fid;
         $insert_array['parentlist'] = $parentlist;
         $inherit = $data['default_permissions'];
         foreach ($data as $id => $permission) {
             if (strpos($id, 'fields_') === false) {
                 continue;
             }
             list(, $gid) = explode('fields_', $id);
             foreach (array('canview', 'canpostthreads', 'canpostreplys', 'canpostpolls') as $name) {
                 if (in_array($name, $permission) || $permission[$name]) {
                     $permissions[$name][$gid] = 1;
                 } else {
                     $permissions[$name][$gid] = 0;
                 }
             }
         }
         $canview = $permissions['canview'];
         $canpostthreads = $permissions['canpostthreads'];
         $canpostpolls = $permissions['canpostpolls'];
         $canpostattachments = $permissions['canpostattachments'];
         $canpostreplies = $permissions['canpostreplys'];
         save_quick_perms($fid);
         $this->plugins->run_hooks("admin_forum_management_add_commit");
         $this->cache->update_forums();
         // Log admin action
         log_admin_action($fid, $insert_array['name']);
         return $insert_array;
     }
 }
Example #8
0
/**
 * Builds a CSV parent list for a particular forum.
 *
 * @param int The forum ID
 * @param string Optional separator - defaults to comma for CSV list
 * @return string The built parent list
 */
function make_parent_list($fid, $navsep = ",", $parent_list = "")
{
    global $pforumcache, $db;
    if (!$pforumcache) {
        $query = $db->simple_select("forums", "fid, import_fid, import_pid", "import_fid > 0", array("order_by" => "import_pid"));
        while ($forum = $db->fetch_array($query)) {
            $pforumcache[$forum['import_fid']] = array("fid" => $forum['fid'], "import_pid" => $forum['import_pid']);
        }
    }
    if (is_array($pforumcache[$fid])) {
        if ($pforumcache[$fid]['import_pid'] && $pforumcache[$pforumcache[$fid]['import_pid']]) {
            $parent_list = make_parent_list($pforumcache[$fid]['import_pid'], $navsep, $parent_list) . $parent_list;
        }
        if ($parent_list) {
            $parent_list .= ',';
        }
        $parent_list .= $pforumcache[$fid]['fid'];
    }
    return $parent_list;
}