Example #1
0
 /**
  * Generates the newsfeed and writes it to disc.
  *
  */
 public function generateNewsRssFeed()
 {
     $dom = new DOMDocument();
     $dom->formatOutput = true;
     $el_root = $dom->appendChild($dom->createElement('rss'));
     $el_root->setAttribute('version', '2.0');
     $el_channel = $el_root->appendChild($dom->createElement('channel'));
     $el_channel->appendChild($dom->createElement('title', $this->title));
     $el_channel->appendChild($dom->createElement('link', $this->link));
     $el_channel->appendChild($dom->createElement('description', $this->desc));
     if ($this->lang != '') {
         $el_channel->appendChild($dom->createElement('language', $this->lang));
     }
     $el_channel->appendChild($dom->createElement('docs', $this->docs));
     $el_channel->appendChild($dom->createElement('lastBuildDate', date(DATE_RSS)));
     $el_channel->appendChild($dom->createElement('generator', 'OBBLM ' . OBBLM_VERSION));
     $entries = array();
     foreach ($this->type as $t) {
         $obj = (object) null;
         switch ($t) {
             case T_TEXT_MSG:
                 foreach (Message::getMessages(RSS_SIZE) as $item) {
                     $entries[] = (object) array('title' => "Announcement by " . get_alt_col('coaches', 'coach_id', $item->f_coach_id, 'name') . ": {$item->title}", 'desc' => $item->message, 'date' => $item->date);
                 }
                 break;
             case 'HOF':
                 if (Module::isRegistered('HOF')) {
                     foreach (Module::run('HOF', array('getHOF', false, RSS_SIZE)) as $item) {
                         $item = $item['hof'];
                         $entries[] = (object) array('title' => "HOF entry for " . get_alt_col('players', 'player_id', $item->pid, 'name') . ": {$item->title}", 'desc' => $item->about, 'date' => $item->date);
                     }
                 }
                 break;
             case 'Wanted':
                 if (Module::isRegistered('Wanted')) {
                     foreach (Module::run('Wanted', array('getWanted', false, RSS_SIZE)) as $item) {
                         $item = $item['wanted'];
                         $entries[] = (object) array('title' => "Wanted entry for " . get_alt_col('players', 'player_id', $item->pid, 'name') . ": {$item->bounty}", 'desc' => $item->why, 'date' => $item->date);
                     }
                 }
                 break;
             case T_TEXT_MATCH_SUMMARY:
                 foreach (MatchSummary::getSummaries(RSS_SIZE) as $item) {
                     $m = new Match($item->match_id);
                     $entries[] = (object) array('title' => "Match: {$m->team1_name} ({$m->team1_score}) vs. {$m->team2_name} ({$m->team2_score})", 'desc' => $m->getText(), 'date' => $m->date_played);
                 }
                 break;
             case T_TEXT_TNEWS:
                 foreach (TeamNews::getNews(false, RSS_SIZE) as $item) {
                     $entries[] = (object) array('title' => "Team news by " . get_alt_col('teams', 'team_id', $item->f_id, 'name'), 'desc' => $item->txt, 'date' => $item->date);
                 }
                 break;
         }
     }
     objsort($entries, array('-date'));
     foreach (array_slice($entries, 0, RSS_SIZE) as $item) {
         $el_item = $dom->createElement('item');
         $el_item->appendChild($dom->createElement('title', htmlspecialchars($item->title, ENT_NOQUOTES, "UTF-8")));
         $el_item->appendChild($dom->createElement('description', htmlspecialchars($item->desc, ENT_NOQUOTES, "UTF-8")));
         $el_item->appendChild($dom->createElement('link', $this->link));
         #            $el_item->appendChild($dom->createElement('pubDate', $item->date));
         $el_item->appendChild($dom->createElement('pubDate', date('r', strtotime($item->date))));
         $el_item->appendChild($dom->createElement('guid', $this->link . 'index.php?' . date('U', strtotime($item->date))));
         # RSS 2.0 dirty workaround.
         $el_channel->appendChild($el_item);
     }
     // Write the file
     $handle = fopen("rss.xml", "w");
     fwrite($handle, $dom->saveXML());
     fclose($handle);
     return $dom->saveXML();
 }
Example #2
0
 public static function getMainBoardMessages($n, $lid = false, $get_tnews = true, $get_summaries = true)
 {
     global $settings;
     $board = array();
     // First we add all commissioner messages to the board structure.
     foreach (Message::getMessages($n, $lid) as $m) {
         $o = (object) array();
         // Specific fields:
         $o->msg_id = $m->msg_id;
         $o->author_id = $m->f_coach_id;
         // General fields:
         $o->cssidx = T_HTMLBOX_ADMIN;
         // CSS box index
         $o->type = T_TEXT_MSG;
         $o->author = get_alt_col('coaches', 'coach_id', $m->f_coach_id, 'name');
         $o->title = $m->title;
         $o->message = $m->message;
         $o->date = $m->date_posted;
         $o->pinned = $m->pinned;
         array_push($board, $o);
     }
     // Now we add all game summaries.
     if ($get_summaries) {
         foreach (MatchSummary::getSummaries($n, $lid) as $r) {
             $o = (object) array();
             $m = new Match($r->match_id);
             // Specific fields:
             $o->date_mod = $m->date_modified;
             $o->match_id = $m->match_id;
             // General fields:
             $o->cssidx = T_HTMLBOX_MATCH;
             // CSS box index
             $o->type = T_TEXT_MATCH_SUMMARY;
             $o->author = get_alt_col('coaches', 'coach_id', $m->submitter_id, 'name');
             $o->title = "Match: {$m->team1_name} {$m->team1_score}—{$m->team2_score} {$m->team2_name}";
             $o->message = $m->getText();
             $o->date = $m->date_played;
             $o->pinned = 0;
             // Not allowed for other types than board messages
             array_push($board, $o);
         }
     }
     // And finally team news.
     if ($get_tnews) {
         foreach (TeamNews::getNews(false, $n, $lid) as $t) {
             $o = (object) array();
             // Specific fields:
             # none
             // General fields:
             $o->cssidx = T_HTMLBOX_INFO;
             // CSS box index
             $o->type = T_TEXT_TNEWS;
             $o->author = get_alt_col('teams', 'team_id', $t->f_id, 'name');
             $o->title = "Team news: {$o->author}";
             $o->message = $t->txt;
             $o->date = $t->date;
             $o->pinned = 0;
             // Not allowed for other types than board messages
             array_push($board, $o);
         }
     }
     // Last touch on the board.
     if (!empty($board)) {
         objsort($board, array('-pinned', '-date'));
         if ($n) {
             $board = array_slice($board, 0, $n);
         }
     }
     return $board;
 }
Example #3
0
 public function saveText($str)
 {
     $txt = new MatchSummary($this->match_id);
     return $txt->save($str);
 }