Projet

Général

Profil

Révision 64156087

Ajouté par Assos Assos il y a plus de 7 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/panels/plugins/layouts/flexible/flexible.inc
1 1
<?php
2 2

  
3 3
/**
4
 * Implementation of hook_panels_layouts()
4
 * @file
5
 * Flexible layout plugin.
5 6
 */
6
// Plugin definition
7

  
8
/**
9
 * Implementation of hook_panels_layouts().
10
 */
11
// Plugin definition.
7 12
$plugin = array(
8 13
  'title' => t('Flexible'),
9 14
  'category' => t('Builders'),
......
18 23
  'regions function' => 'panels_flexible_panels',
19 24
  'hook menu' => 'panels_flexible_menu',
20 25

  
21
  // Reuisable layout Builder specific directives
26
  // Reusable layout Builder specific directives.
22 27
  'builder' => TRUE,
23
  'builder tab title' => 'Add flexible layout', // menu so translated elsewhere
24

  
28
  'builder tab title' => 'Add flexible layout',
25 29
  'get child' => 'panels_flexible_get_sublayout',
26 30
  'get children' => 'panels_flexible_get_sublayouts',
27 31

  
28
  // Define ajax callbacks
32
  // Define ajax callbacks.
29 33
  'ajax' => array(
30 34
    'settings' => 'panels_ajax_flexible_edit_settings',
31 35
    'add' => 'panels_ajax_flexible_edit_add',
......
79 83
}
80 84

  
81 85
/**
86
 * Flexible panel settings converter.
87
 *
82 88
 * Convert settings from old style to new, or provide defaults for
83 89
 * empty settings.
84
 * @param <type> $settings
90
 *
91
 * @param array $settings
92
 *   Drupal settings for the layout.
93
 *
94
 * @return null
95
 *   Nothing to return.
85 96
 */
86 97
function panels_flexible_convert_settings(&$settings, &$layout) {
87 98
  // This indicates that this is a layout that they used the checkbox
......
99 110
  }
100 111

  
101 112
  if (empty($settings)) {
102
    // set up a default
113
    // Set up a default.
103 114
    $settings = array(
104 115
      'items' => array(
105 116
        // The 'canvas' is a special row that does not get rendered
......
133 144
      ),
134 145
    );
135 146
  }
136
  else if (!isset($settings['items'])) {
147
  elseif (!isset($settings['items'])) {
137 148
    // Convert an old style flexible to a new style flexible.
138 149
    $old = $settings;
139 150
    $settings = array();
......
143 154
      'children' => array(),
144 155
      'parent' => NULL,
145 156
    );
146
    // add the left sidebar column, row and region if it exists.
157
    // Add the left sidebar column, row and region if it exists.
147 158
    if (!empty($old['sidebars']['left'])) {
148 159
      $settings['items']['canvas']['children'][] = 'sidebar-left';
149 160
      $settings['items']['sidebar-left'] = array(
......
205 216

  
206 217
    // Add rows and regions.
207 218
    for ($row = 1; $row <= intval($old['rows']); $row++) {
208
      // Create entry for the row
219
      // Create entry for the row:
209 220
      $settings['items']["row_$row"] = array(
210 221
        'type' => 'row',
211 222
        'contains' => 'region',
212 223
        'children' => array(),
213 224
        'parent' => 'main',
214 225
      );
215
      // Add the row to the parent's children
226
      // Add the row to the parent's children:
216 227
      $settings['items']['main']['children'][] = "row_$row";
217 228

  
218 229
      for ($col = 1; $col <= intval($old["row_$row"]['columns']); $col++) {
219
        // Create entry for the region
230
        // Create entry for the region:
220 231
        $settings['items']["row_${row}_$col"] = array(
221 232
          'type' => 'region',
222 233
          'width' => $old["row_$row"]["width_$col"],
223 234
          'width_type' => '%',
224 235
          'parent' => "row_$row",
225 236
        );
226
        // Add entry for the region to the row's children
237
        // Add entry for the region to the row's children:
227 238
        $settings['items']["row_$row"]['children'][] = "row_${row}_$col";
228 239

  
229
        // Apply the proper title to the region
240
        // Apply the proper title to the region:
230 241
        if (!empty($old["row_$row"]['names'][$col - 1])) {
231 242
          $settings['items']["row_${row}_$col"]['title'] = $old["row_$row"]['names'][$col - 1];
232 243
        }
......
236 247
      }
237 248
    }
238 249
  }
239
  else if (isset($settings['canvas'])) {
250
  elseif (isset($settings['canvas'])) {
240 251
    // Convert the old 'canvas' to the new canvas row.
241 252
    $settings['items']['canvas'] = array(
242 253
      'type' => 'row',
......
259 270
    if (!isset($item['type'])) {
260 271
      unset($items[$id]);
261 272
    }
262
    else if ($item['type'] == 'region') {
273
    elseif ($item['type'] == 'region') {
263 274
      $items[$id] = $item['title'];
264 275
    }
265 276
  }
......
276 287
 * @todo Convert the functions to methods and make this properly OO.
277 288
 */
278 289
function panels_flexible_create_renderer($admin, $css_id, $content, $settings, &$display, $layout, $handler) {
279
  $renderer = new stdClass;
290
  $renderer = new stdClass();
280 291
  $renderer->settings = $settings;
281 292
  $renderer->content = $content;
282 293
  $renderer->css_id = $css_id;
283 294
  $renderer->did = &$display->did;
284 295
  if ($admin) {
285
    // always scale in admin mode.
296
    // Always scale in admin mode.
286 297
    $renderer->scale_base = 99.0;
287 298
  }
288 299
  else {
......
325 336
  $renderer->row_separation = !empty($settings['items']['canvas']['row_separation']) ? $settings['items']['canvas']['row_separation'] : '0.5em';
326 337

  
327 338
  // Make some appended classes so it's easier to reference them.
328

  
329 339
  $renderer->base['column'] = $renderer->item_class['column'] . '-' . $renderer->base_class;
330 340
  $renderer->base['row']    = $renderer->item_class['row'] . '-' . $renderer->base_class;
331 341
  $renderer->base['region'] = $renderer->item_class['region'] . '-' . $renderer->base_class;
......
386 396
  }
387 397

  
388 398
  // Also store the CSS on the display in case the live preview or something
389
  // needs it
399
  // needs it.
390 400
  $display->add_css = $css;
391 401

  
392 402
  $output = "<div class=\"panel-flexible " . $renderer->base['canvas'] . " clearfix\" $renderer->id_str>\n";
......
394 404

  
395 405
  $output .= panels_flexible_render_items($renderer, $settings['items']['canvas']['children'], $renderer->base['canvas']);
396 406

  
397
  // Wrap the whole thing up nice and snug
407
  // Wrap the whole thing up nice and snug.
398 408
  $output .= "</div>\n</div>\n";
399 409

  
400 410
  return $output;
......
443 453
  $content = panels_flexible_render_items($renderer, $settings['items']['canvas']['children'], $renderer->base['row'] . '-canvas');
444 454
  $output .= panels_flexible_render_item($renderer, $settings['items']['canvas'], $content, 'canvas', 0, 0, TRUE);
445 455

  
446
  // Wrap the whole thing up nice and snug
456
  // Wrap the whole thing up nice and snug.
447 457
  $output .= "</div>\n</div>\n";
448 458

  
449 459
  drupal_add_js($layout['path'] . '/flexible-admin.js');
......
464 474
    $item = $renderer->settings['items'][$id];
465 475
    $location = isset($renderer->positions[$id]) ? $renderer->positions[$id] : 'middle';
466 476

  
467
    if ($renderer->admin && $item['type'] != 'row' && $prev ) {
477
    if ($renderer->admin && $item['type'] != 'row' && $prev) {
468 478
      $groups[$location] .= panels_flexible_render_splitter($renderer, $prev, $id);
469 479
    }
470 480

  
......
475 485
          $groups[$location] .= panels_flexible_render_item($renderer, $item, $content, $id, $position, $max);
476 486
        }
477 487
        break;
488

  
478 489
      case 'row':
479 490
        $content = panels_flexible_render_items($renderer, $item['children'], $renderer->base['row'] . '-' . $id);
480 491
        if (empty($renderer->settings['items'][$id]['hide_empty']) || trim($content)) {
481 492
          $groups[$location] .= panels_flexible_render_item($renderer, $item, $content, $id, $position, $max, TRUE);
482 493
        }
483 494
        break;
495

  
484 496
      case 'region':
485 497
        if (empty($renderer->settings['items'][$id]['hide_empty'])) {
486 498
          $content = isset($renderer->content[$id]) ? $renderer->content[$id] : "&nbsp;";
......
611 623
  $output = '<div tabindex="0"
612 624
    class="panels-flexible-splitter flexible-splitter-for-' . $left_class . '">';
613 625

  
614
  // Name the left object
626
  // Name the left object:
615 627
  $output .= '<span class="panels-flexible-splitter-left">';
616 628
  $output .= '.' . $left_class;
617 629
  $output .= '</span>';
......
632 644
  $output .= $left['width_type'];
633 645
  $output .= '</span>';
634 646

  
635
  // Name the right object
647
  // Name the right object:
636 648
  $output .= '<span class="panels-flexible-splitter-right">';
637 649
  $output .= '.' . $right_class;
638 650
  $output .= '</span>';
......
677 689
      $add2 = t('Add row to bottom');
678 690
    }
679 691
  }
680
  else if ($item['type'] == 'row') {
692
  elseif ($item['type'] == 'row') {
681 693
    if ($id == 'canvas') {
682 694
      $title = t('Canvas');
683 695
      $settings = t('Canvas settings');
......
697 709
      $add2 = $item['contains'] == 'region' ? t('Add region to right') : t('Add column to right');
698 710
    }
699 711
  }
700
  else if ($item['type'] == 'region') {
712
  elseif ($item['type'] == 'region') {
701 713
    $title = t('Region');
702 714
    $settings = t('Region settings');
703 715
    $remove = t('Remove region');
......
757 769
function panels_flexible_render_css_group($renderer, $list, $owner_id, $type, $id) {
758 770
  $css = array();
759 771

  
760
  // Start off with some generic CSS to properly pad regions
772
  // Start off with some generic CSS to properly pad regions.
761 773
  $css[$owner_id . ' .' . $renderer->item_class['region']] = array(
762 774
    'padding' => '0',
763 775
  );
......
792 804
    'padding-right' => '0',
793 805
  );
794 806

  
795
  // And properly pad rows too
807
  // And properly pad rows too:
796 808
  $css[$owner_id . ' .' . $renderer->item_class['row']] = array(
797 809
    'padding' => '0 0 ' . $renderer->row_separation . ' 0',
798 810
    'margin' => '0',
......
818 830
  if ($type != 'row') {
819 831
    // Go through our items and break up into right/center/right groups so we
820 832
    // can figure out our offsets.
821

  
822 833
    // right == any items on the right that are 'fixed'.
823 834
    // middle == all fluid items.
824 835
    // right == any items on the right that are 'fixed'.
......
827 838
    $current = 'left';
828 839
    foreach ($list as $id) {
829 840
      if ($renderer->settings['items'][$id]['width_type'] == 'px') {
830
        // fixed
841
        // Fixed:
831 842
        if ($current == 'left') {
832 843
          $left[] = $id;
833 844
          $renderer->positions[$id] = 'left';
......
841 852
        }
842 853
      }
843 854
      else {
844
        // fluid
855
        // Fluid:
845 856
        if ($current != 'right') {
846 857
          $current = 'middle';
847 858
          $middle[] = $id;
848 859
          $renderer->positions[$id] = 'middle';
849 860
          $middle_total += $renderer->settings['items'][$id]['width'];
850 861
        }
851
        // fall through: if current is 'right' and we ran into a 'fluid' then
862
        // Fall through: if current is 'right' and we ran into a 'fluid' then
852 863
        // it gets *dropped* because that is invalid.
853 864
      }
854 865
    }
......
903 914
      $css["$owner_id-inside"]['padding-left'] = '0px';
904 915
      if ($renderer->admin || count($middle)) {
905 916
        $css["$owner_id-middle"]['margin-left'] = $left_total . 'px';
906
        // IE hack
917
        // IE hack!
907 918
        $css["* html $owner_id-left"]['left'] = $left_total . "px";
908 919
        // Make this one very specific to the admin CSS so that preview
909 920
        // does not stomp it.
......
912 923
      else {
913 924
        $css["$owner_id-inside"]['margin-left'] = '-' . $left_total . 'px';
914 925
        $css["$owner_id-inside"]['padding-left'] = $left_total . 'px';
915
        // IE hack
926
        // IE hack!
916 927
        $css["* html $owner_id-inside"]['left'] = $left_total . "px";
917 928
      }
918 929
    }
......
958 969
/**
959 970
 * AJAX responder to edit flexible settings for an item.
960 971
 *
961
 * $handler object
972
 * @param object $handler
962 973
 *   The display renderer handler object.
974
 * @param mixed $id
975
 *   Id for the panel.
963 976
 */
964 977
function panels_ajax_flexible_edit_settings($handler, $id) {
965 978
  $settings = &$handler->display->layout_settings;
......
976 989
    $siblings = $settings['items'][$item['parent']]['children'];
977 990
  }
978 991

  
979

  
980 992
  switch ($item['type']) {
981 993
    case 'column':
982 994
      $title = t('Configure column');
983 995
      break;
996

  
984 997
    case 'row':
985 998
      if ($id == 'canvas') {
986 999
        $title = t('Configure canvas');
......
989 1002
        $title = t('Configure row');
990 1003
      }
991 1004
      break;
1005

  
992 1006
    case 'region':
993 1007
      $title = t('Configure region');
994 1008
      break;
......
1026 1040
    $output[] = ajax_command_replace('.flexible-links-' . $id,
1027 1041
      panels_flexible_render_item_links($renderer, $id, $item));
1028 1042

  
1029
    // If editing the canvas, reset the CSS width
1043
    // If editing the canvas, reset the CSS width.
1030 1044
    if ($id == 'canvas') {
1031
      // update canvas CSS.
1045
      // Update canvas CSS.
1032 1046
      $css = array(
1033 1047
        '.' . $renderer->item_class['column'] . '-inside' => array(
1034 1048
          'padding-left' => $renderer->column_separation,
......
1061 1075

  
1062 1076
/**
1063 1077
 * Configure a row, column or region on the flexible page.
1064
 *
1065
 * @param <type> $form_state
1066
 * @return <type>
1067 1078
 */
1068 1079
function panels_flexible_config_item_form($form, &$form_state) {
1069 1080
  $display = &$form_state['display'];
......
1162 1173
        if ($sibling == $id) {
1163 1174
          $current = 'right';
1164 1175
        }
1165
        else if ($settings['items'][$sibling]['width_type'] == '%') {
1166
          $$current = TRUE; // Indirection.
1176
        elseif ($settings['items'][$sibling]['width_type'] == '%') {
1177
          // Indirection.
1178
          $$current = TRUE;
1167 1179
        }
1168 1180
      }
1169 1181

  
......
1234 1246
    $item['region_separation'] = $form_state['values']['region_separation'];
1235 1247
    $item['row_separation'] = $form_state['values']['row_separation'];
1236 1248
  }
1237
  else if ($item['type'] != 'row') {
1249
  elseif ($item['type'] != 'row') {
1238 1250
    $item['width_type'] = $form_state['values']['width_type'];
1239 1251
  }
1240 1252
  else {
......
1270 1282
        'parent' => $id,
1271 1283
      );
1272 1284
      break;
1285

  
1273 1286
    case 'row':
1274 1287
      switch ($parent['contains']) {
1275 1288
        case 'region':
......
1282 1295
            'parent' => $id,
1283 1296
          );
1284 1297
          break;
1298

  
1285 1299
        case 'column':
1286 1300
          $title = $location == 'left' ? t('Add column to left') : t('Add column to right');
1287 1301
          $item = array(
......
1295 1309
      }
1296 1310
      // Create the new item with defaults.
1297 1311
      break;
1312

  
1298 1313
    case 'region':
1299 1314
      // Cannot add items to regions.
1300 1315
      break;
......
1344 1359

  
1345 1360
    }
1346 1361

  
1347
    // render the item
1348
    $parent_class =  $renderer->base[$parent['type']] . '-' . $id;
1362
    // Render the item.
1363
    $parent_class = $renderer->base[$parent['type']] . '-' . $id;
1349 1364
    $item_output = panels_flexible_render_item($renderer, $item, $content, $form_state['key'], 0, 0, $item['type'] == 'row');
1350 1365

  
1351 1366
    // Get all the CSS necessary for the entire row (as width adjustments may
......
1364 1379
          $item_output .= panels_flexible_render_splitter($renderer, $form_state['key'], $form_state['sibling']);
1365 1380
          $output[] = ajax_command_prepend('#panels-dnd-main .' . $parent_class . '-left', $item_output);
1366 1381
        }
1367
        else if ($location == 'right') {
1382
        elseif ($location == 'right') {
1368 1383
          // If we are adding to the right side of the left box, there is
1369 1384
          // a splitter that we have to remove; then we add our box normally,
1370 1385
          // and then add a new splitter for just our guy.
1371 1386
          $output[] = ajax_command_remove('panels-flexible-splitter-for-' . $renderer->base[$item['type']] . '-' . $form_state['key']);
1372
          $item_output = panels_flexible_render_splitter($renderer, $form_state['sibling'], $form_state['key']) .  $item_output;
1387
          $item_output = panels_flexible_render_splitter($renderer, $form_state['sibling'], $form_state['key']) . $item_output;
1373 1388
          $item_output .= panels_flexible_render_splitter($renderer, $form_state['key'], NULL);
1374 1389
          $output[] = ajax_command_append('#panels-dnd-main .' . $parent_class . '-left', $item_output);
1375 1390
        }
1376 1391
        break;
1392

  
1377 1393
      case 'right':
1378 1394
        if (!empty($form_state['sibling'])) {
1379
          $item_output = panels_flexible_render_splitter($renderer, $form_state['sibling'], $form_state['key']) .  $item_output;
1395
          $item_output = panels_flexible_render_splitter($renderer, $form_state['sibling'], $form_state['key']) . $item_output;
1380 1396
        }
1381 1397
        $output[] = ajax_command_append('#panels-dnd-main .' . $parent_class . '-right', $item_output);
1382 1398
        break;
1399

  
1383 1400
      case 'middle':
1384 1401
        if ($location == 'left') {
1385 1402
          if (!empty($form_state['sibling'])) {
......
1389 1406
        }
1390 1407
        else {
1391 1408
          if (!empty($form_state['sibling'])) {
1392
            $item_output = panels_flexible_render_splitter($renderer, $form_state['sibling'], $form_state['key']) .  $item_output;
1409
            $item_output = panels_flexible_render_splitter($renderer, $form_state['sibling'], $form_state['key']) . $item_output;
1393 1410
          }
1394 1411
          $output[] = ajax_command_append('#panels-dnd-main .' . $parent_class . '-middle', $item_output);
1395 1412
        }
......
1429 1446
}
1430 1447
/**
1431 1448
 * Form to add a row, column or region to a flexible layout.
1432
 * @param <type> $form_state
1433
 * @return <type>
1434 1449
 */
1435 1450
function panels_flexible_add_item_form($form, &$form_state) {
1436 1451
  $display = &$form_state['display'];
......
1543 1558
  $item['hide_empty'] = $form_state['values']['hide_empty'];
1544 1559

  
1545 1560
  if ($item['type'] == 'region') {
1546
    // derive the region key from the title
1561
    // Derive the region key from the title.
1547 1562
    $key = preg_replace("/[^a-z0-9]/", '_', drupal_strtolower($item['title']));
1548 1563
    while (isset($settings['items'][$key])) {
1549 1564
      $key .= '_';
......
1569 1584
    // If there is no sibling, or the sibling is of a different type,
1570 1585
    // the default 100 will work for either fixed or fluid.
1571 1586
    if ($form_state['sibling'] && $settings['items'][$form_state['sibling']]['width_type'] == $item['width_type']) {
1572
      // steal half of the sibling's space.
1587
      // Steal half of the sibling's space.
1573 1588
      $width = $settings['items'][$form_state['sibling']]['width'] / 2;
1574 1589
      $settings['items'][$form_state['sibling']]['width'] = $width;
1575 1590
      $item['width'] = $width;
......
1587 1602
}
1588 1603

  
1589 1604
/**
1590
 * AJAX responder to remove an existing row, column or region from a flexible
1591
 * layout.
1605
 * Panels remove AJAX responder.
1606
 *
1607
 * Removes an existing row, column or region from a flexible layout.
1592 1608
 */
1593 1609
function panels_ajax_flexible_edit_remove($handler, $id) {
1594 1610
  $settings = &$handler->display->layout_settings;
......
1602 1618
  $css_id = isset($handler->display->css_id) ? $handler->display->css_id : '';
1603 1619
  // Create a renderer object so we can render our new stuff.
1604 1620
  $renderer = panels_flexible_create_renderer(TRUE, $css_id, array(), $settings, $handler->display, $handler->plugins['layout'], $handler);
1605

  
1606

  
1607 1621
  $siblings = &$settings['items'][$item['parent']]['children'];
1608
  $parent_class = '.'  . $renderer->base[$settings['items'][$item['parent']]['type']] . '-' . $item['parent'];
1622
  $parent_class = '.' . $renderer->base[$settings['items'][$item['parent']]['type']] . '-' . $item['parent'];
1609 1623

  
1610 1624
  // Find the offset of our array. This will also be the key because
1611 1625
  // this is a simple array.
......
1627 1641
        $settings['items'][$next]['width'] += $item['width'];
1628 1642
      }
1629 1643
      // If that failed, try the previous one.
1630
      else if (isset($prev) && $settings['items'][$prev]['width_type'] == '%') {
1644
      elseif (isset($prev) && $settings['items'][$prev]['width_type'] == '%') {
1631 1645
        $settings['items'][$prev]['width'] += $item['width'];
1632 1646
      }
1633 1647
    }
......
1687 1701
}
1688 1702

  
1689 1703
/**
1690
 * AJAX responder to store resize information when the user adjusts the
1691
 * splitter.
1704
 * AJAX responder to store resize information when the user adjusts splitter.
1692 1705
 */
1693 1706
function panels_ajax_flexible_edit_resize($handler) {
1694 1707
  ctools_include('ajax');

Formats disponibles : Unified diff