Changeset 2611
- Timestamp:
- 02/25/2016 05:03:19 AM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 3 added
- 1 copied
- 7 moved
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php
r2562 r2611 1 1 <?php 2 namespace WordPressdotorg\Plugin_Directory\Admin\Metabox; 3 use WordPressdotorg\Plugin_Directory\Tools; 2 4 3 class WPorg_Plugin_Directory_Admin_Metabox_Committers { 4 function __construct() { 5 add_action( 'add_meta_boxes', array( $this, 'register' ) ); 6 } 7 8 function register() { 9 add_meta_box( 'plugin-committers', __( 'Plugin Committers', 'wporg-plugins' ), array( $this, 'display' ), 'plugin' ); 10 } 11 12 function display() { 5 /** 6 * The Plugin Committers admin metabox. 7 * 8 * @package WordPressdotorg_Plugin_Directory 9 */ 10 class Committers { 11 static function display() { 13 12 $plugin_slug = get_post()->post_name; 14 $existing_committers = WPorg_Plugin_Directory_Tools::get_plugin_committers( $plugin_slug );15 $existing_committers = array_map( function( $user ) { return new WP_User( $user ); }, $existing_committers );13 $existing_committers = Tools::get_plugin_committers( $plugin_slug ); 14 $existing_committers = array_map( function( $user ) { return new \WP_User( $user ); }, $existing_committers ); 16 15 17 16 $output = ''; … … 26 25 echo '<ul class="committers">' . $output . '</ul>'; 27 26 } 28 29 27 } 30 new WPorg_Plugin_Directory_Admin_Metabox_Committers(); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r2561 r2611 1 1 <?php 2 namespace WordPressdotorg\Plugin_Directory; 3 2 4 /** 3 * @package WPorg_Plugin_Directory 5 * The main Plugin Directory class, it handles most of the bootstrap and basic operations of the plugin. 6 * 7 * @package WordPressdotorg_Plugin_Directory 4 8 */ 5 6 /** 7 * Class WPorg_Plugin_Directory 8 */ 9 class WPorg_Plugin_Directory { 10 11 /** 12 * Constructor. 13 */ 14 public function __construct() { 9 class Plugin_Directory { 10 11 /** 12 * Fetch the instance of the Plugin_Directory class. 13 */ 14 public static function instance( $plugin_file = null ) { 15 static $instance = null; 16 return ! is_null( $instance ) ? $instance : $instance = new Plugin_Directory( $plugin_file ); 17 } 18 19 private function __construct( $plugin_file ) { 15 20 add_action( 'init', array( $this, 'init' ) ); 21 add_action( 'init', array( $this, 'register_shortcodes' ) ); 16 22 add_filter( 'post_type_link', array( $this, 'package_link' ), 10, 2 ); 17 23 add_filter( 'pre_insert_term', array( $this, 'pre_insert_term_prevent' ) ); 18 24 add_action( 'pre_get_posts', array( $this, 'use_plugins_in_query' ) ); 19 25 add_filter( 'the_content', array( $this, 'filter_post_content_to_correct_page' ), 1 ); 20 } 21 22 /** 23 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 24 */ 25 public function activate() { 26 global $wp_rewrite; 27 28 // Setup the environment. 29 $this->init(); 30 31 // %postname% is required. 32 $wp_rewrite->set_permalink_structure( '/%postname%/' ); 33 34 // /tags/%slug% is required for tags. 35 $wp_rewrite->set_tag_base( '/tags' ); 36 37 // We require the WordPress.org Ratings plugin also be active. 38 if ( ! is_plugin_active( 'wporg-ratings/wporg-ratings.php' ) ) { 39 activate_plugin( 'wporg-ratings/wporg-ratings.php' ); 40 } 41 42 // Enable the WordPress.org Plugin Repo Theme. 43 foreach ( wp_get_themes() as $theme ) { 44 if ( $theme->get( 'Name' ) === 'WordPress.org Plugins' ) { 45 switch_theme( $theme->get_stylesheet() ); 46 break; 47 } 48 } 49 50 flush_rewrite_rules(); 51 52 do_action( 'wporg_plugins_activation' ); 53 } 54 55 /** 56 * 57 */ 58 public function deactivate() { 59 flush_rewrite_rules(); 60 61 do_action( 'wporg_plugins_deactivation' ); 26 27 // Load all Admin-specific items 28 add_action( 'admin_init', array( __NAMESPACE__ . '\\Admin\\Admin_Customizations', 'instance' ) ); 29 30 register_activation_hook( $plugin_file, array( $this, 'activate' ) ); 31 register_deactivation_hook( $plugin_file, array( $this, 'deactivate' ) ); 62 32 } 63 33 … … 130 100 131 101 /** 102 * Register the Shortcodes used within the content. 103 */ 104 public function register_shortcodes() { 105 add_shortcode( 'wporg-plugins-screenshots', array( __NAMESPACE__ . '\\Shortcodes\\Screenshots', 'display' ) ); 106 // add_shortcode( 'wporg-plugins-stats', array( __NAMESPACE__ . '\\Shortcodes\\Stats', 'display' ) ); 107 // add_shortcode( 'wporg-plugins-developer', array( __NAMESPACE__ . '\\Shortcodes\\Developer', 'display' ) ); 108 } 109 110 /** 111 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 112 */ 113 public function activate() { 114 global $wp_rewrite; 115 116 // Setup the environment. 117 $this->init(); 118 119 // %postname% is required. 120 $wp_rewrite->set_permalink_structure( '/%postname%/' ); 121 122 // /tags/%slug% is required for tags. 123 $wp_rewrite->set_tag_base( '/tags' ); 124 125 // We require the WordPress.org Ratings plugin also be active. 126 if ( ! is_plugin_active( 'wporg-ratings/wporg-ratings.php' ) ) { 127 activate_plugin( 'wporg-ratings/wporg-ratings.php' ); 128 } 129 130 // Enable the WordPress.org Plugin Repo Theme. 131 foreach ( wp_get_themes() as $theme ) { 132 if ( $theme->get( 'Name' ) === 'WordPress.org Plugins' ) { 133 switch_theme( $theme->get_stylesheet() ); 134 break; 135 } 136 } 137 138 flush_rewrite_rules(); 139 140 do_action( 'wporg_plugins_activation' ); 141 } 142 143 /** 144 * 145 */ 146 public function deactivate() { 147 flush_rewrite_rules(); 148 149 do_action( 'wporg_plugins_deactivation' ); 150 } 151 152 /** 132 153 * The Plugin Directory is available at multiple URLs (internationalised domains), this method allows 133 154 * for the one blog (a single blog_id) to be presented at multiple URLs yet have correct localised links. … … 303 324 */ 304 325 public function get_plugin_post( $plugin_slug ) { 305 if ( $plugin_slug instanceof WP_Post ) {326 if ( $plugin_slug instanceof \WP_Post ) { 306 327 return $plugin_slug; 307 328 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-geopattern.php
r2560 r2611 1 1 <?php 2 namespace WordPressdotorg\Plugin_Directory; 2 3 3 4 require __DIR__ . '/libs/geopattern-1.1.0/geopattern_loader.php'; 4 5 5 class WPorg_Plugin_Geopattern extends \RedeyeVentures\GeoPattern\GeoPattern { 6 /** 7 * Generates Geopattern icons for Plugins. 8 * 9 * @package WordPressdotorg_Plugin_Directory 10 */ 11 class Plugin_Geopattern extends \RedeyeVentures\GeoPattern\GeoPattern { 6 12 7 13 var $slug; // Hashed to generate pattern … … 19 25 20 26 // Replace the base SVG object with our own, so the dimensions are gettable. 21 $this->svg = new WPorg_Plugin_Geopattern_SVG();27 $this->svg = new Plugin_Geopattern_SVG(); 22 28 } 23 29 … … 38 44 39 45 public function toSVG( $width = 128, $height = 128 ) { 40 $this->svg = new WPorg_Plugin_Geopattern_SVG();46 $this->svg = new Plugin_Geopattern_SVG(); 41 47 $this->generateBackground(); 42 48 … … 69 75 70 76 // The base SVG class doesn't provide functions for getting dimensions, so.. 71 class WPorg_Plugin_Geopattern_SVG extends \RedeyeVentures\GeoPattern\SVG {77 class Plugin_Geopattern_SVG extends \RedeyeVentures\GeoPattern\SVG { 72 78 73 79 protected $viewbox; … … 89 95 90 96 public function addText( $text, $x, $y, $text_anchor, $style, $args=array() ) { 91 $element = new WPorg_Plugin_Geopattern_SVGText($text, $x, $y, $text_anchor, $style, $args);97 $element = new Plugin_Geopattern_SVGText($text, $x, $y, $text_anchor, $style, $args); 92 98 $this->svgString .= $element; 93 99 return $this; … … 106 112 107 113 // Nor does it support text. 108 class WPorg_Plugin_Geopattern_SVGText extends \RedeyeVentures\GeoPattern\SVGElements\Base {114 class Plugin_Geopattern_SVGText extends \RedeyeVentures\GeoPattern\SVGElements\Base { 109 115 protected $tag = 'text'; 110 116 protected $text; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-template.php
r2561 r2611 1 1 <?php 2 /** 3 * @package WPorg_Plugin_Directory 4 */ 2 namespace WordPressdotorg\Plugin_Directory; 5 3 6 4 /** 7 5 * Various helpers to retrieve data not stored within WordPress. 6 * 7 * @package WordPressdotorg_Plugin_Directory 8 8 */ 9 class WPorg_Plugin_Directory_Template {9 class Template { 10 10 11 11 /** … … 149 149 */ 150 150 static function get_plugin_icon( $plugin, $output = 'raw' ) { 151 global $wporg_plugin_directory; 152 $plugin = $wporg_plugin_directory->get_plugin_post( $plugin ); 151 $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin ); 153 152 if ( ! $plugin ) { 154 153 return false; … … 176 175 if ( ! $icon ) { 177 176 $generated = true; 178 if ( ! class_exists( 'WPorg_Plugin_Geopattern' ) ) { 179 include __DIR__ . '/class-wporg-plugin-geopattern.php'; 180 } 181 $icon = new WPorg_Plugin_Geopattern; 177 178 $icon = new Plugin_Geopattern; 182 179 $icon->setString( $plugin->post_name ); 183 180 … … 218 215 */ 219 216 static function get_plugin_banner( $plugin, $output = 'raw' ) { 220 global $wporg_plugin_directory; 221 $plugin = $wporg_plugin_directory->get_plugin_post( $plugin ); 217 $plugin = Plugin_Directory::instance()->get_plugin_post( $plugin ); 222 218 if ( ! $plugin ) { 223 219 return false; … … 251 247 252 248 static function get_asset_url( $plugin, $asset ) { 249 if ( ! empty( $asset['location'] ) && 'plugin' == $asset['location'] ) { 250 // Screenshots in the plugin folder - /plugins/plugin-name/screenshot-1.png 251 $format = 'https://s.w.org/plugins/%s/%s?rev=%s'; 252 } else { 253 // Images in the assets folder - /plugin-name/assets/screenshot-1.png 254 $format = 'https://ps.w.org/%s/assets/%s?rev=%s'; 255 } 256 253 257 return esc_url( sprintf( 254 'https://ps.w.org/%s/assets/%s?rev=%s',258 $format, 255 259 $plugin, 256 260 $asset['filename'], -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php
r2562 r2611 1 1 <?php 2 /** 3 * @package WPorg_Plugin_Directory 4 */ 2 namespace WordPressdotorg\Plugin_Directory; 5 3 6 4 /** 7 5 * Various functions used by other processes, will make sense to move to specific classes. 6 * 7 * @package WordPressdotorg_Plugin_Directory 8 8 */ 9 class WPorg_Plugin_Directory_Tools {9 class Tools { 10 10 11 11 /** … … 19 19 include_once __DIR__ . '/readme-parser/compat.php'; 20 20 21 $data = (object) WPorg_Readme::parse_readme( $readme );21 $data = (object) \WPorg_Readme::parse_readme( $readme ); 22 22 23 23 unset( $data->sections['screenshots'] ); // Useless. … … 53 53 } 54 54 55 $tonesque = new Tonesque( $file_location );55 $tonesque = new \Tonesque( $file_location ); 56 56 return $tonesque->color(); 57 57 } … … 76 76 */ 77 77 public static function grant_plugin_committer( $plugin_slug, $user ) { 78 global $wpdb , $wporg_plugin_directory;79 if ( ! $user instanceof WP_User ) {80 $user = new WP_User( $user );78 global $wpdb; 79 if ( ! $user instanceof \WP_User ) { 80 $user = new \WP_User( $user ); 81 81 } 82 82 83 if ( ! $user->exists() || ! $wporg_plugin_directory->get_plugin_post( $plugin_slug ) ) {83 if ( ! $user->exists() || ! Plugin_Directory::instance()->get_plugin_post( $plugin_slug ) ) { 84 84 return false; 85 85 } … … 108 108 */ 109 109 public static function revoke_plugin_committer( $plugin_slug, $user ) { 110 global $wpdb , $wporg_plugin_directory;111 if ( ! $user instanceof WP_User ) {112 $user = new WP_User( $user );110 global $wpdb; 111 if ( ! $user instanceof \WP_User ) { 112 $user = new \WP_User( $user ); 113 113 } 114 114 115 if ( ! $user->exists() || ! $wporg_plugin_directory->get_plugin_post( $plugin_slug ) ) {115 if ( ! $user->exists() || ! Plugin_Directory::instance()->get_plugin_post( $plugin_slug ) ) { 116 116 return false; 117 117 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/plugin-directory.php
r2602 r2611 1 1 <?php 2 namespace WordPressdotorg\Plugin_Directory; 2 3 /** 3 4 * Plugin Name: Plugin Directory … … 11 12 * License URI: http://opensource.org/licenses/gpl-2.0.php 12 13 * 13 * @package W Porg_Plugin_Directory14 * @package WordPressdotorg_Plugin_Directory 14 15 */ 15 16 16 include __DIR__ . '/class-wporg-plugin-directory.php'; 17 include __DIR__ . '/class- wporg-plugin-directory-template.php';18 include __DIR__ . '/class-wporg-plugin-directory-tools.php';17 // Register an Autoloader for all files 18 include __DIR__ . '/class-autoloader.php'; 19 Autoloader\register_class_path( __NAMESPACE__, __DIR__ ); 19 20 20 include __DIR__ . '/shortcodes/screenshots.php'; 21 22 if ( is_admin() ) { 23 include __DIR__ . '/admin/class-wporg-plugin-directory-admin-metabox-committers.php'; 24 } 25 26 $wporg_plugin_directory = new WPorg_Plugin_Directory(); 27 register_activation_hook( __FILE__, array( $wporg_plugin_directory, 'activate' ) ); 28 register_deactivation_hook( __FILE__, array( $wporg_plugin_directory, 'deactivate' ) ); 21 // Create the instance of the plugin, passing __FILE__ for actions that need it. 22 include __DIR__ . '/class-plugin-directory.php'; 23 Plugin_Directory::instance( __FILE__ ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php
r2560 r2611 1 1 <?php 2 add_shortcode( 'wporg-plugins-screenshots', 'wporg_plugins_screenshots' ); 2 namespace WordPressdotorg\Plugin_Directory\Shortcodes; 3 use WordPressdotorg\Plugin_Directory\Template; 3 4 4 function wporg_plugins_screenshots() { 5 $plugin = get_post(); 5 /** 6 * The [wporg-plugins-screenshots] shortcode handler to display a plugins screenshots. 7 * 8 * @package WordPressdotorg_Plugin_Directory 9 */ 10 class Screenshots { 11 static function display() { 12 $plugin = get_post(); 6 13 7 // All indexed from 18 $screenshot_descriptions = get_post_meta( $plugin->ID, 'screenshots', true );9 $assets_screenshots = get_post_meta( $plugin->ID, 'assets_screenshots', true );14 // All indexed from 1 15 $screenshot_descriptions = get_post_meta( $plugin->ID, 'screenshots', true ); 16 $assets_screenshots = get_post_meta( $plugin->ID, 'assets_screenshots', true ); 10 17 11 $output = ''; 12 foreach ( $screenshot_descriptions as $index => $description ) { 13 // Find the image that corresponds with the text. 14 // The image numbers are stored within the 'resolution' key. 15 $found = false; 16 foreach ( $assets_screenshots as $image ) { 17 if ( $index == $image['resolution'] ) { 18 $found = true; 19 break; 18 $output = ''; 19 foreach ( $screenshot_descriptions as $index => $description ) { 20 // Find the image that corresponds with the text. 21 // The image numbers are stored within the 'resolution' key. 22 $found = false; 23 foreach ( $assets_screenshots as $image ) { 24 if ( $index == $image['resolution'] ) { 25 $found = true; 26 break; 27 } 20 28 } 21 } 22 if ( ! $found ) { 23 continue; 24 } 29 if ( ! $found ) { 30 continue; 31 } 25 32 26 if ( ! empty( $image['location'] ) && 'plugin' == $image['location'] ) { 27 // Screenshot is within the plugin folder 28 $url = sprintf( 29 'https://s.w.org/plugins/%s/%s?rev=%s', 30 $plugin->post_name, 31 $image['filename'], 32 $image['revision'] 33 ); 34 } else { 35 // In the /assets/ folder 36 $url = sprintf( 37 'https://ps.w.org/%s/assets/%s?rev=%s', 38 $plugin->post_name, 39 $image['filename'], 40 $image['revision'] 33 $url = Template::get_asset_url( $plugin->post_name, $image ); 34 35 $output .= sprintf( 36 '<li> 37 <a href="%1$s" rel="nofollow"> 38 <img class="screenshot" src="%1$s"> 39 </a> 40 <p>%2$s</p> 41 </li>', 42 $url, 43 $description 41 44 ); 42 45 } 43 46 44 $output .= sprintf( 45 '<li> 46 <a href="%1$s" rel="nofollow"> 47 <img class="screenshot" src="%1$s"> 48 </a> 49 <p>%2$s</p> 50 </li>', 51 $url, 52 $description 53 ); 47 return '<ol class="screenshots">' . $output . '</ol>'; 48 54 49 } 55 56 return '<ol class="screenshots">' . $output . '</ol>';57 58 50 }
Note: See TracChangeset
for help on using the changeset viewer.