Ejemplo n.º 1
0
 public function getThumbnail($path)
 {
     $gallery_path = \OCP\Config::getSystemValue('datadirectory') . '/' . \OC_User::getUser() . '/gallery';
     if (file_exists($gallery_path . $path)) {
         return new \OC_Image($gallery_path . $path);
     }
     if (!\OC_Filesystem::file_exists($path)) {
         \OC_Log::write(self::TAG, 'File ' . $path . ' don\'t exists', \OC_Log::WARN);
         return false;
     }
     $image = new \OC_Image();
     $image->loadFromFile(\OC_Filesystem::getLocalFile($path));
     if (!$image->valid()) {
         return false;
     }
     $image->fixOrientation();
     $ret = $image->preciseResize(floor(150 * $image->width() / $image->height()), 150);
     if (!$ret) {
         \OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR);
         unset($image);
         return false;
     }
     $image->save($gallery_path . '/' . $path);
     return $image;
 }
Ejemplo n.º 2
0
 public static function getThumbnail($image_name, $owner = null)
 {
     if (!$owner) {
         $owner = OCP\USER::getUser();
     }
     $save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery/';
     $save_dir .= dirname($image_name) . '/';
     $image_path = $image_name;
     $thumb_file = $save_dir . basename($image_name);
     if (!is_dir($save_dir)) {
         mkdir($save_dir, 0777, true);
     }
     if (file_exists($thumb_file)) {
         $image = new OC_Image($thumb_file);
     } else {
         $image_path = OC_Filesystem::getLocalFile($image_path);
         if (!file_exists($image_path)) {
             return null;
         }
         $image = new OC_Image($image_path);
         if ($image->valid()) {
             $image->centerCrop(200);
             $image->fixOrientation();
             $image->save($thumb_file);
         }
     }
     if ($image->valid()) {
         return $image;
     } else {
         $image->destroy();
     }
     return null;
 }
Ejemplo n.º 3
0
 /**
  * scan a file for music
  * @param string $path
  * @return boolean
  */
 public static function scanFile($path)
 {
     if (!self::isMusic($path)) {
         return;
     }
     if (!self::$getID3) {
         self::$getID3 = @new getID3();
         self::$getID3->encoding = 'UTF-8';
     }
     $file = OC_Filesystem::getLocalFile($path);
     $data = @self::$getID3->analyze($file);
     getid3_lib::CopyTagsToComments($data);
     if (!isset($data['comments'])) {
         OCP\Util::writeLog('media', "error reading id3 tags in '{$file}'", OCP\Util::WARN);
         return;
     }
     if (!isset($data['comments']['artist'])) {
         OCP\Util::writeLog('media', "error reading artist tag in '{$file}'", OCP\Util::WARN);
         $artist = 'unknown';
     } else {
         $artist = OCP\Util::sanitizeHTML(stripslashes($data['comments']['artist'][0]));
     }
     if (!isset($data['comments']['album'])) {
         OCP\Util::writeLog('media', "error reading album tag in '{$file}'", OCP\Util::WARN);
         $album = 'unknown';
     } else {
         $album = OCP\Util::sanitizeHTML(stripslashes($data['comments']['album'][0]));
     }
     if (!isset($data['comments']['title'])) {
         OCP\Util::writeLog('media', "error reading title tag in '{$file}'", OCP\Util::WARN);
         $title = 'unknown';
     } else {
         $title = OCP\Util::sanitizeHTML(stripslashes($data['comments']['title'][0]));
     }
     $size = $data['filesize'];
     if (isset($data['comments']['track'])) {
         $track = $data['comments']['track'][0];
     } else {
         if (isset($data['comments']['track_number'])) {
             $track = $data['comments']['track_number'][0];
             $track = explode('/', $track);
             $track = $track[0];
         } else {
             $track = 0;
         }
     }
     $length = isset($data['playtime_seconds']) ? round($data['playtime_seconds']) : 0;
     if (!isset(self::$artists[$artist])) {
         $artistId = OC_MEDIA_COLLECTION::addArtist($artist);
         self::$artists[$artist] = $artistId;
     } else {
         $artistId = self::$artists[$artist];
     }
     if (!isset(self::$albums[$artist . '/' . $album])) {
         $albumId = OC_MEDIA_COLLECTION::addAlbum($album, $artistId);
         self::$albums[$artist . '/' . $album] = $albumId;
     } else {
         $albumId = self::$albums[$artist . '/' . $album];
     }
     $songId = OC_MEDIA_COLLECTION::addSong($title, $path, $artistId, $albumId, $length, $track, $size);
     return !($title == 'unknown' && $artist == 'unknown' && $album == 'unknown') ? $songId : 0;
 }
Ejemplo n.º 4
0
 public static function getViewImage($image_name, $owner = null)
 {
     if (!$owner) {
         $owner = OCP\USER::getUser();
     }
     $view_file = OC_Filesystem::getLocalFile($image_name);
     if (!is_dir($save_dir)) {
         mkdir($save_dir, 0777, true);
     }
     if (file_exists($view_file)) {
         $image = new OC_Image($view_file);
     } else {
         $image_path = OC_Filesystem::getLocalFile($image_path);
         if (!file_exists($image_path)) {
             return null;
         }
         $image = new OC_Image($image_path);
         if ($image->valid()) {
             $image->resize(1200);
             $image->fixOrientation();
             $image->save($view_file);
         }
     }
     if ($image->valid()) {
         return $image;
     } else {
         $image->destroy();
     }
     return null;
 }
Ejemplo n.º 5
0
 /**
  * return the content of a file or return a zip file containning multiply files
  *
  * @param dir  $dir
  * @param file $file ; seperated list of files to download
  * @param boolean $only_header ; boolean to only send header of the request
  */
 public static function get($dir, $files, $only_header = false)
 {
     $xsendfile = false;
     if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
         $xsendfile = true;
     }
     if (strpos($files, ';')) {
         $files = explode(';', $files);
     }
     if (is_array($files)) {
         self::validateZipDownload($dir, $files);
         $executionTime = intval(ini_get('max_execution_time'));
         set_time_limit(0);
         $zip = new ZipArchive();
         if ($xsendfile) {
             $filename = OC_Helper::tmpFileNoClean('.zip');
         } else {
             $filename = OC_Helper::tmpFile('.zip');
         }
         if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
             exit("cannot open <{$filename}>\n");
         }
         foreach ($files as $file) {
             $file = $dir . '/' . $file;
             if (OC_Filesystem::is_file($file)) {
                 $tmpFile = OC_Filesystem::toTmpFile($file);
                 self::$tmpFiles[] = $tmpFile;
                 $zip->addFile($tmpFile, basename($file));
             } elseif (OC_Filesystem::is_dir($file)) {
                 self::zipAddDir($file, $zip);
             }
         }
         $zip->close();
         set_time_limit($executionTime);
     } elseif (OC_Filesystem::is_dir($dir . '/' . $files)) {
         self::validateZipDownload($dir, $files);
         $executionTime = intval(ini_get('max_execution_time'));
         set_time_limit(0);
         $zip = new ZipArchive();
         if ($xsendfile) {
             $filename = OC_Helper::tmpFileNoClean('.zip');
         } else {
             $filename = OC_Helper::tmpFile('.zip');
         }
         if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
             exit("cannot open <{$filename}>\n");
         }
         $file = $dir . '/' . $files;
         self::zipAddDir($file, $zip);
         $zip->close();
         set_time_limit($executionTime);
     } else {
         $zip = false;
         $filename = $dir . '/' . $files;
     }
     OC_Util::obEnd();
     if ($zip or OC_Filesystem::is_readable($filename)) {
         header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
         header('Content-Transfer-Encoding: binary');
         OC_Response::disableCaching();
         if ($zip) {
             ini_set('zlib.output_compression', 'off');
             header('Content-Type: application/zip');
             header('Content-Length: ' . filesize($filename));
             self::addSendfileHeader($filename);
         } else {
             header('Content-Type: ' . OC_Filesystem::getMimeType($filename));
             $storage = OC_Filesystem::getStorage($filename);
             if ($storage instanceof OC_Filestorage_Local) {
                 self::addSendfileHeader(OC_Filesystem::getLocalFile($filename));
             }
         }
     } elseif ($zip or !OC_Filesystem::file_exists($filename)) {
         header("HTTP/1.0 404 Not Found");
         $tmpl = new OC_Template('', '404', 'guest');
         $tmpl->assign('file', $filename);
         $tmpl->printPage();
     } else {
         header("HTTP/1.0 403 Forbidden");
         die('403 Forbidden');
     }
     if ($only_header) {
         if (!$zip) {
             header("Content-Length: " . OC_Filesystem::filesize($filename));
         }
         return;
     }
     if ($zip) {
         $handle = fopen($filename, 'r');
         if ($handle) {
             $chunkSize = 8 * 1024;
             // 1 MB chunks
             while (!feof($handle)) {
                 echo fread($handle, $chunkSize);
                 flush();
             }
         }
         if (!$xsendfile) {
             unlink($filename);
         }
     } else {
         OC_Filesystem::readfile($filename);
     }
     foreach (self::$tmpFiles as $tmpFile) {
         if (file_exists($tmpFile) and is_file($tmpFile)) {
             unlink($tmpFile);
         }
     }
 }
Ejemplo n.º 6
0
{
    OCP\JSON::error(array('data' => array('message' => $msg)));
    OCP\Util::writeLog('contacts', 'ajax/oc_photo.php: ' . $msg, OCP\Util::ERROR);
    exit;
}
function debug($msg)
{
    OCP\Util::writeLog('contacts', 'ajax/oc_photo.php: ' . $msg, OCP\Util::DEBUG);
}
if (!isset($_GET['id'])) {
    bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
}
if (!isset($_GET['path'])) {
    bailOut(OC_Contacts_App::$l10n->t('No photo path was submitted.'));
}
$localpath = OC_Filesystem::getLocalFile($_GET['path']);
$tmpfname = tempnam(get_temp_dir(), "occOrig");
if (!file_exists($localpath)) {
    bailOut(OC_Contacts_App::$l10n->t('File doesn\'t exist:') . $localpath);
}
file_put_contents($tmpfname, file_get_contents($localpath));
$image = new OC_Image();
if (!$image) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if (!$image->loadFromFile($tmpfname)) {
    bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if ($image->width() > 400 || $image->height() > 400) {
    $image->resize(400);
    // Prettier resizing than with browser and saves bandwidth.
Ejemplo n.º 7
0
 public function getThumbnailInfo($path)
 {
     $arr = DatabaseManager::getInstance()->getFileData($path);
     if (!$arr) {
         if (!\OC_Filesystem::file_exists($path)) {
             \OC_Log::write(self::TAG, 'File ' . $path . ' don\'t exists', \OC_Log::WARN);
             return false;
         }
         $image = new \OC_Image();
         $image->loadFromFile(\OC_Filesystem::getLocalFile($path));
         if (!$image->valid()) {
             return false;
         }
         $arr = DatabaseManager::getInstance()->setFileData($path, $this->getThumbnailWidth($image), self::THUMBNAIL_HEIGHT);
     }
     $ret = array('filepath' => $arr['path'], 'width' => $arr['width'], 'height' => $arr['height']);
     return $ret;
 }
Ejemplo n.º 8
0
 /**
  * turns an owncloud path into a path on the filesystem
  * @param string path the path to the file on the oc filesystem
  * @return string the filepath in the filesystem
  */
 public function getLocalFilePath($path)
 {
     # TODO: use public api
     return \OC_Filesystem::getLocalFile($path);
 }
 /**
  * scan a file for music
  * @param string $path
  * @return boolean
  */
 public static function scanFile($path)
 {
     if (is_null(self::$useMp3Info)) {
         self::$useMp3Info = OC_Helper::canExecute("mp3info");
     }
     $file = OC_Filesystem::getLocalFile($path);
     if (substr($path, -3) == 'mp3' and self::$useMp3Info) {
         //use the command line tool id3info if possible
         $output = array();
         $size = filesize($file);
         exec('mp3info -p "%a\\n%l\\n%t\\n%n\\n%S" "' . $file . '"', $output);
         if (count($output) > 4) {
             $artist = $output[0];
             $album = $output[1];
             $title = $output[2];
             $track = $output[3];
             $length = $output[4];
         } else {
             return;
             //invalid mp3 file
         }
     } else {
         if (!self::isMusic($path)) {
             return;
         }
         if (!self::$getID3) {
             self::$getID3 = @new getID3();
         }
         $data = @self::$getID3->analyze($file);
         getid3_lib::CopyTagsToComments($data);
         if (!isset($data['comments'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading id3 tags in '{$file}'");
             }
             return;
         }
         if (!isset($data['comments']['artist'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading artist tag in '{$file}'");
             }
             $artist = 'unknown';
         } else {
             $artist = stripslashes($data['comments']['artist'][0]);
             $artist = utf8_encode($artist);
         }
         if (!isset($data['comments']['album'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading album tag in '{$file}'");
             }
             $album = 'unknown';
         } else {
             $album = stripslashes($data['comments']['album'][0]);
             $album = utf8_encode($album);
         }
         if (!isset($data['comments']['title'])) {
             if (defined("DEBUG") && DEBUG) {
                 error_log("error reading title tag in '{$file}'");
             }
             $title = 'unknown';
         } else {
             $title = stripslashes($data['comments']['title'][0]);
             $title = utf8_encode($title);
         }
         $size = $data['filesize'];
         $track = isset($data['comments']['track']) ? $data['comments']['track'][0] : 0;
         $length = isset($data['playtime_seconds']) ? round($data['playtime_seconds']) : 0;
     }
     if (!isset(self::$artists[$artist])) {
         $artistId = OC_MEDIA_COLLECTION::addArtist($artist);
         self::$artists[$artist] = $artistId;
     } else {
         $artistId = self::$artists[$artist];
     }
     if (!isset(self::$albums[$artist . '/' . $album])) {
         $albumId = OC_MEDIA_COLLECTION::addAlbum($album, $artistId);
         self::$albums[$artist . '/' . $album] = $albumId;
     } else {
         $albumId = self::$albums[$artist . '/' . $album];
     }
     $songId = OC_MEDIA_COLLECTION::addSong($title, $path, $artistId, $albumId, $length, $track, $size);
     return !($title == 'unkown' && $artist == 'unkown' && $album == 'unkown') ? $songId : 0;
 }