Plugin Directory

Changeset 1932005


Ignore:
Timestamp:
08/28/2018 08:01:26 PM (8 years ago)
Author:
piotrmocko
Message:

Version 1.19.0

Location:
perfectdashboard/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • perfectdashboard/trunk/Cms/Wordpress/Task/GetExtensions.php

    r1908589 r1932005  
    88{
    99    protected $current_theme = '';
     10    protected $updates = array();
    1011
    1112    /**
    1213     * @return array
    1314     */
    14     public function doTask()
    15     {
    16         if (($site_id = (int) $this->input('pd_site_id')))
    17         {
    18             AutoUpdater_Config::set('site_id', $site_id);
    19         }
    20 
    21         if (defined('DOING_AJAX'))
    22         {
    23             return $this->getUpdatesFromCustomServers();
    24         }
    25         else
    26         {
    27             return $this->getExtensions();
    28         }
    29     }
    30 
    31     /**
    32      * @return array
    33      */
    3415    protected function getExtensions()
    3516    {
    36         $extensions = array(
    37             array(
    38                 'name'       => 'WordPress',
    39                 'type'       => 'cms',
    40                 'slug'       => 'wordpress',
    41                 'version'    => get_bloginfo('version'),
    42                 'enabled'    => 1,
    43                 'author'     => 'WordPress Team',
    44                 'author_url' => 'https://wordpress.org',
    45             ),
    46             $extensions[] = array(
    47                 'name'       => 'Translations',
    48                 'slug'       => 'core',
    49                 'type'       => 'language',
    50                 'cms'        => 'wordpress',
    51                 'version'    => AUTOUPDATER_WP_VERSION,
    52                 'enabled'    => 1,
    53                 'author'     => 'WordPress Team',
    54                 'author_url' => 'https://wordpress.org',
    55             )
    56         );
     17        $extensions = array();
     18        $this->updates = $this->getUpdatesFromCustomServers();
     19
     20        $cms                 = new stdClass();
     21        $cms->name           = 'WordPress';
     22        $cms->type           = 'cms';
     23        $cms->slug           = 'wordpress';
     24        $cms->version        = get_bloginfo('version');
     25        $cms->enabled        = 1;
     26        $cms->update_servers = array();
     27        $cms->update         = null;
     28
     29        $translations                 = new stdClass();
     30        $translations->name           = 'Translations';
     31        $translations->type           = 'language';
     32        $translations->slug           = 'core';
     33        $translations->version        = AUTOUPDATER_WP_VERSION;
     34        $translations->enabled        = 1;
     35        $translations->update_servers = array();
     36        $translations->update         = $this->checkForUpdates($translations->slug, $translations->type);
     37
     38        $extensions[] = $cms;
     39        $extensions[] = $translations;
    5740
    5841        $list = get_plugins();
     
    8669        }
    8770
    88         return array(
    89             'success'    => true,
    90             'extensions' => $extensions,
    91         );
     71        return $extensions;
    9272    }
    9373
     
    10080    protected function getPluginInfo($slug, $plugin)
    10181    {
    102         $item = array(
    103             'name'           => $this->filterHTML($plugin['Name']),
    104             'type'           => 'plugin',
    105             'slug'           => $slug,
    106             'version'        => strtolower($this->filterHTML($plugin['Version'])),
    107             'enabled'        => (int) is_plugin_active($slug),
    108             'update_servers' => '',
    109         );
    110 
    111         // Get author name
    112         if (isset($plugin['Author']))
    113         {
    114             $item['author'] = $this->filterHTML($plugin['Author']);
    115         }
    116         elseif (isset($plugin['AuthorName']))
    117         {
    118             $item['author'] = $this->filterHTML($plugin['AuthorName']);
    119         }
    120         else
    121         {
    122             $item['author'] = null;
    123         }
    124 
    125         // Get author url
    126         if (isset($plugin['AuthorURI']))
    127         {
    128             $item['author_url'] = $this->filterHTML($plugin['AuthorURI']);
    129         }
    130         else
    131         {
    132             $item['author_url'] = null;
    133         }
     82        $item                 = new stdClass();
     83        $item->name           = $this->filterHTML($plugin['Name']);
     84        $item->type           = 'plugin';
     85        $item->slug           = $slug;
     86        $item->version        = strtolower($this->filterHTML($plugin['Version']));
     87        $item->enabled        = (int) is_plugin_active($slug);
     88        $item->update_servers = array();
     89        $item->update         = $this->checkForUpdates($item->slug, $item->type);
    13490
    13591        return $item;
     
    151107
    152108        // build array with themes data to Dashboard
    153         $item = array(
    154             'name'           => $this->filterHTML(
    155                 $legacy ? $theme['Name'] : $theme->get('Name')),
    156             'type'           => 'theme',
    157             'slug'           => $legacy ? $theme['Template'] : pathinfo($slug, PATHINFO_FILENAME),
    158             'version'        => strtolower($this->filterHTML(
    159                 $legacy ? $theme['Version'] : $theme->get('Version'))),
    160             'update_servers' => '',
    161         );
    162 
    163         // Get author name
    164         $item['author']     = $this->filterHTML(
    165             $legacy ? $theme['Author'] : $theme->get('Author'));
    166         $item['author_url'] = $this->filterHTML(
    167             $legacy ? $theme['Author URI'] : $theme->get('AuthorURI'));
    168 
    169         // Check if theme is activated
    170         $item['enabled'] = (int) ($this->current_theme == $item['name']);
     109        $item                 = new stdClass();
     110        $item->name           = $this->filterHTML($legacy ? $theme['Name'] : $theme->get('Name'));
     111        $item->type           = 'theme';
     112        $item->slug           = $legacy ? $theme['Template'] : pathinfo($slug, PATHINFO_FILENAME);
     113        $item->version        = strtolower($this->filterHTML($legacy ? $theme['Version'] : $theme->get('Version')));
     114        $item->enabled        = (int) ($this->current_theme == $item->name);
     115        $item->update_servers = array();
     116        $item->update         = $this->checkForUpdates($item->slug, $item->type);
    171117
    172118        return $item;
     
    181127        $pagenow = 'update-core.php';
    182128
    183         require_once AUTOUPDATER_WP_PLUGIN_PATH . 'Cms/Wordpress/Helper/Tracker.php';
     129        if (!class_exists(AutoUpdater_Loader::getClassPrefix() . 'Cms_Wordpress_Helper_Tracker'))
     130        {
     131            require_once AUTOUPDATER_WP_PLUGIN_PATH . 'Cms/Wordpress/Helper/Tracker.php';
     132        }
    184133        AutoUpdater_Cms_Wordpress_Helper_Tracker::initDefaults();
    185134
     
    248197                    }
    249198
    250                     $updates[] = array(
    251                         'slug'            => $slug,
    252                         'type'            => 'plugin',
    253                         'cms'             => 'wordpress',
     199                    $updates[$slug . '_plugin'] = array(
    254200                        'version'         => $plugin->new_version,
    255201                        'download_url'    => $plugin->package,
    256                         'cms_version_max' => !empty($plugin->tested) ? $plugin->tested : null,
     202                        'cms_version_max' => !empty($plugin->tested) ? $plugin->tested : null
    257203                    );
    258204                }
     
    300246                    }
    301247
    302                     $updates[] = array(
    303                         'slug'            => $slug,
    304                         'type'            => 'theme',
    305                         'cms'             => 'wordpress',
     248                    $updates[$slug . '_theme'] = array(
    306249                        'version'         => $theme->new_version,
    307250                        'download_url'    => $theme->package,
    308                         'cms_version_max' => !empty($theme->tested) ? $theme->tested : null,
     251                        'cms_version_max' => !empty($theme->tested) ? $theme->tested : null
    309252                    );
    310253                }
     
    328271        if ($translations)
    329272        {
    330             $updates[] = array(
    331                 'slug'            => 'core',
    332                 'type'            => 'language',
    333                 'cms'             => 'wordpress',
     273            $updates['core_language'] = array(
    334274                'version'         => AUTOUPDATER_WP_VERSION . (substr_count(AUTOUPDATER_WP_VERSION, '.') === 1 ? '.0.1' : '.1'),
    335275                'download_url'    => null,
    336                 'cms_version_max' => AUTOUPDATER_WP_VERSION,
     276                'cms_version_max' => AUTOUPDATER_WP_VERSION
    337277            );
    338278        }
    339279
    340         return array(
    341             'success'        => true,
    342             'updates'        => $updates,
    343             'update_servers' => AutoUpdater_Cms_Wordpress_Helper_Tracker::getCachedRequests(),
    344         );
     280        return $updates;
    345281    }
    346282
     
    354290        if (!empty($settings['dlid']))
    355291        {
    356             $plugin['update_servers'] = array(
    357                 array(
    358                     'url'      => 'https://www.perfect-web.co/index.php?option=com_ars&view=update&task=stream&format=json&id=8',
    359                     'dl_query' => 'dlid=' . trim($settings['dlid']),
    360                 ),
    361             );
     292            $plugin->update_servers = array('https://www.perfect-web.co/index.php?option=com_ars&view=update&task=stream&format=json&id=8&dlid=' . trim($settings['dlid']));
    362293        }
    363294
    364295        // Fix name
    365         if (version_compare($plugin['version'], '2.1.5', '<') &&
    366             strripos($plugin['name'], ' PRO') === false &&
     296        if (version_compare($plugin->version, '2.1.5', '<') &&
     297            strripos($plugin->name, ' PRO') === false &&
    367298            file_exists(WP_PLUGIN_DIR . '/pwebcontact/uploader.php'))
    368299        {
    369             $plugin['name'] = $plugin['name'] . ' PRO';
    370         }
     300            $plugin->name = $plugin->name . ' PRO';
     301        }
     302    }
     303
     304    /**
     305     * @param string $slug
     306     * @param string $type
     307     *
     308     * @return object|null
     309     */
     310    protected function checkForUpdates($slug, $type)
     311    {
     312        return isset($this->updates[$slug . '_' . $type]) ? $this->updates[$slug . '_' . $type] : null;
    371313    }
    372314}
  • perfectdashboard/trunk/Cms/Wordpress/Task/PostChildUpdate.php

    r1883279 r1932005  
    1111        $this->setInput('type', 'plugin');
    1212        $this->setInput('slug', AUTOUPDATER_WP_PLUGIN_SLUG);
    13 
    14         if (substr(AUTOUPDATER_WP_PLUGIN_BASENAME, 0, 1) === 'a' || AUTOUPDATER_STAGE != 'app')
    15         {
    16             $this->setInput('path', AutoUpdater_Config::getAutoUpdaterUrl()
     13        $this->setInput('path', AutoUpdater_Config::getAutoUpdaterUrl()
    1714                . 'download/child/' . AUTOUPDATER_CMS . '/' . AUTOUPDATER_WP_PLUGIN_BASENAME . '.zip');
    18         }
    19         else
    20         {
    21             $this->setInput('path', 'https://downloads.wordpress.org/plugin/' . AUTOUPDATER_WP_PLUGIN_BASENAME . '.zip');
    22         }
    2315
    2416        return AutoUpdater_Task::getInstance('PostExtensionUpdate', $this->payload)
  • perfectdashboard/trunk/Cms/Wordpress/Task/PostExtensionUpdate.php

    r1916974 r1932005  
    269269        elseif (!is_null($result) && !is_bool($result))
    270270        {
    271             $response['error'] = array(
    272                 'code'    => 'unknown_error',
    273                 'message' => 'Dump: ' . var_export($result, true)
    274             );
     271            $errors['unknown_error'] = 'Result dump: ' . var_export($result, true);
    275272        }
    276273
    277274        if (count($errors))
    278275        {
    279             $response['errors'] = $errors;
     276            if (!isset($response['error']))
     277            {
     278                end($errors);
     279                $response['error'] = array(
     280                    'code'    => key($errors),
     281                    'message' => current($errors)
     282                );
     283                unset($errors[$response['error']['code']]);
     284            }
     285            if (count($errors))
     286            {
     287                $response['errors'] = $errors;
     288            }
    280289        }
    281290
  • perfectdashboard/trunk/Cms/Wordpress/Upgrader/Plugin.php

    r1883279 r1932005  
    6767        /** @since 3.6.0 */
    6868        $options['abort_if_destination_exists'] = false;
    69 
    70         if (version_compare(AUTOUPDATER_WP_VERSION, '3.6.0', '<'))
    71         {
    72             $options['clear_destination'] = true;
    73         }
     69        $options['clear_destination'] = true;
    7470
    7571        return parent::run($options);
  • perfectdashboard/trunk/Cms/Wordpress/Upgrader/Theme.php

    r1883279 r1932005  
    6767        /** @since 3.6.0 */
    6868        $options['abort_if_destination_exists'] = false;
    69 
    70         if (version_compare(AUTOUPDATER_WP_VERSION, '3.6.0', '<'))
    71         {
    72             $options['clear_destination'] = true;
    73         }
     69        $options['clear_destination'] = true;
    7470
    7571        return parent::run($options);
  • perfectdashboard/trunk/lib/src/Config.php

    r1908589 r1932005  
    197197        }
    198198
    199         if (!$force && !AUTOUPDATER_DEBUG && $this->getOption('config_cached', 0) > strtotime('-1 hour'))
     199        if (!$force && !defined('AUTOUPDATER_DEBUG') && $this->getOption('config_cached', 0) > strtotime('-1 hour'))
    200200        {
    201201            return true;
  • perfectdashboard/trunk/lib/src/Loader.php

    r1883279 r1932005  
    2929        $path = str_replace('_', '/', $name) . '.php';
    3030
    31         if (!file_exists(AUTOUPDATER_LIB_PATH . $path))
    32         {
    33             return false;
    34         }
    35 
    36         include_once AUTOUPDATER_LIB_PATH . $path;
    37 
    3831        if (!class_exists(static::getClassPrefix() . $name))
    3932        {
    40             return false;
     33            if (!file_exists(AUTOUPDATER_LIB_PATH . $path))
     34            {
     35                return false;
     36            }
     37
     38            include_once AUTOUPDATER_LIB_PATH . $path;
     39
     40            if (!class_exists(static::getClassPrefix() . $name))
     41            {
     42                return false;
     43            }
    4144        }
    4245
     
    4548        if (AUTOUPDATER_CMS)
    4649        {
    47             $path = dirname(dirname(AUTOUPDATER_LIB_PATH)) . '/Cms/' . ucfirst(strtolower(AUTOUPDATER_CMS)) . '/' . $path;
    48             if (file_exists($path))
     50            $prefix = 'Cms_' . ucfirst(strtolower(AUTOUPDATER_CMS)) . '_';
     51
     52            if (!class_exists(static::getClassPrefix() . $prefix . $name))
    4953            {
    50                 include_once $path;
    51                 $prefix = 'Cms_' . ucfirst(strtolower(AUTOUPDATER_CMS)) . '_';
    52                 if (class_exists(static::getClassPrefix() . $prefix . $name))
     54                $path = dirname(dirname(AUTOUPDATER_LIB_PATH)) . '/Cms/' . ucfirst(strtolower(AUTOUPDATER_CMS)) . '/' . $path;
     55
     56                if (file_exists($path))
    5357                {
    54                     static::$loaded[$name] = static::$loaded[$prefix . $name] = static::getClassPrefix() . $prefix . $name;
     58                    include_once $path;
    5559                }
     60            }
     61
     62            if (class_exists(static::getClassPrefix() . $prefix . $name))
     63            {
     64                static::$loaded[$name] = static::$loaded[$prefix . $name] = static::getClassPrefix() . $prefix . $name;
    5665            }
    5766        }
  • perfectdashboard/trunk/lib/src/Task/GetEnvironment.php

    r1883279 r1932005  
    1414            'cms_version'      => null,
    1515            'cms_language'     => AutoUpdater_Config::getSiteLanguage(),
    16             'php_version'      => PHP_VERSION,
     16            'php_version'      => php_sapi_name() !== 'cli' ? PHP_VERSION : '',
    1717            'os'               => php_uname('s'),
    1818            'server'           => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '',
     
    2121        );
    2222
     23        if (!$this->input('refresh'))
     24        {
     25            $data['success'] = true;
     26        }
     27
    2328        return $data;
    2429    }
  • perfectdashboard/trunk/lib/src/Task/GetExtensions.php

    r1883279 r1932005  
    99    public function doTask()
    1010    {
     11        if (($site_id = (int) $this->input('pd_site_id')))
     12        {
     13            AutoUpdater_Config::set('site_id', $site_id);
     14        }
     15
     16        $extensions = $this->getExtensions();
     17
     18        $environment = AutoUpdater_Task::getInstance('GetEnvironment', array(
     19            'refresh' => 1
     20        ))->doTask();
     21
     22        $all_extensions = filter_var($this->input('pd_all'), FILTER_VALIDATE_BOOLEAN);
     23
     24        // set defaults
     25        $checksum = sha1(json_encode($extensions));
     26        $checksum_cached = null;
     27        $diff = array(
     28            'changed' => $extensions,
     29            'deleted' => array()
     30        );
     31
     32        // get the cache to compare with the current state
     33        $cache = $all_extensions ? json_encode($extensions) : AutoUpdater_Config::get('extensions_cache', null);
     34
     35        if ($cache !== null && !$all_extensions)
     36        {
     37            // make checksum
     38            $checksum_cached = sha1($cache);
     39
     40            $cache = json_decode($cache);
     41
     42            // compare the extension array with the cache to get changed and removed extensions
     43            if (is_array($cache))
     44            {
     45                $diff = $this->diff($extensions, $cache);
     46            }
     47        }
     48
     49        // save cache & checksum
     50        AutoUpdater_Config::set('extensions_cache', json_encode($extensions));
     51
    1152        return array(
    12             'success'    => true,
    13             'extensions' => array(),
     53            'success'     => true,
     54            'extensions'  => array_merge(
     55                $diff, array(
     56                    'checksum' => $checksum,
     57                    'checksum_cached' => $checksum_cached
     58                )
     59            ),
     60            'environment' => $environment
    1461        );
     62    }
     63
     64    /**
     65     * @param array $extensions
     66     * @param array $cache
     67     *
     68     * @return array
     69     */
     70    protected function diff($extensions, $cache)
     71    {
     72        $changed = array();
     73
     74        foreach ($extensions as $extension)
     75        {
     76            // look for this extension in the cache
     77            $cache_key = $this->findExtensionInCache($extension->type, $extension->slug, $cache);
     78
     79            // this is a newly installed extension
     80            if ($cache_key === false)
     81            {
     82                $changed[] = $extension;
     83                continue;
     84            }
     85            else
     86            {
     87                $cache_extension = $cache[$cache_key];
     88                unset($cache[$cache_key]);
     89
     90                // the status of the extension has changed
     91                if (sha1(json_encode($extension)) != sha1(json_encode($cache_extension)))
     92                {
     93                    $changed[] = $extension;
     94                    continue;
     95                }
     96            }
     97        }
     98
     99        return array(
     100            'changed' => $changed,
     101            'deleted' => array_values($cache)
     102        );
     103    }
     104
     105    /**
     106     * @param string $type
     107     * @param string $slug
     108     * @param array $cache
     109     *
     110     * @return int|bool
     111     */
     112    protected function findExtensionInCache($type, $slug, $cache)
     113    {
     114        foreach ($cache as $i => $extension)
     115        {
     116            if ($extension->type == $type && $extension->slug == $slug)
     117            {
     118                return $i;
     119            }
     120        }
     121
     122        return false;
    15123    }
    16124
  • perfectdashboard/trunk/perfectdashboard.php

    r1915233 r1932005  
    44 * Plugin URI: https://perfectdashboard.com/?utm_source=backend&utm_medium=installer&utm_campaign=in&utm_term=WP
    55 * Description:
    6  * Version: 1.18.1
     6 * Version: 1.19.0
    77 * Text Domain: autoupdater
    88 * Author: Perfect Dashboard
  • perfectdashboard/trunk/readme.txt

    r1922057 r1932005  
    55Requires at least: 3.0
    66Tested up to: 4.9.8
    7 Stable tag: 1.18.1
     7Stable tag: 1.19.0
    88License: GNU/GPL
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
Note: See TracChangeset for help on using the changeset viewer.