Commit 9822f4ee authored by dragonwize's avatar dragonwize
Browse files

Fixed #477934 by dragonwize: PHP warning when no roles have certain permissions.

parent 4975a236
...@@ -102,7 +102,6 @@ function better_formats_get_role_default_fields($mode, $node_type = '') { ...@@ -102,7 +102,6 @@ function better_formats_get_role_default_fields($mode, $node_type = '') {
$per_node_type = variable_get('better_formats_per_node_type', FALSE); $per_node_type = variable_get('better_formats_per_node_type', FALSE);
$block_admins = better_formats_get_roles_by_perm('administer blocks'); $block_admins = better_formats_get_roles_by_perm('administer blocks');
if ($per_node_type && $node_type) { if ($per_node_type && $node_type) {
$type = $mode . '/' . $node_type; $type = $mode . '/' . $node_type;
$types = $type . "','" . $mode; $types = $type . "','" . $mode;
...@@ -121,7 +120,6 @@ function better_formats_get_role_default_fields($mode, $node_type = '') { ...@@ -121,7 +120,6 @@ function better_formats_get_role_default_fields($mode, $node_type = '') {
while ($role = db_fetch_object($result)) { while ($role = db_fetch_object($result)) {
if (in_array($role->rid, $roles_set) || ($mode === 'block' && !in_array($role->rid, $block_admins))) { if (in_array($role->rid, $roles_set) || ($mode === 'block' && !in_array($role->rid, $block_admins))) {
// if (in_array($role->rid, $roles_set)) {
continue; continue;
} }
...@@ -185,18 +183,22 @@ function better_formats_get_formats_per_role() { ...@@ -185,18 +183,22 @@ function better_formats_get_formats_per_role() {
/** /**
* Get a list of roles that have a permission. * Get a list of roles that have a permission.
* *
* @param $perm
* Permission string to get roles for.
* @param $reset
* Boolean to clear static cache.
* @return * @return
* An numeric indexed key of role IDs. * An array of role IDs that have the requested permission.
*/ */
function better_formats_get_roles_by_perm($perm) { function better_formats_get_roles_by_perm($perm, $reset = FALSE) {
static $roles; static $roles;
if (!$roles[$perm]) { if ($reset || !$roles[$perm]) {
$sql = "SELECT rid $sql = "SELECT rid
FROM {permission} FROM {permission}
WHERE perm LIKE '%$perm%' WHERE perm LIKE '%$perm%'
ORDER BY rid"; ORDER BY rid";
$result = db_query($sql); $result = db_query($sql);
$roles = array(); $roles[$perm] = array();
while ($row = db_fetch_object($result)) { while ($row = db_fetch_object($result)) {
$roles[$perm][] = $row->rid; $roles[$perm][] = $row->rid;
} }
...@@ -207,7 +209,7 @@ function better_formats_get_roles_by_perm($perm) { ...@@ -207,7 +209,7 @@ function better_formats_get_roles_by_perm($perm) {
/** /**
* Process variables for better-defaults-admin-form.tpl.php. * Process variables for better-defaults-admin-form.tpl.php.
* *
* @param $variables * @param $vars
* The $variables array contains the following arguments: * The $variables array contains the following arguments:
* - $form * - $form
*/ */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment