root = $root; $this->rss_state_path = "{$root}/{$rss_state_path}"; if (is_file($this->rss_state_path)) { $this->rss_items = BoostState::load($this->rss_state_path); // Temporary code to convert last_modified to date. foreach($this->rss_items as &$item) { if (!empty($item['last_modified']) && is_numeric($item['last_modified'])) { $item['last_modified'] = new DateTime("@{$item['last_modified']}"); } } unset($item); } } function generate_rss_feed($pages, $feed_data) { $feed_file = $feed_data['path']; $feed_pages = $feed_data['pages']; $rss_feed = $this->rss_prefix($feed_file, $feed_data); if (isset($feed_data['count'])) { $feed_pages = array_slice($feed_pages, 0, $feed_data['count']); } foreach ($feed_pages as $qbk_page) { $rss_item = BoostWebsite::array_get($this->rss_items, $qbk_page->qbk_file); if (!$rss_item || BoostWebsite::array_get($rss_item, 'update_count', 0) < $qbk_page->update_count) { $boostbook_values = BoostWebsite::array_get($pages->page_cache, $qbk_page->qbk_file); if ($boostbook_values) { $rss_item = $this->generate_rss_item($qbk_page, $boostbook_values, $pages->transform_page_html($qbk_page, $boostbook_values['description_xhtml'])); $rss_item['item'] = BoostSiteTools::trim_lines($rss_item['item']); $this->rss_items[$qbk_page->qbk_file] = $rss_item; } else { echo "No page contents for {$qbk_page->qbk_file}\n"; } } if ($rss_item) { $rss_feed .= $rss_item['item']; } } $rss_feed .= $this->rss_postfix($feed_file, $feed_data); BoostState::save($this->rss_items, $this->rss_state_path); file_put_contents("{$this->root}/{$feed_file}", $rss_feed); } function rss_prefix($feed_file, $details) { $title = $this->encode_for_rss($details['title']); $link = $this->encode_for_rss("http://www.boost.org/".$details['link']); $description = ''; $language = 'en-us'; $copyright = 'Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)'; return << Boost Website Site Tools {$title} {$link} {$description} {$language} {$copyright} EOL; } function rss_postfix($feed_file, $details) { return "\n \n\n"; } function generate_rss_item($page, $values, $description) { $xml = ''; $page_link = "http://www.boost.org/{$page->location}"; $xml .= ''; $xml .= ''.$this->encode_for_rss($values['title_xml']).''; // TODO: guid and link for beta/dev pages $xml .= ''.$this->encode_for_rss($page_link).''; $xml .= ''.$this->encode_for_rss($page_link).''; // Q: Maybe use $page->last_modified when there's no pub_date. $pub_date = null; if ($page->release_data && array_key_exists('release_date', $page->release_data)) { $pub_date = $page->release_data['release_date']; } else { $pub_date = $values['pub_date']; } if ($pub_date) { $xml .= ''.$this->encode_for_rss($pub_date->format(DATE_RSS)).''; } # Placing the description in a root element to make it well formed xml-> $description = BoostSiteTools::base_links($description, $page_link); $xml .= ''.$this->encode_for_rss($description).''; $xml .= ''; // Q: Should this be using the page last_modified, or when the RSS // feed item was last modified? return(array( 'item' => $xml, 'quickbook' => $page->qbk_file, 'last_modified' => $page->last_modified, 'update_count' => $page->update_count, )); } function encode_for_rss($x) { return htmlspecialchars($x, ENT_NOQUOTES); } }