Plugin Directory

Changeset 2030952


Ignore:
Timestamp:
02/15/2019 12:29:45 AM (7 years ago)
Author:
wpdashboard
Message:

Getting 2.0 ready to launch!

Location:
wp-dashboard/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • wp-dashboard/trunk/api/class-wpdashboard-api-base.php

    r2021642 r2030952  
    11<?php
    22
    3 /**
    4  * The base of the API portion.
    5  *
    6  * Sets up the base needs for the WP Dashboard
    7  * API. Can be used elsewhere too.
    8  *
    9  * @package    Wpdashboard
    10  * @subpackage Wpdashboard/api
    11  * @author     WP Dashboard <brianldj@gmail.com>
    12  */
     3class WpDashboard_Api_Base extends WP_REST_Controller {
    134
    14 class WpDashboard_Api_Base {
    15 
    16     /**
    17      * The ID of this plugin.
    18      *
    19      * @since    1.0.0
    20      * @access   private
    21      * @var      string    $plugin_name    The ID of this plugin.
    22      */
    23     private $plugin_name;
     5    /**
     6     * The ID of this plugin.
     7     *
     8     * @since    2.0.0
     9     * @access   private
     10     * @var      string    $plugin_name    The ID of this plugin.
     11     */
     12    protected $plugin_name;
    2413
    2514    /**
    2615     * The version of this plugin.
    2716     *
    28      * @since    1.0.0
     17     * @since    2.0.0
    2918     * @access   private
    3019     * @var      string    $version    The current version of this plugin.
    3120     */
    32     private $version;
     21    protected $version;
    3322
    3423    /**
    35      * A GuzzleHTTP client used to communicate with WPDashboard.io.
     24     * Initialize the class and set its properties.
    3625     *
    37      * @since    1.0.0
    38      * @access   private
    39      * @var      string    $request_type    The current request made to the API.
     26     * @since    2.0.0
     27     * @param      string    $plugin_name       The name of this plugin.
     28     * @param      string    $version    The version of this plugin.
    4029     */
    41     private $client;
     30    public function __construct( $plugin_name, $version ) {
    4231
    43     /**
    44      * Initialize the class and set its properties.
    45      *
    46      * @since    1.0.0
    47      * @param      string    $plugin_name       The name of this plugin.
    48      * @param      string    $version    The version of this plugin.
    49      */
    50     public function __construct( $plugin_name, $version ) {
    51 
    52         $this->plugin_name = $plugin_name;
    53         $this->version = $version;
    54         $this->client = new WP_Http();
    55 
    56     }
    57 
    58     public function init() {
     32        $this->plugin_name = $plugin_name;
     33        $this->version = $version;
    5934
    6035    }
     
    6338     * Get Option from WordPress.
    6439     *
    65      * @since    1.0.0
     40     * @since    2.0.0
    6641     *
    6742     * @param $name
     
    7550     * Update Option from WordPress.
    7651     *
    77      * @since    1.0.0
     52     * @since    2.0.0
    7853     *
    7954     * @param $name
     
    8964     * Delete Option from WordPress.
    9065     *
    91      * @since    1.0.106
     66     * @since    2.0.0
    9267     *
    9368     * @param $name
     
    9873    }
    9974
     75    /**
     76     * Required
     77     *
     78     * Include the required files,
     79     * only if the route is activated
     80     * though, otherwise... errors...
     81     *
     82     * @since 2.0.0
     83     *
     84     * @return void
     85     */
     86    public function required() {
     87        include_once(ABSPATH . 'wp-admin/includes/file.php');
     88        include_once(ABSPATH . 'wp-admin/includes/plugin.php');
     89        include_once(ABSPATH . 'wp-includes/plugin.php');
     90        include_once(ABSPATH . 'wp-admin/includes/theme.php');
     91        include_once(ABSPATH . 'wp-admin/includes/misc.php');
     92        include_once(ABSPATH . 'wp-admin/includes/template.php');
     93        include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
     94        include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
     95        include_once(ABSPATH . 'wp-admin/includes/update.php');
     96        require_once 'lib/class-wp-upgrade-skin.php';
     97    }
    10098
    10199    /**
    102      * Generate Random String.
     100     * Check Permission
    103101     *
    104      * @since    1.0.0
     102     * Checks to see if the API Key that is given
     103     * matches what we have stored.
    105104     *
    106      * @param $data
    107      * @return string
     105     * @param WP_REST_Request $request Full data about the request.
     106     *
     107     * @return bool|WP_Error
    108108     */
    109     protected function __generate_random_string($data) {
    110         assert(strlen($data) == 16);
    111 
    112         $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
    113         $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
    114 
    115         return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
     109    public function permission_check( $request ) {
     110        if(null !== $request->get_param('api_key')) {
     111            if($request->get_param('api_key') == $this->get_option('api_key')) {
     112                return true;
     113            }
     114        }
     115        return new WP_Error('unauthenticated', 'You are not authenticated to do this.');
    116116    }
    117117
     118    /**
     119     * Coming Soon
     120     *
     121     * Let's whoever is trying to use the
     122     * API know that this function
     123     * is coming in a later version.
     124     *
     125     * @since 2.0.0
     126     *
     127     * @param $feature string The Feature that is missing.
     128     * @param $version float  The estimated version that the feature will show up in.
     129     *
     130     * @return WP_Error
     131     */
     132    public function coming_soon($feature, $version) {
     133        return new WP_Error(404, 'The feature, ' . $feature . ', is coming, hopefully in version ' . $version . ', but we will see.');
     134    }
     135
     136    /**
     137     * Stupid
     138     *
     139     * Okay, let's face it, if you
     140     * are using end up seeing the
     141     * result of this function...
     142     * you probably deserve it...
     143     *
     144     * @since 2.0.0
     145     *
     146     * @param $huh string The stupid thing the end user is attempting to accomplish...
     147     *
     148     * @return WP_Error
     149     */
     150    public function stupid($huh) {
     151        return new WP_Error('wpd_69', '.... you want to... ' . $huh . '... okay, yeah, that is not going to happen??');
     152    }
    118153}
  • wp-dashboard/trunk/api/class-wpdashboard-plugin-routes.php

    r2022347 r2030952  
    11<?php
    22
    3 class WpDashboard_Plugin_Routes extends WP_REST_Controller {
    4 
    5     /**
    6      * The ID of this plugin.
    7      *
    8      * @since    2.0.0
    9      * @access   private
    10      * @var      string    $plugin_name    The ID of this plugin.
    11      */
    12     private $plugin_name;
    13 
    14     /**
    15      * The version of this plugin.
    16      *
    17      * @since    2.0.0
    18      * @access   private
    19      * @var      string    $version    The current version of this plugin.
    20      */
    21     private $version;
    22 
    23     /**
    24      * Initialize the class and set its properties.
    25      *
    26      * @since    2.0.0
    27      * @param      string    $plugin_name       The name of this plugin.
    28      * @param      string    $version    The version of this plugin.
    29      */
    30     public function __construct( $plugin_name, $version ) {
    31 
    32         $this->plugin_name = $plugin_name;
    33         $this->version = $version;
    34 
    35     }
    36 
    37     /**
    38      * Get Option from WordPress.
    39      *
    40      * @since    2.0.0
    41      *
    42      * @param $name
    43      * @return mixed
    44      */
    45     public function get_option($name) {
    46         return get_option($this->plugin_name . '_' . $name);
    47     }
    48 
    49     /**
    50      * Update Option from WordPress.
    51      *
    52      * @since    2.0.0
    53      *
    54      * @param $name
    55      * @param $value
    56      * @param $autoload
    57      * @return mixed
    58      */
    59     public function update_option($name, $value, $autoload) {
    60         return update_option($this->plugin_name . '_' . $name, $value, $autoload);
    61     }
    62 
    63     /**
    64      * Delete Option from WordPress.
    65      *
    66      * @since    2.0.0
    67      *
    68      * @param $name
    69      * @return mixed
    70      */
    71     public function delete_option($name) {
    72         return delete_option($this->plugin_name . '_' . $name);
    73     }
     3class WpDashboard_Plugin_Routes extends WpDashboard_Api_Base {
    744
    755    /**
     
    228158     * Activate Plugin
    229159     *
    230      * Deactivates the plugin on
     160     * Activates the plugin on
    231161     * the site.
    232162     *
     
    365295    }
    366296
    367 
    368     /**
    369      * Required
    370      *
    371      * Include the required files,
    372      * only if the route is activated
    373      * though, otherwise... errors...
    374      *
    375      * @since 2.0.0
    376      *
    377      * @return void
    378      */
    379     public function required() {
    380         include_once(ABSPATH . 'wp-admin/includes/file.php');
    381         include_once(ABSPATH . 'wp-admin/includes/plugin.php');
    382         include_once(ABSPATH . 'wp-includes/plugin.php');
    383         include_once(ABSPATH . 'wp-admin/includes/theme.php');
    384         include_once(ABSPATH . 'wp-admin/includes/misc.php');
    385         include_once(ABSPATH . 'wp-admin/includes/template.php');
    386         include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
    387         include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
    388         require_once 'lib/class-wp-upgrade-skin.php';
    389     }
    390 
    391     /**
    392      * Check Permission
    393      *
    394      * Checks to see if the API Key that is given
    395      * matches what we have stored.
    396      *
    397      * @param WP_REST_Request $request Full data about the request.
    398      *
    399      * @return bool|WP_Error
    400      */
    401     public function permission_check( $request ) {
    402         if(null !== $request->get_param('api_key')) {
    403             if($request->get_param('api_key') == $this->get_option('api_key')) {
    404                 return true;
    405             }
    406         }
    407         return new WP_Error('unauthenticated', 'You are not authenticated to do this.');
    408     }
    409 
    410297    /**
    411298     * Check Plugin Installed
     
    429316        return false;
    430317    }
    431 
    432     /**
    433      * Prepare the item for create or update operation
    434      *
    435      * @param WP_REST_Request $request Request object
    436      * @return WP_Error|object $prepared_item
    437      */
    438     protected function prepare_item_for_database( $request ) {
    439         return array();
    440     }
    441 
    442     /**
    443      * Prepare the item for the REST response
    444      *
    445      * @param mixed $item WordPress representation of the item.
    446      * @param WP_REST_Request $request Request object.
    447      * @return mixed
    448      */
    449     public function prepare_item_for_response( $item, $request ) {
    450         return array();
    451     }
    452 
    453     /**
    454      * Get the query params for collections
    455      *
    456      * @return array
    457      */
    458     public function get_collection_params() {
    459         return array(
    460             'page'     => array(
    461                 'description'       => 'Current page of the collection.',
    462                 'type'              => 'integer',
    463                 'default'           => 1,
    464                 'sanitize_callback' => 'absint',
    465             ),
    466             'per_page' => array(
    467                 'description'       => 'Maximum number of items to be returned in result set.',
    468                 'type'              => 'integer',
    469                 'default'           => 10,
    470                 'sanitize_callback' => 'absint',
    471             ),
    472             'search'   => array(
    473                 'description'       => 'Limit results to those matching a string.',
    474                 'type'              => 'string',
    475                 'sanitize_callback' => 'sanitize_text_field',
    476             ),
    477         );
    478     }
    479318}
  • wp-dashboard/trunk/includes/class-wpdashboard.php

    r2021642 r2030952  
    121121         * The classes responsible for defining all actions that occur in the api.
    122122         */
     123        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-api-base.php';
    123124        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-plugin-routes.php';
     125        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-theme-routes.php';
     126        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-core-routes.php';
     127        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-page-routes.php';
     128        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-post-routes.php';
    124129
    125130        /**
     
    133138         */
    134139        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpdashboard-public.php';
    135 
    136         /**
    137          * Bring in the things required from Composer.
    138          */
    139         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'vendor/autoload.php';
    140140
    141141        $this->loader = new Wpdashboard_Loader();
     
    199199     */
    200200    private function define_api_hooks() {
    201         $api = new WpDashboard_Plugin_Routes( $this->get_plugin_name(), $this->get_version() );
    202         $this->loader->add_action( 'rest_api_init', $api, 'register_routes' );
     201
     202        $plugin_api = new WpDashboard_Plugin_Routes( $this->get_plugin_name(), $this->get_version() );
     203        $this->loader->add_action( 'rest_api_init', $plugin_api, 'register_routes' );
     204
     205        $theme_api = new WpDashboard_Theme_Routes( $this->get_plugin_name(), $this->get_version() );
     206        $this->loader->add_action( 'rest_api_init', $theme_api, 'register_routes' );
     207
     208        $core_api = new WpDashboard_Core_Routes( $this->get_plugin_name(), $this->get_version() );
     209        $this->loader->add_action( 'rest_api_init', $core_api, 'register_routes' );
     210
     211        $page_api = new WpDashboard_Page_Routes( $this->get_plugin_name(), $this->get_version() );
     212        $this->loader->add_action( 'rest_api_init', $page_api, 'register_routes' );
     213
     214        $post_api = new WpDashboard_Post_Routes( $this->get_plugin_name(), $this->get_version() );
     215        $this->loader->add_action( 'rest_api_init', $post_api, 'register_routes' );
     216
    203217        $webhook_api = new Wpdashboard_WebHooks( $this->get_plugin_name(), $this->get_version() );
    204218        $webhook_api->init();
     219
    205220    }
    206221
  • wp-dashboard/trunk/index.php

    r1809618 r2030952  
    1 <?php // Silence is golden
     1<?php
     2// Silence is golden :3
  • wp-dashboard/trunk/readme.txt

    r2020673 r2030952  
    33Donate link: https://wpdashboard.io
    44Tags: wpdashboard, wp, dashboard, manage, updates, plugins, wpdash, dash
    5 Requires at least: 3.0.1
    6 Tested up to: 4.9.1
     5Requires at least: 4.0.0
     6Tested up to: 5.0.3
    77Requires PHP: 5.6
    88Stable tag: 1.1.18
     
    5858
    5959= 2.0.0 =
    60 * Complete re-work of the information gathering!
    61     * Moved to Webhook version, no more pounding servers/sites for information!
    62     * Information is now updated in real-time on the dashboard
    63     * Old version is still in place for those sites NOT upgraded, so no worries!
    64 * Gathering more information, and re-working how the plugin's backend works!
    65 * Starting implementation of the REST API extension, instead of using our own
    66 * Starting implementation of the ability to pack up a site and move it
     60* Moved to a Webhook version; no more pounding servers/sites for information!
     61* Gathering more information and re-working how the plugin's backend works!
     62* Implementation of the REST API extension, instead of using our own
    6763* Bug fixes for PHP 5.6
    6864
  • wp-dashboard/trunk/webhooks/class-wpdashboard-webhooks.php

    r2022347 r2030952  
    8383
    8484//    private $url = 'https://my.wpdashboard.io/api/v2/site/';
    85 //    private $url = 'http://wpdashboard.io.test/api/site/';
    86     private $url = 'https://beta.wpdashboard.io/api/site/';
     85    private $url = 'http://wpdashboard.io.test/api/site/';
    8786
    8887    /**
Note: See TracChangeset for help on using the changeset viewer.