__('Standard'), 'aside' => __('Aside'), 'image' => __('Image'), 'link' => __('Link'), 'quote' => __('Quote'), 'status' => __('Status'), ); // post types without excerpts global $likebtn_no_excerpts; $likebtn_no_excerpts = array( LIKEBTN_ENTITY_PAGE, LIKEBTN_ENTITY_COMMENT ); // post types titles global $likebtn_entity_titles; $likebtn_entity_titles = array( LIKEBTN_ENTITY_POST => __('Posts'), LIKEBTN_ENTITY_PAGE => __('Pages'), LIKEBTN_ENTITY_POST_LIST => __('Post List'), LIKEBTN_ENTITY_COMMENT => __('Comments'), LIKEBTN_ENTITY_USER => __('User'), LIKEBTN_ENTITY_CUSTOM_ITEM => __('Custom Items'), LIKEBTN_ENTITY_PRODUCT => __('Products [WooCommerce]'), LIKEBTN_ENTITY_PRODUCT_LIST => __('Product List [WooCommerce]'), LIKEBTN_ENTITY_BP_ACTIVITY_POST => __('Activity Posts [BuddyPress]'), LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE => __('Activity Updates [BuddyPress]'), LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT => __('Activity Comments [BuddyPress]'), LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC => __('Activity Topics [BuddyPress]'), LIKEBTN_ENTITY_BP_MEMBER => __('Member Profiles [BuddyPress]'), LIKEBTN_ENTITY_BBP_POST => __('Forum Posts [bbPress]'), LIKEBTN_ENTITY_BBP_USER => __('User Profiles [bbPress]'), ); // map entities global $likebtn_map_entities; $likebtn_map_entities = array( LIKEBTN_ENTITY_BP_MEMBER => LIKEBTN_ENTITY_USER, LIKEBTN_ENTITY_BBP_USER => LIKEBTN_ENTITY_USER ); // entities which are not based on posts global $likebtn_nonpost_entities; $likebtn_nonpost_entities = array( LIKEBTN_ENTITY_COMMENT, LIKEBTN_ENTITY_CUSTOM_ITEM, LIKEBTN_ENTITY_BP_ACTIVITY_POST, LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE, LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT, LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC, LIKEBTN_ENTITY_BP_MEMBER, LIKEBTN_ENTITY_BBP_POST, LIKEBTN_ENTITY_BBP_USER ); // bbPress post types in posts table global $likebtn_bbp_post_types; $likebtn_bbp_post_types = array(/*'forum',*/ 'topic', 'reply'); // languages global $likebtn_page_sizes; $likebtn_page_sizes = array( 10, 20, 50, 100, 500, 1000, 5000, ); global $likebtn_post_statuses; $likebtn_post_statuses = array_reverse(get_post_statuses()); // likebtn settings global $likebtn_settings; $likebtn_settings = array( "theme" => array("default" => 'white'), "lang" => array("default" => "en"), "show_like_label" => array("default" => '1'), "show_dislike_label" => array("default" => '0'), "like_enabled" => array("default" => '1'), "lazy_load" => array("default" => '0'), "dislike_enabled" => array("default" => '1'), "icon_like_show" => array("default" => '1'), "icon_dislike_show" => array("default" => '1'), "site_id" => array("default" => ""), "group_identifier" => array("default" => ""), //"local_domain" => array("default" => ''), "domain_from_parent" => array("default" => '0'), //"subdirectory" => array("default" => ''), "item_url" => array("default" => ''), "share_enabled" => array("default" => '1'), "item_title" => array("default" => ''), "item_description" => array("default" => ''), "item_image" => array("default" => ''), "popup_dislike" => array("default" => '0'), "counter_type" => array("default" => "number"), "counter_clickable" => array("default" => '0'), "counter_show" => array("default" => '1'), "counter_padding" => array("default" => ''), "counter_zero_show" => array("default" => '0'), "voting_enabled" => array("default" => '1'), "voting_cancelable" => array("default" => '1'), "voting_both" => array("default" => '0'), "voting_frequency" => array("default" => ''), "addthis_pubid" => array("default" => ''), "addthis_service_codes" => array("default" => ''), "loader_image" => array("default" => ''), "loader_show" => array("default" => '0'), "loader_image" => array("default" => ''), "tooltip_enabled" => array("default" => '1'), "white_label" => array("default" => '0'), "popup_html" => array("default" => ''), "popup_donate" => array("default" => ''), "popup_content_order" => array("default" => 'popup_share,popup_donate,popup_html'), "popup_enabled" => array("default" => '1'), "popup_position" => array("default" => 'top'), "popup_style" => array("default" => 'light'), "popup_hide_on_outside_click" => array("default" => '1'), "event_handler" => array("default" => ''), "info_message" => array("default" => '1'), "i18n_like" => array("default" => ''), "i18n_dislike" => array("default" => ''), "i18n_after_like" => array("default" => ''), "i18n_after_dislike" => array("default" => ''), "i18n_like_tooltip" => array("default" => ''), "i18n_dislike_tooltip" => array("default" => ''), "i18n_unlike_tooltip" => array("default" => ''), "i18n_undislike_tooltip" => array("default" => ''), "i18n_share_text" => array("default" => ''), "i18n_popup_close" => array("default" => ''), "i18n_popup_text" => array("default" => ''), "i18n_popup_donate" => array("default" => '') ); // removed settings global $likebtn_settings_deprecated; $likebtn_settings_deprecated = array( 'style' => array(), 'display_only' => array(), 'unlike_allowed' => array(), 'like_dislike_at_the_same_time' => array(), 'show_copyright' => array() ); // plans global $likebtn_plans; $likebtn_plans = array( LIKEBTN_PLAN_TRIAL => 'TRIAL', LIKEBTN_PLAN_FREE => 'FREE', LIKEBTN_PLAN_PLUS => 'PLUS', LIKEBTN_PLAN_PRO => 'PRO', LIKEBTN_PLAN_VIP => 'VIP', LIKEBTN_PLAN_ULTRA => 'ULTRA', ); // themes global $likebtn_styles; $likebtn_styles = array( 'white', 'lightgray', 'gray', 'black', 'padded', 'drop', 'line', 'github', 'transparent', 'youtube', 'habr', 'heartcross', 'plusminus', 'google', 'greenred', 'large', 'elegant', 'disk', 'squarespace', 'slideshare', 'baidu', 'uwhite', 'ublack', 'uorange', 'ublue', 'ugreen', 'direct', 'homeshop' ); // languages global $likebtn_default_locales; $likebtn_default_locales = array( 'en' => array('name' => 'English', 'en_name' => 'English', 'iso' => 'en' ), 'ru' => array('name' => 'Русский', 'en_name' => 'Russian', 'iso' => 'ru' ), 'de' => array('name' => 'Deutsch', 'en_name' => 'German', 'iso' => 'de' ), 'ja' => array('name' => '日本語', 'en_name' => 'Japanese', 'iso' => 'jp' ), 'uk' => array('name' => 'Українська мова', 'en_name' => 'Ukrainian', 'iso' => 'uk' ), 'kk' => array('name' => 'Қазақ тілі', 'en_name' => 'Kazakh', 'iso' => 'kk' ), 'nl' => array('name' => 'Nederlands', 'en_name' => 'Dutch', 'iso' => 'nl' ), 'hu' => array('name' => 'Magyar', 'en_name' => 'Hungarian', 'iso' => 'hu' ), 'sv' => array('name' => 'Svenska', 'en_name' => 'Swedish', 'iso' => 'sv' ), 'tr' => array('name' => 'Türkçe', 'en_name' => 'Turkish', 'iso' => 'tr' ), 'es' => array('name' => 'Español', 'en_name' => 'Spanish', 'iso' => 'es' ), ); // languages global $likebtn_sync_intervals; $likebtn_sync_intervals = array( 5, 15, 30, 60, 90, 120, ); // LikeBtn website locales available global $likebtn_website_locales; $likebtn_website_locales = array( 'en', 'ru' ); // Form options global $likebtn_settings_options; $likebtn_settings_options = array( 'likebtn_plan' => LIKEBTN_PLAN_TRIAL, 'likebtn_account_email' => '', 'likebtn_account_api_key' => '', 'likebtn_sync_inerval' => '', 'likebtn_site_id' => '' ); // Form entity options global $likebtn_buttons_options; $likebtn_buttons_options = array( 'likebtn_show' => '1', 'likebtn_use_settings_from' => '', 'likebtn_post_format' => array('all'), 'likebtn_exclude_sections' => array(), 'likebtn_exclude_categories' => array(), 'likebtn_allow_ids' => '', 'likebtn_exclude_ids' => '', 'likebtn_user_logged_in' => '', 'likebtn_position' => LIKEBTN_POSITION_BOTTOM, 'likebtn_alignment' => LIKEBTN_ALIGNMENT_LEFT, 'likebtn_html_before' => '', 'likebtn_html_after' => '' ); // Internal settings global $likebtn_internal_options; $likebtn_internal_options = array( 'likebtn_last_sync_time' => 0, 'likebtn_last_successfull_sync_time' => 0, 'likebtn_plugin_v' => '', 'likebtn_installation_timestamp' => '', // 'likebtn_db_version' => 0, ); // Internal settings global $likebtn_entities_config; $likebtn_entities_config = array( 'theme' => array( LIKEBTN_ENTITY_PRODUCT => array('value'=>'github'), LIKEBTN_ENTITY_COMMENT => array('value'=>'transparent'), LIKEBTN_ENTITY_BP_ACTIVITY_POST => array('value'=>'transparent'), LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE => array('value'=>'transparent'), LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT => array('value'=>'transparent'), LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC => array('value'=>'transparent'), LIKEBTN_ENTITY_BP_MEMBER => array('value'=>'github'), LIKEBTN_ENTITY_BBP_USER => array('value'=>'github'), ), 'popup_position' => array( LIKEBTN_ENTITY_BP_MEMBER => array('value'=>'bottom'), LIKEBTN_ENTITY_BP_ACTIVITY_POST => array('value'=>'left'), LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE => array('value'=>'left'), LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT => array('value'=>'left'), LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC => array('value'=>'left') ), 'likebtn_post_format' => array( LIKEBTN_ENTITY_BP_MEMBER => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_POST => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC => array('hide'=>true) ), 'likebtn_exclude_sections' => array( LIKEBTN_ENTITY_BP_MEMBER => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_POST => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC => array('hide'=>true) ), 'likebtn_exclude_categories' => array( LIKEBTN_ENTITY_BP_MEMBER => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_POST => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC => array('hide'=>true) ), 'likebtn_allow_ids' => array( LIKEBTN_ENTITY_BP_MEMBER => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_POST => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC => array('hide'=>true) ), 'likebtn_exclude_ids' => array( LIKEBTN_ENTITY_BP_MEMBER => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_POST => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT => array('hide'=>true), LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC => array('hide'=>true) ), 'likebtn_position' => array( LIKEBTN_ENTITY_PRODUCT => array('hide'=>true), LIKEBTN_ENTITY_BP_MEMBER => array('hide'=>true), LIKEBTN_ENTITY_BBP_USER => array('hide'=>true) ), 'likebtn_alignment' => array( LIKEBTN_ENTITY_PRODUCT => array('hide'=>true), LIKEBTN_ENTITY_BP_MEMBER => array('hide'=>true), LIKEBTN_ENTITY_BBP_USER => array('hide'=>true) ), ); ############### ### Backend ### ############### // i18n function /* function likebtn_trans($text, $params = null) { if (!is_array($params)) { $params = func_get_args(); $params = array_slice($params, 1); } return vsprintf(__($text, LIKEBTN_I18N_DOMAIN), $params); } */ // initicalization function likebtn_init() { _likebtn_plugin_on_load(); load_plugin_textdomain(LIKEBTN_I18N_DOMAIN, false, dirname(plugin_basename(__FILE__)) . '/languages'); if (is_admin()) { wp_enqueue_script('jquery'); } } add_action('init', 'likebtn_init'); // add Settings link to the plugin list page function likebtn_links($links, $file) { $plugin_file = basename(__FILE__); if (basename($file) == $plugin_file) { $settings_link = '' . __('Settings', LIKEBTN_I18N_DOMAIN) . ''; array_unshift($links, $settings_link); } return $links; } add_filter('plugin_action_links', 'likebtn_links', 10, 2); // admin options function likebtn_admin_menu() { $logo_url = _likebtn_get_public_url() . 'img/menu_icon.png'; add_menu_page(__('Like Buttons', LIKEBTN_I18N_DOMAIN), __('Like Buttons', LIKEBTN_I18N_DOMAIN), 'manage_options', 'likebtn_buttons', '', $logo_url); add_submenu_page( 'likebtn_buttons', __('Buttons', LIKEBTN_I18N_DOMAIN) . ' ‹ ' . __('LikeBtn Like Button', LIKEBTN_I18N_DOMAIN), __('Buttons', LIKEBTN_I18N_DOMAIN), 'manage_options', 'likebtn_buttons', 'likebtn_admin_buttons' ); //add_options_page('LikeBtn Like Button', __('LikeBtn Like Button', 'likebtn'), 'activate_plugins', 'likebtn', 'likebtn_admin_content'); add_submenu_page( 'likebtn_buttons', __('Synchronization', LIKEBTN_I18N_DOMAIN) . ' ‹ ' . __('LikeBtn Like Button', LIKEBTN_I18N_DOMAIN), __('Synchronization', LIKEBTN_I18N_DOMAIN), 'manage_options', 'likebtn_settings', 'likebtn_admin_settings' ); add_submenu_page( 'likebtn_buttons', __('Statistics', LIKEBTN_I18N_DOMAIN) . ' ‹ LikeBtn Like Button', __('Statistics', LIKEBTN_I18N_DOMAIN), 'manage_options', 'likebtn_statistics', 'likebtn_admin_statistics' ); add_submenu_page( 'likebtn_buttons', __('Help') . ' ‹ LikeBtn Like Button', __('Help'), 'manage_options', 'likebtn_help', 'likebtn_admin_help' ); } add_action('admin_menu', 'likebtn_admin_menu'); // plugin header function likebtn_admin_head() { $url_css = _likebtn_get_public_url() . 'css/admin.css?ver=' . LIKEBTN_VERSION; $url_js = _likebtn_get_public_url() . 'js/admin.js?ver=' . LIKEBTN_VERSION; echo ''; echo ''; echo ''; echo ''; } add_action('admin_head', 'likebtn_admin_head'); // admin header function likebtn_admin_header() { $logo_url = _likebtn_get_public_url() . 'img/logotype.png'; $header = <<
HEADER; //
// Plan: //
/*$installation_timestamp = get_option('likebtn_installation_timestamp'); if ( (($installation_timestamp && strtotime(date('Y-m-d H:i:s', $installation_timestamp) . ' +' . LIKEBTN_REVIEW_LINK_PERIOD) < time()) || !$installation_timestamp) && (get_option('likebtn_plan') != LIKEBTN_PLAN_FREE && get_option('likebtn_plan') != LIKEBTN_PLAN_TRIAL) ) {*/ //} $header .= ' '; echo $header; } // uninstall hook function likebtn_uninstall() { global $likebtn_settings; global $likebtn_settings_options; global $likebtn_buttons_options; global $likebtn_internal_options; $likebtn_entities = _likebtn_get_entities(); foreach ($likebtn_settings_options as $option_name=>$option_value) { delete_option($option_name); } foreach ($likebtn_entities as $entity_name => $entity_title) { foreach ($likebtn_buttons_options as $option_name=>$option_value) { delete_option($option_name.'_'.$entity_name); } // settings foreach ($likebtn_settings as $option_name => $option_info) { delete_option('likebtn_settings_' . $option_name . '_' . $entity_name); } } foreach ($likebtn_internal_options as $option_name=>$option_value) { delete_option($option_name); } } register_uninstall_hook(__FILE__, 'likebtn_uninstall'); // activation hook function likebtn_activation_hook() { // Install DB _likebtn_db_install(); // Add options _likebtn_add_options(); } // Add options function _likebtn_add_options() { global $likebtn_settings_options; global $likebtn_internal_options; $likebtn_entities = _likebtn_get_entities(); // set default values for options foreach ($likebtn_settings_options as $option_name=>$option_value) { add_option($option_name, $option_value); } // set default options for entities foreach ($likebtn_entities as $entity_name => $entity_title) { _likebtn_add_default_options($entity_name); } // set default values for options foreach ($likebtn_internal_options as $option_name=>$option_value) { add_option($option_name, $option_value); } // For showing review link if (!get_option('likebtn_installation_timestamp')) { add_option('likebtn_installation_timestamp', time()); } add_option('likebtn_db_version', LIKEBTN_DB_VERSION); } // The latest version of DB function _likebtn_db_install() { global $wpdb; $table_name = $wpdb->prefix . LIKEBTN_TABLE_ITEM; $sql = "CREATE TABLE IF NOT EXISTS {$table_name} ( `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `identifier` text NOT NULL, `identifier_hash` varchar(32) NOT NULL, `url` text, `title` text, `description` text, `image` text, `likes` int(11) NOT NULL DEFAULT '0', `dislikes` int(11) NOT NULL DEFAULT '0', `likes_minus_dislikes` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `identifier_hash` (`identifier_hash`), KEY `title` (`title`(1)), KEY `likes` (`likes`), KEY `dislikes` (`dislikes`), KEY `likes_minus_dislikes` (`likes_minus_dislikes`), KEY `identifier` (`identifier`(1)) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } // Plugin loaded function _likebtn_plugin_on_load() { //likebtn_uninstall(); //_likebtn_add_options(); _likebtn_db_update(); _likebtn_update_options(); // Run sunchronization require_once(dirname(__FILE__) . '/likebtn_like_button.class.php'); $likebtn = new LikeBtnLikeButton(); $likebtn->runSyncVotes(); } // Update DB function _likebtn_db_update() { $db_version = (int)get_option('likebtn_db_version'); if (!$db_version) { // Backward compatibility $db_version = (int)get_option('likebtn_like_button_db_version'); } $db_version++; while (function_exists('likebtn_db_update_'.$db_version)) { call_user_func('likebtn_db_update_'.$db_version); update_option("likebtn_db_version", $db_version); $db_version++; } } // database update function function likebtn_db_update_1() { global $wpdb; $table_name = $wpdb->prefix . LIKEBTN_TABLE_ITEM; $sql = "CREATE TABLE IF NOT EXISTS {$table_name} ( `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `identifier` text NOT NULL, `url` text, `title` text, `description` text, `image` text, `likes` int(11) NOT NULL DEFAULT '0', `dislikes` int(11) NOT NULL DEFAULT '0', `likes_minus_dislikes` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `identifier` (`identifier`(1)), KEY `title` (`title`(1)), KEY `likes` (`likes`), KEY `dislikes` (`dislikes`), KEY `likes_minus_dislikes` (`likes_minus_dislikes`) );"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta($sql); } // database update function function likebtn_db_update_2() { global $wpdb; $table_name = $wpdb->prefix . LIKEBTN_TABLE_ITEM; if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") == $table_name) { // Remove UNIQUE from identifier $sql = "DROP INDEX identifier ON {$table_name};"; $wpdb->query($sql); $sql = "CREATE INDEX identifier ON {$table_name} (identifier(1));"; $wpdb->query($sql); $sql = "ALTER TABLE {$table_name} ADD identifier_hash varchar(32) DEFAULT NULL, ADD UNIQUE (identifier_hash);"; $wpdb->query($sql); $sql = "UPDATE {$table_name} SET identifier_hash = md5(identifier);"; $wpdb->query($sql); } } // database update function function likebtn_db_update_3() { global $wpdb; $table_name = $wpdb->prefix . LIKEBTN_TABLE_ITEM; if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") == $table_name) { // Check if there duplicates $duplicates_count = $wpdb->get_results("SELECT count(*) FROM {$table_name} GROUP BY identifier HAVING count(*) > 1"); if (count($duplicates_count) > 0) { // Remove duplicates by creating a proxy table $sql = "CREATE TABLE {$table_name}_tmp AS SELECT * FROM {$table_name};"; $wpdb->query($sql); $sql = "DROP INDEX identifier_hash ON {$table_name}_tmp;"; $wpdb->query($sql); $sql = "UPDATE {$table_name}_tmp SET identifier_hash = md5(identifier);"; $wpdb->query($sql); $sql = "DELETE FROM {$table_name};"; $wpdb->query($sql); $sql = "CREATE UNIQUE INDEX identifier_hash ON {$table_name} (identifier_hash);"; $wpdb->query($sql); $sql = "INSERT IGNORE INTO {$table_name} SELECT * FROM {$table_name}_tmp;"; $wpdb->query($sql); $sql = "DROP TABLE {$table_name}_tmp;"; $wpdb->query($sql); // Set identifier_hash once more $sql = "UPDATE {$table_name} SET identifier_hash = md5(identifier);"; $wpdb->query($sql); $sql = "ALTER TABLE {$table_name} MODIFY identifier_hash varchar(32) NOT NULL;"; $wpdb->query($sql); } else { // Add index once more $sql = "CREATE UNIQUE INDEX identifier_hash ON {$table_name} (identifier_hash);"; $wpdb->query($sql); $sql = "UPDATE {$table_name} SET identifier_hash = md5(identifier);"; $wpdb->query($sql); $sql = "ALTER TABLE {$table_name} MODIFY identifier_hash varchar(32) NOT NULL;"; $wpdb->query($sql); } } } // rename options function likebtn_db_update_4() { // rename options global $likebtn_settings; global $likebtn_settings_deprecated; global $likebtn_settings_options; global $likebtn_buttons_options; global $likebtn_internal_options; // On actiovation at this point options are not added yet _likebtn_add_options(); // no need to rename options //if (!get_option('likebtn_like_button_plan')) { // return true; //} foreach ($likebtn_settings_options as $option_name=>$option_value) { $old_option_name = str_replace('likebtn_', 'likebtn_like_button_', $option_name); update_option($option_name, get_option($old_option_name)); delete_option($old_option_name); } $likebtn_entities = _likebtn_get_entities(); foreach ($likebtn_entities as $entity_name => $entity_title) { foreach ($likebtn_buttons_options as $option_name=>$option_value) { $option_name = $option_name.'_'.$entity_name; $old_option_name = str_replace('likebtn_', 'likebtn_like_button_', $option_name); update_option($option_name, get_option($old_option_name)); delete_option($old_option_name); } // settings $likebtn_settings_all = array_merge($likebtn_settings, $likebtn_settings_deprecated); foreach ($likebtn_settings_all as $option_name => $option_info) { $option_name = 'likebtn_settings_'.$option_name.'_'.$entity_name; $old_option_name = str_replace('likebtn_', 'likebtn_like_button_', $option_name); update_option($option_name, get_option($old_option_name)); delete_option($old_option_name); } } foreach ($likebtn_internal_options as $option_name=>$option_value) { $old_option_name = str_replace('likebtn_', 'likebtn_like_button_', $option_name); update_option($option_name, get_option($old_option_name)); delete_option($old_option_name); } } // update options function _likebtn_update_options() { $likebtn_entities = _likebtn_get_entities(); foreach ($likebtn_entities as $entity_name => $entity_title) { // Set default settings for new entity // User lang parameter to check if option exists if (!get_option('likebtn_settings_lang_' . $entity_name)) { _likebtn_add_default_options($entity_name); } // Backward compatibility if (get_option('likebtn_settings_display_only_' . $entity_name)) { if (get_option('likebtn_settings_display_only_' . $entity_name) == '1') { update_option('likebtn_settings_voting_enabled_' . $entity_name, '0'); } delete_option('likebtn_settings_display_only_' . $entity_name); } if (get_option('likebtn_settings_unlike_allowed_' . $entity_name)) { if (get_option('likebtn_settings_unlike_allowed_' . $entity_name) == '1') { update_option('likebtn_settings_voting_cancelable_' . $entity_name, '1'); } delete_option('likebtn_settings_unlike_allowed_' . $entity_name); } if (get_option('likebtn_settings_like_dislike_at_the_same_time_' . $entity_name)) { if (get_option('likebtn_settings_like_dislike_at_the_same_time_' . $entity_name) == '1') { update_option('likebtn_settings_voting_both_' . $entity_name, '1'); } delete_option('likebtn_settings_like_dislike_at_the_same_time_' . $entity_name); } if (get_option('likebtn_settings_show_copyright_' . $entity_name) === '0') { update_option('likebtn_settings_white_label_' . $entity_name, '1'); delete_option('likebtn_settings_show_copyright_' . $entity_name); } if (get_option('likebtn_settings_style_' . $entity_name)) { update_option('likebtn_settings_theme_' . $entity_name, get_option('likebtn_settings_style_' . $entity_name)); delete_option('likebtn_settings_style_' . $entity_name); } if (get_option('likebtn_settings_revote_period_' . $entity_name)) { update_option('likebtn_settings_voting_frequency_' . $entity_name, get_option('likebtn_settings_revote_period_' . $entity_name)); delete_option('likebtn_settings_revote_period_' . $entity_name); } // Process likebtn_post_view_mode_ for Excerpt entities if (_likebtn_has_list_flag($entity_name)) { $original_name = _likebtn_cut_list_flag($entity_name); if (get_option('likebtn_post_view_mode_' . $entity_name) && get_option('likebtn_show_' . $original_name) == '1') { if (in_array(get_option('likebtn_post_view_mode_' . $entity_name), array('excerpt', 'both')) && get_option('likebtn_show_' . $entity_name) != '1') { update_option('likebtn_show_' . $entity_name, '1'); update_option('likebtn_use_settings_from_' . $entity_name, $original_name); } delete_option('likebtn_post_view_mode_' . $entity_name); } } } } // set default options for post type function _likebtn_add_default_options($entity_name) { global $likebtn_settings; global $likebtn_buttons_options; global $likebtn_entities_config; foreach ($likebtn_buttons_options as $option_name=>$option_value) { switch ($option_name) { case 'likebtn_show': if ($entity_name == LIKEBTN_ENTITY_COMMENT) { $option_value = '0'; } break; case 'likebtn_use_settings_from': // Set copy settings for list entities if (_likebtn_has_list_flag($entity_name)) { $option_value = _likebtn_cut_list_flag($entity_name); } break; case 'likebtn_position': if ($entity_name == LIKEBTN_ENTITY_PRODUCT || $entity_name == LIKEBTN_ENTITY_PRODUCT_LIST) { $option_value = LIKEBTN_POSITION_TOP; } break; } add_option($option_name.'_'.$entity_name, $option_value); } // settings foreach ($likebtn_settings as $option_name => $option_info) { $value = $option_info['default']; if (!empty($likebtn_entities_config[$option_name][$entity_name]['value'])) { $value = $likebtn_entities_config[$option_name][$entity_name]['value']; } add_option('likebtn_settings_' . $option_name . '_' . $entity_name, $value); } } register_activation_hook(__FILE__, 'likebtn_activation_hook'); // admin init hook: registering settings function likebtn_admin_init() { global $likebtn_settings_options; global $likebtn_settings; global $likebtn_buttons_options; // Synchronization foreach ($likebtn_settings_options as $option_name=>$option_value) { register_setting('likebtn_settings', $option_name); } // Buttons $entity_name = _likebtn_get_subpage(); /*$likebtn_entities = _likebtn_get_entities(); foreach ($likebtn_entities as $entity_name => $entity_title) { _likebtn_register_entity_settings($entity_name); }*/ foreach ($likebtn_buttons_options as $option_name=>$option_value) { register_setting('likebtn_buttons', $option_name.'_'.$entity_name); } // settings foreach ($likebtn_settings as $option_name => $option_info) { register_setting('likebtn_buttons', 'likebtn_settings_' . $option_name.'_'.$entity_name); } } // register entity settings /*function _likebtn_register_entity_settings($entity_name) { global $likebtn_settings; global $likebtn_buttons_options; foreach ($likebtn_buttons_options as $option_name=>$option_value) { register_setting('likebtn_buttons', $option_name.'_'.$entity_name); } // settings foreach ($likebtn_settings as $option_name => $option_info) { register_setting('likebtn_buttons', 'likebtn_settings_' . $option_name.'_'.$entity_name); } }*/ add_action('admin_init', 'likebtn_admin_init'); // admin content function likebtn_admin_settings() { global $likebtn_plans; global $likebtn_sync_intervals; // reset sync interval if (!get_option('likebtn_account_email') || !get_option('likebtn_account_api_key')) { update_option('likebtn_sync_inerval', ''); } likebtn_admin_header(); ?>

PLUS plan or higher are allowed to display more than 1 Like Button per page.', LIKEBTN_I18N_DOMAIN) ?>






  1. LikeBtn.com', LIKEBTN_I18N_DOMAIN) ?>
  2. Websites page.', LIKEBTN_I18N_DOMAIN) ?>


Profile page', LIKEBTN_I18N_DOMAIN) ?>


Websites page', LIKEBTN_I18N_DOMAIN) ?>






*/ ?>

Websites page.', LIKEBTN_I18N_DOMAIN) ?>



 

" />  

  ?> localdomain!50f358d30acf358d30ac000001

Websites page after adding your local website to the panel. See FAQ for more details.', LIKEBTN_I18N_DOMAIN) ?>
*/ ?>

  ?> /subdirectory/

multisite networks in which on-demand sites use paths.', LIKEBTN_I18N_DOMAIN) ?>
*/ ?> runSyncLocales(); $likebtn->runSyncStyles(); // Languages $locales = get_option('likebtn_locales'); $languages = array(); $languages['auto'] = __("Automatic", LIKEBTN_I18N_DOMAIN); if (!$locales) { $locales = $likebtn_default_locales; } foreach ($locales as $locale_code => $locale_info) { $lang_option = $locale_info['en_name']; if ($locale_code != 'en') { $lang_option .= ' - ' . $locale_info['name']; } $languages[$locale_code] = $lang_option; } // Get styles $styles = get_option('likebtn_styles'); $style_options = array(); if (!$styles) { // Styles have not been loaded using API yet, load default languages $styles = $likebtn_styles; } foreach ($styles as $style) { $style_options[] = $style; } // Select tab $subpage = _likebtn_get_subpage(); //$entity_title = $likebtn_entities[$entity_name]; // JS and Styles global $likebtn_website_locales; $likebtn_website_locale = substr(get_bloginfo('language'), 0, 2); if (!in_array($likebtn_website_locale, $likebtn_website_locales)) { $likebtn_website_locale = 'en'; } likebtn_admin_header(); ?>
$entity_title): // Display one entity per page if ($subpage != $entity_name) { continue; } $excluded_sections = get_option('likebtn_exclude_sections_' . $entity_name); if (!is_array($excluded_sections)) { $excluded_sections = array(); } $excluded_categories = get_option('likebtn_exclude_categories_' . $entity_name); if (!is_array($excluded_categories)) { $excluded_categories = array(); } // just in case if (!is_array(get_option('likebtn_post_format_' . $entity_name))) { update_option('likebtn_post_format_' . $entity_name, array('all')); } ?>


prefix; if (is_multisite() && is_super_admin()) { global $blog_id; $blog_list = $wpdb->get_results(" SELECT blog_id, domain FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY blog_id "); // Place current blog on the first place foreach ($blog_list as $blog) { if ($blog->blog_id == $blog_id) { $blogs["{$blog->blog_id}"] = get_blog_option($blog->blog_id, 'blogname') . ' - ' . $blog->domain; break; } } foreach ($blog_list as $blog) { if ($blog->blog_id != $blog_id) { $blogs["{$blog->blog_id}"] = get_blog_option($blog->blog_id, 'blogname') . ' - ' . $blog->domain; } } // Add all $blogs['all'] = __('All Sites'); // Determine selected blog id if (isset($_GET['likebtn_blog_id'])) { if ($_GET['likebtn_blog_id'] == 'all') { $statistics_blog_id = $_GET['likebtn_blog_id']; } else { // Check if blog with ID exists foreach ($blog_list as $blog) { if ($blog->blog_id == (int)$_GET['likebtn_blog_id']) { $statistics_blog_id = (int)$_GET['likebtn_blog_id']; break; } } } } // Prepare prefix if this is not main blog if ($blog_id != 1) { $prefix_prepared = substr($wpdb->prefix, 0, strlen($wpdb->prefix)-strlen($blog_id)-1); } } // add comment statuses $likebtn_post_statuses['0'] = __('Comment not approved', LIKEBTN_I18N_DOMAIN); $likebtn_post_statuses['1'] = __('Comment approved', LIKEBTN_I18N_DOMAIN); $sort_by = $_GET['likebtn_sort_by']; if (!$sort_by) { $sort_by = 'likes'; } $page_size = $_GET['likebtn_page_size']; if (!$page_size) { $page_size = LIKEBTN_STATISTIC_PAGE_SIZE; } $post_id = ''; if (isset($_GET['likebtn_post_id'])) { $post_id = trim(stripcslashes($_GET['likebtn_post_id'])); } $post_title = ''; if (isset($_GET['likebtn_post_title'])) { $post_title = trim(stripcslashes($_GET['likebtn_post_title'])); } $post_status = ''; if (isset($_GET['likebtn_post_status'])) { $post_status = trim($_GET['likebtn_post_status']); } // pagination require_once(dirname(__FILE__) . '/likebtn_like_button_pagination.class.php'); $pagination_target = "admin.php?page=likebtn_statistics"; foreach ($_GET as $get_parameter => $get_value) { $pagination_target .= '&' . $get_parameter . '=' . stripcslashes($get_value); } $p = new LikeBtnLikeButtonPagination(); $p->limit($page_size); // Limit entries per page $p->target($pagination_target); $p->currentPage($_GET[$p->paging]); // Gets and validates the current page $p->prevLabel(__('Previous', LIKEBTN_I18N_DOMAIN)); $p->nextLabel(__('Next', LIKEBTN_I18N_DOMAIN)); if (!isset($_GET['paging'])) { $p->page = 1; } else { $p->page = $_GET['paging']; } // query for limit paging $query_limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit; // query parameters $query_where = ''; // Post type switch ($entity_name) { case LIKEBTN_ENTITY_COMMENT: case LIKEBTN_ENTITY_CUSTOM_ITEM: case LIKEBTN_ENTITY_BP_ACTIVITY_POST: case LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE: case LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT: case LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC: case LIKEBTN_ENTITY_BP_MEMBER: case LIKEBTN_ENTITY_BBP_POST: case LIKEBTN_ENTITY_BBP_USER: break; default: $query_where .= ' AND p.post_type = %s '; $query_parameters[] = $entity_name; break; } // Post ID if ($post_id) { switch ($entity_name) { case LIKEBTN_ENTITY_BP_ACTIVITY_POST: case LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE: case LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT: case LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC: case LIKEBTN_ENTITY_BP_MEMBER: $query_where .= ' AND p.id = %d '; break; case LIKEBTN_ENTITY_COMMENT: $query_where .= ' AND p.comment_ID = %d '; break; default: $query_where .= ' AND p.ID = %d '; break; } $query_parameters[] = $post_id; } if ($post_title) { switch ($entity_name) { case LIKEBTN_ENTITY_BP_ACTIVITY_POST: case LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE: case LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT: case LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC: $query_where .= ' AND LOWER(CONCAT(p.action, p.content)) LIKE "%%%s%%" '; break; case LIKEBTN_ENTITY_BP_MEMBER: $query_where .= ' AND LOWER(p.value) LIKE "%%%s%%" '; break; case LIKEBTN_ENTITY_BBP_USER: $query_where .= ' AND LOWER(CONCAT(p.user_login, p.display_name)) LIKE "%%%s%%" '; break; case LIKEBTN_ENTITY_COMMENT: $query_where .= ' AND LOWER(p.comment_content) LIKE "%%%s%%" '; break; case LIKEBTN_ENTITY_CUSTOM_ITEM: $query_where .= ' AND LOWER(p.identifier) LIKE "%%%s%%" '; break; default: $query_where .= ' AND LOWER(p.post_title) LIKE "%%%s%%" '; break; } $query_parameters[] = strtolower($post_title); } if ($post_status !== '') { if ($entity_name == LIKEBTN_ENTITY_COMMENT) { $query_where .= ' AND p.comment_approved = %s '; } elseif ($entity_name != LIKEBTN_ENTITY_CUSTOM_ITEM) { $query_where .= ' AND p.post_status = %s '; } $query_parameters[] = $post_status; } // order by switch ($sort_by) { case 'likes': $query_orderby = 'ORDER BY likes DESC'; break; case 'dislikes': $query_orderby = 'ORDER BY dislikes DESC'; break; /*case 'last_updated': $query_orderby = 'ORDER BY pm_likes.meta_id DESC'; break;*/ } // For Multisite $query = ''; if ($statistics_blog_id && $statistics_blog_id != 1 && $statistics_blog_id != 'all') { $prefix = "{$prefix_prepared}{$statistics_blog_id}_"; $query = _likebtn_get_statistics_sql($entity_name, $prefix, $query_where, $query_orderby, $query_limit); $query_prepared = $wpdb->prepare($query, $query_parameters); } else if ($statistics_blog_id == 'all') { foreach ($blog_list as $blog) { if ($blog->blog_id == 1) { $prefix = $prefix_prepared; } else { $prefix = "{$prefix_prepared}{$blog->blog_id}_"; } $query_list[] = $wpdb->prepare(_likebtn_get_statistics_sql($entity_name, $prefix, $query_where, '', '', $blog->blog_id . ' as blog_id, '), $query_parameters); } $query_prepared = ' SELECT SQL_CALC_FOUND_ROWS * from (' . implode(' UNION ', $query_list) . ") query {$query_orderby} {$query_limit} "; } else { $query = _likebtn_get_statistics_sql($entity_name, $prefix_prepared, $query_where, $query_orderby, $query_limit); $query_prepared = $wpdb->prepare($query, $query_parameters); } // echo "
";
    // echo $query_prepared;
    // echo $wpdb->prepare($query, $query_parameters);
    // $wpdb->show_errors();
    //exit();
    $statistics = $wpdb->get_results($query_prepared);

    $total_found = 0;
    if (isset($statistics[0])) {
        $query_found_rows = "SELECT FOUND_ROWS() as found_rows";
        $found_rows = $wpdb->get_results($query_found_rows);

        $total_found = (int) $found_rows[0]->found_rows;

        $p->items($total_found);
        $p->calculate(); // Calculates what to show
        $p->parameterName('paging');
        $p->adjacents(1); // No. of page away from the current page
    }

    likebtn_admin_header();
    ?>
    


        

        

:


', items: '', upgrade: '' })" method="post" action=""> total_pages > 0): ?>
show(); ?>
post_id, $statistics_item->url); } else { // Multisite switch ($entity_name) { case LIKEBTN_ENTITY_COMMENT: $post_url = _likebtn_get_blog_comment_link($statistics_item->blog_id, $statistics_item->post_id); break; case LIKEBTN_ENTITY_CUSTOM_ITEM: $post_url = $statistics_item->url; break; case LIKEBTN_ENTITY_BP_ACTIVITY_POST: case LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE: case LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT: case LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC: $post_url = bp_activity_get_permalink($statistics_item->post_id); break; default: $post_url = get_blog_permalink($statistics_item->blog_id, $statistics_item->post_id); break; } } ?> post_title = _likebtn_prepare_title($entity_name, $statistics_item->post_title); ?>
ID
blog_id != $blog_id): ?>disabled="disabled"> post_id; ?> post_id, array(32,32)); ?>  post_title); ?> blog_id, 'blogname') ?> blog_id != $blog_id): ?> likes; ?> likes; ?> blog_id != $blog_id): ?> dislikes; ?> dislikes; ?> likes_minus_dislikes; ?>
total_pages > 0): ?>
show(); ?>
  • WordPress LikeBtn Plugin FAQ', LIKEBTN_I18N_DOMAIN); ?>
  • LikeBtn FAQ', LIKEBTN_I18N_DOMAIN); ?>
  • Forum', LIKEBTN_I18N_DOMAIN); ?>
_likebtn_get_entity_title(LIKEBTN_ENTITY_POST), LIKEBTN_ENTITY_POST_LIST => _likebtn_get_entity_title(LIKEBTN_ENTITY_POST_LIST), LIKEBTN_ENTITY_PAGE => _likebtn_get_entity_title(LIKEBTN_ENTITY_PAGE), ); $post_types = get_post_types(array('public'=>true, '_builtin' => false)); if (!empty($post_types)) { foreach ($post_types as $post_type) { // If bbPress is active miss bbPress custom post types if (_likebtn_is_bbp_active() && in_array($post_type, array('forum', 'topic', 'reply'))) { continue; } $likebtn_entities[$post_type] = _likebtn_get_entity_title($post_type); $likebtn_entities[$post_type.LIKEBTN_LIST_FLAG] = _likebtn_get_entity_title($post_type.LIKEBTN_LIST_FLAG); } } // Append BuddyPress if (_likebtn_is_bp_active()) { $likebtn_entities[LIKEBTN_ENTITY_BP_ACTIVITY_POST] = _likebtn_get_entity_title(LIKEBTN_ENTITY_BP_ACTIVITY_POST); $likebtn_entities[LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE] = _likebtn_get_entity_title(LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE); $likebtn_entities[LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT] = _likebtn_get_entity_title(LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT); $likebtn_entities[LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC] = _likebtn_get_entity_title(LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC); $likebtn_entities[LIKEBTN_ENTITY_BP_MEMBER] = _likebtn_get_entity_title(LIKEBTN_ENTITY_BP_MEMBER); } // Append bbPress if (_likebtn_is_bbp_active()) { $likebtn_entities[LIKEBTN_ENTITY_BBP_POST] = _likebtn_get_entity_title(LIKEBTN_ENTITY_BBP_POST); $likebtn_entities[LIKEBTN_ENTITY_BBP_USER] = _likebtn_get_entity_title(LIKEBTN_ENTITY_BBP_USER); } // append Comments $likebtn_entities[LIKEBTN_ENTITY_COMMENT] = _likebtn_get_entity_title(LIKEBTN_ENTITY_COMMENT); // translate entity names // does not work here /* load_plugin_textdomain(LIKEBTN_I18N_DOMAIN, false, dirname(plugin_basename(__FILE__)) . '/languages'); foreach ($entities as $entity_name => $entity_title) { $entities[$entity_name] = __($entity_title, LIKEBTN_I18N_DOMAIN); } */ // Remove excerpt entities if ($no_list) { foreach ($likebtn_entities as $entity_name=>$entity_title) { if (_likebtn_has_list_flag($entity_name)) { unset($likebtn_entities[$entity_name]); } } } // Add invisible if ($include_invisible) { $likebtn_entities = array_merge($likebtn_entities, array( LIKEBTN_ENTITY_USER => _likebtn_get_entity_title(LIKEBTN_ENTITY_USER), )); } return $likebtn_entities; } // short code function likebtn_shortcode($args) { $entity_name = get_post_type(); $entity_id = get_the_ID(); return _likebtn_get_markup($entity_name, $entity_id, $args, '', false, false); } add_shortcode('likebtn', 'likebtn_shortcode'); ################ ### Widget ### ################ require_once(dirname(__FILE__) . '/likebtn_like_button_most_liked_widget.class.php'); // most liked short code function likebtn_most_liked_widget_shortcode($args) { global $LikeBtnLikeButtonMostLiked; $options = $args; if (isset($options['number'])) { $options['number'] = (int) $options['number']; } $options['entity_name'] = array(); if (isset($options['content_types'])) { $options['entity_name'] = explode(',', $options['content_types']); } return $LikeBtnLikeButtonMostLiked->widget(null, $options); } add_shortcode('likebtn_most_liked', 'likebtn_most_liked_widget_shortcode'); // get current admin subpage function _likebtn_get_subpage() { $likebtn_entities = _likebtn_get_entities(); $subpage = LIKEBTN_ENTITY_POST; if (!empty($_POST['likebtn_subpage']) && array_key_exists($_POST['likebtn_subpage'], $likebtn_entities) ) { $subpage = $_POST['likebtn_subpage']; } elseif (!empty($_GET['likebtn_subpage']) && array_key_exists($_GET['likebtn_subpage'], $likebtn_entities) ) { $subpage = $_GET['likebtn_subpage']; } return $subpage; } // Save BuddyPress Member Profile votes function _likebtn_save_bp_member_votes($entity_id, $likes, $dislikes, $likes_minus_dislikes) { global $wpdb; if (!_likebtn_is_bp_active()) { return false; } $bp_xprofile = $wpdb->get_row(" SELECT id FROM ".$wpdb->prefix."bp_xprofile_data WHERE user_id = {$entity_id} "); if (!empty($bp_xprofile)) { if ($likes !== null) { if (count(bp_xprofile_get_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES)) > 1) { bp_xprofile_delete_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES); bp_xprofile_add_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES, $likes, true); } else { bp_xprofile_update_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES, $likes); } } if ($dislikes !== null) { if (count(bp_xprofile_get_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_DISLIKES)) > 1) { bp_xprofile_delete_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_DISLIKES); bp_xprofile_add_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_DISLIKES, $dislikes, true); } else { bp_xprofile_update_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_DISLIKES, $dislikes); } } if ($likes_minus_dislikes !== null) { if (count(bp_xprofile_get_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES)) > 1) { bp_xprofile_delete_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES); bp_xprofile_add_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes, true); } else { bp_xprofile_update_meta($entity_id, LIKEBTN_BP_XPROFILE_OBJECT_TYPE, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes); } } return true; } return false; } // Save user votes function _likebtn_save_user_votes($entity_id, $likes, $dislikes, $likes_minus_dislikes) { global $wpdb; $user = get_user_by('id', $entity_id); if (!empty($user)) { if ($likes !== null) { if (count(get_user_meta($entity_id, LIKEBTN_META_KEY_LIKES)) > 1) { delete_user_meta($entity_id, LIKEBTN_META_KEY_LIKES); add_user_meta($entity_id, LIKEBTN_META_KEY_LIKES, $likes, true); } else { update_user_meta($entity_id, LIKEBTN_META_KEY_LIKES, $likes); } } if ($dislikes !== null) { if (count(get_user_meta($entity_id, LIKEBTN_META_KEY_DISLIKES)) > 1) { delete_user_meta($entity_id, LIKEBTN_META_KEY_DISLIKES); add_user_meta($entity_id, LIKEBTN_META_KEY_DISLIKES, $dislikes, true); } else { update_user_meta($entity_id, LIKEBTN_META_KEY_DISLIKES, $dislikes); } } if ($likes_minus_dislikes !== null) { if (count(get_user_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES)) > 1) { delete_user_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES); add_user_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes, true); } else { update_user_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes); } } } return true; } ################ ### Frontend ### ################ function _likebtn_get_markup($entity_name, $entity_id, $values = null, $use_entity_name = '', $use_entity_settings = true, $wrap = true) { global $wp_version; global $likebtn_map_entities; $prepared_settings = array(); if (!$use_entity_name) { $use_entity_name = $entity_name; } // Cut excerpt flag from entity_name if ($entity_id !== 'demo') { $entity_name = _likebtn_cut_list_flag($entity_name); } if ($values && $values['identifier']) { $data = ' data-identifier="' . $values['identifier'] . '" '; } else { $identifier = $entity_name; if (!empty($likebtn_map_entities[$entity_name])) { $identifier = $likebtn_map_entities[$entity_name]; } $data = ' data-identifier="' . $identifier . '_' . $entity_id . '" '; } // Site ID if (get_option('likebtn_site_id')) { $data .= ' data-site_id="' . get_option('likebtn_site_id') . '" '; } $likebtn_settings = _likebtn_get_all_settings(); foreach ($likebtn_settings as $option_name => $option_info) { if ($values && isset($values[$option_name])) { // if values passed $option_value = $values[$option_name]; } elseif (!$use_entity_settings) { // Do not use entity value - use default. Usually in shortcodes. $option_value = $option_info['default']; } else { $option_value = get_option('likebtn_settings_' . $option_name . '_' . $use_entity_name); } $option_value_prepared = _likebtn_prepare_option($option_name, $option_value); $prepared_settings[$option_name] = $option_value_prepared; // do not add option if it has default value if ($option_value == $likebtn_settings[$option_name]['default'] || //$option_value === '' || is_bool($option_value) ($option_value === '' && $likebtn_settings[$option_name]['default'] == '0') ) { // option has default value } else { $data .= ' data-' . $option_name . '="' . $option_value_prepared . '" '; } } // Add item options $entity = null; $entity_url = ''; $entity_title = ''; $entity_image = ''; if ($entity_name == LIKEBTN_ENTITY_COMMENT) { $entity = get_comment($entity_id); if ($entity) { $entity_url = get_comment_link($entity->comment_ID); $entity_title = $entity->comment_content; } } else if (in_array($entity_name, array(LIKEBTN_ENTITY_BP_ACTIVITY_POST, LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE, LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT, LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC))) { $entity_title = _likebtn_bp_get_activity_title($entity_id); if (function_exists('bp_activity_get_permalink')) { $entity_url = bp_activity_get_permalink($entity_id); } } else if ($entity_name == LIKEBTN_ENTITY_BP_MEMBER) { if (function_exists('bp_core_get_username')) { $entity_title = bp_core_get_username($entity_id); } if (function_exists('bp_core_get_user_domain')) { $entity_url = bp_core_get_user_domain($entity_id); } } else { $entity = get_post($entity_id); if ($entity) { $entity_url = get_permalink($entity->ID); $entity_title = $entity->post_title; $entity_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($entity->ID), 'large'); if (!empty($entity_image_url[0])) { $entity_image = $entity_image_url[0]; } } } if ($entity_url && !$prepared_settings['item_url']) { $data .= ' data-item_url="' . $entity_url . '" '; } if ($entity_title && !$prepared_settings['item_title']) { $entity_title = preg_replace('/\s+/', ' ', $entity_title); $entity_title = htmlspecialchars($entity_title); $data .= ' data-item_title="' . $entity_title . '" '; } if ($entity_image && !$prepared_settings['item_image']) { $data .= ' data-item_image="' . $entity_image . '" '; } // Set engine and plugin info $data .= ' data-engine="WordPress" '; $data .= ' data-engine_v="' . $wp_version . '" '; $plugin_v = LIKEBTN_VERSION; if ($plugin_v) { $data .= ' data-plugin_v="' . $plugin_v . '" '; } $public_url = _likebtn_get_public_url(); $markup = << MARKUP; // HTML before $html_before = ''; if (isset($values['html_before'])) { $html_before = $values['html_before']; } elseif (get_option('likebtn_html_before_' . $use_entity_name)) { $html_before = get_option('likebtn_html_before_' . $use_entity_name); } if (trim($html_before)) { $markup = $html_before . $markup; } // HTML after $html_after = ''; if (isset($values['html_after'])) { $html_after = $values['html_after']; } elseif (get_option('likebtn_html_after_' . $use_entity_name)) { $html_after = get_option('likebtn_html_after_' . $use_entity_name); } if (trim($html_after)) { $markup = $markup . $html_after; } // alignment if ($wrap) { $alignment = get_option('likebtn_alignment_' . $use_entity_name); if ($alignment == LIKEBTN_ALIGNMENT_RIGHT) { $markup = ''; } elseif ($alignment == LIKEBTN_ALIGNMENT_CENTER) { $markup = ''; } else { $markup = ''; } } return $markup; } // prepare option value function _likebtn_prepare_option($option_name, $option_value) { global $likebtn_settings; $option_value_prepared = $option_value; // do not format i18n options if (!strstr($option_name, 'i18n') && (!isset($likebtn_settings[$option_name]) || $likebtn_settings[$option_name]['default'] !== '')) { if (is_int($option_value)) { if ($option_value) { $option_value_prepared = 'true'; } else { $option_value_prepared = 'false'; } } if ($option_value === '1') { $option_value_prepared = 'true'; } if ($option_value === '0' || $option_value === '') { $option_value_prepared = 'false'; } } // Replace quotes with " to avoid XSS. //$option_value_prepared = str_replace('"', '"', $option_value_prepared); $option_value_prepared = htmlspecialchars($option_value_prepared); return $option_value_prepared; } // get Entity settings function _likebtn_get_entity_settings($entity_name) { global $likebtn_settings; $settings = array(); foreach ($likebtn_settings as $option_name => $option_info) { $settings[$option_name] = get_option('likebtn_settings_' . $option_name . '_' . $entity_name); } return $settings; } // add Like Button to content function likebtn_get_content($content, $callback_content_position = '') { global $likebtn_no_excerpts; if (is_feed()) { return $content; } // detemine entity type $real_entity_name = get_post_type(); // Excerpt mode if (!is_single()) { if (!in_array($real_entity_name, $likebtn_no_excerpts)) { $real_entity_name = $real_entity_name . LIKEBTN_LIST_FLAG; } } // get entity name whose settings should be copied $use_entity_name = get_option('likebtn_use_settings_from_' . $real_entity_name); if ($use_entity_name) { $entity_name = $use_entity_name; } else { $entity_name = $real_entity_name; } if (get_option('likebtn_show_' . $real_entity_name) != '1' || get_option('likebtn_show_' . $entity_name) != '1') { return $content; } $entity_id = get_the_ID(); // get the Posts/Pages IDs where we do not need to show like functionality $allow_ids = explode(",", get_option('likebtn_allow_ids_' . $entity_name)); $exclude_ids = explode(",", get_option('likebtn_exclude_ids_' . $entity_name)); $exclude_categories = get_option('likebtn_exclude_categories_' . $entity_name); $exclude_sections = get_option('likebtn_exclude_sections_' . $entity_name); if (empty($exclude_categories)) { $exclude_categories = array(); } if (empty($exclude_sections)) { $exclude_sections = array(); } // checking if section is excluded if ((in_array('home', $exclude_sections) && is_home()) || (in_array('archive', $exclude_sections) && is_archive())) { return $content; } // checking if category is excluded $categories = get_the_category(); foreach ($categories as $category) { if (in_array($category->cat_ID, $exclude_categories) && !in_array($entity_id, $allow_ids)) { return $content; } } // check if post is excluded if (in_array($entity_id, $exclude_ids)) { return $content; } // check Post view mode /*switch (get_option('likebtn_post_view_mode_' . $entity_name)) { case LIKEBTN_POST_VIEW_MODE_FULL: if (!is_single()) { return $content; } break; case LIKEBTN_POST_VIEW_MODE_EXCERPT: if (is_single()) { return $content; } break; }*/ // check Post format $post_format = get_post_format($entity_id); if (!$post_format) { $post_format = 'standard'; } if (!in_array('all', get_option('likebtn_post_format_' . $entity_name)) && !in_array($post_format, get_option('likebtn_post_format_' . $entity_name)) ) { return $content; } // check user authorization $user_logged_in = get_option('likebtn_user_logged_in_' . $entity_name); if ($user_logged_in === '1' || $user_logged_in === '0') { if ($user_logged_in == '1' && !is_user_logged_in()) { return $content; } if ($user_logged_in == '0' && is_user_logged_in()) { return $content; } } $html = _likebtn_get_markup($real_entity_name, $entity_id, array(), $entity_name); $position = get_option('likebtn_position_' . $entity_name); if ($callback_content_position && function_exists($callback_content_position)) { $content = call_user_func($callback_content_position, $content, $html, $position); } else { if ($position == LIKEBTN_POSITION_TOP) { $content = $html . $content; } elseif ($position == LIKEBTN_POSITION_BOTTOM) { $content = $content . $html; } else { $content = $html . $content . $html; } } return $content; } // add Like Button to the entity (except Comment) function likebtn_the_content($content) { if (get_post_type() == LIKEBTN_ENTITY_PRODUCT) { return $content; } $content = likebtn_get_content($content); return $content; } add_filter('the_content', 'likebtn_the_content'); add_filter('the_excerpt', 'likebtn_the_content'); // WooCommerce - top and button function likebtn_woocommerce_product($content) { $content = likebtn_get_content($content); echo $content; } // WooCommerce - top function likebtn_woocommerce_product_top($content) { $content = likebtn_get_content($content, '_likebtn_woocommerce_content_top'); echo $content; } function _likebtn_woocommerce_content_top($content, $html, $position) { // WooCommerce if ($position == LIKEBTN_POSITION_BOTTOM) { return $content; } else { return $html . $content; } } // WooCommerce - bottom function likebtn_woocommerce_after_main_content($content) { if (!is_single()) { return false; } $content = likebtn_get_content($content, '_likebtn_woocommerce_content_bottom'); echo $content; } function likebtn_woocommerce_product_bottom($content) { $content = likebtn_get_content($content, '_likebtn_woocommerce_content_bottom'); echo $content; } function _likebtn_woocommerce_content_bottom($content, $html, $position) { // WooCommerce if ($position == LIKEBTN_POSITION_TOP) { return $content; } else { return $html . $content; } } add_action('woocommerce_single_product_summary', 'likebtn_woocommerce_product_top', 7); add_action('woocommerce_after_main_content', 'likebtn_woocommerce_after_main_content', 7); add_action('woocommerce_after_shop_loop_item_title', 'likebtn_woocommerce_product_top', 7); add_action('woocommerce_after_shop_loop_item_title', 'likebtn_woocommerce_product_bottom', 12); // add Like Button to the Comment function likebtn_comment_text($content) { global $comment; if (is_feed()) { return $content; } // detemine entity type $real_entity_name = LIKEBTN_ENTITY_COMMENT; // get entity name whose settings should be copied $use_entity_name = get_option('likebtn_use_settings_from_' . $real_entity_name); if ($use_entity_name) { $entity_name = $use_entity_name; } else { $entity_name = $real_entity_name; } if (get_option('likebtn_show_' . $real_entity_name) != '1' || get_option('likebtn_show_' . $entity_name) != '1') { return $content; } $comment_id = $comment->comment_ID; //$comment = get_comment($comment_id, ARRAY_A); $post_id = $comment->comment_post_ID; // get the Posts/Pages IDs where we do not need to show like functionality $allow_ids = explode(",", get_option('likebtn_allow_ids_' . $entity_name)); $exclude_ids = explode(",", get_option('likebtn_exclude_ids_' . $entity_name)); $exclude_categories = get_option('likebtn_exclude_categories_' . $entity_name); $exclude_sections = get_option('likebtn_exclude_sections_' . $entity_name); if (empty($exclude_categories)) { $exclude_categories = array(); } if (empty($exclude_sections)) { $exclude_sections = array(); } // checking if section is excluded if ((in_array('home', $exclude_sections) && is_home()) || (in_array('archive', $exclude_sections) && is_archive())) { return $content; } // checking if category is excluded $categories = get_the_category(); foreach ($categories as $category) { if (in_array($category->cat_ID, $exclude_categories) && !in_array($post_id, $allow_ids)) { return $content; } } // check if post is excluded if (in_array($post_id, $exclude_ids)) { return $content; } // check Post view mode - no need // check Post format $post_format = get_post_format($post_id); if (!$post_format) { $post_format = 'standard'; } if (!in_array('all', get_option('likebtn_post_format_' . $entity_name)) && !in_array($post_format, get_option('likebtn_post_format_' . $entity_name)) ) { return $content; } $html = _likebtn_get_markup($real_entity_name, $comment_id, array(), $entity_name); $position = get_option('likebtn_position_' . $entity_name); if ($position == LIKEBTN_POSITION_TOP) { $content = $html . $content; } elseif ($position == LIKEBTN_POSITION_BOTTOM) { $content = $content . $html; } else { $content = $html . $content . $html; } return $content; } add_filter('comment_text', 'likebtn_comment_text'); // show the Like Button in Post/Page // if Like Button is enabled in admin for Post/Page do not show button twice function likebtn_post($post_id = NULL) { global $post; if (empty($post_id)) { $post_id = $post->ID; } // detemine entity type if (is_page()) { $entity_name = LIKEBTN_ENTITY_PAGE; } else { $entity_name = LIKEBTN_ENTITY_POST; } // check if the Like Button should be displayed // if Like Button enabled for Post or Page in Admin do not show Like Button twice if ($entity_name == LIKEBTN_ENTITY_POST && get_option('likebtn_show_' . LIKEBTN_ENTITY_POST) == '1') { return; } if ($entity_name == LIKEBTN_ENTITY_PAGE && get_option('likebtn_show_' . LIKEBTN_ENTITY_PAGE) == '1') { return; } // 'post' here is for the sake of backward compatibility $html = _likebtn_get_markup('post', $post_id); echo $html; } // get or echo the Like Button in comment function likebtn_comment($comment_id = NULL) { //global $comment; if (empty($comment_id)) { $comment_id = get_comment_ID(); } // if Like Button enabled for Comment in Admin do not show Like Button twice if (get_option('likebtn_show_' . LIKEBTN_ENTITY_COMMENT) == '1') { return; } $html = _likebtn_get_markup(LIKEBTN_ENTITY_COMMENT, $comment_id); echo $html; } // test synchronization callback function likebtn_manual_sync_callback() { $likebtn_account_email = ''; if (isset($_POST['likebtn_account_email'])) { $likebtn_account_email = $_POST['likebtn_account_email']; } $likebtn_account_api_key = ''; if (isset($_POST['likebtn_account_api_key'])) { $likebtn_account_api_key = $_POST['likebtn_account_api_key']; } require_once(dirname(__FILE__) . '/likebtn_like_button.class.php'); $likebtn = new LikeBtnLikeButton(); $sync_response = $likebtn->syncVotes($likebtn_account_email, $likebtn_account_api_key, true); if ($sync_response['result'] == 'success') { $result_text = __('OK', LIKEBTN_I18N_DOMAIN); } else { $result_text = __('Error', LIKEBTN_I18N_DOMAIN); } $response = array( 'result' => $sync_response['result'], 'result_text' => $result_text, 'message' => $sync_response['message'], ); if (!DOING_AJAX) { define('DOING_AJAX', true); } if (ob_get_contents()) { ob_clean(); } wp_send_json($response); } add_action('wp_ajax_likebtn_manual_sync', 'likebtn_manual_sync_callback'); // test synchronization callback function likebtn_test_sync_callback() { $likebtn_account_email = ''; if (isset($_POST['likebtn_account_email'])) { $likebtn_account_email = $_POST['likebtn_account_email']; } $likebtn_account_api_key = ''; if (isset($_POST['likebtn_account_api_key'])) { $likebtn_account_api_key = $_POST['likebtn_account_api_key']; } require_once(dirname(__FILE__) . '/likebtn_like_button.class.php'); $likebtn = new LikeBtnLikeButton(); $test_response = $likebtn->testSync($likebtn_account_email, $likebtn_account_api_key); if ($test_response['result'] == 'success') { $result_text = __('OK', LIKEBTN_I18N_DOMAIN); } else { $result_text = __('Error', LIKEBTN_I18N_DOMAIN); } $response = array( 'result' => $test_response['result'], 'result_text' => $result_text, 'message' => $test_response['message'], ); define( 'DOING_AJAX', true ); ob_clean(); wp_send_json($response); } add_action('wp_ajax_likebtn_test_sync', 'likebtn_test_sync_callback'); // edit item callback function likebtn_edit_item_callback() { $entity_name = ''; if (isset($_POST['entity_name'])) { $entity_name = $_POST['entity_name']; } $entity_id = ''; if (isset($_POST['entity_id'])) { $entity_id = $_POST['entity_id']; } $identifier = likebtn_get_identifier($entity_name, $entity_id); $type = ''; if (isset($_POST['type'])) { $type = $_POST['type']; } $value = ''; if (isset($_POST['value'])) { $value = $_POST['value']; } require_once(dirname(__FILE__) . '/likebtn_like_button.class.php'); $likebtn = new LikeBtnLikeButton(); $edit_response = $likebtn->edit($identifier, $type, $value); if ($edit_response['result'] == 'success') { $result_text = __('OK', LIKEBTN_I18N_DOMAIN); // Update custom fields if ($type == '1') { $likes = $value; $dislikes = null; } else { $dislikes = $value; $likes = null; } $likebtn->updateCustomFields($identifier, $likes, $dislikes); } else { $result_text = __('Error', LIKEBTN_I18N_DOMAIN); } $response = array( 'result' => $edit_response['result'], 'result_text' => $result_text, 'message' => $edit_response['message'], 'value' => $value ); define( 'DOING_AJAX', true ); ob_clean(); wp_send_json($response); } add_action('wp_ajax_likebtn_edit_item', 'likebtn_edit_item_callback'); // reset items likes/dislikes function likebtn_reset($entity_name, $items) { $counter = 0; if (empty($entity_name) || empty($items)) { return false; } require_once(dirname(__FILE__) . '/likebtn_like_button.class.php'); $likebtn = new LikeBtnLikeButton(); // prepare an array for resettings in the CMS $reset_list = array(); $reset_list['response'] = array('items'=>array()); foreach ($items as $item_identifier) { $identifier = $entity_name . '_' . $item_identifier; // reset votes in LikeBtn $likebtn_result = $likebtn->reset($identifier); $reset_list['response']['items'][] = array( 'identifier' => $identifier, 'likes' => 0, 'dislikes' => 0 ); if ($likebtn_result) { $counter++; } } if ($reset_list) { $likebtn->updateVotes($reset_list); } return $counter; } // get entity identifier function likebtn_get_identifier($entity_name, $entity_id) { $identifier = $entity_name . '_' . $entity_id; return $identifier; } // get comments sorted by likes function likebtn_comments_sorted_by_likes() { // function for sorting comments by Likes function sort_comments_by_likes($comment_a, $comment_b) { $comment_a_meta = get_comment_meta($comment_a->comment_ID, LIKEBTN_META_KEY_LIKES); $comment_b_meta = get_comment_meta($comment_b->comment_ID, LIKEBTN_META_KEY_LIKES); $comment_a_likes = (int)$comment_a_meta[0]; $comment_b_likes = (int)$comment_b_meta[0]; if ($comment_a_likes > $comment_b_likes) { return -1; } elseif ($comment_a_likes < $comment_b_likes) { return 1; } return 0; } global $wp_query; $comments = $wp_query->comments; usort($comments, 'sort_comments_by_likes'); return $comments; } // get comments sorted by dislikes function likebtn_comments_sorted_by_dislikes() { // function for sorting comments by Likes function sort_comments_by_dislikes($comment_a, $comment_b) { $comment_a_meta = get_comment_meta($comment_a->comment_ID, LIKEBTN_META_KEY_DISLIKES); $comment_b_meta = get_comment_meta($comment_b->comment_ID, LIKEBTN_META_KEY_DISLIKES); $comment_a_dislikes = (int)$comment_a_meta[0]; $comment_b_dislikes = (int)$comment_b_meta[0]; if ($comment_a_dislikes > $comment_b_dislikes) { return -1; } elseif ($comment_a_dislikes < $comment_b_dislikes) { return 1; } return 0; } global $wp_query; $comments = $wp_query->comments; usort($comments, 'sort_comments_by_dislikes'); return $comments; } // Get the permalink for a comment on another blog. function _likebtn_get_blog_comment_link( $blog_id, $comment_id ) { switch_to_blog( $blog_id ); $link = get_comment_link( $comment_id ); restore_current_blog(); return $link; } // Converts entity name to title function _likebtn_get_entity_title($entity_name) { global $likebtn_entity_titles; $title = ''; $is_excerpt = false; if (_likebtn_has_list_flag($entity_name)) { $is_excerpt = true; } if (!array_key_exists($entity_name, $likebtn_entity_titles)) { $entity_name = _likebtn_cut_list_flag($entity_name); $title = __(str_replace('_', ' ', ucfirst($entity_name))); if ($is_excerpt) { $title .= ' ' . __('List'); } } else { $title = __($likebtn_entity_titles[$entity_name]); } return $title; } // Check if entity has a list flag function _likebtn_has_list_flag($entity_name) { if (strstr($entity_name, LIKEBTN_LIST_FLAG)) { return true; } else { return false; } } // Cut list flag from entity name function _likebtn_cut_list_flag($entity_name) { return str_replace(LIKEBTN_LIST_FLAG, '', $entity_name); } // Check if BuddyPress is installed and active function _likebtn_is_bp_active() { if (function_exists('bp_is_active') && bp_is_active()) { return true; } else { return false; } } // add Like Button to content function _likebtn_get_content_universal($real_entity_name, $entity_id, $content = '', $wrap = true, $current_position = '', $current_alignment = array()) { // get entity name whose settings should be copied $use_entity_name = get_option('likebtn_use_settings_from_' . $real_entity_name); if ($use_entity_name) { $entity_name = $use_entity_name; } else { $entity_name = $real_entity_name; } if (get_option('likebtn_show_' . $real_entity_name) != '1' || get_option('likebtn_show_' . $entity_name) != '1') { return ''; } // check user authorization $user_logged_in = get_option('likebtn_user_logged_in_' . $entity_name); if ($user_logged_in === '1' || $user_logged_in === '0') { if ($user_logged_in == '1' && !is_user_logged_in()) { return ''; } if ($user_logged_in == '0' && is_user_logged_in()) { return ''; } } $html = _likebtn_get_markup($real_entity_name, $entity_id, array(), $entity_name, true, $wrap); $position = get_option('likebtn_position_' . $entity_name); if ($current_position && $position != LIKEBTN_POSITION_BOTH && $current_position != $position) { return $content; } $alignment = get_option('likebtn_alignment_' . $entity_name); if ($current_alignment && !in_array($alignment, $current_alignment)) { return $content; } if ($content) { if ($position == LIKEBTN_POSITION_TOP) { $html = $html . $content; } elseif ($position == LIKEBTN_POSITION_BOTTOM) { $html = $content . $html; } else { $html = $html . $content . $html; } } return $html; } // BuddyPress member profile function likebtn_bp_member() { $content = _likebtn_get_content_universal(LIKEBTN_ENTITY_BP_MEMBER, buddypress()->displayed_user->id); echo $content; } // User profile page. add_action('bp_before_member_header_meta', 'likebtn_bp_member'); // BuddyPress activity function _likebtn_bp_activity($wrap = true, $position = LIKEBTN_POSITION_BOTH, $content = '') { $entity_id = ''; $entity_name = _likebtn_bp_get_entity_name(); //if ($entity_name == LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE || $entity_name == LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT) { $entity_id = bp_get_activity_id(); /*} else { $entity_id = bp_get_activity_secondary_item_id(); }*/ /*if ($entity_name == LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC) { echo 'entity_id'.$entity_id; // Get bbPress topic id if (function_exists("bb_get_first_post")) { $post = bb_get_first_post($entity_id); } else { // We consider ppPress to be installed and enabled return false; // Get from DB /*global $bb_table_prefix; // Load bbPress config file @include_once(?); // Failed loading config file. if (!defined("BBDB_NAME")) return false; $connection = null; if (!$connection = mysql_connect(BBDB_HOST, BBDB_USER, BBDB_PASSWORD, true)){ return false; } if (!mysql_selectdb(BBDB_NAME, $connection)){ return false; } $results = mysql_query("SELECT * FROM {$bb_table_prefix}posts WHERE topic_id={$entity_id} AND post_position=1", $connection); $post = mysql_fetch_object($results);/ } if (empty($post->post_id)) { return false; } $entity_id = $post->post_id; }*/ if (!$entity_name || !$entity_id) { return false; } echo _likebtn_get_content_universal($entity_name, $entity_id, $content, $wrap, $position); } // BuddyPress activity comment function likebtn_bp_activity_comment($content) { //return $content; global $activities_template; if (empty($activities_template) || empty($activities_template->activity) || empty($activities_template->activity->current_comment)) { return $content; } $entity_id = $activities_template->activity->current_comment->id; return _likebtn_get_content_universal(LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT, $entity_id, $content); } // BuddyPress activity top function likebtn_bp_activity_top($content) { return _likebtn_bp_activity(true, LIKEBTN_POSITION_TOP) . $content; } // BuddyPress activity bottom function likebtn_bp_activity_bottom() { return _likebtn_bp_activity(false, LIKEBTN_POSITION_BOTTOM); } // Activity page. //add_action("bp_has_activities", array(&$this, "BuddyPressBeforeActivityLoop")); // BuddyPress activity top add_filter('bp_get_activity_action', 'likebtn_bp_activity_top'); // BuddyPress activity bottom add_action('bp_activity_entry_meta', 'likebtn_bp_activity_bottom'); // BuddyPress activity comment add_filter('bp_get_activity_content', 'likebtn_bp_activity_comment'); // Forum topic page add_filter('bp_has_topic_posts', 'likebtn_bp_activity'); // Get entity name of the current BuddyPress activity // Not working for comments function _likebtn_bp_get_entity_name() { $activity_type = bp_get_activity_type(); switch ($activity_type) { case 'bbp_topic_create': return LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC; case 'new_blog_post': // Post return LIKEBTN_ENTITY_BP_ACTIVITY_POST; case 'new_member': return LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE; default: return LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE; } } // Get activity title function _likebtn_bp_get_activity_title($id) { $activity = null; $title = ''; if (function_exists('bp_activity_get_specific')) { $activity_list = bp_activity_get_specific(array( 'activity_ids' => $id, 'display_comments' => true )); if (!empty($activity_list['activities']) && !empty($activity_list['activities'][0])) { $activity = $activity_list['activities'][0]; } } if ($activity) { if ($activity->action) { $title = $activity->action; } elseif ($activity->content) { $title = $activity->content; } elseif ($activity->primary_link) { $title = $activity->primary_link; } if ($activity->content && $activity->type != 'bbp_topic_create') { $title = $title.': '.$activity->content; } $title = strip_tags($title); } return $title; } // Check if bbPress is installed and active function _likebtn_is_bbp_active() { if (function_exists('bbp_has_replies')) { return true; } else { return false; } } // bbPress function likebtn_bbp_reply($wrap = true, $position = LIKEBTN_POSITION_BOTH, $alignment = '', $content = '') { // Reply to topic $entity = bbp_get_reply(bbp_get_reply_id()); // Topic if (!is_object($entity)) { $entity = bbp_get_topic(bbp_get_topic_id()); } if (!$entity) { return false; } return _likebtn_get_content_universal(LIKEBTN_ENTITY_BBP_POST, $entity->ID, $content, $wrap, $position, $alignment); } // bbPress reply top left & center function likebtn_bbp_has_replies($has_replies) { add_filter('bbp_theme_before_reply_admin_links', 'likebtn_bbp_reply_top_left'); add_filter('bbp_theme_after_reply_admin_links', 'likebtn_bbp_reply_top_right'); add_filter('bbp_get_reply_content', 'likebtn_bbp_reply_bottom'); add_filter('bbp_get_reply_author_link', 'likebtn_bbp_author_link'); return $has_replies; } // bbPress reply top left & center function likebtn_bbp_reply_top_left() { echo likebtn_bbp_reply(false, LIKEBTN_POSITION_TOP, array(LIKEBTN_ALIGNMENT_LEFT, LIKEBTN_ALIGNMENT_CENTER)); } // bbPress reply top left & center function likebtn_bbp_reply_top_right() { echo likebtn_bbp_reply(false, LIKEBTN_POSITION_TOP, array(LIKEBTN_ALIGNMENT_RIGHT)); } // bbPress reply bottom function likebtn_bbp_reply_bottom($content) { echo $content.likebtn_bbp_reply(true, LIKEBTN_POSITION_BOTTOM); } // bbPress thread function likebtn_bbp_author_link($author_link) { global $post; $reply_id = bbp_get_reply_id($post->ID); if (bbp_is_reply_anonymous($reply_id)) { return $author_link; } $author_id = bbp_get_reply_author_id($reply_id); $content = _likebtn_get_content_universal(LIKEBTN_ENTITY_BBP_USER, $author_id); return $author_link . $content; } // bbPress reply bottom function likebtn_bbp_user_profile() { $content = _likebtn_get_content_universal(LIKEBTN_ENTITY_BBP_USER, bbpress()->displayed_user->ID); echo $content; } add_filter('bbp_has_replies', 'likebtn_bbp_has_replies'); add_action('bbp_template_after_user_profile', 'likebtn_bbp_user_profile'); // Add style to frontend function likebtn_enqueue_style() { $src = _likebtn_get_public_url() . 'css/style.css?ver=' . LIKEBTN_VERSION; wp_enqueue_style('likebtn_style', $src); } // Add frontend style add_action('wp_enqueue_scripts', 'likebtn_enqueue_style'); // Current + deprecated settings function _likebtn_get_all_settings() { global $likebtn_settings; global $likebtn_settings_deprecated; return array_merge($likebtn_settings, $likebtn_settings_deprecated); } // Prepare entity title function _likebtn_prepare_title($entity_name, $title, $max = LIKEBTN_WIDGET_TITLE_LENGTH) { $title = stripslashes($title); if (in_array($entity_name, array(LIKEBTN_ENTITY_BP_ACTIVITY_POST, LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE, LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT, LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC))) { $title = strip_tags($title); } if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) { $title = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($title); } /*if ($entity_name == LIKEBTN_ENTITY_COMMENT) { if (mb_strlen($title) > 30) { $title = mb_substr($title, 0, 30) . '...'; } } else*/ return _likebtn_shorten_title($title, $max); } // Shorten title function _likebtn_shorten_title($title, $max = LIKEBTN_WIDGET_TITLE_LENGTH) { if (mb_strlen($title) > $max) { $title = mb_substr($title, 0, $max) . '...'; } return $title; } // Shorten title function _likebtn_shorten_excerpt($excerpt, $max = LIKEBTN_WIDGET_EXCERPT_LENGTH) { if (mb_strlen($excerpt) > $max) { $excerpt = mb_substr($excerpt, 0, $max) . '...'; } return $excerpt; } // Get entity URL function _likebtn_get_entity_url($entity_name, $entity_id, $url = '') { if ($url) { return $url; } switch ($entity_name) { case LIKEBTN_ENTITY_COMMENT: $url = get_comment_link($entity_id); break; case LIKEBTN_ENTITY_BP_ACTIVITY_POST: case LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE: case LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT: case LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC: if (function_exists('bp_activity_get_permalink')) { $url = bp_activity_get_permalink($entity_id); } break; case LIKEBTN_ENTITY_BP_MEMBER: case LIKEBTN_ENTITY_BBP_USER: if (function_exists('bp_core_get_user_domain')) { $url = bp_core_get_user_domain($entity_id); } break; default: $url = get_permalink($entity_id); break; } return $url; }