settings(); add_action( 'admin_menu', array( &$this, 'admin_menu')); add_action( 'init', array( &$this, 'init' ), 10 ); add_action( 'wp_footer', array( &$this, 'get_html' ), 21 ); add_action( 'admin_enqueue_scripts', array( &$this, 'admin_init_scripts') ); 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( 'AspexiShareButtons', 'uninstall' ) ); } /* WP init action */ public function init() { /* Internationalization */ load_plugin_textdomain( 'aspexisharebuttons', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } public function settings() { /* Defaults */ $cf_default = array( 'aspexisharebuttons_version' => ASPEXISHAREBUTTONS_VERSION, 'facebook' => '1', 'twitter' => '1' ); if ( !get_option( 'aspexisharebuttons_options' ) ) add_option( 'aspexisharebuttons_options', $cf_default, '', 'yes' ); $this->cf = get_option( 'aspexisharebuttons_options' ); /* Upgrade */ if( $this->cf['aspexisharebuttons_version'] != ASPEXISHAREBUTTONS_VERSION ) { switch( $this->cf['aspexisharebuttons_version'] ) { default: $this->cf = array_merge( $cf_default, (array)$this->cf ); $this->cf['aspexisharebuttons_version'] = ASPEXISHAREBUTTONS_VERSION; update_option( 'aspexisharebuttons_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 .= '

'.$error.'

'; } foreach( (array)$this->messages as $message ) { $ret .= '

'.$message.'

'; } if( $echo ) echo $ret; else return $ret; } public function admin_menu() { add_submenu_page( 'themes.php', __( 'Aspexi Share Buttons', 'aspexisharebuttons' ), __( 'Aspexi Share Buttons', 'aspexisharebuttons' ), '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.')); } if ( isset( $_REQUEST['asb_form_submit'] ) && check_admin_referer( plugin_basename(__FILE__), 'asb_nonce_name' ) ) { // Error checks here - no need in current version // No errors if( !$this->has_errors() ) { $aspexisharebuttons_request_options = array(); $aspexisharebuttons_request_options['facebook'] = ( isset( $_REQUEST['asb_facebook'] ) && 'on' == $_REQUEST['asb_facebook'] ) ? 1 : 0; $aspexisharebuttons_request_options['twitter'] = ( isset( $_REQUEST['asb_twitter'] ) && 'on' == $_REQUEST['asb_twitter'] ) ? 1 : 0; $this->cf = array_merge( (array)$this->cf, $aspexisharebuttons_request_options ); update_option( 'aspexisharebuttons_options', $this->cf, '', 'yes' ); $this->add_message( __( 'Settings saved.', 'aspexisharebuttons' ) ); } } ?>

display_admin_notices( true ); ?>

cf['facebook'] ) echo ' checked'; ?> />
get_pro_link(); ?>
get_pro_link(); ?>
get_pro_link(); ?>


cf['twitter'] ) echo ' checked'; ?>/>
get_pro_link(); ?>
get_pro_link(); ?>
get_pro_link(); ?>


get_pro_link(); ?>
get_pro_link(); ?>
0 ) : foreach ($types as $post_type_name) : ?>


get_pro_link(); ?>

get_pro_link(); ?>

get_pro_url().'" target="_blank">'.__( 'Get PRO version', 'aspexisharebuttons' ).''; return $ret; } public function get_html() { $facebook = 1 == apply_filters( 'aspexisharebuttons_facebook', $this->cf['facebook'] ) ? true : false; $twitter = 1 == apply_filters( 'aspexisharebuttons_twitter', $this->cf['twitter'] ) ? true : false; if( !$facebook && !$twitter ) return; $facebook_html = $twitter_html = ''; // Get current page URL if( is_home() || is_front_page() ) { $permalink = get_home_url(); $title = esc_attr(strip_tags(get_bloginfo('name'))); } else { $post = get_the_ID(); $permalink = get_permalink($post->ID); $title = esc_attr(strip_tags(get_the_title($post->ID))); } if( !$permalink ) return; // Generate share URLs if( $facebook ) { $facebook_link = 'https://www.facebook.com/sharer/sharer.php?u='.urlencode( $permalink ); $facebook_class = array( 'aspexisharebuttons_col', 'aspexisharebuttons_col_facebook' ); $facebook_html = '
'.apply_filters( 'aspexisharebuttons_facebook_icon', '' ).apply_filters( 'aspexisharebuttons_facebook_copy', __('Share on Facebook', 'aspexisharebuttons' ) ).'
'; } if( $twitter ) { $twitter_link = 'https://twitter.com/intent/tweet?text='.$this->urlencode_helper( mb_strimwidth( $title, 0, 140 ) ).'&url='.urlencode( $permalink ); $twitter_class = array( 'aspexisharebuttons_col', 'aspexisharebuttons_col_twitter' ); $twitter_html = '
'.apply_filters( 'aspexisharebuttons_twitter_icon', '' ).apply_filters( 'aspexisharebuttons_twitter_copy', __('Share on Twitter', 'aspexisharebuttons' ) ).'
'; } if( $facebook && $twitter ) { $facebook_class[] = 'aspexisharebuttons_col_50'; $twitter_class[] = 'aspexisharebuttons_col_50'; } $css = ''; $html = '
'; $html .= $facebook_html.$twitter_html; $html .= '
'; $output = apply_filters( 'aspexisharebuttons_css', $css ); $output .= apply_filters( 'aspexisharebuttons_html', $html ); echo $output; } public function admin_init_scripts() { if (is_admin() && isset($_GET['page']) && $_GET['page'] == ASPEXISHAREBUTTONS_BASENAME) { wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'asb_admin', ASPEXISHAREBUTTONS_URL . 'js/asb_admin.js', array( 'wp-color-picker' ), false, true ); } } public function init_scripts() { wp_enqueue_style( 'dashicons' ); return; } public static function uninstall() { delete_option( 'aspexisharebuttons_options' ); } public function admin_scripts() { // premium only return; } function urlencode_helper($string) { $a = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D'); $b = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]"); return str_replace($a, $b, urlencode($string)); } } /* Let's start the show */ global $aspexisharebuttons; $aspexisharebuttons = new AspexiShareButtons(); }