Changeset 1513511
- Timestamp:
- 10/12/2016 04:12:23 PM (9 years ago)
- Location:
- wp-platform/trunk
- Files:
-
- 9 edited
-
classes/Collection.php (modified) (1 diff)
-
classes/Form.php (modified) (3 diffs)
-
classes/Http.php (modified) (2 diffs)
-
classes/Mailchimp.php (modified) (1 diff)
-
classes/Model.php (modified) (1 diff)
-
classes/Request.php (modified) (2 diffs)
-
classes/Route.php (modified) (1 diff)
-
classes/Setup.php (modified) (1 diff)
-
plugin.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-platform/trunk/classes/Collection.php
r1492363 r1513511 8 8 * @return array 9 9 */ 10 public static function convert($posts= false)10 public static function convert($posts=null) 11 11 { 12 12 $rtn = array(); 13 13 14 if ($posts ) {14 if ($posts !== null) { 15 15 //do nothing if array passed 16 16 } elseif (isset($GLOBALS['posts'])) { -
wp-platform/trunk/classes/Form.php
r1507416 r1513511 51 51 { 52 52 53 $this->action = URI;53 $this->action = Request::getPath(); 54 54 $this->uniquevar = $uniquevar; 55 55 $this->form_id = $uniquevar; … … 1430 1430 //make action url 1431 1431 $action = $this->action; 1432 $action .= ($this->keep_gets ? QSTRING: '');1432 $action .= ($this->keep_gets ? Request::getQuery() : ''); 1433 1433 $action .= ($this->fragment ? '#'.$this->fragment : ''); 1434 1434 … … 1520 1520 if ($this->keep_gets && $this->method == 'get') { 1521 1521 1522 $qstring = trim(QSTRING, '?'); 1522 $qstring = Request::getQuery(); 1523 $qstring = trim($qstring, '?'); 1523 1524 $vars = explode('&', $qstring); 1524 1525 $vars = array_filter($vars); -
wp-platform/trunk/classes/Http.php
r1508038 r1513511 59 59 } elseif ($this->method == 'DELETE') { 60 60 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); 61 } elseif ($this->method == 'PATCH') { 62 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); 61 63 } 62 64 … … 96 98 } 97 99 100 /** 101 * 102 */ 103 public function getHttpCode() 104 { 105 return $this->http_code; 106 } 107 98 108 } -
wp-platform/trunk/classes/Mailchimp.php
r1508038 r1513511 16 16 public function subscribe($email, $data=array()) 17 17 { 18 $data['email_address'] = $email; 19 $data['status'] = 'subscribed'; 18 $email_md5 = md5($email); 20 19 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; 26 58 } 27 59 -
wp-platform/trunk/classes/Model.php
r1504964 r1513511 78 78 79 79 //get from database 80 if (property_exists($this, 'id') ) {80 if (property_exists($this, 'id') && $this->id) { 81 81 $this->filter('id', $this->id); 82 82 } elseif (!$this->filters) { 83 re portBug('You cannot call load() on an object which has no ID set');83 return false; 84 84 } 85 85 -
wp-platform/trunk/classes/Request.php
r1505671 r1513511 4 4 class Request { 5 5 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 6 53 /** 7 54 * @return string 8 55 */ 9 public static function addVar($key, $value, $url = false)56 public static function addVar($key, $value, $url = null) 10 57 { 11 if ( !$url) {12 $url = URI;58 if ($url === null) { 59 $url = self::getRequest(); 13 60 } 14 61 … … 24 71 } 25 72 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 26 129 } -
wp-platform/trunk/classes/Route.php
r1508038 r1513511 49 49 50 50 //standardise uri 51 $uri = URI;51 $uri = Request::getPath(); 52 52 $uri = trim($uri, '/'); 53 53 -
wp-platform/trunk/classes/Setup.php
r1492363 r1513511 4 4 class Setup { 5 5 6 /**7 * @return void8 */9 public static function setup()10 {11 //wp constants12 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()); 16 16 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')); 23 19 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(); 30 22 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()); 33 29 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'); 39 32 40 } else { 41 define('URI', ''); 42 } 33 //session start 34 add_action('init', array(__CLASS__, 'sessionStart'), 1); 43 35 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')); 50 38 51 //url 52 define('HTTP_URL', HTTP.HOST);39 //activation 40 register_activation_hook(WP_PLATFORM, array(__CLASS__, 'activate')); 53 41 54 //autoloader 55 spl_autoload_register(array('Platform\Setup', 'autoload')); 42 } 56 43 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 ); 59 57 60 //session start 61 add_action('init', array(__CLASS__, 'sessionStart'), 1); 58 foreach ($namespaces as $prefix => $base_dir) { 62 59 63 //router 64 add_filter('template_redirect', array(__CLASS__, 'router'));60 $prefix_length = strlen($prefix); 61 $haystack_to_match = substr($qualified, 0, $prefix_length); 65 62 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 } 68 66 69 } 67 $sub_namespace = substr($qualified, $prefix_length); 68 $sub_namespace = ltrim($sub_namespace, '\\'); 69 $parts = explode('\\', $sub_namespace); 70 $class = array_pop($parts); 70 71 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 } 84 78 85 foreach ($namespaces as $prefix => $base_dir) { 79 $file = $base_dir.$sub_path.$class.'.php'; 86 80 87 $prefix_length = strlen($prefix); 88 $haystack_to_match = substr($qualified, 0, $prefix_length); 81 if (file_exists($file)) { 82 require_once($file); 83 } 89 84 90 if ($haystack_to_match != $prefix) { 91 continue; //skip if not using this namespace prefix 92 } 85 return; 93 86 94 $sub_namespace = substr($qualified, $prefix_length); 95 $sub_namespace = ltrim($sub_namespace, '\\'); 96 $parts = explode('\\', $sub_namespace); 97 $class = array_pop($parts); 87 } 98 88 99 if ($parts) { 100 $sub_path = implode('/', $parts); 101 $sub_path .= '/'; 102 } else { 103 $sub_path = ''; 104 } 89 } 105 90 106 $file = $base_dir.$sub_path.$class.'.php'; 91 /** 92 * @return void 93 */ 94 public static function router() 95 { 96 $view = Route::dispatch(); 97 } 107 98 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 } 111 108 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 } 147 120 148 121 -
wp-platform/trunk/plugin.php
r1508165 r1513511 2 2 /** 3 3 * Plugin Name: WP-Platform 4 * Version: 1. 3.24 * Version: 1.4.1 5 5 * Description: Provides platform to allow developers to build bespoke functionality in an MVC and OOP fashion 6 6 */
Note: See TracChangeset
for help on using the changeset viewer.