Advertisement
bobemil

BP Like notification hack

Oct 17th, 2012
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 42.01 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, $wpdb;
  272.  
  273.     /* For internal identification */
  274.     $bp->bp_like->id = 'bp-like';  
  275.     $bp->bp_like->format_notification_function = 'bp_like_format_notifications';
  276.     $bp->bp_like->slug = 'bp-like';
  277.  
  278.     /* Register this in the active components array */
  279.     $bp->active_components[$bp->bp_like->slug] = $bp->bp_like->id;
  280. }
  281. add_action( 'bp_setup_globals', 'bp_like_setup_globals' );
  282.  
  283.  
  284. /**
  285. * Hack: bp_like_format_notifications()
  286. *
  287. *
  288. * Sets up notifications format
  289. *
  290. */
  291. function bp_like_format_notifications( $action, $item_id, $secondary_item_id, $total_items) {
  292.     global $bp;
  293.  
  294.     switch ( $action ) {
  295.         case 'new_bp_like':
  296.            
  297.             /***
  298.              * We don't want a whole list of similar notifications in a users list, so we group them.
  299.              * If the user has more than one action from the same component, they are counted and the
  300.              * notification is rendered differently.
  301.              */
  302.             if ( (int)$total_items > 1 ) {
  303.                 $user_fullname = bp_core_get_user_displayname( $item_id, false );
  304.                 $user_url = bp_core_get_userlink( $item_id, false, true );
  305.                 return apply_filters( 'bp_like_notification', '<a href="' . $user_url . '" title="' . $user_fullname .'\'s profile">' . sprintf( __( 'multiple people liked something of yours', 'bp-like' ), $user_fullname ) . '</a>', $user_fullname );
  306.                 return apply_filters( 'bp_like_notification_multiple', 'Many people liked this!' );
  307.             } else {
  308.                 $user_fullname = bp_core_get_user_displayname( $item_id, false );
  309.                 $user_url = bp_core_get_userlink( $item_id, false, true );
  310.                 return apply_filters( 'bp_like_notification', '<a href="' . $user_url . '" title="' . $user_fullname .'\'s profile">' . sprintf( __( '%s liked something of yours', 'bp-like' ), $user_fullname ) . '</a>', $user_fullname );
  311.                 return apply_filters( 'bp_like_notification_single', 'Someone liked this!' );
  312.             }
  313.                
  314.         break;
  315.     }
  316.  
  317.     do_action( 'bp_like_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
  318.  
  319.     return false;
  320. }
  321.  
  322. /**
  323.  * bp_like_get_settings()
  324.  *
  325.  * Returns settings from the database
  326.  *
  327.  */
  328. function bp_like_get_settings( $option = false ) {
  329.    
  330.     $settings = get_site_option( 'bp_like_settings' );
  331.    
  332.     if (!$option)
  333.         return $settings;
  334.        
  335.     else
  336.         return $settings[$option];
  337. }
  338.  
  339. /**
  340.  * bp_like_get_text()
  341.  *
  342.  * Returns a custom text string from the database
  343.  *
  344.  */
  345. function bp_like_get_text( $text = false, $type = 'custom' ) {
  346.    
  347.     $settings = get_site_option( 'bp_like_settings' );
  348.     $text_strings = $settings['text_strings'];
  349.     $string = $text_strings[$text];
  350.        
  351.     return $string[$type];
  352. }
  353.  
  354. /**
  355.  * bp_like_process_ajax()
  356.  *
  357.  * Runs the relevant function depending on what Ajax call has been made.
  358.  *
  359.  */
  360. function bp_like_process_ajax() {
  361.     global $bp;
  362.  
  363.     $id = preg_replace( "/\D/", "", $_POST['id'] );
  364.    
  365.     if ( $_POST['type'] == 'like' )
  366.         bp_like_add_user_like( $id, 'activity' );
  367.    
  368.     if ( $_POST['type'] == 'unlike' )
  369.         bp_like_remove_user_like( $id, 'activity' );
  370.  
  371.     if ( $_POST['type'] == 'view-likes' )
  372.         bp_like_get_likes( $id, 'blogpost' );
  373.  
  374.     if ( $_POST['type'] == 'like_blogpost' )
  375.         bp_like_add_user_like( $id, 'blogpost' );
  376.  
  377.     if ( $_POST['type'] == 'unlike_blogpost' )
  378.         bp_like_remove_user_like( $id, 'blogpost' );
  379.  
  380.     die();
  381. }
  382. add_action( 'wp_ajax_activity_like', 'bp_like_process_ajax' );
  383.  
  384. /**
  385.  * bp_like_is_liked()
  386.  *
  387.  * Checks to see whether the user has liked a given item.
  388.  *
  389.  */
  390. function bp_like_is_liked( $item_id = '', $type = '', $user_id = '' ) {
  391.     global $bp;
  392.    
  393.     if ( !$type )
  394.         return false;
  395.    
  396.     if ( !$item_id )
  397.         return false;
  398.    
  399.     if ( !$user_id )
  400.         $user_id = $bp->loggedin_user->id;
  401.    
  402.     if ( $type == 'activity' )
  403.         $user_likes = get_user_meta( $user_id, 'bp_liked_activities', true );
  404.    
  405.     if ( $type == 'blogpost' )
  406.         $user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true );
  407.    
  408.     if ( !$user_likes ){
  409.         return false;
  410.     } elseif ( !array_key_exists( $item_id, $user_likes ) ) {
  411.         return false;
  412.     } else {
  413.         return true;
  414.     };
  415. }
  416.  
  417. /**
  418.  * bp_like_add_user_like()
  419.  *
  420.  * Registers that the user likes a given item.
  421.  *
  422.  */
  423. function bp_like_add_user_like( $item_id = '', $type = 'activity' ) {
  424.     global $bp;
  425.    
  426.     if ( !$item_id )
  427.         return false;
  428.  
  429.     if ( !$user_id )
  430.         $user_id = $bp->loggedin_user->id;
  431.    
  432.     if ( $user_id == 0 ) {
  433.         echo bp_like_get_text( 'must_be_logged_in' );
  434.         return false;
  435.     }
  436.    
  437.     if ( $type == 'activity' ) :
  438.    
  439.         /* Add to the users liked activities. */
  440.         $user_likes = get_user_meta( $user_id, 'bp_liked_activities', true );
  441.         $user_likes[$item_id] = 'activity_liked';
  442.         update_user_meta( $user_id, 'bp_liked_activities', $user_likes );
  443.    
  444.         /* Add to the total likes for this activity. */
  445.         $users_who_like = bp_activity_get_meta( $item_id, 'liked_count', true );
  446.         $users_who_like[$user_id] = 'user_likes';
  447.         bp_activity_update_meta( $item_id, 'liked_count', $users_who_like );
  448.    
  449.         $liked_count = count( $users_who_like );
  450.        
  451.                      /***
  452.                  * Hack: Post a screen notification to the user's notifications menu.          
  453.                  */
  454.                 bp_core_add_notification( $item_id, $user_id, $bp->bp_like->slug, 'new_bp_like' );
  455.        
  456.         /* Publish to the activity stream if we're allowed to. */
  457.         if ( bp_like_get_settings( 'post_to_activity_stream' ) == 1 ) {
  458.        
  459.             $activity = bp_activity_get_specific( array( 'activity_ids' => $item_id, 'component' => 'bp-like' ) );
  460.             $author_id = $activity['activities'][0]->user_id;
  461.    
  462.             if ($user_id == $author_id)
  463.                 $action = bp_like_get_text( 'record_activity_likes_own' );
  464.             elseif ($user_id == 0)
  465.                 $action = bp_like_get_text( 'record_activity_likes_an' );
  466.             else
  467.                 $action = bp_like_get_text( 'record_activity_likes_users' );
  468.  
  469.             $liker = bp_core_get_userlink( $user_id );
  470.             $author = bp_core_get_userlink( $author_id );
  471.             $activity_url = bp_activity_get_permalink( $item_id );
  472.            
  473.             /* Grab the content and make it into an excerpt of 140 chars if we're allowed */
  474.             if ( bp_like_get_settings( 'show_excerpt' ) == 1 ) {
  475.                 $content = $activity['activities'][0]->content;
  476.                 if ( strlen( $content ) > bp_like_get_settings( 'excerpt_length' ) ) {
  477.                     $content = substr( $content, 0, bp_like_get_settings( 'excerpt_length' ) );
  478.                     $content = $content.'...';
  479.                 }
  480.             };
  481.        
  482.  
  483.             /* Filter out the placeholders */
  484.             $action = str_replace( '%user%', $liker, $action );
  485.             $action = str_replace( '%permalink%', $activity_url, $action );
  486.             $action = str_replace( '%author%', $author, $action );
  487.  
  488.             bp_activity_add(
  489.                 array(
  490.                     'action' => $action,
  491.                     'content' => $content,
  492.                     'primary_link' => $activity_url,
  493.                     'component' => 'bp-like',
  494.                     'type' => 'activity_liked',
  495.                     'user_id' => $user_id,
  496.                     'item_id' => $item_id
  497.                 )
  498.             );
  499.  
  500.         };
  501.    
  502.     elseif ( $type == 'blogpost' ) :
  503.        
  504.         /* Add to the users liked blog posts. */
  505.         $user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true);
  506.         $user_likes[$item_id] = 'blogpost_liked';
  507.         update_user_meta( $user_id, 'bp_liked_blogposts', $user_likes );
  508.  
  509.         /* Add to the total likes for this blog post. */
  510.         $users_who_like = get_post_meta( $item_id, 'liked_count', true );
  511.         $users_who_like[$user_id] = 'user_likes';
  512.         update_post_meta( $item_id, 'liked_count', $users_who_like );
  513.        
  514.         $liked_count = count( $users_who_like );
  515.        
  516.                              /***
  517.                  * Hack: Post a screen notification to the user's notifications menu.          
  518.                  */
  519.                 bp_core_add_notification( $item_id, $user_id, $bp->bp_like->slug, 'new_bp_like' );
  520.        
  521.         if ( bp_like_get_settings( 'post_to_activity_stream' ) == 1 ) {
  522.             $post = get_post($item_id);
  523.             $author_id = $post->post_author;
  524.    
  525.             $liker = bp_core_get_userlink( $user_id );
  526.             $permalink = get_permalink( $item_id );
  527.             $title = $post->post_title;
  528.             $author = bp_core_get_userlink( $post->post_author );
  529.  
  530.             if ($user_id == $author_id)
  531.                 $action = bp_like_get_text( 'record_activity_likes_own_blogpost' );
  532.             elseif ($user_id == 0)
  533.                 $action = bp_like_get_text( 'record_activity_likes_a_blogpost' );
  534.             else
  535.                 $action = bp_like_get_text( 'record_activity_likes_users_blogpost' );
  536.    
  537.             /* Filter out the placeholders */
  538.             $action = str_replace( '%user%', $liker, $action );
  539.             $action = str_replace( '%permalink%', $permalink, $action );
  540.             $action = str_replace( '%title%', $title, $action );
  541.             $action = str_replace( '%author%', $author, $action );
  542.            
  543.             /* Grab the content and make it into an excerpt of 140 chars if we're allowed */
  544.             if ( bp_like_get_settings( 'show_excerpt' ) == 1 ) {
  545.                 $content = $post->post_content;
  546.                 if ( strlen( $content ) > bp_like_get_settings( 'excerpt_length' ) ) {
  547.                     $content = substr( $content, 0, bp_like_get_settings( 'excerpt_length' ) );
  548.                     $content = $content.'...';
  549.                 }
  550.             };
  551.    
  552.             bp_activity_add(
  553.                 array(
  554.                     'action' => $action,
  555.                     'content' => $content,
  556.                     'component' => 'bp-like',
  557.                     'type' => 'blogpost_liked',
  558.                     'user_id' => $user_id,
  559.                     'item_id' => $item_id,
  560.                     'primary_link' => $permalink
  561.                 )
  562.             );
  563.            
  564.             // bp_like_send_notification( $snippet->id, $snippet->user_id, $snippet->item_id, $user_id, $content);
  565.        
  566.         };
  567.        
  568.     endif;
  569.  
  570.     echo bp_like_get_text( 'unlike' );
  571.    
  572.         echo ' ' . $liked_count . '<div style="float: right;">Unlike</div>';
  573. }
  574.  
  575. /**
  576.  * bp_like_remove_user_like()
  577.  *
  578.  * Registers that the user has unliked a given item.
  579.  *
  580.  */
  581. function bp_like_remove_user_like( $item_id = '', $type = 'activity') {
  582.     global $bp;
  583.    
  584.     if ( !$item_id )
  585.         return false;
  586.  
  587.     if ( !$user_id )
  588.         $user_id = $bp->loggedin_user->id;
  589.    
  590.     if ( $user_id == 0 ) {
  591.         echo bp_like_get_text( 'must_be_logged_in' );
  592.         return false;
  593.     }
  594.  
  595.     if ( $type == 'activity' ) :
  596.  
  597.         /* Remove this from the users liked activities. */
  598.         $user_likes = get_user_meta( $user_id, 'bp_liked_activities', true );
  599.         unset( $user_likes[$item_id] );
  600.         update_user_meta( $user_id, 'bp_liked_activities', $user_likes );
  601.  
  602.         /* Update the total number of users who have liked this activity. */
  603.         $users_who_like = bp_activity_get_meta( $item_id, 'liked_count', true );
  604.         unset( $users_who_like[$user_id] );
  605.        
  606.         /* If nobody likes the activity, delete the meta for it to save space, otherwise, update the meta */
  607.         if ( empty( $users_who_like ) )
  608.             bp_activity_delete_meta( $item_id, 'liked_count' );
  609.         else
  610.             bp_activity_update_meta( $item_id, 'liked_count', $users_who_like );
  611.    
  612.         $liked_count = count( $users_who_like );
  613.  
  614.         /* Remove the update on the users profile from when they liked the activity. */
  615.         $update_id = bp_activity_get_activity_id(
  616.             array(
  617.                 'item_id' => $item_id,
  618.                 'component' => 'bp-like',
  619.                 'type' => 'activity_liked',
  620.                 'user_id' => $user_id
  621.             )
  622.         );
  623.    
  624.         bp_activity_delete(
  625.             array(
  626.                 'id' => $update_id,
  627.                 'item_id' => $item_id,
  628.                 'component' => 'bp-like',
  629.                 'type' => 'activity_liked',
  630.                 'user_id' => $user_id
  631.             )
  632.         );
  633.        
  634.     elseif ( $type == 'blogpost' ) :
  635.        
  636.         /* Remove this from the users liked activities. */
  637.         $user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true );
  638.         unset( $user_likes[$item_id] );
  639.         update_user_meta( $user_id, 'bp_liked_blogposts', $user_likes );
  640.  
  641.         /* Update the total number of users who have liked this blog post. */
  642.         $users_who_like = get_post_meta( $item_id, 'liked_count', true );
  643.         unset( $users_who_like[$user_id] );
  644.        
  645.         /* If nobody likes the blog post, delete the meta for it to save space, otherwise, update the meta */
  646.         if ( empty( $users_who_like ) )
  647.             delete_post_meta( $item_id, 'liked_count' );
  648.         else
  649.             update_post_meta( $item_id, 'liked_count', $users_who_like );
  650.  
  651.         $liked_count = count( $users_who_like );
  652.  
  653.         /* Remove the update on the users profile from when they liked the activity. */
  654.         $update_id = bp_activity_get_activity_id(
  655.             array(
  656.                 'item_id' => $item_id,
  657.                 'component' => 'bp-like',
  658.                 'type' => 'blogpost_liked',
  659.                 'user_id' => $user_id
  660.             )
  661.         );
  662.    
  663.         bp_activity_delete(
  664.             array(
  665.                 'id' => $update_id,
  666.                 'item_id' => $item_id,
  667.                 'component' => 'bp-like',
  668.                 'type' => 'blogpost_liked',
  669.                 'user_id' => $user_id
  670.             )
  671.         );
  672.        
  673.     endif;
  674.  
  675.     echo bp_like_get_text( 'like' );
  676.    
  677.         echo ' ' . $liked_count . '<div style="float: right;">Like this</div>';
  678. }
  679.  
  680. /**
  681.  * bp_like_get_likes()
  682.  *
  683.  * Outputs a list of users who have liked a given item.
  684.  *
  685.  */
  686. function bp_like_get_likes( $item_id = '', $type = '', $user_id = '' ) {
  687.     global $bp;
  688.    
  689.     if ( !$type || !$item_id )
  690.         return false;
  691.    
  692.     if ( !$user_id )
  693.         $user_id = $bp->loggedin_user->id;
  694.  
  695.     if ( $type == 'activity' ) :
  696.        
  697.         /* Grab some core data we will need later on, specific to activities */
  698.         $users_who_like     = array_keys( bp_activity_get_meta( $item_id, 'liked_count' ) );
  699.         $liked_count        = count( bp_activity_get_meta( $item_id, 'liked_count' ) );
  700.        
  701.         /* Intercept any messages if nobody likes it, just incase the button was clicked when it shouldn't be */
  702.         if ( $liked_count == 0 ) :
  703.            
  704.             $output .= bp_like_get_text( 'get_likes_no_likes' );
  705.        
  706.         /* We should show information about all likers */
  707.         elseif ( bp_like_get_settings( 'likers_visibility' ) == 'show_all' ) :
  708.            
  709.             /* Settings say we should show their name. */
  710.             if ( bp_like_get_settings( 'name_or_avatar' ) == 'name' ) :
  711.                
  712.                 /* Current user likes it too, remove them from the liked count and output appropriate message */
  713.                 if ( bp_like_is_liked( $item_id, 'activity', $user_id ) ) :
  714.                    
  715.                     $liked_count = $liked_count-1;
  716.                    
  717.                     if ( $liked_count == 1 )
  718.                         $output .= bp_like_get_text( 'get_likes_you_and_singular' );
  719.  
  720.                     elseif ( $liked_count == 0 )
  721.                         $output .= bp_like_get_text('get_likes_only_liker');
  722.  
  723.                     else
  724.                         $output .= bp_like_get_text( 'get_likes_you_and_plural' );
  725.                
  726.                 else :
  727.                    
  728.                     if ( $liked_count == 1 )
  729.                         $output .= bp_like_get_text( 'get_likes_count_people_singular' );
  730.                    
  731.                     else
  732.                         $output .= bp_like_get_text( 'get_likes_count_people_plural' );
  733.                    
  734.                 endif;
  735.                    
  736.                 /* Now output the name of each person who has liked it (except the current user obviously) */
  737.                 foreach( $users_who_like as $id ) :
  738.                    
  739.                     if ( $id != $user_id )
  740.                         $output .= ' &middot <a href="' . bp_core_get_user_domain( $id ) . '" title="' . bp_core_get_user_displayname( $id ) . '">' . bp_core_get_user_displayname( $id ) . '</a>';
  741.                    
  742.                 endforeach;
  743.            
  744.             /* Settings say we should show their avatar. */
  745.             elseif ( bp_like_get_settings( 'name_or_avatar' ) == 'avatar' ) :
  746.                
  747.                 /* Output the avatar of each person who has liked it. */
  748.                 foreach( $users_who_like as $id ) :
  749.                    
  750.                     $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> ';
  751.  
  752.                 endforeach;
  753.                
  754.             endif;
  755.        
  756.         /* We should show the information of friends, but only the number of non-friends. */
  757.         elseif ( bp_like_get_settings( 'likers_visibility' ) == 'friends_names_others_numbers' && bp_is_active( 'friends' ) ) :
  758.            
  759.             /* Grab some information about their friends. */
  760.             $users_friends = friends_get_friend_user_ids( $user_id );
  761.             if ( !empty( $users_friends ) )
  762.                 $friends_who_like = array_intersect( $users_who_like, $users_friends );
  763.            
  764.             /* Current user likes it, so reduce the liked count by 1, to get the number of other people who like it. */
  765.             if ( bp_like_is_liked( $item_id, 'activity', $user_id ) )
  766.                 $liked_count = $liked_count-1;
  767.            
  768.             /* Settings say we should show their names. */
  769.             if ( bp_like_get_settings( 'name_or_avatar' ) == 'name' ) :
  770.                    
  771.                     /* Current user likes it too, tell them. */
  772.                     if ( bp_like_is_liked( $item_id, 'activity', $user_id ) )
  773.                         $output .= 'You ';
  774.                
  775.                     /* Output the name of each friend who has liked it. */
  776.                     foreach( $users_who_like as $id ) :
  777.                    
  778.                         if ( in_array( $id, $friends_who_like ) ) {
  779.                             $output .= ' &middot <a href="' . bp_core_get_user_domain( $id ) . '" title="' . bp_core_get_user_displayname( $id ) . '">' . bp_core_get_user_displayname( $id ) . '</a> ';
  780.                        
  781.                             $liked_count = $liked_count-1;
  782.                         }
  783.                    
  784.                     endforeach;
  785.                    
  786.                     /* If non-friends like it, say so. */
  787.                     if ( $liked_count == 1 )
  788.                         $output .= bp_like_get_text( 'get_likes_and_people_singular' );
  789.  
  790.                     elseif ( $liked_count > 1 )
  791.                         $output .= bp_like_get_text( 'get_likes_and_people_plural' );
  792.                    
  793.                     else
  794.                         $output .= bp_like_get_text( 'get_likes_like_this' );
  795.                
  796.             /* Settings say we should show their avatar. */
  797.             elseif ( bp_like_get_settings( 'name_or_avatar' ) == 'avatar' ) :
  798.                
  799.                 /* Output the avatar of each friend who has liked it, as well as the current users' if they have. */
  800.                 if ( !empty( $friends_who_like ) ) :
  801.            
  802.                     foreach( $users_who_like as $id ) :
  803.                    
  804.                         if ( $id == $user_id || in_array( $id, $friends_who_like ) ) {
  805.                             $user_info = get_userdata( $id );
  806.                             $output .= '<a href="' . bp_core_get_user_domain( $id ) . '" title="' . bp_core_get_user_displayname( $id ) . '">' . get_avatar( $user_info->user_email, 30 ) . '</a> ';
  807.                         }
  808.                    
  809.                     endforeach;
  810.                
  811.                 endif;
  812.                
  813.             endif;
  814.        
  815.         elseif ( bp_like_get_settings( 'likers_visibility' ) == 'friends_names_others_numbers' && !bp_is_active( 'friends' ) ||bp_like_get_settings( 'likers_visibility' ) == 'just_numbers' ) :
  816.            
  817.                 /* Current user likes it too, remove them from the liked count and output appropriate message */
  818.                 if ( bp_like_is_liked( $item_id, 'activity', $user_id ) ) :
  819.                    
  820.                     $liked_count = $liked_count-1;
  821.                    
  822.                     if ( $liked_count == 1 )
  823.                         $output .= bp_like_get_text( 'get_likes_you_and_singular' );
  824.                    
  825.                     elseif ( $liked_count == 0 )
  826.                         $output .= bp_like_get_text('get_likes_only_liker');
  827.                    
  828.                     else
  829.                         $output .= bp_like_get_text( 'get_likes_you_and_plural' );
  830.                
  831.                 else :
  832.                    
  833.                     if ( $liked_count == 1 )
  834.                         $output .= bp_like_get_text( 'get_likes_count_people_singular' );
  835.                    
  836.                     else
  837.                         $output .= bp_like_get_text( 'get_likes_count_people_plural' );
  838.                    
  839.                 endif;
  840.        
  841.         endif;
  842.    
  843.     endif;
  844.    
  845.     /* Filter out the placeholder. */
  846.     $output = str_replace( '%count%', $liked_count, $output );
  847.    
  848.     echo $output;
  849.        
  850. }
  851.  
  852. /**
  853.  * bp_like_button()
  854.  *
  855.  * Outputs the 'Like/Unlike' and 'View likes/Hide likes' buttons.
  856.  *
  857.  */
  858. function bp_like_button( $id = '', $type = '' ) {
  859.    
  860.     $users_who_like = 0;
  861.     $liked_count = 0;
  862.    
  863.     /* Set the type if not already set, and check whether we are outputting the button on a blogpost or not. */
  864.     if ( !$type && !is_single() )
  865.         $type = 'activity';
  866.     elseif ( !$type && is_single() )
  867.         $type = 'blogpost';
  868.    
  869.     if ( $type == 'activity' ) :
  870.    
  871.         $activity = bp_activity_get_specific( array( 'activity_ids' => bp_get_activity_id() ) );
  872.         $activity_type = $activity['activities'][0]->type;
  873.    
  874.         if ( is_user_logged_in() && $activity_type !== 'activity_liked' ) :
  875.            
  876.             if ( bp_activity_get_meta( bp_get_activity_id(), 'liked_count', true )) {
  877.                 $users_who_like = array_keys( bp_activity_get_meta( bp_get_activity_id(), 'liked_count', true ) );
  878.                 $liked_count = count( $users_who_like );
  879.             }
  880.            
  881.             if ( !bp_like_is_liked( bp_get_activity_id(), 'activity' ) ) : ?>
  882.                 <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 ' ' . $liked_count . ''; ?></a>
  883.             <?php else : ?>
  884.                 <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 ' ' . $liked_count . ''; ?></a>
  885.             <?php endif;
  886.            
  887.              if ( $users_who_like ): ?>
  888.                 <a href="#" class="view-likes" id="view-likes-<?php bp_activity_id(); ?>"><?php echo bp_like_get_text( 'view_likes' ); ?></a>
  889.                 <p class="users-who-like" id="users-who-like-<?php bp_activity_id(); ?>"></p>
  890.             <?php
  891.             endif;
  892.         endif;
  893.    
  894.     elseif ( $type == 'blogpost' ) :
  895.         global $post;
  896.        
  897.         if ( !$id && is_single() )
  898.             $id = $post->ID;
  899.        
  900.        
  901.             $liked_count = count( get_post_meta( $id, 'liked_count', true ) );
  902.        
  903.        
  904.         if ( !bp_like_is_liked( $id, 'blogpost' ) ) : ?>
  905.        
  906.         <div class="like-box">
  907.        
  908.         <a href="#" class="like_blogpost" id="like-blogpost-<?php echo $id; ?>" title="<?php echo bp_like_get_text( 'like_this_item' ); ?>"><?php
  909.        
  910.         if ( $liked_count ) echo ' ' . $liked_count . '<div style="float: right;">Like this</div>';
  911.        
  912.         else echo ' 0 <div style="float: right;">Like this</div>'; ?>
  913.        
  914.         </a>
  915.        
  916.         </div>
  917.        
  918.         <?php else : ?>
  919.        
  920.         <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 ' ' . $liked_count . '<div style="float: right;">Unlike</div>'; ?></a></div>
  921.            
  922.         <?php endif;
  923.  
  924.     endif;
  925. };
  926. add_filter( 'bp_activity_entry_meta', 'bp_like_button' );
  927. add_action( 'bp_before_blog_single_post', 'bp_like_button' );
  928.  
  929. /**
  930.  * bp_like_activity_filter()
  931.  *
  932.  * Adds 'Show Activity Likes' to activity stream filters.
  933.  *
  934.  */
  935. function bp_like_activity_filter() {
  936.     echo '<option value="activity_liked">' . bp_like_get_text( 'show_activity_likes' ) . '</option>';
  937.     echo '<option value="blogpost_liked">Show Blog Post Likes</option>';
  938. }
  939. add_action( 'bp_activity_filter_options', 'bp_like_activity_filter' );
  940. add_action( 'bp_member_activity_filter_options', 'bp_like_activity_filter' );
  941. add_action( 'bp_group_activity_filter_options', 'bp_like_activity_filter' );
  942.  
  943. /**
  944.  * bp_like_list_scripts()
  945.  *
  946.  * Includes the Javascript required for Ajax etc.
  947.  *
  948.  */
  949. function bp_like_list_scripts() {
  950.     wp_enqueue_script(
  951.         "bp-like",
  952.         path_join( WP_PLUGIN_URL, basename( dirname( __FILE__ ) )."/_inc/js/bp-like.min.js" ),
  953.         array( 'jquery' )
  954.     );
  955. }
  956. add_action( 'wp_print_scripts', 'bp_like_list_scripts' );
  957.  
  958. /**
  959.  * bp_like_insert_head()
  960.  *
  961.  * Includes any CSS and/or Javascript needed in the <head>.
  962.  *
  963.  */
  964. function bp_like_insert_head() {
  965. ?>
  966. <style type="text/css">
  967.     .bp-like.activity_liked .activity-meta,
  968.     .bp-like.blogpost_liked .activity-meta,
  969.     .users-who-like,
  970.     .mini a.view-likes,
  971.     .mini a.hide-likes {
  972.         display: none;
  973.     }
  974.    
  975.     /* To match the default theme */
  976.     #bp-default .users-who-like {
  977.         margin: 10px 0 -10px 0;
  978.         background: #F5F5F5;
  979.         -moz-border-radius: 4px;
  980.         -webkit-border-radius: 4px;
  981.         border-radius: 4px;
  982.         padding: 8px 8px 0px 12px;
  983.         color: #8C8A8F;
  984.     }
  985.     #bp-default .users-who-like a {
  986.         color: #777;
  987.         padding: 0;
  988.         background: none;
  989.         border: none;
  990.         text-decoration: underline;
  991.         font-size: 12px;
  992.     }
  993.     #bp-default .users-who-like a:hover { color: #222; }
  994.     #bp-default .mini .users-who-like {
  995.         width: 100%;
  996.         position: absolute;
  997.         top: 0;
  998.         left: 0;
  999.     }
  1000.     #bp-default .users-who-like img.avatar {
  1001.         float: none;
  1002.         border: none;
  1003.         width: 30px;
  1004.         height: 30px;
  1005.         padding: 0;
  1006.         margin: 0;
  1007.     }
  1008.     ul#activity-stream li.bp-like .activity-inner {
  1009.         border-left: 3px solid #ddd;
  1010.         color: #888;
  1011.         padding-left: 15px;
  1012.         font-style: italic;
  1013.     }
  1014.     #bp-default div.post div.author-box, div.comment-avatar-box {
  1015.     position: relative;
  1016.     }
  1017.     #bp-default div.like-box {
  1018.         background: #f0f0f0;
  1019.         width: 90px;
  1020.         position: absolute;
  1021.         bottom: -40px;
  1022.         left: 0;
  1023.         font-family: georgia, times, serif;
  1024.         font-style: italic;
  1025.         text-align: center;
  1026.         padding: 5px 0;
  1027.         -moz-border-radius: 3px;
  1028.         -webkit-border-radius: 3px;
  1029.         border-radius: 3px;
  1030.     }
  1031. </style>
  1032. <script type="text/javascript">
  1033. /* <![CDATA[ */
  1034.     var bp_like_terms_like = '<?php echo bp_like_get_text( 'like' ); ?>';
  1035.     var bp_like_terms_like_message = '<?php echo bp_like_get_text( 'like_this_item' ); ?>';
  1036.     var bp_like_terms_unlike_message = '<?php echo bp_like_get_text( 'unlike_this_item' ); ?>';
  1037.     var bp_like_terms_view_likes = '<?php echo bp_like_get_text( 'view_likes' ); ?>';
  1038.     var bp_like_terms_hide_likes = '<?php echo bp_like_get_text( 'hide_likes' ); ?>';
  1039.     var bp_like_terms_unlike_1 = '<?php echo bp_like_get_text( 'unlike' ); ?> (1)';
  1040. /* ]]> */
  1041. </script>
  1042. <?php  
  1043. }
  1044. add_action( 'wp_head', 'bp_like_insert_head' );
  1045.  
  1046. /**
  1047.  * bp_like_add_admin_page_menu()
  1048.  *
  1049.  * Adds "BuddyPress Like" to the main BuddyPress admin menu.
  1050.  *
  1051.  */
  1052. function bp_like_add_admin_page_menu() {
  1053.     add_submenu_page(
  1054.         'bp-general-settings',
  1055.         'BuddyPress Like',
  1056.         'BuddyPress Like',
  1057.         'manage_options',
  1058.         'bp-like-settings',
  1059.         'bp_like_admin_page'
  1060.     );
  1061. }
  1062. add_action( 'admin_menu', 'bp_like_add_admin_page_menu' );
  1063.  
  1064. /**
  1065.  * bp_like_admin_page_verify_nonce()
  1066.  *
  1067.  * When the settings form is submitted, verifies the nonce to ensure security.
  1068.  *
  1069.  */
  1070. function bp_like_admin_page_verify_nonce() {
  1071.     if( isset( $_POST['_wpnonce'] ) && isset( $_POST['bp_like_updated'] ) ) {
  1072.         $nonce = $_REQUEST['_wpnonce'];
  1073.         if ( !wp_verify_nonce( $nonce, 'bp-like-admin' ) )
  1074.             wp_die( __('You do not have permission to do that.') );
  1075.     }
  1076. }
  1077. add_action( 'init', 'bp_like_admin_page_verify_nonce' );
  1078.  
  1079.  
  1080. /**
  1081.  * bp_like_admin_page()
  1082.  *
  1083.  * Outputs the admin settings page.
  1084.  *
  1085.  */
  1086. function bp_like_admin_page() {
  1087.     global $current_user;
  1088.  
  1089.     wp_get_current_user();
  1090.  
  1091.     /* Update our options if the form has been submitted */
  1092.     if( isset( $_POST['_wpnonce'] ) && isset( $_POST['bp_like_updated'] ) ) {
  1093.        
  1094.         /* Add each text string to the $strings_to_save array */
  1095.         foreach ( $_POST as $key => $value ) {
  1096.             if ( preg_match( "/text_string_/i", $key )) {
  1097.                 $default = bp_like_get_text( str_replace( 'bp_like_admin_text_string_', '', $key), 'default' );
  1098.                 $strings_to_save[str_replace( 'bp_like_admin_text_string_', '', $key )] = array('default' => $default, 'custom' => stripslashes( $value ));
  1099.             }
  1100.         }
  1101.        
  1102.         /* Now actually save the data to the options table */
  1103.         update_site_option(
  1104.             'bp_like_settings',
  1105.             array(
  1106.                 'likers_visibility' => $_POST['bp_like_admin_likers_visibility'],
  1107.                 'post_to_activity_stream' => $_POST['bp_like_admin_post_to_activity_stream'],
  1108.                 'show_excerpt' => $_POST['bp_like_admin_show_excerpt'],
  1109.                 'excerpt_length' => $_POST['bp_like_admin_excerpt_length'],
  1110.                 'text_strings' => $strings_to_save,
  1111.                 'translate_nag' => bp_like_get_settings( 'translate_nag' ),
  1112.                 'name_or_avatar' => $_POST['name_or_avatar']
  1113.             )
  1114.         );
  1115.        
  1116.         /* Let the user know everything's cool */
  1117.         echo '<div class="updated"><p><strong>';
  1118.         _e('Settings saved.', 'wordpress');
  1119.         echo '</strong></p></div>';
  1120.     }
  1121.    
  1122.     $text_strings = bp_like_get_settings( 'text_strings' );
  1123.  
  1124. ?>
  1125. <style type="text/css">
  1126. #icon-bp-like-settings { background: url('<?php echo plugins_url('/_inc/img/bp-like-icon32.png', __FILE__); ?>') no-repeat top left; }
  1127. table input { width: 100%; }
  1128. table label { display: block; }
  1129. </style>
  1130. <script type="text/javascript">
  1131. jQuery(document).ready( function() {
  1132.     jQuery('select.name-or-avatar').change(function(){
  1133.         var value = jQuery(this).val();
  1134.         jQuery('select.name-or-avatar').val(value);
  1135.     });
  1136. });
  1137. </script>
  1138.  
  1139. <div class="wrap">
  1140.   <div id="icon-bp-like-settings" class="icon32"><br /></div>
  1141.   <h2><?php _e('BuddyPress Like Settings', 'buddypress-like'); ?></h2>
  1142.   <form action="" method="post" id="bp-like-admin-form">
  1143.     <input type="hidden" name="bp_like_updated" value="updated">
  1144.    
  1145.     <h3><?php _e('General Settings', 'buddypress-like'); ?></h3>
  1146.     <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>
  1147.     <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>
  1148.    
  1149.     <h3><?php _e("'View Likes' Visibility", "buddypress-like"); ?></h3>
  1150.     <p><?php _e("Choose how much information about the 'likers' of a particular item is shown;", "buddypress-like"); ?></p>
  1151.     <p style="line-height: 200%;">
  1152.       <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 />
  1153.       <?php if ( bp_is_active( 'friends' ) ) { ?>
  1154.       <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 />
  1155.       <?php }; ?>
  1156.       <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'); ?>
  1157.     </p>
  1158.     <h3><?php _e('Custom Messages', 'buddypress-like'); ?></h3>
  1159.     <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>
  1160.    
  1161.     <table class="widefat fixed" cellspacing="0">
  1162.       <thead>
  1163.         <tr>
  1164.           <th scope="col" id="default" class="column-name" style="width: 43%;"><?php _e('Default', 'buddypress-like'); ?></th>
  1165.           <th scope="col" id="custom" class="column-name" style=""><?php _e('Custom', 'buddypress-like'); ?></th>
  1166.         </tr>
  1167.       </thead>
  1168.       <tfoot>
  1169.         <tr>
  1170.           <th colspan="2" id="default" class="column-name"></th>
  1171.         </tr>
  1172.       </tfoot>
  1173.  
  1174.       <?php foreach ( $text_strings as $key => $string ) : ?>
  1175.       <tr valign="top">
  1176.           <th scope="row" style="width:400px;"><label for="bp_like_admin_text_string_<?php echo $key; ?>"><?php echo htmlspecialchars( $string['default'] ); ?></label></th>
  1177.           <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>
  1178.         </tr>
  1179.       <?php endforeach; ?>
  1180.       </tbody>
  1181.     </table>
  1182.    
  1183.     <p class="submit">
  1184.       <input class="button-primary" type="submit" name="bp-like-admin-submit" id="bp-like-admin-submit" value="<?php _e('Save Changes', 'wordpress'); ?>"/>
  1185.     </p>
  1186.     <?php wp_nonce_field( 'bp-like-admin' ) ?>
  1187.   </form>
  1188. </div>
  1189. <?php
  1190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement