Documentation

Block extends BlockLibrary
in package

Block

block module class

Tags
copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Cloudrexx Development Team info@cloudrexx.com

access

public

version
1.0.0
subpackage

module_block

Table of Contents

Properties

$_arrBlocks  : array<string|int, mixed>
Block ids
$_categories  : array<string|int, mixed>
Array of categories
$_categoryNames  : array<string|int, mixed>
array containing the category names
$_categoryOptions  : array<string|int, mixed>
holds the category dropdown select options
$blockNamePrefix  : string
Block name prefix
$availableTargeting  : mixed

Methods

__construct()  : mixed
Constructor
_addBlock()  : bool|int
Add a new block to database
_deleteCategory()  : bool
delete a category by id
_getAssociatedPageIds()  : array<string|int, mixed>
Get the associated pages for a placeholder
_getBlock()  : mixed
Get block
_getCategories()  : array<string|int, mixed>
fill and/or return the categories array
_getCategoriesDropdown()  : string
create the categories dropdown
_getCategory()  : array<string|int, mixed>
return the category specified by ID
_getChildCategories()  : array<string|int, mixed>
return all child caegories of a cateogory
_saveCategory()  : int|bool
Save a block category
_saveSettings()  : mixed
Save the settings associated to the block system
_updateBlock()  : bool|int
Update an existing block
checkTargetingCountry()  : bool
Check Country targeting option
checkTargetingOptions()  : bool
Verify targeting options for the given block Id
getBlocks()  : array<string|int, mixed>
Get blocks
getGeoIpComponent()  : ComponentController
Get GeoIp component controller
getSettings()  : array<string|int, mixed>
Get the settings from database
isBlockWithinPublishingSchedule()  : bool
Checks whether a block is currently within its publishing schedule.
loadTargetingSettings()  : array<string|int, mixed>
Load Targeting settings
replacePlaceholdersInContent()  : mixed
Replace the block placeholders by their associated content within a supplied string
setBlocks()  : mixed
flushBlockWidgetCache()  : void
Flushes the cache for a specific Block widget.
flushCategoryWidgetCache()  : void
Flushes the cache for a category-specific Block widget.
flushGlobalWidgetCache()  : void
Flushes the cache for the global Block widget.
flushRandomWidgetCache()  : void
Flushes the cache for all four randomizer Block widgets.
flushWidgetCache()  : void
Flushes all relevant Block widget caches.
setBlock()  : void
Replaces block widgets in the given code with their rendered content.
setBlockGlobal()  : void
Replaces the global block placeholder in the given code with rendered content.
setBlockRandom()  : void
Replaces a randomizer block placeholder in the given code with rendered content.
setCategoryBlock()  : void
Replaces category block placeholders in the given code with rendered content.
storeBlockContent()  : mixed
storePlaceholderSettings()  : bool
Store the placeholder settings for a block

Properties

$_arrBlocks

Block ids

public array<string|int, mixed> $_arrBlocks
Tags
access

private

$_categories

Array of categories

public array<string|int, mixed> $_categories = array()

$_categoryNames

array containing the category names

public array<string|int, mixed> $_categoryNames = array()

catId => name

$_categoryOptions

holds the category dropdown select options

public array<string|int, mixed> $_categoryOptions = array()

of strings: HTML

$blockNamePrefix

Block name prefix

public string $blockNamePrefix = 'BLOCK_'
Tags
access

public

Methods

_addBlock()

Add a new block to database

public _addBlock(int $cat, array<string|int, mixed> $arrContent, string $name, int $start, int $end, int $blockRandom, int $blockRandom2, int $blockRandom3, int $blockRandom4, int $blockWysiwygEditor, array<string|int, mixed> $arrLangActive) : bool|int
Parameters
$cat : int
$arrContent : array<string|int, mixed>
$name : string
$start : int
$end : int
$blockRandom : int
$blockRandom2 : int
$blockRandom3 : int
$blockRandom4 : int
$blockWysiwygEditor : int
$arrLangActive : array<string|int, mixed>
Return values
bool|int

the block's id

_deleteCategory()

delete a category by id

public _deleteCategory([int $id = 0 ]) : bool
Parameters
$id : int = 0

category id

Return values
bool

success

_getAssociatedPageIds()

Get the associated pages for a placeholder

public _getAssociatedPageIds(int $blockId, string $placeholder) : array<string|int, mixed>
Parameters
$blockId : int

block id

$placeholder : string
Return values
array<string|int, mixed>

_getBlock()

Get block

public _getBlock(int $id) : mixed

Return a block

Parameters
$id : int
Tags
access

private

global

ADONewConnection

Return values
mixed

content on success, false on failure

_getCategories()

fill and/or return the categories array

public _getCategories([mixed $refresh = false ]) : array<string|int, mixed>

category arrays are put in the array as first dimension elements, with their parent as key, as follows: $this->_categories[$objRS->fields['parent']][] = $objRS->fields;

just to make this clear: note that $somearray['somekey'][] = $foo adds $foo to $somearray['somekey'] rather than overwriting it.

Parameters
$refresh : mixed = false
Tags
see
blockManager::_parseCategories

for parse example

see
blockLibrary::_getCategoriesDropdown

for parse example

global

ADONewConnection

global

array

Return values
array<string|int, mixed>

all available categories

_getCategoriesDropdown()

create the categories dropdown

public _getCategoriesDropdown([mixed $parent = 0 ][, mixed $catId = 0 ][, array<string|int, mixed> $arrCategories = array() ][, array<string|int, mixed> $arrOptions = array() ][, int $level = 0 ]) : string
Parameters
$parent : mixed = 0
$catId : mixed = 0
$arrCategories : array<string|int, mixed> = array()
$arrOptions : array<string|int, mixed> = array()
$level : int = 0
Return values
string

categories as HTML options

_getCategory()

return the category specified by ID

public _getCategory([int $id = 0 ]) : array<string|int, mixed>
Parameters
$id : int = 0
Return values
array<string|int, mixed>

category information

_getChildCategories()

return all child caegories of a cateogory

public _getChildCategories(mixed $id[, mixed &$_arrChildCategories = array() ]) : array<string|int, mixed>
Parameters
$id : mixed
$_arrChildCategories : mixed = array()
Return values
array<string|int, mixed>

IDs of children

_saveCategory()

Save a block category

public _saveCategory(string $name, string $seperator[, int $id = 0 ][, int $parent = 0 ][, int $order = 1 ][, int $status = 1 ]) : int|bool
Parameters
$name : string
$seperator : string
$id : int = 0
$parent : int = 0
$order : int = 1
$status : int = 1
Return values
int|bool

Inserted ID, or false on failure

_saveSettings()

Save the settings associated to the block system

public _saveSettings(array<string|int, mixed> $arrSettings) : mixed
Parameters
$arrSettings : array<string|int, mixed>
Tags
todo

Flush only the cache of the block widgets once the legacy widgets [[BLOCK_]] have been migrated to a callback esi widget.

_updateBlock()

Update an existing block

public _updateBlock(int $id, int $cat, array<string|int, mixed> $arrContent, string $name, int $start, int $end, int $blockRandom, int $blockRandom2, int $blockRandom3, int $blockRandom4, int $blockWysiwygEditor, array<string|int, mixed> $arrLangActive) : bool|int
Parameters
$id : int
$cat : int
$arrContent : array<string|int, mixed>
$name : string
$start : int
$end : int
$blockRandom : int
$blockRandom2 : int
$blockRandom3 : int
$blockRandom4 : int
$blockWysiwygEditor : int
$arrLangActive : array<string|int, mixed>
Return values
bool|int

the id of the block

checkTargetingCountry()

Check Country targeting option

public checkTargetingCountry(string $filter, array<string|int, mixed> $countryIds) : bool
Parameters
$filter : string

include => client country should exists in given country ids exclude => client country should not exists in given country ids

$countryIds : array<string|int, mixed>

Country ids to match

Return values
bool

True when targeting country option matching to client country False otherwise

checkTargetingOptions()

Verify targeting options for the given block Id

public checkTargetingOptions(int $blockId) : bool
Parameters
$blockId : int

Block id

Return values
bool

True when all targeting options vaild, false otherwise

getBlocks()

Get blocks

public getBlocks([mixed $catId = 0 ]) : array<string|int, mixed>

Get all blocks

Parameters
$catId : mixed = 0
Tags
access

private

see
array

blockLibrary::_arrBlocks

Return values
array<string|int, mixed>

Array with block ids

getSettings()

Get the settings from database

public getSettings() : array<string|int, mixed>
Tags
staticvar

array $settings settings array

Return values
array<string|int, mixed>

settings array

isBlockWithinPublishingSchedule()

Checks whether a block is currently within its publishing schedule.

public isBlockWithinPublishingSchedule([int $start = 0 ][, int $end = 0 ][, DateTime|null &$expirationDate = null ]) : bool

Behavior:

  • If $end is > 0 and earlier than now → block is expired → returns false.
  • If $start is > 0 and in the future → block is not yet active, sets $expirationDate to $start, returns false.
  • If $end is > 0 and still in the future → block is active, sets $expirationDate to $end, returns true.
  • Otherwise → block is considered active with no expiration set.
Parameters
$start : int = 0

Optional start timestamp (Unix epoch). 0 means "no start restriction".

$end : int = 0

Optional end timestamp (Unix epoch). 0 means "no end restriction".

$expirationDate : DateTime|null = null

Reference variable. If set, will contain the next relevant expiration date ($start if in the future, $end if still pending).

Return values
bool

true if the block is currently active, false if it has not yet started or is already expired.

loadTargetingSettings()

Load Targeting settings

public loadTargetingSettings(int $blockId) : array<string|int, mixed>
Parameters
$blockId : int

Content block id

Return values
array<string|int, mixed>

Settings array

replacePlaceholdersInContent()

Replace the block placeholders by their associated content within a supplied string

public static replacePlaceholdersInContent(string &$content) : mixed
Parameters
$content : string

The content to replace all block placeholders by their content in

setBlocks()

public static setBlocks(mixed &$content[, mixed $page = null ]) : mixed
Parameters
$content : mixed
$page : mixed = null

flushBlockWidgetCache()

Flushes the cache for a specific Block widget.

protected flushBlockWidgetCache(int $id) : void
Parameters
$id : int

The ID of the block whose cache should be flushed.

Tags
todo

Once the Block placeholders have been properly migrated to widgets, replace the call to clearSsiCachePage() with the appropriate event trigger.

flushCategoryWidgetCache()

Flushes the cache for a category-specific Block widget.

protected flushCategoryWidgetCache(int $id) : void
Parameters
$id : int

The ID of the category whose cache should be flushed.

Tags
todo

Once the Block placeholders have been properly migrated to widgets, replace the call to clearSsiCachePage() with the appropriate event trigger.

flushGlobalWidgetCache()

Flushes the cache for the global Block widget.

protected flushGlobalWidgetCache() : void
Tags
todo

Once the Block placeholders have been properly migrated to widgets, replace the call to clearSsiCachePage() with the appropriate event trigger.

flushRandomWidgetCache()

Flushes the cache for all four randomizer Block widgets.

protected flushRandomWidgetCache() : void
Tags
todo

Once the Block placeholders have been properly migrated to widgets, replace the call to clearSsiCachePage() with the appropriate event trigger.

flushWidgetCache()

Flushes all relevant Block widget caches.

protected flushWidgetCache([int $blockId = 0 ][, array<string|int, int> $catIds = [] ][, bool $flushGlobal = true ][, bool $flushRandomizers = true ]) : void
Parameters
$blockId : int = 0

Optional block ID for targeted cache flush.

$catIds : array<string|int, int> = []

Optional list of category IDs whose caches should be flushed.

$flushGlobal : bool = true

Whether to flush the global block cache. Default true.

$flushRandomizers : bool = true

Whether to flush randomizer block caches (1–4). Default true.

setBlock()

Replaces block widgets in the given code with their rendered content.

protected setBlock(array<string|int, int> $arrBlocks, string &$code, Page|null $page) : void

Iterates over the provided block IDs, fetches their content via ESI, and replaces placeholders in the $code template.

Example: {BLOCK_123} → rendered block content for ID 123.

The rendering includes context information such as language, page ID, and country (from GeoIP).

Parameters
$arrBlocks : array<string|int, int>

Array of block IDs to render.

$code : string

Reference to the template/code where placeholders should be replaced.

$page : Page|null

Optional page entity. If provided, its ID is used for block rendering.

setBlockGlobal()

Replaces the global block placeholder in the given code with rendered content.

protected setBlockGlobal(string &$code, Page|null $page) : void

Fetches the global block content via ESI and replaces the {BLOCK_GLOBAL} placeholder in $code. The rendering includes context such as language, page ID, and country (from GeoIP).

Example: {BLOCK_GLOBAL} → rendered global block content.

Parameters
$code : string

Reference to the template/code where the placeholder should be replaced.

$page : Page|null

Optional page entity. If provided, its ID is passed to block rendering.

Tags
todo

This is legacy code and must be replaced by proper EsiWidget implementation through a EsiWidgetController.

setBlockRandom()

Replaces a randomizer block placeholder in the given code with rendered content.

protected setBlockRandom(string &$code, int $id, Page|null $page) : void

Fetches the random block content via ESI and replaces the corresponding {BLOCK_RANDOMIZER}, {BLOCK_RANDOMIZER_2}, {BLOCK_RANDOMIZER_3}, or {BLOCK_RANDOMIZER_4} placeholder in $code, depending on the $id. The rendering includes context such as language, page ID, and country (from GeoIP).

Example: {BLOCK_RANDOMIZER_2} → rendered randomized block content for randomizer #2.

Parameters
$code : string

Reference to the template/code where the placeholder should be replaced.

$id : int

The randomizer ID (1–4). 1 uses {BLOCK_RANDOMIZER}, higher IDs use {BLOCK_RANDOMIZER_<id>}.

$page : Page|null

Optional page entity. If provided, its ID is passed to block rendering.

Tags
todo

This is legacy code and must be replaced by proper EsiWidget implementation through a EsiWidgetController.

setCategoryBlock()

Replaces category block placeholders in the given code with rendered content.

protected setCategoryBlock(array<string|int, int> $ids, string &$code, Page|null $page) : void

Iterates over the provided category IDs, fetches their block content via ESI, and replaces placeholders in $code.

Example: {BLOCK_CAT_5} → rendered content of category block with ID 5.

The rendering includes context information such as language, page ID, and country (from GeoIP).

Parameters
$ids : array<string|int, int>

Array of category IDs to render.

$code : string

Reference to the template/code where placeholders should be replaced.

$page : Page|null

Optional page entity. If provided, its ID is passed to block rendering.

Tags
todo

This is legacy code and must be replaced by proper EsiWidget implementation through a EsiWidgetController.

storeBlockContent()

protected storeBlockContent(mixed $blockId, mixed $arrContent, mixed $arrLangActive) : mixed
Parameters
$blockId : mixed
$arrContent : mixed
$arrLangActive : mixed

storePlaceholderSettings()

Store the placeholder settings for a block

protected storePlaceholderSettings(int $blockId, int $global, int $direct, int $category, array<string|int, mixed> $globalAssociatedPages, array<string|int, mixed> $directAssociatedPages, array<string|int, mixed> $categoryAssociatedPages) : bool
Parameters
$blockId : int
$global : int
$direct : int
$category : int
$globalAssociatedPages : array<string|int, mixed>
$directAssociatedPages : array<string|int, mixed>
$categoryAssociatedPages : array<string|int, mixed>
Return values
bool

it was successfully saved


        
On this page

Search results