Project

General

Profile

Paste
Download (8.67 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / panels / panels_ipe / panels_ipe.module @ c06bd9a4

1
<?php
2

    
3
/**
4
 * @file
5
 */
6

    
7
/**
8
 * Implementation of hook_ctools_plugin_directory().
9
 */
10
function panels_ipe_ctools_plugin_directory($module, $plugin) {
11
  if ($module == 'panels' && $plugin == 'display_renderers') {
12
    return 'plugins/' . $plugin;
13
  }
14
}
15

    
16
/**
17
 * Implementation of hook_ctools_plugin_api().
18
 *
19
 * Inform CTools about version information for various plugins implemented by
20
 * Panels.
21
 *
22
 * @param string $owner
23
 *   The system name of the module owning the API about which information is
24
 *   being requested.
25
 * @param string $api
26
 *   The name of the API about which information is being requested.
27
 */
28
function panels_ipe_ctools_plugin_api($owner, $api) {
29
  if ($owner == 'panels' && $api == 'pipelines') {
30
    return array(
31
      'version' => 1,
32
      'path' => drupal_get_path('module', 'panels_ipe') . '/includes',
33
    );
34
  }
35
}
36

    
37
/**
38
 * Implementation of hook_theme().
39
 */
40
function panels_ipe_theme() {
41
  return array(
42
    'panels_ipe_pane_wrapper' => array(
43
      'variables' => array('output' => NULL, 'pane' => NULL, 'display' => NULL, 'renderer' => NULL),
44
    ),
45
    'panels_ipe_region_wrapper' => array(
46
      'variables' => array('output' => NULL, 'region_id' => NULL, 'display' => NULL, 'controls' => NULL, 'renderer' => NULL),
47
    ),
48
    'panels_ipe_add_pane_button' => array(
49
      'variables' => array('region_id' => NULL, 'display' => NULL, 'renderer' => NULL),
50
    ),
51
    'panels_ipe_placeholder_pane' => array(
52
      'variables' => array('region_id' => NULL, 'region_title' => NULL),
53
    ),
54
    'panels_ipe_dnd_form_container' => array(
55
      'variables' => array('link' => NULL, 'cache_key' => NULL, 'display' => NULL),
56
    ),
57
    'panels_ipe_toolbar' => array(
58
      'variables' => array('buttons' => NULL),
59
    ),
60
  );
61
}
62

    
63
/**
64
 * Theme the 'placeholder' pane, which is shown on an active IPE when no panes
65
 * live in that region.
66
 *
67
 * @param string $region_id
68
 * @param string $region_title
69
 */
70
function theme_panels_ipe_placeholder_pane($vars) {
71
  $region_id = $vars['region_id'];
72
  $region_title = $vars['region_title'];
73

    
74
  $output = '<div class="panels-ipe-placeholder-content">';
75
  $output .= "<h3>$region_title</h3>";
76
  $output .= '</div>';
77
  return $output;
78
}
79

    
80
function template_preprocess_panels_ipe_pane_wrapper(&$vars) {
81
  $pane = $vars['pane'];
82
  $display = $vars['display'];
83
  $renderer = $vars['renderer'];
84

    
85
  $content_type = ctools_get_content_type($pane->type);
86
  $subtype = ctools_content_get_subtype($content_type, $pane->subtype);
87
  $vars['links'] = array();
88

    
89
  if (ctools_content_editable($content_type, $subtype, $pane->configuration)) {
90
    $vars['links']['edit'] = array(
91
      'title' => isset($content_type['edit text']) ? '<span>' . $content_type['edit text'] . '</span>' : '<span>' . t('Settings') . '</span>',
92
      'href' => $renderer->get_url('edit-pane', $pane->pid),
93
      'query' => drupal_get_destination(),
94
      'html' => TRUE,
95
      'attributes' => array(
96
        'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
97
        'title' => isset($content_type['edit text']) ? $content_type['edit text'] : t('Settings'),
98
        // 'id' => "pane-edit-panel-pane-$pane->pid",.
99
      ),
100
    );
101
  }
102

    
103
  // Add option to configure style in IPE.
104
  if (user_access('administer panels pane styles')) {
105
    $vars['links']['style'] = array(
106
      'title' => '<span>' . t('Style') . '</span>',
107
      'href' => $renderer->get_url('style-type', 'pane', $pane->pid),
108
      'query' => drupal_get_destination(),
109
      'html' => TRUE,
110
      'attributes' => array(
111
        'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
112
        'title' => t('Style'),
113
      ),
114
    );
115
  }
116

    
117
  // Add option to configure CSS.
118
  if (user_access('administer advanced pane settings')) {
119
    $vars['links']['css'] = array(
120
      'title' => '<span>' . t('CSS') . '</span>',
121
      'href' => $renderer->get_url('pane-css', $pane->pid),
122
      'query' => drupal_get_destination(),
123
      'html' => TRUE,
124
      'attributes' => array(
125
        'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
126
        'title' => t('CSS'),
127
      ),
128
    );
129
  }
130

    
131
  // Deleting is managed entirely in the js; this is just an attachment point
132
  // for it.
133
  $vars['links']['delete'] = array(
134
    'title' => '<span>' . t('Delete') . '</span>',
135
    'href' => '#',
136
    'html' => TRUE,
137
    'attributes' => array(
138
      'class' => 'pane-delete',
139
      'id' => "pane-delete-panel-pane-$pane->pid",
140
      'title' => t('Delete'),
141
    ),
142
  );
143

    
144
  $context = array(
145
    'pane' => $pane,
146
    'display' => $display,
147
    'renderer' => $renderer,
148
  );
149
  drupal_alter('panels_ipe_pane_links', $vars['links'], $context);
150

    
151
}
152

    
153
function theme_panels_ipe_pane_wrapper($vars) {
154
  $output = $vars['output'];
155
  $pane = $vars['pane'];
156
  $display = $vars['display'];
157

    
158
  $attributes = array(
159
    'class' => 'panels-ipe-linkbar',
160
  );
161

    
162
  $type = ctools_get_content_type($pane->type);
163
  $title = '<span class = "panels-ipe-dragbar-admin-title">' . ctools_content_admin_title($type, $pane->subtype, $pane->configuration, $display->context) . '</span>';
164

    
165
  $links = theme('links', array('links' => $vars['links'], 'attributes' => $attributes));
166

    
167
  if (!empty($pane->locks['type']) && $pane->locks['type'] == 'immovable') {
168
    $links = '<div class="panels-ipe-dragbar panels-ipe-nodraghandle clearfix">' . $links . $title . '</div>';
169
  }
170
  else {
171
    $links = '<div class="panels-ipe-dragbar panels-ipe-draghandle clearfix">' . $links . $title . '<span class="panels-ipe-draghandle-icon"><span class="panels-ipe-draghandle-icon-inner"></span></span></div>';
172
  }
173

    
174
  $handlebar = '<div class="panels-ipe-handlebar-wrapper panels-ipe-on">' . $links . '</div>';
175

    
176
  return $handlebar . $output;
177
}
178

    
179
function theme_panels_ipe_region_wrapper($vars) {
180
  return $vars['controls'] . $vars['output'];
181
}
182

    
183
function template_preprocess_panels_ipe_add_pane_button(&$vars) {
184
  $region_id = $vars['region_id'];
185
  $display = $vars['display'];
186
  $renderer = $vars['renderer'];
187
  $vars['links'] = array();
188

    
189
  // Add option to configure style in IPE.
190
  if (user_access('administer panels region styles')) {
191
    $vars['links']['style'] = array(
192
      'title' => '<span>' . t('Region style') . '</span>',
193
      'href' => $renderer->get_url('style-type', 'region', $region_id),
194
      'html' => TRUE,
195
      'attributes' => array(
196
        'class' => array('ctools-use-modal', 'panels-ipe-hide-bar', 'style'),
197
        'title' => t('Region style'),
198
      ),
199
    );
200
  }
201

    
202
  // Add option to add items in the IPE.
203
  $vars['links']['add-pane'] = array(
204
    'title' => '<span>' . t('Add new pane') . '</span>',
205
    'href' => $renderer->get_url('select-content', $region_id),
206
    'attributes' => array(
207
      'class' => array('ctools-use-modal', 'add', 'panels-ipe-hide-bar'),
208
      'title' => t('Add new pane'),
209
    ),
210
    'html' => TRUE,
211
  );
212

    
213
  $context = array(
214
    'region_id' => $region_id,
215
    'display' => $display,
216
    'renderer' => $renderer,
217
  );
218
  drupal_alter('panels_ipe_region_links', $vars['links'], $context);
219

    
220
}
221

    
222
function theme_panels_ipe_add_pane_button($vars) {
223
  $attributes = array(
224
    'class' => array('panels-ipe-linkbar', 'inline'),
225
  );
226

    
227
  $links = theme('links', array('links' => $vars['links'], 'attributes' => $attributes));
228

    
229
  return '<div class="panels-ipe-newblock panels-ipe-on">' . $links . '</div>';
230
}
231

    
232
/**
233
 * Add a button to the IPE toolbar.
234
 */
235
function panels_ipe_toolbar_add_button($cache_key, $id, $button) {
236
  $buttons = &drupal_static('panels_ipe_toolbar_buttons', array());
237
  drupal_alter('panels_ipe_button', $button, $id, $cache_key);
238
  $buttons[$cache_key][$id] = $button;
239
}
240

    
241
/**
242
 * Implementation of hook_footer().
243
 *
244
 * Adds the IPE control container.
245
 *
246
 * @param unknown_type $main
247
 */
248
function panels_ipe_page_alter(&$page) {
249
  $buttons = &drupal_static('panels_ipe_toolbar_buttons', array());
250
  if (empty($buttons)) {
251
    return;
252
  }
253

    
254
  $output = theme('panels_ipe_toolbar', array('buttons' => $buttons));
255

    
256
  $page['page_bottom']['panels_ipe'] = array(
257
    '#markup' => $output,
258
  );
259
}
260

    
261
function theme_panels_ipe_toolbar($vars) {
262
  $buttons = $vars['buttons'];
263
  ctools_include('cleanstring');
264

    
265
  $output = "<div id='panels-ipe-control-container' class='clearfix'>";
266
  foreach ($buttons as $key => $ipe_buttons) {
267
    $key = ctools_cleanstring($key);
268
    $output .= "<div id='panels-ipe-control-$key' class='panels-ipe-control'>";
269

    
270
    // Controls in this container will appear when the IPE is not on.
271
    $output .= '<div class="panels-ipe-button-container clearfix">';
272
    foreach ($ipe_buttons as $button) {
273
      $output .= is_string($button) ? $button : drupal_render($button);
274
    }
275
    $output .= '</div>';
276

    
277
    // Controls in this container will appear when the IPE is on. It is usually
278
    // filled via AJAX.
279
    $output .= '<div class="panels-ipe-form-container clearfix"></div>';
280
    $output .= '</div>';
281
  }
282

    
283
  $output .= "</div>";
284

    
285
  return $output;
286
}