settings();
add_action( 'admin_menu', array( &$this, 'admin_menu'));
add_action( 'admin_notices', array( &$this, 'admin_notices'));
add_action( 'init', array( &$this, 'init' ), 10 );
add_action( 'wp_footer', array( &$this, 'get_html' ), 21 );
add_action( 'admin_enqueue_scripts',array( &$this, 'admin_scripts') );
add_action( 'wp_ajax_afbsb_hide_notice', array( &$this, 'admin_notices_handle') );
add_action( 'wp_enqueue_scripts', array( &$this, 'init_scripts') );
add_filter( 'plugin_action_links', array( &$this, 'settings_link' ), 10, 2);
register_uninstall_hook( __FILE__, array( 'AspexiFBsidebox', 'uninstall' ) );
}
/* WP init action */
public function init() {
/* Internationalization */
load_plugin_textdomain( 'aspexifbsidebox', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
/* Exras */
$this->extras_init();
}
public function settings() {
/* Defaults */
$cf_default = array(
'aspexifbsidebox_version' => ASPEXIFBSIDEBOX_VERSION,
'url' => '',
'locale' => 'en_GB',
'status' => 'enabled',
'hide_notice' => '0'
);
if ( !get_option( 'aspexifbsidebox_options' ) )
add_option( 'aspexifbsidebox_options', $cf_default, '', 'yes' );
$this->cf = get_option( 'aspexifbsidebox_options' );
/* Upgrade */
if( $this->cf['aspexifbsidebox_version'] != ASPEXIFBSIDEBOX_VERSION ) {
switch( $this->cf['aspexifbsidebox_version'] ) {
default:
$this->cf = array_merge( $cf_default, (array)$this->cf );
$this->cf['aspexifbsidebox_version'] = ASPEXIFBSIDEBOX_VERSION;
update_option( 'aspexifbsidebox_options', $this->cf, 'yes' );
}
}
}
public function settings_link( $action_links, $plugin_file ){
if( $plugin_file == plugin_basename(__FILE__) ) {
$pro_link = $this->get_pro_link();
array_unshift( $action_links, $pro_link );
$settings_link = '' . __("Settings") . ' ';
array_unshift( $action_links, $settings_link );
}
return $action_links;
}
private function add_message( $message ) {
$message = trim( $message );
if( strlen( $message ) )
$this->messages[] = $message;
}
private function add_error( $error ) {
$error = trim( $error );
if( strlen( $error ) )
$this->errors[] = $error;
}
public function has_errors() {
return count( $this->errors );
}
public function display_admin_notices( $echo = false ) {
$ret = '';
foreach( (array)$this->errors as $error ) {
$ret .= '
';
}
foreach( (array)$this->messages as $message ) {
$ret .= '';
}
if( $echo )
echo $ret;
else
return $ret;
}
public function admin_menu() {
add_submenu_page( 'themes.php', __( 'Aspexi Like Box Sidebox', 'aspexifbsidebox' ), __( 'Aspexi Like Box Sidebox', 'aspexifbsidebox' ), 'manage_options', basename(__FILE__), array( &$this, 'admin_page') );
}
public function admin_page() {
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
$preview = false;
// request action
if ( isset( $_REQUEST['afbsb_form_submit'] ) && check_admin_referer( plugin_basename(__FILE__), 'afbsb_nonce_name' ) ) {
if( !in_array( $_REQUEST['afbsb_status'], array('enabled','disabled') ) )
$this->add_error( __( 'Wrong or missing status. Available statuses: enabled and disabled. Settings not saved.', 'aspexifbsidebox' ) );
if( !$this->has_errors() ) {
$aspexifbsidebox_request_options = array();
$aspexifbsidebox_request_options['url'] = isset( $_REQUEST['afbsb_url'] ) ? trim( $_REQUEST['afbsb_url'] ) : '';
$aspexifbsidebox_request_options['locale'] = isset( $_REQUEST['afbsb_locale'] ) ? $_REQUEST['afbsb_locale'] : '';
$aspexifbsidebox_request_options['status'] = isset( $_REQUEST['afbsb_status'] ) ? $_REQUEST['afbsb_status'] : '';
$this->cf = array_merge( (array)$this->cf, $aspexifbsidebox_request_options );
update_option( 'aspexifbsidebox_options', $this->cf, 'yes' );
$this->add_message( __( 'Settings saved.', 'aspexifbsidebox' ) );
// Preview maybe
if( @$_REQUEST['preview'] )
$preview = true;
else
$preview = false;
}
}
// Locale
$locales = array(
'Afrikaans' => 'af_ZA',
'Albanian' => 'sq_AL',
'Arabic' => 'ar_AR',
'Armenian' => 'hy_AM',
'Aymara' => 'ay_BO',
'Azeri' => 'az_AZ',
'Basque' => 'eu_ES',
'Belarusian' => 'be_BY',
'Bengali' => 'bn_IN',
'Bosnian' => 'bs_BA',
'Bulgarian' => 'bg_BG',
'Catalan' => 'ca_ES',
'Cherokee' => 'ck_US',
'Croatian' => 'hr_HR',
'Czech' => 'cs_CZ',
'Danish' => 'da_DK',
'Dutch' => 'nl_NL',
'Dutch (Belgium)' => 'nl_BE',
'English (Pirate)' => 'en_PI',
'English (UK)' => 'en_GB',
'English (Upside Down)' => 'en_UD',
'English (US)' => 'en_US',
'Esperanto' => 'eo_EO',
'Estonian' => 'et_EE',
'Faroese' => 'fo_FO',
'Filipino' => 'tl_PH',
'Finnish' => 'fi_FI',
'Finnish (test)' => 'fb_FI',
'French (Canada)' => 'fr_CA',
'French (France)' => 'fr_FR',
'Galician' => 'gl_ES',
'Georgian' => 'ka_GE',
'German' => 'de_DE',
'Greek' => 'el_GR',
'Guaran' => 'gn_PY',
'Gujarati' => 'gu_IN',
'Hebrew' => 'he_IL',
'Hindi' => 'hi_IN',
'Hungarian' => 'hu_HU',
'Icelandic' => 'is_IS',
'Indonesian' => 'id_ID',
'Irish' => 'ga_IE',
'Italian' => 'it_IT',
'Japanese' => 'ja_JP',
'Javanese' => 'jv_ID',
'Kannada' => 'kn_IN',
'Kazakh' => 'kk_KZ',
'Khmer' => 'km_KH',
'Klingon' => 'tl_ST',
'Korean' => 'ko_KR',
'Kurdish' => 'ku_TR',
'Latin' => 'la_VA',
'Latvian' => 'lv_LV',
'Leet Speak' => 'fb_LT',
'Limburgish' => 'li_NL',
'Lithuanian' => 'lt_LT',
'Macedonian' => 'mk_MK',
'Malagasy' => 'mg_MG',
'Malay' => 'ms_MY',
'Malayalam' => 'ml_IN',
'Maltese' => 'mt_MT',
'Marathi' => 'mr_IN',
'Mongolian' => 'mn_MN',
'Nepali' => 'ne_NP',
'Northern Sami' => 'se_NO',
'Norwegian (bokmal)' => 'nb_NO',
'Norwegian (nynorsk)' => 'nn_NO',
'Pashto' => 'ps_AF',
'Persian' => 'fa_IR',
'Polish' => 'pl_PL',
'Portuguese (Brazil)' => 'pt_BR',
'Portuguese (Portugal)' => 'pt_PT',
'Punjabi' => 'pa_IN',
'Quechua' => 'qu_PE',
'Romanian' => 'ro_RO',
'Romansh' => 'rm_CH',
'Russian' => 'ru_RU',
'Sanskrit' => 'sa_IN',
'Serbian' => 'sr_RS',
'Simplified Chinese (China)' => 'zh_CN',
'Slovak' => 'sk_SK',
'Slovenian' => 'sl_SI',
'Somali' => 'so_SO',
'Spanish' => 'es_LA',
'Spanish (Chile)' => 'es_CL',
'Spanish (Colombia)' => 'es_CO',
'Spanish (Mexico)' => 'es_MX',
'Spanish (Spain)' => 'es_ES',
'Spanish (Venezuela)' => 'es_VE',
'Swahili' => 'sw_KE',
'Swedish' => 'sv_SE',
'Syriac' => 'sy_SY',
'Tajik' => 'tg_TJ',
'Tamil' => 'ta_IN',
'Tatar' => 'tt_RU',
'Telugu' => 'te_IN',
'Thai' => 'th_TH',
'Traditional Chinese (Hong Kong)' => 'zh_HK',
'Traditional Chinese (Taiwan)' => 'zh_TW',
'Turkish' => 'tr_TR',
'Ukrainian' => 'uk_UA',
'Urdu' => 'ur_PK',
'Uzbek' => 'uz_UZ',
'Vietnamese' => 'vi_VN',
'Welsh' => 'cy_GB',
'Xhosa' => 'xh_ZA',
'Yiddish' => 'yi_DE',
'Zulu' => 'zu_ZA'
);
$locales_input = '';
foreach( $locales as $k => $v ) {
$locales_input .= 'cf['locale'] == $v ) ? ' selected="selected"' : '' ).'>'.$k.' ';
}
$locales_input .= ' ';
// show form
?>
display_admin_notices( true ); ?>
init_scripts();
echo $this->get_html($preview);
}
}
public function get_pro_url() {
return 'http://aspexi.com/downloads/aspexi-facebook-like-box-sidebox-hd/?src=free_plugin';
}
public function get_pro_link() {
$ret = '';
$ret .= ' '.__( 'Get PRO version', 'aspexifbsidebox' ).' ';
return $ret;
}
public function get_html( $preview = false ) {
$url = apply_filters( 'aspexifbsidebox_url', $this->cf['url'] );
$status = apply_filters( 'aspexifbsidebox_status', $this->cf['status'] );
// Disable maybe
if( ( !strlen( $url ) || 'enabled' != $status ) && !$preview )
return;
// Options
$locale = apply_filters( 'aspexifbsidebox_locale', $this->cf['locale'] );
$height = 218;
$width = 296;
$placement = 'right';
$btspace = 0;
$btimage = 'fb1-right.png';
$bordercolor = '#3B5998';
$borderwidth = 2;
$bgcolor = '#ffffff';
$css_placement = array();
if( 'left' == $placement ) {
$css_placement[0] = 'right';
$css_placement[1] = '0 '.(51+$btspace).'px 0 5px';
} else {
$css_placement[0] = 'left';
$css_placement[1] = '0 5px 0 '.(51+$btspace).'px';
}
$css_placement[2] = '50%;margin-top:-'.floor($height/2).'px';
$smallscreenscss = '';
if( $width > 0 ) {
$widthmax = (int)($width + 2 * $borderwidth + 48 + 30);
$smallscreenscss = '@media (max-width: '.$widthmax.'px) { #aspexifbsidebox { display: none; } }';
}
$stream = 'false';
$header = 'false';
// Facebook button image (check in THEME CHILD -> THEME PARENT -> PLUGIN DIR)
// TODO: move this to admin page
$users_button_custom = '/plugins/'.basename( dirname( __FiLE__ ) ).'/images/aspexi-fb-custom.png';
$users_button_template = get_template_directory() . $users_button_custom;
$users_button_child = get_stylesheet_directory() . $users_button_custom;
$button_uri = '';
if( file_exists( $users_button_child ) )
$button_uri = get_stylesheet_directory_uri() . $users_button_custom;
elseif( file_exists( $users_button_template ) )
$button_uri = get_template_directory_uri() . $users_button_custom;
elseif( file_exists( plugin_dir_path( __FILE__ ).'images/'.$btimage ) )
$button_uri = ASPEXIFBSIDEBOX_URL.'images/'.$btimage;
if( '' == $button_uri ) {
$button_uri = ASPEXIFBSIDEBOX_URL.'images/fb1-right.png';
}
$button_uri = apply_filters( 'aspexifbsidebox_button_uri', $button_uri );
$output = '';
$page_url = 'https://www.facebook.com/'.$url;
$output .= '
';
$output = apply_filters( 'aspexifbsidebox_output', $output );
echo $output;
}
public function init_scripts() {
$width = 296;
$placement = 'right';
$slideon = 'hover';
$ismobile = wp_is_mobile();
wp_enqueue_script( 'aspexi-facebook-side-box', ASPEXIFBSIDEBOX_URL . 'js/afsb.js', array( 'jquery' ), false, true );
wp_localize_script( 'aspexi-facebook-side-box', 'afsb', array(
'slideon' => $slideon,
'placement' => $placement,
'width' => (int)$width,
'ismobile' => $ismobile
) );
}
public static function uninstall() {
delete_option( 'aspexifbsidebox_options' );
}
public function admin_scripts() {
wp_enqueue_script( 'aspexi-facebook-side-box-admin', ASPEXIFBSIDEBOX_URL . 'js/afbsb-admin.js', array( 'jquery' ), false, true );
wp_localize_script( 'aspexi-facebook-side-box-admin', 'aflb_admin', array(
'nonce' => wp_create_nonce( "afbsbhidenotice-nonce" )
) );
return;
}
public function extras_init() {
/* qTranslate */
add_filter( 'aspexifbsidebox_admin_settings', array( &$this, 'extras_qtranslate_admin' ) );
add_filter( 'aspexifbsidebox_admin_settings', array( &$this, 'extras_polylang_admin' ) );
}
public function extras_qtranslate_detect() {
global $q_config;
return (isset($q_config) && !empty($q_config));
}
public function extras_qtranslate_admin( $extra_admin_content ) {
$qtranslate_locale = $this->extras_qtranslate_detect();
if( $qtranslate_locale ) {
$extra_admin_content .= '
'.__('qTranslate/mqTranslate', 'aspexifbsidebox').''.__('Try to detect qTranslate/mqTranslate language and force it instead of language set in Localization.', 'aspexifbsidebox').'
'.$this->get_pro_link().'
';
}
return $extra_admin_content;
}
public function extras_polylang_admin( $extra_admin_content ) {
if(function_exists('pll_current_language')) {
$extra_admin_content .= '
'.__('Polylang', 'aspexifbsidebox').''.__('Try to detect Polylang language and force it instead of language set in Localization.', 'aspexifbsidebox').'
'.$this->get_pro_link().'
';
}
return $extra_admin_content;
}
public function admin_notices() {
if( !isset($this->cf['hide_notice']) || @$this->cf['hide_notice'] != '1' ) {
?>
cf['hide_notice'] = '1';
update_option( 'aspexifbsidebox_options', $this->cf, '', 'yes' );
die();
}
}
/* Let's start the show */
global $aspexifbsidebox;
$aspexifbsidebox = new AspexiFBsidebox();
}