%PDF- %PDF-
Direktori : /www/old2/_music/ingress/ |
Current File : /www/old2/_music/ingress/decode.php |
<?php define('SUB_MAIL', 1); define('SUB_JABBER', 2); require("class.jabber.php"); include "nette.php"; use Nette\Mail\Message; function HTTPGet($url) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0"); curl_setopt($curl, CURLOPT_ENCODING, ""); $page = curl_exec($curl); curl_close($curl); return $page; } function q($query,$assoc=0) { global $queries; $r = @mysql_query($query); $queries++; if( mysql_errno() ) { $error = 'MYSQL ERROR #'.mysql_errno().' : <small>' . mysql_error(). "</small><br><VAR>$query</VAR>"; echo($error); return FALSE; } $queries++; if( strtolower(substr($query,0,6)) != 'select' ) return array(mysql_affected_rows(),mysql_insert_id()); $count = @mysql_num_rows($r); if( !$count ) return 0; if( $count == 1 ) { if( $assoc ) $f = mysql_fetch_assoc($r); else $f = mysql_fetch_row($r); mysql_free_result($r); if( count($f) == 1 ) { list($key) = array_keys($f); return $f[$key]; } else { $all = array(); $all[] = $f; return $all; } } else { $all = array(); for( $i = 0; $i < $count; $i++ ) { if( $assoc ) $f = mysql_fetch_assoc($r); else $f = mysql_fetch_row($r); $all[] = $f; } mysql_free_result($r); return $all; } } function AuthJabber() { global $jabber; $jabber = new Jabber; $jabber->host = "vserver.varak.net"; $jabber->server = "prestiz-pyco.eu"; $jabber->port = 5222; $jabber->username = "ingress"; $jabber->password = "marfusa112"; $jabber->resource = "ClassJabberPHP"; //For debug purpose $jabber->enable_logging = TRUE; $jabber->log_filename = '/www/music/ingress/jabb.log'; $jabber->Connect() or die("ERROR: couldn't connect!\n"); $jabber->SendAuth() or die("ERROR: couldn't authenticate!\n"); } $toBeSent = array(); $jabber = null; $spojeni = mysql_connect("localhost", "waritko", "blade666"); mysql_select_db("ingress", $spojeni); //$maxid = q("select max(codeid) from decode"); $known = array(); $res = q("select code from decode order by id desc"); foreach($res as $r) { $known[] = trim($r[0]); } header("Content-type: text/plain"); $text = HTTPGet("http://decodeingress.me/category/code/"); preg_match_all('#<article id="post-([0-9]+)".*?<a href="(http://decodeingress.me/[0-9]+/[0-9]+/[0-9]+/passcode-([a-zA-Z0-9]+)/)">.*?</article>#ims', $text, $matches); for($i = 0; $i < count($matches); $i++) { $codeid = $matches[1][$i]; $codelink = $matches[2][$i]; $code = $matches[3][$i]; if(!in_array(trim($code), $known)) { q("insert into decode(codeid, code, link) values($codeid, '$code', '$codelink')"); /// BODY $body = "New Ingress code!!! Code: $code Source: $codelink"; /// END BODY $toBeSent[] = $body; } } ?> <?php $data = HTTPGet("https://www.googleapis.com/plus/v1/activities?query=%23ingresspasscode&orderBy=recent&maxResults=20&key=AIzaSyD_MNLtW06c-Zpmg-TjFnS_84DqKSE6i5Y"); $obj = json_decode($data); foreach($obj->items as $item) { $post = $item->url; $cont = $item->object->attachments[0]->content; preg_match("/Passcode: +([0-9A-Za-z]+)/", $item->object->attachments[0]->displayName, $matches); $code = $matches[1]; $body = "New DeCode Ingress code!!! Code: $code Google+ post link: $post Content: $cont"; //echo $body."\n\n"; if(!in_array(trim($code), $known)) { $toBeSent[] = $body; q("insert into decode(codeid, code, link) values(0, '$code', '$post')"); } } // Send found codes if(count($toBeSent) > 0) { AuthJabber(); foreach($toBeSent as $msg) { $res = q("select address from decode_subscribe where type=".SUB_MAIL); foreach($res as $r) { $mail = new Message; $mail->setFrom('Waritko <martin@varak.net>') ->addTo($r[0]) ->setSubject('DeCode Ingress code') ->setBody($msg) ->send(); } $res = q("select address from decode_subscribe where type=".SUB_JABBER); foreach($res as $r) { if(!$jauth) { AuthJabber(); $jauth = true; } $jabber->SendMessage($r[0], "chat", NULL, array("body" => $msg)); } } $jabber->Disconnect(); } mysql_close($spojeni); ?>