custom_php.inc
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008 function panels_custom_php_panels_content_types() {
00009 $items['custom_php'] = array(
00010 'title' => t('Custom PHP'),
00011 'weight' => -10,
00012 'single' => TRUE,
00013 'content_types' => 'panels_admin_content_types_custom_php',
00014 'render callback' => 'panels_content_custom_php',
00015 'editor render callback' => 'panels_admin_content_custom_php',
00016 'add callback' => 'panels_admin_edit_custom_php',
00017 'edit callback' => 'panels_admin_edit_custom_php',
00018 'title callback' => 'panels_admin_title_custom_php',
00019 'no override title' => TRUE,
00020 );
00021 return $items;
00022 }
00023
00024
00025
00026
00027
00028
00029 function panels_content_custom_php($conf, $panel_args, $context) {
00030 static $delta = 0;
00031 $block = new stdClass();
00032
00033
00034 eval($conf['body']);
00035 $block->delta = ++$delta;
00036
00037 $members = array(
00038 'module' => 'custom',
00039 'subject' => filter_xss_admin($conf['title']),
00040 'content' => '',
00041 );
00042
00043
00044
00045 foreach ($members as $member => $value) {
00046 if (empty($block->$member)) {
00047 $block->$member = $value;
00048 }
00049 }
00050
00051 return $block;
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 function panels_admin_content_custom_php($display, $pane) {
00063 $block = new stdClass();
00064 $block->title = filter_xss_admin($pane->configuration['title']);
00065
00066
00067 $block->content = check_markup($pane->configuration['body'], 1);
00068 return $block;
00069 }
00070
00071
00072
00073
00074 function panels_admin_content_types_custom_php() {
00075 if (filter_access(2)) {
00076 return array(
00077 'custom_php' => array(
00078 'title' => t('Custom PHP content'),
00079 'icon' => 'icon_block_custom.png',
00080 'path' => panels_get_path('content_types/custom'),
00081 'description' => t('Custom PHP block with access to Panels context data. Use sparingly, and with caution!'),
00082 'category' => array(t('Custom'), -10),
00083 'optional context' => new panels_optional_context(t('Context'), 'any'),
00084 ),
00085 );
00086 }
00087 }
00088
00089
00090
00091
00092 function panels_admin_edit_custom_php($id, $parents, $conf = NULL) {
00093 if (!is_array($conf)) {
00094 $conf = array('title' => '', 'body' => '');
00095 }
00096 $form['title'] = array(
00097 '#type' => 'textfield',
00098 '#default_value' => $conf['title'],
00099 '#title' => t('Title'),
00100 );
00101 $body = t('Any content you want to have passed along to theme function for displaying MUST be stored in $block->content.') . "\n\n";
00102 $body .= t('MAKE SURE YOU ERASE ALL OF THIS HELP TEXT. Only error-free php code should be saved in this field.') . "\n\n";
00103 $body .= t('Do NOT use php tags.');
00104
00105 $form['body'] = array(
00106 '#title' => t('Body'),
00107 '#type' => 'textarea',
00108 '#default_value' => isset($conf['body']) ? $conf['body'] : $body,
00109 '#rows' => 10,
00110 '#description' => t('The PHP code you enter here will be evaluated at render-time. Any context data present in the display will be available to this code in the $context variable. <strong>DO NOT</strong> include <em>@php</em> tags.', array('@php' => '<?php ?>')),
00111 );
00112
00113 return $form;
00114 }
00115
00116
00117
00118
00119 function panels_admin_title_custom_php($conf) {
00120 $output = t('Custom PHP with context');
00121 if ($conf['title']) {
00122 $output .= " (" . filter_xss_admin($conf['title']) . ")";
00123 }
00124 return $output;
00125 }
00126