admin Founder


Registrato: Oct 03, 2008 Messaggi: 261
|
Inviato: Mer Apr 15, 2009 9:11 pm Oggetto: [PHP] HTML Source Downloader (phpgtk 2) |
|
|
| Codice: | <?php
function scarica(){
global $sito, $file;
//prende i testi dai form
$html = $sito->get_text();
$destinazione = $file->get_text();
//controlla prefisso html
if(array_shift(explode("://", $html)) != "http")
die(errore("URL non valido", "Errore"));
if(array_pop(explode(".", $destinazione)) != "txt")
die(errore("Destinazione non valida", "Errore"));
//scrivi
$scrivi = fopen($destinazione, "w+")
or die(errore("Errore nell'aprire il file di destinazione!", "Errore"));
fwrite($scrivi, file_get_contents($html))
or die(errore("Errore nel scaricare la pagina!", "Errore"));
fclose($scrivi);
die(errore("Sorgente $html salvato correttamente in $destinazione", "OK!"));
//reset form
$sito->set_text("");
$file->set_text("");
}
function errore($msg, $title){
$alert = new GtkDialog();
$alert->set_default_size(180, 150);
$alert->set_title($title);
$alert->connect_simple("destroy", array("gtk", "main_quit"));
$errore = new GtkLabel($msg);
$errore->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#FF0000"));
$top = $alert->vbox;
$top->pack_start($hbox = new GtkHBox());
$hbox->pack_start($errore);
$alert->add_button(Gtk::STOCK_OK, Gtk::RESPONSE_OK);
$alert->show_all();
$alert->run();
}
$finestra = new GtkWindow(); //creo la finestra
$finestra->set_title("HTML Downloader"); //dò il nome alla finestra
$finestra->set_default_size(180, 150);
$finestra->connect_simple('destroy', array('gtk','main_quit'));
//inputbox sito
$sito = new GtkEntry();
$sito->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse("#FFCC66"));
//inputbox file
$file = new GtkEntry();
$file->modify_bg(Gtk::STATE_NORMAL, GdkColor::parse("#FFCC66"));
//text sito
$text_sito = new GtkLabel("Inserisci sito:");
//text file
$text_file = new GtkLabel("Inserisci file di destinazione:");
//bottoni
$b1 = new GtkButton("Ok!");
$b1->connect_simple('clicked', 'scarica');
$b1->modify_bg(Gtk::STATE_NORMAL, GdkCOlor::parse("#CCFF99"));
$table1 = new GtkTable();
$table1->attach($text_sito, 0, 1, 1, 2);
$table1->attach($sito, 0, 2, 2, 3);
$table1->attach($text_file, 0, 3, 3, 4);
$table1->attach($file, 0, 4, 4, 5);
if(isset($errore))
$table1->attach($errore, 0, 5, 5, 6);
$table1->attach($b1, 0, 6, 6, 7);
$finestra->add($table1);
$finestra->show_all();
Gtk::main();
?> |
screen : http://img100.imageshack.us/img100/6049/screenshotmx7.jpg |
|