Guest User

Untitled

a guest
Jan 26th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. <?php
  2.  
  3. if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
  4. if (strpos(@$_SERVER['REMOTE_ADDR'], '10.2.0.') !== 0) {
  5. die('You are not allowed to access this file. Check ' . basename(__FILE__) . ' for more information.');
  6. }
  7. }
  8.  
  9. ini_set('max_execution_time', 600);
  10. set_time_limit(600);
  11. ini_set('memory_limit', "512M");
  12.  
  13. require_once(dirname(__FILE__) . '/../config/ProjectConfiguration.class.php');
  14.  
  15. $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
  16.  
  17. require '../apps/frontend/lib/stringProcessor.class.php';
  18. require '../apps/frontend/lib/menuSystem.class.php';
  19.  
  20. define('DATABASE_CONF_FILE', __DIR__ . '/../config/databases.yml');
  21. define('CACHE_DIR', __DIR__ . '/../cache/menu');
  22.  
  23. if (!file_exists(CACHE_DIR)) {
  24. mkdir(CACHE_DIR);
  25. }
  26.  
  27. class DBConnector {
  28.  
  29. protected static $commentMarker = '#',
  30. $_dsn,
  31. $_user,
  32. $_pass,
  33. $_dbh;
  34.  
  35. public function __construct($filepath) {
  36. if (is_readable($filepath)) {
  37. $dsn_id = 'dsn: \'';
  38. $user_id = 'username: ';
  39. $pass_id = 'password: ';
  40. $handle = fopen($filepath, "r");
  41. while (!feof($handle)) {
  42. $line = fgets($handle);
  43. $comm = strpos($line, self::$commentMarker);
  44. if (is_numeric($comm)) {
  45. $line = substr($line, 0, $comm);
  46. }
  47. $dsn = strpos($line, $dsn_id);
  48. if (is_numeric($dsn)) {
  49. self::$_dsn = substr($line, $dsn + strlen($dsn_id), strrpos($line, '\'') - strlen($line));
  50. continue;
  51. }
  52. $user = strpos($line, $user_id);
  53. if (is_numeric($user)) {
  54. self::$_user = substr($line, $user + strlen($user_id), strrpos($line, "\n") - strlen($line));
  55. continue;
  56. }
  57. $pass = strpos($line, $pass_id);
  58. if (is_numeric($pass)) {
  59. self::$_pass = substr($line, $pass + strlen($pass_id), strrpos($line, "\n") - strlen($line));
  60. continue;
  61. }
  62. }
  63. fclose($handle);
  64. try {
  65. self::$_dbh = new PDO(self::$_dsn, self::$_user, self::$_pass);
  66. } catch (Exception $e) {
  67. print "Erreur !: " . $e->getMessage() . "<br/>";
  68. die(TRUE);
  69. }
  70. }
  71. }
  72.  
  73. public function getPDO() {
  74. return self::$_dbh;
  75. }
  76.  
  77. }
  78.  
  79. class rawDataGatherer {
  80.  
  81. protected static $_dbh;
  82.  
  83. public static function init(PDO $dbh) {
  84. self::$_dbh = $dbh;
  85. }
  86.  
  87. private function __clone() {
  88. ;
  89. }
  90.  
  91. private function __construct() {
  92. ;
  93. }
  94.  
  95. public static function raw_dataGatherer_rayon($table, $rayon = '*') {
  96. if ($rayon != '*') {
  97. print_r($table);
  98. $rayons = self::$_dbh->prepare("SELECT DISTINCT rayon, rayon2 FROM `$table` WHERE rayon = ?");
  99. $rayons->execute(array($rayon));
  100. } else {
  101. $rayons = self::$_dbh->prepare("SELECT DISTINCT rayon, rayon2 FROM `$table`");
  102. $rayons->execute();
  103. }
  104. $rayons = $rayons->fetchAll(PDO::FETCH_BOTH);
  105. return $rayons;
  106. }
  107.  
  108. public static function raw_dataGatherer_rayon2($table, $rayon) {
  109. $rayons = self::$_dbh->prepare("SELECT DISTINCT rayon2, rayon3 FROM `$table` WHERE rayon = ?");
  110. $rayons->execute(array($rayon));
  111. return $rayons->fetchAll(PDO::FETCH_BOTH);
  112. }
  113.  
  114. public static function raw_dataGatherer_rayon3($table, $rayon2) {
  115. $rayons = self::$_dbh->prepare("SELECT DISTINCT rayon, rayon2, rayon3 FROM `$table` WHERE rayon2 = ?");
  116. $rayons->execute(array($rayon2));
  117. return $rayons->fetchAll(PDO::FETCH_BOTH);
  118. }
  119.  
  120. }
  121.  
  122. $conf = new DBConnector(DATABASE_CONF_FILE);
  123. $conf = $conf->getPDO();
  124.  
  125. rawDataGatherer::init($conf);
  126.  
  127.  
  128. $files = glob(CACHE_DIR . '/*');
  129. foreach ($files as $k => $file) {
  130. if (((isset($_GET['rayon']) && strlen(trim($_GET['rayon'])) > 0) && strpos($file, $_GET['rayon']) !== FALSE) || isset($_GET['clearAll'])) {
  131. unlink($file);
  132. unset($files[$k]);
  133. }
  134. }
  135.  
  136.  
  137. $last = array_pop($files);
  138. $match = array();
  139. $last = substr($last, strripos($last, '/') + 1);
  140. preg_match('#^ __(?P<id>\d+)__(?P<rayon>.+).json$#i', $last, $match);
  141. $i = isset($match['id']) ? $match['id'] + 1 : 1;
  142.  
  143.  
  144. if (isset($_GET['rayon']) && strlen(trim($_GET['rayon'])) > 0) {
  145. $menu_entry = menuSystem::refresh(array('savoirmanger_products'), 'rawDataGatherer::raw', $_GET['rayon'], null);
  146. print_r($menu_entry);
  147. file_put_contents(CACHE_DIR . "/__{$i}__{$_GET['rayon']}.json", json_encode($menu_entry));
  148. }
  149. $files = glob(CACHE_DIR . '/*');
  150. foreach ($files as $k => $file) {
  151. echo $file . "<br />\n";
  152. }
Add Comment
Please, Sign In to add comment