Esempio n. 1
0
 public function executeSave()
 {
     $hasError = false;
     try {
         $parameters = $this->getRequest()->getParameterHolder()->getAll();
         $moduleName = $parameters['moduleName'];
         $documentName = $parameters["documentName"];
         $parent = Document::getDocumentInstance($parameters['parent']);
         if (!$parent) {
             if (isset($parameters["parentModule"])) {
                 $parent = Rootfolder::getRootfolderByModule($parameters["parentModule"]);
             } else {
                 $parent = Rootfolder::getRootfolderByModule($moduleName);
             }
         }
         if (is_numeric($parameters['id'])) {
             $obj = Document::getDocumentInstance($parameters['id']);
             $parent = Document::getParentOf($parameters['id']);
         } else {
             $obj = new $documentName();
         }
         include_once sfConfig::get('sf_root_dir') . "/config/Schema.class.php";
         $m = "get" . $documentName . "Properties";
         $properties = Schema::$m();
         if (isset($parameters['imageFields'])) {
             $imageFields = explode(",", $parameters['imageFields']);
         } else {
             $imageFields = array();
         }
         $contentArr = array();
         foreach ($parameters as $key => $value) {
             // parse Content attribute/s for Page
             if ($documentName == "Page" && substr($key, 0, 11) == 'attrContent' && in_array('Content', $properties)) {
                 $ind = intval(substr($key, 11));
                 // check if creating NEW Page
                 if ($ind == 0) {
                     $ind = 1;
                 }
                 $contentArr[$parameters['contentID' . $ind]] = '<block id="' . $parameters['contentID' . $ind] . '" target="' . $parameters['contentTarget' . $ind] . '" action="richtext"><![CDATA[' . $value . ']]></block>';
             } else {
                 if (!(strpos($key, 'attr') === false) && $key != "attrRewriteUrl") {
                     $key = str_replace('attr', '', $key);
                     if ($properties && $key != "Password" && !in_array($key, $properties)) {
                         continue;
                     }
                     if ($key == "Password" && empty($value)) {
                         continue;
                     }
                     $function = 'set' . $key;
                     if (is_array($value)) {
                         if (array_key_exists('year', $value) && array_key_exists('month', $value)) {
                             $date = $value['year'] . '-' . $value['month'] . '-' . $value['day'];
                             // 2009-02-09 16:10:20
                             if ($value['hour'] && $value['minute']) {
                                 $time = $value['hour'] . ':' . $value['minute'];
                                 $value = $date . ' ' . $time;
                             } else {
                                 $value = $date;
                             }
                         } else {
                             $value = implode(";", $value);
                         }
                     }
                     if (in_array($key, $imageFields)) {
                         $getFunction = 'get' . $key;
                         $imgId = $obj->{$getFunction}();
                         if ($imgId != $value) {
                             $img = Document::getDocumentInstance($imgId);
                             if ($img) {
                                 $imgExt = $img->getExtention();
                                 @unlink(sfConfig::get('sf_root_dir') . "/www/media/upload/thumbs/" . $parameters["moduleName"] . "/" . $imgId . "-" . $key . "." . $imgExt);
                             }
                         }
                     }
                     if ($key == "Related") {
                         //						if ($value)
                         //						{
                         //							$value = '['.str_replace(';', '][', $value).']';
                         //						}
                     }
                     if ($key == "Keywords") {
                         //						if ($value)
                         //						{
                         //							$value = str_replace(',', '][', $value);
                         //							$value = '['.substr($value, 0, -1);
                         //						}
                     }
                     $obj->{$function}($value);
                 }
             }
         }
         // Page content save
         if ($documentName == 'Page' && count($contentArr) > 0) {
             // add original NON-RICHTEXT content blocks
             $orgContent = $obj->getContent();
             $blocks = PanelService::get_content_blocks($orgContent);
             foreach ($blocks as $name => $block) {
                 $contentArr[$name] = '<block id="' . $name . '" target="' . $block['target'] . '" action="' . $block['action'] . '"><![CDATA[' . $block['content'] . ']]></block>';
             }
             $allBlocks = PanelService::get_all_content_blocks($orgContent);
             $content = '';
             foreach ($allBlocks as $blockName => $blockData) {
                 $content .= $contentArr[$blockName];
             }
             $content = '<?xml version="1.0" encoding="UTF-8"?><blocks>' . $content . '</blocks>';
             $obj->setContent($content);
         }
         if ($documentName == "Page") {
             $obj->setRewriteUrl($parameters["attrRewriteUrl"]);
         }
         $obj->save(null, $parent);
         if ($tags = Document::getAvailableTagsOf($moduleName, $parameters['documentName'])) {
             foreach ($tags as $tag) {
                 if ($parameters['tag_id_' . $tag->getId()]) {
                     Document::addTag($obj, $tag->getTagId(), false);
                 } else {
                     Document::removeTag($obj, $tag->getTagId(), false);
                 }
             }
             Tagrelation::updateTagRelationCache();
         }
         //UtilsHelper::setBackendMsg("Saved");
     } catch (Exception $e) {
         $hasError = true;
         UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error");
     }
     if (!$hasError) {
         PanelService::redirect();
         exit;
     }
 }
Esempio n. 2
0
 public static function objectSave(&$obj, &$parent, $documentName = null)
 {
     try {
         $parameters = sfContext::getInstance()->getRequest()->getParameterHolder()->getAll();
         if (!$documentName) {
             $documentName = $parameters["documentName"];
         }
         if (!$parent) {
             $parent = Document::getDocumentInstance($parameters['parent']);
         }
         if (!$parent) {
             if (isset($parameters["parentModule"])) {
                 $parent = Rootfolder::getRootfolderByModule($parameters["parentModule"]);
             } else {
                 $parent = Rootfolder::getRootfolderByModule($moduleName);
             }
         }
         if (!is_object($obj)) {
             if (is_numeric($parameters['id']) && !$parent) {
                 $obj = Document::getDocumentInstance($parameters['id']);
                 $parent = Document::getParentOf($parameters['id']);
                 $documentName = $parameters["documentName"];
             } else {
                 $obj = new $documentName();
             }
         }
         include_once sfConfig::get('sf_root_dir') . "/config/Schema.class.php";
         $m = "get" . $documentName . "Properties";
         $properties = Schema::$m();
         $contentArr = array();
         foreach ($parameters as $key => $value) {
             // parse Content attribute/s for Page
             if ($documentName == "Page" && substr($key, 0, 11) == 'attrContent' && $key > 'attrContent' && in_array('Content', $properties)) {
                 $ind = intval(substr($key, 11));
                 // check if creating NEW Page
                 if ($ind == 0) {
                     $ind = 1;
                 }
                 $contentArr[$parameters['contentID' . $ind]] = '<block id="' . $parameters['contentID' . $ind] . '" target="' . $parameters['contentTarget' . $ind] . '" action="richtext"><![CDATA[' . $value . ']]></block>';
             } else {
                 if (!(strpos($key, 'attr') === false) && $key != "attrRewriteUrl") {
                     if ($value == '') {
                         $value = null;
                     }
                     $key = str_replace('attr', '', $key);
                     if ($properties && $key != "Password" && !in_array($key, $properties)) {
                         continue;
                     }
                     if ($key == "Password" && empty($value)) {
                         continue;
                     }
                     $function = 'set' . $key;
                     if (is_array($value)) {
                         // date field
                         if (array_key_exists('year', $value) || array_key_exists('month', $value) || array_key_exists('day', $value)) {
                             //$value = implode('-', $value);
                             //							$date = $value['year'].'-'.str_pad($value['month'], 2, "0", STR_PAD_LEFT).'-'.str_pad($value['day'], 2, "0", STR_PAD_LEFT); // 2009-02-09 16:10:20
                             $date = implode('-', $value);
                             if ($value['hour'] && $value['minute']) {
                                 // if 'include_custom' is used
                                 if (empty($value['year']) || empty($value['month']) || empty($value['day']) || empty($value['hour']) || empty($value['minute'])) {
                                     $value = null;
                                 } else {
                                     $time = $value['hour'] . ':' . $value['minute'];
                                     $value = $date . ' ' . $time;
                                 }
                             } else {
                                 // if 'include_custom' is used
                                 if (empty($value['year']) && empty($value['month']) && empty($value['day'])) {
                                     $value = null;
                                 } else {
                                     $value = $date;
                                 }
                             }
                         } else {
                             $value = implode(";", $value);
                         }
                     }
                     if ($key == "Related") {
                         if ($value) {
                             $value = '[' . str_replace(';', '][', $value) . ']';
                             $value = str_replace('[]', '', $value);
                         }
                     }
                     if ($key == "Keywords") {
                         if ($value) {
                             $value = '[' . str_replace(',', '][', $value) . ']';
                             $value = str_replace('[]', '', $value);
                         }
                     }
                     $obj->{$function}($value);
                 }
             }
         }
         // Page content save
         if ($documentName == 'Page' && count($contentArr) > 0) {
             // add original NON-RICHTEXT content blocks
             $orgContent = $obj->getContent();
             $blocks = self::get_content_blocks($orgContent);
             foreach ($blocks as $name => $block) {
                 $contentArr[$name] = '<block id="' . $name . '" target="' . $block['target'] . '" action="' . $block['action'] . '"><![CDATA[' . $block['content'] . ']]></block>';
             }
             $allBlocks = PanelService::get_all_content_blocks($orgContent);
             $content = '';
             foreach ($allBlocks as $blockName => $blockData) {
                 $content .= $contentArr[$blockName];
             }
             $content = '<?xml version="1.0" encoding="UTF-8"?><blocks>' . $content . '</blocks>';
             $obj->setContent($content);
         }
         if ($documentName == "Page") {
             $obj->setRewriteUrl($parameters["attrRewriteUrl"]);
         }
         $obj->save(null, $parent);
         if ($tags = Document::getAvailableTagsOf($parameters['moduleName'], $documentName)) {
             foreach ($tags as $tag) {
                 if ($parameters['tag_id_' . $tag->getId()]) {
                     Document::addTag($obj, $tag->getTagId());
                 } else {
                     Document::removeTag($obj, $tag->getTagId());
                 }
             }
             Tagrelation::updateTagRelationCache();
         }
         //UtilsHelper::setBackendMsg("Saved");
     } catch (Exception $e) {
         throw $e;
     }
 }