Esempio n. 1
0
 public function parseScript($script, $base_path)
 {
     if (!filter_var($script, FILTER_VALIDATE_URL)) {
         if ($script[0] != "/") {
             $script = strReplaceFirst(ROOT, BASE_URL, $base_path) . $script;
         }
     }
     return $script;
 }
Esempio n. 2
0
 public function where($condition, $op = 'AND')
 {
     $tab = explode(' ', $condition);
     $oldField = $field = Arrays::first($tab);
     if (!strstr($field, '.')) {
         $field = $this->db->database . '.' . $this->db->table . '.' . $field;
         $condition = strReplaceFirst($oldField, $field, $condition);
     }
     $this->db = $this->db->where($condition, $op);
     return $this;
 }
Esempio n. 3
0
 public static function tables()
 {
     $dbt = container()->nbm('nma_table');
     $rows = redis()->keys('*_nodeCount');
     $tables = array();
     if (count($rows)) {
         foreach ($rows as $row) {
             $seg = repl('_nodeCount', '', $row);
             $tab = explode('_', $seg);
             $ns = Arrays::first($tab);
             $index = strReplaceFirst($ns . "_", "", $seg);
             if (!strstr($index, 'nma_')) {
                 $t = $dbt->where('name = ' . $index)->where('ns = ' . $ns)->first(true);
                 if (is_null($t)) {
                     $tableName = "dbNode_" . $ns . "::{$index}";
                     $tables[$index]['count'] = redis()->get($row);
                     $data = redis()->hkeys($tableName);
                     if (count($data)) {
                         $first = Arrays::first($data);
                         $first = json_decode(redis()->hget($tableName, $first), true);
                         $fields = array_keys($first);
                         $tables[$index]['fields'] = $fields;
                     } else {
                         $fields = array();
                     }
                     self::structure($ns, $index, $fields);
                 }
             }
         }
     }
     return $tables;
 }
Esempio n. 4
0
 public function link($routeName, $params = array())
 {
     $link = URLSITE;
     $routes = container()->getMapRoutes();
     if (Arrays::isArray($routes)) {
         if (ake($routeName, $routes)) {
             $route = $routes[$routeName];
             $path = $route->getPath();
             if (count($params)) {
                 foreach ($params as $key => $param) {
                     $path = strReplaceFirst('(.*)', $param, $path);
                 }
             }
             $link .= $path;
         }
     }
     return $link;
 }
Esempio n. 5
0
 private function siren2($siren)
 {
     $infos = [];
     if (is_numeric($siren) && strlen($siren)) {
         $cache = redis()->get('siren::' . $siren);
         if (!strlen($cache)) {
             $data = dwn("http://www.verif.com/imprimer/{$siren}/1/1/");
             redis()->set('siren::' . $siren, $data);
         } else {
             $data = $cache;
         }
         $formeJuridique = $registre = $capital = $dirigeant = $immatriculation = $departement = $codePostal = $ville = $adresse = $ape = $creation = $activite = $tel = $fax = $effectif = $siret = null;
         $cmdTel = "curl 'http://www.pagespro.com/recherche.php' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3' -H 'Connection: keep-alive' -H 'Cookie: EIRAM=1; xtvrn=\$486926\$; xtan=-; xtant=1' -H 'Host: www.pagespro.com' -H 'Referer: http://www.pagespro.com/recherche.php' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0' -H 'Content-Type: application/x-www-form-urlencoded' --data 'p_ACTION=&p_ORDRE=AfficheRes&a_PAGE=1&a_TAG=&a_OccRecherche=&typeRecherche=express&satellite=siret&a_activ=&a_rai_soc=&a_naf=&a_siren={$siren}&a_tel=&a_geo=&typeTri=&ordreTri=&a_session='";
         $cacheTel = redis()->get('siren::tel::' . $siren);
         if (!strlen($cacheTel)) {
             exec($cmdTel, $dataTel);
             $dataTel = implode("", $dataTel);
             redis()->set('siren::tel::' . $siren, $dataTel);
         } else {
             $dataTel = $cacheTel;
         }
         if (strstr($dataTel, '<span itemprop="tel">')) {
             $tel = strReplaceFirst('0', '+33', str_replace(["\t", '&nbsp;', ' '], '', Utils::cut('<span itemprop="tel">', '</span>', $dataTel)));
         }
         $dataFax = str_replace(["\t"], '', $dataTel);
         if (strstr($dataFax, "<span>fax")) {
             $segFax = Utils::cut('<span>fax', '</d', $dataFax);
             $fax = strReplaceFirst('0', '+33', str_replace(["\t", '&nbsp;', ' '], '', Utils::cut('<span itemprop="tel">', '</span>', $segFax)));
         }
         if (strstr($dataTel, '<b>Effectif')) {
             $segEffectif = Utils::cut('<b>Effectif', '/div>', $dataTel);
             $effectif = str_replace(["\t", '&nbsp;'], '', Utils::cut('</b>', '<', $segEffectif));
         }
         if (strstr($dataTel, '<b>Siret')) {
             $segSiret = Utils::cut('<b>Siret', '/div>', $dataTel);
             $siret = str_replace(["\t", '&nbsp;'], '', Utils::cut('</b>', '<', $segSiret));
         }
         $seg = Utils::cut('<h4>Informations g&eacute;n&eacute;rales</h4>', '</table>', $data);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Raison sociale</td>', '</tr>', $seg);
         $raisonSociale = Utils::cut('<td>', '</td>', $sousSeg);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">APE</td>', '</tr>', $seg);
         $ape = Utils::cut('<td>', '</td>', $sousSeg);
         list($ape, $activite) = explode(' / ', Utils::cut('>', '</', $ape), 2);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Forme juridique', '</tr>', $seg);
         list($formeJuridique, $creation) = explode(', cr&eacute;&eacute;e le ', Utils::cut('<td>', '</td>', $sousSeg), 2);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Adresse', '</tr>', $seg);
         $adr = Utils::cut('<td>', '</td>', $sousSeg);
         $adr = explode("\n", $adr);
         array_pop($adr);
         $adresse = Arrays::first($adr);
         $cpville = Arrays::last($adr);
         $adresse = $this->clean(str_replace(["\t", "<br />"], '', $adresse));
         list($codePostal, $ville) = explode('&nbsp;', $cpville, 2);
         $codePostal = $this->clean(str_replace(["\t", " "], '', $codePostal));
         $departement = substr($codePostal, 0, 2);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Capital Social', '</tr>', $seg);
         $capital = Utils::cut('<td>', '&', $sousSeg);
         $sousSeg = Utils::cut('<td class="fiche_tdhead">Registre du commerce', '</tr>', $seg);
         $registre = Utils::cut('<td>', '<', $sousSeg);
         $registre = str_replace(' ', '', $registre);
         if (null === $siret && strstr($seg, 'tdhead">SIRET</td>')) {
             $sousSeg = Utils::cut('<td class="fiche_tdhead">SIRET</td>', '</tr>', $seg);
             $siret = str_replace(' ', '', Utils::cut('<td>', '</td>', $sousSeg));
         }
         if (strstr($data, '<H4>Dirigeants</H4>')) {
             $segDirigeant = Utils::cut('<H4>Dirigeants</H4>', '</div>', $data);
             $d = Utils::cut('<table', '</table>', $segDirigeant);
             $d = Utils::cut('<tr', '</tr>', $d);
             $rows = explode("\n", $d);
             array_shift($rows);
             array_pop($rows);
             $fonction = Utils::cut('>', '<', Arrays::first($rows));
             $segPersonne = Arrays::last($rows);
             if (fnmatch('*(*', $segPersonne)) {
                 $personne = Utils::cut('>', '(', $segPersonne);
                 $personne = str_replace(['&nbsp;'], '', $personne);
             } else {
                 $personne = Utils::cut('>', '</', $segPersonne);
             }
             $dirigeant = "{$personne} - {$fonction}";
         }
         $infos = ['siren' => $this->clean($siren), 'siret' => $this->clean($siret), 'raison_sociale' => $this->clean($raisonSociale), 'ape' => $this->clean($ape), 'activite' => $this->clean($activite), 'forme_juridique' => $this->clean($formeJuridique), 'telephone' => $this->clean($tel), 'fax' => $this->clean($fax), 'adresse' => $this->clean($adresse), 'code_postal' => $this->clean($codePostal), 'ville' => $this->clean($ville), 'departement' => $this->clean($departement), 'effectif' => $this->clean($effectif), 'date_immatriculation' => $this->clean($creation), 'registre' => $this->clean($registre), 'capital' => $this->clean($capital), 'dirigeant' => $this->clean($dirigeant)];
     }
     return $infos;
 }
Esempio n. 6
0
 public static function to($name, $args = [])
 {
     $route = static::getRouteByName($name);
     if (null !== $route) {
         $path = $route['path'];
         if (count($args)) {
             foreach ($args as $key => $value) {
                 $path = strReplaceFirst('(.*)', $value, $path);
             }
         }
         return trim(urldecode(URLSITE), '/') . $path;
     }
     return urldecode(URLSITE);
 }
Esempio n. 7
0
        $db = new Txtdb('cache');
        $db->expire($key, $value, $ttl);
    }
});
context('cache')->_get(function ($key, $default = null) {
    if (is_string($key)) {
        $db = new Txtdb('cache');
        return $db->get($key, $default);
    }
    return $default;
});
$core->router(function () {
    $routes = container()->getRoutes();
    $base_uri = Config::get('application.base_uri', '');
    if (strlen($base_uri)) {
        $uri = strReplaceFirst($base_uri, '', $_SERVER['REQUEST_URI']);
    } else {
        $uri = $_SERVER['REQUEST_URI'];
    }
    $uri = strlen($uri) > 1 ? rtrim($uri, '/') : $uri;
    context()->set('uri', $uri);
    if (!empty($routes)) {
        foreach ($routes as $name => $route) {
            if (!$route instanceof Container) {
                continue;
            }
            $path = $route->getPath();
            if (strlen($path) && $path == $uri) {
                Router::make($route);
                return true;
            }
Esempio n. 8
0
File: Mvc.php Progetto: schpill/thin
 public static function to($name, $args = [], $dry = true, $echo = true)
 {
     $route = static::getRouteByName($name);
     if (null !== $route) {
         $path = $route->path;
         if (!empty($args)) {
             foreach ($args as $key => $value) {
                 $path = strReplaceFirst('(.*)', $value, $path);
             }
         }
         $path = Config::get('application.base_uri') . $path;
         if (true === $echo) {
             echo $dry ? $path : trim(urldecode(URLSITE), '/') . $path;
         } else {
             return $dry ? $path : trim(urldecode(URLSITE), '/') . $path;
         }
     } else {
         if (true === $echo) {
             echo $dry ? '/' . Config::get('application.base_uri') : urldecode(URLSITE);
         } else {
             return $dry ? '/' . Config::get('application.base_uri') : urldecode(URLSITE);
         }
     }
 }
Esempio n. 9
0
 public function data(array $data)
 {
     $reseller_id = isAke($data, 'reseller_id', false);
     if ($reseller_id) {
         $myzelift = Model::Myzelift()->firstOrCreate(['reseller_id' => (int) $reseller_id]);
         $tel = isAke($data, 'tel', null);
         $mobile = isAke($data, 'mobile', null);
         if (fnmatch('0*', $tel)) {
             $tel = strReplaceFirst('0', '+33', $tel);
         }
         if (fnmatch('0*', $mobile)) {
             $mobile = strReplaceFirst('0', '+33', $mobile);
         }
         $data['tel'] = $tel;
         $data['mobile'] = $mobile;
         return $myzelift->fillAndSave($data);
     }
     exception('myzelift', "A valid reseller_id is required to proceed.");
 }