Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.78 KB | None | 0 0
  1. <?php
  2. /**
  3.  * i-doit
  4.  *
  5.  * Index / Front Controller
  6.  *
  7.  * @package     i-doit
  8.  * @subpackage  General
  9.  * @version     1.0.1
  10.  * @copyright   synetics GmbH
  11.  * @license     http://www.gnu.org/licenses/agpl-3.0.html GNU AGPLv3
  12.  *
  13.  * - http://i-doit.org
  14.  * - http://i-doit.org/forum
  15.  */
  16.  
  17. /**
  18.  * index.php/Front controller - program sequence:
  19.  * ---------------------------------------------------------------------------
  20.  * 1. Determine current directory (for absolute path references)
  21.  * 2. Load Configuration
  22.  * (3. Check directories (we have to make this UNIX-compatible at first))
  23.  * 4. Load globals and surrounding function libraries
  24.  * 5. If external request is wanted, do it.
  25.  * 6. If i-doit internal request, forward to hypergate.inc.php
  26.  * ---------------------------------------------------------------------------
  27.  */
  28. // Set the current start time for detecting the php processing time.
  29. $g_start_time = microtime(true);
  30.  
  31. // Determine our directory.
  32. $g_absdir = dirname(__FILE__);
  33.  
  34. /**
  35.  * @return mixed
  36.  */
  37. function gettime()
  38. {
  39.     global $g_start_time;
  40.  
  41.     return (microtime(true) - $g_start_time);
  42. } // function
  43.  
  44. // Set error reporting.
  45. $l_errorReporting = E_ALL & ~E_NOTICE;
  46. if (defined('E_DEPRECATED')) $l_errorReporting &= ~E_DEPRECATED;
  47. if (defined('E_STRICT')) $l_errorReporting &= ~E_STRICT;
  48. error_reporting($l_errorReporting);
  49.  
  50. /* Set default charset to utf-8 */
  51. ini_set('default_charset', 'utf-8');
  52.  
  53. // Set maximal execution time.
  54. if (ini_get("max_execution_time") < 600)
  55. {
  56.     set_time_limit(600);
  57. } // if
  58.  
  59. /**
  60.  * Dies with a preformatted monospace message.
  61.  *
  62.  * @param string $p_message
  63.  */
  64. function startup_die($p_message)
  65. {
  66.     echo "<pre>" . $p_message . "</pre>\n";
  67.     die();
  68. } // function
  69.  
  70. if ((int) ini_get("memory_limit") < 128)
  71. {
  72.     ini_set("memory_limit", "128M");
  73. } // if
  74.  
  75. if ((int) ini_get("upload_max_filesize") < 8)
  76. {
  77.     ini_set("upload_max_filesize", "8M");
  78. } // if
  79.  
  80. // Check configuration parameters of php.ini
  81.  
  82. // Allow FOPEN Wrapper for URLs.
  83. ini_set("allow_url_fopen", "1");
  84.  
  85. try
  86. {
  87.     // Initialize framework.
  88.     if (file_exists("src/config.inc.php") && include_once("src/config.inc.php"))
  89.     {
  90.  
  91.         // Bootstrap.
  92.         if (!include_once "src/bootstrap.inc.php")
  93.         {
  94.             startup_die("Could not find bootstrap.inc.php");
  95.         } // if
  96.  
  97.         // Include caching implementation.
  98.         if (!include_once "src/caching.inc.php")
  99.         {
  100.             startup_die("Could not find caching.inc.php");
  101.         } // if
  102.  
  103.         global $g_dirs;
  104.  
  105.         // Temp cleanup.
  106.         if (isset($_GET["IDOIT_DELETE_TEMPLATES_C"]))
  107.         {
  108.             $g_clear_temp = true;
  109.             $l_directory  = $g_dirs["smarty"] . "templates_c/";
  110.         }
  111.  
  112.         if (isset($_GET["IDOIT_DELETE_TEMP"]))
  113.         {
  114.             $g_clear_temp = true;
  115.             $l_directory  = $g_dirs["temp"];
  116.         }
  117.         else
  118.         {
  119.             if (isset($_POST["IDOIT_DELETE_TEMP"]))
  120.             {
  121.                 isys_glob_delete_recursive($g_dirs["temp"], $l_deleted, $l_undeleted);
  122.             }
  123.         } // if
  124.  
  125.         if ($g_clear_temp && isset($l_directory))
  126.         {
  127.             echo "Deleting temporary files ...<br>\n";
  128.  
  129.             $l_deleted   = 0;
  130.             $l_undeleted = 0;
  131.             isys_glob_delete_recursive($l_directory, $l_deleted, $l_undeleted);
  132.             echo "Success: $l_deleted files - Failure: $l_undeleted files!<br />\n";
  133.  
  134.             unset($l_directory);
  135.  
  136.             if (isset($_GET["ajax"]))
  137.             {
  138.                 die();
  139.             } // if
  140.         } // if
  141.     }
  142.     else
  143.     {
  144.         if (!require_once "setup/install.inc.php")
  145.         {
  146.             startup_die("Could not start installer. Setup files not found.");
  147.         } // if
  148.     } // if
  149. }
  150. catch (Exception $e)
  151. {
  152.     if (isset($_SERVER))
  153.     {
  154.         isys_glob_display_error(
  155.             stripslashes(nl2br($e->getMessage()))
  156.         );
  157.     }
  158.     else
  159.     {
  160.         printf($e->getMessage());
  161.     }
  162.     die();
  163.  
  164. } // try
  165.  
  166. try
  167. {
  168.     // Process ajax requests.
  169.     if (isset($_GET["ajax"]))
  170.     {
  171.         if (isys_application::instance()->session->is_logged_in())
  172.         {
  173.             require_once("src/ajax.inc.php");
  174.         }
  175.     } // if
  176. }
  177. catch (Exception $e)
  178. {
  179.     if (isset($g_error) && $g_error)
  180.     {
  181.         isys_notify::error($g_error);
  182.     }
  183.     isys_notify::error($e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ')');
  184.     die;
  185. }
  186.  
  187. try
  188. {
  189.  
  190.     // Process api requests.
  191.     if (isset($_GET['api']))
  192.     {
  193.         try
  194.         {
  195.             switch ($_GET['api'])
  196.             {
  197.                 case 'jsonrpc':
  198.                     include_once('src/jsonrpc.php');
  199.                     break;
  200.             } // switch
  201.         }
  202.         catch (Exception $e)
  203.         {
  204.             echo $e->getMessage();
  205.         } // try
  206.  
  207.         die;
  208.     } // if
  209.  
  210.     // Main request handler.
  211.     switch ($_GET["load"])
  212.     {
  213.         /*
  214.         case "test":
  215.             if (isset($_GET['type']))
  216.             {
  217.                 $_GET['type'] = str_replace(chr(0), '', addslashes($_GET['type']));
  218.  
  219.                 if (file_exists("src/tests/i-doit/" . strtolower($_GET['type']) . ".php"))
  220.                 {
  221.                     global $g_comp_session;
  222.                     $g_comp_session->include_mandator_cache();
  223.                     include_once("src/tests/i-doit/" . strtolower($_GET['type']) . ".php");
  224.                 }
  225.             }
  226.             break;
  227.         */
  228.         case "api_properties":
  229.             include_once("src/tools/php/properties.inc.php");
  230.             break;
  231.  
  232.         case "property_infos":
  233.             include_once("src/tools/php/property_infos.inc.php");
  234.             break;
  235.  
  236.         case "css":
  237.             include_once("src/tools/css/css.php");
  238.             break;
  239.         case "mod-css":
  240.             include_once("src/tools/css/mod-css.php");
  241.             break;
  242.  
  243.         case "update":
  244.         default:
  245.             // The hypergate is the i-doit-internal entrypoint, in which all i-doit internal requests are running.
  246.             include_once "src/hypergate.inc.php";
  247.             break;
  248.     } // switch
  249.  
  250.     // Get PHP processing time.
  251.     if (isset($g_config["show_proc_time"]))
  252.     {
  253.         if ($g_config["show_proc_time"] == true)
  254.         {
  255.             echo "\n<!-- i-doit processing time: " . gettime() . " -->";
  256.         } // if
  257.     } // if
  258. }
  259. catch (SmartyException $e)
  260. {
  261.     try
  262.     {
  263.         \idoit\View\ExceptionView::factory()
  264.             ->setDi(isys_application::instance()->container)
  265.             ->draw($e);
  266.     }
  267.     catch (Exception $e)
  268.     {
  269.         isys_glob_display_error($e->getMessage());
  270.         die();
  271.     }
  272. }
  273. catch (Exception $e)
  274. {
  275.     isys_glob_display_error($e->getMessage());
  276.     die();
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement