]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/libomb/helper.php
Merge branch 'master' of gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / extlib / libomb / helper.php
1 <?php
2 /**
3  * This file is part of libomb
4  *
5  * PHP version 5
6  *
7  * LICENSE: This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  * @package OMB
21  * @author  Adrian Lang <mail@adrianlang.de>
22  * @license http://www.gnu.org/licenses/agpl.html GNU AGPL 3.0
23  * @version 0.1a-20090828
24  * @link    http://adrianlang.de/libomb
25  */
26
27 require_once 'Validate.php';
28
29 /**
30  * Helper functions for libomb
31  *
32  * This class contains helper functions for libomb.
33  */
34 class OMB_Helper
35 {
36
37     /**
38      * Non-scalar constants
39      *
40      * The set of OMB and OAuth Services an OMB Server has to implement.
41      */
42
43     public static $OMB_SERVICES   = array(OMB_ENDPOINT_UPDATEPROFILE,
44                                           OMB_ENDPOINT_POSTNOTICE);
45     public static $OAUTH_SERVICES = array(OAUTH_ENDPOINT_REQUEST,
46                                           OAUTH_ENDPOINT_AUTHORIZE,
47                                           OAUTH_ENDPOINT_ACCESS);
48
49     /**
50      * Validate URL
51      *
52      * Basic URL validation. Currently http, https, ftp and gopher are supported
53      * schemes.
54      *
55      * @param string $url The URL which is to be validated.
56      *
57      * @return bool Whether URL is valid.
58      *
59      * @access public
60      */
61     public static function validateURL($url)
62     {
63         return Validate::uri($url, array('allowed_schemes' => array('http',
64                                                     'https', 'gopher', 'ftp')));
65     }
66
67     /**
68      * Validate Media type
69      *
70      * Basic Media type validation. Checks for valid maintype and correct
71      * format.
72      *
73      * @param string $mediatype The Media type which is to be validated.
74      *
75      * @return bool Whether media type is valid.
76      *
77      * @access public
78      */
79     public static function validateMediaType($mediatype)
80     {
81         return preg_match('/^(\w+)\/([\w\d-+.]+)$/', $mediatype, $subtypes) > 0
82                &&
83                in_array(strtolower($subtypes[1]), array('application', 'audio',
84                'image', 'message', 'model', 'multipart', 'text', 'video'));
85     }
86
87     /**
88      * Remove escaping from request parameters
89      *
90      * Neutralise the evil effects of magic_quotes_gpc in the current request.
91      * This is used before handing a request off to OAuthRequest::from_request.
92      * Many thanks to Ciaran Gultnieks for this fix.
93      *
94      * @access public
95      */
96     public static function removeMagicQuotesFromRequest()
97     {
98         if (get_magic_quotes_gpc() === 1) {
99             $_POST = array_map('stripslashes', $_POST);
100             $_GET  = array_map('stripslashes', $_GET);
101         }
102     }
103 }
104 ?>