| @@ -45,12 +45,13 @@ | ||
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * put your comment there... |
| 48 | 48 | * |
| 49 | - * @param mixed $block | |
| 50 | - * @param mixed $forceAddCodeBlock | |
| 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); |
| @@ -58,23 +59,18 @@ | ||
| 58 | 59 | // Get new id if not specified. |
| 59 | 60 | if (!isset($block['id']) || !$block['id']) { |
| 60 | 61 | $block['id'] = $blocks->getNextId(); |
| 61 | 62 | } |
| 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 | - } | |
| 63 | + // Cache code for MASTER file. | |
| 64 | + $codeFile->set('code', (isset($block['code']) ? $block['code'] : null)); | |
| 65 | + unset($block['code']); // If it passed it mist be removed from blocks data(avoid field not found) | |
| 75 | 66 | // Add new block. |
| 76 | 67 | $blocks->insert($block); |
| 68 | + // Add code files. | |
| 69 | + $codeFile->set('blockId', $block['id']) | |
| 70 | + ->set('id', 1) | |
| 71 | + ->set('name', 'Master') | |
| 72 | + ->save(true, true); | |
| 77 | 73 | // Return Newly added block id. |
| 78 | 74 | return $block['id']; |
| 79 | 75 | } |
| 80 | 76 | |
| @@ -273,61 +269,8 @@ | ||
| 273 | 269 | |
| 274 | 270 | /** |
| 275 | 271 | * put your comment there... |
| 276 | 272 | * |
| 277 | - */ | |
| 278 | - public static function getCustomPostTypes() | |
| 279 | - { | |
| 280 | - | |
| 281 | - static $postTypes = null; | |
| 282 | - | |
| 283 | - if ( $postTypes !== null ) | |
| 284 | - { | |
| 285 | - return $postTypes; | |
| 286 | - } | |
| 287 | - | |
| 288 | - | |
| 289 | - $postTypes = array(); | |
| 290 | - | |
| 291 | - // Create tabs for every custom post under the custom posts tab. | |
| 292 | - // Get all registered custom posts. | |
| 293 | - $customPosts = get_post_types( array( 'public' => 1, 'show_ui' => true, '_builtin' => false ), 'objects' ); | |
| 294 | - | |
| 295 | - // Add tab for every custom post | |
| 296 | - // Exclude 'Empty' Custom Post Types. | |
| 297 | - foreach ( $customPosts as $typeName => $customPost ) | |
| 298 | - { | |
| 299 | - // Check if has posts. | |
| 300 | - $hasPosts = count( get_posts( array( 'post_type' => $typeName, 'offset' => 0, 'numberposts' => 1 ) ) ); | |
| 301 | - | |
| 302 | - // Add only types with at least one post exists. | |
| 303 | - if ( $hasPosts ) | |
| 304 | - { | |
| 305 | - $postTypes[ $typeName ] = array | |
| 306 | - ( | |
| 307 | - 'title' => $customPost->labels->name, | |
| 308 | - 'renderer' => 'objects-list', | |
| 309 | - 'type' => array | |
| 310 | - ( | |
| 311 | - 'type' => $typeName, | |
| 312 | - 'group' => 'posts', | |
| 313 | - 'targetType' => 'post' | |
| 314 | - ) | |
| 315 | - | |
| 316 | - ); | |
| 317 | - | |
| 318 | - } | |
| 319 | - | |
| 320 | - } | |
| 321 | - | |
| 322 | - do_action( CJTPluggableHelper::ACTION_BLOCK_CUSTOM_POST_TYPES, $postTypes ); | |
| 323 | - | |
| 324 | - return $postTypes; | |
| 325 | - } | |
| 326 | - | |
| 327 | - /** | |
| 328 | - * put your comment there... | |
| 329 | - * | |
| 330 | 273 | * @param mixed $id |
| 331 | 274 | */ |
| 332 | 275 | public function getInfo($id) { |
| 333 | 276 | // Info fields. |
| @@ -376,46 +319,30 @@ | ||
| 376 | 319 | * put your comment there... |
| 377 | 320 | * |
| 378 | 321 | * @param mixed $block |
| 379 | 322 | */ |
| 380 | - public function update( $block, $updatePins ) | |
| 381 | - { | |
| 382 | - | |
| 383 | - $block = ( array ) $block; | |
| 384 | - | |
| 385 | - $blocks = new CJTBlocksTable( $this->dbDriver ); | |
| 386 | - $pins = new CJTBlockPinsTable( $this->dbDriver ); | |
| 387 | - | |
| 323 | + public function update($block, $updatePins) { | |
| 324 | + // To be used by array_intersect_key. | |
| 325 | + $block = (array) $block; | |
| 326 | + // Create Tables objects. | |
| 327 | + $blocks = new CJTBlocksTable($this->dbDriver); | |
| 328 | + $pins = new CJTBlockPinsTable($this->dbDriver); | |
| 388 | 329 | // Update block pins if requested. |
| 389 | - if ( $updatePins ) | |
| 390 | - { | |
| 330 | + if ($updatePins) { | |
| 391 | 331 | // Isolate block pins freom native block data. |
| 392 | - $pinsData = array_intersect_key( $block, array_flip( array_keys( CJTBlockModel::getCustomPins() ) ) ); | |
| 393 | - | |
| 394 | - do_action( CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK_PINS, $block, $pinsData ); | |
| 395 | - | |
| 396 | - $pins->update( $block[ 'id' ], $pinsData ); | |
| 397 | - | |
| 332 | + $pinsData = array_intersect_key($block, array_flip(array('pages', 'posts', 'categories'))); | |
| 333 | + $pins->update($block['id'], $pinsData); | |
| 398 | 334 | } |
| 399 | - | |
| 400 | 335 | // Update code file |
| 401 | - if ( isset( $block[ 'activeFileId' ] ) ) | |
| 402 | - { | |
| 403 | - | |
| 404 | - $codeFile = new CJTBlockFilesTable( $this->dbDriver ); | |
| 405 | - | |
| 406 | - $codeFile->set( 'blockId', $block[ 'id' ] ) | |
| 407 | - ->set( 'id', $block[ 'activeFileId'] ) | |
| 408 | - ->set( 'code', $block[ 'code'] ) | |
| 336 | + if (isset($block['activeFileId'])) { | |
| 337 | + $codeFile = new CJTBlockFilesTable($this->dbDriver); | |
| 338 | + $codeFile->set('blockId', $block['id']) | |
| 339 | + ->set('id', $block['activeFileId']) | |
| 340 | + ->set('code', $block['code']) | |
| 409 | 341 | ->save(); |
| 410 | 342 | } |
| 411 | - | |
| 412 | 343 | // Isolate block fields. |
| 413 | 344 | $blockData = array_intersect_key($block, $blocks->getFields()); |
| 414 | - | |
| 415 | - do_action( CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK, $updatePins, $blockData ); | |
| 416 | - | |
| 417 | - $blocks->update( $blockData ); | |
| 418 | - | |
| 345 | + $blocks->update($blockData); | |
| 419 | 346 | } |
| 420 | 347 | |
| 421 | 348 | } // End class. |