panels_export.module
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 function panels_export_menu($may_cache) {
00016 if ($may_cache) {
00017 $items = array();
00018 $items[] = array(
00019 'path' => 'admin/panels/export',
00020 'title' => t('Export panels'),
00021 'access' => user_access('use panels exporter'),
00022 'callback' => 'panels_export_export',
00023 'description' => t('Export panels in bulk.'),
00024 );
00025 $items[] = array(
00026 'path' => 'admin/panels/export/results',
00027 'access' => user_access('use panels exporter'),
00028 'callback' => 'panels_export_export',
00029 'type' => MENU_CALLBACK,
00030 );
00031 return $items;
00032 }
00033 }
00034
00035
00036
00037
00038 function panels_export_perm() {
00039 return array('use panels exporter');
00040 }
00041
00042
00043
00044
00045
00046
00047
00048 function panels_export_export() {
00049 $exportables = array();
00050 foreach (module_implements('panels_exportables') as $module) {
00051 $function = $module . '_panels_exportables';
00052 $exportables[$module] = $function('list');
00053 }
00054 if ($exportables) {
00055 $form_id = 'panels_export_export_form';
00056 $form = drupal_retrieve_form($form_id, $exportables);
00057 $output = drupal_process_form($form_id, $form);
00058 if (!$output) {
00059 $output = drupal_render_form($form_id, $form);
00060 }
00061 return $output;
00062 }
00063 else {
00064 return t('There are no panels to be exported at this time.');
00065 }
00066 }
00067
00068
00069
00070
00071 function panels_export_export_form($exportables) {
00072 foreach ($exportables as $module => $panels) {
00073 $form['modules']['#tree'] = TRUE;
00074 $form['modules'][$module] = array(
00075 '#type' => 'checkboxes',
00076 '#options' => $panels,
00077 '#default_value' => array(),
00078 );
00079 }
00080
00081 $form['name'] = array(
00082 '#type' => 'textfield',
00083 '#title' => t('Module name'),
00084 '#description' => t('Enter the module name to export code to.'),
00085 );
00086
00087 $form['submit'] = array(
00088 '#type' => 'submit',
00089 '#value' => t('Export'),
00090 );
00091
00092 $form['#action'] = url('admin/panels/export/results');
00093 $form['#redirect'] = FALSE;
00094 $form['#exportables'] = $exportables;
00095 return $form;
00096 }
00097
00098 function theme_panels_export_export_form($form) {
00099 $files = module_rebuild_cache();
00100 $exportables = $form['#exportables'];
00101 $output = '';
00102
00103 foreach ($exportables as $module => $panels) {
00104 $header = array(theme('table_select_header_cell'), $files[$module]->info['name']);
00105 $rows = array();
00106 foreach ($panels as $name => $panel) {
00107 $title = $form['modules'][$module][$name]['#title'];
00108 unset($form['modules'][$module][$name]['#title']);
00109 $rows[] = array(drupal_render($form['modules'][$module][$name]), $title);
00110 }
00111 $output .= '<div class="export-container">';
00112 $output .= theme('table', $header, $rows);
00113 $output .= "</div>\n";
00114 }
00115 drupal_add_css(panels_get_path('panels_export/panels_export.css'));
00116 $output .= drupal_render($form);
00117 return $output;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 function panels_export_export_form_submit($form_id, $form_values) {
00127 $code = '';
00128 if (empty($form_values['name'])) {
00129 $form_values['name'] = 'foo';
00130 }
00131
00132 foreach ($form_values['modules'] as $module => $panels) {
00133 $panels = array_filter($panels);
00134 if ($panels) {
00135 $code .= module_invoke($module, 'panels_exportables', 'export', $panels, $form_values['name']) . "\n\n";
00136 }
00137 }
00138
00139 $lines = substr_count($code, "\n");
00140 $element = array(
00141 '#type' => 'textarea',
00142 '#id' => 'export-textarea',
00143 '#name' => 'export-textarea',
00144 '#attributes' => array(),
00145 '#rows' => min($lines, 150),
00146 '#value' => $code,
00147 '#parents' => array(),
00148 );
00149
00150 return theme('textarea', $element);
00151 }
00152