| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: stylizer.inc,v 1.1.2.6 2010/08/22 00:42:52 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * Definition of the 'stylizer' panel style. 7 */ 8 9 // Plugin definition 10 $plugin = array( 11 'title' => t('Custom style'), 12 'weight' => -10, 13 'description' => t('Allows choice of a stylizer style'), 14 15 'render pane' => 'panels_stylizer_stylizer_style_render_pane', 16 'pane settings form' => 'panels_stylizer_stylizer_style_settings_form', 17 18 'render region' => 'panels_stylizer_stylizer_style_render_region', 19 'settings form' => 'panels_stylizer_stylizer_style_settings_form', 20 21 // We offer substyles so provide callbacks to do so. 22 'get child' => 'panels_stylizer_get_substyle', 23 'get children' => 'panels_stylizer_get_substyles', 24 25 // Set up an AJAX callback for the style 26 'ajax' => array( 27 'custom' => 'panels_stylizer_pane_add_style', 28 ), 29 // 'settings validate' => 'panels_stylizer_stylizer_style_settings_validate', 30 ); 31 32 /** 33 * Merge the main stylizer plugin with a style to create a sub plugin. 34 * 35 * This is used for both panels_stylizer_get_substyle and 36 * panels_stylizer_get_substyles. 37 */ 38 function panels_stylizer_merge_plugin($plugin, $style) { 39 $plugin['name'] = 'stylizer:' . $style->name; 40 $plugin['title'] = check_plain($style->admin_title); 41 $plugin['description'] = check_plain($style->admin_description); 42 $plugin['style'] = $style; 43 $plugin['weight'] = 0; 44 45 ctools_include('stylizer'); 46 $base = ctools_get_style_base($style->settings['style_base']); 47 if ($base['type'] == 'pane') { 48 unset($plugin['render region']); 49 } 50 else { 51 unset($plugin['render pane']); 52 } 53 54 unset($plugin['settings form']); 55 unset($plugin['pane settings form']); 56 return $plugin; 57 } 58 59 /** 60 * Callback to provide a single stored stylizer style. 61 */ 62 function panels_stylizer_get_substyle($plugin, $style_name, $substyle_name) { 63 // Do not worry about caching; Panels is handling that for us. 64 ctools_include('export'); 65 $item = ctools_export_crud_load('stylizer', $substyle_name); 66 if ($item) { 67 return panels_stylizer_merge_plugin($plugin, $item); 68 } 69 } 70 71 /** 72 * Callback to provide all stored stylizer styles. 73 */ 74 function panels_stylizer_get_substyles($plugin, $style_name) { 75 $styles[$style_name] = $plugin; 76 ctools_include('export'); 77 ctools_include('stylizer'); 78 $items = ctools_export_crud_load_all('stylizer'); 79 foreach ($items as $name => $item) { 80 $base = ctools_get_style_base($item->settings['style_base']); 81 if ($base && $base['module'] == 'panels') { 82 $styles['stylizer:' . $name] = panels_stylizer_merge_plugin($plugin, $item); 83 } 84 } 85 86 return $styles; 87 } 88 89 function _panels_stylizer_get_style($plugin, $style_settings) { 90 if (!empty($plugin['style'])) { 91 return $plugin['style']->settings; 92 } 93 else if ($style_settings['style'] == '$') { 94 return $style_settings['settings']; 95 } 96 else { 97 ctools_include('export'); 98 $style = ctools_export_crud_load('stylizer', $style_settings['style']); 99 if ($style) { 100 return $style->settings; 101 } 102 } 103 } 104 105 /** 106 * Region render theme. 107 */ 108 function theme_panels_stylizer_stylizer_style_render_region($display, $owner_id, $panes, $style_settings, $region_id, $plugin) { 109 $output = ''; 110 111 foreach ($panes as $pane_id => $pane_output) { 112 $output .= $pane_output; 113 } 114 115 $settings = _panels_stylizer_get_style($plugin, $style_settings); 116 117 if (!empty($settings)) { 118 ctools_include('stylizer'); 119 $plugin = ctools_get_style_base($settings['style_base']); 120 ctools_stylizer_add_css($plugin, $settings); 121 122 return theme($plugin['theme'], $settings, ctools_stylizer_get_css_class($plugin, $settings), $output); 123 } 124 else { 125 // if the style is gone, just display the output. 126 return $output; 127 } 128 } 129 130 /** 131 * Pane render theme 132 */ 133 function theme_panels_stylizer_stylizer_style_render_pane($content, $pane, $display, $plugin) { 134 $settings = _panels_stylizer_get_style($plugin, $pane->style['settings']); 135 136 if ($settings) { 137 ctools_include('stylizer'); 138 $plugin = ctools_get_style_base($settings['style_base']); 139 140 if (empty($content->css_class)) { 141 $content->css_class = ctools_stylizer_get_css_class($plugin, $settings); 142 } 143 else { 144 $content->css_class .= ' ' . ctools_stylizer_get_css_class($plugin, $settings); 145 } 146 147 ctools_stylizer_add_css($plugin, $settings); 148 149 if (isset($plugin['theme'])) { 150 return theme($plugin['theme'], $settings, $content, $pane, $display); 151 } 152 } 153 154 // if the style is gone or has no theme of its own, just display the output. 155 return theme('panels_pane', $content, $pane, $display); 156 } 157 158 /** 159 * Settings form callback. 160 */ 161 function panels_stylizer_stylizer_style_settings_form($style_settings, $display, $pid, $type, $form_state) { 162 // Just redirect this to the custom style settings ajax. 163 panels_stylizer_pane_add_style($form_state['renderer'], array(), $style_settings, $type, $pid); 164 ctools_ajax_render($form_state['renderer']->commands); 165 } 166 167 168 /** 169 * Allow on-the-fly creation of styles in panes. 170 */ 171 function panels_stylizer_pane_add_style(&$renderer, $plugin, &$conf, $type, $pid, $step = NULL) { 172 if (!user_access('administer panels styles')) { 173 return; 174 } 175 176 ctools_include('stylizer'); 177 $js = FALSE; 178 179 $path = $renderer->get_url('style', 'custom', $type, $pid, '%step'); 180 181 $info = array( 182 'module' => 'panels', 183 'type' => $type, 184 'path' => $path, 185 'modal' => t('Create custom style'), 186 'owner form' => 'panels_stylizer_edit_pane_style_form', 187 'owner form validate' => 'panels_stylizer_edit_pane_style_form_validate', 188 'owner form submit' => 'panels_stylizer_edit_pane_style_form_submit', 189 'owner settings' => array('preconfigured' => FALSE, 'name' => '', 'admin_title' => '', 'admin_description' => ''), 190 'cache' => &$renderer->cache, 191 'conf' => &$conf, 192 'pid' => $pid, 193 ); 194 195 if (!empty($conf['settings'])) { 196 $info['settings'] = $conf['settings']; 197 } 198 199 $output = ctools_stylizer_edit_style($info, TRUE, $step); 200 if (!empty($info['complete'])) { 201 if (!empty($info['owner settings']['preconfigured'])) { 202 ctools_include('export'); 203 $style = ctools_export_crud_new('stylizer'); 204 $style->name = $info['settings']['name']; 205 $style->admin_title = $info['owner settings']['admin_title']; 206 $style->admin_description = $info['owner settings']['admin_description']; 207 $style->settings = $info['settings']; 208 ctools_export_crud_save('stylizer', $style); 209 $conf['style'] = $info['settings']['name']; 210 if (isset($conf['settings'])) { 211 unset($conf['settings']); 212 } 213 } 214 else { 215 $conf['style'] = '$'; 216 $conf['settings'] = $info['settings']; 217 } 218 219 // Be sure to unset the temporary if the style was just changed. 220 if (isset($renderer->cache->style)) { 221 unset($renderer->cache->style); 222 } 223 // $conf was a reference so it should just modify. 224 panels_edit_cache_set($renderer->cache); 225 226 $renderer->commands[] = ctools_modal_command_dismiss(); 227 228 if ($type == 'pane') { 229 $renderer->command_update_pane($pid); 230 } 231 else if ($type == 'region') { 232 $renderer->command_update_region_links($pid); 233 } 234 else { 235 $renderer->command_update_display_links(); 236 } 237 } 238 else { 239 $renderer->commands = $output; 240 } 241 } 242 243 244 /** 245 * The form for determining if a pane should create a local style or a 246 * preconfigured style. 247 */ 248 function panels_stylizer_edit_pane_style_form(&$form, &$form_state) { 249 if (!user_access('administer panels styles') || !module_exists('stylizer')) { 250 return; 251 } 252 ctools_include('dependent'); 253 254 $settings = $form_state['owner info']['owner settings']; 255 $form['panels']['admin_title'] = array( 256 '#type' => 'textfield', 257 '#title' => t('Administrative title'), 258 '#description' => t('The name of this style. This will appear in the administrative interface to easily identify it.'), 259 '#default_value' => $settings['admin_title'], 260 '#process' => array('ctools_dependent_process'), 261 '#dependency' => array('edit-preconfigured' => array(1)), 262 ); 263 264 $form['panels']['name'] = array( 265 '#type' => 'textfield', 266 '#title' => t('Machine name'), 267 '#description' => t('The machine readable name of this page. It must be unique, and it must contain only alphanumeric characters and underscores. Once created, you will not be able to change this value!'), 268 '#default_value' => $settings['name'], 269 '#process' => array('ctools_dependent_process'), 270 '#dependency' => array('edit-preconfigured' => array(1)), 271 ); 272 273 $form['panels']['admin_description'] = array( 274 '#type' => 'textarea', 275 '#title' => t('Administrative description'), 276 '#description' => t('A description of what this style is, does or is for, for administrative use.'), 277 '#default_value' => $settings['admin_description'], 278 '#process' => array('ctools_dependent_process'), 279 '#dependency' => array('edit-preconfigured' => array(1)), 280 ); 281 282 // Add the checkbox, set the weight early 283 $form['panels']['preconfigured'] = array( 284 '#type' => 'checkbox', 285 '#title' => t('Make this style available to other regions or panes'), 286 '#default_value' => $settings['name'], 287 '#weight' => -1, 288 ); 289 290 } 291 292 /** 293 * Validate to see if we need to check the preconfigured values. 294 */ 295 function panels_stylizer_edit_pane_style_form_validate(&$form, &$form_state) { 296 if (!user_access('administer panels styles')) { 297 return; 298 } 299 300 // Only validate if preconfigured is checked. 301 if ($form_state['values']['preconfigured'] && !empty($form_state['clicked_button']['#wizard type'])) { 302 if (empty($form_state['values']['admin_title'])) { 303 form_error($form['panels']['admin_title'], t('You must choose an administrative title.')); 304 } 305 306 // If this is new, make sure the name is unique: 307 if ($form_state['op'] == 'add') { 308 if (empty($form_state['values']['name'])) { 309 form_error($form['panels']['name'], t('You must choose a machine name.')); 310 } 311 312 ctools_include('export'); 313 $test = ctools_export_crud_load('stylizer', $form_state['values']['name']); 314 if ($test) { 315 form_error($form['panels']['name'], t('That name is used by another style: @page', array('@page' => $test->admin_title))); 316 } 317 318 // Ensure name fits the rules: 319 if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) { 320 form_error($form['panels']['name'], t('Name must be alphanumeric or underscores only.')); 321 } 322 } 323 } 324 } 325 326 /** 327 * Store the preconfigured values. 328 */ 329 function panels_stylizer_edit_pane_style_form_submit(&$form, &$form_state) { 330 if (!user_access('administer panels styles')) { 331 return; 332 } 333 334 // Only validate if preconfigured is checked. 335 if ($form_state['values']['preconfigured'] && !empty($form_state['clicked_button']['#wizard type'])) { 336 $form_state['owner info']['owner settings']['admin_title'] = $form_state['values']['admin_title']; 337 $form_state['owner info']['owner settings']['admin_description'] = $form_state['values']['admin_description']; 338 339 // Clean up preview files before we set the name 340 ctools_stylizer_cleanup_style($form_state['plugin'], $form_state['settings']); 341 342 $form_state['settings']['name'] = $form_state['values']['name']; 343 $form_state['name'] = $form_state['values']['name']; 344 $form_state['owner info']['owner settings']['preconfigured'] = $form_state['values']['preconfigured']; 345 } 346 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |