private function _replaceLinksToFiles($retour, $directory) { $reg_exp = '~\\<a\\s{1}href=\\"([^"]*)\\"~u'; preg_match_all($reg_exp, $retour, $matches_array); $i = 0; $iids = array(); $thumb_array = array(); if (!empty($matches_array[1]) and !is_dir($directory . '/images')) { mkdir($directory . '/images', 0777); } foreach ($matches_array[1] as $match) { $new = parse_url($match, PHP_URL_QUERY); $out = ''; parse_str($new, $out); $index = ''; if (isset($out['amp;iid'])) { $index = $out['amp;iid']; } elseif (isset($out['iid'])) { $index = $out['iid']; } if (!empty($index) and $index == $this->_item_id and stristr($match, '#anchor')) { $thumb_name = substr($match, strpos($match, '#')); $retour = str_replace($match, $thumb_name, $retour); } elseif (isset($index)) { $filemanager = $this->_environment->getFileManager(); $file = $filemanager->getItem($index); if (isset($file)) { $icon = $directory . '/images/' . $file->getIconFilename(); $filearray[$i] = $file->getDiskFileName(); if (file_exists(realpath($file->getDiskFileName()))) { include_once 'functions/text_functions.php'; copy($file->getDiskFileName(), $directory . '/' . toggleUmlaut($file->getFilename())); $retour = str_replace($match, toggleUmlaut($file->getFilename()), $retour); copy('htdocs/images/' . $file->getIconFilename(), $icon); // thumbs $thumb_name = $file->getFilename() . '_thumb'; $thumb_disk_name = $file->getDiskFileName() . '_thumb'; if (file_exists(realpath($thumb_disk_name))) { copy($thumb_disk_name, $directory . '/images/' . $thumb_name); $retour = str_replace($match, $thumb_name, $retour); $thumb_array[basename($thumb_disk_name)] = $thumb_name; } } } } $i++; } // img src $matches_array = array(); $reg_exp = '~src=\\"([^"]*)\\"~u'; preg_match_all($reg_exp, $retour, $matches_array); $link_list = array(); if (!empty($matches_array[1])) { foreach ($matches_array[1] as $link) { if (stristr($link, 'getFile') and stristr($link, 'picture') or stristr($link, 'images/disc1')) { $link_list[] = $link; } } } foreach ($link_list as $link) { $img_name = ''; if (stristr($link, 'picture=')) { $name = substr($link, strpos($link, '?') + 1); $name_array = explode('&', $name); foreach ($name_array as $param) { if (stristr($param, 'picture=')) { $img_name = substr($param, strpos($param, '=') + 1); } } } elseif (stristr($link, 'images/disc1')) { $img_name = str_replace('images/', '', $link); } if (!empty($img_name)) { if (!empty($thumb_array[$img_name])) { $retour = str_replace($link, 'images/' . $thumb_array[$img_name], $retour); } else { if (!file_exists($directory . '/images/' . $img_name)) { $orig_img_file = ''; if (stristr($link, 'picture=')) { $disc_manager = $this->_environment->getDiscManager(); $disc_manager->setPortalID($this->_environment->getCurrentPortalID()); $disc_manager->setContextID($this->_environment->getCurrentContextID()); $orig_img_file = $disc_manager->getFilePath(); unset($disc_manager); $orig_img_file .= $img_name; } elseif (stristr($link, 'images/disc1')) { $orig_img_file = 'htdocs/images/'; $orig_img_file .= $img_name; } if (!empty($orig_img_file) and file_exists($orig_img_file)) { copy($orig_img_file, $directory . '/images/' . $img_name); } } $retour = str_replace($link, 'images/' . $img_name, $retour); } } } return $retour; }
public function _replaceLinksToFiles($retour, $directory) { $reg_exp = '~\\<a\\s{1}href=\\"([^"]*)\\"~u'; preg_match_all($reg_exp, $retour, $matches_array); $link_list = array(); if (!empty($matches_array[1])) { foreach ($matches_array[1] as $link) { if (stristr($link, 'detail') or stristr($link, 'getFile')) { $link_list[] = $link; } } } $iids = array(); if (!empty($matches_array[1])) { if (!is_dir($directory . '/images')) { mkdir($directory . '/images', 0777); } } foreach ($link_list as $link) { if (stristr($link, 'getFile')) { $name = str_replace('commsy.php/', '', $link); $name = substr($name, 0, strpos($name, '?')); include_once 'functions/text_functions.php'; $name = toggleUmlaut($name); $retour = str_replace($link, $name, $retour); } else { $reg_exp = '~iid=([0-9]*)~u'; $iid_array = array(); preg_match_all($reg_exp, $link, $iid_array); if (!empty($iid_array[1][0])) { $retour = str_replace($link, $iid_array[1][0] . '.html', $retour); } } } // img src $matches_array = array(); $reg_exp = '~src=\\"([^"]*)\\"~u'; preg_match_all($reg_exp, $retour, $matches_array); $link_list = array(); if (!empty($matches_array[1])) { foreach ($matches_array[1] as $link) { if (stristr($link, 'getFile') and stristr($link, 'picture')) { $link_list[] = $link; } } } foreach ($link_list as $link) { $img_name = ''; $name = substr($link, strpos($link, '?') + 1); $name_array = explode('&', $name); foreach ($name_array as $param) { if (stristr($param, 'picture=')) { $img_name = substr($param, strpos($param, '=') + 1); } } if (!empty($img_name)) { if (!file_exists($directory . '/images' . $img_name)) { $disc_manager = $this->_environment->getDiscManager(); $disc_manager->setPortalID($this->_environment->getCurrentPortalID()); $disc_manager->setContextID($this->_environment->getCurrentContextID()); $orig_img_file = $disc_manager->getFilePath(); unset($disc_manager); $orig_img_file .= $img_name; if (file_exists($orig_img_file)) { copy($orig_img_file, $directory . '/images/' . $img_name); } } $retour = str_replace($link, 'images/' . $img_name, $retour); } } return $retour; }
$index = $out['amp;iid']; } elseif(isset($out['iid'])) { $index = $out['iid']; } if(isset($index)) { $file = $filemanager->getItem($index); if ( isset($file) ) { $icon = $directory.'/images/'.$file->getIconFilename(); $filearray[$i] = $file->getDiskFileName(); if(file_exists(realpath($file->getDiskFileName()))) { include_once('functions/text_functions.php'); copy($file->getDiskFileName(),$directory.'/'.toggleUmlaut($file->getFilename())); $output = str_replace($match, toggleUmlaut($file->getFilename()), $output); copy('htdocs/images/'.$file->getIconFilename(),$icon); // thumbs gehen nicht // warum nicht allgemeiner mit <img? (siehe unten) // geht unten aber auch nicht $thumb_name = $file->getFilename() . '_thumb'; $thumb_disk_name = $file->getDiskFileName() . '_thumb'; if ( file_exists(realpath($thumb_disk_name)) ) { copy($thumb_disk_name,$directory.'/images/'.$thumb_name); $output = str_replace($match, $thumb_name, $output); } } } } $i++;