common.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. require_once('RainTPL.php');
  38. require_once('i18n.php');
  39. class_exists('Plugin') or require_once('Plugin.class.php');
  40. class_exists('MysqlEntity') or require_once('MysqlEntity.class.php');
  41. class_exists('Update') or require_once('Update.class.php');
  42. $resultUpdate = Update::ExecutePatch();
  43. class_exists('Feed') or require_once('Feed.class.php');
  44. class_exists('Event') or require_once('Event.class.php');
  45. class_exists('Functions') or require_once('Functions.class.php');
  46. class_exists('User') or require_once('User.class.php');
  47. class_exists('Folder') or require_once('Folder.class.php');
  48. class_exists('Configuration') or require_once('Configuration.class.php');
  49. class_exists('Opml') or require_once('Opml.class.php');
  50. class_exists('Logger') or require_once('Logger.class.php');
  51. //error_reporting(E_ALL);
  52. //Calage de la date
  53. date_default_timezone_set('Europe/Paris');
  54. $userManager = new User();
  55. $myUser = (isset($_SESSION['currentUser'])?unserialize($_SESSION['currentUser']):false);
  56. if (empty($myUser)) {
  57. /* Pas d'utilisateur dans la session ?
  58. * On tente de récupérer une nouvelle session avec un jeton. */
  59. $myUser = User::existAuthToken();
  60. $_SESSION['currentUser'] = serialize($myUser);
  61. }
  62. $feedManager = new Feed();
  63. $eventManager = new Event();
  64. $folderManager = new Folder();
  65. $configurationManager = new Configuration();
  66. $conf = $configurationManager->getAll();
  67. $language = $configurationManager->get('language');
  68. //@todo requis pour la MAJ mais pourra être supprimé.
  69. if (empty($language)) {
  70. // On tente de récupérer la valeur issue de 'constant.php'
  71. if (defined('LANGUAGE')) $language = LANGUAGE;
  72. elseif (defined('LANGAGE')) $language = LANGAGE; // ancien bug de nommage
  73. else $language = Translation::DEFAULT_LANGUAGE;
  74. $configurationManager->put('language', $language);
  75. }
  76. // Faut-il supprimer la variable /langu?age/ de 'constant.php'?
  77. $theme = $configurationManager->get('theme');
  78. //Instanciation du template
  79. $tpl = new RainTPL();
  80. //Definition des dossiers de template
  81. raintpl::configure("base_url", null );
  82. raintpl::configure("tpl_dir", './templates/'.$theme.'/' );
  83. raintpl::configure("cache_dir", "./cache/tmp/" );
  84. i18n_init($language, dirname(__FILE__).'/templates/'.$theme.'/');
  85. if ($resultUpdate) die (_t('LEED_UPDATE_MESSAGE'));
  86. $view = '';
  87. $tpl->assign('myUser',$myUser);
  88. $tpl->assign('feedManager',$feedManager);
  89. $tpl->assign('eventManager',$eventManager);
  90. $tpl->assign('userManager',$userManager);
  91. $tpl->assign('folderManager',$folderManager);
  92. $tpl->assign('configurationManager',$configurationManager);
  93. $tpl->assign('synchronisationCode',$configurationManager->get('synchronisationCode'));
  94. //Récuperation et sécurisation de toutes les variables POST et GET
  95. $_ = array();
  96. foreach($_POST as $key=>$val){
  97. $_[$key]=Functions::secure($val, 2); // on ne veut pas d'addslashes
  98. }
  99. foreach($_GET as $key=>$val){
  100. $_[$key]=Functions::secure($val, 2); // on ne veut pas d'addslashes
  101. }
  102. $tpl->assign('_',$_);
  103. $tpl->assign('action','');
  104. //Inclusion des plugins
  105. Plugin::includeAll();
  106. // pour inclure aussi les traductions des plugins dans les js
  107. $tpl->assign('i18n_js',$i18n_js);
  108. ?>