/[drupal]/contributions/modules/bookmarks/bookmarks.admin.inc
ViewVC logotype

Diff of /contributions/modules/bookmarks/bookmarks.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.5.2.4 by darthclue, Tue Jan 20 15:02:42 2009 UTC revision 1.5.2.5 by darthclue, Fri Jan 23 16:14:35 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: bookmarks.admin.inc,v 1.5.2.3 2008/12/17 17:40:38 darthclue Exp $  // $Id: bookmarks.admin.inc,v 1.5.2.4 2009/01/20 15:02:42 darthclue Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 10  Line 10 
10   * Menu callback which shows an overview page of all the custom menus and their descriptions.   * Menu callback which shows an overview page of all the custom menus and their descriptions.
11   */   */
12  function bookmarks_overview_page() {  function bookmarks_overview_page() {
13    $result = db_query("SELECT * FROM {menu_bookmarks} ORDER BY title");    $content[] = array(
14    $content = array();      'title' => 'Default Bookmarks',
15    while ($menu = db_fetch_array($result)) {      'href' => 'admin/build/bookmarks-customize/bookmarks-defaults',
16      if ($menu['menu_name']=='defaults') {      'localized_options' => array(),
17        $menu['title'] = 'Default Bookmarks';      'description' => 'The default bookmarks for all users. This list will be used to pre-populate bookmarks for new users.',
18        $menu['href'] = 'admin/build/bookmarks-customize/'. $menu['menu_name'];      'menu_name' => 'bookmarks-default',
19        $menu['localized_options'] = array();    );
20      }    $content[] = array(
21      else {      'title' => 'Preset Bookmarks',
22        $usr = user_load(str_replace('bookmarks-','',$menu['menu_name']));      'href' => 'admin/build/bookmarks-customize/bookmarks-presets',
23        $menu['title'] = $usr->name;      'localized_options' => array(),
24        $menu['href'] = 'admin/build/bookmarks-customize/'. $menu['menu_name'];      'description' => 'The preset bookmarks for all users. This list will be used to provide a list or presets for all users.',
25        $menu['localized_options'] = array();      'menu_name' => 'bookmarks-presets',
26      }    );
     $content[] = $menu;  
   }  
27    
28    return theme('admin_block_content', $content);    return theme('admin_block_content', $content);
29  }  }
# Line 58  function bookmarks_overview_form(&$form_ Line 56  function bookmarks_overview_form(&$form_
56    
57    $form = _bookmarks_overview_tree_form($tree, $menu);    $form = _bookmarks_overview_tree_form($tree, $menu);
58    $form['#menu'] =  $menu;    $form['#menu'] =  $menu;
59    if (element_children($form)) {  
60      if (element_children($form) && $_GET['q'] != PRESETS_URL) {
61      $form['submit'] = array(      $form['submit'] = array(
62        '#type' => 'submit',        '#type' => 'submit',
63        '#value' => t('Save configuration'),        '#value' => t('Save configuration'),
64      );      );
65    }    }
66    else {    else if (!element_children($form)) {
67      $form['empty_menu'] = array('#value' => t('There are no bookmarks yet.'));      $form['empty_menu'] = array('#value' => t('There are no bookmarks yet.'));
68    }    }
69    return $form;    return $form;
# Line 94  function _bookmarks_overview_tree_form($ Line 93  function _bookmarks_overview_tree_form($
93        else {        else {
94          $form[$mlid]['title']['#value'] = l($item['title'], $item['href'], $item['localized_options']) . ($item['hidden'] ? ' ('. t('disabled') .')' : '');          $form[$mlid]['title']['#value'] = l($item['title'], $item['href'], $item['localized_options']) . ($item['hidden'] ? ' ('. t('disabled') .')' : '');
95        }        }
       $form[$mlid]['hidden'] = array(  
         '#type' => 'checkbox',  
         '#default_value' => !$item['hidden'],  
       );  
       $form[$mlid]['expanded'] = array(  
         '#type' => 'checkbox',  
         '#default_value' => $item['expanded'],  
       );  
       if (module_exists('bookmarks_public')) {  
         $form[$mlid]['public'] = array(  
           '#type' => 'checkbox',  
           '#default_value' => $item['options']['attributes']['public'],  
         );  
       }  
       $form[$mlid]['weight'] = array(  
         '#type' => 'weight',  
         '#delta' => 50,  
         '#default_value' => isset($form_state[$mlid]['weight']) ? $form_state[$mlid]['weight'] : $item['weight'],  
       );  
96        $form[$mlid]['mlid'] = array(        $form[$mlid]['mlid'] = array(
97          '#type' => 'hidden',          '#type' => 'hidden',
98          '#value' => $item['mlid'],          '#value' => $item['mlid'],
# Line 122  function _bookmarks_overview_tree_form($ Line 102  function _bookmarks_overview_tree_form($
102          '#default_value' => isset($form_state[$mlid]['plid']) ? $form_state[$mlid]['plid'] : $item['plid'],          '#default_value' => isset($form_state[$mlid]['plid']) ? $form_state[$mlid]['plid'] : $item['plid'],
103          '#size' => 6,          '#size' => 6,
104        );        );
105        // Build a list of operations.        $form[$mlid]['hidden'] = array(
106        $operations = array();          '#type' => 'checkbox',
107        $operations['edit'] = l(t('edit'), $actionpaths .'item/edit/'. $item['mlid']);          '#default_value' => !$item['hidden'],
108        // Only items created by the bookmarks module can be deleted.        );
109        if ($item['module'] == 'bookmarks' || $item['updated'] == 1) {        if ($_GET['q']!=PRESETS_URL) {
110          $operations['delete'] = l(t('delete'), $actionpaths .'item/delete/'. $item['mlid']);          $form[$mlid]['expanded'] = array(
111        }            '#type' => 'checkbox',
112              '#default_value' => $item['expanded'],
113            );
114            if (module_exists('bookmarks_public')) {
115              $form[$mlid]['public'] = array(
116                '#type' => 'checkbox',
117                '#default_value' => $item['options']['attributes']['public'],
118              );
119            }
120            $form[$mlid]['weight'] = array(
121              '#type' => 'weight',
122              '#delta' => 50,
123              '#default_value' => isset($form_state[$mlid]['weight']) ? $form_state[$mlid]['weight'] : $item['weight'],
124            );
125            // Build a list of operations.
126            $operations = array();
127            $operations['edit'] = l(t('edit'), $actionpaths .'item/edit/'. $item['mlid']);
128            // Only items created by the bookmarks module can be deleted.
129            if ($item['module'] == 'bookmarks' || $item['updated'] == 1) {
130              $operations['delete'] = l(t('delete'), $actionpaths .'item/delete/'. $item['mlid']);
131            }
132    
133        $form[$mlid]['operations'] = array();          $form[$mlid]['operations'] = array();
134        foreach ($operations as $op => $value) {          foreach ($operations as $op => $value) {
135          $form[$mlid]['operations'][$op] = array('#value' => $value);            $form[$mlid]['operations'][$op] = array('#value' => $value);
136            }
137          }
138          else {
139            // Build a list of operations.
140            $operations = array();
141            if ($item['href']=='folder') {
142              $operations['add'] = l(t('Add Folder'), PRESETS_URL .'/add/'. $item['mlid']);
143            }
144            else {
145              $operations['add'] = l(t('Add'), PRESETS_URL .'/add/'. $item['mlid']);
146            }
147    
148            $form[$mlid]['operations'] = array();
149            foreach ($operations as $op => $value) {
150              $form[$mlid]['operations'][$op] = array('#value' => $value);
151            }
152        }        }
153      }      }
154    
# Line 201  function bookmarks_overview_form_submit( Line 217  function bookmarks_overview_form_submit(
217   * @ingroup themeable   * @ingroup themeable
218   */   */
219  function theme_bookmarks_overview_form($form) {  function theme_bookmarks_overview_form($form) {
220    drupal_add_tabledrag('bookmarks-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1);    $output = '';
221    drupal_add_tabledrag('bookmarks-overview', 'order', 'sibling', 'menu-weight');    if ($_GET['q'] == PRESETS_URL) {
   
   if (module_exists('bookmarks_public')) {  
222      $header = array(      $header = array(
223        t('Menu item'),        t('Menu item'),
       array('data' => t('Enabled'), 'class' => 'checkbox'),  
       array('data' => t('Expanded'), 'class' => 'checkbox'),  
       array('data' => t('Public'), 'class' => 'checkbox'),  
       t('Weight'),  
224        array('data' => t('Operations'), 'colspan' => '3'),        array('data' => t('Operations'), 'colspan' => '3'),
225      );      );
226    }    }
227    else {    else {
228      $header = array(      drupal_add_tabledrag('bookmarks-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1);
229        t('Menu item'),      drupal_add_tabledrag('bookmarks-overview', 'order', 'sibling', 'menu-weight');
230        array('data' => t('Enabled'), 'class' => 'checkbox'),  
231        array('data' => t('Expanded'), 'class' => 'checkbox'),      if (module_exists('bookmarks_public')) {
232        t('Weight'),        $header = array(
233        array('data' => t('Operations'), 'colspan' => '3'),          t('Menu item'),
234      );          array('data' => t('Enabled'), 'class' => 'checkbox'),
235            array('data' => t('Expanded'), 'class' => 'checkbox'),
236            array('data' => t('Public'), 'class' => 'checkbox'),
237            t('Weight'),
238            array('data' => t('Operations'), 'colspan' => '3'),
239          );
240        }
241        else {
242          $header = array(
243            t('Menu item'),
244            array('data' => t('Enabled'), 'class' => 'checkbox'),
245            array('data' => t('Expanded'), 'class' => 'checkbox'),
246            t('Weight'),
247            array('data' => t('Operations'), 'colspan' => '3'),
248          );
249        }
250    }    }
251    
252    $rows = array();    $rows = array();
# Line 244  function theme_bookmarks_overview_form($ Line 269  function theme_bookmarks_overview_form($
269    
270        // Change the parent field to a hidden. This allows any value but hides the field.        // Change the parent field to a hidden. This allows any value but hides the field.
271        $element['plid']['#type'] = 'hidden';        $element['plid']['#type'] = 'hidden';
272          if ($_GET['q'] == PRESETS_URL) {
273            $element['hidden']['#type'] = 'hidden';
274          }
275    
276        $row = array();        $row = array();
277        $row[] = theme('indentation', $element['#item']['depth'] - 1) . drupal_render($element['title']);        $row[] = theme('indentation', $element['#item']['depth'] - 1) . drupal_render($element['title']);
278        $row[] = array('data' => drupal_render($element['hidden']), 'class' => 'checkbox');        if ($_GET['q'] != PRESETS_URL) {
279        $row[] = array('data' => drupal_render($element['expanded']), 'class' => 'checkbox');          $row[] = array('data' => drupal_render($element['hidden']), 'class' => 'checkbox');
280        if (module_exists('bookmarks_public')) {          $row[] = array('data' => drupal_render($element['expanded']), 'class' => 'checkbox');
281          $row[] = array('data' => drupal_render($element['public']), 'class' => 'checkbox');          if (module_exists('bookmarks_public')) {
282              $row[] = array('data' => drupal_render($element['public']), 'class' => 'checkbox');
283            }
284        }        }
285        $row[] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']);        $row[] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']);
286        $row = array_merge($row, $operations);        $row = array_merge($row, $operations);
# Line 260  function theme_bookmarks_overview_form($ Line 290  function theme_bookmarks_overview_form($
290        $rows[] = $row;        $rows[] = $row;
291      }      }
292    }    }
   $output = '';  
293    if ($rows) {    if ($rows) {
294      $output .= theme('table', $header, $rows, array('id' => 'bookmarks-overview'));      $output .= theme('table', $header, $rows, array('id' => 'bookmarks-overview'));
295    }    }
296    $output .= drupal_render($form);    $output .= drupal_render($form);
297    
298    return $output;    return $output;
299  }  }
300    
# Line 372  function bookmarks_edit_item(&$form_stat Line 402  function bookmarks_edit_item(&$form_stat
402    $options = menu_parent_options(bookmarks_get_menus(FALSE, $menu['menu_name']), $item);    $options = menu_parent_options(bookmarks_get_menus(FALSE, $menu['menu_name']), $item);
403    $default = $item['menu_name'] .':'. $item['plid'];    $default = $item['menu_name'] .':'. $item['plid'];
404    $menu_userid = (str_replace('bookmarks-', '', $item['menu_name']));    $menu_userid = (str_replace('bookmarks-', '', $item['menu_name']));
405    if ($menu_userid == $user->uid) {    switch ($item['menu_name']) {
406      $options[$item['menu_name'] . ':0'] = $user->name;      case $user->uid:
407    }        $options[$item['menu_name'] . ':0'] = '<' . $user->name . '>';
408    else {        break;
409      $menu_user = user_load($menu_userid);      case 'bookmarks-defaults':
410      $options[$item['menu_name'] . ':0'] = $menu_user->name;        $options[$item['menu_name'] . ':0'] = '<Defaults>';
411          break;
412        case 'bookmarks-presets':
413          $options[$item['menu_name'] . ':0'] = '<Presets>';
414          break;
415        default:
416          $menu_user = user_load($menu_userid);
417          $options[$item['menu_name'] . ':0'] = '<' . $menu_user->name . '>';
418          break;
419    }    }
420    $form['bookmarks']['parent'] = array(    $form['bookmarks']['parent'] = array(
421      '#type' => 'select',      '#type' => 'select',
# Line 667  function bookmarks_item_delete_form_subm Line 705  function bookmarks_item_delete_form_subm
705    }    }
706  }  }
707    
708    /**
709     * Add presets to the current users bookmarks
710     */
711    function bookmarks_add_preset($item, $plid = array('p1' => 0, 'p2' => 0, 'p3' => 0, 'p4' => 0, 'p5' => 0, 'p6' => 0, 'p7' => 0, 'p8' => 0, 'p9' => 0), $depth = 1) {
712      global $user;
713      _bookmarks_add_preset($item, $plid, $depth);
714    
715      menu_cache_clear('bookmarks-' . $user->uid );
716      drupal_set_message('The preset has been added to your bookmarks.');
717      drupal_goto('bookmarks/mine');
718      return '';
719    }
720    
721    /**
722     * Helper function to add presets to the current users bookmarks.
723     */
724    function _bookmarks_add_preset($item, $plid, $depth) {
725      global $user;
726    
727      db_query("INSERT INTO {menu_links} (menu_name, plid, link_path, router_path, link_title, options, module, hidden, external, has_children, expanded, weight, depth, customized, p1, p2, p3, p4, p5, p6, p7, p8, p9, updated) SELECT 'bookmarks-%d', %d, link_path, router_path, link_title, options, 'bookmarks', hidden, external, has_children, expanded, 0, %d, customized, %d, %d, %d, %d, %d, %d, %d, %d, %d, updated FROM menu_links WHERE mlid=%d", $user->uid, $plid['p1'], $depth, $plid['p1'], $plid['p2'], $plid['p3'], $plid['p4'], $plid['p5'], $plid['p6'], $plid['p7'], $plid['p8'], $plid['p9'], $item['mlid']);
728    
729    
730    //There's got to be a better way to do this.
731    
732      $plid['p9']=$plid['p8'];
733      $plid['p8']=$plid['p7'];
734      $plid['p7']=$plid['p6'];
735      $plid['p6']=$plid['p5'];
736      $plid['p5']=$plid['p4'];
737      $plid['p4']=$plid['p3'];
738      $plid['p3']=$plid['p2'];
739      $plid['p2']=$plid['p1'];
740      $plid['p1']=db_last_insert_id('menu_links','mlid');
741    
742      $pl_tmp = $plid;
743      $pl_cnt = 1;
744    
745      for ($i=1;$i<10;$i++) {
746        if ($plid['p' . $i]==0) {
747          $pl_cnt = $i;
748          $i = 10;
749        }
750      }
751    
752      $pl_keys = array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9');
753    
754      $plid = array_combine($pl_keys, array_merge(array_reverse(array_slice($plid, 0, $pl_cnt-1)), array_slice($plid, $pl_cnt-1)));
755    
756      db_query("UPDATE {menu_links} SET p1=%d, p2=%d, p3=%d, p4=%d, p5=%d, p6=%d, p7=%d, p8=%d, p9=%d WHERE mlid = %d", $plid['p1'], $plid['p2'], $plid['p3'], $plid['p4'], $plid['p5'], $plid['p6'], $plid['p7'], $plid['p8'], $plid['p9'], $pl_tmp['p1']);
757    
758      if ($item['has_children']) {
759        $depth++;
760    
761        $result = db_query("SELECT mlid FROM menu_links WHERE plid=%d", $item['mlid']);
762        while ($mnu = db_fetch_object($result)) {
763          _bookmarks_add_preset(array('mlid' => $mnu->mlid), $plid, $depth);
764        }
765      }
766      return $plid;
767    }

Legend:
Removed from v.1.5.2.4  
changed lines
  Added in v.1.5.2.5

  ViewVC Help
Powered by ViewVC 1.1.3