Plugin Directory

Changeset 1492363


Ignore:
Timestamp:
09/08/2016 09:15:58 AM (10 years ago)
Author:
spindogs
Message:

release v1.1.0

Location:
wp-platform/trunk
Files:
1 added
3 edited

Legend:

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

    r1487792 r1492363  
    44class PostType {
    55
    6     protected static $custom_type;
     6    //protected static $custom_type; //abstract
    77    protected static $models = array();
    88
     
    1212    public $post_type;
    1313    public $parent_id;
     14    public $date_published;
    1415    public $image;
    1516    public $excerpt;
    1617    public $content;
    17     public $filters;
    1818
    1919    /**
     
    3131    public function load()
    3232    {
    33 
    3433        $this->name = get_the_title($this->id);
    3534        $this->url = get_permalink($this->id);
     
    3938        $this->content = get_post_field('post_content', $this->id);
    4039        $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);
    4142
    4243        if (has_post_thumbnail($this->id)) {
     
    6667
    6768    /**
     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    /**
    68196     * @return array
    69197     */
    70     public function getLatest()
    71     {
    72 
     198    public static function getAll()
     199    {
    73200        $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,
    75218            '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        );
    82222
    83223        $rtn = get_posts($args);
    84         $rtn = static::convert($rtn);
     224        $rtn = Collection::convert($rtn);
    85225        return $rtn;
    86 
    87226    }
    88227
     
    90229     * @return array
    91230     */
    92     public function getFeatured()
    93     {
    94 
     231    public static function getFeatured()
     232    {
    95233        $meta_query = array();
    96234        $meta_query[] = array(
     
    101239
    102240        $args = array(
    103             'post_type' => self::$custom_type,
     241            'post_type' => static::$custom_type,
    104242            'posts_per_page' => -1,
    105243            'meta_query' => $meta_query
     
    107245
    108246        $rtn = get_posts($args);
     247        $rtn = Collection::convert($rtn);
    109248        return $rtn;
    110 
    111     }
    112 
    113     /**
    114      * @param array $row
    115      * @return void
    116      */
    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 void
    141      */
    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 $posts
    155      * @return array
    156      */
    157     public static function get_posts($posts=false)
    158     {
    159         $rtn = array();
    160 
    161         if ($posts) {
    162             //do nothing if array passed
    163         } 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 $id
    180      * @return Platform\PostType
    181      */
    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 void
    215      */
    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 prefix
    243         $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 
    262249    }
    263250
  • wp-platform/trunk/classes/Setup.php

    r1491664 r1492363  
    1010    {
    1111        //wp constants
    12         define('WP_PLATFORM', true);
    1312        define('PLATFORM_PATH', WP_PLUGIN_DIR.'/wp-platform');
    1413        define('APP_PATH', get_template_directory().'/app');
     
    5049        }
    5150
     51        //url
     52        define('HTTP_URL', HTTP.HOST);
     53
    5254        //autoloader
    5355        spl_autoload_register(array('Platform\Setup', 'autoload'));
     
    6163        //router
    6264        add_filter('template_redirect', array(__CLASS__, 'router'));
     65
     66        //activation
     67        register_activation_hook(WP_PLATFORM, array(__CLASS__, 'activate'));
    6368
    6469    }
     
    129134    }
    130135
     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
    131148
    132149}
  • wp-platform/trunk/plugin.php

    r1491664 r1492363  
    22/**
    33 * Plugin Name: WP-Platform
    4  * Version: 1.0.4
     4 * Version: 1.1.0
    55 * Description: Provides platform to allow developers to build bespoke functionality in an MVC and OOP fashion
    66 */
     7//set plugin path
     8define('WP_PLATFORM', __FILE__);
    79
    810//load in platform
     
    1315Platform\Breadcrumb::setup();
    1416Platform\Paging::setup();
    15 
    16 //esc wysiwyg
    17 function esc_wysiwyg($str) {
    18     return $str;
    19 }
Note: See TracChangeset for help on using the changeset viewer.