Ejemplo n.º 1
0
 /**
  * Save XML file
  *
  * @param string $language
  * @param bool $compress
  * @param bool $replace
  * @param string $path
  * @return bool
  */
 public function saveLanguageXML($language, $compress = false, $replace, $path = CC_LANGUAGE_DIR)
 {
     if (!$this->_checkPath($path)) {
         trigger_error('Invalid language path ' . $path, E_USER_ERROR);
     }
     if ($path !== CC_LANGUAGE_DIR) {
         $path = appendDS($path);
     }
     if (!empty($language)) {
         // Load in existing file
         $source = $path . $language . '.xml';
         $this->exported_lang_file = $replace ? $source : $path . $language . '-custom.xml';
         $strings = array();
         if (file_exists($source)) {
             $data = file_get_contents($source);
             $xml = new SimpleXMLElement($data);
             foreach ($xml->info as $values) {
                 foreach ($values as $key => $value) {
                     $info[$key] = $value;
                 }
             }
             if ($xml->translation && $xml->translation->group) {
                 foreach ($xml->translation->group as $groups) {
                     $group = $groups->attributes()->name;
                     foreach ($groups->string as $string) {
                         $name = $string->attributes()->name;
                         $strings[(string) $group][(string) $name] = $string;
                     }
                 }
             }
             unset($data, $xml);
             // Fetch Database Results
             if (($custom = $GLOBALS['db']->select('CubeCart_lang_strings', false, array('language' => $language))) !== false) {
                 foreach ($custom as $row) {
                     $strings[$row['type']][$row['name']] = $row['value'];
                 }
             } else {
                 trigger_error('No custom strings exist', E_USER_NOTICE);
             }
             $xml = new XML();
             $xml->startElement('language', array('version' => '2.0'));
             $xml->startElement('info');
             foreach ($info as $key => $value) {
                 $xml->setElement($key, $value, false, false);
             }
             $xml->endElement();
             $xml->startElement('translation');
             foreach ($strings as $group => $values) {
                 $xml->startElement('group', array('name' => $group));
                 foreach ($values as $name => $value) {
                     $xml->setElement('string', $value, array('name' => $name));
                 }
                 $xml->endElement();
             }
             $xml->endElement();
             $xml->endElement();
             if ($compress) {
                 $output = gzencode($xml->getDocument(), 9, FORCE_GZIP);
                 $this->exported_lang_file .= '.gz';
             } else {
                 $output = $xml->getDocument();
             }
             return (bool) file_put_contents($this->exported_lang_file, $output);
         }
     }
     return false;
 }
Ejemplo n.º 2
0
} else {
    if (isset($_POST['export']) && !empty($_POST['export'])) {
        if (preg_match(Language::LANG_REGEX, $_POST['export'])) {
            ## Export language to XML...
            if (($emails = $GLOBALS['db']->select('CubeCart_email_content', false, array('language' => $_POST['export']))) !== false) {
                $xml = new XML();
                $xml->startElement('emails', array('version' => '1.0', 'language' => $_POST['export']));
                $content_types = array('html', 'text');
                foreach ($emails as $email) {
                    $xml->startElement('email', array('name' => $email['content_type']));
                    foreach ($content_types as $type) {
                        if (!empty($email['content_' . $type])) {
                            $xml->setElement('content', $email['content_' . $type], array('type' => $type));
                        }
                    }
                    $xml->endElement();
                }
                $xml->endElement();
                $data = $xml->getDocument();
                $file = CC_ROOT_DIR . '/language/email_' . $_POST['export'] . '-custom.xml';
                if (isset($_POST['export_compress'])) {
                    $data = gzencode($data, 9, FORCE_GZIP);
                    $file = $file . '.gz';
                }
                if (file_put_contents($file, $data)) {
                    $GLOBALS['main']->setACPNotify($lang['email']['notify_export']);
                } else {
                    $GLOBALS['main']->setACPWarning($lang['email']['error_export']);
                }
            } else {
                $GLOBALS['main']->setACPWarning($lang['email']['error_export']);
Ejemplo n.º 3
0
 /**
  * End Parent element
  * @return void
  */
 public function endElement()
 {
     $this->xmlWriter->endElement();
 }