t('Views'), '#description' => t('Set this context when displaying the page of one of these views.'), '#options' => _context_contrib_get_views(), '#type' => 'checkboxes', ); } // 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', ); } return $items; } /** * Implementation of hook_context_reactions(). */ function context_contrib_context_reactions() { $items = array(); // CSS Injector 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; } /** * Implementation of hook_context_reaction(). */ function context_contrib_context_reaction($context) { if (module_exists('css_injector')) { _context_contrib_css_injector_response($context); } } /** * Implementation of hook_nodeapi(). */ function context_contrib_nodeapi(&$node, $op, $teaser, $page) { if ($op == 'view' && $page && arg(0) == 'node') { // Implementation of context 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_set_by_condition('nodequeue', $qid->qid); } } } } /** * Implementation of hook_views_pre_view(). */ 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); // Set any contexts associated with the current display if (!empty($view->current_display)) { context_set_by_condition('views', "{$view->name}:{$view->current_display}"); } break; } } /** * Helper function to generate a list of database and module provided views. */ 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; // Provide more granular options for each page display $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; } /** * Helper function to generate a list of css_injector files. */ 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; } /** * Getter response function for css injector */ 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; } }