00001 <?php 00002 // dashboard_rss.php - Display your rss feeds on the dashboard 00003 // 00004 // SiT (Support Incident Tracker) - Support call tracking system 00005 // Copyright (C) 2010-2011 The Support Incident Tracker Project 00006 // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors 00007 // 00008 // This software may be used and distributed according to the terms 00009 // of the GNU General Public License, incorporated herein by reference. 00010 // 00011 // Author: Paul Heaney <paulheaney[at]users.sourceforge.net> 00012 00013 $PLUGININFO['dashboard_rss']['version'] = 4; 00014 $PLUGININFO['dashboard_rss']['description'] = 'Displays RSS and Atom feeds'; 00015 $PLUGININFO['dashboard_rss']['author'] = 'SiT! Developers'; 00016 $PLUGININFO['dashboard_rss']['legal'] = 'GPL'; 00017 $PLUGININFO['dashboard_rss']['sitminversion'] = 3.45; 00018 $PLUGININFO['dashboard_rss']['sitmaxversion'] = 3.69; 00019 00020 00021 $dashboard_rss_version = $PLUGININFO['dashboard_rss']['version']; 00022 00023 00024 function dashboard_rss($dashletid) 00025 { 00026 global $sit, $CONFIG, $iconset; 00027 00028 echo dashlet('rss', $dashletid, icon('feed-icon', 16), $GLOBALS['strFeeds'], '', $content); 00029 } 00030 00031 function dashboard_rss_install() 00032 { 00033 global $CONFIG; 00034 00035 $schema = "CREATE TABLE `{$CONFIG['db_tableprefix']}dashboard_rss` ( 00036 `owner` smallint(6) NOT NULL, 00037 `url` varchar(255) NOT NULL, 00038 `items` int(5) default NULL, 00039 `enabled` enum('true','false') NOT NULL, 00040 KEY `owner` (`owner`,`url`) 00041 ) ENGINE = MYISAM ; 00042 "; 00043 $result = mysql_query($schema); 00044 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00045 if (mysql_error()) 00046 { 00047 echo "<p>Dashboard RSS failed to install, please run the following SQL statement on the SiT database to create the required schema.</p>"; 00048 echo "<pre>{$schema}</pre>"; 00049 $res = FALSE; 00050 } 00051 else $res = TRUE; 00052 00053 $datasql = "INSERT INTO `{$CONFIG['db_tableprefix']}dashboard_rss` (`owner`, `url`, `items`, `enabled`) VALUES (1, 'http://sourceforge.net/export/rss2_projnews.php?group_id=160319', 3, 'true');"; 00054 $result = mysql_query($datasql); 00055 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00056 00057 return $res; 00058 } 00059 00060 00061 function dashboard_rss_display($dashletid) 00062 { 00063 global $CONFIG, $dbInterfaceStyles, $dbDashboardRSS, $sit, $lib_path; 00064 00065 if ($_SESSION['auth'] == TRUE) $styleid = $_SESSION['style']; 00066 else $styleid = $CONFIG['default_interface_style']; 00067 00068 $csssql = "SELECT cssurl, iconset FROM `{$dbInterfaceStyles}` WHERE id='{$styleid}'"; 00069 $cssresult = mysql_query($csssql); 00070 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00071 else list($cssurl, $iconset) = mysql_fetch_row($cssresult); 00072 00073 /* 00074 Originally from dashboard/dashboard.inc.php 00075 */ 00076 00077 require_once(APPLICATION_LIBPATH . 'magpierss/rss_fetch.inc'); 00078 00079 $sql = "SELECT url, items FROM `{$CONFIG['db_tableprefix']}dashboard_rss` WHERE owner = {$sit[2]} AND enabled = 'true'"; 00080 $result = mysql_query($sql); 00081 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00082 00083 define ('MAGPIE_CACHE_ON',TRUE); 00084 define ('MAGPIE_CACHE_DIR', $CONFIG['attachment_fspath'].'feeds'); 00085 define ('MAGPIE_OUTPUT_ENCODING', $i18ncharset); 00086 00087 $feedallowedtags = '<img><strong><em><br><p>'; 00088 00089 if (mysql_num_rows($result) > 0) 00090 { 00091 while ($row = mysql_fetch_row($result)) 00092 { 00093 $url = $row[0]; 00094 if ($rss = fetch_rss( $url )) 00095 { 00096 // if ($CONFIG['debug']) echo "<pre>".print_r($rss,true)."</pre>"; 00097 echo "<table>"; 00098 echo "<tr><th><span style='float: right;'><a href='".htmlspecialchars($url)."'>"; 00099 echo "<img src='{$CONFIG['application_webpath']}images/icons/{$iconset}/12x12/feed-icon.png' alt='Feed Icon' />"; 00100 echo "</a></span>"; 00101 echo "<a href='{$rss->channel['link']}' class='direct info'>{$rss->channel['title']}"; 00102 if (!empty($rss->image['url']) OR !empty($rss->channel['description']) OR !empty($rss->channel['icon'])) 00103 { 00104 echo "<span>"; 00105 if (!empty($rss->image['url'])) echo "<img src='{$rss->image['url']}' alt='{$rss->image['title']}' style='float: right; margin-right: 2px; margin-left: 5px; margin-top: 2px;' />"; 00106 elseif (!empty($rss->channel['icon'])) echo "<img src='{$rss->channel['icon']}' style='float: right; margin-right: 2px; margin-left: 5px; margin-top: 2px;' />"; 00107 echo "{$rss->channel['description']}</span>"; 00108 } 00109 echo "</a>"; 00110 echo "</th></tr>\n"; 00111 $counter=0; 00112 foreach ($rss->items as $item) 00113 { 00114 //echo "<pre>".print_r($item,true)."</pre>"; 00115 echo "<tr><td>"; 00116 echo "<a href='{$item['link']}' class='info'>{$item['title']}"; 00117 if ($rss->feed_type == 'RSS') 00118 { 00119 if (!empty($item['pubdate'])) $itemdate = strtotime($item['pubdate']); 00120 elseif (!empty($item['dc']['date'])) $itemdate = strtotime($item['dc']['date']); 00121 else $itemdate = ''; 00122 $d = strip_tags($item['description'],$feedallowedtags); 00123 } 00124 elseif ($rss->feed_type == 'Atom') 00125 { 00126 if (!empty($item['issued'])) $itemdate = strtotime($item['issued']); 00127 elseif (!empty($item['published'])) $itemdate = strtotime($item['published']); 00128 $d = strip_tags($item['atom_content'],$feedallowedtags); 00129 } 00130 if ($itemdate > 10000) $itemdate = ldate($CONFIG['dateformat_datetime'], $itemdate); 00131 echo "<span>"; 00132 if (!empty($itemdate)) echo "<strong>{$itemdate}</strong><br />"; 00133 echo "{$d}</span></a></td></tr>\n"; 00134 $counter++; 00135 if (($row[1] > 0) AND $counter > $row[1]) break; 00136 } 00137 echo "</table>\n"; 00138 } 00139 else 00140 { 00141 echo "Error: It's not possible to get $url..."; 00142 } 00143 } 00144 } 00145 else 00146 { 00147 echo "<p align='center'>{$GLOBALS['strNoRecords']}</p>"; 00148 } 00149 } 00150 00151 00152 function dashboard_rss_edit($dashletid) 00153 { 00154 global $CONFIG, $sit; 00155 00156 $action = $_REQUEST['editaction']; 00157 00158 switch ($action) 00159 { 00160 case 'add': 00161 echo "<h2>".icon('feed-icon', 32)." {$GLOBALS['strAddRSSAtomFeed']}</h2>"; 00162 echo "<form id='dashrssaddform' action='{$_SERVER['PHP_SELF']}?action=do_add' method='post'>"; 00163 echo "<table class='vertical'>"; 00164 echo "<tr><td><label>".icon('feed-icon', 12, $GLOBALS['strFeedIcon'])." "; 00165 echo "{$GLOBALS['strRSSAtomURL']}: <input type='text' name='url' size='45' /></label></td></tr>\n"; 00166 echo "<tr><td><label>{$GLOBALS['strDisplay']}: <input type='text' name='items' size='3' value='0' /></label> ({$GLOBALS['str0MeansUnlimited']})</td></tr>"; 00167 echo "</table>"; 00168 // <input name='submit' type='submit' value='{$GLOBALS['strAdd']}' /> 00169 echo "<p align='center'>".dashlet_link('rss', $dashletid, $GLOBALS['strAdd'], 'save', array('editaction'=>'do_add'), false, 'dashrssaddform')."</p>"; 00170 echo "</form>"; 00171 break; 00172 case 'do_add': 00173 $url = cleanvar($_REQUEST['url']); 00174 $enable = cleanvar($_REQUEST['enable']); 00175 $items = cleanvar($_REQUEST['items']); 00176 $sql = "INSERT INTO `{$CONFIG['db_tableprefix']}dashboard_rss` (owner, url, items, enabled) VALUES ({$sit[2]},'{$url}','{$items}','true')"; //SET enabled = '{$enable}' WHERE url = '{$url}' AND owner = {$sit[2]}"; 00177 $result = mysql_query($sql); 00178 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00179 00180 if (!$result) 00181 { 00182 echo "<p class='error'>{$GLOBALS['strFailed']}</p>"; 00183 } 00184 else 00185 { 00186 echo "<p>{$GLOBALS['strAddedSuccessfully']}</p>"; 00187 echo dashlet_link('rss', $dashletid, $GLOBALS['strBackToList'], '', '', TRUE); 00188 } 00189 break; 00190 case 'edit': 00191 $url = cleanvar(urldecode($_REQUEST['url'])); 00192 $sql = "SELECT * FROM `{$CONFIG['db_tableprefix']}dashboard_rss` WHERE owner = {$sit[2]} AND url = '{$url}' LIMIT 1 "; 00193 if ($CONFIG['debug']) $dbg .= print_r($sql,true); 00194 $result = mysql_query($sql); 00195 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00196 if (mysql_num_rows($result) > 0) 00197 { 00198 $feed = mysql_fetch_object($result); 00199 if ($feed->items=='') 00200 { 00201 $feed->items=0; 00202 } 00203 00204 echo "<h2>".icon('feed-icon', 32)." {$GLOBALS['strEditRSSAtomFeed']}</h2>"; 00205 echo "<form id='dashrsseditform' action='{$_SERVER['PHP_SELF']}?action=do_edit' method='post'>"; 00206 echo "<table class='vertical'>"; 00207 echo "<tr><td><label><img src='{$CONFIG['application_webpath']}images/icons/{$iconset}/12x12/feed-icon.png' alt='Feed Icon' /> "; 00208 echo "{$GLOBALS['strRSSAtomURL']}: <input type='text' name='url' size='45' value='{$feed->url}' /></label></td></tr>\n"; 00209 echo "<tr><td><label>{$GLOBALS['strDisplay']}: <input type='text' name='items' size='3' value='{$feed->items}' /></label> ({$GLOBALS['str0MeansUnlimited']})</td></tr>"; 00210 echo "</table>"; 00211 echo "<input type='hidden' name='oldurl' size='45' value='{$feed->url}' />"; 00212 echo "<p align='center'>".dashlet_link('rss', $dashletid, $GLOBALS['strSave'], 'save', array('editaction'=>'do_edit'), false, 'dashrsseditform')."</p>"; 00213 echo "</form>"; 00214 } 00215 else 00216 { 00217 echo "<p class='error'>{$GLOBALS['strNoRecords']}</p>"; 00218 } 00219 break; 00220 case 'do_edit': 00221 $url = cleanvar($_REQUEST['url']); 00222 $oldurl = cleanvar($_REQUEST['oldurl']); 00223 $items = cleanvar($_REQUEST['items']); 00224 $sql = "UPDATE `{$CONFIG['db_tableprefix']}dashboard_rss` SET url = '{$url}', items = '{$items}' WHERE url = '{$oldurl}' AND owner = {$sit[2]}"; 00225 $result = mysql_query($sql); 00226 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 00227 00228 if (!$result) 00229 { 00230 echo "<p class='error'>{$GLOBALS['strFailed']}</p>"; 00231 } 00232 else 00233 { 00234 echo "<p>{$GLOBALS['strSuccess']}</p>"; 00235 echo dashlet_link('rss', $dashletid, $GLOBALS['strBackToList'], '', '', TRUE); 00236 } 00237 break; 00238 case 'enable': 00239 $url = urldecode(cleanvar($_REQUEST['url'])); 00240 $enable = cleanvar($_REQUEST['enable']); 00241 $sql = "UPDATE `{$CONFIG['db_tableprefix']}dashboard_rss` SET `enabled` = '{$enable}' WHERE `url` = '{$url}' AND `owner` = {$sit[2]}"; 00242 mysql_query($sql); 00243 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 00244 00245 if (mysql_affected_rows() < 1) html_redirect("edit_rss_feeds.php", FALSE, "Changed enabled state failed"); 00246 if (mysql_affected_rows() < 1) 00247 { 00248 echo "<p class='error'>{$GLOBALS['strFailed']}</p>"; 00249 } 00250 else 00251 { 00252 echo "<p>{$GLOBALS['strSuccess']}</p>"; 00253 echo dashlet_link('rss', $dashletid, $GLOBALS['strBackToList'], '', '', TRUE); 00254 } 00255 break; 00256 case 'delete': 00257 $url = $_REQUEST['url']; 00258 $enable = $_REQUEST['enable']; 00259 $sql = "DELETE FROM `{$CONFIG['db_tableprefix']}dashboard_rss` WHERE url = '{$url}' AND owner = {$sit[2]}"; 00260 $result = mysql_query($sql); 00261 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 00262 00263 if (!$result) 00264 { 00265 echo "<p class='error'>{$GLOBALS['strFailed']}</p>"; 00266 } 00267 else 00268 { 00269 echo "<p>{$GLOBALS['strSuccess']}</p>"; 00270 echo dashlet_link('rss', $dashletid, $GLOBALS['strBackToList'], '', '', TRUE); 00271 } 00272 break; 00273 default: 00274 echo "<h2>".icon('feed-icon', 32)." {$GLOBALS['strEditRSSAtomFeed']}</h2>"; 00275 00276 $sql = "SELECT * FROM `{$CONFIG['db_tableprefix']}dashboard_rss` WHERE owner = {$sit[2]}"; 00277 $result = mysql_query($sql); 00278 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00279 00280 if (mysql_num_rows($result) > 0) 00281 { 00282 echo "<table align='center'>\n"; 00283 echo "<tr><th>URL</th><th>{$GLOBALS['strDisplay']}</th><th>{$GLOBALS['strEnabled']}</th><th>{$GLOBALS['strOperation']}</th></tr>\n"; 00284 $shade = 'shade1'; 00285 while ($obj = mysql_fetch_object($result)) 00286 { 00287 if ($obj->enabled == "true") 00288 { 00289 $opposite = "false"; 00290 } 00291 else 00292 { 00293 $opposite = "true"; 00294 } 00295 00296 $urlparts = parse_url($obj->url); 00297 if ($obj->enabled == 'false') 00298 { 00299 $shade = 'expired'; 00300 } 00301 00302 echo "<tr class='$shade'><td align='left'><a href=\"".htmlentities($obj->url,ENT_NOQUOTES, $GLOBALS['i18ncharset'])."\">"; 00303 echo icon('feed-icon', 12, $strFeedIcon); 00304 echo "</a> <a href=\"{$obj->url}\">{$urlparts['host']}</a></td>"; 00305 echo "<td>"; 00306 if ($obj->items >= 1) 00307 { 00308 echo "{$obj->items}"; 00309 } 00310 else 00311 { 00312 echo $GLOBALS['strUnlimited']; 00313 } 00314 00315 echo "</td>"; 00316 echo "<td>".dashlet_link('rss', $dashletid, $obj->enabled, 'edit', array('editaction'=>'enable', 'enable'=>$opposite, 'url'=>urlencode($obj->url)))."</td>"; 00317 echo "<td>".dashlet_link('rss', $dashletid, $GLOBALS['strEdit'], 'edit', array('editaction'=>'edit', 'url'=>urlencode($obj->url))); 00318 echo " | ".dashlet_link('rss', $dashletid, $GLOBALS['strRemove'], 'edit', array('editaction'=>'delete', 'url'=>urlencode($obj->url))); 00319 echo "</td></tr>\n"; 00320 if ($shade == 'shade1') $shade = 'shade2'; 00321 else $shade = 'shade1'; 00322 } 00323 echo "</table>\n"; 00324 } 00325 else 00326 { 00327 echo "<p align='center'>{$GLOBALS['strNoFeedsCurrentlyPresent']}</p>"; 00328 } 00329 00330 echo "<p align='center'>".dashlet_link('rss', $dashletid, $GLOBALS['strAdd'], 'edit', array('editaction'=>'add'))."</p>"; 00331 break; 00332 } 00333 00334 } 00335 00336 00337 00338 function dashboard_rss_upgrade() 00339 { 00340 global $CONFIG; 00341 $upgrade_schema[2] = " 00342 -- INL 22Nov07 00343 ALTER TABLE `{$CONFIG['db_tableprefix']}dashboard_rss` ADD `items` INT( 5 ) NULL AFTER `url`; 00344 "; 00345 00346 $upgrade_schema[3] = " 00347 -- INL 22May09 00348 ALTER TABLE `{$CONFIG['db_tableprefix']}dashboard_rss` CHANGE `owner` `owner` SMALLINT( 6 ) NOT NULL;"; 00349 00350 00351 $upgrade_schema[4] = " 00352 -- CJ 14Mar10 00353 UPDATE `{$CONFIG['db_tableprefix']}dashboard_rss` SET url='http://sourceforge.net/export/rss2_projnews.php?group_id=160319' WHERE url='http://sourceforge.net/export/rss2_projfiles.php?group_id=160319'"; 00354 00355 return $upgrade_schema; 00356 00357 00358 } 00359 00360 function dashboard_rss_get_version() 00361 { 00362 global $dashboard_rss_version; 00363 return $dashboard_rss_version; 00364 } 00365 00366 00367 ?>
For more help developing with SiT! see http://sitracker.org/wiki/DevelopmentHowTo