]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/libomb/helper.php
Merge branch '0.8.x' into 0.9.x
[quix0rs-gnu-social.git] / extlib / libomb / helper.php
1 <?php
2
3 require_once 'Validate.php';
4
5 /**
6  * Helper functions for libomb
7  *
8  * This file contains helper functions for libomb.
9  *
10  * PHP version 5
11  *
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.
16  *
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.
21  *
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/>.
24  *
25  * @package   OMB
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
29  **/
30
31 class OMB_Helper {
32
33   /**
34    * Non-scalar constants
35    *
36    * The set of OMB and OAuth Services an OMB Server has to implement.
37    */
38
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);
43
44   /**
45    * Validate URL
46    *
47    * Basic URL validation. Currently http, https, ftp and gopher are supported
48    * schemes.
49    *
50    * @param string $url The URL which is to be validated.
51    *
52    * @return bool Whether URL is valid.
53    *
54    * @access public
55    */
56   public static function validateURL($url) {
57     return Validate::uri($url, array('allowed_schemes' => array('http', 'https',
58             'gopher', 'ftp')));
59   }
60
61   /**
62    * Validate Media type
63    *
64    * Basic Media type validation. Checks for valid maintype and correct format.
65    *
66    * @param string $mediatype The Media type which is to be validated.
67    *
68    * @return bool Whether media type is valid.
69    *
70    * @access public
71    */
72   public static function validateMediaType($mediatype) {
73     if (0 === preg_match('/^(\w+)\/([\w\d-+.]+)$/', $mediatype, $subtypes)) {
74       return false;
75     }
76     if (!in_array(strtolower($subtypes[1]), array('application', 'audio', 'image',
77               'message', 'model', 'multipart', 'text', 'video'))) {
78       return false;
79     }
80     return true;
81   }
82
83   /**
84    * Remove escaping from request parameters
85    *
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.
89    *
90    * @access public
91    */
92   public static function removeMagicQuotesFromRequest() {
93     if(get_magic_quotes_gpc() == 1) {
94       $_POST = array_map('stripslashes', $_POST);
95       $_GET = array_map('stripslashes', $_GET);
96     }
97   }
98 }
99 ?>