本文整理汇总了PHP中OCP\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function export()
{
$data = $this->data->export();
$fileName = User::getUser() . ".csv";
$Download = new DataDownloadResponse($data, $fileName, 'text/csv');
return $Download;
}
示例2: show
/**
* Get the template for a specific activity-event in the activities
*
* @param array $activity An array with all the activity data in it
* @return string
*/
public static function show($activity)
{
$tmpl = new Template('activity', 'activity.box');
$tmpl->assign('formattedDate', Util::formatDate($activity['timestamp']));
$tmpl->assign('formattedTimestamp', \OCP\relative_modified_date($activity['timestamp']));
$tmpl->assign('user', $activity['user']);
$tmpl->assign('displayName', User::getDisplayName($activity['user']));
if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
// We do not link the subject as we create links for the parameters instead
$activity['link'] = '';
}
$tmpl->assign('event', $activity);
if ($activity['file']) {
$rootView = new View('/' . $activity['affecteduser'] . '/files');
$exist = $rootView->file_exists($activity['file']);
$is_dir = $rootView->is_dir($activity['file']);
unset($rootView);
// show a preview image if the file still exists
$mimetype = \OC_Helper::getFileNameMimeType($activity['file']);
if (!$is_dir && \OC::$server->getPreviewManager()->isMimeSupported($mimetype) && $exist) {
$tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => dirname($activity['file']))));
$tmpl->assign('previewImageLink', Util::linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
} else {
$tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => $activity['file'])));
$tmpl->assign('previewImageLink', \OC_Helper::mimetypeIcon($is_dir ? 'dir' : $mimetype));
$tmpl->assign('previewLinkIsDir', true);
}
}
return $tmpl->fetchPage();
}
示例3: __construct
public function __construct(array $urlParams = array())
{
parent::__construct('weather', $urlParams);
$container = $this->getContainer();
/**
* Core
*/
$container->registerService('UserId', function (IContainer $c) {
return \OCP\User::getUser();
});
/**
* Database Layer
*/
$container->registerService('CityMapper', function (IContainer $c) {
return new CityMapper($c->query('ServerContainer')->getDb());
});
$container->registerService('SettingsMapper', function (IContainer $c) {
return new SettingsMapper($c->query('ServerContainer')->getDb());
});
/**
* Controllers
*/
$container->registerService('CityController', function (IContainer $c) {
return new CityController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('CityMapper'), $c->query('SettingsMapper'));
});
$container->registerService('SettingsController', function (IContainer $c) {
return new SettingsController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('SettingsMapper'), $c->query('CityMapper'));
});
$container->registerService('WeatherController', function (IContainer $c) {
return new WeatherController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('CityMapper'), $c->query('SettingsMapper'));
});
}
示例4: register
public function register()
{
$loginRecord = function ($user) {
\OCP\Util::writeLog('core', "user:" . \OCP\User::getDisplayName() . " action:login success", \OCP\Util::INFO);
};
$logoutRecord = function () {
\OCP\Util::writeLog('core', "user:" . \OCP\User::getDisplayName() . " action:logout success", \OCP\Util::INFO);
};
$createRecord = function ($node) {
\OCP\Util::writeLog('activity', "user:" . \OCP\User::getDisplayName() . " action:cretes " . $node->getName() . " sucess", \OCP\Util::INFO);
};
$deleteRecord = function ($node) {
\OCP\Util::writeLog('activity', "user:" . \OCP\User::getDisplayName() . " action:deletes " . $node->getName() . " sucess", \OCP\Util::INFO);
};
$renameRecord = function ($node) {
\OCP\Util::writeLog('activity', "user:" . \OCP\User::getDisplayName() . " action:renames " . $node->getName() . " sucess", \OCP\Util::INFO);
};
$touchRecord = function ($node) {
\OCP\Util::writeLog('activity', "user:" . \OCP\User::getDisplayName() . " action:touches " . $node->getName() . " sucess", \OCP\Util::INFO);
};
$this->userManager->listen('\\OC\\User', 'postLogin', $loginRecord);
$this->userManager->listen('\\OC\\User', 'logout', $logoutRecord);
$this->UserFolder->listen('\\OC\\Files', 'postCreate', $createRecord);
$this->UserFolder->listen('\\OC\\Files', 'postDelete', $deleteRecord);
$this->UserFolder->listen('\\OC\\Files', 'postRename', $renameRecord);
}
示例5: __construct
public function __construct (array $urlParams=array()) {
parent::__construct('ownnote', $urlParams);
$container = $this->getContainer();
/**
* Controllers
*/
$container->registerService('PageController', function(IContainer $c) {
return new PageController(
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId')
);
});
$container->registerService('OwnnoteApiController', function($c){
return new OwnnoteApiController(
$c->query('AppName'),
$c->query('Request')
);
});
/**
* Core
*/
$container->registerService('UserId', function(IContainer $c) {
return \OCP\User::getUser();
});
}
示例6: getACL
/**
* Returns a list of ACE's for this node.
*
* Each ACE has the following properties:
* * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
* currently the only supported privileges
* * 'principal', a url to the principal who owns the node
* * 'protected' (optional), indicating that this ACE is not allowed to
* be updated.
*
* @return array
*/
public function getACL()
{
$readprincipal = $this->getOwner();
$writeprincipal = $this->getOwner();
$createprincipal = $this->getOwner();
$deleteprincipal = $this->getOwner();
$uid = AddrBook::extractUserID($this->getOwner());
//\OCP\Config::setUserValue($uid, 'contactsplus', 'syncaddrbook', $this->addressBookInfo['uri']);
$readWriteACL = array(array('privilege' => '{DAV:}read', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true));
if ($uid !== \OCP\USER::getUser()) {
$sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX . $this->addressBookInfo['id']);
if ($sharedAddressbook) {
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
return $readWriteACL;
}
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) {
$createprincipal = 'principals/' . \OCP\USER::getUser();
}
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) {
$readprincipal = 'principals/' . \OCP\USER::getUser();
}
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) {
$writeprincipal = 'principals/' . \OCP\USER::getUser();
}
if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) {
$deleteprincipal = 'principals/' . \OCP\USER::getUser();
}
}
} else {
return parent::getACL();
}
return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write-content', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}bind', 'principal' => $createprincipal, 'protected' => true), array('privilege' => '{DAV:}unbind', 'principal' => $deleteprincipal, 'protected' => true));
}
示例7: __construct
public function __construct(array $urlParams = array())
{
parent::__construct('tasks', $urlParams);
$container = $this->getContainer();
/**
* Controllers
*/
$container->registerService('PageController', function ($c) {
return new PageController($c->query('AppName'), $c->query('Request'), $c->query('UserId'));
});
$container->registerService('CollectionsController', function ($c) {
return new CollectionsController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('L10N'), $c->query('Settings'));
});
$container->registerService('ListsController', function ($c) {
return new ListsController($c->query('AppName'), $c->query('Request'), $c->query('UserId'));
});
$container->registerService('SettingsController', function ($c) {
return new SettingsController($c->query('AppName'), $c->query('Request'), $c->query('UserId'), $c->query('Settings'));
});
$container->registerService('TasksController', function ($c) {
return new TasksController($c->query('AppName'), $c->query('Request'), $c->query('UserId'));
});
/**
* Core
*/
$container->registerService('UserId', function ($c) {
return \OCP\User::getUser();
});
$container->registerService('L10N', function ($c) {
return $c->query('ServerContainer')->getL10N($c->query('AppName'));
});
$container->registerService('Settings', function ($c) {
return $c->query('ServerContainer')->getConfig();
});
}
示例8: createShare
/**
* create a new share
*
* @param array $params
* @return \OC_OCS_Result
*/
public function createShare($params)
{
if (!$this->isS2SEnabled(true)) {
return new \OC_OCS_Result(null, 503, 'Server does not support federated cloud sharing');
}
$remote = isset($_POST['remote']) ? $_POST['remote'] : null;
$token = isset($_POST['token']) ? $_POST['token'] : null;
$name = isset($_POST['name']) ? $_POST['name'] : null;
$owner = isset($_POST['owner']) ? $_POST['owner'] : null;
$shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
$remoteId = isset($_POST['remoteId']) ? (int) $_POST['remoteId'] : null;
if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
if (!\OCP\Util::isValidFileName($name)) {
return new \OC_OCS_Result(null, 400, 'The mountpoint name contains invalid characters.');
}
if (!\OCP\User::userExists($shareWith)) {
return new \OC_OCS_Result(null, 400, 'User does not exists');
}
\OC_Util::setupFS($shareWith);
$externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), $shareWith);
try {
$externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
$user = $owner . '@' . $this->cleanupRemote($remote);
\OC::$server->getActivityManager()->publishActivity('files_sharing', \OCA\Files_Sharing\Activity::SUBJECT_REMOTE_SHARE_RECEIVED, array($user), '', array(), '', '', $shareWith, \OCA\Files_Sharing\Activity::TYPE_REMOTE_SHARE, \OCA\Files_Sharing\Activity::PRIORITY_LOW);
return new \OC_OCS_Result();
} catch (\Exception $e) {
\OCP\Util::writeLog('files_sharing', 'server can not add remote share, ' . $e->getMessage(), \OCP\Util::ERROR);
return new \OC_OCS_Result(null, 500, 'internal server error, was not able to add share from ' . $remote);
}
}
return new \OC_OCS_Result(null, 400, 'server can not add remote share, missing parameter');
}
示例9: checkAttributes
/**
* Checks if the user has all required attributes
* and, if successfull, returns user's owncloud uid.
*
* @return false|string false if requirements not met, OC uid otherwise
*/
public function checkAttributes()
{
// Shibboleth/SAML uid is always required
$shibUid = $this->getShibUid();
if (!$shibUid) {
return false;
}
// TODO: Move email to $backendConfig['required_attrs']
// TODO: Require email for all users (not only newly created)
// when all IdP's will provide it for us. Then move getOcUid
// call to the end of this method.
$ocUid = $this->getOcUid();
if (!$this->getEmail() && !\OCP\User::userExists($ocUid)) {
return false;
}
// Check for additional required attributes
$missingAttrs = '';
foreach ($this->backendConfig['required_attrs'] as &$attr) {
if (!$this->getAttribute($attr)) {
$missingAttrs .= $attr . ' ';
}
}
if ($missingAttrs !== '') {
$this->logger->warning(sprintf('User: %s is' . ' missing required attributes: %s', $shibUid, $missingAttrs), $this->logCtx);
return false;
}
return $ocUid;
}
示例10: __construct
public function __construct(array $urlParams = array())
{
parent::__construct('documents', $urlParams);
$container = $this->getContainer();
/**
* Controllers
*/
$container->registerService('UserController', function ($c) {
return new UserController($c->query('AppName'), $c->query('Request'));
});
$container->registerService('SessionController', function ($c) {
return new SessionController($c->query('AppName'), $c->query('Request'), $c->query('Logger'), $c->query('UserId'));
});
$container->registerService('DocumentController', function ($c) {
return new DocumentController($c->query('AppName'), $c->query('Request'), $c->query('CoreConfig'), $c->query('L10N'), $c->query('UserId'));
});
$container->registerService('SettingsController', function ($c) {
return new SettingsController($c->query('AppName'), $c->query('Request'), $c->query('CoreConfig'), $c->query('Logger'), $c->query('L10N'), $c->query('UserId'));
});
/**
* Core
*/
$container->registerService('Logger', function ($c) {
return $c->query('ServerContainer')->getLogger();
});
$container->registerService('CoreConfig', function ($c) {
return $c->query('ServerContainer')->getConfig();
});
$container->registerService('L10N', function ($c) {
return $c->query('ServerContainer')->getL10N($c->query('AppName'));
});
$container->registerService('UserId', function () {
return \OCP\User::getUser();
});
}
示例11: getShortcode
function getShortcode($url) {
$shortcode = '';
$query = OCP\DB::prepare('SELECT shortcode FROM *PREFIX*shorten WHERE url=?');
$results = $query->execute(Array($url))->fetchAll();
if ($results) {
foreach($results as $result) {
$shortcode = $result['shortcode'];
}
}
if ($shortcode == "") {
$shortcode = rand_chars(6);
$found = true;
while ($found) {
$query = OCP\DB::prepare('SELECT id FROM *PREFIX*shorten WHERE shortcode=?');
$results = $query->execute(Array($shortcode))->fetchAll();
if (!$results) {
$found = false;
$uid = \OCP\User::getUser();
$query = OCP\DB::prepare('INSERT INTO *PREFIX*shorten (uid, shortcode, url) VALUES (?,?,?)');
$query->execute(Array($uid,$shortcode,$url));
$id = OCP\DB::insertid('*PREFIX*shorten');
} else
$shortcode = rand_chars(6);
}
}
return $shortcode;
}
示例12: __construct
/**
* Define your dependencies in here
*/
public function __construct(array $urlParams = array())
{
parent::__construct('user_files_restore', $urlParams);
$container = $this->getContainer();
/**
* Controllers
*/
$container->registerService('PageController', function ($c) {
return new PageController($c->query('AppName'), $c->query('Request'), $c->query('L10N'), $c->query('RequestService'), $c->query('UserId'));
});
$container->registerService('RequestController', function ($c) {
return new RequestController($c->query('AppName'), $c->query('Request'), $c->query('L10N'), $c->query('RequestMapper'), $c->query('UserId'));
});
/**
* Services
*/
$container->registerService('RequestService', function ($c) {
return new RequestService($c->query('RequestMapper'), $c->query('UserId'), $c->query('L10N'));
});
/**
* Database Layer
*/
$container->registerService('RequestMapper', function ($c) {
return new RequestMapper($c->query('ServerContainer')->getDb(), $c->query('L10N'));
});
/**
* Core
*/
$container->registerService('UserId', function ($c) {
return \OCP\User::getUser();
});
$container->registerService('L10N', function ($c) {
return $c->query('ServerContainer')->getL10N($c->query('AppName'));
});
}
示例13: show
/**
* Get the template for a specific activity-event in the activities
*
* @param array $activity An array with all the activity data in it
* @return string
*/
public function show($activity)
{
$tmpl = new Template('activity', 'stream.item');
$tmpl->assign('formattedDate', $this->dateTimeFormatter->formatDateTime($activity['timestamp']));
$tmpl->assign('formattedTimestamp', Template::relative_modified_date($activity['timestamp']));
$tmpl->assign('user', $activity['user']);
$tmpl->assign('displayName', User::getDisplayName($activity['user']));
if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
// We do not link the subject as we create links for the parameters instead
$activity['link'] = '';
}
$tmpl->assign('event', $activity);
if ($activity['file']) {
$this->view->chroot('/' . $activity['affecteduser'] . '/files');
$exist = $this->view->file_exists($activity['file']);
$is_dir = $this->view->is_dir($activity['file']);
$tmpl->assign('previewLink', $this->getPreviewLink($activity['file'], $is_dir));
// show a preview image if the file still exists
$mimeType = \OC_Helper::getFileNameMimeType($activity['file']);
if ($mimeType && !$is_dir && $this->preview->isMimeSupported($mimeType) && $exist) {
$tmpl->assign('previewImageLink', $this->urlGenerator->linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
} else {
$mimeTypeIcon = Template::mimetype_icon($is_dir ? 'dir' : $mimeType);
$mimeTypeIcon = substr($mimeTypeIcon, -4) === '.png' ? substr($mimeTypeIcon, 0, -4) . '.svg' : $mimeTypeIcon;
$tmpl->assign('previewImageLink', $mimeTypeIcon);
$tmpl->assign('previewLinkIsDir', true);
}
}
return $tmpl->fetchPage();
}
示例14: exportEvents
/**
*@PublicPage
* @NoCSRFRequired
*
*/
public function exportEvents()
{
$token = $this->params('t');
$calid = null;
$eventid = null;
if (isset($token)) {
$linkItem = \OCP\Share::getShareByToken($token, false);
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
$rootLinkItem = \OCP\Share::resolveReShare($linkItem);
if (isset($rootLinkItem['uid_owner'])) {
\OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
$sPrefix = CalendarApp::SHARECALENDARPREFIX;
}
if ($linkItem['item_type'] === CalendarApp::SHAREEVENT) {
$sPrefix = CalendarApp::SHAREEVENTPREFIX;
}
if ($linkItem['item_type'] === CalendarApp::SHARETODO) {
$sPrefix = CalendarApp::SHARETODOPREFIX;
}
$itemSource = CalendarApp::validateItemSource($linkItem['item_source'], $sPrefix);
if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
$calid = $itemSource;
}
if ($linkItem['item_type'] === CalendarApp::SHAREEVENT || $linkItem['item_type'] === CalendarApp::SHARETODO) {
$eventid = $itemSource;
}
}
}
} else {
if (\OCP\User::isLoggedIn()) {
$calid = $this->params('calid');
$eventid = $this->params('eventid');
}
}
if (!is_null($calid)) {
$calendar = CalendarApp::getCalendar($calid, true);
if (!$calendar) {
$params = ['status' => 'error'];
$response = new JSONResponse($params);
return $response;
}
$name = str_replace(' ', '_', $calendar['displayname']) . '.ics';
$calendarEvents = Export::export($calid, Export::CALENDAR);
$response = new DataDownloadResponse($calendarEvents, $name, 'text/calendar');
return $response;
}
if (!is_null($eventid)) {
$data = CalendarApp::getEventObject($eventid, false);
if (!$data) {
$params = ['status' => 'error'];
$response = new JSONResponse($params);
return $response;
}
$name = str_replace(' ', '_', $data['summary']) . '.ics';
$singleEvent = Export::export($eventid, Export::EVENT);
$response = new DataDownloadResponse($singleEvent, $name, 'text/calendar');
return $response;
}
}
示例15: search
function search($query)
{
$collection = new Collection(\OCP\User::getUser());
$l = \OC_L10N::get('media');
$app_name = (string) $l->t('Music');
$artists = $collection->getArtists($query);
$albums = $collection->getAlbums(0, $query);
$songs = $collection->getSongs(0, 0, $query);
$results = array();
foreach ($artists as $artist) {
$results[] = new \OC_Search_Result($artist['artist_name'], '', \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist['artist_name']), $app_name);
}
foreach ($albums as $album) {
$artist = $collection->getArtistName($album['album_artist']);
$results[] = new \OC_Search_Result($album['album_name'], 'by ' . $artist, \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album['album_name']), $app_name);
}
foreach ($songs as $song) {
$minutes = floor($song['song_length'] / 60);
$seconds = $song['song_length'] % 60;
$artist = $collection->getArtistName($song['song_artist']);
$album = $collection->getalbumName($song['song_album']);
$results[] = new \OC_Search_Result($song['song_name'], "by {$artist}, in {$album} {$minutes}:{$seconds}", \OCP\Util::linkTo('media', 'index.php') . '#artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&song=' . urlencode($song['song_name']), $app_name);
}
return $results;
}