array( 'title' => t('Access to materio database'), 'description' => t('Access to materio database.'), ), 'use materio search api' => array( 'title' => t('Use materio search api'), 'description' => t('Use materio search api.'), ), 'use materio search api for breves' => array( 'title' => t('Use materio search api for breves'), 'description' => t('Use materio search api for breves.'), ), 'use materio search api autocomplete' => array( 'title' => t('Use materio search api autocomplete'), 'description' => t('Use materio search api autocomplete.'), ), 'use materio search api viewmode selection' => array( 'title' => t('Use materio search api viewmode selection'), 'description' => t('Use materio search api viewmode selection.'), ), 'administer materio_search_api' => array( 'title' => t('administer Materio search api'), 'description' => t('Administer materio search api.'), ), 'use materio search api filters' => array( 'title' => t('use Materio search api filters'), 'description' => t('Use materio search api filters.'), ), ); } /** * Implements hook_menu(). */ function materio_search_api_menu() { $items = array(); $base = array( 'type' => MENU_CALLBACK, 'file' => 'materio_search_api.pages.inc', ); $items['admin/config/search/search_api/materiosearchapi'] = array( 'title' => 'Materio Search Api', 'page callback' => 'drupal_get_form', 'page arguments' => array('materio_search_api_settings'), 'access arguments' => array('administer materio_search_api'), 'file' => 'materio_search_api.admin.inc', 'type' => MENU_LOCAL_TASK, ); $items['materiosearchapi/autocomplete/dbselect'] = $base+array( 'access arguments' => array('use materio search api autocomplete'), 'page callback' => 'materio_search_api_autocomplete_dbselect', ); $items['materiosearchapi/autocomplete/searchapi'] = $base+array( 'access arguments' => array('use materio search api autocomplete'), 'page callback' => 'materio_search_api_autocomplete_searchapi', ); $items['explore'] = $base+array( // 'access arguments' => array('use materio search api'), 'access callback' => 'materio_search_api_access_search', 'page callback' => 'materio_search_api_results_search', 'title' => t('Explore'), //'page argument' => array(1,2,3), ); $items['actuality'] = $base+array( // 'access arguments' => array(), 'page callback' => 'materio_search_api_actuality', // 'page argument' => array(), 'access callback' => TRUE, ); $items['materiosearchapi/viewmode/change'] = $base+array( 'access arguments' => array('use materio search api viewmode selection'), 'page callback' => 'materio_search_api_viewmode_change', 'page argument' => array(3), ); return $items; } function materio_search_api_access_search(){ return true; // return user_access('use materio search api for breves') || user_access('use materio search api'); } /** * - - - - - - - - - - - - SOLR - - - - - - - - - - - - */ /** * Implements hook_search_api_data_type_info(). * * Declare our new type to Search API so it can be selected for a field. */ function materio_search_api_search_api_data_type_info() { return array( 'edge_n2_kw_text' => array( 'name' => t('Fulltext (partial matching)'), 'fallback' => 'text', 'prefix' => 'tem', 'always multiValued' => TRUE, ), 'edge_n2_kw_mapped_text' => array( 'name' => t('Fulltext without accents (partial matching)'), 'fallback' => 'text', 'prefix' => 'temmap', 'always multiValued' => TRUE, ), // 'term_tid' => array( // 'name' => t('Taxonomy term tid'), // 'fallback' => 'integer', // 'prefix' => 'im', // 'always multiValued' => TRUE, // ), ); } /** * Implements hook_search_api_solr_dynamic_field_info(). * * Tell Search API Solr how to index our new data type. */ function materio_search_api_search_api_solr_dynamic_field_info() { return array( 'edge_n2_kw_text' => array( 'prefix' => 'tem', 'always multiValued' => TRUE, ), 'edge_n2_kw_mapped_text' => array( 'prefix' => 'temmap', 'always multiValued' => TRUE, ), // 'term_tid' => array( // 'prefix' => 'im', // 'always multiValued' => TRUE, // ), ); } /** * hook_entity_property_info_alter(). * * define own fields * - main taxonomy terms, the purpose is to be able to attribute differente boost on serach api depending on term order * - companies infos (address) : retrieve for materiau content type the companie info from the tode node * */ function materio_search_api_entity_property_info_alter(&$info){ // dsm($info, 'hook_entity_property_info_alter | info'); // watchdog('materio solr', 'materio_search_api_entity_property_info_alter', array()); $node_props = &$info['node']['properties']; for ($i=1; $i <= 5 ; $i++) { $node_props['materio_search_api_onthologie_term_'.$i.'_text'] = array( 'type'=>'text', 'label'=> t('Main onthologie term '.$i. ' as text (+ synonyms)'), 'getter callback'=>'materio_search_api_get_onthologie_term_'.$i.'_text', ); $node_props['materio_search_api_onthologie_term_'.$i.'_tid'] = array( 'type'=>'text', 'label'=> t('Main onthologie term '.$i. ' as tid'), 'getter callback'=>'materio_search_api_get_onthologie_term_'.$i.'_tid', ); } $node_props['materio_search_api_onthologie_term_others_text'] = array( 'type'=>'list', 'label'=> t('Others onthologie terms as text (+ synonyms)'), 'getter callback'=>'materio_search_api_get_taxonomy_terms_others_text', ); $node_props['materio_search_api_onthologie_term_others_tid'] = array( 'type'=>'list', 'label'=> t('Others onthologie terms as tid'), 'getter callback'=>'materio_search_api_get_taxonomy_terms_others_tid', ); $node_props['materio_search_api_taglibres_text'] = array( 'type'=>'list', 'label'=> t('Tag libres terms as text (+ synonyms)'), 'getter callback'=>'materio_search_api_get_taglibres_terms_text', ); $node_materiau_props = &$info['node']['bundles']['materiau']['properties']; $node_materiau_props['materio_search_api_node_propertie_companie'] = array( 'type'=>'list', 'label'=> t('Manufacturers and distributors companies localised (dont addresse)'), 'getter callback'=>'materio_search_api_get_node_propertie_companie', ); $term_props = &$info['taxonomy_term']['properties']; $term_props['materio_search_api_term_property_dup_name'] = array( 'label' => t("Term name field dup"), 'description' => t("Duplicate the term name field to apply different filter in solr (remove accents for instance)"), 'type' => 'text', 'getter callback' => 'materio_search_api_term_property_dup_name', ); } /** * taxonomy propoerties as text + synonymes */ function materio_search_api_get_onthologie_term_1_text($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 0); } function materio_search_api_get_onthologie_term_2_text($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 1); } function materio_search_api_get_onthologie_term_3_text($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 2); } function materio_search_api_get_onthologie_term_4_text($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 3); } function materio_search_api_get_onthologie_term_5_text($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_text($item, "field_onthologie", 4); } function materio_search_api_get_taxonomy_terms_others_text($item){ // dsm($item, 'item'); $delta = 5; $terms = array(); while( isset($item->field_onthologie['und'][$delta]) ){ $terms[] = materio_search_api_get_taxo_term_field_text($item, "field_onthologie", $delta); $delta++; } return $terms; } function materio_search_api_get_taglibres_terms_text($item){ // dsm($item, 'item'); $delta = 0; $terms = array(); while( isset($item->field_tags_libres['und'][$delta]) ){ $terms[] = materio_search_api_get_taxo_term_field_text($item, "field_tags_libres", $delta); $delta++; } return $terms; } function materio_search_api_get_taxo_term_field_text($item, $field_name, $delta){ // dsm($item, 'item'); // dsm($delta, 'delta'); if(isset($item->{$field_name}['und'][$delta])){ // print '** item **'."\n"; // print_r($item); $term = taxonomy_term_load($item->{$field_name}['und'][$delta]['tid']); // use entity metadata wrappers as they are SMART $wrapper = entity_metadata_wrapper('taxonomy_term', $term); // print '** wrapper **'."\n"; // print_r($wrapper); // print "\n"; $keywords[] = $wrapper->language($item->language)->name_field->raw(); // print '** term_name **'."\n"; // print_r($term->name); // print "\n"; // print_r($term_name); // print "\n"; $synonymes = array(); foreach ($wrapper->language($item->language)->synonyms_synonym->value() as $index => $synonym) { // print '** synonym **'."\n"; // print_r($synonym); // print "\n"; $keywords[] = $synonym; } return implode(" ", $keywords); } return null; } /** * taxonomy properties as tid */ function materio_search_api_get_onthologie_term_1_tid($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 0); } function materio_search_api_get_onthologie_term_2_tid($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 1); } function materio_search_api_get_onthologie_term_3_tid($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 2); } function materio_search_api_get_onthologie_term_4_tid($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 3); } function materio_search_api_get_onthologie_term_5_tid($item){ // dsm($item, 'item'); return materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", 4); } function materio_search_api_get_taxonomy_terms_others_tid($item){ // dsm($item, 'item'); $delta = 5; $terms = array(); while( isset($item->field_onthologie['und'][$delta]) ){ $terms[] = materio_search_api_get_taxo_term_field_tid($item, "field_onthologie", $delta); $delta++; } return $terms; } function materio_search_api_get_taxo_term_field_tid($item, $field_name, $delta){ // dsm($item, 'item'); // dsm($delta, 'delta'); $tid = null; if(isset($item->{$field_name}['und'][$delta])) $tid = $item->{$field_name}['und'][$delta]['tid']; // print 'tid = '.$tid."\n"; return $tid; } /** * */ function materio_search_api_get_node_propertie_companie($item){ // dsm($item, '$item'); $lang = "fr";//$item->language; $languages = language_list(); global $language; $language = $languages[$lang]; $cies = array(); $cie_fields = array("field_company_fab", "field_company_distrib"); foreach ($cie_fields as $cie_field_name) { $delta = 0; while( isset($item->{$cie_field_name}['und'][$delta]) ){ $tid = $item->{$cie_field_name}['und'][$delta]['tid']; $cie_term = taxonomy_term_load($tid); if($cie_node = company_get_tode_node($cie_term)){ $cie_node->language = $lang; $cie_view = node_view($cie_node, "full", $lang); $cie_rendered = rip_tags(drupal_render($cie_view)); // dsm($cie_rendered, 'cie_rendered'); $cies[] = $cie_rendered; } $delta++; } } return $cies; } function company_get_tode_node($term){ if(module_exists('tode')) if( $entitys = tode_get_nids_from_term($term)) if(isset($entitys['node'])) foreach ($entitys['node'] as $nid => $n) return node_load($nid); return false; } function rip_tags($string) { // ----- remove HTML TAGs ----- $string = preg_replace ('/<[^>]*>/', ' ', $string); // ----- remove control characters ----- $string = str_replace("\r", '', $string); // --- replace with empty space $string = str_replace("\n", ' ', $string); // --- replace with space $string = str_replace("\t", ' ', $string); // --- replace with space // $string = str_replace(" ", ' ', $string); // --- replace with space // $string = str_replace("'", '\'', $string); // --- replace with space // ----- remove multiple spaces ----- $string = trim(preg_replace('/ {2,}/', ' ', $string)); // ----- remove html entities preg_match_all('/&[^;]+;/', $string, $entities); foreach ($entities[0] as $entity) { $string = str_replace($entity, mb_convert_encoding($entity, 'UTF-8', 'HTML-ENTITIES'), $string); } return $string; } function materio_search_api_term_property_dup_name($term){ $lang = $term->language; return $term->name_field[$lang][0]['value']; } /** * - - -- - - - - - - blocks - - - - - - - - - - - * */ /** * Implements hook_block_info(). */ function materio_search_api_block_info() { $blocks['materio_search_api_search'] = array( 'info' => t('Materio search api search'), 'cache' => DRUPAL_NO_CACHE ); # NOT USED $blocks['materio_search_api_viewmode'] = array( 'info' => t('Materio search api view mode selection'), 'cache' => DRUPAL_NO_CACHE ); // $blocks['materio_search_api_filters'] = array( // 'info' => t('Materio search api filters'), // 'cache' => DRUPAL_NO_CACHE // ); return $blocks; } /** * Implements hook_block_view(). */ function materio_search_api_block_view($delta = '') { // This example comes from node.module. Note that you can also return a // renderable array rather than rendered HTML for 'content'. $block = array(); switch ($delta) { case 'materio_search_api_search': if (user_access('use materio search api') || user_access('use materio search api for breves')) { $block['subject'] = t('Search'); $block['content'] = theme('materio_search_api_search_block', array()); } break; case 'materio_search_api_viewmode': // restrict display on node page for materiau and breve $block_is_visible = true; $q = parse_url($_GET['q']); $parts = explode('/', $q['path']); if($parts[0] == "node"){ $node = node_load($parts[1]); $block_is_visible = in_array($node->type, array('materiau','breve')) ? true : false; } if (user_access('use materio search api viewmode selection') && $block_is_visible) { $block['subject'] = t('View mode'); $block['content'] = theme('materio_search_api_select_viewmode_block', array()); } break; // case 'materio_search_api_filters': // if (user_access('use materio search api filters')) { // $block['subject'] = t('Filters'); // $block['content'] = theme('materio_search_api_filters_block', array()); // } // break; } return $block; } /** * Implements hook_entity_info_alter(). */ function materio_search_api_entity_info_alter(&$entity_info) { $entity_info['node']['view modes']['cardsmall'] = array( 'label' => t('Small cards'), 'custom settings' => TRUE, ); $entity_info['node']['view modes']['cardmedium'] = array( 'label' => t('Medium cards'), 'custom settings' => TRUE, ); $entity_info['node']['view modes']['cardbig'] = array( 'label' => t('Big cards'), 'custom settings' => TRUE, ); $entity_info['node']['view modes']['cardfull'] = array( 'label' => t('Full cards'), 'custom settings' => TRUE, ); } /** * Implements hook_node_view_alter(). */ function materio_search_api_node_view_alter(&$build) { $node = $build['#node']; if (arg(0) == 'node' && arg(1) == $node->nid) { // dsm($build, 'build'); global $user; $viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full'); // dsm($viewmode, 'viewmode'); $node = $build['#node']; if($build['#view_mode'] != $viewmode && $build['#view_mode'] != "bookmark" & in_array($node->type, array('breve', 'materiau'))){ $build = node_view($node, $viewmode); } } } /** * Implements hook_node_view(). */ function materio_search_api_node_view($node, $view_mode, $langcode) { if (in_array($view_mode, array('cardsmall','cardmedium', 'cardbig', 'cardfull'))) { # PRINT 7.1 // print_node_view($node, 'full'); // print_pdf_node_view($node, 'full'); # PRINT 7.2-beta // call for hook_node_view of print module to insert link print_ui_node_view($node, 'full'); // dsm($node, 'node'); } } /** * materiobase_search_form() */ function materio_search_api_search_form($form, &$form_state){ // dsm($form_state, 'form_state'); // dsm($form, 'form'); global $user; $form = array(); $args = arg(); $path = array_shift($args); // dsm($args, 'args'); if($args[0] == "advanced"){ $advanced = true; array_shift($args); // dsm($args, 'shifted arsg'); // foreach ($args as $arg) { // $typed[] = $arg;//(integer)$arg; // } $keys = implode(' +', $args); }else{ $keys = implode('/', $args); } if(user_access('use materio search api autocomplete')){ // use materio search api autocomplete | use materio search api filters $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'materiau') ->propertyCondition('status', 1); $count = $query->count()->execute(); $default_value = t("search among our !fiches cards", array("!fiches"=>$count)); }else{ $default_value = ''; } $form['searchfield'] = array( '#type' => 'textfield', '#default_value' => $path == 'explore' ? $keys : $default_value, // TODO: set the search page path global or a variable in settings '#autocomplete_path' => 'materiosearchapi/autocomplete/searchapi', //'#autocomplete_path' => 'materiosearchapi/autocomplete/dbselect', '#size' => 30, '#maxlength' => 1024, '#attributes' => array("default"=>$default_value), ); if(user_access('use materio search api 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) { $bundles_options[$bundle] = $bundle; $default_bundles[] = $bundle; } $user_bundles_filter = isset($user->data['materiosearchapi_bundlesfilter']) ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles; $form['bundles_filter'] = array( '#type'=>'checkboxes', '#options' => $bundles_options, '#default_value' => $user_bundles_filter, // '#attributes' => array('class'=>array('btn-group')), ); } $form['create'] = array( '#type' => 'image_button', '#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png', '#value' => t('Search'), ); return $form; } function materio_search_api_search_form_validate($form, &$form_state){ // dsm($form, '$form'); // dsm($form_state, '$form_state'); // dsm(strlen($form_state['values']['searchfield'])); if (strlen(trim($form_state['values']['searchfield'])) <= 1) { form_set_error('searchfield', 'Please enter at least 2 characters keyword.'); } } function materio_search_api_search_form_submit($form, &$form_state){ // dsm($form_state, 'form_state'); global $user; if(user_access('use materio search api filters')){ foreach($form_state['values']['bundles_filter'] as $bundle => $value) if($value) $bundles[] = $bundle; # if no filter checked we checked them all by default if(!isset($bundles)) foreach($form_state['values']['bundles_filter'] as $bundle => $value) $bundles[] = $bundle; }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) { $bundles[] = $bundle; } } user_save($user, array("data"=>array('materiosearchapi_bundlesfilter' => $bundles))); $form_state['redirect'] = 'explore/'.$form_state['values']['searchfield']; } /** * viewmode */ function _materio_search_api_change_viewmode($vm){ // dsm($vm, '_materio_search_api_change_viewmode'); 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'); } return $rep; } /** * - - - - - - - - - - - - THEME - - - - - - - - - - - - */ /** * Implements hook_theme(). */ function materio_search_api_theme($existing, $type, $theme, $path) { return array( 'materio_search_api_search_block' => array( 'arguments' => array(), 'template' => 'materio-search-api-search-block', 'path' => drupal_get_path('module', 'materio_search_api').'/templates', ), 'materio_search_api_select_viewmode_block' => array( 'arguments' => array(), 'template' => 'materio-search-api-select-viewmode-block', 'path' => drupal_get_path('module', 'materio_search_api').'/templates', ), // 'materio_search_api_filters_block' => array( // 'arguments' => array(), // 'template' => 'materio-search-api-filters-block', // 'path' => drupal_get_path('module', 'materio_search_api').'/templates', // ), 'materio_search_api_results' => array( 'arguments' => array(), 'template' => 'materio-search-api-results', 'path' => drupal_get_path('module', 'materio_search_api').'/templates', 'variables' => array( 'index' => NULL, 'results' => array('result count' => 0), 'items' => array(), 'view_mode' => 'teaser', 'keys' => '', // 'page_machine_name' => NULL, 'spellcheck' => NULL, 'pager' => NULL, ), ), // 'materio_search_api_performance' => array( // 'render element' => 'element', // ), 'materio_search_api_actuality' => array( 'template' => 'materio-search-api-actuality', 'path' => drupal_get_path('module', 'materio_search_api').'/templates', 'arguments' => array( 'items' => array(), 'view_mode' => "teaser", 'pager' => NULL, 'count' => 0, ) ), 'materio_search_api_advanced_search_block' => array( 'template' => 'materio-search-api-advanced-search-block', 'path' => drupal_get_path('module', 'materio_search_api').'/templates', 'arguments' => array(), ), 'materio_search_api_form_element' => array( 'render element' => 'element', ), ); } /** * Implements theme for rendering search-performance */ // function theme_materio_search_api_performance($variables) { // $element = array_shift($variables); // return $element['#markup']; // } /** * template_preprocess_materiobase_search_block(); */ function template_preprocess_materio_search_api_search_block(&$vars){ // dsm($vars, '$vars'); $vars['searchform'] = drupal_get_form("materio_search_api_search_form"); } function template_preprocess_materio_search_api_select_viewmode_block(&$vars){ global $user; $active = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full'); $availableviewmodes = variable_get('availableviewmodes', -1); // dsm($availableviewmodes); $entity_infos = entity_get_info(); // dsm($entity_infos, 'entity_infos'); $content = '
'; foreach ($entity_infos['node']['view modes'] as $viewmode => $value) { if(in_array($viewmode, $availableviewmodes)){ $link = l( ''.$value['label'].'', 'materiosearchapi/viewmode/change/'.$viewmode, array( 'query' => drupal_get_destination(), 'html' => true, 'attributes' => array( 'class' => array( 'viewmode-link', 'viewmode-'.$viewmode, $active == $viewmode ? " active" : '' ), 'rel' => $viewmode ) ) ); $content .= $link; } } $content .= '
'; $vars['content'] = $content; } // function template_preprocess_materio_search_api_filters_block(&$vars){ // $index_machine_name = variable_get('mainsearchindex', -1); // $index = search_api_index_load($index_machine_name); // dsm($index, 'index'); // // $entity_infos = entity_get_info($index->item_type); // // dsm($entity_infos, 'entity_infos'); // $indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles']; // dsm($indexed_bundles, 'indexed_bundles'); // $vars['content'] = drupal_get_form('materio_search_api_filters_form', $indexed_bundles); // } // function materio_search_api_filters_form($form, $form_state, $bundles){ // $form = array(); // dsm($bundles, 'bundles'); // foreach ($bundles as $bundle) { // $form[$bundle . '_filter'] = array( // '#type'=>'checkbox', // '#default_value' => -1, // '#title' => $bundle, // ); // } // return $form; // } /** * Function for preprocessing the variables for the search_api_page_results * template. * * @param array $variables * An associative array containing: * - $index: The index this search was executed on. * - $results: An array of search results, as returned by * SearchApiQueryInterface::execute(). * - $keys: The keywords of the executed search. * * @see materio-search-api-results.tpl.php */ function template_preprocess_materio_search_api_results(array &$vars) { // dsm($vars, 'vars'); $results = $vars['results']; if(isset($results['result count'])){ $vars['result_count'] = $results['result count']; $vars['sec'] = round($results['performance']['complete'], 3); $vars['keywords'] = $vars['keys']; if(isset($results['breves count'])){ // for free users // dsm("free users"); $vars['perfascard'] = true; $perfoutput = format_plural( $results['breves count'], 'The search found 1 news ', 'The search found @count news ' ); $perfoutput .= format_plural( $vars['result_count'] - $results['breves count'], 'with 1 associated matter.', 'with @count associated matters.' ); $perfoutput .= '
'; $perfoutput .= format_plural( $results['could results']['result count'], ' You could have found 1 result with a ', ' You could have found @count results with a ' ); $perfoutput .= l(t('full access to materiO\'.'), 'node/11187'); $perfoutput .= l(t('Pricing'), 'node/11187', array("attributes"=>array("class"=>array('button')))); $vars['search_performance'] = $perfoutput; }else{ // for members $vars['perfascard'] = false; // $vars['search_performance'] = format_plural( // // $results['result count'], // $vars['result_count'], // 'The search found 1 result ', // 'The search found @count results ' // ) $vars['search_performance'] = t('The search found @count result(s) with keywords @keys.', array( "@count"=>$vars['result_count'], "@keys"=>$vars['keywords']) ); // TODO indicate how many materials and how many news // $vars['search_performance'] = t('The search found @count result(s) with keywords @keys. @mat materials and @new news.', array( // "@count"=>$vars['result_count'], // "@keys"=>$vars['keywords'], // "@mat"=>4, // "@new"=>7) // ); } }else{ //for anonymous $vars['perfascard'] = true; $perfoutput = t('You can\'t access to the materiO\' search tool without an account.').'
'; $perfoutput .= format_plural( $results['could results']['result count'], ' You could have found 1 result with a ', ' You could have found @count results with a ' ); $perfoutput .= l(t('full access to materiO\'.'), 'node/11187'); $perfoutput .= l(t('Pricing'), 'node/11187', array("attributes"=>array("class"=>array('button')))); $vars['search_performance'] = $perfoutput; } //dsm($vars, '$vars'); } function template_preprocess_materio_search_api_actuality(&$vars){ // dsm($vars, 'template_preprocess_materio_search_api_actuality | vars'); // $vars['actualities_infos'] = t('Actualities by materiO\''); $vars['actualities_infos'] = t(''); } function template_preprocess_materio_search_api_advanced_search_block(&$vars){ // dsm($vars, "vars"); $vars['searchform'] = drupal_get_form("materio_search_api_advanced_search_form"); } function theme_materio_search_api_form_element($variables) { // dsm($variables, 'variables'); $element = &$variables['element']; // This function is invoked as theme wrapper, but the rendered form element // may not necessarily have been processed by form_builder(). $element += array( '#title_display' => 'before', ); // Add element #id for #type 'item'. if (isset($element['#markup']) && !empty($element['#id'])) { $attributes['id'] = $element['#id']; } // Add element's #type and #name as class to aid with JS/CSS selectors. $attributes['class'] = array('form-item'); if (!empty($element['#type'])) { $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-'); } if (!empty($element['#name'])) { $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => '')); } // Add a class for disabled elements to facilitate cross-browser styling. if (!empty($element['#attributes']['disabled'])) { $attributes['class'][] = 'form-disabled'; } # adding element class to wrapper foreach ($element['#attributes']['class'] as $value) { $attributes['class'][] = $value; } foreach ($element['#attributes'] as $attr => $value) { if(!in_array($attr, array('class', 'multiple', 'id', 'type', 'name'))){ $attributes[$attr] = $value; } } $output = '' . "\n"; // If #title is not set, we don't display any label or required marker. if (!isset($element['#title'])) { $element['#title_display'] = 'none'; } $prefix = isset($element['#field_prefix']) ? '' . $element['#field_prefix'] . ' ' : ''; $suffix = isset($element['#field_suffix']) ? ' ' . $element['#field_suffix'] . '' : ''; switch ($element['#title_display']) { case 'before': case 'invisible': $output .= ' ' . theme('form_element_label', $variables); $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; case 'after': $output .= ' ' . $prefix . $element['#children'] . $suffix; $output .= ' ' . theme('form_element_label', $variables) . "\n"; break; case 'none': case 'attribute': // Output no label and no required marker, only the children. $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; } if (!empty($element['#description'])) { $output .= '
' . $element['#description'] . "
\n"; } $output .= "\n"; return $output; } /** * - - - - - - - - - - - - SEARCH API PAGE - - - - - - - - - - - - */ /** * Implements hook_block_view_alter(). */ function materio_search_api_block_view_alter(&$data, $block) { // this alter prepopulate the search form provide by search_api_page if ($block->module == 'search_api_page') { $page = search_api_page_load($block->delta); $item = menu_get_item(); if (isset($page->path) && $page->path == $item['path']) { $keys = arg(count(arg(NULL, $page->path))); if ($keys) { $data['content']['keys_' . $page->id]['#default_value'] = $keys; $data['content']['keys_' . $page->id]['#value'] = $keys; } } } }