Пример #1
0
 private function fixThesaurus2(&$domth, &$tenode, $depth, \unicode $unicode)
 {
     $sy = $tenode->appendChild($domth->createElement("sy"));
     $sy->setAttribute("lng", $v = $tenode->getAttribute("lng"));
     $sy->setAttribute("v", $v = $tenode->getAttribute("v"));
     $sy->setAttribute("w", $unicode->remove_indexer_chars($v));
     if (($k = $tenode->getAttribute("k")) != "") {
         $sy->setAttribute("k", $k);
     }
     $tenode->removeAttribute("lng");
     $tenode->removeAttribute("v");
     $tenode->removeAttribute("w");
     $tenode->removeAttribute("k");
     if ($tenode->getAttribute("nextid") == "") {
         $tenode->setAttribute("nextid", "0");
     }
     $todel = [];
     for ($n = $tenode->firstChild; $n; $n = $n->nextSibling) {
         if ($n->nodeName == "ta") {
             $todel[] = $n;
         }
         if ($n->nodeName == "te") {
             $this->fixThesaurus2($domth, $n, $depth + 1, $unicode);
         }
     }
     foreach ($todel as $n) {
         $n->parentNode->removeChild($n);
     }
 }
Пример #2
0
 /**
  *
  * @param Application $app
  * @param integer     $sbas_id
  * @param integer     $record_id
  * @param string      $directory
  * @param integer     $remain_hd
  *
  * @return record_exportElement
  */
 public function __construct(Application $app, $sbas_id, $record_id, $directory = '', $remain_hd = false)
 {
     $this->directory = $directory;
     if ($this->directory) {
         $unicode = new \unicode();
         $this->directory = $unicode->remove_nonazAZ09($this->directory) . '/';
     }
     $this->remain_hd = $remain_hd;
     $this->size = [];
     parent::__construct($app, $sbas_id, $record_id);
     $this->get_actions($remain_hd);
     return $this;
 }
Пример #3
0
 function clean($html, $config = false)
 {
     global $AR;
     if (!$config) {
         $config["path"] = $this->tidy;
         $config["temp"] = $this->temp;
         $config["options"] = $this->options;
     }
     if ($AR->OS == "WIN32") {
         include_once $AR->dir->install . "/lib/modules/mod_unicode.php";
         $html = unicode::utf8convert($html);
     }
     $html = preg_replace('|(<[?]xml:namespace[^/]*office[^/]*/>)|i', '', $html);
     $file = tempnam($config["temp"], 'tidy-php-tmp');
     $errfile = tempnam($config["temp"], 'tidy-php-err');
     $fd = fopen($file, "w");
     fwrite($fd, $html, strlen($html));
     fclose($fd);
     $pd = popen($config["path"] . " -f " . $errfile . " " . $config["options"] . " " . $file, "r");
     while (!feof($pd)) {
         $outhtml .= fread($pd, 1024);
     }
     pclose($pd);
     $fd = fopen($errfile, "r");
     while (!feof($fd)) {
         $errors .= fread($fd, 1024);
     }
     fclose($fd);
     unlink($file);
     unlink($errfile);
     $ret['html'] = $outhtml;
     $ret['errors'] = $errors;
     return $ret;
 }
Пример #4
0
 /**
  * @covers \unicode::parseDate
  */
 public function testparseDate()
 {
     $this->assertEquals('2012/00/00 00:00:00', $this->object->parseDate('2012'));
     $this->assertEquals('2012/01/00 00:00:00', $this->object->parseDate('2012-01'));
     $this->assertEquals('2012/03/15 00:00:00', $this->object->parseDate('2012-03-15'));
     $this->assertEquals('2012/03/15 12:00:00', $this->object->parseDate('2012-03-15 12'));
     $this->assertEquals('2012/03/15 12:11:00', $this->object->parseDate('2012-03-15 12:11'));
     $this->assertEquals('2012/03/15 12:12:12', $this->object->parseDate('2012-03-15 12-12-12'));
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function toMetadataArray(\databox_descriptionStructure $metadatasStructure)
 {
     $metas = [];
     $unicode = new \unicode();
     foreach ($metadatasStructure as $databox_field) {
         if ('' === $databox_field->get_tag()->getTagname()) {
             // skipping fields without sources
             continue;
         }
         if ($this->containsKey($databox_field->get_tag()->getTagname())) {
             if ($databox_field->is_multi()) {
                 $values = $this->get($databox_field->get_tag()->getTagname())->getValue()->asArray();
                 $tmp = [];
                 foreach ($values as $value) {
                     foreach (\caption_field::get_multi_values($value, $databox_field->get_separator()) as $v) {
                         $tmp[] = $v;
                     }
                 }
                 $values = array_unique($tmp);
                 foreach ($values as $value) {
                     $value = $unicode->substituteCtrlCharacters($value, ' ');
                     $value = $unicode->toUTF8($value);
                     if ($databox_field->get_type() == 'date') {
                         $value = $unicode->parseDate($value);
                     }
                     $metas[] = ['meta_struct_id' => $databox_field->get_id(), 'value' => $value, 'meta_id' => null];
                 }
             } else {
                 $value = $this->get($databox_field->get_tag()->getTagname())->getValue()->asString();
                 $value = $unicode->substituteCtrlCharacters($value, ' ');
                 $value = $unicode->toUTF8($value);
                 if ($databox_field->get_type() == 'date') {
                     $value = $unicode->parseDate($value);
                 }
                 $metas[] = ['meta_struct_id' => $databox_field->get_id(), 'value' => $value, 'meta_id' => null];
             }
         }
     }
     unset($unicode);
     return $metas;
 }
Пример #6
0
 public function convertToUTF8($data, $charset = "CP1252")
 {
     include_once $this->store->get_config("code") . "modules/mod_unicode.php";
     if (isset($data) && is_array($data)) {
         foreach ($data as $key => $val) {
             $data[$key] = $this->convertToUTF8($val, $charset);
         }
     } else {
         if (is_object($data)) {
             foreach ($data as $key => $val) {
                 $data->{$key} = $this->convertToUTF8($val, $charset);
             }
         } else {
             $data = unicode::convertToUTF8($charset, $data);
         }
     }
     return $data;
 }
Пример #7
0
 public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode)
 {
     $needreindex = false;
     if ($version == "2.0.4") {
         $xp = new DOMXPath($domth);
         $sy = $xp->query("//sy");
         for ($i = 0; $i < $sy->length; $i++) {
             if ($k = $sy->item($i)->getAttribute("k")) {
                 $v = $sy->item($i)->getAttribute("v");
                 if (strpos($v, "(") === false) {
                     $sy->item($i)->setAttribute("v", $v . " (" . $k . ")");
                     printf("//  context '({$k})' pasted to value '{$v}'\n");
                     $needreindex = true;
                 } else {
                     printf("//  <font color=\"#ff8000\">warning</font> : &lt;sy id='%s' v='%s' ...&gt; already had context (left unchanged)\n", $sy->item($i)->getAttribute("id"), htmlentities($v));
                 }
                 $newk = trim($unicode->remove_indexer_chars($k));
                 if ($newk != $k) {
                     $sy->item($i)->setAttribute("k", $newk);
                     $needreindex = true;
                 }
             }
         }
         $domth->documentElement->setAttribute("version", "2.0.5");
         $domth->documentElement->setAttribute("modification_date", date("YmdHis"));
         if ($needreindex) {
             print "//   need to reindex, deleting cterms (keeping rejected)\n";
             $xp = new DOMXPath($domct);
             $nodes = $xp->query("//te[not(starts-with(@id, 'R')) and count(te[starts-with(@id, 'R')])=0]");
             $nodestodel = [];
             for ($i = 0; $i < $nodes->length; $i++) {
                 $nodestodel[] = $nodes->item($i);
             }
             $ctdel = 0;
             foreach ($nodestodel as $node) {
                 $sql2 = "DELETE FROM thit WHERE value LIKE :like";
                 $stmt = $connbas->prepare($sql2);
                 $stmt->execute([':like' => str_replace(".", "d", $node->getAttribute("id")) . "d%"]);
                 $stmt->closeCursor();
                 $node->parentNode->removeChild($node);
                 $ctdel++;
             }
             print "//     {$ctdel} nodes removed\n";
             $sql2 = "UPDATE record SET status=((status | 15) & ~2)";
             $stmt = $connbas->prepare($sql2);
             $stmt->execute();
             $stmt->closeCursor();
         }
         $sy = $xp->query("//sy");
         for ($i = 0; $i < $sy->length; $i++) {
             if ($k = $sy->item($i)->getAttribute("k")) {
                 if (strpos($v = $sy->item($i)->getAttribute("v"), "(") === false) {
                     $sy->item($i)->setAttribute("v", $v . " (" . $k . ")");
                 } else {
                     printf("//   <font color=\"#ff8000\">warning</font> : &lt;sy id='%s' v='%s' ...&gt already had context (left unchanged)\n", $sy->item($i)->getAttribute("id"), htmlentities($v));
                 }
                 $sy->item($i)->setAttribute("k", $unicode->remove_indexer_chars($k));
             }
         }
         $domct->documentElement->removeAttribute("id");
         $this->fixRejected($connbas, $domct->documentElement, false);
         $this->fixIds($connbas, $domct->documentElement);
         $domct->documentElement->setAttribute("version", "2.0.5");
         $domct->documentElement->setAttribute("modification_date", date("YmdHis"));
         $version = "2.0.5";
     }
     return $version;
 }
Пример #8
0
 public static function generateName($name)
 {
     $unicode_processor = new unicode();
     $name = $unicode_processor->remove_nonazAZ09($name, false, false);
     return $unicode_processor->remove_first_digits($name);
 }
Пример #9
0
 /**
  *
  * @param User       $user
  * @param Filesystem $filesystem
  * @param Array      $subdefs
  * @param boolean    $rename_title
  * @param boolean    $includeBusinessFields
  *
  * @return Array
  */
 public function prepare_export(User $user, Filesystem $filesystem, array $subdefs, $rename_title, $includeBusinessFields)
 {
     if (!is_array($subdefs)) {
         throw new Exception('No subdefs given');
     }
     $includeBusinessFields = !!$includeBusinessFields;
     $files = [];
     $n_files = 0;
     $file_names = [];
     $size = 0;
     $unicode = new \unicode();
     foreach ($this->elements as $download_element) {
         $id = count($files);
         $files[$id] = ['base_id' => $download_element->get_base_id(), 'record_id' => $download_element->get_record_id(), 'original_name' => '', 'export_name' => '', 'subdefs' => []];
         $BF = false;
         if ($includeBusinessFields && $this->app['acl']->get($user)->has_right_on_base($download_element->get_base_id(), 'canmodifrecord')) {
             $BF = true;
         }
         $desc = $this->app['serializer.caption']->serialize($download_element->get_caption(), CaptionSerializer::SERIALIZE_XML, $BF);
         $files[$id]['original_name'] = $files[$id]['export_name'] = $download_element->get_original_name(true);
         $files[$id]['original_name'] = trim($files[$id]['original_name']) != '' ? $files[$id]['original_name'] : $id;
         $infos = pathinfo($files[$id]['original_name']);
         $extension = isset($infos['extension']) ? $infos['extension'] : '';
         if ($rename_title) {
             $title = strip_tags($download_element->get_title(null, null, true));
             $files[$id]['export_name'] = $unicode->remove_nonazAZ09($title, true, true, true);
         } else {
             $files[$id]["export_name"] = $infos['filename'];
         }
         $sizeMaxAjout = 0;
         $sizeMaxExt = 0;
         $sd = $download_element->get_subdefs();
         foreach ($download_element->get_downloadable() as $name => $properties) {
             if ($properties === false || !in_array($name, $subdefs)) {
                 continue;
             }
             if (!in_array($name, ['caption', 'caption-yaml']) && !isset($sd[$name])) {
                 continue;
             }
             set_time_limit(100);
             $subdef_export = $subdef_alive = false;
             $n_files++;
             $tmp_pathfile = ['path' => null, 'file' => null];
             switch ($properties['class']) {
                 case 'caption':
                 case 'caption-yaml':
                     $subdef_export = true;
                     $subdef_alive = true;
                     break;
                 case 'thumbnail':
                     $tmp_pathfile = ['path' => $sd[$name]->get_path(), 'file' => $sd[$name]->get_file()];
                     $subdef_export = true;
                     $subdef_alive = true;
                     break;
                 case 'document':
                     $subdef_export = true;
                     $path = \recordutils_image::stamp($this->app, $sd[$name]);
                     $tmp_pathfile = ['path' => $sd[$name]->get_path(), 'file' => $sd[$name]->get_file()];
                     if (file_exists($path)) {
                         $tmp_pathfile = ['path' => dirname($path), 'file' => basename($path)];
                         $subdef_alive = true;
                     }
                     break;
                 case 'preview':
                     $subdef_export = true;
                     $tmp_pathfile = ['path' => $sd[$name]->get_path(), 'file' => $sd[$name]->get_file()];
                     if (!$this->app['acl']->get($user)->has_right_on_base($download_element->get_base_id(), "nowatermark") && !$this->app['acl']->get($user)->has_preview_grant($download_element) && $sd[$name]->get_type() == media_subdef::TYPE_IMAGE) {
                         $path = recordutils_image::watermark($this->app, $sd[$name]);
                         if (file_exists($path)) {
                             $tmp_pathfile = ['path' => dirname($path), 'file' => basename($path)];
                             $subdef_alive = true;
                         }
                     } else {
                         $subdef_alive = true;
                     }
                     break;
             }
             if ($subdef_export === true && $subdef_alive === true) {
                 switch ($properties['class']) {
                     case 'caption':
                         if ($name == 'caption-yaml') {
                             $suffix = '_captionyaml';
                             $extension = 'yml';
                             $mime = 'text/x-yaml';
                         } else {
                             $suffix = '_caption';
                             $extension = 'xml';
                             $mime = 'text/xml';
                         }
                         $files[$id]["subdefs"][$name]["ajout"] = $suffix;
                         $files[$id]["subdefs"][$name]["exportExt"] = $extension;
                         $files[$id]["subdefs"][$name]["label"] = $properties['label'];
                         $files[$id]["subdefs"][$name]["path"] = null;
                         $files[$id]["subdefs"][$name]["file"] = null;
                         $files[$id]["subdefs"][$name]["size"] = 0;
                         $files[$id]["subdefs"][$name]["folder"] = $download_element->get_directory();
                         $files[$id]["subdefs"][$name]["mime"] = $mime;
                         break;
                     case 'document':
                     case 'preview':
                     case 'thumbnail':
                         $infos = pathinfo(p4string::addEndSlash($tmp_pathfile["path"]) . $tmp_pathfile["file"]);
                         $files[$id]["subdefs"][$name]["ajout"] = $name == 'document' ? '' : "_" . $name;
                         $files[$id]["subdefs"][$name]["path"] = $tmp_pathfile["path"];
                         $files[$id]["subdefs"][$name]["file"] = $tmp_pathfile["file"];
                         $files[$id]["subdefs"][$name]["label"] = $properties['label'];
                         $files[$id]["subdefs"][$name]["size"] = $sd[$name]->get_size();
                         $files[$id]["subdefs"][$name]["mime"] = $sd[$name]->get_mime();
                         $files[$id]["subdefs"][$name]["folder"] = $download_element->get_directory();
                         $files[$id]["subdefs"][$name]["exportExt"] = isset($infos['extension']) ? $infos['extension'] : '';
                         $size += $sd[$name]->get_size();
                         break;
                 }
                 $longueurAjoutCourant = mb_strlen($files[$id]["subdefs"][$name]["ajout"]);
                 $sizeMaxAjout = max($longueurAjoutCourant, $sizeMaxAjout);
                 $longueurExtCourant = mb_strlen($files[$id]["subdefs"][$name]["exportExt"]);
                 $sizeMaxExt = max($longueurExtCourant, $sizeMaxExt);
             }
         }
         $max_length = 31 - $sizeMaxExt - $sizeMaxAjout;
         $name = $files[$id]["export_name"];
         $start_length = mb_strlen($name);
         if ($start_length > $max_length) {
             $name = mb_substr($name, 0, $max_length);
         }
         $n = 1;
         while (in_array(mb_strtolower($name), $file_names)) {
             $n++;
             $suffix = "-" . $n;
             // pour diese si besoin
             $max_length = 31 - $sizeMaxExt - $sizeMaxAjout - mb_strlen($suffix);
             $name = mb_strtolower($files[$id]["export_name"]);
             if ($start_length > $max_length) {
                 $name = mb_substr($name, 0, $max_length) . $suffix;
             } else {
                 $name = $name . $suffix;
             }
         }
         $file_names[] = mb_strtolower($name);
         $files[$id]["export_name"] = $name;
         $files[$id]["export_name"] = $unicode->remove_nonazAZ09($files[$id]["export_name"], true, true, true);
         $files[$id]["original_name"] = $unicode->remove_nonazAZ09($files[$id]["original_name"], true, true, true);
         $i = 0;
         $name = utf8_decode($files[$id]["export_name"]);
         $tmp_name = "";
         $good_keys = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_', '.', '#'];
         while (isset($name[$i])) {
             if (!in_array(mb_strtolower($name[$i]), $good_keys)) {
                 $tmp_name .= '_';
             } else {
                 $tmp_name .= $name[$i];
             }
             $tmp_name = str_replace('__', '_', $tmp_name);
             $i++;
         }
         $files[$id]["export_name"] = $tmp_name;
         if (in_array('caption', $subdefs)) {
             $caption_dir = $this->app['root.path'] . '/tmp/desc_tmp/' . time() . $this->app['authentication']->getUser()->getId() . '/';
             $filesystem->mkdir($caption_dir, 0750);
             $desc = $this->app['serializer.caption']->serialize($download_element->get_caption(), CaptionSerializer::SERIALIZE_XML, $BF);
             $file = $files[$id]["export_name"] . $files[$id]["subdefs"]['caption']["ajout"] . '.' . $files[$id]["subdefs"]['caption']["exportExt"];
             $path = $caption_dir;
             file_put_contents($path . $file, $desc);
             $files[$id]["subdefs"]['caption']["path"] = $path;
             $files[$id]["subdefs"]['caption']["file"] = $file;
             $files[$id]["subdefs"]['caption']["size"] = filesize($path . $file);
             $files[$id]["subdefs"]['caption']['businessfields'] = $BF ? '1' : '0';
         }
         if (in_array('caption-yaml', $subdefs)) {
             $caption_dir = $this->app['root.path'] . '/tmp/desc_tmp/' . time() . $this->app['authentication']->getUser()->getId() . '/';
             $filesystem->mkdir($caption_dir, 0750);
             $desc = $this->app['serializer.caption']->serialize($download_element->get_caption(), CaptionSerializer::SERIALIZE_YAML, $BF);
             $file = $files[$id]["export_name"] . $files[$id]["subdefs"]['caption-yaml']["ajout"] . '.' . $files[$id]["subdefs"]['caption-yaml']["exportExt"];
             $path = $caption_dir;
             file_put_contents($path . $file, $desc);
             $files[$id]["subdefs"]['caption-yaml']["path"] = $path;
             $files[$id]["subdefs"]['caption-yaml']["file"] = $file;
             $files[$id]["subdefs"]['caption-yaml']["size"] = filesize($path . $file);
             $files[$id]["subdefs"]['caption-yaml']['businessfields'] = $BF ? '1' : '0';
         }
     }
     $this->list = ['files' => $files, 'names' => $file_names, 'size' => $size, 'count' => $n_files];
     return $this->list;
 }
Пример #10
0
 public function WriteHTML($html)
 {
     require_once 'mod_unicode.php';
     $html = unicode::utf8toiso8859($html);
     $html = strip_tags($html, "<b><u><i><a><img><p><br><strong><em><font><tr><blockquote>");
     //remove all unsupported tags
     $html = str_replace("\n", ' ', $html);
     //replace carriage returns by spaces
     $a = preg_split('/<(.*)>/U', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
     //explodes the string
     foreach ($a as $i => $e) {
         if ($i % 2 == 0) {
             //Text
             if ($this->HREF) {
                 $this->PutLink($this->HREF, $e);
             } else {
                 $this->Write(5, stripslashes($this->txtentities($e)));
             }
         } else {
             //Tag
             if ($e[0] == '/') {
                 $this->CloseTag(strtoupper(substr($e, 1)));
             } else {
                 //Extract attributes
                 $a2 = explode(' ', $e);
                 $tag = strtoupper(array_shift($a2));
                 $attr = array();
                 foreach ($a2 as $v) {
                     if (preg_match('/^([^=]*)=["\']?([^"\']*)["\']?$/', $v, $a3)) {
                         $attr[strtoupper($a3[1])] = $a3[2];
                     }
                 }
                 $this->OpenTag($tag, $attr);
             }
         }
     }
 }
Пример #11
0
 function utf8toiso8859($string, $entities = true)
 {
     return unicode::utf8convert($string, 0xff, $entities);
 }
Пример #12
0
 public function next()
 {
     switch ($this->readMode) {
         case 'array':
             $result = current($this->csvArray);
             next($this->csvArray);
             break;
         default:
         case "fp":
             if (feof($this->fp)) {
                 $result = array();
             } else {
                 $result = fgetcsv($this->fp, $this->settings['bufferLength'], $this->settings['seperator'], $this->settings['quotation']);
                 if (is_array($result) && strtolower($this->settings['charset']) != "utf-8") {
                     if (!function_exists("iconv")) {
                         global $store;
                         include_once $store->get_config("code") . "modules/mod_unicode.php";
                         foreach ($result as $item => $resultItem) {
                             $result[$item] = unicode::convertToUTF8($this->settings["charset"], $result[$item]);
                         }
                     } else {
                         foreach ($result as $item => $resultItem) {
                             $result[$item] = iconv($this->settings["charset"], "utf-8", $result[$item]);
                         }
                     }
                 }
             }
             break;
     }
     if ($result && $this->keys && $this->settings['keySelection']) {
         $hashResult = array();
         foreach ($this->keys as $i => $key) {
             if (in_array($key, $this->settings['keySelection'])) {
                 $hashResult[$key] = $result[$i];
             }
         }
         $result = $hashResult;
     }
     $this->readLine = $result;
     return $result;
 }