1 | <?php |
---|
2 | |
---|
3 | class rss |
---|
4 | { |
---|
5 | |
---|
6 | function rss (){ |
---|
7 | } |
---|
8 | // BEGIN of functions. |
---|
9 | function getContent($param){ |
---|
10 | $daurl=$param['url']; |
---|
11 | if (preg_match('/http(s)?:\/\//i',$daurl,$matches) == 0) |
---|
12 | $daurl = 'http://'.$daurl; |
---|
13 | |
---|
14 | // Set your return content type |
---|
15 | header('Content-type: application/xml'); |
---|
16 | |
---|
17 | // Get that website's content |
---|
18 | $handle = fopen($daurl, "r"); |
---|
19 | |
---|
20 | // If there is something, read and return |
---|
21 | if ($handle) { |
---|
22 | $buffer = fgets($handle, 4096); |
---|
23 | $pattern = '/<\?xml version=".\.0"( encoding="[A-Z\-0-9]+")?\ *\?>/i'; |
---|
24 | if (preg_match($pattern,$buffer,$matches) == 0) |
---|
25 | exit; |
---|
26 | echo $buffer; |
---|
27 | while (!feof($handle)) { |
---|
28 | $buffer = fgets($handle, 4096); |
---|
29 | echo $buffer; |
---|
30 | } |
---|
31 | fclose($handle); |
---|
32 | } |
---|
33 | exit; |
---|
34 | } |
---|
35 | |
---|
36 | private function createTableRSS() |
---|
37 | { |
---|
38 | $query = 'CREATE TABLE phpgw_userrss( uid INT NOT NULL,rss_url VARCHAR(1000),name varchar(50), PRIMARY KEY (uid,rss_url) );'; |
---|
39 | |
---|
40 | $GLOBALS['phpgw']->db->query($query); |
---|
41 | |
---|
42 | if ( $GLOBALS['phpgw']->db->Error ) |
---|
43 | return false; |
---|
44 | else |
---|
45 | return true; |
---|
46 | } |
---|
47 | |
---|
48 | function getChannels() |
---|
49 | { |
---|
50 | include('../header.inc.php'); |
---|
51 | |
---|
52 | $flag = false; |
---|
53 | $tableQuery = "select relname from pg_stat_user_tables order by relname;"; |
---|
54 | |
---|
55 | if( $GLOBALS['phpgw']->db->query( $tableQuery ) ) |
---|
56 | { |
---|
57 | while( $GLOBALS['phpgw']->db->next_record() ) |
---|
58 | { |
---|
59 | $tables[] = $GLOBALS['phpgw']->db->row(); |
---|
60 | } |
---|
61 | |
---|
62 | foreach( $tables as $tableName ) |
---|
63 | { |
---|
64 | if( strtolower( $tableName['relname'] ) === 'phpgw_userrss' ) |
---|
65 | { |
---|
66 | $flag = true; |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | if( !$flag ) |
---|
72 | { |
---|
73 | $flag = $this->createTableRSS(); |
---|
74 | } |
---|
75 | |
---|
76 | $query = 'SELECT rss_url,name FROM phpgw_userrss WHERE uid = '.$_SESSION['phpgw_session']['account_id']; |
---|
77 | |
---|
78 | if( $GLOBALS['phpgw']->db->query($query) ) |
---|
79 | { |
---|
80 | while( $GLOBALS['phpgw']->db->next_record() ) |
---|
81 | { |
---|
82 | $return[] = $GLOBALS['phpgw']->db->row(); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | if( count($return) > 0 ) |
---|
87 | return $return; |
---|
88 | else |
---|
89 | return ""; |
---|
90 | } |
---|
91 | |
---|
92 | function addChannel($param) |
---|
93 | { |
---|
94 | include('../header.inc.php'); |
---|
95 | $name = $GLOBALS['phpgw']->db->db_addslashes(htmlentities($param['name'])); |
---|
96 | $url = $GLOBALS['phpgw']->db->db_addslashes($param['url']); |
---|
97 | $GLOBALS['phpgw']->db->query('INSERT INTO phpgw_userrss values('.$_SESSION['phpgw_session']['account_id'].',\''.$url.'\',\''.$name.'\');',__LINE__,__FILE__); |
---|
98 | if ($GLOBALS['phpgw']->db->Error) |
---|
99 | return "Error"; |
---|
100 | else |
---|
101 | return "Success"; |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | function removeChannel($param) |
---|
106 | { |
---|
107 | include('../header.inc.php'); |
---|
108 | $url = $GLOBALS['phpgw']->db->db_addslashes($param['url']); |
---|
109 | $GLOBALS['phpgw']->db->query('DELETE FROM phpgw_userrss where rss_url = \''.$url.'\';',__LINE__,__FILE__); |
---|
110 | if ($GLOBALS['phpgw']->db->Error) |
---|
111 | return "Error"; |
---|
112 | else |
---|
113 | return "Success"; |
---|
114 | } |
---|
115 | |
---|
116 | } |
---|
117 | ?> |
---|