-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc-funnelback-search-client.php
156 lines (136 loc) · 4.5 KB
/
bc-funnelback-search-client.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/*
Plugin Name: Funnelback Search Client
Plugin URI: https://github.com/BellevueCollege/bc-funnelback-search-client
Description: Funnelback search client for BC Website
Author: Bellevue College Integration Team
Version: 1.0.3
Author URI: http://www.bellevuecollege.edu
GitHub Plugin URI: BellevueCollege/bc-funnelback-search-client
Text Domain: bcfunnelback
*/
defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
require_once('classes/class-funnelback-request.php');
require_once('classes/class-funnelback-display.php');
$fb_base_url = 'https://bellevuecollege-search.clients.us.funnelback.com/s';
$fb_config_default = array(
'query_peram' => 'txtQuery',
'site_peram' => 'site',
'engine_url' => "$fb_base_url/search.html",
'collection' => 'bellevuecollege-search',
'cookie_name' => 'user-id'
);
// Shortcode
function bcfunnelback_shortcode( $sc_config ) {
global $fb_config_default;
$sc_config = shortcode_atts( array(
'query_peram' => $fb_config_default['query_peram'],
'site_peram' => $fb_config_default['site_peram'],
'engine_url' => $fb_config_default['engine_url'],
'collection' => $fb_config_default['collection'],
'localstorage_key' => 'searchHistory',
'debug' => false
), $sc_config, 'bcfunnelback_shortcode' );
$request = new Funnelback_Request(
$sc_config['engine_url'],
$sc_config['collection'],
$_GET,
$sc_config['query_peram'],
$fb_config_default['cookie_name'],
);
$raw_results = $request->get_results();
$results_display = new Funnelback_Display(
$raw_results,
$sc_config['debug'],
$fb_config_default['cookie_name'],
);
return $results_display->display();
}
add_shortcode( 'bc-funnelback-search', 'bcfunnelback_shortcode' );
/**
* Enqueue Scripts and Styles
*/
function bcfunnelback_scripts() {
wp_register_style( 'bcfunnelback_style', plugin_dir_url( __FILE__ ) . 'css/funnelback.css', '1.0.2' );
wp_enqueue_style( 'bcfunnelback_style' );
//wp_enqueue_script( 'typeahead_script', 'https://stage-15-20-search.clients.funnelback.com/s/resources-global/thirdparty/typeahead-0.11.1/typeahead.bundle.min.js', array( 'jquery' ), '1.0.1', true );
//wp_enqueue_script( 'handlebars_script', 'https://stage-15-20-search.clients.funnelback.com/s/resources-global/thirdparty/handlebars-4.0.5/handlebars.min.js', array( 'jquery' ), '1.0.1', true );
//wp_enqueue_script( 'funnelback_script', 'https://stage-15-20-search.clients.funnelback.com/s/resources-global/js/funnelback.autocompletion-2.6.0.js', array( 'jquery' ), '1.0.1', true );
}
add_action( 'wp_enqueue_scripts', 'bcfunnelback_scripts' );
/**
* Add REST Routes for cart
*/
add_action( 'rest_api_init', function () {
register_rest_route( 'funnelback/v1', '/cart', array(
'methods' => 'GET',
'callback' => 'fb_relay_get',
) );
register_rest_route( 'funnelback/v1', '/cart', array(
'methods' => 'POST',
'callback' => 'fb_relay_post',
) );
register_rest_route( 'funnelback/v1', '/cart', array(
'methods' => 'PUT',
'callback' => 'fb_relay_put',
) );
register_rest_route( 'funnelback/v1', '/cart', array(
'methods' => 'DELETE',
'callback' => 'fb_relay_delete',
) );
} );
function fb_relay_get( $data ) {
global $fb_config_default;
$request = fb_relay( $data );
$raw_results = $request->get_results();
$results = new Funnelback_Display(
$raw_results,
false,
$fb_config_default['cookie_name'],
);
return $results->display_cart();
}
function fb_relay_post( $data ) {
global $fb_config_default;
$request = fb_relay( $data );
$raw_results = $request->post_request();
$results = new Funnelback_Display(
$raw_results,
false,
$fb_config_default['cookie_name'],
);
return $results->display_cart();
}
function fb_relay_put( $data ) {
global $fb_config_default;
$request = fb_relay( $data );
$raw_results = $request->put_request();
$results = new Funnelback_Display(
$raw_results,
false,
$fb_config_default['cookie_name'],
);
return $results->display_cart();
}
function fb_relay_delete( $data ) {
global $fb_config_default;
$request = fb_relay( $data );
$raw_results = $request->delete_request();
$results = new Funnelback_Display(
$raw_results,
false,
$fb_config_default['cookie_name'],
);
return $results->display_cart();
}
function fb_relay ( $data ) {
global $fb_config_default, $fb_base_url;
$request = new Funnelback_Request(
"$fb_base_url/cart.json",
$fb_config_default['collection'],
$data->get_params(),
$fb_config_default['query_peram'],
$fb_config_default['cookie_name'],
);
return $request;
}