stylizer.module
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* @file
* Stylizer module
*
* This module allows styles to be created and managed on behalf of modules
* that implement styles.
*
* The Stylizer tool allows recolorable styles to be created via a miniature
* scripting language. Panels utilizes this to allow administrators to add
* styles directly to any panel display.
*/
/**
* Implements hook_permission()
*/
function stylizer_permission() {
return array(
'administer stylizer' => array(
'title' => t("Use the Stylizer UI"),
'description' => t("Allows a user to use the CTools Stylizer UI."),
),
);
}
/**
* Implementation of hook_ctools_plugin_directory() to let the system know
* we implement task and task_handler plugins.
*/
function stylizer_ctools_plugin_directory($module, $plugin) {
// Most of this module is implemented as an export ui plugin, and the
// rest is in ctools/includes/stylizer.inc
if ($module == 'ctools' && $plugin == 'export_ui') {
return 'plugins/' . $plugin;
}
}
/**
* Implements hook_ctools_plugin_type() to inform the plugin system that
* Stylizer style_base plugin types.
*/
function stylizer_ctools_plugin_type() {
return array(
'style_bases' => array(
'load themes' => TRUE,
),
);
}
/**
* Implementation of hook_panels_dashboard_blocks().
*
* Adds page information to the Panels dashboard.
*/
function stylizer_panels_dashboard_blocks(&$vars) {
$vars['links']['stylizer'] = array(
'title' => l(t('Custom style'), 'admin/structure/stylizer/add'),
'description' => t('Custom styles can be applied to Panel regions and Panel panes.'),
);
// Load all mini panels and their displays.
ctools_include('export');
ctools_include('stylizer');
$items = ctools_export_crud_load_all('stylizer');
$count = 0;
$rows = array();
$base_types = ctools_get_style_base_types();
foreach ($items as $item) {
$style = ctools_get_style_base($item->settings['style_base']);
if ($style && $style['module'] == 'panels') {
$type = $base_types[$style['module']][$style['type']]['title'];
$rows[] = array(
check_plain($item->admin_title),
$type,
array(
'data' => l(t('Edit'), "admin/structure/stylizer/list/$item->name/edit"),
'class' => 'links',
),
);
// Only show 10.
if (++$count >= 10) {
break;
}
}
}
if ($rows) {
$content = theme('table', array('rows' => $rows, 'attributes' => array('class' => 'panels-manage')));
}
else {
$content = '<p>' . t('There are no custom styles.') . '</p>';
}
$vars['blocks']['stylizer'] = array(
'title' => t('Manage styles'),
'link' => l(t('Go to list'), 'admin/structure/stylizer'),
'content' => $content,
'class' => 'dashboard-styles',
'section' => 'left',
);
}
/**
* Implementation of hook_theme to load all content plugins and pass thru if
* necessary.
*/
function stylizer_theme() {
$theme = array();
ctools_include('stylizer');
// Register all themes given for basetypes.
$plugins = ctools_get_style_bases();
$base_types = ctools_get_style_base_types();
foreach ($plugins as $plugin) {
if (!empty($base_types[$plugin['module']][$plugin['type']]) && !empty($plugin['theme'])) {
$base_type = $base_types[$plugin['module']][$plugin['type']];
$theme[$plugin['theme']] = array(
'variables' => $base_type['theme variables'],
'path' => $plugin['path'],
);
// if no theme function exists, assume template.
if (!function_exists("theme_$plugin[theme]")) {
$theme[$plugin['theme']]['template'] = str_replace('_', '-', $plugin['theme']);
$theme[$plugin['theme']]['file'] = $plugin['file']; // for preprocess.
}
}
}
return $theme;
}