Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
- if (strpos(@$_SERVER['REMOTE_ADDR'], '10.2.0.') !== 0) {
- die('You are not allowed to access this file. Check ' . basename(__FILE__) . ' for more information.');
- }
- }
- ini_set('max_execution_time', 600);
- set_time_limit(600);
- ini_set('memory_limit', "512M");
- require_once(dirname(__FILE__) . '/../config/ProjectConfiguration.class.php');
- $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
- require '../apps/frontend/lib/stringProcessor.class.php';
- require '../apps/frontend/lib/menuSystem.class.php';
- define('DATABASE_CONF_FILE', __DIR__ . '/../config/databases.yml');
- define('CACHE_DIR', __DIR__ . '/../cache/menu');
- if (!file_exists(CACHE_DIR)) {
- mkdir(CACHE_DIR);
- }
- class DBConnector {
- protected static $commentMarker = '#',
- $_dsn,
- $_user,
- $_pass,
- $_dbh;
- public function __construct($filepath) {
- if (is_readable($filepath)) {
- $dsn_id = 'dsn: \'';
- $user_id = 'username: ';
- $pass_id = 'password: ';
- $handle = fopen($filepath, "r");
- while (!feof($handle)) {
- $line = fgets($handle);
- $comm = strpos($line, self::$commentMarker);
- if (is_numeric($comm)) {
- $line = substr($line, 0, $comm);
- }
- $dsn = strpos($line, $dsn_id);
- if (is_numeric($dsn)) {
- self::$_dsn = substr($line, $dsn + strlen($dsn_id), strrpos($line, '\'') - strlen($line));
- continue;
- }
- $user = strpos($line, $user_id);
- if (is_numeric($user)) {
- self::$_user = substr($line, $user + strlen($user_id), strrpos($line, "\n") - strlen($line));
- continue;
- }
- $pass = strpos($line, $pass_id);
- if (is_numeric($pass)) {
- self::$_pass = substr($line, $pass + strlen($pass_id), strrpos($line, "\n") - strlen($line));
- continue;
- }
- }
- fclose($handle);
- try {
- self::$_dbh = new PDO(self::$_dsn, self::$_user, self::$_pass);
- } catch (Exception $e) {
- print "Erreur !: " . $e->getMessage() . "<br/>";
- die(TRUE);
- }
- }
- }
- public function getPDO() {
- return self::$_dbh;
- }
- }
- class rawDataGatherer {
- protected static $_dbh;
- public static function init(PDO $dbh) {
- self::$_dbh = $dbh;
- }
- private function __clone() {
- ;
- }
- private function __construct() {
- ;
- }
- public static function raw_dataGatherer_rayon($table, $rayon = '*') {
- if ($rayon != '*') {
- print_r($table);
- $rayons = self::$_dbh->prepare("SELECT DISTINCT rayon, rayon2 FROM `$table` WHERE rayon = ?");
- $rayons->execute(array($rayon));
- } else {
- $rayons = self::$_dbh->prepare("SELECT DISTINCT rayon, rayon2 FROM `$table`");
- $rayons->execute();
- }
- $rayons = $rayons->fetchAll(PDO::FETCH_BOTH);
- return $rayons;
- }
- public static function raw_dataGatherer_rayon2($table, $rayon) {
- $rayons = self::$_dbh->prepare("SELECT DISTINCT rayon2, rayon3 FROM `$table` WHERE rayon = ?");
- $rayons->execute(array($rayon));
- return $rayons->fetchAll(PDO::FETCH_BOTH);
- }
- public static function raw_dataGatherer_rayon3($table, $rayon2) {
- $rayons = self::$_dbh->prepare("SELECT DISTINCT rayon, rayon2, rayon3 FROM `$table` WHERE rayon2 = ?");
- $rayons->execute(array($rayon2));
- return $rayons->fetchAll(PDO::FETCH_BOTH);
- }
- }
- $conf = new DBConnector(DATABASE_CONF_FILE);
- $conf = $conf->getPDO();
- rawDataGatherer::init($conf);
- $files = glob(CACHE_DIR . '/*');
- foreach ($files as $k => $file) {
- if (((isset($_GET['rayon']) && strlen(trim($_GET['rayon'])) > 0) && strpos($file, $_GET['rayon']) !== FALSE) || isset($_GET['clearAll'])) {
- unlink($file);
- unset($files[$k]);
- }
- }
- $last = array_pop($files);
- $match = array();
- $last = substr($last, strripos($last, '/') + 1);
- preg_match('#^ __(?P<id>\d+)__(?P<rayon>.+).json$#i', $last, $match);
- $i = isset($match['id']) ? $match['id'] + 1 : 1;
- if (isset($_GET['rayon']) && strlen(trim($_GET['rayon'])) > 0) {
- $menu_entry = menuSystem::refresh(array('savoirmanger_products'), 'rawDataGatherer::raw', $_GET['rayon'], null);
- print_r($menu_entry);
- file_put_contents(CACHE_DIR . "/__{$i}__{$_GET['rayon']}.json", json_encode($menu_entry));
- }
- $files = glob(CACHE_DIR . '/*');
- foreach ($files as $k => $file) {
- echo $file . "<br />\n";
- }
Add Comment
Please, Sign In to add comment