/
cms.php
executable file
·249 lines (198 loc) · 6.25 KB
/
cms.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?
/**
* Class: CMS_Controller
* The main CMS class, handling add, delete, and retrieval of pages
* @author Matthew Shultz
* @version 1.0
* @package Kororor
*/
class MOP_CMS extends MOP_CMSInterface {
protected $_actionsThatGetLayout = array(
'index',
);
/*
* Variable: page_id
* static int the global page id when operating within the CMS submodules get the page id
* we could just reference the primaryId attribute of Display as well...
*/
private static $objectId = NULL;
/*
* Variable: unique
* Used to provide unique ids for radio buttons and other input elements
*/
private static $unique = 1;
/*
Variable: model
The main data model for content stored by this module
*/
private $model = 'page';
/*
*
* Variable: modules
* Build the cms's included modules
*
*/
protected $defaulttemplate='mop_cms';
/*
Function: __constructor
Loads subModules to build from config
*/
public function __construct($request, $response){
parent::__construct($request, $response);
$this->modules = Kohana::config('cms.subModules');
$this->loadResources('mop_cms');
}
public function action_index(){
$this->view = new View('mop_cms');
if(Auth::instance()->logged_in('superuser')){
$this->view->userlevel = 'superuser';
} else {
$this->view->userlevel = 'basic';
}
$this->assignObjectId();
//basically this is an issue with wanting to have multiple things going on
//with the same controller as a parent at runtime
$this->view->navigation = Request::factory(Kohana::config($this->controllerName.'.navigationRequest'))->execute()->body();
$this->response->body($this->view->render());
//$this->outputLayout(); //consider using AFTER for this, but need to know whats up with ajax, etc
//can we route through a layout controller???
}
/*
* Function: setPageId($page_id)
* Sets the page id of the object currently being edited
* Parameters:
* page_id - the page id
* Returns: nothing
*/
private function setPageId($page_id){
if(self::$objectId == NULL){
self::$objectId = $page_id;
}
}
/*
* Function: getPageId()
* Returns the page id of the object currently being edited
* Parameters: none
* Returns: page id
*/
public static function getPageId(){
return self::$objectId;
}
/*
Function: getPage(id)
Builds the editing page for the object currenlty being edited
Parameters:
id - the page id to be retrieved
Returns: array('html'=>html, 'js'=>js, 'css'=>css)
*/
public function action_getPage($id){
self::$objectId = $id;
$controller = $id;
if(Kohana::find_file('controllers', $controller)){
//needs to be recoded
$controller = $id.'_Controller';
$controller = new $controller;
$controller->createIndexView();
$return = array();
$return['html']= $controller->render();
$return['css'] = array_values(array_merge($controller->view->resources['librarycss'], $controller->view->resources['css']));
$return['js'] = array_values(array_merge($controller->view->resources['libraryjs'], $controller->view->resources['js']));
return $return;
}
$page = ORM::factory('page', $id);
if($page->id == 0){
throw new Kohana_User_Exception('Invalid Page Id '.$id);
}
//new generation of page
//1 grap cms_nodetitle
$this->nodetitle = new View('mop_cms_nodetitle');
$this->nodetitle->title = $page->contenttable->title; //this should change to page table
$this->nodetitle->slug = $page->slug;
$this->nodetitle->allowDelete = $page->template->allowDelete;
$this->nodetitle->allowTitleEdit = ($page->template->allowTitleEdit == "true" ? true : false);
$settings = Kohana::config('cms.defaultsettings');
if(is_array($settings)){
foreach($settings as $key=>$value){
$this->nodetitle->$key = $value;
}
}
//and get settings for specific template
$settings = Kohana::config('cms.'.$page->template->templatename.'.defaultsettings');
if(is_array($settings)){
foreach($settings as $key=>$value){
$this->nodetitle->$key = $value;
}
}
$nodetitlehtml = $this->nodetitle->render();
$customview = 'templates/'.$page->template->templatename; //check for custom view for this template
$htmlChunks = mopcms::buildUIHtmlChunksForObject($page);
$usecustomview = false;
if(Kohana::find_file('views', $customview)){
$usecustomview = true;
}
if(!$usecustomview){
$html = $nodetitlehtml.implode($htmlChunks);
} else {
$html = $nodetitlehtml;
$view = new View($customview);
$view->loadResources();
foreach($htmlChunks as $key=>$value){
$view->$key = $value;
}
$html .= $view->render();
}
$this->response->body($html);
}
public function action_addchild($id, $template_id){
Kohana::$log->add(Log::ERROR, var_export($_POST, true));
Kohana::$log->add(Log::ERROR, var_export($_FILES, true));
$data = $_POST;
$newId = mopcms::addObject($id, $template_id, $data);
$this->response->data($newId);
}
public function action_save($id){
}
/*
* Function: associate
* Associate an object to another object
*/
public function action_associate($objectId){
//gotta issue here
}
/*
Function: addObject($id)
Public interface for adding an object to the cms data
Parameters:
id - the id of the parent category
template_id - the type of object to add
title - optional title for initialization
$_POST - possible array of keys and values to initialize with
Returns: nav controller node object
*/
public function action_addObject($id, $template_id, $title=null){
$data = $_POST;
if($title){
$data['title'] = $title;
}
$newid = mopcms::addObject($id, $template_id, $data);
//Dial up associated navi and ask for details
$nav_controller = ucfirst($this->modules['navigation']).'_Controller';
$nav_controller = new $nav_controller();
return $nav_controller->getNode($newid);
}
public function assignObjectId(){
//get the default
if(!self::$objectId){ //this allows for the controller to force it,
//but the below initialization should happen first in the future
if(!Request::initial()->param('id')){
self::$objectId = null;
} else {
self::$objectId = Request::initial()->param('id');
}
}
$page = ORM::Factory('page', self::$objectId);
self::$objectId = $page->id; //make sure we're storing id and not slug
$this->view->objectId = $page->id;
}
}
?>