本文整理汇总了PHP中OC_Template::assign方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Template::assign方法的具体用法?PHP OC_Template::assign怎么用?PHP OC_Template::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Template
的用法示例。
在下文中一共展示了OC_Template::assign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendEmail
public static function sendEmail($args)
{
$isEncrypted = OC_App::isEnabled('files_encryption');
if (!$isEncrypted || isset($_POST['continue'])) {
$continue = true;
} else {
$continue = false;
}
if (OC_User::userExists($_POST['user']) && $continue) {
$token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
// Hash the token again to prevent timing attacks
$email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
if (!empty($email)) {
$link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
$link = OC_Helper::makeURLAbsolute($link);
$tmpl = new OC_Template('core/lostpassword', 'email');
$tmpl->assign('link', $link, false);
$msg = $tmpl->fetchPage();
$l = OC_L10N::get('core');
$from = OCP\Util::getDefaultEmailAddress('lostpassword-noreply');
try {
OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
} catch (Exception $e) {
OC_Template::printErrorPage('A problem occurs during sending the e-mail please contact your administrator.');
}
self::displayLostPasswordPage(false, true);
} else {
self::displayLostPasswordPage(true, false);
}
} else {
self::displayLostPasswordPage(true, false);
}
}
示例2: sendEmail
public static function sendEmail($args)
{
if (OC_User::userExists($_POST['user'])) {
$token = hash('sha256', OC_Util::generate_random_bytes(30) . OC_Config::getValue('passwordsalt', ''));
OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash('sha256', $token));
// Hash the token again to prevent timing attacks
$email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
if (!empty($email)) {
$link = OC_Helper::linkToRoute('core_lostpassword_reset', array('user' => $_POST['user'], 'token' => $token));
$link = OC_Helper::makeURLAbsolute($link);
$tmpl = new OC_Template('core/lostpassword', 'email');
$tmpl->assign('link', $link, false);
$msg = $tmpl->fetchPage();
$l = OC_L10N::get('core');
$from = 'lostpassword-noreply@' . OCP\Util::getServerHost();
OC_Mail::send($email, $_POST['user'], $l->t('ownCloud password reset'), $msg, $from, 'ownCloud');
echo 'Mailsent';
self::displayLostPasswordPage(false, true);
} else {
self::displayLostPasswordPage(true, false);
}
} else {
self::displayLostPasswordPage(true, false);
}
}
示例3: av_scan
public static function av_scan($path)
{
$path = $path[\OC\Files\Filesystem::signal_param_path];
if ($path != '') {
$files_view = \OCP\Files::getStorage("files");
if ($files_view->file_exists($path)) {
$root = OC_User::getHome(OC_User::getUser()) . '/files';
$file = $root . $path;
$result = self::clamav_scan($file);
switch ($result) {
case CLAMAV_SCANRESULT_UNCHECKED:
//TODO: Show warning to the user: The file can not be checked
break;
case CLAMAV_SCANRESULT_INFECTED:
//remove file
$files_view->unlink($path);
OCP\JSON::error(array("data" => array("message" => "Virus detected! Can't upload the file.")));
$email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
\OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG);
if (!empty($email)) {
$tmpl = new OC_Template('files_antivirus', 'notification');
$tmpl->assign('file', $path);
$tmpl->assign('host', OCP\Util::getServerHost());
$tmpl->assign('user', OC_User::getUser());
$msg = $tmpl->fetchPage();
$from = OCP\Util::getDefaultEmailAddress('security-noreply');
OCP\Util::sendMail($email, OC_User::getUser(), 'Malware detected', $msg, $from, 'ownCloud', 1);
}
exit;
break;
case CLAMAV_SCANRESULT_CLEAN:
//do nothing
break;
}
}
}
}
示例4: handshake
/**
* do the initial handshake
*
* @param array $params
*/
public function handshake($params)
{
$auth = isset($params['auth']) ? $params['auth'] : false;
$user = isset($params['user']) ? $params['user'] : false;
$time = isset($params['timestamp']) ? $params['timestamp'] : false;
$now = time();
if ($now - $time > 10 * 60) {
$this->error(400, 'timestamp is more then 10 minutes old');
}
if ($auth and $user and $time) {
$query = \OCP\DB::prepare("SELECT `user_id`, `user_password_sha256` FROM `*PREFIX*media_users` WHERE `user_id`=?");
$result = $query->execute(array($user));
if ($row = $result->fetchRow()) {
$pass = $row['user_password_sha256'];
$key = hash('sha256', $time . $pass);
if ($key == $auth) {
$token = hash('sha256', 'oc_media_' . $key);
$this->collection = new Collection($row['user_id']);
$date = date('c');
//todo proper update/add/clean dates
$songs = $this->collection->getSongCount();
$artists = $this->collection->getArtistCount();
$albums = $this->collection->getAlbumCount();
$query = \OCP\DB::prepare("INSERT INTO `*PREFIX*media_sessions` (`token`, `user_id`, `start`) VALUES (?, ?, now());");
$query->execute(array($token, $user));
$expire = date('c', time() + 600);
$tmpl = new \OC_Template('media', 'ampache/handshake');
$tmpl->assign('token', $token);
$tmpl->assign('date', $date);
$tmpl->assign('songs', $songs);
$tmpl->assign('artists', $artists);
$tmpl->assign('albums', $albums);
$tmpl->assign('expire', $expire);
$tmpl->printPage();
return;
}
}
$this->error(400, 'Invalid login');
} else {
$this->error(400, 'Missing arguments');
}
}
示例5: validateZipDownload
/**
* checks if the selected files are within the size constraint. If not, outputs an error page.
*
* @param dir $dir
* @param files $files
*/
static function validateZipDownload($dir, $files)
{
if (!OC_Config::getValue('allowZipDownload', true)) {
$l = OC_L10N::get('files');
header("HTTP/1.0 409 Conflict");
$tmpl = new OC_Template('', 'error', 'user');
$errors = array(array('error' => $l->t('ZIP download is turned off.'), 'hint' => $l->t('Files need to be downloaded one by one.') . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>'));
$tmpl->assign('errors', $errors);
$tmpl->printPage();
exit;
}
$zipLimit = OC_Config::getValue('maxZipInputSize', OC_Helper::computerFileSize('800 MB'));
if ($zipLimit > 0) {
$totalsize = 0;
if (is_array($files)) {
foreach ($files as $file) {
$totalsize += OC_Filesystem::filesize($dir . '/' . $file);
}
} else {
$totalsize += OC_Filesystem::filesize($dir . '/' . $files);
}
if ($totalsize > $zipLimit) {
$l = OC_L10N::get('files');
header("HTTP/1.0 409 Conflict");
$tmpl = new OC_Template('', 'error', 'user');
$errors = array(array('error' => $l->t('Selected files too large to generate zip file.'), 'hint' => 'Download the files in smaller chunks, seperately or kindly ask your administrator.<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>'));
$tmpl->assign('errors', $errors);
$tmpl->printPage();
exit;
}
}
}
示例6: get
/**
* return the content of a file or return a zip file containing multiple files
*
* @param string $dir
* @param string $files ; separated 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_SENDFILE2_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
$xsendfile = true;
}
if (is_array($files) && count($files) === 1) {
$files = $files[0];
}
if (is_array($files)) {
$get_type = GET_TYPE::ZIP_FILES;
$basename = basename($dir);
if ($basename) {
$name = $basename . '.zip';
} else {
$name = 'download.zip';
}
$filename = $dir . '/' . $name;
} else {
$filename = $dir . '/' . $files;
if (\OC\Files\Filesystem::is_dir($dir . '/' . $files)) {
$get_type = GET_TYPE::ZIP_DIR;
// downloading root ?
if ($files === '') {
$name = 'download.zip';
} else {
$name = $files . '.zip';
}
} else {
$get_type = GET_TYPE::FILE;
$name = $files;
}
}
if ($get_type === GET_TYPE::FILE) {
$zip = false;
if ($xsendfile && OC_App::isEnabled('files_encryption')) {
$xsendfile = false;
}
} else {
$zip = new ZipStreamer(false);
}
OC_Util::obEnd();
if ($zip or \OC\Files\Filesystem::isReadable($filename)) {
self::sendHeaders($filename, $name, $zip);
} elseif (!\OC\Files\Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OC_Template('', '404', 'guest');
$tmpl->assign('file', $name);
$tmpl->printPage();
} else {
header("HTTP/1.0 403 Forbidden");
die('403 Forbidden');
}
if ($only_header) {
return;
}
if ($zip) {
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
if ($get_type === GET_TYPE::ZIP_FILES) {
foreach ($files as $file) {
$file = $dir . '/' . $file;
if (\OC\Files\Filesystem::is_file($file)) {
$fh = \OC\Files\Filesystem::fopen($file, 'r');
$zip->addFileFromStream($fh, basename($file));
fclose($fh);
} elseif (\OC\Files\Filesystem::is_dir($file)) {
self::zipAddDir($file, $zip);
}
}
} elseif ($get_type === GET_TYPE::ZIP_DIR) {
$file = $dir . '/' . $files;
self::zipAddDir($file, $zip);
}
$zip->finalize();
set_time_limit($executionTime);
} else {
if ($xsendfile) {
$view = \OC\Files\Filesystem::getView();
/** @var $storage \OC\Files\Storage\Storage */
list($storage) = $view->resolvePath($filename);
if ($storage->isLocal()) {
self::addSendfileHeader($filename);
} else {
\OC\Files\Filesystem::readfile($filename);
}
} else {
\OC\Files\Filesystem::readfile($filename);
}
}
}
示例7: count
OC_App::setActiveNavigationEntry("admin");
$template = new OC_Template('settings', 'admin', 'user');
$l = OC_L10N::get('settings');
$showLog = \OC::$server->getConfig()->getSystemValue('log_type', 'owncloud') === 'owncloud';
$numEntriesToLoad = 3;
$entries = OC_Log_Owncloud::getEntries($numEntriesToLoad + 1);
$entriesRemaining = count($entries) > $numEntriesToLoad;
$entries = array_slice($entries, 0, $numEntriesToLoad);
$logFilePath = OC_Log_Owncloud::getLogFilePath();
$doesLogFileExist = file_exists($logFilePath);
$logFileSize = filesize($logFilePath);
$config = \OC::$server->getConfig();
$appConfig = \OC::$server->getAppConfig();
$request = \OC::$server->getRequest();
// Should we display sendmail as an option?
$template->assign('sendmail_is_available', (bool) \OC_Helper::findBinaryPath('sendmail'));
$template->assign('loglevel', $config->getSystemValue("loglevel", 2));
$template->assign('mail_domain', $config->getSystemValue("mail_domain", ''));
$template->assign('mail_from_address', $config->getSystemValue("mail_from_address", ''));
$template->assign('mail_smtpmode', $config->getSystemValue("mail_smtpmode", ''));
$template->assign('mail_smtpsecure', $config->getSystemValue("mail_smtpsecure", ''));
$template->assign('mail_smtphost', $config->getSystemValue("mail_smtphost", ''));
$template->assign('mail_smtpport', $config->getSystemValue("mail_smtpport", ''));
$template->assign('mail_smtpauthtype', $config->getSystemValue("mail_smtpauthtype", ''));
$template->assign('mail_smtpauth', $config->getSystemValue("mail_smtpauth", false));
$template->assign('mail_smtpname', $config->getSystemValue("mail_smtpname", ''));
$template->assign('mail_smtppassword', $config->getSystemValue("mail_smtppassword", ''));
$template->assign('entries', $entries);
$template->assign('entriesremain', $entriesRemaining);
$template->assign('logFileSize', $logFileSize);
$template->assign('doesLogFileExist', $doesLogFileExist);
示例8: printExceptionErrorPage
/**
* print error page using Exception details
* @param Exception $exception
*/
public static function printExceptionErrorPage($exception)
{
try {
$request = \OC::$server->getRequest();
$content = new \OC_Template('', 'exception', 'error', false);
$content->assign('errorClass', get_class($exception));
$content->assign('errorMsg', $exception->getMessage());
$content->assign('errorCode', $exception->getCode());
$content->assign('file', $exception->getFile());
$content->assign('line', $exception->getLine());
$content->assign('trace', $exception->getTraceAsString());
$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
$content->assign('remoteAddr', $request->getRemoteAddress());
$content->assign('requestID', $request->getId());
$content->printPage();
} catch (\Exception $e) {
$logger = \OC::$server->getLogger();
$logger->logException($exception, ['app' => 'core']);
$logger->logException($e, ['app' => 'core']);
header(self::getHttpProtocol() . ' 500 Internal Server Error');
header('Content-Type: text/plain; charset=utf-8');
print "Internal Server Error\n\n";
print "The server encountered an internal error and was unable to complete your request.\n";
print "Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n";
print "More details can be found in the server log.\n";
}
die;
}
示例9: printUpgradePage
/**
* Prints the upgrade page
*/
private static function printUpgradePage()
{
$systemConfig = \OC::$server->getSystemConfig();
$oldTheme = $systemConfig->getValue('theme');
$systemConfig->setValue('theme', '');
\OCP\Util::addScript('config');
// needed for web root
\OCP\Util::addScript('update');
// check whether this is a core update or apps update
$installedVersion = $systemConfig->getValue('version', '0.0.0');
$currentVersion = implode('.', OC_Util::getVersion());
$appManager = \OC::$server->getAppManager();
$tmpl = new OC_Template('', 'update.admin', 'guest');
$tmpl->assign('version', OC_Util::getVersionString());
// if not a core upgrade, then it's apps upgrade
if (version_compare($currentVersion, $installedVersion, '=')) {
$tmpl->assign('isAppsOnlyUpgrade', true);
} else {
$tmpl->assign('isAppsOnlyUpgrade', false);
}
// get third party apps
$ocVersion = OC_Util::getVersion();
$tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion));
$tmpl->assign('incompatibleAppsList', $appManager->getIncompatibleApps($ocVersion));
$tmpl->assign('productName', 'ownCloud');
// for now
$tmpl->assign('oldTheme', $oldTheme);
$tmpl->printPage();
}
示例10: createMailBody
/**
* create mail body for plain text and html mail
*
* @param string $filename the shared file
* @param string $link link to the shared file
* @param int $expiration expiration date (timestamp)
* @return array an array of the html mail body and the plain text mail body
*/
private function createMailBody($filename, $link, $expiration) {
$formatedDate = $expiration ? $this->l->l('date', $expiration) : null;
$html = new \OC_Template("core", "mail", "");
$html->assign ('link', $link);
$html->assign ('user_displayname', $this->senderDisplayName);
$html->assign ('filename', $filename);
$html->assign('expiration', $formatedDate);
$htmlMail = $html->fetchPage();
$alttext = new \OC_Template("core", "altmail", "");
$alttext->assign ('link', $link);
$alttext->assign ('user_displayname', $this->senderDisplayName);
$alttext->assign ('filename', $filename);
$alttext->assign('expiration', $formatedDate);
$alttextMail = $alttext->fetchPage();
return array($htmlMail, $alttextMail);
}
示例11: createMailBody
/**
* create mail body for plain text and html mail
*
* @param string $filename the shared file
* @param string $link link to the shared file
* @param int $expiration expiration date (timestamp)
* @param string $prefix prefix of mail template files
* @return array an array of the html mail body and the plain text mail body
*/
private function createMailBody($filename, $link, $expiration, $prefix = '')
{
$formattedDate = $expiration ? $this->l->l('date', $expiration) : null;
$html = new \OC_Template('core', $prefix . 'mail', '');
$html->assign('link', $link);
$html->assign('user_displayname', $this->senderDisplayName);
$html->assign('filename', $filename);
$html->assign('expiration', $formattedDate);
$htmlMail = $html->fetchPage();
$plainText = new \OC_Template('core', $prefix . 'altmail', '');
$plainText->assign('link', $link);
$plainText->assign('user_displayname', $this->senderDisplayName);
$plainText->assign('filename', $filename);
$plainText->assign('expiration', $formattedDate);
$plainTextMail = $plainText->fetchPage();
return [$htmlMail, $plainTextMail];
}
示例12: array
$breadcrumb = array();
$pathtohere = "";
foreach (explode("/", $dir) as $i) {
if ($i != "") {
$pathtohere .= "/" . str_replace('+', '%20', urlencode($i));
$breadcrumb[] = array("dir" => $pathtohere, "name" => $i);
}
}
// make breadcrumb und filelist markup
$list = new OC_Template("files", "part.list", "");
$list->assign("files", $files);
$list->assign("baseURL", OC_Helper::linkTo("files", "index.php") . "?dir=");
$list->assign("downloadURL", OC_Helper::linkTo("files", "download.php") . "?file=");
$breadcrumbNav = new OC_Template("files", "part.breadcrumb", "");
$breadcrumbNav->assign("breadcrumb", $breadcrumb);
$breadcrumbNav->assign("baseURL", OC_Helper::linkTo("files", "index.php") . "?dir=");
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size'));
$maxUploadFilesize = min($upload_max_filesize, $post_max_size);
$freeSpace = OC_Filesystem::free_space('/');
$freeSpace = max($freeSpace, 0);
$maxUploadFilesize = min($maxUploadFilesize, $freeSpace);
$tmpl = new OC_Template("files", "index", "user");
$tmpl->assign("fileList", $list->fetchPage());
$tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage());
$tmpl->assign('dir', $dir);
$tmpl->assign('readonly', !OC_Filesystem::is_writable($dir));
$tmpl->assign("files", $files);
$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign('uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize));
$tmpl->printPage();
示例13: compareEntries
<?php
/**
* Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/
require_once '../lib/base.php';
OC_Util::checkAdminUser();
OC_Util::addStyle("settings", "settings");
OC_Util::addScript("settings", "admin");
OC_Util::addScript("settings", "log");
OC_App::setActiveNavigationEntry("admin");
$tmpl = new OC_Template('settings', 'admin', 'user');
$forms = OC_App::getForms('admin');
$entries = OC_Log_Owncloud::getEntries(3);
function compareEntries($a, $b)
{
return $b->time - $a->time;
}
usort($entries, 'compareEntries');
$tmpl->assign('loglevel', OC_Config::getValue("loglevel", 2));
$tmpl->assign('entries', $entries);
$tmpl->assign('forms', array());
foreach ($forms as $form) {
$tmpl->append('forms', $form);
}
$tmpl->printPage();
示例14: sendEmail
/**
* @param string $user
* @throws \Exception
*/
protected function sendEmail($user)
{
if (!$this->userManager->userExists($user)) {
throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.'));
}
$email = $this->config->getUserValue($user, 'settings', 'email');
if (empty($email)) {
throw new \Exception($this->l10n->t('Couldn\'t send reset email because there is no ' . 'email address for this username. Please ' . 'contact your administrator.'));
}
$token = $this->secureRandom->getMediumStrengthGenerator()->generate(21, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER);
$this->config->setUserValue($user, 'owncloud', 'lostpassword', $token);
$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user, 'token' => $token));
$tmpl = new \OC_Template('core/lostpassword', 'email');
$tmpl->assign('link', $link, false);
$msg = $tmpl->fetchPage();
try {
$message = $this->mailer->createMessage();
$message->setTo([$email => $user]);
$message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()]));
$message->setPlainBody($msg);
$message->setFrom([$this->from => $this->defaults->getName()]);
$this->mailer->send($message);
} catch (\Exception $e) {
throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please contact your administrator.'));
}
}
示例15: printUpgradePage
/**
* Prints the upgrade page
*/
private static function printUpgradePage()
{
$systemConfig = \OC::$server->getSystemConfig();
$disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false);
$tooBig = false;
if (!$disableWebUpdater) {
$apps = \OC::$server->getAppManager();
$tooBig = $apps->isInstalled('user_ldap') || $apps->isInstalled('user_shibboleth');
if (!$tooBig) {
// count users
$stats = \OC::$server->getUserManager()->countUsers();
$totalUsers = array_sum($stats);
$tooBig = $totalUsers > 50;
}
}
if ($disableWebUpdater || $tooBig) {
// send http status 503
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 120');
// render error page
$template = new OC_Template('', 'update.use-cli', 'guest');
$template->assign('productName', 'ownCloud');
// for now
$template->assign('version', OC_Util::getVersionString());
$template->assign('tooBig', $tooBig);
$template->printPage();
die;
}
// check whether this is a core update or apps update
$installedVersion = $systemConfig->getValue('version', '0.0.0');
$currentVersion = implode('.', \OCP\Util::getVersion());
// if not a core upgrade, then it's apps upgrade
$isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '=');
$oldTheme = $systemConfig->getValue('theme');
$systemConfig->setValue('theme', '');
\OCP\Util::addScript('config');
// needed for web root
\OCP\Util::addScript('update');
\OCP\Util::addStyle('update');
$appManager = \OC::$server->getAppManager();
$tmpl = new OC_Template('', 'update.admin', 'guest');
$tmpl->assign('version', OC_Util::getVersionString());
$tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade);
// get third party apps
$ocVersion = \OCP\Util::getVersion();
$tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion));
$tmpl->assign('incompatibleAppsList', $appManager->getIncompatibleApps($ocVersion));
$tmpl->assign('productName', 'ownCloud');
// for now
$tmpl->assign('oldTheme', $oldTheme);
$tmpl->printPage();
}