PluginProbe
CSS & JavaScript Toolbox / 8.3
CSS & JavaScript Toolbox v8.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/block.php +104 -103 108.3 View file →
@@ -14,11 +14,11 @@
14 14 require_once CJTOOLBOX_MVC_FRAMEWOK . '/model.inc.php';
15 15
16 16 /**
17 17 * Represent single block object.
18 -*
18 +*
19 19 * Provide simple access read or write to block properties.
20 -*
20 +*
21 21 * @author Ahmed Said
22 22 * @version 6
23 23 */
24 24 class CJTBlockModel extends CJTModel {
@@ -27,9 +27,9 @@
27 27 * Global scope pins
28 28 */
29 29 const PINS_FRONTEND = 0x01;
30 30 const PINS_BACKEND = 0x02;
31 -
31 +
32 32 /**
33 33 * Pages Pins.
34 34 */
35 35 const PINS_PAGES_ALL_PAGES = 0x10;
@@ -34,23 +34,23 @@
34 34 */
35 35 const PINS_PAGES_ALL_PAGES = 0x10;
36 36 const PINS_PAGES_CUSTOM_PAGE = 0x20;
37 37 const PINS_PAGES_FRONT_PAGE = 0x40;
38 -
38 +
39 39 /**
40 40 * Posts Pins.
41 - */
41 + */
42 42 const PINS_POSTS_ALL_POSTS = 0x100;
43 43 const PINS_POSTS_CUSTOM_POST = 0x200;
44 44 const PINS_POSTS_RECENT = 0x400;
45 45 const PINS_POSTS_BLOG_INDEX = 0x800;
46 -
46 +
47 47 /**
48 48 * Categories Pins.
49 49 */
50 50 const PINS_CATEGORIES_ALL_CATEGORIES = 0x1000;
51 51 const PINS_CATEGORIES_CUSTOM_CATEGORY = 0x2000;
52 -
52 +
53 53 /**
54 54 * Other general pages pins.
55 55 */
56 56 const PINS_SEARCH = 0x10000;
@@ -58,30 +58,30 @@
58 58 const PINS_TAG = 0x40000;
59 59 const PINS_AUTHOR = 0x80000;
60 60 const PINS_ATTACHMENT = 0x100000;
61 61 const PINS_404_ERROR = 0x200000;
62 -
62 +
63 63 /**
64 - *
64 + *
65 65 */
66 66 const PINS_LINKS = 0x1000000;
67 67 const PINS_EXPRESSIONS = 0x2000000;
68 -
68 +
69 69 /**
70 - *
70 + *
71 71 */
72 72 const PINS_LINK_EXPRESSION = 0x3000000;
73 -
73 +
74 74 /**
75 75 * put your comment there...
76 - *
76 + *
77 77 * @var mixed
78 78 */
79 79 private static $customPins;
80 -
80 +
81 81 /**
82 82 * put your comment there...
83 - *
83 + *
84 84 * @var mixed
85 85 */
86 86 private $propertiesMeta = array
87 87 (
@@ -93,93 +93,94 @@
93 93 'links' => array(),
94 94 'expressions' => array(),
95 95 'id' => array(),
96 96 );
97 -
97 +
98 98 /**
99 99 * Create block object.
100 - *
100 + *
101 101 * @param integer Block id.
102 102 * @param array Block data array or null to use default data.
103 103 * @return void
104 104 */
105 - public function __construct( $values = array() )
105 + public function __construct( $values = array() )
106 106 {
107 107 // Allow pluggable custom pins
108 108 $customPins = self::getCustomPins();
109 -
109 +
110 110 // Allow pluggable fields
111 111 $this->propertiesMeta = apply_filters( CJTPluggableHelper::FILTER_BLOCK_MODEL_PROPERTIES_META, $this->propertiesMeta );
112 -
112 +
113 113 // Merge prpperties meta wioth custom pins to create one full propertiesMeta objetc
114 114 // that hold both fields and custom pins fields
115 115 $this->propertiesMeta = array_merge( $this->propertiesMeta, $customPins );
116 -
117 - // Properties backward compatibolity to hold all available properties
118 - $this->properties = array_combine(
119 -
120 - array_keys( $this->propertiesMeta ),
121 -
122 - array_fill( 0, count( $this->propertiesMeta ), null )
123 -
116 +
117 + // Properties backward compatibolity to hold all available properties
118 + $this->properties = array_combine(
119 +
120 + array_keys( $this->propertiesMeta ),
121 +
122 + array_fill( 0, count( $this->propertiesMeta ), null )
123 +
124 124 );
125 -
125 +
126 126 // Set block properties.
127 127 $this->setValues( $values );
128 128 }
129 -
129 +
130 130 /**
131 131 * Get block property value.
132 - *
132 + *
133 133 * @param string Property name.
134 134 * @return mixed Property value.
135 135 */
136 136 public function __get( $property )
137 137 {
138 +
138 139 // Return default values
139 - $value = ( isset( $this->properties[ $property ] ) && ( $this->properties[ $property ] === null ) &&
140 - ( isset( $this->propertiesMeta[ $property ][ 'default' ] ) ) ) ?
141 -
140 + $value = ( ( $this->properties[ $property ] === null ) &&
141 + ( isset( $this->propertiesMeta[ $property ][ 'default' ] ) ) ) ?
142 +
142 143 $this->propertiesMeta[ $property ][ 'default' ] :
143 - ( $this->properties[ $property ] ?? null );
144 -
144 + $this->properties[ $property ];
145 +
145 146 return $value;
146 147 }
147 -
148 +
148 149 /**
149 150 * Set block proprty value.
150 - *
151 + *
151 152 * @param string Property name.
152 153 * @param mixed Property value.
153 154 * @return void
154 155 */
155 - public function __set($property, $value)
156 + public function __set($property, $value)
156 157 {
157 - switch ( $property )
158 + switch ( $property )
158 159 {
159 160 case 'code':
160 -
161 +
161 162 case 'links':
162 -
163 +
163 164 case 'expressions':
164 -
165 +
165 166 // New lines submitted to server as CRLF but displayed in browser as LF.
166 167 // PHP script and JS work on two different versions of texts.
167 168 // Replace CRLF with LF just as displayed in browsers.
168 169 $value = preg_replace( "/\x0D\x0A/", "\x0A", $value );
169 -
170 +
170 171 break;
171 172 }
172 -
173 +
173 174 $this->properties[ $property ] = $value;
174 175 }
175 -
176 +
176 177 /**
177 178 * put your comment there...
178 - *
179 + *
179 180 * @param mixed $blockData
180 181 */
181 - public static function arrangePins( & $blockData )
182 + public static function arrangePins( & $blockData )
182 183 {
183 184
184 185 $pinsGroupNames = array_flip( array_merge( array_keys( self::getCustomPins() ), array( 'pinPoint' ) ) );
185 186 $dbDriver = cssJSToolbox::getInstance()->getDBDriver();
@@ -186,38 +187,38 @@
186 187 $mdlBlock = new CJTBlocksModel();
187 188 $block = $mdlBlock->getBlock( $blockData->id, array(), array( 'id', 'pinPoint' ) );
188 189 $submittedPins = array_intersect_key( ( ( array ) $blockData ), $pinsGroupNames );
189 190 $assignedPins = array_intersect_key( ( ( array ) $block ), $pinsGroupNames );
190 -
191 +
191 192 // Transfer assigned PinPoint from "FLAGGED INTEGER" TO "ARRAY" like
192 193 // the other pins.
193 194 $assignedPins[ 'pinPoint' ] = array_keys( CJT_Models_Block_Assignmentpanel_Helpers_Auxiliary
194 195 ::getInstance()
195 196 ->getPinsArray( $assignedPins[ 'pinPoint' ] ) );
196 -
197 +
197 198 // Walk through all assigned pins.
198 199 // Unassigned any item with 'value=false'.
199 200 // Whenever an item is found on the submitted
200 201 // pins it should be removed from the submitted list
201 - foreach ( $submittedPins as $groupName => $submittedGroup )
202 + foreach ( $submittedPins as $groupName => $submittedGroup )
202 203 {
203 - // Get assigned pins group if found
204 - if ( ! isset( $assignedPins[ $groupName ] ) )
204 + // Get assigned pins group if found
205 + if ( ! isset( $assignedPins[ $groupName ] ) )
205 206 {
206 207 // Initialize new assigned group array.
207 208 $assignedPins[ $groupName ] = array();
208 209 }
209 -
210 +
210 211 $assignedGroup =& $assignedPins[ $groupName ];
211 -
212 +
212 213 // For every submitted item there is three types.
213 214 // 1. Already assigned :WHEN: (sync == true and value == true)
214 215 // 2. Unassigned :WHEN: (value == false)
215 216 // 3. Newly assigned :WHEN: (sync = false).
216 - foreach ( $submittedGroup as $submittedPinId => $submittedPin )
217 + foreach ( $submittedGroup as $submittedPinId => $submittedPin )
217 218 {
218 219 // Unassigned pin
219 - if ( ! $submittedPin[ 'value' ] )
220 + if ( ! $submittedPin[ 'value' ] )
220 221 {
221 222 // Find the submittedPinId AssignedPins index.
222 223 $assignedIndex = array_search( $submittedPinId, $assignedGroup );
223 224 // Unassigned it :REMOVE FROM ARRAY:
@@ -222,24 +223,24 @@
222 223 $assignedIndex = array_search( $submittedPinId, $assignedGroup );
223 224 // Unassigned it :REMOVE FROM ARRAY:
224 225 unset( $assignedGroup[ $assignedIndex ] );
225 226 }
226 - else if ( ! $submittedPin[ 'sync' ] )
227 + else if ( ! $submittedPin[ 'sync' ] )
227 228 {
228 229 // Add newly assigned item.
229 230 $assignedGroup[] = $submittedPinId;
230 231 }
231 -
232 +
232 233 }
233 -
234 +
234 235 }
235 -
236 +
236 237 // Copy all assigned pins back to the block object.
237 238 foreach ( $assignedPins as $groupName => $finalGroupAssigns )
238 239 {
239 240 $blockData->{$groupName} = $finalGroupAssigns;
240 241 }
241 -
242 +
242 243 // Important for caller short-circle condition.
243 244 return true;
244 245 }
245 246
@@ -244,37 +245,37 @@
244 245 }
245 246
246 247 /**
247 248 * put your comment there...
248 - *
249 + *
249 250 * @deprecated Use calculatePinpoint
250 251 */
251 - public static function calculateBlockPinPoint( & $block )
252 + public static function calculateBlockPinPoint( & $block )
252 253 {
253 -
254 +
254 255 // Generate PinPoint Value.
255 - if ( isset( $block->pinPoint ) && is_array( $block->pinPoint ) )
256 + if ( isset( $block->pinPoint ) && is_array( $block->pinPoint ) )
256 257 {
257 258 $pinPoint = 0;
258 -
259 +
259 260 // Each item is a bit flag.
260 - foreach ( $block->pinPoint as $pin )
261 + foreach ( $block->pinPoint as $pin )
261 262 {
262 263 $pinPoint |= hexdec($pin);
263 264 }
264 -
265 +
265 266 }
266 - else
267 + else
267 268 {
268 269 // Provided as integer or not even provided!
269 - if ( ! isset( $block->pinPoint ) )
270 + if ( ! isset( $block->pinPoint ) )
270 271 {
271 272 $block->pinPoint = 0;
272 273 }
273 -
274 +
274 275 $pinPoint = (int) $block->pinPoint;
275 276 }
276 -
277 +
277 278 // Pin should be set only for not empty properties.
278 279 // This help us retreiving only needed blocks when querying blocks code.
279 280 $pins = array
280 281 (
@@ -280,11 +281,11 @@
280 281 (
281 282 self::PINS_LINKS => 'links',
282 283 self::PINS_EXPRESSIONS => 'expressions',
283 284 );
284 -
285 +
285 286 $customPins = self::getCustomPins();
286 -
287 +
287 288 // Add Custom Pins to pins to be calculated below
288 289 foreach ( $customPins as $customPinName => $customPin )
289 290 {
290 291 $pins[ $customPin[ 'pinValue' ] ] = $customPinName;
@@ -289,73 +290,73 @@
289 290 {
290 291 $pins[ $customPin[ 'pinValue' ] ] = $customPinName;
291 292 }
292 293
293 - foreach ( $pins as $flag => $pin )
294 + foreach ( $pins as $flag => $pin )
294 295 {
295 296 $pinPoint |= abs( ( int ) ( ! empty( $block->{$pin} ) ) ) * $flag;
296 297 }
297 -
298 +
298 299 $block->pinPoint = $pinPoint;
299 -
300 +
300 301 return $block;
301 302 }
302 -
303 +
303 304 /**
304 305 * put your comment there...
305 - *
306 + *
306 307 * @param mixed $block
307 308 * @param mixed $pins
308 309 */
309 - public static function calculatePinPoint( $block, $pins )
310 + public static function calculatePinPoint( $block, $pins )
310 311 {
311 312 // Add pins to Block object so that calculateBlockPinPoint can calculate PinPoint value!
312 313 $block = ( object ) array_merge( $block, $pins );
313 -
314 +
314 315 $pinPoint = self::calculateBlockPinPoint( $block )->pinPoint;
315 -
316 +
316 317 return $pinPoint;
317 318 }
318 319
319 320 /**
320 321 * put your comment there...
321 - *
322 + *
322 323 */
323 324 public static function getCustomPins()
324 325 {
325 326 static $pins = array
326 - (
327 + (
327 328 'pages' => array
328 - (
329 -
329 + (
330 +
330 331 'default' => array(),
331 - 'pinValue' => self::PINS_PAGES_CUSTOM_PAGE
332 -
332 + 'pinValue' => self::PINS_PAGES_CUSTOM_PAGE
333 +
333 334 ),
334 -
335 +
335 336 'posts' => array
336 - (
337 -
337 + (
338 +
338 339 'default' => array(),
339 - 'pinValue' => self::PINS_POSTS_CUSTOM_POST
340 -
340 + 'pinValue' => self::PINS_POSTS_CUSTOM_POST
341 +
341 342 ),
342 -
343 +
343 344 'categories' => array
344 - (
345 -
345 + (
346 +
346 347 'default' => array(),
347 - 'pinValue' => self::PINS_CATEGORIES_CUSTOM_CATEGORY
348 -
348 + 'pinValue' => self::PINS_CATEGORIES_CUSTOM_CATEGORY
349 +
349 350 ),
350 351 );
351 -
352 +
352 353 // Cache custom pins
353 354 if ( ! self::$customPins )
354 355 {
355 - self::$customPins = apply_filters( CJTPluggableHelper::FILTER_BLOCK_MODEL_CUSTOM_PINS, $pins );
356 + self::$customPins = apply_filters( CJTPluggableHelper::FILTER_BLOCK_MODEL_CUSTOM_PINS, $pins );
356 357 }
357 -
358 +
358 359 return self::$customPins;
359 360 }
360 -
361 +
361 362 } // End class.