use App\Fluidbook\SearchIndex;
use App\Fluidbook\SEO\Document;
use App\Fluidbook\SEO\Page;
-use App\Http\Controllers\Admin\Operations\FluidbookPublication\Services\SocialImageOperation;
+use App\Fluidbook\SocialImage;
use App\Http\Controllers\Admin\Operations\Tools\Favicon;
use App\Jobs\Base;
use App\Jobs\FluidbookImagesPreprocess;
{
use FluidbookPlayerBranches;
use \Fluidbook\Tools\Compiler\FluidbookCompiler;
- use SocialImageOperation;
use Favicon;
protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', '');
$socialTitle = htmlspecialchars($this->fluidbookSettings->facebook_title ?: $titre, ENT_COMPAT);
$socialDescription = htmlspecialchars($this->fluidbookSettings->facebook_description ?: $this->fluidbookSettings->seoDescription, ENT_COMPAT);
- $socialImage = backpack_url('services/socialimage/' . $this->getFluidbook()->cid);
- $dim = self::getSocialImageSize($this->getFluidbook());
-
- $socialImageWidth = $dim[0];
- $socialImageHeight = $dim[1];
$this->log('Got index vars 2.5');
$titre = $this->fluidbookSettings->title;
-
$description = '<meta name="description" content="' . $this->seo->pages[1]->description . '">';
-
$twittercard = '<meta name="twitter:title" content="' . $socialTitle . '">
<meta name="twitter:description" content="' . $socialDescription . '">
- <meta name="twitter:image" content="' . $socialImage . '">
<meta name="twitter:site" content="@Fluidbook">
<meta name="twitter:card" content="summary_large_image">';
$opengraph = '<meta property="og:title" content="' . $socialTitle . '"/>
- <meta property="og:description" content="' . $socialDescription . '"/>
- <meta property="og:image" content="' . $socialImage . '"/>
+ <meta property="og:description" content="' . $socialDescription . '"/>';
+
+ $dim = SocialImage::getSocialImageSize($this->getFluidbook());
+ if ($dim) {
+ $socialImage = backpack_url('services/socialimage/' . $this->getFluidbook()->cid);
+ $socialImageWidth = $dim[0];
+ $socialImageHeight = $dim[1];
+
+ $opengraph .= ' <meta property="og:image" content="' . $socialImage . '"/>
<meta property="og:image:width" content="' . $socialImageWidth . '"/>
<meta property="og:image:height" content="' . $socialImageHeight . '"/>';
+ $twittercard .= ' <meta name="twitter:image" content="' . $socialImage . '">';
+ }
$this->log('Got index vars 3');
--- /dev/null
+<?php
+
+namespace App\Fluidbook;
+
+use App\Models\FluidbookPublication;
+use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Graphics\Image;
+
+class SocialImage{
+
+ /**
+ * @param $fluidbook FluidbookPublication
+ * @return string
+ */
+ public static function createSocialImage($fluidbook)
+ {
+ $id = $fluidbook->id;
+ $wid = $fluidbook->getAssetDir() . '/';
+
+ if ($fluidbook->facebook_image != '') {
+ $c = $wid . $fluidbook->facebook_image;
+ if (file_exists($c)) {
+ $res = $c;
+ }
+ }
+
+ if (!isset($res)) {
+ $res = self::socialImagePath($id);
+ $limit = max(time() - (3600 * 24 * 30), $fluidbook->updated_at->getTimestamp());
+ $minsize = 20 * 1024;
+
+ if (isset($_GET['force']) || !file_exists($res) || filemtime($res) < $limit || filesize($res) < $minsize) {
+ $lock = self::socialImagePath($id, 'lock');
+ if (!file_exists($lock) || filemtime($lock) < time() - 3600) {
+ touch($lock);
+
+ $force = (file_exists($res) && filemtime($res) < $limit) || isset($_GET['forcecompile']);
+ $url = route('fluidbook_preview_with_time', ['version' => 'online', 'id' => $id, 'hash' => $fluidbook->hash, 'time' => time(), 'nointerface' => 1, 'force' => $force ? '1' : '0', 'puppeteer' => '1']);
+
+ $w = 1200;
+ $h = 628;
+
+ $cl = new CommandLine('node');
+ $cl->setArg(null, resource_path('fluidbookpublication/social_screenshot/social_screenshot.js'));
+ $cl->setArg('width', $w);
+ $cl->setArg('height', $h);
+ $cl->setArg('delay', 10);
+ $cl->setArg('scale', 0.5);
+ $cl->setArg('dest', $res);
+ $cl->setArg('url', '"'.$url.'"');
+ $cl->execute();
+ unlink($lock);
+ }
+ }
+ }
+ return $res;
+ }
+
+ /**
+ * @param $fluidbook
+ * @return array
+ * @throws \Exception
+ */
+ public static function getSocialImageSize($fluidbook)
+ {
+ $socialImage = self::createSocialImage($fluidbook);
+ if(!file_exists($socialImage)){
+ return null;
+ }
+ $sizeFile = self::socialImagePath($fluidbook->id, 'size');
+ if (!file_exists($sizeFile) || filemtime($sizeFile) < filemtime($socialImage)) {
+ $res = Image::getimagesize($socialImage);
+ file_put_contents($sizeFile, json_encode($res));
+ return $res;
+ }
+ return json_decode(file_get_contents($sizeFile), true);
+ }
+
+ public static function socialImagePath($id, $ext = 'jpg')
+ {
+ return Files::mkdir(protected_path('fluidbookpublication/socialimage')) . $id . '.' . $ext;
+ }
+}
namespace App\Http\Controllers\Admin\Operations\FluidbookPublication\Services;
+use App\Fluidbook\SocialImage;
use App\Http\Middleware\CheckIfAdmin;
use App\Models\FluidbookPublication;
use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
-use Cubist\Util\CommandLine;
-use Cubist\Util\Files\Files;
-use Cubist\Util\Graphics\Image;
use Cubist\Util\PHP;
use Illuminate\Support\Facades\Route;
-use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
+
trait SocialImageOperation
{
+
protected function setupSocialimageRoutes($segment, $routeName, $controller)
{
foreach (['services', 's'] as $segment) {
return $this->_socialImage($publication);
}
- public static function socialImagePath($id, $ext = 'jpg')
- {
- return Files::mkdir(protected_path('fluidbookpublication/socialimage')) . $id . '.' . $ext;
- }
-
/**
* @param $fluidbook FluidbookPublication
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|object
{
PHP::neverStop(true);
- $social = self::createSocialImage($fluidbook);
+ $social = SocialImage::createSocialImage($fluidbook);
return XSendFileController::sendfile($social);
}
- /**
- * @param $fluidbook FluidbookPublication
- * @return string
- */
- public static function createSocialImage($fluidbook)
- {
- $id = $fluidbook->id;
- $wid = $fluidbook->getAssetDir() . '/';
-
- if ($fluidbook->facebook_image != '') {
- $c = $wid . $fluidbook->facebook_image;
- if (file_exists($c)) {
- $res = $c;
- }
- }
-
- if (!isset($res)) {
- $res = self::socialImagePath($id);
- $limit = max(time() - (3600 * 24 * 30), $fluidbook->updated_at->getTimestamp());
- $minsize = 20 * 1024;
-
- if (isset($_GET['force']) || !file_exists($res) || filemtime($res) < $limit || filesize($res) < $minsize) {
- $lock = self::socialImagePath($id, 'lock');
- if (!file_exists($lock) || filemtime($lock) < time() - 3600) {
- touch($lock);
-
- $force = (file_exists($res) && filemtime($res) < $limit) || isset($_GET['forcecompile']);
- $url = route('fluidbook_preview_with_time', ['version' => 'online', 'id' => $id, 'hash' => $fluidbook->hash, 'time' => time(), 'nointerface' => 1, 'force' => $force ? '1' : '0', 'puppeteer' => '1']);
-
- $w = 1200;
- $h = 628;
-
- $cl = new CommandLine('node');
- $cl->setArg(null, resource_path('fluidbookpublication/social_screenshot/social_screenshot.js'));
- $cl->setArg('width', $w);
- $cl->setArg('height', $h);
- $cl->setArg('delay', 10);
- $cl->setArg('scale', 0.5);
- $cl->setArg('dest', $res);
- $cl->setArg('url', '"'.$url.'"');
- $cl->execute();
- $cl->debug();
- unlink($lock);
- }
- }
- }
- return $res;
- }
-
- /**
- * @param $fluidbook
- * @return array
- * @throws \Exception
- */
- public static function getSocialImageSize($fluidbook)
- {
- $socialImage = self::createSocialImage($fluidbook);
- $sizeFile = self::socialImagePath($fluidbook->id, 'size');
- if (!file_exists($sizeFile) || filemtime($sizeFile) < filemtime($socialImage)) {
- $res = Image::getimagesize($socialImage);
- file_put_contents($sizeFile, json_encode($res));
- return $res;
- }
- return json_decode(file_get_contents($sizeFile), true);
- }
}