2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
39 require_once('include/Dashlets/Dashlet.php');
40 require_once('include/Sugar_Smarty.php');
42 class RSSDashlet extends Dashlet
44 protected $url = 'http://www.sugarcrm.com/crm/aggregator/rss/1';
45 protected $height = '200'; // height of the pad
46 protected $images_dir = 'modules/Home/Dashlets/RSSDashlet/images';
51 * @global string current language
52 * @param guid $id id for the current dashlet (assigned from Home module)
53 * @param array $def options saved for this dashlet
55 public function __construct($id, $def)
57 $this->loadLanguage('RSSDashlet', 'modules/Home/Dashlets/'); // load the language strings here
59 if(!empty($def['height'])) // set a default height if none is set
60 $this->height = $def['height'];
62 if(!empty($def['url']))
63 $this->url = $def['url'];
65 if(!empty($def['title']))
66 $this->title = $def['title'];
68 $this->title = $this->dashletStrings['LBL_TITLE'];
70 parent::Dashlet($id); // call parent constructor
72 $this->isConfigurable = true; // dashlet is configurable
73 $this->hasScript = false; // dashlet has javascript attached to it
77 * Displays the dashlet
79 * @return string html to display dashlet
81 public function display()
83 $ss = new Sugar_Smarty();
84 $ss->assign('saving', $this->dashletStrings['LBL_SAVING']);
85 $ss->assign('saved', $this->dashletStrings['LBL_SAVED']);
86 $ss->assign('id', $this->id);
87 $ss->assign('height', $this->height);
88 $ss->assign('rss_output', $this->getRSSOutput($this->url));
89 $str = $ss->fetch('modules/Home/Dashlets/RSSDashlet/RSSDashlet.tpl');
90 return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $str; // return parent::display for title and such
94 * Displays the configuration form for the dashlet
96 * @return string html to display form
98 public function displayOptions() {
99 global $app_strings, $sugar_version, $sugar_config;
101 $ss = new Sugar_Smarty();
102 $ss->assign('titleLbl', $this->dashletStrings['LBL_CONFIGURE_TITLE']);
103 $ss->assign('heightLbl', $this->dashletStrings['LBL_CONFIGURE_HEIGHT']);
104 $ss->assign('rssUrlLbl', $this->dashletStrings['LBL_CONFIGURE_RSSURL']);
105 $ss->assign('saveLbl', $app_strings['LBL_SAVE_BUTTON_LABEL']);
106 $ss->assign('title', $this->title);
107 $ss->assign('height', $this->height);
108 $ss->assign('url', $this->url);
109 $ss->assign('id', $this->id);
111 return parent::displayOptions() . $ss->fetch('modules/Home/Dashlets/RSSDashlet/RSSDashletOptions.tpl');
115 * called to filter out $_REQUEST object when the user submits the configure dropdown
117 * @param array $req $_REQUEST
118 * @return array filtered options to save
120 public function saveOptions(
125 $options['title'] = $req['title'];
126 $options['url'] = $req['url'];
127 $options['height'] = $req['height'];
132 protected function getRSSOutput(
136 // suppress XML errors
137 libxml_use_internal_errors(true);
138 $rssdoc = simplexml_load_file($url);
139 // return back the error message if the loading wasn't successful
141 return $this->dashletStrings['ERR_LOADING_FEED'];
143 $output = "<table class='edit view'>";
144 if ( isset($rssdoc->channel) ) {
145 foreach ( $rssdoc->channel as $channel ) {
146 if ( isset($channel->item ) ) {
147 foreach ( $channel->item as $item ) {
151 <h3><a href="{$item->link}" target="_child">{$item->title}</a></h3>
161 foreach ( $rssdoc->entry as $entry ) {
165 <h3><a href="{$entry->link}" target="_child">{$entry->title}</a></h3>
172 $output .= "</table>";