Ejemplo n.º 1
0
 public function __construct($bucket = null, $args = [])
 {
     $this->bucket = !$bucket ? SITE_NAME : Inflector::urlize($bucket, '');
     $this->args = $args;
     if ($this->bucket == 'download') {
         throw new Exception("The bucket name 'download' is not possible. Please chosse another one => ex: 'downloads'.");
     }
     $dir = session_save_path() . DS . 'bucket';
     if (!is_dir($dir)) {
         File::mkdir($dir);
     }
     $this->dir = $dir . DS . $this->bucket;
     if (!is_dir($this->dir)) {
         File::mkdir($this->dir);
     }
     $this->dir .= '/';
     $this->check();
 }
Ejemplo n.º 2
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->file = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table)) . '.flat';
     if (!file_exists($this->file)) {
         File::put($this->file, serialize([]));
     }
     Now::set('flat.collection.' . $this->db . '.' . $this->table, lib('sessy', [$this->db, $this->table, unserialize(File::read($this->file))]));
 }
Ejemplo n.º 3
0
 /**
  * Normalise une chaine en ne conservant que des caractères alphanumériques et des tirets. Si l'extension est renseignée,
  * elle sera protégée (non normalisée) dans le texte. L'extension peut être indifféremment de la forme '.ext' ou 'ext'.
  * @param string $text
  * @param string $extension
  * @return string
  */
 public static function slugify($text, $extension = "")
 {
     // Protection de l'extension (pour les noms de fichiers complets)
     $extension = trim($extension);
     if ($extension != "" && strpos($text, $extension) === false) {
         $extension = "";
     }
     if ($extension != "") {
         if ($extension[0] != '.') {
             /**
              *  L'extension doit commencer par un .
              */
             $extension = ".{$extension}";
         }
         // On la supprime du texte à traiter pour qu'elle ne soit pas transformée.
         // On la replacera en fin de texte avant de quitter la méthode
         $text = str_replace($extension, "", $text);
     }
     $text = Inflector::urlize($text);
     return "{$text}{$extension}";
 }
Ejemplo n.º 4
0
 public function forget($key)
 {
     $key = Inflector::urlize($key, '.');
     unset(self::$datas[$this->ns][$key]);
     return $this;
 }
Ejemplo n.º 5
0
 public function getTransports($lat, $lng)
 {
     $bbox = $this->getBoundingBox($lat, $lng);
     $url = "https://navitia.opendatasoft.com/api/records/1.0/download/?dataset=global_stops&format=json&geofilter.bbox={$bbox[0]},{$bbox[1]},{$bbox[2]},{$bbox[3]}&rows=1000&timezone=Europe%2FParis";
     return xCache('get.transports.' . sha1($url), function () use($url, $lat, $lng) {
         $json = lib('geo')->dwnCache($url);
         $tab = json_decode($json, true);
         $collection = [];
         foreach ($tab as $row) {
             $obj = [];
             $stop_id = isAke(isAke($row, 'fields', []), 'stop_id', '');
             $name = isAke(isAke($row, 'fields', []), 'stop_name', '');
             $geo = isAke(isAke($row, 'fields', []), 'geo', [0, 0]);
             $distances = distanceKmMiles($lng, $lat, $geo[1], $geo[0]);
             $type = 'bus';
             for ($i = 0; $i < strlen($name); $i++) {
                 $char = $name[$i];
                 $charC = Inflector::urlize($char, '');
                 if (strlen($charC)) {
                     if (!is_numeric($charC)) {
                         if (ctype_lower($char)) {
                             $type = 'subway';
                         }
                     }
                 }
             }
             $has = false;
             if (fnmatch("StopArea:OIF*", $stop_id)) {
                 list($dummy, $ratp_stop_id) = explode('StopArea:OIF', $stop_id, 2);
                 $native = clipp()->em('transports')->findOne(['stop_id' => strval($ratp_stop_id)]);
                 $has = true;
                 if ($native) {
                     unset($native['_id']);
                     unset($native['created_at']);
                     unset($native['updated_at']);
                     unset($native['status']);
                     unset($native['__v']);
                     $native['geo'] = $native['location']['coordinates'];
                     $native['km'] = $distances['km'];
                     $native['distances'] = $distances;
                     $collection[] = $native;
                 }
             }
             if (!$has) {
                 $obj['title'] = $name;
                 $obj['geo'] = $geo;
                 $obj['km'] = $distances['km'];
                 $obj['distances'] = $distances;
                 $obj['type'] = $type;
                 $obj['stop_id'] = $stop_id;
                 $collection[] = $obj;
             }
         }
         $check = coll($collection)->min('km');
         $collection = coll($collection)->sortBy('km')->toArray();
         $collection = array_values($collection);
         if (0.5 > $check) {
             $return = [];
             foreach ($collection as $row) {
                 if (0.5 >= $row['km']) {
                     $return[] = $row;
                 } else {
                     return $return;
                 }
             }
         } else {
             return $collection;
         }
     });
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
 /**
  * [__construct description]
  * @param [type] $name [description]
  */
 public function __construct($name = null)
 {
     $name = is_null($name) ? 'core' : $name;
     $this->_name = Inflector::urlize($name, '.');
     $this->check();
 }
Ejemplo n.º 8
0
 public function open($savePath, $sessionName)
 {
     $this->db = core('fast')->instanciate('session', Inflector::urlize($sessionName, ''));
 }
Ejemplo n.º 9
0
 private function normalize($str)
 {
     return Inflector::urlize($str, '');
 }
Ejemplo n.º 10
0
 /**
  * Convert a string (normally a title) to a string suitable for using in
  * urls and other html attributes. Uses {@link URLSegmentFilter}.
  *
  * @param string
  * @return string
  */
 public function raw2url($title)
 {
     return Inflector::urlize($title);
 }