Making WordPress.org


Ignore:
Timestamp:
02/25/2016 10:49:24 PM (10 years ago)
Author:
obenland
Message:

Plugins Directory: Formatting update.

  • Updates phpdocs throughout the plugin.
  • Breaks out classes into their own files.
  • Some minor namespace-related tweaks.

See #1584.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-geopattern.php

    r2611 r2621  
    77 * Generates Geopattern icons for Plugins.
    88 *
    9  * @package WordPressdotorg_Plugin_Directory
     9 * @package WordPressdotorg\Plugin_Directory
    1010 */
    1111class Plugin_Geopattern extends \RedeyeVentures\GeoPattern\GeoPattern {
    1212
    13         var $slug; // Hashed to generate pattern
    14         var $text; // Text to be overlaid
    15         var $textcolor = 'black';
     13        /**
     14         * Hashed to generate pattern.
     15         *
     16         * @var string
     17         */
     18        public $slug;
    1619
    17         function __construct($options=array()) {
     20        /**
     21         * Text to be overlaid.
     22         *
     23         * @var string
     24         */
     25        public $text;
     26
     27        /**
     28         * @var string
     29         */
     30        public $textcolor = 'black';
     31
     32        /**
     33         * @param array $options
     34         */
     35        function __construct( $options = array() ) {
    1836                parent::__construct( $options );
    1937
    20                 if ( isset( $options['text'] ) )
     38                if ( isset( $options['text'] ) ) {
    2139                        $this->text = $options['text'];
     40                }
    2241
    23                 if ( isset( $options['textcolor'] ) )
     42                if ( isset( $options['textcolor'] ) ) {
    2443                        $this->textcolor = $options['textcolor'];
     44                }
    2545
    2646                // Replace the base SVG object with our own, so the dimensions are gettable.
     
    2848        }
    2949
     50        /**
     51         * @param $text
     52         */
    3053        function setText( $text ) {
    3154                $this->text = $text;
    3255        }
    3356
     57        /**
     58         * @param $color
     59         */
    3460        function setTextColor( $color ) {
    3561                $this->textcolor = $color;
    3662        }
    3763
     64        /**
     65         *
     66         */
    3867        function generateText() {
    39                 $size = min( $this->svg->getHeight(), $this->svg->getWidth() );
     68                $size        = min( $this->svg->getHeight(), $this->svg->getWidth() );
    4069                $text_height = floor( $size * 0.8 ) . 'px';
    4170
     
    4372        }
    4473
     74        /**
     75         * @param int $width
     76         * @param int $height
     77         * @return string
     78         */
    4579        public function toSVG( $width = 128, $height = 128 ) {
    4680                $this->svg = new Plugin_Geopattern_SVG();
    4781                $this->generateBackground();
    4882
    49                 // Work around a bug in 1.1.0: the hash-based pattern selection doesn't account for the size of the pattern array and can choose a null result.
    50                 $this->setGenerator( $this->patterns[$this->hexVal(20, 1) % count( $this->patterns )] );
     83                /*
     84                 * Work around a bug in 1.1.0:
     85                 * The hash-based pattern selection doesn't account for the size of the
     86                 * pattern array and can choose a null result.
     87                 */
     88                $this->setGenerator( $this->patterns[ $this->hexVal( 20, 1 ) % count( $this->patterns ) ] );
    5189
    5290                $this->generatePattern();
     
    5997                        $inner = $this->svg;
    6098
    61                         // Outer SVG, containing the text and nested inner SVG.
    62                         // Needed because of aspect ratio problems with the background pattern. The outer is square, inner may be a different shape.
     99                        /*
     100                         * Outer SVG, containing the text and nested inner SVG.
     101                         *
     102                         * Needed because of aspect ratio problems with the background pattern.
     103                         * The outer is square, inner may be a different shape.
     104                         */
    63105                        $this->svg = new PluginSVG();
    64106                        $this->svg->setWidth( $width );
     
    69111
    70112                return $this->svg->getString();
    71 
    72     }
    73 
    74 }
    75 
    76 // The base SVG class doesn't provide functions for getting dimensions, so..
    77 class Plugin_Geopattern_SVG extends \RedeyeVentures\GeoPattern\SVG {
    78 
    79         protected $viewbox;
    80 
    81         function getWidth() {
    82                 return $this->width;
    83         }
    84 
    85         function getHeight() {
    86                 return $this->height;
    87         }
    88 
    89     protected function getSvgHeader() {
    90                 if ( $this->viewbox )
    91                         return "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"{$this->width}\" height=\"{$this->height}\" viewbox=\"{$this->viewbox}\" preserveAspectRatio=\"none\">";
    92                 else
    93                         return "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"{$this->width}\" height=\"{$this->height}\">";
    94     }
    95 
    96     public function addText( $text, $x, $y, $text_anchor, $style, $args=array() ) {
    97         $element = new Plugin_Geopattern_SVGText($text, $x, $y, $text_anchor, $style, $args);
    98         $this->svgString .= $element;
    99         return $this;
    100         }
    101 
    102         public function addNested( $svg ) {
    103                 if ( method_exists( $svg, 'getString' ) )
    104                         $this->svgString .= $svg->getString();
    105         }
    106 
    107         public function setViewBox( $x, $y, $w, $h ) {
    108                 $this->viewbox = esc_attr( "$x $y $w $h" );
    109         }
    110 
    111 }
    112 
    113 // Nor does it support text.
    114 class Plugin_Geopattern_SVGText extends \RedeyeVentures\GeoPattern\SVGElements\Base {
    115         protected $tag = 'text';
    116         protected $text;
    117 
    118         function __construct($text, $x, $y, $text_anchor, $style, $args=array()) {
    119                 $this->elements = array(
    120                         'x' => $x,
    121                         'y' => $y,
    122                         'text-anchor' => $text_anchor,
    123                         'style' => $style,
    124                         );
    125                 $this->text = esc_html( $text );
    126                 parent::__construct($args);
    127         }
    128 
    129         public function getString() {
    130                 return "<{$this->tag}{$this->elementsToString()}{$this->argsToString()}>{$this->text}</{$this->tag}>";
    131113        }
    132114}
    133 
Note: See TracChangeset for help on using the changeset viewer.