| 1 |
<?php
|
| 2 |
// $Id: context_ui_contrib.module,v 1.4 2008/08/05 00:31:49 yhahn Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_context_items()
|
| 6 |
*/
|
| 7 |
function context_ui_contrib_context_items() {
|
| 8 |
$items = array();
|
| 9 |
|
| 10 |
// Views
|
| 11 |
if (module_exists('views')) {
|
| 12 |
$items['views'] = array(
|
| 13 |
'#title' => t('Views'),
|
| 14 |
'#description' => t('Set this context when displaying the page of one of these views.'),
|
| 15 |
'#options' => _context_ui_contrib_get_views(),
|
| 16 |
'#type' => 'checkboxes',
|
| 17 |
'#context_ui' => 'setter',
|
| 18 |
);
|
| 19 |
}
|
| 20 |
|
| 21 |
// Nodequeue
|
| 22 |
if (module_exists('nodequeue')) {
|
| 23 |
$result = db_query("SELECT qid, title FROM {nodequeue_queue}");
|
| 24 |
$options = array();
|
| 25 |
while ($nq = db_fetch_object($result)) {
|
| 26 |
$options[$nq->qid] = $nq->title;
|
| 27 |
}
|
| 28 |
$items['nodequeue'] = array(
|
| 29 |
'#title' => t('Nodequeue'),
|
| 30 |
'#description' => t('Set this context when a node in the selected nodequeue(s) is viewed.'),
|
| 31 |
'#options' => $options,
|
| 32 |
'#type' => 'checkboxes',
|
| 33 |
'#context_ui' => 'setter',
|
| 34 |
);
|
| 35 |
}
|
| 36 |
|
| 37 |
// Outline
|
| 38 |
if (module_exists('outline')) {
|
| 39 |
$result = db_query("SELECT volume_id, title FROM {outline_volume}");
|
| 40 |
$options = array();
|
| 41 |
while ($vol = db_fetch_object($result)) {
|
| 42 |
$options[$vol->volume_id] = $vol->title;
|
| 43 |
}
|
| 44 |
$items['outline'] = array(
|
| 45 |
'#title' => t('Outline'),
|
| 46 |
'#description' => t('Set this context when a node in the selected volumes(s) is viewed.'),
|
| 47 |
'#options' => $options,
|
| 48 |
'#type' => 'checkboxes',
|
| 49 |
'#context_ui' => 'setter',
|
| 50 |
);
|
| 51 |
}
|
| 52 |
|
| 53 |
// CSS Injector
|
| 54 |
if (module_exists('css_injector')) {
|
| 55 |
$items['css_injector'] = array(
|
| 56 |
'#title' => t('CSS injector'),
|
| 57 |
'#description' => t('Inject the selected css when this context is set.'),
|
| 58 |
'#options' => _context_ui_contrib_get_css_injector(),
|
| 59 |
'#type' => 'checkboxes',
|
| 60 |
'#context_ui' => 'getter',
|
| 61 |
);
|
| 62 |
}
|
| 63 |
|
| 64 |
return $items;
|
| 65 |
}
|
| 66 |
|
| 67 |
/**
|
| 68 |
* Implementation of hook_context_getter().
|
| 69 |
*/
|
| 70 |
function context_ui_contrib_context_getter($context) {
|
| 71 |
if (module_exists('css_injector')) {
|
| 72 |
_context_ui_contrib_css_injector_response($context);
|
| 73 |
}
|
| 74 |
}
|
| 75 |
|
| 76 |
/**
|
| 77 |
* Implementation of hook_nodeapi().
|
| 78 |
*/
|
| 79 |
function context_ui_contrib_nodeapi(&$node, $op, $teaser, $page) {
|
| 80 |
if ($op == 'view' && $page && arg(0) == 'node') {
|
| 81 |
// Implementation of context_ui_set for nodequeue.
|
| 82 |
if (module_exists('nodequeue')) {
|
| 83 |
$result = db_query("SELECT qid FROM {nodequeue_nodes} WHERE nid = %d", $node->nid);
|
| 84 |
while($qid = db_fetch_object($result)) {
|
| 85 |
context_ui_set('nodequeue', $qid->qid);
|
| 86 |
}
|
| 87 |
}
|
| 88 |
|
| 89 |
// Implementation of context_ui_set for outline
|
| 90 |
if (module_exists('outline') && $vol = $node->volume_id) {
|
| 91 |
context_ui_set('outline', $vol);
|
| 92 |
}
|
| 93 |
}
|
| 94 |
}
|
| 95 |
|
| 96 |
/**
|
| 97 |
* Implementation of hook_views_pre_query().
|
| 98 |
*/
|
| 99 |
function context_ui_contrib_views_pre_view($display_id, $args) {
|
| 100 |
if ($display_id->type == 'Normal') {
|
| 101 |
context_ui_set('views', $display_id->name);
|
| 102 |
}
|
| 103 |
}
|
| 104 |
|
| 105 |
/**
|
| 106 |
* Helper function to generate a list of database and module provided views.
|
| 107 |
*/
|
| 108 |
function _context_ui_contrib_get_views() {
|
| 109 |
$enabled_views = array();
|
| 110 |
|
| 111 |
$views = views_get_all_views();
|
| 112 |
|
| 113 |
foreach ($views as $view) {
|
| 114 |
if (!isset($views[$view->name]->disabled) || !$views[$view->name]->disabled) {
|
| 115 |
$enabled_views[$view->name] = $view->name;
|
| 116 |
}
|
| 117 |
}
|
| 118 |
ksort($enabled_views);
|
| 119 |
return $enabled_views;
|
| 120 |
}
|
| 121 |
|
| 122 |
/**
|
| 123 |
* Helper function to generate a list of css_injector files.
|
| 124 |
*/
|
| 125 |
function _context_ui_contrib_get_css_injector() {
|
| 126 |
$list = array();
|
| 127 |
foreach (_css_injector_load_rule() as $css_rule) {
|
| 128 |
$list[$css_rule['crid']] = $css_rule['title'];
|
| 129 |
}
|
| 130 |
ksort($list);
|
| 131 |
return $list;
|
| 132 |
}
|
| 133 |
|
| 134 |
/**
|
| 135 |
* Getter response function for css injector
|
| 136 |
*/
|
| 137 |
function _context_ui_contrib_css_injector_response($context) {
|
| 138 |
if (is_array($context->css_injector)) {
|
| 139 |
foreach ($context->css_injector as $crid) {
|
| 140 |
if ($css_rule = _css_injector_load_rule($crid)) {
|
| 141 |
drupal_add_css(file_create_path($css_rule['file_path']), 'module', $css_rule['media'], $css_rule['preprocess']);
|
| 142 |
}
|
| 143 |
}
|
| 144 |
}
|
| 145 |
else {
|
| 146 |
return;
|
| 147 |
}
|
| 148 |
}
|