context_contrib.module in Context 6
File
context_contrib/context_contrib.module
View source
<?php
function context_contrib_context_conditions() {
$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_contrib_get_views(),
'#type' => 'checkboxes',
);
}
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',
);
}
return $items;
}
function context_contrib_context_reactions() {
$items = array();
if (module_exists('css_injector')) {
$items['css_injector'] = array(
'#title' => t('CSS injector'),
'#description' => t('Inject the selected css when this context is set.'),
'#options' => _context_contrib_get_css_injector(),
'#type' => 'checkboxes',
);
}
return $items;
}
function context_contrib_context_reaction($context) {
if (module_exists('css_injector')) {
_context_contrib_css_injector_response($context);
}
}
function context_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_set_by_condition('nodequeue', $qid->qid);
}
}
}
}
function context_contrib_views_pre_view($view, $args) {
switch ($view->display_handler->display->display_plugin) {
case 'page':
case 'calendar':
context_set_by_condition('views', $view->name);
if (!empty($view->current_display)) {
context_set_by_condition('views', "{$view->name}:{$view->current_display}");
}
break;
}
}
function _context_contrib_get_views() {
$enabled_views = array();
$views = views_get_all_views();
foreach ($views as $view) {
if (!isset($views[$view->name]->disabled) || !$views[$view->name]->disabled) {
$enabled_views[$view->name] = $view->name;
$displays = array();
foreach ($view->display as $id => $display) {
if ($display->display_plugin == 'page') {
$displays[$view->name . ":" . $id] = "-- {$display->display_title}";
}
}
if (count($displays) > 1) {
$enabled_views += $displays;
}
}
}
ksort($enabled_views);
return $enabled_views;
}
function _context_contrib_get_css_injector() {
$list = array();
foreach (_css_injector_load_rule() as $css_rule) {
$list[$css_rule['crid']] = $css_rule['title'];
}
ksort($list);
return $list;
}
function _context_contrib_css_injector_response($context) {
if (is_array($context->css_injector)) {
foreach ($context->css_injector as $crid) {
if ($css_rule = _css_injector_load_rule($crid)) {
drupal_add_css(file_create_path($css_rule['file_path']), 'module', $css_rule['media'], $css_rule['preprocess']);
}
}
}
else {
return;
}
}