| 1 |
<?php |
<?php |
| 2 |
// $Id: $ |
// $Id: component.module,v 1.1.2.1 2008/11/12 20:53:11 crell Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 6 |
*/ |
*/ |
| 7 |
function component_menu($may_cache) { |
function component_menu() { |
| 8 |
$items = array(); |
$items = array(); |
| 9 |
if ($may_cache) { |
|
| 10 |
|
$items['node/%node/component'] = array( |
| 11 |
} |
'page callback' => 'component_ajax_get_node', |
| 12 |
else { |
'page arguments' => array(1), |
| 13 |
if (arg(0) == 'node' && is_numeric(arg(1))) { |
'access arguments' => array('access content'), |
| 14 |
// Add the ajax-component callback for nodes |
'type' => MENU_CALLBACK, |
| 15 |
$items[] = array( |
); |
| 16 |
'path' => 'node/' . arg(1) . '/get', |
$items['component/node/%node'] = array( |
| 17 |
'callback' => 'component_ajax_get_node', |
'page callback' => 'component_ajax_get_node', |
| 18 |
'callback arguments' => array(arg(1)), |
'page arguments' => array(2), |
| 19 |
'access' => user_access('access content'), |
'access arguments' => array('access content'), |
| 20 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 21 |
); |
); |
| 22 |
} |
|
| 23 |
elseif (arg(0) == 'component' && arg(1) == 'node' && is_numeric(arg(2))) { |
$items['component/block/%/%'] = array( |
| 24 |
// Add the ajax-component callback for nodes (yes, we allow it in both places) |
'page callback' => 'component_ajax_get_block', |
| 25 |
$items[] = array( |
'page arguments' => array(2, 3), |
| 26 |
'path' => 'component/node/' . arg(2), |
'access arguments' => array('access content'), |
| 27 |
'callback' => 'component_ajax_get_node', |
'type' => MENU_CALLBACK, |
| 28 |
'callback arguments' => array(arg(2)), |
); |
| 29 |
'access' => user_access('access content'), |
|
| 30 |
'type' => MENU_CALLBACK, |
if (module_exists('views')) { |
| 31 |
); |
$items['component/view/%'] = array( |
| 32 |
} |
'page callback' => 'component_ajax_get_view', |
| 33 |
elseif (arg(0) == 'component' && arg(1) == 'block' && arg(2) && arg(3)) { |
'page arguments' => array(2), |
| 34 |
// Add the ajax-component callback for blocks |
'access arguments' => array('access content'), |
| 35 |
$items[] = array( |
'type' => MENU_CALLBACK, |
| 36 |
'path' => 'component/block/' . arg(2) . '/' . arg(3), |
); |
| 37 |
'callback' => 'component_ajax_get_block', |
$items['component/viewform/%'] = array( |
| 38 |
'callback arguments' => array(arg(2), arg(3)), |
'page callback' => 'component_ajax_get_view_filter_form', |
| 39 |
'access' => user_access('access content'), |
'page arguments' => array(2), |
| 40 |
'type' => MENU_CALLBACK, |
'access arguments' => array('access content'), |
| 41 |
); |
'type' => MENU_CALLBACK, |
| 42 |
} |
); |
|
elseif (arg(0) == 'component' && arg(1) == 'view' && arg(2) && module_exists('views')) { |
|
|
// Add the ajax-component callback for views |
|
|
$i = 2; |
|
|
$parts = array(); |
|
|
while ($parts[] = arg($i++)); |
|
|
array_pop($parts); // The last item will be boolean false |
|
|
$items[] = array( |
|
|
'path' => 'component/view/' . implode('/', $parts), |
|
|
'callback' => 'component_ajax_get_view', |
|
|
'callback arguments' => $parts, |
|
|
'access' => user_access('access content'), |
|
|
'type' => MENU_CALLBACK, |
|
|
); |
|
|
} |
|
|
elseif (arg(0) == 'component' && arg(1) == 'viewform') { |
|
|
// Add the ajax-component callback for views filter forms |
|
|
$items[] = array( |
|
|
'path' => 'component/viewform/' . arg(2), |
|
|
'callback' => 'component_ajax_get_view_filter_form', |
|
|
'callback arguments' => array(arg(2)), |
|
|
'access' => user_access('access content'), |
|
|
'type' => MENU_CALLBACK, |
|
|
); |
|
|
} |
|
| 43 |
} |
} |
| 44 |
|
|
|
|
|
| 45 |
return $items; |
return $items; |
| 46 |
} |
} |
| 47 |
|
|
| 69 |
} |
} |
| 70 |
|
|
| 71 |
|
|
| 72 |
if(module_exists('views')) { |
/** |
| 73 |
/** |
* Output function for the 'views' content type. Outputs a views |
| 74 |
* Output function for the 'views' content type. Outputs a views |
* based on the view and display name. |
| 75 |
* based on the module and delta supplied in the configuration. |
* |
| 76 |
* |
* @param $view_name |
| 77 |
* @param $view_name |
* The name of the view to display |
| 78 |
* The name of the view to display |
* @param $display |
| 79 |
*/ |
* The name of the display on the specified view. |
| 80 |
//function component_get_view($view_name, $type, $override_url='', $args=array(), $pager_id=0, $nodes_per_page=0) { |
*/ |
| 81 |
function component_get_view($view_name) { |
function component_get_view($view_name, $display) { |
| 82 |
$args = func_get_args(); |
return views_embed_view($view_name, $display); |
| 83 |
$view_name = array_shift($args); |
} |
|
$view = views_get_view($view_name); |
|
|
|
|
|
if (!$view) { |
|
|
$output = t('No such view'); |
|
|
return $output; |
|
|
} |
|
|
|
|
|
$output = views_build_view('embed', $view, $args, $view->use_pager, $view->nodes_per_page); |
|
|
if ($output === FALSE) { |
|
|
$output = t('View has no data'); |
|
|
} |
|
| 84 |
|
|
| 85 |
return $output; |
/** |
| 86 |
} |
* Returns the rendered filter form for a specified view. |
| 87 |
|
*/ |
| 88 |
/** |
function component_get_view_filter_form($view_name) { |
| 89 |
* Returns the rendered filter form for a specified view |
$args = func_get_args(); |
| 90 |
* |
$view = views_get_view($view_name); |
| 91 |
*/ |
return views_theme('views_display_filters', $view); |
|
function component_get_view_filter_form($view_name) { |
|
|
$view = views_get_view($view_name); |
|
|
return views_theme('views_display_filters', $view); |
|
|
} |
|
| 92 |
} |
} |
| 93 |
|
|
| 94 |
if (module_exists('panels')) { |
/* |
| 95 |
function component_get_panel($did) { |
// I've no idea how this will work when Panels is actually done. :-) |
| 96 |
return panels_panels_page($did); |
function component_get_panel($did) { |
| 97 |
} |
return panels_panels_page($did); |
| 98 |
} |
} |
| 99 |
|
*/ |
| 100 |
|
|
| 101 |
/** |
/** |
| 102 |
* Returns the themed contents of a node |
* Returns the themed contents of a node. |
| 103 |
* |
* |
| 104 |
* @param $nid |
* @param $node |
| 105 |
* The node id of the node to display |
* The node object to display. |
| 106 |
* |
* |
| 107 |
*/ |
*/ |
| 108 |
function component_get_node($nid) { |
function component_get_node($node) { |
| 109 |
return node_show(node_load($nid), $cid); |
return node_show($node, 0); |
| 110 |
} |
} |
| 111 |
|
|
| 112 |
/* |
/* |
| 118 |
exit(); |
exit(); |
| 119 |
} |
} |
| 120 |
|
|
| 121 |
function component_ajax_get_node($nid) { |
function component_ajax_get_node($node) { |
| 122 |
print component_get_node($nid); |
print component_get_node($node); |
| 123 |
exit(); |
exit(); |
| 124 |
} |
} |
| 125 |
|
|