common.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /*
  3. @nom: common
  4. @auteur: Idleman (idleman@idleman.fr)
  5. @description: Page incluse dans tous (ou presque) les fichiers du projet, inclus les entitées SQL et récupère/traite les variables de requetes
  6. */
  7. define('VERSION_NUMBER_CODE','1.6.1');
  8. define('VERSION_NAME_CODE','dev');
  9. /* ----------MAJ de la version du constant.php--------------------- */
  10. if (is_writable('constant.php')) {
  11. $content = file_get_contents('constant.php');
  12. preg_match('#define\(\'VERSION_NUMBER\',\'([A-Za-z0-9.]+)\'\);?#',$content,$matches_version);
  13. preg_match('#define\(\'VERSION_NAME\',\'([A-Za-z0-9.]+)\'\);?#',$content,$matches_name);
  14. if ($matches_version[1]!=VERSION_NUMBER_CODE or $matches_name[1]!=VERSION_NAME_CODE)
  15. {
  16. $content = preg_replace('#define\(\'VERSION_NUMBER\',\'([A-Za-z0-9.]+)\'\);?#','define(\'VERSION_NUMBER\',\''.VERSION_NUMBER_CODE.'\');', $content);
  17. $content = preg_replace('#define\(\'VERSION_NAME\',\'([A-Za-z0-9.]+)\'\);?#','define(\'VERSION_NAME\',\''.VERSION_NAME_CODE.'\');', $content);
  18. file_put_contents('constant.php', $content);
  19. }
  20. };
  21. /* ---------------------------------------------------------------- */
  22. // Mise en place d'un timezone par default pour utiliser les fonction de date en php
  23. $timezone_default = 'Europe/Paris'; // valeur par défaut :)
  24. date_default_timezone_set($timezone_default);
  25. $timezone_phpini = ini_get('date.timezone');
  26. if (($timezone_phpini!='') && (strcmp($timezone_default, $timezone_phpini))) {
  27. date_default_timezone_set($timezone_phpini);
  28. }
  29. /* ---------------------------------------------------------------- */
  30. $cookiedir = '';
  31. if(dirname($_SERVER['SCRIPT_NAME'])!='/') $cookiedir=dirname($_SERVER["SCRIPT_NAME"]).'/';
  32. session_set_cookie_params(0, $cookiedir);
  33. session_start();
  34. mb_internal_encoding('UTF-8'); // UTF8 pour fonctions mb_*
  35. $start=microtime(true);
  36. require_once('constant.php');
  37. //@todo requis pour la MAJ 1.5 vers 1.6 mais pourra être supprimé.
  38. if (!defined('LANGUAGE')) {
  39. preg_match('#define\(\'LANGAGE\',\'([A-Za-z0-9.]+)\'\);?#',$content,$matches_language);
  40. if (isset($matches_language[1]) && isset($matches_language[1])!='') {
  41. // pour ceux qui viennent de la branche de dev avant update en LANGUAGE.
  42. $content = preg_replace('#define\(\'LANGAGE\',\'([A-Za-z0-9.]+)\'\);?#','define(\'LANGUAGE\',\''.$matches_language[1].'\');', $content);
  43. file_put_contents('constant.php', $content);
  44. define('LANGUAGE', $matches_language[1]); // ancienne constante encore utilisée
  45. } else {
  46. // pour ceux qui viennent de la v1.5. la variable n'existait pas
  47. $content = preg_replace('#\?\>#',"//Langue utilisée\ndefine('LANGUAGE','fr');\n?>", $content);
  48. file_put_contents('constant.php', $content);
  49. define('LANGUAGE', 'fr');
  50. }
  51. }
  52. // fin MAJ 1.5 vers 1.6
  53. require_once('RainTPL.php');
  54. require_once('i18n.php');
  55. class_exists('Plugin') or require_once('Plugin.class.php');
  56. class_exists('MysqlEntity') or require_once('MysqlEntity.class.php');
  57. class_exists('Update') or require_once('Update.class.php');
  58. $resultUpdate = Update::ExecutePatch();
  59. class_exists('Feed') or require_once('Feed.class.php');
  60. class_exists('Event') or require_once('Event.class.php');
  61. class_exists('Functions') or require_once('Functions.class.php');
  62. class_exists('User') or require_once('User.class.php');
  63. class_exists('Folder') or require_once('Folder.class.php');
  64. class_exists('Configuration') or require_once('Configuration.class.php');
  65. class_exists('Opml') or require_once('Opml.class.php');
  66. //error_reporting(E_ALL);
  67. //Calage de la date
  68. date_default_timezone_set('Europe/Paris');
  69. $userManager = new User();
  70. $myUser = (isset($_SESSION['currentUser'])?unserialize($_SESSION['currentUser']):false);
  71. if (empty($myUser)) {
  72. /* Pas d'utilisateur dans la session ?
  73. * On tente de récupérer une nouvelle session avec un jeton. */
  74. $myUser = User::existAuthToken();
  75. $_SESSION['currentUser'] = serialize($myUser);
  76. }
  77. $feedManager = new Feed();
  78. $eventManager = new Event();
  79. $folderManager = new Folder();
  80. $configurationManager = new Configuration();
  81. $conf = $configurationManager->getAll();
  82. $theme = $configurationManager->get('theme');
  83. if (empty($theme)) {
  84. $configurationManager->put('theme', 'marigolds');
  85. $theme = $configurationManager->get('theme');
  86. }
  87. //Instanciation du template
  88. $tpl = new RainTPL();
  89. //Definition des dossiers de template
  90. raintpl::configure("base_url", null );
  91. raintpl::configure("tpl_dir", './templates/'.$theme.'/' );
  92. raintpl::configure("cache_dir", "./cache/tmp/" );
  93. i18n_init(LANGUAGE);
  94. if ($resultUpdate) die (_t('LEED_UPDATE_MESSAGE'));
  95. $view = '';
  96. $tpl->assign('myUser',$myUser);
  97. $tpl->assign('feedManager',$feedManager);
  98. $tpl->assign('eventManager',$eventManager);
  99. $tpl->assign('userManager',$userManager);
  100. $tpl->assign('folderManager',$folderManager);
  101. $tpl->assign('configurationManager',$configurationManager);
  102. $tpl->assign('synchronisationCode',$configurationManager->get('synchronisationCode'));
  103. //Récuperation et sécurisation de toutes les variables POST et GET
  104. $_ = array();
  105. foreach($_POST as $key=>$val){
  106. $_[$key]=Functions::secure($val, 2); // on ne veut pas d'addslashes
  107. }
  108. foreach($_GET as $key=>$val){
  109. $_[$key]=Functions::secure($val, 2); // on ne veut pas d'addslashes
  110. }
  111. $tpl->assign('_',$_);
  112. $tpl->assign('action','');
  113. //Inclusion des plugins
  114. Plugin::includeAll();
  115. // pour inclure aussi les traductions des plugins dans les js
  116. $tpl->assign('i18n_js',$i18n_js);
  117. ?>