function _outline_designer_setup in Outline Designer 7
Same name and namespace in other branches
- 6.2 outline_designer.module \_outline_designer_setup()
- 6 outline_designer.module \_outline_designer_setup()
- 7.2 outline_designer.module \_outline_designer_setup()
1 call to _outline_designer_setup()
File
- ./
outline_designer.module, line 50 - Massive usability improvement for quickly structuring / creating content.
Code
function _outline_designer_setup($nid, $ajax_path) {
global $user;
drupal_add_css(drupal_get_path('module', 'outline_designer') . '/css/outline_designer.css');
drupal_add_js(drupal_get_path('module', 'outline_designer') . '/script/jquery.contextmenu.js');
drupal_add_js(drupal_get_path('module', 'outline_designer') . '/script/overrides.js', array(
'type' => 'header',
'scope' => JS_DEFAULT,
));
drupal_add_js(drupal_get_path('module', 'outline_designer') . '/script/scripts.js', array(
'type' => 'footer',
'scope' => JS_DEFAULT,
));
// Select only those that the book module say can be outlined
$types_ary = variable_get('book_allowed_types', array(
'page',
));
// Make sure default is allowed by this user.
if (node_access('create', variable_get('book_child_type', 'book'))) {
$default_type = variable_get('book_child_type', 'book');
}
else {
foreach ($types_ary as $current_type) {
if (node_access('create', $current_type)) {
$default_type = $current_type;
}
}
}
// create the array of menu items unavailable to the user by combining
// the unavailable menu items in common in all of the user's roles
$unchecked_menu_items = array();
$view_all = FALSE;
if ($user->uid == 1) {
// user1 should always see all menu items
$view_all = TRUE;
}
else {
$saved_unchecked_items = variable_get('outline_designer_context_menu_exclusion_matrix', array());
// collect only the items unchecked in all of the user's roles
foreach (array_keys($user->roles) as $rid) {
if ($saved_unchecked_items[$rid] != NULL) {
$unchecked_menu_items = array_keys($saved_unchecked_items[$rid]);
if (isset($tmp)) {
$unchecked_menu_items = array_intersect($tmp, $unchecked_menu_items);
}
$tmp = $unchecked_menu_items;
}
else {
// because we're storing all the roles that are exceptions to the rule, if they have a role that isn't in the list, they automatically have access to all buttons in the context menu
$view_all = TRUE;
}
}
}
// the permission check found that this user should have access to view everything so ignore the unchecked metric
if ($view_all) {
$unchecked_menu_items = array();
}
$purl = '';
if (module_exists('purl')) {
$options = array();
// need to look for a group if it exists otherwise it should work fine
if (arg(0) == 'admin') {
$node = node_load($nid);
purl_url_outbound_alter($purl, $options, '');
$ajax_base_path = base_path() . $purl . $ajax_path;
$node = node_load($nid);
if (count($node->og_groups)) {
$group = node_load(array_pop($node->og_groups));
$ajax_base_path = base_path() . $group->purl . '/' . $ajax_path;
}
else {
$ajax_base_path = base_path() . $ajax_path;
}
}
else {
purl_url_outbound_alter($purl, $options, '');
$ajax_base_path = base_path() . $purl . $ajax_path;
}
}
else {
$ajax_base_path = base_path() . $ajax_path;
}
// pass variables to js
$js_variables = array(
'path' => base_path() . drupal_get_path('module', 'outline_designer') . '/',
'types' => array(),
'theme' => variable_get('outline_designer_theme', 'vista'),
'unavailableContextMenuItems' => array_values($unchecked_menu_items),
'collapseToggle' => variable_get('outline_designer_collapse_toggle', 1),
'collapseList' => array(),
'token' => drupal_get_token(),
'factor' => 1,
'activeNid' => '',
'rootNid' => $nid,
'defaultType' => $default_type,
'activeType' => $default_type,
'ajaxPath' => $ajax_base_path,
);
$result = db_query("SELECT type,name FROM {node_type} ORDER BY name");
while ($value = db_fetch_array($result)) {
// ensure there is no permission escalation
if (array_search($value['type'], $types_ary) === FALSE) {
}
elseif (node_access('create', $value['type'])) {
$js_variables['types'][$value['type']] = array(
$value['name'],
variable_get("outline_designer_" . $value['type'] . "_icon", drupal_get_path('module', 'outline_designer') . "/images/page.png"),
);
}
}
drupal_add_js(array(
'outline_designer' => $js_variables,
), array(
'type' => "setting",
'scope' => JS_DEFAULT,
));
// dual purpose of the function, since we calcuated this array, return it in-case we need to hide the add button
return array_values($unchecked_menu_items);
}