Esempio n. 1
0
 /**
  * Returns a RSS feed. Cached result is returned if exists.
  */
 public function view()
 {
     $cache_key = $this->module . '_cache_key';
     $content = PHPWS_Cache::get($cache_key, RSS_CACHE_TIMEOUT);
     if (!empty($content)) {
         return $content;
     }
     if (empty($this->_feeds)) {
         $this->loadFeeds();
     }
     $home_http = PHPWS_Core::getHomeHttp();
     $template['CHANNEL_TITLE'] = $this->EncodeString($this->title);
     $template['CHANNEL_ADDRESS'] = $this->getAddress();
     $template['HOME_ADDRESS'] = $home_http;
     $template['CHANNEL_DESCRIPTION'] = $this->EncodeString($this->description);
     $template['LANGUAGE'] = CURRENT_LANGUAGE;
     // change later
     $template['SEARCH_LINK'] = sprintf('%sindex.php?module=search&mod_title=%s&user=search', $home_http, $this->module);
     $template['SEARCH_DESCRIPTION'] = sprintf('Search in %s', $this->title);
     $template['SEARCH_NAME'] = 'search';
     $template['COPYRIGHT'] = PHPWS_Settings::get('rss', 'copyright');
     $template['WEBMASTER'] = PHPWS_Settings::get('rss', 'webmaster');
     $template['MANAGING_EDITOR'] = PHPWS_Settings::get('rss', 'editor');
     //        $template['LAST_BUILD_DATE'] = $this->_last_build_date;
     $timezone = strftime('%z');
     $timezone = substr($timezone, 0, 3) . ':' . substr($timezone, 3, 2);
     if ($this->_feeds) {
         foreach ($this->_feeds as $key) {
             $itemTpl = NULL;
             $url = preg_replace('/^\\.\\//', '', $key->url);
             $url = $home_http . preg_replace('/&(?!amp;)/', '&', $url);
             $itemTpl['ITEM_LINK'] = $url;
             $itemTpl['ITEM_TITLE'] = $this->EncodeString($key->title);
             $itemTpl['ITEM_GUID'] = $url;
             $itemTpl['ITEM_LINK'] = $url;
             $itemTpl['ITEM_SOURCE'] = sprintf('%sindex.php?module=rss&mod_title=%s', $home_http, $this->module);
             $itemTpl['ITEM_DESCRIPTION'] = strip_tags(trim($this->EncodeString($key->summary)));
             $itemTpl['ITEM_AUTHOR'] = $key->creator;
             //              $itemTpl['ITEM_PUBDATE']      = $key->getCreateDate('%Y-%m-%d %H:%M:%S CST');
             $itemTpl['ITEM_PUBDATE'] = $this->rssDate($key->create_date);
             $itemTpl['ITEM_DC_DATE'] = $key->getCreateDate('%Y-%m-%dT%H:%M:%S') . $timezone;
             $itemTpl['ITEM_DC_TYPE'] = 'Text';
             //pull from db later
             $itemTpl['ITEM_DC_CREATOR'] = $key->creator;
             $itemTpl['ITEM_SOURCE_TITLE'] = $this->EncodeString($this->title);
             $template['item-listing'][] = $itemTpl;
         }
     }
     if (PHPWS_Settings::get('rss', 'rssfeed') == 2) {
         $tpl_file = 'rss20.tpl';
     } else {
         $tpl_file = 'rss10.tpl';
     }
     $content = PHPWS_Template::process($template, 'rss', $tpl_file);
     $content = utf8_encode($content);
     PHPWS_Cache::save($cache_key, $content);
     return $content;
 }
Esempio n. 2
0
 public static function whatsnewBlock()
 {
     if (PHPWS_Settings::get('whatsnew', 'cache_timeout') > 0) {
         $cache_key = 'whatsnew_cache_key';
         $content = PHPWS_Cache::get($cache_key, PHPWS_Settings::get('whatsnew', 'cache_timeout'));
         if (!empty($content)) {
             return $content;
         }
     }
     $link = null;
     $summary = null;
     $date = null;
     $module_name = null;
     $exclude = unserialize(PHPWS_Settings::get('whatsnew', 'exclude'));
     $db = new PHPWS_DB('phpws_key');
     $db->addJoin('left', 'phpws_key', 'modules', 'module', 'title');
     $db->addWhere('active', 1);
     $db->addWhere('restricted', 0);
     if ($exclude) {
         foreach ($exclude as $module) {
             $db->addWhere('module', $module, '!=');
         }
     }
     $db->addOrder('update_date desc');
     $db->setLimit(PHPWS_Settings::get('whatsnew', 'qty_items'));
     $db->setIndexBy('id');
     $db->addColumn('phpws_key.url');
     $db->addColumn('phpws_key.title');
     $db->addColumn('phpws_key.summary');
     $db->addColumn('phpws_key.update_date');
     $db->addColumn('modules.title', null, 'module_title');
     $db->addColumn('modules.proper_name');
     //        $db->setTestMode();
     $result = $db->select();
     $tpl['TITLE'] = PHPWS_Text::parseOutput(PHPWS_Settings::get('whatsnew', 'title'));
     $tpl['TEXT'] = PHPWS_Text::parseOutput(PHPWS_Settings::get('whatsnew', 'text'));
     if (!PHPWS_Error::logIfError($result) && !empty($result)) {
         foreach ($result as $item) {
             $link = '<a href="' . $item['url'] . '">' . $item['title'] . '</a>';
             if (PHPWS_Settings::get('whatsnew', 'show_summaries')) {
                 $summary = PHPWS_Text::parseOutput($item['summary']);
             }
             if (PHPWS_Settings::get('whatsnew', 'show_dates')) {
                 $date = strftime(WHATSNEW_DATE_FORMAT, $item['update_date']);
             }
             if (PHPWS_Settings::get('whatsnew', 'show_source_modules')) {
                 $module_name = dgettext($item['module_title'], PHPWS_Text::parseOutput($item['proper_name']));
             }
             $tpl['new-items'][] = array('LINK' => $link, 'SUMMARY' => $summary, 'DATE' => $date, 'MODULE_NAME' => $module_name);
         }
     } else {
         $tpl['new-items'][] = array('LINK' => dgettext('whatsnew', 'Sorry, no results'));
     }
     $content = PHPWS_Template::process($tpl, 'whatsnew', 'block.tpl');
     if (PHPWS_Settings::get('whatsnew', 'cache_timeout') > 0 && !Current_User::isLogged() && !Current_User::allow('whatsnew')) {
         PHPWS_Cache::save($cache_key, $content);
     }
     return $content;
 }
Esempio n. 3
0
 public function month_list()
 {
     if (PHPWS_Settings::get('calendar', 'use_calendar_style')) {
         Layout::addStyle('calendar');
     }
     $month =& $this->calendar->int_month;
     $year =& $this->calendar->int_year;
     $day = 1;
     if ($this->calendar->schedule->public && !Current_User::isLogged() && PHPWS_Settings::get('calendar', 'cache_month_views')) {
         $cache_key = sprintf('list_%s_%s_%s', $month, $year, $this->calendar->schedule->id);
     }
     if (isset($cache_key)) {
         // Check cache
         $content = PHPWS_Cache::get($cache_key);
         if (!empty($content)) {
             return $content;
         }
     }
     // cache empty, make calendar
     $startdate = mktime(0, 0, 0, $month, 1, $year);
     $enddate = mktime(23, 59, 59, $month + 1, 0, $year);
     $date_pick = $this->getDatePick();
     $this->calendar->loadEventList($startdate, $enddate);
     $tpl = new PHPWS_Template('calendar');
     $tpl->setFile('view/month/list.tpl');
     $events_found = false;
     $lvars = array('view' => 'day', 'schedule_id' => $this->calendar->schedule->id);
     $slink = new PHPWS_Link(null, 'calendar');
     $slink->setNoFollow(PHPWS_Settings::get('calendar', 'no_follow'));
     for ($i = $startdate; $i <= $enddate; $i += 86400) {
         $day_result = $this->getDaysEvents($i, $tpl);
         $lvars['date'] = $i;
         $slink->clearValues();
         $slink->addValues($lvars);
         if ($day_result) {
             $events_found = true;
             $slink->setLabel(strftime('%A', $i));
             $day_tpl['FULL_WEEKDAY'] = $slink->get();
             $slink->setLabel(strftime('%a', $i));
             $day_tpl['ABBR_WEEKDAY'] = $slink->get();
             $slink->setLabel(strftime('%e', $i));
             $day_tpl['DAY_NUMBER'] = $slink->get();
             $tpl->setCurrentBlock('days');
             $tpl->setData($day_tpl);
             $tpl->parseCurrentBlock();
         }
     }
     if (!$events_found) {
         $tpl->setVariable('MESSAGE', dgettext('calendar', 'No events this month.'));
     }
     $main_tpl = $this->viewLinks('list');
     $main_tpl['FULL_MONTH_NAME'] = strftime('%B', mktime(0, 0, 0, $month, $day, $year));
     $main_tpl['ABRV_MONTH_NAME'] = strftime('%b', mktime(0, 0, 0, $month, $day, $year));
     $main_tpl['SCHEDULE_TITLE'] = $this->calendar->schedule->title;
     $main_tpl['FULL_YEAR'] = strftime('%Y', mktime(0, 0, 0, $month, $day, $year));
     $main_tpl['ABRV_YEAR'] = strftime('%y', mktime(0, 0, 0, $month, $day, $year));
     $main_tpl['SCHEDULE_PICK'] = $this->schedulePick();
     $main_tpl['PICK'] = $date_pick;
     $main_tpl['DOWNLOAD'] = $this->downloadLink($startdate, $enddate);
     $main_tpl['SUGGEST'] = $this->suggestLink();
     if ($this->calendar->schedule->checkPermissions()) {
         $main_tpl['ADD_EVENT'] = '<button class="add-event btn btn-success" data-schedule-id="' . $this->calendar->schedule->id . '" data-date="' . $this->calendar->current_date * 1000 . '"><i class="fa fa-plus"></i> Add event</button>';
     }
     $tpl->setData($main_tpl);
     $content = $tpl->get();
     if (isset($cache_key)) {
         PHPWS_Cache::save($cache_key, $content);
     }
     return $content;
 }
Esempio n. 4
0
 public function loadParser($use_cache = TRUE)
 {
     if (empty($this->address)) {
         return FALSE;
     }
     if ($use_cache) {
         $cache_key = $this->address;
         $data = PHPWS_Cache::get($cache_key, $this->refresh_time);
     }
     if (!empty($data)) {
         $this->mapped = unserialize($data);
         return TRUE;
     } else {
         if (isset($this->_parser) && empty($this->_parser->error)) {
             return TRUE;
         }
         $this->_parser = new XMLParser($this->address);
         if ($this->_parser->error) {
             PHPWS_Error::log($this->_parser->error);
             return FALSE;
         }
         $this->mapData();
         if ($use_cache) {
             PHPWS_Cache::save($cache_key, serialize($this->mapped));
         }
     }
     return TRUE;
 }