-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtrapaloPlugin.php
139 lines (121 loc) · 4.27 KB
/
AtrapaloPlugin.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
<?php
/*
Plugin Name: AtrapaloPlugin
Plugin URI: http://www.atrapalo.com/
Description: Plugin with widget to search bookings in Atrapalo.com.
Author: victor.guardiola
Version: 1.0
Author URI: http://www.atrapalo.com/
*/
define('WPATR_VERSION', '0.1');
if (!defined('WPATR_PLUGIN_BASENAME'))
define('WPATR_PLUGIN_BASENAME', plugin_basename(__FILE__));
if (!defined('WPATR_PLUGIN_NAME'))
define('WPATR_PLUGIN_NAME', trim(dirname(WPATR_PLUGIN_BASENAME), '/'));
if (!defined('WPATR_PLUGIN_DIR'))
define('WPATR_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . WPATR_PLUGIN_NAME);
if (!defined('WPATR_PLUGIN_DB_OPTION'))
define('WPATR_PLUGIN_DB_OPTION', 'AtrapaloApi_options');
class WP_Widget_BusquedaAPI extends WP_Widget {
function WP_Widget_BusquedaAPI() {
$widget_ops = array('description' => __('Busqueda Hoteles en Atrapalo.com', 'atrapalo'));
$this->WP_Widget('Busqueda Atrapalo.com', __('Busqueda Atrapalo.com', 'atrapalo'), $widget_ops);
}
/**
*
* @param <type> $args
* @param <type> $instance
*/
function widget($args, $instance) {
$options = $this->get_options();
if((int)$options['api_page']) $action = get_page_link($options['api_page']);
if($action=='') $action="/resultados/";
include WPATR_PLUGIN_DIR . "/xhtml/widget.xhtml";
}
/**
*
* @param <type> $atts
* @param <type> $content
* @param <type> $code
*/
public function embedResult($atts, $content=null, $code="") {
require_once WPATR_PLUGIN_DIR . '/AtrapaloHotelesSearch.php';
$req = new AtrapaloHotelesSearch();
$req->doRequest($this->get_options(), $_POST);
$req->sendRequest();
$req->processRequest();
}
/**
*
*/
public function admin_menu() {
add_options_page('Atrapalo', 'Atrapalo', 8, basename(__FILE__),
array($this, 'handle_options'),
"http://www.atrapalo.com/favicon.ico");
}
/**
*
* @return array
*/
public function get_options() {
$options = array(
'api_user' => '',
'api_pass' => '',
'api_page' => '',
'api_domain' => 'atrapalo.com',
'api_num_results' => 20,
'api_max_results' => 300,
'api_pri_lang' => 'es_ES',
'api_sec_lang' => 'en_EN'
);
$saved = get_option(WPATR_PLUGIN_DB_OPTION);
if (!empty($saved)) {
foreach ($saved as $key => $option)
$options[$key] = $option;
}
if ($saved != $options) {
update_option(WPATR_PLUGIN_DB_OPTION, $options);
}
return $options;
}
/**
*
*/
function install() {
$this->get_options();
}
/**
*
*/
public function handle_options() {
if (isset($_POST['submitted'])) {
check_admin_referer('atrpalo-api-nonce');
$atts = array();
$atts['api_user'] = htmlspecialchars($_POST['api_user']);
$atts['api_pass'] = htmlspecialchars($_POST['api_pass']);
$atts['api_domain'] = htmlspecialchars($_POST['api_domain']);
$atts['api_page'] = (int) $_POST['api_page'];
$atts['api_num_results'] = (int) $_POST['api_num_results'] > 0 ? (int) $_POST['api_num_results'] : $atts['api_num_results'];
$atts['api_max_results'] = (int) $_POST['api_max_results'] > 0 ? (int) $_POST['api_max_results'] : $atts['api_max_results'];
$atts['api_pri_lang'] = $_POST['api_pri_lang'];
$atts['api_sec_lang'] = $_POST['api_sec_lang'];
update_option(WPATR_PLUGIN_DB_OPTION, $atts);
echo '<div class="updated fade"><p>Plugin settings saved.</p></div>';
}
$atts = $this->get_options();
$action_url = $_SERVER['REQUEST_URI'];
$paginasDisponibles = get_pages();
include(WPATR_PLUGIN_DIR . '/xhtml/AtrapaloAdminPage.php');
}
}
//Registramos el widget
add_action('widgets_init', 'widget_BusquedaAPI_init');
/**
*
*/
function widget_BusquedaAPI_init() {
register_widget('WP_Widget_BusquedaAPI');
$AtrapaloApi = new WP_Widget_BusquedaAPI();
add_action('admin_menu', array($AtrapaloApi, 'admin_menu'));
add_shortcode('atr_res', array($AtrapaloApi, 'embedResult'));
}