| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if( !defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
class wpForoAPI{ |
| 6 |
private $default; |
| 7 |
public $options; |
| 8 |
public $locale = 'en_US'; |
| 9 |
public $locale_iso = 'en'; |
| 10 |
public $fb_local = array( 'af_ZA', 'ar_AR', 'az_AZ', 'be_BY', 'bg_BG', 'bn_IN', 'bs_BA', 'ca_ES', 'cs_CZ', 'cy_GB', 'da_DK', 'de_DE', 'el_GR', 'en_US', |
| 11 |
'en_GB', 'eo_EO', 'es_ES', 'es_LA', 'et_EE', 'eu_ES', 'fa_IR', 'fb_LT', 'fi_FI', 'fo_FO', 'fr_FR', 'fr_CA', 'fy_NL', 'ga_IE', |
| 12 |
'gl_ES', 'he_IL', 'hi_IN', 'hr_HR', 'hu_HU', 'hy_AM', 'id_ID', 'is_IS', 'it_IT', 'ja_JP', 'ka_GE', 'km_KH', 'ko_KR', 'ku_TR', |
| 13 |
'la_VA', 'lt_LT', 'lv_LV', 'mk_MK', 'ml_IN', 'ms_MY', 'nb_NO', 'ne_NP', 'nl_NL', 'nn_NO', 'pa_IN', 'pl_PL', 'ps_AF', 'pt_PT', |
| 14 |
'pt_BR', 'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sq_AL', 'sr_RS', 'sv_SE', 'sw_KE', 'ta_IN', 'te_IN', 'th_TH', 'tl_PH', 'tr_TR', |
| 15 |
'uk_UA', 'vi_VN', 'zh_CN', 'zh_HK', 'zh_TW' ); |
| 16 |
public $tw_local = array( 'en', 'ar', 'bn', 'cs', 'da', 'de', 'el', 'es', 'fa', 'fi', 'fil', 'fr', 'he', 'hi', 'hu', 'id', 'it', 'ja', 'ko', 'msa', 'nl', |
| 17 |
'no', 'pl', 'pt', 'ro', 'ru', 'sv', 'th', 'tr', 'uk', 'ur', 'vi', 'zh-cn', 'zh-tw'); |
| 18 |
public $ok_local = array( "ru", "en", "uk", "hy", "mo", "ro", "kk", "uz", "az", "tr"); |
| 19 |
|
| 20 |
public function __construct(){ |
| 21 |
$this->init_defaults(); |
| 22 |
$this->init_options(); |
| 23 |
} |
| 24 |
|
| 25 |
private function init_defaults(){ |
| 26 |
$this->default = new stdClass; |
| 27 |
$this->default->options = array( |
| 28 |
'fb_api_id' => '', |
| 29 |
'fb_api_secret' => '', |
| 30 |
'fb_login' => 0, |
| 31 |
'fb_load_sdk' => 1, |
| 32 |
'fb_sdk_version' => 'v2.10', |
| 33 |
'fb_lb_on_lp' => 1, |
| 34 |
'fb_lb_on_rp' => 1, |
| 35 |
'fb_redirect' => 'profile', |
| 36 |
'fb_redirect_url' => '', |
| 37 |
'tw_load_wjs' => 1, |
| 38 |
'gg_load_js' => 1, |
| 39 |
'vk_load_js' => 1, |
| 40 |
'ok_load_js' => 1, |
| 41 |
'sb_on' => 1, |
| 42 |
'sb_toggle_on' => 1, |
| 43 |
'sb' => array('fb' => 1, 'tw' => 1, 'gg' => 1, 'vk' => 0, 'ok' => 0), |
| 44 |
'sb_icon' => 'mixed', |
| 45 |
'sb_type' => 'icon', |
| 46 |
'sb_style' => 'grey', |
| 47 |
'sb_toggle' => 4, |
| 48 |
'sb_location_toggle' => 'top', |
| 49 |
'sb_toggle_type' => 'collapsed', |
| 50 |
'sb_location' => array('top' => 0, 'bottom' => 1), |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
private function init_options(){ |
| 55 |
$this->options = get_wpf_option('wpforo_api_options', $this->default->options); |
| 56 |
} |
| 57 |
|
| 58 |
public function hooks(){ |
| 59 |
|
| 60 |
$template = WPF()->current_object['template']; |
| 61 |
|
| 62 |
############################################################################### |
| 63 |
############### Facebook & Twitter API ######################################## |
| 64 |
############################################################################### |
| 65 |
|
| 66 |
if(!is_user_logged_in()){ |
| 67 |
if( $this->options['fb_login'] ){ |
| 68 |
if( $template == 'login' || $template == 'register' ){ |
| 69 |
add_action('wp_enqueue_scripts', array($this, 'fb_enqueue')); |
| 70 |
add_action('wpforo_bottom_hook', array($this, 'fb_login_sdk'), 9); |
| 71 |
} |
| 72 |
if( $this->options['fb_api_id'] && $this->options['fb_api_secret'] ){ |
| 73 |
if( $this->options['fb_lb_on_lp'] ){ |
| 74 |
add_action('wpforo_login_form_end', array($this, 'fb_login_button')); |
| 75 |
} |
| 76 |
if( $this->options['fb_lb_on_rp'] ){ |
| 77 |
add_action('wpforo_register_form_end', array($this, 'fb_login_button')); |
| 78 |
} |
| 79 |
} |
| 80 |
add_action('wp_ajax_wpforo_facebook_auth', array($this, 'fb_auth')); |
| 81 |
add_action('wp_ajax_nopriv_wpforo_facebook_auth', array($this, 'fb_auth')); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
if( is_wpforo_page() ){ |
| 86 |
if( $this->options['fb_load_sdk'] ){ |
| 87 |
add_action('wpforo_bottom_hook', array($this, 'fb_sdk'), 10); |
| 88 |
} |
| 89 |
if( $this->options['tw_load_wjs'] && wpfval($this->options, 'sb', 'tw') ){ |
| 90 |
add_action('wpforo_top_hook', array($this, 'tw_wjs'), 11); |
| 91 |
} |
| 92 |
if( $this->options['gg_load_js'] && wpfval($this->options, 'sb', 'gg') ){ |
| 93 |
add_action('wpforo_top_hook', array($this, 'gg_js'), 12); |
| 94 |
} |
| 95 |
if( $this->options['vk_load_js'] && wpfval($this->options, 'sb', 'vk') ){ |
| 96 |
add_action('wpforo_top_hook', array($this, 'vk_js'), 13); |
| 97 |
} |
| 98 |
if( $this->options['ok_load_js'] && wpfval($this->options, 'sb', 'ok') ){ |
| 99 |
add_action('wpforo_top_hook', array($this, 'ok_js'), 14); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
############################################################################### |
| 104 |
############### reCAPTCHA API ################################################# |
| 105 |
############################################################################### |
| 106 |
|
| 107 |
$site_key = WPF()->tools_antispam['rc_site_key']; |
| 108 |
$secret_key = WPF()->tools_antispam['rc_secret_key']; |
| 109 |
|
| 110 |
if( !is_user_logged_in() && $site_key && $secret_key ){ |
| 111 |
|
| 112 |
$rc_reg_form = WPF()->tools_antispam['rc_reg_form']; |
| 113 |
$rc_login_form = WPF()->tools_antispam['rc_login_form']; |
| 114 |
$rc_lostpass_form = WPF()->tools_antispam['rc_lostpass_form']; |
| 115 |
$rc_wpf_reg_form = WPF()->tools_antispam['rc_wpf_reg_form']; |
| 116 |
$rc_wpf_login_form = WPF()->tools_antispam['rc_wpf_login_form']; |
| 117 |
$rc_wpf_lostpass_form = WPF()->tools_antispam['rc_wpf_lostpass_form']; |
| 118 |
$rc_post_editor = WPF()->tools_antispam['rc_post_editor']; |
| 119 |
$rc_topic_editor = WPF()->tools_antispam['rc_topic_editor']; |
| 120 |
|
| 121 |
add_filter('script_loader_tag', array(&$this,'rc_enqueue_async'), 10, 3); |
| 122 |
|
| 123 |
//Verification Hooks: Login / Register / Reset Pass |
| 124 |
if( $rc_login_form || $rc_wpf_login_form ) add_filter('wp_authenticate_user', array($this, 'rc_verify_wp_login'), 15, 2); |
| 125 |
if( $rc_reg_form || $rc_wpf_reg_form ) add_filter('registration_errors', array($this, 'rc_verify_wp_register'), 10, 3); |
| 126 |
if( $rc_lostpass_form || $rc_wpf_lostpass_form ) add_action('lostpassword_post', array($this, 'rc_verify_wp_lostpassword'), 10); |
| 127 |
|
| 128 |
//Load reCAPTCHA API and Widget on wp-login.php |
| 129 |
if( $rc_reg_form || $rc_login_form || $rc_lostpass_form ){ |
| 130 |
add_action('login_enqueue_scripts', array($this, 'rc_enqueue')); |
| 131 |
add_action('login_enqueue_scripts', array($this, 'rc_enqueue_css')); |
| 132 |
if( $rc_login_form && $template != 'login' ) add_action('login_form', array($this, 'rc_widget')); |
| 133 |
if( $rc_reg_form && $template != 'register') add_action('register_form', array($this, 'rc_widget')); |
| 134 |
if( $rc_lostpass_form && $template != 'lostpassword' )add_action('lostpassword_form', array( $this, 'rc_widget')); |
| 135 |
} |
| 136 |
|
| 137 |
//Load reCAPTCHA API on wpForo pages: Login / Register / Reset Pass |
| 138 |
if( $template == 'login' || $template == 'register' || $template == 'lostpassword'){ |
| 139 |
if( $rc_wpf_reg_form || $rc_wpf_login_form || $rc_wpf_lostpass_form ){ |
| 140 |
add_action('wp_enqueue_scripts', array($this, 'rc_enqueue')); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
//Load reCAPTCHA Widget wpForo forms: Login / Register / Reset Pass |
| 145 |
if( $rc_wpf_login_form && $template == 'login' ) add_action('login_form', array($this, 'rc_widget')); |
| 146 |
if( $rc_wpf_reg_form && $template == 'register') add_action('register_form', array($this, 'rc_widget')); |
| 147 |
if( $rc_wpf_lostpass_form && $template == 'lostpassword' ) add_action('lostpassword_form', array( $this, 'rc_widget')); |
| 148 |
|
| 149 |
//Load reCAPTCHA API and Widget for Topic and Post Editor |
| 150 |
if( $template == 'forum' || $template == 'topic' || $template == 'post' ){ |
| 151 |
add_action('wp_enqueue_scripts', array($this, 'rc_enqueue')); |
| 152 |
add_action('wpforo_verify_form_end', array($this, 'rc_verify')); |
| 153 |
if( $rc_topic_editor ) add_action('wpforo_topic_form_extra_fields_after', array($this, 'rc_widget')); |
| 154 |
if( $rc_post_editor ) add_action('wpforo_reply_form_extra_fields_after', array($this, 'rc_widget')); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
############################################################################### |
| 159 |
} |
| 160 |
|
| 161 |
public function local( $api ){ |
| 162 |
|
| 163 |
$wplocal = get_locale(); |
| 164 |
$wplocal_iso = substr($wplocal, 0, 2); |
| 165 |
|
| 166 |
if( $api == 'fb' ){ |
| 167 |
if( in_array($wplocal, $this->fb_local) ){ |
| 168 |
return $wplocal; |
| 169 |
} |
| 170 |
else{ |
| 171 |
return $this->locale; |
| 172 |
} |
| 173 |
} |
| 174 |
elseif( $api == 'tw' ){ |
| 175 |
if( in_array($wplocal_iso, $this->tw_local) ){ |
| 176 |
return $wplocal_iso; |
| 177 |
} |
| 178 |
else{ |
| 179 |
return $this->locale_iso; |
| 180 |
} |
| 181 |
} |
| 182 |
elseif( $api == 'gg' ){ |
| 183 |
return $wplocal_iso; |
| 184 |
} |
| 185 |
elseif( $api == 'vk' ){ |
| 186 |
return $wplocal_iso; |
| 187 |
} |
| 188 |
elseif( $api == 'ok' ){ |
| 189 |
if( in_array($wplocal_iso, $this->ok_local) ){ |
| 190 |
return $wplocal_iso; |
| 191 |
} |
| 192 |
else{ |
| 193 |
return $this->locale_iso; |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
public function fb_enqueue() { |
| 199 |
$app_id = $this->options['fb_api_id']; |
| 200 |
wp_register_script('wpforo-snfb', WPFORO_URL . '/wpf-assets/js/snfb.js', array('jquery'), WPFORO_VERSION, false ); |
| 201 |
wp_enqueue_script('wpforo-snfb'); |
| 202 |
wp_localize_script('wpforo-snfb', 'wpforo_fb', |
| 203 |
array( 'ajaxurl' => admin_url('admin-ajax.php'), 'site_url' => home_url(), 'scopes' => 'email,public_profile', 'appId' => $app_id, 'l18n' => array( 'chrome_ios_alert' => __( 'Please login into Facebook and then click connect button again', 'wpforo' ))) |
| 204 |
); |
| 205 |
} |
| 206 |
|
| 207 |
public function fb_auth(){ |
| 208 |
|
| 209 |
$app_version = 'v2.10'; |
| 210 |
$app_secret = $this->options['fb_api_secret']; |
| 211 |
check_ajax_referer( 'wpforo-fb-nonce', 'security' ); |
| 212 |
$fb_token = isset( $_POST['fb_response']['authResponse']['accessToken'] ) ? $_POST['fb_response']['authResponse']['accessToken'] : ''; |
| 213 |
$fb_url = add_query_arg( array( 'fields' => 'id,first_name,last_name,email,link,about,locale,birthday', 'access_token' => $fb_token ), 'https://graph.facebook.com/' . $app_version . '/' . $_POST['fb_response']['authResponse']['userID'] ); |
| 214 |
|
| 215 |
################################################################################################################### |
| 216 |
// Verifying Graph API Calls with appsecret_proof |
| 217 |
// Graph API calls can be made from clients or from your server on behalf of clients. |
| 218 |
// Calls from a server can be better secured by adding a parameter called appsecret_proof. |
| 219 |
// https://developers.facebook.com/docs/graph-api/securing-requests/ |
| 220 |
if( $app_secret ) { |
| 221 |
$appsecret_proof = hash_hmac('sha256', $fb_token, trim($app_secret) ); |
| 222 |
$fb_url = add_query_arg( array( 'appsecret_proof' => $appsecret_proof ), $fb_url ); |
| 223 |
} |
| 224 |
################################################################################################################### |
| 225 |
|
| 226 |
$fb_response = wp_remote_get( esc_url_raw( $fb_url ), array( 'timeout' => 30 ) ); |
| 227 |
if( is_wp_error( $fb_response ) ) wpforo_ajax_response( array( 'error' => $fb_response->get_error_message() ) ); |
| 228 |
$fb_user = json_decode( wp_remote_retrieve_body( $fb_response ), true ); |
| 229 |
if( isset( $fb_user['error'] ) ) wpforo_ajax_response( array( 'error' => 'Error code: '. $fb_user['error']['code'] . ' - ' . $fb_user['error']['message'] ) ); |
| 230 |
if( empty( $fb_user['email'] ) ) wpforo_ajax_response( array( 'error' => __('Your email is required to be able authorize you here. Please try loging again. ', 'wpforo' ), 'fb' => $fb_user ) ); |
| 231 |
$fb_user['link'] = ( isset($fb_user['link']) ) ? $fb_user['link'] : ''; |
| 232 |
$fb_user['about'] = ( isset($fb_user['about']) ) ? $fb_user['about'] : ''; |
| 233 |
$fb_user['locale'] = ( isset($fb_user['locale']) ) ? $fb_user['locale'] : ''; |
| 234 |
$user = array( 'fb_user_id' => $fb_user['id'], 'first_name' => $fb_user['first_name'], 'last_name' => $fb_user['last_name'], 'user_email' => $fb_user['email'], 'user_url' => $fb_user['link'], 'user_pass' => wp_generate_password(), 'description' => $fb_user['about'], 'locale' => $fb_user['locale'], 'rich_editing' => 'true' ); |
| 235 |
$message = array( 'error' => __( 'Invalid User', 'wpforo' ) ); |
| 236 |
if ( empty( $user['fb_user_id'] ) ) wpforo_ajax_response( $message ); |
| 237 |
$member = wpforo_get_fb_user( $user ); |
| 238 |
$meta_updated = false; |
| 239 |
|
| 240 |
if ( $member ){ |
| 241 |
$user_id = $member->ID; |
| 242 |
$message = array( 'success' => $user_id, 'method' => 'login'); |
| 243 |
if( empty( $member->user_email ) ) wp_update_user( array( 'ID' => $user_id, 'user_email' => $user['user_email'] ) ); |
| 244 |
} else { |
| 245 |
if( !wpforo_feature('user-register') ) wpforo_ajax_response( array( 'error' => __( 'User registration is disabled', 'wpforo' ) ) ); |
| 246 |
$username = wpforo_unique_username( $user['user_email'] ); |
| 247 |
$user['user_login'] = str_replace('.', '', $username); |
| 248 |
$user['user_nicename'] = sanitize_title($username); |
| 249 |
$user['display_name'] = ( $user['first_name'] || $user['last_name'] ) ? trim($user['first_name'] . ' ' . $user['last_name']) : ucfirst(str_replace('-', ' ', $user['user_nicename'])); |
| 250 |
$user_id = wp_insert_user( $user ); |
| 251 |
if( !is_wp_error( $user_id ) ) { |
| 252 |
wp_new_user_notification( $user_id, NULL, 'admin' ); |
| 253 |
wp_new_user_notification( $user_id, '', 'user' ); |
| 254 |
update_user_meta( $user_id, '_fb_user_id', $user['fb_user_id'] ); |
| 255 |
if( isset($fb_user['birthday']) && $fb_user['birthday'] ){ |
| 256 |
update_user_meta( $user_id, '_fb_user_birthday', $fb_user['birthday'] ); |
| 257 |
} |
| 258 |
$meta_updated = true; |
| 259 |
$message = array( 'success' => $user_id, 'method' => 'registration' ); |
| 260 |
} |
| 261 |
} |
| 262 |
if( is_numeric( $user_id ) ) { |
| 263 |
wp_set_auth_cookie( $user_id, true ); |
| 264 |
if( !$meta_updated ) update_user_meta( $user_id, '_fb_user_id', $user['fb_user_id'] ); |
| 265 |
} |
| 266 |
wpforo_ajax_response( $message ); |
| 267 |
} |
| 268 |
|
| 269 |
public function fb_redirect(){ |
| 270 |
if( $this->options['fb_redirect'] == 'custom' && $this->options['fb_redirect_url'] != '' ){ |
| 271 |
return esc_url($this->options['fb_redirect_url']); |
| 272 |
} |
| 273 |
elseif( $this->options['fb_redirect'] == 'profile' ){ |
| 274 |
$current_user_id = WPF()->current_userid; |
| 275 |
return wpforo_home_url("account/"); |
| 276 |
} |
| 277 |
else{ |
| 278 |
return wpforo_home_url(); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
public function fb_sdk(){ |
| 283 |
?> |
| 284 |
<div id="fb-root"></div> |
| 285 |
<script type='text/javascript' >(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/<?php echo $this->local('fb') ?>/sdk.js#xfbml=1&version=<?php echo $this->options['fb_sdk_version'] ?>&appId=<?php echo $this->options['fb_api_id']?>&autoLogAppEvents=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> |
| 286 |
<?php |
| 287 |
} |
| 288 |
|
| 289 |
public function fb_login_sdk(){ |
| 290 |
?> |
| 291 |
<script type='text/javascript'>function statusChangeCallback(response){ if (response.status === 'connected') {} else if (response.status === 'not_authorized') {} else {}} function checkLoginState() { FB.getLoginStatus(function(response) { statusChangeCallback(response); });} window.fbAsyncInit = function(){ FB.init({ appId : '<?php echo trim($this->options['fb_api_id']) ?>', cookie : <?php echo ( WPF()->tools_legal['cookies'] ) ? 'true' : 'false'; ?>, xfbml : true, status : false, version : '<?php echo $this->options['fb_sdk_version'] ?>' }); FB.getLoginStatus(function(response) {statusChangeCallback(response);}); };</script> |
| 292 |
<?php |
| 293 |
} |
| 294 |
|
| 295 |
public function fb_login_button(){ |
| 296 |
$checkbox = WPF()->tools_legal['checkbox_fb_login']; |
| 297 |
$public_profile = '<a href="https://developers.facebook.com/docs/facebook-login/permissions#reference-public_profile" target="_blank" rel="nofollow" title="' . wpforo_phrase('Read more about Facebook public_profile properties.', false) . '">public_profile</a>'; |
| 298 |
?> |
| 299 |
<?php if( $checkbox ): ?> |
| 300 |
<div class="wpforo-fb-info"> |
| 301 |
<span class="wpforo-fb-info-title"> |
| 302 |
<i class="fas fa-info-circle wpfcl-5" aria-hidden="true" style="font-size:16px;"></i> <?php wpforo_phrase('Facebook Login Information'); ?> |
| 303 |
</span> |
| 304 |
<span class="wpforo-fb-info-text"> |
| 305 |
<?php echo sprintf( wpforo_phrase('When you login first time using Facebook Login button, we collect your account %s information shared by Facebook, based on your privacy settings. We also get your email address to automatically create a forum account for you. Once your account is created, you\'ll be logged-in to this account and you\'ll receive a confirmation email.', false ), $public_profile); ?> |
| 306 |
</span> |
| 307 |
<label class="wpforo-legal-checkbox wpflegal-fblogin"> |
| 308 |
<input id="wpflegal_fblogin" name="legal[agree-fb-login]" value="1" type="checkbox"> |
| 309 |
<span><?php wpforo_phrase('I allow to create an account and send confirmation email.'); ?></span> |
| 310 |
</label> |
| 311 |
</div> |
| 312 |
<?php endif; ?> |
| 313 |
<div class="wpforo_fb-button wpforo-fb-login-wrap" data-redirect="<?php echo $this->fb_redirect() ?>" data-fb_nonce="<?php echo wp_create_nonce( 'wpforo-fb-nonce' ) ?>" <?php if( $checkbox ) echo 'style="pointer-events: none; opacity:0.6;"'; ?>> |
| 314 |
<div class="fb-login-button" data-max-rows="1" onlogin="wpforo_fb_check_auth" data-size="medium" data-button-type="login_with" data-show-faces="false" data-auth-type="rerequest" data-auto-logout-link="false" data-use-continue-as="true" data-scope="email,public_profile"></div> |
| 315 |
<img data-no-lazy="1" src="<?php echo WPFORO_URL . '/wpf-assets/images/loading.gif'; ?>" class="wpforo_fb-spinner" style="display:none"/> |
| 316 |
</div> |
| 317 |
<?php |
| 318 |
} |
| 319 |
|
| 320 |
public function fb_share_button( $url = '', $type = 'custom', $text = '' ){ |
| 321 |
if( !wpfval($this->options, 'sb', 'fb') || !wpfval($this->options, 'fb_api_id') ) return; |
| 322 |
$url = ( $url ) ? $url : WPF()->current_url; |
| 323 |
$text = ( $text ) ? $text : wpfval(WPF()->current_object,'og_text'); |
| 324 |
if( $type == 'custom' ){ |
| 325 |
?> |
| 326 |
<span class="wpforo-share-button wpf-fb" data-wpfurl="<?php echo $url ?>" title="<?php wpforo_phrase('Share to Facebook'); ?>"> |
| 327 |
<?php if( $this->options['sb_icon'] == 'figure' ): ?> |
| 328 |
<i class="fab fa-facebook-f" aria-hidden="true"></i> |
| 329 |
<?php elseif( $this->options['sb_icon'] == 'square' ): ?> |
| 330 |
<i class="fab fa-facebook-square" aria-hidden="true"></i> |
| 331 |
<?php else: ?> |
| 332 |
<i class="fab fa-facebook" aria-hidden="true"></i> |
| 333 |
<?php endif; ?> |
| 334 |
</span> |
| 335 |
<?php |
| 336 |
} |
| 337 |
else{ |
| 338 |
?> |
| 339 |
<div class="wpf-sbw wpf-sbw-fb"> |
| 340 |
<?php if($this->options['sb_type'] == 'button_count'): ?> |
| 341 |
<div class="fb-share-button" data-href="<?php echo esc_url($url) ?>" data-layout="button_count" data-size="small" data-mobile-iframe="true"> |
| 342 |
<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode($url) ?>" class="fb-xfbml-parse-ignore"><?php wpforo_phrase('Share'); ?></a> |
| 343 |
</div> |
| 344 |
<?php elseif($this->options['sb_type'] == 'button'): ?> |
| 345 |
<span class="wpf-sb-button wpf-fb" data-wpfurl="<?php echo esc_url($url) ?>"> |
| 346 |
<i class="fab fa-facebook-f" aria-hidden="true"></i> <span><?php echo wpforo_phrase('Share') ?></span> |
| 347 |
</span> |
| 348 |
<?php else: ?> |
| 349 |
<span class="wpf-sb-button wpf-sb-icon wpf-fb" data-wpfurl="<?php echo esc_url($url) ?>"> |
| 350 |
<i class="fab fa-facebook-f" aria-hidden="true"></i> |
| 351 |
</span> |
| 352 |
<?php endif; ?> |
| 353 |
</div> |
| 354 |
<?php |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
public function tw_wjs(){ |
| 359 |
?> |
| 360 |
<script type="text/javascript">window.twttr = (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return t; js = d.createElement(s); js.id = id; js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); t._e = []; t.ready = function(f) { t._e.push(f); }; return t;}(document, "script", "twitter-wjs"));</script> |
| 361 |
<?php |
| 362 |
} |
| 363 |
|
| 364 |
public function tw_share_button( $url = '', $type = 'custom', $text = '' ){ |
| 365 |
if( !wpfval($this->options, 'sb', 'tw') ) return; |
| 366 |
$url = ( $url ) ? $url : WPF()->current_url; |
| 367 |
$n_url = strlen($url); $n_text = 280 - $n_url; |
| 368 |
$text = ( $text ) ? $text : wpfval(WPF()->current_object,'og_text'); |
| 369 |
$text = urlencode( wpforo_text( strip_shortcodes( strip_tags($text) ), $n_text, false) ); |
| 370 |
if( $type == 'custom' ){ ?> |
| 371 |
<a class="wpforo-share-button wpf-tw" href="https://twitter.com/intent/tweet?text=<?php echo $text ?>&url=<?php echo urlencode($url) ?>" title="<?php wpforo_phrase('Tweet this post'); ?>"> |
| 372 |
<?php if( $this->options['sb_icon'] == 'figure' ): ?> |
| 373 |
<i class="fab fa-twitter" aria-hidden="true"></i> |
| 374 |
<?php elseif( $this->options['sb_icon'] == 'square' ): ?> |
| 375 |
<i class="fab fa-twitter-square" aria-hidden="true"></i> |
| 376 |
<?php else: ?> |
| 377 |
<i class="fab fa-twitter" aria-hidden="true"></i> |
| 378 |
<?php endif; ?> |
| 379 |
</a> |
| 380 |
<?php |
| 381 |
} |
| 382 |
else{ ?> |
| 383 |
<div class="wpf-sbw wpf-sbw-tw"> |
| 384 |
<?php if($this->options['sb_type'] == 'button_count'): ?> |
| 385 |
<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-lang="<?php $this->local('tw') ?>" data-show-count="true"><?php wpforo_phrase('Tweet'); ?></a> |
| 386 |
<?php elseif($this->options['sb_type'] == 'button'): ?> |
| 387 |
<a class="wpf-sb-button wpf-tw" href="https://twitter.com/intent/tweet?text=<?php echo $text ?>&url=<?php echo urlencode($url) ?>"> |
| 388 |
<i class="fab fa-twitter" aria-hidden="true"></i> <span><?php echo wpforo_phrase('Tweet') ?></span> |
| 389 |
</a> |
| 390 |
<?php else: ?> |
| 391 |
<a class="wpf-sb-button wpf-sb-icon wpf-tw" href="https://twitter.com/intent/tweet?text=<?php echo $text ?>&url=<?php echo urlencode($url) ?>"> |
| 392 |
<i class="fab fa-twitter" aria-hidden="true"></i> |
| 393 |
</a> |
| 394 |
<?php endif; ?> |
| 395 |
</div> |
| 396 |
<?php |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
public function gg_js(){ |
| 401 |
?> |
| 402 |
<script src="https://apis.google.com/js/platform.js" async defer></script> |
| 403 |
<?php |
| 404 |
} |
| 405 |
|
| 406 |
public function gg_share_button( $url = '', $type = 'custom', $text = '' ){ |
| 407 |
if( !wpfval($this->options, 'sb', 'gg') ) return; |
| 408 |
$url = ( $url ) ? $url : WPF()->current_url; |
| 409 |
$text = ( $text ) ? $text : wpfval(WPF()->current_object,'og_text'); |
| 410 |
if( $type == 'custom' ){ ?> |
| 411 |
<a class="wpforo-share-button wpf-gg" href="//plus.google.com/share?app=110&url=<?php echo urlencode($url) ?>" target="_blank" onclick="window.open(this.href,'','scrollbars=1,resizable=1,width=400,height=620');return false;" title="<?php wpforo_phrase('Share to Google+'); ?>"> |
| 412 |
<?php if( $this->options['sb_icon'] == 'figure' ): ?> |
| 413 |
<i class="fab fa-google-plus-g" aria-hidden="true"></i> |
| 414 |
<?php elseif( $this->options['sb_icon'] == 'square' ): ?> |
| 415 |
<i class="fab fa-google-plus-square" aria-hidden="true"></i> |
| 416 |
<?php else: ?> |
| 417 |
<i class="fab fa-google-plus" aria-hidden="true"></i> |
| 418 |
<?php endif; ?> |
| 419 |
</a> |
| 420 |
<?php |
| 421 |
} |
| 422 |
else{ ?> |
| 423 |
<div class="wpf-sbw wpf-sbw-gg"> |
| 424 |
<?php if($this->options['sb_type'] == 'button_count'): ?> |
| 425 |
<div class="g-plus" data-action="share" data-annotation="bubble"></div> |
| 426 |
<?php elseif($this->options['sb_type'] == 'button'): ?> |
| 427 |
<a class="wpf-sb-button wpf-gg" href="//plus.google.com/share?app=110&url=<?php echo urlencode($url) ?>" target="_blank" onclick="window.open(this.href,'','scrollbars=1,resizable=1,width=400,height=620');return false;"> |
| 428 |
<i class="fab fa-google-plus-g" aria-hidden="true"></i> <span><?php echo wpforo_phrase('Share') ?></span> |
| 429 |
</a> |
| 430 |
<?php else: ?> |
| 431 |
<a class="wpf-sb-button wpf-sb-icon wpf-gg" href="//plus.google.com/share?app=110&url=<?php echo urlencode($url) ?>" target="_blank" onclick="window.open(this.href,'','scrollbars=1,resizable=1,width=400,height=620');return false;"> |
| 432 |
<i class="fab fa-google-plus-g" aria-hidden="true"></i> |
| 433 |
</a> |
| 434 |
<?php endif; ?> |
| 435 |
</div> |
| 436 |
<?php |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
public function vk_js(){ |
| 441 |
?> |
| 442 |
<script type="text/javascript" src="https://vk.com/js/api/share.js?95" charset="windows-1251"></script> |
| 443 |
<?php |
| 444 |
} |
| 445 |
|
| 446 |
public function vk_share_button( $url = '', $type = 'custom', $text = '' ){ |
| 447 |
if( !wpfval($this->options, 'sb', 'vk') ) return; |
| 448 |
$url = ( $url ) ? $url : WPF()->current_url; |
| 449 |
$text = ( $text ) ? $text : wpfval(WPF()->current_object,'og_text'); |
| 450 |
$text = urlencode( wpforo_text( strip_shortcodes( strip_tags($text) ), 1000, false) ); |
| 451 |
if( $type == 'custom' ){ ?> |
| 452 |
<a class="wpforo-share-button wpf-vk" onclick="return VK.Share.click(0, this);" href="https://vk.com/share.php?url=<?php echo urlencode($url) ?>&description=<?php echo $text ?>" title="<?php wpforo_phrase('Share to VK'); ?>" target="_blank"> |
| 453 |
<i class="fab fa-vk" aria-hidden="true"></i> |
| 454 |
</a> |
| 455 |
<?php |
| 456 |
} |
| 457 |
else{ ?> |
| 458 |
<div class="wpf-sbw wpf-sbw-vk"> |
| 459 |
<?php if($this->options['sb_type'] == 'button_count'): ?> |
| 460 |
<script type="text/javascript">document.write(VK.Share.button(false,{type: "round", text: "<?php wpforo_phrase('Share'); ?>"}));</script> |
| 461 |
<?php elseif($this->options['sb_type'] == 'button'): ?> |
| 462 |
<a class="wpf-sb-button wpf-vk" onclick="return VK.Share.click(0, this);" href="https://vk.com/share.php?url=<?php echo urlencode($url) ?>&description=<?php echo $text ?>" target="_blank"> |
| 463 |
<i class="fab fa-vk" aria-hidden="true"></i> <span><?php echo wpforo_phrase('Share') ?></span> |
| 464 |
</a> |
| 465 |
<?php else: ?> |
| 466 |
<a class="wpf-sb-button wpf-sb-icon wpf-vk" onclick="return VK.Share.click(0, this);" href="https://vk.com/share.php?url=<?php echo urlencode($url) ?>&description=<?php echo $text ?>" target="_blank"> |
| 467 |
<i class="fab fa-vk" aria-hidden="true"></i> |
| 468 |
</a> |
| 469 |
<?php endif; ?> |
| 470 |
</div> |
| 471 |
<?php |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
public function ok_js(){ |
| 476 |
|
| 477 |
} |
| 478 |
|
| 479 |
public function ok_share_button( $url = '', $type = 'custom', $text = '' ){ |
| 480 |
if( !wpfval($this->options, 'sb', 'ok') ) return; |
| 481 |
$url = ( $url ) ? $url : WPF()->current_url; |
| 482 |
if( preg_match('|\#post-(\d+)|s', $url, $a) ){ $pid = ( isset($a[1]) ) ? intval($a[1]) : mt_rand(100000, 999999); } else{ $pid = mt_rand(100000, 999999); } |
| 483 |
$text = ( $text ) ? $text : wpfval(WPF()->current_object,'og_text'); |
| 484 |
$text = wpforo_text( strip_shortcodes( strip_tags($text) ), 1000, false); |
| 485 |
if( $type == 'custom' ){ ?> |
| 486 |
<a class="wpforo-share-button wpf-ok" href="https://connect.ok.ru/offer?url=<?php echo urlencode( $url ) ?>&description=<?php echo urlencode($text) ?>" title="<?php wpforo_phrase('Share to OK'); ?>" target="_blank" > |
| 487 |
<?php if( $this->options['sb_icon'] == 'figure' ): ?> |
| 488 |
<i class="fab fa-odnoklassniki" aria-hidden="true"></i> |
| 489 |
<?php elseif( $this->options['sb_icon'] == 'square' ): ?> |
| 490 |
<i class="fab fa-odnoklassniki-square" aria-hidden="true"></i> |
| 491 |
<?php else: ?> |
| 492 |
<i class="fab fa-odnoklassniki-square" aria-hidden="true"></i> |
| 493 |
<?php endif; ?> |
| 494 |
</a> |
| 495 |
<?php |
| 496 |
} |
| 497 |
else{ ?> |
| 498 |
<div class="wpf-sbw wpf-sbw-ok"> |
| 499 |
<?php if($this->options['sb_type'] == 'button_count'): ?> |
| 500 |
<div id="<?php echo 'wpfokb_' . $pid ?>"></div> |
| 501 |
<script> |
| 502 |
!function (d, id, did, st, title, description, image) { var js = d.createElement("script"); js.src = "https://connect.ok.ru/connect.js"; js.onload = js.onreadystatechange = function () { if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") { if (!this.executed) { this.executed = true; setTimeout(function () { OK.CONNECT.insertShareWidget(id,did,st, title, description, image); }, 0); }}}; d.documentElement.appendChild(js); |
| 503 |
}(document,"<?php echo 'wpfokb_' . $pid ?>","<?php echo esc_attr( $url ) ?>",'{"sz":20,"st":"straight","ck":2,"lang":"<?php echo $this->local('ok') ?>"}',"","",""); |
| 504 |
</script> |
| 505 |
<?php elseif($this->options['sb_type'] == 'button'): ?> |
| 506 |
<a class="wpf-sb-button wpf-ok" href="https://connect.ok.ru/offer?url=<?php echo urlencode( $url ) ?>&description=<?php echo urlencode($text) ?>" title="<?php wpforo_phrase('Share to OK'); ?>" target="_blank" > |
| 507 |
<i class="fab fa-odnoklassniki" aria-hidden="true"></i> <span><?php echo wpforo_phrase('Share') ?></span> |
| 508 |
</a> |
| 509 |
<?php else: ?> |
| 510 |
<a class="wpf-sb-button wpf-sb-icon wpf-ok" href="https://connect.ok.ru/offer?url=<?php echo urlencode( $url ) ?>&description=<?php echo urlencode($text) ?>" title="<?php wpforo_phrase('Share to OK'); ?>" target="_blank" > |
| 511 |
<i class="fab fa-odnoklassniki" aria-hidden="true"></i> |
| 512 |
</a> |
| 513 |
<?php endif; ?> |
| 514 |
</div> |
| 515 |
<?php |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
public function share_toggle( $url = '', $text = '', $type = 'custom' ){ |
| 520 |
WPF()->api->fb_share_button($url, $type, $text); |
| 521 |
WPF()->api->tw_share_button($url, $type, $text); |
| 522 |
WPF()->api->gg_share_button($url, $type, $text); |
| 523 |
WPF()->api->vk_share_button($url, $type, $text); |
| 524 |
WPF()->api->ok_share_button($url, $type, $text); |
| 525 |
} |
| 526 |
|
| 527 |
public function share_buttons( $url = '', $type = 'default', $text = '' ){ |
| 528 |
WPF()->api->fb_share_button($url, $type, $text); |
| 529 |
WPF()->api->tw_share_button($url, $type, $text); |
| 530 |
WPF()->api->gg_share_button($url, $type, $text); |
| 531 |
WPF()->api->vk_share_button($url, $type, $text); |
| 532 |
WPF()->api->ok_share_button($url, $type, $text); |
| 533 |
} |
| 534 |
|
| 535 |
public function rc_enqueue() { |
| 536 |
$theme = WPF()->tools_antispam['rc_theme']; |
| 537 |
$site_key = WPF()->tools_antispam['rc_site_key']; |
| 538 |
wp_register_script( 'wpforo_recaptcha', 'https://www.google.com/recaptcha/api.js?onload=wpForoReCallback&render=explicit' ); |
| 539 |
wp_enqueue_script( 'wpforo_recaptcha' ); |
| 540 |
wp_localize_script('wpforo_recaptcha', 'wpForoRC', |
| 541 |
array( 'wpforo_rc_site_key' => $site_key, 'wpforo_rc_theme' => $theme ) |
| 542 |
); |
| 543 |
} |
| 544 |
|
| 545 |
public function rc_enqueue_async( $tag, $handle, $src ) { |
| 546 |
if ( $handle == 'wpforo_recaptcha' ) return str_replace( '<script', '<script async defer', $tag ); |
| 547 |
return $tag; |
| 548 |
} |
| 549 |
|
| 550 |
public function rc_enqueue_css() { |
| 551 |
wp_register_style( 'wpforo-rc-style', false ); |
| 552 |
wp_enqueue_style( 'wpforo-rc-style' ); |
| 553 |
$custom_css = "#wpforo_recaptcha_widget{ -webkit-transform:scale(0.9); transform:scale(0.9); -webkit-transform-origin:left 0; transform-origin:left 0; }"; |
| 554 |
wp_add_inline_style( 'wpforo-rc-style', $custom_css ); |
| 555 |
} |
| 556 |
|
| 557 |
public function rc_widget() { |
| 558 |
$site_key = WPF()->tools_antispam['rc_site_key']; |
| 559 |
if( $site_key ){ |
| 560 |
echo '<div id="wpforo_recaptcha_widget"></div><div class="wpf-cl"></div>'; |
| 561 |
echo "\r\n<script>var wpForoReCallback = function () { grecaptcha.render('wpforo_recaptcha_widget', { 'sitekey': wpForoRC.wpforo_rc_site_key, 'theme': wpForoRC.wpforo_rc_theme, }); };</script>"; |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
public function rc_check() { |
| 566 |
if ( isset( $_POST['g-recaptcha-response'] ) ) { |
| 567 |
$secret_key = WPF()->tools_antispam['rc_secret_key']; |
| 568 |
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . $secret_key . '&response=' . $_POST['g-recaptcha-response']; |
| 569 |
$response = wp_remote_get( $url ); |
| 570 |
if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
| 571 |
$error = wpforo_phrase("ERROR: Can't connect to Google reCAPTCHA API", false); |
| 572 |
if( WP_DEBUG === true ) $error .= ' ( '. $response->get_error_message() .' )'; |
| 573 |
return $error; |
| 574 |
} |
| 575 |
$response = json_decode( $response['body'], true ); |
| 576 |
if ( $response['success'] == true ) { |
| 577 |
return 'success'; |
| 578 |
} else { |
| 579 |
return wpforo_phrase('Google reCAPTCHA verification failed', false); |
| 580 |
} |
| 581 |
} |
| 582 |
else{ |
| 583 |
return wpforo_phrase('Google reCAPTCHA data are not submitted', false); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
public function rc_verify() { |
| 588 |
if( !WPF()->tools_antispam['rc_post_editor'] || !WPF()->tools_antispam['rc_topic_editor'] ){ |
| 589 |
if( wpfval($_POST, 'post','save') && !WPF()->tools_antispam['rc_post_editor'] ){ |
| 590 |
return true; |
| 591 |
} |
| 592 |
elseif( wpfval($_POST, 'topic', 'save') && !WPF()->tools_antispam['rc_topic_editor'] ){ |
| 593 |
return true; |
| 594 |
} |
| 595 |
} |
| 596 |
$result = $this->rc_check(); |
| 597 |
if ( $result == 'success' ) { |
| 598 |
return true; |
| 599 |
} else { |
| 600 |
WPF()->notice->add( $result , 'error'); |
| 601 |
wp_redirect( wpforo_get_request_uri() ); |
| 602 |
exit(); |
| 603 |
} |
| 604 |
} |
| 605 |
|
| 606 |
public function rc_verify_wp_login( $user ) { |
| 607 |
if ( !isset($_POST['log']) && !isset($_POST['pwd'])) return $user; |
| 608 |
if( !WPF()->tools_antispam['rc_login_form'] || !WPF()->tools_antispam['rc_wpf_login_form'] ){ |
| 609 |
if( !wpfval($_POST, 'wpforologin') && !WPF()->tools_antispam['rc_login_form'] ){ |
| 610 |
return $user; |
| 611 |
} |
| 612 |
elseif( wpfval($_POST, 'wpforologin') && !WPF()->tools_antispam['rc_wpf_login_form'] ){ |
| 613 |
return $user; |
| 614 |
} |
| 615 |
} |
| 616 |
$errors = is_wp_error($user) ? $user : new WP_Error(); |
| 617 |
$result = $this->rc_check(); |
| 618 |
if( $result != 'success' ) { |
| 619 |
$errors->add('wpforo-recaptcha-error', $result); |
| 620 |
$user = is_wp_error($user) ? $user : $errors; |
| 621 |
remove_filter('authenticate', 'wp_authenticate_username_password', 10); |
| 622 |
remove_filter('authenticate', 'wp_authenticate_cookie', 10); |
| 623 |
} |
| 624 |
return $user; |
| 625 |
} |
| 626 |
|
| 627 |
public function rc_verify_wp_register( $errors = '' ){ |
| 628 |
if ( !is_wp_error($errors) ) $errors = new WP_Error(); |
| 629 |
if( !WPF()->tools_antispam['rc_reg_form'] || !WPF()->tools_antispam['rc_wpf_reg_form'] ){ |
| 630 |
if( !wpfval($_POST, 'wpfreg') && !WPF()->tools_antispam['rc_reg_form'] ){ |
| 631 |
return $errors; |
| 632 |
} |
| 633 |
elseif( wpfval($_POST, 'wpfreg') && !WPF()->tools_antispam['rc_wpf_reg_form'] ){ |
| 634 |
return $errors; |
| 635 |
} |
| 636 |
} |
| 637 |
$result = $this->rc_check(); |
| 638 |
if( $result != 'success' ) { |
| 639 |
$errors->add('wpforo-recaptcha-error', $result); |
| 640 |
} |
| 641 |
return $errors; |
| 642 |
} |
| 643 |
|
| 644 |
public function rc_verify_wp_lostpassword( $errors = '' ){ |
| 645 |
if ( !is_wp_error($errors) ) $errors = new WP_Error(); |
| 646 |
if( !WPF()->tools_antispam['rc_lostpass_form'] || !WPF()->tools_antispam['rc_wpf_lostpass_form'] ){ |
| 647 |
if( !wpfval($_POST, 'wpfororp') && !WPF()->tools_antispam['rc_lostpass_form'] ){ |
| 648 |
return; |
| 649 |
} |
| 650 |
elseif( wpfval($_POST, 'wpfororp') && !WPF()->tools_antispam['rc_wpf_lostpass_form'] ){ |
| 651 |
return; |
| 652 |
} |
| 653 |
} |
| 654 |
$result = $this->rc_check(); |
| 655 |
if( $result != 'success' ) { |
| 656 |
if ( isset($_POST['wc_reset_password']) && isset($_POST['_wp_http_referer']) ) { |
| 657 |
//$errors->add('wpforo-recaptcha-error', $result); |
| 658 |
//return $errors; |
| 659 |
return; |
| 660 |
} else { |
| 661 |
wp_die( $result, 'reCAPTCHA ERROR', array( 'back_link' => true ) ); |
| 662 |
} |
| 663 |
} |
| 664 |
return; |
| 665 |
} |
| 666 |
|
| 667 |
public function rc_exists(){ |
| 668 |
|
| 669 |
} |
| 670 |
|
| 671 |
} |