3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 // Some people forget to set their timezone in their php.ini,
22 // this prevents that from generating warnings
23 @date_default_timezone_set
(@date_default_timezone_get
());
25 include_once ('src/common/Config.php');
26 include_once ('src/common/File.php');
28 if (Config
::get('debug')) {
29 // Basic sanity check if we have all required modules
30 $modules = array('json', 'SimpleXML', 'libxml', 'curl', 'openssl');
31 // if plain text tokens are disallowed we require mcrypt
32 if (! Config
::get('allow_plaintext_token')) {
33 $modules[] = 'mcrypt';
35 // if you selected the memcache caching backend, you need the memcache extention too :)
36 if (Config
::get('data_cache') == 'CacheMemcache') {
37 $modules[] = 'memcache';
39 foreach ($modules as $module) {
40 if (! extension_loaded($module)) {
41 die("Shindig requires the {$module} extention, see <a href='http://www.php.net/{$module}'>http://www.php.net/{$module}</a> for more info");
46 // All configurable classes are autoloaded (see config.php for the configurable classes)
47 // To load these, we scan our entire directory structure
48 function __autoload($className) {
53 'src/gadgets/servlet',
59 'src/social/opensocial',
62 'src/social/converters',
66 $extension_class_paths = Config
::get('extension_class_paths');
67 if (! empty($extension_class_paths)) {
68 $locations = array_merge(explode(',', $extension_class_paths), $locations);
70 // Check for the presense of this class in our all our directories.
71 $fileName = $className . '.php';
72 foreach ($locations as $path) {
73 if (file_exists("{$path}/$fileName")) {
74 require $path.'/'.$fileName;
81 Config
::get('web_prefix') . '/gadgets/files' => 'FilesServlet',
82 Config
::get('web_prefix') . '/gadgets/js' => 'JsServlet',
83 Config
::get('web_prefix') . '/gadgets/proxy' => 'ProxyServlet',
84 Config
::get('web_prefix') . '/gadgets/makeRequest' => 'ProxyServlet',
85 Config
::get('web_prefix') . '/gadgets/ifr' => 'GadgetRenderingServlet',
86 Config
::get('web_prefix') . '/gadgets/metadata' => 'MetadataServlet',
87 Config
::get('web_prefix') . '/social/rest' => 'DataServiceServlet',
88 Config
::get('web_prefix') . '/social/rpc' => 'JsonRpcServlet',
89 Config
::get('web_prefix') . '/public.crt' => 'CertServlet',
90 Config
::get('web_prefix') . '/public.cer' => 'CertServlet'
93 // Try to match the request url to our servlet mapping
95 $uri = $_SERVER["REQUEST_URI"];
96 foreach ($servletMap as $url => $class) {
97 if (substr($uri, 0, strlen($url)) == $url) {
98 //FIXME temporary hack to support both /proxy and /makeRequest with the same event handler
99 // /makeRequest == /proxy?output=js
100 if ($url == Config
::get('web_prefix') . '/gadgets/makeRequest') {
101 $_GET['output'] = 'js';
108 // If we found a correlating servlet, instance and call it. Otherwise give a 404 error
110 $class = new $class();
111 $method = $_SERVER['REQUEST_METHOD'];
112 // Not all clients support the PUT, HEAD & DELETE http methods, they depend on the X-HTTP-Method-Override instead
113 if ($method == 'POST' && isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
114 $method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'];
116 $method = 'do' . ucfirst(strtolower($method));
117 if (is_callable(array($class, $method))) {
120 header("HTTP/1.0 405 Method Not Allowed");
121 echo "<html><body><h1>405 Method Not Allowed</h1></body></html>";
124 // Unhandled event, display simple 404 error
125 header("HTTP/1.0 404 Not Found");
126 echo "<html><body><h1>404 Not Found</h1></body></html>";