Example #1
0
 public static function start($base_path = null)
 {
     if (self::$initialized) {
         return;
     }
     /* project root
      ********************/
     //define( 'PROJECT_DIR', dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR);
     define('PROJECT_DIR', $base_path);
     define('API_DIR', PROJECT_DIR . 'inc' . DIRECTORY_SEPARATOR);
     define('APP_DIR', PROJECT_DIR . 'app' . DIRECTORY_SEPARATOR);
     define('VENDOR_DIR', PROJECT_DIR . 'vendor');
     define('SF_EVENT_DIR', VENDOR_DIR . DIRECTORY_SEPARATOR . 'sfEvent' . DIRECTORY_SEPARATOR);
     define('LOCAL_API_DIR', PROJECT_DIR . 'localinc' . DIRECTORY_SEPARATOR);
     $root = dirname(dirname(__FILE__));
     set_include_path(API_DIR . PATH_SEPARATOR . APP_DIR . PATH_SEPARATOR . VENDOR_DIR . PATH_SEPARATOR . SF_EVENT_DIR . PATH_SEPARATOR . LOCAL_API_DIR . PATH_SEPARATOR . get_include_path());
     include 'autoload.php';
     // Start sessions
     $sessions = api_session::getInstance();
     // Construct URL for Web home (root of current host)
     $hostname = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
     $hostinfo = self::getHostConfig($hostname);
     $schema = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
     $reqHostPath = '/';
     if ($hostname != '') {
         $reqHostPath = $schema . '://' . $hostname;
         if (is_null($hostinfo)) {
             $reqHostPath .= '/';
         } else {
             $reqHostPath .= $hostinfo['path'];
         }
     }
     define('API_HOST', $schema . '://' . $hostname . '/');
     define('API_WEBROOT', $reqHostPath);
     define('API_MOUNTPATH', $hostinfo['path']);
     require_once PROJECT_DIR . "config/commandmap.php";
     if (!function_exists('e')) {
         /**
          * This function is dynamically redefinable.
          * @see $GLOBALS['_global_function_callback_e']
          */
         function e($args)
         {
             $args = func_get_args();
             return call_user_func_array($GLOBALS['_global_function_callback_e'], $args);
         }
         if (!isset($GLOBALS['_global_function_callback_e'])) {
             $GLOBALS['_global_function_callback_e'] = NULL;
         }
     }
     if (!function_exists('__')) {
         /**
          * This function is dynamically redefinable.
          * @see $GLOBALS['_global_function_callback___']
          */
         function __($args)
         {
             $args = func_get_args();
             return call_user_func_array($GLOBALS['_global_function_callback___'], $args);
         }
         if (!isset($GLOBALS['_global_function_callback___'])) {
             $GLOBALS['_global_function_callback___'] = NULL;
         }
     }
     if (!function_exists('t')) {
         /**
          * This function is dynamically redefinable.
          * @see $GLOBALS['_global_function_callback_t']
          */
         function t($args)
         {
             $args = func_get_args();
             return call_user_func_array($GLOBALS['_global_function_callback_t'], $args);
         }
         if (!isset($GLOBALS['_global_function_callback_t'])) {
             $GLOBALS['_global_function_callback_t'] = NULL;
         }
     }
     if (!function_exists('url')) {
         /**
          * This function is dynamically redefinable.
          * @see $GLOBALS['_global_function_callback_url']
          */
         function url($args)
         {
             $args = func_get_args();
             return call_user_func_array($GLOBALS['_global_function_callback_url'], $args);
         }
         if (!isset($GLOBALS['_global_function_callback_url'])) {
             $GLOBALS['_global_function_callback_url'] = NULL;
         }
     }
     self::$initialized = true;
 }
Example #2
0
<?php

require_once dirname(__FILE__) . '/inc/api/init.php';
api_init::start();
require_once API_LIBS_DIR . 'controller.php';
$ctrl = new api_controller();
$ctrl->process();
Example #3
0
 /**
  * Constructor. Parses the request and fills in all the
  * values it can.
  */
 protected function __construct()
 {
     $this->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
     $config = api_config::getInstance();
     $this->outputLangs = $config->lang['languages'];
     $this->defaultLang = $config->lang['default'];
     if (is_null($this->outputLangs)) {
         $this->outputLangs = array('en');
     }
     if (is_null($this->defaultLang)) {
         $this->defaultLang = 'en';
     }
     // Parse host, get SLD / TLDww.tv.nu/
     $hostinfo = api_init::getHostConfig($this->host);
     if ($hostinfo) {
         $this->sld = $hostinfo['sld'];
         $this->tld = $hostinfo['tld'];
     }
     $path = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
     //$path = isset($_REQUEST['p']) ? $_GET['p'] : '';
     if (strpos($path, '.php') !== FALSE) {
         $path = substr($path, 0, strpos($path, '.php'));
     }
     if (strpos($path, '?') !== FALSE) {
         $path = substr($path, 0, strpos($path, '?'));
     }
     // Get language from the beginning of the URL
     $lang = $this->getLanguageFromPath($path);
     if ($lang !== null) {
         $this->lang = $lang['lang'];
         $path = $lang['path'];
     }
     // Strip out path prefix from path
     if (isset($hostinfo['path'])) {
         if (strpos($path, $hostinfo['path']) === 0) {
             $path = substr($path, strlen($hostinfo['path']));
         }
         if (substr($path, 0, 1) !== '/') {
             $path = '/' . $path;
         }
     }
     // HTTP verb - assume GET as default
     $this->verb = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET';
     $this->params = new api_params();
     $this->params->setGet($_GET);
     if ($this->verb == 'POST') {
         $this->params->setPost($_POST);
     }
     if ($this->lang === '') {
         $lang = $this->parseLanguage($path);
         $this->lang = $lang['lang'];
         $path = $lang['path'];
     }
     $this->url = API_HOST . $this->lang . API_MOUNTPATH . substr($path, 1);
     $this->path = api_helpers_string::removeDoubleSlashes($path);
     // Path
     $this->filename = $this->parseFilename($this->path);
     $matches = array();
     if ($this->filename != '') {
         /* if you set an extension: [xml, foo, rss, html] node in your
          * config file, only these extensions are valid extensions.
          * the rest is not parsed as an extension */
         preg_match("#\\.([a-z]+)\$#", $this->filename, $matches);
         $aExtensions = api_config::getInstance()->extensions;
         if (isset($matches[1]) && !empty($matches[1])) {
             if (isset($aExtensions) && is_array($aExtensions)) {
                 if (in_array($matches[1], $aExtensions)) {
                     $this->extension = $matches[1];
                 }
             } else {
                 $this->extension = $matches[1];
             }
         }
     }
 }