public static function set($parameters) { OC_Util::checkLoggedIn(); $user = OC_User::getUser(); $app = addslashes(strip_tags($parameters['app'])); $key = addslashes(strip_tags($parameters['key'])); $value = OC_OCS::readData('post', 'value', 'text'); if (OC_Preferences::setValue($user, $app, $key, $value)) { return new OC_OCS_Result(null, 100); } }
/** * set a key * test: curl http://login:passwd@oc/core/ocs/v1.php/privatedata/setattribute/testy/123 --data "value=foobar" * @param array $parameters The OCS parameter * @return \OC_OCS_Result */ public static function set($parameters) { $user = OC_User::getUser(); $app = addslashes(strip_tags($parameters['app'])); $key = addslashes(strip_tags($parameters['key'])); $value = OC_OCS::readData('post', 'value', 'text'); // update in DB $query = \OCP\DB::prepare('UPDATE `*PREFIX*privatedata` SET `value` = ? WHERE `user` = ? AND `app` = ? AND `key` = ?'); $numRows = $query->execute(array($value, $user, $app, $key)); if ($numRows === false || $numRows === 0) { // store in DB $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*privatedata` (`user`, `app`, `key`, `value`)' . ' VALUES(?, ?, ?, ?)'); $query->execute(array($user, $app, $key, $value)); } return new OC_OCS_Result(null, 100); }
* ownCloud * * @author Frank Karlitschek * @copyright 2012 Frank Karlitschek frank@owncloud.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ require_once '../lib/base.php'; use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; try { OC::getRouter()->match('/ocs' . OC_Request::getRawPathInfo()); } catch (ResourceNotFoundException $e) { OC_API::setContentType(); OC_OCS::notFound(); } catch (MethodNotAllowedException $e) { OC_API::setContentType(); OC_Response::setStatus(405); }
<?php /** * ownCloud * * @author Frank Karlitschek * @copyright 2010 Frank Karlitschek karlitschek@kde.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ require_once '../lib/base.php'; ob_clean(); OC_OCS::handle();
/** * get the private key of a user * @param string $format * @param string $user * @return string xml/json */ private static function privateKeyGet($format, $user) { $login = OC_OCS::checkpassword(); if (OC_Group::inGroup($login, 'admin') or $login == $user) { if (OC_User::userExists($user)) { // calculate the disc space $txt = 'this is the private key of ' . $user; echo $txt; } else { echo self::generateXml('', 'fail', 300, 'User does not exist'); } } else { echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.'); } }
/** * delete private data referenced by $key and generate the xml for ocs * @param string $format * @param string $app * @param string $key * @return string xml/json */ private static function privateDataDelete($format, $app, $key) { if ($key == "" or $app == "") { return; //key and app are NOT optional here } $user = OC_OCS::checkpassword(); if (OC_OCS::deleteData($user, $app, $key)) { echo OC_OCS::generatexml($format, 'ok', 100, ''); } }
/** * @param resource $writer * @param array $data * @param string $node */ public static function toXml($writer, $data, $node) { foreach ($data as $key => $value) { if (is_numeric($key)) { $key = $node; } if (is_array($value)) { xmlwriter_start_element($writer, $key); OC_OCS::toxml($writer, $value, $node); xmlwriter_end_element($writer); } else { xmlwriter_write_element($writer, $key, $value); } } }
public static function notFound() { $format = OC_API::requestedFormat(); $txt = 'Invalid query, please check the syntax. API specifications are here:' . ' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:' . "\n"; $txt .= OC_OCS::getDebugOutput(); OC_API::respond(new OC_OCS_Result(null, API::RESPOND_UNKNOWN_ERROR, $txt), $format); }