custom_php.inc

Go to the documentation of this file.
00001 <?php
00002 // $Id: custom_php.inc,v 1.1.2.2 2008/08/05 08:10:59 sdboyer Exp $
00003 
00004 
00005 /**
00006  * Callback function to supply a list of content types.
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  * Output function for the 'custom_php' content type. Allows sufficiently
00026  * privileged users to enter custom php code that is evaluated while
00027  * $context is in scope. Use with caution!
00028  */
00029 function panels_content_custom_php($conf, $panel_args, $context) {
00030   static $delta = 0;
00031   $block = new stdClass();
00032   
00033   // eval() the php that has been entered by the user.
00034   eval($conf['body']);
00035   $block->delta = ++$delta;
00036   // Put our default member values into a separate array.
00037   $members = array(
00038     'module'  => 'custom',
00039     'subject' => filter_xss_admin($conf['title']),
00040     'content' => '',
00041   );
00042   // Iterate through the array of defaults and assign put in
00043   // any values that haven't already been set by the custom
00044   // php code.
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  * Render callback for when the custom content is in the editor so that people
00056  * can have a preview on the spot.
00057  *
00058  * @param panels_display $display
00059  * @param stdClass $pane
00060  * @return stdClass $block
00061  */
00062 function panels_admin_content_custom_php($display, $pane) {
00063   $block = new stdClass();
00064   $block->title = filter_xss_admin($pane->configuration['title']);
00065   // We don't want to render php output on preview here, because if something is
00066   // wrong the whole display will be borked.
00067   $block->content = check_markup($pane->configuration['body'], 1);
00068   return $block;
00069 }
00070 
00071 /**
00072  * Return all content types available.
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  * Returns an edit form for the custom_php type.
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  * Returns the administrative title for a type.
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 

Generated on Thu Jul 29 05:00:14 2010 for Panels 2 by  doxygen 1.5.6