| @@ -12,96 +12,77 @@ | ||
| 12 | 12 | require_once CJTOOLBOX_TABLES_PATH . '/blocks.php'; |
| 13 | 13 | require_once CJTOOLBOX_TABLES_PATH . '/block-pins.php'; |
| 14 | 14 | // MYSQL Queue Driver. |
| 15 | 15 | require_once CJTOOLBOX_INCLUDE_PATH . '/db/mysql/queue-driver.inc.php'; |
| 16 | - | |
| 16 | + | |
| 17 | 17 | /** |
| 18 | 18 | * Provide simple access (read or write) to all Blocks data. |
| 19 | -* | |
| 19 | +* | |
| 20 | 20 | * @author Ahmed Said |
| 21 | 21 | * @version 6 |
| 22 | 22 | */ |
| 23 | 23 | class CJTBlocksModel { |
| 24 | - | |
| 24 | + | |
| 25 | 25 | /** |
| 26 | - * | |
| 26 | + * | |
| 27 | 27 | */ |
| 28 | - const MAX_REVISIONS_PER_BLOCK = 99; | |
| 29 | - | |
| 28 | + const MAX_REVISIONS_PER_BLOCK = 10; | |
| 29 | + | |
| 30 | 30 | /** |
| 31 | 31 | * put your comment there... |
| 32 | - * | |
| 32 | + * | |
| 33 | 33 | * @var mixed |
| 34 | 34 | */ |
| 35 | 35 | protected $dbDriver = null; |
| 36 | - | |
| 36 | + | |
| 37 | 37 | /** |
| 38 | 38 | * put your comment there... |
| 39 | - * | |
| 39 | + * | |
| 40 | 40 | */ |
| 41 | 41 | public function __construct() { |
| 42 | 42 | // Initialize CTTTable MYSQL Driver. |
| 43 | 43 | $this->dbDriver = new CJTMYSQLQueueDriver($GLOBALS['wpdb']); |
| 44 | 44 | } |
| 45 | - | |
| 45 | + | |
| 46 | 46 | /** |
| 47 | 47 | * put your comment there... |
| 48 | - * | |
| 49 | - * @param mixed $block | |
| 50 | - * @param mixed $forceAddCodeBlock | |
| 48 | + * | |
| 49 | + * @param mixed $data | |
| 50 | + * @param mixed $pins | |
| 51 | + * @param mixed $customPins | |
| 51 | 52 | */ |
| 52 | - public function add($block, $forceAddCodeBlock = false) { | |
| 53 | + public function add($block) { | |
| 53 | 54 | // Make sure it array and not stdClass as it has been used from various areas! |
| 54 | 55 | $block = (array) $block; |
| 55 | 56 | // Create Tables objects. |
| 56 | 57 | $blocks = new CJTBlocksTable($this->dbDriver); |
| 57 | - $codeFile = new CJTBlockFilesTable($this->dbDriver); | |
| 58 | 58 | // Get new id if not specified. |
| 59 | - if (!isset($block['id']) || !$block['id']) { | |
| 60 | - $block['id'] = $blocks->getNextIdNEW(); | |
| 59 | + if (!$block['id']) { | |
| 60 | + $block['id'] = $blocks->getNextId(); | |
| 61 | 61 | } |
| 62 | - // Backward compatibility for old block style | |
| 63 | - // that has code field inside blocks table. | |
| 64 | - /// if passed create master code file for the code field. | |
| 65 | - if ($forceAddCodeBlock || isset($block['code'])) { | |
| 66 | - // Cache code for MASTER file. | |
| 67 | - $codeFile->set('code', $block['code']); | |
| 68 | - unset($block['code']); // If it passed it mist be removed from blocks data(avoid field not found) | |
| 69 | - // Add code files. | |
| 70 | - $codeFile->set('blockId', $block['id']) | |
| 71 | - ->set('id', 1) | |
| 72 | - ->set('name', 'Master') | |
| 73 | - ->save(true, true); | |
| 74 | - } | |
| 75 | - // Add new block. | |
| 76 | 62 | $blocks->insert($block); |
| 77 | - // Return Newly added block id. | |
| 78 | 63 | return $block['id']; |
| 79 | 64 | } |
| 80 | - | |
| 65 | + | |
| 81 | 66 | /** |
| 82 | 67 | * put your comment there... |
| 83 | - * | |
| 84 | - * @param mixed $blockId | |
| 85 | - * @param mixed $activeFileId | |
| 68 | + * | |
| 69 | + * @param mixed $id | |
| 86 | 70 | */ |
| 87 | - public function addRevision($blockId, $activeFileId) { | |
| 71 | + public function addRevision($blockId) { | |
| 88 | 72 | // Create Tables objects. |
| 89 | 73 | $blocks = new CJTBlocksTable($this->dbDriver); |
| 90 | 74 | $pins = new CJTBlockPinsTable($this->dbDriver); |
| 91 | - $codeFile = new CJTBlockFilesTable($this->dbDriver); | |
| 92 | - // We allow only up to self::MAX_REVISIONS_PER_BLOCK revisions per | |
| 93 | - // block code files So that a single block may has up to | |
| 94 | - // self::MAX_REVISIONS_PER_BLOCK * count(codeFiles) | |
| 75 | + // We allow only up to self::MAX_REVISIONS_PER_BLOCK revisions per block. | |
| 95 | 76 | $revisions['fields'] = array('id'); |
| 96 | - $revisions['filters'] = array('type' => 'revision', 'parent' => $blockId, 'masterFile' => $activeFileId); | |
| 77 | + $revisions['filters'] = array('type' => 'revision', 'parent' => $blockId); | |
| 97 | 78 | $revisions = $blocks->get(null, $revisions['fields'], $revisions['filters']); |
| 98 | 79 | // If revisions reached self::MAX_REVISIONS_PER_BLOCK delete first one. |
| 99 | 80 | if (count($revisions) == self::MAX_REVISIONS_PER_BLOCK) { |
| 100 | 81 | $this->delete(array_shift($revisions)->id); |
| 101 | 82 | } |
| 102 | - // Get block data. | |
| 103 | - $block['fields'] = array('id', 'lastModified', 'pinPoint', 'links', 'expressions'); | |
| 83 | + // Get block data. | |
| 84 | + $block['fields'] = array('id', 'lastModified', 'pinPoint', 'code', 'links', 'expressions'); | |
| 104 | 85 | // get() developed to return multiple blocks, fetch the first. |
| 105 | 86 | $result = $blocks->get($blockId, $block['fields']); |
| 106 | 87 | $block = reset($result); |
| 107 | 88 | // Set other fields. |
| @@ -109,12 +90,9 @@ | ||
| 109 | 90 | $block->parent = $blockId; |
| 110 | 91 | $block->type = 'revision'; |
| 111 | 92 | $block->created = current_time('mysql'); |
| 112 | 93 | $block->owner = get_current_user_id(); |
| 113 | - $block->masterFile = $activeFileId; // Only the revisioned code file would be exists and must be | |
| 114 | - // used as the masterFile! | |
| 115 | - //$block->id = $blocks->getNextId(); // Get new id for revision rrecord. | |
| 116 | - $block->id = $blocks->getNextIdNEW(); // Get new id for revision rrecord. | |
| 94 | + $block->id = $blocks->getNextId(); // Get new id for revision rrecord. | |
| 117 | 95 | // Add block data. |
| 118 | 96 | $blocks->insert($block); |
| 119 | 97 | // Get block pins and insert pins for the revision block. |
| 120 | 98 | $blockPins = $pins->get($blockId); |
| @@ -120,42 +98,29 @@ | ||
| 120 | 98 | $blockPins = $pins->get($blockId); |
| 121 | 99 | if (!empty($blockPins)) { |
| 122 | 100 | $pins->insertRaw($block->id, $blockPins); |
| 123 | 101 | } |
| 124 | - // Revision current ActiveFileId code record. | |
| 125 | - // Simply, get a copy of it from the target block | |
| 126 | - // and assign the copy to the new created block revision. | |
| 127 | - $codeFile->set('id', $activeFileId) | |
| 128 | - ->set('blockId', $blockId) | |
| 129 | - ->load() | |
| 130 | - ->set('blockId', $block->id) | |
| 131 | - ->save(true, true); | |
| 132 | 102 | } |
| 133 | - | |
| 103 | + | |
| 134 | 104 | /** |
| 135 | 105 | * Put your comments here... |
| 136 | 106 | * |
| 137 | 107 | * |
| 138 | - * @return | |
| 139 | - */ | |
| 108 | + * @return | |
| 109 | + */ | |
| 140 | 110 | public function dbDriver() { |
| 141 | 111 | return $this->dbDriver; |
| 142 | 112 | } |
| 143 | - | |
| 113 | + | |
| 144 | 114 | /** |
| 145 | 115 | * put your comment there... |
| 146 | - * | |
| 116 | + * | |
| 147 | 117 | * @param mixed $ids |
| 148 | 118 | */ |
| 149 | 119 | public function delete($ids) { |
| 150 | - // Allow single or multiple Ids to be passed. | |
| 151 | - if (!is_array($ids)) { | |
| 152 | - $ids = array($ids); | |
| 153 | - } | |
| 154 | 120 | // Create Tables objects. |
| 155 | 121 | $blocks = new CJTBlocksTable($this->dbDriver); |
| 156 | 122 | $pins = new CJTBlockPinsTable($this->dbDriver); |
| 157 | - $codeFile = new CJTBlockFilesTable($this->dbDriver); | |
| 158 | 123 | // Get blocks revisions. |
| 159 | 124 | $revisions['fields'] = array('id'); |
| 160 | 125 | $revisions['filters']['parent'] = $ids; |
| 161 | 126 | $revisions['type'] = 'revision'; |
| @@ -166,79 +131,19 @@ | ||
| 166 | 131 | // only if there is at least one revision. |
| 167 | 132 | if (!empty($revisions)) { |
| 168 | 133 | $blocks->delete($revisions); |
| 169 | 134 | $pins->delete($revisions); |
| 170 | - // Delete code files. | |
| 171 | - $this->dbDriver->delete(sprintf('DELETE FROM #__cjtoolbox_block_files WHERE blockId IN(%s)', implode(',', $revisions))); | |
| 172 | 135 | } |
| 173 | - // Delete linked templates. | |
| 174 | - $linkedOnlyTemplatesQuery = 'DELETE FROM #__cjtoolbox_block_templates WHERE blockId IN(%s)'; | |
| 175 | - $this->dbDriver->delete(sprintf($linkedOnlyTemplatesQuery, implode(',', $ids))); | |
| 176 | - // Delete associated parameters. | |
| 177 | - $mdlParams = new CJT_Models_Parameters(); | |
| 178 | - $mdlParams->delete($ids); | |
| 179 | - // Delete form. | |
| 180 | - $mdlForm = new CJT_Models_Forms(); | |
| 181 | - $mdlForm->delete($ids); | |
| 182 | 136 | // Delete blocks. |
| 183 | 137 | $blocks->delete($ids); |
| 184 | 138 | $pins->delete($ids); |
| 185 | - // Delete code files. | |
| 186 | - $this->dbDriver->delete(sprintf('DELETE FROM #__cjtoolbox_block_files WHERE blockId IN(%s)', implode(',', $ids))); | |
| 187 | 139 | // Chaining! |
| 188 | 140 | return $this; |
| 189 | 141 | } |
| 190 | - | |
| 191 | - /** | |
| 192 | - * put your comment there... | |
| 193 | - * | |
| 194 | - * @param mixed $block | |
| 195 | - */ | |
| 196 | - public static function getAllAssignments($block) { | |
| 197 | - | |
| 198 | - $inPages = $block->pages ? $block->pages : []; | |
| 199 | - $inPosts = $block->posts ? $block->posts : []; | |
| 200 | - $inCats = $block->categories ? $block->categories : []; | |
| 201 | - $inTags = $block->post_tags ? $block->post_tags : []; | |
| 202 | - $inLinks = ! empty( $block->links ) ? explode( "\n", $block->links ) : []; | |
| 203 | - $inExps = ! empty( $block->expressions ) ? explode( "\n", $block->expressions ) : []; | |
| 204 | - $inAux = array(); | |
| 205 | - | |
| 206 | - // Found selected Aux | |
| 207 | - $auxFlags = array( | |
| 208 | - CJTBlockModel::PINS_404_ERROR, | |
| 209 | - CJTBlockModel::PINS_ARCHIVE, | |
| 210 | - CJTBlockModel::PINS_ATTACHMENT, | |
| 211 | - CJTBlockModel::PINS_AUTHOR, | |
| 212 | - CJTBlockModel::PINS_BACKEND, | |
| 213 | - CJTBlockModel::PINS_CATEGORIES_ALL_CATEGORIES, | |
| 214 | - CJTBlockModel::PINS_EXPRESSIONS, | |
| 215 | - CJTBlockModel::PINS_FRONTEND, | |
| 216 | - CJTBlockModel::PINS_PAGES_ALL_PAGES, | |
| 217 | - CJTBlockModel::PINS_POSTS_ALL_POSTS, | |
| 218 | - CJTBlockModel::PINS_POSTS_BLOG_INDEX, | |
| 219 | - CJTBlockModel::PINS_POSTS_RECENT, | |
| 220 | - CJTBlockModel::PINS_SEARCH, | |
| 221 | - CJTBlockModel::PINS_TAG | |
| 222 | - ); | |
| 223 | - | |
| 224 | - foreach ($auxFlags as $auxFlag) { | |
| 225 | - | |
| 226 | - if ($auxFlag & $block->pinPoint) { | |
| 227 | - | |
| 228 | - $inAux[] = $auxFlag; | |
| 229 | - } | |
| 230 | - | |
| 231 | - } | |
| 232 | - | |
| 233 | - $allAssignment = array_merge( $inPages, $inPosts, $inCats, $inTags, $inLinks, $inExps, $inAux ); | |
| 234 | - | |
| 235 | - return $allAssignment; | |
| 236 | - } | |
| 237 | - | |
| 142 | + | |
| 238 | 143 | /** |
| 239 | 144 | * put your comment there... |
| 240 | - * | |
| 145 | + * | |
| 241 | 146 | * @param mixed $id |
| 242 | 147 | * @param mixed $fields |
| 243 | 148 | */ |
| 244 | 149 | public function getBlock($id, $filters = array(), $fields = array('*'), $useDefaultBackupFltr = true) { |
| @@ -245,23 +150,19 @@ | ||
| 245 | 150 | $blocks = $this->getBlocks($id, $filters, $fields, OBJECT_K, array(), $useDefaultBackupFltr); |
| 246 | 151 | $block = !empty($blocks) ? reset($blocks) : null; |
| 247 | 152 | return $block; |
| 248 | 153 | } |
| 249 | - | |
| 154 | + | |
| 250 | 155 | /** |
| 251 | 156 | * put your comment there... |
| 252 | - * | |
| 157 | + * | |
| 253 | 158 | * @param mixed $ids |
| 254 | 159 | */ |
| 255 | 160 | public function getBlocks($ids = array(), $filters = array(), $fields = array('*'), $returnType = OBJECT_K, $orderBy = array(), $useDefaultBackupFltr = true) { |
| 256 | - // initialize. | |
| 257 | 161 | $blocks = array(); |
| 258 | - $returnCodeFile = isset($filters['returnCodeFile']) && ($filters['returnCodeFile'] == true); | |
| 259 | - unset($filters['returnCodeFile']); | |
| 260 | 162 | // Create Tables objects. |
| 261 | 163 | $blocksTable = new CJTBlocksTable($this->dbDriver); |
| 262 | 164 | $pinsTable = new CJTBlockPinsTable($this->dbDriver); |
| 263 | - $blockFiles = new CJTBlockFilesTable($this->dbDriver); | |
| 264 | 165 | // Read blocks. |
| 265 | 166 | $blocks = $blocksTable->get($ids, $fields, $filters, $returnType, $orderBy, $useDefaultBackupFltr); |
| 266 | 167 | // Get only pins for retrieved blocks. |
| 267 | 168 | $ids = array_keys($blocks); |
| @@ -272,130 +173,14 @@ | ||
| 272 | 173 | // Each pin is an array. |
| 273 | 174 | // e.g blocks[ID]->pages[] = PAGE-ID. |
| 274 | 175 | $blocks[$pin->blockId]->{$pin->pin}[] = $pin->value; |
| 275 | 176 | } |
| 276 | - // Get active file code. | |
| 277 | - // There always should be active file unless that the | |
| 278 | - // requested block is never switched by current author before. | |
| 279 | - // However we'll do that only if filters['returnCodeFile'] set to TRUE. | |
| 280 | - if ($returnCodeFile) { | |
| 281 | - foreach ($ids as $id) { | |
| 282 | - if(!$activeFileId = $this->getCurrentAuthorBlockActiveFileId($id)) { | |
| 283 | - // If first time use masterFile ID as he default. | |
| 284 | - $activeFileId = $blocks[$id]->masterFile; | |
| 285 | - } | |
| 286 | - // Retreive code for block code file. | |
| 287 | - $codeFile = (array) $blockFiles->setData(array('blockId' => $id, 'id' => $activeFileId)) | |
| 288 | - ->load() | |
| 289 | - ->getData(); | |
| 290 | - unset($codeFile['description']); | |
| 291 | - $blocks[$id]->file = (object) $codeFile; | |
| 292 | - // Also return the active file id withing the set. | |
| 293 | - $blocks[$id]->activeFileId = $activeFileId; | |
| 294 | - } | |
| 295 | - } | |
| 296 | 177 | return $blocks; |
| 297 | 178 | } |
| 298 | - | |
| 179 | + | |
| 299 | 180 | /** |
| 300 | 181 | * put your comment there... |
| 301 | - * | |
| 302 | - * @param mixed $blockId | |
| 303 | - * @param mixed $authorId | |
| 304 | - */ | |
| 305 | - public function getAuthorBlockActiveFileId($blockId, $authorId = null) { | |
| 306 | - // Get author active file for the requested block. | |
| 307 | - $activeFileId = (int) get_user_meta($authorId, "cjt_block_active_file_{$blockId}", true); | |
| 308 | - // Query block active file. | |
| 309 | - return $activeFileId; | |
| 310 | - } | |
| 311 | - | |
| 312 | - /** | |
| 313 | - * put your comment there... | |
| 314 | - * | |
| 315 | - * @param mixed $blockId | |
| 316 | - */ | |
| 317 | - public static function getCodeFilesCount($blockId) { | |
| 318 | - | |
| 319 | - global $wpdb; | |
| 320 | - | |
| 321 | - $query = " SELECT count(*) | |
| 322 | - FROM {$wpdb->prefix}cjtoolbox_block_files f | |
| 323 | - WHERE f.blockId = %d;"; | |
| 324 | - | |
| 325 | - $query = $wpdb->prepare($query, $blockId); | |
| 326 | - | |
| 327 | - $codeFilesCount = $wpdb->get_var($query); | |
| 328 | - | |
| 329 | - return $codeFilesCount; | |
| 330 | - } | |
| 331 | - | |
| 332 | - /** | |
| 333 | - * put your comment there... | |
| 334 | - * | |
| 335 | - * @param mixed $blockId | |
| 336 | - * @param mixed $authorId | |
| 337 | - */ | |
| 338 | - public function getCurrentAuthorBlockActiveFileId($blockId) { | |
| 339 | - return $this->getAuthorBlockActiveFileId($blockId, get_current_user_id()); | |
| 340 | - } | |
| 341 | - | |
| 342 | - /** | |
| 343 | - * put your comment there... | |
| 344 | - * | |
| 345 | - */ | |
| 346 | - public static function getCustomPostTypes() | |
| 347 | - { | |
| 348 | - | |
| 349 | - static $postTypes = null; | |
| 350 | - | |
| 351 | - if ( $postTypes !== null ) | |
| 352 | - { | |
| 353 | - return $postTypes; | |
| 354 | - } | |
| 355 | - | |
| 356 | - | |
| 357 | - $postTypes = array(); | |
| 358 | - | |
| 359 | - // Create tabs for every custom post under the custom posts tab. | |
| 360 | - // Get all registered custom posts. | |
| 361 | - $customPosts = get_post_types( array( 'public' => 1, 'show_ui' => true, '_builtin' => false ), 'objects' ); | |
| 362 | - | |
| 363 | - // Add tab for every custom post | |
| 364 | - // Exclude 'Empty' Custom Post Types. | |
| 365 | - foreach ( $customPosts as $typeName => $customPost ) | |
| 366 | - { | |
| 367 | - // Check if has posts. | |
| 368 | - $hasPosts = count( get_posts( array( 'post_type' => $typeName, 'offset' => 0, 'numberposts' => 1 ) ) ); | |
| 369 | - | |
| 370 | - // Add only types with at least one post exists. | |
| 371 | - if ( $hasPosts ) | |
| 372 | - { | |
| 373 | - $postTypes[ $typeName ] = array | |
| 374 | - ( | |
| 375 | - 'title' => $customPost->labels->name, | |
| 376 | - 'renderer' => 'objects-list', | |
| 377 | - 'type' => array | |
| 378 | - ( | |
| 379 | - 'type' => $typeName, | |
| 380 | - 'group' => 'posts', | |
| 381 | - 'targetType' => 'post' | |
| 382 | - ) | |
| 383 | - | |
| 384 | - ); | |
| 385 | - | |
| 386 | - } | |
| 387 | - | |
| 388 | - } | |
| 389 | - | |
| 390 | - do_action( CJTPluggableHelper::ACTION_BLOCK_CUSTOM_POST_TYPES, $postTypes ); | |
| 391 | - | |
| 392 | - return $postTypes; | |
| 393 | - } | |
| 394 | - | |
| 395 | - /** | |
| 396 | - * put your comment there... | |
| 397 | - * | |
| 182 | + * | |
| 398 | 183 | * @param mixed $id |
| 399 | 184 | */ |
| 400 | 185 | public function getInfo($id) { |
| 401 | 186 | // Info fields. |
| @@ -409,28 +194,28 @@ | ||
| 409 | 194 | // Set shortcode name. |
| 410 | 195 | $info->shortcode = "[cjtoolbox name='{$info->name}']"; |
| 411 | 196 | return $info; |
| 412 | 197 | } |
| 413 | - | |
| 198 | + | |
| 414 | 199 | /** |
| 415 | 200 | * put your comment there... |
| 416 | - * | |
| 201 | + * | |
| 417 | 202 | */ |
| 418 | 203 | public function getOrder() { |
| 419 | 204 | return get_option('meta-box-order_cjtoolbox'); |
| 420 | 205 | } |
| 421 | - | |
| 206 | + | |
| 422 | 207 | /** |
| 423 | 208 | * put your comment there... |
| 424 | - * | |
| 209 | + * | |
| 425 | 210 | */ |
| 426 | 211 | public function save() { |
| 427 | 212 | $this->dbDriver->processQueue(); |
| 428 | 213 | } |
| 429 | - | |
| 214 | + | |
| 430 | 215 | /** |
| 431 | 216 | * put your comment there... |
| 432 | - * | |
| 217 | + * | |
| 433 | 218 | * @param mixed $order |
| 434 | 219 | */ |
| 435 | 220 | public function setOrder($order) { |
| 436 | 221 | $orderOptionName = 'meta-box-order_cjtoolbox'; |
| @@ -438,52 +223,27 @@ | ||
| 438 | 223 | update_user_option(get_current_user_id(), $orderOptionName, $order, true); |
| 439 | 224 | // Update CENTRALIZED order in the options table! |
| 440 | 225 | update_option($orderOptionName, $order); |
| 441 | 226 | } |
| 442 | - | |
| 227 | + | |
| 443 | 228 | /** |
| 444 | 229 | * put your comment there... |
| 445 | - * | |
| 230 | + * | |
| 446 | 231 | * @param mixed $block |
| 447 | 232 | */ |
| 448 | - public function update( $block, $updatePins ) | |
| 449 | - { | |
| 450 | - | |
| 451 | - $block = ( array ) $block; | |
| 452 | - | |
| 453 | - $blocks = new CJTBlocksTable( $this->dbDriver ); | |
| 454 | - $pins = new CJTBlockPinsTable( $this->dbDriver ); | |
| 455 | - | |
| 233 | + public function update($block, $updatePins) { | |
| 234 | + $block = (array) $block; // To be used by array_intersect_key. | |
| 235 | + // Create Tables objects. | |
| 236 | + $blocks = new CJTBlocksTable($this->dbDriver); | |
| 237 | + $pins = new CJTBlockPinsTable($this->dbDriver); | |
| 456 | 238 | // Update block pins if requested. |
| 457 | - if ( $updatePins ) | |
| 458 | - { | |
| 239 | + if ($updatePins) { | |
| 459 | 240 | // Isolate block pins freom native block data. |
| 460 | - $pinsData = array_intersect_key( $block, array_flip( array_keys( CJTBlockModel::getCustomPins() ) ) ); | |
| 461 | - | |
| 462 | - do_action( CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK_PINS, $block, $pinsData ); | |
| 463 | - | |
| 464 | - $pins->update( $block[ 'id' ], $pinsData ); | |
| 465 | - | |
| 241 | + $pinsData = array_intersect_key($block, array_flip(array('pages', 'posts', 'categories'))); | |
| 242 | + $pins->update($block['id'], $pinsData); | |
| 466 | 243 | } |
| 467 | - | |
| 468 | - // Update code file | |
| 469 | - if ( isset( $block[ 'activeFileId' ] ) ) | |
| 470 | - { | |
| 471 | - | |
| 472 | - $codeFile = new CJTBlockFilesTable( $this->dbDriver ); | |
| 473 | - | |
| 474 | - $codeFile->set( 'blockId', $block[ 'id' ] ) | |
| 475 | - ->set( 'id', $block[ 'activeFileId'] ) | |
| 476 | - ->set( 'code', $block[ 'code'] ) | |
| 477 | - ->save(); | |
| 478 | - } | |
| 479 | - | |
| 480 | 244 | // Isolate block fields. |
| 481 | - $blockData = array_intersect_key($block, $blocks->getFields()); | |
| 482 | - | |
| 483 | - do_action( CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK, $updatePins, $blockData ); | |
| 484 | - | |
| 485 | - $blocks->update( $blockData ); | |
| 486 | - | |
| 245 | + $block = array_intersect_key($block, $blocks->getFields()); | |
| 246 | + $blocks->update($block); | |
| 487 | 247 | } |
| 488 | - | |
| 248 | + | |
| 489 | 249 | } // End class. |