Guest User

Untitled

a guest
Jan 24th, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.08 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. ustvari mysql tabelo:
  5.  
  6. CREATE TABLE IF NOT EXISTS `impm` (
  7.   `id` int(11) NOT NULL AUTO_INCREMENT,
  8.   `pmid` int(11) NOT NULL,
  9.   `pmtime` varchar(32) NOT NULL,
  10.   KEY `id` (`id`)
  11. ) DEFAULT CHARSET=utf8
  12.  
  13. prilozi simple_html_dom.php (http://simplehtmldom.sourceforge.net/)
  14. http://sourceforge.net/projects/simplehtmldom/files/simplehtmldom/1.11/simplehtmldom_1_11.zip/download
  15.  
  16.  */
  17.  
  18. //config//
  19.  
  20. $DBhost = "localhost";
  21. $DBusername = "";
  22. $DBpassword = "";
  23. $DBname = "";
  24. $IMuser = "";
  25. $IMpass = "";
  26. $demail = "";
  27.  
  28. //end config//
  29.  
  30. include('simple_html_dom.php');
  31.  
  32. mysql_connect($DBhost, $DBusername, $DBpassword) or die(mysql_error());
  33. mysql_select_db($DBname) or die(mysql_error());
  34.  
  35. $pmsindb = mysql_query("SELECT * FROM `impm`");
  36.  
  37. while ($row = mysql_fetch_assoc($pmsindb)) {
  38.    $allpmsids[] = $row['pmid'];
  39.    $allpmtimes[$row['pmid']] = $row['pmtime'];
  40. }
  41.  
  42. function send_email($title, $demail){
  43.  
  44.     $subject = "IM forum - Novo zasebno sporočilo: ".$title;
  45.     $message = "Prejel si novo sporočilo na IM forumu. http://www.internetmojster.com/zs/";
  46.     $headers = "From: [email protected]" . "\r\n" .
  47.         "Reply-To: ".$demail." \r\n" .
  48.         "X-Mailer: PHP/" . phpversion();
  49.     mail($demail, $subject, $message, $headers);
  50.  
  51. }
  52.  
  53. $ch = curl_init();
  54. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  55. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  56. curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
  57. curl_setopt($ch, CURLOPT_HEADER, 0);
  58. curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile.txt");
  59. curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile.txt");
  60. curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
  61. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  62.  
  63. curl_setopt($ch, CURLOPT_URL, 'http://www.internetmojster.com/?xajax=auth%2Flogin&xajaxr=1295878324505&xajaxargs[]=%3Cxjxquery%3E%3Cq%3Euname%3D'.$IMuser.'%26pwd%3D'.$IMpass.'%26remember%3Don%3C%2Fq%3E%3C%2Fxjxquery%3E');
  64. $login_return = (string)curl_exec($ch);
  65. $is_logged_in = strpos($login_return, "Prijava je bila uspešna!");
  66.  
  67. if($is_logged_in == false){
  68.  
  69.     print ("Prijava v IM ni uspela.");
  70.    
  71. } else {
  72.    
  73.     curl_setopt($ch, CURLOPT_URL, 'http://www.internetmojster.com/zs/');
  74.     $zspage = curl_exec($ch);
  75.     $zshtml = str_get_html($zspage);
  76.    
  77.     $i=0;
  78.     foreach($zshtml->find('td[class=icon first new]') as $unread){
  79.    
  80.         $strhtml = $unread->parent();
  81.        
  82.         foreach($strhtml->find('.ts') as $e2){
  83.             $hashtimes[] = hash('md5', (string)$e2->innertext);
  84.         }
  85.  
  86.         foreach($strhtml->find('.big') as $e){
  87.  
  88.             $title = $e->innertext;
  89.             $id_arr = explode("/", $e->href);
  90.  
  91.             if (!in_array($id_arr[2], $allpmsids)){ //nov pm, dodaj
  92.                 $query = mysql_query("INSERT INTO `impm` (`pmid`, `pmtime`) VALUES (".intval($id_arr[2]).", '".$hashtimes[$i]."')");
  93.                 send_email($title, $demail);
  94.                    
  95.             } else if ($allpmtimes[intval($id_arr[2])] != $hashtimes[$i]){  //"star" zelen pm, glej ce je nov time
  96.            
  97.                 $query = mysql_query("UPDATE `impm` SET `pmtime` = '".$hashtimes[$i]."' WHERE `pmid` = ".intval($id_arr[2]));
  98.                 send_email($title, $demail);
  99.             }
  100.         }
  101.     $i++;
  102.     }
  103. }
  104.  
  105. mysql_close();
  106. curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment