コード例 #1
0
ファイル: unicodeTest.php プロジェクト: nlegoff/Phraseanet
 /**
  * @covers \unicode::remove_nonazAZ09
  */
 public function testRemove_nonazAZ09()
 {
     $this->assertEquals('Elephant', $this->object->remove_nonazAZ09('Eléphant'));
     $this->assertEquals('Ee-e_cau.09876543213e32', $this->object->remove_nonazAZ09('É&é"\'(-è_çà)=$*ù:;,?./§%µ£°0987654321Œ3~#{[|^`@]}ê³²÷׿', true, true, true));
     $this->assertEquals('Ee-e_cau09876543213e32', $this->object->remove_nonazAZ09('É&é"\'(-è_çà)=$*ù:;,?./§%µ£°0987654321Œ3~#{[|^`@]}ê³²÷׿', true, true, false));
     $this->assertEquals('Eee_cau.09876543213e32', $this->object->remove_nonazAZ09('É&é"\'(-è_çà)=$*ù:;,?./§%µ£°0987654321Œ3~#{[|^`@]}ê³²÷׿', true, false, true));
     $this->assertEquals('Ee-ecau.09876543213e32', $this->object->remove_nonazAZ09('É&é"\'(-è_çà)=$*ù:;,?./§%µ£°0987654321Œ3~#{[|^`@]}ê³²÷׿', false, true, true));
     $this->assertEquals('Eeecau09876543213e32', $this->object->remove_nonazAZ09('É&é"\'(-è_çà)=$*ù:;,?./§%µ£°0987654321Œ3~#{[|^`@]}ê³²÷׿', false, false, false));
 }
コード例 #2
0
ファイル: exportElement.php プロジェクト: nlegoff/Phraseanet
 /**
  *
  * @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
ファイル: field.php プロジェクト: nlegoff/Phraseanet
 public static function generateName($name)
 {
     $unicode_processor = new unicode();
     $name = $unicode_processor->remove_nonazAZ09($name, false, false);
     return $unicode_processor->remove_first_digits($name);
 }
コード例 #4
0
ファイル: export.php プロジェクト: romainneutron/Phraseanet
 /**
  *
  * @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;
 }