160 lines
4.1 KiB
PHP
160 lines
4.1 KiB
PHP
<?php
|
|
|
|
|
|
function materio_search_api_ajax_search($keys, $page = 0){
|
|
$debug = false;
|
|
global $user;
|
|
// TODO: set research path configurable
|
|
$search_path = "explore";
|
|
|
|
# content type filter s
|
|
// $types = $_GET['types'];
|
|
if(isset($_GET['types'])){
|
|
# if user have access to filters;
|
|
|
|
foreach($_GET['types'] as $type => $value)
|
|
if($value == 'true')
|
|
$active_types[] = $type;
|
|
|
|
// if no filter checked we checked them all by default
|
|
if(!isset($active_types))
|
|
foreach($_GET['types'] as $type => $value)
|
|
$active_types[] = $type;
|
|
}else{
|
|
# if user have no access to filters
|
|
$index = search_api_index_load(variable_get('mainsearchindex', -1));
|
|
$indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
|
foreach ($indexed_bundles as $bundle) {
|
|
$active_types[] = $bundle;
|
|
}
|
|
}
|
|
|
|
user_save($user, array("data"=>array('materiosearchapi_bundlesfilter' => $active_types)));
|
|
|
|
# execute search
|
|
$_GET['page'] = $page;
|
|
|
|
$path = $search_path . '/' . $keys ;//. ($page ? '?page='.$page : '');
|
|
// dsm($menuhandler, 'menuhandler');
|
|
|
|
// check if request is ajax, if not rediret to search_api_page page with right keys
|
|
if (!$debug && (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')) {
|
|
drupal_goto($path, array(), 301);
|
|
exit ;
|
|
}
|
|
|
|
// get results
|
|
menu_set_active_item($path);
|
|
$return = menu_execute_active_handler($path, FALSE);
|
|
|
|
//dsm($return, '$return');
|
|
|
|
if (is_int($return)) {
|
|
switch ($return) {
|
|
case MENU_NOT_FOUND :
|
|
drupal_add_http_header('Status', '404 Not Found');
|
|
break;
|
|
case MENU_ACCESS_DENIED :
|
|
drupal_add_http_header('Status', '403 Forbidden');
|
|
break;
|
|
case MENU_SITE_OFFLINE :
|
|
drupal_add_http_header('Status', '503 Service unavailable');
|
|
break;
|
|
}
|
|
} elseif (isset($return)) {
|
|
|
|
if (is_array($return)) {
|
|
$return = drupal_render($return);
|
|
}
|
|
|
|
$rep = array(
|
|
// 'id'=>$id,
|
|
'keys'=>$keys,
|
|
'search_path'=>$search_path,
|
|
'return'=>$return,
|
|
'active_types'=>$active_types,
|
|
'title' => drupal_get_title(),
|
|
);
|
|
|
|
if ($debug) {
|
|
dsm($rep, 'rep');
|
|
return "debug display";
|
|
}else{
|
|
drupal_json_output($rep);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function materio_search_api_ajax_viewmode_change($vm){
|
|
// dsm($vm);
|
|
|
|
// global $user;
|
|
// // dsm($user, 'user');
|
|
|
|
// $entity_infos = entity_get_info();
|
|
// // dsm($entity_infos, 'entity_infos');
|
|
|
|
// if (in_array($vm, variable_get('availableviewmodes', array()))) {
|
|
// user_save($user, array("data"=>array('materiosearchapi_viewmode' => $vm)));
|
|
// $rep = array('statut'=>'saved');
|
|
// }else{
|
|
// $rep = array('statut'=>'viewmode not allowed');
|
|
// }
|
|
$_GET['page'] = 0;
|
|
$rep = _materio_search_api_change_viewmode($vm);
|
|
|
|
drupal_json_output($rep);
|
|
}
|
|
|
|
|
|
function materio_search_api_ajax_actuality($page = 0){
|
|
$_GET['page'] = $page;
|
|
|
|
$path = 'actuality';
|
|
|
|
// check if request is ajax, if not rediret to search_api_page page with right keys
|
|
if (!$debug && (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')) {
|
|
drupal_goto($path, array(), 301);
|
|
exit ;
|
|
}
|
|
|
|
// get results
|
|
menu_set_active_item($path);
|
|
$return = menu_execute_active_handler($path, FALSE);
|
|
|
|
//dsm($return, '$return');
|
|
|
|
if (is_int($return)) {
|
|
switch ($return) {
|
|
case MENU_NOT_FOUND :
|
|
drupal_add_http_header('Status', '404 Not Found');
|
|
break;
|
|
case MENU_ACCESS_DENIED :
|
|
drupal_add_http_header('Status', '403 Forbidden');
|
|
break;
|
|
case MENU_SITE_OFFLINE :
|
|
drupal_add_http_header('Status', '503 Service unavailable');
|
|
break;
|
|
}
|
|
} elseif (isset($return)) {
|
|
|
|
if (is_array($return)) {
|
|
$return = drupal_render($return);
|
|
}
|
|
|
|
$rep = array(
|
|
'return'=>$return,
|
|
'title' => drupal_get_title(),
|
|
);
|
|
|
|
if ($debug) {
|
|
dsm($rep, 'rep');
|
|
return "debug display";
|
|
}else{
|
|
drupal_json_output($rep);
|
|
}
|
|
}
|
|
} |