Changeset 1357067
- Timestamp:
- 02/24/2016 06:51:08 AM (10 years ago)
- Location:
- techxplorers-plugin-listicle
- Files:
-
- 1 added
- 8 edited
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-3.png (added)
-
trunk/README.txt (modified) (1 diff)
-
trunk/admin/class-txp-plugin-listicle-admin.php (modified) (10 diffs)
-
trunk/admin/partials/txp-plugin-listicle-admin-display.php (modified) (3 diffs)
-
trunk/includes/class-txp-plugin-listicle.php (modified) (1 diff)
-
trunk/public/class-txp-plugin-listicle-public.php (modified) (2 diffs)
-
trunk/public/css/txp-plugin-listicle-public.css (modified) (1 diff)
-
trunk/txp-plugin-listicle.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
techxplorers-plugin-listicle/trunk/README.txt
r1352384 r1357067 1 1 === Plugin Name === 2 2 Contributors: techxplorer 3 Tags: shortcode, plugin, credit 3 Tags: shortcode, plugin, credit, post, page 4 4 Requires at least: 4.4.2 5 5 Tested up to: 4.4.2 -
techxplorers-plugin-listicle/trunk/admin/class-txp-plugin-listicle-admin.php
r1352383 r1357067 41 41 42 42 /** 43 * The base template for icon files. 44 * 45 * @since 2.1.0 46 * @access private 47 * @var string $icon_uri_templ The template for icon URIs. 48 */ 49 private $icon_uri_templ = 'http://ps.w.org/%s/assets/icon-128x128.%s'; 50 51 /** 52 * An array of icon file extensions. 53 * 54 * @since 2.1.0 55 * @access private 56 * @var array $icon_uri_exts The file extensions of icon files. 57 */ 58 private $icon_uri_exts = array( 'png', 'jpg', 'svg' ); 59 60 /** 43 61 * Initialize the class and set its properties. 44 62 * 45 63 * @since 2.0.0 46 * @param string $plugin_nameThe name of this plugin.47 * @param string $versionThe version of this plugin.64 * @param string $plugin_name The name of this plugin. 65 * @param string $version The version of this plugin. 48 66 */ 49 67 public function __construct( $plugin_name, $version ) { … … 127 145 128 146 // Link formatting. 129 $valid['nofollow'] = (isset( $input['nofollow'] ) && ! empty( $input['nofollow'] )) ? 1 : 0; 130 $valid['newtab'] = (isset( $input['newtab'] ) && ! empty( $input['newtab'] )) ? 1 : 0; 147 $valid['nofollow'] = ( isset( $input['nofollow'] ) && ! empty( $input['nofollow'] ) ) ? 1 : 0; 148 $valid['newtab'] = ( isset( $input['newtab'] ) && ! empty( $input['newtab'] ) ) ? 1 : 0; 149 150 // Include plugin icons. 151 $valid['icons'] = ( isset( $input['icons'] ) && ! empty( $input['icons'] ) ) ? 1 : 0; 152 153 // Disable plugin CSS. 154 $valid['css'] = ( isset( $input['css'] ) && ! empty( $input['css'] ) ) ? 1 : 0; 131 155 132 156 // Filtered Plugin List. … … 147 171 * Get a list of active plugins 148 172 * 149 * @since 2.0.0 173 * @since 2.0.0 174 * @return array An array containing details of all active plugins. 150 175 */ 151 176 public function get_active_plugins() { … … 178 203 * Generate a link in a safe way taking into account some options 179 204 * 180 * @param string $url The url to link to. 181 * @param string $text The text of the link. 205 * @since 2.0.0 206 * @param string $url The url to link to. 207 * @param string $text The text of the link. 182 208 * @param boolean $nofollow Add the rel="nofollow" attribute. 183 209 * @param boolean $newtab Add the target="_blank" attribute. … … 214 240 215 241 // Build the link. 216 $link = "<a href=\"{$url}\" {$nofollow} {$newtab}>{$text}</a> ";242 $link = "<a href=\"{$url}\" {$nofollow} {$newtab}>{$text}</a>."; 217 243 218 244 // Play it safe. … … 223 249 224 250 /** 251 * Generate the HTML to show a plugin icon 252 * 253 * @since 2.1.0 254 * @param string $plugin_slug The plugin slug to use in the URL to the icon. 255 * @param string $url The url to link to. 256 * @param boolean $nofollow Add the rel="nofollow" attribute. 257 * @param boolean $newtab Add the target="_blank" attribute. 258 * 259 * @return string The HTML to display the icon, or an empty string on failure. 260 */ 261 public function generate_icon_link( $plugin_slug, $url, $nofollow = false, $newtab = false ) { 262 263 // Build a list of allowed tags and attributes. 264 static $allowed = null; 265 266 if ( null === $allowed ) { 267 $allowed = array( 268 'a' => array( 269 'href' => array(), 270 'rel' => array(), 271 'target' => array(), 272 ), 273 'img' => array( 274 'src' => array(), 275 'height' => array(), 276 'width' => array(), 277 ), 278 'span' => array( 279 'class' => array(), 280 ), 281 ); 282 } 283 284 // Before we do anything else, check to see if the URI to the icon can be determined. 285 $uri = $this->confirm_icon_uri( $plugin_slug ); 286 287 if ( empty( $uri ) ) { 288 return ''; 289 } else { 290 // Make URI protocol agnostic. 291 $uri = substr( $uri, 4 ); 292 } 293 294 // Check to see if we need to add the attributes. 295 if ( ! empty( $nofollow ) ) { 296 $nofollow = ' rel="nofollow" '; 297 } else { 298 $nofollow = ' '; 299 } 300 301 if ( ! empty( $newtab ) ) { 302 $newtab = ' target="_blank" '; 303 } else { 304 $newtab = ' '; 305 } 306 307 // Build the img src tag. 308 $img = "<img src=\"{$uri}\" height=\"128px\" width=\"128px\"/>"; 309 310 // Build the link. 311 $link = "<a href=\"{$url}\" {$nofollow} {$newtab}>{$img}</a>"; 312 313 // Finalise the element. 314 $span = "<span class=\"alignleft\">$link</span>"; 315 316 // Play it safe. 317 $span = wp_kses( $span, $allowed ); 318 319 return $span; 320 } 321 322 /** 323 * Determine the plugin icon uri 324 * 325 * @since 2.1.0 326 * @param string $plugin_slug the slug of the plugin. 327 * 328 * @return mixed null|string The uri for the icon, or null if it cannot be found 329 */ 330 public function confirm_icon_uri( $plugin_slug ) { 331 332 // Try each of the support file types. 333 foreach ( $this->icon_uri_exts as $ext ) { 334 $uri = sprintf( $this->icon_uri_templ, $plugin_slug, $ext ); 335 336 $result = wp_remote_head( $uri ); 337 338 // Bail if something really bad happened. 339 if ( is_wp_error( $result ) ) { 340 return null; 341 } else if ( wp_remote_retrieve_response_code( $result ) === 200 ) { 342 return $uri; 343 } 344 } 345 346 return null; 347 } 348 349 /** 225 350 * Build the list of plugins for display 226 351 * 227 * @return The HTML to display the list of links 352 * @since 2.0.0 353 * 354 * @return string The HTML to display the list of links 228 355 */ 229 356 public function build_plugin_list() { … … 238 365 // Get the required information. 239 366 $active_plugins = $this->get_active_plugins(); 240 $options = get_option( $this->plugin_name);367 $options = $this->validate( get_option( $this->plugin_name ) ); 241 368 242 369 if ( isset( $options['nofollow'] ) && ! empty( $options['nofollow'] ) ) { … … 251 378 $newtab = false; 252 379 } 380 381 if ( isset( $options['icons'] ) && ! empty( $options['icons'] ) ) { 382 $icons = true; 383 } else { 384 $icons = false; 385 } 386 253 387 // Build the HTML. 254 $html = "<div class=\"{$this->plugin_name}\">< dl>";388 $html = "<div class=\"{$this->plugin_name}\"><table>"; 255 389 256 390 foreach ( $active_plugins as $plugin ) { … … 275 409 } 276 410 411 $icon_link = ''; 412 413 // Build the icon link. 414 if ( true === $icons && isset( $plugin['PluginURI'] ) ) { 415 $icon_link = $this->generate_icon_link( 416 $plugin['Txp_slug'], 417 $plugin['PluginURI'], 418 $nofollow, 419 $newtab 420 ); 421 } else if ( true === $icons ) { 422 $icon_link = '<!-- No plugin url so no plugin icon -->'; 423 } 424 277 425 // Get the rest of the description. 278 426 $description = wp_kses( $plugin['Description'], array() ); 279 427 280 // Build the HTML snipped. 281 $snippet = "<dt>{$plugin_link}</dt><dd><p>{$description}</p><p>By: {$author_link}</p></dd>"; 282 283 $html .= $snippet; 284 } 285 286 $html .= '</dl></div>'; 287 288 update_option( $this->plugin_name . '_cache', $html ); 428 // Build the table row. 429 $row = '<tr>'; 430 431 if ( true === $icons ) { 432 $row .= '<td class="' . $this->plugin_name . '-icon">' . $icon_link . '</td>'; 433 } 434 435 $row .= '<td class="' . $this->plugin_name . '-descr">'; 436 $row .= "<p>{$plugin_link}</p>"; 437 $row .= "<p>{$description}</p>"; 438 $row .= '<p>' . sprintf( esc_html__( 'By: %s', $this->plugin_name ), $author_link ) . '</p>'; 439 $row .= '</td></tr>'; 440 441 $html .= $row; 442 } 443 444 $html .= '</table></div>'; 445 446 // Do not autoload this option as it can be quite large and we want to play nice. 447 update_option( $this->plugin_name . '_cache', $html, false ); 289 448 290 449 return $html; … … 292 451 293 452 /** 294 * Rebuild the list if plugins, bypassing the cache453 * Delete the option that is being used as a cache of the HTML for the list. 295 454 * 296 455 * @since 2.0.0 -
techxplorers-plugin-listicle/trunk/admin/partials/txp-plugin-listicle-admin-display.php
r1352383 r1357067 27 27 <form method="post" name="<?php esc_html_e( $this->plugin_name, $this->plugin_name ); ?>" action="options.php"> 28 28 <?php settings_fields( $this->plugin_name ); ?> 29 <?php $options = get_option( $this->plugin_name); ?>29 <?php $options = $this->validate( get_option( $this->plugin_name ) ); ?> 30 30 <h2><?php esc_html_e( 'Link format settings', $this->plugin_name ); ?></h2> 31 31 <div class="inside"> … … 54 54 value="1" <?php checked( $options['newtab'], 1 ); ?>/> 55 55 <span><?php esc_html_e( 'Open links in new tab / window.', $this->plugin_name ); ?></span> 56 </label> 57 </fieldset> 58 </li> 59 <li> 60 <!-- Incude plugin icons --> 61 <fieldset> 62 <legend class="screen-reader-text"><span><?php esc_html_e( 'Display plugin icons.', $this->plugin_name ); ?></span></legend> 63 <label for="<?php echo esc_html( $this->plugin_name ); ?>-icons"> 64 <input type="checkbox" 65 id="<?php echo esc_html( $this->plugin_name ); ?>-icons" 66 name="<?php echo esc_html( $this->plugin_name ); ?>[icons]" 67 value="1" <?php checked( $options['icons'], 1 ); ?>/> 68 <span><?php esc_html_e( 'Display plugin icons.', $this->plugin_name ); ?></span> 69 </label> 70 </fieldset> 71 </li> 72 <li> 73 <!-- Disable plugin CSS --> 74 <fieldset> 75 <legend class="screen-reader-text"><span><?php esc_html_e( 'Disable plugin CSS.', $this->plugin_name ); ?></span></legend> 76 <label for="<?php echo esc_html( $this->plugin_name ); ?>-css"> 77 <input type="checkbox" 78 id="<?php echo esc_html( $this->plugin_name ); ?>-css" 79 name="<?php echo esc_html( $this->plugin_name ); ?>[css]" 80 value="1" <?php checked( $options['css'], 1 ); ?>/> 81 <span><?php esc_html_e( 'Disable plugin CSS. You will need to add your own using the customisation functionality of your theme.', $this->plugin_name ); ?></span> 56 82 </label> 57 83 </fieldset> … … 97 123 </div> 98 124 </div> 125 <div class="meta-box-sortables ui-sortable"> 126 <div class="postbox"> 127 <h2><?php esc_html_e( 'Shortcode instructions', $this->plugin_name ); ?></h2> 128 <div class="inside"> 129 <p><?php esc_html_e( 'Use the following shortcode to display the list of active plugins in a post or page.', $this->plugin_name ); ?></p> 130 <pre>[txp-plugin-listicle]</pre> 131 </div> 132 </div> 133 </div> 99 134 </div> 100 135 <!-- Sidebar --> -
techxplorers-plugin-listicle/trunk/includes/class-txp-plugin-listicle.php
r1352383 r1357067 180 180 $plugin_public = new Txp_Plugin_Listicle_Public( $this->get_plugin_name(), $this->get_version() ); 181 181 182 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); 183 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); 182 $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'register_styles' ); 184 183 185 184 $this->loader->add_shortcode( 'txp-plugin-listicle', $plugin_public, 'do_shortcode' ); -
techxplorers-plugin-listicle/trunk/public/class-txp-plugin-listicle-public.php
r1352383 r1357067 99 99 100 100 /** 101 * Register the stylesheet for use by the shortcode if necessary 102 * 103 * @since 2.1.0 104 * 105 * @return void 106 */ 107 public function register_styles() { 108 wp_register_style( 109 $this->plugin_name, 110 plugin_dir_url( __FILE__ ) . 'css/txp-plugin-listicle-public.css', 111 array(), 112 $this->version, 113 'all' 114 ); 115 } 116 117 /** 101 118 * Replace the shortcode with the list of puglins. 102 119 * … … 106 123 // Replace the shortocde with the list of plugins. 107 124 $plugin_list = get_option( $this->plugin_name . '_cache', false ); 125 126 // Get the other plugin options. 127 $options = get_option( $this->plugin_name ); 128 129 // Load the plugin specific public css. 130 if ( isset( $options['css'] ) && empty( $options['css'] ) ) { 131 wp_enqueue_style( $this->plugin_name ); 132 } 108 133 109 134 if ( empty( $plugin_list ) ) { -
techxplorers-plugin-listicle/trunk/public/css/txp-plugin-listicle-public.css
r1352383 r1357067 1 /** 2 * All of the CSS for your public-facing functionality should be 3 * included in this file. 1 /* 2 * Public facing CSS for Techxplorers' Plugin Listicle plugin 4 3 */ 4 .txp-plugin-listicle .txp-plugin-listicle-icon { 5 min-width: 130px; 6 } 7 8 .txp-plugin-listicle tr, 9 .txp-plugin-listicle td, 10 .txp-plugin-listicle table { 11 vertical-align: top; 12 border: 0px; 13 } 14 15 .txp-plugin-listicle .txp-plugin-listicle-descr p:first-of-type { 16 font-size: 1.2em; 17 } -
techxplorers-plugin-listicle/trunk/txp-plugin-listicle.php
r1352383 r1357067 16 16 * Plugin URI: https://techxplorer.com/projects/txp-plugin-listicle 17 17 * Description: Using a shortcode this plugin makes it easy to credit the authors of plugins used on your site. 18 * Version: 2. 0.018 * Version: 2.1.0 19 19 * Author: techxplorer 20 20 * Author URI: https://techxplorer.com
Note: See TracChangeset
for help on using the changeset viewer.