26 $this->site = $this->page->
getSite();
46 public function put($source, $name, $dir =
'', $extract =
false, $replace =
true, $types =
'', $save =
true, $original =
true, $source_extra = array(), &$files = array()) {
47 if (!isset($GLOBALS[
'__egotec_skip_replication'])) {
48 $GLOBALS[
'__egotec_skip_replication'] =
'pool.put';
51 if ($original && ($original_page = $this->page->getCloneOriginal())) {
52 return $original_page->getMediapool()->put($source, $name, $dir, $extract, $replace, $types);
57 if ($extract || $this->page->validateFile($source, $name)) {
59 require_once(
'base/Ego_MimeType.php');
63 if (strpos($mime->autoDetect($source),
'image') !== 0) {
68 if (strpos($mime->autoDetect($source),
'image') === 0) {
75 $dir = $this->getDir($dir);
77 . rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
81 $name = strtr(mb_ereg_replace(
'[^a-zA-Z0-9\-äöüÄÖÜß()\[\]\.,_ ]',
'_', $name),
'#?&+',
'____');
84 $parts = explode(
'.', $name, 2);
85 $filename = $parts[0];
86 $suffix = $parts[1] ?
'.' . $parts[1] :
'';
88 while ((
bool)$this->
file($name, $dir)) {
89 $name = $filename .
'_' . ($n++) . $suffix;
93 if ($source !== $file) {
98 $this->
extract($name, $dir, $files);
100 $files[] = $this->
get($name, $dir);
104 $save_copyright =
false;
105 foreach ($files as $data) {
106 if ($data[
'isImage']) {
107 require_once(
'base/Ego_Image.php');
110 $imageTransform->load($data[
'file']);
113 if (trim($copyright) !=
'') {
114 $data[
'copyright'] = $copyright;
118 || $this->site->conf[
'admin'][
'mediapool'][
'upload_copyright']
120 $this->
setInfo($dir, $data[
'name'],
'copyright', $copyright);
121 $save_copyright =
true;
130 if ($save_copyright) {
131 $this->page->extra[
'_asis'] = 3;
134 if (!empty($source_extra)) {
135 foreach ($source_extra as $key => $value) {
136 $this->
setInfo($dir, $name, $key, $value);
138 $this->page->extra[
'_asis'] = 5;
141 $data[
'extra'] = $this->page->extra[
'mediapool'];
142 if ($save_copyright || !empty($source_extra)) {
143 $this->page->update(array(),
true,
true);
150 $this->page->replicate(
'pool.put',
"@file:$source", $name, $dir, $extract, $replace, $types, $save, $original);
163 $item = $this->
get($name, $dir);
165 return $this->
put($item[
'file'], $name, $dir,
false,
false,
'',
true,
true, $item[
'extra']);
178 public function extract($name, $dir =
'', &$files = []) {
179 if (!isset($GLOBALS[
'__egotec_skip_replication'])) {
180 $GLOBALS[
'__egotec_skip_replication'] =
'pool.extract';
183 if ($original_page = $this->page->getCloneOriginal()) {
184 return $original_page->getMediapool()->extract($name, $dir);
186 $dir = $this->getDir($dir);
187 $path = $this->
dir();
188 $file = $this->
file($name, $dir);
190 $tmp_file = tempnam($GLOBALS[
'egotec_conf'][
'tmp_dir'],
'ZIP_').
'.zip';
192 require_once(
'media/functions.php');
193 if (preg_match(
'/\.gz$/msi', $name)) {
194 require_once(
'Archive/Tar.php');
195 $zip =
new Archive_Tar($tmp_file);
197 require_once(
'Archive/Zip.php');
198 $zip =
new Archive_Zip($tmp_file);
203 $list = $zip->extract();
207 if (is_array($list)) {
209 foreach ($list as $info) {
211 .rtrim($dir, DIRECTORY_SEPARATOR)
212 .DIRECTORY_SEPARATOR.$info[
'stored_filename'];
213 if (!is_dir($info_dir)) {
214 if ($this->page->validateFile($info_dir)) {
219 . rtrim($dir, DIRECTORY_SEPARATOR)
220 . DIRECTORY_SEPARATOR . $info_name
224 $files[] = $this->
get(basename($info[
'stored_filename']), $dir);
228 } elseif ($main_dir ==
'' || strlen($info_dir) < strlen($main_dir)) {
229 $main_dir = $info_dir;
232 if ($main_dir !=
'') {
236 $this->page->replicate(
"pool.extract", $name, $dir);
239 } elseif ($list ===
true) {
259 public function get($name, $dir =
'', $params = array(), $decoded =
false, $block =
'') {
260 $dir = $this->getDir($dir);
261 $params[
'pool'] = $name;
262 $file = $this->
file($name, $dir, $convert);
263 $name_key = md5(!empty($convert) ? $convert[
'name'] : $name);
264 $sub_dir = $this->subDir($dir);
268 return $this->
get(urldecode($name), $dir, $params,
true);
274 if (preg_match(
'/\.([^\.]+)$/ims', $name, $match)) {
275 $suffix = strtolower($match[1]);
279 require_once
'base/Ego_MimeType.php';
281 $mime_type = !empty($convert)
283 : ($mime->byExtension($suffix) ?? $mime->autoDetect($file));
286 (!empty($suffix) && $ext = $suffix)
287 || ($ext = $mime->getExtension($mime_type))
295 $width = $height =
null;
297 $width = $info[
'width'];
298 $height = $info[
'height'];
300 $params[
'width'] = $width ?:
null;
301 $params[
'height'] = $height ?:
null;
303 if (isset($info[
'duration'])) {
304 $sub_data[
'duration'] = $info[
'duration'];
307 if ((
string) $dir != (
string) $this->currentDir) {
308 $params[
'dir'] = $this->subDir($dir);
310 $params[
'site'] = $this->site->name;
311 $params[
'lang'] = $this->site->language;
312 $params[
'id'] = $this->page->field[
'id'];
315 $download_params = $params;
316 $download_params[
'download'] = 1;
317 unset($download_params[
'width'], $download_params[
'height']);
320 $title = empty($params[
'no_auto_title']) ? $name :
'';
321 if ($extra_title = (
string) ($this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'title'])) {
322 $title = $extra_title;
323 } elseif ($pos = strrpos($title,
'.')) {
324 $title = substr($title, 0, $pos);
330 $extra_key =
'block.' . $block;
332 $extra_key = ($sub = strrchr($dir, DIRECTORY_SEPARATOR)) ? substr($sub, 1) :
'default';
334 if ($this->page->conf[
'mediapool'][$extra_key][
'extra']) {
335 foreach ($this->page->conf[
'mediapool'][$extra_key][
'extra'] as $field) {
336 $extra[$field[
'name']] = $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][$field[
'name']];
346 $get_url =
function($params) {
347 unset($params[
'mime_type']);
348 return 'index.php?' . str_replace(
'%2F',
'/', http_build_query($params));
362 $pattern =
'/([.?*+^$[\]\\(){}|-])/';
363 $name1 = str_replace($pattern,
'\\$1', $name);
364 $name2 = str_replace($pattern,
'\\$1', str_replace(
'/%20/',
'+', urlencode($name)));
365 $name3 = str_replace([
'/\(/',
'/\)/'], [
'%28',
'%29'], $name2);
366 $regex =
'/([?&-]pool[=-]|\/_\/)('
367 . preg_quote($name1,
'/')
368 .
'|' . preg_quote($name2,
'/')
369 .
'|' . preg_quote($name3,
'/')
371 foreach ([
'content',
'short',
'extra'] as $key) {
372 if (preg_match($regex, $this->page->field[$key])) {
380 $convert_ignore = array_filter(explode(
',', (
string) $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'convert_ignore']));
381 sort($convert_ignore);
384 if (!empty($params[
'get_formats']) && $isImage) {
385 unset($params[
'get_formats'], $download_params[
'get_formats']);
386 require_once
'base/Ego_Output.php';
387 $output =
new Ego_Output($this->page, $name, $dir);
388 $sub_data[
'converted_files'] = array_filter($output->getConvertedImages(),
function($file) use ($convert_ignore) {
389 return !in_array($file[
'format'], $convert_ignore);
391 $sub_data[
'converted_files'] = array_map(
function($file) use (&$params, &$get_url) {
392 $file[
'url'] = $get_url(array_merge($params, [
'suffix' => $file[
'format'],
'inactive' => 1,
'preview' => 1]));
394 }, $sub_data[
'converted_files']);
397 $data = array_merge(array(
398 'identity' => $this->page->getIdentity(),
402 'url' => $get_url($params),
403 'download' => $get_url($download_params),
404 'convert' => !empty($convert),
405 'size' => @filesize($file),
406 'mime' => $mime_type,
410 'isImage' => $isImage,
411 'isArchive' => $isArchive,
412 'isVideo' => $isVideo,
414 'lastChange' => @filemtime($file),
416 'description' => (
string) $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'description'],
417 'copyright' => (
string) $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'copyright'],
418 'order' => (
int) $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'order'],
419 'nav_hide' => (
int) $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'nav_hide'],
420 'clip' => $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'clip'],
421 'rotation' => (
int) $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'rotation'],
422 'mirror' => (
string) $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'mirror'],
423 'grayscale' => (
string) $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'grayscale'],
424 'quarantine' => (
bool) $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'quarantine'],
425 'convertIgnore' => $convert_ignore,
426 'vtt' => $this->page->extra[
'mediapool'][md5($sub_dir)][$name_key][
'vtt'],
428 'extra_key' => implode(
'.', [
'mediapool', md5($sub_dir), $name_key])
441 public function file($name, $dir =
'', &$convert = []) {
442 $dir = $this->getDir($dir);
444 .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.Ego_System::base64Encode($name);
450 .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.base64_encode($name);
457 require_once
'base/Ego_Output.php';
460 ($matches = preg_split(
'/\.' . preg_quote($type,
'/') .
'$/i', $name, 2))
461 &&
sizeof($matches) > 1
463 $basename = preg_quote($matches[0],
'/');
464 $convertable_file = $this->first(
'/^' . $basename .
'\..*?$/', $dir, $found);
465 if ($convertable_file) {
469 'mime' => $info[
'mime']
472 return $convertable_file;
487 private function first($pattern, $dir =
'', &$found =
'') {
488 $dir = $this->getDir($dir);
489 $folder = $this->
dir()
490 .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
494 while (($file = $d->read()) !==
false) {
497 || preg_match($pattern, ($decoded = base64_decode($file)))
500 $path = $folder.$file;
517 public function delete($name, $dir =
'', $replication =
true) {
518 if (!isset($GLOBALS[
'__egotec_skip_replication'])) {
519 $GLOBALS[
'__egotec_skip_replication'] =
'pool.delete';
522 if ($original_page = $this->page->getCloneOriginal()) {
523 return $original_page->getMediapool()->delete($name, $dir);
525 $dir = $this->getDir($dir);
527 .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.Ego_System::base64Encode($name);
531 .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.base64_encode($name);
535 require_once
'base/Ego_Output.php';
536 $output =
new Ego_Output($this->page, $name, $dir);
537 $output->clearConvertedImages();
543 if ($dir == $this->currentDir) {
544 $this->page->update();
548 $this->page->replicate(
"pool.delete", $name, $dir);
565 public function edit($name, $params = array(), $dir =
'') {
566 if (!isset($GLOBALS[
'__egotec_skip_replication'])) {
567 $GLOBALS[
'__egotec_skip_replication'] =
'pool.edit';
570 if ($original_page = $this->page->getCloneOriginal()) {
571 return $original_page->getMediapool()->put($name, $params, $dir);
573 $dir = $this->getDir($dir);
574 $file = $params[
'new_file'] ?: $this->
file($name, $dir);
575 $sub_dir = $this->subDir($dir);
576 $new_name = trim($params[
'new_name']);
581 && $name != $new_name
582 && ($data = $this->
put($file, $new_name, $dir,
false, (
bool) $params[
'replace']))
584 if ($this->
delete($name, $dir,
false)) {
586 $this->page->field[
'content'] = $this->renameRecursive($name, $new_name, $this->page->field[
'content']);
587 $this->page->field[
'short'] = $this->renameRecursive($name, $new_name, $this->page->field[
'short']);
588 $this->page->extra = $this->renameRecursive($name, $new_name, $this->page->extra);
589 $this->page->extra[
'mediapool'][md5($sub_dir)][md5($new_name)] = $this->page->extra[
'mediapool'][md5($sub_dir)][md5($name)];
590 unset($this->page->extra[
'mediapool'][md5($sub_dir)][md5($name)]);
594 $this->
delete($new_name, $dir);
599 if (empty($this->page->extra[
'mediapool'][md5($sub_dir)][md5($name)])) {
600 $this->page->extra[
'mediapool'][md5($sub_dir)][md5($name)] = array();
603 unset($params[
'new_name'], $params[
'replace']);
604 $this->page->extra[
'mediapool'][md5($sub_dir)][md5($name)] = array_merge($this->page->extra[
'mediapool'][md5($sub_dir)][md5($name)], $params);
606 $this->page->replicate(
"pool.edit", $name, $params, $dir);
608 $this->page->update(array(
610 'content' => $this->page->field[
'content'],
611 'short' => $this->page->field[
'short']
613 'extra' => $this->page->extra
627 private function renameRecursive($name, $new_name, $value) {
628 if (is_array($value)) {
629 foreach ($value as $key => $v) {
630 $value[$key] = $this->renameRecursive($name, $new_name, $value[$key]);
632 } elseif (preg_match_all(
'/index\.php\?[^>"]+/ims', $value, $matches)) {
639 $encode =
function($s) {
640 return str_replace(
' ',
'+', $s);
642 foreach ($matches[0] as $match) {
643 $new_url = preg_replace(
'/([&?])pool='.preg_quote($encode($name),
'/').
'/msi',
'$1pool='.$encode($new_name), $match);
644 $value = str_replace($match, $new_url, $value);
671 public function list($dir =
'', $params = array(), $block =
'') {
672 $dir = $this->getDir($dir);
675 .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
677 if ($handle = opendir($path)) {
680 $params2[
'sort_field'],
681 $params2[
'sort_reverse'],
683 $params2[
'only_image']
685 while (
false !== ($file = readdir($handle))) {
686 if ($file !=
'.' && $file !=
'..' && !is_dir($path.$file)) {
692 !$params[
'only_image']
693 && !$_REQUEST[
'session'][
'insert_image']
699 !$params[
'only_video']
700 && !$_REQUEST[
'session'][
'insert_video']
706 !$params[
'only_file']
707 && !$_REQUEST[
'session'][
'insert_file']
713 !$params[
'only_media']
714 && !$_REQUEST[
'session'][
'insert_media']
720 empty($params[
'mime_type'])
721 || preg_match(
'#'.$params[
'mime_type'].
'#i', $data[
'mime'])
724 empty($params[
'search'])
725 || stripos($data[
'name'], $params[
'search']) !==
false
726 || stripos($data[
'title'], $params[
'search']) !== false
729 if ($this->site->admin[
'mediapool'][
'video_compress'] && $data[
'mime'] ===
'video/mp4') {
731 $data[
'compressed_files'][str_replace(
':',
' x ', $scale)] = $this->
get(
"{$data['title']}_{$height}p.mp4",
'_compress');
745 foreach ($list as $file) {
746 $sort_field = ($params[
'sort_field'] && isset($file[$params[
'sort_field']]))
747 ? $file[$params[
'sort_field']]
749 $sort[] = is_string($sort_field)
750 ? mb_strtolower($sort_field)
752 $names[] = mb_strtolower($file[
'name']);
754 if (!$params[
'sort_field'] &&
sizeof(array_unique($sort)) == 1) {
758 $params[
'sort_reverse'] ? SORT_DESC : SORT_ASC,
766 $params[
'sort_reverse'] ? SORT_DESC : SORT_ASC,
767 is_string($sort_field) ? SORT_STRING : SORT_NUMERIC,
772 if (isset($params[
'start'])) {
774 $list = array_slice($list, $params[
'start'], $params[
'end']);
788 foreach (glob($this->
dir() .
'*', GLOB_ONLYDIR) as $path) {
789 $dir = basename($path);
790 if ($dir == $this->currentDir) {
792 } elseif (!is_numeric($dir) || $archives) {
809 public function setInfo($dir, $name, $key, $value =
null) {
810 $sub_dir = $this->subDir($dir);
811 if ($value ===
null) {
812 unset($this->page->extra[
'mediapool'][md5($sub_dir)][md5($name)][$key]);
814 $this->page->extra[
'mediapool'][md5($sub_dir)][md5($name)][$key] = $value;
816 return implode(
'.', array(
'mediapool', md5($sub_dir), md5($name), $key));
826 public function dir($relative =
false, $source =
null) {
828 $site = $source->getSite();
830 $lang = $site->language;
831 $id = $source->field[
'id'];
833 $name = $this->site->name;
834 $lang = $this->site->language;
835 $id = $this->page->field[
'id'];
837 return (!$relative ? $GLOBALS[
'egotec_conf'][
'var_dir'] :
'').
'media'.
838 DIRECTORY_SEPARATOR.$name.
839 DIRECTORY_SEPARATOR.$lang.
840 DIRECTORY_SEPARATOR.
'pool' .
841 DIRECTORY_SEPARATOR.$id.
851 private function subDir($dir) {
853 if ($dirs = explode(DIRECTORY_SEPARATOR, $dir)) {
854 if ($dirs[0] == $this->currentDir) {
857 $sub_dir = implode(DIRECTORY_SEPARATOR, $dirs);
868 private function getDir($dir) {
869 if (is_numeric(explode(DIRECTORY_SEPARATOR, $dir)[0])) {
872 } elseif (empty($dir) || $dir == $this->currentDir) {
877 return $this->currentDir . DIRECTORY_SEPARATOR . $this->subDir($dir);
888 if ($original_page = $this->page->getCloneOriginal()) {
889 return $original_page->getMediapool()->archive($c_date, $dir);
891 $dir = $this->getDir($dir);
892 $path = $this->
dir();
894 $src = $path.rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
895 $dest = $path.($dir != $this->currentDir ? $dir :
'')
911 public function restore($c_date, $name =
'', $dir =
'') {
912 if (!isset($GLOBALS[
'__egotec_skip_replication'])) {
913 $GLOBALS[
'__egotec_skip_replication'] =
'pool.restore';
916 if ($original_page = $this->page->getCloneOriginal()) {
917 return $original_page->restore($c_date, $name, $dir);
919 if (!empty($c_date)) {
920 $dir = $this->getDir($dir);
924 .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
925 $source = $this->
dir().$c_date.DIRECTORY_SEPARATOR;
930 $archive_page = $this->page->getArchivePage(is_numeric($c_date) ? date(
'Y-m-d H:i:s', $c_date) : $c_date);
931 $mediapool = $archive_page ? $archive_page->extra[
'mediapool'] : array();
932 $this->
clear($dir, $mediapool);
934 $this->page->replicate(
"pool.restore", $c_date, $name, $dir);
940 $path = $dir == $this->currentDir
942 : rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$c_date;
943 $source = $this->
get($name, $path);
945 $this->page->replicate(
"pool.restore", $c_date, $name, $dir);
947 return (
bool) $this->
put($source[
'file'], $name, $dir);
959 private function create() {
980 public function copy(
Page $target, $dir =
'', $clear =
false, $integrate =
false, $archive =
true, $asis =
true, $specific_sub_dir =
false, $rename =
'', $matrix =
true) {
981 if (!isset($GLOBALS[
'__egotec_skip_replication'])) {
982 $GLOBALS[
'__egotec_skip_replication'] =
'pool.copy';
985 $path = $this->
dir();
988 if ($specific_sub_dir) {
989 $path .= $this->currentDir.DIRECTORY_SEPARATOR;
993 $path .= rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
998 $dest = $this->
dir(
false, $target);
1001 if ($specific_sub_dir) {
1002 $dest .= $this->currentDir.DIRECTORY_SEPARATOR;
1006 $dest .= rtrim($rename ?: $dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
1009 if (!$integrate && $this->page->getIdentity() != $target->
getIdentity()) {
1013 $this->page->replicate(
"pool.copy", $target, $dir, $clear, $integrate, $archive, $asis);
1018 $target->
getMediapool()->import(
true,
true, $dir,
true, $asis, $rename, $matrix);
1025 $target->extra[
'mediapool'][md5($dir)] = $this->page->extra[
'mediapool'][md5($dir)];
1027 $target->extra[
'mediapool'] = $this->page->extra[
'mediapool'];
1029 $target->extra[
'_asis'] = 5;
1030 $target->
update(array(), $matrix,
true);
1049 public function move($target, $dir =
'', $integrate =
false, $archive =
true) {
1050 if (!isset($GLOBALS[
'__egotec_skip_replication'])) {
1051 $GLOBALS[
'__egotec_skip_replication'] =
'pool.move';
1054 $this->
copy($target, $dir,
true, $integrate, $archive);
1056 $this->page->replicate(
"pool.move", $target, $dir, $integrate, $archive);
1066 public function exists($dir =
'', $empty =
true) {
1067 $dir = $this->getDir($dir);
1068 $path = $this->
dir()
1069 .rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
1070 return Ego_System::file_exists($path) && ($empty ||
sizeof(is_array($scanned_dir = scandir($path)) ? $scanned_dir : []) > 2);
1081 public function clear($dir =
'', $mediapool = array(), $update =
true) {
1082 if (!isset($GLOBALS[
'__egotec_skip_replication'])) {
1083 $GLOBALS[
'__egotec_skip_replication'] =
'pool.clear';
1086 if ($original_page = $this->page->getCloneOriginal()) {
1087 return $original_page->getMediapool()->clear($dir);
1089 $path = $this->
dir();
1091 $path .= rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
1093 $sub_dir = $this->subDir($dir);
1096 if (!empty($mediapool)) {
1097 $this->page->extra[
'mediapool'] = $mediapool;
1099 unset($this->page->extra[
'mediapool'][md5($sub_dir)]);
1102 $this->page->update(array(),
true,
true);
1105 $this->page->replicate(
"pool.clear", $dir, $mediapool, $update);
1122 public function import($only_pool =
false, $replace =
false, $dir =
'', $update =
true, $asis =
true, $rename =
'', $matrix =
true) {
1123 $this->page->field[
'content'] = $this->importRecursive($this->page->field[
'content'], $only_pool, $replace, $dir, $rename);
1124 $this->page->field[
'short'] = $this->importRecursive($this->page->field[
'short'], $only_pool, $replace, $dir, $rename);
1125 $this->page->extra = $this->importRecursive($this->page->extra, $only_pool, $replace, $dir, $rename);
1127 $this->page->update(array(
1129 'content' => $this->page->field[
'content'],
1130 'short' => $this->page->field[
'short']
1132 'extra' => $this->page->extra
1148 private function importRecursive($value, $only_pool =
false, $replace =
false, $dir =
'', $rename =
'') {
1149 if (is_array($value)) {
1150 foreach ($value as $key => $v) {
1151 $value[$key] = $this->importRecursive($v, $only_pool, $replace, $dir, $rename);
1153 } elseif (preg_match_all(
'/index\.php\?[^>"\\\]+/ims', $value, $matches)) {
1154 $dir = $dir ==
'' ?
'' : rtrim($dir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
1155 foreach ($matches[0] as $url) {
1160 'deleted_or' =>
'1=1',
1162 'only_active' =>
false
1170 && in_array($page->field[
'type'], array(
'multimedia/file',
'multimedia/image'))
1173 $site = $page->getSite();
1174 $path = $GLOBALS[
'egotec_conf'][
'var_dir'].
'media/'.$site->name.
'/';
1175 $file = $path.$page->getMediaFilename();
1177 $name = $page->field[
'name'];
1179 if ($page->extra[
'image_type']) {
1180 $suffix =
'.'.$page->extra[
'image_type'];
1183 while ($this->
file($name.$suffix, $dir)) {
1185 if (preg_match(
'/_(\d+)$/ims', $name, $match)) {
1186 $num = ((int) $match[1]) + 1;
1187 $name = preg_replace(
'/_\d+$/ims',
'', $name);
1194 $media = $this->
put($file, $name.$suffix, $rename ?: $dir);
1195 if (!empty($media[
'url'])) {
1196 $value = str_replace($url, $media[
'url'], $value);
1199 } elseif (!empty($info[
'params'][
'pool'])) {
1201 $media = $page->getMediapool()->get(urldecode($info[
'params'][
'pool']), $dir);
1202 if ($media[
'file']) {
1203 $media = $this->
put(
1211 !$this->page->isClone()
1214 if (!empty($media[
'url'])) {
1215 $value = str_replace($url, $media[
'url'] . (!empty($info[
'params'][
'clip']) ?
"&clip=" . $info[
'params'][
'clip'] :
""), $value);
1232 if (is_array($this->page->extra[
'mediapool'])) {
1233 $recursive =
function($dir, $sub =
'') use (&$recursive, &$files) {
1236 while (($entry = $d->read()) !==
false) {
1237 if ($entry[0] !=
'.' && $entry ==
'current') {
1238 $sub_dir = rtrim($dir) . DIRECTORY_SEPARATOR . $entry;
1239 if (is_dir($sub_dir)) {
1240 $recursive($sub_dir, ($sub ? $sub . DIRECTORY_SEPARATOR :
'') . $entry);
1243 if ($info && $info[
'quarantine']) {
1244 $files[] = ($sub ? $sub . DIRECTORY_SEPARATOR :
'') . basename($info[
'file']);
1252 $recursive($this->
dir());
static urltopage($url, $params=array(), $only_site=false, $error_page=false, $commit_params=false)
static deldir($location, $del=true, $without='', $rename=true)
static dateEncode($string)
static getFileInfo($file)
static getUrlInfo($url, $encode=false)
static file_exists($file)
static mkdir($dir, $mode=0755, $recursive=true)
static copy($src, $dest, $except='', $useLinks=false, $noArchive=false, $preserveDate=false)
update($param=array(), $matrix_flag=true, $asis=false, $silent=false)