panels_views_legacy.module

Go to the documentation of this file.
00001 <?php
00002 // $Id: panels_views_legacy.module,v 1.1.2.9 2008/07/13 19:26:50 sdboyer Exp $
00003 
00004 
00005 /**
00006  * @file panels_views_legacy.module
00007  *
00008  * This module exposes nodes directly to the add content interface.
00009  * The panels views module is a recommended replacement that is better suited
00010  * for non-admin users.
00011  */
00012 
00013 /**
00014  * Implementation of hook_menu().
00015  */
00016 function panels_views_legacy_menu($may_cache) {
00017   if ($may_cache) {
00018     $items[] = array(
00019       'path' => 'admin/panels/views-legacy',
00020       'title' => t('Legacy views'),
00021       'access' => user_access('access administration pages'),
00022       'type' => MENU_NORMAL_ITEM,
00023       'callback' => 'panels_views_legacy_admin',
00024       'description' => t('Information about the legacy views content type.'),
00025     );
00026     return $items;
00027   }
00028 }
00029 
00030 /**
00031  * Page callback for the very short admin page.
00032  */
00033 function panels_views_legacy_admin() {
00034   $output = '<p>';
00035   $output .= t('Panels legacy views does not have a normal administrative UI, such as panels pages or mini panels. With this module, all of your views are provided as panes that can be added to any panel display; these panes have many options; because of all of these options, these panes are generally unsuitable for non administrative users. It is recommended that you only use panels views legacy if 1) you are upgrading a site that already uses this kind of view or 2) you do not want the extra work of having to determine which views are available as content. Otherwise, it is recommended you use the normal "Panels views content" module.');
00036   $output .= '</p>';
00037   return $output;
00038 }
00039 
00040 /**
00041  * Implementation of hook_panels_content_types()
00042  */
00043 function panels_views_legacy_panels_content_types() {
00044   // Only valid if views module loaded.
00045   $items['views'] = array(
00046     'title' => t('Legacy views'),
00047     'content_types' => 'panels_views_legacy_content_types',
00048     'render callback' => 'panels_views_legacy_render',
00049     'add callback' => 'panels_views_legacy_add',
00050     'edit callback' => 'panels_views_legacy_edit',
00051     'title callback' => 'panels_views_legacy_title',
00052   );
00053   return $items;
00054 }
00055 
00056 /**
00057  * Output function for the 'views' content type.
00058  *
00059  * Outputs a views based on the module and delta supplied in the configuration.
00060  */
00061 function panels_views_legacy_render($conf, $panel_args, $contexts) {
00062   if (!is_array($contexts)) {
00063     $contexts = array($contexts);
00064   }
00065 
00066   // Use clone to make sure this is fresh.
00067   $v = views_get_view($conf['view']);
00068   if ($v) {
00069     $view = drupal_clone($v);
00070     if (function_exists('views_access') && !views_access($view)) {
00071       return NULL;
00072     }
00073     $arguments = explode('/', $_GET['q']);
00074     $args = $conf['args'];
00075 
00076     foreach ($arguments as $id => $arg) {
00077       $args = str_replace("%$id", $arg, $args);
00078     }
00079 
00080     foreach ($panel_args as $id => $arg) {
00081       $args = str_replace("@$id", $arg, $args);
00082     }
00083 
00084     $args = preg_replace(',/?(%\d|@\d),', '', $args);
00085     $args = $args ? explode('/', $args) : array();
00086 
00087     if ($conf['panel_args'] && is_array($panel_args)) {
00088       $args = array_merge($panel_args, $args);
00089     }
00090 
00091     if (is_array($conf['context'])) {
00092       foreach ($conf['context'] as $count => $cid) {
00093         if ($cid != 'any' && !empty($contexts[$count]) && isset($contexts[$count]->argument)) {
00094           array_splice($args, $count, 0, array($contexts[$count]->argument));
00095         }
00096       }
00097     }
00098 
00099     if ($conf['url']) {
00100       $view->url = $conf['url'];
00101     }
00102 
00103     $block = new stdClass();
00104     $block->module = 'views';
00105     $block->delta  = $view->name;
00106 
00107     $view_type = $conf['type'] == 'embed' ? 'page' : $conf['type'];
00108     $block->subject = views_get_title($view, $view_type);
00109     if (!empty($conf['link_to_view'])) {
00110       $block->title_link = views_get_url($view, $args);
00111     }
00112 
00113     if (!empty($conf['more_link'])) {
00114       $block->more = array('href' => views_get_url($view, $args));
00115       $view->block_more = FALSE;
00116     }
00117 
00118     $pager_id = empty($conf['use_pager']) ? 0 : intval($conf['pager_id']);
00119 
00120     $stored_feeds = drupal_add_feed();
00121     $block->content = views_build_view($conf['type'], $view, $args, $pager_id, intval($conf['nodes_per_page']), 0, intval($conf['offset']));
00122 
00123     if (!empty($conf['feed_icons'])) {
00124       $new_feeds = drupal_add_feed();
00125       if ($diff = array_diff(array_keys($new_feeds), array_keys($stored_feeds))) {
00126         foreach ($diff as $url) {
00127           $block->feeds[$url] = $new_feeds[$url];
00128         }
00129       }
00130     }
00131 
00132     if (user_access('administer views')) {
00133       $block->admin_links['update'] = array(
00134         'title' => t('Edit view'),
00135         'alt' => t("Edit this view"),
00136         'href' => $view->vid ? "admin/build/views/$view->name/edit" : "admin/build/views/add/$view->name",
00137         'query' => drupal_get_destination(),
00138       );
00139     }
00140   }
00141   return $block;
00142 }
00143 
00144 /**
00145  * Return all content types available.
00146  */
00147 function panels_views_legacy_content_types() {
00148   $types = array();
00149   $views = array();
00150   $args  = array();
00151   views_load_cache();
00152   $arginfo = _views_get_arguments();
00153 
00154   $result = db_query("SELECT * FROM {view_argument}");
00155   while ($arg = db_fetch_array($result)) {
00156     $args[$arg['vid']][$arg['position']] = $arg;
00157   }
00158   $result = db_query("SELECT * FROM {view_view}");
00159   while ($view = db_fetch_object($result)) {
00160     $view->argument = $args[$view->vid];
00161 
00162     $title = views_get_title($view, 'admin');
00163     $icon = !empty($view->block) ? 'icon_views_block_legacy.png' : 'icon_views_page_legacy.png';
00164 
00165     $contexts = array();
00166     if (!empty($view->argument)) {
00167       foreach ($view->argument as $arg) {
00168         $contexts[] = new panels_optional_context($arginfo[$arg['type']]['name'], 'any');
00169       }
00170     }
00171     $types[$view->name] = array(
00172       'title' => strip_tags($title ? $title : $view->name),
00173       'icon' => $icon,
00174       'description' => filter_xss_admin($view->description),
00175       'required context' => $contexts,
00176       'category' => array(t('Views'), -1),
00177     );
00178     $views[$view->name] = TRUE;
00179   }
00180 
00181   views_load_cache();
00182   $default_views = _views_get_default_views();
00183   $views_status = variable_get('views_defaults', array());
00184   foreach ($default_views as $view) {
00185     if (!$views[$view->name] &&
00186       ($views_status[$view->name] == 'enabled' || (!$views_status[$view->name] && !$view->disabled))) {
00187       $title    = views_get_title($view, 'admin');
00188       $icon     = !empty($view->block) ? 'icon_views_block_legacy.png' : 'icon_views_page_legacy.png';
00189       $contexts = array();
00190       if (!empty($view->argument)) {
00191         foreach ($view->argument as $arg) {
00192           $contexts[] = new panels_optional_context($arginfo[$arg['type']]['name'], 'any');
00193         }
00194       }
00195       $types[$view->name] = array(
00196         'title' => strip_tags($title ? $title : $view->name),
00197         'icon' => $icon,
00198         'description' => filter_xss_admin($view->description),
00199         'required context' => $contexts,
00200         'category' => array(t('Views'), -1),
00201       );
00202     }
00203   }
00204   return $types;
00205 }
00206 
00207 /**
00208  * Returns the form for a new view.
00209  */
00210 function panels_views_legacy_add($id, $parents, $conf = array()) {
00211   $view = views_get_view($id);
00212   if (!$view) {
00213     return;
00214   }
00215   $conf['view'] = $id;
00216   if ($view->page) {
00217     $conf['type'] = 'page';
00218     $conf['nodes_per_page'] = $view->nodes_per_page;
00219   }
00220   else {
00221     $conf['type'] = 'block';
00222     $conf['nodes_per_page'] = $view->nodes_per_block;
00223   }
00224   $conf['type']      = 'embed';
00225   $conf['pager_id']  = 1;
00226   $conf['use_pager'] = 0;
00227   return panels_views_legacy_edit($id, $parents, $conf);
00228 }
00229 
00230 /**
00231  * Returns an edit form for a block.
00232  */
00233 function panels_views_legacy_edit($id, $parents, $conf) {
00234   $form['view'] = array(
00235     '#type' => 'value',
00236     '#default_value' => $conf['view'],
00237   );
00238   $form['type'] = array(
00239     '#type' => 'select',
00240     '#default_value' => $conf['type'],
00241     '#title' => t('View type'),
00242     '#description' => t('Select which type of the view to display.'),
00243     '#options' => array('page' => t('Page'), 'block' => t('Block'), 'embed' => t('Embedded')),
00244   );
00245 
00246   $form['link_to_view'] = array(
00247     '#type' => 'checkbox',
00248     '#default_value' => $conf['link_to_view'],
00249     '#title' => t('Link title to view'),
00250     '#description' => t('If checked, the title will be a link to the view.'),
00251   );
00252 
00253   $form['more_link'] = array(
00254     '#type' => 'checkbox',
00255     '#default_value' => $conf['more_link'],
00256     '#title' => t('Provide a "more" link that links to the view'),
00257     '#description' => t('This is independent of any more link that may be provided by the view itself; if you see two more links, turn this one off. Views will only provide a more link if using the "block" type, however, so if using embed, use this one.'),
00258   );
00259 
00260   $form['feed_icons'] = array(
00261     '#type' => 'checkbox',
00262     '#default_value' => $conf['feed_icons'],
00263     '#title' => t('Display feed icons'),
00264     '#description' => t('If checked, any feed icons provided by this view will be displayed.'),
00265   );
00266 
00267   $form['pager_aligner_start'] = array(
00268     '#value' => '<div class="option-text-aligner">',
00269   );
00270   $form['use_pager'] = array(
00271     '#type' => 'checkbox',
00272     '#title' => t('Use pager'),
00273     '#default_value' => $conf['use_pager'],
00274     '#id' => 'use-pager-checkbox',
00275   );
00276   $form['pager_id'] = array(
00277     '#type' => 'textfield',
00278     '#default_value' => $conf['pager_id'],
00279     '#title' => t('Pager ID'),
00280     '#size' => 4,
00281     '#id' => 'use-pager-textfield',
00282   );
00283   $form['pager_aligner_stop'] = array(
00284     '#value' => '</div><div style="clear: both; padding: 0; margin: 0"></div>',
00285   );
00286 
00287   $form['nodes_per_page'] = array(
00288     '#type' => 'textfield',
00289     '#default_value' => $conf['nodes_per_page'],
00290     '#title' => t('Num posts'),
00291     '#size' => 4,
00292     '#description' => t('Select the number of posts to display, or 0 to display all results.'),
00293   );
00294 
00295   $form['offset'] = array(
00296     '#type' => 'textfield',
00297     '#default_value' => $conf['offset'],
00298     '#title' => t('Offset'),
00299     '#size' => 4,
00300     '#description' => t('Offset in the node list or 0 to start at 1st item.'),
00301   );
00302 
00303   $form['panel_args'] = array(
00304     '#type' => 'checkbox',
00305     '#title' => t('Send arguments'),
00306     '#default_value' => $conf['panel_args'],
00307     '#description' => t('Select this to send all arguments from the panel directly to the view. If checked, the panel arguments will come after any context arguments above and precede any additional arguments passed in through the Arguments field below.'),
00308   );
00309 
00310   $form['args'] = array(
00311     '#type' => 'textfield',
00312     '#default_value' => $conf['args'],
00313     '#title' => t('Arguments'),
00314     '#size' => 30,
00315     '#description' => t('Additional arguments to send to the view as if they were part of the URL in the form of arg1/arg2/arg3. You may use %0, %1, ..., %N to grab arguments from the URL. Or use @0, @1, @2, ..., @N to use arguments passed into the panel.'),
00316   );
00317 
00318   $form['url'] = array(
00319     '#type' => 'textfield',
00320     '#default_value' => $conf['url'],
00321     '#title' => t('Override URL'),
00322     '#size' => 30,
00323     '#description' => t('If this is set, override the View URL; this can sometimes be useful to set to the panel URL'),
00324   );
00325 
00326   return $form;
00327 }
00328 
00329 /**
00330  * Returns the administrative title for a type.
00331  */
00332 function panels_views_legacy_title($conf) {
00333   $view = views_get_view($conf['view']);
00334   if (empty($view)) {
00335     return t('Deleted/missing view @view', array('@view' => $conf['view']));
00336   }
00337   $title = views_get_title($view, 'admin');
00338   return $title ? $title : $view->name;
00339 }
00340 
00341 /**
00342  * Don't show Views' blocks; we expose them already.
00343  */
00344 function views_panels_block_info($module, $delta, &$info) {
00345   $info = NULL;
00346 }
00347 

Generated on Sun Sep 5 05:00:14 2010 for Panels 2 by  doxygen 1.5.6