Newer
Older
1
2
3
4
5
6
7
8
9
10
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
<?php
/**
* This file contains \QUI\Blocks\Utils
*/
namespace QUI\Blocks;
use QUI;
use QUI\Utils\XML;
/**
* Class Utils
* Blocks helper class
*
* @package quiqqer/blocks
* @author www.pcsg.de (Henning Leutz)
*/
class Utils
{
/**
* Return the blocks from a xml file
*
* @param String $file
* @return array
*/
static function getBlocksFromXML($file)
{
if ( !file_exists( $file ) ) {
return array();
}
$Dom = XML::getDomFromXml( $file );
$Path = new \DOMXPath( $Dom );
$blocks = $Path->query( "//quiqqer/blocks/block" );
$list = array();
if ( !$blocks->length ) {
return $list;
}
foreach ( $blocks as $Block ) {
$list[] = self::parseBlockToArray( $Block, $Path );
}
return $list;
}
/**
* Return the template blocks from a xml file
*
* @param string $file - path to xm file
* @return array
*/
static function getTemplateAreasFromXML($file)
{
if ( !file_exists( $file ) ) {
return array();
}
$Dom = XML::getDomFromXml( $file );
$Path = new \DOMXPath( $Dom );
$globalBlocks = $Path->query( "//quiqqer/blocks/templateAreas/areas/area" );
$typeBlocks = $Path->query( "//quiqqer/blocks/templateAreas/types/type/area" );
$list = array();
if ( $globalBlocks->length )
foreach ( $globalBlocks as $Block ) {
$list[] = self::parseBlockToArray( $Block, $Path );
if ( $typeBlocks->length )
{
foreach ( $typeBlocks as $Block ) {
$list[] = self::parseBlockToArray( $Block, $Path );
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
return $list;
}
static function getGlobalTemplateAreasFromXML()
{
}
static function getTypeTemplateAreasFromXML($file, $siteType)
{
}
/**
* parse a <block> xml node to an array
*
* @param \DOMElement $Block
* @param \DOMXPath $Path
* @return array
*/
static function parseBlockToArray(\DOMElement $Block, \DOMXPath $Path)
{
$control = $Block->getAttribute( 'control' );
$name = $Block->getAttribute( 'name' );
$title = array();
$description = array();
$titleLocale = $Path->query( './title/locale', $Block );
$descLocale = $Path->query( './description/locale', $Block );
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
);