Exemple #1
0
 public function __construct($db)
 {
     $this->orm = $db;
     $this->db = $db->db();
     $this->table = $db->table();
     $dir = Config::get('dir.blizz.store', session_save_path());
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db));
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $this->dir = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table));
     if (!is_dir($this->dir)) {
         File::mkdir($this->dir);
     }
     $file = $this->dir . DS . 'data.db';
     $new = false;
     if (!is_file($file)) {
         File::create($file);
         $new = true;
         File::put($this->dir . DS . 'age.blizz', '');
     }
     $link = new SQLite3($file);
     Now::set("blizz.link.{$this->db}.{$this->table}", $link);
     if ($new) {
         $this->init();
     }
 }
Exemple #2
0
 public function import(array $array, $erase = false)
 {
     if (count($array)) {
         $data = [];
         $i = 1;
         foreach ($array as $row) {
             if (Arrays::is($row) && Arrays::assoc($row)) {
                 foreach ($row as $key => $value) {
                     $newRow[Inflector::urlize($key, '_')] = $value;
                 }
                 array_push($data, $newRow);
                 $i++;
             }
         }
         if (count($data)) {
             $file = $this->dir . DS . 'data.db';
             if (true === $erase) {
                 File::delete($file);
             }
             foreach ($data as $row) {
                 $this->save($row);
             }
         }
     }
     return $this;
 }
Exemple #3
0
 public function __construct($db = null, $table = null)
 {
     $this->db = is_null($db) ? SITE_NAME : $db;
     $this->table = is_null($table) ? 'core' : $table;
     $this->store = Config::get('dir.flight.store');
     $this->db = Inflector::urlize($this->db, '');
     $this->table = Inflector::urlize($this->table, '');
     if (!$this->store) {
         throw new Exception("You must defined in config a dir store for JDB.");
     }
     if (!is_dir($this->store)) {
         File::mkdir($this->store);
     }
     $this->dir = $this->store . DS . $this->db;
     if (!is_dir($this->dir)) {
         File::mkdir($this->dir);
     }
     $this->ids = $this->dir . DS . 'ids.' . $this->table;
     if (!file_exists($this->ids)) {
         File::put($this->ids, 1);
     }
     $this->dir .= DS . $this->table;
     if (!is_dir($this->dir)) {
         File::mkdir($this->dir);
     }
     $this->age = filemtime($this->dir);
     $this->tuplesDir = $this->dir . DS . 'tuples';
     if (!is_dir($this->tuplesDir)) {
         File::mkdir($this->tuplesDir);
     }
     $this->cacheDir = $this->dir . DS . 'cache';
     if (!is_dir($this->cacheDir)) {
         File::mkdir($this->cacheDir);
     }
     $this->indicesDir = $this->dir . DS . 'indices';
     if (!is_dir($this->indicesDir)) {
         File::mkdir($this->indicesDir);
     }
     $this->relationsDir = $this->dir . DS . 'relations';
     if (!is_dir($this->relationsDir)) {
         File::mkdir($this->relationsDir);
     }
 }
Exemple #4
0
 public function __construct($db = null, $table = null)
 {
     $this->db = is_null($db) ? SITE_NAME : $db;
     $this->table = is_null($table) ? 'core' : $table;
     $dir = Config::get('dir.blizz.store', session_save_path());
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db));
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $this->dir = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table));
     if (!is_dir($this->dir)) {
         File::mkdir($this->dir);
     }
     $store = lib('blizzstore', [$this]);
     Now::set("blizz.store.{$this->db}.{$this->table}", $store);
     $this->cursor = lib('blizzcursor', [$this]);
 }
Exemple #5
0
 public function __construct($db = null, $table = null)
 {
     $this->db = is_null($db) ? SITE_NAME : $db;
     $this->table = is_null($table) ? 'core' : $table;
     $dir = Config::get('dir.flat.store', session_save_path());
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db));
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $this->dir = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table));
     if (!is_dir($this->dir)) {
         File::mkdir($this->dir);
     }
     if (!is_file($this->dir . DS . 'age.blazz')) {
         File::put($this->dir . DS . 'age.blazz', '');
     }
     $this->cursor = core('cursor', [$this]);
 }
Exemple #6
0
 public static function flush($db = null, $table = null, $name = null)
 {
     $db = is_null($db) ? '*' : $db;
     $table = is_null($table) ? '*' : $table;
     $name = is_null($name) ? '*' : Inflector::urlize($name, '.');
     if ($db != '*' && $table != '*') {
         $cache = Database::instance($db, $table)->cache();
     } else {
         $cache = Database::instance('auth', 'user')->cache();
     }
     $hashes = $cache->keys("dbjson::cachedQueries::{$db}::{$table}");
     $ages = $cache->keys("dbjson::cachedQueries::{$db}::{$table}::{$name}::age");
     if (count($hashes)) {
         foreach ($hashes as $hash) {
             $cache->del($hash);
         }
     }
     if (count($ages)) {
         foreach ($ages as $age) {
             $cache->del($age);
         }
     }
 }
Exemple #7
0
 public function check($id, $html)
 {
     require_once APPLICATION_PATH . DS . '..' . '/public/vendeur/lib/simple_html_dom.php';
     $str = str_get_html($html);
     $segLangs = $str->find('lang');
     foreach ($segLangs as $segLang) {
         $default = $segLang->innertext;
         $args = $segLang->args;
         if (!empty($args)) {
             $replace = "<lang args=\"{$args}\">{$default}</lang>";
         } else {
             $args = '[]';
             $replace = "<lang>{$default}</lang>";
         }
         $by = '<?php __(\'' . $default . '\', \'' . $id . '.' . Inflector::urlize($default, '-') . '\', ' . $args . '); ?>';
         $html = str_replace($replace, $by, $html);
     }
     return $html;
 }
Exemple #8
0
 public function searchNearByAddress($address, $query)
 {
     $collection = lib('collection');
     $coords = lib('geo')->getCoords($address);
     $url = 'http://search.mappy.net/search/1.0/find?extend_bbox=1&bbox=' . $coords['lat1'] . ',' . $coords['lng1'] . ',' . $coords['lat2'] . ',' . $coords['lng2'] . '&q=' . urlencode($query) . '&favorite_country=' . $coords['country_id'] . '&language=FRE&&max_results=199';
     dd($url);
     $key = 'serach.near.' . sha1($url);
     $json = redis()->get($key);
     if (!$json) {
         $json = dwn($url);
         redis()->set($key, $json);
     }
     $data = json_decode($json, true);
     $pois = isAke($data, 'pois', []);
     foreach ($pois as $service) {
         $dbService = rdb('geo', 'service')->where(['code', '=', $service['rubricId']])->first(true);
         if ($dbService) {
             $id = $dbService->id;
         } else {
             if (isset($service['allRubrics'])) {
                 if (count($service['allRubrics'])) {
                     foreach ($service['allRubrics'] as $rubrikA) {
                         $idr = isAke($rubrikA, 'id');
                         $lr = isAke($rubrikA, 'label');
                         $pr = isAke($rubrikA, 'rubricParentId');
                         if ($idr == $service['rubricId']) {
                             $spi = rdb('geo', 'service')->firstOrCreate(['code' => $idr])->setLabel($lr)->setFamily($pr)->save();
                             $id = $spi->id;
                         }
                     }
                 }
             }
         }
         $serviceproxIds = $supplements = [];
         $serviceproxIds[] = $id;
         $poi = $service['id'];
         $checkEtab = rdb('geo', 'etablissement')->where(['poi', '=', (string) $poi])->first(true);
         $add = $checkEtab ? false : true;
         unset($service['id']);
         if (false === $add) {
             $service['id'] = $checkEtab->id;
         }
         unset($service['offer']);
         unset($service['prov']);
         unset($service['pjBlocId']);
         unset($service['thematicId']);
         if (isset($service['tabs'])) {
             if (count($service['tabs'])) {
                 foreach ($service['tabs'] as $tmp) {
                     $tmpUrl = isAke($tmp, 'url', false);
                     $tmpId = isAke($tmp, 'appId', false);
                     if (false !== $tmpUrl && false !== $tmpId) {
                         $key = 'inf.' . $poi . '.' . $tmpId;
                         if ($tmpId == 'pj') {
                             $inf = redis()->get($key);
                             if (empty($inf)) {
                                 $infHtml = dwn($tmpUrl);
                                 $inf = substr($infHtml, strlen('callback('), -1);
                                 redis()->set($key, $inf);
                             }
                             $inf = json_decode($inf, true);
                             $t = isAke($inf, 'tabs', []);
                             if (!empty($t)) {
                                 foreach ($t as $tmpT) {
                                     $b = isAke($tmpT, 'blocks', []);
                                     $t = isAke($tmpT, 'tags', []);
                                     if (!empty($b)) {
                                         for ($ti = 0; $ti < count($b); $ti += 2) {
                                             $seg = $b[$ti];
                                             $seg2 = $b[$ti + 1];
                                             if (is_array($seg) && is_array($seg2)) {
                                                 $title = isAke($seg, 'title', false);
                                                 $kv = isAke($seg2, 'keyValue', false);
                                                 if (false !== $title && false !== $kv) {
                                                     $title = Inflector::urlize($title);
                                                     foreach ($kv as $tmpRow) {
                                                         $supplements[$title][] = [$tmpRow['key'] => $tmpRow['value']];
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         } elseif ($tmpId == 'indoor') {
                         } elseif ($tmpId == 'localbusinesspremium') {
                         } elseif ($tmpId == 'total') {
                         } elseif ($tmpId == 'totalaccess') {
                         } elseif ($tmpId == 'darty') {
                         } elseif ($tmpId == 'eleclerc') {
                         } elseif ($tmpId == 'moteurproduitpromo') {
                         } elseif ($tmpId == 'mappyshopping') {
                         } elseif ($tmpId == 'booking') {
                             $inf = redis()->get($key);
                             if (empty($inf)) {
                                 $infHtml = dwn($tmpUrl);
                                 $inf = substr($infHtml, strlen('callback('), -1);
                                 redis()->set($key, $inf);
                             }
                             $inf = json_decode($inf, true);
                             /* TODO */
                         } elseif ($tmpId == 'localbusinessdiscovery') {
                             $inf = redis()->get($key);
                             if (empty($inf)) {
                                 $infHtml = dwn($tmpUrl);
                                 $inf = substr($infHtml, strlen('callback('), -1);
                                 redis()->set($key, $inf);
                             }
                             $inf = json_decode($inf, true);
                             $t = isAke($inf, 'tabs', []);
                             if (!empty($t)) {
                                 foreach ($t as $tmpT) {
                                     $b = isAke($tmpT, 'blocks', []);
                                     if (!empty($b)) {
                                         foreach ($b as $tmpB) {
                                             $kv = isAke($tmpB, 'keyValue', false);
                                             if (false !== $kv) {
                                                 foreach ($kv as $tmpRow) {
                                                     $tmpK = Inflector::urlize($tmpRow['key']);
                                                     $supplements['infos'][$tmpK] = $tmpRow['value'];
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         } else {
                             $inf = redis()->get($key);
                             if (empty($inf)) {
                                 $infHtml = dwn($tmpUrl);
                                 $inf = substr($infHtml, strlen('callback('), -1);
                                 redis()->set($key, $inf);
                             }
                             $inf = json_decode($inf, true);
                         }
                     }
                 }
             }
         }
         unset($service['tabs']);
         unset($service['contextualPoiUrl']);
         unset($service['providerIds']);
         unset($service['pjRatingId']);
         unset($service['hasUnclaimableProvider']);
         unset($service['additionalInfos']);
         unset($service['additionalInfo']);
         unset($service['coordinateProvider']);
         unset($service['coordinateProvider3D']);
         unset($service['offerType']);
         unset($service['rubricId']);
         unset($service['closestPanoramicId']);
         if (isset($service['allRubrics'])) {
             if (count($service['allRubrics'])) {
                 foreach ($service['allRubrics'] as $rubrikA) {
                     $idr = isAke($rubrikA, 'id');
                     $lr = isAke($rubrikA, 'label');
                     $pr = isAke($rubrikA, 'rubricParentId');
                     $spi = rdb('geo', 'service')->firstOrCreate(['code' => $idr])->setLabel($lr)->setFamily($pr)->save();
                 }
             }
             unset($service['allRubrics']);
         }
         if (isset($service['additionalRubricIds'])) {
             if (count($service['additionalRubricIds'])) {
                 foreach ($service['additionalRubricIds'] as $newRubrique) {
                     $spi = rdb('geo', 'service')->firstOrCreate(['code' => $newRubrique]);
                     $serviceproxIds[] = $spi->id;
                 }
             }
         }
         unset($service['additionalRubricIds']);
         unset($service['brandIconUrl']);
         unset($service['slat']);
         unset($service['slng']);
         unset($service['salt']);
         unset($service['brand']);
         unset($service['indoors']);
         unset($service['visibleIn3D']);
         unset($service['townCode']);
         if (isset($service['town'])) {
             $service['city'] = $service['town'];
             unset($service['town']);
         }
         if (isset($service['positions3D'])) {
             if (isset($service['positions3D']['origin'])) {
                 if (isset($service['positions3D']['origin']['alt'])) {
                     $service['altitude'] = $service['positions3D']['origin']['alt'];
                     unset($service['positions3D']);
                 }
             }
         }
         if (isset($service['way'])) {
             $service['address'] = $service['way'];
             unset($service['way']);
         }
         if (isset($service['pCode'])) {
             $service['zip'] = $service['pCode'];
             unset($service['pCode']);
             unset($service['positions3D']);
         }
         if (isset($service['lat']) && isset($service['lng'])) {
             $distances = distanceKmMiles($coords['lng1'], $coords['lat1'], $service['lng'], $service['lat']);
             $service['distance'] = (double) $distances['km'];
         }
         ksort($service);
         $service['poi'] = $poi;
         if (false === $add) {
             $collection[] = $service;
         }
         if (true === $add) {
             $distance = $service['distance'];
             unset($service['distance']);
             $etab = rdb('geo', 'etablissement')->firstOrCreate($service)->setPoi($poi)->save();
             setLocation($etab, $etab->lng, $etab->lat);
             if (!empty($supplements)) {
                 foreach ($supplements as $supK => $supV) {
                     $setter = setter($supK);
                     $etab->{$setter}($supV);
                 }
                 $etab->save();
             }
             $fields = $etab->_keys();
             $sFields = array_merge(array_keys($service), array_keys($supplements));
             $except = ['id', 'poi', 'created_at', 'updated_at'];
             $resave = false;
             $expurge = [];
             foreach ($fields as $field) {
                 if (!in_array($field, $except)) {
                     if (!in_array($field, $sFields)) {
                         $expurge[] = $field;
                         $etab = $etab->expurge($field);
                         $resave = true;
                     }
                 }
             }
             if (true === $resave) {
                 $etab = $etab->save();
             }
             foreach ($serviceproxIds as $serviceproxId) {
                 $spTmp = rdb('geo', 'service')->find((int) $serviceproxId);
                 $spTmp->attach($etab);
             }
             $zone = rdb('geo', 'zone')->find(1);
             $zone->attach($etab);
             $service['new'] = true;
             $service['id'] = $etab->id;
             $service['distance'] = $distance;
         }
         $collection[] = $service;
     }
     if (!empty($collection)) {
         $tuples = $new = [];
         $collection->sortBy('distance');
         foreach ($collection as $row) {
             $hasPoi = isAke($row, 'poi', false);
             if (false === $hasPoi) {
                 $new[] = $row;
             } else {
                 $poi = sha1($hasPoi);
                 if (!in_array($poi, $tuples)) {
                     $tuples[] = $poi;
                     $new[] = $row;
                 }
             }
         }
         $collection = lib('collection', [$new]);
     }
     return $collection->toArray();
 }
Exemple #9
0
 public function import(array $array)
 {
     if (!empty($array)) {
         $data = [];
         foreach ($array as $row) {
             if (Arrays::is($row) && Arrays::isAssoc($row)) {
                 foreach ($row as $key => $value) {
                     $newRow[Inflector::urlize($key, '_')] = str_replace('[NL]', "\n", $value);
                 }
                 array_push($data, $newRow);
             }
         }
         if (!empty($data)) {
             foreach ($data as $row) {
                 $this->save($row);
             }
         }
     }
     return $this;
 }
Exemple #10
0
 public function check($id, $html)
 {
     require_once __DIR__ . DS . 'dom.php';
     $str = str_get_html($html);
     $segLangs = $str->find('lang');
     foreach ($segLangs as $segLang) {
         $default = $segLang->innertext;
         $args = $segLang->args;
         if (!empty($args)) {
             $controller = Now::get('instance.controller');
             $replace = "<lang args=\"{$args}\">{$default}</lang>";
             $file = path('cache') . DS . sha1(serialize($args)) . '.display';
             File::put($file, '<?php namespace Thin; ?>' . $args);
             ob_start();
             include $file;
             $args = ob_get_contents();
             ob_end_clean();
             File::delete($file);
         } else {
             $args = '[]';
             $replace = "<lang>{$default}</lang>";
         }
         $by = '<?php __(\'' . $default . '\', \'' . $id . '.' . Inflector::urlize($default, '-') . '\', ' . $args . '); ?>';
         $html = str_replace($replace, $by, $html);
     }
     return $html;
 }
Exemple #11
0
 function htmlToPng($html, $name = null, $orientation = null, $count = 0)
 {
     $name = is_null($name) ? 'doc.pdf' : Inflector::urlize($name) . '.pdf';
     $orientation = is_null($orientation) ? 'portrait' : $orientation;
     $file = TMP_PUBLIC_PATH . DS . sha1(serialize(func_get_args())) . '.html';
     files()->put($file, $html);
     $pdf = str_replace('.html', '.pdf', $file);
     // $keep = lib('keep')->instance();
     $url = URLSITE . 'tmp/' . Arrays::last(explode('/', $file));
     $this->urlToPng($url);
 }
Exemple #12
0
 public static function lng($content)
 {
     $tab = array_merge(explode('<t ', $content), explode('<t>', $content));
     if (count($tab)) {
         array_shift($tab);
         foreach ($tab as $row) {
             $id = Utils::cut('id="', '"', trim($row));
             $args = Utils::cut('args=[', ']', trim($row));
             $default = Utils::cut('">', '</t>', trim($row));
             $default = !strlen($default) ? Utils::cut(']>', '</t>', trim($row)) : $default;
             if (!strlen($default)) {
                 if (!strstr($row, '</t>')) {
                     continue;
                 } else {
                     list($default, $dummy) = explode('</t>', $row, 2);
                 }
             }
             if (strlen($args)) {
                 if (strlen($id)) {
                     $content = repl('<t id="' . $id . '" args=[' . $args . ']>' . $default . '</t>', '<?php echo trad("' . repl('"', '\\"', $id) . '", "' . repl('"', '\\"', $default) . '", "' . repl('"', '\\"', $args) . '"); ?>', $content);
                 } else {
                     $id = Inflector::urlize($default);
                     $content = repl('<t args=[' . $args . ']>' . $default . '</t>', '<?php echo trad("' . $id . '", "' . repl('"', '\\"', $default) . '", "' . repl('"', '\\"', $args) . '"); ?>', $content);
                 }
             } else {
                 if (strlen($id)) {
                     $content = repl('<t id="' . $id . '">' . $default . '</t>', '<?php echo trad("' . repl('"', '\\"', $id) . '", "' . repl('"', '\\"', $default) . '"); ?>', $content);
                 } else {
                     $id = Inflector::urlize($default);
                     $content = repl('<t>' . $default . '</t>', '<?php echo trad("' . $id . '", "' . repl('"', '\\"', $default) . '"); ?>', $content);
                 }
             }
         }
     }
     return $content;
 }
Exemple #13
0
 public function getPoisArticle($art)
 {
     $article = null;
     if (is_array($art)) {
         $article = $art;
     } elseif (is_object($art) || is_string($art)) {
         $article = $this->native($art);
     }
     if (is_array($article)) {
         $key = 'getPoisArticles.' . (string) $article['_id'];
         // getCached($key, function () use ($article) {
         $ll = lib('clipp')->getLatLng($article);
         $ida = (string) $article['_id'];
         $lat = isAke($ll, 'lat', 0);
         $lng = isAke($ll, 'lng', 0);
         if ($lat != 0 && $lng != 0) {
             $pois = lib('geo')->poisTouristic(floatval($lat), floatval($lng));
             $key = 'getPoisArticle.' . sha1((string) $article['_id'] . floatval($lat) . floatval($lng));
             $db = lib('clipp')->em('nodes');
             foreach ($pois as $poi) {
                 $ds = isAke($poi, 'datasheets', []);
                 if (!empty($ds)) {
                     $row = current($ds);
                     $count = $db->find(['permalink' => '/poi/' . Inflector::urlize($row['name'])])->count();
                     if ($count == 0) {
                         $obj = ['__v' => 0, 'history' => [], 'key' => isAke($poi, 'poi_id', null), 'type' => 'poi', 'status' => 2, 'lang' => 'fr_fr', 'title' => $row['name'], 'description' => $row['description'], 'medias' => $row['medias'], 'permalink' => '/poi/' . Inflector::urlize($row['name']), 'search' => Inflector::urlize($row['description'], ' '), 'updated_at' => new \MongoDate(), 'created_at' => new \MongoDate()];
                         $location = new \stdclass();
                         $location->address = new \stdclass();
                         $location->address->area = isAke($row, 'area', null);
                         $location->address->country = isAke($row, 'country', null);
                         $location->address->city = isAke($row, 'city', null);
                         $location->address->ref = isAke($row, 'ref_lieu', null);
                         $location->address->street = isAke($row, 'address', null);
                         $location->address->zip = isAke($row, 'postcode', null);
                         $location->formatted_address = isAke($row, 'formated_address_line', null);
                         $location->formatted_city = isAke($row, 'formated_city_line', null);
                         $location->type = 'Point';
                         $location->coordinates = [floatval(isAke($row, 'longitude', 0)), floatval(isAke($row, 'latitude', 0))];
                         $obj['location'] = $location;
                         $db->insert($obj, ['fsync' => true]);
                         $idp = (string) $obj['_id'];
                         // Model::PoiAssoc()->create([
                         //     'id_node' => $ida,
                         //     'id_poi' => $idp
                         // ])->save();
                     }
                     // else {
                     //     if ($count == 1) {
                     //         $row = $db->findOne([
                     //             'permalink' => '/poi/' . Inflector::urlize($row['name'])
                     //         ]);
                     //         $idp = (string) $row['_id'];
                     //         Model::PoiAssoc()->create([
                     //             'id_node' => $ida,
                     //             'id_poi' => $idp
                     //         ])->save();
                     //     }
                     // }
                 }
             }
         }
         return true;
         // });
     }
 }
Exemple #14
0
 private static function prepareFulltext($text)
 {
     $text = Inflector::urlize(strip_tags(Blog::parse($text)));
     return explode('-', $text);
 }
Exemple #15
0
 function pdfFile($html, $name = null, $orientation = null, $count = 0)
 {
     $name = is_null($name) ? 'doc.pdf' : Inflector::urlize($name) . '.pdf';
     $orientation = is_null($orientation) ? 'portrait' : $orientation;
     $file = TMP_PUBLIC_PATH . DS . sha1(serialize(func_get_args())) . '.html';
     files()->put($file, $html);
     $pdf = str_replace('.html', '.pdf', $file);
     // $keep = lib('keep')->instance();
     $url = 'http://www.zelift.com/tmp/' . Arrays::last(explode('/', $file));
     $cnt = dwn('http://apphuge.uk/pdf.php?url=' . urlencode($url) . '&orientation=' . $orientation);
     // if (!strlen($cnt) && $count < 5) {
     //     return pdfFile($html, $name, $orientation, $count++);
     // }
     // if (!strlen($cnt) && $count >= 5) {
     //     exception('pdf', 'Le pdf est erroné et ne peut être créé.');
     // }
     files()->delete($file);
     return $cnt;
 }