Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezsimplifiedxmlinput.php
Go to the documentation of this file.
1 <?php
11 class eZSimplifiedXMLInput extends eZXMLInputHandler
12 {
13 public function __construct( $xmlData, $aliasedType, $contentObjectAttribute )
14 {
15 parent::__construct( $xmlData, $aliasedType, $contentObjectAttribute );
16
17 $this->IsInputValid = true;
18 $this->ContentObjectAttribute = $contentObjectAttribute;
19
20 $contentIni = eZINI::instance( 'content.ini' );
21 }
22
26 static function updateUrlObjectLinks( $contentObjectAttribute, $urlIDArray )
27 {
28 $objectAttributeID = $contentObjectAttribute->attribute( 'id' );
29 $objectAttributeVersion = $contentObjectAttribute->attribute('version');
30
31 // Ensure links that have been removed from the attribute version are removed from the object link table
32 $linkObjectLinkList = eZURLObjectLink::fetchLinkObjectList( $objectAttributeID, $objectAttributeVersion );
33 foreach ( $linkObjectLinkList as $linkObjectLink ) {
34 if ( !in_array( $linkObjectLink->attribute( 'url_id' ), $urlIDArray ) ) {
35 $linkObjectLink->remove();
36 }
37 }
38
39 // Ensure links that have been added to the attribute version are added to the object link table
40 foreach( $urlIDArray as $urlID )
41 {
42 $linkObjectLink = eZURLObjectLink::fetch( $urlID, $objectAttributeID, $objectAttributeVersion );
43 if ( $linkObjectLink == null )
44 {
45 $linkObjectLink = eZURLObjectLink::create( $urlID, $objectAttributeID, $objectAttributeVersion );
46 $linkObjectLink->store();
47 }
48 }
49 }
50
54 function validateInput( $http, $base, $contentObjectAttribute )
55 {
56 $contentObjectID = $contentObjectAttribute->attribute( 'contentobject_id' );
57 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
58 $contentObjectAttributeVersion = $contentObjectAttribute->attribute('version');
59 if ( $http->hasPostVariable( $base . '_data_text_' . $contentObjectAttributeID ) )
60 {
61 $data = $http->postVariable( $base . '_data_text_' . $contentObjectAttributeID );
62
63 // Set original input to a global variable
64 $originalInput = 'originalInput_' . $contentObjectAttributeID;
65 $GLOBALS[$originalInput] = $data;
66
67 // Set input valid true to a global variable
68 $isInputValid = 'isInputValid_' . $contentObjectAttributeID;
69 $GLOBALS[$isInputValid] = true;
70
71 $text = $data;
72
73 $text = preg_replace('/\r/', '', $text);
74 $text = preg_replace('/\t/', ' ', $text);
75
76 // first empty paragraph
77 $text = preg_replace('/^\n/', '<p></p>', $text );
78
79 eZDebugSetting::writeDebug( 'kernel-datatype-ezxmltext', $text, 'eZSimplifiedXMLInput::validateInput text' );
80
81 $parser = new eZSimplifiedXMLInputParser( $contentObjectID, true, eZXMLInputParser::ERROR_ALL, true );
82 $document = $parser->process( $text );
83
84 if ( !is_object( $document ) )
85 {
86 $GLOBALS[$isInputValid] = false;
87 $errorMessage = implode( ' ', $parser->getMessages() );
88 $contentObjectAttribute->setValidationError( $errorMessage );
89 return eZInputValidator::STATE_INVALID;
90 }
91
92 if ( $contentObjectAttribute->validateIsRequired() )
93 {
94 $root = $document->documentElement;
95 if ( !$root->hasChildNodes() )
96 {
97 $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes',
98 'Content required' ) );
99 return eZInputValidator::STATE_INVALID;
100 }
101 }
102 $contentObjectAttribute->setValidationLog( $parser->getMessages() );
103
104 $xmlString = eZXMLTextType::domString( $document );
105
106 $urlIDArray = $parser->getUrlIDArray();
107
108 if ( count( $urlIDArray ) > 0 )
109 {
110 $this->updateUrlObjectLinks( $contentObjectAttribute, $urlIDArray );
111 }
112
113 $contentObject = $contentObjectAttribute->attribute( 'object' );
114 $contentObject->appendInputRelationList( $parser->getRelatedObjectIDArray(), eZContentObject::RELATION_EMBED );
115 $contentObject->appendInputRelationList( $parser->getLinkedObjectIDArray(), eZContentObject::RELATION_LINK );
116
117 $contentObjectAttribute->setAttribute( 'data_text', $xmlString );
118 return eZInputValidator::STATE_ACCEPTED;
119 }
120 return eZInputValidator::STATE_ACCEPTED;
121 }
122
126 function inputXML()
127 {
128 $contentObjectAttribute = $this->ContentObjectAttribute;
129 $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
130
131 $originalInput = 'originalInput_' . $contentObjectAttributeID;
132 $isInputValid = 'isInputValid_' . $contentObjectAttributeID;
133
134 if ( isset( $GLOBALS[$isInputValid] ) and $GLOBALS[$isInputValid] == false )
135 {
136 $output = $GLOBALS[$originalInput];
137 }
138 else
139 {
140 $dom = new DOMDocument( '1.0', 'utf-8' );
141 $success = $dom->loadXML( $this->XMLData );
142
143 $editOutput = new eZSimplifiedXMLEditOutput();
144 $dom->formatOutput = true;
145 if ( eZDebugSetting::isConditionTrue( 'kernel-datatype-ezxmltext', eZDebug::LEVEL_DEBUG ) )
146 eZDebug::writeDebug( $dom->saveXML(), eZDebugSetting::changeLabel( 'kernel-datatype-ezxmltext', __METHOD__ . ' xml string stored in database' ) );
147 $output = $editOutput->performOutput( $dom );
148 }
149 return $output;
150 }
151
152 public $IsInputValid;
153 }
154
155 ?>
eZContentObject\RELATION_LINK
const RELATION_LINK
Definition: ezcontentobject.php:39
eZContentObject\RELATION_EMBED
const RELATION_EMBED
Definition: ezcontentobject.php:38
eZDebugSetting\isConditionTrue
static isConditionTrue( $conditionName, $messageType)
Definition: ezdebugsetting.php:47
eZDebugSetting\changeLabel
static changeLabel( $conditionName, $label='')
Definition: ezdebugsetting.php:70
eZDebugSetting\writeDebug
static writeDebug( $conditionName, $string, $label="")
Definition: ezdebugsetting.php:127
eZDebug\writeDebug
static writeDebug( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:588
eZDebug\LEVEL_DEBUG
const LEVEL_DEBUG
Definition: ezdebug.php:63
eZInputValidator\STATE_ACCEPTED
const STATE_ACCEPTED
Definition: ezinputvalidator.php:79
eZInputValidator\STATE_INVALID
const STATE_INVALID
Definition: ezinputvalidator.php:81
eZSimplifiedXMLEditOutput
Definition: ezsimplifiedxmleditoutput.php:13
eZSimplifiedXMLInputParser
Definition: ezsimplifiedxmlinputparser.php:13
eZSimplifiedXMLInput
Definition: ezsimplifiedxmlinput.php:12
eZSimplifiedXMLInput\inputXML
inputXML()
Definition: ezsimplifiedxmlinput.php:126
eZSimplifiedXMLInput\$IsInputValid
$IsInputValid
Definition: ezsimplifiedxmlinput.php:152
eZSimplifiedXMLInput\updateUrlObjectLinks
static updateUrlObjectLinks( $contentObjectAttribute, $urlIDArray)
Definition: ezsimplifiedxmlinput.php:26
eZSimplifiedXMLInput\validateInput
validateInput( $http, $base, $contentObjectAttribute)
Definition: ezsimplifiedxmlinput.php:54
eZSimplifiedXMLInput\__construct
__construct( $xmlData, $aliasedType, $contentObjectAttribute)
Definition: ezsimplifiedxmlinput.php:13
eZURLObjectLink\create
static create( $urlID, $contentObjectAttributeID, $contentObjectAttributeVersion)
Definition: ezurlobjectlink.php:51
eZURLObjectLink\fetch
static fetch( $urlID, $contentObjectAttributeID, $contentObjectAttributeVersion, $asObject=true)
Definition: ezurlobjectlink.php:64
eZURLObjectLink\fetchLinkObjectList
static fetchLinkObjectList( $contentObjectAttributeID, $contentObjectAttributeVersion, $asObject=true)
Definition: ezurlobjectlink.php:190
eZXMLInputHandler
The class eZXMLInputHandler does.
Definition: ezxmlinputhandler.php:19
eZXMLInputHandler\$ContentObjectAttribute
$ContentObjectAttribute
Definition: ezxmlinputhandler.php:210
eZXMLInputParser\ERROR_ALL
const ERROR_ALL
Definition: ezxmlinputparser.php:36
eZXMLTextType\domString
static domString( $domDocument)
Definition: ezxmltexttype.php:383
ezpI18n\tr
static tr( $context, $source, $comment=null, $arguments=null)
Definition: ezpi18n.php:86
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.