/** * @brief offer preview for download * * if no preview exists for this file, send icon instead * * @param string $path full path to file * @param string type type of preview requested */ public static function servePreview($path, $type) { \OCP\User::checkLoggedIn(); \OC::$server->getSession()->close(); $i = \OC\Files\Filesystem::getFileInfo($path, false); /* check for predefined cover, if found replace $path with that of cover file */ $meta = Meta::get($i['fileid']); if ($meta['cover']) { $path = pathinfo($path)['dirname'] . '/' . $meta['cover']; $i = \OC\Files\Filesystem::getFileInfo($path, false); } if (\OC::$server->getPreviewManager()->isMimeSupported($i['mimetype'])) { $preview = new \OC\Preview(\OC_User::getUser(), 'files'); $preview->setFile($path); switch ($type) { case 'cover': $preview->setMaxX(Config::getApp('cover-x', '200')); $preview->setMaxY(Config::getApp('cover-y', '200')); break; case 'thumbnail': $preview->setMaxX(Config::getApp('thumb-x', '36')); $preview->setMaxY(Config::getApp('thumb-y', '36')); break; } $preview->showPreview(); } else { // no preview, serve icon instead $scheme = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http'; header("Location: " . $scheme . "://" . $_SERVER['HTTP_HOST'] . \OC_Helper::mimetypeIcon($i->getMimeType())); /* Note: relative URL should be enough (RFC7231) but some OPDS clients * (especially those in dedicated book readers) might not support them * * header("Location: " . \OC_Helper::mimetypeIcon($i->getMimeType())); */ } }
<?php \OCP\User::checkLoggedIn(); \OCP\App::checkAppEnabled('fc_mail_attachments'); \OCP\Util::addscript('fc_mail_attachments', 'utils'); \OCP\Util::addscript('fc_mail_attachments', 'account'); //OCP\Util::addstyle('fc_mail_attachments', 'style'); $user = OCP\User::getUser(); $tmpl = new OCP\Template('fc_mail_attachments', 'settings'); $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*fc_mail_attachments` WHERE user = ?'); $results = $query->execute(array($user))->fetchAll(); if (sizeof($results)) { $conf = $results[0]; $tmpl->assign('dir', $conf['dir']); $tmpl->assign('mail_host', $conf['mail_host']); $tmpl->assign('mail_port', $conf['mail_port']); $tmpl->assign('mail_security', $conf['mail_security']); $tmpl->assign('mail_user', $conf['mail_user']); } return $tmpl->fetchPage();
public static function initController() { \OCP\User::checkLoggedIn(); \OCP\App::checkAppEnabled('contacts'); \OCP\App::checkAppEnabled(self::APP_ID); }