-
Notifications
You must be signed in to change notification settings - Fork 3
/
conjugador.php
95 lines (64 loc) · 2.94 KB
/
conjugador.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* Template Name: Conjugador
*
* @package wp-softcatala
*/
$url_api = get_option( 'api_conjugador' );
/* JS scripts */
wp_enqueue_script( 'sc-js-contacte', get_template_directory_uri() . '/static/js/contact_form.js', array('sc-js-main'), WP_SOFTCATALA_VERSION, true );
wp_enqueue_script( 'sc-js-typeahead', get_template_directory_uri() . '/static/js/typeahead.js', array('sc-js-main'), WP_SOFTCATALA_VERSION, true );
wp_enqueue_script( 'sc-js-conjugador', get_template_directory_uri() . '/static/js/conjugador/conjugador.js', array('sc-js-typeahead'), WP_SOFTCATALA_VERSION, true );
wp_enqueue_style( 'sc-css-conjugador', get_template_directory_uri() . '/static/css/conjugador.css', array('sc-css-main'),WP_SOFTCATALA_VERSION );
wp_localize_script( 'sc-js-conjugador', 'scajax', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'autocomplete_url' => $url_api . 'autocomplete/'
));
$verb = urldecode( get_query_var('verb') );
$infinitiu = urldecode( get_query_var('infinitiu') );
$url = urldecode( get_query_var('url') );
$lletra = get_query_var('lletra');
$content_title = 'Conjugador de verbs';
$title = '';
$description = '';
$canonical = '';
//Ads
$context_holder = array();
$context_holder['ads_container'] = true;
$show404 = false; // si no existeix el verb mostre 404 al final
if( ! empty ( $verb ) ) {
$conjugador = new SC_Conjugador();
$r = $conjugador->get_verb( $verb, $infinitiu, $url, false );
if($r){
$canonical = $r->canonical;
$title = $r->title;
$content_title = $r->content_title;
$description = $r->description;
$context_holder['cerca_result'] = $r->html;
}else{
$show404 = true; // Cal mostrar un 404
}
} else if ( ! empty ( $lletra ) ) {
$conjugador = new SC_Conjugador();
$r = $conjugador->get_lletra( $lletra );
$canonical = $r->canonical;
$title = $r->title;
$content_title = $r->content_title;
$description = $r->description;
$context_holder['cerca_result'] = $r->html;
}
$context_filterer = new SC_ContextFilterer( $context_holder );
$context_overrides = array( 'title' => $title, 'description' => $description, 'canonical' => $canonical );
$context = $context_filterer->get_filtered_context( $context_overrides, false );
$context['post'] = new TimberPost();
$context['verb'] = $verb;
$context['lletra'] = $lletra;
$context['description'] = $description;
$context['content_title'] = $content_title;
$context['sidebar_top'] = Timber::get_widgets('sidebar_top_recursos');
$context['sidebar_elements'] = array( 'static/ajudeu.twig', 'static/dubte_forum.twig', 'baixades.twig', 'links.twig' );
$context['sidebar_bottom'] = Timber::get_widgets('sidebar_bottom_recursos');
//Contact Form
$context['contact']['to_email'] = get_option('email_recursos');
if($show404) Timber::render( array( '404.twig' ), $context );
else Timber::render( array( 'conjugador.twig' ), $context );