-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#92 - Convert pptx to a Carousel-based HTML slideshow
- Loading branch information
Showing
10 changed files
with
325 additions
and
16 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
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,148 @@ | ||
<?php | ||
/* | ||
* This file is part of the FileConverter package. | ||
* | ||
* (c) Greg Payne | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FileConverter\Engine\Convert; | ||
use FileConverter\Engine\EngineBase; | ||
use FileConverter\Engine\Helper\Archive; | ||
use GuzzleHttp\json_decode; | ||
|
||
class NativeSlideshow extends EngineBase { | ||
/** | ||
* @todo use Message::fromString($raw) to convert from eml to other formats | ||
*/ | ||
public function convertFile($source, $destination) { | ||
// Add default configurations | ||
$this->configuration = array_replace(array( | ||
'mode' => 'default', | ||
), (array) $this->configuration); | ||
|
||
// Create a folder containing all of the images | ||
$imageArchive = new Archive($this); | ||
$imagePath = $imageArchive->getTempDirectory(); | ||
$this->converter->convertFile($source, $imagePath, $this->conversion[0] | ||
. '->directory/jpg'); | ||
|
||
// Build the slideshow configuration | ||
$slideshow = array( | ||
'title' => 'Slideshow', | ||
'items' => array(), | ||
); | ||
foreach ($this->configuration as $k => $v) { | ||
if ($k{0} !== '#') { | ||
$slideshow[$k] = $v; | ||
} | ||
} | ||
try { | ||
// Get the configuration for the slides. | ||
$tmpJson = $this->getTempFile('.json'); | ||
$this->converter->convertFile($source, $tmpJson, $this->conversion[0] | ||
. '->json'); | ||
$slideshow = array_replace($slideshow, (array) json_decode(file_get_contents($tmpJson), TRUE)); | ||
|
||
// Apply the slideshow mode. | ||
foreach ($slideshow['items'] as $i => &$slide) { | ||
if (!isset($slide['notes'])) { | ||
if ($slideshow['mode'] === 'schedule') { | ||
unset($slideshow['items'][$i]); | ||
} | ||
} | ||
else { | ||
// Extract settings from the slide notes. | ||
$keys = array( | ||
'@(?<k>SLIDESHOW\.[^:]+):(?<v>[^\n]+)(?:\n|$)@s', | ||
'@(?<k>BEGIN):(?<v>[^\n]+)(?:\n|$)@s', | ||
'@(?<k>TITLE):(?<v>[^\n]+)(?:\n|$)@s', | ||
'@(?<k>DESCRIPTION):(?<v>[^\n]+)(?:\n|$)@s', | ||
); | ||
foreach ($keys as $match) { | ||
if (preg_match($match, $slide['notes'], $arr)) { | ||
if (strpos($arr['k'], 'SLIDESHOW.') === 0) { | ||
$slideshow[strtolower(substr($arr['k'], 10))] = $arr['v']; | ||
} | ||
else { | ||
$slide[strtolower($arr['k'])] = $arr['v']; | ||
} | ||
} | ||
} | ||
unset($slide['notes']); | ||
} | ||
} | ||
unset($slide); | ||
$slideshow['items'] = array_values($slideshow['items']); | ||
} catch (\Exception $e) { | ||
// Build the default meta data based on the images. | ||
$slideshow['mode'] = 'default'; | ||
$i = 1; | ||
while (is_file("$imagePath/page$i.jpg")) { | ||
$slideshow['items'][] = array( | ||
'number' => $i, | ||
'title' => "Slide $i", | ||
); | ||
++$i; | ||
} | ||
} | ||
|
||
// Build the actual slideshow archive. | ||
$archive = new Archive($this); | ||
$tmp = $archive->getTempDirectory(); | ||
file_put_contents("$tmp/meta.json", json_encode($slideshow)); | ||
|
||
// Copy the images as appropriate. | ||
foreach ($slideshow['items'] as $slide) { | ||
$from = "$imagePath/page$slide[number].jpg"; | ||
$to = "$tmp/img/slide$slide[number].jpg"; | ||
$this->isTempWritable($to); | ||
copy($from, $to); | ||
} | ||
|
||
// Copy the slideshow resources. | ||
$to = "$tmp/js/slideshow.js"; | ||
$this->isTempWritable($to); | ||
copy(__DIR__ . '/Resources/Slideshow/slideshow.js', $to); | ||
$to = "$tmp/css/slideshow.css"; | ||
$this->isTempWritable($to); | ||
copy(__DIR__ . '/Resources/Slideshow/slideshow.css', $to); | ||
|
||
// The index file involves template variables. | ||
// Provide a raw | ||
$to = "$tmp/index.htm"; | ||
$this->isTempWritable($to); | ||
$content = file_get_contents(__DIR__ . '/Resources/Slideshow/index.htm'); | ||
$content = strtr($content, array( | ||
'{{ slideshow.title|escape }}' => htmlspecialchars($slideshow['title']), | ||
'{{ slideshow|json_encode() }}' => json_encode($slideshow), | ||
)); | ||
file_put_contents($to, $content); | ||
|
||
// Save the slideshow. | ||
$archive->save($destination); | ||
} | ||
|
||
protected function getHelpInstallation($os, $os_version) { | ||
$help = array( | ||
'title' => 'Native Slideshow Extractor', | ||
); | ||
switch ($os) { | ||
case 'Ubuntu': | ||
$help['os'] = 'confirmed on Ubuntu 16.04'; | ||
$help['notes'] = array( | ||
'composer update', | ||
); | ||
return $help; | ||
} | ||
|
||
return parent::getHelpInstallation($os, $os_version); | ||
} | ||
|
||
public function isAvailable() { | ||
return TRUE; | ||
} | ||
|
||
} |
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,35 @@ | ||
|
||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> | ||
<title>{{ slideshow.title|escape }}</title> | ||
|
||
<!-- Bootstrap CDN: http://getbootstrap.com/getting-started/ --> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> | ||
|
||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> | ||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | ||
<!--[if lt IE 9]> | ||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> | ||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | ||
<![endif]--> | ||
</head> | ||
<body> | ||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | ||
<!-- Include all compiled plugins (below), or include individual files as needed --> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> | ||
|
||
<!-- Embed the slideshow js --> | ||
<script src="js/slideshow.js"></script> | ||
<script type="text/javascript"> | ||
slideshow({{ slideshow|json_encode() }}); | ||
</script> | ||
</body> | ||
</html> |
Empty file.
Oops, something went wrong.