You are here

function ckeditor_sorted_roles in CKEditor - WYSIWYG HTML editor 6

sort roles according to precedence settings. previously sorted roles are followed by latest added roles.

2 calls to ckeditor_sorted_roles()
ckeditor_admin_global_profile_form in includes/ckeditor.admin.inc
ckeditor_user_get_profile in includes/ckeditor.lib.inc

File

includes/ckeditor.lib.inc, line 560
CKEditor - The text editor for the Internet - http://ckeditor.com Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.

Code

function ckeditor_sorted_roles($clear = FALSE) {
  static $order;
  if (isset($order) && $clear !== TRUE) {
    return $order;
  }
  $order = array();
  $roles = user_roles(0, 'access ckeditor');
  $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name='CKEditor Global Profile'");
  $data = db_fetch_object($result);
  if (!empty($data->settings)) {
    $settings = unserialize($data->settings);
    if (isset($settings['rank']) && !empty($settings['rank'])) {
      foreach ($settings['rank'] as $rid) {
        if (isset($roles[$rid])) {
          $order[$rid] = $roles[$rid];
          unset($roles[$rid]);
        }
      }
    }
  }
  krsort($roles);

  //sort the remaining unsorted roles by id, descending.
  $order += $roles;
  return $order;
}