Plugin Directory

Changeset 1684796


Ignore:
Timestamp:
06/24/2017 04:46:22 PM (9 years ago)
Author:
optimality
Message:

New features towards 0.3.0

Location:
optimality/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • optimality/trunk/index.php

    r1683276 r1684796  
    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.2.0
     7 * Version:     0.3.0
    88 * License:     GPLv2 or later
    99 * Author:      Optimality
     
    3333class Plugin
    3434{
     35    const WIDGET = 'widget';
     36
    3537    protected $preset;
    3638    protected $option;
     
    4850        $this->option = array_merge($this->preset =
    4951        [
     52            Html::CUSTOM    => NULL,
     53            Plugin::WIDGET  => 'on',
     54
    5055            Html::UNMETA    => NULL,
    5156            Html::UNEMOJ    => NULL,
    5257            Html::PREDNS    => NULL,
    5358            Html::MINIFY    => NULL,
    54             Html::CUSTOM    => NULL,
    5559            Style::MINIFY   => NULL,
    5660            Style::CDNLIB   => NULL,
     
    7276            Section::UNBASE => NULL,
    7377            Comment::UNLINK => NULL,
     78            Comment::UNPAGE => NULL,
    7479            User::UNLINK    => NULL,
    7580            Media::UNLINK   => NULL,
     
    272277
    273278
    274         add_action('admin_bar_menu', function($widget)
     279        @$this->option[Plugin::WIDGET] && add_action('admin_bar_menu', function($widget)
    275280        {
    276281            $this->addWidget($widget,        NULL,   ucwords(__NAMESPACE__    ), $this->urlPlugin());
     
    310315            register_setting(__NAMESPACE__, __NAMESPACE__, array( $this, 'onSubmit' ));
    311316
     317            $this->addModule($module = 'gen', __('General Settings'     ));
     318            $this->addOption(Html::CUSTOM   , __('Custom HTML'          ), $module, 'editor', __('This code will be injected into the head section of every HTML page.'));
     319            $this->addOption(Plugin::WIDGET , __('Admin Bar Menu'       ), $module, 'binary', __('Display a menu on the Admin Bar when browsing as admin.'));
     320
    312321            $this->addModule($module = 'cdo', __('Content Delivery'     ));
    313322            $this->addOption(Html::UNMETA   , __('Clean Meta Tags'      ), $module, 'binary', __('Remove unnecessary meta tags from the head section of HTML.'));
     
    315324            $this->addOption(Html::PREDNS   , __('Prefetch DNS'         ), $module, 'binary', __('Reduce DNS lookup time by pre-resolving all external domains.'));
    316325            $this->addOption(Html::MINIFY   , __('Optimize HTML'        ), $module, 'binary', __('Remove comments, unnecessary whitespace and empty nodes.'));
    317             $this->addOption(Html::CUSTOM   , __('Custom HTML'          ), $module, 'editor', __('This code will be injected into the head section of every HTML page.'));
    318326            $this->addOption(Style::MINIFY  , __('Optimize Styles'      ), $module, 'binary', __('Combine files, flatten imports, remove comments and cache.'));
    319327            $this->addAction(Style::MINIFY  , __('Clean Style Cache'    ), 'trash', [Style::class, 'cleanCache'], [Style::class, 'countCache']);
     
    350358            $this->addOption(Media::UNLINK  , __('Disable Attachments'  ), $module, 'binary', __('Redirect image attachment pages to the URL of the parent page.'));
    351359            $this->addOption(Comment::UNLINK, __('Disable Reply Queries'), $module, 'binary', __('Redirect ?replytocom=id to #comment-id in comment replies.'));
     360            $this->addOption(Comment::UNPAGE, __('Depaginate Comments'  ), $module, 'binary', __('Redirect paginated comments to the URL of the parent page.'));
    352361
    353362            $this->addModule($module = 'seo', __('Search Engines'       ));
  • optimality/trunk/markup/comment.php

    r1683276 r1684796  
    99    const DBMETA = 'comment_dbmeta';
    1010    const UNLINK = 'comment_unlink';
     11    const UNPAGE = 'comment_unpage';
    1112    const SEMETA = 'comment_semeta';
    1213    const SENAME = 'comment_sename';
  • optimality/trunk/markup/page.php

    r1683276 r1684796  
    1111    const SMNAME = 'page_smname';
    1212    const SMDESC = 'page_smdesc';
     13
     14    public $notes;
    1315
    1416
     
    2729        $this->edit  = date(DATE_W3C, strtotime($object->post_modified));
    2830        $this->user  = $object->post_author;
     31        $this->notes = intval($object->comment_count);
    2932    }
    3033
     
    4346
    4447
     48    function apply($target, $option)
     49    {
     50        if (@$option[Comment::UNLINK])
     51        {
     52            if ($source = @$_GET['replytocom'])
     53            {
     54                return Comment::route(NULL, $source);
     55            }
     56        }
     57
     58        if (@$option[Comment::UNPAGE])
     59        {
     60            if (get_query_var('cpage'))
     61            {
     62                return $this->route;
     63            }
     64        }
     65
     66        return parent::apply($target, $option);
     67    }
     68
     69
    4570    static function fetch()
    4671    {
  • optimality/trunk/markup/post.php

    r1683276 r1684796  
    33namespace optimality;
    44
    5 class Post extends Html
     5class Post extends Page
    66{
    77    const DBAUTO = 'post_dbauto';
     
    1717    public $section;
    1818    public $terms = [];
    19     public $notes;
    2019
    2120
     
    2524
    2625        $this->type  = 'Article';
    27         $this->ruid  = $object->ID;
    28         $this->slug  = $object->post_name;
    29         $this->name  = $object->post_title;
    30         $this->lead  = $object->post_excerpt;
    31         $this->image = get_the_post_thumbnail_url($object, 'full');
    32         $this->route = get_page_link($object);
    33         $this->date  = date(DATE_W3C, strtotime($object->post_date));
    34         $this->edit  = date(DATE_W3C, strtotime($object->post_modified));
    35         $this->user  = $object->post_author;
    36         $this->notes = intval($object->comment_count);
    3726    }
    3827
     
    5443        return array_merge(parent::getMeta($option),
    5544        [
    56             'og:type'                => 'article',
    57             'article:published_time' => $this->date,
    58             'article:modified_time'  => $this->edit,
    59             'article:author'         => $this->user->face,
    60             'article:publisher'      => $this->site->face,
    6145            'article:section'        => $this->section,
    6246            'article:tag'            => $this->terms,
     
    6751    function apply($target, $option)
    6852    {
    69         if (@$option[Comment::UNLINK])
    70         {
    71             if ($source = @$_GET['replytocom'])
    72             {
    73                 return Comment::route(NULL, $source);
    74             }
    75         }
    76 
    7753        if (is_array($result = get_the_terms($this->ruid, 'category')))
    7854        {
  • optimality/trunk/markup/script.php

    r1683276 r1684796  
    3030    ];
    3131
    32     static $export =
     32    static $hoster =
    3333    [
     34        'backbone'       => 'https://cdnjs.cloudflare.com/ajax/libs/backbone.js/%s/backbone-min.js',
     35        'bootstrap'      => 'https://maxcdn.bootstrapcdn.com/bootstrap/%s/js/bootstrap.min.js',
     36        'device'         => 'https://cdnjs.cloudflare.com/ajax/libs/device.js/0.2.7/device.min.js',
     37        'hoverIntent'    => 'https://cdnjs.cloudflare.com/ajax/libs/jquery.hoverintent/%s/jquery.hoverIntent.min.js',
     38        'jquery-color'   => 'https://cdnjs.cloudflare.com/ajax/libs/jquery-color/%s/jquery.color.min.js',
    3439        'jquery-core'    => 'https://cdnjs.cloudflare.com/ajax/libs/jquery/%s/jquery.min.js',
     40        'jquery-form'    => 'https://cdnjs.cloudflare.com/ajax/libs/jquery.form/%s/jquery.form.min.js',
    3541        'jquery-migrate' => 'https://cdnjs.cloudflare.com/ajax/libs/jquery-migrate/%s/jquery-migrate.min.js',
     42        'masonry'        => 'https://cdnjs.cloudflare.com/ajax/libs/masonry/%s/masonry.pkgd.min.js',
    3643        'mediaelement'   => 'https://cdnjs.cloudflare.com/ajax/libs/mediaelement/%s/mediaelement-and-player.min.js',
    37         'device'         => 'https://cdnjs.cloudflare.com/ajax/libs/device.js/0.2.7/device.min.js',
    38         'bootstrap'      => 'https://maxcdn.bootstrapcdn.com/bootstrap/%s/js/bootstrap.min.js',
     44        'schedule'       => 'https://cdnjs.cloudflare.com/ajax/libs/schedulejs/%s/schedule.min.js',
     45        'swfobject'      => 'https://cdnjs.cloudflare.com/ajax/libs/swfobject/%s/swfobject.min.js',
     46        'tiny_mce'       => 'https://cdnjs.cloudflare.com/ajax/libs/tinymce/%s/tinymce.min.js',
     47        'underscore'     => 'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/%s/underscore-min.js',
    3948    ];
    4049
     
    95104    private function bundle($target)
    96105    {
     106        $stream = stream_context_create(
     107        [
     108            'ssl' => array('verify_peer' => false, 'verify_peer_name' => false),
     109        ]); 
     110
    97111        $import = 'import \s* " ([^"]+) " \s* ;';
    98112
    99         return preg_replace_callback("/$import/ix", function($result)
     113        return preg_replace_callback("/$import/ix", function($result) use($stream)
    100114        {
    101             if ($string = @file_get_contents($source = $result[1]))
     115            if ($string = @file_get_contents($source = $result[1], false, $stream))
    102116            {
    103117                return (new static([$string]))->bundle($source);
     
    110124    static function serve($source, $handle)
    111125    {
    112         if (($target = @static::$export[$handle]) && ($offset = strpos($source, '?ver=')))
     126        if (($target = @static::$hoster[$handle]) && ($offset = strpos($source, '?ver=')))
    113127        {
    114128            return sprintf($target, substr($source, $offset + 5));
  • optimality/trunk/markup/style.php

    r1683276 r1684796  
    2222    ];
    2323
    24     static $export =
     24    static $hoster =
    2525    [
    26         'mediaelement'    => 'https://cdnjs.cloudflare.com/ajax/libs/mediaelement/%s/mediaelementplayer.min.css',
     26        'animate'         => 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/%s/animate.min.css',
    2727        'bootstrap'       => 'https://maxcdn.bootstrapcdn.com/bootstrap/%s/css/bootstrap.min.css',
    2828        'font-awesome'    => 'https://maxcdn.bootstrapcdn.com/font-awesome/%s/css/font-awesome.min.css',
     29        'materialize'     => 'https://cdnjs.cloudflare.com/ajax/libs/materialize/%s/css/materialize.min.css',
     30        'mediaelement'    => 'https://cdnjs.cloudflare.com/ajax/libs/mediaelement/%s/mediaelementplayer.min.css',
     31        'normalize'       => 'https://cdnjs.cloudflare.com/ajax/libs/normalize/%s/normalize.min.css',
     32        'skeleton'        => 'https://cdnjs.cloudflare.com/ajax/libs/skeleton/%s/skeleton.min.css',
    2933    ];
    3034
     
    97101    private function bundle($target)
    98102    {
     103        $stream = stream_context_create(
     104        [
     105            'ssl' => array('verify_peer' => false, 'verify_peer_name' => false),
     106        ]); 
     107
    99108        $import = '@import \s* url \( [\'"]? ([^\'"\)]+) [\'"]? \) \s* ([^;]*) \s* ;';
    100109
    101         return preg_replace_callback("/$import/ix", function($result)
     110        return preg_replace_callback("/$import/ix", function($result) use($stream)
    102111        {
    103             if ($string = @file_get_contents($source = $result[1]))
     112            if ($string = @file_get_contents($source = $result[1], false, $stream))
    104113            {
    105114                $string = (new static([$string]))->bundle($source);
     
    134143    static function serve($source, $handle)
    135144    {
    136         if (($target = @static::$export[$handle]) && ($offset = strpos($source, '?ver=')))
     145        if (($target = @static::$hoster[$handle]) && ($offset = strpos($source, '?ver=')))
    137146        {
    138147            return sprintf($target, substr($source, $offset + 5));
  • optimality/trunk/readme.txt

    r1683808 r1684796  
    7676== Changelog ==
    7777
     78= 0.3.0 =
     79* Feature: Added option to disable Admin Bar menu
     80* Feature: Moved custom HTML to general settings
     81* Feature: Redirect paginated comment pages to their parent
     82* Feature: More CDN providers for popular JS/CSS libraries
     83* Feature: Ignore SSL errors on self signed SSL certificates
     84
    7885= 0.2.0 =
    79 * Feature: Extended the mapping of popular JS/CSS libraries
     86* Feature: More CDN providers for popular JS/CSS libraries
    8087* Feature: +10% reduction in filesize of PNG thumbnails
    8188
Note: See TracChangeset for help on using the changeset viewer.