示例#1
0
    function convert_quickbook_pages($refresh = false)
    {
        try {
            BoostSuperProject::run_process('quickbook --version');
            $have_quickbook = true;
        } catch (ProcessError $e) {
            echo "Problem running quickbook, will not convert quickbook articles.\n";
            $have_quickbook = false;
        }
        $bb_parser = new BoostBookParser();
        foreach ($this->pages as $page => $page_data) {
            if ($page_data->page_state || $refresh) {
                // Hash the quickbook source
                $hash = hash('sha256', str_replace("\r\n", "\n", file_get_contents("{$this->root}/{$page}")));
                // Get the page from quickbook/read from cache
                if (array_key_exists($page, $this->page_cache) && (!$have_quickbook || $this->page_cache[$page]['hash'] === $hash)) {
                    $description_xhtml = $this->page_cache[$page]['description_xhtml'];
                } else {
                    if ($have_quickbook) {
                        $xml_filename = tempnam(sys_get_temp_dir(), 'boost-qbk-');
                        try {
                            echo "Converting ", $page, ":\n";
                            BoostSuperProject::run_process("quickbook --output-file {$xml_filename} -I {$this->root}/feed {$this->root}/{$page}");
                            $values = $bb_parser->parse($xml_filename);
                            $page_data->load_boostbook_data($values, $refresh);
                            $description_xhtml = $values['description_xhtml'];
                        } catch (Exception $e) {
                            unlink($xml_filename);
                            throw $e;
                        }
                        unlink($xml_filename);
                        $this->page_cache[$page] = array('hash' => $hash, 'description_xhtml' => $description_xhtml);
                    } else {
                        echo "Unable to generate page for {$page}.\n";
                        continue;
                    }
                }
                // Set the path where the page should be built.
                // This can only be done after the quickbook file has been converted,
                // as the page id is based on the file contents.
                if (!$page_data->location) {
                    $location_data = $this->get_page_location_data($page_data->qbk_file);
                    $page_data->location = "{$location_data['destination']}/{$page_data->id}.html";
                }
                // Transform links in description
                if ($page_data->section === 'history') {
                    $doc_prefix = null;
                    if ($page_data->get_release_status() === 'dev' || $page_data->get_release_status() === 'beta') {
                        $doc_prefix = rtrim($page_data->get_documentation() ?: '/doc/libs/master/', '/');
                        $description_xhtml = BoostSiteTools::transform_links($description_xhtml, function ($x) use($doc_prefix) {
                            return preg_match('@^/(?:libs/|doc/html/)@', $x) ? $doc_prefix . $x : $x;
                        });
                    }
                    $version = BoostWebsite::array_get($page_data->release_data, 'version');
                    if ($version && $doc_prefix) {
                        $final_documentation = "/doc/libs/{$version->final_doc_dir()}";
                        $link_pattern = '@^' . preg_quote($final_documentation, '@') . '/@';
                        $replace = "{$doc_prefix}/";
                        $description_xhtml = BoostSiteTools::transform_links($description_xhtml, function ($x) use($link_pattern, $replace) {
                            return preg_replace($link_pattern, $replace, $x);
                        });
                    }
                }
                $description_xhtml = BoostSiteTools::trim_lines($description_xhtml);
                $page_data->description_xml = $description_xhtml;
                // Generate the various pages.
                $template_vars = array('history_style' => '', 'full_title_xml' => $page_data->full_title_xml(), 'title_xml' => $page_data->title_xml, 'note_xml' => '', 'web_date' => $page_data->web_date(), 'documentation_para' => '', 'download_table' => $page_data->download_table(), 'description_xml' => $page_data->description_xml);
                if ($page_data->get_release_status() === 'dev') {
                    $template_vars['note_xml'] = <<<EOL
                        <div class="section-alert"><p>Note: This release is
                        still under development. Please don't use this page as
                        a source of information, it's here for development
                        purposes only. Everything is subject to
                        change.</p></div>
EOL;
                }
                if ($page_data->section === 'history' && BoostWebsite::array_get($page_data->release_data, 'documentation')) {
                    $template_vars['documentation_para'] = '              <p><a href="' . html_encode(BoostWebsite::array_get($page_data->release_data, 'documentation')) . '">Documentation</a>';
                }
                if (strpos($page_data->location, 'users/history/') === 0) {
                    $template_vars['history_style'] = <<<EOL

  <style type="text/css">
/*<![CDATA[*/
  #content .news-description ul {
    list-style: none;
  }
  #content .news-description ul ul {
    list-style: circle;
  }
  /*]]>*/
  </style>

EOL;
                }
                self::write_template("{$this->root}/{$page_data->location}", __DIR__ . "/templates/entry.php", $template_vars);
                $page_data->page_state = null;
            }
        }
    }
示例#2
0
 function load($values, $refresh = false)
 {
     assert($this->dir_location || $refresh);
     assert(!$this->loaded);
     $this->title_xml = BoostSiteTools::fragment_to_string($values['title_fragment']);
     $this->purpose_xml = BoostSiteTools::fragment_to_string($values['purpose_fragment']);
     $this->notice_xml = BoostSiteTools::fragment_to_string($values['notice_fragment']);
     $this->notice_url = $values['notice_url'];
     $this->pub_date = $values['pub_date'];
     $this->last_modified = $values['last_modified'];
     $this->download_item = $values['download_item'];
     $this->download_basename = $values['download_basename'];
     $this->documentation = $values['documentation'];
     $this->final_documentation = $values['final_documentation'];
     $this->id = $values['id'];
     if (!$this->id) {
         $this->id = strtolower(preg_replace('@[\\W]@', '_', $this->title_xml));
     }
     if ($this->dir_location) {
         $this->location = $this->dir_location . $this->id . '.html';
         $this->dir_location = null;
         $this->page_state = null;
     }
     $this->release_status = $values['status_item'];
     $this->loaded = true;
     $this->initialise();
     if (empty($this->flags['released']) && $this->documentation) {
         $doc_prefix = rtrim($this->documentation, '/');
         BoostSiteTools::transform_links($values['description_fragment'], function ($x) use($doc_prefix) {
             return preg_match('@^/(?:libs/|doc/html/)@', $x) ? $doc_prefix . $x : $x;
         });
     }
     if ($this->final_documentation) {
         $link_pattern = '@^' . rtrim($this->final_documentation, '/') . '/@';
         $replace = "{$doc_prefix}/";
         BoostSiteTools::transform_links($values['description_fragment'], function ($x) use($link_pattern, $replace) {
             return preg_replace($link_pattern, $replace, $x);
         });
     }
     $this->description_xml = BoostSiteTools::fragment_to_string($values['description_fragment']);
 }