summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.26/modules/shortcut
diff options
context:
space:
mode:
Diffstat (limited to 'kolab.org/www/drupal-7.26/modules/shortcut')
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut-rtl.css48
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.css8
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.inc788
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.js115
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.api.php42
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.css106
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.info13
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.install115
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.module767
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.pngbin0 -> 558 bytes
-rw-r--r--kolab.org/www/drupal-7.26/modules/shortcut/shortcut.test371
11 files changed, 2373 insertions, 0 deletions
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut-rtl.css b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut-rtl.css
new file mode 100644
index 0000000..5dec957
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut-rtl.css
@@ -0,0 +1,48 @@
+
+div#toolbar a#edit-shortcuts {
+ position: absolute;
+ left: 0;
+ top: 0;
+ padding: 5px 5px 5px 10px;
+}
+div#toolbar div.toolbar-shortcuts ul {
+ float: none;
+ margin-right: 5px;
+ margin-left: 10em;
+}
+div#toolbar div.toolbar-shortcuts ul li a {
+ margin-left: 5px;
+ margin-right: 0;
+ padding: 0 5px;
+}
+div#toolbar div.toolbar-shortcuts span.icon {
+ float: right;
+}
+div.add-or-remove-shortcuts a span.icon {
+ float: right;
+ margin-right: 8px;
+ margin-left: 0;
+}
+div.add-or-remove-shortcuts a span.text {
+ float: right;
+ padding-right: 10px;
+ padding-left: 0;
+}
+div.add-or-remove-shortcuts a:focus span.text,
+div.add-or-remove-shortcuts a:hover span.text {
+ -moz-border-radius: 5px 0 0 5px;
+ -webkit-border-top-left-radius: 5px;
+ -webkit-border-bottom-left-radius: 5px;
+ border-radius: 5px 0 0 5px;
+ padding-left: 6px;
+}
+#shortcut-set-switch .form-item-new {
+ padding-right: 17px;
+ padding-left: 0;
+}
+div.add-shortcut a:hover span.icon {
+ background-position: 0 -24px;
+}
+div.remove-shortcut a:hover span.icon {
+ background-position: -12px -24px;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.css b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.css
new file mode 100644
index 0000000..8ca03be
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.css
@@ -0,0 +1,8 @@
+
+.shortcut-slot-hidden {
+ display: none;
+}
+
+div.form-item-set div.form-item-new {
+ display: inline;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.inc b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.inc
new file mode 100644
index 0000000..2e8ddb4
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.inc
@@ -0,0 +1,788 @@
+<?php
+
+/**
+ * @file
+ * Administrative page callbacks for the shortcut module.
+ */
+
+/**
+ * Returns the maximum number of shortcut "slots" available per shortcut set.
+ *
+ * This is used as a limitation in the user interface only.
+ *
+ * @return
+ * The maximum number of shortcuts allowed to be added to a shortcut set.
+ */
+function shortcut_max_slots() {
+ return variable_get('shortcut_max_slots', 7);
+}
+
+/**
+ * Form callback: builds the form for switching shortcut sets.
+ *
+ * @param $form
+ * An associative array containing the structure of the form.
+ * @param $form_state
+ * An associative array containing the current state of the form.
+ * @param $account
+ * (optional) The user account whose shortcuts will be switched. Defaults to
+ * the current logged-in user.
+ *
+ * @return
+ * An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_set_switch_validate()
+ * @see shortcut_set_switch_submit()
+ */
+function shortcut_set_switch($form, &$form_state, $account = NULL) {
+ global $user;
+ if (!isset($account)) {
+ $account = $user;
+ }
+
+ // Prepare the list of shortcut sets.
+ $sets = shortcut_sets();
+ $current_set = shortcut_current_displayed_set($account);
+
+ $options = array();
+ foreach ($sets as $name => $set) {
+ $options[$name] = check_plain($set->title);
+ }
+
+ // Only administrators can add shortcut sets.
+ $add_access = user_access('administer shortcuts');
+ if ($add_access) {
+ $options['new'] = t('New set');
+ }
+
+ if (count($options) > 1) {
+ $form['account'] = array(
+ '#type' => 'value',
+ '#value' => $account,
+ );
+
+ $form['set'] = array(
+ '#type' => 'radios',
+ '#title' => $user->uid == $account->uid ? t('Choose a set of shortcuts to use') : t('Choose a set of shortcuts for this user'),
+ '#options' => $options,
+ '#default_value' => $current_set->set_name,
+ );
+
+ $form['new'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name'),
+ '#title_display' => 'invisible',
+ '#description' => t('The new set is created by copying items from your default shortcut set.'),
+ '#access' => $add_access,
+ );
+
+ if ($user->uid != $account->uid) {
+ $default_set = shortcut_default_set($account);
+ $form['new']['#description'] = t('The new set is created by copying items from the %default set.', array('%default' => $default_set->title));
+ }
+
+ $form['#attached'] = array(
+ 'css' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.css'),
+ 'js' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.js'),
+ );
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Change set'),
+ );
+ }
+ else {
+ // There is only 1 option, so output a message in the $form array.
+ $form['info'] = array(
+ '#markup' => '<p>' . t('You are currently using the %set-name shortcut set.', array('%set-name' => $current_set->title)) . '</p>',
+ );
+ }
+
+ return $form;
+}
+
+/**
+ * Validation handler for shortcut_set_switch().
+ */
+function shortcut_set_switch_validate($form, &$form_state) {
+ if ($form_state['values']['set'] == 'new') {
+ // Check to prevent creating a shortcut set with an empty title.
+ if (trim($form_state['values']['new']) == '') {
+ form_set_error('new', t('The new set name is required.'));
+ }
+ // Check to prevent a duplicate title.
+ if (shortcut_set_title_exists($form_state['values']['new'])) {
+ form_set_error('new', t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['new'])));
+ }
+ }
+}
+
+/**
+ * Submit handler for shortcut_set_switch().
+ */
+function shortcut_set_switch_submit($form, &$form_state) {
+ global $user;
+ $account = $form_state['values']['account'];
+
+ if ($form_state['values']['set'] == 'new') {
+ // Save a new shortcut set with links copied from the user's default set.
+ $default_set = shortcut_default_set($account);
+ $set = (object) array(
+ 'title' => $form_state['values']['new'],
+ 'links' => menu_links_clone($default_set->links),
+ );
+ shortcut_set_save($set);
+ $replacements = array(
+ '%user' => $account->name,
+ '%set_name' => $set->title,
+ '@switch-url' => url(current_path()),
+ );
+ if ($account->uid == $user->uid) {
+ // Only administrators can create new shortcut sets, so we know they have
+ // access to switch back.
+ drupal_set_message(t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href="@switch-url">switch back to a different one.</a>', $replacements));
+ }
+ else {
+ drupal_set_message(t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements));
+ }
+ $form_state['redirect'] = 'admin/config/user-interface/shortcut/' . $set->set_name;
+ }
+ else {
+ // Switch to a different shortcut set.
+ $set = shortcut_set_load($form_state['values']['set']);
+ $replacements = array(
+ '%user' => $account->name,
+ '%set_name' => $set->title,
+ );
+ drupal_set_message($account->uid == $user->uid ? t('You are now using the %set_name shortcut set.', $replacements) : t('%user is now using the %set_name shortcut set.', $replacements));
+ }
+
+ // Assign the shortcut set to the provided user account.
+ shortcut_set_assign_user($set, $account);
+}
+
+/**
+ * Menu page callback: builds the page for administering shortcut sets.
+ */
+function shortcut_set_admin() {
+ $shortcut_sets = shortcut_sets();
+ $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 4));
+
+ $rows = array();
+ foreach ($shortcut_sets as $set) {
+ $row = array(
+ check_plain($set->title),
+ l(t('list links'), "admin/config/user-interface/shortcut/$set->set_name"),
+ l(t('edit set name'), "admin/config/user-interface/shortcut/$set->set_name/edit"),
+ );
+ if (shortcut_set_delete_access($set)) {
+ $row[] = l(t('delete set'), "admin/config/user-interface/shortcut/$set->set_name/delete");
+ }
+ else {
+ $row[] = '';
+ }
+
+ $rows[] = $row;
+ }
+
+ return theme('table', array('header' => $header, 'rows' => $rows));
+}
+
+/**
+ * Form callback: builds the form for adding a shortcut set.
+ *
+ * @param $form
+ * An associative array containing the structure of the form.
+ * @param $form_state
+ * An associative array containing the current state of the form.
+ *
+ * @return
+ * An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_set_add_form_validate()
+ * @see shortcut_set_add_form_submit()
+ */
+function shortcut_set_add_form($form, &$form_state) {
+ $form['new'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Set name'),
+ '#description' => t('The new set is created by copying items from your default shortcut set.'),
+ '#required' => TRUE,
+ );
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Create new set'),
+ );
+
+ return $form;
+}
+
+/**
+ * Validation handler for shortcut_set_add_form().
+ */
+function shortcut_set_add_form_validate($form, &$form_state) {
+ // Check to prevent a duplicate title.
+ if (shortcut_set_title_exists($form_state['values']['new'])) {
+ form_set_error('new', t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['new'])));
+ }
+}
+
+/**
+ * Submit handler for shortcut_set_add_form().
+ */
+function shortcut_set_add_form_submit($form, &$form_state) {
+ // Save a new shortcut set with links copied from the user's default set.
+ $default_set = shortcut_default_set();
+ $set = (object) array(
+ 'title' => $form_state['values']['new'],
+ 'links' => menu_links_clone($default_set->links),
+ );
+ shortcut_set_save($set);
+ drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', array('%set_name' => $set->title)));
+ $form_state['redirect'] = 'admin/config/user-interface/shortcut/' . $set->set_name;
+}
+
+/**
+ * Form callback: builds the form for customizing shortcut sets.
+ *
+ * @param $form
+ * An associative array containing the structure of the form.
+ * @param $form_state
+ * An associative array containing the current state of the form.
+ * @param $shortcut_set
+ * An object representing the shortcut set which is being edited.
+ *
+ * @return
+ * An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_set_customize_submit()
+ */
+function shortcut_set_customize($form, &$form_state, $shortcut_set) {
+ $form['#shortcut_set_name'] = $shortcut_set->set_name;
+ $form['shortcuts'] = array(
+ '#tree' => TRUE,
+ '#weight' => -20,
+ 'enabled' => array(),
+ 'disabled' => array(),
+ );
+
+ foreach ($shortcut_set->links as $link) {
+ $mlid = $link['mlid'];
+ $status = $link['hidden'] ? 'disabled' : 'enabled';
+ $form['shortcuts'][$status][$mlid]['name']['#markup'] = l($link['link_title'], $link['link_path']);
+ $form['shortcuts'][$status][$mlid]['weight'] = array(
+ '#type' => 'weight',
+ '#title' => t('Weight'),
+ '#delta' => 50,
+ '#default_value' => $link['weight'],
+ '#attributes' => array('class' => array('shortcut-weight')),
+ );
+ $form['shortcuts'][$status][$mlid]['status'] = array(
+ '#type' => 'select',
+ '#title' => t('Status'),
+ '#options' => array('disabled' => t('Disabled'), 'enabled' => t('Enabled')),
+ '#default_value' => $status,
+ '#attributes' => array('class' => array('shortcut-status-select')),
+ );
+
+ $form['shortcuts'][$status][$mlid]['edit']['#markup'] = l(t('edit'), 'admin/config/user-interface/shortcut/link/' . $mlid);
+ $form['shortcuts'][$status][$mlid]['delete']['#markup'] = l(t('delete'), 'admin/config/user-interface/shortcut/link/' . $mlid . '/delete');
+ }
+
+ $form['#attached'] = array(
+ 'css' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.css'),
+ 'js' => array(drupal_get_path('module', 'shortcut') . '/shortcut.admin.js'),
+ );
+
+ $form['actions'] = array(
+ '#type' => 'actions',
+ '#access' => !empty($shortcut_set->links),
+ );
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save changes'),
+ );
+
+ return $form;
+}
+
+/**
+ * Submit handler for shortcut_set_customize().
+ */
+function shortcut_set_customize_submit($form, &$form_state) {
+ foreach ($form_state['values']['shortcuts'] as $group => $links) {
+ foreach ($links as $mlid => $data) {
+ $link = menu_link_load($mlid);
+ $link['hidden'] = $data['status'] == 'enabled' ? 0 : 1;
+ $link['weight'] = $data['weight'];
+ menu_link_save($link);
+ }
+ }
+ drupal_set_message(t('The shortcut set has been updated.'));
+}
+
+/**
+ * Returns HTML for a shortcut set customization form.
+ *
+ * @param $variables
+ * An associative array containing:
+ * - form: A render element representing the form.
+ *
+ * @see shortcut_set_customize()
+ * @ingroup themeable
+ */
+function theme_shortcut_set_customize($variables) {
+ $form = $variables['form'];
+ $map = array('disabled' => t('Disabled'), 'enabled' => t('Enabled'));
+ $shortcuts_by_status = array(
+ 'enabled' => element_children($form['shortcuts']['enabled']),
+ 'disabled' => element_children($form['shortcuts']['disabled']),
+ );
+ // Do not add any rows to the table if there are no shortcuts to display.
+ $statuses = empty($shortcuts_by_status['enabled']) && empty($shortcuts_by_status['disabled']) ? array() : array_keys($shortcuts_by_status);
+
+ $rows = array();
+ foreach ($statuses as $status) {
+ drupal_add_tabledrag('shortcuts', 'match', 'sibling', 'shortcut-status-select');
+ drupal_add_tabledrag('shortcuts', 'order', 'sibling', 'shortcut-weight');
+ $rows[] = array(
+ 'data' => array(array(
+ 'colspan' => 5,
+ 'data' => '<strong>' . $map[$status] . '</strong>',
+ )),
+ 'class' => array('shortcut-status', 'shortcut-status-' . $status),
+ );
+
+ foreach ($shortcuts_by_status[$status] as $key) {
+ $shortcut = &$form['shortcuts'][$status][$key];
+ $row = array();
+ $row[] = drupal_render($shortcut['name']);
+ $row[] = drupal_render($shortcut['weight']);
+ $row[] = drupal_render($shortcut['status']);
+ $row[] = drupal_render($shortcut['edit']);
+ $row[] = drupal_render($shortcut['delete']);
+ $rows[] = array(
+ 'data' => $row,
+ 'class' => array('draggable'),
+ );
+ }
+
+ if ($status == 'enabled') {
+ for ($i = 0; $i < shortcut_max_slots(); $i++) {
+ $rows['empty-' . $i] = array(
+ 'data' => array(array(
+ 'colspan' => 5,
+ 'data' => '<em>' . t('Empty') . '</em>',
+ )),
+ 'class' => array('shortcut-slot-empty'),
+ );
+ }
+ $count_shortcuts = count($shortcuts_by_status[$status]);
+ if (!empty($count_shortcuts)) {
+ for ($i = 0; $i < min($count_shortcuts, shortcut_max_slots()); $i++) {
+ $rows['empty-' . $i]['class'][] = 'shortcut-slot-hidden';
+ }
+ }
+ }
+ }
+
+ $header = array(t('Name'), t('Weight'), t('Status'), array('data' => t('Operations'), 'colspan' => 2));
+ $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'shortcuts'), 'empty' => t('No shortcuts available. <a href="@link">Add a shortcut</a>.', array('@link' => url('admin/config/user-interface/shortcut/' . $form['#shortcut_set_name'] . '/add-link')))));
+ $output .= drupal_render($form['actions']);
+ $output = drupal_render_children($form) . $output;
+ return $output;
+}
+
+/**
+ * Form callback: builds the form for adding a new shortcut link.
+ *
+ * @param $form
+ * An associative array containing the structure of the form.
+ * @param $form_state
+ * An associative array containing the current state of the form.
+ * @param $shortcut_set
+ * An object representing the shortcut set to which the link will be added.
+ *
+ * @return
+ * An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_link_edit_validate()
+ * @see shortcut_link_add_submit()
+ */
+function shortcut_link_add($form, &$form_state, $shortcut_set) {
+ drupal_set_title(t('Add new shortcut'));
+ $form['shortcut_set'] = array(
+ '#type' => 'value',
+ '#value' => $shortcut_set,
+ );
+ $form += _shortcut_link_form_elements();
+ return $form;
+}
+
+/**
+ * Form callback: builds the form for editing a shortcut link.
+ *
+ * @param $form
+ * An associative array containing the structure of the form.
+ * @param $form_state
+ * An associative array containing the current state of the form.
+ * @param $shortcut_link
+ * An array representing the link that is being edited.
+ *
+ * @return
+ * An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_link_edit_validate()
+ * @see shortcut_link_edit_submit()
+ */
+function shortcut_link_edit($form, &$form_state, $shortcut_link) {
+ drupal_set_title(t('Editing @shortcut', array('@shortcut' => $shortcut_link['link_title'])));
+ $form['original_shortcut_link'] = array(
+ '#type' => 'value',
+ '#value' => $shortcut_link,
+ );
+ $form += _shortcut_link_form_elements($shortcut_link);
+ return $form;
+}
+
+/**
+ * Helper function for building a form for adding or editing shortcut links.
+ *
+ * @param $shortcut_link
+ * (optional) An array representing the shortcut link that will be edited. If
+ * not provided, a new link will be created.
+ *
+ * @return
+ * An array of form elements.
+ */
+function _shortcut_link_form_elements($shortcut_link = NULL) {
+ if (!isset($shortcut_link)) {
+ $shortcut_link = array(
+ 'link_title' => '',
+ 'link_path' => ''
+ );
+ }
+ else {
+ $shortcut_link['link_path'] = ($shortcut_link['link_path'] == '<front>') ? '' : drupal_get_path_alias($shortcut_link['link_path']);
+ }
+
+ $form['shortcut_link']['#tree'] = TRUE;
+ $form['shortcut_link']['link_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name'),
+ '#description' => t('The name of the shortcut.'),
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#default_value' => $shortcut_link['link_title'],
+ '#required' => TRUE,
+ );
+
+ $form['shortcut_link']['link_path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Path'),
+ '#description' => t('The path to the shortcut.'),
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
+ '#default_value' => $shortcut_link['link_path'],
+ );
+
+ $form['#validate'][] = 'shortcut_link_edit_validate';
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ );
+
+ return $form;
+}
+
+/**
+ * Validation handler for the shortcut link add and edit forms.
+ */
+function shortcut_link_edit_validate($form, &$form_state) {
+ if (!shortcut_valid_link($form_state['values']['shortcut_link']['link_path'])) {
+ form_set_error('shortcut_link][link_path', t('The link must correspond to a valid path on the site.'));
+ }
+}
+
+/**
+ * Submit handler for shortcut_link_edit().
+ */
+function shortcut_link_edit_submit($form, &$form_state) {
+ // Normalize the path in case it is an alias.
+ $shortcut_path = drupal_get_normal_path($form_state['values']['shortcut_link']['link_path']);
+ if (empty($shortcut_path)) {
+ $shortcut_path = '<front>';
+ }
+ $form_state['values']['shortcut_link']['link_path'] = $shortcut_path;
+
+ $shortcut_link = array_merge($form_state['values']['original_shortcut_link'], $form_state['values']['shortcut_link']);
+
+ menu_link_save($shortcut_link);
+ $form_state['redirect'] = 'admin/config/user-interface/shortcut/' . $shortcut_link['menu_name'];
+ drupal_set_message(t('The shortcut %link has been updated.', array('%link' => $shortcut_link['link_title'])));
+}
+
+/**
+ * Submit handler for shortcut_link_add().
+ */
+function shortcut_link_add_submit($form, &$form_state) {
+ // Add the shortcut link to the set.
+ $shortcut_set = $form_state['values']['shortcut_set'];
+ $shortcut_link = $form_state['values']['shortcut_link'];
+ $shortcut_link['menu_name'] = $shortcut_set->set_name;
+ shortcut_admin_add_link($shortcut_link, $shortcut_set, shortcut_max_slots());
+ shortcut_set_save($shortcut_set);
+ $form_state['redirect'] = 'admin/config/user-interface/shortcut/' . $shortcut_link['menu_name'];
+ drupal_set_message(t('Added a shortcut for %title.', array('%title' => $shortcut_link['link_title'])));
+}
+
+/**
+ * Adds a link to the end of a shortcut set, keeping within a prescribed limit.
+ *
+ * @param $link
+ * An array representing a shortcut link.
+ * @param $shortcut_set
+ * An object representing the shortcut set which the link will be added to.
+ * The links in the shortcut set will be re-weighted so that the new link is
+ * at the end, and some existing links may be disabled (if the $limit
+ * parameter is provided).
+ * @param $limit
+ * (optional) The maximum number of links that are allowed to be enabled for
+ * this shortcut set. If provided, existing links at the end of the list that
+ * exceed the limit will be automatically disabled. If not provided, no limit
+ * will be enforced.
+ */
+function shortcut_admin_add_link($shortcut_link, &$shortcut_set, $limit = NULL) {
+ if (isset($limit)) {
+ // Disable any existing links at the end of the list that would cause the
+ // limit to be exceeded. Take into account whether or not the new link will
+ // be enabled and count towards the total.
+ $number_enabled = !empty($shortcut_link['hidden']) ? 0 : 1;
+ foreach ($shortcut_set->links as &$link) {
+ if (!$link['hidden']) {
+ $number_enabled++;
+ if ($number_enabled > $limit) {
+ $link['hidden'] = 1;
+ }
+ }
+ }
+ }
+
+ // Normalize the path in case it is an alias.
+ $shortcut_link['link_path'] = drupal_get_normal_path($shortcut_link['link_path']);
+ if (empty($shortcut_link['link_path'])) {
+ $shortcut_link['link_path'] = '<front>';
+ }
+
+ // Add the link to the end of the list.
+ $shortcut_set->links[] = $shortcut_link;
+ shortcut_set_reset_link_weights($shortcut_set);
+}
+
+/**
+ * Form callback: builds the form for editing the shortcut set name.
+ *
+ * @param $form
+ * An associative array containing the structure of the form.
+ * @param $form_state
+ * An associative array containing the current state of the form.
+ * @param object $shortcut_set
+ * An object representing the shortcut set, as returned from
+ * shortcut_set_load().
+ *
+ * @return
+ * An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_set_edit_form_validate()
+ * @see shortcut_set_edit_form_submit()
+ */
+function shortcut_set_edit_form($form, &$form_state, $shortcut_set) {
+ $form['shortcut_set'] = array(
+ '#type' => 'value',
+ '#value' => $shortcut_set,
+ );
+ $form['title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Set name'),
+ '#default_value' => $shortcut_set->title,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#weight' => -5,
+ );
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ '#weight' => 5,
+ );
+
+ return $form;
+}
+
+/**
+ * Validation handler for shortcut_set_edit_form().
+ */
+function shortcut_set_edit_form_validate($form, &$form_state) {
+ // Check to prevent a duplicate title, if the title was edited from its
+ // original value.
+ if ($form_state['values']['title'] != $form_state['values']['shortcut_set']->title && shortcut_set_title_exists($form_state['values']['title'])) {
+ form_set_error('title', t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['title'])));
+ }
+}
+
+/**
+ * Submit handler for shortcut_set_edit_form().
+ */
+function shortcut_set_edit_form_submit($form, &$form_state) {
+ $shortcut_set = $form_state['values']['shortcut_set'];
+ $shortcut_set->title = $form_state['values']['title'];
+ shortcut_set_save($shortcut_set);
+ drupal_set_message(t('Updated set name to %set-name.', array('%set-name' => $shortcut_set->title)));
+ $form_state['redirect'] = "admin/config/user-interface/shortcut/$shortcut_set->set_name";
+}
+
+/**
+ * Form callback: builds the confirmation form for deleting a shortcut set.
+ *
+ * @param $form
+ * An associative array containing the structure of the form.
+ * @param $form_state
+ * An associative array containing the current state of the form.
+ * @param object $shortcut_set
+ * An object representing the shortcut set, as returned from
+ * shortcut_set_load().
+ *
+ * @return
+ * An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_set_delete_form_submit()
+ */
+function shortcut_set_delete_form($form, &$form_state, $shortcut_set) {
+ $form['shortcut_set'] = array(
+ '#type' => 'value',
+ '#value' => $shortcut_set->set_name,
+ );
+
+ // Find out how many users are directly assigned to this shortcut set, and
+ // make a message.
+ $number = db_query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $shortcut_set->set_name))->fetchField();
+ $info = '';
+ if ($number) {
+ $info .= '<p>' . format_plural($number,
+ '1 user has chosen or been assigned to this shortcut set.',
+ '@count users have chosen or been assigned to this shortcut set.') . '</p>';
+ }
+
+ // Also, if a module implements hook_shortcut_default_set(), it's possible
+ // that this set is being used as a default set. Add a message about that too.
+ if (count(module_implements('shortcut_default_set')) > 0) {
+ $info .= '<p>' . t('If you have chosen this shortcut set as the default for some or all users, they may also be affected by deleting it.') . '</p>';
+ }
+
+ $form['info'] = array(
+ '#markup' => $info,
+ );
+
+ return confirm_form(
+ $form,
+ t('Are you sure you want to delete the shortcut set %title?', array('%title' => $shortcut_set->title)),
+ 'admin/config/user-interface/shortcut/' . $shortcut_set->set_name,
+ t('This action cannot be undone.'),
+ t('Delete'),
+ t('Cancel')
+ );
+}
+
+/**
+ * Submit handler for shortcut_set_delete_form().
+ */
+function shortcut_set_delete_form_submit($form, &$form_state) {
+ $shortcut_set = shortcut_set_load($form_state['values']['shortcut_set']);
+ shortcut_set_delete($shortcut_set);
+ $form_state['redirect'] = 'admin/config/user-interface/shortcut';
+ drupal_set_message(t('The shortcut set %title has been deleted.', array('%title' => $shortcut_set->title)));
+}
+
+/**
+ * Form callback: builds the confirmation form for deleting a shortcut link.
+ *
+ * @param $form
+ * An associative array containing the structure of the form.
+ * @param $form_state
+ * An associative array containing the current state of the form.
+ * @param $shortcut_link
+ * An array representing the link that will be deleted.
+ *
+ * @return
+ * An array representing the form definition.
+ *
+ * @ingroup forms
+ * @see shortcut_link_delete_submit()
+ */
+function shortcut_link_delete($form, &$form_state, $shortcut_link) {
+ $form['shortcut_link'] = array(
+ '#type' => 'value',
+ '#value' => $shortcut_link,
+ );
+
+ return confirm_form(
+ $form,
+ t('Are you sure you want to delete the shortcut %title?', array('%title' => $shortcut_link['link_title'])),
+ 'admin/config/user-interface/shortcut/' . $shortcut_link['menu_name'],
+ t('This action cannot be undone.'),
+ t('Delete'),
+ t('Cancel')
+ );
+}
+
+/**
+ * Submit handler for shortcut_link_delete_submit().
+ */
+function shortcut_link_delete_submit($form, &$form_state) {
+ $shortcut_link = $form_state['values']['shortcut_link'];
+ menu_link_delete($shortcut_link['mlid']);
+ $form_state['redirect'] = 'admin/config/user-interface/shortcut/' . $shortcut_link['menu_name'];
+ drupal_set_message(t('The shortcut %title has been deleted.', array('%title' => $shortcut_link['link_title'])));
+}
+
+/**
+ * Menu page callback: creates a new link in the provided shortcut set.
+ *
+ * After completion, redirects the user back to where they came from.
+ *
+ * @param $shortcut_set
+ * Returned from shortcut_set_load().
+ */
+function shortcut_link_add_inline($shortcut_set) {
+ if (isset($_REQUEST['token']) && drupal_valid_token($_REQUEST['token'], 'shortcut-add-link') && shortcut_valid_link($_GET['link'])) {
+ $item = menu_get_item($_GET['link']);
+ $title = ($item && $item['title']) ? $item['title'] : $_GET['name'];
+ $link = array(
+ 'link_title' => $title,
+ 'link_path' => $_GET['link'],
+ );
+ shortcut_admin_add_link($link, $shortcut_set, shortcut_max_slots());
+ if (shortcut_set_save($shortcut_set)) {
+ drupal_set_message(t('Added a shortcut for %title.', array('%title' => $link['link_title'])));
+ }
+ else {
+ drupal_set_message(t('Unable to add a shortcut for %title.', array('%title' => $link['link_title'])));
+ }
+ drupal_goto();
+ }
+
+ return MENU_ACCESS_DENIED;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.js b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.js
new file mode 100644
index 0000000..422cc4c
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.admin.js
@@ -0,0 +1,115 @@
+(function ($) {
+
+/**
+ * Handle the concept of a fixed number of slots.
+ *
+ * This behavior is dependent on the tableDrag behavior, since it uses the
+ * objects initialized in that behavior to update the row.
+ */
+Drupal.behaviors.shortcutDrag = {
+ attach: function (context, settings) {
+ if (Drupal.tableDrag) {
+ var table = $('table#shortcuts'),
+ visibleLength = 0,
+ slots = 0,
+ tableDrag = Drupal.tableDrag.shortcuts;
+ $('> tbody > tr, > tr', table)
+ .filter(':visible')
+ .filter(':odd').filter('.odd')
+ .removeClass('odd').addClass('even')
+ .end().end()
+ .filter(':even').filter('.even')
+ .removeClass('even').addClass('odd')
+ .end().end()
+ .end()
+ .filter('.shortcut-slot-empty').each(function(index) {
+ if ($(this).is(':visible')) {
+ visibleLength++;
+ }
+ slots++;
+ });
+
+ // Add a handler for when a row is swapped.
+ tableDrag.row.prototype.onSwap = function (swappedRow) {
+ var disabledIndex = $(table).find('tr').index($(table).find('tr.shortcut-status-disabled')) - slots - 2,
+ count = 0;
+ $(table).find('tr.shortcut-status-enabled').nextAll(':not(.shortcut-slot-empty)').each(function(index) {
+ if (index < disabledIndex) {
+ count++;
+ }
+ });
+ var total = slots - count;
+ if (total == -1) {
+ var disabled = $(table).find('tr.shortcut-status-disabled');
+ // To maintain the shortcut links limit, we need to move the last
+ // element from the enabled section to the disabled section.
+ var changedRow = disabled.prevAll(':not(.shortcut-slot-empty)').not($(this.element)).get(0);
+ disabled.after(changedRow);
+ if ($(changedRow).hasClass('draggable')) {
+ // The dropped element will automatically be marked as changed by
+ // the tableDrag system. However, the row that swapped with it
+ // has moved to the "disabled" section, so we need to force its
+ // status to be disabled and mark it also as changed.
+ var changedRowObject = new tableDrag.row(changedRow, 'mouse', false, 0, true);
+ changedRowObject.markChanged();
+ tableDrag.rowStatusChange(changedRowObject);
+ }
+ }
+ else if (total != visibleLength) {
+ if (total > visibleLength) {
+ // Less slots on screen than needed.
+ $('.shortcut-slot-empty:hidden:last').show();
+ visibleLength++;
+ }
+ else {
+ // More slots on screen than needed.
+ $('.shortcut-slot-empty:visible:last').hide();
+ visibleLength--;
+ }
+ }
+ };
+
+ // Add a handler so when a row is dropped, update fields dropped into new regions.
+ tableDrag.onDrop = function () {
+ tableDrag.rowStatusChange(this.rowObject);
+ return true;
+ };
+
+ tableDrag.rowStatusChange = function (rowObject) {
+ // Use "status-message" row instead of "status" row because
+ // "status-{status_name}-message" is less prone to regexp match errors.
+ var statusRow = $(rowObject.element).prevAll('tr.shortcut-status').get(0);
+ var statusName = statusRow.className.replace(/([^ ]+[ ]+)*shortcut-status-([^ ]+)([ ]+[^ ]+)*/, '$2');
+ var statusField = $('select.shortcut-status-select', rowObject.element);
+ statusField.val(statusName);
+ };
+
+ tableDrag.restripeTable = function () {
+ // :even and :odd are reversed because jQuery counts from 0 and
+ // we count from 1, so we're out of sync.
+ // Match immediate children of the parent element to allow nesting.
+ $('> tbody > tr:visible, > tr:visible', this.table)
+ .filter(':odd').filter('.odd')
+ .removeClass('odd').addClass('even')
+ .end().end()
+ .filter(':even').filter('.even')
+ .removeClass('even').addClass('odd');
+ };
+ }
+ }
+};
+
+/**
+ * Make it so when you enter text into the "New set" textfield, the
+ * corresponding radio button gets selected.
+ */
+Drupal.behaviors.newSet = {
+ attach: function (context, settings) {
+ var selectDefault = function() {
+ $(this).closest('form').find('.form-item-set .form-type-radio:last input').attr('checked', 'checked');
+ };
+ $('div.form-item-new input').focus(selectDefault).keyup(selectDefault);
+ }
+};
+
+})(jQuery);
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.api.php b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.api.php
new file mode 100644
index 0000000..717a7c9
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.api.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * @file
+ * Hooks provided by the Shortcut module.
+ */
+
+/**
+ * @addtogroup hooks
+ * @{
+ */
+
+/**
+ * Return the name of a default shortcut set for the provided user account.
+ *
+ * This hook allows modules to define default shortcut sets for a particular
+ * user that differ from the site-wide default (for example, a module may want
+ * to define default shortcuts on a per-role basis).
+ *
+ * The default shortcut set is used only when the user does not have any other
+ * shortcut set explicitly assigned to them.
+ *
+ * Note that only one default shortcut set can exist per user, so when multiple
+ * modules implement this hook, the last (i.e., highest weighted) module which
+ * returns a valid shortcut set name will prevail.
+ *
+ * @param $account
+ * The user account whose default shortcut set is being requested.
+ * @return
+ * The name of the shortcut set that this module recommends for that user, if
+ * there is one.
+ */
+function hook_shortcut_default_set($account) {
+ // Use a special set of default shortcuts for administrators only.
+ if (in_array(variable_get('user_admin_role', 0), $account->roles)) {
+ return variable_get('mymodule_shortcut_admin_default_set');
+ }
+}
+
+/**
+ * @} End of "addtogroup hooks".
+ */
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.css b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.css
new file mode 100644
index 0000000..3afcb94
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.css
@@ -0,0 +1,106 @@
+div#toolbar a#edit-shortcuts {
+ float: right;
+ padding: 5px 10px 5px 5px;
+ line-height: 24px;
+ color: #fefefe;
+}
+div#toolbar a#edit-shortcuts:focus,
+div#toolbar a#edit-shortcuts:hover,
+div#toolbar a#edit-shortcuts.active {
+ color: #fff;
+ text-decoration: underline;
+}
+
+div#toolbar div.toolbar-shortcuts ul {
+ padding: 5px 0 2px 0;
+ height: 28px;
+ line-height: 24px;
+ float: left; /* LTR */
+ margin-left:5px; /* LTR */
+}
+
+div#toolbar div.toolbar-shortcuts ul li a {
+ padding: 0 5px 0 5px;
+ margin-right: 5px; /* LTR */
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border-radius: 5px;
+}
+
+div#toolbar div.toolbar-shortcuts ul li a:focus,
+div#toolbar div.toolbar-shortcuts ul li a:hover,
+div#toolbar div.toolbar-shortcuts ul li a.active:focus {
+ background: #555;
+}
+
+div#toolbar div.toolbar-shortcuts ul li a.active:hover,
+div#toolbar div.toolbar-shortcuts ul li a.active {
+ background: #000;
+}
+
+div#toolbar div.toolbar-shortcuts span.icon {
+ float: left; /* LTR */
+ background: #444;
+ width: 30px;
+ height: 30px;
+ margin-right: 5px; /* LTR */
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border-radius: 5px;
+}
+
+div.add-or-remove-shortcuts {
+ padding-top: 5px;
+}
+
+div.add-or-remove-shortcuts a span.icon {
+ display: block;
+ width: 12px;
+ background: transparent url(shortcut.png) no-repeat scroll 0 0;
+ height: 12px;
+ float: left;
+ margin-left:8px;
+}
+
+div.add-shortcut a:focus span.icon,
+div.add-shortcut a:hover span.icon {
+ background-position: 0 -12px;
+}
+div.remove-shortcut a span.icon {
+ background-position: -12px 0;
+}
+div.remove-shortcut a:focus span.icon,
+div.remove-shortcut a:hover span.icon {
+ background-position: -12px -12px;
+}
+
+div.add-or-remove-shortcuts a span.text {
+ float: left;
+ padding-left:10px;
+ display: none;
+}
+
+div.add-or-remove-shortcuts a:focus span.text,
+div.add-or-remove-shortcuts a:hover span.text {
+ font-size: 10px;
+ line-height: 12px;
+ color: #fff;
+ background-color: #5f605b;
+ display: block;
+ padding-right: 6px; /* LTR */
+ cursor: pointer;
+ -moz-border-radius: 0 5px 5px 0; /* LTR */
+ -webkit-border-top-right-radius: 5px; /* LTR */
+ -webkit-border-bottom-right-radius: 5px; /* LTR */
+ border-radius: 0 5px 5px 0; /* LTR */
+}
+
+#shortcut-set-switch .form-type-radios {
+ padding-bottom: 0;
+ margin-bottom: 0;
+}
+
+#shortcut-set-switch .form-item-new {
+ padding-top: 0;
+ padding-left: 17px; /* LTR */
+}
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.info b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.info
new file mode 100644
index 0000000..4b8f7b5
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.info
@@ -0,0 +1,13 @@
+name = Shortcut
+description = Allows users to manage customizable lists of shortcut links.
+package = Core
+version = VERSION
+core = 7.x
+files[] = shortcut.test
+configure = admin/config/user-interface/shortcut
+
+; Information added by Drupal.org packaging script on 2014-01-15
+version = "7.26"
+project = "drupal"
+datestamp = "1389815930"
+
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.install b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.install
new file mode 100644
index 0000000..60ee6be
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.install
@@ -0,0 +1,115 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the shortcut module.
+ */
+
+/**
+ * Implements hook_install().
+ */
+function shortcut_install() {
+ $t = get_t();
+ // Create an initial default shortcut set.
+ $shortcut_set = new stdClass();
+ $shortcut_set->title = $t('Default');
+ $shortcut_set->links = array(
+ array(
+ 'link_path' => 'node/add',
+ 'link_title' => $t('Add content'),
+ 'weight' => -20,
+ ),
+ array(
+ 'link_path' => 'admin/content',
+ 'link_title' => $t('Find content'),
+ 'weight' => -19,
+ ),
+ );
+ // If Drupal is being installed, rebuild the menu before saving the shortcut
+ // set, to make sure the links defined above can be correctly saved. (During
+ // installation, the menu might not have been built at all yet, or it might
+ // have been built but without the node module's links in it.)
+ if (drupal_installation_attempted()) {
+ menu_rebuild();
+ }
+ shortcut_set_save($shortcut_set);
+}
+
+/**
+ * Implements hook_uninstall().
+ */
+function shortcut_uninstall() {
+ drupal_load('module', 'shortcut');
+ // Delete the menu links associated with each shortcut set.
+ foreach (shortcut_sets() as $shortcut_set) {
+ menu_delete_links($shortcut_set->set_name);
+ }
+}
+
+/**
+ * Implements hook_schema().
+ */
+function shortcut_schema() {
+ $schema['shortcut_set'] = array(
+ 'description' => 'Stores information about sets of shortcuts links.',
+ 'fields' => array(
+ 'set_name' => array(
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => "Primary Key: The {menu_links}.menu_name under which the set's links are stored.",
+ ),
+ 'title' => array(
+ 'type' => 'varchar',
+ 'length' => 255,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => 'The title of the set.',
+ ),
+ ),
+ 'primary key' => array('set_name'),
+ 'foreign keys' => array(
+ 'menu_name' => array(
+ 'table' => 'menu_links',
+ 'columns' => array('set_name' => 'menu_name'),
+ ),
+ ),
+ );
+
+ $schema['shortcut_set_users'] = array(
+ 'description' => 'Maps users to shortcut sets.',
+ 'fields' => array(
+ 'uid' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => 'The {users}.uid for this set.',
+ ),
+ 'set_name' => array(
+ 'type' => 'varchar',
+ 'length' => 32,
+ 'not null' => TRUE,
+ 'default' => '',
+ 'description' => "The {shortcut_set}.set_name that will be displayed for this user.",
+ ),
+ ),
+ 'primary key' => array('uid'),
+ 'indexes' => array(
+ 'set_name' => array('set_name'),
+ ),
+ 'foreign keys' => array(
+ 'set_user' => array(
+ 'table' => 'users',
+ 'columns' => array('uid' => 'uid'),
+ ),
+ 'set_name' => array(
+ 'table' => 'shortcut_set',
+ 'columns' => array('set_name' => 'set_name'),
+ ),
+ ),
+ );
+
+ return $schema;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.module b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.module
new file mode 100644
index 0000000..2f6db0a
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.module
@@ -0,0 +1,767 @@
+<?php
+
+/**
+ * @file
+ * Allows users to manage customizable lists of shortcut links.
+ */
+
+/**
+ * The name of the default shortcut set.
+ *
+ * This set will be displayed to any user that does not have another set
+ * assigned, unless overridden by a hook_shortcut_default_set() implementation.
+ */
+define('SHORTCUT_DEFAULT_SET_NAME', 'shortcut-set-1');
+
+/**
+ * Implements hook_help().
+ */
+function shortcut_help($path, $arg) {
+ global $user;
+
+ switch ($path) {
+ case 'admin/help#shortcut':
+ $output = '<h3>' . t('About') . '</h3>';
+ $output .= '<p>' . t('The Shortcut module allows users to create sets of <em>shortcut</em> links to commonly-visited pages of the site. Shortcuts are contained within <em>sets</em>. Each user with <em>Select any shortcut set</em> permission can select a shortcut set created by anyone at the site. For more information, see the online handbook entry for <a href="@shortcut">Shortcut module</a>.', array('@shortcut' => 'http://drupal.org/documentation/modules/shortcut/')) . '</p>';
+ $output .= '<h3>' . t('Uses') . '</h3>';
+ $output .= '<dl><dt>' . t('Administering shortcuts') . '</dt>';
+ $output .= '<dd>' . t('Users with the <em>Administer shortcuts</em> permission can manage shortcut sets and edit the shortcuts within sets from the <a href="@shortcuts">Shortcuts administration page</a>.', array('@shortcuts' => url('admin/config/user-interface/shortcut'))) . '</dd>';
+ $output .= '<dt>' . t('Choosing shortcut sets') . '</dt>';
+ $output .= '<dd>' . t('Users with permission to switch shortcut sets can choose a shortcut set to use from the Shortcuts tab of their user account page.') . '</dd>';
+ $output .= '<dt>' . t('Adding and removing shortcuts') . '</dt>';
+ $output .= '<dd>' . t('The Shortcut module creates an add/remove link for each page on your site; the link lets you add or remove the current page from the currently-enabled set of shortcuts (if your theme displays it and you have permission to edit your shortcut set). The core Seven administration theme displays this link next to the page title, as a small + or - sign. If you click on the + sign, you will add that page to your preferred set of shortcuts. If the page is already part of your shortcut set, the link will be a - sign, and will allow you to remove the current page from your shortcut set.') . '</dd>';
+ $output .= '<dt>' . t('Displaying shortcuts') . '</dt>';
+ $output .= '<dd>' . t('You can display your shortcuts by enabling the Shortcuts block on the <a href="@blocks">Blocks administration page</a>. Certain administrative modules also display your shortcuts; for example, the core <a href="@toolbar-help">Toolbar module</a> displays them near the top of the page, along with an <em>Edit shortcuts</em> link.', array('@blocks' => url('admin/structure/block'), '@toolbar-help' => url('admin/help/toolbar'))) . '</dd>';
+ $output .= '</dl>';
+ return $output;
+
+ case 'admin/config/user-interface/shortcut':
+ case 'admin/config/user-interface/shortcut/%':
+ if (user_access('switch shortcut sets')) {
+ $output = '<p>' . t('Define which shortcut set you are using on the <a href="@shortcut-link">Shortcuts tab</a> of your account page.', array('@shortcut-link' => url("user/{$user->uid}/shortcuts"))) . '</p>';
+ return $output;
+ }
+ }
+}
+
+/**
+ * Implements hook_permission().
+ */
+function shortcut_permission() {
+ return array(
+ 'administer shortcuts' => array(
+ 'title' => t('Administer shortcuts'),
+ ),
+ 'customize shortcut links' => array(
+ 'title' => t('Edit current shortcut set'),
+ 'description' => t('Editing the current shortcut set will affect other users if that set has been assigned to or selected by other users. Granting "Select any shortcut set" permission along with this permission will grant permission to edit any shortcut set.'),
+ ),
+ 'switch shortcut sets' => array(
+ 'title' => t('Select any shortcut set'),
+ 'description' => t('From all shortcut sets, select one to be own active set. Without this permission, an administrator selects shortcut sets for users.'),
+ ),
+ );
+}
+
+/**
+ * Implements hook_menu().
+ */
+function shortcut_menu() {
+ $items['admin/config/user-interface/shortcut'] = array(
+ 'title' => 'Shortcuts',
+ 'description' => 'Add and modify shortcut sets.',
+ 'page callback' => 'shortcut_set_admin',
+ 'access arguments' => array('administer shortcuts'),
+ 'file' => 'shortcut.admin.inc',
+ );
+ $items['admin/config/user-interface/shortcut/add-set'] = array(
+ 'title' => 'Add shortcut set',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('shortcut_set_add_form'),
+ 'access arguments' => array('administer shortcuts'),
+ 'type' => MENU_LOCAL_ACTION,
+ 'file' => 'shortcut.admin.inc',
+ );
+ $items['admin/config/user-interface/shortcut/%shortcut_set'] = array(
+ 'title' => 'Edit shortcuts',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('shortcut_set_customize', 4),
+ 'title callback' => 'shortcut_set_title_callback',
+ 'title arguments' => array(4),
+ 'access callback' => 'shortcut_set_edit_access',
+ 'access arguments' => array(4),
+ 'file' => 'shortcut.admin.inc',
+ );
+ $items['admin/config/user-interface/shortcut/%shortcut_set/links'] = array(
+ 'title' => 'List links',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ );
+ $items['admin/config/user-interface/shortcut/%shortcut_set/edit'] = array(
+ 'title' => 'Edit set name',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('shortcut_set_edit_form', 4),
+ 'access callback' => 'shortcut_set_edit_access',
+ 'access arguments' => array(4),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'shortcut.admin.inc',
+ 'weight' => 10,
+ );
+ $items['admin/config/user-interface/shortcut/%shortcut_set/delete'] = array(
+ 'title' => 'Delete shortcut set',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('shortcut_set_delete_form', 4),
+ 'access callback' => 'shortcut_set_delete_access',
+ 'access arguments' => array(4),
+ 'file' => 'shortcut.admin.inc',
+ );
+ $items['admin/config/user-interface/shortcut/%shortcut_set/add-link'] = array(
+ 'title' => 'Add shortcut',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('shortcut_link_add', 4),
+ 'access callback' => 'shortcut_set_edit_access',
+ 'access arguments' => array(4),
+ 'type' => MENU_LOCAL_ACTION,
+ 'file' => 'shortcut.admin.inc',
+ );
+ $items['admin/config/user-interface/shortcut/%shortcut_set/add-link-inline'] = array(
+ 'title' => 'Add shortcut',
+ 'page callback' => 'shortcut_link_add_inline',
+ 'page arguments' => array(4),
+ 'access callback' => 'shortcut_set_edit_access',
+ 'access arguments' => array(4),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'shortcut.admin.inc',
+ );
+ $items['admin/config/user-interface/shortcut/link/%menu_link'] = array(
+ 'title' => 'Edit shortcut',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('shortcut_link_edit', 5),
+ 'access callback' => 'shortcut_link_access',
+ 'access arguments' => array(5),
+ 'file' => 'shortcut.admin.inc',
+ );
+ $items['admin/config/user-interface/shortcut/link/%menu_link/delete'] = array(
+ 'title' => 'Delete shortcut',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('shortcut_link_delete', 5),
+ 'access callback' => 'shortcut_link_access',
+ 'access arguments' => array(5),
+ 'file' => 'shortcut.admin.inc',
+ );
+ $items['user/%user/shortcuts'] = array(
+ 'title' => 'Shortcuts',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('shortcut_set_switch', 1),
+ 'access callback' => 'shortcut_set_switch_access',
+ 'access arguments' => array(1),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'shortcut.admin.inc',
+ );
+
+ return $items;
+}
+
+/**
+ * Implements hook_admin_paths().
+ */
+function shortcut_admin_paths() {
+ $paths = array(
+ 'user/*/shortcuts' => TRUE,
+ );
+ return $paths;
+}
+
+/**
+ * Implements hook_theme().
+ */
+function shortcut_theme() {
+ return array(
+ 'shortcut_set_customize' => array(
+ 'render element' => 'form',
+ 'file' => 'shortcut.admin.inc',
+ ),
+ );
+}
+
+/**
+ * Implements hook_block_info().
+ */
+function shortcut_block_info() {
+ $blocks['shortcuts']['info'] = t('Shortcuts');
+ // Shortcut blocks can't be cached because each menu item can have a custom
+ // access callback. menu.inc manages its own caching.
+ $blocks['shortcuts']['cache'] = DRUPAL_NO_CACHE;
+ return $blocks;
+}
+
+/**
+ * Implements hook_block_view().
+ */
+function shortcut_block_view($delta = '') {
+ if ($delta == 'shortcuts') {
+ $shortcut_set = shortcut_current_displayed_set();
+ $data['subject'] = t('@shortcut_set shortcuts', array('@shortcut_set' => $shortcut_set->title));
+ $data['content'] = shortcut_renderable_links($shortcut_set);
+ return $data;
+ }
+}
+
+/**
+ * Access callback for editing a shortcut set.
+ *
+ * @param object $shortcut_set
+ * (optional) The shortcut set to be edited. If not set, the current user's
+ * shortcut set will be used.
+ *
+ * @return
+ * TRUE if the current user has access to edit the shortcut set, FALSE
+ * otherwise.
+ */
+function shortcut_set_edit_access($shortcut_set = NULL) {
+ // Sufficiently-privileged users can edit their currently displayed shortcut
+ // set, but not other sets. Shortcut administrators can edit any set.
+ if (user_access('administer shortcuts')) {
+ return TRUE;
+ }
+ if (user_access('customize shortcut links')) {
+ return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set();
+ }
+ return FALSE;
+}
+
+/**
+ * Access callback for deleting a shortcut set.
+ *
+ * @param $shortcut_set
+ * The shortcut set to be deleted.
+ *
+ * @return
+ * TRUE if the current user has access to delete shortcut sets and this is
+ * not the site-wide default set; FALSE otherwise.
+ */
+function shortcut_set_delete_access($shortcut_set) {
+ // Only admins can delete sets.
+ if (!user_access('administer shortcuts')) {
+ return FALSE;
+ }
+
+ // Never let the default shortcut set be deleted.
+ if ($shortcut_set->set_name == SHORTCUT_DEFAULT_SET_NAME) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ * Access callback for switching the shortcut set assigned to a user account.
+ *
+ * @param object $account
+ * (optional) The user account whose shortcuts will be switched. If not set,
+ * permissions will be checked for switching the logged-in user's own
+ * shortcut set.
+ *
+ * @return
+ * TRUE if the current user has access to switch the shortcut set of the
+ * provided account, FALSE otherwise.
+ */
+function shortcut_set_switch_access($account = NULL) {
+ global $user;
+
+ if (user_access('administer shortcuts')) {
+ // Administrators can switch anyone's shortcut set.
+ return TRUE;
+ }
+
+ if (!user_access('switch shortcut sets')) {
+ // The user has no permission to switch anyone's shortcut set.
+ return FALSE;
+ }
+
+ if (!isset($account) || $user->uid == $account->uid) {
+ // Users with the 'switch shortcut sets' permission can switch their own
+ // shortcuts sets.
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/**
+ * Access callback for editing a link in a shortcut set.
+ */
+function shortcut_link_access($menu_link) {
+ // The link must belong to a shortcut set that the current user has access
+ // to edit.
+ if ($shortcut_set = shortcut_set_load($menu_link['menu_name'])) {
+ return shortcut_set_edit_access($shortcut_set);
+ }
+ return FALSE;
+}
+
+/**
+ * Loads the data for a shortcut set.
+ *
+ * @param $set_name
+ * The name of the shortcut set to load.
+ *
+ * @return object
+ * If the shortcut set exists, an object containing the following properties:
+ * - 'set_name': The internal name of the shortcut set.
+ * - 'title': The title of the shortcut set.
+ * - 'links': An array of links associated with this shortcut set.
+ * If the shortcut set does not exist, the function returns FALSE.
+ */
+function shortcut_set_load($set_name) {
+ $set = db_select('shortcut_set', 'ss')
+ ->fields('ss')
+ ->condition('set_name', $set_name)
+ ->execute()
+ ->fetchObject();
+ if (!$set) {
+ return FALSE;
+ }
+ $set->links = menu_load_links($set_name);
+ return $set;
+}
+
+/**
+ * Saves a shortcut set.
+ *
+ * @param $shortcut_set
+ * An object containing the following properties:
+ * - 'title': The title of the shortcut set.
+ * - 'set_name': (optional) The internal name of the shortcut set. If
+ * omitted, a new shortcut set will be created, and the 'set_name' property
+ * will be added to the passed-in object.
+ * - 'links': (optional) An array of menu links to save for the shortcut set.
+ * Each link is an array containing at least the following keys (which will
+ * be expanded to fill in other default values after the shortcut set is
+ * saved):
+ * - 'link_path': The Drupal path or external path that the link points to.
+ * - 'link_title': The title of the link.
+ * Any other keys accepted by menu_link_save() may also be provided.
+ *
+ * @return
+ * A constant which is either SAVED_NEW or SAVED_UPDATED depending on whether
+ * a new set was created or an existing one was updated.
+ *
+ * @see menu_link_save()
+ */
+function shortcut_set_save(&$shortcut_set) {
+ // First save the shortcut set itself.
+ if (isset($shortcut_set->set_name)) {
+ $return = drupal_write_record('shortcut_set', $shortcut_set, 'set_name');
+ }
+ else {
+ $shortcut_set->set_name = shortcut_set_get_unique_name();
+ $return = drupal_write_record('shortcut_set', $shortcut_set);
+ }
+ // If links were provided for the set, save them.
+ if (isset($shortcut_set->links)) {
+ foreach ($shortcut_set->links as &$link) {
+ // Do not specifically associate these links with the shortcut module,
+ // since other modules may make them editable via the menu system.
+ // However, we do need to specify the correct menu name.
+ $link['menu_name'] = $shortcut_set->set_name;
+ $link['plid'] = 0;
+ menu_link_save($link);
+ }
+ // Make sure that we have a return value, since if the links were updated
+ // but the shortcut set was not, the call to drupal_write_record() above
+ // would not return an indication that anything had changed.
+ if (empty($return)) {
+ $return = SAVED_UPDATED;
+ }
+ }
+ return $return;
+}
+
+/**
+ * Deletes a shortcut set.
+ *
+ * Note that the default set cannot be deleted.
+ *
+ * @param $shortcut_set
+ * An object representing the shortcut set to delete.
+ *
+ * @return
+ * TRUE if the set was deleted, FALSE otherwise.
+ */
+function shortcut_set_delete($shortcut_set) {
+ // Don't allow deletion of the system default shortcut set.
+ if ($shortcut_set->set_name == SHORTCUT_DEFAULT_SET_NAME) {
+ return FALSE;
+ }
+
+ // First, delete any user assignments for this set, so that each of these
+ // users will go back to using whatever default set applies.
+ db_delete('shortcut_set_users')
+ ->condition('set_name', $shortcut_set->set_name)
+ ->execute();
+
+ // Next, delete the menu links for this set.
+ menu_delete_links($shortcut_set->set_name);
+
+ // Finally, delete the set itself.
+ $deleted = db_delete('shortcut_set')
+ ->condition('set_name', $shortcut_set->set_name)
+ ->execute();
+
+ return (bool) $deleted;
+}
+
+/**
+ * Resets the link weights in a shortcut set to match their current order.
+ *
+ * This function can be used, for example, when a new shortcut link is added to
+ * the set. If the link is added to the end of the array and this function is
+ * called, it will force that link to display at the end of the list.
+ *
+ * @param object $shortcut_set
+ * An object representing a shortcut set. The link weights of the passed-in
+ * object will be reset as described above.
+ */
+function shortcut_set_reset_link_weights(&$shortcut_set) {
+ $weight = -50;
+ foreach ($shortcut_set->links as &$link) {
+ $link['weight'] = $weight;
+ $weight++;
+ }
+}
+
+/**
+ * Assigns a user to a particular shortcut set.
+ *
+ * @param $shortcut_set
+ * An object representing the shortcut set.
+ * @param $account
+ * A user account that will be assigned to use the set.
+ */
+function shortcut_set_assign_user($shortcut_set, $account) {
+ db_merge('shortcut_set_users')
+ ->key(array('uid' => $account->uid))
+ ->fields(array('set_name' => $shortcut_set->set_name))
+ ->execute();
+ drupal_static_reset('shortcut_current_displayed_set');
+}
+
+/**
+ * Unassigns a user from any shortcut set they may have been assigned to.
+ *
+ * The user will go back to using whatever default set applies.
+ *
+ * @param $account
+ * A user account that will be removed from the shortcut set assignment.
+ *
+ * @return
+ * TRUE if the user was previously assigned to a shortcut set and has been
+ * successfully removed from it. FALSE if the user was already not assigned
+ * to any set.
+ */
+function shortcut_set_unassign_user($account) {
+ $deleted = db_delete('shortcut_set_users')
+ ->condition('uid', $account->uid)
+ ->execute();
+ return (bool) $deleted;
+}
+
+/**
+ * Returns the current displayed shortcut set for the provided user account.
+ *
+ * @param $account
+ * (optional) The user account whose shortcuts will be returned. Defaults to
+ * the currently logged-in user.
+ *
+ * @return
+ * An object representing the shortcut set that should be displayed to the
+ * current user. If the user does not have an explicit shortcut set defined,
+ * the default set is returned.
+ */
+function shortcut_current_displayed_set($account = NULL) {
+ $shortcut_sets = &drupal_static(__FUNCTION__, array());
+ global $user;
+ if (!isset($account)) {
+ $account = $user;
+ }
+ // Try to return a shortcut set from the static cache.
+ if (isset($shortcut_sets[$account->uid])) {
+ return $shortcut_sets[$account->uid];
+ }
+ // If none was found, try to find a shortcut set that is explicitly assigned
+ // to this user.
+ $query = db_select('shortcut_set', 's');
+ $query->addField('s', 'set_name');
+ $query->join('shortcut_set_users', 'u', 's.set_name = u.set_name');
+ $query->condition('u.uid', $account->uid);
+ $shortcut_set_name = $query->execute()->fetchField();
+ if ($shortcut_set_name) {
+ $shortcut_set = shortcut_set_load($shortcut_set_name);
+ }
+ // Otherwise, use the default set.
+ else {
+ $shortcut_set = shortcut_default_set($account);
+ }
+
+ $shortcut_sets[$account->uid] = $shortcut_set;
+ return $shortcut_set;
+}
+
+/**
+ * Returns the default shortcut set for a given user account.
+ *
+ * @param object $account
+ * (optional) The user account whose default shortcut set will be returned.
+ * If not provided, the function will return the currently logged-in user's
+ * default shortcut set.
+ *
+ * @return
+ * An object representing the default shortcut set.
+ */
+function shortcut_default_set($account = NULL) {
+ global $user;
+ if (!isset($account)) {
+ $account = $user;
+ }
+
+ // Allow modules to return a default shortcut set name. Since we can only
+ // have one, we allow the last module which returns a valid result to take
+ // precedence. If no module returns a valid set, fall back on the site-wide
+ // default, which is the lowest-numbered shortcut set.
+ $suggestions = array_reverse(module_invoke_all('shortcut_default_set', $account));
+ $suggestions[] = SHORTCUT_DEFAULT_SET_NAME;
+ foreach ($suggestions as $name) {
+ if ($shortcut_set = shortcut_set_load($name)) {
+ break;
+ }
+ }
+
+ return $shortcut_set;
+}
+
+/**
+ * Returns a unique, machine-readable shortcut set name.
+ */
+function shortcut_set_get_unique_name() {
+ // Shortcut sets are numbered sequentially, so we keep trying until we find
+ // one that is available. For better performance, we start with a number
+ // equal to one more than the current number of shortcut sets, so that if
+ // no shortcut sets have been deleted from the database, this will
+ // automatically give us the correct one.
+ $number = db_query("SELECT COUNT(*) FROM {shortcut_set}")->fetchField() + 1;
+ do {
+ $name = shortcut_set_name($number);
+ $number++;
+ } while ($shortcut_set = shortcut_set_load($name));
+ return $name;
+}
+
+/**
+ * Returns the name of a shortcut set, based on a provided number.
+ *
+ * All shortcut sets have names like "shortcut-set-N" so that they can be
+ * matched with a properly-namespaced entry in the {menu_links} table.
+ *
+ * @param $number
+ * A number representing the shortcut set whose name should be retrieved.
+ *
+ * @return
+ * A string representing the expected shortcut name.
+ */
+function shortcut_set_name($number) {
+ return "shortcut-set-$number";
+}
+
+/**
+ * Returns an array of all shortcut sets, keyed by the set name.
+ *
+ * @return
+ * An array of shortcut sets. Note that only the basic shortcut set
+ * properties (name and title) are returned by this function, not the list
+ * of menu links that belong to the set.
+ */
+function shortcut_sets() {
+ return db_select('shortcut_set', 'ss')
+ ->fields('ss')
+ ->execute()
+ ->fetchAllAssoc('set_name');
+}
+
+/**
+ * Check to see if a shortcut set with the given title already exists.
+ *
+ * @param $title
+ * Human-readable name of the shortcut set to check.
+ *
+ * @return
+ * TRUE if a shortcut set with that title exists; FALSE otherwise.
+ */
+function shortcut_set_title_exists($title) {
+ return (bool) db_query_range('SELECT 1 FROM {shortcut_set} WHERE title = :title', 0, 1, array(':title' => $title))->fetchField();
+}
+
+/**
+ * Determines if a path corresponds to a valid shortcut link.
+ *
+ * @param $path
+ * The path to the link.
+ * @return
+ * TRUE if the shortcut link is valid, FALSE otherwise. Valid links are ones
+ * that correspond to actual paths on the site.
+ *
+ * @see menu_edit_item_validate()
+ */
+function shortcut_valid_link($path) {
+ // Do not use URL aliases.
+ $normal_path = drupal_get_normal_path($path);
+ if ($path != $normal_path) {
+ $path = $normal_path;
+ }
+ // An empty path is valid too and will be converted to <front>.
+ return (!url_is_external($path) && menu_get_item($path)) || empty($path) || $path == '<front>';
+}
+
+/**
+ * Returns an array of shortcut links, suitable for rendering.
+ *
+ * @param $shortcut_set
+ * (optional) An object representing the set whose links will be displayed.
+ * If not provided, the user's current set will be displayed.
+ * @return
+ * An array of shortcut links, in the format returned by the menu system.
+ *
+ * @see menu_tree()
+ */
+function shortcut_renderable_links($shortcut_set = NULL) {
+ if (!isset($shortcut_set)) {
+ $shortcut_set = shortcut_current_displayed_set();
+ }
+ return menu_tree($shortcut_set->set_name);
+}
+
+/**
+ * Implements hook_preprocess_page().
+ */
+function shortcut_preprocess_page(&$variables) {
+ // Only display the shortcut link if the user has the ability to edit
+ // shortcuts and if the page's actual content is being shown (for example,
+ // we do not want to display it on "access denied" or "page not found"
+ // pages).
+ if (shortcut_set_edit_access() && ($item = menu_get_item()) && $item['access']) {
+ $link = $_GET['q'];
+ $query_parameters = drupal_get_query_parameters();
+ if (!empty($query_parameters)) {
+ $link .= '?' . drupal_http_build_query($query_parameters);
+ }
+ $query = array(
+ 'link' => $link,
+ 'name' => drupal_get_title(),
+ );
+ $query += drupal_get_destination();
+
+ $shortcut_set = shortcut_current_displayed_set();
+
+ // Check if $link is already a shortcut and set $link_mode accordingly.
+ foreach ($shortcut_set->links as $shortcut) {
+ if ($link == $shortcut['link_path']) {
+ $mlid = $shortcut['mlid'];
+ break;
+ }
+ }
+ $link_mode = isset($mlid) ? "remove" : "add";
+
+ if ($link_mode == "add") {
+ $query['token'] = drupal_get_token('shortcut-add-link');
+ $link_text = shortcut_set_switch_access() ? t('Add to %shortcut_set shortcuts', array('%shortcut_set' => $shortcut_set->title)) : t('Add to shortcuts');
+ $link_path = 'admin/config/user-interface/shortcut/' . $shortcut_set->set_name . '/add-link-inline';
+ }
+ else {
+ $query['mlid'] = $mlid;
+ $link_text = shortcut_set_switch_access() ? t('Remove from %shortcut_set shortcuts', array('%shortcut_set' => $shortcut_set->title)) : t('Remove from shortcuts');
+ $link_path = 'admin/config/user-interface/shortcut/link/' . $mlid . '/delete';
+ }
+
+ if (theme_get_setting('shortcut_module_link')) {
+ $variables['title_suffix']['add_or_remove_shortcut'] = array(
+ '#attached' => array('css' => array(drupal_get_path('module', 'shortcut') . '/shortcut.css')),
+ '#prefix' => '<div class="add-or-remove-shortcuts ' . $link_mode . '-shortcut">',
+ '#type' => 'link',
+ '#title' => '<span class="icon"></span><span class="text">' . $link_text . '</span>',
+ '#href' => $link_path,
+ '#options' => array('query' => $query, 'html' => TRUE),
+ '#suffix' => '</div>',
+ );
+ }
+ }
+}
+
+/**
+ * Implements hook_page_alter().
+ */
+function shortcut_page_alter(&$page) {
+ if (isset($page['page_top']['toolbar'])) {
+ // If the toolbar is available, add a pre-render function to display the
+ // current shortcuts in the toolbar drawer.
+ $page['page_top']['toolbar']['#pre_render'][] = 'shortcut_toolbar_pre_render';
+ }
+}
+
+/**
+ * Pre-render function for adding shortcuts to the toolbar drawer.
+ */
+function shortcut_toolbar_pre_render($toolbar) {
+ $links = shortcut_renderable_links();
+ $links['#attached'] = array('css' => array(drupal_get_path('module', 'shortcut') . '/shortcut.css'));
+ $links['#prefix'] = '<div class="toolbar-shortcuts">';
+ $links['#suffix'] = '</div>';
+ $shortcut_set = shortcut_current_displayed_set();
+ $configure_link = NULL;
+ if (shortcut_set_edit_access($shortcut_set)) {
+ $configure_link = array(
+ '#type' => 'link',
+ '#title' => t('Edit shortcuts'),
+ '#href' => 'admin/config/user-interface/shortcut/' . $shortcut_set->set_name,
+ '#options' => array('attributes' => array('id' => 'edit-shortcuts')),
+ );
+ }
+
+ $drawer = array(
+ 'shortcuts' => $links,
+ 'configure' => $configure_link,
+ );
+
+ $toolbar['toolbar_drawer'][] = $drawer;
+ return $toolbar;
+}
+
+/**
+ * Returns the sanitized title of a shortcut set.
+ *
+ * Deprecated. This function was previously used as a menu item title callback
+ * but has been replaced by shortcut_set_title_callback() (which does not
+ * sanitize the title, since the menu system does that automatically). In
+ * Drupal 7, use that function for title callbacks, and call check_plain()
+ * directly if you need a sanitized title. In Drupal 8, this function will be
+ * restored as a title callback and therefore will no longer sanitize its
+ * output.
+ *
+ * @param $shortcut_set
+ * An object representing the shortcut set, as returned by
+ * shortcut_set_load().
+ */
+function shortcut_set_title($shortcut_set) {
+ return check_plain($shortcut_set->title);
+}
+
+/**
+ * Returns the title of a shortcut set.
+ *
+ * Title callback for the editing pages for shortcut sets.
+ *
+ * @param $shortcut_set
+ * An object representing the shortcut set, as returned by
+ * shortcut_set_load().
+ */
+function shortcut_set_title_callback($shortcut_set) {
+ return $shortcut_set->title;
+}
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.png b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.png
new file mode 100644
index 0000000..2924557
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.png
Binary files differ
diff --git a/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.test b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.test
new file mode 100644
index 0000000..2bd9605
--- /dev/null
+++ b/kolab.org/www/drupal-7.26/modules/shortcut/shortcut.test
@@ -0,0 +1,371 @@
+<?php
+
+/**
+ * @file
+ * Tests for shortcut.module.
+ */
+
+/**
+ * Defines base class for shortcut test cases.
+ */
+class ShortcutTestCase extends DrupalWebTestCase {
+
+ /**
+ * User with permission to administer shortcuts.
+ */
+ protected $admin_user;
+
+ /**
+ * User with permission to use shortcuts, but not administer them.
+ */
+ protected $shortcut_user;
+
+ /**
+ * Generic node used for testing.
+ */
+ protected $node;
+
+ /**
+ * Site-wide default shortcut set.
+ */
+ protected $set;
+
+ function setUp() {
+ parent::setUp('toolbar', 'shortcut');
+ // Create users.
+ $this->admin_user = $this->drupalCreateUser(array('access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview'));
+ $this->shortcut_user = $this->drupalCreateUser(array('customize shortcut links', 'switch shortcut sets'));
+
+ // Create a node.
+ $this->node = $this->drupalCreateNode(array('type' => 'article'));
+
+ // Log in as admin and grab the default shortcut set.
+ $this->drupalLogin($this->admin_user);
+ $this->set = shortcut_set_load(SHORTCUT_DEFAULT_SET_NAME);
+ shortcut_set_assign_user($this->set, $this->admin_user);
+ }
+
+ /**
+ * Creates a generic shortcut set.
+ */
+ function generateShortcutSet($title = '', $default_links = TRUE) {
+ $set = new stdClass();
+ $set->title = empty($title) ? $this->randomName(10) : $title;
+ if ($default_links) {
+ $set->links = array();
+ $set->links[] = $this->generateShortcutLink('node/add');
+ $set->links[] = $this->generateShortcutLink('admin/content');
+ }
+ shortcut_set_save($set);
+
+ return $set;
+ }
+
+ /**
+ * Creates a generic shortcut link.
+ */
+ function generateShortcutLink($path, $title = '') {
+ $link = array(
+ 'link_path' => $path,
+ 'link_title' => !empty($title) ? $title : $this->randomName(10),
+ );
+
+ return $link;
+ }
+
+ /**
+ * Extracts information from shortcut set links.
+ *
+ * @param object $set
+ * The shortcut set object to extract information from.
+ * @param string $key
+ * The array key indicating what information to extract from each link:
+ * - 'link_path': Extract link paths.
+ * - 'link_title': Extract link titles.
+ * - 'mlid': Extract the menu link item ID numbers.
+ *
+ * @return array
+ * Array of the requested information from each link.
+ */
+ function getShortcutInformation($set, $key) {
+ $info = array();
+ foreach ($set->links as $link) {
+ $info[] = $link[$key];
+ }
+ return $info;
+ }
+}
+
+/**
+ * Defines shortcut links test cases.
+ */
+class ShortcutLinksTestCase extends ShortcutTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Shortcut link functionality',
+ 'description' => 'Create, view, edit, delete, and change shortcut links.',
+ 'group' => 'Shortcut',
+ );
+ }
+
+ /**
+ * Tests that creating a shortcut works properly.
+ */
+ function testShortcutLinkAdd() {
+ $set = $this->set;
+
+ // Create an alias for the node so we can test aliases.
+ $path = array(
+ 'source' => 'node/' . $this->node->nid,
+ 'alias' => $this->randomName(8),
+ );
+ path_save($path);
+
+ // Create some paths to test.
+ $test_cases = array(
+ array('path' => ''),
+ array('path' => 'admin'),
+ array('path' => 'admin/config/system/site-information'),
+ array('path' => "node/{$this->node->nid}/edit"),
+ array('path' => $path['alias']),
+ );
+
+ // Check that each new shortcut links where it should.
+ foreach ($test_cases as $test) {
+ $title = $this->randomName(10);
+ $form_data = array(
+ 'shortcut_link[link_title]' => $title,
+ 'shortcut_link[link_path]' => $test['path'],
+ );
+ $this->drupalPost('admin/config/user-interface/shortcut/' . $set->set_name . '/add-link', $form_data, t('Save'));
+ $this->assertResponse(200);
+ $saved_set = shortcut_set_load($set->set_name);
+ $paths = $this->getShortcutInformation($saved_set, 'link_path');
+ $test_path = empty($test['path']) ? '<front>' : $test['path'];
+ $this->assertTrue(in_array(drupal_get_normal_path($test_path), $paths), 'Shortcut created: '. $test['path']);
+ $this->assertLink($title, 0, 'Shortcut link found on the page.');
+ }
+ }
+
+ /**
+ * Tests that the "add to shortcut" link changes to "remove shortcut".
+ */
+ function testShortcutQuickLink() {
+ $this->drupalGet($this->set->links[0]['link_path']);
+ $this->assertRaw(t('Remove from %title shortcuts', array('%title' => $this->set->title)), '"Add to shortcuts" link properly switched to "Remove from shortcuts".');
+ }
+
+ /**
+ * Tests that shortcut links can be renamed.
+ */
+ function testShortcutLinkRename() {
+ $set = $this->set;
+
+ // Attempt to rename shortcut link.
+ $new_link_name = $this->randomName(10);
+
+ $this->drupalPost('admin/config/user-interface/shortcut/link/' . $set->links[0]['mlid'], array('shortcut_link[link_title]' => $new_link_name, 'shortcut_link[link_path]' => $set->links[0]['link_path']), t('Save'));
+ $saved_set = shortcut_set_load($set->set_name);
+ $titles = $this->getShortcutInformation($saved_set, 'link_title');
+ $this->assertTrue(in_array($new_link_name, $titles), 'Shortcut renamed: ' . $new_link_name);
+ $this->assertLink($new_link_name, 0, 'Renamed shortcut link appears on the page.');
+ }
+
+ /**
+ * Tests that changing the path of a shortcut link works.
+ */
+ function testShortcutLinkChangePath() {
+ $set = $this->set;
+
+ // Tests changing a shortcut path.
+ $new_link_path = 'admin/config';
+
+ $this->drupalPost('admin/config/user-interface/shortcut/link/' . $set->links[0]['mlid'], array('shortcut_link[link_title]' => $set->links[0]['link_title'], 'shortcut_link[link_path]' => $new_link_path), t('Save'));
+ $saved_set = shortcut_set_load($set->set_name);
+ $paths = $this->getShortcutInformation($saved_set, 'link_path');
+ $this->assertTrue(in_array($new_link_path, $paths), 'Shortcut path changed: ' . $new_link_path);
+ $this->assertLinkByHref($new_link_path, 0, 'Shortcut with new path appears on the page.');
+ }
+
+ /**
+ * Tests deleting a shortcut link.
+ */
+ function testShortcutLinkDelete() {
+ $set = $this->set;
+
+ $this->drupalPost('admin/config/user-interface/shortcut/link/' . $set->links[0]['mlid'] . '/delete', array(), 'Delete');
+ $saved_set = shortcut_set_load($set->set_name);
+ $mlids = $this->getShortcutInformation($saved_set, 'mlid');
+ $this->assertFalse(in_array($set->links[0]['mlid'], $mlids), 'Successfully deleted a shortcut.');
+ }
+
+ /**
+ * Tests that the add shortcut link is not displayed for 404/403 errors.
+ *
+ * Tests that the "Add to shortcuts" link is not displayed on a page not
+ * found or a page the user does not have access to.
+ */
+ function testNoShortcutLink() {
+ // Change to a theme that displays shortcuts.
+ variable_set('theme_default', 'seven');
+
+ $this->drupalGet('page-that-does-not-exist');
+ $this->assertNoRaw('add-shortcut', 'Add to shortcuts link was not shown on a page not found.');
+
+ // The user does not have access to this path.
+ $this->drupalGet('admin/modules');
+ $this->assertNoRaw('add-shortcut', 'Add to shortcuts link was not shown on a page the user does not have access to.');
+
+ // Verify that the testing mechanism works by verifying the shortcut
+ // link appears on admin/content/node.
+ $this->drupalGet('admin/content/node');
+ $this->assertRaw('add-shortcut', 'Add to shortcuts link was shown on a page the user does have access to.');
+ }
+}
+
+/**
+ * Defines shortcut set test cases.
+ */
+class ShortcutSetsTestCase extends ShortcutTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Shortcut set functionality',
+ 'description' => 'Create, view, edit, delete, and change shortcut sets.',
+ 'group' => 'Shortcut',
+ );
+ }
+
+ /**
+ * Tests creating a shortcut set.
+ */
+ function testShortcutSetAdd() {
+ $new_set = $this->generateShortcutSet($this->randomName(10));
+ $sets = shortcut_sets();
+ $this->assertTrue(isset($sets[$new_set->set_name]), 'Successfully created a shortcut set.');
+ $this->drupalGet('user/' . $this->admin_user->uid . '/shortcuts');
+ $this->assertText($new_set->title, 'Generated shortcut set was listed as a choice on the user account page.');
+ }
+
+ /**
+ * Tests switching a user's own shortcut set.
+ */
+ function testShortcutSetSwitchOwn() {
+ $new_set = $this->generateShortcutSet($this->randomName(10));
+
+ // Attempt to switch the default shortcut set to the newly created shortcut
+ // set.
+ $this->drupalPost('user/' . $this->admin_user->uid . '/shortcuts', array('set' => $new_set->set_name), t('Change set'));
+ $this->assertResponse(200);
+ $current_set = shortcut_current_displayed_set($this->admin_user);
+ $this->assertTrue($new_set->set_name == $current_set->set_name, 'Successfully switched own shortcut set.');
+ }
+
+ /**
+ * Tests switching another user's shortcut set.
+ */
+ function testShortcutSetAssign() {
+ $new_set = $this->generateShortcutSet($this->randomName(10));
+
+ shortcut_set_assign_user($new_set, $this->shortcut_user);
+ $current_set = shortcut_current_displayed_set($this->shortcut_user);
+ $this->assertTrue($new_set->set_name == $current_set->set_name, "Successfully switched another user's shortcut set.");
+ }
+
+ /**
+ * Tests switching a user's shortcut set and creating one at the same time.
+ */
+ function testShortcutSetSwitchCreate() {
+ $edit = array(
+ 'set' => 'new',
+ 'new' => $this->randomName(10),
+ );
+ $this->drupalPost('user/' . $this->admin_user->uid . '/shortcuts', $edit, t('Change set'));
+ $current_set = shortcut_current_displayed_set($this->admin_user);
+ $this->assertNotEqual($current_set->set_name, $this->set->set_name, 'A shortcut set can be switched to at the same time as it is created.');
+ $this->assertEqual($current_set->title, $edit['new'], 'The new set is correctly assigned to the user.');
+ }
+
+ /**
+ * Tests switching a user's shortcut set without providing a new set name.
+ */
+ function testShortcutSetSwitchNoSetName() {
+ $edit = array('set' => 'new');
+ $this->drupalPost('user/' . $this->admin_user->uid . '/shortcuts', $edit, t('Change set'));
+ $this->assertText(t('The new set name is required.'));
+ $current_set = shortcut_current_displayed_set($this->admin_user);
+ $this->assertEqual($current_set->set_name, $this->set->set_name, 'Attempting to switch to a new shortcut set without providing a set name does not succeed.');
+ }
+
+ /**
+ * Tests that shortcut_set_save() correctly updates existing links.
+ */
+ function testShortcutSetSave() {
+ $set = $this->set;
+ $old_mlids = $this->getShortcutInformation($set, 'mlid');
+
+ $set->links[] = $this->generateShortcutLink('admin', $this->randomName(10));
+ shortcut_set_save($set);
+ $saved_set = shortcut_set_load($set->set_name);
+
+ $new_mlids = $this->getShortcutInformation($saved_set, 'mlid');
+ $this->assertTrue(count(array_intersect($old_mlids, $new_mlids)) == count($old_mlids), 'shortcut_set_save() did not inadvertently change existing mlids.');
+ }
+
+ /**
+ * Tests renaming a shortcut set.
+ */
+ function testShortcutSetRename() {
+ $set = $this->set;
+
+ $new_title = $this->randomName(10);
+ $this->drupalPost('admin/config/user-interface/shortcut/' . $set->set_name . '/edit', array('title' => $new_title), t('Save'));
+ $set = shortcut_set_load($set->set_name);
+ $this->assertTrue($set->title == $new_title, 'Shortcut set has been successfully renamed.');
+ }
+
+ /**
+ * Tests renaming a shortcut set to the same name as another set.
+ */
+ function testShortcutSetRenameAlreadyExists() {
+ $set = $this->generateShortcutSet($this->randomName(10));
+ $existing_title = $this->set->title;
+ $this->drupalPost('admin/config/user-interface/shortcut/' . $set->set_name . '/edit', array('title' => $existing_title), t('Save'));
+ $this->assertRaw(t('The shortcut set %name already exists. Choose another name.', array('%name' => $existing_title)));
+ $set = shortcut_set_load($set->set_name);
+ $this->assertNotEqual($set->title, $existing_title, format_string('The shortcut set %title cannot be renamed to %new-title because a shortcut set with that title already exists.', array('%title' => $set->title, '%new-title' => $existing_title)));
+ }
+
+ /**
+ * Tests unassigning a shortcut set.
+ */
+ function testShortcutSetUnassign() {
+ $new_set = $this->generateShortcutSet($this->randomName(10));
+
+ shortcut_set_assign_user($new_set, $this->shortcut_user);
+ shortcut_set_unassign_user($this->shortcut_user);
+ $current_set = shortcut_current_displayed_set($this->shortcut_user);
+ $default_set = shortcut_default_set($this->shortcut_user);
+ $this->assertTrue($current_set->set_name == $default_set->set_name, "Successfully unassigned another user's shortcut set.");
+ }
+
+ /**
+ * Tests deleting a shortcut set.
+ */
+ function testShortcutSetDelete() {
+ $new_set = $this->generateShortcutSet($this->randomName(10));
+
+ $this->drupalPost('admin/config/user-interface/shortcut/' . $new_set->set_name . '/delete', array(), t('Delete'));
+ $sets = shortcut_sets();
+ $this->assertFalse(isset($sets[$new_set->set_name]), 'Successfully deleted a shortcut set.');
+ }
+
+ /**
+ * Tests deleting the default shortcut set.
+ */
+ function testShortcutSetDeleteDefault() {
+ $this->drupalGet('admin/config/user-interface/shortcut/' . SHORTCUT_DEFAULT_SET_NAME . '/delete');
+ $this->assertResponse(403);
+ }
+}