context_ui_contrib.module in Context 5
File
context_ui/context_ui_contrib.module
View source
<?php
function context_ui_contrib_context_items() {
$items = array();
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',
);
}
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',
);
}
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;
}
function context_ui_contrib_nodeapi(&$node, $op, $teaser, $page) {
if ($op == 'view' && $page && arg(0) == 'node') {
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);
}
}
if (module_exists('outline') && ($vol = $node->volume_id)) {
context_ui_set('outline', $vol);
}
}
}
function context_ui_contrib_views_pre_query($view) {
if ($view->build_type == 'page') {
context_ui_set('views', $view->name);
}
}
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();
$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;
}