} if (is_file($autoload = __DIR__ . '/../vendor/autoload.php')) { require $autoload; } elseif (is_file($autoload = __DIR__ . '/../../../autoload.php')) { require $autoload; } else { fwrite(STDERR, 'You must set up the project dependencies, run the following commands:' . PHP_EOL . 'curl -s http://getcomposer.org/installer | php' . PHP_EOL . 'php composer.phar install' . PHP_EOL); exit(1); } $xml = ''; while (($buffer = fgets(STDIN)) !== FALSE) { $xml .= $buffer; } if (!empty($xml)) { $xmlstring = \eLifeIngestXsl\ConvertXML\XMLString::fromString($xml); $convertxml = new \eLifeIngestXsl\ConvertXMLToHtml($xmlstring); $sections = ['//h1[contains(concat(" ", normalize-space(@class), " "), " page-title ")]' => $convertxml->getTitle(), '//*[@id="abstract"]/div' => $convertxml->getAbstract(), '//*[@id="digest"]/div' => $convertxml->getDigest(), '//*[@id="main-text"]/div' => $convertxml->getMainText(), '//*[@id="references"]/div' => $convertxml->getReferences(), '//*[@id="acknowledgements"]/div' => $convertxml->getAcknowledgements(), '//*[@id="decision-letter"]/div' => $convertxml->getDecisionLetter(), '//*[@id="author-response"]/div' => $convertxml->getAuthorResponse()]; $excludes = ['//*[contains(concat(" ", normalize-space(@class), " "), " author-list-full ")]', '//*[contains(concat(" ", normalize-space(@class), " "), " elife-article-indicators ")]', '//*[contains(concat(" ", normalize-space(@class), " "), " panel-region-content-top ")]', '//*[contains(concat(" ", normalize-space(@class), " "), " pane-panels-ajax-tab-tabs ")]', '//*[contains(concat(" ", normalize-space(@class), " "), " author-list ")]', '//*[contains(concat(" ", normalize-space(@class), " "), " elife-institutions-list ")]', '//*[contains(concat(" ", normalize-space(@class), " "), " pane-elife-article-doi ")]', '//*[contains(concat(" ", normalize-space(@class), " "), " pane-elife-article-toolbox ")]', '//*[contains(concat(" ", normalize-space(@class), " "), " pane-elife-article-jumpto ")]', '//*[contains(concat(" ", normalize-space(@class), " "), " pane-elife-article-categories ")]']; $dom_template = new DOMDocument(); $dom_template->loadHTMLFile(__DIR__ . '/elife-research-article.tpl.html'); $html_prefix = '<meta http-equiv="content-type" content="text/html; charset=utf-8">'; $wrapper = 'wrapper'; foreach ($sections as $xpath_query => $html) { if (!empty($html)) { $xpath = new DOMXpath($dom_template); $elements = $xpath->query($xpath_query); if ($elements->length) { $replace_node = $elements->item(0); $replace_dom = new DOMDocument(); $replace_dom->loadHTML($html_prefix . '<' . $wrapper . '>' . $html . '</' . $wrapper . '>'); $children = $replace_node->childNodes;
if (!empty($xml)) { $params = []; $types = ['bib', 'ris', 'html']; while ($param = array_shift($_SERVER['argv'])) { switch ($param) { case '--type': case '-t': $type = array_shift($_SERVER['argv']); if (empty($type) || !in_array($type, $types)) { fwrite(STDERR, 'Please declare a supported conversion type:' . PHP_EOL . '* ' . implode(PHP_EOL . '* ', $types) . PHP_EOL); exit(1); } $params['type'] = $type; break; } } $params += ['type' => 'html']; $convertxml = ''; $xmlstring = \eLifeIngestXsl\ConvertXML\XMLString::fromString($xml); switch ($params['type']) { case 'bib': $convertxml = new \eLifeIngestXsl\ConvertXMLToBibtex($xmlstring); break; case 'ris': $convertxml = new \eLifeIngestXsl\ConvertXMLToRis($xmlstring); break; default: $convertxml = new \eLifeIngestXsl\ConvertXMLToHtml($xmlstring); } echo $convertxml->getOutput(); }