Skip to content
Snippets Groups Projects
Select Git revision
  • e4e0b5a82217be7a86d47db1b5fd0de545a6fbb2
  • master default protected
2 results

ocs.php

Blame
  • user avatar
    Bart Visscher authored
    52f2e711
    History
    ocs.php 20.75 KiB
    <?php
    
    /**
    * ownCloud
    *
    * @author Frank Karlitschek
    * @author Michael Gapczynski
    * @copyright 2012 Frank Karlitschek frank@owncloud.org
    * @copyright 2012 Michael Gapczynski mtgap@owncloud.com
    *
    * 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/>.
    *
    */
    
    
    
    /**
     * Class to handle open collaboration services API requests
     *
     */
    class OC_OCS {
    
    	/**
    	* reads input date from get/post/cookies and converts the date to a special data-type
    	*
    	* @param string HTTP method to read the key from
    	* @param string Parameter to read
    	* @param string Variable type to format data
    	* @param mixed Default value to return if the key is not found
    	* @return mixed Data or if the key is not found and no default is set it will exit with a 400 Bad request
    	*/
    	public static function readData($method, $key, $type = 'raw', $default = null) {
    		if ($method == 'get') {
    			if (isset($_GET[$key])) {
    				$data = $_GET[$key];
    			} else if (isset($default)) {
    				return $default;
    			} else {
    				$data = false;
    			}
    		} else if ($method == 'post') {
    			if (isset($_POST[$key])) {
    				$data = $_POST[$key];
    			} else if (isset($default)) {
    				return $default;
    			} else {
    				$data = false;
    			}
    		}
    		if ($data === false) {
    			echo self::generateXml('', 'fail', 400, 'Bad request. Please provide a valid '.$key);
    			exit();
    		} else {
    			// NOTE: Is the raw type necessary? It might be a little risky without sanitization
    			if ($type == 'raw') return $data;
    			elseif ($type == 'text') return OC_Util::sanitizeHTML($data);
    			elseif ($type == 'int')  return (int) $data;
    			elseif ($type == 'float') return (float) $data;
    			elseif ($type == 'array') return OC_Util::sanitizeHTML($data);