本文整理汇总了PHP中OCP\JSON类的典型用法代码示例。如果您正苦于以下问题:PHP JSON类的具体用法?PHP JSON怎么用?PHP JSON使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSON类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preDispatchGuest
/**
* Do security precheck for not logged in users
* @param bool callcheck - whether security token check is needed
*/
public static function preDispatchGuest($callcheck = true)
{
if ($callcheck) {
\OCP\JSON::callCheck();
}
\OCP\JSON::checkAppEnabled('documents');
}
示例2: Add
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function Add()
{
\OCP\JSON::setContentTypeHeader('application/json');
if (isset($_POST['FILE']) && strlen($_POST['FILE']) > 0 && Tools::CheckURL($_POST['FILE']) && isset($_POST['OPTIONS'])) {
try {
$Target = Tools::CleanString(substr($_POST['FILE'], strrpos($_POST['FILE'], '/') + 1));
// If target file exists, create a new one
if (\OC\Files\Filesystem::file_exists($this->DownloadsFolder . '/' . $Target)) {
$Target = time() . '_' . $Target;
}
// Create the target file if the downloader is Aria2
if ($this->WhichDownloader == 0) {
\OC\Files\Filesystem::touch($this->DownloadsFolder . '/' . $Target);
} else {
if (!\OC\Files\Filesystem::is_dir($this->DownloadsFolder)) {
\OC\Files\Filesystem::mkdir($this->DownloadsFolder);
}
}
// Build OPTIONS array
$OPTIONS = array('dir' => $this->AbsoluteDownloadsFolder, 'out' => $Target, 'follow-torrent' => false);
if (isset($_POST['OPTIONS']['FTPUser']) && strlen(trim($_POST['OPTIONS']['FTPUser'])) > 0 && isset($_POST['OPTIONS']['FTPPasswd']) && strlen(trim($_POST['OPTIONS']['FTPPasswd'])) > 0) {
$OPTIONS['ftp-user'] = $_POST['OPTIONS']['FTPUser'];
$OPTIONS['ftp-passwd'] = $_POST['OPTIONS']['FTPPasswd'];
}
if (isset($_POST['OPTIONS']['FTPPasv']) && strlen(trim($_POST['OPTIONS']['FTPPasv'])) > 0) {
$OPTIONS['ftp-pasv'] = strcmp($_POST['OPTIONS']['FTPPasv'], "true") == 0 ? true : false;
}
if (!$this->ProxyOnlyWithYTDL && !is_null($this->ProxyAddress) && $this->ProxyPort > 0 && $this->ProxyPort <= 65536) {
$OPTIONS['all-proxy'] = rtrim($this->ProxyAddress, '/') . ':' . $this->ProxyPort;
if (!is_null($this->ProxyUser) && !is_null($this->ProxyPasswd)) {
$OPTIONS['all-proxy-user'] = $this->ProxyUser;
$OPTIONS['all-proxy-passwd'] = $this->ProxyPasswd;
}
}
$AddURI = $this->WhichDownloader == 0 ? Aria2::AddUri(array($_POST['FILE']), array('Params' => $OPTIONS)) : CURL::AddUri($_POST['FILE'], $OPTIONS);
if (isset($AddURI['result']) && !is_null($AddURI['result'])) {
$SQL = 'INSERT INTO `*PREFIX*ocdownloader_queue` (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES (?, ?, ?, ?, ?, ?)';
if ($this->DbType == 1) {
$SQL = 'INSERT INTO *PREFIX*ocdownloader_queue ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES (?, ?, ?, ?, ?, ?)';
}
$Query = \OCP\DB::prepare($SQL);
$Result = $Query->execute(array($this->CurrentUID, $AddURI['result'], $Target, strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 1, time()));
sleep(1);
$Status = $this->WhichDownloader == 0 ? Aria2::TellStatus($AddURI['result']) : CURL::TellStatus($AddURI['result']);
$Progress = 0;
if ($Status['result']['totalLength'] > 0) {
$Progress = $Status['result']['completedLength'] / $Status['result']['totalLength'];
}
$ProgressString = Tools::GetProgressString($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress);
return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('Download started'), 'GID' => $AddURI['result'], 'PROGRESSVAL' => round($Progress * 100, 2) . '%', 'PROGRESS' => is_null($ProgressString) ? (string) $this->L10N->t('N/A') : $ProgressString, 'STATUS' => isset($Status['result']['status']) ? (string) $this->L10N->t(ucfirst($Status['result']['status'])) : (string) $this->L10N->t('N/A'), 'STATUSID' => Tools::GetDownloadStatusID($Status['result']['status']), 'SPEED' => isset($Status['result']['downloadSpeed']) ? Tools::FormatSizeUnits($Status['result']['downloadSpeed']) . '/s' : (string) $this->L10N->t('N/A'), 'FILENAME' => strlen($Target) > 40 ? substr($Target, 0, 40) . '...' : $Target, 'PROTO' => strtoupper(substr($_POST['FILE'], 0, strpos($_POST['FILE'], ':'))), 'ISTORRENT' => false));
} else {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t($this->WhichDownloader == 0 ? 'Returned GID is null ! Is Aria2c running as a daemon ?' : 'An error occurred while running the CURL download')));
}
} catch (Exception $E) {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage()));
}
} else {
return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Please check the URL you\'ve just provided')));
}
}
示例3: 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;
}
}
示例4: initAjaxController
public static function initAjaxController()
{
\OCP\JSON::checkLoggedIn();
\OCP\JSON::callCheck();
\OCP\JSON::checkAppEnabled('contacts');
\OCP\JSON::checkAppEnabled(self::APP_ID);
}
示例5: render
/**
* Returns the rendered json
* @return the rendered json
*/
public function render()
{
parent::render();
ob_start();
if ($this->error) {
\OCP\JSON::error($this->data);
} else {
\OCP\JSON::success($this->data);
}
$result = ob_get_contents();
ob_end_clean();
return $result;
}
示例6: runChecks
/**
* Runs all security checks
*/
public function runChecks()
{
if ($this->csrfCheck) {
\OCP\JSON::callCheck();
}
if ($this->loggedInCheck) {
\OCP\JSON::checkLoggedIn();
}
if ($this->appEnabledCheck) {
\OCP\JSON::checkAppEnabled($this->appName);
}
if ($this->isAdminCheck) {
\OCP\User::checkAdminUser();
}
}
示例7: postlogin_hook
/**
* Send JSON response on successful login
* @param String $uid
*/
public static function postlogin_hook($uid)
{
if (!self::$_isPersona) {
return;
}
\OCP\Util::writeLog(App::APP_ID, 'Check ambigous ', \OCP\Util::DEBUG);
if (self::$_isAmbigous) {
//Reply with error and logout
\OCP\User::logout();
\OCP\JSON::error(array('msg' => 'More than one user found'));
exit;
} else {
\OCP\JSON::success(array('msg' => 'Access granted'));
exit;
}
}
示例8: Check
/**
* @AdminRequired
* @NoCSRFRequired
*/
public function Check()
{
\OCP\JSON::setContentTypeHeader('application/json');
if ($this->Allow) {
try {
$LastVersionNumber = Tools::GetLastVersionNumber();
$AppVersion = \OCP\App::getAppVersion('ocdownloader');
$Response = array('ERROR' => false, 'RESULT' => version_compare($AppVersion, $LastVersionNumber, '<'));
} catch (Exception $E) {
$Response = array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('Error while checking application version on GitHub'));
}
} else {
$Response = array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('You are not allowed to check for application updates'));
}
return new JSONResponse($Response);
}
示例9: invite
/**
* Invite users to the editing session
*/
public static function invite()
{
self::preDispatch();
$invitees = @$_POST['users'];
if (is_array($invitees)) {
$invitees = array_unique($invitees);
$esId = @$_POST['esId'];
foreach ($invitees as $userId) {
try {
Invite::add($esId, $userId);
} catch (\Exception $e) {
}
}
}
\OCP\JSON::success();
}
示例10: setupFromToken
/**
* Sets up the filesystem and user for public sharing
* @param string $token string share token
* @param string $relativePath optional path relative to the share
* @param string $password optional password
*/
public static function setupFromToken($token, $relativePath = null, $password = null)
{
\OC_User::setIncognitoMode(true);
$linkItem = \OCP\Share::getShareByToken($token, !$password);
if ($linkItem === false || $linkItem['item_type'] !== 'file' && $linkItem['item_type'] !== 'folder') {
\OC_Response::setStatus(404);
\OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG);
exit;
}
if (!isset($linkItem['uid_owner']) || !isset($linkItem['file_source'])) {
\OC_Response::setStatus(500);
\OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")', \OC_Log::WARN);
exit;
}
$rootLinkItem = \OCP\Share::resolveReShare($linkItem);
$path = null;
if (isset($rootLinkItem['uid_owner'])) {
\OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
\OC_Util::tearDownFS();
\OC_Util::setupFS($rootLinkItem['uid_owner']);
$path = \OC\Files\Filesystem::getPath($linkItem['file_source']);
}
if ($path === null) {
\OCP\Util::writeLog('share', 'could not resolve linkItem', \OCP\Util::DEBUG);
\OC_Response::setStatus(404);
\OCP\JSON::error(array('success' => false));
exit;
}
if (!isset($linkItem['item_type'])) {
\OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR);
\OC_Response::setStatus(404);
\OCP\JSON::error(array('success' => false));
exit;
}
if (isset($linkItem['share_with'])) {
if (!self::authenticate($linkItem, $password)) {
\OC_Response::setStatus(403);
\OCP\JSON::error(array('success' => false));
exit;
}
}
$basePath = $path;
if ($relativePath !== null && \OC\Files\Filesystem::isReadable($basePath . $relativePath)) {
$path .= \OC\Files\Filesystem::normalizePath($relativePath);
}
return array('linkItem' => $linkItem, 'basePath' => $basePath, 'realPath' => $path);
}
示例11: rename
public static function rename($args)
{
self::preDispatchGuest();
$memberId = Helper::getArrayValueByKey($args, 'member_id');
$name = Helper::getArrayValueByKey($_POST, 'name');
$member = new Db\Member();
$member->load($memberId);
if ($member->getEsId() && $member->getStatus() == Db\Member::MEMBER_STATUS_ACTIVE && $member->getIsGuest()) {
$guestMark = Db\Member::getGuestPostfix();
if (substr($name, -strlen($guestMark)) !== $guestMark) {
$name = $name . ' ' . $guestMark;
}
$op = new Db\Op();
$op->changeNick($member->getEsId(), $memberId, $name);
}
\OCP\JSON::success();
}
示例12: __construct
public function __construct($AppName, IRequest $request, $UserId)
{
parent::__construct($AppName, $request);
$this->userId = $UserId;
$path = self::PROJECTKIT_PREFIX . DIRECTORY_SEPARATOR;
if (isset($_GET['containerId'])) {
$path .= self::PROJECT_PREFIX . (string) $_GET['containerId'] . DIRECTORY_SEPARATOR;
if (isset($_GET['targetType']) && isset($_GET['targetId'])) {
switch ($_GET['targetType']) {
case TargetType::TASK:
$path .= self::TASK_PREFIX;
break;
case TargetType::ISSUE:
$path .= self::ISSUE_PREFIX;
break;
default:
break;
}
$path .= (string) $_GET['targetId'] . DIRECTORY_SEPARATOR;
$_SESSION['targetType'] = $_GET['targetType'];
} elseif (!isset($_GET['targetType']) && !isset($_GET['targetId'])) {
$_SESSION['targetType'] = TargetType::PROJECT;
}
//use session to save targetType
$path = Filesystem::normalizePath($path);
//Create folder for path
if (!Filesystem::file_exists($path)) {
try {
Filesystem::mkdir($path);
} catch (\Exception $e) {
$result = ['success' => false, 'data' => ['message' => $e->getMessage()]];
\OCP\JSON::error($result);
exit;
}
}
if (!isset($_GET['dir'])) {
$params = array_merge($_GET, ["dir" => $path]);
$url = $_SERVER['PHP_SELF'] . '?' . http_build_query($params);
header('Location: ' . $url, true, 302);
exit;
}
}
}
示例13: av_scan
public static function av_scan($path)
{
$path = $path[\OC\Files\Filesystem::signal_param_path];
if ($path != '') {
if (isset($_POST['dirToken'])) {
//Public upload case
$filesView = \OC\Files\Filesystem::getView();
} else {
$filesView = \OCP\Files::getStorage("files");
}
if (!is_object($filesView)) {
\OCP\Util::writeLog('files_antivirus', 'Can\'t init filesystem view', \OCP\Util::WARN);
return;
}
// check if path is a directory
if ($filesView->is_dir($path)) {
return;
}
// we should have a file to work with, and the file shouldn't
// be empty
$fileExists = $filesView->file_exists($path);
if ($fileExists && $filesView->filesize($path) > 0) {
$fileStatus = self::scanFile($filesView, $path);
$result = $fileStatus->getNumericStatus();
switch ($result) {
case Status::SCANRESULT_UNCHECKED:
//TODO: Show warning to the user: The file can not be checked
break;
case Status::SCANRESULT_INFECTED:
//remove file
$filesView->unlink($path);
Notification::sendMail($path);
$message = \OCP\Util::getL10N('files_antivirus')->t("Virus detected! Can't upload the file %s", array(basename($path)));
\OCP\JSON::error(array("data" => array("message" => $message)));
exit;
break;
case Status::SCANRESULT_CLEAN:
//do nothing
break;
}
}
}
}
示例14: apply
/**
* Check if we have a user to login
* @param String $email
* @param String $uid
* @return String
*/
public static function apply($email, $uid = '')
{
//Get list of matching users
$list = array();
$query = \OCP\DB::prepare('SELECT userid FROM *PREFIX*preferences WHERE appid = ? AND configkey = ? AND configvalue = ?');
$result = $query->execute(array('settings', 'email', $email));
while ($userid = $result->fetchOne()) {
$list[] = $userid;
}
$qtyUser = count($list);
//No users found
if (!$qtyUser) {
\OCP\Util::writeLog(App::APP_ID, 'No users found. Deny login.', \OCP\Util::DEBUG);
return false;
}
//One user found
if ($qtyUser == 1) {
\OCP\Util::writeLog(App::APP_ID, 'Single user found. Entering the open space.', \OCP\Util::DEBUG);
return $list[0];
}
//Multiple users found
$currentPolicy = self::getSystemPolicy();
$isValidUid = in_array($uid, $list);
if ($currentPolicy == self::MULTIPLE_USERS_LIST) {
//Do we have correct uid?
if ($isValidUid) {
\OCP\Util::writeLog(App::APP_ID, 'Multiple users found. Entering the open space.', \OCP\Util::DEBUG);
return $uid;
} else {
\OCP\Util::writeLog(App::APP_ID, 'Multiple users found. List them all.', \OCP\Util::DEBUG);
\OCP\JSON::success(array('list' => $list));
exit;
}
} elseif ($currentPolicy == self::MULTIPLE_USERS_FIRST) {
\OCP\Util::writeLog(App::APP_ID, 'Multiple users found. Use first.', \OCP\Util::DEBUG);
//not first but the best matching ;)
$userid = $isValidUid ? $uid : $list[0];
return $userid;
}
\OCP\Util::writeLog(App::APP_ID, 'Multiple users found. Deny login.', \OCP\Util::DEBUG);
return Validator::setAmbigous();
}
示例15: sendTestMail
/**
* Send a mail to test the settings
*/
public static function sendTestMail()
{
\OC_Util::checkAdminUser();
\OCP\JSON::callCheck();
$l = \OC::$server->getL10N('settings');
$email = \OC_Preferences::getValue(\OC_User::getUser(), 'settings', 'email', '');
if (!empty($email)) {
$defaults = new \OC_Defaults();
try {
\OC_Mail::send($email, \OC_User::getDisplayName(), $l->t('test email settings'), $l->t('If you received this email, the settings seem to be correct.'), \OCP\Util::getDefaultEmailAddress('no-reply'), $defaults->getName());
} catch (\Exception $e) {
$message = $l->t('A problem occurred while sending the e-mail. Please revisit your settings.');
\OC_JSON::error(array("data" => array("message" => $message)));
exit;
}
\OC_JSON::success(array("data" => array("message" => $l->t("Email sent"))));
} else {
$message = $l->t('You need to set your user email before being able to send test emails.');
\OC_JSON::error(array("data" => array("message" => $message)));
}
}