00001 <?php
00002
00003
00004
00005
00006
00007
00008 function panels_flexible_panels_layouts() {
00009 $items['flexible'] = array(
00010 'title' => t('Flexible'),
00011 'icon' => 'layouts/flexible.png',
00012 'theme' => 'panels_flexible',
00013 'css' => 'layouts/flexible.css',
00014 'settings form' => 'panels_flexible_settings_form',
00015 'settings submit' => 'panels_flexible_settings_submit',
00016 'panels function' => 'panels_flexible_panels',
00017 );
00018
00019 return $items;
00020 }
00021
00022 function panels_flexible_default_panels() {
00023 return array(
00024 'percent_width' => 100,
00025 'rows' => 3,
00026 'width_type' => '%',
00027 'row_1' => array(
00028 'columns' => 1,
00029 'width_1' => 100,
00030 'names' => array(t('Top')),
00031 ),
00032 'row_2' => array(
00033 'columns' => 3,
00034 'width_1' => 25,
00035 'width_2' => 50,
00036 'width_3' => 25,
00037 'names' => array(t('Left'), t('Middle'), t('Right')),
00038 ),
00039
00040 'row_3' => array(
00041 'columns' => 1,
00042 'width_1' => 100,
00043 'names' => array(t('Bottom')),
00044 ),
00045 'sidebars' => array(
00046 'left' => FALSE,
00047 'left_width' => 200,
00048 'right' => FALSE,
00049 'right_width' => 200,
00050 'width_type' => 'px',
00051 ),
00052 );
00053 }
00054
00055 function panels_flexible_settings_form($display, $layout, $settings) {
00056 if (empty($settings)) {
00057
00058 $settings = panels_flexible_default_panels();
00059 }
00060
00061
00062 if (empty($settings['width_type'])) {
00063 $settings['width_type'] = '%';
00064 $settings['percent_width'] = 100;
00065 $settings['sidebars']['left'] = FALSE;
00066 $settings['sidebars']['left_width'] = 200;
00067 $settings['sidebars']['right'] = FALSE;
00068 $settings['sidebars']['right_width'] = 200;
00069 $settings['sidebars']['width_type'] = 'px';
00070 }
00071
00072 $form['instructions'] = array(
00073 '#value' => t('<p>Here you may determine the number of rows and columns your layout may have. Each row can have its own number of columns, and each column can have its width set independently. When changing the number of rows or columns, click Save to update the form so you can set the widths for new cells properly.</p><p><strong>Note: Removing cells which contain panes will cause those panes to be disappear. Please move any content you wish to keep.</strong></p>'),
00074 );
00075
00076 $form['width_type'] = array(
00077 '#type' => 'select',
00078 '#title' => t('Width unit type'),
00079 '#options' => array('%' => t('% (percentage)'), 'px' => t('px (pixels)'), 'em' => t('em (current)')),
00080 '#description' => t('The width unit type this layout can have: %, px or em. When using percentage, your layout will be fluid; when using px or em, your layout will be fixed.'),
00081 '#default_value' => $settings['width_type'],
00082 );
00083
00084 $form['percent_width'] = array(
00085 '#type' => 'textfield',
00086 '#size' => 2,
00087 '#width' => 10,
00088 '#title' => t('Total width'),
00089 '#description' => t('If using the percentage width, choose the total width that this layout must add up to; if you are having problems with your flexible layout having columns fall off, try lowering this number and adjusting the width of individual columns to match.'),
00090 '#default_value' => $settings['percent_width'],
00091 );
00092
00093 $form['rows'] = array(
00094 '#type' => 'textfield',
00095 '#size' => 2,
00096 '#width' => 10,
00097 '#title' => t('Rows'),
00098 '#description' => t('The number of rows this layout can have.'),
00099 '#default_value' => $settings['rows'],
00100 );
00101
00102 for ($row = 1; $row <= intval($settings['rows']); $row++) {
00103 $form["row_$row"] = array(
00104 '#type' => 'fieldset',
00105 '#title' => t('Row @d', array('@d' => $row)),
00106 );
00107 $form["row_$row"]["columns"] = array(
00108 '#prefix' => '<div style="float: left; padding-right: 2em">',
00109 '#suffix' => '</div>',
00110 '#type' => 'textfield',
00111 '#size' => 2,
00112 '#width' => 10,
00113 '#title' => t('Columns'),
00114
00115 '#default_value' => $settings["row_$row"]["columns"],
00116 );
00117 for ($col = 1; $col <= intval($settings["row_$row"]["columns"]); $col++) {
00118 $form["row_$row"]["width_$row_$col"] = array(
00119 '#prefix' => '<div style="float: left; padding-right: 2em">',
00120 '#suffix' => '</div>',
00121 '#type' => 'textfield',
00122 '#size' => 2,
00123 '#width' => 10,
00124 '#title' => t('Width @d', array('@d' => $col)),
00125 '#default_value' => $settings["row_$row"]["width_$col"],
00126 );
00127 }
00128 if (is_array($settings["row_$row"]["names"])) {
00129 $names = implode(', ', $settings["row_$row"]["names"]);
00130 }
00131 else {
00132 $names = '';
00133 }
00134 $form["row_$row"]['names'] = array(
00135 '#prefix' => '<div style="float: left;">',
00136 '#suffix' => '</div>',
00137 '#type' => 'textfield',
00138 '#title' => t('Column titles, separated by commas'),
00139 '#default_value' => $names,
00140 );
00141 }
00142
00143 $form['sidebars'] = array(
00144 '#type' => 'fieldset',
00145 '#title' => t('Sidebars'),
00146 );
00147
00148 $form['sidebars']['left_aligner_start'] = array(
00149 '#value' => '<div class="option-text-aligner">',
00150 '#tree' => TRUE,
00151 );
00152 $form['sidebars']['left'] = array(
00153 '#type' => 'checkbox',
00154 '#id' => 'sidebar-left-checkbox',
00155 '#title' => t('Sidebar left'),
00156 '#default_value' => $settings['sidebars']['left'],
00157 );
00158 $form['sidebars']['left_width'] = array(
00159 '#type' => 'textfield',
00160 '#id' => 'sidebar-left-width',
00161 '#size' => 2,
00162 '#width' => 10,
00163 '#default_value' => $settings['sidebars']['left_width'],
00164 );
00165 $form['sidebars']['right'] = array(
00166 '#type' => 'checkbox',
00167 '#id' => 'sidebar-right-checkbox',
00168 '#title' => t('Sidebar right'),
00169 '#default_value' => $settings['sidebars']['right'],
00170 );
00171
00172 $form['sidebars']['right_width'] = array(
00173 '#type' => 'textfield',
00174 '#id' => 'sidebar-right-width',
00175 '#size' => 2,
00176 '#width' => 10,
00177 '#default_value' => $settings['sidebars']['right_width'],
00178 );
00179 $form['sidebars']['left_aligner_stop'] = array(
00180 '#value' => '</div><div style="clear: both; padding: 0; margin: 0"></div>',
00181 );
00182 $form['sidebars']['left_title_markup'] = array(
00183 '#prefix' => '<div class="description">',
00184 '#suffix' => '</div>',
00185 '#value' => t('If a sidebar is selected, enter the width of the sidebar.'),
00186 );
00187
00188 $form['sidebars']['width_type'] = array(
00189 '#type' => 'select',
00190 '#title' => t('Width unit type'),
00191 '#options' => array('%' => t('% (percentage)'), 'px' => t('px (pixels)'), 'em' => t('em (current)')),
00192 '#description' => t('The width unit type activated sidebars will have: %, px or em. When using percentage, your sidebars will be fluid; when using px or em, your sidebars will be fixed.'),
00193 '#default_value' => $settings['sidebars']['width_type'],
00194 );
00195
00196 $js_settings = array('panels' => array('checkboxes' => array(
00197 '#sidebar-left-checkbox' => array('#sidebar-left-width'),
00198 '#sidebar-right-checkbox' => array('#sidebar-right-width'),
00199 )));
00200 drupal_add_js(panels_get_path('js/checkboxes.js'));
00201 drupal_add_js($js_settings, 'setting');
00202 return $form;
00203 }
00204
00205 function panels_flexible_settings_validate($values, $form, $display, $layout, $settings) {
00206 if ($values['rows'] < 1) {
00207 form_error($form['rows'], t('Rows must be a positive integer.'));
00208 return;
00209 }
00210
00211
00212 if ($settings['width_type'] == '%') {
00213 for ($row = 1; $row <= intval($values['rows']); $row++) {
00214
00215 if ($settings['rows'] >= $row) {
00216 if ($values["row_$row"]['columns'] < 1) {
00217 form_error($form["row_$row"]['columns'], t('Columns must be a positive integer.'));
00218 return;
00219 }
00220 $total = 0;
00221 for ($col = 1; $col <= intval($values["row_$row"]["columns"]); $col++) {
00222 $total += $values["row_$row"]["width_$col"];
00223 }
00224 if ($total != $settings['percent_width']) {
00225 form_error($form["row_$row"]['columns'], t('Column widths must add up to 100.'));
00226 }
00227 }
00228 }
00229 }
00230 }
00231
00232 function panels_flexible_settings_submit(&$values, $display, $layout, $settings) {
00233 for ($row = 1; $row <= $values['rows']; $row++) {
00234 if ($row > $settings['rows'] && empty($values["row_$row"]['columns'])) {
00235 $values["row_$row"]['columns'] = 1;
00236 $values["row_$row"]['width_1'] = 100;
00237 }
00238 if (!empty($values["row_$row"]['names'])) {
00239 $names = explode(',', $values["row_$row"]['names']);
00240 foreach ($names as $nid => $name) {
00241 $names[$nid] = trim($name);
00242 }
00243 $values["row_$row"]['names'] = $names;
00244 }
00245 }
00246 }
00247
00248
00249
00250
00251 function panels_flexible_panels($display, $settings) {
00252 $panels = array();
00253 if (empty($settings)) {
00254 $settings = panels_flexible_default_panels();
00255 }
00256
00257 if (!empty($settings['sidebars']['left'])) {
00258 $panels['sidebar_left'] = t('Left sidebar');
00259 }
00260
00261 if (!empty($settings['sidebars']['right'])) {
00262 $panels['sidebar_right'] = t('Right sidebar');
00263 }
00264
00265 for ($row = 1; $row <= intval($settings['rows']); $row++) {
00266 for ($col = 1; $col <= intval($settings["row_$row"]['columns']); $col++) {
00267 if (!empty($settings["row_$row"]['names'][$col - 1])) {
00268 $panels["row_${row}_$col"] = $settings["row_$row"]['names'][$col - 1];
00269 }
00270 else {
00271 $panels["row_${row}_$col"] = t("Row @row, Column @col", array('@row' => $row, '@col' => $col));
00272 }
00273 }
00274 }
00275 return $panels;
00276 }
00277
00278 function theme_panels_flexible($id, $content, $settings) {
00279 if (empty($settings)) {
00280 $settings = panels_flexible_default_panels();
00281 }
00282
00283
00284 if (empty($settings['width_type'])) {
00285 $settings['width_type'] = '%';
00286 $settings['percent_width'] = 100;
00287 }
00288
00289 if ($id) {
00290 $idstr = " id='$id'";
00291 $idcss = "#$id";
00292 }
00293 else {
00294 $idcss = "div.panel-flexible";
00295 }
00296
00297 $css = '';
00298 $output = '';
00299
00300 for ($row = 1; $row <= intval($settings['rows']); $row++) {
00301 $output .= "<div class=\"panel-row panel-row-$row clear-block\">\n";
00302 for ($col = 1; $col <= intval($settings["row_$row"]["columns"]); $col++) {
00303
00304
00305 $reduce = 0;
00306 if ($settings['width_type'] == '%' && $settings['percent_width'] == 100) {
00307 $reduce = 1 / $settings["row_$row"]["columns"];
00308 }
00309 if ($col == 1) {
00310 if (intval($settings["row_$row"]["columns"]) == 1) {
00311 $class = 'panel-col-only';
00312 }
00313 else {
00314 $class = 'panel-col-first';
00315 }
00316 }
00317 elseif ($col == intval($settings["row_$row"]["columns"])) {
00318 $class = 'panel-col-last';
00319 }
00320 else {
00321 $class = 'panel-col-inside';
00322 }
00323 $output .= "<div class=\"panel-col panel-col-$col $class\">\n";
00324 $output .= "<div class=\"inside\">" . $content["row_${row}_$col"] . "</div>\n";
00325 $output .= "</div>\n";
00326 $css .= "$idcss div.panel-row-$row div.panel-col-$col { width: " . ((intval($settings["row_$row"]["width_$col"])) - $reduce) . $settings["width_type"] ."; }\n";
00327 }
00328 $output .= "</div>\n";
00329 }
00330
00331
00332 if (!empty($settings['sidebars']['left']) || !empty($settings['sidebars']['right'])) {
00333
00334 $output = "<div class=\"panel-sidebar-middle panel-sidebar\">\n$output</div>\n";
00335 if ($settings['sidebars']['width_type'] == '%') {
00336 $css .= "$idcss div.panel-flexible-sidebars div.panel-sidebar-middle { width: " . (intval($settings['percent_width']) - intval($settings['sidebars']['left_width']) - intval($settings['sidebars']['right_width'])) . "; }\n";
00337 }
00338 }
00339
00340 if (!empty($settings['sidebars']['left'])) {
00341 $size = intval($settings['sidebars']['left_width']) . $settings['sidebars']['width_type'];
00342 $output = "<div class=\"panel-sidebar panel-sidebar-left panel-col panel-col-first\"><div class=\"inside\">\n" . $content["sidebar_left"] . "</div>\n</div>\n" . $output;
00343 $css .= "$idcss div.panel-flexible-sidebars div.panel-sidebar-left { width: $size; margin-left: -$size; }\n";
00344 $css .= "$idcss div.panel-flexible-sidebars { padding-left: $size; }\n";
00345
00346 $css .= "* html $idcss div.panel-flexible-sidebars div.panel-sidebar-left { left: $size; }\n";
00347 }
00348
00349 if (!empty($settings['sidebars']['right'])) {
00350 $size = intval($settings['sidebars']['right_width']) . $settings['sidebars']['width_type'];
00351 $output .= "<div class=\"panel-sidebar panel-sidebar-right panel-col panel-col-last\"><div class=\"inside\">\n" . $content["sidebar_right"] . "</div>\n</div>\n";
00352 $css .= "$idcss div.panel-flexible-sidebars div.panel-sidebar-right { width: $size; margin-right: -$size; }\n";
00353 $css .= "$idcss div.panel-flexible-sidebars { padding-right: $size; }\n";
00354 }
00355
00356
00357 $sidebar_class = (!empty($settings['sidebars']['left']) || !empty($settings['sidebars']['right'])) ? ' class="panel-flexible-sidebars"' : '';
00358 $output = "<div class=\"panel-flexible clear-block\" $idstr>\n<div". $sidebar_class .">\n" . $output . "</div>\n</div>\n";
00359 drupal_set_html_head("<style type=\"text/css\" media=\"all\">\n$css</style>\n");
00360 return $output;
00361 }
00362