1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// Exit if accessed directly |
4
|
|
|
if ( !defined( 'ABSPATH' ) ) { |
5
|
|
|
exit; |
6
|
|
|
} |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Bitly Class |
10
|
|
|
* |
11
|
|
|
* Handles all bitly functions |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
if( !class_exists( 'PPP_Bitly' ) ) { |
15
|
|
|
|
16
|
|
|
class PPP_Bitly { |
17
|
|
|
|
18
|
|
|
var $bitly; |
19
|
|
|
|
20
|
|
|
public function __construct(){ |
21
|
|
|
ppp_maybe_start_session(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Include Twitter Class |
26
|
|
|
* |
27
|
|
|
* Handles to load twitter class |
28
|
|
|
*/ |
29
|
|
|
public function ppp_load_bitly() { |
30
|
|
|
if( !class_exists( 'Bitly' ) ) { |
31
|
|
|
require_once ( PPP_PATH . '/includes/libs/bitly/bitly.php' ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
ppp_set_social_tokens(); |
35
|
|
|
|
36
|
|
|
if ( ! defined( 'bitly_clientid' ) || ! defined( 'bitly_secret' ) ) { |
37
|
|
|
return false; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
global $ppp_social_settings; |
41
|
|
|
|
42
|
|
|
if ( isset( $ppp_social_settings['bitly'] ) ) { |
43
|
|
|
if ( !defined( 'bitly_accesstoken' ) ) { |
44
|
|
|
define( 'bitly_accesstoken', $ppp_social_settings['bitly']['access_token'] ); |
45
|
|
|
} |
46
|
|
|
$this->bitly = new Bitly( bitly_clientid, bitly_secret, bitly_accesstoken ); |
47
|
|
|
} else { |
48
|
|
|
$this->bitly = new Bitly( bitly_clientid, bitly_secret ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return true; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function revoke_access() { |
55
|
|
|
global $ppp_social_settings; |
56
|
|
|
|
57
|
|
|
unset( $ppp_social_settings['bitly'] ); |
58
|
|
|
|
59
|
|
|
update_option( 'ppp_social_settings', $ppp_social_settings ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get auth codes for Bitly |
64
|
|
|
* |
65
|
|
|
*/ |
66
|
|
|
public function ppp_get_bitly_auth_url () { |
67
|
|
|
//load bitly class |
68
|
|
|
$bitly = $this->ppp_load_bitly(); |
69
|
|
|
|
70
|
|
|
//check bitly class is loaded or not |
71
|
|
|
if( !$bitly ) { |
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$url = $this->bitly->getAuthUrl( ); |
76
|
|
|
return $url; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function ppp_make_bitly_link( $link = null ) { |
80
|
|
|
if ( empty( $link ) ) { |
81
|
|
|
return false; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$bitly = $this->ppp_load_bitly(); |
85
|
|
|
|
86
|
|
|
if ( !$bitly ) { |
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $this->bitly->shorten( $link ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function ppp_bitly_user_info() { |
94
|
|
|
$bitly = $this->ppp_load_bitly(); |
95
|
|
|
|
96
|
|
|
if ( !$bitly ) { |
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $this->bitly->userInfo( null, null, false ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|