Changeset 1492363
- Timestamp:
- 09/08/2016 09:15:58 AM (10 years ago)
- Location:
- wp-platform/trunk
- Files:
-
- 1 added
- 3 edited
-
classes/Collection.php (added)
-
classes/PostType.php (modified) (8 diffs)
-
classes/Setup.php (modified) (4 diffs)
-
plugin.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-platform/trunk/classes/PostType.php
r1487792 r1492363 4 4 class PostType { 5 5 6 protected static $custom_type;6 //protected static $custom_type; //abstract 7 7 protected static $models = array(); 8 8 … … 12 12 public $post_type; 13 13 public $parent_id; 14 public $date_published; 14 15 public $image; 15 16 public $excerpt; 16 17 public $content; 17 public $filters;18 18 19 19 /** … … 31 31 public function load() 32 32 { 33 34 33 $this->name = get_the_title($this->id); 35 34 $this->url = get_permalink($this->id); … … 39 38 $this->content = get_post_field('post_content', $this->id); 40 39 $this->content = apply_filters('the_content', $this->content); 40 $this->date_published = get_the_date('Y-m-d H:i:s', $this->id); 41 $this->date_published = Filter::from_mysqltime($this->date_published); 41 42 42 43 if (has_post_thumbnail($this->id)) { … … 66 67 67 68 /** 69 * @param array $row 70 * @return void 71 */ 72 public function map($row) 73 { 74 if (!$row) { 75 return; 76 } 77 78 $row = (array)$row; 79 $fields = get_object_vars($this); 80 81 foreach ($row as $key => $val) { 82 83 if (!array_key_exists($key, $fields)) { 84 continue; 85 } 86 87 $this->{$key} = $val; 88 89 } 90 91 } 92 93 /** 94 * @return void 95 */ 96 public static function setup() 97 { 98 $static = get_called_class(); 99 $custom_type = $static::$custom_type; 100 101 if (!$custom_type) { 102 throw new Exception('You must define $custom_type in your PostType model'); 103 } 104 105 self::$models[$custom_type]['class'] = $static; 106 107 add_action('wp', array($static, 'listPage')); 108 109 } 110 111 /** 112 * @return void 113 */ 114 public static function listPage() 115 { 116 global $wp_query; 117 118 if (is_admin()) { 119 return; 120 } 121 122 $custom_type = static::$custom_type; 123 $post_type = $wp_query->get('post_type'); 124 125 if ($post_type != $custom_type) { 126 return; 127 } 128 129 if (!$wp_query->is_archive()) { 130 return; 131 } 132 133 $base_blog = get_site_url(1); 134 $curr_blog = get_bloginfo('url'); 135 $curr_prefix = str_replace($base_blog, '', $curr_blog); 136 137 $uri = $_SERVER['REQUEST_URI']; 138 $path = parse_url($uri, PHP_URL_PATH); 139 $path = str_replace($curr_prefix, '', $path); //remove multisite blog prefix 140 $path = trim($path, '/'); 141 $page = get_page_by_path($path); 142 143 if (!$page) { 144 return; 145 } 146 147 $wp_query->queried_object_id = $page->ID; 148 $wp_query->queried_object = $page; 149 $wp_query->queried_object->ancestors = array(); 150 151 $wp_query->post = $page; 152 $wp_query->is_page = 1; 153 $wp_query->is_singular = 1; 154 $wp_query->is_404 = 0; 155 $wp_query->reset_postdata(); 156 157 $GLOBALS['wp_the_query'] = $wp_query; 158 159 } 160 161 /** 162 * @param int $id 163 * @return Platform\PostType 164 */ 165 public static function getPost($id=false) 166 { 167 if (!$id) { 168 $id = get_the_ID(); 169 } 170 171 if (!$id) { 172 return false; 173 } 174 175 $models = self::$models; 176 $post_type = get_post_type($id); 177 178 if (!$post_type) { 179 return false; 180 } 181 182 if (isset($models[$post_type]['class'])) { 183 $class = $models[$post_type]['class']; 184 } else { 185 $class = get_called_class(); 186 } 187 188 $post = new $class($id); 189 $post->load(); 190 191 return $post; 192 193 } 194 195 /** 68 196 * @return array 69 197 */ 70 public function getLatest() 71 { 72 198 public static function getAll() 199 { 73 200 $args = array( 74 'post_type' => self::$post_type, 201 'post_type' => static::$custom_type, 202 'posts_per_page' => -1 203 ); 204 205 $rtn = get_posts($args); 206 $rtn = Collection::convert($rtn); 207 return $rtn; 208 } 209 210 /** 211 * @param int $limit 212 * @return array 213 */ 214 public static function getLatest($limit) 215 { 216 $args = array( 217 'post_type' => static::$custom_type, 75 218 'orderby' => 'date', 76 'order' => 'ASC' 77 ); 78 79 if (isset($this->filters['limit'])) { 80 $args['posts_per_page'] = $this->filters['limit']; 81 } 219 'order' => 'DESC', 220 'posts_per_page' => $limit 221 ); 82 222 83 223 $rtn = get_posts($args); 84 $rtn = static::convert($rtn);224 $rtn = Collection::convert($rtn); 85 225 return $rtn; 86 87 226 } 88 227 … … 90 229 * @return array 91 230 */ 92 public function getFeatured() 93 { 94 231 public static function getFeatured() 232 { 95 233 $meta_query = array(); 96 234 $meta_query[] = array( … … 101 239 102 240 $args = array( 103 'post_type' => s elf::$custom_type,241 'post_type' => static::$custom_type, 104 242 'posts_per_page' => -1, 105 243 'meta_query' => $meta_query … … 107 245 108 246 $rtn = get_posts($args); 247 $rtn = Collection::convert($rtn); 109 248 return $rtn; 110 111 }112 113 /**114 * @param array $row115 * @return void116 */117 public function map($row)118 {119 120 if (!$row) {121 return;122 }123 124 $row = (array)$row;125 $fields = get_object_vars($this);126 127 foreach ($row as $key => $val) {128 129 if (!array_key_exists($key, $fields)) {130 continue;131 }132 133 $this->{$key} = $val;134 135 }136 137 }138 139 /**140 * @return void141 */142 public static function setup()143 {144 145 $static = get_called_class();146 $custom_type = $static::$custom_type;147 self::$models[$custom_type]['class'] = $static;148 149 add_action('wp', array($static, 'list_page'));150 151 }152 153 /**154 * @param array $posts155 * @return array156 */157 public static function get_posts($posts=false)158 {159 $rtn = array();160 161 if ($posts) {162 //do nothing if array passed163 } elseif (isset($GLOBALS['posts'])) {164 $posts = $GLOBALS['posts'];165 } else {166 return array();167 }168 169 foreach ($posts as $wp_post) {170 $id = $wp_post->ID;171 $rtn[] = self::get_post($id);172 }173 174 return $rtn;175 176 }177 178 /**179 * @param int $id180 * @return Platform\PostType181 */182 public static function get_post($id=false)183 {184 185 if (!$id) {186 $id = get_the_ID();187 }188 189 if (!$id) {190 return false;191 }192 193 $models = self::$models;194 $post_type = get_post_type($id);195 196 if (!$post_type) {197 return false;198 }199 200 if (isset($models[$post_type]['class'])) {201 $class = $models[$post_type]['class'];202 } else {203 $class = get_called_class();204 }205 206 $post = new $class($id);207 $post->load();208 209 return $post;210 211 }212 213 /**214 * @return void215 */216 public static function list_page()217 {218 219 global $wp_query;220 221 if (is_admin()) {222 return;223 }224 225 $custom_type = static::$custom_type;226 $post_type = $wp_query->get('post_type');227 228 if ($post_type != $custom_type) {229 return;230 }231 232 if (!$wp_query->is_archive()) {233 return;234 }235 236 $base_blog = get_site_url(1);237 $curr_blog = get_bloginfo('url');238 $curr_prefix = str_replace($base_blog, '', $curr_blog);239 240 $uri = $_SERVER['REQUEST_URI'];241 $path = parse_url($uri, PHP_URL_PATH);242 $path = str_replace($curr_prefix, '', $path); //remove multisite blog prefix243 $path = trim($path, '/');244 $page = get_page_by_path($path);245 246 if (!$page) {247 return;248 }249 250 $wp_query->queried_object_id = $page->ID;251 $wp_query->queried_object = $page;252 $wp_query->queried_object->ancestors = array();253 254 $wp_query->post = $page;255 $wp_query->is_page = 1;256 $wp_query->is_singular = 1;257 $wp_query->is_404 = 0;258 $wp_query->reset_postdata();259 260 $GLOBALS['wp_the_query'] = $wp_query;261 262 249 } 263 250 -
wp-platform/trunk/classes/Setup.php
r1491664 r1492363 10 10 { 11 11 //wp constants 12 define('WP_PLATFORM', true);13 12 define('PLATFORM_PATH', WP_PLUGIN_DIR.'/wp-platform'); 14 13 define('APP_PATH', get_template_directory().'/app'); … … 50 49 } 51 50 51 //url 52 define('HTTP_URL', HTTP.HOST); 53 52 54 //autoloader 53 55 spl_autoload_register(array('Platform\Setup', 'autoload')); … … 61 63 //router 62 64 add_filter('template_redirect', array(__CLASS__, 'router')); 65 66 //activation 67 register_activation_hook(WP_PLATFORM, array(__CLASS__, 'activate')); 63 68 64 69 } … … 129 134 } 130 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 } 147 131 148 132 149 } -
wp-platform/trunk/plugin.php
r1491664 r1492363 2 2 /** 3 3 * Plugin Name: WP-Platform 4 * Version: 1. 0.44 * Version: 1.1.0 5 5 * Description: Provides platform to allow developers to build bespoke functionality in an MVC and OOP fashion 6 6 */ 7 //set plugin path 8 define('WP_PLATFORM', __FILE__); 7 9 8 10 //load in platform … … 13 15 Platform\Breadcrumb::setup(); 14 16 Platform\Paging::setup(); 15 16 //esc wysiwyg17 function esc_wysiwyg($str) {18 return $str;19 }
Note: See TracChangeset
for help on using the changeset viewer.