loadLanguage('RSSDashlet', 'modules/Home/Dashlets/'); // load the language strings here if(!empty($def['height'])) // set a default height if none is set $this->height = $def['height']; if(!empty($def['url'])) $this->url = $def['url']; if(!empty($def['title'])) $this->title = $def['title']; else $this->title = $this->dashletStrings['LBL_TITLE']; if(isset($def['autoRefresh'])) $this->autoRefresh = $def['autoRefresh']; parent::Dashlet($id); // call parent constructor $this->isConfigurable = true; // dashlet is configurable $this->hasScript = false; // dashlet has javascript attached to it } /** * Displays the dashlet * * @return string html to display dashlet */ public function display() { $ss = new Sugar_Smarty(); $ss->assign('saving', $this->dashletStrings['LBL_SAVING']); $ss->assign('saved', $this->dashletStrings['LBL_SAVED']); $ss->assign('id', $this->id); $ss->assign('height', $this->height); $ss->assign('rss_output', $this->getRSSOutput($this->url)); $str = $ss->fetch('modules/Home/Dashlets/RSSDashlet/RSSDashlet.tpl'); return parent::display($this->dashletStrings['LBL_DBLCLICK_HELP']) . $str; // return parent::display for title and such } /** * Displays the configuration form for the dashlet * * @return string html to display form */ public function displayOptions() { global $app_strings, $sugar_version, $sugar_config; $ss = new Sugar_Smarty(); $ss->assign('titleLbl', $this->dashletStrings['LBL_CONFIGURE_TITLE']); $ss->assign('heightLbl', $this->dashletStrings['LBL_CONFIGURE_HEIGHT']); $ss->assign('rssUrlLbl', $this->dashletStrings['LBL_CONFIGURE_RSSURL']); $ss->assign('saveLbl', $app_strings['LBL_SAVE_BUTTON_LABEL']); $ss->assign('title', $this->title); $ss->assign('height', $this->height); $ss->assign('url', $this->url); $ss->assign('id', $this->id); if($this->isAutoRefreshable()) { $ss->assign('isRefreshable', true); $ss->assign('autoRefresh', $GLOBALS['app_strings']['LBL_DASHLET_CONFIGURE_AUTOREFRESH']); $ss->assign('autoRefreshOptions', $this->getAutoRefreshOptions()); $ss->assign('autoRefreshSelect', $this->autoRefresh); } return parent::displayOptions() . $ss->fetch('modules/Home/Dashlets/RSSDashlet/RSSDashletOptions.tpl'); } /** * called to filter out $_REQUEST object when the user submits the configure dropdown * * @param array $req $_REQUEST * @return array filtered options to save */ public function saveOptions( array $req ) { $options = array(); $options['title'] = $req['title']; $options['url'] = $req['url']; $options['height'] = $req['height']; $options['autoRefresh'] = empty($req['autoRefresh']) ? '0' : $req['autoRefresh']; return $options; } protected function getRSSOutput( $url ) { // suppress XML errors libxml_use_internal_errors(true); $rssdoc = simplexml_load_file($url); // return back the error message if the loading wasn't successful if (!$rssdoc) return $this->dashletStrings['ERR_LOADING_FEED']; $output = ""; if ( isset($rssdoc->channel) ) { foreach ( $rssdoc->channel as $channel ) { if ( isset($channel->item ) ) { foreach ( $channel->item as $item ) { $output .= << EOHTML; } } } } else { foreach ( $rssdoc->entry as $entry ) { $output .= << EOHTML; } } $output .= "

{$item->title}

{$item->description}

{$entry->title}

{$entry->summary}
"; return $output; } }