query_select_value_if_there('privilege_list', 'the_name', array('the_name' => $name)); return !is_null($test); } /** * Add a privilege, and apply it to every usergroup. * * @param ID_TEXT $section The section the privilege is filled under * @param ID_TEXT $name The codename for the privilege * @param boolean $default Whether this permission is granted to all usergroups by default * @param boolean $not_even_mods Whether this permission is not granted to supermoderators by default (something very sensitive) */ function add_privilege($section, $name, $default = false, $not_even_mods = false) { if (!$not_even_mods) { // NB: Don't actually need to explicitly give admins privileges $ins_privilege = array(); $ins_group_id = array(); $ins_the_page = array(); $ins_module_the_name = array(); $ins_category_name = array(); $ins_the_value = array(); $usergroups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); $admin_groups = array_merge($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), $GLOBALS['FORUM_DRIVER']->get_moderator_groups()); foreach (array_keys($usergroups) as $id) { if (($default) || (in_array($id, $admin_groups))) { $ins_privilege[] = $name; $ins_group_id[] = $id; $ins_the_page[] = ''; $ins_module_the_name[] = ''; $ins_category_name[] = ''; $ins_the_value[] = 1; } } $GLOBALS['SITE_DB']->query_insert('group_privileges', array( 'privilege' => $ins_privilege, 'group_id' => $ins_group_id, 'the_page' => $ins_the_page, 'module_the_name' => $ins_module_the_name, 'category_name' => $ins_category_name, 'the_value' => $ins_the_value, )); } $GLOBALS['SITE_DB']->query_insert('privilege_list', array('p_section' => $section, 'the_name' => $name, 'the_default' => ($default ? 1 : 0))); } /** * Sets the privilege of a usergroup * * @param GROUP $group_id The usergroup having the permission set * @param ID_TEXT $permission The codename of the permission * @param boolean $value Whether the usergroup has the permission * @param ?ID_TEXT $page The ID code for the page being checked (null: current page) * @param ?ID_TEXT $category_type The category-type for the permission (null: none required) * @param ?ID_TEXT $category_name The category-name/value for the permission (null: none required) */ function set_privilege($group_id, $permission, $value, $page = null, $category_type = null, $category_name = null) { if (is_null($page)) { $page = ''; } if (is_null($category_type)) { $category_type = ''; } if (is_null($category_name)) { $category_name = ''; } $GLOBALS['SITE_DB']->query_delete('group_privileges', array('privilege' => $permission, 'group_id' => $group_id, 'the_page' => $page, 'module_the_name' => $category_type, 'category_name' => $category_name), '', 1); $GLOBALS['SITE_DB']->query_insert('group_privileges', array('privilege' => $permission, 'group_id' => $group_id, 'the_page' => $page, 'module_the_name' => $category_type, 'category_name' => $category_name, 'the_value' => $value ? 1 : 0)); global $PRIVILEGE_CACHE; $PRIVILEGE_CACHE = array(); } /** * Rename a privilege. * * @param ID_TEXT $old The old name * @param ID_TEXT $new The new name */ function rename_privilege($old, $new) { $GLOBALS['SITE_DB']->query_update('privilege_list', array('the_name' => $new), array('the_name' => $old), '', 1); $GLOBALS['SITE_DB']->query_update('group_privileges', array('privilege' => $new), array('privilege' => $old), '', 1); $GLOBALS['SITE_DB']->query_update('member_privileges', array('privilege' => $new), array('privilege' => $old), '', 1); } /** * Delete a privilege. * * @param ID_TEXT $name The codename of the permission */ function delete_privilege($name) { $GLOBALS['SITE_DB']->query_delete('privilege_list', array('the_name' => $name), '', 1); $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'group_privileges WHERE ' . db_string_equal_to('privilege', $name)); } /** * Delete attachments solely used by the specified hook. * * @param ID_TEXT $type The hook * @param ?object $connection The database connection to use (null: standard site connection) */ function delete_attachments($type, $connection = null) { if (get_option('attachment_cleanup') == '0') { return; } if (is_null($connection)) { $connection = $GLOBALS['SITE_DB']; } require_code('attachments2'); require_code('attachments3'); // Clear any de-referenced attachments $before = $connection->query_select('attachment_refs', array('a_id', 'id'), array('r_referer_type' => $type)); foreach ($before as $ref) { // Delete reference (as it's not actually in the new comcode!) $connection->query_delete('attachment_refs', array('id' => $ref['id']), '', 1); // Was that the last reference to this attachment? (if so -- delete attachment) $test = $connection->query_select_value_if_there('attachment_refs', 'id', array('a_id' => $ref['a_id'])); if (is_null($test)) { _delete_attachment($ref['a_id'], $connection); } } } /** * Deletes all language strings linked to by the specified table and attribute identifiers, if they exist. * * @param ID_TEXT $table The table * @param array $attrs The attributes * @param ?object $connection The database connection to use (null: standard site connection) */ function mass_delete_lang($table, $attrs, $connection) { if (count($attrs) == 0) { return; } if (is_null($connection)) { $connection = $GLOBALS['SITE_DB']; } $start = 0; do { $rows = $connection->query_select($table, $attrs, null, '', 1000, $start, true); if (!is_null($rows)) { foreach ($rows as $row) { foreach ($attrs as $attr) { if (!is_null($row[$attr])) { delete_lang($row[$attr], $connection); } } } } $start += 1000; } while ((!is_null($rows)) && (count($rows) == 1000)); }