12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646 |
- <?php
- /**
- * @file
- * This is the file description for Materiobasemod module.
- *
- * In this more verbose, multi-line description, you can specify what this
- * file does exactly. Make sure to wrap your documentation in column 78 so
- * that the file can be displayed nicely in default-sized consoles.
- */
- // define(MATERIO_SEARCH_API_RESULTS_PATH, 'explore');
- /**
- * Implements hook_permission().
- */
- function materio_search_api_permission() {
- return array(
- 'access to materio database' => 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.'),
- ),
- 'use materio advanced search' => array(
- 'title' => t('Use materio advanced search'),
- 'description' => t('Use materio advanced search.'),
- ),
- );
- }
- /**
- * 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 PROPERTIES
- $node_props = &$info['node']['properties'];
- $fields = msa_get_custom_onto_taxo_searchable_fields();
- foreach ($fields['termname'] as $field) {
- $node_props[$field['name']] = array(
- 'type'=>$field['type'],
- 'label'=> $field['label'],
- 'getter callback'=>$field['getter']
- );
- }
- foreach ($fields['tid'] as $field) {
- $node_props[$field['name']] = array(
- 'type'=>$field['type'],
- 'label'=> $field['label'],
- 'getter callback'=>$field['getter']
- );
- }
- // 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<text>',
- // '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<text>',
- // '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<text>',
- '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<text>',
- 'label'=> t('Manufacturers and distributors companies localised (dont addresse)'),
- 'getter callback'=>'materio_search_api_get_node_propertie_companie',
- );
- // TAXONOMIE TERMS PROPERTIES
- $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',
- );
- // $term_props['materio_search_api_term_property_name_translated'] = array(
- // 'label' => t("Term name translated"),
- // 'description' => t(""),
- // 'type' => 'text',
- // 'getter callback' => 'materio_search_api_term_property_name_translated',
- // );
- }
- function msa_get_custom_onto_taxo_searchable_fields(){
- for ($i=1; $i <= 5 ; $i++) {
- $fields_name['termname'][] = array(
- 'type' => 'text',
- 'name' => 'materio_search_api_onthologie_term_'.$i.'_text',
- 'label' => t('Main onthologie term '.$i. ' as text (+ synonyms)'),
- 'getter' => 'materio_search_api_get_onthologie_term_'.$i.'_text'
- );
- $fields_name['tid'][] = array(
- 'type' => 'text',
- 'name' => 'materio_search_api_onthologie_term_'.$i.'_tid',
- 'label' => t('Main onthologie term '.$i. ' as tid'),
- 'getter' => 'materio_search_api_get_onthologie_term_'.$i.'_tid'
- );
- }
- $fields_name['termname'][] = array(
- 'type'=>'list<text>',
- 'name' => 'materio_search_api_onthologie_term_others_text',
- 'label' => t('Others onthologie terms as text (+ synonyms)'),
- 'getter' => 'materio_search_api_get_taxonomy_terms_others_text'
- );
- $fields_name['tid'][] = array(
- 'type'=>'list<text>',
- 'name' => 'materio_search_api_onthologie_term_others_tid',
- 'label' => t('Others onthologie terms as tid'),
- 'getter' => 'materio_search_api_get_taxonomy_terms_others_tid'
- );
- return $fields_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;
- }
- /**
- * Taxonomy terms properties
- */
- function materio_search_api_term_property_dup_name($term){
- $lang = $term->language;
- return $term->name_field[$lang][0]['value'];
- }
- // function materio_search_api_term_property_name_translated($term){
- // if($term->vid == 4){
- // print_r(get_defined_vars());
- //
- // // print_r($term);
- //
- // $trans = module_exists('i18n_taxonomy')
- // ? i18n_taxonomy_term_name($term, 'fr')
- // : $term->name;
- //
- // print_r($trans);
- // print "\n";
- // }
- // }
- // ____ __ __
- // / __ )/ /___ _____/ /_______
- // / __ / / __ \/ ___/ //_/ ___/
- // / /_/ / / /_/ / /__/ ,< (__ )
- // /_____/_/\____/\___/_/|_/____/
- /**
- * 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
- );
- $blocks['mo_searchapi_advanced_search'] = array(
- 'info' => t('Materio search api advanced 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 advanced search')) {
- $block['subject'] = t('Search');
- $block['content'] = theme('materio_search_api_double_search_block', array());
- }else 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 'mo_searchapi_advanced_search':
- if (user_access('use materio advanced search')) {
- $block['subject'] = t('Advanced Search');
- $block['content'] = theme('materio_search_api_advanced_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);
- if (isset($args[0]) && $args[0] == "filters") {
- $path .= '/'.array_shift($args);
- }
- $is_explore = $path == 'explore' || $path == 'explore/filters';
- $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' => $is_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'),
- '#prefix' => '<div class="search-btn-wrapper">',
- '#suffix'=> '</div>'
- );
- // add a back to search/base home bouton if on explore/foo
- if ($path == 'explore' || $path == 'explore/filters' || $path == 'bookmarks' || $path == 'lists' ) {
- // buttons form container
- $form['rightcol'] = array(
- '#type' => 'container',
- );
- $link = l('<i class="fi-home"></i>', base_path().'actuality', array(
- 'html'=>true,
- 'attributes'=>array('class'=>'back-search-home')
- ));
- $form['rightcol']['actu'] = array(
- '#type' => 'markup',
- '#markup' => $link,
- //'<a href="'.base_path().'actuality" class="back-search-home"><i class="fi-home"></i></a>'
- );
- }
- 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'];
- }
- // ___ __ __ _____ __
- // / | ____/ / ______ _____ ________ ____/ / / ___/___ ____ ___________/ /_
- // / /| |/ __ / | / / __ `/ __ \/ ___/ _ \/ __ / \__ \/ _ \/ __ `/ ___/ ___/ __ \
- // / ___ / /_/ /| |/ / /_/ / / / / /__/ __/ /_/ / ___/ / __/ /_/ / / / /__/ / / /
- // /_/ |_\__,_/ |___/\__,_/_/ /_/\___/\___/\__,_/ /____/\___/\__,_/_/ \___/_/ /_/
- /**
- * materio_search_api_advanced_search_form()
- */
- function materio_search_api_advanced_search_form($form, &$form_state){
- // dsm($form_state, 'form_state');
- // dsm($form, 'form');
- // get vid from settings
- $vid = variable_get('msa-advancedsearchvocabulary', null);
- if($vid){
- $voc = taxonomy_vocabulary_load($vid);
- $voc_machinename = $voc->machine_name;
- // dsm($voc, "voc");
- $hidden_terms = variable_get('msa-hiddentaxoterms', array());
- // dsm($hidden_terms, 'hidden_terms');
- $values = isset($form_state['values']) ? $form_state['values'] : null;
- // dsm($values, "values");
- $args = arg();
- // dsm($args, 'args');
- // get the first elemt of url args
- $path = array_shift($args);
- if (isset($args[0]) && $args[0] == "filters") {
- $path .= '/'.array_shift($args);
- }
- // get the keywords from args and reconstruct the filter lines with default values
- $args_values = array();
- if($path == 'explore/filters' && $args[0] !== "ajax"){
- // WORKING WITH TIDS instead of term name
- $tids = explode("+", $args[0]);
- foreach ($tids as $key => $tid) {
- $term = taxonomy_term_load($tid);
- // dsm($term, $term->tid.' : '.$term->name);
- // get parents
- if(isset($term->tid)){
- $parents = taxonomy_get_parents_all($tid);
- // dsm($parents, 'parents');
- // build default values
- for ($p=count($parents)-1; $p >=0 ; $p--) {
- $args_values[$key][] = $parents[$p]->tid;
- }
- }
- }
- }
- // dsm($args_values, 'args_values');
- // TODO: show result count live
- // TODO: filter next select form item
- // define number of lines,
- // 1 by default
- // or from url arguments
- // or let it as it is if already chanched by ajax
- if(!isset($form_state['filterlines'])){
- if(count($args_values)){
- $form_state['filterlines'] = count($args_values);
- }else{
- $form_state['filterlines'] = 1;
- }
- }
- // dsm($form_state['filterlines'], "form_state['filterlines']");
- // filters form container
- $form['filters'] = array(
- '#type' => 'container',
- '#attributes' => array('class' => array("advancedsearch-filters")),
- '#prefix' => '<div id="advancedsearch-filters-wrapper">',
- '#suffix' => '</div>',
- );
- $form['filters']['filters-table'] = array(
- '#type' => 'container',
- '#attributes' => array('class' => array("advanced-search-form-table"))
- );
- // form headers
- // $form['filters']['filters-table']['headers'] = array(
- // '#type' => 'container',
- // '#attributes' => array('class' => array("advanced-search-form-headers")),
- // 'category' => array(
- // '#markup' => t("Category"),
- // '#prefix' => '<div>','#suffix' => '</div>',
- // ),
- // 'main' => array(
- // '#markup' => t("Main Filter"),
- // '#prefix' => '<div>','#suffix' => '</div>',
- // ),
- // 'child' => array(
- // '#markup' => t("Child Filter"),
- // '#prefix' => '<div>','#suffix' => '</div>',
- // )
- // );
- $trigger = FALSE;
- if (!empty($form_state['triggering_element']['#name'])) {
- $trigger = $form_state['triggering_element'];
- }
- $rmline = false;
- if ($trigger) {
- // dsm($form_state['triggering_element'], $form_state['triggering_element']['#name']);
- // dsm($values, 'form state values');
- // add a line if needed
- if($trigger['#name'] == 'addfilters'){
- $form_state['filterlines'] = $form_state['filterlines']+1;
- }
- // remove a line if needed
- if(strpos($trigger['#name'], 'rm-filter-') === 0){
- // $form_state['filterlines'] = $form_state['filterlines']+1;
- $rmline = $trigger['#return_value'];
- // dsm($rmline, "rmline");
- }
- }
- // build first level taxonomy tree and select options
- $taxotree = taxonomy_get_tree($vid, 0, 1, true);
- // $taxotree = msa_get_taxo_tree($vid, 0, 1);
- // dsm($taxotree, "taxotree");
- // return $form;
- foreach ($taxotree as $index => $term) {
- // TODO: get translated tag name
- if(!in_array($term->tid, $hidden_terms)){
- $level_0_ops[$term->tid] = $term->name;
- }
- }
- // build filters lines (ajax enabled)
- for ($l=0; $l < $form_state['filterlines']; $l++) {
- // if rmline this line,
- // continue the loop without creating the line
- if($l === $rmline){
- continue;
- }
- // if we are after the removed line,
- // create a second counter ($ll) to keep a continuous order for form items
- // and keep the current counter ($l) to retrieve de current values
- // if before removed line or no removed line at all, $l = $ll
- if($rmline !== false && $l >= $rmline){
- $ll = $l-1;
- }else{
- $ll = $l;
- }
- // dsm("l : ".$l." | ll : ".$ll);
- $form['filters']['filters-table']['filterline-'.$ll] = array(
- '#type' => 'container',
- '#attributes' => array('class' => array("filter-line"))
- );
- // get the default value
- // from from_state values if ajax
- // or from url args
- // or 0
- $default0 = null;
- if(isset($values['filter-'.$l.'-0']) && $values['filter-'.$l.'-0']){
- $default0 = $values['filter-'.$l.'-0'];
- }elseif(isset($args_values[$l][0])){
- $default0 = $args_values[$l][0];
- }
- // dsm($default0, "default 0");
- // form select element for first level
- $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-0'] = array(
- '#type' => 'select',
- '#options' => $level_0_ops,
- '#name' => 'filter-'.$ll.'-0',
- '#empty_option' => t("Choose a category"),
- // '#empty_values' => 0,
- '#default_value' => $default0,
- '#ajax' => array(
- 'callback' => 'materio_search_api_advanced_search_select_callback',
- 'wrapper' => 'advancedsearch-filters-wrapper',
- // 'progress'=>array('message'=>''),
- ),
- );
- // without this line, form api will mess with default values
- $form_state["input"]['filter-'.$ll.'-0'] = $default0;
- // add level 1 filter if level 0 chosen
- if(is_null($default0)){
- // $form['filters']['filterline-'.$ll]['filter-'.$ll.'-1']
- $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-1'] = array(
- '#markup' => t("Main Filter"),
- '#prefix' => '<div class="filter-markup"><span>',
- '#suffix' => '</span></div>',
- );
- // the definition of this markup appears twice, i may avoid that ...
- $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
- '#markup' => t("Child Filter"),
- '#prefix' => '<div class="filter-markup"><span>',
- '#suffix' => '</span></div>',
- );
- }else{
- // build second level taxonomy tree and select options
- $taxotree1 = taxonomy_get_tree($vid, $default0, 1, true);
- // dsm($taxotree1, 'taxotree1');
- $level_1_ops = array();
- foreach ($taxotree1 as $index => $term) {
- // TODO: get translated tag name
- // $term = taxonomy_term_load($tid);
- $level_1_ops[$term->tid] = $term->name;
- }
- // get the default value
- // from from_state values if ajax
- // or from url args
- // or 0
- $default1 = null;
- if(isset($values['filter-'.$l.'-1']) && $values['filter-'.$l.'-1']){
- $default1 = $values['filter-'.$l.'-1'];
- }elseif(isset($args_values[$l][1])){
- $default1 = $args_values[$l][1];
- }
- // dsm($default1, "default 1");
- // form select element for second level
- $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-1'] = array(
- '#type' => 'select',
- '#options' => $level_1_ops,
- '#name' => 'filter-'.$ll.'-1',
- '#empty_option' => t("Choose a main filter"),
- // '#empty_values' => 0,
- '#default_value' => $default1,
- '#ajax' => array(
- 'callback' => 'materio_search_api_advanced_search_select_callback',
- 'wrapper' => 'advancedsearch-filters-wrapper',
- ),
- );
- // without this line, form api will mess with default values
- $form_state["input"]['filter-'.$ll.'-1'] = $default1;
- // add level 2 filter if level 1 chosen
- if(is_null($default1)){
- $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
- '#markup' => t("Child Filter"),
- '#prefix' => '<div class="filter-markup"><span>',
- '#suffix' => '</span></div>',
- );
- }else{
- // build second level taxonomy tree and select options
- $taxotree2 = taxonomy_get_tree($vid, $default1, 1, true);
- if(!count($taxotree2)){
- $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
- '#markup' => t("No Child"),
- '#prefix' => '<div class="filter-markup"><span>',
- '#suffix' => '</span></div>',
- );
- }else{
- // $default2 = isset($args_values[$l][2]) ? $args_values[$l][2] : 0;
- $default2 = null;
- if(isset($values['filter-'.$l.'-2']) && $values['filter-'.$l.'-2']){
- $default2 = $values['filter-'.$l.'-2'];
- }elseif(isset($args_values[$l][2])){
- $default2 = $args_values[$l][2];
- }
- // dsm($default2, "default 2");
- $level_2_ops = array();
- foreach ($taxotree2 as $index => $term) {
- // TODO: get translated tag name
- $level_2_ops[$term->tid] = t($term->name);
- }
- // form select element for third level
- $form['filters']['filters-table']['filterline-'.$ll]['filter-'.$ll.'-2'] = array(
- '#type' => 'select',
- '#options' => $level_2_ops,
- '#name' => 'filter-'.$ll.'-2',
- '#empty_option' => t("Refine with a child filter"),
- // '#empty_values' => 0,
- '#default_value' => $default2,
- );
- // without this line, form api will mess with default values
- $form_state["input"]['filter-'.$ll.'-2'] = $default2;
- }
- }
- }
- // add remove the line button
- $form['filters']['filters-table']['filterline-'.$ll]['rm-filter-'.$ll] = array(
- '#type' => 'image_button',
- '#src' => drupal_get_path('module', 'materio_search_api') . '/images/rmfilter.png',
- '#title' => t('Remove this filter line'),
- '#name' => 'rm-filter-'.$ll,
- '#return_value' => $ll,
- '#executes_submit_callback' => false,
- '#ajax' => array(
- 'callback' => 'materio_search_api_advanced_search_rmline_callback',
- 'wrapper' => 'advancedsearch-filters-wrapper',
- // 'trigger_as' => array("name"=>"rmfilters".$l),
- ),
- // "#attributes" => array('class'=>array('rm-btn')),
- '#prefix'=> '<div class="rm-btn">', '#suffix'=> '</div>',
- );
- } // end of lines loop
- if($rmline !== false){
- $form_state['filterlines'] = $form_state['filterlines']-1;
- }
- // button to add a new line of criterias
- $form['filters']['addfilters'] = array(
- '#type' => 'image_button',
- '#src' => drupal_get_path('module', 'materio_search_api') . '/images/addfilter.png',
- '#title' => t('Add a filter line'),
- '#name' => "addfilters",
- '#return_value' => "add",
- '#ajax' => array(
- 'callback' => 'materio_search_api_advanced_search_addfilter_callback',
- 'wrapper' => 'advancedsearch-filters-wrapper',
- ),
- '#executes_submit_callback' => false,
- '#attributes' => array('class'=>array('add-filter'))
- );
- // buttons form container
- $form['rightcol'] = array(
- '#type' => 'container',
- "#attributes" => array('class'=>array('right-col')),
- );
- // add a back to search/base home bouton if on explore/foo
- if ($path == 'explore' || $path == 'explore/filters' || $path == 'bookmarks' || $path == 'lists' ) {
- $link = l('<i class="fi-home"></i>', base_path().'actuality', array(
- 'html'=>true,
- 'attributes'=>array('class'=>'back-search-home')
- ));
- $form['rightcol']['actu'] = array(
- '#type' => 'markup',
- '#markup' => $link,
- );
- }
- // submit the search
- $form['rightcol']['search'] = array(
- '#type' => 'image_button',
- '#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
- '#title' => t('Search'),
- '#name' => "search",
- '#return_value' => "search",
- '#prefix' => '<div class="search-btn-wrapper">',
- '#suffix'=> '</div>'
- );
- }else{
- $form['novoc'] = array(
- '#markup' => "Please choose a vocabulary to search from in materio search api settings"
- );
- }
- // dsm($form, 'form');
- return $form;
- }
- function msa_get_taxo_tree($vid, $parent, $depth){
- $query = new EntityFieldQuery();
- $query->entityCondition('entity_type', 'taxonomy_term')
- ->propertyCondition('vid', $vid);
- // ->propertyCondition('parent', $parent);
- // ->propertyCondition('status', 1);
- // ->entityCondition('bundle', $voc_machinename)
- $result = $query->execute();
- if (isset($result['taxonomy_term'])) {
- $terms = $result['taxonomy_term'];
- // At first we need to get field's id. If you already know field id, you can ommit this step
- // Get all fields attached to a given node type
- $fields = field_info_instances('taxonomy_term');
- // Get id of body field
- // $field_id = $fields['name']['field_id'];
- // Attach a field of selected id only to get value for it
- field_attach_load('taxonomy_term', $terms, FIELD_LOAD_CURRENT, array('field_id' => 'name'));
- // Get values of our node field
- // $output = field_get_items('node', $stories, 'field_story_image');
- }
- return $terms;
- }
- function materio_search_api_advanced_search_select_callback($form, &$form_state) {
- return $form['filters'];
- }
- function materio_search_api_advanced_search_addfilter_callback($form, &$form_state) {
- $commands = array();
- $commands[] = ajax_command_replace('#advancedsearch-filters-wrapper', render($form['filters']));
- $commands[] = array('command'=>'ajaxAfterAddedFilterLine');
- return array("#type"=>'ajax', "#commands"=>$commands);
- // return $form['filters'];
- }
- function materio_search_api_advanced_search_rmline_callback($form, &$form_state) {
- $commands = array();
- $commands[] = ajax_command_replace('#advancedsearch-filters-wrapper', render($form['filters']));
- $commands[] = array('command'=>'ajaxAfterRemovedFilterLine');
- return array("#type"=>'ajax', "#commands"=>$commands);
- // return $form['filters'];
- }
- function materio_search_api_advanced_search_form_validate($form, &$form_state){
- if($form_state['triggering_element']['#name'] == 'search'){
- // dsm($form, '$form');
- dsm($form_state, 'form_state');
- if (!isset($form_state['values']['filter-0-1']) || $form_state['values']['filter-0-1'] == '') {
- form_set_error('filters', 'Please choose at least 1 keyword.');
- }
- }
- }
- function materio_search_api_advanced_search_form_submit($form, &$form_state){
- // dsm($form_state, 'form_state');
- $values = $form_state['values'];
- $filterlines = isset($form_state['filterlines']) ? $form_state['filterlines'] : 0;
- // $keywords = array();
- // extract last tag of each lines
- for ($l=0; $l < $filterlines ; $l++) {
- for ($i=2; $i > 0 ; $i--) {
- if(isset($values['filter-'.$l.'-'.$i]) && $values['filter-'.$l.'-'.$i]){
- // $term = taxonomy_term_load($values['filter-'.$l.'-'.$i]);
- // $keywords[$term->tid] = '"'.$term->name.'"';
- // $tids[] = '"'.$values['filter-'.$l.'-'.$i].'"';
- $tids[] = $values['filter-'.$l.'-'.$i];
- continue 2;
- }else{
- continue;
- }
- }
- }
- // dsm($keywords, 'keywordstid');
- $keywords_str = implode("+", $tids);
- // dsm($keywords_str);
- $form_state['redirect'] = 'explore/filters/'.$keywords_str; //rawurlencode($keywords_str);
- }
- /**
- * 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_advanced_search_block' => array(
- 'arguments' => array(),
- 'template' => 'materio-search-api-advanced-search-block',
- 'path' => drupal_get_path('module', 'materio_search_api').'/templates',
- ),
- 'materio_search_api_double_search_block' => array(
- 'arguments' => array(),
- 'template' => 'materio-search-api-double-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_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_advanced_search_block();
- */
- function template_preprocess_materio_search_api_search_block(&$vars){
- // dsm($vars, '$vars');
- $vars['searchform'] = drupal_get_form("materio_search_api_search_form");
- }
- /**
- * template_preprocess_materiobase_advanced_search_block();
- */
- function template_preprocess_materio_search_api_advanced_search_block(&$vars){
- // dsm($vars, '$vars');
- $vars['searchform'] = drupal_get_form("materio_search_api_advanced_search_form");
- }
- /**
- * template_preprocess_materiobase_search_block();
- */
- function template_preprocess_materio_search_api_double_search_block(&$vars){
- // dsm($vars, '$vars');
- $vars['search_title'] = t("Text search");
- $vars['searchform'] = drupal_get_form("materio_search_api_search_form");
- $vars['advanced_search_title'] = t("Filtered search");
- $vars['advanced_searchform'] = drupal_get_form("materio_search_api_advanced_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 = '<div class="btn-group btn-group-vertical">';
- foreach ($entity_infos['node']['view modes'] as $viewmode => $value) {
- if(in_array($viewmode, $availableviewmodes)){
- $link = l(
- '<i class="icon-materio-viewmode-'.$viewmode.($active == $viewmode ? " active" : '').'"></i><span class="inner">'.$value['label'].'</span>',
- '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 .= '</div>';
- $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 .= '<br />';
- $perfoutput .= format_plural(
- $results['could results']['result count'],
- ' You could have found 1 result with a ',
- ' You could have found <strong>@count results</strong> 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.').'<br />';
- $perfoutput .= format_plural(
- $results['could results']['result count'],
- ' You could have found 1 result with a ',
- ' You could have found <strong>@count results</strong> 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 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 = '<div' . drupal_attributes($attributes) . '>' . "\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']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
- $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
- 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 .= '<div class="description">' . $element['#description'] . "</div>\n";
- }
- $output .= "</div>\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;
- }
- }
- }
- }
|