properties = array( 'name' => null, 'pinPoint' => null, 'state' => null, 'location' => null, 'code' => null, 'pages' => null, 'posts' => null, 'categories' => null, 'links' => null, 'expressions' => null, 'id' => null, ); // Set block properties. $this->setValues($values); } /** * Get block property value. * * @param string Property name. * @return mixed Property value. */ public function __get($property) { switch ($property) { case 'pages': case 'posts': case 'categories': $value = ($this->properties[$property] !== null) ? $this->properties[$property] : array(); break; default: $value = $this->properties[$property]; break; } return $value; } /** * Set block proprty value. * * @param string Property name. * @param mixed Property value. * @return void */ public function __set($property, $value) { switch ($property) { case 'code': case 'links': case 'expressions': // New lines submitted to server as CRLF but displayed in browser as LF. // PHP script and JS work on two different versions of texts. // Replace CRLF with LF just as displayed in browsers. $value = preg_replace("/\x0D\x0A/", "\x0A", $value); break; } $this->properties[$property] = $value; } /** * put your comment there... * * @deprecated Use calculatePinpoint */ public static function calculateBlockPinPoint(&$block) { // Generate PinPoint Value. if (is_array($block->pinPoint)) { $pinPoint = 0; // Each item is a bit flag. foreach ($block->pinPoint as $pin) { $pinPoint |= hexdec($pin); } } else { // If provided as integer. $pinPoint = (int) $block->pinPoint; } // Pin should be set only for not empty properties. // This help us retreiving only needed blocks when outputing blocks code. $pins = array( self::PINS_PAGES_CUSTOM_PAGE => 'pages', self::PINS_POSTS_CUSTOM_POST => 'posts', self::PINS_CATEGORIES_CUSTOM_CATEGORY => 'categories', self::PINS_LINKS => 'links', self::PINS_EXPRESSIONS => 'expressions', ); foreach ($pins as $flag => $pin) { $pinPoint |= abs((int) (!empty($block->{$pin}))) * $flag; } // Set new pin point. $block->pinPoint = $pinPoint; return $block; } /** * put your comment there... * * @param mixed $block * @param mixed $pins */ public static function calculatePinPoint($block, $pins) { // Add pins to Block object so that calculateBlockPinPoint can calculate PinPoint value! $block = (object) array_merge($block, $pins); $pinPoint = self::calculateBlockPinPoint($block)->pinPoint; // Return only pinPoint. return $pinPoint; } /** * put your comment there... * * @param mixed $values */ public static function getInstance($values) { return new CJTBlockModel($values); } } // End class.