You are here

context_ui_contrib.module in Context 5

File

context_ui/context_ui_contrib.module
View source
<?php

/**
 * Implementation of hook_context_items()
 */
function context_ui_contrib_context_items() {
  $items = array();

  // Views
  if (module_exists('views')) {
    $items['views'] = array(
      '#title' => t('Views'),
      '#description' => t('Set this context when displaying the page of one of these views.'),
      '#options' => _context_ui_contrib_get_views(),
      '#type' => 'checkboxes',
      '#context_ui' => 'setter',
    );
  }

  // Nodequeue
  if (module_exists('nodequeue')) {
    $result = db_query("SELECT qid, title FROM {nodequeue_queue}");
    $options = array();
    while ($nq = db_fetch_object($result)) {
      $options[$nq->qid] = $nq->title;
    }
    $items['nodequeue'] = array(
      '#title' => t('Nodequeue'),
      '#description' => t('Set this context when a node in the selected nodequeue(s) is viewed.'),
      '#options' => $options,
      '#type' => 'checkboxes',
      '#context_ui' => 'setter',
    );
  }

  // Outline
  if (module_exists('outline')) {
    $result = db_query("SELECT volume_id, title FROM {outline_volume}");
    $options = array();
    while ($vol = db_fetch_object($result)) {
      $options[$vol->volume_id] = $vol->title;
    }
    $items['outline'] = array(
      '#title' => t('Outline'),
      '#description' => t('Set this context when a node in the selected volumes(s) is viewed.'),
      '#options' => $options,
      '#type' => 'checkboxes',
      '#context_ui' => 'setter',
    );
  }
  return $items;
}

/**
 * Implementation of hook_nodeapi().
 */
function context_ui_contrib_nodeapi(&$node, $op, $teaser, $page) {
  if ($op == 'view' && $page && arg(0) == 'node') {

    // Implementation of context_ui_set for nodequeue.
    if (module_exists('nodequeue')) {
      $result = db_query("SELECT qid FROM {nodequeue_nodes} WHERE nid = %d", $node->nid);
      while ($qid = db_fetch_object($result)) {
        context_ui_set('nodequeue', $qid->qid);
      }
    }

    // Implementation of context_ui_set for outline
    if (module_exists('outline') && ($vol = $node->volume_id)) {
      context_ui_set('outline', $vol);
    }
  }
}

/**
 * Implementation of hook_views_pre_query().
 */
function context_ui_contrib_views_pre_query($view) {
  if ($view->build_type == 'page') {
    context_ui_set('views', $view->name);
  }
}

/**
 * Helper function to generate a list of database and module provided views.
 */
function _context_ui_contrib_get_views() {
  $views = array();
  $result = db_query("SELECT name FROM {view_view}");
  while ($view = db_fetch_object($result)) {
    $views[$view->name] = $view->name;
  }
  views_load_cache();

  // the function below was not loaded without this call
  $default_views = _views_get_default_views();
  $views_status = variable_get('views_defaults', array());
  foreach ($default_views as $view) {
    if (!$views[$view->name] && ($views_status[$view->name] == 'enabled' || !$views_status[$view->name] && !$view->disabled)) {
      $views[$view->name] = $view->name;
    }
  }
  ksort($views);
  return $views;
}

Functions

Namesort descending Description
context_ui_contrib_context_items Implementation of hook_context_items()
context_ui_contrib_nodeapi Implementation of hook_nodeapi().
context_ui_contrib_views_pre_query Implementation of hook_views_pre_query().
_context_ui_contrib_get_views Helper function to generate a list of database and module provided views.