/
s4u-endomondo-challenges.php
97 lines (86 loc) · 2.84 KB
/
s4u-endomondo-challenges.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
<?php
/**
* @package S4U Endomondo Challenges
* @version 1.0.0
*/
/*
Plugin Name: S4U Endomondo Challenges
Plugin URI: https://solution4u.nl/wordpress-plug-in-endomondo-challenges/
Description: Show the challenge(s) you accepted on Endomondo on your website.
Author: ing. Dirk Hornstra
Version: 1.0.0
Author URI: https://solution4u.nl/
*/
require('s4u-endomondo-challenges-html.php');
$adminHandler = null;
if (is_admin()) {
require('s4u-endomondo-challenges-admin.php');
if (isset($_POST['admin_action'])) {
$adminHandler = new S4U_Endomondo_Challenges_Admin();
$adminHandler->ProcessPost($_POST['admin_action']);
}
}
else {
if (isset($_GET['cron']) && ($_GET['cron']=='update-endomondo')) {
require('s4u-endomondo-challenges-admin.php');
$adminHandler = new S4U_Endomondo_Challenges_Admin();
$adminHandler->ProcessPost('crontask');
echo "OK!";
exit;
}
}
class S4U_Endomondo_Challenges_Widget extends WP_Widget {
function __construct() {
parent::__construct( false, __( 'Endomondo Uitdaging(en)', 'textdomain' ) );
}
function widget( $args, $instance ) {
$html = new S4U_Endomondo_Challenges_Html();
$html->ShowSideBarWidget();
}
function update( $new_instance, $old_instance ) {
return $new_instance;
}
function form( $instance ) {
return 'ADMIN HTML';
}
}
function s4uendomondochallenges_register_widgets() {
register_widget( 'S4U_Endomondo_Challenges_Widget' );
}
add_action( 'widgets_init', 's4uendomondochallenges_register_widgets' );
function s4uendomondochallenges_admin_settings() {
$hasError = false;
if ($adminHandler != null) {
$hasError = $adminHandler->HasError();
}
$html = new S4U_Endomondo_Challenges_Html();
if ($hasError) {
$html->ShowAdminError($adminHandler->GetError());
}
else {
$html->ShowAdminHtmlForm();
}
}
function s4uendomondochallenges_admin_menu_action() {
add_options_page( 'Endomondo Uitdaging(en)', 'Endomondo', 'administrator', __FILE__, 's4uendomondochallenges_admin_settings', 1 );
}
add_action('admin_menu', 's4uendomondochallenges_admin_menu_action');
/* because some pages on Endomondo are slow extend default CURL time-out of 5 seconds to 15 */
// source: https://gist.github.com/sudar/4945588
function bal_http_request_args($r) //called on line 237
{
$r['timeout'] = 15;
return $r;
}
add_filter('http_request_args', 'bal_http_request_args', 100, 1);
function bal_http_api_curl($handle) //called on line 1315
{
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 15 );
curl_setopt( $handle, CURLOPT_TIMEOUT, 15 );
}
add_action('http_api_curl', 'bal_http_api_curl', 100, 1);
function bal_custom_http_request_timeout( $timeout ) {
return 15; // 15 seconds
}
add_filter( 'http_request_timeout', 'bal_custom_http_request_timeout', 9999 );
?>