EGOCMS  18.0
EGOTEC Content-Managament-System
Mediapool.php
gehe zur Dokumentation dieser Datei
1 <?php
13 class Mediapool {
14  private $page;
15  private $site;
16  public $currentDir = 'current';
24  public function __construct(Page $page) {
25  $this->page = $page;
26  $this->site = $this->page->getSite();
27  }
28 
42  public function put($source, $name, $dir = '', $extract = false, $replace = true, $types = '', $save = true, $original = true) {
43  if ($original && ($original_page = $this->page->getCloneOriginal())) {
44  return $original_page->getMediapool()->put($source, $name, $dir, $extract, $replace, $types);
45  }
46  if ($extract || $this->page->validateFile($source, $name)) {
47  // Prüfen, ob dieser Dateityp hochgeladen werden darf
48  require_once('base/Ego_MimeType.php');
49  $mime = new Ego_MimeType();
50  switch ($types) {
51  case 'image':
52  if (strpos($mime->autoDetect($source), 'image') !== 0) {
53  return null;
54  }
55  break;
56  case 'file':
57  if (strpos($mime->autoDetect($source), 'image') === 0) {
58  return null;
59  }
60  }
61 
62  // Datei hinzufügen
63  $this->create();
64  $dir = $this->getDir($dir);
65  $path = $this->dir()
66  . rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
67  if (!Ego_System::file_exists($path)) {
68  Ego_System::mkdir($path);
69  }
70  $name = strtr(mb_ereg_replace('[^a-zA-Z0-9\-äöüÄÖÜß()\[\]\.,_ ]', '_', $name), '#?&+', '____'); // Zeichen, die im Namen vorkommen dürfen
71  if (!$replace) {
72  // Eine Datei mit dem selben Namen nicht überschreiben
73  $parts = explode('.', $name, 2);
74  $filename = $parts[0];
75  $suffix = $parts[1] ? '.' . $parts[1] : '';
76  $n = 1;
77  while ((bool)$this->file($name, $dir)) {
78  $name = $filename . '_' . ($n++) . $suffix;
79  }
80  }
81  $file = $path . Ego_System::base64Encode($name);
82  if ($source !== $file) {
83  @unlink($file); // Wegen hard links muss vorher gelöscht werden.
84  }
85  if (Ego_System::copy($source, $file)) {
86  if ($extract) {
87  $this->extract($name, $dir);
88  }
89 
90  $data = $this->get($name, $dir);
91 
92  // Copyright für Bilder automatisch ermitteln
93  if ($data['isImage']) {
94  require_once('base/Ego_Image.php');
95  $imageTransform = new Ego_Image();
96  $imageTransform->load($file);
97 
98  $copyright = $imageTransform->getExif(Ego_Image::EXIF_COPYRIGHT);
99  if (trim($copyright) != '') {
100  $data['copyright'] = $copyright;
101 
102  if ($save) {
103  $this->setInfo($dir, $name, 'copyright', $copyright);
104  $this->page->update(array(), true, true);
105  }
106  }
107  }
108 
109  return $data;
110  }
111  }
112  return null;
113  }
114 
122  public function extract($name, $dir = '') {
123  if ($original_page = $this->page->getCloneOriginal()) {
124  return $original_page->getMediapool()->extract($name, $dir);
125  }
126  $dir = $this->getDir($dir);
127  $path = $this->dir();
128  $file = $this->file($name, $dir);
129  if ($file) {
130  $tmp_file = tempnam($GLOBALS['egotec_conf']['tmp_dir'], 'ZIP_').'.zip';
131  if (Ego_System::copy($file, $tmp_file)) {
132  require_once('media/functions.php');
133  if (preg_match('/\.gz$/msi', $name)) {
134  require_once('Archive/Tar.php');
135  $zip = new Archive_Tar($tmp_file);
136  } else {
137  require_once('Archive/Zip.php');
138  $zip = new Archive_Zip($tmp_file);
139  }
140  $cwd = getcwd();
141  chdir($path.$dir);
142  @set_time_limit(0);
143  $list = $zip->extract();
144  @unlink($file);
145  @unlink($tmp_file);
146  chdir($cwd);
147  if (is_array($list)) {
148  $main_dir = '';
149  foreach ($list as $info) {
150  $info_dir = $path
151  .rtrim($dir, DIRECTORY_SEPARATOR)
152  .DIRECTORY_SEPARATOR.$info['stored_filename'];
153  if (!is_dir($info_dir)) {
154  if ($this->page->validateFile($info_dir)) {
155  $info_name = Ego_System::base64Encode(basename($info['stored_filename']));
156  @rename(
157  $info_dir,
158  $path
159  . rtrim($dir, DIRECTORY_SEPARATOR)
160  . DIRECTORY_SEPARATOR . $info_name
161  );
162  } else {
163  @unlink($info_dir);
164  }
165  } elseif ($main_dir == '' || strlen($info_dir) < strlen($main_dir)) {
166  $main_dir = $info_dir;
167  }
168  }
169  if ($main_dir != '') {
170  Ego_System::deldir($main_dir);
171  }
172  return true;
173  } elseif ($list === true) {
174  // TODO Tar liefert keine Liste der entpackten Dateien
175  return true;
176  }
177  }
178  }
179  return false;
180  }
181 
192  public function get($name, $dir = '', $params = array(), $decoded = false, $block = '') {
193  $dir = $this->getDir($dir);
194  $params['pool'] = $name;
195  $file = $this->file($name, $dir);
196  $sub_dir = $this->subDir($dir);
197  if (!$file) {
198  if (!$decoded) {
199  // Fallback, falls der Name kodiert übergeben, aber nicht kodiert gespeichert wurde
200  return $this->get(urldecode($name), $dir, $params, true);
201  }
202  return array();
203  }
204 
205  // Mime-Type der Datei
206  require_once 'base/Ego_MimeType.php';
207  $mime = new Ego_MimeType();
208  $mime_type = $mime->autoDetect($file);
209 
210  $suffix = '';
211  if (preg_match('/\.([^\.]+)$/ims', $name, $match)) {
212  $suffix = strtolower($match[1]);
213  }
214  if (
215  (!empty($suffix) && $ext = $suffix)
216  || ($ext = $mime->getExtension($mime_type))
217  ) {
218  $isImage = in_array($ext, Ego_System::getFormats('image'));
219  $isArchive = in_array($ext, Ego_System::getFormats('archive'));
220  $isVideo = in_array($ext, Ego_System::getFormats('video'));
221  }
222  $sub_data = array();
223 
224  $width = $height = null;
225  if ($info = Ego_System::getFileInfo($file)) {
226  $width = $info['width'];
227  $height = $info['height'];
228  if ($isImage) {
229  $params['width'] = $width;
230  $params['height'] = $height;
231  }
232  if (isset($info['duration'])) {
233  $sub_data['duration'] = $info['duration'];
234  }
235  }
236  if ((string) $dir != (string) $this->currentDir) {
237  $params['dir'] = $this->subDir($dir);
238  }
239  $params['site'] = $this->site->name;
240  $params['lang'] = $this->site->language;
241  $params['id'] = $this->page->field['id'];
242 
243  // Download URL ohne width und height
244  $download_params = $params;
245  $download_params['download'] = 1;
246  unset($download_params['width'], $download_params['height']);
247 
248  // Titel bestimmen
249  $title = $name;
250  if ($extra_title = (string) ($this->page->extra['mediapool'][md5($sub_dir)][md5($name)]['title'])) {
251  $title = $extra_title;
252  } elseif ($pos = strrpos($name, '.')) {
253  $title = substr($name, 0, $pos);
254  }
255 
256  // Zusätzliche Eigenschaften
257  $extra = array();
258  if ($block) {
259  $extra_key = 'block.' . $block;
260  } else {
261  $extra_key = ($sub = strrchr($dir, DIRECTORY_SEPARATOR)) ? substr($sub, 1) : 'default';
262  }
263  if ($this->page->conf['mediapool'][$extra_key]['extra']) {
264  foreach ($this->page->conf['mediapool'][$extra_key]['extra'] as $field) {
265  $extra[$field['name']] = $this->page->extra['mediapool'][md5($sub_dir)][md5($name)][$field['name']];
266  }
267  }
268 
275  $get_url = function($params) {
276  unset($params['mime_type']);
277  return 'index.php?' . str_replace('%2F', '/', http_build_query($params));
278  };
279 
280  $data = array_merge(array(
281  'name' => $name,
282  'file' => $file,
283  'url' => $get_url($params),
284  'download' => $get_url($download_params),
285  'size' => @filesize($file),
286  'mime' => $mime_type,
287  'width' => $width,
288  'height' => $height,
289  'suffix' => $suffix,
290  'isImage' => $isImage,
291  'isArchive' => $isArchive,
292  'isVideo' => $isVideo,
293  'lastChange' => @filemtime($file),
294  'title' => $title,
295  'description' => (string) $this->page->extra['mediapool'][md5($sub_dir)][md5($name)]['description'],
296  'copyright' => (string) $this->page->extra['mediapool'][md5($sub_dir)][md5($name)]['copyright'],
297  'order' => (int) $this->page->extra['mediapool'][md5($sub_dir)][md5($name)]['order'],
298  'clip' => $this->page->extra['mediapool'][md5($sub_dir)][md5($name)]['clip'],
299  'rotation' => (int) $this->page->extra['mediapool'][md5($sub_dir)][md5($name)]['rotation'],
300  'mirror' => (string) $this->page->extra['mediapool'][md5($sub_dir)][md5($name)]['mirror'],
301  'extra' => $extra
302  ), $sub_data);
303  return $data;
304  }
305 
313  public function file($name, $dir = '') {
314  $dir = $this->getDir($dir);
315  $file = $this->dir()
316  .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.Ego_System::base64Encode($name);
317  if (Ego_System::file_exists($file)) {
318  return $file;
319  } else {
320  // Abwärtskompatibilität zu alten base64 Strings
321  $file = $this->dir()
322  .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.base64_encode($name);
323  if (Ego_System::file_exists($file)) {
324  return $file;
325  }
326  }
327  return null;
328  }
329 
337  public function delete($name, $dir = '') {
338  if ($original_page = $this->page->getCloneOriginal()) {
339  return $original_page->getMediapool()->delete($name, $dir);
340  }
341  $dir = $this->getDir($dir);
342  $file = $this->dir()
343  .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.Ego_System::base64Encode($name);
344  if (!Ego_System::file_exists($file)) {
345  // Abwärtskompatibilität zu alten base64 Strings
346  $file = $this->dir()
347  .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.base64_encode($name);
348  }
349 
350  if (
351  (is_dir($file) && Ego_System::deldir($file))
352  || @unlink($file)
353  ) {
354  if ($dir == $this->currentDir) {
355  $this->page->update();
356  }
357  return true;
358  }
359  return false;
360  }
361 
370  public function edit($name, $params = array(), $dir = '') {
371  if ($original_page = $this->page->getCloneOriginal()) {
372  return $original_page->getMediapool()->put($name, $params, $dir);
373  }
374  $dir = $this->getDir($dir);
375  $file = $this->file($name, $dir);
376  $sub_dir = $this->subDir($dir);
377  $new_name = trim($params['new_name']);
378 
379  if (
380  !empty($file)
381  && !empty($new_name)
382  && $name != $new_name
383  && ($data = $this->put($file, $new_name, $dir, false, (bool) $params['replace']))
384  ) {
385  if ($this->delete($name, $dir, false)) {
386  // Alle Verweise auf den originalen Namen ändern
387  $this->page->field['content'] = $this->renameRecursive($name, $new_name, $this->page->field['content']);
388  $this->page->field['short'] = $this->renameRecursive($name, $new_name, $this->page->field['short']);
389  $this->page->extra = $this->renameRecursive($name, $new_name, $this->page->extra);
390  $this->page->extra['mediapool'][md5($sub_dir)][md5($new_name)] = $this->page->extra['mediapool'][md5($sub_dir)][md5($name)];
391  unset($this->page->extra['mediapool'][md5($sub_dir)][md5($name)]);
392  $name = $new_name;
393  } else {
394  // Änderungen zurücksetzen
395  $this->delete($new_name, $dir);
396  return false;
397  }
398  }
399  // Hinzufügen der Datei in das Extra-Feld der Seite
400  if (empty($this->page->extra['mediapool'][md5($sub_dir)][md5($name)])) {
401  $this->page->extra['mediapool'][md5($sub_dir)][md5($name)] = array();
402  }
403 
404  unset($params['new_name'], $params['replace']);
405  $this->page->extra['mediapool'][md5($sub_dir)][md5($name)] = array_merge($this->page->extra['mediapool'][md5($sub_dir)][md5($name)], $params);
406 
407  $this->page->update(array(
408  'field' => array(
409  'content' => $this->page->field['content'],
410  'short' => $this->page->field['short']
411  ),
412  'extra' => $this->page->extra
413  ), true, true);
414  return true;
415  }
416 
425  private function renameRecursive($name, $new_name, $value) {
426  if (is_array($value)) {
427  foreach ($value as $key => $v) {
428  $value[$key] = $this->renameRecursive($name, $new_name, $value[$key]);
429  }
430  } elseif (preg_match_all('/index\.php\?[^>"]+/ims', $value, $matches)) {
431  foreach ($matches[0] as $match) {
432  $new_url = preg_replace('/([&?])pool='.preg_quote($name, '/').'/msi', '$1pool='.$new_name, $match);
433  $value = str_replace($match, $new_url, $value);
434  }
435  }
436  return $value;
437  }
438 
460  public function list($dir = '', $params = array(), $block = '') {
461  $dir = $this->getDir($dir);
462  $list = array();
463  $path = $this->dir()
464  .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
465  if (Ego_System::file_exists($path)) {
466  if ($handle = opendir($path)) {
467  $params2 = $params;
468  unset(
469  $params2['sort_field'],
470  $params2['sort_reverse'],
471  $params2['search'],
472  $params2['only_image']
473  );
474  while (false !== ($file = readdir($handle))) {
475  if ($file != '.' && $file != '..' && !is_dir($path.$file)) {
476  $data = $this->get(Ego_System::base64Decode($file), $dir, $params2, false, $block);
477  if (
478  !empty($data)
479  && (
480  (
481  !$params['only_image']
482  && !$_REQUEST['session']['insert_image']
483  )
484  || $data['isImage']
485  )
486  && (
487  (
488  !$params['only_video']
489  && !$_REQUEST['session']['insert_video']
490  )
491  || $data['isVideo']
492  )
493  && (
494  (
495  !$params['only_file']
496  && !$_REQUEST['session']['insert_file']
497  )
498  || !$data['isImage']
499  )
500  && (
501  (
502  !$params['only_media']
503  && !$_REQUEST['session']['insert_media']
504  )
505  || $data['isImage']
506  || $data['isVideo']
507  )
508  && (
509  empty($params['mime_type'])
510  || preg_match('#'.$params['mime_type'].'#i', $data['mime'])
511  )
512  && (
513  empty($params['search'])
514  || stripos($data['name'], $params['search']) !== false
515  || stripos($data['title'], $params['search']) !== false
516  )
517  ) {
518  $list[] = $data;
519  }
520  }
521  }
522  }
523  }
524  if (!empty($list)) {
525  $sort = array();
526  $names = array();
527  foreach ($list as $file) {
528  $sort_field = ($params['sort_field'] && isset($file[$params['sort_field']]))
529  ? $file[$params['sort_field']]
530  : $file['order'];
531  $sort[] = is_string($sort_field)
532  ? mb_strtolower($sort_field)
533  : $sort_field;
534  $names[] = mb_strtolower($file['name']);
535  }
536  if (!$params['sort_field'] && sizeof(array_unique($sort)) == 1) {
537  // Standardmäßig nach Namen sortieren
538  array_multisort(
539  $names,
540  $params['sort_reverse'] ? SORT_DESC : SORT_ASC,
541  SORT_STRING,
542  $list
543  );
544  } else {
545  // Individuelle Sortierung
546  array_multisort(
547  $sort,
548  $params['sort_reverse'] ? SORT_DESC : SORT_ASC,
549  is_string($sort_field) ? SORT_STRING : SORT_NUMERIC,
550  $list
551  );
552  }
553  }
554  if (isset($params['start'])) {
555  // Einen Teil ausgeben
556  $list = array_slice($list, $params['start'], $params['end']);
557  }
558  return $list;
559  }
560 
570  public function setInfo($dir, $name, $key, $value = null) {
571  $sub_dir = $this->subDir($dir);
572  if ($value === null) {
573  unset($this->page->extra['mediapool'][md5($sub_dir)][md5($name)][$key]);
574  } else {
575  $this->page->extra['mediapool'][md5($sub_dir)][md5($name)][$key] = $value;
576  }
577  return implode('.', array('mediapool', md5($sub_dir), md5($name), $key));
578  }
579 
587  public function dir($relative = false, $source = null) {
588  if ($source) {
589  $site = $source->getSite();
590  $name = $site->name;
591  $lang = $site->language;
592  $id = $source->field['id'];
593  } else {
594  $name = $this->site->name;
595  $lang = $this->site->language;
596  $id = $this->page->field['id'];
597  }
598  return (!$relative ? $GLOBALS['egotec_conf']['var_dir'] : '').'media'.
599  DIRECTORY_SEPARATOR.$name.
600  DIRECTORY_SEPARATOR.$lang.
601  DIRECTORY_SEPARATOR. 'pool' .
602  DIRECTORY_SEPARATOR.$id.
603  DIRECTORY_SEPARATOR;
604  }
605 
612  private function subDir($dir) {
613  $sub_dir = '';
614  if ($dirs = explode(DIRECTORY_SEPARATOR, $dir)) {
615  if ($dirs[0] == $this->currentDir) {
616  unset($dirs[0]);
617  }
618  $sub_dir = implode(DIRECTORY_SEPARATOR, $dirs);
619  }
620  return $sub_dir;
621  }
622 
629  private function getDir($dir) {
630  if (preg_match('/^\d+($|' . preg_quote(DIRECTORY_SEPARATOR, '/') . '.*?$)/', $dir)) {
631  // Archive sind niemals Unterverzeichnisse
632  return $dir;
633  } elseif (empty($dir) || $dir == $this->currentDir) {
634  // Standard Verzeichnis
635  return $this->currentDir;
636  }
637  // Unterverzeichnis
638  return $this->currentDir . DIRECTORY_SEPARATOR . $this->subDir($dir);
639  }
640 
648  public function archive($c_date, $dir = '') {
649  if ($original_page = $this->page->getCloneOriginal()) {
650  return $original_page->getMediapool()->archive($c_date, $dir);
651  }
652  $dir = $this->getDir($dir);
653  $path = $this->dir();
654  if (Ego_System::file_exists($path)) {
655  $src = $path.rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
656  $dest = $path.($dir != $this->currentDir ? $dir : '')
657  .Ego_System::dateEncode($c_date).DIRECTORY_SEPARATOR;
658  Ego_System::deldir($dest); // Archiv vorher löschen, falls es bereits existiert
659  return Ego_System::copy($src, $dest, '', true); // Kopie mit hard links
660  }
661  return false;
662  }
663 
672  public function restore($c_date, $name = '', $dir = '') {
673  if ($original_page = $this->page->getCloneOriginal()) {
674  return $original_page->restore($c_date, $name, $dir);
675  }
676  if (!empty($c_date)) {
677  $dir = $this->getDir($dir);
678  if (empty($name)) {
679  // Gesamten Mediapool wiederherstellen
680  $dest = $this->dir()
681  .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
682  $source = $this->dir().$c_date.DIRECTORY_SEPARATOR;
683  if (
684  Ego_System::file_exists($source)
685  && Ego_System::file_exists($dest)
686  ) {
687  $archive_page = $this->page->getArchivePage(is_numeric($c_date) ? date('Y-m-d H:i:s', $c_date) : $c_date);
688  $mediapool = $archive_page ? $archive_page->extra['mediapool'] : array();
689  $this->clear($dir, $mediapool);
690  return Ego_System::copy($source, $dest);
691  }
692  } else {
693  // Eine Datei im Mediapool wiederherstellen
694  $path = $dir == $this->currentDir
695  ? $c_date
696  : rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$c_date;
697  $source = $this->get($name, $path);
698  return (bool) $this->put($source['file'], $name, $dir);
699  }
700  }
701  return false;
702  }
703 
709  private function create() {
710  $dir = $this->dir();
711  if (!Ego_System::file_exists($dir)) {
712  Ego_System::mkdir($dir);
713  }
714  }
715 
727  public function copy(Page $target, $dir = '', $clear = false, $integrate = false, $archive = true, $asis = true) {
728  $path = $this->dir();
729  if (!empty($dir)) {
730  $path .= rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
731  }
732  if (Ego_System::file_exists($path)) {
733  // Original kopieren
734  $dest = $this->dir(false, $target);
735  if (!empty($dir)) {
736  $dest .= rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
737  }
738  if (!$integrate) {
739  Ego_System::deldir($dest);
740  }
741  Ego_System::copy($path, $dest, ($archive ? '' : '/^\d+$/'), true); // Hard Links erstellen
742 
743  // Verweise anpassen
744  $target->getMediapool()->import(true, true, $dir, true, $asis);
745 
746  // Original löschen
747  if ($clear) {
748  $this->clear($dir);
749  }
750  }
751  }
752 
762  public function move($target, $dir = '', $integrate = false, $archive = true) {
763  $this->copy($target, $dir, true, $integrate, $archive);
764  }
765 
773  public function exists($dir = '', $empty = true) {
774  $dir = $this->getDir($dir);
775  $path = $this->dir()
776  .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
777  return Ego_System::file_exists($path) && ($empty || sizeof(is_array($scanned_dir = scandir($path)) ? $scanned_dir : []) > 2);
778  }
779 
788  public function clear($dir = '', $mediapool = array(), $update = true) {
789  if ($original_page = $this->page->getCloneOriginal()) {
790  return $original_page->getMediapool()->clear($dir);
791  }
792  $path = $this->dir();
793  if (!empty($dir)) {
794  $path .= rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
795  }
796  $sub_dir = $this->subDir($dir);
797 
798  if ($update) { // Zusätzliche Informationen zu diesem Mediapool löschen/setzen
799  if (!empty($mediapool)) {
800  $this->page->extra['mediapool'] = $mediapool;
801  } else {
802  unset($this->page->extra['mediapool'][md5($sub_dir)]);
803  }
804  $this->page->update(array(), true, true);
805  }
806 
807  Ego_System::deldir($path);
808  }
809 
820  public function import($only_pool = false, $replace = false, $dir = '', $update = true, $asis = true) {
821  $this->page->field['content'] = $this->importRecursive($this->page->field['content'], $only_pool, $replace, $dir);
822  $this->page->field['short'] = $this->importRecursive($this->page->field['short'], $only_pool, $replace, $dir);
823  $this->page->extra = $this->importRecursive($this->page->extra, $only_pool, $replace, $dir);
824  if ($update) {
825  $this->page->update(array(
826  'field' => array(
827  'content' => $this->page->field['content'],
828  'short' => $this->page->field['short']
829  ),
830  'extra' => $this->page->extra
831  ), true, $asis);
832  }
833  }
834 
845  private function importRecursive($value, $only_pool = false, $replace = false, $dir = '') {
846  if (is_array($value)) {
847  foreach ($value as $key => $v) {
848  $value[$key] = $this->importRecursive($v, $only_pool, $replace, $dir);
849  }
850  } elseif (preg_match_all('/index\.php\?[^>"]+/ims', $value, $matches)) {
851  $dir = $dir == '' ? '' : rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
852  foreach ($matches[0] as $url) {
853  $page = Ego_System::urltopage($url, array(
854  'params' => array(
855  'param' => array(
856  'auth_or' => '1=1',
857  'deleted_or' => '1=1',
858  'inactive' => true,
859  'only_active' => false
860  )
861  )
862  ));
863  $info = Ego_System::getUrlInfo($url);
864  if ($page) {
865  if (
866  !$only_pool
867  && in_array($page->field['type'], array('multimedia/file', 'multimedia/image'))
868  ) {
869  // Multimedia
870  $site = $page->getSite();
871  $path = $GLOBALS['egotec_conf']['var_dir'].'media/'.$site->name.'/';
872  $file = $path.$page->getMediaFilename();
873  if (Ego_System::file_exists($file)) {
874  $name = $page->field['name'];
875  $suffix = '';
876  if ($page->extra['image_type']) {
877  $suffix = '.'.$page->extra['image_type'];
878  }
879  if (!$replace) {
880  while ($this->file($name.$suffix, $dir)) {
881  // Eine Datei mit dem selben Namen existiert bereits
882  if (preg_match('/_(\d+)$/ims', $name, $match)) {
883  $num = ((int) $match[1]) + 1;
884  $name = preg_replace('/_\d+$/ims', '', $name);
885  } else {
886  $num = 1;
887  }
888  $name .= '_'.$num;
889  }
890  }
891  $media = $this->put($file, $name.$suffix, $dir);
892  if (!empty($media['url'])) {
893  $value = str_replace($url, $media['url'], $value);
894  }
895  }
896  } elseif (!empty($info['params']['pool'])) {
897  // Mediapool
898  $media = $page->getMediapool()->get(urldecode($info['params']['pool']), $dir);
899  if ($media['file']) {
900  $media = $this->put(
901  $media['file'],
902  $media['name'],
903  $dir,
904  false,
905  $replace,
906  '',
907  true,
908  !$this->page->isClone() // Beim Import in einen Klon, werden die Mediapool URLs auf den Klon umgeschrieben
909  );
910  }
911  if (!empty($media['url'])) {
912  $value = str_replace($url, $media['url'], $value);
913  }
914  }
915  }
916  }
917  }
918  return $value;
919  }
920 }
dir($relative=false, $source=null)
Definition: Mediapool.php:587
static getFormats($type)
archive($c_date, $dir='')
Definition: Mediapool.php:648
exists($dir='', $empty=true)
Definition: Mediapool.php:773
extract($name, $dir='')
Definition: Mediapool.php:122
static deldir($location, $del=true, $without='', $rename=true)
Definition: Ego_System.php:593
__construct(Page $page)
Definition: Mediapool.php:24
static urltopage($url, $params=array(), $only_site=false, $error_page=false, $commit_params=false)
static base64Decode($s)
move($target, $dir='', $integrate=false, $archive=true)
Definition: Mediapool.php:762
restore($c_date, $name='', $dir='')
Definition: Mediapool.php:672
static file_exists($file)
Definition: Page.php:27
setInfo($dir, $name, $key, $value=null)
Definition: Mediapool.php:570
static mkdir($dir, $mode=0755, $recursive=true)
Definition: Ego_System.php:497
file($name, $dir='')
Definition: Mediapool.php:313
const EXIF_COPYRIGHT
Definition: Ego_Image.php:20
getSite()
Definition: Page.php:4426
list($dir='', $params=array(), $block='')
Definition: Mediapool.php:460
static getUrlInfo($url, $encode=false)
edit($name, $params=array(), $dir='')
Definition: Mediapool.php:370
static copy($src, $dest, $except='', $useLinks=false)
put($source, $name, $dir='', $extract=false, $replace=true, $types='', $save=true, $original=true)
Definition: Mediapool.php:42
static base64Encode($s)
static getFileInfo($file)
static dateEncode($string)
Definition: Ego_System.php:484
clear($dir='', $mediapool=array(), $update=true)
Definition: Mediapool.php:788
copy(Page $target, $dir='', $clear=false, $integrate=false, $archive=true, $asis=true)
Definition: Mediapool.php:727
getMediapool()
Definition: Page.php:4435