| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: panels_renderer_ipe.class.php,v 1.1.2.21 2010/10/22 19:12:12 merlinofchaos Exp $ 3 4 /** 5 * Renderer class for all In-Place Editor (IPE) behavior. 6 */ 7 class panels_renderer_ipe extends panels_renderer_editor { 8 // The IPE operates in normal render mode, not admin mode. 9 var $admin = FALSE; 10 11 function render() { 12 $output = parent::render(); 13 return "<div id='panels-ipe-display-{$this->clean_key}' class='panels-ipe-display-container'>$output</div>"; 14 } 15 16 function add_meta() { 17 ctools_include('display-edit', 'panels'); 18 ctools_include('content'); 19 20 if (empty($this->display->cache_key)) { 21 $this->cache = panels_edit_cache_get_default($this->display); 22 } 23 // @todo we may need an else to load the cache, but I am not sure we 24 // actually need to load it if we already have our cache key, and doing 25 // so is a waste of resources. 26 27 ctools_include('cleanstring'); 28 $this->clean_key = ctools_cleanstring($this->display->cache_key); 29 panels_ipe_get_cache_key($this->clean_key); 30 31 ctools_include('ajax'); 32 ctools_include('modal'); 33 ctools_modal_add_js(); 34 35 ctools_add_css('panels_dnd', 'panels'); 36 ctools_add_css('panels_admin', 'panels'); 37 ctools_add_js('panels_ipe', 'panels_ipe'); 38 ctools_add_css('panels_ipe', 'panels_ipe'); 39 40 $settings = array( 41 'formPath' => url($this->get_url('save-form')), 42 ); 43 drupal_add_js(array('PanelsIPECacheKeys' => array($this->clean_key)), 'setting'); 44 drupal_add_js(array('PanelsIPESettings' => array($this->clean_key => $settings)), 'setting'); 45 46 jquery_ui_add(array('ui.draggable', 'ui.droppable', 'ui.sortable')); 47 parent::add_meta(); 48 } 49 50 /** 51 * Override & call the parent, then pass output through to the dnd wrapper 52 * theme function. 53 * 54 * @param $pane 55 */ 56 function render_pane(&$pane) { 57 $output = parent::render_pane($pane); 58 if (empty($output)) { 59 return; 60 } 61 62 if (empty($pane->IPE_empty)) { 63 // Add an inner layer wrapper to the pane content before placing it into 64 // draggable portlet 65 $output = "<div class=\"panels-ipe-portlet-content\">$output</div>"; 66 } 67 else { 68 $output = "<div class=\"panels-ipe-portlet-content panels-ipe-empty-pane\">$output</div>"; 69 } 70 // Hand it off to the plugin/theme for placing draggers/buttons 71 $output = theme('panels_ipe_pane_wrapper', $output, $pane, $this->display, $this); 72 return "<div id=\"panels-ipe-paneid-{$pane->pid}\" class=\"panels-ipe-portlet-wrapper panels-ipe-portlet-marker\">" . $output . "</div>"; 73 } 74 75 function render_pane_content(&$pane) { 76 $content = parent::render_pane_content($pane); 77 // Ensure that empty panes have some content. 78 if (empty($content->content)) { 79 // Get the administrative title. 80 $content_type = ctools_get_content_type($pane->type); 81 $title = ctools_content_admin_title($content_type, $pane->subtype, $pane->configuration, $this->display->context); 82 83 $content->content = t('Placeholder for empty "@title"', array('@title' => $title)); 84 $pane->IPE_empty = TRUE; 85 } 86 87 return $content; 88 } 89 90 /** 91 * Add an 'empty' pane placeholder above all the normal panes. 92 * 93 * @param $region_id 94 * @param $panes 95 */ 96 function render_region($region_id, $panes) { 97 // Generate this region's 'empty' placeholder pane from the IPE plugin. 98 $empty_ph = theme('panels_ipe_placeholder_pane', $region_id, $this->plugins['layout']['panels'][$region_id]); 99 100 // Wrap the placeholder in some guaranteed markup. 101 $panes['empty_placeholder'] = '<div class="panels-ipe-placeholder panels-ipe-on panels-ipe-portlet-marker panels-ipe-portlet-static">' . $empty_ph . "</div>"; 102 103 // Generate this region's add new pane button. FIXME waaaaay too hardcoded 104 $panes['add_button'] = theme('panels_ipe_add_pane_button', $region_id, $this->display, $this); 105 106 $output = parent::render_region($region_id, $panes); 107 $output = theme('panels_ipe_region_wrapper', $output, $region_id, $this->display); 108 $classes = 'panels-ipe-region'; 109 110 ctools_include('cleanstring'); 111 $region_id = ctools_cleanstring($region_id); 112 return "<div id='panels-ipe-regionid-$region_id' class='panels-ipe-region'>$output</div>"; 113 } 114 115 /** 116 * AJAX entry point to create the controller form for an IPE. 117 */ 118 function ajax_save_form($break = NULL) { 119 ctools_include('form'); 120 if (!empty($this->cache->locked)) { 121 if ($break != 'break') { 122 $account = user_load($this->cache->locked->uid); 123 $name = theme('username', $account); 124 $lock_age = format_interval(time() - $this->cache->locked->updated); 125 126 $message = t("This panel is being edited by user !user, and is therefore locked from editing by others. This lock is !age old.\n\nClick OK to break this lock and discard any changes made by !user.", array('!user' => $name, '!age' => $lock_age)); 127 128 $this->commands[] = array( 129 'command' => 'unlockIPE', 130 'message' => $message, 131 'break_path' => url($this->get_url('save-form', 'break')) 132 ); 133 return; 134 } 135 136 // Break the lock. 137 panels_edit_cache_break_lock($this->cache); 138 } 139 140 $form_state = array( 141 'display' => &$this->display, 142 'content_types' => $this->cache->content_types, 143 'rerender' => FALSE, 144 'no_redirect' => TRUE, 145 // Panels needs this to make sure that the layout gets callbacks 146 'layout' => $this->plugins['layout'], 147 ); 148 149 $output = ctools_build_form('panels_ipe_edit_control_form', $form_state); 150 if ($output) { 151 // At this point, we want to save the cache to ensure that we have a lock. 152 panels_edit_cache_set($this->cache); 153 $this->commands[] = array( 154 'command' => 'initIPE', 155 'key' => $this->clean_key, 156 'data' => $output, 157 ); 158 return; 159 } 160 161 // no output == submit 162 if (!empty($form_state['clicked_button']['#save-display'])) { 163 // Saved. Save the cache. 164 panels_edit_cache_save($this->cache); 165 } 166 else { 167 // Cancelled. Clear the cache. 168 panels_edit_cache_clear($this->cache); 169 } 170 171 $this->commands[] = array( 172 'command' => 'endIPE', 173 'key' => $this->clean_key, 174 'data' => $output, 175 ); 176 } 177 178 /** 179 * Create a command array to redraw a pane. 180 */ 181 function command_update_pane($pid) { 182 if (is_object($pid)) { 183 $pane = $pid; 184 } 185 else { 186 $pane = $this->display->content[$pid]; 187 } 188 189 $this->commands[] = ctools_ajax_command_replace("#panels-ipe-paneid-$pane->pid", $this->render_pane($pane)); 190 $this->commands[] = ctools_ajax_command_changed("#panels-ipe-display-{$this->clean_key}"); 191 } 192 193 /** 194 * Create a command array to add a new pane. 195 */ 196 function command_add_pane($pid) { 197 if (is_object($pid)) { 198 $pane = $pid; 199 } 200 else { 201 $pane = $this->display->content[$pid]; 202 } 203 204 ctools_include('cleanstring'); 205 $region_id = ctools_cleanstring($pane->panel); 206 $this->commands[] = ctools_ajax_command_append("#panels-ipe-regionid-$region_id div.panels-ipe-sort-container", $this->render_pane($pane)); 207 $this->commands[] = ctools_ajax_command_changed("#panels-ipe-display-{$this->clean_key}"); 208 } 209 } 210 211 /** 212 * FAPI callback to create the Save/Cancel form for the IPE. 213 */ 214 function panels_ipe_edit_control_form(&$form_state) { 215 $display = &$form_state['display']; 216 // @todo -- this should be unnecessary as we ensure cache_key is set in add_meta() 217 // $display->cache_key = isset($display->cache_key) ? $display->cache_key : $display->did; 218 219 // Annoyingly, theme doesn't have access to form_state so we have to do this. 220 $form['#display'] = $display; 221 222 $layout = panels_get_layout($display->layout); 223 $layout_panels = panels_get_regions($layout, $display); 224 225 $form['panel'] = array('#tree' => TRUE); 226 $form['panel']['pane'] = array('#tree' => TRUE); 227 228 foreach ($layout_panels as $panel_id => $title) { 229 // Make sure we at least have an empty array for all possible locations. 230 if (!isset($display->panels[$panel_id])) { 231 $display->panels[$panel_id] = array(); 232 } 233 234 $form['panel']['pane'][$panel_id] = array( 235 // Use 'hidden' instead of 'value' so the js can access it. 236 '#type' => 'hidden', 237 '#default_value' => implode(',', (array) $display->panels[$panel_id]), 238 ); 239 } 240 241 $form['buttons']['submit'] = array( 242 '#type' => 'submit', 243 '#value' => t('Save'), 244 '#id' => 'panels-ipe-save', 245 '#submit' => array('panels_edit_display_form_submit'), 246 '#save-display' => TRUE, 247 ); 248 $form['buttons']['cancel'] = array( 249 '#type' => 'submit', 250 '#value' => t('Cancel'), 251 '#id' => 'panels-ipe-cancel', 252 ); 253 return $form; 254 }
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 |