00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 function panels_node_legacy_menu($may_cache) {
00017 if ($may_cache) {
00018 $items[] = array(
00019 'path' => 'admin/panels/node-legacy',
00020 'title' => t('Legacy node panes'),
00021 'access' => user_access('access administration pages'),
00022 'type' => MENU_NORMAL_ITEM,
00023 'callback' => 'panels_node_legacy_admin',
00024 'description' => t('Information about the legacy node content type.'),
00025 );
00026 return $items;
00027 }
00028 }
00029
00030
00031
00032
00033 function panels_node_legacy_admin() {
00034 $output = '<p>';
00035 $output .= t('Panels legacy nodes does not have a normal administrative UI, such as panels pages or mini panels. With this module, users may add a node directly to a panel via the add content interface. They may then select this node using an auto-complete field. In general, this method of adding nodes to panes should be considered deprecated (especially by module developers implementing the Panels API) and is only retained to support updating sites that use this older method. Moving forward, it is recommended that the context system be used to embed nodes, as that is far more powerful and interesting.');
00036 $output .= t('However, certain modules which make use of Panels are dependent on this method of getting node context (often without the developer even being aware of it), so it is important to emphasize that you CAN leave this module enabled without negatively impacting your site.');
00037 $output .= '</p>';
00038 return $output;
00039 }
00040
00041
00042
00043
00044 function panels_node_panels_content_types() {
00045 $items['node'] = array(
00046 'title' => t('Node'),
00047 'weight' => -10,
00048 'single' => TRUE,
00049 'content_types' => 'panels_node_legacy_content_types',
00050 'render callback' => 'panels_node_legacy_render',
00051 'add callback' => 'panels_node_legacy_add',
00052 'edit callback' => 'panels_node_legacy_edit',
00053 'title callback' => 'panels_node_legacy_title',
00054 'add validate callback' => 'panels_node_legacy_edit_validate',
00055 'edit validate callback' => 'panels_node_legacy_edit_validate',
00056 );
00057 return $items;
00058 }
00059
00060
00061
00062
00063
00064
00065 function panels_node_legacy_render($conf, $panel_args) {
00066 $nid = $conf['nid'];
00067 $block = new stdClass();
00068
00069 foreach (explode('/', $_GET['q']) as $id => $arg) {
00070 $nid = str_replace("%$id", $arg, $nid);
00071 }
00072
00073 foreach ($panel_args as $id => $arg) {
00074 $nid = str_replace("@$id", $arg, $nid);
00075 }
00076
00077
00078 if (module_exists('translation')) {
00079 if ($translation = module_invoke('translation', 'node_nid', $nid, $GLOBALS['locale'])) {
00080 $nid = $translation;
00081 }
00082 }
00083
00084 if (!is_numeric($nid)) {
00085 return;
00086 }
00087
00088 $node = node_load($nid);
00089 if (!node_access('view', $node)) {
00090 return;
00091 }
00092
00093 if (node_access('update', $node)) {
00094 $block->admin_links['update'] = array(
00095 'title' => t('Edit node'),
00096 'alt' => t("Edit this node"),
00097 'href' => "node/$node->nid/edit",
00098 'query' => drupal_get_destination(),
00099 );
00100 }
00101
00102 $block->module = 'node';
00103 $block->delta = $node->nid;
00104
00105 $block->subject = $node->title;
00106
00107 if (empty($conf['leave_node_title'])) {
00108 unset($node->title);
00109 }
00110 if (!empty($conf['identifier'])) {
00111 $node->panel_identifier = $conf['identifier'];
00112 }
00113
00114 $block->content = node_view($node, $conf['teaser'], FALSE, $conf['links']);
00115 return $block;
00116 }
00117
00118
00119
00120
00121 function panels_node_legacy_content_types() {
00122 return array(
00123 'node' => array(
00124 'title' => t('Node content'),
00125 'icon' => 'icon_node.png',
00126 'description' => t('Add a node from your site as content.'),
00127 'category' => array(t('Custom'), -10),
00128 ),
00129 );
00130 }
00131
00132
00133
00134
00135 function panels_node_legacy_add($id, $parents, $conf = array()) {
00136 $form = panels_node_legacy_edit($id, $parents, $conf);
00137 $form['nid'] = array(
00138 '#prefix' => '<div class="no-float">',
00139 '#suffix' => '</div>',
00140 '#title' => t('Enter the title or NID of a post'),
00141 '#description' => t('To use a NID from the URL, you may use %0, %1, ..., %N to get URL arguments. Or use @0, @1, @2, ..., @N to use arguments passed into the panel.'),
00142 '#type' => 'textfield',
00143 '#maxlength' => 512,
00144 '#autocomplete_path' => 'panels/node/autocomplete',
00145 '#weight' => -10,
00146 );
00147 $form['validate_me'] = array('#type' => 'value', '#value' => TRUE);
00148 return $form;
00149 }
00150
00151
00152
00153
00154 function panels_node_legacy_edit($id, $parents, $conf) {
00155 $form['nid'] = array(
00156 '#type' => 'value',
00157 '#default_value' => $conf['nid'],
00158 );
00159 $form['teaser'] = array(
00160 '#title' => t('Teaser'),
00161 '#type' => 'checkbox',
00162 '#default_value' => $conf['teaser'],
00163 '#description' => t('Check here to show only the node teaser'),
00164 );
00165 $form['links'] = array(
00166 '#type' => 'checkbox',
00167 '#default_value' => $conf['links'],
00168 '#title' => t('Display links'),
00169 '#description' => t('Check here to display the links with the post.'),
00170 );
00171
00172 $form['leave_node_title'] = array(
00173 '#type' => 'checkbox',
00174 '#default_value' => $conf['leave_node_title'],
00175 '#title' => t('Leave node title'),
00176 '#description' => t('Advanced: if checked, do not touch the node title; this can cause the node title to appear twice unless your theme is aware of this.'),
00177 );
00178 $form['identifier'] = array(
00179 '#type' => 'textfield',
00180 '#default_value' => $conf['identifier'],
00181 '#title' => t('Identifier'),
00182 '#description' => t('Whatever is placed here will appear in $node->panel_identifier to make it easier to theme a node or part of a node as necessary.'),
00183 );
00184
00185 return $form;
00186 }
00187
00188
00189
00190
00191 function panels_node_legacy_edit_validate($form, $form_values) {
00192 if (!$form_values['validate_me']) {
00193 return;
00194 }
00195
00196 if ($nid = panels_nid_autocomplete($form_values['nid'])) {
00197 form_set_value($form['nid'], $nid);
00198 } else {
00199 if (!preg_match('/^[@%]\d+$/', $form_values['nid'])) {
00200 form_error($form['nid'], t('Invalid node'));
00201 }
00202 }
00203 }
00204
00205
00206
00207
00208 function panels_node_legacy_title($conf) {
00209 if (!is_numeric($conf['nid'])) {
00210 return t('Node loaded from @var', array('@var' => $conf['nid']));
00211 }
00212
00213 $node = node_load($conf['nid']);
00214 if ($node) {
00215 return check_plain($node->title);
00216 }
00217 else {
00218 return t('Deleted/missing node @nid', array('@nid' => $conf['nid']));
00219 }
00220 }
00221