Newer
Older
<?php
/**
* This file contains \QUI\Bricks\Utils
*/
namespace QUI\Bricks;
use QUI;
use QUI\Utils\Text\XML;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use QUI\Projects\Project;
/**
* Class Utils
* Bricks helper class
*
* @package QUI\Bricks
* @author www.pcsg.de (Henning Leutz) <support@pcsg.de>
*/
class Utils
{
/**
* Return the bricks from a xml file
*
* @param String $file - path to file
*
* @return array
*/
public static function getBricksFromXML($file)
{
if (!file_exists($file)) {
return array();
}
$Dom = XML::getDomFromXml($file);
$Path = new \DOMXPath($Dom);
$bricks = $Path->query("//quiqqer/bricks/brick");
$list = array();
if (!$bricks->length) {
return $list;
}
if ($Brick->getAttribute('control') == '*') {
continue;
}
$list[] = self::parseAreaToArray($Brick, $Path);
}
return $list;
}
/**
* Return the template bricks from a xml file
*
* @param string $file - path to xm file
* @param string|bool $layoutType - optional, return only the bricks for the specific layout type
*
* @return array
*/
public static function getTemplateAreasFromXML($file, $layoutType = false)
{
if (!file_exists($file)) {
return array();
}
$Dom = XML::getDomFromXml($file);
$Path = new \DOMXPath($Dom);
$globalAreas = $Path->query("//quiqqer/bricks/templateAreas/areas/area");
if ($layoutType) {
$typeAreas = $Path->query(
"//quiqqer/bricks/templateAreas/layouts/layout[@layout='{$layoutType}']/area"
);
} else {
$typeAreas = $Path->query("//quiqqer/bricks/templateAreas/layouts/layout/area");
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
}
$list = array();
if ($globalAreas->length) {
foreach ($globalAreas as $Area) {
$list[] = self::parseAreaToArray($Area, $Path);
}
}
if ($typeAreas->length) {
foreach ($typeAreas as $Area) {
$list[] = self::parseAreaToArray($Area, $Path);
}
}
return $list;
}
public static function getGlobalTemplateAreasFromXML()
{
}
/**
* @param $file
* @param $siteType
*/
public static function getTypeTemplateAreasFromXML($file, $siteType)
{
}
/**
* parse a <area> xml node to an array
*
* @param \DOMElement $Brick
* @param \DOMXPath $Path
*
* @return array
*/
public static function parseAreaToArray(\DOMElement $Brick, \DOMXPath $Path)
{
$control = $Brick->getAttribute('control');
$name = $Brick->getAttribute('name');
$title = array();
$description = array();
$titleLocale = $Path->query('./title/locale', $Brick);
$descLocale = $Path->query('./description/locale', $Brick);
if ($titleLocale->length) {
$title = array(
'group' => $titleLocale->item(0)->getAttribute('group'),
'var' => $titleLocale->item(0)->getAttribute('var')
);
}
if ($descLocale->length) {
$description = array(
'group' => $descLocale->item(0)->getAttribute('group'),
'var' => $descLocale->item(0)->getAttribute('var')
);
}
return array(
'control' => $control,
'name' => $name,
'title' => $title,
'description' => $description,
'inheritance' => $Brick->getAttribute('inheritance'),
'priority' => $Brick->getAttribute('priority')
);
}
/**
*
* @param Project $Project
* @param String $areaName
*
* @return bool
*/
public static function hasInheritance(Project $Project, $areaName)
{
$template = $Project->getAttribute('template');
// getAreasByProject
$brickXML = realpath(OPT_DIR.$template.'/bricks.xml');
$bricks = self::getTemplateAreasFromXML($brickXML);
foreach ($bricks as $brickData) {
if ($brickData['name'] != $areaName) {
continue;
}
if (isset($brickData['inheritance']) && $brickData['inheritance']) {
return true;
}
return false;
}
return true;
}
}