Ejemplo n.º 1
0
 private function getDataFromXmlFile($sFilename)
 {
     //load XML from file
     if (!file_exists($sFilename)) {
         throw new AnwBadCallException("import file not found");
     }
     $sFileContent = AnwUtils::file_get_contents($sFilename);
     $oRootNode = AnwUtils::loadXml($sFileContent);
     $aaData = array();
     $aaData['PAGEGROUPS'] = array();
     $aaData['TIME'] = $oRootNode->getAttribute("time");
     $aaData['FROM'] = AnwXml::xmlFileAttributeDecode($oRootNode->getAttribute("from"));
     $aaData['VERSION_ID'] = $oRootNode->getAttribute("version_id");
     $aaData['VERSION_NAME'] = AnwXml::xmlFileAttributeDecode($oRootNode->getAttribute("version_name"));
     $aoPageGroupsNodes = AnwXml::xmlGetChildsByTagName(self::XMLTAG_PAGEGROUP, $oRootNode);
     foreach ($aoPageGroupsNodes as $oPageGroupNode) {
         $aaDataGroup = array();
         $aaDataGroup['CONTENTCLASS'] = AnwXml::xmlFileAttributeDecode($oPageGroupNode->getAttribute("contentclass"));
         $aaDataGroup['PAGES'] = array();
         $aoTranslationsNodes = AnwXml::xmlGetChildsByTagName(self::XMLTAG_PAGE, $oPageGroupNode);
         foreach ($aoTranslationsNodes as $oPageNode) {
             $asDataPage = array();
             $asDataPage['NAME'] = AnwXml::xmlFileAttributeDecode($oPageNode->getAttribute("name"));
             $asDataPage['LANG'] = AnwXml::xmlFileAttributeDecode($oPageNode->getAttribute("lang"));
             $asDataPage['TIME'] = (int) $oPageNode->getAttribute("time");
             $asDataPage['CONTENT'] = AnwUtils::xmlDumpNodeChilds($oPageNode);
             $aaDataGroup['PAGES'][] = $asDataPage;
         }
         $aaData['PAGEGROUPS'][] = $aaDataGroup;
     }
     return $aaData;
 }
Ejemplo n.º 2
0
 static function propagateContentEdition($oOldContent, $oNewContent, $oContentTranslation)
 {
     $oContentTranslation = clone $oContentTranslation;
     //don't edit content directly !
     // Warning: Diff is applied to the first-level contentfields, and not recursively.
     // This allows content to be moved from one subcontentfield to another without loosing translations.
     //
     // Due to this non-recursive approach, subcontentfields translatable flags are not respected.
     // That's why we will need to run propagateUntranslatableContentEdition() at the end to fix this.
     //
     // TODO: find a cleaner way to do this.
     $aoContentFields = $oNewContent->getContentFieldsContainer()->getContentFields();
     foreach ($aoContentFields as $oContentField) {
         $sFieldName = $oContentField->getName();
         if ($oContentField->isTranslatable()) {
             //determine FIELD value with diffs method (recalc same diffs)
             $oOldContentFieldValuesXml = $oOldContent->getContentFieldDataAsXml($sFieldName);
             $oContentFieldValuesXml = $oNewContent->getContentFieldDataAsXml($sFieldName);
             $oDiffs = new AnwDiffs($oOldContentFieldValuesXml, $oContentFieldValuesXml);
             //print $oDiffs->debugHtml();
             $oTranslateContentFieldValuesXml = $oContentTranslation->getContentFieldDataAsXml($sFieldName);
             $oTranslateContentFieldValuesXml = self::applyDiffs($oDiffs, $oTranslateContentFieldValuesXml, $oContentField);
             AnwDebug::log("setContentField(" . $sFieldName . ") : " . htmlentities(AnwUtils::xmlDumpNode($oTranslateContentFieldValuesXml)));
             //set content field value
             if ($oContentField instanceof AnwStructuredContentField_atomic) {
                 $asValues = array();
                 $oValuesNodes = $oTranslateContentFieldValuesXml->childNodes;
                 for ($i = 0; $i < $oValuesNodes->length; $i++) {
                     $oChild = $oValuesNodes->item($i);
                     $sValue = AnwUtils::xmlDumpNodeChilds($oChild);
                     //TODO better parsing for anwv?
                     $asValues[] = $sValue;
                 }
                 $oContentTranslation->setContentFieldValues($sFieldName, $asValues);
             } else {
                 //extract subcontents from xml tree...
                 $aoSubContents = array();
                 $oSubContentsNodes = $oTranslateContentFieldValuesXml->childNodes;
                 for ($i = 0; $i < $oSubContentsNodes->length; $i++) {
                     $oChild = $oSubContentsNodes->item($i);
                     $sSubContentValue = AnwUtils::xmlDumpNodeChilds($oChild);
                     //using $oContentTranslation instead of self for php inherance
                     $oSubContent = $oContentTranslation->rebuildContentFromXml($oContentField, $sSubContentValue);
                     $aoSubContents[] = $oSubContent;
                 }
                 $oContentTranslation->setSubContents($sFieldName, $aoSubContents);
             }
         } else {
             //not translatable = keep same value
             if ($oContentField instanceof AnwStructuredContentField_atomic) {
                 $oContentTranslation->setContentFieldValues($sFieldName, $oNewContent->getContentFieldValues($sFieldName));
             } else {
                 $oContentTranslation->setSubContents($sFieldName, $oNewContent->getSubContents($sFieldName));
             }
         }
     }
     // As explained below, we need to run propagateUntranslatableContentEdition() to respect subcontentfields' translatable attribute.
     //AnwDebug::log("####before####".htmlentities($oContentTranslation->toXmlString()));
     //print "####before####".htmlentities($oContentTranslation->toXmlString())."<hr/>";
     $oContentTranslation = self::propagateUntranslatableContentEdition($oContentTranslation, $oNewContent);
     //AnwDebug::log("####after####".htmlentities($oContentTranslation->toXmlString()));
     //print "####after####".htmlentities($oContentTranslation->toXmlString());exit;
     return $oContentTranslation;
 }
Ejemplo n.º 3
0
 function setUntranslated()
 {
     $aoContentFields = $this->getContentFieldsContainer()->getContentFields();
     foreach ($aoContentFields as $sFieldName => $oContentField) {
         if ($oContentField->isTranslatable()) {
             $asValues = array();
             if ($oContentField instanceof AnwStructuredContentField_composed) {
                 $aoSubContents = $this->getSubContents($sFieldName);
                 foreach ($aoSubContents as $i => $oSubContent) {
                     $oSubContent->setUntranslated();
                     //$asValues[] = AnwUtils::xmlDumpNodeChilds($oSubContent->toXml()->documentElement);
                 }
             } else {
                 $asValues = $this->getContentFieldValues($sFieldName);
                 foreach ($asValues as $i => $sValue) {
                     $oValueXml = AnwUtils::loadXML('<doc>' . $sValue . '</doc>');
                     $oValueXml = AnwXml::xmlAddTranslateTags($oValueXml);
                     //contentfield already checked
                     $asValues[$i] = AnwUtils::xmlDumpNodeChilds($oValueXml);
                 }
                 $this->setContentFieldValues($sFieldName, $asValues);
             }
         }
     }
 }
Ejemplo n.º 4
0
 function saveTranslation_cbkOnValue($oContentField, $oXmlValue, $sInputName)
 {
     $fOnTextValue = "saveTranslation_onTextValue";
     AnwUtils::runCallbacksOnTranslatableValue($this, $oXmlValue, $sInputName, $fOnTextValue, null, null);
     //$oXmlValue has been modified by callback
     $sValue = AnwUtils::xmlDumpNodeChilds($oXmlValue);
     AnwDebug::log(" => value[] for {$sInputName} : " . htmlentities($sValue));
     $this->saveTranslation_ContentFieldValues[] = $sValue;
 }