PageRenderTime 57ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Rss/Rss.php

https://github.com/vtiger-jp/vtigercrm-5.1.x-ja
PHP | 464 lines | 345 code | 59 blank | 60 comment | 38 complexity | 8c6e2f7d94ed2f431a9c727d1372d93d MD5 | raw file
  1. <?php
  2. /*********************************************************************************
  3. ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. *
  10. ********************************************************************************/
  11. global $calpath;
  12. global $app_strings,$mod_strings;
  13. global $theme;
  14. $theme_path="themes/".$theme."/";
  15. $image_path=$theme_path."images/";
  16. require_once('data/CRMEntity.php');
  17. require_once('include/database/PearDatabase.php');
  18. // Require the xmlParser class
  19. //require_once('include/feedParser/xmlParser.php');
  20. // Require the feedParser class
  21. //require_once('include/feedParser/feedParser.php');
  22. require_once('include/magpierss/rss_fetch.inc');
  23. class vtigerRSS extends CRMEntity
  24. {
  25. var $rsscache_time = 1200;
  26. /** Function to get the Rss Feeds from the Given URL
  27. * This Function accepts the url string as the argument
  28. * and assign the value for the class variables correspondingly
  29. */
  30. function setRSSUrl($url)
  31. {
  32. global $cache_dir;
  33. $this->rss = fetch_rss($url);
  34. // Read in our sample feed file
  35. //$data = @implode("",@file($url));
  36. // Tell feedParser to parse the data
  37. $info = $this->rss->items;
  38. if(isset($info))
  39. {
  40. $this->rss_object = $info;
  41. }else
  42. {
  43. return false;
  44. }
  45. if(isset($this->rss))
  46. {
  47. $this->rss_title = $this->rss->channel["title"];
  48. $this->rss_link = $this->rss->channel["link"];
  49. $this->rss_object = $info;
  50. return true;
  51. }else
  52. {
  53. return false;
  54. }
  55. }
  56. /** Function to get the List of Rss feeds
  57. * This Function accepts no arguments and returns the listview contents on Sucess
  58. * returns "Sorry: It's not possible to reach RSS URL" if fails
  59. */
  60. function getListViewRSSHtml()
  61. {
  62. global $default_charset;
  63. if(isset($this->rss_object))
  64. {
  65. $i = 0;
  66. foreach($this->rss_object as $key=>$item)
  67. {
  68. $stringConvert = function_exists(iconv) ? @iconv("UTF-8",$default_charset,$item[title]) : $item[title];
  69. $rss_title= ltrim(rtrim($stringConvert));
  70. $i = $i + 1;
  71. $shtml .= "<tr class='prvPrfHoverOff' onmouseover=\"this.className='prvPrfHoverOn'\" onmouseout=\"this.className='prvPrfHoverOff'\"><td><a href=\"javascript:display('".$item[link]."','feedlist_".$i."')\"; id='feedlist_".$i."' class=\"rssNews\">".$rss_title."</a></td><td>".$this->rss_title."</td></tr>";
  72. if($i == 10)
  73. {
  74. return $shtml;
  75. }
  76. }
  77. return $shtml;
  78. }else
  79. {
  80. $shtml = "<strong>".$mod_strings['LBL_REGRET_MSG']."</strong>";
  81. }
  82. }
  83. /** Function to get the List of Rss feeds in the Customized Home page
  84. * This Function accepts maximum entries as arguments and returns the listview contents on Success
  85. * returns "Sorry: It's not possible to reach RSS URL" if fails
  86. */
  87. function getListViewHomeRSSHtml($maxentries)
  88. {
  89. $return_value=Array();
  90. $return_more=Array();
  91. if(isset($this->rss_object))
  92. {
  93. $y = 0;
  94. foreach($this->rss_object as $key=>$item)
  95. {
  96. $title =$item[title];
  97. $link = $item[link];
  98. if($y == $maxentries)
  99. {
  100. $return_more=Array("Details"=>$return_value,"More"=>$this->rss_link);
  101. return $return_more;
  102. }
  103. $y = $y + 1;
  104. $return_value[]=Array($title,$link);
  105. }
  106. $return_more=Array("Details"=>$return_value,"More"=>$this->rss_link);
  107. return $return_more;
  108. }else
  109. {
  110. return $return_more;
  111. }
  112. }
  113. /** Function to save the Rss Feeds
  114. * This Function accepts the RssURl,Starred Status as arguments and
  115. * returns true on sucess
  116. * returns false if fails
  117. */
  118. function saveRSSUrl($url,$makestarred=0)
  119. {
  120. global $adb;
  121. if ($url != "")
  122. {
  123. $rsstitle = $this->rss_title;
  124. if($rsstitle == "")
  125. {
  126. $rsstitle = $url;
  127. }
  128. $genRssId = $adb->getUniqueID("vtiger_rss");
  129. $sSQL = "insert into vtiger_rss (RSSID,RSSURL,RSSTITLE,RSSTYPE,STARRED) values (?,?,?,?,?)";
  130. $sparams = array($genRssId, $url, $rsstitle, 0, $makestarred);
  131. $result = $adb->pquery($sSQL, $sparams);
  132. if($result)
  133. {
  134. return $genRssId;
  135. }else
  136. {
  137. return false;
  138. }
  139. }
  140. }
  141. function getCRMRssFeeds()
  142. {
  143. global $adb;
  144. global $image_path,$theme;
  145. $sSQL = "select * from vtiger_rss where rsstype=1";
  146. $result = $adb->pquery($sSQL, array());
  147. while($allrssrow = $adb->fetch_array($result))
  148. {
  149. $shtml .= "<tr>";
  150. if($allrssrow["starred"] == 1)
  151. {
  152. $shtml .= "<td width=\"15\">
  153. <img src=\"". vtiger_imageurl('onstar.gif', $theme) ."\" align=\"absmiddle\" onMouseOver=\"this.style.cursor='pointer'\" id=\"star-$allrssrow[rssid]\"></td>";
  154. }else
  155. {
  156. $shtml .= "<td width=\"15\">
  157. <img src=\"". vtiger_imageurl('offstar.gif', $theme) ."\" align=\"absmiddle\" onMouseOver=\"this.style.cursor='pointer'\" id=\"star-$allrssrow[rssid]\" onClick=\"makedefaultRss($allrssrow[rssid])\"></td>";
  158. }
  159. $shtml .= "<td class=\"rssTitle\"><a href=\"index.php?module=Rss&action=ListView&record=$allrssrow[rssid]
  160. \" class=\"rssTitle\">".$allrssrow[rsstitle]."</a></td>";
  161. $shtml .= "<td>&nbsp;</td></tr>";
  162. }
  163. return $shtml;
  164. }
  165. function getAllRssFeeds()
  166. {
  167. global $adb;
  168. global $image_path;
  169. $sSQL = "select * from vtiger_rss where rsstype <> 1";
  170. $result = $adb->pquery($sSQL, array());
  171. while($allrssrow = $adb->fetch_array($result))
  172. {
  173. $shtml .= "<tr>";
  174. if($allrssrow["starred"] == 1)
  175. {
  176. $shtml .= "<td width=\"15\">
  177. <img src=\"". vtiger_imageurl('onstar.gif', $theme) ."\" align=\"absmiddle\" onMouseOver=\"this.style.cursor='pointer'\" id=\"star-$allrssrow[rssid]\"></td>";
  178. }else
  179. {
  180. $shtml .= "<td width=\"15\">
  181. <img src=\"". vtiger_imageurl('offstar.gif', $theme) ."\" align=\"absmiddle\" onMouseOver=\"this.style.cursor='pointer'\" id=\"star-$allrssrow[rssid]\" onClick=\"makedefaultRss($allrssrow[rssid])\"></td>";
  182. }
  183. $shtml .= "<td class=\"rssTitle\"><a href=\"index.php?module=Rss&action=ListView&record=$allrssrow[rssid]\" class=\"rssTitle\">".$allrssrow[rsstitle]."</a></td><td>&nbsp;</td>";
  184. $shtml .= "</tr>";
  185. }
  186. return $shtml;
  187. }
  188. /** Function to get the rssurl for the given id
  189. * This Function accepts the rssid as argument and returns the rssurl for that id
  190. */
  191. function getRssUrlfromId($rssid)
  192. {
  193. global $adb;
  194. if($rssid != "")
  195. {
  196. $sSQL = "select * from vtiger_rss where rssid=?";
  197. $result = $adb->pquery($sSQL, array($rssid));
  198. $rssrow = $adb->fetch_array($result);
  199. if(count($rssrow) > 0)
  200. {
  201. $rssurl = $rssrow[rssurl];
  202. }
  203. }
  204. return $rssurl;
  205. }
  206. function getRSSHeadings($rssid)
  207. {
  208. global $image_path;
  209. global $adb;
  210. if($rssid != "")
  211. {
  212. $sSQL = "select * from vtiger_rss where rssid=?";
  213. $result = $adb->pquery($sSQL, array($rssid));
  214. $rssrow = $adb->fetch_array($result);
  215. if(count($rssrow) > 0)
  216. {
  217. $shtml = "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
  218. <tr>
  219. <td class=\"rssPgTitle\">";
  220. if($rssrow[starred] == 1)
  221. {
  222. $shtml .= "<img src=\"". vtiger_imageurl('starred.gif', $theme) ."\" align=\"absmiddle\">";
  223. }else
  224. {
  225. $shtml .= "<img src=\"". vtiger_imageurl('unstarred.gif', $theme) ."\" align=\"absmiddle\">";
  226. }
  227. $shtml .= "<a href=\"".$this->rss_object[link]."\"> ".$rssrow[rsstitle]."</a>
  228. </td>
  229. </tr>
  230. </table>";
  231. }
  232. }
  233. return $shtml;
  234. }
  235. /** Function to get the StarredRSSFeeds lists
  236. * This Function accepts no argument and returns the rss feeds of
  237. * the starred Feeds as HTML strings
  238. */
  239. function getTopStarredRSSFeeds()
  240. {
  241. global $adb;
  242. global $image_path;
  243. $sSQL = "select * from vtiger_rss where starred=1";
  244. $result = $adb->pquery($sSQL, array());
  245. $shtml .= "<img src=\"". vtiger_imageurl('rss.gif', $theme) ."\" border=\"0\" align=\"absmiddle\" hspace=\"2\"><a href=\"#\" onclick='window.open(\"index.php?module=Rss&action=Popup\",\"new\",\"width=500,height=300,resizable=1,scrollbars=1\");'>Add New Rss</a>";
  246. while($allrssrow = $adb->fetch_array($result))
  247. {
  248. $shtml .= "<img src=\"". vtiger_imageurl('rss.gif', $theme) ."\" border=\"0\" align=\"absmiddle\" hspace=\"2\">";
  249. $shtml .= "<a href=\"index.php?module=Rss&action=ListView&record=$allrssrow[rssid]\" class=\"rssFavLink\"> ".substr($allrssrow['rsstitle'],0,10)."...</a></img>";
  250. }
  251. return $shtml;
  252. }
  253. /** Function to get the rssfeed lists for the starred Rss feeds
  254. * This Function accepts no argument and returns the rss feeds of
  255. * the starred Feeds as HTML strings
  256. */
  257. function getStarredRssHTML()
  258. {
  259. global $adb;
  260. global $image_path,$mod_strings;
  261. $sSQL = "select * from vtiger_rss where starred=1";
  262. $result = $adb->pquery($sSQL, array());
  263. while($allrssrow = $adb->fetch_array($result))
  264. {
  265. if($this->setRSSUrl($allrssrow["rssurl"]))
  266. {
  267. $rss_html = $this->getListViewRSSHtml();
  268. }
  269. $shtml .= $rss_html;
  270. if(isset($this->rss_object))
  271. {
  272. if(count($this->rss_object) > 10)
  273. {
  274. $shtml .= "<tr><td colspan='3' align=\"right\">
  275. <a target=\"_BLANK\" href=\"$this->rss_link\">".$mod_strings['LBL_MORE']."</a>
  276. </td></tr>";
  277. }
  278. }
  279. $sreturnhtml[] = $shtml;
  280. $shtml = "";
  281. }
  282. $recordcount = round((count($sreturnhtml))/2);
  283. $j = $recordcount;
  284. for($i=0;$i<$recordcount;$i++)
  285. {
  286. $starredhtml .= $sreturnhtml[$i].$sreturnhtml[$j];
  287. $j = $j + 1;
  288. }
  289. $starredhtml = "<table class='rssTable' cellspacing='0' cellpadding='0'>
  290. <tr>
  291. <th width='75%'>".$mod_strings['LBL_SUBJECT']."</th>
  292. <th width='25%'>".$mod_strings['LBL_SENDER']."</th>
  293. </tr>".$starredhtml."</table>";
  294. return $starredhtml;
  295. }
  296. /** Function to get the rssfeed lists for the given rssid
  297. * This Function accepts the rssid as argument and returns the rss feeds as HTML strings
  298. */
  299. function getSelectedRssHTML($rssid)
  300. {
  301. global $adb;
  302. global $image_path, $mod_strings;
  303. $sSQL = "select * from vtiger_rss where rssid=?";
  304. $result = $adb->pquery($sSQL, array($rssid));
  305. while($allrssrow = $adb->fetch_array($result))
  306. {
  307. if($this->setRSSUrl($allrssrow["rssurl"]))
  308. {
  309. $rss_html = $this->getListViewRSSHtml();
  310. }
  311. $shtml .= $rss_html;
  312. if(isset($this->rss_object))
  313. {
  314. if(count($this->rss_object) > 10)
  315. {
  316. $shtml .= "<tr><td colspan='3' align=\"right\">
  317. <a target=\"_BLANK\" href=\"$this->rss_link\">".$mod_strings['LBL_MORE']."</a>
  318. </td></tr>";
  319. }
  320. }
  321. $sreturnhtml[] = $shtml;
  322. $shtml = "";
  323. }
  324. $recordcount = round((count($sreturnhtml))/2);
  325. $j = $recordcount;
  326. for($i=0;$i<$recordcount;$i++)
  327. {
  328. $starredhtml .= $sreturnhtml[$i].$sreturnhtml[$j];
  329. $j = $j + 1;
  330. }
  331. $starredhtml = "<table class='rssTable' cellspacing='0' cellpadding='0'>
  332. <tr>
  333. <th width='75%'>".$mod_strings['LBL_SUBJECT']."</th>
  334. <th width='25%'>".$mod_strings['LBL_SENDER']."</th>
  335. </tr>".$starredhtml."</table>";
  336. return $starredhtml;
  337. }
  338. /** Function to get the Rss Feeds by Category
  339. * This Function accepts the RssCategory as argument
  340. * and returns the html string for the Rss feeds lists
  341. */
  342. function getRSSCategoryHTML()
  343. {
  344. global $adb;
  345. global $image_path;
  346. $shtml .= "<tr>
  347. <td colspan=\"3\">
  348. <table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\" style=\"margin:5 0 0 35\">".$this->getRssFeedsbyCategory()."</table>
  349. </td>
  350. </tr>";
  351. return $shtml;
  352. }
  353. /** Function to get the Rss Feeds for the Given Category
  354. * This Function accepts the RssCategory as argument
  355. * and returns the html string for the Rss feeds lists
  356. */
  357. function getRssFeedsbyCategory()
  358. {
  359. global $adb;
  360. global $image_path,$theme;
  361. $sSQL = "select * from vtiger_rss";
  362. $result = $adb->pquery($sSQL, array());
  363. while($allrssrow = $adb->fetch_array($result))
  364. {
  365. $shtml .= "<tr id='feed_".$allrssrow[rssid]."'>";
  366. $shtml .= "<td align='left' width=\"15\">";
  367. if($allrssrow["starred"] == 1)
  368. {
  369. $shtml .= "<img src=\"". vtiger_imageurl('onstar.gif', $theme) ."\" align=\"absmiddle\" onMouseOver=\"this.style.cursor='pointer'\" id=\"star-$allrssrow[rssid]\">";
  370. }else
  371. {
  372. $shtml .= "<img src=\"". vtiger_imageurl('offstar.gif', $theme) ."\" align=\"absmiddle\" onMouseOver=\"this.style.cursor='pointer'\" id=\"star-$allrssrow[rssid]\" onClick=\"makedefaultRss($allrssrow[rssid])\">";
  373. }
  374. $shtml .= "</td>";
  375. $shtml .= "<td class=\"rssTitle\" width=\"10%\" nowrap><a href=\"javascript:GetRssFeedList('$allrssrow[rssid]')\" class=\"rssTitle\">".$allrssrow[rsstitle]."</a></td><td>&nbsp;</td>";
  376. $shtml .= "</tr>";
  377. }
  378. return $shtml;
  379. }
  380. // Function to delete an entity with given Id
  381. function trash($module, $id) {
  382. global $log, $adb;
  383. $del_query = 'DELETE FROM vtiger_rss WHERE rssid=?';
  384. $adb->pquery($del_query, array($id));
  385. }
  386. }
  387. /** Function to get the rsstitle for the given rssid
  388. * This Function accepts the rssid as an optional argument and returns the title
  389. * if no id is passed it will return the tittle of the starred rss
  390. */
  391. function gerRssTitle($id='')
  392. {
  393. global $adb;
  394. if($id == '') {
  395. $query = 'select * from vtiger_rss where starred=1';
  396. $params = array();
  397. } else {
  398. $query = 'select * from vtiger_rss where rssid =?';
  399. $params = array($id);
  400. }
  401. $result = $adb->pquery($query, $params);
  402. $title = $adb->query_result($result,0,'rsstitle');
  403. return $title;
  404. }
  405. ?>