| @@ -32,15 +32,39 @@ | ||
| 32 | 32 | add_action('wp_ajax_cjtoolbox_get_revision', array(&$this, '_doAction')); |
| 33 | 33 | add_action('wp_ajax_cjtoolbox_get_revisions', array(&$this, '_doAction')); |
| 34 | 34 | // Redirects |
| 35 | 35 | $this->registryAction('getBlockBy'); |
| 36 | + $this->registryAction('getAPOP'); | |
| 37 | + $this->registryAction('restoreRevision'); | |
| 38 | + $this->registryAction('loadUrl'); | |
| 39 | + $this->registryAction('downloadCodeFile'); | |
| 36 | 40 | } |
| 37 | - | |
| 41 | + | |
| 38 | 42 | /** |
| 39 | 43 | * put your comment there... |
| 40 | 44 | * |
| 41 | 45 | * @deprecated this is just a redirect to the CJTBlockContoller::getAction(). |
| 42 | 46 | */ |
| 47 | + protected function downloadCodeFileAction() { | |
| 48 | + // Pass to CJTBlockController! | |
| 49 | + $this->redirect('block'); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * put your comment there... | |
| 54 | + * | |
| 55 | + * @deprecated this is just a redirect to the CJTBlockContoller::getAction(). | |
| 56 | + */ | |
| 57 | + protected function getAPOPAction() { | |
| 58 | + // Pass to CJTBlockController! | |
| 59 | + $this->redirect('block'); | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * put your comment there... | |
| 64 | + * | |
| 65 | + * @deprecated this is just a redirect to the CJTBlockContoller::getAction(). | |
| 66 | + */ | |
| 43 | 67 | protected function getBlockByAction() { |
| 44 | 68 | // Pass to CJTBlockController! |
| 45 | 69 | $this->redirect('block'); |
| 46 | 70 | } |
| @@ -69,13 +93,27 @@ | ||
| 69 | 93 | * |
| 70 | 94 | * @deprecated All will be moved to other controllers in the future versions. |
| 71 | 95 | */ |
| 72 | 96 | public function getRevisionAction() { |
| 97 | + // Initialize | |
| 73 | 98 | $model = $this->getModel('blocks'); |
| 99 | + $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver()); | |
| 100 | + // Inputs. | |
| 101 | + $revisionId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); | |
| 74 | 102 | // Get request parameters. |
| 75 | - $revision['id'] = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); | |
| 76 | - $revision['fields'] = array('id', 'code', 'pinPoint', 'links', 'expressions'); | |
| 103 | + $revision['id'] = $revisionId; | |
| 104 | + $revision['fields'] = array('id', 'links', 'expressions', 'masterFile'); | |
| 77 | 105 | $revision = $model->getBlock($revision['id'], array(), $revision['fields']); |
| 106 | + // Get revisioned code file. | |
| 107 | + $revision->code = $tblCodeFile->set('blockId', $revisionId) | |
| 108 | + ->set('id', $revision->masterFile) | |
| 109 | + ->load() | |
| 110 | + ->getData()->code; | |
| 111 | + // Discard Pins. | |
| 112 | + $revision->pages = false; | |
| 113 | + $revision->posts = false; | |
| 114 | + $revision->categories = false; | |
| 115 | + // Return revision. | |
| 78 | 116 | $this->response = $revision; |
| 79 | 117 | } |
| 80 | 118 | |
| 81 | 119 | /** |
| @@ -83,12 +121,14 @@ | ||
| 83 | 121 | * |
| 84 | 122 | * @deprecated All will be moved to other controllers in the future versions. |
| 85 | 123 | */ |
| 86 | 124 | public function getRevisionsAction() { |
| 125 | + // initialize. | |
| 87 | 126 | $model = $this->getModel('blocks'); |
| 88 | 127 | // Get request parameters. |
| 89 | 128 | $blockId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
| 90 | 129 | // Get block revisions. |
| 130 | + $revisions['filter']['masterFile'] = $_GET['activeFileId']; | |
| 91 | 131 | $revisions['filter']['parent'] = $blockId; |
| 92 | 132 | $revisions['filter']['type'] = 'revision'; |
| 93 | 133 | // Its mandatory to select fields instead of using just .*. |
| 94 | 134 | // This is because id field must be first to be used as the array key |
| @@ -104,9 +144,52 @@ | ||
| 104 | 144 | $this->httpContentType = 'text/html'; |
| 105 | 145 | // Return view content. |
| 106 | 146 | $this->response = $view->getTemplate('default'); |
| 107 | 147 | } |
| 108 | - | |
| 148 | + | |
| 149 | + /** | |
| 150 | + * put your comment there... | |
| 151 | + * | |
| 152 | + * @deprecated this is just a redirect to the CJTBlockContoller::getAction(). | |
| 153 | + */ | |
| 154 | + protected function loadUrlAction() { | |
| 155 | + // Pass to CJTBlockController! | |
| 156 | + $this->redirect('block'); | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * put your comment there... | |
| 161 | + * | |
| 162 | + */ | |
| 163 | + protected function restoreRevisionAction() { | |
| 164 | + // Initialize. | |
| 165 | + $mdlBlocks = new CJTBlocksModel(); | |
| 166 | + $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver()); | |
| 167 | + // Get revision ID. | |
| 168 | + $rId = (int) $_GET['rid']; | |
| 169 | + $bId = (int) $_GET['bid']; | |
| 170 | + // Get Revision Block + Revision Code. | |
| 171 | + $revisionBlock = $mdlBlocks->getBlock($rId, array(), array('id', 'pinPoint', 'links', 'expressions', 'masterFile')); | |
| 172 | + $revisionBlock->code = $tblCodeFile->set('blockId', $rId) | |
| 173 | + ->set('id', $revisionBlock->masterFile) | |
| 174 | + ->load() | |
| 175 | + ->getData()->code; | |
| 176 | + // If code === null set it to empoty string '' as null woulod | |
| 177 | + // prevent the field from being in the query, cause SQL error. | |
| 178 | + if ($revisionBlock->code === null) { | |
| 179 | + $revisionBlock->code = ''; | |
| 180 | + } | |
| 181 | + // Code File Fields. | |
| 182 | + $revisionBlock->activeFileId = $revisionBlock->masterFile; | |
| 183 | + $revisionBlock->masterFile = null; // This is just for querying CodeFile. DONT UPDATE. | |
| 184 | + // Restore Block. | |
| 185 | + $revisionBlock->id = $bId; | |
| 186 | + $mdlBlocks->update($revisionBlock, true); | |
| 187 | + $mdlBlocks->save(); | |
| 188 | + // Return TRUE. | |
| 189 | + $this->response = true; | |
| 190 | + } | |
| 191 | + | |
| 109 | 192 | /** |
| 110 | 193 | * Update exists block property value. |
| 111 | 194 | * |
| 112 | 195 | * |