00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009 function panels_help($section = NULL) {
00010 $output = '';
00011 switch ($section) {
00012 case 'admin/help#panels':
00013 case 'admin/panels':
00014 $output = '<p>'. t(' Panels module is the core engine for a number of sub-modules, including Panels pages, Panels nodes, Mini panels, and Views panes. Panels module allows the website adminstrator (or sometimes the end-user) to manipulate the layout of individual pages, sidebars, and content pieces, as well as easily dictate what content is displayed in the layout.') .'</p>';
00015 $output .= '<p>'. t('Most Drupal users are familiar with the block to region layout mechanism in which you can assign a block to any region defined in your theme. Panels takes this concept a massive step forward. Through the panels interface you can start by creating a layout with any number of columns, headers, and footer, and control the width of those areas.') .'</p>';
00016 $output .= '<p>'. t('After creating your layout, you can assign pieces of content to those areas in an easy drag and drop interface. Content is not limited to blocks, but can be nodes, views, or other types of content that expose themselves to panels.') .'</p>';
00017 $output .= '<p><b>'. t('Panel pages') .'</b>'. t(' are the the primary panels module, you can use this for creating single full page layouts. This replaces the standard panel that existed in the earlier versions of panels. If you are upgrading your site from Panels 1, and you cannot find where your panels went, be sure to enable the panel pages module!') .'</p>';
00018 $output .= '<p><b>'. t('Panel nodes') .'</b>'. t(' are useful for creating layouts that only occupy the content area of your pages. Frequently, it is desirable to add an area to a node layout, such as a pull quote for a newspaper or a photo block, that you don\'t necessarily want on every node. Panels Nodes lets you control the layout of a single node at a time and place content such as blog posts, images, blogs in and around the post.') .'</p>';
00019 $output .= '<p><b>'. t('Mini panels') .'</b>'. t(' are a layout mechanism for blocks. It won\'t take long using panels before you get to a point when you want a panel inside of a panel. Or a panel that can be used as a block. That is exactly what mini-panels does. You can create a small panel here with various pieces of content and then put it inside of a panels-page or panels-node.') .'</p>';
00020 $output .= '<p><b>'. t('Views panes') .'</b>'. t(" expose views so they may be added to panels. Panels will automatically detect block views without this module; however, page and embedded views will <strong>not be</strong> selectable from Panels by default. If you enable the <strong>Views panes</strong> module, you may expose individual views to Panels. The <strong>Legacy views panes</strong> module will simply expose all views, so that you may add them in any panel. Both modules provide options for customization of the views' settings on a per-Panel basis. This is useful if you have multiple administrators or want to use panels for something other than just panel pages.") .'</p>';
00021 $output .= '<p>' . t('If you do not see the above items in the list below, you may need to activate them on the <a href="!url">module administration</a> page.', array('!url' => url('admin/build/modules'))) . '</p>';
00022
00023 return $output;
00024 }
00025 }
00026
00027
00028
00029
00030
00031
00032 function panels_api_version() {
00033 return array(2, 0);
00034 }
00035
00036
00037
00038
00039 function panels_menu($may_cache) {
00040 if ($may_cache) {
00041 $items[] = array(
00042 'path' => 'admin/panels',
00043 'title' => t('Panels'),
00044 'access' => user_access('access administration pages'),
00045 'callback' => 'system_admin_menu_block_page',
00046 'description' => t('Administer items related to the Panels module.'),
00047 );
00048 $items[] = array(
00049 'path' => 'panels/node/autocomplete',
00050 'title' => t('Autocomplete node'),
00051 'callback' => 'panels_node_autocomplete',
00052 'access' => user_access('access content'),
00053 'type' => MENU_CALLBACK,
00054 );
00055
00056 $items[] = array(
00057 'path' => 'panels/ajax',
00058 'title' => t('ajax'),
00059 'callback' => 'panels_ajax_passthru',
00060 'callback arguments' => array('panels_ajax'),
00061 'access' => user_access('access content'),
00062 'type' => MENU_CALLBACK,
00063 );
00064 $items[] = array(
00065 'path' => 'panels/common/ajax',
00066 'title' => t('ajax'),
00067 'callback' => 'panels_ajax_passthru',
00068 'callback arguments' => array('panels_common_ajax'),
00069 'access' => user_access('access content'),
00070 'type' => MENU_CALLBACK,
00071 );
00072 $items[] = array(
00073 'path' => 'panels/ajax/add-content',
00074 'title' => t('ajax'),
00075 'callback' => 'panels_ajax_passthru',
00076 'callback arguments' => array('panels_ajax_add_content'),
00077 'access' => user_access('access content'),
00078 'type' => MENU_CALLBACK,
00079 );
00080 $items[] = array(
00081 'path' => 'panels/ajax/add-config',
00082 'title' => t('ajax'),
00083 'callback' => 'panels_ajax_passthru',
00084 'callback arguments' => array('panels_ajax_add_config'),
00085 'access' => user_access('access content'),
00086 'type' => MENU_CALLBACK,
00087 );
00088 $items[] = array(
00089 'path' => 'panels/ajax/configure',
00090 'title' => t('ajax'),
00091 'callback' => 'panels_ajax_passthru',
00092 'callback arguments' => array('panels_ajax_configure'),
00093 'access' => user_access('access content'),
00094 'type' => MENU_CALLBACK,
00095 );
00096 $items[] = array(
00097 'path' => 'panels/ajax/toggle-shown',
00098 'title' => t('ajax'),
00099 'callback' => 'panels_ajax_passthru',
00100 'callback arguments' => array('panels_ajax_toggle_shown'),
00101 'access' => user_access('access content'),
00102 'type' => MENU_CALLBACK,
00103 );
00104 $items[] = array(
00105 'path' => 'panels/ajax/cache',
00106 'title' => t('ajax'),
00107 'callback' => 'panels_ajax_passthru',
00108 'callback arguments' => array('panels_ajax_cache'),
00109 'access' => user_access('access content'),
00110 'type' => MENU_CALLBACK,
00111 );
00112 $items[] = array(
00113 'path' => 'panels/ajax/cache-settings',
00114 'title' => t('ajax'),
00115 'callback' => 'panels_ajax_passthru',
00116 'callback arguments' => array('panels_ajax_cache_settings'),
00117 'access' => user_access('access content'),
00118 'type' => MENU_CALLBACK,
00119 );
00120 $items[] = array(
00121 'path' => 'panels/ajax/panel_settings',
00122 'title' => t('ajax'),
00123 'callback' => 'panels_ajax_passthru',
00124 'callback arguments' => array('panels_panel_settings_ajax'),
00125 'access' => user_access('access content'),
00126 'type' => MENU_CALLBACK,
00127 );
00128 }
00129 else {
00130 drupal_add_css(panels_get_path('css/panels.css'));
00131 drupal_add_js(panels_get_path('js/panels.js'));
00132 }
00133
00134 return $items;
00135 }
00136
00137
00138
00139
00140 function panels_load_include($include, $path = 'includes/') {
00141 require_once './' . panels_get_path("$path$include.inc");
00142 }
00143
00144
00145
00146
00147 function panels_ajax_passthru() {
00148 $args = func_get_args();
00149 $callback = array_shift($args);
00150
00151 panels_load_include('plugins');
00152 if (arg(1) == 'common') {
00153 panels_load_include('common');
00154 }
00155 else {
00156 panels_load_include('display_edit');
00157 }
00158 return call_user_func_array($callback, $args);
00159 }
00160
00161
00162
00163
00164
00165
00166 function panels_ajax_render($output = NULL, $title = NULL, $url = NULL) {
00167 if (!is_object($output)) {
00168 $temp = new stdClass();
00169 $temp->output = $output;
00170 switch ($output) {
00171 case 'dismiss':
00172 $temp->type = $output;
00173 break;
00174
00175 default:
00176 $temp->type = 'display';
00177 }
00178 $temp->title = $title;
00179 $temp->url = $url;
00180 $output = $temp;
00181 }
00182 if (!$output->output || !$output->type) {
00183 $output->output = t('The input was invalid');
00184 $output->type = 'display';
00185 $output->title = t('Error');
00186 }
00187 drupal_set_header('Content-Type: text/javascript; charset=utf-8');
00188 print drupal_to_js($output);
00189 exit;
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 function panels_ajax_form($form_id, $title, $url) {
00209 $args = func_get_args();
00210
00211
00212 array_splice($args, 1, 2);
00213
00214 $form = call_user_func_array('drupal_retrieve_form', $args);
00215 $form['#redirect'] = FALSE;
00216
00217 $result = drupal_process_form($form_id, $form);
00218 if (isset($result)) {
00219 return $result;
00220 }
00221
00222
00223 $output = theme('status_messages');
00224 $output .= drupal_render_form($form_id, $form);
00225 panels_ajax_render($output, $title, $url);
00226 }
00227
00228
00229
00230
00231 function panels_get_path($file, $base_path = false, $module = 'panels') {
00232 if ($base_path) {
00233 $output = base_path();
00234 }
00235 return $output . drupal_get_path('module', $module) . '/' . $file;
00236 }
00237
00238
00239
00240
00241 function panels_perm() {
00242 return array('view all panes', 'view pane admin links', 'administer pane visibility', 'administer pane access', 'administer advanced pane settings', 'use panels caching features');
00243 }
00244
00245
00246
00247
00248
00249
00250
00251 function panels_elements() {
00252 $type['panels_imagebutton'] = array('#input' => TRUE, '#button_type' => 'submit');
00253 return $type;
00254 }
00255
00256
00257
00258
00259 function theme_panels_imagebutton($element) {
00260 return '<input type="image" ' .
00261 'class="form-' . $element['#button_type'] . ' ' . $element['#class'] . '" ' .
00262 'name="'. $element['#name'] .'" ' .
00263 'value="'. check_plain($element['#default_value']) .'" ' .
00264 'id="' . $element['#id'] . '" ' .
00265 drupal_attributes($element['#attributes']) .
00266 ' src="' . base_path() . $element['#image'] . '" ' .
00267 'alt="' . $element['#title'] . '" ' .
00268 'title="' . $element['#title'] . '" ' .
00269 "/>\n";
00270 }
00271
00272 function panels_imagebutton_value() {
00273
00274 }
00275
00276
00277
00278
00279 function panels_add_button($image, $name, $text, $class, $id = NULL) {
00280 return array(
00281 '#type' => 'panels_imagebutton',
00282 '#image' => panels_get_path('images/' . $image),
00283 '#title' => $text,
00284 '#default_value' => $name,
00285 '#class' => $class,
00286 '#id' => $id,
00287 );
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297 function panels_cache_get($did) {
00298 return panels_common_cache_get('panels', $did);
00299 }
00300
00301
00302
00303
00304 function panels_cache_set($did, $cache) {
00305 return panels_common_cache_set('panels', $did, $cache);
00306 }
00307
00308
00309
00310
00311 function panels_cache_clear($did) {
00312 return panels_common_cache_clear('panels', $did);
00313 }
00314
00315
00316
00317
00318
00319
00320
00321 function panels_common_cache_get($obj, $did, $skip_cache = FALSE) {
00322 static $cache = array();
00323 $key = "$obj:$did";
00324 if ($skip_cache) {
00325 unset($cache[$key]);
00326 }
00327
00328 if (!array_key_exists($key, $cache)) {
00329 $data = db_fetch_object(db_query("SELECT * FROM {panels_object_cache} WHERE sid = '%s' AND obj = '%s' AND did = %d", session_id(), $obj, $did));
00330 if ($data) {
00331 $cache[$key] = unserialize($data->data);
00332 }
00333 }
00334 return isset($cache[$key]) ? $cache[$key] : NULL;
00335 }
00336
00337
00338
00339
00340 function panels_common_cache_set($obj, $did, $cache) {
00341 panels_common_cache_clear($obj, $did);
00342 db_query("INSERT INTO {panels_object_cache} (sid, obj, did, data, timestamp) VALUES ('%s', '%s', %d, '%s', %d)", session_id(), $obj, $did, serialize($cache), time());
00343 }
00344
00345
00346
00347
00348 function panels_common_cache_clear($obj, $did) {
00349 db_query("DELETE FROM {panels_object_cache} WHERE sid = '%s' AND obj = '%s' AND did = %d", session_id(), $obj, $did);
00350 }
00351
00352
00353
00354
00355 function panels_cron() {
00356
00357 db_query("DELETE FROM {panels_object_cache} WHERE timestamp < %d", time() - (86400 * 7));
00358 }
00359
00360
00361
00362
00363
00364 function panels_set($var, $value = NULL) {
00365 static $vars = array();
00366 if ($value !== NULL) {
00367 $vars[$var] = $value;
00368 }
00369 return $vars[$var];
00370 }
00371
00372
00373
00374
00375 function panels_get($var) {
00376 return panels_set($var);
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 function panels_edit($display, $destination = NULL, $content_types = NULL) {
00441 panels_load_include('display_edit');
00442 panels_load_include('plugins');
00443 return _panels_edit($display, $destination, $content_types);
00444 }
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486 function panels_edit_layout($display, $finish, $destination = NULL, $allowed_layouts = NULL) {
00487 panels_load_include('display_edit');
00488 panels_load_include('plugins');
00489 return _panels_edit_layout($display, $finish, $destination, $allowed_layouts);
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542 function panels_edit_layout_settings($display, $finish, $destination = NULL, $title = FALSE) {
00543 panels_load_include('display_edit');
00544 panels_load_include('plugins');
00545 return _panels_edit_layout_settings($display, $finish, $destination, $title);
00546 }
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558 class panels_display {
00559 var $args = array();
00560 var $content = array();
00561 var $panels = array();
00562 var $incoming_content = NULL;
00563 var $css_id = NULL;
00564 var $context = array();
00565 var $title = '';
00566 var $hide_title = 0;
00567
00568 function add_pane($pane, $location = FALSE) {
00569 $pane->pid = $this->next_new_pid();
00570 if (!$location || !isset($this->panels[$location])) {
00571 foreach ($this->panels as $panel_name => $panel) {
00572 if (array_key_exists($pane->pid, $panel)) {
00573 $this->panels[$panel_name][] = $pane->pid;
00574 }
00575 }
00576 }
00577 else {
00578 $this->panels[$location][] = $pane->pid;
00579 }
00580 }
00581
00582 function duplicate_pane($pid, $location = FALSE) {
00583 $pane = $this->clone_pane($pid);
00584 $this->add_pane($pane, $location);
00585 }
00586
00587 function clone_pane($pid) {
00588 $pane = drupal_clone($this->content[$pid]);
00589 foreach (array_keys($this->content) as $pidcheck) {
00590
00591 unset($pane->position);
00592 }
00593 return $pane;
00594 }
00595
00596 function next_new_pid() {
00597
00598
00599 $id = array(0);
00600 foreach (array_keys($this->content) as $pid) {
00601 if (!is_numeric($pid)) {
00602 $id[] = substr($pid, 4);
00603 }
00604 }
00605 $next_id = end($id);
00606 return ++$next_id;
00607 }
00608 }
00609
00610
00611
00612
00613
00614
00615 function panels_sanitize_display(&$display) {
00616 if (!isset($display->args)) {
00617 $display->args = array();
00618 }
00619
00620 if (!isset($display->incoming_content)) {
00621 $display->incoming_content = NULL;
00622 }
00623
00624 if (!isset($display->context)) {
00625 $display->context = array();
00626 }
00627
00628 if (!isset($display->css_id)) {
00629 $display->css_id = NULL;
00630 }
00631 }
00632
00633
00634
00635
00636
00637
00638 function panels_new_display() {
00639 $display = new panels_display();
00640 $display->did = 'new';
00641 return $display;
00642 }
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657 function panels_load_displays($dids) {
00658 $displays = array();
00659 if (empty($dids) || !is_array($dids)) {
00660 return $displays;
00661 }
00662
00663 $subs = implode(', ', array_fill(0, count($dids), '%d'));
00664
00665 $result = db_query("SELECT * FROM {panels_display} WHERE did IN ($subs)", $dids);
00666
00667 while ($obj = db_fetch_array($result)) {
00668 $display = new panels_display();
00669
00670 foreach ($obj as $key => $value) {
00671 $display->$key = $value;
00672
00673 if (in_array($key, array('layout_settings', 'panel_settings', 'cache'))) {
00674 $display->$key = empty($display->$key) ? array() : unserialize($display->$key);
00675 }
00676 }
00677
00678 $display->panels = $display->content = array();
00679
00680 $displays[$display->did] = $display;
00681 }
00682
00683 foreach (module_implements('panels_layout_content_alter') as $module) {
00684 $function = $module . '_panels_layout_content_alter';
00685 $function($content, $layout, $settings);
00686 }
00687
00688 $result = db_query("SELECT * FROM {panels_pane} WHERE did IN ($subs) ORDER BY did, panel, position", $dids);
00689
00690 while ($pane = db_fetch_object($result)) {
00691 $pane->configuration = unserialize($pane->configuration);
00692 $pane->cache = empty($pane->cache) ? array() : unserialize($pane->cache);
00693 $pane->access = ($pane->access ? explode(', ', $pane->access) : array());
00694
00695 $pane->shown = isset($pane->shown) ? $pane->shown : TRUE;
00696
00697 $displays[$pane->did]->panels[$pane->panel][] = $pane->pid;
00698 $displays[$pane->did]->content[$pane->pid] = $pane;
00699 }
00700 return $displays;
00701 }
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729 function panels_load_display($did) {
00730 $displays = panels_load_displays(array($did));
00731 if (!empty($displays)) {
00732 return array_shift($displays);
00733 }
00734 }
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752 function panels_save_display(&$display) {
00753 if ($display->did && $display->did != 'new') {
00754 if (empty($display->cache)) {
00755 $display->cache = array();
00756 }
00757 db_query("UPDATE {panels_display} SET layout = '%s', layout_settings = '%s', panel_settings = '%s', cache = '%s', title = '%s', hide_title = %d WHERE did = %d", $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache), $display->title, $display->hide_title, $display->did);
00758 db_query("DELETE FROM {panels_pane} WHERE did = %d", $display->did);
00759 }
00760 else {
00761 $display->did = db_next_id("{panels_display}_did");
00762 db_query("INSERT INTO {panels_display} (did, layout, layout_settings, panel_settings, cache, title, hide_title) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d)", $display->did, $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache), $display->title, $display->hide_title);
00763 }
00764
00765
00766 panels_load_include('plugins');
00767 foreach ((array) $display->panels as $id => $panes) {
00768 $position = 0;
00769 $new_panes = array();
00770 foreach ((array) $panes as $pid) {
00771 $pane = $display->content[$pid];
00772 $pane->position = $position++;
00773 if (!is_numeric($pid)) {
00774 unset($display->content[$pid]);
00775 $pane->pid = db_next_id("{panels_pane}_pid");
00776 }
00777 if (empty($pane->cache)) {
00778 $pane->cache = array();
00779 }
00780
00781 $type = panels_get_content_type($pane->type);
00782 $access = isset($pane->access) ? implode(', ', $pane->access) : '';
00783 $visibility = $type['visibility serialize'] ? serialize($pane->visibility) : $pane->visibility;
00784
00785 $f = 'pid, did, panel, type, subtype, configuration, cache, shown, access, visibility, position';
00786 $q = "%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d";
00787 $pane->shown = isset($pane->shown) ? $pane->shown : TRUE;
00788 $v = array($pane->pid, $display->did, $pane->panel, $pane->type, $pane->subtype, serialize($pane->configuration), serialize($pane->cache), $pane->shown, $access, $visibility, $pane->position);
00789 db_query("INSERT INTO {panels_pane} ($f) VALUES ($q)", $v);
00790
00791 $display->content[$pane->pid] = $pane;
00792 $new_panes[] = $pane->pid;
00793 }
00794 $display->panels[$id] = $new_panes;
00795 }
00796
00797
00798 panels_clear_cached_content($display);
00799
00800
00801 return $display;
00802 }
00803
00804
00805
00806
00807
00808 function panels_delete_display($display) {
00809 if (is_object($display)) {
00810 $did = $display->did;
00811 }
00812 else {
00813 $did = $display;
00814 }
00815 db_query("DELETE FROM {panels_display} WHERE did = %d", $did);
00816 db_query("DELETE FROM {panels_pane} WHERE did = %d", $did);
00817 }
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846 function panels_export_display($display, $prefix = '') {
00847 $output = '';
00848 $output .= $prefix . '$display = new panels_display()' . ";\n";
00849 $output .= $prefix . '$display->did = \'new\'' . ";\n";
00850 $fields = array('layout', 'layout_settings', 'panel_settings', 'cache', 'title', 'hide_title');
00851 foreach ($fields as $field) {
00852 if (isset($display->$field)) {
00853 $output .= $prefix . '$display->' . $field . ' = ' . panels_var_export($display->$field, $prefix) . ";\n";
00854 }
00855 }
00856
00857 $output .= $prefix . '$display->content = array()' . ";\n";
00858 $output .= $prefix . '$display->panels = array()' . ";\n";
00859 $panels = array();
00860
00861 if (!empty($display->content)) {
00862 $pid_counter = 0;
00863 $region_counters = array();
00864 foreach ($display->content as $pane) {
00865 $pane->pid = 'new-' . ++$pid_counter;
00866 $output .= panels_export_pane($pane, $prefix . ' ');
00867 $output .= "$prefix " . '$display->content[\'' . $pane->pid . '\'] = $pane' . ";\n";
00868 if (!isset($region_counters[$pane->panel])) {
00869 $region_counters[$pane->panel] = 0;
00870 }
00871 $output .= "$prefix " . '$display->panels[\'' . $pane->panel . '\'][' . $region_counters[$pane->panel]++ .'] = \'' . $pane->pid . "';\n";
00872 }
00873 }
00874 return $output;
00875 }
00876
00877 function panels_export_pane($pane, $prefix = '') {
00878 $output = '';
00879 $output = $prefix . '$pane = new stdClass()' . ";\n";
00880 $fields = array('pid', 'panel', 'type', 'subtype', 'shown', 'access', 'visibility', 'configuration', 'cache');
00881 foreach ($fields as $field) {
00882 $output .= "$prefix " . '$pane->' . $field . ' = ' . panels_var_export($pane->$field, "$prefix ") . ";\n";
00883 }
00884 return $output;
00885 }
00886
00887 function panels_var_export($object, $prefix = '') {
00888 if (is_array($object) && empty($object)) {
00889 $output = 'array()';
00890 }
00891 else {
00892 $output = var_export($object, TRUE);
00893 }
00894
00895 if ($prefix) {
00896 $output = str_replace("\n", "\n$prefix", $output);
00897 }
00898 return $output;
00899 }
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912 function panels_render_display(&$display) {
00913 panels_load_include('plugins');
00914 $layout = panels_get_layout($display->layout);
00915 if (!$layout) {
00916 return NULL;
00917 }
00918
00919
00920 panels_sanitize_display($display);
00921
00922 $output = '';
00923
00924
00925 foreach (module_implements('panels_pre_render') as $module) {
00926 $function = $module . '_panels_pre_render';
00927 $output .= $function($display);
00928 }
00929
00930 $output .= panels_render_layout($layout, $display, $display->css_id, $display->layout_settings);
00931
00932
00933 foreach (module_implements('panels_post_render') as $module) {
00934 $function = $module . '_panels_post_render';
00935 $output .= $function($display);
00936 }
00937 return $output;
00938 }
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949 function panels_print_layout($id, $content) {
00950 panels_load_include('plugins');
00951 $layout = panels_get_layout($id);
00952 if (!$layout) {
00953 return;
00954 }
00955
00956 return panels_render_layout($layout, $content);
00957 }
00958
00959
00960
00961
00962
00963 function panels_render_layout($layout, $content, $css_id = NULL, $settings = array()) {
00964 if (!empty($layout['css'])) {
00965 if (file_exists(path_to_theme() . '/' . $layout['css'])) {
00966 drupal_add_css(path_to_theme() . '/' . $layout['css']);
00967 }
00968 else {
00969 drupal_add_css(panels_get_path($layout['css'], false, $layout['module']));
00970 }
00971 }
00972 $display = NULL;
00973
00974
00975
00976
00977
00978 if (is_object($content)) {
00979 $display = $content;
00980 if (empty($display->cache['method'])) {
00981 $content = panels_render_panes($display);
00982 }
00983 else {
00984 $cache = panels_get_cached_content($display, $display->args, $display->context);
00985 if ($cache === FALSE) {
00986 $cache = new panels_cache_object();
00987 $cache->set_content(panels_render_panes($display));
00988 panels_set_cached_content($cache, $display, $display->args, $display->context);
00989 }
00990 $content = $cache->content;
00991 }
00992 }
00993
00994 $output = theme($layout['theme'], check_plain($css_id), $content, $settings, $display);
00995
00996 return $output;
00997 }
00998
00999
01000
01001
01002
01003 function panels_render_panes($display) {
01004
01005 if (empty($display->content)) {
01006 return array();
01007 }
01008
01009
01010
01011
01012 $panes = array();
01013 $later = array();
01014
01015 foreach ($display->content as $pid => $pane) {
01016 $pane->shown = isset($pane->shown) ? $pane->shown : TRUE;
01017
01018
01019 if (!$pane->shown || !panels_pane_access($pane, $display)) {
01020 continue;
01021 }
01022
01023
01024 $content_type = panels_get_content_type($pane->type);
01025
01026 if (!empty($content_type['render last'])) {
01027 $later[$pid] = $pane;
01028 continue;
01029 }
01030
01031 $panes[$pid] = panels_render_pane_content($display, $pane);
01032 }
01033
01034 foreach ($later as $pid => $pane) {
01035 $panes[$pid] = panels_render_pane_content($display, $pane);
01036 }
01037
01038
01039
01040
01041 $content = array();
01042 foreach ($display->panels as $panel_name => $pids) {
01043 $panel = array();
01044 foreach ($pids as $pid) {
01045 if (!empty($panes[$pid])) {
01046 $panel[$pid] = $panes[$pid];
01047 }
01048 }
01049 $content[$panel_name] = panels_render_panel($display, $panel_name, $panel);
01050 }
01051
01052 return $content;
01053 }
01054
01055
01056
01057
01058
01059 function panels_render_pane_content(&$display, &$pane) {
01060 if (empty($pane->context)) {
01061 $pane->context = panels_pane_select_context($pane, $display->context);
01062 if ($pane->context === FALSE) {
01063 return FALSE;
01064 }
01065 }
01066
01067 $content = panels_get_pane_content($display, $pane, $display->args, $pane->context, $display->incoming_content);
01068
01069 $keywords = !empty($display->keywords) ? $display->keywords : array();
01070
01071 if (!empty($pane->configuration['override_title'])) {
01072
01073 $keywords['%title'] = $content->title;
01074 $content->title = $pane->configuration['override_title_text'];
01075 }
01076
01077
01078 if (!empty($pane->configuration['css_id'])) {
01079 $content->css_id = $pane->configuration['css_id'];
01080 }
01081
01082
01083 if (!empty($pane->configuration['css_class'])) {
01084 $content->css_class = $pane->configuration['css_class'];
01085 }
01086
01087 if (!empty($content->title)) {
01088
01089 if (!empty($keywords)) {
01090 $content->title = strtr($content->title, $keywords);
01091 }
01092
01093
01094 $content->title = filter_xss_admin($content->title);
01095
01096
01097 if (!empty($content->title_link)) {
01098 if (!is_array($content->title_link)) {
01099 $url = array('href' => $content->title_link);
01100 }
01101 else {
01102 $url = $content->title_link;
01103 }
01104
01105 $url += array('href' => '', 'attributes' => NULL, 'query' => NULL, 'fragment' => NULL, 'absolute' => NULL);
01106 $content->title = l($content->title,
01107 $url['href'],
01108 $url['attributes'],
01109 $url['query'],
01110 $url['fragment'],
01111 $url['absolute'], TRUE);
01112 }
01113 }
01114 return $content;
01115 }
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127 function panels_render_pane($content, $pane, $display) {
01128 if (!empty($pane->configuration['style'])) {
01129 $style = panels_get_style($pane->configuration['style']);
01130
01131 if (isset($style)) {
01132 $output = theme($style['render pane'], $content, $pane, $display);
01133
01134
01135 if (isset($output)) {
01136 return $output;
01137 }
01138 }
01139 }
01140
01141 if (!empty($content)) {
01142
01143 return theme('panels_pane', $content, $pane, $display);
01144 }
01145 }
01146
01147
01148
01149
01150
01151 function panels_get_panel_style_and_settings($panel_settings, $panel) {
01152 if (empty($panel_settings)) {
01153 return array(panels_get_style('default'), array());
01154 }
01155
01156 if (empty($panel_settings['individual']) || empty($panel_settings['panel'][$panel]['style'])) {
01157 $style = panels_get_style($panel_settings['style']);
01158 $style_settings = $panel_settings['style_settings']['default'];
01159 }
01160 else {
01161 $style = panels_get_style($panel_settings['panel'][$panel]['style']);
01162 $style_settings = $panel_settings['style_settings'][$panel];
01163 }
01164
01165 return array($style, $style_settings);
01166 }
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184 function panels_render_panel($display, $panel, $panes) {
01185 list($style, $style_settings) = panels_get_panel_style_and_settings($display->panel_settings, $panel);
01186
01187
01188
01189
01190
01191 $owner_id = 0;
01192 if (isset($display->owner) && is_object($display->owner) && isset($display->owner->id)) {
01193 $owner_id = $display->owner->id;
01194 }
01195
01196 return theme($style['render panel'], $display, $owner_id, $panes, $style_settings, $panel);
01197 }
01198
01199
01200
01201
01202
01203 function panels_print_layout_link($id, $layout, $link) {
01204 drupal_add_css(panels_get_path('css/panels_admin.css'));
01205 $file = panels_get_path($layout['icon'], false, $layout['module']);
01206 $image = l(theme('image', $file), $link, NULL, NULL, NULL, NULL, TRUE);
01207 $title = l($layout['title'], $link);
01208 return theme('panels_layout_link', $title, $id, $image, $link);
01209 }
01210
01211
01212 function panels_print_layout_icon($id, $layout, $title = NULL) {
01213 drupal_add_css(panels_get_path('css/panels_admin.css'));
01214 $file = panels_get_path($layout['icon'], false, $layout['module']);
01215 return theme('panels_layout_icon', $id, theme('image', $file), $title);
01216 }
01217
01218
01219
01220
01221
01222 function theme_panels_layout_link($title, $id, $image, $link) {
01223 $output .= '<div class="layout-link">';
01224 $output .= $image;
01225 $output .= '<div>' . $title . '</div>';
01226 $output .= '</div>';
01227 return $output;
01228 }
01229
01230
01231
01232
01233
01234 function theme_panels_layout_icon($id, $image, $title = NULL) {
01235 $output .= '<span class="layout-icon">';
01236 $output .= $image;
01237 if ($title) {
01238 $output .= '<span class="caption">' . $title . '</span>';
01239 }
01240 $output .= '</span>';
01241 return $output;
01242 }
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262 function theme_panels_pane($content, $pane, $display) {
01263 if (!empty($content->content)) {
01264 $idstr = $classstr = '';
01265 if (!empty($content->css_id)) {
01266 $idstr = ' id="' . $content->css_id . '"';
01267 }
01268 if (!empty($content->css_class)) {
01269 $classstr = ' ' . $content->css_class;
01270 }
01271
01272 $output = "<div class=\"panel-pane$classstr\"$idstr>\n";
01273 if (user_access('view pane admin links') && !empty($content->admin_links)) {
01274 $output .= "<div class=\"admin-links panel-hide\">" . theme('links', $content->admin_links) . "</div>\n";
01275 }
01276 if (!empty($content->title)) {
01277 $output .= "<h2 class=\"title\">$content->title</h2>\n";
01278 }
01279
01280 if (!empty($content->feeds)) {
01281 $output .= "<div class=\"feed\">" . implode(' ', $content->feeds) . "</div>\n";
01282 }
01283
01284 $output .= "<div class=\"content\">$content->content</div>\n";
01285
01286 if (!empty($content->links)) {
01287 $output .= "<div class=\"links\">" . theme('links', $content->links) . "</div>\n";
01288 }
01289
01290
01291 if (!empty($content->more)) {
01292 if (empty($content->more['title'])) {
01293 $content->more['title'] = t('more');
01294 }
01295 $output .= "<div class=\"more-link\">" . l($content->more['title'], $content->more['href']) . "</div>\n";
01296 }
01297
01298 $output .= "</div>\n";
01299 return $output;
01300 }
01301 }
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313 function panels_nid_autocomplete($int) {
01314 $nid = NULL;
01315 if (is_numeric($int)) {
01316
01317 $nid = $int;
01318 }
01319 else {
01320
01321 $preg_matches = array();
01322 $match = preg_match('/\[nid: (\d+)\]/', $int, $preg_matches)
01323 || preg_match('/^nid: (\d+)/', $int, $preg_matches);
01324 if ($match) {
01325 $nid = $preg_matches[1];
01326 }
01327 }
01328 if (isset($nid)) {
01329
01330 $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid = %d"), $nid));
01331 }
01332 else {
01333
01334 $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE LOWER(n.title) = LOWER('%s')"), $int));
01335 }
01336 if ($node) {
01337 return $node->nid;
01338 }
01339 }
01340
01341
01342
01343
01344 function panels_node_autocomplete($string) {
01345
01346
01347
01348 if ($string != '') {
01349 $preg_matches = array();
01350 $match = preg_match('/\[nid: (\d+)\]/', $string, $preg_matches);
01351 if (!$match) {
01352 $match = preg_match('/^nid: (\d+)/', $string, $preg_matches);
01353 }
01354 if ($match) {
01355 $arg = $preg_matches[1];
01356 $where = "n.nid = %d";
01357 }
01358 else {
01359 $arg = $string;
01360 $where = "LOWER(title) LIKE LOWER('%%%s%%')";
01361 }
01362 $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, u.name FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE $where"), $arg, 0, 10);
01363
01364 $matches = array();
01365 while ($node = db_fetch_object($result)) {
01366 $name = empty($node->name) ? variable_get('anonymous', t('Anonymous')) : check_plain($node->name);
01367 $matches[$node->title . " [nid: $node->nid]"] = '<span class="autocomplete_title">'. check_plain($node->title) .'</span> <span class="autocomplete_user">('. t('by @user', array('@user' => $name)) .')</span>';
01368 }
01369 drupal_set_header('Content-Type: text/javascript; charset=utf-8');
01370 print drupal_to_js($matches);
01371 }
01372 }
01373
01374
01375
01376
01377
01378
01379
01380 function panels_node_type($op, $info) {
01381 if ($op == 'update') {
01382 if (!empty($info->old_type) && $info->old_type != $info->type) {
01383
01384 $result = db_query("SELECT * FROM {panels_pane} WHERE type NOT IN ('block', 'custom')");
01385 while ($pane = db_fetch_object($result)) {
01386
01387 if (!preg_match('/s:7:\"context/', $pane->configuration) || stripos($pane->configuration, 'node-' . $info->old_type) === FALSE) {
01388
01389 continue;
01390 }
01391 $conf = unserialize($pane->configuration);
01392
01393 if (is_array($conf['context'] && ($keys = array_keys($conf['context'], 'node-' . $info->old_type)))) {
01394 foreach ($keys as $key) {
01395 $conf['context'][$key] = 'node-' . $info->type;
01396 }
01397 db_query("UPDATE {panels_pane} SET configuration = '%s' WHERE pid = %d", serialize($conf), $pane->pid);
01398 }
01399
01400 else if ($conf['context'] == 'node-' . $info->old_type) {
01401 $conf['context'] = 'node-' . $info->type;
01402 db_query("UPDATE {panels_pane} SET configuration = '%s' WHERE pid = %d", serialize($conf), $pane->pid);
01403 }
01404 }
01405 }
01406 }
01407 }