|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Zikula package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright Zikula Foundation - http://zikula.org/ |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Zikula\BlocksModule\Block; |
|
13
|
|
|
|
|
14
|
|
|
use DOMDocument; |
|
15
|
|
|
use XSLTProcessor; |
|
16
|
|
|
use Zikula\BlocksModule\AbstractBlockHandler; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Block to display a parsed xml document |
|
20
|
|
|
*/ |
|
21
|
|
|
class XsltBlock extends AbstractBlockHandler |
|
22
|
|
|
{ |
|
23
|
|
|
public function display(array $properties) |
|
24
|
|
|
{ |
|
25
|
|
|
if (!$this->hasPermission('xsltblock::', "$properties[title]::", ACCESS_OVERVIEW)) { |
|
26
|
|
|
return ''; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$doc = new DOMDocument(); |
|
30
|
|
|
$xsl = new XSLTProcessor(); |
|
31
|
|
|
|
|
32
|
|
|
// load stylesheet |
|
33
|
|
View Code Duplication |
if (isset($properties['styleurl']) && !empty($properties['styleurl'])) { |
|
|
|
|
|
|
34
|
|
|
$doc->load($properties['styleurl']); |
|
35
|
|
|
} else { |
|
36
|
|
|
$doc->loadXML($properties['stylecontents']); |
|
37
|
|
|
} |
|
38
|
|
|
$xsl->importStyleSheet($doc); |
|
39
|
|
|
|
|
40
|
|
|
// load xml source |
|
41
|
|
View Code Duplication |
if (isset($properties['docurl']) && !empty($properties['docurl'])) { |
|
|
|
|
|
|
42
|
|
|
$doc->load($properties['docurl']); |
|
43
|
|
|
} else { |
|
44
|
|
|
$doc->loadXML($properties['doccontents']); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// apply stylesheet and return output |
|
48
|
|
|
return $xsl->transformToXML($doc); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getFormClassName() |
|
52
|
|
|
{ |
|
53
|
|
|
return 'Zikula\BlocksModule\Block\Form\Type\XsltBlockType'; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getFormTemplate() |
|
57
|
|
|
{ |
|
58
|
|
|
return '@ZikulaBlocksModule/Block/xslt_modify.html.twig'; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getFormOptions() |
|
62
|
|
|
{ |
|
63
|
|
|
return [ |
|
64
|
|
|
'translator' => $this->getTranslator() |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.