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