aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/wysiwyg.php
diff options
context:
space:
mode:
authorMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2022-09-06 08:17:41 +0000
committerElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2022-09-06 08:17:41 +0000
commit5d79d3eaaa9c66126cafb20ff50d2782c926faf3 (patch)
treeb0066794efa87ee06f12e7d1d34f664240637085 /app/controllers/wysiwyg.php
parent8c5a90d52e8f3ea8edb4ee2e24275c96119e07aa (diff)
Remove WYSIWYG toolbar icon to disable WYSIWYG, fixes #1495
Closes #1495 Merge request studip/studip!946
Diffstat (limited to 'app/controllers/wysiwyg.php')
-rw-r--r--app/controllers/wysiwyg.php329
1 files changed, 0 insertions, 329 deletions
diff --git a/app/controllers/wysiwyg.php b/app/controllers/wysiwyg.php
index 88e640c..cb07e6f 100644
--- a/app/controllers/wysiwyg.php
+++ b/app/controllers/wysiwyg.php
@@ -120,333 +120,4 @@ class WysiwygController extends AuthenticatedController
}
$this->render_json($response); // send HTTP response to client
}
-
- /**
- * Store or retrieve settings.
- *
- * Settings are further subdivided into groups. For example: global,
- * seminar- and user-specific settings (see below).
- *
- * HTTP GET
- * returns a JSON object with current settings.
- *
- * HTTP PUT
- * expects a JSON object with settings to store and returns
- * updated settings as a JSON object. Some settings are read-only,
- * others can only be set if the user has the necessary access level.
- *
- * Currently only the following basic features are supported:
- *
- * HTTP GET wysiwyg/settings/global
- * Always returns:
- * {
- * "upload": {
- * "permission": "autor",
- * "folder": {
- * "name": "Wysiwyg Uploads",
- * "description": "Vom WYSIWYG Editor hochgeladene Dateien."
- * }
- * }
- * }
- * }
- *
- * HTTP GET wysiwyg/settings/users/current
- * Always returns following setting for the authenticated user:
- * {
- * "disabled": false | true
- * }
- *
- * HTTP PUT wysiwyg/settings/users/current
- * Allows only to reset or set the disabled state with:
- * {
- * "disabled": false | true
- * }
- *
- * Below is a specification of possible future extensions to this
- * interface, that are based on current feature requests by users
- * (mainly people from ELMO, ELAN and ECULT).
- *
- * wysiwyg/settings/global
- * Common settings for all WYSIWYG editors throughout Stud.IP.
- * wysiwyg/settings/seminars
- * Settings of all seminars.
- * Listed seminars depend on access level:
- * root => full access to all seminars
- * dozent, tutor of a seminar => full access to those seminars
- * others => read-access to seminars they are a member of
- * wysiwyg/settings/seminars/ID
- * Settings of the seminar with the given ID.
- * Access permissions: see above.
- * wysiwyg/settings/seminars/ID/users
- * Seminar's settings for all its users.
- * Access permissions: see above.
- * wysiwyg/settings/seminars/ID/users/ID
- * Seminar's settings for a specific user in that seminar.
- * Access permissions: see above.
- * wysiwyg/settings/users
- * Settings of all users.
- * Listed users depend on access level:
- * root => full access to all users
- * not root => full access to own settings only
- * wysiwyg/settings/users/ID
- * Settings of the user with the given ID.
- * Access permissions: see above.
- * wysiwyg/settings/users/ID/seminars
- * User's settings for all seminars the user is a member of.
- * Access permissions: see above.
- * wysiwyg/settings/users/ID/seminars/ID
- * User's settings for the seminar with the given ID.
- * Access permissions: see above.
- *
- * The difference of seminar's settings for a user and user's settings
- * for a seminar:
- *
- * A seminar's teacher may want to set the upload directory for each user
- * to a separate one, which should not be overwritable by a user, in
- * order to make sure that users cannot see other users uploads (there
- * are other ways to do this, but it's just an example).
- *
- * A user might want to have a specific upload directory in order to
- * collaborate better with other users in the same seminar (e.g. when
- * students form a study group).
- *
- * For example the ELMO module needs such settings.
- *
- * JSON scheme for access to wysiwyg/settings:
- * {
- * "global": { "SETTING": ..., ... },
- * "seminars": {
- * "ID": {
- * "users": { "ID": {...}, ... },
- * "SETTING": ...,
- * ...
- * },
- * "ID": {...},
- * ...
- * },
- * "users": {
- * "ID": {
- * "seminars": { "ID": {...}, ... },
- * "SETTING": ...,
- * ...
- * },
- * "ID": {...},
- * ...
- * }
- * }
- *
- * When accessing a sub-resource that resource's branch of the JSON scheme
- * will be returned.
- */
- public function settings_action()
- {
- try {
- if (!Request::isGet() && !Request::isPut()) {
- throw new WysiwygHttpExceptionMethodNotAllowed(
- _('Nur die HTTP-Methoden GET und PUT sind erlaubt.')
- );
- }
-
- $arguments = func_get_args();
- $settingsGroup = array_shift($arguments);
-
- if (Request::isPut()) {
- $this->setSettings($settingsGroup, $arguments);
- }
- $this->render_json($this->objectToArray(
- $this->getSettings($settingsGroup, $arguments)
- ));
- } catch (WysiwygHttpException $e) {
- $this->set_status($e->getCode());
- $this->set_content_type('text/plain; charset=utf-8');
- $this->render_text($e->getMessage());
- }
- }
-
- public function a11yhelp_action()
- {
- // nothing to do
- PageLayout::setTitle(_('Hilfe zur Bedienung des Editors'));
- }
-
- /**
- * Set WYSIWYG settings for a specific group.
- *
- * Dummy implementation: Currently only accepts setting the
- * disabled flag for wysiwyg/settings/users/current.
- *
- * The HTTP request's body must contain a JSON document of the form:
- * {
- * "disabled": true | false
- * }
- *
- * If the JSON contains other additional values they will be ignored.
- *
- * @param string $group Must be set to 'users'.
- * @param array $arguments Must contain exactly one entry: 'current'.
- */
- private function setSettings($group, $arguments) {
- $user = array_shift($arguments);
- if ($group !== 'users' || $user !== 'current') {
- throw new WysiwygHttpExceptionForbidden(
- _('Zugriff verweigert')
- );
- }
-
- $subgroup = array_shift($arguments);
- if (($subgroup !== null && $subgroup !== '') || count($arguments) > 0) {
- throw new WysiwygHttpExceptionNotFound(
- _('Die Benutzereinstellungen enthalten keine Untergruppen.')
- );
- }
-
- $data = json_decode(file_get_contents('php://input'));
- if (isset($data->disabled)) {
- $config = $GLOBALS['user']->cfg;
- //$config->WYSIWYG_DISABLED = (boolean)$data->disabled;
- $config->store(
- 'WYSIWYG_DISABLED',
- (boolean)$data->disabled
- );
- } else {
- throw new WysiwygHttpExceptionBadRequest(
- _('Die Anfrage enthält ungültige Werte.')
- );
- }
- // all unknown parameters are ignored
- }
-
- /**
- * Return WYSIWYG settings for a specific group.
- *
- * @param $group string The requested settings group: 'user', 'seminar',
- * 'global' or 'all'. If the group is set to 'all' then all levels will be
- * returned. If the group is unknown an error will be thrown.
- *
- * @return object Settings for the requested group.
- */
- private function getSettings($group, $arguments)
- {
- switch ($group) {
- case null: return $this->getAllSettings();
- case 'global': return $this->getGlobalSettings($arguments);
- case 'users': return $this->getUserSettings($arguments);
- }
- throw new WysiwygHttpExceptionNotFound(
- _('Die angeforderte Gruppe von Einstellungen existiert nicht.')
- );
- }
-
- /**
- * Return all WYSIWYG settings.
- *
- * Returns an object with properties named after settings groups,
- * containing the respective group's settings. For example:
- *
- * {
- * "global": {...}
- * "seminars": {...},
- * "users": {...},
- * }
- *
- * @return object All settings.
- */
- private function getAllSettings()
- {
- $settings = new stdClass;
- $settings->global = $this->getGlobalSettings();
- $settings->users = $this->getUserSettings();
- return $settings;
- }
-
- /**
- * Return global WYSIWYG settings.
- *
- * @return object Global settings.
- */
- private function getGlobalSettings($arguments = [])
- {
- $subgroup = array_shift($arguments);
- if (($subgroup !== null && $subgroup !== '') || count($arguments) > 0) {
- throw new WysiwygHttpExceptionNotFound(_('Die globalen Einstellungen enthalten keine Untergruppen.'));
- }
- $settings = new stdClass;
- $settings->disabled = !\Config::get()->WYSIWYG;
- $settings->upload = new stdClass;
- $settings->upload->permission = self::UPLOAD_PERMISSION;
- $settings->upload->folder = new stdClass;
- $settings->upload->folder->name = self::FOLDER_NAME;
- $settings->upload->folder->description = self::FOLDER_DESCRIPTION;
- return $settings;
- }
-
- /**
- * Return current user's WYSIWYG settings.
- *
- * @return object User's settings.
- */
- private function getUserSettings($arguments = [])
- {
- // NOTE simulate a list of users containing only the current
- // user until this is implemented correctly
- $settings = new stdClass;
- $settings->current = $this->getCurrentUserSettings();
-
- $userId = array_shift($arguments);
- if ($userId === null || $userId === '' && count($arguments) === 0) {
- return $settings;
- }
-
- if ($userId === 'current') {
- $subgroup = array_shift($arguments);
- if (($subgroup !== null && $subgroup !== '') || count($arguments) > 0) {
- throw new WysiwygHttpExceptionNotFound(
- _('Die Benutzereinstellungen enthalten keine Untergruppen.')
- );
- }
- return $settings->current;
- }
-
- throw new WysiwygHttpExceptionForbidden(
- _('Zugriff verweigert.')
- );
- }
-
- /**
- * Return current user's WYSIWYG settings.
- *
- * @return object User's settings.
- */
- public function getCurrentUserSettings()
- {
- $config = $GLOBALS['user']->cfg;
- $settings = new stdClass;
- $settings->disabled = (boolean)$config->WYSIWYG_DISABLED;
- return $settings;
- }
-
- /**
- * Recursively convert objects to associative arrays.
- *
- * Workaround for broken StudipController::render_json.
- *
- * If the data is neither object nor array then it will be
- * returned unchanged.
- *
- * @param mixed $data Data to convert.
- *
- * @return mixed Converted data.
- */
- private function objectToArray($data)
- {
- if (gettype($data) === 'object') {
- $data = (array)$data;
- }
- if (gettype($data) === 'array') {
- foreach ($data as $key => $value) {
- $data[$key] = $this->objectToArray($value);
- }
- }
- return $data;
- }
}