示例#1
0
文件: EPub.php 项目: grandt/phpepub
 /**
  * Resolve a media src and determine it's target location and add it to the book.
  *
  * @param string $source           Source link.
  * @param string $internalPath     (referenced) Return value, will be set to the target path and name in the book.
  * @param string $internalSrc      (referenced) Return value, will be set to the target name in the book.
  * @param string $isSourceExternal (referenced) Return value, will be set to TRUE if the image originated from a full URL.
  * @param string $baseDir          Default is "", meaning it is pointing to the document root.
  * @param string $htmlDir          The path to the parent HTML file's directory from the root of the archive.
  *
  * @return bool
  */
 protected function resolveMedia($source, &$internalPath, &$internalSrc, &$isSourceExternal, $baseDir = "", $htmlDir = "")
 {
     if ($this->isFinalized) {
         return false;
     }
     $mediaPath = null;
     $tmpFile = null;
     if (preg_match('#^(http|ftp)s?://#i', $source) == 1) {
         $urlInfo = parse_url($source);
         if (strpos($urlInfo['path'], $baseDir . "/") !== false) {
             $internalSrc = substr($urlInfo['path'], strpos($urlInfo['path'], $baseDir . "/") + strlen($baseDir) + 1);
         }
         $internalPath = $urlInfo["scheme"] . "/" . $urlInfo["host"] . "/" . pathinfo($urlInfo["path"], PATHINFO_DIRNAME);
         $isSourceExternal = true;
         $mediaPath = FileHelper::getFileContents($source, true);
         $tmpFile = $mediaPath;
     } else {
         if (strpos($source, "/") === 0) {
             $internalPath = pathinfo($source, PATHINFO_DIRNAME);
             $mediaPath = $source;
             if (!file_exists($mediaPath)) {
                 $mediaPath = $this->docRoot . $mediaPath;
             }
         } else {
             $internalPath = $htmlDir . "/" . preg_replace('#^[/\\.]+#', '', pathinfo($source, PATHINFO_DIRNAME));
             $mediaPath = $baseDir . "/" . $source;
             if (!file_exists($mediaPath)) {
                 $mediaPath = $this->docRoot . $mediaPath;
             }
         }
     }
     if ($mediaPath !== false) {
         $mime = MimeHelper::getMimeTypeFromExtension(pathinfo($source, PATHINFO_EXTENSION));
         $internalPath = RelativePath::getRelativePath("media/" . $internalPath . "/" . $internalSrc);
         if (!array_key_exists($internalPath, $this->fileList) && $this->addLargeFile($internalPath, "m_" . $internalSrc, $mediaPath, $mime)) {
             $this->fileList[$internalPath] = $source;
         }
         if (isset($tmpFile)) {
             unlink($tmpFile);
         }
         return true;
     }
     return false;
 }
示例#2
0
 /**
  * Try to determine the mimetype of the file path.
  *
  * @param string $source Path
  *
  * @return string mimetype, or FALSE.
  * @deprecated Use getMimeTypeFromExtension(string $extension) instead.
  */
 public static function getMime($source)
 {
     return MimeHelper::getMimeTypeFromExtension(pathinfo($source, PATHINFO_EXTENSION));
 }