19 require_once(BASE.
"wcmf/lib/presentation/class.Controller.php");
20 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceFacade.php");
21 require_once(BASE.
"wcmf/lib/persistence/class.LockManager.php");
22 require_once(BASE.
"wcmf/lib/model/class.Node.php");
23 require_once(BASE.
"wcmf/lib/model/class.NodeUtil.php");
24 require_once(BASE.
"wcmf/lib/util/class.InifileParser.php");
25 require_once(BASE.
"wcmf/lib/util/class.FileUtil.php");
26 require_once(BASE.
"wcmf/lib/util/class.URIUtil.php");
27 require_once(BASE.
"wcmf/lib/util/class.GraphicsUtil.php");
28 require_once(BASE.
"wcmf/lib/util/class.SessionData.php");
29 require_once(BASE.
"wcmf/lib/util/class.FormUtil.php");
85 $persistenceFacade->startTransaction();
89 foreach($this->_request->getData() as $key => $value)
92 && is_a($value,
'PersistentObject'))
95 $saveEntry[
'oid'] = $key;
98 $lockManager->releaseLock($saveEntry[
'oid']);
101 $lock = $lockManager->getLock($saveEntry[
'oid']);
104 $this->
appendErrorMsg($lockManager->getLockMessage($lock, $saveEntry[
'oid']));
109 foreach ($saveNode->getDataTypes() as $dataType)
111 $saveEntry[
'dataType'] = $dataType;
112 foreach ($saveNode->getValueNames($dataType) as $name)
114 $saveEntry[
'name'] = $name;
115 $saveEntry[
'value'] = $saveNode->getValue($name, $dataType);
120 if (is_array($saveEntry[
'value']))
125 if ($result ===
false) {
128 if ($result ===
true)
132 if (
sizeof($saveEntry[
'value']) > 0)
133 $saveEntry[
'value'] = join($saveEntry[
'value'],
",");;
138 $saveEntry[
'value'] = $result;
143 if ($this->_request->hasValue(
'delete'.$fieldDelimiter.$key))
145 $saveEntry[
'value'] =
'';
151 if ($saveEntry[
'oid'] !=
'')
155 $curOID = $saveEntry[
'oid'];
156 if (!isset($saveArray[$curOID]))
164 $curNode->setOID($curOID);
171 if ($curNode == null)
177 $nodeUtil->completeNode($curNode);
181 $curNode = &$saveArray[$curOID];
185 if (ini_get(
'magic_quotes_gpc')) {
186 $saveEntry[
'value'] = stripslashes($saveEntry[
'value']);
188 if (!$isFile || ($isFile && !$deleteFile && $saveEntry[
'value'] !=
'') || ($isFile && $deleteFile))
190 $properties = $curNode->getValueProperties($saveEntry[
'name'], $saveEntry[
'dataType']);
193 $oldValue = $curNode->getValue($saveEntry[
'name'], $saveEntry[
'dataType']);
194 $oldState = $curNode->getState();
197 $newValue = $saveEntry[
'value'];
198 if ($oldValue != $newValue) {
200 if (strpos($properties[
'input_type'],
'file') !==
false && strlen($newValue) > 0)
202 $filename = $newValue;
204 $uploadDir = $this->
getUploadDir($curOID, $saveEntry[
'name'], $saveEntry[
'dataType']);
205 if (strpos($filename, $uploadDir) !== 0) {
206 $filename = $uploadDir.$newValue;
209 else if (strpos($filename, UriUtil::getProtocolStr()) === 0)
211 $refURL = UriUtil::getProtocolStr().$_SERVER[
'HTTP_HOST'].$_SERVER[
'SCRIPT_NAME'];
214 $newValue = $filename;
217 $curNode->setValue($saveEntry[
'name'], $newValue, $saveEntry[
'dataType']);
220 if ($this->
modify($curNode, $saveEntry[
'name'], $saveEntry[
'dataType'], $oldValue)) {
224 $newValue = $curNode->getValue($saveEntry[
'name'], $saveEntry[
'dataType']);
230 $validationMsg = $curNode->validateValue($name, $newValue, $type);
231 $validationFailed = strlen($validationMsg) > 0 ?
true :
false;
232 $fileOk = $isFile ? $this->
checkFile($curOID, $saveEntry[
'name'], $saveEntry[
'dataType'], $newValue) :
true;
233 if (!$validationFailed && $fileOk)
235 if ($this->
confirmSave($curNode, $saveEntry[
'name'], $saveEntry[
'dataType'], $newValue))
241 $curNode->setValue($saveEntry[
'name'], $oldValue, $saveEntry[
'dataType']);
246 $errorMessage = $validationMsg;
250 if (strlen($errorMessage) > 0)
255 $session->addError($key, $errorMessage);
258 $curNode->setValue($saveEntry[
'name'], $oldValue, $saveEntry[
'dataType']);
259 $curNode->setState($oldState);
264 $oldState = $curNode->getState();
265 if (!isset($saveArray[$curNode->getOID()]))
267 $saveArray[$curNode->getOID()] = &$curNode;
268 $curNode->setState($oldState);
276 $saveOIDs = array_keys($saveArray);
282 for($i=0; $i<
sizeof($saveOIDs); $i++)
284 $curObj = &$saveArray[$saveOIDs[$i]];
288 $localization->saveTranslation($curObj, $this->_request->getValue(
'language'));
299 for($i=0; $i<
sizeof($saveOIDs); $i++) {
300 $this->
afterSave($saveArray[$saveOIDs[$i]]);
304 $persistenceFacade->commitTransaction();
307 if (
sizeof($saveOIDs) > 0) {
308 $this->_response->setValue(
'oid', $saveOIDs[
sizeof($saveOIDs)-1]);
310 $this->_response->setAction(
'ok');
321 $mediaFile = $data[
'value'];
322 if ($mediaFile[
'name'] !=
'')
325 if ($mediaFile[
'tmp_name'] !=
'none')
328 if ($this->_fileUtil == null) {
333 if(($maxFileSize = $parser->getValue(
'maxFileSize',
'htmlform')) ===
false) {
337 if (!is_uploaded_file($mediaFile[
'tmp_name']))
340 if ($maxFileSize != -1) {
341 $this->
appendErrorMsg(
Message::get(
"A possible reason is that the file size is too big (maximum allowed: %1% bytes).", array($maxFileSize)));
347 $uploadDir = $this->
getUploadDir($data[
'oid'], $data[
'name'], $data[
'dataType']);
350 if (!$this->
checkFile($data[
'oid'], $data[
'name'], $data[
'dataType'], $mediaFile[
'tmp_name'], $mediaFile[
'type'])) {
354 $uploadFilename = $uploadDir.$this->getUploadFilename($data[
'oid'], $data[
'name'], $data[
'dataType'], $mediaFile[
'name']);
357 $override = $this->
shouldOverride($data[
'oid'], $data[
'name'], $data[
'dataType'], $uploadFilename);
360 $filename = $this->_fileUtil->uploadFile($mediaFile, $uploadFilename, null, $maxFileSize, $override);
393 function checkFile($oid, $valueName, $dataType, $filename, $mimeType=null)
396 if ($mimeType != null)
398 $mimeTypes = $this->
getMimeTypes($oid, $valueName, $dataType);
399 if ($mimeTypes != null && !in_array($mimeType, $mimeTypes))
401 $this->
appendErrorMsg(
Message::get(
"File '%1%' has wrong mime type: %2%. Allowed types: %3%.", array($filename, $mimeType, join(
", ", $mimeTypes))));
408 $imgWidth = $imgConstraints[
'width'];
409 $imgHeight = $imgConstraints[
'height'];
411 if ($imgWidth ===
false && $imgHeight ===
false) {
415 if ($this->_graphicsUtil == null) {
419 if ($imgWidth !==
false) {
420 $checkWidth = $this->_graphicsUtil->isValidImageWidth($filename, $imgWidth[0], $imgWidth[1]);
425 if ($imgHeight !==
false) {
426 $checkHeight = $this->_graphicsUtil->isValidImageHeight($filename, $imgHeight[0], $imgHeight[1]);
431 if(!($checkWidth && $checkHeight))
473 $constraints = array(
'width' =>
false,
'height' =>
false);
476 if ($type && ($width = $parser->getValue($type.
'.'.$valueName.
'.width',
'Media',
false)) !==
false) {
477 $constraints[
'width'] = $width;
480 else if (($width = $parser->getValue(
'imgWidth',
'Media',
false)) !==
false) {
481 $constraints[
'width'] = $width;
485 if ($type && ($height = $parser->getValue($type.
'.'.$valueName.
'.height',
'Media',
false)) !==
false) {
486 $constraints[
'height'] = $height;
489 else if (($width = $parser->getValue(
'imgHeight',
'Media',
false)) !==
false) {
490 $constraints[
'width'] = $width;
508 $filename = preg_replace(
"/[^a-zA-Z0-9\-_\.\/]+/",
"_", $filename);
538 if ($this->_request->hasValue(
'uploadDir')) {
539 $uploadDir = $this->_request->getValue(
'uploadDir').
'/';
547 if ($type && ($dir = $parser->getValue(
'uploadDir.'.$type,
'Media',
false)) !==
false) {
551 if(($dir = $parser->getValue(
'uploadDir',
'media')) !==
false) {
558 if (substr($uploadDir,-1) !=
'/') {
562 if (!is_dir($uploadDir)) {
590 function modify(&$node, $valueName, $valueType, $oldValue)
GraphicsUtil provides support for graphic manipulation.
SaveController is a controller that saves Node data.
get($message, $parameters=null, $domain='', $lang='')
getMimeTypes($oid, $valueName, $dataType)
NodeUtil provides services for the Node class. All methods are static.
makeRelative($abs_uri, $base)
shouldOverride($oid, $valueName, $dataType, $filename)
Controller is the base class of all controllers. If a Controller has a view it is expected to reside ...
getUploadDir($oid, $valueName, $dataType)
checkFile($oid, $valueName, $dataType, $filename, $mimeType=null)
getOIDParameter($oid, $param, $validate=true)
getUploadFilename($oid, $valueName, $dataType, $filename)
getImageConstraints($oid, $valueName, $dataType)
confirmSave(&$node, $valueName, $valueType, $newValue)
FileUtil provides basic support for file functionality like HTTP file upload.
modify(&$node, $valueName, $valueType, $oldValue)