37d863afc882408a3d615cffaeb08fcfad6a8f33
[project/panels.git] / content_types / custom.inc
1 <?php
2 /**
3 * Callback function to supply a list of content types.
4 */
5 function panels_custom_panels_content_types() {
6 $items['custom'] = array(
7 'callback' => 'panels_content_custom',
8 'admin' => 'panels_admin_custom',
9 );
10 return $items;
11 }
12
13 /**
14 * Output function for the 'custom' content type. Outputs a custom
15 * based on the module and delta supplied in the configuration.
16 */
17 function panels_content_custom($conf) {
18 $title = filter_xss_admin($conf['title']);
19 $body = check_markup($conf['body'], $conf['format'], FALSE);
20 return theme('panels_content_custom', $title, $body);
21 }
22
23 function theme_panels_content_custom($title, $body) {
24 $output = '<div class="panel-custom">';
25 if ($title) {
26 $output .= '<h2 class="title">' . $title . '</h2>';
27 }
28 $output .= $body;
29 $output .= '</div>';
30 EOT;
31 return $output;
32 }
33 /**
34 * Callback to perform administrative functions on the content block
35 */
36 function panels_admin_custom($op, &$arg, $arg2 = NULL) {
37 switch ($op) {
38 case 'list':
39 $conf = $arg;
40 return '<strong>Custom</strong>: ' . filter_xss_admin($conf['title']);
41 case 'add button':
42 $form['title'] = array(
43 '#title' => t('Enter an optional title for custom content you define'),
44 '#type' => 'textfield',
45 '#maxlength' => 512,
46 '#weight' => -10,
47 );
48 $form['submit'] = array(
49 '#type' => 'button',
50 '#value' => t('Add custom'),
51 );
52
53 $form['#prefix'] = '<div class="container-inline">';
54 $form['#suffix'] = '</div>';
55 return $form;
56 case 'add':
57 if ($_POST['op'] != t('Add custom')) {
58 return;
59 }
60 return $arg;
61 case 'edit':
62 $conf = &$arg;
63 $form['title'] = array(
64 '#type' => 'textfield',
65 '#default_value' => $conf['title'],
66 '#title' => t('Title'),
67 '#description' => t('Title'),
68 '#size' => 15,
69 );
70 $form['body'] = array(
71 '#title' => t('Body'),
72 '#type' => 'textarea',
73 '#default_value' => $conf['body'],
74 '#rows' => 10,
75 '#cols' => 20,
76 );
77 $arg2[] = 'format';
78 $form['format'] = filter_form($conf['format'], 1, $arg2);
79
80 return $form;
81 case 'validate':
82 // This one has nothing to validate.
83 $form = &$arg;
84 return;
85 case 'save':
86 // For this one, the form values go directly into the config.
87 $form = &$arg;
88 return $form;
89 }
90 }