gtk-rss-reader

Gesponsorde koppelingen

PHP script bestanden

  1. gtk-rss-reader

« Lees de omschrijving en reacties

// rss_class.php

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?
if(!extension_loaded('gtk')) {    
    dl( 'php_gtk.' . PHP_SHLIB_SUFFIX);
}


class rss_reader {
var
$CONFIG, $widgets, $rss_array;

function
rss_reader ($url = "http://www.phphulp.nl/feeds/phphulp_forum.xml",$rate = 30, $browser = "firefox.exe",$tooltips = true) {
if (preg_match('#^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $url)) {
$this->CONFIG['feed'] = $url; // set de url van de rss feed.
} else {
$this->CONFIG['feed'] = false;
}

if (is_numeric($rate)) {
$this->CONFIG['refresh'] = $rate; // set de refresh snelheid
} else {
$this->CONFIG['refresh'] = 30;
}

if (is_bool($tooltips)) {
$this->CONFIG['tooltips'] = $tooltips;
}
else {
$this->CONFIG['tooltips'] = true;
}

$this->CONFIG['browser'] = $browser;
}

function
change_refresh ($rate) {
if (is_numeric($rate)) {
$this->CONFIG['refresh'] = $rate; // set de refresh snelheid
} else {
$this->CONFIG['refresh'] = 30;
}
}

function
change_browser ($browser) {
$this->CONFIG['browser'] = $browser;
}

function
change_tooltips ($tooltips) {
if (is_bool($tooltips)) {
$this->CONFIG['tooltips'] = $tooltips;
}
else {
$this->CONFIG['tooltips'] = true;
}
}

function
change_url ($url) {
if (preg_match('#^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $url)) {
$this->CONFIG['feed'] = $url; // set de url van de rss feed.
} else {
$this->CONFIG['feed'] = false;
}
}


function
build_window () {
$this->widgets['window'] = &new GtkWindow(GTK_WINDOW_DIALOG);
$this->widgets['window']->set_name('Rss feeds');
$this->widgets['window']->set_title('Rss feeds');
$this->widgets['window']->set_usize(500,400);
$this->widgets['window']->connect_object('destroy', array('gtk', 'main_quit'));
$this->widgets['window']->set_border_width(10);
$this->widgets['window']->set_position(GTK_WIN_POS_CENTER);
}


function
show_rss () {

// Get rss feeds;
$old_rss = $this->rss_array;
$this->rss_array = $this->getRssFeeds("Rss feed", $this->CONFIG['feed']);
if (count($this->rss_array) > 0 && $this->rss_array != $old_rss) {
if ($this->widgets['window']->child) $this->widgets['window']->remove($this->widgets['window']->child);

if ($this->CONFIG['tooltips']) $tooltips = &new GtkTooltips();

$scrolledwindow = &new GtkScrolledWindow();
$scrolledwindow->set_policy(GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);

$this->widgets['window']->add($scrolledwindow);

$table = &new GtkTable(count($rss_array),1,true);

    $scrolledwindow->add_with_viewport($table);

foreach ($this->rss_array as $key => $val) {
if ($val['pubdate']) {
$date = date("H:i",$val['pubdate']);
}

$button[$key] = &new GtkButton($date . " " . $this->dec_str(strip_tags(html_entity_decode($val['title']))));
$button[$key]->connect('released', array($this,'open_url'),$val['link']);
$button[$key]->set_relief(GTK_RELIEF_NONE);
if ($this->CONFIG['tooltips']) $tooltips->set_tip($button[$key], trim(strip_tags(html_entity_decode(str_replace("\n"," ",$val['description'])))), '');
$table->attach_defaults($button[$key],0,1,$key,$key + 1);
$this->change_style($button[$key]);
}

$this->change_style($table);
$this->change_style($scrolledwindow);
$this->change_style($this->widgets['window']);
$this->widgets['window']->show_all();
}
elseif (!$this->widgets['window']->child) {
$scrolledwindow = &new GtkScrolledWindow();
$scrolledwindow->set_policy(GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);

$this->widgets['window']->add($scrolledwindow);

$table = &new GtkTable(count($rss_array),1,true);

    $scrolledwindow->add_with_viewport($table);
$key = 0;
$button[$key] = &new GtkButton("Click to refresh");
$button[$key]->connect('released', '$this->show_rss');
$button[$key]->set_relief(GTK_RELIEF_NONE);
$table->attach_defaults($button[$key],0,1,$key,$key + 1);
$this->change_style($button[$key]);

$this->change_style($table);
$this->change_style($scrolledwindow);
$this->change_style($this->widgets['window']);
$this->widgets['window']->show_all();
}

return true;
}

function
start_reading () {
gtk::timeout_add($this->CONFIG['refresh'] * 1000, array($this,'show_rss'));
gtk::main_iteration();
Gtk::main();
}


// hieronder alleen internal functies :)

function change_style (&$style_widget) {

 $style = $style_widget->style;
$style = $style->copy();
$cmap = $style_widget->get_colormap();
 $blue = $cmap->alloc('#406090');
$white = $cmap->alloc('#FFFFFF');
$style->bg[GTK_STATE_NORMAL] = $blue;
$style->bg[GTK_STATE_ACTIVE] = $white;
$style->bg[GTK_STATE_PRELIGHT] = $blue;

$style_widget->set_style($style);

$label = $style_widget->child;
$style = $label->style;
if ($style) {
$style = $style->copy();
$style->font = gdk::font_load('-*-helvetica-medium-r-normal--*-130-*-*-p-0-iso8859-1');
$label->set_style($style);
}
}

function
dec_str($line, $len = 70) {
    if (strlen($line) > $len) {
        $afgekort = substr($line, 0, $len) . "...";
   }
else {
        $afgekort = $line;
}

return $afgekort;
}

function
open_url ($widget,$url) {
exec("\"Start ".$this->CONFIG['browser']." \"" . $url . "");
}

function
getRssFeeds($name, $url)
{

    if($file = fopen($url,"r"))
    {

        while(!feof($file))
        {

            $data .= fgets($file, 1024);
        }

        fclose($file);
    }

$data = html_entity_decode($data);

    $p = explode("<item>", $data);
    for($i = 0; $i < count($p); $i++)
    {

        $item = $p[$i];

        if($q = stristr($item, "<title"))
        {

            $r = stristr($q, "</title");
            $rss[$i]['title'] = substr($q, 7, strlen($q) - strlen($r) - 7);
        }


        if($q = stristr($item, "<description"))
        {

            $r = stristr($q, "</description");
            $rss[$i]['description'] = substr($q, 13, strlen($q) - strlen($r) - 13);          
                $rss[$i]['description'] = preg_replace('/&lt;(.*?)&gt;/i', "[HTML]", $rss[$i]['description']);
        }


        if($q = stristr($item, "<pubDate"))
        {

            $r = stristr($q, "</pubDate");
            $rss[$i]['pubdate'] = strtotime(substr($q, 9, strlen($q) - strlen($r) - 9));
        }


        if($q = stristr($item, "<link"))
        {

            $r = stristr($q, "</link");
            $rss[$i]['link'] = substr($q, 6, strlen($q) - strlen($r) - 6);
        }
    }


    return $rss;
}
}

?>


// rss_reader.php: voorbeeld

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?
include('rss_class.php');  // includen van de class, spreekt voor zichzelf

$reader = new rss_reader; // class 'starten'
// kan ook: $reader = new rss_reader(url,refresh rate, browser, tooltips true/false)



$reader->build_window(); // maak de window

$reader->change_url("http://rss.fok.nl/feeds/nieuws"); // verander de url van de standaard naar fok.nl, dit kan ook via de eerste parameter van rss_reader();

$reader->change_refresh(30); // stel de refreshrate in op 30 seconden, zie 2de parameter rss_reader

$reader->change_browser("firefox.exe"); // stel de browser in, 3de parameter..

$reader->change_tooltips(true); // zet tooltips aan, zie 4de parameter...

$reader->show_rss(); // laat de rss feed direct zien

$reader->start_reading(); // BELANGRIJK, deze functie niet vergeten anders refreshed hij niet, en werkt het script sowieso niet :)

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.