-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bcd967
commit ea2e16c
Showing
12 changed files
with
263 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php namespace BookStack\Services; | ||
|
||
|
||
use BookStack\Page; | ||
|
||
class ExportService | ||
{ | ||
|
||
|
||
/** | ||
* Convert a page to a self-contained HTML file. | ||
* Includes required CSS & image content. Images are base64 encoded into the HTML. | ||
* @param Page $page | ||
* @return mixed|string | ||
*/ | ||
public function pageToContainedHtml(Page $page) | ||
{ | ||
$cssContent = file_get_contents(public_path('/css/export-styles.css')); | ||
$pageHtml = view('pages/pdf', ['page' => $page, 'css' => $cssContent])->render(); | ||
|
||
$imageTagsOutput = []; | ||
preg_match_all("/\<img.*src\=(\'|\")(.*?)(\'|\").*?\>/i", $pageHtml, $imageTagsOutput); | ||
|
||
// Replace image src with base64 encoded image strings | ||
if (isset($imageTagsOutput[0]) && count($imageTagsOutput[0]) > 0) { | ||
foreach ($imageTagsOutput[0] as $index => $imgMatch) { | ||
$oldImgString = $imgMatch; | ||
$srcString = $imageTagsOutput[2][$index]; | ||
if (strpos(trim($srcString), 'http') !== 0) { | ||
$pathString = public_path($srcString); | ||
} else { | ||
$pathString = $srcString; | ||
} | ||
$imageContent = file_get_contents($pathString); | ||
$imageEncoded = 'data:image/' . pathinfo($pathString, PATHINFO_EXTENSION) . ';base64,' . base64_encode($imageContent); | ||
$newImageString = str_replace($srcString, $imageEncoded, $oldImgString); | ||
$pageHtml = str_replace($oldImgString, $newImageString, $pageHtml); | ||
} | ||
} | ||
|
||
$linksOutput = []; | ||
preg_match_all("/\<a.*href\=(\'|\")(.*?)(\'|\").*?\>/i", $pageHtml, $linksOutput); | ||
|
||
// Replace image src with base64 encoded image strings | ||
if (isset($linksOutput[0]) && count($linksOutput[0]) > 0) { | ||
foreach ($linksOutput[0] as $index => $linkMatch) { | ||
$oldLinkString = $linkMatch; | ||
$srcString = $linksOutput[2][$index]; | ||
if (strpos(trim($srcString), 'http') !== 0) { | ||
$newSrcString = url($srcString); | ||
$newLinkString = str_replace($srcString, $newSrcString, $oldLinkString); | ||
$pageHtml = str_replace($oldLinkString, $newLinkString, $pageHtml); | ||
} | ||
} | ||
} | ||
|
||
// Replace any relative links with system domain | ||
return $pageHtml; | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* Generated by Font Squirrel (http://www.fontsquirrel.com) on December 30, 2015 */ | ||
@font-face { | ||
font-family: 'Roboto'; | ||
src: url('/fonts/roboto-bold-webfont.eot'); | ||
src: url('/fonts/roboto-bold-webfont.eot?#iefix') format('embedded-opentype'), | ||
url('/fonts/roboto-bold-webfont.woff2') format('woff2'), | ||
url('/fonts/roboto-bold-webfont.woff') format('woff'), | ||
url('/fonts/roboto-bold-webfont.ttf') format('truetype'), | ||
url('/fonts/roboto-bold-webfont.svg#robotobold') format('svg'); | ||
font-weight: bold; | ||
font-style: normal; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Roboto'; | ||
src: url('/fonts/roboto-bolditalic-webfont.eot'); | ||
src: url('/fonts/roboto-bolditalic-webfont.eot?#iefix') format('embedded-opentype'), | ||
url('/fonts/roboto-bolditalic-webfont.woff2') format('woff2'), | ||
url('/fonts/roboto-bolditalic-webfont.woff') format('woff'), | ||
url('/fonts/roboto-bolditalic-webfont.ttf') format('truetype'), | ||
url('/fonts/roboto-bolditalic-webfont.svg#robotobold_italic') format('svg'); | ||
font-weight: bold; | ||
font-style: italic; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Roboto'; | ||
src: url('/fonts/roboto-italic-webfont.eot'); | ||
src: url('/fonts/roboto-italic-webfont.eot?#iefix') format('embedded-opentype'), | ||
url('/fonts/roboto-italic-webfont.woff2') format('woff2'), | ||
url('/fonts/roboto-italic-webfont.woff') format('woff'), | ||
url('/fonts/roboto-italic-webfont.ttf') format('truetype'), | ||
url('/fonts/roboto-italic-webfont.svg#robotoitalic') format('svg'); | ||
font-weight: normal; | ||
font-style: italic; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Roboto'; | ||
src: url('/fonts/roboto-light-webfont.eot'); | ||
src: url('/fonts/roboto-light-webfont.eot?#iefix') format('embedded-opentype'), | ||
url('/fonts/roboto-light-webfont.woff2') format('woff2'), | ||
url('/fonts/roboto-light-webfont.woff') format('woff'), | ||
url('/fonts/roboto-light-webfont.ttf') format('truetype'), | ||
url('/fonts/roboto-light-webfont.svg#robotolight') format('svg'); | ||
font-weight: 300; | ||
font-style: normal; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Roboto'; | ||
src: url('/fonts/roboto-lightitalic-webfont.eot'); | ||
src: url('/fonts/roboto-lightitalic-webfont.eot?#iefix') format('embedded-opentype'), | ||
url('/fonts/roboto-lightitalic-webfont.woff2') format('woff2'), | ||
url('/fonts/roboto-lightitalic-webfont.woff') format('woff'), | ||
url('/fonts/roboto-lightitalic-webfont.ttf') format('truetype'), | ||
url('/fonts/roboto-lightitalic-webfont.svg#robotolight_italic') format('svg'); | ||
font-weight: 300; | ||
font-style: italic; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Roboto'; | ||
src: url('/fonts/roboto-medium-webfont.eot'); | ||
src: url('/fonts/roboto-medium-webfont.eot?#iefix') format('embedded-opentype'), | ||
url('/fonts/roboto-medium-webfont.woff2') format('woff2'), | ||
url('/fonts/roboto-medium-webfont.woff') format('woff'), | ||
url('/fonts/roboto-medium-webfont.ttf') format('truetype'), | ||
url('/fonts/roboto-medium-webfont.svg#robotomedium') format('svg'); | ||
font-weight: 500; | ||
font-style: normal; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Roboto'; | ||
src: url('/fonts/roboto-mediumitalic-webfont.eot'); | ||
src: url('/fonts/roboto-mediumitalic-webfont.eot?#iefix') format('embedded-opentype'), | ||
url('/fonts/roboto-mediumitalic-webfont.woff2') format('woff2'), | ||
url('/fonts/roboto-mediumitalic-webfont.woff') format('woff'), | ||
url('/fonts/roboto-mediumitalic-webfont.ttf') format('truetype'), | ||
url('/fonts/roboto-mediumitalic-webfont.svg#robotomedium_italic') format('svg'); | ||
font-weight: 500; | ||
font-style: italic; | ||
} | ||
|
||
@font-face { | ||
font-family: 'Roboto'; | ||
src: url('/fonts/roboto-regular-webfont.eot'); | ||
src: url('/fonts/roboto-regular-webfont.eot?#iefix') format('embedded-opentype'), | ||
url('/fonts/roboto-regular-webfont.woff2') format('woff2'), | ||
url('/fonts/roboto-regular-webfont.woff') format('woff'), | ||
url('/fonts/roboto-regular-webfont.ttf') format('truetype'), | ||
url('/fonts/roboto-regular-webfont.svg#robotoregular') format('svg'); | ||
font-weight: normal; | ||
font-style: normal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.