3 require_once 'Validate.php';
6 * Helper functions for libomb
8 * This file contains helper functions for libomb.
12 * LICENSE: This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Affero General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
22 * You should have received a copy of the GNU Affero General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 * @author Adrian Lang <mail@adrianlang.de>
27 * @copyright 2009 Adrian Lang
28 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
34 * Non-scalar constants
36 * The set of OMB and OAuth Services an OMB Server has to implement.
39 public static $OMB_SERVICES =
40 array(OMB_ENDPOINT_UPDATEPROFILE, OMB_ENDPOINT_POSTNOTICE);
41 public static $OAUTH_SERVICES =
42 array(OAUTH_ENDPOINT_REQUEST, OAUTH_ENDPOINT_AUTHORIZE, OAUTH_ENDPOINT_ACCESS);
47 * Basic URL validation. Currently http, https, ftp and gopher are supported
50 * @param string $url The URL which is to be validated.
52 * @return bool Whether URL is valid.
56 public static function validateURL($url) {
57 return Validate::uri($url, array('allowed_schemes' => array('http', 'https',
64 * Basic Media type validation. Checks for valid maintype and correct format.
66 * @param string $mediatype The Media type which is to be validated.
68 * @return bool Whether media type is valid.
72 public static function validateMediaType($mediatype) {
73 if (0 === preg_match('/^(\w+)\/([\w\d-+.]+)$/', $mediatype, $subtypes)) {
76 if (!in_array(strtolower($subtypes[1]), array('application', 'audio', 'image',
77 'message', 'model', 'multipart', 'text', 'video'))) {
84 * Remove escaping from request parameters
86 * Neutralise the evil effects of magic_quotes_gpc in the current request.
87 * This is used before handing a request off to OAuthRequest::from_request.
88 * Many thanks to Ciaran Gultnieks for this fix.
92 public static function removeMagicQuotesFromRequest() {
93 if(get_magic_quotes_gpc() == 1) {
94 $_POST = array_map('stripslashes', $_POST);
95 $_GET = array_map('stripslashes', $_GET);