PluginProbe
CSS & JavaScript Toolbox / 6.0.15
CSS & JavaScript Toolbox v6.0.15
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
css-javascript-toolbox / models / block.php

block.php in CSS & JavaScript Toolbox 6.0.15, at models/block.php

193 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version $ Id; block-ajax.php 21-03-2012 03:22:10 Ahmed Said $
4 */
5
6 /**
7 * No direct access.
8 */
9 defined('ABSPATH') or die("Access denied");
10
11 /**
12 * Model base class.
13 */
14 require_once CJTOOLBOX_MVC_FRAMEWOK . '/model.inc.php';
15
16 /**
17 * Represent single block object.
18 *
19 * Provide simple access read or write to block properties.
20 *
21 * @author Ahmed Said
22 * @version 6
23 */
24 class CJTBlockModel extends CJTModel {
25
26 /**
27 * Global scope pins
28 */
29 const PINS_FRONTEND = 0x01;
30 const PINS_BACKEND = 0x02;
31
32 /**
33 * Pages Pins.
34 */
35 const PINS_PAGES_ALL_PAGES = 0x10;
36 const PINS_PAGES_CUSTOM_PAGE = 0x20;
37 const PINS_PAGES_FRONT_PAGE = 0x40;
38
39 /**
40 * Posts Pins.
41 */
42 const PINS_POSTS_ALL_POSTS = 0x100;
43 const PINS_POSTS_CUSTOM_POST = 0x200;
44 const PINS_POSTS_RECENT = 0x400;
45 const PINS_POSTS_BLOG_INDEX = 0x800;
46
47 /**
48 * Categories Pins.
49 */
50 const PINS_CATEGORIES_ALL_CATEGORIES = 0x1000;
51 const PINS_CATEGORIES_CUSTOM_CATEGORY = 0x2000;
52
53 /**
54 * Other general pages pins.
55 */
56 const PINS_SEARCH = 0x10000;
57 const PINS_ARCHIVE = 0x20000;
58 const PINS_TAG = 0x40000;
59 const PINS_AUTHOR = 0x80000;
60 const PINS_ATTACHMENT = 0x100000;
61 const PINS_404_ERROR = 0x200000;
62
63 /**
64 *
65 */
66 const PINS_LINKS = 0x1000000;
67 const PINS_EXPRESSIONS = 0x2000000;
68
69 /**
70 *
71 */
72 const PINS_LINK_EXPRESSION = 0x3000000;
73
74 /**
75 * Create block object.
76 *
77 * @param integer Block id.
78 * @param array Block data array or null to use default data.
79 * @return void
80 */
81 public function __construct($values = array()) {
82 $this->properties = array(
83 'name' => null,
84 'pinPoint' => null,
85 'state' => null,
86 'location' => null,
87 'code' => null,
88 'pages' => null,
89 'posts' => null,
90 'categories' => null,
91 'links' => null,
92 'expressions' => null,
93 'id' => null,
94 );
95 // Set block properties.
96 $this->setValues($values);
97 }
98
99 /**
100 * Get block property value.
101 *
102 * @param string Property name.
103 * @return mixed Property value.
104 */
105 public function __get($property) {
106 switch ($property) {
107 case 'pages':
108 case 'posts':
109 case 'categories':
110 $value = ($this->properties[$property] !== null) ? $this->properties[$property] : array();
111 break;
112
113 default:
114 $value = $this->properties[$property];
115 break;
116 }
117 return $value;
118 }
119
120 /**
121 * Set block proprty value.
122 *
123 * @param string Property name.
124 * @param mixed Property value.
125 * @return void
126 */
127 public function __set($property, $value) {
128 switch ($property) {
129 case 'code':
130 case 'links':
131 case 'expressions':
132 // New lines submitted to server as CRLF but displayed in browser as LF.
133 // PHP script and JS work on two different versions of texts.
134 // Replace CRLF with LF just as displayed in browsers.
135 $value = preg_replace("/\x0D\x0A/", "\x0A", $value);
136 break;
137 }
138 $this->properties[$property] = $value;
139 }
140
141 /**
142 * put your comment there...
143 *
144 * @deprecated Use calculatePinpoint
145 */
146 public static function calculateBlockPinPoint(& $block) {
147 // Generate PinPoint Value.
148 if (isset($block->pinPoint) && is_array($block->pinPoint)) {
149 $pinPoint = 0;
150 // Each item is a bit flag.
151 foreach ($block->pinPoint as $pin) {
152 $pinPoint |= hexdec($pin);
153 }
154 }
155 else {
156 // Provided as integer or not even provided!
157 if (!isset($block->pinPoint)) {
158 $block->pinPoint = 0;
159 }
160 $pinPoint = (int) $block->pinPoint;
161 }
162 // Pin should be set only for not empty properties.
163 // This help us retreiving only needed blocks when outputing blocks code.
164 $pins = array(
165 self::PINS_PAGES_CUSTOM_PAGE => 'pages',
166 self::PINS_POSTS_CUSTOM_POST => 'posts',
167 self::PINS_CATEGORIES_CUSTOM_CATEGORY => 'categories',
168 self::PINS_LINKS => 'links',
169 self::PINS_EXPRESSIONS => 'expressions',
170 );
171 foreach ($pins as $flag => $pin) {
172 $pinPoint |= abs((int) (!empty($block->{$pin}))) * $flag;
173 }
174 // Set new pin point.
175 $block->pinPoint = $pinPoint;
176 return $block;
177 }
178
179 /**
180 * put your comment there...
181 *
182 * @param mixed $block
183 * @param mixed $pins
184 */
185 public static function calculatePinPoint($block, $pins) {
186 // Add pins to Block object so that calculateBlockPinPoint can calculate PinPoint value!
187 $block = (object) array_merge($block, $pins);
188 $pinPoint = self::calculateBlockPinPoint($block)->pinPoint;
189 // Return only pinPoint.
190 return $pinPoint;
191 }
192
193 } // End class.