PluginProbe
CSS & JavaScript Toolbox / 11.2
CSS & JavaScript Toolbox v11.2
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / controllers / block-ajax.php

block-ajax.php in CSS & JavaScript Toolbox 11.2, at controllers/block-ajax.php

245 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version $ Id; block-ajax.php 21-03-2012 03:22:10 Ahmed Said $
4 */
5
6 // Disallow direct access.
7 defined('ABSPATH') or die("Access denied");
8
9 // import dependencies.
10 cssJSToolbox::import('framework:mvc:controller-ajax.inc.php');
11
12 /**
13 * Server single block OR block specific actions.
14 *
15 * @author Ahmed Said
16 * @version 6
17 * @deprecated DONT ADD MORE ACTIONS. USE CJTBlockController and other controllers instead!
18 */
19 class CJTBlockAjaxController extends CJTAjaxController {
20
21 /**
22 * Initialize controller object.
23 *
24 * @see CJTController for more details
25 * @return void
26 */
27 public function __construct() {
28 parent::__construct();
29 // Supported actions.
30 add_action('wp_ajax_cjtoolbox_get_info_view', array(&$this, '_doAction'));
31 add_action('wp_ajax_cjtoolbox_set_property', array(&$this, '_doAction'));
32 add_action('wp_ajax_cjtoolbox_get_revision', array(&$this, '_doAction'));
33 add_action('wp_ajax_cjtoolbox_get_revisions', array(&$this, '_doAction'));
34 // Redirects
35 $this->registryAction('getBlockBy');
36 $this->registryAction('getAPOP');
37 $this->registryAction('restoreRevision');
38 $this->registryAction('loadUrl');
39 $this->registryAction('downloadCodeFile');
40 $this->registryAction('getAllAssignment');
41 }
42
43 /**
44 * put your comment there...
45 *
46 * @deprecated this is just a redirect to the CJTBlockContoller::getAction().
47 */
48 protected function downloadCodeFileAction() {
49 // Pass to CJTBlockController!
50 $this->redirect('block');
51 }
52
53 /**
54 * put your comment there...
55 *
56 */
57 protected function getAllAssignmentAction() {
58 $this->redirect('block');
59 }
60
61 /**
62 * put your comment there...
63 *
64 * @deprecated this is just a redirect to the CJTBlockContoller::getAction().
65 */
66 protected function getAPOPAction() {
67 // Pass to CJTBlockController!
68 $this->redirect('block');
69 }
70
71 /**
72 * put your comment there...
73 *
74 * @deprecated this is just a redirect to the CJTBlockContoller::getAction().
75 */
76 protected function getBlockByAction() {
77 // Pass to CJTBlockController!
78 $this->redirect('block');
79 }
80
81 /**
82 * put your comment there...
83 *
84 * @deprecated All will be moved to other controllers in the future versions.
85 */
86 public function getInfoViewAction() {
87 $model = $this->getModel('blocks');
88 // Set content type as HTML.
89 $this->httpContentType = "text/html";
90 // Get block info.
91 $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
92 $Info = $model->getInfo($id);
93 // Create info view object.
94 $view = CJTController::getView('blocks/info');
95 // Get view info content.
96 $view->info = $Info;
97 $this->response = $view->getTemplate('default');
98 }
99
100 /**
101 * put your comment there...
102 *
103 * @deprecated All will be moved to other controllers in the future versions.
104 */
105 public function getRevisionAction() {
106 // Initialize
107 $model = $this->getModel('blocks');
108 $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver());
109 // Inputs.
110 $revisionId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
111 // Get request parameters.
112 $revision['id'] = $revisionId;
113 $revision['fields'] = array('id', 'links', 'expressions', 'masterFile');
114 $revision = $model->getBlock($revision['id'], array(), $revision['fields']);
115 // Get revisioned code file.
116 $revision->code = $tblCodeFile->set('blockId', $revisionId)
117 ->set('id', $revision->masterFile)
118 ->load()
119 ->getData()->code;
120 // Discard Pins.
121 $customPins = array_keys( CJTBlockModel::getCustomPins() );
122
123 foreach ( $customPins as $customPinName )
124 {
125 $revision->{$customPinName} = false;
126 }
127
128 // Return revision.
129 $this->response = $revision;
130 }
131
132 /**
133 * put your comment there...
134 *
135 * @deprecated All will be moved to other controllers in the future versions.
136 */
137 public function getRevisionsAction() {
138 // initialize.
139 $model = $this->getModel('blocks');
140 // Get request parameters.
141 $blockId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
142 // Get block revisions.
143 $revisions['filter']['masterFile'] = $_GET['activeFileId'];
144 $revisions['filter']['parent'] = $blockId;
145 $revisions['filter']['type'] = 'revision';
146 // Its mandatory to select fields instead of using just .*.
147 // This is because id field must be first to be used as the array key
148 $revisions['fields'] = array('id', 'name', 'created', 'lastModified', 'owner');
149 // Query getBlocks without ids filter or backup.
150 $revisions = $model->getBlocks(null, $revisions['filter'], $revisions['fields']);
151 // Create view.
152 $view = $this->getView('blocks/revisions');
153 // Push view vars.
154 $view->blockId = $blockId;
155 $view->revisions = array_reverse($revisions);
156 // Set output header.
157 $this->httpContentType = 'text/html';
158 // Return view content.
159 $this->response = $view->getTemplate('default');
160 }
161
162 /**
163 * put your comment there...
164 *
165 * @deprecated this is just a redirect to the CJTBlockContoller::getAction().
166 */
167 protected function loadUrlAction() {
168 // Pass to CJTBlockController!
169 $this->redirect('block');
170 }
171
172 /**
173 * put your comment there...
174 *
175 */
176 protected function restoreRevisionAction() {
177 // Initialize.
178 $mdlBlocks = new CJTBlocksModel();
179 $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver());
180 // Get revision ID.
181 $rId = (int) $_GET['rid'];
182 $bId = (int) $_GET['bid'];
183 // Get Revision Block + Revision Code.
184 $revisionBlock = $mdlBlocks->getBlock($rId, array(), array('id', 'pinPoint', 'links', 'expressions', 'masterFile'));
185 $revisionBlock->code = $tblCodeFile->set('blockId', $rId)
186 ->set('id', $revisionBlock->masterFile)
187 ->load()
188 ->getData()->code;
189 // If code === null set it to empoty string '' as null woulod
190 // prevent the field from being in the query, cause SQL error.
191 if ($revisionBlock->code === null) {
192 $revisionBlock->code = '';
193 }
194 // Code File Fields.
195 $revisionBlock->activeFileId = $revisionBlock->masterFile;
196 $revisionBlock->masterFile = null; // This is just for querying CodeFile. DONT UPDATE.
197 // Restore Block.
198 $revisionBlock->id = $bId;
199 $mdlBlocks->update($revisionBlock, true);
200 $mdlBlocks->save();
201 // Return TRUE.
202 $this->response = true;
203 }
204
205 /**
206 * Update exists block property value.
207 *
208 *
209 * Call this method using POST method with the following parameters.
210 * - id integer Block id.
211 * - property string Property Name to change.
212 * - value mixed Property value to change.
213 *
214 * Response body is array with the following elements.
215 * - string oldValue Old property value.
216 * - string value New value.
217 *
218 * @deprecated
219 * @return void
220 */
221 public function setPropertyAction() {
222 // Initialize.
223 $response = array();
224 $blocks = $this->getModel('blocks');
225 // Prepare parameters.
226 $blockId = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
227 $property = filter_input(INPUT_POST, 'property', FILTER_SANITIZE_STRING);
228 $newValue = filter_input(INPUT_POST, 'value', FILTER_UNSAFE_RAW);
229 // Get old value.
230 $block = $blocks->getBlock($blockId);
231 $oldValue = $block->$property;
232 // Update only if there is a change.
233 if ($oldValue != $newValue) {
234 // Update block property.
235 $block->$property = $newValue;
236 $blocks->setBlock($block);
237 $blocks->save();
238 // Set response object.
239 $response['oldValue'] = $oldValue;
240 $response['value'] = $newValue;
241 }
242 $this->response = $response;
243 }
244
245 } // End class.