2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition 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 if(isset($def['autoRefresh'])) $this->autoRefresh = $def['autoRefresh'];
72 parent::Dashlet($id); // call parent constructor
74 $this->isConfigurable = true; // dashlet is configurable
75 $this->hasScript = false; // dashlet has javascript attached to it
79 * Displays the dashlet
81 * @return string html to display dashlet
83 public function display()
85 $ss = new Sugar_Smarty();
86 $ss->assign('saving', $this->dashletStrings['LBL_SAVING']);
87 $ss->assign('saved', $this->dashletStrings['LBL_SAVED']);
88 $ss->assign('id', $this->id);
89 $ss->assign('height', $this->height);
90 $ss->assign('rss_output', $this->getRSSOutput($this->url));
91 $str = $ss->fetch('modules/Home/Dashlets/RSSDashlet/RSSDashlet.tpl');
92 return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $str; // return parent::display for title and such
96 * Displays the configuration form for the dashlet
98 * @return string html to display form
100 public function displayOptions() {
101 global $app_strings, $sugar_version, $sugar_config;
103 $ss = new Sugar_Smarty();
104 $ss->assign('titleLbl', $this->dashletStrings['LBL_CONFIGURE_TITLE']);
105 $ss->assign('heightLbl', $this->dashletStrings['LBL_CONFIGURE_HEIGHT']);
106 $ss->assign('rssUrlLbl', $this->dashletStrings['LBL_CONFIGURE_RSSURL']);
107 $ss->assign('saveLbl', $app_strings['LBL_SAVE_BUTTON_LABEL']);
108 $ss->assign('title', $this->title);
109 $ss->assign('height', $this->height);
110 $ss->assign('url', $this->url);
111 $ss->assign('id', $this->id);
112 if($this->isAutoRefreshable()) {
113 $ss->assign('isRefreshable', true);
114 $ss->assign('autoRefresh', $GLOBALS['app_strings']['LBL_DASHLET_CONFIGURE_AUTOREFRESH']);
115 $ss->assign('autoRefreshOptions', $this->getAutoRefreshOptions());
116 $ss->assign('autoRefreshSelect', $this->autoRefresh);
119 return parent::displayOptions() . $ss->fetch('modules/Home/Dashlets/RSSDashlet/RSSDashletOptions.tpl');
123 * called to filter out $_REQUEST object when the user submits the configure dropdown
125 * @param array $req $_REQUEST
126 * @return array filtered options to save
128 public function saveOptions(
133 $options['title'] = $req['title'];
134 $options['url'] = $req['url'];
135 $options['height'] = $req['height'];
136 $options['autoRefresh'] = empty($req['autoRefresh']) ? '0' : $req['autoRefresh'];
141 protected function getRSSOutput(
145 // suppress XML errors
146 libxml_use_internal_errors(true);
147 $rssdoc = simplexml_load_file($url);
148 // return back the error message if the loading wasn't successful
150 return $this->dashletStrings['ERR_LOADING_FEED'];
152 $output = "<table class='edit view'>";
153 if ( isset($rssdoc->channel) ) {
154 foreach ( $rssdoc->channel as $channel ) {
155 if ( isset($channel->item ) ) {
156 foreach ( $channel->item as $item ) {
160 <h3><a href="{$item->link}" target="_child">{$item->title}</a></h3>
170 foreach ( $rssdoc->entry as $entry ) {
174 <h3><a href="{$entry->link}" target="_child">{$entry->title}</a></h3>
181 $output .= "</table>";