| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Simple Facebook Plugin |
| 4 |
Plugin URI: http://plugins.topdevs.net/simple-facebook-plugin |
| 5 |
Description: Allows you to integrate Facebook Like Box into your WordPress Site. |
| 6 |
Version: 1.3.2 |
| 7 |
Author: topdevs |
| 8 |
Author URI: http://codecanyon.net/user/topdevs/portfolio?ref=topdevs |
| 9 |
License: GPLv2 or later |
| 10 |
*/ |
| 11 |
|
| 12 |
define( SFP_VERSION, '1.3.2' ); |
| 13 |
|
| 14 |
/** |
| 15 |
* Main SF Plugin Class |
| 16 |
* |
| 17 |
* Contains the main functions for SF and stores variables |
| 18 |
* |
| 19 |
* @since SF Plugin 1.2 |
| 20 |
* @author Ilya K. |
| 21 |
*/ |
| 22 |
|
| 23 |
// Check if class already exist |
| 24 |
if ( !class_exists( 'SFPlugin' ) ) { |
| 25 |
|
| 26 |
// Main plugin class |
| 27 |
class SFPlugin { |
| 28 |
|
| 29 |
public $pluginPath; |
| 30 |
public $pluginUrl; |
| 31 |
public $pluginName; |
| 32 |
public $optionName; |
| 33 |
|
| 34 |
public $facebookLocalesUrl = "http://www.facebook.com/translations/FacebookLocales.xml"; |
| 35 |
public $locales; |
| 36 |
|
| 37 |
/** |
| 38 |
* SF Plugin Constructor |
| 39 |
* |
| 40 |
* Gets things started |
| 41 |
*/ |
| 42 |
public function __construct( ) { |
| 43 |
$this->pluginPath = plugin_dir_path(__FILE__); |
| 44 |
$this->pluginUrl = plugin_dir_url(__FILE__); |
| 45 |
|
| 46 |
$this->optionName = "simple_facebook_plugin_options"; |
| 47 |
|
| 48 |
$this->locales = $this->parseLocales($this->facebookLocalesUrl); |
| 49 |
|
| 50 |
$this->loadFiles(); |
| 51 |
$this->addActions(); |
| 52 |
$this->addShortcodes(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Load all the required files. |
| 57 |
*/ |
| 58 |
protected function loadFiles() { |
| 59 |
// Include social plugins files |
| 60 |
require_once( $this->pluginPath . 'lib/sfp-like-box.php' ); |
| 61 |
|
| 62 |
// Allow addons load files |
| 63 |
do_action('sfp_load_files'); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Add all the required actions. |
| 68 |
*/ |
| 69 |
protected function addActions() { |
| 70 |
|
| 71 |
//add_action( 'admin_menu', array( $this, 'pluginMenu') ); |
| 72 |
add_action( 'admin_notices', array( $this, 'adminNotice') ); |
| 73 |
add_action( 'widgets_init', array( $this, 'addWidgets') ); |
| 74 |
//add_action( 'wp_footer', array( $this, 'addJavaScriptSDK') ); |
| 75 |
add_action( 'admin_init', array( $this, 'saveOptions' ) ); |
| 76 |
add_action( 'admin_init', array( $this, 'ignoreNotices' ) ); |
| 77 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueueScriptsAdmin') ); |
| 78 |
add_action( "sfp_like_box_widget_form_after_checkboxes", array( $this, "fakeCheckbox" ) ); |
| 79 |
|
| 80 |
// Add settings link on Plugins page |
| 81 |
$plugin = "simple-facebook-plugin/simple-facebook-plugin.php"; |
| 82 |
//add_filter( "plugin_action_links_$plugin", array( $this, 'pluginSettingsLink') ); |
| 83 |
|
| 84 |
// Allow addons add actions |
| 85 |
do_action( 'sfp_add_actions', $this ); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Register all widgets |
| 90 |
*/ |
| 91 |
public function addWidgets() { |
| 92 |
|
| 93 |
register_widget('SFPLikeBoxWidget'); |
| 94 |
|
| 95 |
// Allow addons add widgets |
| 96 |
do_action('sfp_add_widgets'); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Register all shortcodes |
| 101 |
*/ |
| 102 |
public function addShortcodes() { |
| 103 |
|
| 104 |
add_shortcode('sfp-like-box', 'sfp_like_box_shortcode'); |
| 105 |
|
| 106 |
// Allow addons add shortcodes |
| 107 |
do_action('sfp_add_shortcodes'); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Get remote XML file by URL |
| 112 |
* |
| 113 |
* @param string $url |
| 114 |
* @return array |
| 115 |
* @since 1.3 |
| 116 |
*/ |
| 117 |
public function parseLocales ( $url = "" ) { |
| 118 |
|
| 119 |
if ( file_exists( $url ) && function_exists( "simplexml_load_file" ) ) { |
| 120 |
|
| 121 |
$locales = array(); |
| 122 |
$xml = simplexml_load_file( $url ); |
| 123 |
|
| 124 |
foreach ( $xml as $key => $locale ) { |
| 125 |
|
| 126 |
$name = (array) $locale->englishName; |
| 127 |
$name = $name[0]; |
| 128 |
|
| 129 |
$code = (array) $locale->codes->code->standard->representation; |
| 130 |
$code = $code[0]; |
| 131 |
|
| 132 |
$locales[$code] = $name; |
| 133 |
}; |
| 134 |
} |
| 135 |
else |
| 136 |
$locales = array( |
| 137 |
"af_ZA"=> "Afrikaans", |
| 138 |
"ar_AR"=> "Arabic", |
| 139 |
"az_AZ"=> "Azerbaijani", |
| 140 |
"be_BY"=> "Belarusian", |
| 141 |
"bg_BG"=> "Bulgarian", |
| 142 |
"bn_IN"=> "Bengali", |
| 143 |
"bs_BA"=> "Bosnian", |
| 144 |
"ca_ES"=> "Catalan", |
| 145 |
"cs_CZ"=> "Czech", |
| 146 |
"cy_GB"=> "Welsh", |
| 147 |
"da_DK"=> "Danish", |
| 148 |
"de_DE"=> "German", |
| 149 |
"el_GR"=> "Greek", |
| 150 |
"en_GB"=> "English (UK)", |
| 151 |
"en_PI"=> "English (Pirate)", |
| 152 |
"en_UD"=> "English (Upside Down)", |
| 153 |
"en_US"=> "English (US)", |
| 154 |
"eo_EO"=> "Esperanto", |
| 155 |
"es_ES"=> "Spanish (Spain)", |
| 156 |
"es_LA"=> "Spanish", |
| 157 |
"et_EE"=> "Estonian", |
| 158 |
"eu_ES"=> "Basque", |
| 159 |
"fa_IR"=> "Persian", |
| 160 |
"fb_LT"=> "Leet Speak", |
| 161 |
"fi_FI"=> "Finnish", |
| 162 |
"fo_FO"=> "Faroese", |
| 163 |
"fr_CA"=> "French (Canada)", |
| 164 |
"fr_FR"=> "French (France)", |
| 165 |
"fy_NL"=> "Frisian", |
| 166 |
"ga_IE"=> "Irish", |
| 167 |
"gl_ES"=> "Galician", |
| 168 |
"he_IL"=> "Hebrew", |
| 169 |
"hi_IN"=> "Hindi", |
| 170 |
"hr_HR"=> "Croatian", |
| 171 |
"hu_HU"=> "Hungarian", |
| 172 |
"hy_AM"=> "Armenian", |
| 173 |
"id_ID"=> "Indonesian", |
| 174 |
"is_IS"=> "Icelandic", |
| 175 |
"it_IT"=> "Italian", |
| 176 |
"ja_JP"=> "Japanese", |
| 177 |
"ka_GE"=> "Georgian", |
| 178 |
"km_KH"=> "Khmer", |
| 179 |
"ko_KR"=> "Korean", |
| 180 |
"ku_TR"=> "Kurdish", |
| 181 |
"la_VA"=> "Latin", |
| 182 |
"lt_LT"=> "Lithuanian", |
| 183 |
"lv_LV"=> "Latvian", |
| 184 |
"mk_MK"=> "Macedonian", |
| 185 |
"ml_IN"=> "Malayalam", |
| 186 |
"ms_MY"=> "Malay", |
| 187 |
"nb_NO"=> "Norwegian (bokmal)", |
| 188 |
"ne_NP"=> "Nepali", |
| 189 |
"nl_NL"=> "Dutch", |
| 190 |
"nn_NO"=> "Norwegian (nynorsk)", |
| 191 |
"pa_IN"=> "Punjabi", |
| 192 |
"pl_PL"=> "Polish", |
| 193 |
"ps_AF"=> "Pashto", |
| 194 |
"pt_BR"=> "Portuguese (Brazil)", |
| 195 |
"pt_PT"=> "Portuguese (Portugal)", |
| 196 |
"ro_RO"=> "Romanian", |
| 197 |
"ru_RU"=> "Russian", |
| 198 |
"sk_SK"=> "Slovak", |
| 199 |
"sl_SI"=> "Slovenian", |
| 200 |
"sq_AL"=> "Albanian", |
| 201 |
"sr_RS"=> "Serbian", |
| 202 |
"sv_SE"=> "Swedish", |
| 203 |
"sw_KE"=> "Swahili", |
| 204 |
"ta_IN"=> "Tamil", |
| 205 |
"te_IN"=> "Telugu", |
| 206 |
"th_TH"=> "Thai", |
| 207 |
"tl_PH"=> "Filipino", |
| 208 |
"tr_TR"=> "Turkish", |
| 209 |
"uk_UA"=> "Ukrainian", |
| 210 |
"vi_VN"=> "Vietnamese", |
| 211 |
"zh_CN"=> "Simplified Chinese (China)", |
| 212 |
"zh_HK"=> "Traditional Chinese (Hong Kong)", |
| 213 |
"zh_TW"=> "Traditional Chinese (Taiwan)" |
| 214 |
); |
| 215 |
|
| 216 |
return $locales; |
| 217 |
} |
| 218 |
|
| 219 |
/** |
| 220 |
* Load styles for dashboard |
| 221 |
* |
| 222 |
* @since 1.3.1 |
| 223 |
*/ |
| 224 |
|
| 225 |
static function enqueueScriptsAdmin() { |
| 226 |
|
| 227 |
// add scripts |
| 228 |
wp_register_script( 'gumroad', 'https://gumroad.com/js/gumroad.js' ); |
| 229 |
wp_enqueue_script( 'gumroad' ); |
| 230 |
|
| 231 |
// add custom css |
| 232 |
wp_register_style( 'sfp-admin-style', plugin_dir_url(__FILE__) . '/lib/css/sfp-admin-style.css' ); |
| 233 |
wp_enqueue_style( 'sfp-admin-style' ); |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* Load Facebook JavaScript SDK |
| 238 |
* |
| 239 |
* @since 1.3 |
| 240 |
*/ |
| 241 |
|
| 242 |
public function addJavaScriptSDK() { |
| 243 |
|
| 244 |
$options = $this->getPluginOptions(); |
| 245 |
$locale = $options['locale']; |
| 246 |
|
| 247 |
?> |
| 248 |
|
| 249 |
<div id="fb-root"></div> |
| 250 |
<script> |
| 251 |
(function(d){ |
| 252 |
var js, id = 'facebook-jssdk'; |
| 253 |
if (d.getElementById(id)) {return;} |
| 254 |
js = d.createElement('script'); |
| 255 |
js.id = id; |
| 256 |
js.async = true; |
| 257 |
js.src = "//connect.facebook.net/<?php echo $locale; ?>/all.js#xfbml=1"; |
| 258 |
d.getElementsByTagName('head')[0].appendChild(js); |
| 259 |
}(document)); |
| 260 |
</script> |
| 261 |
|
| 262 |
<?php } |
| 263 |
|
| 264 |
/** |
| 265 |
* Add Dashboard > Plugins Menu Page |
| 266 |
* |
| 267 |
* @since 1.3 |
| 268 |
*/ |
| 269 |
|
| 270 |
public function pluginMenu() { |
| 271 |
|
| 272 |
add_plugins_page('Simple Facebook Plugin Menu', 'Simple Facebook', 'read', 'simple_facebook_plugin', array( $this, "pluginMenuView" ) ); |
| 273 |
} |
| 274 |
|
| 275 |
/** |
| 276 |
* Show Menu Page View |
| 277 |
* |
| 278 |
* @since 1.3 |
| 279 |
*/ |
| 280 |
|
| 281 |
public function pluginMenuView() { |
| 282 |
|
| 283 |
$options = $this->getPluginOptions(); |
| 284 |
|
| 285 |
// include Like Box view |
| 286 |
include( $sfplugin->pluginPath . 'views/view-menu.php' ); |
| 287 |
|
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Show admin notice |
| 292 |
* |
| 293 |
* @since 1.3 |
| 294 |
*/ |
| 295 |
|
| 296 |
public function adminNotice() { |
| 297 |
|
| 298 |
global $current_user; |
| 299 |
$user_id = $current_user->ID; |
| 300 |
|
| 301 |
/* Check that the user hasn't already clicked to ignore the message */ |
| 302 |
if ( ! get_user_meta( $user_id, 'sfp_ignore_notice_1') ) { |
| 303 |
|
| 304 |
echo '<div class="updated"><p>'; |
| 305 |
|
| 306 |
printf( __('Thanks for using <strong>Simple Facebook Plugin</strong>. Use our Responsive Add-on to make it look nice on all devices. <a class="button" href="https://gum.co/zrJx">Buy Add-on Now</a> or <a href="http://plugins.topdevs.net/simple-facebook-plugin/responsive-like-box-addon/">Visit Add-on Page</a> | <a href="%1$s">Don\'t show this</a>'), '?sfp_ignore_1=0'); |
| 307 |
|
| 308 |
echo "</p></div>"; |
| 309 |
|
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
public function ignoreNotices() { |
| 314 |
|
| 315 |
global $current_user; |
| 316 |
$user_id = $current_user->ID; |
| 317 |
|
| 318 |
/* If user clicks to ignore the notice, add that to their user meta */ |
| 319 |
if ( isset( $_GET['sfp_ignore_1'] ) && '0' == $_GET['sfp_ignore_1'] ) { |
| 320 |
add_user_meta( $user_id, 'sfp_ignore_notice_1', 'true', true); |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
/** |
| 325 |
* Add status link on plugins page |
| 326 |
* |
| 327 |
* @since 1.3 |
| 328 |
*/ |
| 329 |
|
| 330 |
public function pluginSettingsLink ( $links ) { |
| 331 |
|
| 332 |
$settings_link = '<a href="' . menu_page_url( "simple_facebook_plugin", false ) . '">Settings</a>'; |
| 333 |
|
| 334 |
array_unshift( $links, $settings_link ); |
| 335 |
|
| 336 |
return $links; |
| 337 |
} |
| 338 |
|
| 339 |
/** |
| 340 |
* Get plugin options |
| 341 |
* |
| 342 |
* @since 1.3 |
| 343 |
*/ |
| 344 |
|
| 345 |
public function getPluginOptions() { |
| 346 |
|
| 347 |
$defaults = array( |
| 348 |
'locale' => "en_US" ); |
| 349 |
|
| 350 |
$defaults = apply_filters( "sfp_default_options", $defaults ); |
| 351 |
|
| 352 |
$options = get_option( $this->optionName, $defaults ); |
| 353 |
|
| 354 |
return $options; |
| 355 |
} |
| 356 |
|
| 357 |
/** |
| 358 |
* Save plugin options |
| 359 |
* |
| 360 |
* @since 1.3 |
| 361 |
*/ |
| 362 |
|
| 363 |
public function savePluginOptions( $options = array() ) { |
| 364 |
|
| 365 |
update_option( $this->optionName, $options ); |
| 366 |
} |
| 367 |
|
| 368 |
/** |
| 369 |
* Trigger when settings page form submitted |
| 370 |
* |
| 371 |
* @since 1.3 |
| 372 |
*/ |
| 373 |
|
| 374 |
public function saveOptions() { |
| 375 |
|
| 376 |
//delete_option( $this->optionName ); |
| 377 |
|
| 378 |
// If submit button pressed |
| 379 |
if ( isset( $_POST['sfp_options_saved'] ) ) { |
| 380 |
|
| 381 |
$options = $this->getPluginOptions(); |
| 382 |
|
| 383 |
if ( isset( $_POST['locale'] ) && !empty( $_POST['locale'] ) ) { |
| 384 |
|
| 385 |
$options['locale'] = $_POST['locale']; |
| 386 |
} |
| 387 |
|
| 388 |
$this->savePluginOptions( $options ); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
/** |
| 393 |
* Add disabled 'Responsive' checkbox |
| 394 |
* |
| 395 |
* @since 1.3.1 |
| 396 |
*/ |
| 397 |
|
| 398 |
public function fakeCheckbox () { |
| 399 |
|
| 400 |
if ( is_plugin_active( 'sfp-responsive-like-box/sfp-responsive-like-box.php' ) ) |
| 401 |
return; |
| 402 |
?> |
| 403 |
<tr><td> |
| 404 |
<label><?php _e('Responsive'); ?></label> |
| 405 |
</td><td> |
| 406 |
<input type="checkbox" disabled="disabled"/> |
| 407 |
<span class="sfp-icon"> |
| 408 |
<span class="sfp-tooltip-wrap"> |
| 409 |
<span class="sfp-tooltip"> |
| 410 |
Available with "Responsive Like Box Add-on" installed and activated. |
| 411 |
<span class="sfp-buttons"> |
| 412 |
<a class="button" href="https://gum.co/zrJx">Buy Add-on Now</a> or <a href="http://plugins.topdevs.net/simple-facebook-plugin/responsive-like-box-addon/">Learn more</a> |
| 413 |
</span> |
| 414 |
</span> |
| 415 |
</span> |
| 416 |
</span |
| 417 |
</td></tr> |
| 418 |
<?php |
| 419 |
} |
| 420 |
|
| 421 |
} // end SFPlugin class |
| 422 |
|
| 423 |
} // end if !class_exists |
| 424 |
|
| 425 |
// Create new SFPlugin instance |
| 426 |
$GLOBALS["sfplugin"] = new SFPlugin(); |
| 427 |
|
| 428 |
?> |