Plugin Directory

Changeset 1513511


Ignore:
Timestamp:
10/12/2016 04:12:23 PM (9 years ago)
Author:
spindogs
Message:

release v1.4.1

Location:
wp-platform/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • wp-platform/trunk/classes/Collection.php

    r1492363 r1513511  
    88     * @return array
    99     */
    10     public static function convert($posts=false)
     10    public static function convert($posts=null)
    1111    {
    1212        $rtn = array();
    1313
    14         if ($posts) {
     14        if ($posts !== null) {
    1515            //do nothing if array passed
    1616        } elseif (isset($GLOBALS['posts'])) {
  • wp-platform/trunk/classes/Form.php

    r1507416 r1513511  
    5151    {
    5252
    53         $this->action = URI;
     53        $this->action = Request::getPath();
    5454        $this->uniquevar = $uniquevar;
    5555        $this->form_id = $uniquevar;
     
    14301430        //make action url
    14311431        $action = $this->action;
    1432         $action .= ($this->keep_gets ? QSTRING : '');
     1432        $action .= ($this->keep_gets ? Request::getQuery() : '');
    14331433        $action .= ($this->fragment ? '#'.$this->fragment : '');
    14341434
     
    15201520        if ($this->keep_gets && $this->method == 'get') {
    15211521
    1522             $qstring = trim(QSTRING, '?');
     1522            $qstring = Request::getQuery();
     1523            $qstring = trim($qstring, '?');
    15231524            $vars = explode('&', $qstring);
    15241525            $vars = array_filter($vars);
  • wp-platform/trunk/classes/Http.php

    r1508038 r1513511  
    5959        } elseif ($this->method == 'DELETE') {
    6060            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
     61        } elseif ($this->method == 'PATCH') {
     62            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
    6163        }
    6264
     
    9698    }
    9799
     100    /**
     101     *
     102     */
     103    public function getHttpCode()
     104    {
     105        return $this->http_code;
     106    }
     107
    98108}
  • wp-platform/trunk/classes/Mailchimp.php

    r1508038 r1513511  
    1616    public function subscribe($email, $data=array())
    1717    {
    18         $data['email_address'] = $email;
    19         $data['status'] = 'subscribed';
     18        $email_md5 = md5($email);
    2019
    21         $this->uri = '/lists/'.$this->list_id.'/members';
    22         $this->method = 'POST';
    23         $this->body = $data;
    24         $rtn = $this->call();
    25         return $rtn;
     20        $request = clone $this;
     21        $request->uri = '/lists/'.$this->list_id.'/members/'.$email_md5;
     22        $request->method = 'GET';
     23
     24        try {
     25            $response = $request->call();
     26        } catch (Exception $e) {
     27            //do nothing
     28        }
     29
     30        if (!$request->success()) {
     31            $mode = 'create';
     32        } elseif ($response->status != 'subscribed') {
     33            $mode = 'update';
     34        } else {
     35            return false;
     36        }
     37
     38        if ($mode == 'create') {
     39
     40            $data['email_address'] = $email;
     41            $data['status'] = 'subscribed';
     42
     43            $this->uri = '/lists/'.$this->list_id.'/members';
     44            $this->method = 'POST';
     45            $this->body = $data;
     46            $response = $this->call();
     47
     48        } elseif ($mode == 'update') {
     49
     50            $this->uri = '/lists/'.$this->list_id.'/members/'.$email_md5;
     51            $this->method = 'PATCH';
     52            $this->body = ['status' => 'subscribed'];
     53            $response = $this->call();
     54
     55        }
     56
     57        return $response;
    2658    }
    2759
  • wp-platform/trunk/classes/Model.php

    r1504964 r1513511  
    7878
    7979            //get from database
    80             if (property_exists($this, 'id')) {
     80            if (property_exists($this, 'id') && $this->id) {
    8181                $this->filter('id', $this->id);
    8282            } elseif (!$this->filters) {
    83                 reportBug('You cannot call load() on an object which has no ID set');
     83                return false;
    8484            }
    8585
  • wp-platform/trunk/classes/Request.php

    r1505671 r1513511  
    44class Request {
    55
     6    protected static $scheme;
     7    protected static $host;
     8    protected static $path;
     9    protected static $query;
     10    protected static $fragment;
     11
     12    /**
     13     * @return void
     14     */
     15    public static function setup()
     16    {
     17        //scheme
     18        if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
     19            self::$scheme = 'https://';
     20        } else {
     21            self::$scheme = 'http://';
     22        }
     23
     24        //host
     25        if (isset($_SERVER['HTTP_HOST'])) {
     26            self::$host = $_SERVER['HTTP_HOST'];
     27        } else {
     28            self::$host = '';
     29        }
     30
     31        //path
     32        if (isset($_SERVER['REQUEST_URI'])) {
     33
     34            if (strpos($_SERVER['REQUEST_URI'], '?') !== false) {
     35                self::$path = strstr($_SERVER['REQUEST_URI'], '?', true);
     36            } else {
     37                self::$path = $_SERVER['REQUEST_URI'];
     38            }
     39
     40        } else {
     41            self::$path = '';
     42        }
     43
     44        //query
     45        if (empty($_SERVER['QUERY_STRING'])) {
     46            self::$query = '';
     47        } else {
     48            self::$query = '?'.$_SERVER['QUERY_STRING'];
     49        }
     50
     51    }
     52
    653    /**
    754     * @return string
    855     */
    9     public static function addVar($key, $value, $url = false)
     56    public static function addVar($key, $value, $url = null)
    1057    {
    11         if (!$url) {
    12             $url = URI;
     58        if ($url === null) {
     59            $url = self::getRequest();
    1360        }
    1461
     
    2471    }
    2572
     73    /**
     74     * @return string
     75     */
     76    public static function getScheme()
     77    {
     78        return self::$scheme;
     79    }
     80
     81    /**
     82     * @return string
     83     */
     84    public static function getHost()
     85    {
     86        return self::$host;
     87    }
     88
     89    /**
     90     * @return string
     91     */
     92    public static function getPath()
     93    {
     94        return self::$path;
     95    }
     96
     97    /**
     98     * @return string
     99     */
     100    public static function getQuery()
     101    {
     102        return self::$query;
     103    }
     104
     105    /**
     106     * @return string
     107     */
     108    public static function getFragment()
     109    {
     110        return self::$fragment;
     111    }
     112
     113    /**
     114     * @return string
     115     */
     116    public static function getHttpUrl()
     117    {
     118        return self::getScheme().self::getHost();
     119    }
     120
     121    /**
     122     * @return string
     123     */
     124    public static function getRequest()
     125    {
     126        return self::getPath().self::getQuery();
     127    }
     128
    26129}
  • wp-platform/trunk/classes/Route.php

    r1508038 r1513511  
    4949
    5050        //standardise uri
    51         $uri = URI;
     51        $uri = Request::getPath();
    5252        $uri = trim($uri, '/');
    5353
  • wp-platform/trunk/classes/Setup.php

    r1492363 r1513511  
    44class Setup {
    55
    6     /**
    7     * @return void
    8     */
    9     public static function setup()
    10     {
    11         //wp constants
    12         define('PLATFORM_PATH', WP_PLUGIN_DIR.'/wp-platform');
    13         define('APP_PATH', get_template_directory().'/app');
    14         define('TEMPLATE_URI', get_template_directory_uri());
    15         define('TEMPLATE_PATH', get_template_directory());
     6    /**
     7    * @return void
     8    */
     9    public static function setup()
     10    {
     11        //paths
     12        define('PLATFORM_PATH', WP_PLUGIN_DIR.'/wp-platform');
     13        define('APP_PATH', get_template_directory().'/app');
     14        define('TEMPLATE_URI', get_template_directory_uri());
     15        define('TEMPLATE_PATH', get_template_directory());
    1616
    17         //http
    18         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
    19             define('HTTP', 'https://');
    20         } else {
    21             define('HTTP', 'http://');
    22         }
     17        //autoloader
     18        spl_autoload_register(array('Platform\Setup', 'autoload'));
    2319
    24         //host
    25         if (isset($_SERVER['HTTP_HOST'])) {
    26             define('HOST', $_SERVER['HTTP_HOST']);
    27         } else {
    28             define('HOST', '');
    29         }
     20        //setup request
     21        Request::setup();
    3022
    31         //uri
    32         if (isset($_SERVER['REQUEST_URI'])) {
     23        //deprecated
     24        define('HTTP', Request::getScheme());
     25        define('HOST', Request::getHost());
     26        define('URI', Request::getPath());
     27        define('QSTRING', Request::getQuery());
     28        define('HTTP_URL', Request::getHttpUrl());
    3329
    34             if (strpos($_SERVER['REQUEST_URI'], '?') !== false) {
    35                 define('URI', strstr($_SERVER['REQUEST_URI'], '?', true));
    36             } else {
    37                 define('URI', $_SERVER['REQUEST_URI']);
    38             }
     30        //theme support
     31        add_theme_support('post-thumbnails');
    3932
    40         } else {
    41             define('URI', '');
    42         }
     33        //session start
     34        add_action('init', array(__CLASS__, 'sessionStart'), 1);
    4335
    44         //querystr
    45         if (empty($_SERVER['QUERY_STRING'])) {
    46             define('QSTRING', '');
    47         } else {
    48             define('QSTRING', '?'.$_SERVER['QUERY_STRING']);
    49         }
     36        //router
     37        add_filter('template_redirect', array(__CLASS__, 'router'));
    5038
    51         //url
    52         define('HTTP_URL', HTTP.HOST);
     39        //activation
     40        register_activation_hook(WP_PLATFORM, array(__CLASS__, 'activate'));
    5341
    54         //autoloader
    55         spl_autoload_register(array('Platform\Setup', 'autoload'));
     42    }
    5643
    57         //theme support
    58         add_theme_support('post-thumbnails');
     44    /**
     45     * @param string $qualified
     46     * @return void
     47     */
     48    public static function autoload($qualified)
     49    {
     50        $namespaces = array(
     51            'Platform' => PLATFORM_PATH.'/classes/',
     52            'App\\Controller' => APP_PATH.'/controllers/',
     53            'App\\Model' => APP_PATH.'/models/',
     54            'App\\Service' => APP_PATH.'/services/',
     55            'App\\Widget' => APP_PATH.'/widgets/'
     56        );
    5957
    60         //session start
    61         add_action('init', array(__CLASS__, 'sessionStart'), 1);
     58        foreach ($namespaces as $prefix => $base_dir) {
    6259
    63         //router
    64         add_filter('template_redirect', array(__CLASS__, 'router'));
     60            $prefix_length = strlen($prefix);
     61            $haystack_to_match = substr($qualified, 0, $prefix_length);
    6562
    66         //activation
    67         register_activation_hook(WP_PLATFORM, array(__CLASS__, 'activate'));
     63            if ($haystack_to_match != $prefix) {
     64                continue; //skip if not using this namespace prefix
     65            }
    6866
    69     }
     67            $sub_namespace = substr($qualified, $prefix_length);
     68            $sub_namespace = ltrim($sub_namespace, '\\');
     69            $parts = explode('\\', $sub_namespace);
     70            $class = array_pop($parts);
    7071
    71     /**
    72      * @param string $qualified
    73      * @return void
    74      */
    75     public static function autoload($qualified)
    76     {
    77         $namespaces = array(
    78             'Platform' => PLATFORM_PATH.'/classes/',
    79             'App\\Controller' => APP_PATH.'/controllers/',
    80             'App\\Model' => APP_PATH.'/models/',
    81             'App\\Service' => APP_PATH.'/services/',
    82             'App\\Widget' => APP_PATH.'/widgets/'
    83         );
     72            if ($parts) {
     73                $sub_path = implode('/', $parts);
     74                $sub_path .= '/';
     75            } else {
     76                $sub_path = '';
     77            }
    8478
    85         foreach ($namespaces as $prefix => $base_dir) {
     79            $file = $base_dir.$sub_path.$class.'.php';
    8680
    87             $prefix_length = strlen($prefix);
    88             $haystack_to_match = substr($qualified, 0, $prefix_length);
     81            if (file_exists($file)) {
     82                require_once($file);
     83            }
    8984
    90             if ($haystack_to_match != $prefix) {
    91                 continue; //skip if not using this namespace prefix
    92             }
     85            return;
    9386
    94             $sub_namespace = substr($qualified, $prefix_length);
    95             $sub_namespace = ltrim($sub_namespace, '\\');
    96             $parts = explode('\\', $sub_namespace);
    97             $class = array_pop($parts);
     87        }
    9888
    99             if ($parts) {
    100                 $sub_path = implode('/', $parts);
    101                 $sub_path .= '/';
    102             } else {
    103                 $sub_path = '';
    104             }
     89    }
    10590
    106             $file = $base_dir.$sub_path.$class.'.php';
     91    /**
     92     * @return void
     93     */
     94    public static function router()
     95    {
     96        $view = Route::dispatch();
     97    }
    10798
    108             if (file_exists($file)) {
    109                 require_once($file);
    110             }
     99    /**
     100     * @return void
     101     */
     102    public static function sessionStart()
     103    {
     104        if (!session_id()) {
     105            session_start();
     106        }
     107    }
    111108
    112             return;
    113 
    114         }
    115 
    116     }
    117 
    118     /**
    119      * @return void
    120      */
    121     public static function router()
    122     {
    123         $view = Route::dispatch();
    124     }
    125 
    126     /**
    127      * @return void
    128      */
    129     public static function sessionStart()
    130     {
    131         if (!session_id()) {
    132             session_start();
    133         }
    134     }
    135 
    136     /**
    137      * @return void
    138      */
    139     public static function activate()
    140     {
    141         $plugin_data = get_plugin_data(WP_PLATFORM);
    142         $version = $plugin_data['Version'];
    143         $body = HTTP_URL."\n";
    144         $body .= 'Version: '.$version;
    145         wp_mail('osalisbury@spindogs.com', 'WP-Platform activation', $body);
    146     }
     109    /**
     110     * @return void
     111     */
     112    public static function activate()
     113    {
     114        $plugin_data = get_plugin_data(WP_PLATFORM);
     115        $version = $plugin_data['Version'];
     116        $body = Request::getHttpUrl()."\n";
     117        $body .= 'Version: '.$version;
     118        wp_mail('osalisbury@spindogs.com', 'WP-Platform activation', $body);
     119    }
    147120
    148121
  • wp-platform/trunk/plugin.php

    r1508165 r1513511  
    22/**
    33 * Plugin Name: WP-Platform
    4  * Version: 1.3.2
     4 * Version: 1.4.1
    55 * Description: Provides platform to allow developers to build bespoke functionality in an MVC and OOP fashion
    66 */
Note: See TracChangeset for help on using the changeset viewer.