1 <?php defined('SYSPATH') or die('No direct script access.');
3 * Helper class mainly for API controllers
5 * @author Artem Daniliants <artem@daniliants.com>
6 * @copyright (c) 2010 Speed Freak team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 * Get XML either from POST variable or FILES variable
17 * @return mixed Returns either SimpleXml object or outputs error along with HTTP 400 error
19 public static function get_xml(){
20 if (isset($_POST['xml'])){
21 $xml = simplexml_load_string($_POST['xml']);
23 elseif (isset($_FILES['xml'])){
24 $xml = simplexml_load_file($_FILES['xml']['tmp_name']);
27 header("HTTP/1.1 400 Bad Request");
28 echo "Please supply required parameters";
36 * Check if user is authorized
40 * @return boolean Returns TRUE if authorized and FALSE otherwise
42 public static function is_authorized(){
43 if (isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])){
44 $user = new User_Model();
45 if ($user->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
57 * Display "Unauthorized error"
61 * @return string Prints error text
63 public static function not_authorized(){
64 header('HTTP/1.0 401 Unauthorized');
65 print "Invalid credentials or not registered";
70 * Verify user's credentials
73 * @return string Outputs "OK" or error
75 public function login(){
76 if ($this->is_authorized()){
80 $this->not_authorized();