Kodlarda yeteri kadar açıklama mevcut diye düşünerekten ayrıca bir açıklama yazmayacağım.
Bu kodların sadece linuxda çalışabileceğini de ekleyeyim.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | /** * @author Ersin DOĞAN http ://www.ersindogan.com * Gmail posta kontrolü yapan basit bir servis */ class GmailServis { /** * gmail kullanıcı adı * * @var string */ protected $_kullanici = null; /** * gmail şifre * * @var string */ protected $_sifre = null; /** * gmail feed adresi , öntanımlı olan yeterli şimdilik * * @var string */ protected $_servis_url = null; /** * Objenin kurucu metodu * * @param string $kullanici * @param string $sifre * @param string $servis_url */ public function __construct($kullanici, $sifre, $servis_url = 'https://mail.google.com/mail/feed/atom') { $this->_kullanici = $kullanici; $this->_sifre = $sifre; $this->_servis_url = $servis_url; if (empty ( $this->_kullanici ) || empty ( $this->_sifre ) || empty ( $this->_servis_url )) { throw new Exception ( "Kullanıcı adı , şifre veya servis adreslerinden birini eksik girdiniz" ); } } /** * Posta kutusunu kontrol eder * * @return SimplXMLElement */ public function kontrol_et() { $_c = curl_init ( $this->_servis_url ); curl_setopt ( $_c, CURLOPT_USERPWD, $this->_kullanici . ':' . $this->_sifre ); curl_setopt ( $_c, CURLOPT_HTTPAUTH, CURLAUTH_ANY ); curl_setopt ( $_c, CURLOPT_SSL_VERIFYPEER, 0 ); curl_setopt ( $_c, CURLOPT_RETURNTRANSFER, 1 ); return simplexml_load_string ( curl_exec ( $_c ) ); } } class GmailKontrol extends GtkWindow { /** * * * @var GtkVBox */ protected $kutu; /** * * * @var integer */ protected $durum; /** * * * @var GtkLabel */ protected $eposta_durum; /** * * @var GtkStatusIcon */ protected $status_icon; /** * * @var GmailServis */ protected $servis; function __construct() { parent::__construct(); $this->set_default_size(200,200); $this->set_position(Gtk::WIN_POS_CENTER_ALWAYS); $this->set_title('.::Gmail E-Posta Kontrol::.'); $this->connect_simple('destroy', array('gtk', 'main_quit')); $this->add($this->__create_box()); $this->hide_all(); } /** * arayüzü oluşturuyoruz * * @return GtkVBox */ protected function __create_box() { $this->kutu = new GtkVBox ( ); $this->eposta_durum = new GtkLabel ( "GKontrol - Gmail Eposta Kontrol Aracı" ); $this->kutu->pack_start ( $this->eposta_durum ); $this->status_icon = new GtkStatusIcon ( ); $this->status_icon->set_from_stock ( Gtk::STOCK_NO ); $this->status_icon->set_tooltip_text ( 'Gmail E-Posta Kontrol' ); $this->status_icon->connect ( 'activate', array ($this, 'on_activate' ) ); $this->durum = 0; return $this->kutu; } /** * mailleri kontrol ederek * mail geldiğinde bizi uyarıyor. * */ public function mail_kontrol(){ $durum=$this->servis->kontrol_et(); if($durum->fullcount>0){ $this->bildirim('GPosta','Okunmammış '.$durum->fullcount.' epostanız mevcut'); $this->status_icon->set_from_stock(Gtk::STOCK_YES); $this->status_icon->set_blinking(true); }else { $this->bildirim('GPosta','yeni eposta yok'); } } /** * notification iconuna tıklandığında * çalışan metotdur * * @param $statusicon */ public function on_activate($statusicon) { if ($this->durum) { $this->hide_all (); $this->durum = 0; } else { $this->show_all (); $this->status_icon->set_from_stock(Gtk::STOCK_NO); $this->status_icon->set_blinking(false); $this->durum = 1; } } /** * bildirim başlığı * * @param string $baslik * @param string $bildirim */ public function bildirim($baslik,$bildirim){ // notify-send bir linux aracıdır ve bunu sisteminizde yoksa kurmalısınız // sudo apt-get install libnotify-bin // komutu ile $komut=sprintf('notify-send "%s" "%s" -t 1',$baslik,$bildirim); system($komut); } public function servisAyarla(GmailServis $servis){ $this->servis=$servis; } } $gKontrol=new GmailKontrol(); $gServis=new GmailServis ( 'kullanıcı-adı', 'şifre' ); $gKontrol->servisAyarla($gServis); /** * Gtk::timeout_add metodu, zamanlayıcı özelliği ile * bize, belirli aralıklarda gmail * posta kutusunu yoklama şansını veriyor */ Gtk::timeout_add(2000, array($gKontrol,'mail_kontrol')); Gtk::main(); |