Plugin Directory

Changeset 1688504


Ignore:
Timestamp:
06/30/2017 08:04:04 PM (9 years ago)
Author:
optimality
Message:

Changes towards version 0.5.0

Location:
optimality/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • optimality/trunk/index.php

    r1685786 r1688504  
    55 * Plugin URI:  https://wordpress.org/plugins/optimality
    66 * Description: Optimizes website's content delivery, images, database, permalink structure, search engines and social media markup.
    7  * Version:     0.4.0
     7 * Version:     0.5.0
    88 * License:     GPLv2 or later
    99 * Author:      Optimality
     
    5757            Html::PREDNS    => NULL,
    5858            Html::MINIFY    => NULL,
     59            Html::STATIC    => NULL,
    5960            Style::MINIFY   => NULL,
    6061            Style::CDNLIB   => NULL,
     
    147148        {
    148149            wp_clear_scheduled_hook( __NAMESPACE__ );
    149             Style::cleanCache(); Script::cleanCache();
     150            Style::cleanCache(); Script::cleanCache(); Html::cleanCache();
    150151        });
    151152
     
    153154        add_action(__NAMESPACE__, function()
    154155        {
    155             @$this->option[Site::DBTEMP] && Site::cleanTemp();
    156             @$this->option[Post::DBAUTO] && Post::cleanAuto();
    157             @$this->option[Post::DBEDIT] && Post::cleanEdit();
    158             @$this->option[Post::DBMETA] && Post::cleanMeta();
    159             @$this->option[Term::DBLINK] && Term::cleanLink();
    160             @$this->option[Comment::DBSPAM] && Comment::cleanSpam();
    161             @$this->option[Comment::DBPING] && Comment::cleanPing();
    162             @$this->option[Comment::DBMETA] && Comment::cleanMeta();
     156            isset($this->option[Site::DBTEMP]) && Site::cleanTemp();
     157            isset($this->option[Post::DBAUTO]) && Post::cleanAuto();
     158            isset($this->option[Post::DBEDIT]) && Post::cleanEdit();
     159            isset($this->option[Post::DBMETA]) && Post::cleanMeta();
     160            isset($this->option[Term::DBLINK]) && Term::cleanLink();
     161            isset($this->option[Comment::DBSPAM]) && Comment::cleanSpam();
     162            isset($this->option[Comment::DBPING]) && Comment::cleanPing();
     163            isset($this->option[Comment::DBMETA]) && Comment::cleanMeta();
    163164        });
    164165
    165         if (@$this->option[Image::MINIFY])
     166        if (isset($this->option[Image::MINIFY]))
    166167        {
    167168            add_filter('wp_image_editors', [Image::class, 'mount']);
     
    175176    function __constructFront()
    176177    {
    177         if (@$this->option[Html::UNMETA])
     178        if (isset($this->option[Html::UNMETA]))
    178179        {
    179180            remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
     
    187188        }
    188189
    189         if (@$this->option[Html::UNEMOJ])
     190        if (isset($this->option[Html::UNEMOJ]))
    190191        {
    191192            remove_filter('comment_text_rss' , 'wp_staticize_emoji');
     
    196197        }
    197198
    198         if (@$this->option[Html::PREDNS])
     199        if (isset($this->option[Html::PREDNS]))
    199200        {
    200201            remove_action('wp_head', 'wp_resource_hints', 2);
    201202        }
    202203
    203         if (@$this->option[Section::UNBASE])
     204        if (isset($this->option[Section::UNBASE]))
    204205        {
    205206            add_filter('request'  , [Section::class, 'query'], 10, 1);
     
    207208        }
    208209
    209         if (@$this->option[Comment::UNLINK])
     210        if (isset($this->option[Comment::UNLINK]))
    210211        {
    211212            add_filter('comment_reply_link', [Comment::class, 'route'], 10, 1);
    212213        }
    213214
    214         if (@$this->option[User::UNLINK])
     215        if (isset($this->option[User::UNLINK]))
    215216        {
    216217            add_filter('author_link', [User::class, 'route'], 10, 2);
    217218        }
    218219
    219         if (@$this->option[Media::UNLINK])
     220        if (isset($this->option[Media::UNLINK]))
    220221        {
    221222            add_filter('attachment_link', [Media::class, 'route'], 10, 2);
    222223        }
    223224
    224         if (@$this->option[Image::SRCSET])
     225        if (isset($this->option[Image::SRCSET]))
    225226        {
    226227            remove_filter('the_content', 'wp_make_content_images_responsive');
    227228        }
    228229
    229         if (@$this->option[Style::CDNLIB])
     230        if (isset($this->option[Style::CDNLIB]))
    230231        {
    231232            add_filter('style_loader_src', [Style::class, 'serve'], 10, 2);
    232233        }
    233234
    234         if (@$this->option[Script::MINIFY])
     235        if (isset($this->option[Script::MINIFY]))
    235236        {
    236237            remove_action('comment_form', 'wp_comment_form_unfiltered_html_nonce');
    237238        }
    238239
    239         if (@$this->option[Script::CDNLIB])
     240        if (isset($this->option[Script::CDNLIB]))
    240241        {
    241242            add_filter('script_loader_src', [Script::class, 'serve'], 10, 2);
     
    246247            switch (true)
    247248            {
    248                 case is_admin()     :
    249249                case is_feed()      :
    250250                case is_robots()    : return;
     
    263263            }
    264264
     265            $ishtml = preg_grep(Html::HEADER, headers_list());
     266            $method = strtoupper(@$_SERVER['REQUEST_METHOD']);
     267           
     268            if ($static = isset( $this->option[ Html::STATIC ] ) &&
     269                $ishtml && empty($_REQUEST) && $method === 'GET' &&
     270                !is_user_logged_in() && !defined('DOING_CRON'))
     271            {
     272                Html::serve(@$_SERVER['HTTP_ACCEPT_ENCODING']);
     273            }
     274
    265275            $markup = new $markup(get_queried_object());
    266276
     
    270280            }
    271281
    272             ob_start(function($string) use($markup)
    273             {
    274                 return $markup->build($string, $this->option);
     282            $ishtml && ob_start(function($string) use($markup, $static)
     283            {
     284                return call_user_func(array($markup, $static ?
     285                    'cache' : 'build'), $string, $this->option);
    275286            });
    276287        });
    277288
    278289
    279         @$this->option[Plugin::WIDGET] && add_action('admin_bar_menu', function($widget)
     290        isset($this->option[Plugin::WIDGET]) && add_action('admin_bar_menu', function($widget)
    280291        {
    281292            $this->addWidget($widget,        NULL,   ucwords(__NAMESPACE__    ), $this->urlPlugin());
     
    324335            $this->addOption(Html::PREDNS   , __('Prefetch DNS'         ), $module, 'binary', __('Reduce DNS lookup time by pre-resolving all external domains.'));
    325336            $this->addOption(Html::MINIFY   , __('Optimize HTML'        ), $module, 'binary', __('Remove comments, unnecessary whitespace and empty nodes.'));
     337            $this->addOption(Html::STATIC   , __('Cache HTML'           ), $module, 'binary', __('Cache dynamic HTML content and serve it as static HTML files.'));
     338            $this->addAction(Html::STATIC   , __('Clean HTML Cache'     ), 'trash', [Html::class, 'cleanCache'], [Html::class, 'countCache']);
    326339            $this->addOption(Style::MINIFY  , __('Optimize Styles'      ), $module, 'binary', __('Combine files, flatten imports, remove comments and cache.'));
    327340            $this->addAction(Style::MINIFY  , __('Clean Style Cache'    ), 'trash', [Style::class, 'cleanCache'], [Style::class, 'countCache']);
  • optimality/trunk/markup/html.php

    r1685786 r1688504  
    55class Html extends \DOMDocument
    66{
     7    const HEADER = '/^Content-Type\:\s*text\/html/';
    78    const OGMETA = '/^(og|article|profile):(.+)$/';
    89    const CUSTOM = 'html_custom';
     
    1112    const PREDNS = 'html_predns';
    1213    const MINIFY = 'html_minify';
     14    const STATIC = 'html_static';
    1315    const CDNURL = 'html_cdnurl';
    1416    const SEMETA = 'html_semeta';
     
    1921    const SMDESC = 'html_smdesc';
    2022
     23    public $proto;
    2124    public $root;
    2225    public $head;
    2326    public $body;
    2427    public $meta = [];
    25     public $type;
    2628    public $ruid;
    2729    public $slug;
     
    3537    public $user;
    3638    public $site;
    37     public $attr;
    38     public $file;
     39    public $text;
     40    public $path;
    3941
    4042
    4143    function __construct($object)
    4244    {
    43         $this->type = 'CreativeWork';
     45        $this->proto = $object;
    4446    }
    4547
     
    5456        }
    5557
    56         $this->attr = array
     58        $this->text = array
    5759        (
    5860            ':name'        => $this->name,
     
    6769        );
    6870
    69         $this->file = array
     71        $this->path = array
    7072        (
    7173            __CDNURL__ => $option[static::CDNURL],
     
    120122        (
    121123            'twitter:card'        => 'summary_large_image',
    122             'twitter:title'       => ucfirst(strtr(@$option[static::SMNAME], $this->attr)),
    123             'twitter:description' => ucfirst(strtr(@$option[static::SMDESC], $this->attr)),
    124             'twitter:image'       => strtr($this->image ?: $this->site->image, $this->file),
     124            'twitter:title'       => ucfirst(strtr(@$option[static::SMNAME], $this->text)),
     125            'twitter:description' => ucfirst(strtr(@$option[static::SMDESC], $this->text)),
     126            'twitter:image'       => strtr($this->image ?: $this->site->image, $this->path),
    125127            'twitter:creator'     => $this->user ? $this->user->twit : NULL,
    126128            'twitter:site'        => $this->site ? $this->site->twit : NULL,
    127129
    128130            'og:type'             => 'website',
    129             'og:title'            => ucfirst(strtr(@$option[static::SMNAME], $this->attr)),
    130             'og:description'      => ucfirst(strtr(@$option[static::SMDESC], $this->attr)),
    131             'og:image'            => strtr($this->image ?: $this->site->image, $this->file),
     131            'og:title'            => ucfirst(strtr(@$option[static::SMNAME], $this->text)),
     132            'og:description'      => ucfirst(strtr(@$option[static::SMDESC], $this->text)),
     133            'og:image'            => strtr($this->image ?: $this->site->image, $this->path),
    132134            'og:url'              => $this->route,
    133135            'og:locale'           => $this->site->lang,
     
    154156        (
    155157            '@context'            => 'http://schema.org',
    156             '@type'               => $this->type,
    157             'name'                => ucfirst(strtr(@$option[static::SENAME], $this->attr)),
    158             'description'         => ucfirst(strtr(@$option[static::SEDESC], $this->attr)),
    159             'image'               => strtr($this->image ?: $this->site->image, $this->file),
     158            '@type'               => 'Thing',
     159            'name'                => ucfirst(strtr(@$option[static::SENAME], $this->text)),
     160            'description'         => ucfirst(strtr(@$option[static::SEDESC], $this->text)),
     161            'image'               => strtr($this->image ?: $this->site->image, $this->path),
    160162            'url'                 => $this->route,
    161             'author'              => $this->user ? $this->user->goog : NULL,
    162             'publisher'           => $this->site ? $this->site->goog : NULL,
    163             'datePublished'       => $this->date,
    164             'dateModified'        => $this->edit,
     163
     164            //'author'              => $this->user ? $this->user->goog : NULL,
     165            //'publisher'           => $this->site ? $this->site->goog : NULL,
     166            //'datePublished'       => $this->date,
     167            //'dateModified'        => $this->edit,
    165168        );
    166169    }
     
    215218    function build($string, $option)
    216219    {
    217         $this->preserveWhiteSpace = empty(@$option[static::MINIFY]);
    218         @$this->loadHTML($string , LIBXML_COMPACT|LIBXML_NOBLANKS);
     220        $this->preserveWhiteSpace = !isset($option[static::MINIFY]);
     221        @$this->loadHTML($string, LIBXML_COMPACT | LIBXML_NOBLANKS);
    219222
    220223        $schema = new \DOMXPath($this); $linked = [ ];
     
    230233        }
    231234
    232         if ($object = @$this->meta['viewport'])
    233         {
    234             $values = preg_split('/\s*,\s*/', $object->getAttribute( 'content' ));
    235             $values = array_diff($values, ['maximum-scale=1.0', 'user-scalable=0']);
    236             $object->setAttribute('content', implode(', ', $values));
    237         }
    238 
    239235        if ($source = @$option[static::CUSTOM])
    240236        {
     
    245241        // SEO
    246242
    247         if (@$option[static::SEMETA])
     243        if (isset($option[static::SEMETA]))
    248244        {
    249245            if (!($object = @$schema->query('/html/head/title[1]')[0]))
     
    253249            }
    254250
    255             $object->nodeValue = ucfirst(strtr(@$option[static::SENAME], $this->attr));
    256 
    257             $this->setMeta('description', ucfirst(strtr(@$option[static::SEDESC], $this->attr)));
     251            $object->nodeValue = ucfirst(strtr(@$option[static::SENAME], $this->text));
     252
     253            $this->setMeta('description', ucfirst(strtr(@$option[static::SEDESC], $this->text)));
    258254            $this->addJson(array_filter($this->getJson($option)), 'application/ld+json');
    259255        }
     
    261257        // SMO
    262258
    263         if (@$option[static::SMMETA])
     259        if (isset($option[static::SMMETA]))
    264260        {
    265261            $this->root->setAttribute('prefix', 'og: http://ogp.me/ns#');
     
    273269        // DNS
    274270
    275         if (@$option[static::PREDNS])
     271        if (isset($option[static::PREDNS]))
    276272        {
    277273            $filter = '//link[@rel="stylesheet"]|//script[@src]|/html/body//img[@src]';
     
    294290        // CSS
    295291
    296         if (@$option[Style::MINIFY])
     292        if (isset($option[Style::MINIFY]))
    297293        {
    298294            $bundle = new Style();
     
    361357        // JS
    362358
    363         if (@$option[Script::MINIFY])
     359        if (isset($option[Script::MINIFY]))
    364360        {
    365361            $bundle = new Script();
     
    417413        // IMG
    418414
    419         if (@$option[Image::SRCSET])
     415        if (isset($option[Image::SRCSET]))
    420416        {
    421417            $cdndir = wp_parse_url(__CDNURL__, PHP_URL_PATH);
     
    442438        // DOM
    443439
    444         if (@$option[static::MINIFY])
    445         {
     440        if (isset($option[static::MINIFY]))
     441        {
     442            if ($object = @$this->meta['viewport'])
     443            {
     444                $values = preg_split('/\s*,\s*/', $object->getAttribute( 'content' ));
     445                $values = array_diff($values, ['maximum-scale=1.0', 'user-scalable=0']);
     446                $object->setAttribute('content', implode(', ', $values));
     447            }
     448
    446449            foreach ($schema->query('//comment()') as $object)
    447450            {
     
    457460        }
    458461
    459         count($linked) && header('Link: '. implode(',', $linked));
     462        count($linked) && header('Link: ' . implode(',', $linked));
    460463        return $string;
    461464    }
    462465
    463466
     467    function cache($string, $option)
     468    {
     469        if ($string = $this->build($string, $option))
     470        {
     471            $handle = sprintf('~%s.html', md5(__TARGET__));
     472
     473            file_put_contents($target = __CDNDIR__ . $handle, $string);
     474            file_put_contents($target . '.gz' , gzencode($string , 9));
     475        }
     476
     477        return $string;
     478    }
     479
     480
     481    static function serve($accept)
     482    {
     483        $source = sprintf(__CDNDIR__ . '~%s.html', md5( __TARGET__ ));
     484
     485        if ($encode = $accept && (strpos($accept, 'gzip') !== false))
     486        {
     487            $source .= '.gz';
     488        }
     489
     490        if (file_exists($source) && time() - filemtime($source) < 600)
     491        {
     492            header('Vary: Accept-Encoding, Cookie');
     493            $encode && header('Content-Encoding: gzip');
     494            @readfile($source) && exit();
     495        }
     496    }
     497
     498
    464499    static function encap($result)
    465500    {
     
    470505        }, $result ?: [ ]);
    471506    }
     507
     508
     509    // ACTIONS
     510
     511    static function countCache()
     512    {
     513        return count(glob(__CDNDIR__ . '~*.{html}', GLOB_BRACE));
     514    }
     515
     516
     517    static function cleanCache()
     518    {
     519        return count(array_filter(glob(__CDNDIR__ . '~*.{html,html.gz}', GLOB_BRACE), 'unlink')) / 2;
     520    }
    472521}
    473522
  • optimality/trunk/markup/media.php

    r1683276 r1688504  
    1818        parent::__construct($object);
    1919
    20         $this->type  = 'ImageObject';
    2120        $this->ruid  = $object->ID;
    2221        $this->slug  = $object->post_name;
     
    2928        $this->edit  = date(DATE_W3C, strtotime($object->post_modified));
    3029        $this->user  = $object->post_author;
     30    }
     31
     32
     33    function getJson($option)
     34    {
     35        return array_merge(parent::getJson($option),
     36        [
     37            '@type'                  => 'ImageObject',
     38            'headline'               => $this->name,
     39            'caption'                => $this->lead,
     40            'datePublished'          => $this->date,
     41            'dateModified'           => $this->edit,
     42            'author'                 => $this->user->goog,
     43            'publisher'              => $this->site->goog,
     44        ]);
    3145    }
    3246
  • optimality/trunk/markup/page.php

    r1685786 r1688504  
    1919        parent::__construct($object);
    2020
    21         $this->type  = 'WebPage';
    2221        $this->ruid  = $object->ID;
    2322        $this->slug  = $object->post_name;
     
    3534    function __invoke($target, $option)
    3635    {
    37         if (@$option[static::SEMETA])
     36        if (isset($option[static::SEMETA]))
    3837        {
    3938            add_filter('post_class', function($vector)
     
    4342        }
    4443
    45         if (@$option[Comment::UNLINK])
     44        if (isset($option[Comment::UNLINK]))
    4645        {
    4746            if ($source = @$_GET['replytocom'])
     
    5150        }
    5251
    53         if (@$option[Comment::UNPAGE])
     52        if (isset($option[Comment::UNPAGE]))
    5453        {
    5554            if (get_query_var('cpage'))
     
    7675
    7776
     77    function getJson($option)
     78    {
     79        return array_merge(parent::getJson($option),
     80        [
     81            '@type'                  => 'WebPage',
     82            'headline'               => $this->name,
     83            'datePublished'          => $this->date,
     84            'dateModified'           => $this->edit,
     85            'commentCount'           => $this->notes,
     86            'author'                 => $this->user->goog,
     87            'publisher'              => $this->site->goog,
     88        ]);
     89    }
     90
     91
    7892    static function fetch()
    7993    {
  • optimality/trunk/markup/post.php

    r1685786 r1688504  
    1515    const SMDESC = 'post_smdesc';
    1616
    17     public $section;
    18     public $terms = [];
    19 
    2017
    2118    function __construct($object)
    2219    {
    2320        parent::__construct($object);
    24 
    25         $this->type  = 'Article';
    2621    }
    2722
    2823
    29     function __invoke($target, $option)
     24    function getMeta($option)
    3025    {
    31         if (is_array($result = get_the_terms($this->ruid, 'category')))
    32         {
    33             $this->section = @$result[0]->name;
    34         }
     26        $object = get_the_terms($this->proto, 'category');
    3527
    36         if (is_array($result = get_the_terms($this->ruid, 'post_tag')))
    37         {
    38             foreach ($result as $object) $this->terms[] = $object->name;
    39         }
     28        return array_merge(parent::getMeta($option),
     29        [
     30            'article:section' => empty($object) ? NULL : $object[0]->name,
     31            'article:tag'     => array_map(function($object)
     32            {
     33                return $object->name;
    4034
    41         return parent::__invoke($target, $option);
     35            }, get_the_terms($this->proto, 'post_tag') ?: []),
     36        ]);
    4237    }
    4338
     
    4540    function getJson($option)
    4641    {
     42        $object = get_the_terms($this->proto, 'category');
     43
    4744        return array_merge(parent::getJson($option),
    4845        [
    49             'headline'               => $this->name,
    50             'articleSection'         => $this->section,
    51             'keywords'               => implode(',' , $this->terms),
    52             'commentCount'           => $this->notes,
    53         ]);
    54     }
     46            '@type'           => 'Article',
     47            'articleSection'  => empty($object) ? NULL : $object[0]->name,
     48            'keywords'        => implode(',', array_map(function($object)
     49            {
     50                return $object->name;
    5551
    56 
    57     function getMeta($option)
    58     {
    59         return array_merge(parent::getMeta($option),
    60         [
    61             'article:section'        => $this->section,
    62             'article:tag'            => $this->terms,
     52            }, get_the_terms($this->proto, 'post_tag') ?: [])),
    6353        ]);
    6454    }
  • optimality/trunk/markup/section.php

    r1685786 r1688504  
    2222    function __invoke($target, $option)
    2323    {
    24         if ($option[static::UNBASE])
     24        if (isset($option[static::UNBASE]))
    2525        {
    2626            if (strpos($target, $this->route) !== 0)
  • optimality/trunk/markup/site.php

    r1683276 r1688504  
    2323        parent::__construct($object);
    2424
    25         $this->type  = 'WebSite';
    2625        $this->ruid  = NULL;
    2726        $this->name  = get_bloginfo('name');
     
    3433        $this->twit  = get_option('twitter');
    3534        $this->site  = $this;
     35    }
     36
     37
     38    function getJson($option)
     39    {
     40        return array_merge(parent::getJson($option),
     41        [
     42            '@type'     => 'WebSite',
     43            'publisher' => $this->goog,
     44        ]);
    3645    }
    3746
  • optimality/trunk/markup/sitemap.php

    r1685786 r1688504  
    1010
    1111    public $root;
    12     public $file;
     12    public $path;
     13
     14
     15    function __invoke($target, $option)
     16    {
     17        $this->path = array
     18        (
     19            __CDNURL__  => $option[Html::CDNURL],
     20        );
     21    }
    1322
    1423
     
    3443
    3544            $source = $this->createElement('image:loc');
    36             $source->nodeValue = strtr($entity->image, $this->file);
     45            $source->nodeValue = strtr($entity->image, $this->path);
    3746            $branch->appendChild($source);
    3847
     
    4958
    5059
    51     function __invoke($target, $option)
    52     {
    53         $this->file = array
    54         (
    55             __CDNURL__  => $option[Html::CDNURL],
    56         );
    57     }
    58 
    59 
    6060    function build($string, $option)
    6161    {
     
    6666        $this->root->setAttribute('xmlns:image', 'http://www.google.com/schemas/sitemap-image/1.1');
    6767
    68         if (@$option[Site::SEMETA])
     68        if (isset($option[Site::SEMETA]))
    6969        {
    7070            array_map([$this, 'addNode'], Site::fetch());
    7171        }
    7272
    73         if (@$option[Page::SEMETA])
     73        if (isset($option[Page::SEMETA]))
    7474        {
    7575            array_map([$this, 'addNode'], Page::fetch());
    7676        }
    7777
    78         if (@$option[Post::SEMETA])
     78        if (isset($option[Post::SEMETA]))
    7979        {
    8080            array_map([$this, 'addNode'], Post::fetch());
    8181        }
    8282
    83         if (@$option[Section::SEMETA])
     83        if (isset($option[Section::SEMETA]))
    8484        {
    8585            array_map([$this, 'addNode'], Section::fetch());
    8686        }
    8787
    88         if (@$option[Term::SEMETA])
     88        if (isset($option[Term::SEMETA]))
    8989        {
    9090            array_map([$this, 'addNode'], Term::fetch());
    9191        }
    9292
    93         if (@$option[User::SEMETA] && !@$option[User::UNLINK])
     93        if (isset($option[User::SEMETA]) && !isset($option[User::UNLINK]))
    9494        {
    9595            array_map([$this, 'addNode'], User::fetch());
    9696        }
    9797
    98         if (@$option[Media::SEMETA] && !@$option[Media::UNLINK])
     98        if (isset($option[Media::SEMETA]) && !isset($option[Media::UNLINK]))
    9999        {
    100100            array_map([$this, 'addNode'], Media::fetch());
  • optimality/trunk/markup/term.php

    r1685794 r1688504  
    1313    const SMDESC = 'term_smdesc';
    1414
    15     public $items;
     15    public $posts;
    1616
    1717
     
    2020        parent::__construct($object);
    2121
    22         $this->type  = 'ItemList';
    2322        $this->ruid  = $object->term_id;
    2423        $this->slug  = $object->slug;
     
    2625        $this->desc  = $object->description;
    2726        $this->route = get_term_link($object);
    28         $this->items = [ ];
    29     }
    30 
    31 
    32     function __invoke($target, $option)
    33     {
    34         foreach (@$GLOBALS['wp_query']->posts ?: [] as $offset => $object)
    35         {
    36             $this->items[] = array
    37             (
    38                 '@type'    => 'ListItem',
    39                 'position' => $offset + 1,
    40                 'url'      => get_permalink($object),
    41             );
    42         }
    43 
    44         return parent::__invoke($target, $option);
     27        $this->posts = @$GLOBALS['wp_query']->posts ?: [];
    4528    }
    4629
     
    4831    function getJson($option)
    4932    {
     33        $offset = 0;
     34
    5035        return array_merge(parent::getJson($option),
    5136        [
    52             'publisher'       => NULL,
    53             'author'          => NULL,
    54             'numberOfItems'   => count($this->items),
    55             'itemListElement' => $this->items,
     37            '@type'              => 'ItemList',
     38            'numberOfItems'      => count($this->posts),
     39            'itemListElement'    => array_map(function($object) use(&$offset)
     40            {
     41                return
     42                [
     43                    '@type'      => 'ListItem',
     44                    'position'   => ++$offset,
     45                    'url'        => get_permalink($object)
     46                ];
     47
     48            }, $this->posts),
    5649        ]);
    5750    }
  • optimality/trunk/markup/user.php

    r1685786 r1688504  
    2424        parent::__construct($object);
    2525
    26         $this->type  = 'Person';
    2726        $this->ruid  = $object->ID;
    2827        $this->slug  = $object->data->user_nicename;
     
    4645    function __invoke($target, $option)
    4746    {
    48         if (@$option[static::UNLINK])
     47        if (isset($option[static::UNLINK]))
    4948        {
    5049            return static::route($target, NULL);
     
    5251
    5352        return parent::__invoke($target, $option);
    54     }
    55 
    56 
    57     function getJson($option)
    58     {
    59         return array_merge(parent::getJson($option),
    60         [
    61             'givenName'          => $this->fname,
    62             'familyName'         => $this->lname,
    63         ]);
    6453    }
    6554
     
    7968
    8069
     70    function getJson($option)
     71    {
     72        return array_merge(parent::getJson($option),
     73        [
     74            '@type'              => 'Person',
     75            'givenName'          => $this->fname,
     76            'familyName'         => $this->lname,
     77        ]);
     78    }
     79
     80
    8181    static function route($origin, $userid)
    8282    {
  • optimality/trunk/readme.txt

    r1685786 r1688504  
    2020* Reduces DNS lookup time by pre-resolving all external domains.
    2121* Removes comments, unnecessary whitespace and empty nodes from HTML.
    22 * Combines stylesheets, flattens imports, removes comments and caches.
     22* Caches dynamic HTML content and serves it as static HTML files.
     23* Combines CSS files, flattens imports, removes comments and caches.
    2324* Serves popular CSS libraries from content delivery networks.
    24 * Combines scripts, defers loading, removes comments and caches.
     25* Combines JS files, defers loading, removes comments and caches.
    2526* Serves popular JS libraries from content delivery networks.
    2627* Strips metadata and compresses thumbnail images (requires ImageMagick).
     
    7778== Changelog ==
    7879
     80= 0.5.0 =
     81* Feature: HTML cache
     82* Feature: Schema markup fine-tunning
     83* Feature: Code fine-tuning for faster processing
     84* Bug Fix: Process only 'text/html' responses
     85
    7986= 0.4.0 =
    8087* Feature: ItemList schema instead CollectionPage for taxonomies
Note: See TracChangeset for help on using the changeset viewer.