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