コード例 #1
0
ファイル: GetPreface.php プロジェクト: Nolfneo/docvert
 function process($currentXml)
 {
     $configFilenamesPath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'custom-filenames.php';
     include_once $configFilenamesPath;
     $customFileNames = getCustomFilenames();
     $xslAttributes = array('loopdepth' => $this->loopDepth, 'process' => $this->elementAttributes['process'], 'customFilenameIndex' => $customFileNames[0], 'customFilenameSection' => $customFileNames[1]);
     $currentXml = xsltTransform($currentXml, $this->docvertTransformDirectory . 'each-page.xsl', $xslAttributes);
     return $currentXml;
 }
コード例 #2
0
ファイル: Transform.php プロジェクト: Nolfneo/docvert
 public function process($currentXml)
 {
     if (!array_key_exists('withFile', $this->elementAttributes)) {
         webServiceError('&error-process-transform-lacks-withfile;');
     }
     $xslPath = $this->pipelineDirectory . $this->elementAttributes['withFile'];
     if (!file_exists($xslPath)) {
         webServiceError('&error-process-transform-withfile-missing-file;', 500, array('xslPath' => $xslPath));
     }
     $this->elementAttributes['loopdepth'] = $this->loopDepth;
     return xsltTransform($currentXml, $xslPath, $this->elementAttributes);
 }
コード例 #3
0
 /**
  appends metadata content
 */
 function getMetaData()
 {
     $metaDataPath = $this->contentDirectory . DIRECTORY_SEPARATOR . 'docvert-meta.xml';
     if (!file_exists($metaDataPath)) {
         $this->saveTestResult('Warning: This Word Processing file lacked a meta.xml file. This means that some semantic information is not available. To be fair though, this also may not be a problem.', 'warning');
         return '';
     } else {
         $metaData = file_get_contents($metaDataPath);
         $metaData = xsltTransform($metaData, $this->docvertTransformDirectory . 'opendocument-meta-to-docbook.xsl');
         // '<docvert:external-file xmlns:docvert="urn:holloway.co.nz:names:docvert:2" docvert:name="meta.xml">'
         // $metaData = $metaData;
         // '</docvert:external-file>'
         return $metaData;
     }
 }
コード例 #4
0
 public function process($currentXml)
 {
     if (!file_exists($this->generatePath('docvert--all-docbook.xml'))) {
         $editableDocbook = xsltTransform($currentXml, $this->docvertTransformDirectory . 'docbook-to-docbook-with-placeholders.xsl');
         $this->saveFile('docvert--all-docbook.xml', $editableDocbook);
     }
     $chosenTheme = getGlobalConfigItem('theme');
     if ($chosenTheme == null) {
         $chosenTheme = 'docvert';
     }
     $editorTemplatePath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $chosenTheme . DIRECTORY_SEPARATOR . 'fckeditor-template.html';
     $editorTemplate = file_get_contents($editorTemplatePath);
     $editorTemplate = preg_replace_callback('/\\&(.*?)\\;/s', 'replaceLanguagePlaceholder', $editorTemplate);
     include_once dirname(__FILE__) . '/DocBookToXHTML.php';
     $toHtmlObject = new DocBookToXHTML($this->elementAttributes, $this->pipelineDirectory, $this->contentDirectory, $this->docvertTransformDirectory, $this->loopDepth, $this->depthArray, $this->previewDirectory, $this->pipelineSettings);
     $html = $toHtmlObject->process($currentXml);
     $documentTitlePattern = "/<title[^>]*?>(.*?)<\\/title>/sm";
     preg_match($documentTitlePattern, $html, $matches);
     $documentTitle = trim($matches[1]);
     $documentTitle = preg_replace("/<.*?>/", '', $documentTitle);
     //die($documentTitle.'<hr />'.$html);
     $html = substringAfter($html, '<body');
     $html = substringAfter($html, '>');
     $html = substringBefore($html, '</body');
     $paragraphTitlePattern = "/<p.*?documentTitle[^>]*?>(.*?)<\\/p>/sm";
     $html = preg_replace($paragraphTitlePattern, '', $html);
     $imagePathPrefix = '../../../../writable/' . basename($this->previewDirectory) . '/' . basename($this->contentDirectory) . '/';
     $html = str_replace('src="', 'src="' . $imagePathPrefix, $html);
     //displayXmlString($html);
     $html = str_replace('&', '&amp;', $html);
     $html = str_replace('<', '&lt;', $html);
     $html = str_replace('>', '&gt;', $html);
     $html = str_replace('"', '&quot;', $html);
     $html = trim($html);
     $autoPipeline = $this->pipelineSettings['autopipeline'];
     $autoPipeline = str_replace('.xml', '', $autoPipeline);
     $autoPipeline = str_replace('.default', '', $autoPipeline);
     $editorTemplate = str_replace('{{value}}', $html, $editorTemplate);
     $editorTemplate = str_replace('{{config}}', '', $editorTemplate);
     $editorTemplate = str_replace('{{documentTitle}}', $documentTitle, $editorTemplate);
     $editorTemplate = str_replace('{{documentPath}}', basename($this->previewDirectory) . '/' . basename($this->contentDirectory), $editorTemplate);
     $editorTemplate = str_replace('{{pathToRemove}}', $imagePathPrefix, $editorTemplate);
     $editorTemplate = str_replace('{{pipeline}}', $this->pipelineSettings['pipeline'], $editorTemplate);
     $editorTemplate = str_replace('{{autopipeline}}', $autoPipeline, $editorTemplate);
     $this->saveFile('docvert--all-html.html', $editorTemplate);
     return $currentXml;
 }
コード例 #5
0
ファイル: Test.php プロジェクト: Nolfneo/docvert
 function performTest(&$currentXml)
 {
     if (!array_key_exists('withFile', $this->elementAttributes)) {
         webServiceError('&error-process-test-withfile;');
     }
     $xslPath = null;
     if (stripos($this->elementAttributes['withFile'], 'internal://') !== FALSE) {
         $xslPath = $this->docvertTransformDirectory . str_ireplace('internal://', '', $this->elementAttributes['withFile']);
     } else {
         $xslPath = $this->pipelineDirectory . $this->elementAttributes['withFile'];
     }
     if (!file_exists($xslPath)) {
         webServiceError('&error-process-test-missing-xsl;', 500, array('xslPath' => $xslPath));
     }
     $xslAttributes = array('loopdepth' => $this->loopDepth);
     $testResults = xsltTransform($currentXml, $xslPath, $xslAttributes);
     if (trim($testResults)) {
         $this->logError($testResults, 'raw');
     }
 }
コード例 #6
0
 function process($currentXml)
 {
     return xsltTransform($currentXml, $this->docvertTransformDirectory . 'html-to-opendocument.xsl');
 }
コード例 #7
0
ファイル: save-changes.php プロジェクト: Nolfneo/docvert
}
$autopipeline = $unescapedPosts["autopipeline"];
if (!preg_match($badCharactersPattern, $autopipeline)) {
    webServiceError('autopipeline contains bad characters. Was "' . revealXml($autopipeline) . '"');
}
$allhtml = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><body>' . $allhtml . '</body></html>';
$transformDirectory = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'transform' . DIRECTORY_SEPARATOR;
$htmlPagesXsltPath = $transformDirectory . 'htmlpages-to-html.xsl';
$allhtml = characterEntityToNCR($allhtml);
$html = xsltTransform($allhtml, $htmlPagesXsltPath);
if (!$html) {
    webServiceError("Unable to rebuild document, either because I was given invalid XML or there was a programming error.<hr />Document was:<blockquote>" . str_replace("\n", "<br />", str_replace(" ", '&nbsp;', revealXml($allhtml))) . "</blockquote>");
}
//displayXmlString($html);
$docbookBodyXsltPath = $transformDirectory . 'html-to-docbook-body.xsl';
$docbookBody = xsltTransform($html, $docbookBodyXsltPath);
$docbookBody = removeXmlDeclaration($docbookBody);
$docbookBody = preg_replace("/<docvert-remove-me[^>]*?>/", '', $docbookBody);
$docbookBody = preg_replace("/<\\/docvert-remove-me[^>]*?>/", '', $docbookBody);
//displayXmlString($docbookBody);
//displayXmlString(file_get_contents($docbookBodyXsltPath));
$allDocumentsPreviewDirectory = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'writable' . DIRECTORY_SEPARATOR . $documentPathParts[0] . DIRECTORY_SEPARATOR;
$previewDirectory = $allDocumentsPreviewDirectory . $documentPathParts[1] . DIRECTORY_SEPARATOR;
$unitTestResults = $previewDirectory . 'test.html';
if (file_exists($unitTestResults)) {
    silentlyUnlink($unitTestResults);
}
$zipsInPreviewDirectory = glob($allDocumentsPreviewDirectory . '*.zip');
if (count($zipsInPreviewDirectory)) {
    foreach ($zipsInPreviewDirectory as $zipInPreviewDirectory) {
        silentlyUnlink($zipInPreviewDirectory);
コード例 #8
0
 function process($currentXml)
 {
     $extractImagesPath = $this->docvertTransformDirectory . 'extract-pages-html-images-and-links.xsl';
     $htmlUrls = trim(xsltTransform($currentXml, $extractImagesPath));
     $htmlUrlLines = explode("\n", $htmlUrls);
     $imageUrls = array();
     foreach ($htmlUrlLines as $htmlUrlLine) {
         if (trim($htmlUrlLine) == '') {
             continue;
         }
         $urlLineParts = explode("\t", $htmlUrlLine);
         $urlType = $urlLineParts[0];
         $baseUrl = $urlLineParts[1];
         $possiblyRelativeUrl = $urlLineParts[2];
         $fullUrl = '';
         if (stringStartsWith($possiblyRelativeUrl, "http://") || stringStartsWith($possiblyRelativeUrl, "https://") || stringStartsWith($possiblyRelativeUrl, "mailto:")) {
             $fullUrl = $possiblyRelativeUrl;
         } else {
             $connectionPart = getUrlConnectionPart($baseUrl);
             $getUrlLocalPart = getUrlLocalPart($baseUrl);
             $localPartDirectory = getUrlLocalPartDirectory($baseUrl);
             if (stringStartsWith($possiblyRelativeUrl, '/')) {
                 $fullUrl = $connectionPart . $possiblyRelativeUrl;
             } else {
                 $relativePath = resolveRelativeUrl($localPartDirectory . $possiblyRelativeUrl);
                 if (!stringStartsWith($relativePath, '/')) {
                     $relativePath = '/' . $relativePath;
                 }
                 $fullUrl = $connectionPart . $relativePath;
             }
         }
         $missingImagePlaceholderImagePath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . '404image.gif';
         if (!file_exists($missingImagePlaceholderImagePath)) {
             webServiceError('&dynamic-error-process-downloadimagesandsetlinks-missing-placeholder;', 500, array('fourOhFourImagePath' => $fourOhFourImagePath));
         }
         $fullUrl = html_entity_decode($fullUrl);
         switch ($urlType) {
             case 'image':
                 $imageData = file_get_contents($fullUrl);
                 if ($imageData == null) {
                     $imageData = file_get_contents($missingImagePlaceholderImagePath);
                 }
                 $picturesDirectory = $this->contentDirectory . DIRECTORY_SEPARATOR . 'Pictures';
                 if (!file_exists($picturesDirectory)) {
                     mkdir($picturesDirectory);
                 }
                 if (!function_exists('imagecreatefromstring')) {
                     webServiceError('&error-process-downloadimagesandsetlinks-missing-gd;');
                 }
                 $imageResource = imagecreatefromstring($imageData);
                 if (!$imageResource) {
                     $imageResource = imagecreatefromstring(file_get_contents($missingImagePlaceholderImagePath));
                 }
                 $imageWidth = imagesx($imageResource);
                 $imageHeight = imagesy($imageResource);
                 $fileExtension = substr($fullUrl, strrpos($fullUrl, '.') + 1);
                 switch ($fileExtension) {
                     case 'jpg':
                     case 'jpeg':
                     case 'gif':
                     case 'png':
                         break;
                     default:
                         $fileExtension = 'jpg';
                 }
                 $openDocumentPath = 'Pictures/' . md5($fullUrl) . '.' . $fileExtension;
                 file_put_contents($this->contentDirectory . DIRECTORY_SEPARATOR . $openDocumentPath, $imageData);
                 $imageUrlReplacement = $openDocumentPath . '" c:width="' . $imageWidth . '" c:height="' . $imageHeight;
                 //FIXME: assumes image @src has double-quote and not single
                 $currentXml = str_replace('"' . $possiblyRelativeUrl . '"', '"' . $imageUrlReplacement . '"', $currentXml);
                 break;
             case 'link':
                 $linkUrl = $urlLineParts[2];
                 //print '"'.$possiblyRelativeUrl.'  vs  '.$fullUrl.'<hr />';
                 $currentXml = str_replace('"' . $possiblyRelativeUrl . '"', '"' . htmlentities($fullUrl) . '"', $currentXml);
                 break;
         }
     }
     return $currentXml;
 }
コード例 #9
0
ファイル: DocBookToXHTML.php プロジェクト: Nolfneo/docvert
 function process($currentXml)
 {
     $currentXml = xsltTransform($currentXml, $this->docvertTransformDirectory . 'docbook-to-html.xsl', $this->elementAttributes);
     return $currentXml;
 }