PluginProbe
Cornerstone / 0.8.0
Cornerstone v0.8.0
trunk 0.7.7 0.7.8 0.8.0 0.8.1
cornerstone / controller.php

controller.php in Cornerstone 0.8.0, at controller.php

236 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package Cornerstone
5 */
6 class Cornerstone extends CNR_Base {
7 /* Variables */
8
9 /**
10 * Script files
11 * @var array
12 * @see CNR_Base::files
13 */
14 var $scripts = array (
15 'core' => array (
16 'file' => 'js/lib.core.js',
17 'deps' => 'jquery'
18 ),
19 'admin' => array (
20 'file' => 'js/lib.admin.js',
21 'deps' => array('jquery', '[core]'),
22 'context' => 'admin'
23 ),
24 'inline_edit' => array (
25 'file' => 'js/lib.posts.inline_edit.js',
26 'deps' => array('inline-edit-post','jquery', '[posts]'),
27 'context' => 'admin_page_edit'
28 )
29 );
30
31 /**
32 * Style files
33 * @var array
34 * @see CNR_Base::files
35 */
36 var $styles = array (
37 'admin' => array (
38 'file' => 'css/admin.css',
39 'context' => 'admin'
40 )
41 );
42
43 /* Featured Content variables */
44
45 /**
46 * Category slug value that denotes a "featured" post
47 * @var string
48 * @see posts_featured_cat()
49 * @todo Remove need for this property
50 */
51 var $posts_featured_cat = "feature";
52
53 /**
54 * Featured posts container
55 * @var CNR_Post_Query
56 */
57 var $posts_featured = null;
58
59 /* Children Content Variables */
60
61 /**
62 * Children posts
63 * @var CNR_Post_Query
64 */
65 var $post_children_collection = null;
66
67 /* Instance Variables */
68
69 /**
70 * Structure instance
71 * @var CNR_Structure
72 */
73 var $structure = null;
74
75 /**
76 * Media instance
77 * @var CNR_Media
78 */
79 var $media = null;
80
81 /**
82 * Post class instance
83 * @var CNR_Post
84 */
85 var $post = null;
86
87 /**
88 * Feeds instance
89 * @var CNR_Feeds
90 */
91 var $feeds = null;
92
93 /* Constructor */
94
95 function __construct() {
96 //Parent Constructor
97 parent::__construct();
98
99 //Init
100 $this->init();
101
102 //Special Queries
103 $this->posts_featured = new CNR_Post_Query( array( 'category' => $this->posts_featured_get_cat_id(), 'numberposts' => 4 ) );
104 $this->post_children_collection = new CNR_Post_Query();
105
106 $this->post = new CNR_Post();
107 $this->post->init();
108
109
110 //Init class instances
111 $this->structure = new CNR_Structure();
112 $this->structure->init();
113
114 $this->media = new CNR_Media();
115 $this->media->init();
116
117 $this->feeds = new CNR_Feeds();
118 $this->feeds->init();
119 }
120
121 /* Init */
122
123 /**
124 * Initialize environment
125 * Overrides parent method
126 * @see parent::init_env
127 * @return void
128 */
129 function init_env() {
130 //Localization
131 $ldir = 'l10n';
132 $lpath = $this->util->get_plugin_file_path($ldir, array(false, false));
133 $lpath_abs = $this->util->get_file_path($ldir);
134 if ( is_dir($lpath_abs) ) {
135 load_plugin_textdomain($this->util->get_plugin_textdomain(), false, $lpath);
136 }
137
138 //Context
139 add_action(( is_admin() ) ? 'admin_head' : 'wp_head', $this->m('set_client_context'));
140 }
141
142 /* Methods */
143
144 /*-** Request **-*/
145
146 /**
147 * Output current context to client-side
148 * @uses `wp_head` action hook
149 * @uses `admin_head` action hook
150 * @return void
151 */
152 function set_client_context() {
153 $ctx = new stdClass();
154 $ctx->context = $this->util->get_context();
155 $this->util->extend_client_object($ctx, true);
156 }
157
158 /*-** Child Content **-*/
159
160 /**
161 * Gets children posts of specified page and stores them for later use
162 * This method hooks into 'the_posts' filter to retrieve child posts for any single page retrieved by WP
163 * @return array $posts Posts array (required by 'the_posts' filter)
164 * @param array $posts Array of Posts (@see WP_QUERY)
165 */
166 function post_children_get($posts) {
167 //Global variables
168 global $wp_query;
169
170 //Reset post children collection
171 $this->post_children_collection->init();
172
173 //Stop here if post is not a page
174 if ( ! is_page() || empty($posts) )
175 return $posts;
176
177 //Get children posts
178 $post =& $posts[0];
179 $this->post_children_collection =& CNR_Post::get_children($post);
180
181 //Return posts (required by filter)
182 return $posts;
183 }
184
185 /*-** Featured Content **-*/
186
187 /**
188 * Retrieves featured post category object
189 * @return object Featured post category object
190 * @todo integrate into CNR_Post_Query
191 */
192 function posts_featured_get_cat() {
193 static $cat = null;
194
195 //Only fetch category object if it hasn't already been retrieved
196 if (is_null($cat) || !is_object($cat)) {
197 //Retrieve category object
198 if (is_int($this->posts_featured_cat)) {
199 $cat = get_category((int)$this->posts_featured_cat);
200 }
201 elseif (is_string($this->posts_featured_cat) && strlen($this->posts_featured_cat) > 0) {
202 $cat = get_category_by_slug($this->posts_featured_cat);
203 }
204 }
205
206 return $cat;
207 }
208
209 /**
210 * @todo integrate into CNR_Post_Query
211 */
212 function posts_featured_get_cat_id() {
213 static $id = '';
214 if ($id == '') {
215 $cat = $this->posts_featured_get_cat();
216 if (!is_null($cat) && is_object($cat) && $this->util->property_exists($cat, 'cat_ID'))
217 $id = $cat->cat_ID;
218 }
219 return $id;
220 }
221
222 /**
223 * Checks if post has content to display
224 * @param object $post (optional) Post object
225 * @return bool TRUE if post has content, FALSE otherwise
226 * @todo Review for deletion/relocation
227 */
228 function post_has_content($post = null) {
229 if ( !$this->util->check_post($post) )
230 return false;
231 if ( isset($post->post_content) && trim($post->post_content) != '' )
232 return true;
233 return false;
234 }
235 }
236