/**
  * Grab the RSS document content and return it
  *
  * @access	public
  * @return	string		RSS document
  */
 public function returnRSSDocument()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $member_id = intval(ipsRegistry::$request['member_id']);
     $secure_key = IPSText::md5Clean(ipsRegistry::$request['rss_key']);
     $rss_data = array();
     $to_print = '';
     if ($secure_key and $member_id) {
         if ($member_id == ipsRegistry::member()->getProperty('member_id')) {
             //-----------------------------------------
             // Get RSS export
             //-----------------------------------------
             $rss_data = ipsRegistry::DB()->buildAndFetch(array('select' => 'rss_cache', 'from' => 'rc_modpref', 'where' => "mem_id=" . $member_id . " AND rss_key='" . $secure_key . "'"));
             //-----------------------------------------
             // Got one?
             //-----------------------------------------
             if ($rss_data['rss_cache']) {
                 return $rss_data['rss_cache'];
             }
         }
         //-----------------------------------------
         // Create a dummy one
         //-----------------------------------------
         ipsRegistry::getClass('class_localization')->loadLanguageFile(array('public_reports'), 'core');
         require_once IPS_KERNEL_PATH . 'classRss.php';
         $rss = new classRss();
         $channel_id = $rss->createNewChannel(array('title' => ipsRegistry::getClass('class_localization')->words['rss_feed_title'], 'link' => ipsRegistry::$settings['board_url'], 'description' => ipsRegistry::getClass('class_localization')->words['reports_rss_desc'], 'pubDate' => $rss->formatDate(time())));
         $rss->createRssDocument();
         return $rss->rss_document;
     }
 }
 /**
  * Build a private RSS feed for the member to monitor reports
  *
  * @access	private
  * @return	void
  */
 private function _buildRSSFeed($data = array(), $report_data)
 {
     $ids = array();
     $this->registry->getClass('class_localization')->loadLanguageFile(array('public_reports'), 'core');
     if (is_array($data) and count($data)) {
         foreach ($data as $user) {
             $ids[] = $user['member_id'];
         }
     }
     if (count($ids) == 0) {
         return;
     }
     require_once IPS_KERNEL_PATH . 'classRss.php';
     $status = array();
     $this->DB->build(array('select' => 'status, is_new, is_complete', 'from' => 'rc_status', 'where' => "is_new=1 OR is_complete=1"));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         if ($row['is_new'] == 1) {
             $status['new'] = $row['status'];
         } elseif ($row['is_complete'] == 1) {
             $status['complete'] = $row['status'];
         }
     }
     //-----------------------------------------
     // Now, we loop over each of the member ids
     //-----------------------------------------
     foreach ($ids as $id) {
         //-----------------------------------------
         // Clear out for new RSS doc and add channel
         //-----------------------------------------
         $rss = new classRss();
         $channel_id = $rss->createNewChannel(array('title' => $this->lang->words['rss_feed_title'], 'link' => $this->settings['board_url'], 'description' => $this->lang->words['reports_rss_desc'], 'pubDate' => $rss->formatDate(time())));
         //-----------------------------------------
         // Now we need to find all open reports for
         // this member
         //-----------------------------------------
         $this->DB->build(array('select' => 'i.*', 'from' => array('rc_reports_index' => 'i'), 'where' => 's.is_active=1', 'add_join' => array(array('from' => array('rc_status' => 's'), 'where' => 's.status=i.status', 'type' => 'left'), array('select' => 'c.my_class, c.mod_group_perm', 'from' => array('rc_classes' => 'c'), 'where' => 'c.com_id=i.rc_class', 'type' => 'left'))));
         $outer = $this->DB->execute();
         while ($r = $this->DB->fetch($outer)) {
             //-----------------------------------------
             // Fix stuff....this is hackish :(
             //-----------------------------------------
             if ($r['my_class'] == 'post') {
                 $r['FORUM_ID'] = $r['exdat1'];
             }
             //-----------------------------------------
             // Found all open reports, can we access?
             //-----------------------------------------
             require_once IPSLib::getAppdir('core') . '/sources/reportPlugins/' . $r['my_class'] . '.php';
             $class = $r['my_class'] . '_plugin';
             $object = new $class($this->registry);
             $notify = $object->getNotificationList(IPSText::cleanPermString($r['mod_group_perm']), $r);
             $pass = false;
             if (is_array($notify['RSS']) and count($notify['RSS'])) {
                 foreach ($notify['RSS'] as $memberAccount) {
                     if ($memberAccount['mem_id'] == $id) {
                         $pass = true;
                         break;
                     }
                 }
             }
             if ($pass) {
                 $url = $this->registry->getClass('reportLibrary')->processUrl(str_replace('&', '&', $r['url']));
                 $rss->addItemToChannel($channel_id, array('title' => $url, 'link' => $url, 'description' => $r['title'], 'content' => $r['title'], 'pubDate' => $rss->formatDate($r['date_updated'])));
             }
         }
         $rss->createRssDocument();
         $this->DB->update('rc_modpref', array('rss_cache' => $rss->rss_document), "mem_id=" . $id);
     }
 }
 /**
  * Rebuild the RSS Cache
  *
  * @access	public
  * @param	mixed	$calendar_id	Specify which calendar to rebuild, all is default
  * @param	bool	$return			If set to 0, the cache will be output to the browser
  * @return	mixed	void, or the RSS document
  */
 public function calendarRSSCache($calendar_id = 'all', $return = 0)
 {
     /* INIT */
     $seenids = array();
     $calevents = "";
     /* Calendar Class */
     require_once IPSLib::getAppDir('calendar') . '/modules_public/calendar/calendars.php';
     $calendar = new public_calendar_calendar_calendars();
     $calendar->makeRegistryShortcuts($this->registry);
     /* RSS Class */
     require_once IPS_KERNEL_PATH . 'classRss.php';
     $class_rss = new classRss();
     $class_rss->use_sockets = $this->use_sockets;
     $class_rss->doc_type = IPS_DOC_CHAR_SET;
     /* Reset the cache */
     $cache = array();
     /* Get the calendars */
     $this->DB->build(array('select' => 'c.*', 'from' => array('cal_calendars' => 'c'), 'where' => 'c.cal_rss_export_days > 0 AND c.cal_rss_export_max > 0 AND c.cal_rss_export=1', 'add_join' => array(array('select' => 'p.*', 'from' => array('permission_index' => 'p'), 'where' => "p.perm_type='calendar' AND perm_type_id=c.cal_id", 'type' => 'left'))));
     $outer = $this->DB->execute();
     /* Loop through the calendars */
     while ($row = $this->DB->fetch($outer)) {
         //print_r($row);exit;
         /* Add Calendar to cache */
         if ($row['cal_rss_export']) {
             $cache[] = array('url' => $this->settings['board_url'] . '/index.php?app=core&module=global&section=rss&type=calendar&id=' . $row['cal_id'], 'title' => $row['cal_title']);
         }
         /* Are we including events from this calendar? */
         if ($calendar_id == $row['cal_id'] or $calendar_id == 'all') {
             /* Create the RSS Channel */
             $channel_id = $class_rss->createNewChannel(array('title' => $row['cal_title'], 'link' => $this->settings['board_url'] . '/index.php?app=calendar&module=calendar&cal_id=' . $row['cal_id'], 'pubDate' => $class_rss->formatDate(time()), 'ttl' => $row['cal_rss_update'] * 60, 'description' => $row['cal_title']));
             /* Check guest permissions */
             if ($row['perm_view'] == '*' or preg_match("/(^|,)" . $this->settings['guest_group'] . "(,|\$)/", $row['perm_view'])) {
                 $pass = 1;
             }
             if (!$pass) {
                 continue;
             }
             /* Sort out the dates */
             $row['cal_rss_export_days'] = intval($row['cal_rss_export_days']) + 1;
             list($month, $day, $year) = explode(',', gmdate('n,j,Y', time()));
             $timenow = gmmktime(0, 0, 0, $month, 1, $year);
             $timethen = time() + $row['cal_rss_export_days'] * 86400 + 86400;
             $nowtime = time() - 86400;
             $items = 0;
             /* Get Events */
             $calendar->calendarGetEventsSQL(0, 0, array('timenow' => $timenow, 'timethen' => $timethen, 'cal_id' => $row['cal_id']), 0);
             /* Check the events */
             for ($i = 0; $i <= $row['cal_rss_export_days']; $i++) {
                 /* Get the month, day, and year */
                 list($month, $day, $year) = explode(',', gmdate('n,j,Y', $nowtime));
                 /* Get the events for this day */
                 $eventcache = $calendar->calendarGetDayEvents($month, $day, $year);
                 /* Loop through the events */
                 foreach ($eventcache as $event) {
                     if (!in_array($event['event_id'], $seenids)) {
                         /* Reached the max? */
                         if ($row['cal_rss_export_max'] <= $items) {
                             break;
                         }
                         /* Get the event info */
                         if ($calendar->getInfoEvents($event, $month, $day, $year, 0)) {
                             /* Approved */
                             if (!$event['event_approved']) {
                                 continue;
                             }
                             /* Check Private */
                             if ($event['event_private']) {
                                 continue;
                             }
                             /* Check Permis */
                             if ($event['event_perms'] != '*' and !preg_match("/(^|,)" . $this->settings['guest_group'] . "(,|\$)/", $event['event_perms'])) {
                                 continue;
                             }
                             /* Get Dates */
                             list($m, $d, $y) = explode(",", gmdate('n,j,Y', $event['event_unix_from']));
                             list($m1, $d1, $y1) = explode(",", gmdate('n,j,Y', $event['event_unix_to']));
                             $event['_from_month'] = $m;
                             $event['_from_day'] = $d;
                             $event['_from_year'] = $y;
                             $event['_to_month'] = $m1;
                             $event['_to_day'] = $d1;
                             $event['_to_year'] = $y1;
                             //-----------------------------------------
                             // Coming from RSS rebuild?
                             //-----------------------------------------
                             if (!$this->html) {
                                 /* Load Skin and Lang */
                                 $this->html = $this->registry->output->getTemplate('calendar');
                                 $this->lang->loadLanguageFile(array('admin_calendar'));
                             }
                             //-----------------------------------------
                             // Parse bbcode
                             //-----------------------------------------
                             IPSText::getTextClass('bbcode')->parse_html = 0;
                             IPSText::getTextClass('bbcode')->parse_smilies = intval($event['event_smilies']);
                             IPSText::getTextClass('bbcode')->parse_bbcode = 1;
                             IPSText::getTextClass('bbcode')->parsing_section = 'calendar';
                             IPSText::getTextClass('bbcode')->parsing_mgroup = $event['member_group_id'];
                             IPSText::getTextClass('bbcode')->parsing_mgroup_others = $event['mgroup_others'];
                             $event['event_content'] = IPSText::getTextClass('bbcode')->preDisplayParse($event['event_content']);
                             if ($event['recurring']) {
                                 $event['event_content'] = $this->html->calendar_rss_recurring($event);
                             } else {
                                 if ($event['single']) {
                                     $event['event_content'] = $this->html->calendar_rss_single($event);
                                 } else {
                                     $event['event_content'] = $this->html->calendar_rss_range($event);
                                 }
                             }
                             $event['event_unix_from'] = $event['event_tz'] ? $event['event_unix_from'] : $event['event_unix_from'] + $this->settings['time_offset'] * 3600;
                             /* Add the item to our channel */
                             $class_rss->addItemToChannel($channel_id, array('title' => $event['event_title'], 'link' => $this->settings['board_url'] . '/index.php?app=calendar&amp;module=calendar&amp;do=showevent&amp;cal_id=' . $row['cal_id'] . '&amp;event_id=' . $event['event_id'], 'description' => $event['event_content'], 'pubDate' => $class_rss->formatDate($event['event_unix_from']), 'guid' => $event['event_id']));
                         }
                         /* Increment */
                         $seenids[$event['event_id']] = $event['event_id'];
                         $items++;
                     }
                 }
                 $nowtime += 86400;
             }
             /* Create the RSS Document */
             $class_rss->createRssDocument();
             /* Update the cache */
             $this->DB->update('cal_calendars', array('cal_rss_update_last' => time(), 'cal_rss_cache' => $class_rss->rss_document), 'cal_id=' . $row['cal_id']);
         }
     }
     /* Update Cache */
     $this->cache->setCache('rss_calendar', $cache, array('name' => 'rss_calendar', 'deletefirst' => 1, 'donow' => 1, 'array' => 1));
     /* Return */
     if ($return) {
         $this->registry->output->global_message = $this->lang->words['c_rssrecached'];
         $this->calendarsList();
         return;
     } else {
         return $class_rss->rss_document;
     }
 }
 /**
  * Rebuild Export Cache
  *
  * @access	public
  * @param	mixed	$rss_export_id	Which export id to execute
  * @param	bool	$return			Whether to return afterwards or output to page
  * @return	mixed
  **/
 public function rssExportRebuildCache($rss_export_id = '', $return = true)
 {
     /* INIT */
     if (!$rss_export_id) {
         $rss_export_id = $this->request['rss_export_id'] == 'all' ? 'all' : intval($this->request['rss_export_id']);
     }
     /* Check ID */
     if (!$rss_export_id) {
         $this->registry->output->global_message = $this->lang->words['ex_noid'];
         $this->rssExportOverview();
         return;
     }
     /* Get RSS Clas */
     require_once IPS_KERNEL_PATH . 'classRss.php';
     $class_rss = new classRss();
     $class_rss->use_sockets = $this->use_sockets;
     $class_rss->doc_type = IPS_DOC_CHAR_SET;
     /* Reset rss_export cache */
     $this->cache->updateCacheWithoutSaving('rss_export', array());
     /* Go loopy */
     $this->DB->build(array('select' => '*', 'from' => 'rss_export'));
     $outer = $this->DB->execute();
     $cache = array();
     while ($row = $this->DB->fetch($outer)) {
         /* Update RSS Cache */
         if ($row['rss_export_enabled']) {
             $cache[] = array('url' => $this->settings['board_url'] . '/index.php?act=rssout&amp;id=' . $row['rss_export_id'], 'title' => $row['rss_export_title']);
         }
         /* Add to cache? */
         if ($rss_export_id == 'all' or $row['rss_export_id'] == $rss_export_id) {
             /* Build DB Query */
             if ($row['rss_export_include_post']) {
                 $this->DB->build(array('select' => 't.*', 'from' => array('topics' => 't'), 'where' => "t.forum_id IN( " . $row['rss_export_forums'] . " ) AND t.state != 'link' AND t.approved=1", 'order' => 't.' . $row['rss_export_order'] . ' ' . $row['rss_export_sort'], 'limit' => array(0, $row['rss_export_count']), 'add_join' => array(array('select' => 'p.pid, p.post, p.use_emo, p.post_htmlstate', 'from' => array('posts' => 'p'), 'where' => 't.topic_firstpost=p.pid', 'type' => 'left'))));
             } else {
                 $this->DB->build(array('select' => '*', 'from' => 'topics', 'where' => "forum_id IN( " . $row['rss_export_forums'] . " ) AND state != 'link' AND approved=1", 'order' => $row['rss_export_order'] . ' ' . $row['rss_export_sort'], 'limit' => array(0, $row['rss_export_count'])));
             }
             /* Exec Query */
             $inner = $this->DB->execute();
             /* Set var.  Doing this so we can set pubDate to start date or last post date appropriately... */
             $channelCreated = false;
             /* Loop through topics and display */
             while ($topic = $this->DB->fetch($inner)) {
                 //-----------------------------------------
                 // Create channel if not already crated
                 //-----------------------------------------
                 if (!$channelCreated) {
                     /* Create Channel */
                     $channel_id = $class_rss->createNewChannel(array('title' => $row['rss_export_title'], 'description' => $row['rss_export_desc'], 'link' => $this->settings['board_url'] . '/index.php', 'pubDate' => $class_rss->formatDate($row['rss_export_order'] == 'start_date' ? $topic['start_date'] : $topic['last_post']), 'ttl' => $row['rss_export_cache_time']));
                     if ($row['rss_export_image']) {
                         $class_rss->addImageToChannel($channel_id, array('title' => $row['rss_export_title'], 'url' => $row['rss_export_image'], 'link' => $this->settings['board_url'] . '/index.php'));
                     }
                     $channelCreated = true;
                 }
                 //-----------------------------------------
                 // Parse the post
                 //-----------------------------------------
                 $this->settings['__noTruncateUrl'] = 1;
                 IPSText::getTextClass('bbcode')->parse_smilies = $topic['use_emo'];
                 IPSText::getTextClass('bbcode')->parse_html = ($this->registry->class_forums->forum_by_id[$topic['forum_id']]['use_html'] and $topic['post_htmlstate']) ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_nl2br = $topic['post_htmlstate'] == 2 ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_bbcode = 1;
                 IPSText::getTextClass('bbcode')->parsing_section = 'topics';
                 $topic['post'] = IPSText::getTextClass('bbcode')->preDisplayParse($topic['post']);
                 if ($row['rss_export_include_post'] and $topic['topic_hasattach']) {
                     if (!is_object($_attachments)) {
                         //-----------------------------------------
                         // Grab render attach class
                         //-----------------------------------------
                         require_once IPSLib::getAppDir('core') . '/sources/classes/attach/class_attach.php';
                         $_attachments = new class_attach($this->registry);
                     }
                     $_attachments->type = 'post';
                     $_attachments->init();
                     # attach_pids is generated in the func_topic_xxxxx files
                     $attachHTML = $_attachments->renderAttachments(array($topic['pid'] => $topic['post']), array($topic['pid'] => $topic['pid']));
                     /* Now parse back in the rendered posts */
                     if (is_array($attachHTML) and count($attachHTML)) {
                         foreach ($attachHTML as $id => $data) {
                             /* Get rid of any lingering attachment tags */
                             if (stristr($data['html'], "[attachment=")) {
                                 $data['html'] = IPSText::stripAttachTag($data['html']);
                             }
                             $topic['post'] = $data['html'];
                             $topic['post'] .= $data['attachmentHtml'];
                         }
                     }
                 }
                 /* Parse */
                 //$topic['post'] = preg_replace( "#\[attachment=(\d+?)\:(?:[^\]]+?)\]#is", "<a href='{$this->settings['board_url']}/index.php?app=core&module=attach&section=attach&attach_rel_module=post&attach_id=\\1'>".$this->settings['board_url']."/index.php?app=forums&module=forums&section=attach&type=post&attach_id=\\1</a>", $topic['post'] );
                 /* Fix up relative URLs */
                 $topic['post'] = preg_replace("#([^/])style_images/(<\\#IMG_DIR\\#>)#is", "\\1" . $this->settings['board_url'] . "/style_images/\\2", $topic['post']);
                 $topic['post'] = preg_replace("#([\"'])style_emoticons/#is", "\\1" . $this->settings['board_url'] . "/style_emoticons/", $topic['post']);
                 $topic['post'] = $this->registry->output->replaceMacros($topic['post']);
                 $topic['last_poster_name'] = $topic['last_poster_name'] ? $topic['last_poster_name'] : 'Guest';
                 $topic['starter_name'] = $topic['starter_name'] ? $topic['starter_name'] : 'Guest';
                 /* Add item */
                 $class_rss->addItemToChannel($channel_id, array('title' => $topic['title'], 'link' => $this->registry->output->buildSEOUrl('showtopic=' . $topic['tid'], 'public', $topic['title_seo'], 'showtopic'), 'description' => $topic['post'], 'pubDate' => $class_rss->formatDate($row['rss_export_order'] == 'last_post' ? $topic['last_post'] : $topic['start_date']), 'guid' => $this->registry->output->buildSEOUrl('showtopic=' . $topic['tid'], 'public', $topic['title_seo'], 'showtopic')));
             }
             /* Build document				 */
             $class_rss->createRssDocument();
             /* Update the cache */
             $this->DB->update('rss_export', array('rss_export_cache_last' => time(), 'rss_export_cache_content' => $class_rss->rss_document), 'rss_export_id=' . $row['rss_export_id']);
         }
     }
     /* Update cache */
     $this->cache->setCache('rss_export', $cache, array('deletefirst' => 1, 'donow' => 1, 'array' => 1));
     $this->cache->rebuildCache('rss_output_cache');
     /* Return */
     if ($return) {
         $this->registry->output->global_message = $this->lang->words['ex_recached'];
         $this->rssExportOverview();
         return;
     } else {
         return $class_rss->rss_document;
     }
 }