function processTd($html, &$movie) { $res = $html->find('a', 2); if (!$res) { return false; } $movie['link'] = RUTORROOT . $res->href; if (trySkip($movie)) { return false; } $title = html_entity_decode($res->plaintext, ENT_QUOTES, "UTF-8"); $movie['description'] = $title; $pos = strrpos($title, ' / ') + 3; if ($pos > 4) { $title = trim(substr($title, $pos)); } $result = array(); $res1 = preg_match_all('/\\[S\\d+/isU', $title, $result, PREG_OFFSET_CAPTURE); $res2 = preg_match_all('/\\[[\\d\\-x ,из]+\\]/isU', $title, $result, PREG_OFFSET_CAPTURE); if ($res1 || $res2) { //that's a series $this->logger->info("skip series: " . $title); return false; } $res1 = preg_match_all('/\\| трейлер/isuU', $title, $result, PREG_OFFSET_CAPTURE); if ($res1) { //that's a trailer $this->logger->info("skip trailer: " . $title); return false; } extractString($title, $movie); extractTranslate($title, $movie); return true; }
function processTd($html, &$movie) { $res = str_get_html($html)->find('a', 0); if (!$res) { return false; } $movie['link'] = "http://nnm-club.me/forum/" . $res->href; if (trySkip($movie)) { return false; } $title = html_entity_decode($res->plaintext, ENT_QUOTES, "UTF-8"); $movie['description'] = $title; $result = array(); $res1 = preg_match_all('/\\[S\\d+/isU', $title, $result, PREG_OFFSET_CAPTURE); $res2 = preg_match_all('/\\[[\\d-x ,]+\\]/isU', $title, $result, PREG_OFFSET_CAPTURE); if ($res1 || $res2) { //that's a series $this->logger->info("skip series: " . $title); return false; } extractTranslate($title, $movie); $pos = strpos($title, '['); if ($pos !== FALSE) { $title = trim(substr($title, 0, $pos)); } $pos = strrpos($title, '/') + 1; if ($pos > 4) { $title = trim(substr($title, $pos)); } extractString($title, $movie); return true; }
function processTd($html, &$movie) { $res = $html->find('a', 0); if (!$res) { return false; } $movie['link'] = "http://www.seedoff.net" . $res->href; if (trySkip($movie)) { return false; } $title = html_entity_decode($res->plaintext, ENT_QUOTES, "UTF-8"); $movie['description'] = $title; $pos = strrpos($title, '/') + 1; $title = trim(substr($title, $pos)); extractString($title, $movie); extractTranslate($title, $movie); return true; }
function processTd($html, &$movie) { $res = $html->find('div.detName a', 0); if (!$res) { return false; } $link = PIRATEROOT . $res->href; $movie['link'] = $link; if (trySkip($movie)) { return false; } $movie['description'] = html_entity_decode($res->plaintext, ENT_QUOTES, "UTF-8"); extractString($res->plaintext, $movie); $res = $html->find('font.detDesc', 0); if (!$res) { return false; } $this->processDesc($res->plaintext, $movie); return true; }
function shell($telegram, $text, $chat_id, $user_id, $location, $reply_to_msg) { date_default_timezone_set('Europe/Rome'); $today = date("Y-m-d H:i:s"); if ($text == "/start" || $text == "Informazioni") { $img = curl_file_create('logo.png', 'image/png'); $contentp = array('chat_id' => $chat_id, 'photo' => $img); $telegram->sendPhoto($contentp); $reply = "Benvenuto. Questo è un servizio automatico (bot da Robot) per gli orari delle " . NAME . ".\n\t\tPuoi ricercare gli orari dei Bus e Treni per Matera da Bari e viceversa.\n\t\tPer cercare i prossimi Treni o Bus clicca nel menù in basso o segui la sezione Istruzioni.\n\t\tIn qualsiasi momento scrivendo /start ti ripeterò questo messaggio.\nQuesto bot è stato realizzato da @piersoft, senza fini di lucro e a titolo di Demo, non ha collegamenti con l'azienda Ferrovie Appulo Lucane, non è ufficiale e l'autore declina da ogni responsabilità. La fonte dati è realtime quella del sito http://ferrovieappulolucane.it/. Il codice sorgente è liberamente riutilizzabile con licenza MIT."; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ",new chat started," . $chat_id . "\n"; file_put_contents(LOG_FILE, $log, FILE_APPEND | LOCK_EX); $this->create_keyboard_temp($telegram, $chat_id); exit; } elseif ($text == "/istruzioni" || $text == "Istruzioni") { $reply = "Devi seguire alcune semplici regole. Il formato è 1bm%11/01/2016?5-11 dove il primo numero è 2 per i Treni e 1 per Bus, bm è per Bari->Matera e quindi mb per Matera->Bari, poi il carattere % e la data nel formato gg/mm/aaaa, quindi il carattere ? e infine l'ora e i minuti separati dal carattere - (meno). Attenzione! Se cercate nella giornata odierna, inserite sempre un orario successivo all'ora attuale."; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ",istruzioni," . $chat_id . "\n"; file_put_contents(LOG_FILE, $log, FILE_APPEND | LOCK_EX); $this->create_keyboard_temp($telegram, $chat_id); exit; } elseif ($text == "Prossimi Treni da BA" || $text == "Prossimi Treni da MT") { $ore = date("H"); $minuti = $todaym; $datad = date("d/m/Y"); $minuti = date("i"); if ($text == "Prossimi Treni da BA") { $partenza = "bm"; $mezzo = "2"; } else { $partenza = "mb"; $mezzo = "2"; } if ($mezzo == "1") { $bus = "Bus"; if ($partenza == "bm" || $partenza == "BM") { $partenza = "partenza=5&arrivo=36"; $reply = "Sto cercando i " . $bus . " che partono da Bari\n"; } else { $partenza = "partenza=36&arrivo=5"; $reply = "Sto cercando i " . $bus . " che partono da Matera\n"; } } else { $bus = "Treni"; if ($partenza == "bm" || $partenza == "BM") { $partenza = "partenza=16532&arrivo=16540"; $reply = "Sto cercando i " . $bus . " che partono da Bari Centrale\n"; $log = $today . ",next T da B," . $chat_id . "\n"; } else { $partenza = "partenza=16540&arrivo=16532"; $reply = "Sto cercando i " . $bus . " che partono da Matera Centrale\n"; $log = $today . ",next T da M," . $chat_id . "\n"; } } $reply .= "dalle ore " . $ore . " e " . $minuti . " del giorno " . $datad; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); sleep(2); $datad = str_replace("/", "%2F", $datad); extract($_POST); $url = 'http://ferrovieappulolucane.it/ricerca-corse/'; $ch = curl_init(); $options = 'tipo_mezzo=' . $mezzo . '&' . $partenza . '&data=' . $datad . '&ore=' . $ore . '&minuti=' . $minuti; $file = fopen('db/fal.txt', 'w+'); //da decommentare se si vuole il file locale curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8', 'Accept: Application/json', 'X-Requested-With: XMLHttpRequest', 'Content-Type: application/octet-stream', 'Content-Type: application/download', 'Content-Type: application/force-download', 'Content-Transfer-Encoding: binary ')); curl_setopt($ch, CURLOPT_POSTFIELDS, $options); curl_setopt($ch, CURLOPT_FILE, $file); curl_exec($ch); curl_close($ch); $html = file_get_contents("db/fal.txt"); $html = sprintf('<html><head><title></title></head><body>%s</body></html>', $html); $html = sprintf('<html><head><title></title></head><body>%s</body></html>', $html); $html = sprintf('<html><head><title></title></head><body>%s</body></html>', $html); $html = str_replace("</td>", "</td>;", $html); $html = str_replace("</th>", "</th>;", $html); // $html=str_replace("<tr class=\"dettagli\">","",$html); $html = str_replace("class=\"mostra_dettagli\" ", "action=get_corsa&", $html); $html = str_replace("id=\"", "id_corsa=", $html); $html = str_replace("\" data-id_partenza=\"", "&id_partenza=", $html); $html = str_replace("\" data-id_arrivo=\"", "&id_arrivo=", $html); $html = str_replace("<a href=\"#\"", "", $html); $html = str_replace("\">dettagli</a>", "dettagli", $html); $doc = new DOMDocument(); $doc->loadHTML($html); $xpa = new DOMXPath($doc); $count = 0; $rows = $doc->getElementsByTagName('table'); foreach ($rows as $row) { $values = array(); foreach ($row->childNodes as $cell) { $values[] = $cell->textContent; } $data[] = $values; $count++; } $allertatmp = []; $allerta = []; $countr = 0; $text = "Numero Bus,Partenza,Ora,Arrivo,Ora,Durata,Garantito in caso di sciopero" . "\n"; for ($i = 0; $i < $count; $i++) { array_push($allerta, $data[$i]); $countr++; } for ($tt = 0; $tt < 20; $tt++) { for ($t = 1; $t < 20; $t++) { //array_push($allertatmp, explode(';',$allerta[$tt][$t])); // preg_replace( "", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(" ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(" ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(" ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\n\n\t\t\t\t\t\t\t \t\t\t\t\t\t", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\n\t\t\t\t\t\t\t \t\t\t\t\t\t", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\t\t\t\t\t\t\t \t\t\t\t\t\t", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\t\t\t\t\t ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(array("\r\n", "\r", "\n"), "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\n", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("<br>", "", $allerta[$tt][$t]); $text .= $allerta[$tt][$t]; //$text .=$allerta[$tt][$t].","; //var_dump(explode(';',$allerta[$tt][$t])); } } $text = str_replace("\t\t\t\t\t\t", "", $text); $text = str_replace("\t\t\t\t\t", "", $text); $text = str_replace("\t\t\t\t \t\t\t\t\t\t\t\t\t\t\t\t\t", "", $text); $text = str_replace("\t\t\t\t \t", "", $text); $text = str_replace(" ", "", $text); $text = str_replace(" ", "", $text); $text = str_replace(" ", "", $text); $text = str_replace("Â", "", $text); $text = str_replace(";", ",", $text); $text = str_replace(",,", "", $text); $text = str_replace("Info", "\n", $text); $text = str_replace("dettagli", "\n", $text); $text = utf8_decode($text); //header('Content-type: text/csv'); //header("Content-Disposition: attachment;filename=delibere.csv"); //echo $text; //$allerta .=preg_replace('/\s+?(\S+)?$/', '', substr($allerta, 0, 400))."....\n"; $filecsv = fopen('db/fal.csv', 'w+'); fwrite($filecsv, $text); // Write information to the file fclose($filecsv); $csv = array_map('str_getcsv', file('db/fal.csv')); //var_dump($csv); $countcsv = 0; foreach ($csv as $data => $csv1) { $countcsv = $countcsv + 1; } if ($countcsv == 1) { $content = array('chat_id' => $chat_id, 'text' => "La ricerca non ha prodotto risultati", 'disable_web_page_preview' => true); $telegram->sendMessage($content); $this->create_keyboard_temp($telegram, $chat_id); exit; } //echo $count; for ($i = 1; $i < $countcsv; $i++) { $homepage .= "\n"; $homepage .= "Numero mezzo: " . $csv[$i][0] . "\n"; $homepage .= "Partenza: " . $csv[$i][1] . "\n"; $homepage .= "Alle ore: " . $csv[$i][2] . "\n"; $homepage .= "Arrivo: " . $csv[$i][3] . "\n"; $homepage .= "Alle ore: " . $csv[$i][4] . "\n"; $homepage .= "Durata: " . $csv[$i][5] . "\n"; $homepage .= "Garantito in caso di sciopero: " . $csv[$i][6] . "\n"; $homepage .= "Dettagli fermate intermedie:\n"; $longUrl = "http://www.piersoft.it/falbot/dettaglio.php?" . $csv[$i][7]; $longUrl = str_replace(" ", "", $longUrl); $apiKey = API; $postData = array('longUrl' => $longUrl, 'key' => $apiKey); $jsonData = json_encode($postData); $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key=' . $apiKey); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curlObj, CURLOPT_HEADER, 0); curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json')); curl_setopt($curlObj, CURLOPT_POST, 1); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData); $response = curl_exec($curlObj); // Change the response json string to object $json = json_decode($response); curl_close($curlObj); // $reply="Puoi visualizzarlo su :\n".$json->id; $shortLink = get_object_vars($json); //return $json->id; $homepage .= $shortLink['id'] . "\n"; $homepage .= "____________\n"; } $chunks = str_split($homepage, self::MAX_LENGTH); foreach ($chunks as $chunk) { $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true); $telegram->sendMessage($content); } $content = array('chat_id' => $chat_id, 'text' => "Approfondimenti e biglietti online su http://ferrovieappulolucane.it/", 'disable_web_page_preview' => true); $telegram->sendMessage($content); file_put_contents(LOG_FILE, $log, FILE_APPEND | LOCK_EX); // $this->create_keyboard_temp($telegram,$chat_id); exit; } elseif ($text == "Prossimi Bus da BA" || $text == "Prossimi Bus da MT") { $ore = date("H"); $minuti = $todaym; $datad = date("d/m/Y"); $minuti = date("i"); if ($text == "Prossimi Bus da BA") { $partenza = "bm"; $mezzo = "1"; } else { $partenza = "mb"; $mezzo = "1"; } if ($mezzo == "1") { $bus = "Bus"; if ($partenza == "bm" || $partenza == "BM") { $partenza = "partenza=5&arrivo=36"; $reply = "Sto cercando i " . $bus . " che partono da Bari\n"; } else { $partenza = "partenza=36&arrivo=5"; $reply = "Sto cercando i " . $bus . " che partono da Matera\n"; } } else { $bus = "Treni"; if ($partenza == "bm" || $partenza == "BM") { $partenza = "partenza=16532&arrivo=16540"; $reply = "Sto cercando i " . $bus . " che partono da Bari Centrale\n"; $log = $today . ",next T da B," . $chat_id . "\n"; } else { $partenza = "partenza=16540&arrivo=16532"; $reply = "Sto cercando i " . $bus . " che partono da Matera Centrale\n"; $log = $today . ",next T da M," . $chat_id . "\n"; } } $reply .= "dalle ore " . $ore . " e " . $minuti . " del giorno " . $datad; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); sleep(2); $datad = str_replace("/", "%2F", $datad); extract($_POST); $url = 'http://ferrovieappulolucane.it/ricerca-corse/'; $ch = curl_init(); $options = 'tipo_mezzo=' . $mezzo . '&' . $partenza . '&data=' . $datad . '&ore=' . $ore . '&minuti=' . $minuti; $file = fopen('db/fal.txt', 'w+'); //da decommentare se si vuole il file locale curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8', 'Accept: Application/json', 'X-Requested-With: XMLHttpRequest', 'Content-Type: application/octet-stream', 'Content-Type: application/download', 'Content-Type: application/force-download', 'Content-Transfer-Encoding: binary ')); curl_setopt($ch, CURLOPT_POSTFIELDS, $options); curl_setopt($ch, CURLOPT_FILE, $file); curl_exec($ch); curl_close($ch); $html = file_get_contents("db/fal.txt"); $html = sprintf('<html><head><title></title></head><body>%s</body></html>', $html); $html = sprintf('<html><head><title></title></head><body>%s</body></html>', $html); $html = sprintf('<html><head><title></title></head><body>%s</body></html>', $html); $html = str_replace("</td>", "</td>;", $html); $html = str_replace("</th>", "</th>;", $html); $html = str_replace("<tr class=\"dettagli\">", "", $html); $doc = new DOMDocument(); $doc->loadHTML($html); $xpa = new DOMXPath($doc); $count = 0; $rows = $doc->getElementsByTagName('table'); foreach ($rows as $row) { $values = array(); foreach ($row->childNodes as $cell) { $values[] = $cell->textContent; } $data[] = $values; $count++; } $allertatmp = []; $allerta = []; $countr = 0; $text = "Numero Bus,Partenza,Ora,Arrivo,Ora,Durata,Garantito in caso di sciopero" . "\n"; for ($i = 0; $i < $count; $i++) { array_push($allerta, $data[$i]); $countr++; } for ($tt = 0; $tt < 20; $tt++) { for ($t = 1; $t < 20; $t++) { //array_push($allertatmp, explode(';',$allerta[$tt][$t])); // preg_replace( "", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(" ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(" ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(" ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\n\n\t\t\t\t\t\t\t\t\t\t \t\t\t\t\t\t", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\t\t\t\t\t\t\t \t\t\t\t\t\t", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\t\t\t\t\t ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(array("\r\n", "\r", "\n"), "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\n", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("<br>", "", $allerta[$tt][$t]); $text .= $allerta[$tt][$t]; //$text .=$allerta[$tt][$t].","; //var_dump(explode(';',$allerta[$tt][$t])); } } $text = str_replace("\t\t\t\t\t\t", "", $text); $text = str_replace("\t\t\t\t\t", "", $text); $text = str_replace("\t\t\t\t \t\t\t\t\t\t\t\t\t\t\t\t\t", "", $text); $text = str_replace("\t\t\t\t \t", "", $text); $text = str_replace(" ", "", $text); $text = str_replace(" ", "", $text); $text = str_replace(" ", "", $text); $text = str_replace("Â", "", $text); $text = str_replace(";", ",", $text); $text = str_replace(",,", "", $text); $text = str_replace("Info", "\n", $text); $text = str_replace("dettagli", "\n", $text); $text = utf8_decode($text); //header('Content-type: text/csv'); //header("Content-Disposition: attachment;filename=delibere.csv"); //echo $text; //$allerta .=preg_replace('/\s+?(\S+)?$/', '', substr($allerta, 0, 400))."....\n"; $filecsv = fopen('db/fal.csv', 'w+'); fwrite($filecsv, $text); // Write information to the file fclose($filecsv); $csv = array_map('str_getcsv', file('db/fal.csv')); //var_dump($csv); $countcsv = 0; foreach ($csv as $data => $csv1) { $countcsv = $countcsv + 1; } if ($countcsv == 1) { $content = array('chat_id' => $chat_id, 'text' => "La ricerca non ha prodotto risultati", 'disable_web_page_preview' => true); $telegram->sendMessage($content); $this->create_keyboard_temp($telegram, $chat_id); exit; } //echo $count; for ($i = 1; $i < $countcsv; $i++) { $homepage .= "\n"; $homepage .= "Numero mezzo: " . $csv[$i][0] . "\n"; $homepage .= "Partenza: " . $csv[$i][1] . "\n"; $homepage .= "Alle ore: " . $csv[$i][2] . "\n"; $homepage .= "Arrivo: " . $csv[$i][3] . "\n"; $homepage .= "Alle ore: " . $csv[$i][4] . "\n"; $homepage .= "Durata: " . $csv[$i][5] . "\n"; $homepage .= "Garantito in caso di sciopero: " . $csv[$i][6] . "\n"; $homepage .= "____________\n"; } $chunks = str_split($homepage, self::MAX_LENGTH); foreach ($chunks as $chunk) { $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true); $telegram->sendMessage($content); } $content = array('chat_id' => $chat_id, 'text' => "Approfondimenti e biglietti online su http://ferrovieappulolucane.it/", 'disable_web_page_preview' => true); $telegram->sendMessage($content); file_put_contents(LOG_FILE, $log, FILE_APPEND | LOCK_EX); // $this->create_keyboard_temp($telegram,$chat_id); exit; } elseif ($location != null) { // $this->location_manager($telegram,$user_id,$chat_id,$location); exit; } elseif (strpos($text, '?') !== false && strpos($text, '%') !== false && strpos($text, '-') !== false) { //$mezzo="1"; function extractString($string, $start, $end) { $string = " " . $string; $ini = strpos($string, $start); if ($ini == 0) { return ""; } $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); } //$testo=$_POST["q"]; //$testo="bm%11/01/2016?5-11"; $datad = extractString($text, "%", "?"); $ore = extractString($text, "?", "-"); $minuti = substr($text, -2, 2); $partenza = substr($text, 1, 2); $mezzo = substr($text, 0, 1); // echo $partenza; // echo $minuti; if ($mezzo == "1") { $bus = "Bus"; if ($partenza == "bm" || $partenza == "BM") { $partenza = "partenza=5&arrivo=36"; $reply = "Sto cercando i " . $bus . " che partono da Bari\n"; } else { $partenza = "partenza=36&arrivo=5"; $reply = "Sto cercando i " . $bus . " che partono da Matera\n"; } } else { $bus = "Treni"; if ($partenza == "bm" || $partenza == "BM") { $partenza = "partenza=16532&arrivo=16540"; $reply = "Sto cercando i " . $bus . " che partono da Bari Centrale\n"; } else { $partenza = "partenza=16540&arrivo=16532"; $reply = "Sto cercando i " . $bus . " che partono da Matera Centrale\n"; } } if (intval($ore) < 10) { $ore = "0" . $ore; } if (intval($minuti) < 10) { $minuti = "0" . $minuti; if ($minuti == "000") { $minuti = str_replace("000", "00", $minuti); } } $reply .= "dalle ore " . $ore . " e " . $minuti . " del giorno " . $datad; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); sleep(2); $datad = str_replace("/", "%2F", $datad); extract($_POST); $url = 'http://ferrovieappulolucane.it/ricerca-corse/'; $ch = curl_init(); $options = 'tipo_mezzo=' . $mezzo . '&' . $partenza . '&data=' . $datad . '&ore=' . $ore . '&minuti=' . $minuti; $file = fopen('db/fal.txt', 'w+'); //da decommentare se si vuole il file locale curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8', 'Accept: Application/json', 'X-Requested-With: XMLHttpRequest', 'Content-Type: application/octet-stream', 'Content-Type: application/download', 'Content-Type: application/force-download', 'Content-Transfer-Encoding: binary ')); curl_setopt($ch, CURLOPT_POSTFIELDS, $options); curl_setopt($ch, CURLOPT_FILE, $file); curl_exec($ch); curl_close($ch); $html = file_get_contents("db/fal.txt"); $html = sprintf('<html><head><title></title></head><body>%s</body></html>', $html); $html = sprintf('<html><head><title></title></head><body>%s</body></html>', $html); $html = sprintf('<html><head><title></title></head><body>%s</body></html>', $html); $html = str_replace("</td>", "</td>;", $html); $html = str_replace("</th>", "</th>;", $html); $html = str_replace("<tr class=\"dettagli\">", "", $html); $doc = new DOMDocument(); $doc->loadHTML($html); $xpa = new DOMXPath($doc); $count = 0; $rows = $doc->getElementsByTagName('table'); foreach ($rows as $row) { $values = array(); foreach ($row->childNodes as $cell) { $values[] = $cell->textContent; } $data[] = $values; $count++; } $allertatmp = []; $allerta = []; $countr = 0; $text = "Numero Bus,Partenza,Ora,Arrivo,Ora,Durata,Garantito in caso di sciopero" . "\n"; for ($i = 0; $i < $count; $i++) { array_push($allerta, $data[$i]); $countr++; } for ($tt = 0; $tt < 20; $tt++) { for ($t = 1; $t < 20; $t++) { //array_push($allertatmp, explode(';',$allerta[$tt][$t])); // preg_replace( "", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(" ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(" ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(" ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\n\n\t\t\t\t \t\t\t\t\t\t", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\n\t\t\t\t \t\t\t\t\t\t", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\t\t\t\t\t\t\t \t\t\t\t\t\t", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\t\t\t\t\t ", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace(array("\r\n", "\r", "\n"), "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("\n", "", $allerta[$tt][$t]); $allerta[$tt][$t] = str_replace("<br>", "", $allerta[$tt][$t]); $text .= $allerta[$tt][$t]; //$text .=$allerta[$tt][$t].","; //var_dump(explode(';',$allerta[$tt][$t])); } } $text = str_replace("\t\t\t\t\t\t", "", $text); $text = str_replace("\t\t\t\t\t", "", $text); $text = str_replace("\t\t\t\t \t\t\t\t\t\t\t\t\t\t\t\t\t", "", $text); $text = str_replace("\t\t\t\t \t", "", $text); $text = str_replace(" ", "", $text); $text = str_replace(" ", "", $text); $text = str_replace(" ", "", $text); $text = str_replace("Â", "", $text); $text = str_replace(";", ",", $text); $text = str_replace(",,", "", $text); $text = str_replace("Info", "\n", $text); $text = str_replace("dettagli", "\n", $text); $text = utf8_decode($text); //header('Content-type: text/csv'); //header("Content-Disposition: attachment;filename=delibere.csv"); //echo $text; //$allerta .=preg_replace('/\s+?(\S+)?$/', '', substr($allerta, 0, 400))."....\n"; $filecsv = fopen('db/fal.csv', 'w+'); fwrite($filecsv, $text); // Write information to the file fclose($filecsv); $csv = array_map('str_getcsv', file('db/fal.csv')); //var_dump($csv); $countcsv = 0; foreach ($csv as $data => $csv1) { $countcsv = $countcsv + 1; } if ($countcsv == 1) { $content = array('chat_id' => $chat_id, 'text' => "La ricerca non ha prodotto risultati", 'disable_web_page_preview' => true); $telegram->sendMessage($content); $this->create_keyboard_temp($telegram, $chat_id); exit; } //echo $count; for ($i = 1; $i < $countcsv; $i++) { $homepage .= "\n"; $homepage .= "Numero mezzo: " . $csv[$i][0] . "\n"; $homepage .= "Partenza: " . $csv[$i][1] . "\n"; $homepage .= "Alle ore: " . $csv[$i][2] . "\n"; $homepage .= "Arrivo: " . $csv[$i][3] . "\n"; $homepage .= "Alle ore: " . $csv[$i][4] . "\n"; $homepage .= "Durata: " . $csv[$i][5] . "\n"; $homepage .= "Garantito in caso di sciopero: " . $csv[$i][6] . "\n"; $homepage .= "____________\n"; } $chunks = str_split($homepage, self::MAX_LENGTH); foreach ($chunks as $chunk) { $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true); $telegram->sendMessage($content); } $content = array('chat_id' => $chat_id, 'text' => "Approfondimenti e biglietti online su http://ferrovieappulolucane.it/", 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ",ricerca," . $chat_id . "\n"; file_put_contents(LOG_FILE, $log, FILE_APPEND | LOCK_EX); } $this->create_keyboard_temp($telegram, $chat_id); exit; }
if ($pos_start_str >= 0 && @substr_count($html, $start_str) > 0 && @substr_count($html, $end_str) > 0) { $html = substr($html, $pos_start_str + strlen($start_str)); $pos_end_str = strpos($html, $end_str); $res = substr($html, 0, $pos_end_str); $html = substr($html, $pos_end_str + strlen($end_str)); } return $res; } // iterate through pages for ($page = 1; $page <= NUM_PAGES; $page++) { // Read page url $html = scraperwiki::scrape($main_url . $page); $html = prepareHtml($html); // iterate through items (as long as first string to extract exists) do { // Read out data $url_str = extractString($url_start_str, $url_end_str, &$html); // Read rest of the stuff from detail page $html_detail_page = scraperwiki::scrape($url_base_str . $url_str); $html_detail_page = prepareHtml($html_detail_page); $title_str = extractString($title_start_str, $title_end_str, &$html_detail_page); $desc_str = html_entity_decode(extractString($desc_start_str, $desc_end_str, &$html_detail_page)); $date_str = extractString($date_start_str, $date_end_str, &$html_detail_page); $adress_str = extractString($adress_start_str, $adress_end_str, &$html_detail_page); $adress_str = str_replace('<br />', ', ', $adress_str); // Save new item if ($url_str) { scraperwiki::save(array('guid'), array('title' => $title_str, 'guid' => $url_base_str . $url_str, 'md:address' => $adress_str, 'md:zuordnung' => 'Strasse', 'md:start_date' => $date_str, 'md:author' => 'bewegung.taz.de', 'content' => utf8_encode($desc_str))); } } while ($url_str != ''); }
} if ($date_str == '0000-00-00 00:00:00') { $date_str = $submission_date_str; } if ($date_str == '0000-00-00 00:00:00') { $date_str = date('Y-m-d H:i:s', strtotime("{$year}-01-01 00:00:00")); } $sign_nrs_str = extractString($sign_nrs_start_str, $sign_nrs_stop_str, $html_detail_page); if ($sign_nrs_str != '') { $desc_str .= '<br />Unterschriften insgesamt: ' . $sign_nrs_str; } $exp_date_str = extractString($exp_date_start_str, $exp_date_end_str, $html_detail_page); /*Datum des Bürgerentscheids (Ist der Entscheid noch als offen gekennzeichnet, so wird das expiration_date automatisch auf ein Jahr nach dem start_date gelegt - sollte ausreichen und sorgt dafür, dass Einträge verschwinden, die nicht ordnungsgemäss aktualisiert sind) */ if ($exp_date_str == '0000-00-00 00:00:00') { $exp_date_str = date('Y-m-d H:i:s', strtotime('+1 year', strtotime($date_str))); } $result_str = extractString($result_start_str, $result_end_str, $html_detail_page); $jastimmen_str = extractString($jastimmen_start_str, $jastimmen_end_str, $html_detail_page); if ($jastimmen_str != '') { $desc_str .= '<br />Ja-Stimmen: ' . $jastimmen_str; } // Save new item if ($url_str) { scraperwiki::save(array('guid'), array('title' => $title_str, 'guid' => $url_base_str . $url_str, 'md:address' => $adress_str, 'date_scraped' => strftime("%Y-%m-%d %T"), 'md:author' => 'mehr-demokratie.de', 'md:start_date' => $date_str, 'md:expiration_date' => $exp_date_str, 'category1' => 'Bürgerbegehren', 'description' => $desc_str, 'md:tag1' => 'bb-' . $result_str, 'md:tag2' => 'bb-' . $proc_type_str)); } } while ($url_str != ''); }
//$desc_str = html_entity_decode(utf8_encode(extractString($desc_start_str, $desc_end_str, $html_detail_page))); $desc_str = extractString($desc_start_str, $desc_end_str, $html_detail_page); $desc_str = html_entity_decode($desc_str, ENT_QUOTES, 'UTF-8'); $date_str = extractString($date_start_str, $date_end_str, $html_detail_page); $date_str = str_replace("Uhr", "", $date_str); $dates = explode("-", $date_str); //print "DATE: $date_str \n"; $date_str = strtotime($dates[0]); if (count($dates) <= 1) { $exp_date_str = strtotime("+1 day", $date_str); } else { $exp_date_str = strtotime($dates[1], $date_str); } //print strftime("%c",$date_str) . ":::" . strftime("%c",$exp_date_str) . "\n"; $adress_str = extractString($adress_start_str, $adress_end_str, $html_detail_page); $adress_str = str_replace('<br />', ', ', $adress_str); //filter types of events $aktion_str = extractString($aktion_start_str, $aktion_end_str, $html_detail_page); //print $aktion_str . "\n"; if (strpos($aktion_str, "Demo") !== false) { $cat = "Demonstration"; $zuordnung = "Ort"; } else { continue; } // Save new item if ($url_str) { scraperwiki::save(array('guid'), array('title' => $title_str, 'guid' => $url_base_str . $url_str, 'date_scraped' => strftime("%Y-%m-%d %T"), 'md:address' => $adress_str, 'md:zuordnung' => $zuordnung, 'md:start_date' => strftime("%d-%m-%Y %H:%M", $date_str), 'md:expiration_date' => strftime("%d-%m-%Y %H:%M", $exp_date_str), 'md:author' => 'bewegung.taz.de', 'description' => $desc_str, 'category' => $cat)); } } while ($url_str != ''); }
function shell($inline_query, $telegram, $text, $chat_id, $user_id, $location, $reply_to_msg) { date_default_timezone_set('Europe/Rome'); $today = date("Y-m-d H:i:s"); if ($text == "/start" || $text == "Info") { $reply = "Benvenuto. Per ricercare un Museo, clicca sulla graffetta (📎) e poi 'posizione' oppure digita il nome del Comune. Verrà interrogato il DataBase Unico del Mibact utilizzabile con licenza CC-BY e verranno elencati fino a max 50 musei. In qualsiasi momento scrivendo /start ti ripeterò questo messaggio di benvenuto.\nQuesto bot, non ufficiale, è stato realizzato da @piersoft e il codice sorgente per libero riuso si trova su https://github.com/piersoft/MuseiMibactBot. La propria posizione viene ricercata grazie al geocoder di openStreetMap con Lic. odbl."; $reply .= "\nWelcome. To search for a Museum, click on the paper clip (📎) and then 'position' or type the name of the municipality. It will be questioned DataBase Unique Mibact used with the CC-BY license, and will be listed up to max 50 museums. At any time by writing / start you repeat this welcome message. This bot, unofficially, has been realized by @piersoft and the source code for free reuse is on https://github.com/piersoft/MuseiMibactBot. Its position is searched through the geocoder OpenStreetMap with Lic. ODbL."; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ";new chat started;" . $chat_id . "\n"; $this->create_keyboard($telegram, $chat_id); exit; } else { if (strpos($inline_query["location"], '.') !== false) { $this->location_manager_inline($inline_query, $telegram, $user_id, $chat_id, $location); exit; } else { if ($text == "/location" || $text == "location") { $option = array(array($telegram->buildKeyboardButton("Invia la tua posizione / send your location", false, true))); // Create a permanent custom keyboard $keyb = $telegram->buildKeyBoard($option, $onetime = false); $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "Attiva la localizzazione sul tuo smartphone / Turn on your GPS"); $telegram->sendMessage($content); } elseif ($location != null) { $this->location_manager($telegram, $user_id, $chat_id, $location); exit; } elseif (strpos($text, '🏛') === false && strpos($text, '/') === false && strpos($text, '-') === false) { $location = "Sto cercando i Musei del Comune di: / Searching for Town's Museums of: " . $text; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); // sleep (1); $text = str_replace(" ", "%20", $text); $html = file_get_contents('http://dbunico20.beniculturali.it/DBUnicoManagerWeb/dbunicomanager/searchPlace?tipologiaLuogo=1&quantita=50&comune=' . $text); $html = str_replace("<![CDATA[", "", $html); $html = str_replace("]]>", "", $html); $html = str_replace("</br>", "", $html); $html = str_replace("\n", "", $html); $html = str_replace(" ", "", $html); $html = str_replace(";", " ", $html); $html = str_replace(",", " ", $html); if (strpos($html, '<mibac>') == false) { $content = array('chat_id' => $chat_id, 'text' => "Non ci risultano Musei censiti Mibact in questo luogo", 'disable_web_page_preview' => true); $telegram->sendMessage($content); $this->create_keyboard($telegram, $chat_id); exit; } $doc = new DOMDocument(); $doc->loadHTML($html); $xpa = new DOMXPath($doc); //var_dump($doc); $divsl = $xpa->query('//codice[@sorgente="DBUnico 2.0"]'); $divs0 = $xpa->query('//mibac'); $divs = $xpa->query('//mibac//luogodellacultura/proprieta'); $divs1 = $xpa->query('//mibac//luogodellacultura/denominazione/nomestandard'); $dival = []; $diva = []; $diva1 = []; $count = 0; foreach ($divs0 as $div0) { $count++; } echo "Count: " . $count . "\n"; foreach ($divsl as $divl) { array_push($dival, $divl->nodeValue); } foreach ($divs as $div) { array_push($diva, $div->nodeValue); } foreach ($divs1 as $div1) { array_push($diva1, $div1->nodeValue); } //$count=3; if ($count > 50) { $content = array('chat_id' => $chat_id, 'text' => "Troppe richieste, registringi la ricerca"); $telegram->sendMessage($content); exit; } $option = []; for ($i = 0; $i < $count; $i++) { $alert .= "\n\n"; $alert .= $diva1[$i] . "\n"; // $alert .="🏛 ".$dival[$i]."\n"; $option[$i] = $dival[$i]; $alert .= "🏛 /" . $dival[$i] . "-" . $diva1[$i] . "\n"; $alert .= "__________________"; } // echo $alert; $chunks = str_split($alert, self::MAX_LENGTH); foreach ($chunks as $chunk) { // $forcehide=$telegram->buildForceReply(true); //chiedo cosa sta accadendo nel luogo // $content = array('chat_id' => $chat_id, 'text' => $chunk, 'reply_markup' =>$forcehide,'disable_web_page_preview'=>true); $forcehide = $telegram->buildForceReply(true); //chiedo cosa sta accadendo nel luogo $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true); $telegram->sendMessage($content); } $optionf = array([]); for ($i = 0; $i < $count; $i++) { array_push($optionf, ["🏛 " . $dival[$i] . "_" . $diva1[$i]]); } $keyb = $telegram->buildKeyBoard($optionf, $onetime = false); $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "[Clicca su 🏛 per dettagli / Click on 🏛 for details]"); $telegram->sendMessage($content); // $this->create_keyboard($telegram,$chat_id); // exit; // $content = array('chat_id' => $chat_id, 'text' => "Digita un Comune oppure invia la tua posizione tramite la graffetta (📎) / Send your position clicking 📎 or digit Town"); // $telegram->sendMessage($content); /* $reply = "Hai selezionato un comando non previsto. Ricordati che devi prima inviare la tua posizione cliccando sulla graffetta (📎) "; $content = array('chat_id' => $chat_id, 'text' => $reply); $telegram->sendMessage($content); $log=$today. ";wrong command sent;" .$chat_id. "\n"; //$this->create_keyboard($telegram,$chat_id); */ } elseif (strpos($text, '🏛') !== false || strpos($text, '/') !== false) { function extractString($string, $start, $end) { $string = " " . $string; $ini = strpos($string, $start); if ($ini == 0) { return ""; } $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); } if (strpos($text, '/') !== false) { $text = str_replace("/", "", $text); //}elseif (strpos($text,'-') !== false) { // $text=extractString($text,"🏛 ","-"); } else { $text = extractString($text, "🏛 ", "_"); } $text = str_replace("🏛 ", "", $text); $text = str_replace("🏛", "", $text); // $text=str_replace("/","",$text); // $text=str_replace("$$",")",$text); // $text=str_replace("$","(",$text); // $text=str_replace("___","-",$text); // $text=str_replace("__","'",$text); // $text=str_replace("_"," ",$text); // $text=str_replace("22","\"",$text); // $text=str_replace("E2809C","“",$text); if (empty($text) !== false) { $content = array('chat_id' => $chat_id, 'text' => "Nessun risultato / No result", 'disable_web_page_preview' => true); $telegram->sendMessage($content); $this->create_keyboard($telegram, $chat_id); exit; } $location = "Sto cercando: / Searching for: " . $text; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); // sleep (1); // $text=urlencode($text); $text = str_replace("-", "%2D", $text); // $text=str_replace("'","%27",$text); $text = str_replace(" ", "%20", $text); // $text=str_replace("(","%28",$text); // $text=str_replace(")","%29",$text); // $text=str_replace("\"","%22",$text); // $text=str_replace("“","%E2%80%9C",$text); $html = file_get_contents('http://dbunico20.beniculturali.it/DBUnicoManagerWeb/dbunicomanager/searchPlace?tipologiaLuogo=1&quantita=50&id=' . $text); $html = str_replace("<![CDATA[", "", $html); $html = str_replace("]]>", "", $html); $html = str_replace("</br>", "", $html); $html = str_replace("\n", "", $html); $html = str_replace(" ", "", $html); $html = str_replace(";", " ", $html); $html = str_replace(",", " ", $html); if (strpos($html, '<mibac>') == false) { $content = array('chat_id' => $chat_id, 'text' => "Nessun risultato / No result", 'disable_web_page_preview' => true); $telegram->sendMessage($content); $this->create_keyboard($telegram, $chat_id); exit; } $doc = new DOMDocument(); $doc->loadHTML($html); $xpa = new DOMXPath($doc); //var_dump($doc); $divsl = $xpa->query('//codice[@sorgente="DBUnico 2.0"]'); $divs0 = $xpa->query('//mibac'); $divs = $xpa->query('//mibac//luogodellacultura/proprieta'); $divs1 = $xpa->query('//mibac//luogodellacultura/denominazione/nomestandard'); $divs2 = $xpa->query('//mibac//luogodellacultura/descrizione/testostandard'); $divs3 = $xpa->query('//mibac//luogodellacultura/descrizione/traduzioni'); $divs4 = $xpa->query('//mibac//luogodellacultura/orario/testostandard'); $divs5 = $xpa->query('//info/sitoweb'); $divs6 = $xpa->query('//info/email'); $divs7 = $xpa->query('//info/telefono/testostandard'); $divs8 = $xpa->query('//chiusurasettimanale/testostandard'); $divs9 = $xpa->query('//latitudine'); $divs10 = $xpa->query('//longitudine'); $divs11 = $xpa->query('//indirizzo/via-piazza'); $divs12 = $xpa->query('//allegati/file/url'); $divs13 = $xpa->query('//info/orario/testostandard'); $dival = []; $diva = []; $diva1 = []; $diva2 = []; $diva3 = []; $diva4 = []; $diva5 = []; $diva6 = []; $diva7 = []; $diva8 = []; $diva9 = []; $diva10 = []; $diva11 = []; $diva12 = []; $diva13 = []; $count = 0; foreach ($divs0 as $div0) { $count++; } echo "Count: " . $count . "\n"; foreach ($divsl as $divl) { array_push($dival, $divl->nodeValue); } foreach ($divs as $div) { array_push($diva, $div->nodeValue); } foreach ($divs1 as $div1) { array_push($diva1, $div1->nodeValue); } foreach ($divs2 as $div2) { array_push($diva2, $div2->nodeValue); } foreach ($divs3 as $div3) { array_push($diva3, $div3->nodeValue); } foreach ($divs4 as $div4) { array_push($diva4, $div4->nodeValue); } foreach ($divs5 as $div5) { array_push($diva5, $div5->nodeValue); } foreach ($divs6 as $div6) { array_push($diva6, $div6->nodeValue); } foreach ($divs7 as $div7) { array_push($diva7, $div7->nodeValue); } foreach ($divs8 as $div8) { array_push($diva8, $div8->nodeValue); } foreach ($divs9 as $div9) { array_push($diva9, $div9->nodeValue); } foreach ($divs10 as $div10) { array_push($diva10, $div10->nodeValue); } foreach ($divs11 as $div11) { array_push($diva11, $div11->nodeValue); } foreach ($divs12 as $div12) { array_push($diva12, $div12->nodeValue); } foreach ($divs13 as $div13) { array_push($diva13, $div13->nodeValue); } //$count=3; if ($count > 50) { $content = array('chat_id' => $chat_id, 'text' => "Troppe richieste, registringi la ricerca"); $telegram->sendMessage($content); exit; } for ($i = 0; $i < $count; $i++) { $alert .= "\n\n"; $alert .= "Ente: " . $diva1[$i] . "\n"; $alert .= "Proprietà: " . $diva[$i] . "\n"; $alert .= "Descrizione: " . $diva2[$i] . "\n"; if ($diva3[$i] != NULL) { $alert .= "\n" . $diva3[$i]; } if ($diva4[$i] != NULL) { $alert .= "\nApertura: " . $diva4[$i]; } if ($diva5[$i] != NULL) { $alert .= "\nSitoweb: " . $diva5[$i]; } if ($diva6[$i] != NULL) { $alert .= "\nEmail: " . $diva6[$i]; } if ($diva7[$i] != NULL) { $alert .= "\nTelefono: " . $diva7[$i]; } if ($diva11[$i] != NULL) { $alert .= "\nIndirizzo: " . $diva11[$i]; } if ($diva13[$i] != NULL) { $alert .= "\nApertura: " . $diva13[$i]; } if ($diva8[$i] != NULL) { $alert .= "\nChiusura settimanale: " . $diva8[$i]; } /* if ($dival[$i]!=NULL) { $longUrl = "http://www.beniculturali.it/mibac/opencms/MiBAC/sito-MiBAC/MenuPrincipale/LuoghiDellaCultura/Ricerca/index.html?action=show&idluogo=".$dival[$i]; $apiKey = "AIzaSyABhW2DAsHzlYAyLrJxLLgCt0e6J735eYw"; $postData = array('longUrl' => $longUrl, 'key' => $apiKey); $jsonData = json_encode($postData); $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curlObj, CURLOPT_HEADER, 0); curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json')); curl_setopt($curlObj, CURLOPT_POST, 1); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData); $response = curl_exec($curlObj); // Change the response json string to object $json = json_decode($response); curl_close($curlObj); $shortLink = get_object_vars($json); $alert .="\nScheda completa: ".$shortLink['id']; // $alert .="Foto: ".$diva12[$i]."\n\n"; // $content = array('chat_id' => $chat_id, 'text' => $diva12[$i]); // $telegram->sendMessage($content); } */ if ($diva12[$i] != NULL) { $longUrl = $diva12[$i]; $apiKey = "AIzaSyABhW2DAsHzlYAyLrJxLLgCt0e6J735eYw"; $postData = array('longUrl' => $longUrl, 'key' => $apiKey); $jsonData = json_encode($postData); $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key=' . $apiKey); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curlObj, CURLOPT_HEADER, 0); curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json')); curl_setopt($curlObj, CURLOPT_POST, 1); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData); $response = curl_exec($curlObj); // Change the response json string to object $json = json_decode($response); curl_close($curlObj); $shortLink = get_object_vars($json); $alert .= "\nFoto/Video: " . $shortLink['id']; } if ($diva9[$i] != NULL) { $longUrl = "http://www.openstreetmap.org/?mlat=" . $diva9[$i] . "&mlon=" . $diva10[$i] . "#map=19/" . $diva9[$i] . "/" . $diva10[$i]; /* $apiKey = API; $postData = array('longUrl' => $longUrl, 'key' => $apiKey); $jsonData = json_encode($postData); $curlObj = curl_init(); curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey); curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curlObj, CURLOPT_HEADER, 0); curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json')); curl_setopt($curlObj, CURLOPT_POST, 1); curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData); $response = curl_exec($curlObj); // Change the response json string to object $json = json_decode($response); curl_close($curlObj); $shortLinkMappa = get_object_vars($json); $alert .="\nMappa: ".$shortLinkMappa['id']; */ $option = array(array($telegram->buildInlineKeyboardButton("Mappa", $url = $longUrl))); $keyb = $telegram->buildInlineKeyBoard($option); $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "Vai alla"); $telegram->sendMessage($content); } $alert .= "\n\n__________________"; } // echo $alert; $chunks = str_split($alert, self::MAX_LENGTH); foreach ($chunks as $chunk) { // $forcehide=$telegram->buildForceReply(true); //chiedo cosa sta accadendo nel luogo // $content = array('chat_id' => $chat_id, 'text' => $chunk, 'reply_markup' =>$forcehide,'disable_web_page_preview'=>true); $forcehide = $telegram->buildForceReply(true); //chiedo cosa sta accadendo nel luogo $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true); $telegram->sendMessage($content); } if ($diva12[0] != NULL) { // $reply=$diva12[0]; $reply = $shortLink['id']; $content = array('chat_id' => $chat_id, 'text' => $reply); $telegram->sendMessage($content); } // $telegram->buildKeyBoardHide(true); $this->create_keyboard($telegram, $chat_id); exit; /* $reply = "Hai selezionato un comando non previsto. Ricordati che devi prima inviare la tua posizione cliccando sulla graffetta (📎) "; $content = array('chat_id' => $chat_id, 'text' => $reply); $telegram->sendMessage($content); $log=$today. ";wrong command sent;" .$chat_id. "\n"; // $this->create_keyboard($telegram,$chat_id); */ } } } }
function match_route($r, $_routes) { //echo "request - ".$r; $flag = 0; $params = []; foreach ($_routes as $route => $controller) { $flag = 0; if (strtolower($r) == $route) { return array('route' => $controller, 'params' => []); } if (substr_count($route, '/') == substr_count($r, '/')) { $data = explode('/', $r); $count = substr_count($route, '/'); $data2 = explode('/', $route); for ($i = 0; $i <= $count; $i++) { if (strpos($data2[$i], '{') === false) { if ($data2[$i] != $data[$i]) { $flag = 1; break; } } else { $key = extractString($data2[$i], '{', '}'); //echo $key.' - '.$data[$i]; $params[$key] = $data[$i]; } } if ($flag == 1) { continue; } /* $params = $data; //print_r($params); $i=0; while($i < $count){ unset($params[$i]); $i++; } $params = array_slice($params,$i-1); */ return array('route' => $controller, 'params' => $params); } } }
function shell($telegram, $text, $chat_id, $user_id, $location, $reply_to_msg) { date_default_timezone_set('Europe/Rome'); $today = date("Y-m-d H:i:s"); if ($text == "/start" || $text == "Informazioni") { $reply = "Benvenuto. Per ricercare le spese di un Ente, devi prima ricavare il Codice Ente e poi puoi ricercare per parola chiave la spesa. Segui le istruzioni delle sezioni Ricerca e Ente. Verrà interrogato il DataBase openData utilizzabile con licenza CC-BY 3.0 (http://creativecommons.org/licenses/by/3.0/it/legalcode) presente su http://soldipubblici.gov.it/it/home . In qualsiasi momento scrivendo /start ti ripeterò questo messaggio di benvenuto.\nQuesto bot, non ufficiale e non collegato con il sito del Governo Soldipubblici.gov.it, è stato realizzato da @piersoft e potete migliorare il codice sorgente con licenza MIT che trovate su https://github.com/piersoft/soldipubblicigovit."; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ",new chat started," . $chat_id . "\n"; file_put_contents(dirname(__FILE__) . '/./db/telegram.log', $log, FILE_APPEND | LOCK_EX); $this->create_keyboard_temp($telegram, $chat_id); exit; } elseif ($text == "Ente" || $text == "/ente") { $reply = "Digita direttamente il nome dell'Ente per conoscerne il Codice Ente che ti servirà per la ricerca delle spese. Esempio: Comune di Prato"; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ",Ente," . $chat_id . "\n"; file_put_contents(dirname(__FILE__) . '/./db/telegram.log', $log, FILE_APPEND | LOCK_EX); $this->create_keyboard_temp($telegram, $chat_id); exit; } elseif ($text == "Ricerca" || $text == "/ricerca") { $reply = "Scrivi in ordine: %codiceente ricavato dalla ricerca dell'Ente e poi la spesa da cercare anteponendo il carattere ?, ad esempio: %000705530?Spese postali per le Spese Postali inerenti il Comune di Lecce"; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ",ricerca," . $chat_id . "\n"; file_put_contents(dirname(__FILE__) . '/./db/telegram.log', $log, FILE_APPEND | LOCK_EX); $this->create_keyboard_temp($telegram, $chat_id); exit; } elseif (strpos($text, '/') === false) { function extractString($string, $start, $end) { $string = " " . $string; $ini = strpos($string, $start); if ($ini == 0) { return ""; } $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); } $string = 0; $img = curl_file_create('soldipubblici.png', 'image/png'); $contentp = array('chat_id' => $chat_id, 'photo' => $img); $telegram->sendPhoto($contentp); if (strpos($text, '%') !== false) { $codiceente = extractString($text, "%", "?"); $text = str_replace($codiceente, "", $text); $text = str_replace("%", "", $text); $text = str_replace("?", "", $text); $location = "Sto interrogando Soldipubblici.gov.it per\ncodice ente: " . $codiceente . "\ne per: " . $text; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $where = utf8_decode($text); $where = str_replace("?", "", $where); $where = str_replace(" ", "%20", $where); extract($_POST); $url = 'http://soldipubblici.gov.it/it/ricerca'; $ch = curl_init(); $file = fopen('db/spese.json', 'w+'); //da decommentare se si vuole il file locale curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8', 'Accept: Application/json', 'X-Requested-With: XMLHttpRequest', 'Content-Type: application/octet-stream', 'Content-Type: application/download', 'Content-Type: application/force-download', 'Content-Transfer-Encoding: binary ')); curl_setopt($ch, CURLOPT_POSTFIELDS, 'codicecomparto=PRO&codiceente=' . $codiceente . '&cosa=' . $where); curl_setopt($ch, CURLOPT_FILE, $file); curl_exec($ch); curl_close($ch); $json_string = file_get_contents("db/spese.json"); $parsed_json = json_decode($json_string); //var_dump( $parsed_json); // debug $count = 0; foreach ($parsed_json->{'data'} as $data => $csv1) { $count = $count + 1; } if ($count == 0) { $location = "Nessun risultato trovato"; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $this->create_keyboard_temp($telegram, $chat_id); exit; } $temp_c1 = ""; for ($i = 0; $i < $count; $i++) { $temp_c1 .= "\n\n"; $mese = substr_replace($parsed_json->{'data'}[$i]->{'imp_uscite_att'}, ",", -2, 0); $annoprecedente = substr_replace($parsed_json->{'data'}[$i]->{'importo_2014'}, ",", -2, 0); $annoincorso = substr_replace($parsed_json->{'data'}[$i]->{'importo_2015'}, ",", -2, 0); $temp_c1 .= "Ricerca per: " . $parsed_json->{'data'}[$i]->{'ricerca'} . "\nTrovata la voce: " . $parsed_json->{'data'}[$i]->{'descrizione_codice'} . "\nCodice Siope: " . $parsed_json->{'data'}[$i]->{'codice_siope'} . "\nNel periodo " . $parsed_json->{'data'}[$i]->{'periodo'} . "/" . $parsed_json->{'data'}[$i]->{'anno'} . " spesi: " . $mese . "€\nNel 2014 sono stati spesi: " . $annoprecedente . "€\nIl progressivo 2015 è " . $annoincorso . "€"; $temp_c1 .= "\n"; } $chunks = str_split($temp_c1, self::MAX_LENGTH); foreach ($chunks as $chunk) { $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true); $telegram->sendMessage($content); } $this->create_keyboard_temp($telegram, $chat_id); $log = $today . ",spese," . $chat_id . "\n"; file_put_contents(dirname(__FILE__) . '/./db/telegram.log', $log, FILE_APPEND | LOCK_EX); exit; } else { $where = $text; $where = utf8_decode($where); $where = str_replace("?", "", $where); $where = str_replace(" ", "%20", $where); extract($_POST); $url = 'http://soldipubblici.gov.it/it/chi/search/' . $where; $ch = curl_init(); $file = fopen('db/entespese.json', 'w+'); //da decommentare se si vuole il file locale curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8', 'Accept: Application/json', 'X-Requested-With: XMLHttpRequest', 'Content-Type: application/octet-stream', 'Content-Type: application/download', 'Content-Type: application/force-download', 'Content-Transfer-Encoding: binary ')); //curl_setopt($ch,CURLOPT_POSTFIELDS, $where); curl_setopt($ch, CURLOPT_FILE, $file); curl_exec($ch); curl_close($ch); $json_string = file_get_contents("db/entespese.json"); $parsed_json = json_decode($json_string); // var_dump($parsed_json[0]->{'ripartizione_geografica'}); // debug $count = 0; foreach ($parsed_json as $data => $csv1) { $count = $count + 1; } if ($count == 0) { $location = "Nessun risultato trovato"; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $this->create_keyboard_temp($telegram, $chat_id); exit; } //echo $count; $temp_c1 = ""; $temp_c1 .= "\nEnte: " . $parsed_json[0]->{'descrizione_ente'}; $temp_c1 .= "\nRicerca per comparto: " . $parsed_json[0]->{'codice_sottocomparto'}; $temp_c1 .= "\nNumero abitanti: " . $parsed_json[0]->{'numero_abitanti'}; $temp_c1 .= "\nCodice Ente: " . $parsed_json[0]->{'codice_ente'}; $chunks = str_split($temp_c1, self::MAX_LENGTH); foreach ($chunks as $chunk) { $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true); $telegram->sendMessage($content); } $location = "ora puoi interrogare il database digitando ad esempio: %" . $parsed_json[0]->{'codice_ente'} . "?spese postali "; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $this->create_keyboard_temp($telegram, $chat_id); $log = $today . ",codice ente," . $chat_id . "\n"; file_put_contents(dirname(__FILE__) . '/./db/telegram.log', $log, FILE_APPEND | LOCK_EX); exit; } } $this->create_keyboard_temp($telegram, $chat_id); }
<?php //$partenza="Bari-Matera"; //$ore="5"; //$minuti="11"; //$datad="11/01/2016"; $mezzo = "1"; $testo = $_POST["q"]; //$testo="bm%11/01/2016?5-11"; $datad = extractString($testo, "%", "?"); $ore = extractString($testo, "?", "-"); $minuti = substr($testo, -2, 2); $partenza = substr($testo, 0, 2); // echo $partenza; // echo $minuti; function extractString($string, $start, $end) { $string = " " . $string; $ini = strpos($string, $start); if ($ini == 0) { return ""; } $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); } if ($partenza == "bm" || $partenza == "BM") { $partenza = "partenza=36&arrivo=5"; } else { $partenza = "partenza=5&arrivo=36"; }
function shell($inline_query, $telegram, $text, $chat_id, $user_id, $location, $reply_to_msg) { date_default_timezone_set('Europe/Rome'); $today = date("Y-m-d H:i:s"); // if (strpos($text,'@viaggiareinpugliabot') !== false) $text=str_replace("@viaggiareinpugliabot ","",$text); if ($text == "/start" || $text == "Info") { $img = curl_file_create('puglia.png', 'image/png'); $contentp = array('chat_id' => $chat_id, 'photo' => $img); $telegram->sendPhoto($contentp); $reply = "Benvenuto. Per ricercare un luogo di interesse turistico, culturale censito da ViaggiareinPuglia.it, digita il nome del Comune oppure clicca sulla graffetta (📎) e poi 'posizione' . Puoi anche ricercare per parola chiave nel titolo anteponendo il carattere ?. Verrà interrogato il DataBase openData utilizzabile con licenza IoDL2.0 presente su http://www.dataset.puglia.it/dataset/luoghi-di-interesse-turistico-culturale-naturalistico . In qualsiasi momento scrivendo /start ti ripeterò questo messaggio di benvenuto.\nQuesto bot, non ufficiale e non collegato con il marchio regionale ViaggiareinPuglia.it, è stato realizzato da @piersoft e potete migliorare il codice sorgente con licenza MIT che trovate su https://github.com/piersoft/viaggiareinpugliabot. La propria posizione viene ricercata grazie al geocoder di openStreetMap con Lic. odbl."; $reply .= "\nWelcome. To search for a place of tourist, cultural surveyed by ViaggiareinPuglia.it, type the name of the municipality or click on the paper clip (📎) and then 'position'. You can also search by keyword in the title prefixing the character ?. Will be questioned DataBase OpenData IoDL2.0 used with this license on http://www.dataset.puglia.it/dataset/luoghi-di-interesse-turistico-culturale-naturalistico. At any time by writing /start will repeat this message of welcome. \nThis bots, unofficial and unconnected with the regional brand ViaggiareinPuglia.it, has been realized by @piersoft and you can improve the source code under the MIT license that found on https://github.com/piersoft/viaggiareinpugliabot. Its position is searched through the geocoder OpenStreetMap with Lic. ODbL."; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ";new chat started;" . $chat_id . "\n"; $this->create_keyboard_temp($telegram, $chat_id); exit; } elseif ($text == "Città /City") { $reply = "Digita direttamente il nome del Comune. / Type city or Town"; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ";new chat started;" . $chat_id . "\n"; exit; } elseif ($text == "Ricerca/Search") { $reply = "Digita la parola da cercare anteponendo il carattere ?, ad esempio: ?Chiesa Matrice"; $reply .= "\nType in the search word by prefixing the character?, For example: ?Chiesa Matrice"; $content = array('chat_id' => $chat_id, 'text' => $reply, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $log = $today . ";new chat started;" . $chat_id . "\n"; exit; } elseif (strpos($inline_query["location"], '.') !== false) { $this->location_manager_inline($inline_query, $telegram, $user_id, $chat_id, $location); exit; } elseif ($text == "/location" || $text == "Posizione") { $option = array(array($telegram->buildKeyboardButton("Invia la tua posizione / send your location", false, true))); // Create a permanent custom keyboard $keyb = $telegram->buildKeyBoard($option, $onetime = false); $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "Attiva la localizzazione sul tuo smartphone / Turn on your GPS"); $telegram->sendMessage($content); exit; } elseif ($location != null) { $this->location_manager($telegram, $user_id, $chat_id, $location); exit; } else { function extractString($string, $start, $end) { $string = " " . $string; $ini = strpos($string, $start); if ($ini == 0) { return ""; } $ini += strlen($start); $len = strpos($string, $end, $ini) - $ini; return substr($string, $ini, $len); } if (strpos($text, ' ') !== false) { $text = extractString($text, "/", " "); } if (strpos($text, '1') !== false || strpos($text, '2') !== false || strpos($text, '3') !== false || strpos($text, '4') !== false || strpos($text, '5') !== false || strpos($text, '6') !== false || strpos($text, '7') !== false || strpos($text, '8') !== false || strpos($text, '9') !== false) { $text = "/" . $text; } $string = 0; $optionf = array([]); if (strpos($text, '?') !== false) { $text = str_replace("?", "", $text); $location = "Sto cercando i luoghi aventi nel titolo: " . $text; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $string = 1; // sleep (1); } elseif (strpos($text, '/') === false) { $location = "Sto cercando i luoghi di interesse per località comprendente: " . $text; $location .= "\nI'm looking for the places of interest in locations including:" . $text; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $string = 0; // sleep (1); } elseif (strpos($text, '/') !== false) { $text = str_replace("/", "", $text); $string = 2; } $urlgd = "db/luoghi.csv"; $inizio = 0; $homepage = ""; $csv = array_map('str_getcsv', file($urlgd)); $count = 0; foreach ($csv as $data => $csv1) { $count = $count + 1; } if ($count == 0 || $count == 1) { $location = "Nessun luogo trovato / No founds"; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); } function decode_entities($textt) { $textt = htmlentities($textt, ENT_COMPAT, 'ISO-8859-1', true); $textt = preg_replace('/&#(\\d+);/me', "chr(\\1)", $textt); #decimal notation $textt = preg_replace('/&#x([a-f0-9]+);/mei', "chr(0x\\1)", $textt); #hex notation $textt = html_entity_decode($textt, ENT_COMPAT, "UTF-8"); #NOTE: UTF-8 does not work! return $textt; } $result = 0; $ciclo = 0; //if ($count > 40) $count=40; for ($i = $inizio; $i < $count; $i++) { if ($string == 1) { $filter = strtoupper($csv[$i][0]); } elseif ($string == 0) { $filter = strtoupper($csv[$i][3]); } elseif ($string == 2) { $content = array('chat_id' => $chat_id, 'text' => $text, 'disable_web_page_preview' => true); $telegram->sendMessage($content); $i = intval($text); $result = 1; $homepage .= "\nID: /" . $i . "\n"; $homepage .= "Nome: / Name: " . decode_entities($csv[$i][0]) . "\n"; $homepage .= "Risorsa: / Resource: " . decode_entities($csv[$i][1]) . "\n"; if ($csv[$i][4] != NULL) { $homepage .= "Indirizzo: / Address: " . decode_entities($csv[$i][4]); } if ($csv[$i][5] != NULL) { $homepage .= ", " . decode_entities($csv[$i][5]); } $homepage .= "\n"; if ($csv[$i][3] != NULL) { $homepage .= "Comune: / City: " . decode_entities($csv[$i][3]) . "\n"; } if (strpos($csv[$i][10], 'http') !== false) { $homepage .= "Web: " . decode_entities($csv[$i][9]) . "\n"; } if ($csv[$i][10] != NULL) { $homepage .= "Email: " . decode_entities($csv[$i][10]) . "\n"; } // if($csv[$i][22] !=NULL) $homepage .="Descrizione: ".substr(decode_entities($csv[$i][22]), 0, 400)."..[....]\n"; if ($csv[$i][11] != NULL) { $homepage .= "Tel: " . decode_entities($csv[$i][11]) . "\n"; } if ($csv[$i][14] != NULL) { $homepage .= "Servizi: / Service: " . $csv[$i][14] . "\n"; } if ($csv[$i][15] != NULL) { $homepage .= "Attrezzature: / Various: " . decode_entities($csv[$i][15]) . "\n"; } if ($csv[$i][16] != NULL) { $homepage .= "Foto1: / Photo1: " . decode_entities($csv[$i][16]) . "\n"; } if ($csv[$i][17] != NULL) { $homepage .= "(realizzata da: / By: " . decode_entities($csv[$i][17]) . ")\n"; } if ($csv[$i][18] != NULL) { $homepage .= "Foto2: / Photo2: " . decode_entities($csv[$i][18]) . "\n"; } if ($csv[$i][19] != NULL) { $homepage .= "(realizzata da: / By: " . decode_entities($csv[$i][19]) . ")\n"; } $homepage .= "\n____________\n"; $chunks = str_split($homepage, self::MAX_LENGTH); foreach ($chunks as $chunk) { $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => false); $telegram->sendMessage($content); if ($csv[$i][7] != NULL) { $homepagemappa = "http://www.openstreetmap.org/?mlat=" . $csv[$i][7] . "&mlon=" . $csv[$i][8] . "#map=19/" . $csv[$i][7] . "/" . $csv[$i][8]; $option = array(array($telegram->buildInlineKeyboardButton("MAPPA", $url = $homepagemappa))); $keyb = $telegram->buildInlineKeyBoard($option); $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "<b>Vai alla</b>", 'parse_mode' => "HTML"); $telegram->sendMessage($content); // $homepage .="Mappa: / Map: \n"; } } $this->create_keyboard_temp($telegram, $chat_id); exit; } if (strpos(decode_entities($filter), strtoupper($text)) !== false) { $ciclo++; // if ($ciclo >40) exit; array_push($optionf, ["/" . $i . " " . decode_entities($csv[$i][0])]); $result = 1; $homepage .= "\nClicca l'ID per dettagli: /" . $i . "\n"; $homepage .= "Nome: / Name: " . decode_entities($csv[$i][0]) . "\n"; /* $homepage .="Risorsa: / Resource: ".decode_entities($csv[$i][1])."\n"; if($csv[$i][4] !=NULL) $homepage .="Indirizzo: / Address: ".decode_entities($csv[$i][4]); if($csv[$i][5] !=NULL) $homepage .=", ".decode_entities($csv[$i][5]); $homepage .="\n"; if($csv[$i][3] !=NULL)$homepage .="Comune: / City: ".decode_entities($csv[$i][3])."\n"; if($csv[$i][9] !=NULL)$homepage .="Web: ".decode_entities($csv[$i][9])."\n"; if($csv[$i][10] !=NULL) $homepage .="Email: ".decode_entities($csv[$i][10])."\n"; // if($csv[$i][22] !=NULL) $homepage .="Descrizione: ".substr(decode_entities($csv[$i][22]), 0, 400)."..[....]\n"; if($csv[$i][11] !=NULL) $homepage .="Tel: ".decode_entities($csv[$i][11])."\n"; if($csv[$i][14] !=NULL) $homepage .="Servizi: / Service: ".decode_entities($csv[$i][14])."\n"; if($csv[$i][15] !=NULL) $homepage .="Attrezzature: / Various: ".decode_entities($csv[$i][15])."\n"; if($csv[$i][16] !=NULL) $homepage .="Foto1: / Photo1".decode_entities($csv[$i][16])."\n"; if($csv[$i][17] !=NULL) $homepage .="(realizzata da: / By: ".decode_entities($csv[$i][17]).")\n"; if($csv[$i][18] !=NULL) $homepage .="Foto2: / Photo2: ".decode_entities($csv[$i][18])."\n"; if($csv[$i][19] !=NULL) $homepage .="(realizzata da: / By: ".decode_entities($csv[$i][19]).")\n"; if($csv[$i][7] !=NULL){ $homepage .="Mappa: / Map: \n"; $homepage .= "http://www.openstreetmap.org/?mlat=".$csv[$i][7]."&mlon=".$csv[$i][8]."#map=19/".$csv[$i][7]."/".$csv[$i][8]; } */ $homepage .= "____________\n"; } if ($ciclo > 300) { $location = "Troppi risultati per essere visualizzati (più di 300). Restringi la ricerca"; $location .= "\nToo many results to be displayed (more than 300). Narrow Search"; $content = array('chat_id' => $chat_id, 'text' => $location, 'disable_web_page_preview' => true); $telegram->sendMessage($content); exit; } } $chunks = str_split($homepage, self::MAX_LENGTH); foreach ($chunks as $chunk) { $content = array('chat_id' => $chat_id, 'text' => $chunk, 'disable_web_page_preview' => true); $telegram->sendMessage($content); } $keyb = $telegram->buildKeyBoard($optionf, $onetime = false); $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => $ciclo . " luoghi/places"); $telegram->sendMessage($content); $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "[Clicca su ID per dettagli / Click on ID for details]"); $telegram->sendMessage($content); } // $this->create_keyboard_temp($telegram,$chat_id); }
function logIn($data) { if (isset($data->x) && isset($data->y)) { $userdetails = extractString($data->x); $cookie = $data->y; } else { $userdetails = "anon"; $cookie = "none"; } $ok = TRUE; $keksi = trim(file_get_contents(KARTAT_DIRECTORY . "keksi.txt")); //rg2log("logIn ".$userdetails." ".$cookie); if (file_exists(KARTAT_DIRECTORY . "rg2userinfo.txt")) { $saved_user = trim(file_get_contents(KARTAT_DIRECTORY . "rg2userinfo.txt")); $temp = crypt($userdetails, $saved_user); if ($temp != $saved_user) { //rg2log("User details incorrect. ".$temp." : ".$saved_user); $ok = FALSE; } if ($keksi != $cookie) { //rg2log("Cookies don't match. ".$keksi." : ".$cookie); $ok = FALSE; } } else { // new account being set up: rely on JS end to force a reasonable name/password $temp = crypt($userdetails, $keksi); rg2log("Creating new account " . $temp); file_put_contents(KARTAT_DIRECTORY . "rg2userinfo.txt", $temp . PHP_EOL); } return $ok; }