Projet

Général

Profil

Paste
Télécharger (3,71 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / stylizer / stylizer.module @ 6e3ce7c2

1
<?php
2

    
3
/**
4
 * @file
5
 * Stylizer module.
6
 *
7
 * This module allows styles to be created and managed on behalf of modules
8
 * that implement styles.
9
 *
10
 * The Stylizer tool allows recolorable styles to be created via a miniature
11
 * scripting language. Panels utilizes this to allow administrators to add
12
 * styles directly to any panel display.
13
 */
14

    
15
/**
16
 * Implements hook_permission()
17
 */
18
function stylizer_permission() {
19
  return array(
20
    'administer stylizer' => array(
21
      'title' => t("Use the Stylizer UI"),
22
      'description' => t("Allows a user to use the CTools Stylizer UI."),
23
    ),
24
  );
25
}
26

    
27
/**
28
 * Implementation of hook_ctools_plugin_directory() to let the system know
29
 * we implement task and task_handler plugins.
30
 */
31
function stylizer_ctools_plugin_directory($module, $plugin) {
32
  // Most of this module is implemented as an export ui plugin, and the
33
  // rest is in ctools/includes/stylizer.inc.
34
  if ($module == 'ctools' && $plugin == 'export_ui') {
35
    return 'plugins/' . $plugin;
36
  }
37
}
38

    
39
/**
40
 * Implements hook_ctools_plugin_type() to inform the plugin system that
41
 * Stylizer style_base plugin types.
42
 */
43
function stylizer_ctools_plugin_type() {
44
  return array(
45
    'style_bases' => array(
46
      'load themes' => TRUE,
47
    ),
48
  );
49
}
50

    
51
/**
52
 * Implementation of hook_panels_dashboard_blocks().
53
 *
54
 * Adds page information to the Panels dashboard.
55
 */
56
function stylizer_panels_dashboard_blocks(&$vars) {
57
  $vars['links']['stylizer'] = array(
58
    'title' => l(t('Custom style'), 'admin/structure/stylizer/add'),
59
    'description' => t('Custom styles can be applied to Panel regions and Panel panes.'),
60
  );
61

    
62
  // Load all mini panels and their displays.
63
  ctools_include('export');
64
  ctools_include('stylizer');
65
  $items = ctools_export_crud_load_all('stylizer');
66
  $count = 0;
67
  $rows = array();
68

    
69
  $base_types = ctools_get_style_base_types();
70
  foreach ($items as $item) {
71
    $style = ctools_get_style_base($item->settings['style_base']);
72
    if ($style && $style['module'] == 'panels') {
73
      $type = $base_types[$style['module']][$style['type']]['title'];
74

    
75
      $rows[] = array(
76
        check_plain($item->admin_title),
77
        $type,
78
        array(
79
          'data' => l(t('Edit'), "admin/structure/stylizer/list/$item->name/edit"),
80
          'class' => 'links',
81
        ),
82
      );
83

    
84
      // Only show 10.
85
      if (++$count >= 10) {
86
        break;
87
      }
88
    }
89
  }
90

    
91
  if ($rows) {
92
    $content = theme('table', array('rows' => $rows, 'attributes' => array('class' => 'panels-manage')));
93
  }
94
  else {
95
    $content = '<p>' . t('There are no custom styles.') . '</p>';
96
  }
97

    
98
  $vars['blocks']['stylizer'] = array(
99
    'title' => t('Manage styles'),
100
    'link' => l(t('Go to list'), 'admin/structure/stylizer'),
101
    'content' => $content,
102
    'class' => 'dashboard-styles',
103
    'section' => 'left',
104
  );
105
}
106

    
107
/**
108
 * Implementation of hook_theme to load all content plugins and pass thru if
109
 * necessary.
110
 */
111
function stylizer_theme() {
112
  $theme = array();
113
  ctools_include('stylizer');
114
  // Register all themes given for basetypes.
115
  $plugins = ctools_get_style_bases();
116
  $base_types = ctools_get_style_base_types();
117
  foreach ($plugins as $plugin) {
118
    if (!empty($base_types[$plugin['module']][$plugin['type']]) && !empty($plugin['theme'])) {
119
      $base_type = $base_types[$plugin['module']][$plugin['type']];
120
      $theme[$plugin['theme']] = array(
121
        'variables' => $base_type['theme variables'],
122
        'path' => $plugin['path'],
123
      );
124

    
125
      // If no theme function exists, assume template.
126
      if (!function_exists("theme_$plugin[theme]")) {
127
        $theme[$plugin['theme']]['template'] = str_replace('_', '-', $plugin['theme']);
128
        // For preprocess.
129
        $theme[$plugin['theme']]['file'] = $plugin['file'];
130
      }
131
    }
132
  }
133

    
134
  return $theme;
135
}