Advertisement
Guest User

like-hack-edit

a guest
Jul 15th, 2013
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 61.60 KB | None | 0 0
  1. <?php
  2.     /*
  3.     Plugin Name: BuddyPress Like
  4.     Plugin URI: http://bplike.wordpress.com
  5.     Description: Gives users the ability to 'like' content across your BuddyPress enabled site.
  6.     Author: Alex Hempton-Smith
  7.     Version: 0.0.8
  8.     Author URI: http://bplike.wordpress.com
  9.     */
  10.      
  11.     /* Make sure BuddyPress is loaded before we do anything. */
  12.     if ( !function_exists( 'bp_core_install' ) ) {
  13.            
  14.             require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
  15.            
  16.             if ( is_plugin_active( 'buddypress/bp-loader.php' ) ) {
  17.                     require_once ( WP_PLUGIN_DIR . '/buddypress/bp-loader.php' );
  18.             } else {
  19.                     add_action( 'admin_notices', 'bp_like_install_buddypress_notice' );
  20.                     return;
  21.             }
  22.     }
  23.      
  24.     define ( 'BP_LIKE_VERSION', '0.0.8' );
  25.     define ( 'BP_LIKE_DB_VERSION', '10' );
  26.      
  27.     /**
  28.      * bp_like_install()
  29.      *
  30.      * Installs or upgrades the database content
  31.      *
  32.      */
  33.     function bp_like_install() {
  34.      
  35.                     $default_text_strings = array(
  36.                             'like' => array(
  37.                                     'default'       => __('Like', 'buddypress-like'),
  38.                                     'custom'        => __('Like', 'buddypress-like')
  39.                             ),
  40.                             'unlike' => array(
  41.                                     'default'       => __('Unlike', 'buddypress-like'),
  42.                                     'custom'        => __('Unlike', 'buddypress-like')
  43.                             ),
  44.                             'like_this_item' => array(
  45.                                     'default'       => __('Like this item', 'buddypress-like'),
  46.                                     'custom'        => __('Like this item', 'buddypress-like')
  47.                             ),
  48.                             'unlike_this_item' => array(
  49.                                     'default'       => __('Unlike this item', 'buddypress-like'),
  50.                                     'custom'        => __('Unlike this item', 'buddypress-like')
  51.                             ),
  52.                             'view_likes' => array(
  53.                                     'default'       => __('View likes', 'buddypress-like'),
  54.                                     'custom'        => __('View likes', 'buddypress-like')
  55.                             ),
  56.                             'hide_likes' => array(
  57.                                     'default'       => __('Hide likes', 'buddypress-like'),
  58.                                     'custom'        => __('Hide likes', 'buddypress-like')
  59.                             ),
  60.                             'show_activity_likes' => array(
  61.                                     'default'       => __('Show Activity Likes', 'buddypress-like'),
  62.                                     'custom'        => __('Show Activity Likes', 'buddypress-like')
  63.                             ),
  64.                             'show_blogpost_likes' => array(
  65.                                     'default'       => __('Show Blog Post Likes', 'buddypress-like'),
  66.                                     'custom'        => __('Show Blog Post Likes', 'buddypress-like')
  67.                             ),
  68.                             'must_be_logged_in' => array(
  69.                                     'default'       => __('Sorry, you must be logged in to like that.', 'buddypress-like'),
  70.                                     'custom'        => __('Sorry, you must be logged in to like that.', 'buddypress-like')),
  71.                             'record_activity_likes_own' => array(
  72.                                     'default'       => __('%user% likes their own <a href="%permalink%">activity</a>', 'buddypress-like'),
  73.                                     'custom'        => __('%user% likes their own <a href="%permalink%">activity</a>', 'buddypress-like')
  74.                             ),
  75.                             'record_activity_likes_an' => array(
  76.                                     'default'       => __('%user% likes an <a href="%permalink%">activity</a>', 'buddypress-like'),
  77.                                     'custom'        => __('%user% likes an <a href="%permalink%">activity</a>', 'buddypress-like')
  78.                             ),
  79.                             'record_activity_likes_users' => array(
  80.                                     'default'       => __('%user% likes %author%\'s <a href="%permalink%">activity</a>', 'buddypress-like'),
  81.                                     'custom'        => __('%user% likes %author%\'s <a href="%permalink%">activity</a>', 'buddypress-like')
  82.                             ),
  83.                             'record_activity_likes_own_blogpost' => array(
  84.                                     'default'       => __('%user% likes their own blog post, <a href="%permalink%">%title%</a>', 'buddypress-like'),
  85.                                     'custom'        => __('%user% likes their own blog post, <a href="%permalink%">%title%</a>', 'buddypress-like')
  86.                             ),
  87.                             'record_activity_likes_a_blogpost' => array(
  88.                                     'default'       => __('%user% likes a blog post, <a href="%permalink%">%title%</a>', 'buddypress-like'),
  89.                                     'custom'        => __('%user% likes an blog post, <a href="%permalink%">%title%</a>', 'buddypress-like')
  90.                             ),
  91.                             'record_activity_likes_users_blogpost' => array(
  92.                                     'default'       => __('%user% likes %author%\'s blog post, <a href="%permalink%">%title%</a>', 'buddypress-like'),
  93.                                     'custom'        => __('%user% likes %author%\'s blog post, <a href="%permalink%">%title%</a>', 'buddypress-like')
  94.                             ),
  95.                             'get_likes_no_likes' => array(
  96.                                     'default'       => __('Nobody likes this yet.', 'buddypress-like'),
  97.                                     'custom'        => __('Nobody likes this yet.', 'buddypress-like')
  98.                             ),
  99.                             'get_likes_only_liker' => array(
  100.                                     'default'       => __('You are the only person who likes this so far.', 'buddypress-like'),
  101.                                     'custom'        => __('You are the only person who likes this so far.', 'buddypress-like')
  102.                             ),
  103.                             'get_likes_you_and_singular' => array(
  104.                                     'default'       => __('You and %count% other person like this.', 'buddypress-like'),
  105.                                     'custom'        => __('You and %count% other person like this.', 'buddypress-like')
  106.                             ),
  107.                             'get_likes_you_and_plural' => array(
  108.                                     'default'       => __('You and %count% other people like this', 'buddypress-like'),
  109.                                     'custom'        => __('You and %count% other people like this', 'buddypress-like')
  110.                             ),
  111.                             'get_likes_count_people_singular' => array(
  112.                                     'default'       => __('%count% person likes this.', 'buddypress-like'),
  113.                                     'custom'        => __('%count% person likes this.', 'buddypress-like')
  114.                             ),
  115.                             'get_likes_count_people_plural' => array(
  116.                                     'default'       => __('%count% people like this.', 'buddypress-like'),
  117.                                     'custom'        => __('%count% people like this.', 'buddypress-like')
  118.                             ),
  119.                             'get_likes_and_people_singular' => array(
  120.                                     'default'       => __('and %count% other person like this.', 'buddypress-like'),
  121.                                     'custom'        => __('and %count% other person like this.', 'buddypress-like')
  122.                             ),
  123.                             'get_likes_and_people_plural' => array(
  124.                                     'default'       => __('and %count% other people like this.', 'buddypress-like'),
  125.                                     'custom'        => __('and %count% other people like this.', 'buddypress-like')
  126.                             ),
  127.                             'get_likes_likes_this' => array(
  128.                                     'default'       => __('likes this.', 'buddypress-like'),
  129.                                     'custom'        => __('likes this.', 'buddypress-like')
  130.                             ),
  131.                             'get_likes_like_this' => array(
  132.                                     'default'       => __('like this.', 'buddypress-like'),
  133.                                     'custom'        => __('like this.', 'buddypress-like')
  134.                             ),
  135.                             'get_likes_no_friends_you_and_singular' => array(
  136.                                     'default'       => __('None of your friends like this yet, but you and %count% other person does.', 'buddypress-like'),
  137.                                     'custom'        => __('None of your friends like this yet, but you and %count% other person does.', 'buddypress-like')
  138.                             ),
  139.                             'get_likes_no_friends_you_and_plural' => array(
  140.                                     'default'       => __('None of your friends like this yet, but you and %count% other people do.', 'buddypress-like'),
  141.                                     'custom'        => __('None of your friends like this yet, but you and %count% other people do.', 'buddypress-like')
  142.                             ),
  143.                             'get_likes_no_friends_singular' => array(
  144.                                     'default'       => __('None of your friends like this yet, but %count% other person does.', 'buddypress-like'),
  145.                                     'custom'        => __('None of your friends like this yet, but %count% other person does.', 'buddypress-like')
  146.                             ),
  147.                             'get_likes_no_friends_plural' => array(
  148.                                     'default'       => __('None of your friends like this yet, but %count% other people do.', 'buddypress-like'),
  149.                                     'custom'        => __('None of your friends like this yet, but %count% other people do.', 'buddypress-like')
  150.                             )
  151.                     );
  152.      
  153.             $current_settings = get_site_option('bp_like_settings');
  154.      
  155.             if ( $current_settings['post_to_activity_stream'] )
  156.                     $post_to_activity_stream = $current_settings['post_to_activity_stream'];
  157.             else
  158.                     $post_to_activity_stream = 1;
  159.      
  160.             if ( $current_settings['show_excerpt'] )
  161.                     $show_excerpt = $current_settings['show_excerpt'];
  162.             else
  163.                     $show_excerpt = 0;
  164.      
  165.             if ( $current_settings['excerpt_length'] )
  166.                     $excerpt_length = $current_settings['excerpt_length'];
  167.             else
  168.                     $excerpt_length = 140;
  169.      
  170.             if ( $current_settings['likers_visibility'] )
  171.                     $likers_visibility = $current_settings['likers_visibility'];
  172.             else
  173.                     $likers_visibility = 'show_all';
  174.      
  175.             if ( $current_settings['name_or_avatar'] )
  176.                     $name_or_avatar = $current_settings['name_or_avatar'];
  177.             else
  178.                     $name_or_avatar = 'name';
  179.      
  180.             if ( $current_settings['text_strings'] ) :
  181.                    
  182.                     $current_text_strings = $current_settings['text_strings'];
  183.                    
  184.                     /* Go through each string and update the default to the current default, keep the custom settings */
  185.                     foreach( $default_text_strings as $string_name => $string_contents ) :
  186.                    
  187.                             $default = $default_text_strings[$string_name]['default'];
  188.                             $custom = $current_settings['text_strings'][$string_name]['custom'];
  189.                            
  190.                             if ( empty( $custom ) )
  191.                                     $custom = $default;
  192.                            
  193.                             $text_strings[$string_name] = array('default' => $default, 'custom' => $custom);
  194.                    
  195.                     endforeach;
  196.            
  197.             else :
  198.                     $text_strings = $default_text_strings;
  199.             endif;
  200.      
  201.             $settings = array(
  202.                     'likers_visibility'             => $likers_visibility,
  203.                     'post_to_activity_stream'       => $post_to_activity_stream,
  204.                     'show_excerpt'                          => $show_excerpt,
  205.                     'excerpt_length'                        => $excerpt_length,
  206.                     'text_strings'                          => $text_strings,
  207.                     'name_or_avatar'                        => $name_or_avatar
  208.             );
  209.      
  210.             update_site_option( 'bp_like_db_version', BP_LIKE_DB_VERSION );
  211.             update_site_option( 'bp_like_settings', $settings );
  212.      
  213.             add_action( 'admin_notices', 'bp_like_updated_notice' );
  214.     }
  215.      
  216.     /* The notice we show when the plugin is installed. */
  217.     function bp_like_install_buddypress_notice() {
  218.      
  219.             echo '<div id="message" class="error fade"><p style="line-height: 150%">';
  220.             _e('<strong>BuddyPress Like</strong></a> requires the BuddyPress plugin to work. Please <a href="http://buddypress.org">install BuddyPress</a> first, or <a href="plugins.php">deactivate BuddyPress Like</a>.', 'buddypress-like');
  221.             echo '</p></div>';
  222.      
  223.     }
  224.      
  225.     /* The notice we show if the plugin is updated. */
  226.     function bp_like_updated_notice() {
  227.            
  228.             if ( !is_site_admin() )
  229.                     return false;
  230.            
  231.             echo '<div id="message" class="updated fade"><p style="line-height: 150%">';
  232.             printf(__('<strong>BuddyPress Like</strong> has been successfully updated to version %s.', 'buddypress-like'), BP_LIKE_VERSION);
  233.             echo '</p></div>';
  234.      
  235.     }
  236.      
  237.     /**
  238.      * bp_like_check_installed()
  239.      *
  240.      * Checks to see if the DB tables exist or if you are running an old version
  241.      * of the component. If it matches, it will run the installation function.
  242.      * This means we don't have to deactivate and then reactivate.
  243.      *
  244.      */
  245.     function bp_like_check_installed() {
  246.             global $wpdb;
  247.      
  248.             if ( !is_site_admin() )
  249.                     return false;
  250.      
  251.             if ( !get_site_option( 'bp_like_settings' ) || get_site_option( 'bp-like-db-version' ) )
  252.                     bp_like_install();
  253.      
  254.             if ( get_site_option( 'bp_like_db_version' ) < BP_LIKE_DB_VERSION )
  255.                     bp_like_install();
  256.     }
  257.     add_action( 'admin_menu', 'bp_like_check_installed' );
  258.      
  259.     // Hack: make the admin work in wp 3.1 and bp 1.2.8
  260.     add_action( 'network_admin_menu', 'bp_like_check_installed' );
  261.     //add_action( 'admin_menu', 'bp_like_check_installed' );
  262.      
  263.     /**
  264.     * Hack: bp_like_setup_globals()
  265.     *
  266.     *
  267.     * Sets up a Buddypress component to add notifications
  268.     *
  269.     */
  270. function bp_like_setup_globals() {
  271. global $bp, $current_blog;
  272. $bp->bp_like=new stdClass();
  273. $bp->bp_like->id = 'bp-like';
  274. $bp->bp_like->slug = 'bp_like';
  275. $bp->bp_like->notification_callback = 'bp_like_format_notifications';
  276. $bp->active_components[$bp->bp_like->slug] = $bp->bp_like->id;
  277. do_action( 'bp_like_setup_globals' );
  278. }
  279. add_action( 'bp_setup_globals', 'bp_like_setup_globals' );
  280.  
  281. function bp_like_format_notifications( $action, $item_id, $secondary_item_id, $total_items,$format='string') {
  282. global $bp;
  283. $glue="";
  284. $user_names=array();
  285. $activity = new BP_Activity_Activity( $activity_id );
  286. $link=ac_notifier_activity_get_permalink( $activity_id );
  287.  
  288. //si c’est le posteur d’origine, dites que vous êtes, d’autre dire de% s après
  289. if($activity->user_id==$bp->loggedin_user->id){
  290. $text=__("your");
  291. $also="";
  292. }
  293. else{
  294. $text=sprintf(__("%s’s"), bp_core_get_user_displayname ($activity->user_id));//quelqu’un
  295. $also=" also";
  296. }
  297. $ac_action='new_bp_like_'.$item_id;
  298.  
  299. if($action==$ac_action){
  300. // if ( (int)$total_items > 1 ) {
  301. // $users=ac_notifier_find_involved_persons($activity_id);
  302. $total_user= $count=count($users);//montrent de nombreux utilisateurs uniques ont commenté
  303. if($count>2){
  304. $users=array_slice($users, $count-2);//simplement indiquer le nom de deux affiches, le repos doit être aussi et ‘n’ autre a également commenté
  305. $count=$count-2;
  306. $glue=", ";
  307. }
  308. else if($total_user==2)
  309. $glue=" xxxx1xxxx ";//si il ya 2 utilisateurs uniques, disons x et y commenté
  310.  
  311. foreach((array)$users as $user_id)
  312. $user_names[]=bp_core_get_user_displayname ($user_id);
  313.  
  314. if(!empty($user_names))
  315. $commenting_users=join ($glue, $user_names);
  316.  
  317. if($total_user>2)
  318. $text=$commenting_users." xxxxxxxx2xxxxxxx ".$count." xxxx3xxxx".$also." xxxxxxxx4xxxxxxx on " .$text. " post";//peut-on changer la poste à quelque chose de significatif en fonction de l’élément d’activité?
  319. else
  320. $text=$commenting_users.$also ." xxxxxx5xxxxx on ".$text. " post";
  321.  
  322. if($format=='string')
  323. return apply_filters( 'bp_activity_multiple_new_likes_notification', '' . $text . '');
  324. else{
  325. return array('link'=>$link,
  326. 'text'=>$text);
  327. }
  328. return false;
  329. }
  330.  
  331. }
  332.   /**
  333.      * bp_like_get_settings()
  334.      *
  335.      * Returns settings from the database
  336.      *
  337.      */
  338.     function bp_like_get_settings( $option = false ) {
  339.            
  340.             $settings = get_site_option( 'bp_like_settings' );
  341.            
  342.             if (!$option)
  343.                     return $settings;
  344.                    
  345.             else
  346.                     return $settings[$option];
  347.     }
  348.      
  349.     /**
  350.      * bp_like_get_text()
  351.      *
  352.      * Returns a custom text string from the database
  353.      *
  354.      */
  355.     function bp_like_get_text( $text = false, $type = 'custom' ) {
  356.            
  357.             $settings = get_site_option( 'bp_like_settings' );
  358.             $text_strings = $settings['text_strings'];
  359.             $string = $text_strings[$text];
  360.                    
  361.             return $string[$type];
  362.     }
  363.      
  364.     /**
  365.      * bp_like_process_ajax()
  366.      *
  367.      * Runs the relevant function depending on what Ajax call has been made.
  368.      *
  369.      */
  370.     function bp_like_process_ajax() {
  371.             global $bp;
  372.      
  373.             $id = preg_replace( "/\D/", "", $_POST['id'] );
  374.            
  375.             if ( $_POST['type'] == 'like' )
  376.                     bp_like_add_user_like( $id, 'activity' );
  377.            
  378.             if ( $_POST['type'] == 'unlike' )
  379.                     bp_like_remove_user_like( $id, 'activity' );
  380.      
  381.             if ( $_POST['type'] == 'view-likes' )
  382.                     bp_like_get_likes( $id, 'blogpost' );
  383.      
  384.             if ( $_POST['type'] == 'like_blogpost' )
  385.                     bp_like_add_user_like( $id, 'blogpost' );
  386.      
  387.             if ( $_POST['type'] == 'unlike_blogpost' )
  388.                     bp_like_remove_user_like( $id, 'blogpost' );
  389.      
  390.             die();
  391.     }
  392.     add_action( 'wp_ajax_activity_like', 'bp_like_process_ajax' );
  393.      
  394.     /**
  395.      * bp_like_is_liked()
  396.      *
  397.      * Checks to see whether the user has liked a given item.
  398.      *
  399.      */
  400.     function bp_like_is_liked( $item_id = '', $type = '', $user_id = '' ) {
  401.             global $bp;
  402.            
  403.             if ( !$type )
  404.                     return false;
  405.            
  406.             if ( !$item_id )
  407.                     return false;
  408.            
  409.             if ( !$user_id )
  410.                     $user_id = $bp->loggedin_user->id;
  411.            
  412.             if ( $type == 'activity' )
  413.                     $user_likes = get_user_meta( $user_id, 'bp_liked_activities', true );
  414.            
  415.             if ( $type == 'blogpost' )
  416.                     $user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true );
  417.            
  418.             if ( !$user_likes ){
  419.                     return false;
  420.             } elseif ( !array_key_exists( $item_id, $user_likes ) ) {
  421.                     return false;
  422.             } else {
  423.                     return true;
  424.             };
  425.     }
  426.      
  427.     /**
  428.      * bp_like_add_user_like()
  429.      *
  430.      * Registers that the user likes a given item.
  431.      *
  432.      */
  433.     function bp_like_add_user_like( $item_id = '', $type = 'activity' ) {
  434.             global $bp;
  435.            
  436.             if ( !$item_id )
  437.                     return false;
  438.      
  439.             if ( !$user_id )
  440.                     $user_id = $bp->loggedin_user->id;
  441.            
  442.             if ( $user_id == 0 ) {
  443.                     echo bp_like_get_text( 'must_be_logged_in' );
  444.                     return false;
  445.             }
  446.            
  447.             if ( $type == 'activity' ) :
  448.            
  449.                     /* Add to the users liked activities. */
  450.                     $user_likes = get_user_meta( $user_id, 'bp_liked_activities', true );
  451.                     $user_likes[$item_id] = 'activity_liked';
  452.                     update_user_meta( $user_id, 'bp_liked_activities', $user_likes );
  453.            
  454.                     /* Add to the total likes for this activity. */
  455.                     $users_who_like = bp_activity_get_meta( $item_id, 'liked_count', true );
  456.                     $users_who_like[$user_id] = 'user_likes';
  457.                     bp_activity_update_meta( $item_id, 'liked_count', $users_who_like );
  458.            
  459.                     $liked_count = count( $users_who_like );
  460.                    
  461.                                  /***
  462.                      * Hack: Post a screen notification to the user's notifications menu.          
  463.                      */
  464.                     bp_core_add_notification( $item_id, $user_id, $bp->bp_like->slug, 'new_bp_like' );
  465.                    
  466.                     /* Publish to the activity stream if we're allowed to. */
  467.                     if ( bp_like_get_settings( 'post_to_activity_stream' ) == 1 ) {
  468.                    
  469.                             $activity = bp_activity_get_specific( array( 'activity_ids' => $item_id, 'component' => 'bp-like' ) );
  470.                             $author_id = $activity['activities'][0]->user_id;
  471.            
  472.                             if ($user_id == $author_id)
  473.                                     $action = bp_like_get_text( 'record_activity_likes_own' );
  474.                             elseif ($user_id == 0)
  475.                                     $action = bp_like_get_text( 'record_activity_likes_an' );
  476.                             else
  477.                                     $action = bp_like_get_text( 'record_activity_likes_users' );
  478.      
  479.                             $liker = bp_core_get_userlink( $user_id );
  480.                             $author = bp_core_get_userlink( $author_id );
  481.                             $activity_url = bp_activity_get_permalink( $item_id );
  482.                            
  483.                             /* Grab the content and make it into an excerpt of 140 chars if we're allowed */
  484.                             if ( bp_like_get_settings( 'show_excerpt' ) == 1 ) {
  485.                                     $content = $activity['activities'][0]->content;
  486.                                     if ( strlen( $content ) > bp_like_get_settings( 'excerpt_length' ) ) {
  487.                                             $content = substr( $content, 0, bp_like_get_settings( 'excerpt_length' ) );
  488.                                             $content = $content.'...';
  489.                                     }
  490.                             };
  491.                    
  492.      
  493.                             /* Filter out the placeholders */
  494.                             $action = str_replace( '%user%', $liker, $action );
  495.                             $action = str_replace( '%permalink%', $activity_url, $action );
  496.                             $action = str_replace( '%author%', $author, $action );
  497.      
  498.                             bp_activity_add(
  499.                                     array(
  500.                                             'action' => $action,
  501.                                             'content' => $content,
  502.                                             'primary_link' => $activity_url,
  503.                                             'component' => 'bp-like',
  504.                                             'type' => 'activity_liked',
  505.                                             'user_id' => $user_id,
  506.                                             'item_id' => $item_id
  507.                                     )
  508.                             );
  509.      
  510.                     };
  511.            
  512.             elseif ( $type == 'blogpost' ) :
  513.                    
  514.                     /* Add to the users liked blog posts. */
  515.                     $user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true);
  516.                     $user_likes[$item_id] = 'blogpost_liked';
  517.                     update_user_meta( $user_id, 'bp_liked_blogposts', $user_likes );
  518.      
  519.                     /* Add to the total likes for this blog post. */
  520.                     $users_who_like = get_post_meta( $item_id, 'liked_count', true );
  521.                     $users_who_like[$user_id] = 'user_likes';
  522.                     update_post_meta( $item_id, 'liked_count', $users_who_like );
  523.                    
  524.                     $liked_count = count( $users_who_like );
  525.                    
  526.                                                  /***
  527.                      * Hack: Post a screen notification to the user's notifications menu.          
  528.                      */
  529.                     bp_core_add_notification( $item_id, $user_id, $bp->bp_like->slug, 'new_bp_like' );
  530.                    
  531.                     if ( bp_like_get_settings( 'post_to_activity_stream' ) == 1 ) {
  532.                             $post = get_post($item_id);
  533.                             $author_id = $post->post_author;
  534.            
  535.                             $liker = bp_core_get_userlink( $user_id );
  536.                             $permalink = get_permalink( $item_id );
  537.                             $title = $post->post_title;
  538.                             $author = bp_core_get_userlink( $post->post_author );
  539.      
  540.                             if ($user_id == $author_id)
  541.                                     $action = bp_like_get_text( 'record_activity_likes_own_blogpost' );
  542.                             elseif ($user_id == 0)
  543.                                     $action = bp_like_get_text( 'record_activity_likes_a_blogpost' );
  544.                             else
  545.                                     $action = bp_like_get_text( 'record_activity_likes_users_blogpost' );
  546.            
  547.                             /* Filter out the placeholders */
  548.                             $action = str_replace( '%user%', $liker, $action );
  549.                             $action = str_replace( '%permalink%', $permalink, $action );
  550.                             $action = str_replace( '%title%', $title, $action );
  551.                             $action = str_replace( '%author%', $author, $action );
  552.                            
  553.                             /* Grab the content and make it into an excerpt of 140 chars if we're allowed */
  554.                             if ( bp_like_get_settings( 'show_excerpt' ) == 1 ) {
  555.                                     $content = $post->post_content;
  556.                                     if ( strlen( $content ) > bp_like_get_settings( 'excerpt_length' ) ) {
  557.                                             $content = substr( $content, 0, bp_like_get_settings( 'excerpt_length' ) );
  558.                                             $content = $content.'...';
  559.                                     }
  560.                             };
  561.            
  562.                             bp_activity_add(
  563.                                     array(
  564.                                             'action' => $action,
  565.                                             'content' => $content,
  566.                                             'component' => 'bp-like',
  567.                                             'type' => 'blogpost_liked',
  568.                                             'user_id' => $user_id,
  569.                                             'item_id' => $item_id,
  570.                                             'primary_link' => $permalink
  571.                                     )
  572.                             );
  573.                            
  574.                             // bp_like_send_notification( $snippet->id, $snippet->user_id, $snippet->item_id, $user_id, $content);
  575.                    
  576.                     };
  577.                    
  578.             endif;
  579.      
  580.             echo bp_like_get_text( 'unlike' );
  581.            
  582.                     echo ' <span>' . $liked_count . '</span>';
  583.     }
  584.      
  585.     /**
  586.      * bp_like_remove_user_like()
  587.      *
  588.      * Registers that the user has unliked a given item.
  589.      *
  590.      */
  591.     function bp_like_remove_user_like( $item_id = '', $type = 'activity') {
  592.             global $bp;
  593.            
  594.             if ( !$item_id )
  595.                     return false;
  596.      
  597.             if ( !$user_id )
  598.                     $user_id = $bp->loggedin_user->id;
  599.            
  600.             if ( $user_id == 0 ) {
  601.                     echo bp_like_get_text( 'must_be_logged_in' );
  602.                     return false;
  603.             }
  604.      
  605.             if ( $type == 'activity' ) :
  606.      
  607.                     /* Remove this from the users liked activities. */
  608.                     $user_likes = get_user_meta( $user_id, 'bp_liked_activities', true );
  609.                     unset( $user_likes[$item_id] );
  610.                     update_user_meta( $user_id, 'bp_liked_activities', $user_likes );
  611.      
  612.                     /* Update the total number of users who have liked this activity. */
  613.                     $users_who_like = bp_activity_get_meta( $item_id, 'liked_count', true );
  614.                     unset( $users_who_like[$user_id] );
  615.                    
  616.                     /* If nobody likes the activity, delete the meta for it to save space, otherwise, update the meta */
  617.                     if ( empty( $users_who_like ) )
  618.                             bp_activity_delete_meta( $item_id, 'liked_count' );
  619.                     else
  620.                             bp_activity_update_meta( $item_id, 'liked_count', $users_who_like );
  621.            
  622.                     $liked_count = count( $users_who_like );
  623.      
  624.                     /* Remove the update on the users profile from when they liked the activity. */
  625.                     $update_id = bp_activity_get_activity_id(
  626.                             array(
  627.                                     'item_id' => $item_id,
  628.                                     'component' => 'bp-like',
  629.                                     'type' => 'activity_liked',
  630.                                     'user_id' => $user_id
  631.                             )
  632.                     );
  633.            
  634.                     bp_activity_delete(
  635.                             array(
  636.                                     'id' => $update_id,
  637.                                     'item_id' => $item_id,
  638.                                     'component' => 'bp-like',
  639.                                     'type' => 'activity_liked',
  640.                                     'user_id' => $user_id
  641.                             )
  642.                     );
  643.                    
  644.             elseif ( $type == 'blogpost' ) :
  645.                    
  646.                     /* Remove this from the users liked activities. */
  647.                     $user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true );
  648.                     unset( $user_likes[$item_id] );
  649.                     update_user_meta( $user_id, 'bp_liked_blogposts', $user_likes );
  650.      
  651.                     /* Update the total number of users who have liked this blog post. */
  652.                     $users_who_like = get_post_meta( $item_id, 'liked_count', true );
  653.                     unset( $users_who_like[$user_id] );
  654.                    
  655.                     /* If nobody likes the blog post, delete the meta for it to save space, otherwise, update the meta */
  656.                     if ( empty( $users_who_like ) )
  657.                             delete_post_meta( $item_id, 'liked_count' );
  658.                     else
  659.                             update_post_meta( $item_id, 'liked_count', $users_who_like );
  660.      
  661.                     $liked_count = count( $users_who_like );
  662.      
  663.                     /* Remove the update on the users profile from when they liked the activity. */
  664.                     $update_id = bp_activity_get_activity_id(
  665.                             array(
  666.                                     'item_id' => $item_id,
  667.                                     'component' => 'bp-like',
  668.                                     'type' => 'blogpost_liked',
  669.                                     'user_id' => $user_id
  670.                             )
  671.                     );
  672.            
  673.                     bp_activity_delete(
  674.                             array(
  675.                                     'id' => $update_id,
  676.                                     'item_id' => $item_id,
  677.                                     'component' => 'bp-like',
  678.                                     'type' => 'blogpost_liked',
  679.                                     'user_id' => $user_id
  680.                             )
  681.                     );
  682.                    
  683.             endif;
  684.      
  685.             echo bp_like_get_text( 'like' );
  686.            
  687.                     echo ' <span>' . $liked_count . '</span>';
  688.     }
  689.      
  690.     /**
  691.      * bp_like_get_likes()
  692.      *
  693.      * Outputs a list of users who have liked a given item.
  694.      *
  695.      */
  696.     function bp_like_get_likes( $item_id = '', $type = '', $user_id = '' ) {
  697.             global $bp;
  698.            
  699.             if ( !$type || !$item_id )
  700.                     return false;
  701.            
  702.             if ( !$user_id )
  703.                     $user_id = $bp->loggedin_user->id;
  704.      
  705.             if ( $type == 'activity' ) :
  706.                    
  707.                     /* Grab some core data we will need later on, specific to activities */
  708.                     $users_who_like         = array_keys( bp_activity_get_meta( $item_id, 'liked_count' ) );
  709.                     $liked_count            = count( bp_activity_get_meta( $item_id, 'liked_count' ) );
  710.                    
  711.                     /* Intercept any messages if nobody likes it, just incase the button was clicked when it shouldn't be */
  712.                     if ( $liked_count == 0 ) :
  713.                            
  714.                             $output .= bp_like_get_text( 'get_likes_no_likes' );
  715.                    
  716.                     /* We should show information about all likers */
  717.                     elseif ( bp_like_get_settings( 'likers_visibility' ) == 'show_all' ) :
  718.                            
  719.                             /* Settings say we should show their name. */
  720.                             if ( bp_like_get_settings( 'name_or_avatar' ) == 'name' ) :
  721.                                    
  722.                                     /* Current user likes it too, remove them from the liked count and output appropriate message */
  723.                                     if ( bp_like_is_liked( $item_id, 'activity', $user_id ) ) :
  724.                                            
  725.                                             $liked_count = $liked_count-1;
  726.                                            
  727.                                             if ( $liked_count == 1 )
  728.                                                     $output .= bp_like_get_text( 'get_likes_you_and_singular' );
  729.      
  730.                                             elseif ( $liked_count == 0 )
  731.                                                     $output .= bp_like_get_text('get_likes_only_liker');
  732.      
  733.                                             else
  734.                                                     $output .= bp_like_get_text( 'get_likes_you_and_plural' );
  735.                                    
  736.                                     else :
  737.                                            
  738.                                             if ( $liked_count == 1 )
  739.                                                     $output .= bp_like_get_text( 'get_likes_count_people_singular' );
  740.                                            
  741.                                             else
  742.                                                     $output .= bp_like_get_text( 'get_likes_count_people_plural' );
  743.                                            
  744.                                     endif;
  745.                                            
  746.                                     /* Now output the name of each person who has liked it (except the current user obviously) */
  747.                                     foreach( $users_who_like as $id ) :
  748.                                            
  749.                                             if ( $id != $user_id )
  750.                                                     $output .= ' &middot <a href="' . bp_core_get_user_domain( $id ) . '" title="' . bp_core_get_user_displayname( $id ) . '">' . bp_core_get_user_displayname( $id ) . '</a>';
  751.                                            
  752.                                     endforeach;
  753.                            
  754.                             /* Settings say we should show their avatar. */
  755.                             elseif ( bp_like_get_settings( 'name_or_avatar' ) == 'avatar' ) :
  756.                                    
  757.                                     /* Output the avatar of each person who has liked it. */
  758.                                     foreach( $users_who_like as $id ) :
  759.                                            
  760.                                             $output .= '<a href="' . bp_core_get_user_domain( $id ) . '" title="' . bp_core_get_user_displayname( $id ) . '">' . bp_core_fetch_avatar( array( 'item_id' => $id, 'object' => 'user', 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ) . '</a> ';
  761.      
  762.                                     endforeach;
  763.                                    
  764.                             endif;
  765.                    
  766.                     /* We should show the information of friends, but only the number of non-friends. */
  767.                     elseif ( bp_like_get_settings( 'likers_visibility' ) == 'friends_names_others_numbers' && bp_is_active( 'friends' ) ) :
  768.                            
  769.                             /* Grab some information about their friends. */
  770.                             $users_friends = friends_get_friend_user_ids( $user_id );
  771.                             if ( !empty( $users_friends ) )
  772.                                     $friends_who_like = array_intersect( $users_who_like, $users_friends );
  773.                            
  774.                             /* Current user likes it, so reduce the liked count by 1, to get the number of other people who like it. */
  775.                             if ( bp_like_is_liked( $item_id, 'activity', $user_id ) )
  776.                                     $liked_count = $liked_count-1;
  777.                            
  778.                             /* Settings say we should show their names. */
  779.                             if ( bp_like_get_settings( 'name_or_avatar' ) == 'name' ) :
  780.                                            
  781.                                             /* Current user likes it too, tell them. */
  782.                                             if ( bp_like_is_liked( $item_id, 'activity', $user_id ) )
  783.                                                     $output .= 'You ';
  784.                                    
  785.                                             /* Output the name of each friend who has liked it. */
  786.                                             foreach( $users_who_like as $id ) :
  787.                                            
  788.                                                     if ( in_array( $id, $friends_who_like ) ) {
  789.                                                             $output .= ' &middot <a href="' . bp_core_get_user_domain( $id ) . '" title="' . bp_core_get_user_displayname( $id ) . '">' . bp_core_get_user_displayname( $id ) . '</a> ';
  790.                                                    
  791.                                                             $liked_count = $liked_count-1;
  792.                                                     }
  793.                                            
  794.                                             endforeach;
  795.                                            
  796.                                             /* If non-friends like it, say so. */
  797.                                             if ( $liked_count == 1 )
  798.                                                     $output .= bp_like_get_text( 'get_likes_and_people_singular' );
  799.      
  800.                                             elseif ( $liked_count > 1 )
  801.                                                     $output .= bp_like_get_text( 'get_likes_and_people_plural' );
  802.                                            
  803.                                             else
  804.                                                     $output .= bp_like_get_text( 'get_likes_like_this' );
  805.                                    
  806.                             /* Settings say we should show their avatar. */
  807.                             elseif ( bp_like_get_settings( 'name_or_avatar' ) == 'avatar' ) :
  808.                                    
  809.                                     /* Output the avatar of each friend who has liked it, as well as the current users' if they have. */
  810.                                     if ( !empty( $friends_who_like ) ) :
  811.                            
  812.                                             foreach( $users_who_like as $id ) :
  813.                                            
  814.                                                     if ( $id == $user_id || in_array( $id, $friends_who_like ) ) {
  815.                                                             $user_info = get_userdata( $id );
  816.                                                             $output .= '<a href="' . bp_core_get_user_domain( $id ) . '" title="' . bp_core_get_user_displayname( $id ) . '">' . get_avatar( $user_info->user_email, 30 ) . '</a> ';
  817.                                                     }
  818.                                            
  819.                                             endforeach;
  820.                                    
  821.                                     endif;
  822.                                    
  823.                             endif;
  824.                    
  825.                     elseif ( bp_like_get_settings( 'likers_visibility' ) == 'friends_names_others_numbers' && !bp_is_active( 'friends' ) ||bp_like_get_settings( 'likers_visibility' ) == 'just_numbers' ) :
  826.                            
  827.                                     /* Current user likes it too, remove them from the liked count and output appropriate message */
  828.                                     if ( bp_like_is_liked( $item_id, 'activity', $user_id ) ) :
  829.                                            
  830.                                             $liked_count = $liked_count-1;
  831.                                            
  832.                                             if ( $liked_count == 1 )
  833.                                                     $output .= bp_like_get_text( 'get_likes_you_and_singular' );
  834.                                            
  835.                                             elseif ( $liked_count == 0 )
  836.                                                     $output .= bp_like_get_text('get_likes_only_liker');
  837.                                            
  838.                                             else
  839.                                                     $output .= bp_like_get_text( 'get_likes_you_and_plural' );
  840.                                    
  841.                                     else :
  842.                                            
  843.                                             if ( $liked_count == 1 )
  844.                                                     $output .= bp_like_get_text( 'get_likes_count_people_singular' );
  845.                                            
  846.                                             else
  847.                                                     $output .= bp_like_get_text( 'get_likes_count_people_plural' );
  848.                                            
  849.                                     endif;
  850.                    
  851.                     endif;
  852.            
  853.             endif;
  854.            
  855.             /* Filter out the placeholder. */
  856.             $output = str_replace( '%count%', $liked_count, $output );
  857.            
  858.             echo $output;
  859.                    
  860.     }
  861.      
  862.     /**
  863.      * bp_like_button()
  864.      *
  865.      * Outputs the 'Like/Unlike' and 'View likes/Hide likes' buttons.
  866.      *
  867.      */
  868.     function bp_like_button( $id = '', $type = '' ) {
  869.            
  870.             $users_who_like = 0;
  871.             $liked_count = 0;
  872.            
  873.             /* Set the type if not already set, and check whether we are outputting the button on a blogpost or not. */
  874.             if ( !$type && !is_single() )
  875.                     $type = 'activity';
  876.             elseif ( !$type && is_single() )
  877.                     $type = 'blogpost';
  878.            
  879.             if ( $type == 'activity' ) :
  880.            
  881.                     $activity = bp_activity_get_specific( array( 'activity_ids' => bp_get_activity_id() ) );
  882.                     $activity_type = $activity['activities'][0]->type;
  883.            
  884.                     if ( is_user_logged_in() && $activity_type !== 'activity_liked' ) :
  885.                            
  886.                             if ( bp_activity_get_meta( bp_get_activity_id(), 'liked_count', true )) {
  887.                                     $users_who_like = array_keys( bp_activity_get_meta( bp_get_activity_id(), 'liked_count', true ) );
  888.                                     $liked_count = count( $users_who_like );
  889.                             }
  890.                            
  891.                             if ( !bp_like_is_liked( bp_get_activity_id(), 'activity' ) ) : ?>
  892.                                     <a href="#" class="like" id="like-activity-<?php bp_activity_id(); ?>" title="<?php echo bp_like_get_text( 'like_this_item' ); ?>"><?php echo bp_like_get_text( 'like' ); if ( $liked_count ) echo ' <span>' . $liked_count . '</span>'; ?></a>
  893.                             <?php else : ?>
  894.                                     <a href="#" class="unlike" id="unlike-activity-<?php bp_activity_id(); ?>" title="<?php echo bp_like_get_text( 'unlike_this_item' ); ?>"><?php echo bp_like_get_text( 'unlike' ); if ( $liked_count ) echo ' <span>' . $liked_count . '</span>'; ?></a>
  895.                             <?php endif;
  896.                            
  897.                              if ( $users_who_like ): ?>
  898.                                     <a href="#" class="view-likes" id="view-likes-<?php bp_activity_id(); ?>"><?php echo bp_like_get_text( 'view_likes' ); ?></a>
  899.                                     <p class="users-who-like" id="users-who-like-<?php bp_activity_id(); ?>"></p>
  900.                             <?php
  901.                             endif;
  902.                     endif;
  903.            
  904.             elseif ( $type == 'blogpost' ) :
  905.                     global $post;
  906.                    
  907.                     if ( !$id && is_single() )
  908.                             $id = $post->ID;
  909.                    
  910.                    
  911.                             $liked_count = count( get_post_meta( $id, 'liked_count', true ) );
  912.                    
  913.                    
  914.                     if ( !bp_like_is_liked( $id, 'blogpost' ) ) : ?>
  915.                    
  916.                     <div class="like-box">
  917.                    
  918.                     <a href="#" class="like_blogpost" id="like-blogpost-<?php echo $id; ?>" title="<?php echo bp_like_get_text( 'like_this_item' ); ?>"><?php
  919.                    
  920.                     if ( $liked_count ) echo '  <span>' . $liked_count . '</span>';
  921.                    
  922.                     else echo ' 0 '; ?>
  923.                    
  924.                     </a>
  925.                    
  926.                     </div>
  927.                    
  928.                     <?php else : ?>
  929.                    
  930.                     <div class="like-box"><a href="#" class="unlike_blogpost" id="unlike-blogpost-<?php echo $id; ?>" title="<?php echo bp_like_get_text( 'unlike_this_item' ); ?>"><?php echo bp_like_get_text( 'unlike' ); if ( $liked_count ) echo ' <span>' . $liked_count . '</span>'; ?></a></div>
  931.                
  932.                     <?php endif;
  933.      
  934.             endif;
  935.     };
  936.     add_filter( 'bp_activity_entry_meta', 'bp_like_button' );
  937.     add_action( 'bp_before_blog_single_post', 'bp_like_button' );
  938.      
  939.     /**
  940.      * bp_like_activity_filter()
  941.      *
  942.      * Adds 'Show Activity Likes' to activity stream filters.
  943.      *
  944.      */
  945.     function bp_like_activity_filter() {
  946.             echo '<option value="activity_liked">' . bp_like_get_text( 'show_activity_likes' ) . '</option>';
  947.             echo '<option value="blogpost_liked">Show Blog Post Likes</option>';
  948.     }
  949.     add_action( 'bp_activity_filter_options', 'bp_like_activity_filter' );
  950.     add_action( 'bp_member_activity_filter_options', 'bp_like_activity_filter' );
  951.     add_action( 'bp_group_activity_filter_options', 'bp_like_activity_filter' );
  952.      
  953.     /**
  954.      * bp_like_list_scripts()
  955.      *
  956.      * Includes the Javascript required for Ajax etc.
  957.      *
  958.      */
  959.     function bp_like_list_scripts() {
  960.             wp_enqueue_script(
  961.                     "bp-like",
  962.                     path_join( WP_PLUGIN_URL, basename( dirname( __FILE__ ) )."/_inc/js/bp-like.min.js" ),
  963.                     array( 'jquery' )
  964.             );
  965.     }
  966.     add_action( 'wp_print_scripts', 'bp_like_list_scripts' );
  967.      
  968.     /**
  969.      * bp_like_insert_head()
  970.      *
  971.      * Includes any CSS and/or Javascript needed in the <head>.
  972.      *
  973.      */
  974.     function bp_like_insert_head() {
  975.     ?>
  976.     <style type="text/css">
  977.             .bp-like.activity_liked .activity-meta,
  978.             .bp-like.blogpost_liked .activity-meta,
  979.             .users-who-like,
  980.             .mini a.view-likes,
  981.             .mini a.hide-likes {
  982.                     display: none;
  983.             }
  984.            
  985.             /* To match the default theme */
  986.             #bp-default .users-who-like {
  987.                     margin: 10px 0 -10px 0;
  988.                     background: #F5F5F5;
  989.                     -moz-border-radius: 4px;
  990.                     -webkit-border-radius: 4px;
  991.                     border-radius: 4px;
  992.                     padding: 8px 8px 0px 12px;
  993.                     color: #8C8A8F;
  994.             }
  995.             #bp-default .users-who-like a {
  996.                     color: #777;
  997.                     padding: 0;
  998.                     background: none;
  999.                     border: none;
  1000.                     text-decoration: underline;
  1001.                     font-size: 12px;
  1002.             }
  1003.             #bp-default .users-who-like a:hover { color: #222; }
  1004.             #bp-default .mini .users-who-like {
  1005.                     width: 100%;
  1006.                     position: absolute;
  1007.                     top: 0;
  1008.                     left: 0;
  1009.             }
  1010.             #bp-default .users-who-like img.avatar {
  1011.                     float: none;
  1012.                     border: none;
  1013.                     width: 30px;
  1014.                     height: 30px;
  1015.                     padding: 0;
  1016.                     margin: 0;
  1017.             }
  1018.             ul#activity-stream li.bp-like .activity-inner {
  1019.                     border-left: 3px solid #ddd;
  1020.                     color: #888;
  1021.                     padding-left: 15px;
  1022.                     font-style: italic;
  1023.             }
  1024.             #bp-default div.post div.author-box, div.comment-avatar-box {
  1025.             position: relative;
  1026.             }
  1027.             #bp-default div.like-box {
  1028.                     background: #f0f0f0;
  1029.                     width: 90px;
  1030.                     position: absolute;
  1031.                     bottom: -40px;
  1032.                     left: 0;
  1033.                     font-family: georgia, times, serif;
  1034.                     font-style: italic;
  1035.                     text-align: center;
  1036.                     padding: 5px 0;
  1037.                     -moz-border-radius: 3px;
  1038.                     -webkit-border-radius: 3px;
  1039.                     border-radius: 3px;
  1040.             }
  1041.     </style>
  1042.     <script type="text/javascript">
  1043.     /* <![CDATA[ */
  1044.             var bp_like_terms_like = '<?php echo bp_like_get_text( 'like' ); ?>';
  1045.             var bp_like_terms_like_message = '<?php echo bp_like_get_text( 'like_this_item' ); ?>';
  1046.             var bp_like_terms_unlike_message = '<?php echo bp_like_get_text( 'unlike_this_item' ); ?>';
  1047.             var bp_like_terms_view_likes = '<?php echo bp_like_get_text( 'view_likes' ); ?>';
  1048.             var bp_like_terms_hide_likes = '<?php echo bp_like_get_text( 'hide_likes' ); ?>';
  1049.             var bp_like_terms_unlike_1 = '<?php echo bp_like_get_text( 'unlike' ); ?> (1)';
  1050.     /* ]]> */
  1051.     </script>
  1052.     <?php  
  1053.     }
  1054.     add_action( 'wp_head', 'bp_like_insert_head' );
  1055.      
  1056.     /**
  1057.      * bp_like_add_admin_page_menu()
  1058.      *
  1059.      * Adds "BuddyPress Like" to the main BuddyPress admin menu.
  1060.      *
  1061.      */
  1062.     function bp_like_add_admin_page_menu() {
  1063.         add_submenu_page(
  1064.             'bp-general-settings',
  1065.             'BuddyPress Like',
  1066.             'BuddyPress Like',
  1067.             'manage_options',
  1068.             'bp-like-settings',
  1069.             'bp_like_admin_page'
  1070.         );
  1071.     }
  1072.     add_action( 'admin_menu', 'bp_like_add_admin_page_menu' );
  1073.      
  1074.     /**
  1075.      * bp_like_admin_page_verify_nonce()
  1076.      *
  1077.      * When the settings form is submitted, verifies the nonce to ensure security.
  1078.      *
  1079.      */
  1080.     function bp_like_admin_page_verify_nonce() {
  1081.             if( isset( $_POST['_wpnonce'] ) && isset( $_POST['bp_like_updated'] ) ) {
  1082.                     $nonce = $_REQUEST['_wpnonce'];
  1083.                     if ( !wp_verify_nonce( $nonce, 'bp-like-admin' ) )
  1084.                             wp_die( __('You do not have permission to do that.') );
  1085.             }
  1086.     }
  1087.     add_action( 'init', 'bp_like_admin_page_verify_nonce' );
  1088.      
  1089.      
  1090.     /**
  1091.      * bp_like_admin_page()
  1092.      *
  1093.      * Outputs the admin settings page.
  1094.      *
  1095.      */
  1096.     function bp_like_admin_page() {
  1097.             global $current_user;
  1098.      
  1099.             wp_get_current_user();
  1100.      
  1101.             /* Update our options if the form has been submitted */
  1102.         if( isset( $_POST['_wpnonce'] ) && isset( $_POST['bp_like_updated'] ) ) {
  1103.                    
  1104.                     /* Add each text string to the $strings_to_save array */
  1105.                     foreach ( $_POST as $key => $value ) {
  1106.                             if ( preg_match( "/text_string_/i", $key )) {
  1107.                                     $default = bp_like_get_text( str_replace( 'bp_like_admin_text_string_', '', $key), 'default' );
  1108.                                     $strings_to_save[str_replace( 'bp_like_admin_text_string_', '', $key )] = array('default' => $default, 'custom' => stripslashes( $value ));
  1109.                             }
  1110.                     }
  1111.                    
  1112.                     /* Now actually save the data to the options table */
  1113.                     update_site_option(
  1114.                             'bp_like_settings',
  1115.                             array(
  1116.                                     'likers_visibility' => $_POST['bp_like_admin_likers_visibility'],
  1117.                                     'post_to_activity_stream' => $_POST['bp_like_admin_post_to_activity_stream'],
  1118.                                     'show_excerpt' => $_POST['bp_like_admin_show_excerpt'],
  1119.                                     'excerpt_length' => $_POST['bp_like_admin_excerpt_length'],
  1120.                                     'text_strings' => $strings_to_save,
  1121.                                     'translate_nag' => bp_like_get_settings( 'translate_nag' ),
  1122.                                     'name_or_avatar' => $_POST['name_or_avatar']
  1123.                             )
  1124.                     );
  1125.                    
  1126.                     /* Let the user know everything's cool */
  1127.                     echo '<div class="updated"><p><strong>';
  1128.                     _e('Settings saved.', 'wordpress');
  1129.                     echo '</strong></p></div>';
  1130.             }
  1131.            
  1132.             $text_strings = bp_like_get_settings( 'text_strings' );
  1133.      
  1134.     ?>
  1135.     <style type="text/css">
  1136.     #icon-bp-like-settings { background: url('<?php echo plugins_url('/_inc/img/bp-like-icon32.png', __FILE__); ?>') no-repeat top left; }
  1137.     table input { width: 100%; }
  1138.     table label { display: block; }
  1139.     </style>
  1140.     <script type="text/javascript">
  1141.     jQuery(document).ready( function() {
  1142.             jQuery('select.name-or-avatar').change(function(){
  1143.                     var value = jQuery(this).val();
  1144.                     jQuery('select.name-or-avatar').val(value);
  1145.             });
  1146.     });
  1147.     </script>
  1148.      
  1149.     <div class="wrap">
  1150.       <div id="icon-bp-like-settings" class="icon32"><br /></div>
  1151.       <h2><?php _e('BuddyPress Like Settings', 'buddypress-like'); ?></h2>
  1152.       <form action="" method="post" id="bp-like-admin-form">
  1153.         <input type="hidden" name="bp_like_updated" value="updated">
  1154.        
  1155.         <h3><?php _e('General Settings', 'buddypress-like'); ?></h3>
  1156.         <p><input type="checkbox" id="bp_like_admin_post_to_activity_stream" name="bp_like_admin_post_to_activity_stream" value="1"<?php if (bp_like_get_settings( 'post_to_activity_stream' ) == 1) echo ' checked="checked"'?>> <label for="bp_like_admin_post_activity_updates"><?php _e("Post an activity update when something is liked", 'buddypress-like'); ?>, (e.g. "<?php echo $current_user->display_name; ?> likes Bob's activity")</label></p>
  1157.         <p><input type="checkbox" id="bp_like_admin_show_excerpt" name="bp_like_admin_show_excerpt" value="1"<?php if (bp_like_get_settings( 'show_excerpt' ) == 1) echo ' checked="checked"'?>> <label for="bp_like_admin_show_excerpt"><?php _e("Show a short excerpt of the activity that has been liked", 'buddypress-like'); ?></label>; limit to <input type="text" maxlength="3" style="width: 40px" value="<?php echo bp_like_get_settings( 'excerpt_length' ); ?>" name="bp_like_admin_excerpt_length" /> characters.</p>
  1158.        
  1159.         <h3><?php _e("'View Likes' Visibility", "buddypress-like"); ?></h3>
  1160.         <p><?php _e("Choose how much information about the 'likers' of a particular item is shown;", "buddypress-like"); ?></p>
  1161.         <p style="line-height: 200%;">
  1162.           <input type="radio" name="bp_like_admin_likers_visibility" value="show_all"<?php if ( bp_like_get_settings( 'likers_visibility' ) == 'show_all' ) { echo ' checked="checked""'; }; ?> /> Show <select name="name_or_avatar" class="name-or-avatar"><option value="name"<?php if ( bp_like_get_settings( 'name_or_avatar' ) == 'name' ) { echo ' selected="selected""'; }; ?>>names</option><option value="avatar"<?php if ( bp_like_get_settings( 'name_or_avatar' ) == 'avatar' ) { echo ' selected="selected""'; }; ?>>avatars</option></select> of all likers<br />
  1163.           <?php if ( bp_is_active( 'friends' ) ) { ?>
  1164.           <input type="radio" name="bp_like_admin_likers_visibility" value="friends_names_others_numbers"<?php if ( bp_like_get_settings( 'likers_visibility' ) == 'friends_names_others_numbers' ) { echo ' checked="checked""'; }; ?> /> Show <select name="name_or_avatar" class="name-or-avatar"><option value="name"<?php if ( bp_like_get_settings( 'name_or_avatar' ) == 'name' ) { echo ' selected="selected""'; }; ?>>names</option><option value="avatar"<?php if ( bp_like_get_settings( 'name_or_avatar' ) == 'avatar' ) { echo ' selected="selected""'; }; ?>>avatars</option></select> of friends, and the number of non-friends<br />
  1165.           <?php }; ?>
  1166.           <input type="radio" name="bp_like_admin_likers_visibility" value="just_numbers"<?php if ( bp_like_get_settings( 'likers_visibility' ) == 'just_numbers' ) { echo ' checked="checked""'; }; ?> /> <?php _e('Show only the number of likers', 'buddypress-like'); ?>
  1167.         </p>
  1168.         <h3><?php _e('Custom Messages', 'buddypress-like'); ?></h3>
  1169.         <p><?php _e("Change what messages are shown to users. For example, they can 'love' or 'dig' items instead of liking them.", "buddypress-like"); ?><br /><br /></p>
  1170.        
  1171.         <table class="widefat fixed" cellspacing="0">
  1172.               <thead>
  1173.                 <tr>
  1174.                   <th scope="col" id="default" class="column-name" style="width: 43%;"><?php _e('Default', 'buddypress-like'); ?></th>
  1175.                   <th scope="col" id="custom" class="column-name" style=""><?php _e('Custom', 'buddypress-like'); ?></th>
  1176.                 </tr>
  1177.               </thead>
  1178.               <tfoot>
  1179.                 <tr>
  1180.                   <th colspan="2" id="default" class="column-name"></th>
  1181.                 </tr>
  1182.               </tfoot>
  1183.      
  1184.           <?php foreach ( $text_strings as $key => $string ) : ?>
  1185.           <tr valign="top">
  1186.               <th scope="row" style="width:400px;"><label for="bp_like_admin_text_string_<?php echo $key; ?>"><?php echo htmlspecialchars( $string['default'] ); ?></label></th>
  1187.               <td><input name="bp_like_admin_text_string_<?php echo $key; ?>" id="bp_like_admin_text_string_<?php echo $key; ?>" value="<?php echo htmlspecialchars( $string['custom'] ); ?>" class="regular-text" type="text"></td>
  1188.             </tr>
  1189.           <?php endforeach; ?>
  1190.           </tbody>
  1191.         </table>
  1192.            
  1193.         <p class="submit">
  1194.           <input class="button-primary" type="submit" name="bp-like-admin-submit" id="bp-like-admin-submit" value="<?php _e('Save Changes', 'wordpress'); ?>"/>
  1195.         </p>
  1196.         <?php wp_nonce_field( 'bp-like-admin' ) ?>
  1197.       </form>
  1198.     </div>
  1199.     <?php
  1200.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement