PluginProbe
CSS & JavaScript Toolbox / 9.3
CSS & JavaScript Toolbox v9.3
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
← All changes | models/blocks.php +71 -139 12.09.3 View file →
@@ -12,41 +12,41 @@
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 - *
48 + *
49 49 * @param mixed $block
50 50 * @param mixed $forceAddCodeBlock
51 51 */
52 52 public function add($block, $forceAddCodeBlock = false) {
@@ -56,9 +56,9 @@
56 56 $blocks = new CJTBlocksTable($this->dbDriver);
57 57 $codeFile = new CJTBlockFilesTable($this->dbDriver);
58 58 // Get new id if not specified.
59 59 if (!isset($block['id']) || !$block['id']) {
60 - $block['id'] = $blocks->getNextIdNEW();
60 + $block['id'] = $blocks->getNextId();
61 61 }
62 62 // Backward compatibility for old block style
63 63 // that has code field inside blocks table.
64 64 /// if passed create master code file for the code field.
@@ -76,12 +76,12 @@
76 76 $blocks->insert($block);
77 77 // Return Newly added block id.
78 78 return $block['id'];
79 79 }
80 -
80 +
81 81 /**
82 82 * put your comment there...
83 - *
83 + *
84 84 * @param mixed $blockId
85 85 * @param mixed $activeFileId
86 86 */
87 87 public function addRevision($blockId, $activeFileId) {
@@ -89,9 +89,9 @@
89 89 $blocks = new CJTBlocksTable($this->dbDriver);
90 90 $pins = new CJTBlockPinsTable($this->dbDriver);
91 91 $codeFile = new CJTBlockFilesTable($this->dbDriver);
92 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
93 + // block code files So that a single block may has up to
94 94 // self::MAX_REVISIONS_PER_BLOCK * count(codeFiles)
95 95 $revisions['fields'] = array('id');
96 96 $revisions['filters'] = array('type' => 'revision', 'parent' => $blockId, 'masterFile' => $activeFileId);
97 97 $revisions = $blocks->get(null, $revisions['fields'], $revisions['filters']);
@@ -98,9 +98,9 @@
98 98 // If revisions reached self::MAX_REVISIONS_PER_BLOCK delete first one.
99 99 if (count($revisions) == self::MAX_REVISIONS_PER_BLOCK) {
100 100 $this->delete(array_shift($revisions)->id);
101 101 }
102 - // Get block data.
102 + // Get block data.
103 103 $block['fields'] = array('id', 'lastModified', 'pinPoint', 'links', 'expressions');
104 104 // get() developed to return multiple blocks, fetch the first.
105 105 $result = $blocks->get($blockId, $block['fields']);
106 106 $block = reset($result);
@@ -109,12 +109,11 @@
109 109 $block->parent = $blockId;
110 110 $block->type = 'revision';
111 111 $block->created = current_time('mysql');
112 112 $block->owner = get_current_user_id();
113 - $block->masterFile = $activeFileId; // Only the revisioned code file would be exists and must be
113 + $block->masterFile = $activeFileId; // Only the revisioned code file would be exists and must be
114 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.
115 + $block->id = $blocks->getNextId(); // Get new id for revision rrecord.
117 116 // Add block data.
118 117 $blocks->insert($block);
119 118 // Get block pins and insert pins for the revision block.
120 119 $blockPins = $pins->get($blockId);
@@ -129,22 +128,22 @@
129 128 ->load()
130 129 ->set('blockId', $block->id)
131 130 ->save(true, true);
132 131 }
133 -
132 +
134 133 /**
135 134 * Put your comments here...
136 135 *
137 136 *
138 - * @return
139 - */
137 + * @return
138 + */
140 139 public function dbDriver() {
141 140 return $this->dbDriver;
142 141 }
143 -
142 +
144 143 /**
145 144 * put your comment there...
146 - *
145 + *
147 146 * @param mixed $ids
148 147 */
149 148 public function delete($ids) {
150 149 // Allow single or multiple Ids to be passed.
@@ -186,59 +185,12 @@
186 185 $this->dbDriver->delete(sprintf('DELETE FROM #__cjtoolbox_block_files WHERE blockId IN(%s)', implode(',', $ids)));
187 186 // Chaining!
188 187 return $this;
189 188 }
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 -
189 +
238 190 /**
239 191 * put your comment there...
240 - *
192 + *
241 193 * @param mixed $id
242 194 * @param mixed $fields
243 195 */
244 196 public function getBlock($id, $filters = array(), $fields = array('*'), $useDefaultBackupFltr = true) {
@@ -245,12 +197,12 @@
245 197 $blocks = $this->getBlocks($id, $filters, $fields, OBJECT_K, array(), $useDefaultBackupFltr);
246 198 $block = !empty($blocks) ? reset($blocks) : null;
247 199 return $block;
248 200 }
249 -
201 +
250 202 /**
251 203 * put your comment there...
252 - *
204 + *
253 205 * @param mixed $ids
254 206 */
255 207 public function getBlocks($ids = array(), $filters = array(), $fields = array('*'), $returnType = OBJECT_K, $orderBy = array(), $useDefaultBackupFltr = true) {
256 208 // initialize.
@@ -294,12 +246,12 @@
294 246 }
295 247 }
296 248 return $blocks;
297 249 }
298 -
250 +
299 251 /**
300 252 * put your comment there...
301 - *
253 + *
302 254 * @param mixed $blockId
303 255 * @param mixed $authorId
304 256 */
305 257 public function getAuthorBlockActiveFileId($blockId, $authorId = null) {
@@ -308,31 +260,11 @@
308 260 // Query block active file.
309 261 return $activeFileId;
310 262 }
311 263
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 264 /**
333 265 * put your comment there...
334 - *
266 + *
335 267 * @param mixed $blockId
336 268 * @param mixed $authorId
337 269 */
338 270 public function getCurrentAuthorBlockActiveFileId($blockId) {
@@ -340,23 +272,23 @@
340 272 }
341 273
342 274 /**
343 275 * put your comment there...
344 - *
276 + *
345 277 */
346 278 public static function getCustomPostTypes()
347 279 {
348 -
280 +
349 281 static $postTypes = null;
350 -
282 +
351 283 if ( $postTypes !== null )
352 284 {
353 285 return $postTypes;
354 286 }
355 -
356 -
287 +
288 +
357 289 $postTypes = array();
358 -
290 +
359 291 // Create tabs for every custom post under the custom posts tab.
360 292 // Get all registered custom posts.
361 293 $customPosts = get_post_types( array( 'public' => 1, 'show_ui' => true, '_builtin' => false ), 'objects' );
362 294
@@ -361,15 +293,15 @@
361 293 $customPosts = get_post_types( array( 'public' => 1, 'show_ui' => true, '_builtin' => false ), 'objects' );
362 294
363 295 // Add tab for every custom post
364 296 // Exclude 'Empty' Custom Post Types.
365 - foreach ( $customPosts as $typeName => $customPost )
297 + foreach ( $customPosts as $typeName => $customPost )
366 298 {
367 - // Check if has posts.
299 + // Check if has posts.
368 300 $hasPosts = count( get_posts( array( 'post_type' => $typeName, 'offset' => 0, 'numberposts' => 1 ) ) );
369 -
301 +
370 302 // Add only types with at least one post exists.
371 - if ( $hasPosts )
303 + if ( $hasPosts )
372 304 {
373 305 $postTypes[ $typeName ] = array
374 306 (
375 307 'title' => $customPost->labels->name,
@@ -374,28 +306,28 @@
374 306 (
375 307 'title' => $customPost->labels->name,
376 308 'renderer' => 'objects-list',
377 309 'type' => array
378 - (
310 + (
379 311 'type' => $typeName,
380 312 'group' => 'posts',
381 313 'targetType' => 'post'
382 314 )
383 -
315 +
384 316 );
385 -
317 +
386 318 }
387 -
319 +
388 320 }
389 321
390 322 do_action( CJTPluggableHelper::ACTION_BLOCK_CUSTOM_POST_TYPES, $postTypes );
391 -
323 +
392 324 return $postTypes;
393 325 }
394 -
326 +
395 327 /**
396 328 * put your comment there...
397 - *
329 + *
398 330 * @param mixed $id
399 331 */
400 332 public function getInfo($id) {
401 333 // Info fields.
@@ -409,28 +341,28 @@
409 341 // Set shortcode name.
410 342 $info->shortcode = "[cjtoolbox name='{$info->name}']";
411 343 return $info;
412 344 }
413 -
345 +
414 346 /**
415 347 * put your comment there...
416 - *
348 + *
417 349 */
418 350 public function getOrder() {
419 351 return get_option('meta-box-order_cjtoolbox');
420 352 }
421 -
353 +
422 354 /**
423 355 * put your comment there...
424 - *
356 + *
425 357 */
426 358 public function save() {
427 359 $this->dbDriver->processQueue();
428 360 }
429 -
361 +
430 362 /**
431 363 * put your comment there...
432 - *
364 + *
433 365 * @param mixed $order
434 366 */
435 367 public function setOrder($order) {
436 368 $orderOptionName = 'meta-box-order_cjtoolbox';
@@ -438,52 +370,52 @@
438 370 update_user_option(get_current_user_id(), $orderOptionName, $order, true);
439 371 // Update CENTRALIZED order in the options table!
440 372 update_option($orderOptionName, $order);
441 373 }
442 -
374 +
443 375 /**
444 376 * put your comment there...
445 - *
377 + *
446 378 * @param mixed $block
447 379 */
448 - public function update( $block, $updatePins )
380 + public function update( $block, $updatePins )
449 381 {
450 -
382 +
451 383 $block = ( array ) $block;
452 -
384 +
453 385 $blocks = new CJTBlocksTable( $this->dbDriver );
454 386 $pins = new CJTBlockPinsTable( $this->dbDriver );
455 -
387 +
456 388 // Update block pins if requested.
457 - if ( $updatePins )
389 + if ( $updatePins )
458 390 {
459 391 // Isolate block pins freom native block data.
460 392 $pinsData = array_intersect_key( $block, array_flip( array_keys( CJTBlockModel::getCustomPins() ) ) );
461 -
393 +
462 394 do_action( CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK_PINS, $block, $pinsData );
463 -
395 +
464 396 $pins->update( $block[ 'id' ], $pinsData );
465 397
466 398 }
467 -
399 +
468 400 // Update code file
469 - if ( isset( $block[ 'activeFileId' ] ) )
401 + if ( isset( $block[ 'activeFileId' ] ) )
470 402 {
471 -
403 +
472 404 $codeFile = new CJTBlockFilesTable( $this->dbDriver );
473 -
405 +
474 406 $codeFile->set( 'blockId', $block[ 'id' ] )
475 407 ->set( 'id', $block[ 'activeFileId'] )
476 408 ->set( 'code', $block[ 'code'] )
477 409 ->save();
478 410 }
479 -
411 +
480 412 // Isolate block fields.
481 413 $blockData = array_intersect_key($block, $blocks->getFields());
482 -
414 +
483 415 do_action( CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK, $updatePins, $blockData );
484 -
416 +
485 417 $blocks->update( $blockData );
486 -
418 +
487 419 }
488 -
420 +
489 421 } // End class.