View source
<?php
function quickbar_help_permission() {
return array(
'administer quickbar_help' => array(
'title' => t('Administer quickbar_help'),
'description' => t('TODO'),
),
'access quickbar_help' => array(
'title' => t('Access quickbar_help'),
'description' => t('TODO'),
),
);
}
function quickbar_help_init() {
drupal_add_css(drupal_get_path('module', 'quickbar_help') . '/css/quickbar_help.css');
drupal_add_js(drupal_get_path('module', 'quickbar_help') . '/js/quickbar_help.js');
}
function quickbar_help_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'quickbar_configure_form') {
$form['submit']['#weight'] = 1000;
$form['help'] = array(
'#type' => 'fieldset',
'#title' => t('Help Settings'),
'#collapsible' => 1,
'#collapsed' => 0,
);
$current_help = array();
$result = db_select('quickbar_help', 'qh')
->fields('qh')
->condition('rid', arg(4))
->execute();
while ($record = $result
->fetchAssoc()) {
$current_help[$record['path']] = $record;
}
$menus = variable_get('quickbar_role_menus', array());
$menu_used = $menus[arg(4)];
$result = db_query("SELECT link_path, link_title FROM {menu_links}\n WHERE menu_name = :menu\n AND module <> 'menu_item_container'\n AND hidden = 0\n AND link_path NOT LIKE '%\\%%'\n GROUP BY link_path\n ORDER BY depth ASC, weight ASC", array(
':menu' => $menu_used,
));
$menu_found = 0;
while ($record = $result
->fetchAssoc()) {
$path = str_replace('<front>', '/', $record['link_path']);
$title = $record['link_title'];
$form['help'][$path] = array(
'#type' => 'fieldset',
'#title' => $title,
'#description' => t('Enter the text that will be linked to %path', array(
'%path' => $path == '/' ? '<front>' : '/' . $path,
)),
'#collapsible' => 1,
'#collapsed' => 1,
);
$form['help'][$path]['text'] = array(
'#type' => 'text_format',
'#title' => t('Help Text'),
'#default_value' => isset($current_help[$path]['text']) ? $current_help[$path]['text'] : '',
'#format' => isset($current_help[$path]['format']) ? $current_help[$path]['format'] : NULL,
);
$menu_found = 1;
}
if (!$menu_found) {
$form['help']['text'] = array(
'#type' => 'item',
'#value' => t('<em>There is not a menu associated with this role.</em>'),
);
}
$form['#submit'][] = 'quickbar_help_configure_form_submit';
}
}
function quickbar_help_configure_form_submit(&$form, &$form_state) {
$rid = $form_state['build_info']['args'][0];
$result = db_query("SELECT path FROM {quickbar_help} WHERE rid = :rid", array(
':rid' => $rid,
));
$current_paths = array();
while ($record = $result
->fetchField()) {
$current_paths[] = $record;
}
foreach ($form_state['values']['help'] as $path => $help) {
$text = $help['text']['value'];
$format = $help['text']['format'];
if (in_array($path, $current_paths)) {
if ($text != '') {
db_update('quickbar_help')
->fields(array(
'text' => $text,
'format' => $format,
))
->condition('path', $path)
->condition('rid', $rid)
->execute();
}
else {
db_delete('quickbar_help')
->condition('path', $path)
->condition('rid', $rid)
->execute();
}
}
else {
if ($text != '') {
db_insert('quickbar_help')
->fields(array(
'rid' => $rid,
'text' => $text,
'path' => $path,
'format' => 0,
'format' => $format,
))
->execute();
}
}
}
}
function quickbar_help_preprocess_quickbar(&$vars) {
global $user;
$set_class = 'not-active';
$current_path = drupal_get_path_alias();
if (drupal_is_front_page()) {
$current_path = '/';
}
$roles = variable_get('quickbar_role_weights', '');
if (is_array($roles)) {
asort($roles);
$menus = variable_get('quickbar_role_menus', array());
foreach ($roles as $rid => $weight) {
if (!empty($user->roles[$rid]) && $menus[$rid]) {
$result = db_query("SELECT path FROM {quickbar_help} WHERE path = :path AND rid = :rid", array(
':path' => $current_path,
':rid' => $rid,
))
->fetchField();
if ($result) {
$set_class = 'active';
break;
}
}
}
}
$vars['tree'][0]['help']['help-icon'] = array();
$vars['tree_0']['help'] = theme('links', array(
'links' => $vars['tree'][0]['help'],
'attributes' => array(
'class' => "links clearfix {$set_class}",
'id' => 'quickbar-help',
),
));
}
function quickbar_help_page_build(&$page) {
global $user;
$roles = variable_get('quickbar_role_weights', '');
$path = drupal_get_path_alias();
if (drupal_is_front_page()) {
$path = '/';
}
if (is_array($roles)) {
asort($roles);
$menus = variable_get('quickbar_role_menus', array());
foreach ($roles as $rid => $weight) {
if (!empty($user->roles[$rid]) && $menus[$rid]) {
$item = db_query("SELECT text, format FROM {quickbar_help}\n WHERE path = :path\n AND rid = :rid", array(
':path' => $path,
':rid' => $rid,
))
->fetchAssoc();
if ($item['text']) {
$page['page_bottom']['quickbar_help'] = array(
'#type' => 'markup',
'#markup' => "<div id='quickbar-help-box'><span class='close-button'></span>" . check_markup($item['text'], $item['format']) . '</div>',
);
}
}
}
}
}