PluginProbe
CSS & JavaScript Toolbox / 6.0.9
CSS & JavaScript Toolbox v6.0.9
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 6.0.9, at controllers/block-ajax.php

149 lines 4.5 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 }
37
38 /**
39 * put your comment there...
40 *
41 * @deprecated this is just a redirect to the CJTBlockContoller::getAction().
42 */
43 protected function getBlockByAction() {
44 // Pass to CJTBlockController!
45 $this->redirect('block');
46 }
47
48 /**
49 * put your comment there...
50 *
51 * @deprecated All will be moved to other controllers in the future versions.
52 */
53 public function getInfoViewAction() {
54 $model = $this->getModel('blocks');
55 // Set content type as HTML.
56 $this->httpContentType = "text/html";
57 // Get block info.
58 $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
59 $Info = $model->getInfo($id);
60 // Create info view object.
61 $view = CJTController::getView('blocks/info');
62 // Get view info content.
63 $view->info = $Info;
64 $this->response = $view->getTemplate('default');
65 }
66
67 /**
68 * put your comment there...
69 *
70 * @deprecated All will be moved to other controllers in the future versions.
71 */
72 public function getRevisionAction() {
73 $model = $this->getModel('blocks');
74 // Get request parameters.
75 $revision['id'] = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
76 $revision['fields'] = array('id', 'code', 'pinPoint', 'links', 'expressions');
77 $revision = $model->getBlock($revision['id'], array(), $revision['fields']);
78 $this->response = $revision;
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 getRevisionsAction() {
87 $model = $this->getModel('blocks');
88 // Get request parameters.
89 $blockId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
90 // Get block revisions.
91 $revisions['filter']['parent'] = $blockId;
92 $revisions['filter']['type'] = 'revision';
93 // Its mandatory to select fields instead of using just .*.
94 // This is because id field must be first to be used as the array key
95 $revisions['fields'] = array('id', 'name', 'created', 'lastModified', 'owner');
96 // Query getBlocks without ids filter or backup.
97 $revisions = $model->getBlocks(null, $revisions['filter'], $revisions['fields']);
98 // Create view.
99 $view = $this->getView('blocks/revisions');
100 // Push view vars.
101 $view->blockId = $blockId;
102 $view->revisions = $revisions;
103 // Set output header.
104 $this->httpContentType = 'text/html';
105 // Return view content.
106 $this->response = $view->getTemplate('default');
107 }
108
109 /**
110 * Update exists block property value.
111 *
112 *
113 * Call this method using POST method with the following parameters.
114 * - id integer Block id.
115 * - property string Property Name to change.
116 * - value mixed Property value to change.
117 *
118 * Response body is array with the following elements.
119 * - string oldValue Old property value.
120 * - string value New value.
121 *
122 * @deprecated
123 * @return void
124 */
125 public function setPropertyAction() {
126 // Initialize.
127 $response = array();
128 $blocks = $this->getModel('blocks');
129 // Prepare parameters.
130 $blockId = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
131 $property = filter_input(INPUT_POST, 'property', FILTER_SANITIZE_STRING);
132 $newValue = filter_input(INPUT_POST, 'value', FILTER_UNSAFE_RAW);
133 // Get old value.
134 $block = $blocks->getBlock($blockId);
135 $oldValue = $block->$property;
136 // Update only if there is a change.
137 if ($oldValue != $newValue) {
138 // Update block property.
139 $block->$property = $newValue;
140 $blocks->setBlock($block);
141 $blocks->save();
142 // Set response object.
143 $response['oldValue'] = $oldValue;
144 $response['value'] = $newValue;
145 }
146 $this->response = $response;
147 }
148
149 } // End class.