Changeset 3545
- Timestamp:
- 06/22/2016 01:33:53 PM (8 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/class-base.php
r3510 r3545 12 12 */ 13 13 static function load_routes() { 14 new Routes\Commit_Subscriptions();15 14 new Routes\Internal_Stats(); 16 15 new Routes\Plugin(); 17 16 new Routes\Plugin_Translations(); 17 new Routes\Plugin_Favorites(); 18 new Routes\Commit_Subscriptions(); 18 19 new Routes\Popular_Categories(); 19 20 new Routes\Query_Plugins(); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-favorites.php
r3523 r3545 6 6 7 7 /** 8 * An API endpoint for subscribing to commits fora particular plugin.8 * An API endpoint for favoriting a particular plugin. 9 9 * 10 10 * @package WordPressdotorg_Plugin_Directory 11 11 */ 12 class Commit_Subscriptions extends Base {12 class Plugin_Favorites extends Base { 13 13 14 14 public function __construct() { 15 register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/ commit-subscription', array(16 'methods' => \WP_REST_Server::READABLE,17 'callback' => array( $this, ' subscribe' ),15 register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/favorite', array( 16 'methods' => array( \WP_REST_Server::READABLE, \WP_REST_Server::CREATABLE ), 17 'callback' => array( $this, 'favorite' ), 18 18 'args' => array( 19 19 'plugin_slug' => array( 20 20 'validate_callback' => array( $this, 'validate_plugin_slug_callback' ), 21 21 ), 22 ' subscribe' => array(22 'favorite' => array( 23 23 'validate_callback' => function( $bool ) { return is_numeric( $bool ); }, 24 24 ), 25 'un subscribe' => array(25 'unfavorite' => array( 26 26 'validate_callback' => function( $bool ) { return is_numeric( $bool ); }, 27 27 ), … … 32 32 33 33 /** 34 * Endpoint to subscribe to a plugin's commits.34 * Endpoint to favorite a plugin. 35 35 * 36 36 * @param \WP_REST_Request $request The Rest API Request. 37 * @return bool True if the subscriptionwas successful.37 * @return bool True if the favoriting was successful. 38 38 */ 39 public function subscribe( $request ) {40 $location = get_permalink( Plugin_Directory::get_plugin_post( $request['plugin_slug'] ) ) . '#developers';39 public function favorite( $request ) { 40 $location = get_permalink( Plugin_Directory::get_plugin_post( $request['plugin_slug'] ) ); 41 41 header( "Location: $location" ); 42 42 … … 45 45 ); 46 46 47 if ( ! isset( $request[' subscribe'] ) && ! isset( $request['unsubscribe'] ) ) {47 if ( ! isset( $request['favorite'] ) && ! isset( $request['unfavorite'] ) ) { 48 48 $result['error'] = 'Unknown Action'; 49 49 } 50 50 51 $result[' subscribed'] = Tools::subscribe_to_plugin_commits( $request['plugin_slug'], get_current_user_id(), isset( $request['subscribe'] ) );51 $result['favorite'] = Tools::favorite_plugin( $request['plugin_slug'], get_current_user_id(), isset( $request['favorite'] ) ); 52 52 53 53 return (object) $result; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r3511 r3545 462 462 return ent2ncr( htmlspecialchars_decode( htmlentities( $string, ENT_NOQUOTES, 'UTF-8' ), ENT_NOQUOTES ) ); 463 463 } 464 465 /** 466 * Generates a link to toggle a plugin favorites state. 467 * 468 * @param string $plugin_slug The plugin slug. 469 * @param mixed $user The user to alter the favorite status for. 470 * @return string URL to toggle status. 471 */ 472 public static function get_favourite_link( $plugin_slug, $user = 0 ) { 473 $post = Plugin_Directory::get_plugin_post( $plugin_slug ); 474 if ( ! $post ) { 475 return false; 476 } 477 478 $favorited = Tools::favorited_plugin( $post, $user ); 479 480 return add_query_arg( 481 array( 482 '_wpnonce' => wp_create_nonce( 'wp_rest' ), 483 ( $favorited ? 'unfavorite' : 'favorite' ) => '1' 484 ), 485 home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/favorite' ) 486 ); 487 } 464 488 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php
r3530 r3545 257 257 258 258 /** 259 * Determine if a plugin has been favorited by a user. 260 * 261 * @param string $plugin_slug The plugin to check. 262 * @param mixed $user The user to check. 263 * @return bool 264 */ 265 public static function favorited_plugin( $plugin_slug, $user = 0 ) { 266 $post = Plugin_Directory::get_plugin_post( $plugin_slug ); 267 if ( ! $post ) { 268 return false; 269 } 270 271 $user = new WP_User( $user ?: get_current_user_id() ); 272 if ( ! $user->exists() ) { 273 return false; 274 } 275 276 $users_favorites = get_user_meta( $user->ID, 'plugin_favorites', true ) ?: array(); 277 278 return in_array( $post->post_name, $users_favorites, true ); 279 } 280 281 /** 282 * Favorite a plugin 283 * 284 * @param string $plugin_slug The plugin to favorite 285 * @param mixed $user The user favorite 286 * @param bool $favorite Whether it's a favorite, or unfavorite. 287 * @return bool 288 */ 289 public static function favorite_plugin( $plugin_slug, $user = 0, $favorite = true ) { 290 $post = Plugin_Directory::get_plugin_post( $plugin_slug ); 291 if ( ! $post ) { 292 return false; 293 } 294 295 $user = new WP_User( $user ?: get_current_user_id() ); 296 if ( ! $user->exists() ) { 297 return false; 298 } 299 300 $users_favorites = get_user_meta( $user->ID, 'plugin_favorites', true ) ?: array(); 301 302 $already_favorited = in_array( $post->post_name, $users_favorites, true ); 303 304 if ( $favorite && $already_favorited ) { 305 return true; 306 } elseif ( $favorite ) { 307 // Add it 308 $users_favorites[] = $post->post_name; 309 } elseif ( ! $favorite && $already_favorited ) { 310 // Remove it 311 unset( $users_favorites[ array_search( $post->post_name, $users_favorites, true ) ] ); 312 } else { 313 return true; 314 } 315 316 return update_user_meta( $user->ID, 'plugin_favorites', wp_slash( array_values( $users_favorites ) ) ); 317 318 } 319 320 /** 259 321 * Retrieve a list of users who are subscribed to plugin commits. 260 322 * -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/css/style-rtl.css
r3539 r3545 2159 2159 } 2160 2160 2161 .single .type-plugin .plugin-header .plugin- download{2161 .single .type-plugin .plugin-header .plugin-actions { 2162 2162 float: left; 2163 } 2164 2165 .single .type-plugin .plugin-header .plugin-favorite-heart { 2166 color: gray; 2167 line-heght: 3em; 2168 font-size: 3em; 2169 } 2170 2171 .single .type-plugin .plugin-header .plugin-favorite-heart.favorited, .single .type-plugin .plugin-header .plugin-favorite-heart:hover, .single .type-plugin .plugin-header .plugin-favorite-heart:focus { 2172 color: red; 2173 } 2174 2175 .single .type-plugin .plugin-header .plugin-favorite-heart:hover, .single .type-plugin .plugin-header .plugin-favorite-heart:focus { 2176 text-decoration: none; 2177 } 2178 2179 .single .type-plugin .plugin-header .plugin-favorite-heart:after { 2180 content: "\f487"; 2181 font-family: dashicons; 2182 vertical-align: top; 2163 2183 } 2164 2184 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/css/style.css
r3539 r3545 2159 2159 } 2160 2160 2161 .single .type-plugin .plugin-header .plugin- download{2161 .single .type-plugin .plugin-header .plugin-actions { 2162 2162 float: right; 2163 } 2164 2165 .single .type-plugin .plugin-header .plugin-favorite-heart { 2166 /* FIX ME */ 2167 color: gray; 2168 line-heght: 3em; 2169 font-size: 3em; 2170 } 2171 2172 .single .type-plugin .plugin-header .plugin-favorite-heart.favorited, .single .type-plugin .plugin-header .plugin-favorite-heart:hover, .single .type-plugin .plugin-header .plugin-favorite-heart:focus { 2173 color: red; 2174 } 2175 2176 .single .type-plugin .plugin-header .plugin-favorite-heart:hover, .single .type-plugin .plugin-header .plugin-favorite-heart:focus { 2177 text-decoration: none; 2178 } 2179 2180 .single .type-plugin .plugin-header .plugin-favorite-heart:after { 2181 content: "\f487"; 2182 font-family: dashicons; 2183 vertical-align: top; 2163 2184 } 2164 2185 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/sass/site/primary/_plugin-single.scss
r3459 r3545 47 47 } 48 48 49 .plugin- download{49 .plugin-actions { 50 50 float: right; 51 } 52 53 .plugin-favorite-heart { 54 /* FIX ME */ 55 color: gray; 56 line-heght: 3em; 57 font-size: 3em; 58 59 &.favorited, 60 &:hover, 61 &:focus { 62 color: red; 63 } 64 65 &:hover, 66 &:focus { 67 text-decoration: none; 68 } 69 70 &:after { 71 content: "\f487"; 72 font-family: dashicons; 73 vertical-align: top; 74 } 75 51 76 } 52 77 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php
r3466 r3545 11 11 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 12 12 use WordPressdotorg\Plugin_Directory\Template; 13 use WordPressdotorg\Plugin_Directory\Tools; 13 14 14 15 $content = Plugin_Directory::instance()->split_post_content_into_pages( get_the_content() ); … … 33 34 </div> 34 35 35 <a class="plugin-download button download-button button-large" href="<?php echo esc_url( Template::download_link() ); ?>" itemprop="downloadUrl"><?php _e( 'Download', 'wporg-plugins' ); ?></a> 36 <meta itemprop="softwareVersion" content="<?php echo esc_attr( get_post_meta( get_the_ID(), 'version', true ) ); ?>"> 37 <meta itemprop="fileFormat" content="application/zip"> 36 <div class="plugin-actions"> 37 38 <?php 39 if ( is_user_logged_in() ) { 40 $url = Template::get_favourite_link( $post ); 41 echo '<a href="' . esc_url( $url ) . '" class="plugin-favorite-heart' . (Tools::favorited_plugin( $post ) ? ' favorited' : '' ) . '" onclick="jQuery(this).toggleClass(\'favorited\')"></a>'; 42 } 43 ?> 44 45 <a class="plugin-download button download-button button-large" href="<?php echo esc_url( Template::download_link() ); ?>" itemprop="downloadUrl"><?php _e( 'Download', 'wporg-plugins' ); ?></a> 46 <meta itemprop="softwareVersion" content="<?php echo esc_attr( get_post_meta( get_the_ID(), 'version', true ) ); ?>"> 47 <meta itemprop="fileFormat" content="application/zip"> 48 </div> 38 49 39 50 <?php the_title( '<h1 class="plugin-title">', '</h1>' ); ?>
Note: See TracChangeset
for help on using the changeset viewer.