node.inc
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 function panels_node_panels_contexts() {
00012 $args['node'] = array(
00013 'title' => t("Node"),
00014 'description' => t('A node object.'),
00015 'context' => 'panels_context_create_node',
00016 'settings form' => 'panels_context_node_settings_form',
00017 'settings form validate' => 'panels_context_node_settings_form_validate',
00018 'keyword' => 'node',
00019 'context name' => 'node',
00020 );
00021 return $args;
00022 }
00023
00024
00025
00026
00027
00028 function panels_context_create_node($empty, $data = NULL, $conf = FALSE) {
00029 $types = array('node');
00030 if (!empty($conf['types'])) {
00031 foreach ($conf['types'] as $type) {
00032 if ($type) {
00033 $types[] = 'node-' . $type;
00034 }
00035 }
00036 }
00037 $context = new panels_context($types);
00038 $context->plugin = 'node';
00039
00040 if ($empty) {
00041 return $context;
00042 }
00043
00044 if ($conf) {
00045 $nid = is_array($data) ? $data['nid'] : $data->nid;
00046
00047 if (module_exists('translation')) {
00048 if ($translation = module_invoke('translation', 'node_nid', $nid, $GLOBALS['locale'])) {
00049 $nid = $translation;
00050 $reload = TRUE;
00051 }
00052 }
00053
00054 if (is_array($data) || !empty($reload)) {
00055 $data = node_load($nid);
00056 }
00057 }
00058
00059 if (!empty($data)) {
00060 $context->data = $data;
00061 $context->title = $data->title;
00062 $context->argument = $data->nid;
00063 if (is_array($context->type)) {
00064 $context->type[] = 'node-' . $data->type;
00065 }
00066 else {
00067 $context->type = array($context->type, 'node-' . $data->type);
00068 }
00069 return $context;
00070 }
00071 }
00072
00073 function panels_context_node_settings_form($conf, $external = FALSE) {
00074 if ($external) {
00075 $form['external'] = array(
00076 '#type' => 'checkbox',
00077 '#default_value' => $conf['external'],
00078 '#title' => t('Require this context from an external source (such as a containing panel page).'),
00079 '#description' => t('If selected, node selection (below) will be ignored.'),
00080 );
00081 }
00082
00083
00084 $form['node'] = array(
00085 '#prefix' => '<div class="no-float">',
00086 '#suffix' => '</div>',
00087 '#title' => t('Enter the title or NID of a post'),
00088 '#type' => 'textfield',
00089 '#maxlength' => 512,
00090 '#autocomplete_path' => 'panels/node/autocomplete',
00091 '#weight' => -10,
00092 );
00093
00094 if (!empty($conf['nid'])) {
00095 $info = db_fetch_object(db_query("SELECT * FROM {node} n WHERE n.nid = %d", $conf['nid']));
00096 if ($info) {
00097 $link = l("'$info->title' [node id: $info->nid]", "node/$info->nid", array('target' => '_blank', 'title' => t('Open in new window')));
00098 $form['node']['#description'] = t('Currently set to !link', array('!link' => $link));
00099 }
00100 }
00101
00102 $form['nid'] = array(
00103 '#type' => 'value',
00104 '#value' => $conf['nid'],
00105 );
00106
00107 return $form;
00108 }
00109
00110
00111
00112
00113 function panels_context_node_settings_form_validate($form, $form_values) {
00114
00115 if (empty($form_values['external']) && empty($form_values['nid']) && empty($form_values['node'])) {
00116 form_error($form['node'], t('You must select a node.'));
00117 return;
00118 }
00119
00120 if (empty($form_values['node'])) {
00121 return;
00122 }
00123
00124 if ($nid = panels_nid_autocomplete($form_values['node'])) {
00125 form_set_value($form['nid'], $nid);
00126 }
00127 else {
00128 form_error($form['node'], t('Invalid node selected.'));
00129 }
00130 }
00131