public static function init($youtube_video_url, $final_flv_filename, $test = 0, $overwrite = 0){ self::$youtube_video_url = $youtube_video_url; self::$test = $test; self::$final_flv_filename = $final_flv_filename; self::$youtube_video_id = self::get_youtube_video_id(); self::$cookies_path = "cookies.txt"; $clear_cookies = self::clear_cookies(); self::$curl_headers = Array( "Accept-Language: en-us", "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15", "Connection: Keep-Alive", "Cache-Control: no-cache" ); self::$flv_url = self::get_flv_url(); $fs = OCP\Files::getStorage('files'); if($fs->file_exists('/Downloads/' . $final_flv_filename) && !$overwrite){ self::$final_flv_filename = md5(rand()) . '_' . $final_flv_filename; } self::$fs = $fs->fopen('/Downloads/' . self::$final_flv_filename, 'w'); $save_binary = self::get_curl_binary(); $clear_cookies = self::clear_cookies(); }
public static function getThumbnail($image_name, $owner = null) { if (!$owner) { $owner = OCP\USER::getUser(); } $view = OCP\Files::getStorage('gallery'); $save_dir = dirname($image_name); if (!$view->is_dir($save_dir)) { $view->mkdir($save_dir); } $view->chroot($view->getRoot() . '/' . $save_dir); $thumb_file = basename($image_name); if ($view->file_exists($thumb_file)) { $image = new OC_Image($view->fopen($thumb_file, 'r')); } else { $image_path = OC_Filesystem::getLocalFile($image_name); if (!file_exists($image_path)) { return null; } $image = new OC_Image($image_path); if ($image->valid()) { $image->centerCrop(200); $image->fixOrientation(); $image->save($view->getLocalFile($thumb_file)); } } if ($image->valid()) { return $image; } else { $image->destroy(); } return null; }
function handleGetThumbnails($albumname) { OCP\Response::enableCaching(3600 * 24); // 24 hour $view = OCP\Files::getStorage('gallery'); $thumbnail = $view->fopen(urldecode($albumname) . '.png', 'r'); header('Content-Type: ' . OC_Image::getMimeTypeForFile($thumbnail)); OCP\Response::sendFile($thumbnail); }
/** * Get the file by an URL * @param $url URL of the file * @param $path Simple path of the file * @param $l Lang * @param $overwrite Overwrite the target file */ public static function getFile($url, $path, $l, $overwrite = 0){ try{ $code = 0; if(!self::checkFileAccess($url, $code)){ OC_ocDownloaderPB::setError($l->t(self::$errors[$code])); exit(); } $pathinfo = pathinfo($path); $fs = OCP\Files::getStorage('files'); if($fs->file_exists('/Downloads/' . $pathinfo['basename']) && !$overwrite){ $pathinfo['basename'] = md5(rand()) . '_' . $pathinfo['basename']; } $fs = $fs->fopen('/Downloads/' . $pathinfo['basename'], 'w'); $size = self::getRemoteFileSize($url); if($size == 0){ OC_ocDownloaderPB::setError($l->t('Filesize is null')); exit(); } $chunkSize = self::getChunkSize($size); $fp = fopen($url, 'rb'); $received = $last = 0; while(!feof($fp)){ $data = @fread($fp, $chunkSize); if($data == ''){ break; } $saved = fwrite($fs, $data); if($saved > -1){ $received += $saved; } if($received >= $size){ $percent = 100; }else{ $percent = @round(($received/$size)*100, 2); } if($received > $last + $chunkSize){ OC_ocDownloaderPB::setProgressBarProgress($percent); $last = $received; } usleep(100); } OC_ocDownloaderPB::setProgressBarProgress(100); OC_ocDownloader::setUserHistory($pathinfo['basename'], 1); fclose($fp);fclose($fs); }catch(exception $e){ OC_ocDownloaderPB::setError($l->t('Unknown error')); } }
public static function createThumbnails($albumName, $files) { // create gallery thumbnail $file_count = min(count($files), 10); $thumbnail = imagecreatetruecolor($file_count * 200, 200); for ($i = 0; $i < $file_count; $i++) { $image = OC_Gallery_Photo::getThumbnail($files[$i]); if ($image && $image->valid()) { imagecopyresampled($thumbnail, $image->resource(), $i * 200, 0, 0, 0, 200, 200, 200, 200); $image->destroy(); } } $view = OCP\Files::getStorage('gallery'); imagepng($thumbnail, $view->getLocalFile($albumName . '.png')); imagedestroy($thumbnail); }
* * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); function bailOut($msg) { OCP\JSON::error(array('data' => array('message' => $msg))); OCP\Util::writeLog('contacts', 'ajax/uploadimport.php: ' . $msg, OCP\Util::ERROR); exit; } $view = OCP\Files::getStorage('contacts'); $tmpfile = md5(rand()); // If it is a Drag'n'Drop transfer it's handled here. $fn = isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : false; if ($fn) { if ($view->file_put_contents('/' . $tmpfile, file_get_contents('php://input'))) { OCP\JSON::success(array('data' => array('path' => '', 'file' => $tmpfile))); exit; } else { bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.')); } } // File input transfers are handled here if (!isset($_FILES['importfile'])) { OCP\Util::writeLog('contacts', 'ajax/uploadphoto.php: No file was uploaded. Unknown error.', OCP\Util::DEBUG); OCP\JSON::error(array('data' => array('message' => 'No file was uploaded. Unknown error')));
function handleGetPhoto($token, $photo) { $owner = OC_Gallery_Sharing::getTokenOwner($token); $view = OCP\Files::getStorage('files'); $file = $view->fopen(urldecode($photo), 'r'); header('Content-Type: ' . OC_Image::getMimeTypeForFile($file)); OCP\Response::sendFile($file); }
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ OCP\App::checkAppEnabled('storagecharts2'); $l = new OC_L10N('storagecharts2'); OC::$CLASSPATH['OC_DLStCharts'] = OC_App::getAppPath('storagecharts2') . "/lib/db.class.php"; OC::$CLASSPATH['OC_DLStChartsLoader'] = OC_App::getAppPath('storagecharts2') . "/lib/loader.class.php"; OCP\App::addNavigationEntry(array('id' => 'storagecharts2_index', 'order' => 60, 'href' => OCP\Util::linkTo('storagecharts2', 'index.php'), 'icon' => OCP\Util::imagePath('storagecharts2', 'app.svg'), 'name' => $l->t('Usage'))); OCP\App::registerPersonal('storagecharts2', 'settings'); // Get storage value for logged in user $data_dir = OCP\Config::getSystemValue('datadirectory', ''); if (OCP\User::getUser() && strlen($data_dir) != 0) { $fs = OCP\Files::getStorage('files'); // workaround to detect OC version $ocVersion = @reset(OCP\Util::getVersion()); // OC 5 if ($ocVersion < 6) { OCP\Util::writeLog('storagecharts2', 'Running on OwnCloud 5', OCP\Util::DEBUG); $used = OC_DLStCharts::getTotalDataSize(OC::$CONFIG_DATADIRECTORY); // OC 6 or greater } else { $datadir = OC_Config::getValue('datadirectory') . '/' . OCP\User::getUser(); OCP\Util::writeLog('storagecharts2', 'Running on OwnCloud ' . $ocVersion, OCP\Util::DEBUG); $used = OC_DLStCharts::getTotalDataSize($datadir); } // omit errors in desktop client ... if (method_exists($fs, 'free_space')) { OCP\Util::writeLog('storagecharts2', 'Calculating available space in oc << 8 for client', OCP\Util::DEBUG);
public static function changeThumbnailPath($oldname, $newname) { $view = OCP\Files::getStorage('gallery'); $view->rename($oldname . '.png', $newname . '.png'); }
/** * Get file * @param $path The remote file path * @param $l Lang * @param $overwrite Overwrite the target file */ public static function getFile($path, $l, $overwrite){ try{ $pathinfo = pathinfo($path); $fs = OCP\Files::getStorage('files'); if($fs->file_exists('/Downloads/' . $pathinfo['basename']) && !$overwrite){ $pathinfo['basename'] = md5(rand()) . '_' . $pathinfo['basename']; } $size = self::getRemoteFileSize($path); if($size == 0){ OC_ocDownloaderPB::setError($l->t('Filesize is null')); self::closeConnection(); exit(); } $chunkSize = self::getChunkSize($size); $received = $last = 0; $ret = ftp_nb_get(self::$conn, $fs->getLocalFile('/Downloads/' . $pathinfo['basename']), $path, FTP_BINARY); while($ret == FTP_MOREDATA){ $received += $fs->filesize('/Downloads/' . $pathinfo['basename']); if($received >= $size){ $percent = 100; }else{ $percent = @round(($received/$size)*100, 2); } if($received > $last + $chunkSize){ OC_ocDownloaderPB::setProgressBarProgress($percent); $last = $received; } usleep(100); $ret = ftp_nb_continue(self::$conn); } if($ret != FTP_FINISHED){ OC_ocDownloaderPB::setError($l->t('Download error')); self::closeConnection(); exit(); }else{ OC_ocDownloaderPB::setProgressBarProgress(100); OC_ocDownloader::setUserHistory($pathinfo['basename'], 1); } self::closeConnection(); }catch(exception $e){ OC_ocDownloaderPB::setError($l->t('Unknown error')); } }