From 7659e02a89c3305a176123047f1e1393a7a3e158 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 4 Oct 2023 11:43:29 +0200 Subject: [PATCH] wip #6278 @0.5 --- app/Fluidbook/Compiler/Compiler.php | 87 ++++++++++--------- resources/tools/dockerwebcontainer/base | 3 - .../tools/dockerwebcontainer/elasticsearch | 5 +- resources/tools/dockerwebcontainer/matomo | 1 + resources/tools/dockerwebcontainer/mysql | 3 +- resources/tools/dockerwebcontainer/php | 1 + resources/tools/dockerwebcontainer/redis | 1 + .../template/config/cron/crontab | 3 +- .../template/images/elasticsearch/Dockerfile | 2 + .../template/images/php-fpm/Dockerfile | 2 +- 10 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 resources/tools/dockerwebcontainer/template/images/elasticsearch/Dockerfile diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index 5922d57ac..6dfc6d039 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -170,7 +170,7 @@ class Compiler extends Base implements CompilerInterface ], ]; - protected $specialJsFiles = array(); + protected $specialJsFiles = []; public $jsFiles = []; @@ -179,21 +179,21 @@ class Compiler extends Base implements CompilerInterface // Filename with no extension, relative to the /style directory in the player build folder public $lessFiles = ['fluidbook']; - public $specialCSS = array(); + public $specialCSS = []; public $phonegapStandardPlugins = array('ios' => array('ExternalFileUtil'), 'android' => array('webintent')); - public $pluginCSS = array(); - public $pluginJs = array(); - public $htmlmultimedia = array(); - public $cssX = array(); - public $cssY = array(); - public $cssWidths = array(); + public $pluginCSS = []; + public $pluginJs = []; + public $htmlmultimedia = []; + public $cssX = []; + public $cssY = []; + public $cssWidths = []; public $pdf2htmlRatio; public $scale; public $multiply; - public $div = array(); + public $div = []; public $numerotation; - public $fontDocs = array(); + public $fontDocs = []; public $dir; public $z = 3; protected $_lottieIDByHash = []; @@ -215,25 +215,25 @@ class Compiler extends Base implements CompilerInterface public $linkScale; public $optimalWidth = 567; public $optimalHeight = 709; - public $additionalConfig = array(); + public $additionalConfig = []; public $fontScale = 1; - public $cache = array(); - public $backgroundsPrefix = array(); + public $cache = []; + public $backgroundsPrefix = []; public $svg = true; public $assets = ''; public $phonegap = false; public $phonegapVersion; public $standalone = false; - public $hiddenContents = array(); + public $hiddenContents = []; public $appcache; public $home; public $widget = true; public $multiApp = false; - public $pageLabels = array(); - public $stylesheets = array(); + public $pageLabels = []; + public $stylesheets = []; public $logfp = null; public $logtime = null; - public $beginBody = array(); + public $beginBody = []; public $securityPolicyWhitelist = ['*.google-analytics.com', '*.youtube.com', '*.ytimg.com', '*.googletagmanager.com']; public $writeLinksData = false; @@ -793,7 +793,7 @@ class Compiler extends Base implements CompilerInterface $e = explode("\n", $this->fluidbookSettings->mobilePlugins); $main = array_pop($this->jsFiles); - $plugins = array(); + $plugins = []; foreach ($e as $plugin) { $plugin = trim($plugin); @@ -897,6 +897,12 @@ class Compiler extends Base implements CompilerInterface public function getIndexVars() { if (null === $this->_indexVars) { + $assetsPrefix = ''; + if ($this->fluidbookSettings->hosting_loadbalancer) { + $assetsPrefix = 'https://s1.lb.fluidbook.com/' . $this->book_id . '_' . $this->_fluidbook->hash . '/'; + } + + $titre = $this->fluidbookSettings->title; if (null === $this->_signature) { @@ -905,15 +911,14 @@ class Compiler extends Base implements CompilerInterface } else { $credits = ''; } - $hiddenContents = implode("\n", $this->hiddenContents); $bgcolor = $this->themeSettings->loadingBackColor; // Feuilles de style $sheets = array_merge($this->stylesheets, $this->specialCSS); - $style = array(); + $style = []; foreach ($sheets as $sheet) { - $style[] = ''; + $style[] = ''; } $style = implode("\n\t\t", $style); @@ -927,6 +932,7 @@ class Compiler extends Base implements CompilerInterface $jstime = "?j=" . time(); + $iscript = ''; if (count($this->htmlmultimedia)) { $iscript .= '' . "\n"; } - $script = '' . "\n"; + $script = '' . "\n"; foreach ($this->jsLibs as $jsLib => $files) { - $script .= "\t" . '' . "\n"; + $script .= "\t" . '' . "\n"; } if ($this->fluidbookSettings->scorm_enable) { - $script .= "\t" . '' . "\n"; + $script .= "\t" . '' . "\n"; } if (count($this->specialJsFiles)) { - $script .= "\t" . '' . "\n"; + $script .= "\t" . '' . "\n"; } foreach ($this->pluginJs as $p) { - $script .= "\t" . '' . "\n"; + $script .= "\t" . '' . "\n"; } $script .= $iscript; @@ -991,7 +997,7 @@ class Compiler extends Base implements CompilerInterface $datapng = 'data:image/png;base64,' . base64_encode(file_get_contents($pngFile)); $favicon .= '' . "\n\t"; - $favicon .= ''; + $favicon .= ''; } $print = $this->writePDF(); @@ -1082,7 +1088,7 @@ class Compiler extends Base implements CompilerInterface } $this->log('Got index vars 5'); - $vars = array('lang', 'titre', 'credits', 'style', 'script', 'pagesContents', 'print', 'hiddenContents', 'splash', 'splashstyles', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard', 'description', 'console'); + $vars = array('lang', 'titre', 'credits', 'style', 'script', 'pagesContents', 'print', 'splash', 'splashstyles', 'cache', 'bgcolor', 'message', 'favicon', 'svg', 'beginbody', 'csp', 'opengraph', 'twittercard', 'description', 'console'); $res = []; foreach ($vars as $v) { @@ -1236,7 +1242,7 @@ class Compiler extends Base implements CompilerInterface return; } if (!isset($this->config->filesInfos)) { - $this->config->filesInfos = array(); + $this->config->filesInfos = []; } $infos = array('filesize' => filesize($file)); $dim = Image::getimagesize($file); @@ -1262,7 +1268,7 @@ class Compiler extends Base implements CompilerInterface $multilang = Text::explodeNewLines($this->config->get('multilang', '')); if (count($multilang)) { - $m = array(); + $m = []; foreach ($multilang as $line) { $line = trim($line); if ($line == '') { @@ -1492,7 +1498,7 @@ class Compiler extends Base implements CompilerInterface $this->addPDFJS(); if ($this->fluidbookSettings->scorm_enable) { - $finals['scorm'] = array(); + $finals['scorm'] = []; $finals['scorm'][] = 'js/libs/scorm/apiwrapper.js'; $finals['scorm'][] = 'js/libs/scorm/scorm.js'; } @@ -1630,6 +1636,7 @@ class Compiler extends Base implements CompilerInterface $v = $data[$k] = !!$v; } } + $data['hiddenContents'] = implode('', $this->hiddenContents); $data['id'] = $this->book_id; $data['compiler'] = 3; return 'var SETTINGS=' . json_encode($data) . ';' . "\n"; @@ -1644,7 +1651,7 @@ class Compiler extends Base implements CompilerInterface protected function writeManifest() { - $res = array(); + $res = []; // TODO: Why was this function missing a return statement? It's called from populateConfig() is expected to return a value. return $res; } @@ -1701,7 +1708,7 @@ class Compiler extends Base implements CompilerInterface protected function writeCSS($links) { - $res = array(); + $res = []; $this->addFontKit('OpenSans'); @@ -1943,7 +1950,7 @@ class Compiler extends Base implements CompilerInterface $from = $this->assets . '/style/*'; `cp -r $from $tmp`; - $bookVariables = array(); + $bookVariables = []; foreach ($variables as $k => $v) { $bookVariables[] = '@' . trim($k) . ':' . $v . ';'; } @@ -2072,7 +2079,7 @@ class Compiler extends Base implements CompilerInterface public static function writeCSSUA($property, $value) { - $res = array(); + $res = []; foreach (self::$uaPrefixes as $prefix) { $res[] = $prefix . $property . ':' . $value; } @@ -2235,7 +2242,7 @@ class Compiler extends Base implements CompilerInterface if (is_string($format)) { if ($format == 'none') { - $format = array(); + $format = []; } elseif ($format == 'all') { $format = $videos; } else { @@ -2244,7 +2251,7 @@ class Compiler extends Base implements CompilerInterface } if (!$force) { - $format = array(); + $format = []; } @@ -2284,7 +2291,7 @@ class Compiler extends Base implements CompilerInterface $e = explode('.', $source); array_pop($e); $base = implode('.', $e); - $source = array(); + $source = []; foreach ($types as $type) { $source[] = $base . '.' . $type; } @@ -2351,7 +2358,7 @@ class Compiler extends Base implements CompilerInterface $res['height'] = intval((string)$meta->getAttribute('content')); } - $r = array('html' => 'index.html', 'inject' => array(), 'injectcss' => array(), 'injectjs' => array()); + $r = array('html' => 'index.html', 'inject' => [], 'injectcss' => [], 'injectjs' => []); } else { $r = array('html' => false, 'inject' => array(file_get_contents($d . '/init.js')), 'injectcss' => array('multimedia.css'), 'injectjs' => array('multimedia.js')); } @@ -2386,7 +2393,7 @@ class Compiler extends Base implements CompilerInterface public static function getPhonegapVersions() { - $versions = array(); + $versions = []; $phonegap_dir = resource_path('fluidbookpublication/phonegap'); if (is_dir($phonegap_dir)) { diff --git a/resources/tools/dockerwebcontainer/base b/resources/tools/dockerwebcontainer/base index 93716760f..d6a541f54 100644 --- a/resources/tools/dockerwebcontainer/base +++ b/resources/tools/dockerwebcontainer/base @@ -8,12 +8,9 @@ services: - './www/public/:/usr/local/apache2/htdocs/' - './www/:/application/' - './config/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf' - ports: - - '$port:80' environment: VIRTUAL_HOST: $domain LETSENCRYPT_HOST: $domain networks: - $name restart: unless-stopped - diff --git a/resources/tools/dockerwebcontainer/elasticsearch b/resources/tools/dockerwebcontainer/elasticsearch index e5d76ceff..2035df754 100644 --- a/resources/tools/dockerwebcontainer/elasticsearch +++ b/resources/tools/dockerwebcontainer/elasticsearch @@ -1,12 +1,13 @@ elasticsearch: container_name: $name-elasticsearch - image: docker.elastic.co/elasticsearch/elasticsearch:8.10.2 + build: './images/elasticsearch' volumes: - ./esdata:/usr/share/elasticsearch/data environment: - - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - discovery.type=single-node + - xpack.security.enabled=false networks: - $name restart: unless-stopped + diff --git a/resources/tools/dockerwebcontainer/matomo b/resources/tools/dockerwebcontainer/matomo index a86901d29..d70067557 100644 --- a/resources/tools/dockerwebcontainer/matomo +++ b/resources/tools/dockerwebcontainer/matomo @@ -56,3 +56,4 @@ - ./matomo/redis:/data networks: - $name + diff --git a/resources/tools/dockerwebcontainer/mysql b/resources/tools/dockerwebcontainer/mysql index 7d1003eca..666d2159a 100644 --- a/resources/tools/dockerwebcontainer/mysql +++ b/resources/tools/dockerwebcontainer/mysql @@ -2,14 +2,13 @@ image: 'adminer:latest' container_name: $name-adminer restart: unless-stopped - ports: - - $portadminer:8080 environment: ADMINER_DEFAULT_SERVER: $name-mariadb VIRTUAL_HOST: adminer.$domain LETSENCRYPT_HOST: adminer.$domain networks: - $name + mariadb: container_name: $name-mariadb image: 'mariadb:latest' diff --git a/resources/tools/dockerwebcontainer/php b/resources/tools/dockerwebcontainer/php index d72b0ec0f..40a6810eb 100644 --- a/resources/tools/dockerwebcontainer/php +++ b/resources/tools/dockerwebcontainer/php @@ -29,3 +29,4 @@ networks: - $name restart: unless-stopped + diff --git a/resources/tools/dockerwebcontainer/redis b/resources/tools/dockerwebcontainer/redis index cc1313cb8..299a41617 100644 --- a/resources/tools/dockerwebcontainer/redis +++ b/resources/tools/dockerwebcontainer/redis @@ -6,3 +6,4 @@ networks: - $name restart: unless-stopped + diff --git a/resources/tools/dockerwebcontainer/template/config/cron/crontab b/resources/tools/dockerwebcontainer/template/config/cron/crontab index ea5e3f9a3..72643719a 100644 --- a/resources/tools/dockerwebcontainer/template/config/cron/crontab +++ b/resources/tools/dockerwebcontainer/template/config/cron/crontab @@ -2,4 +2,5 @@ MAILTO=sysadmin@cubedesigners.com SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin - +* * * * * runuser -l $name -c '/usr/bin/php /application/artisan schedule:run' > /proc/1/fd/1 2>/proc/1/fd/2 +# 20 5 * * * /application/scripts/restartworkers > /proc/1/fd/1 2>/proc/1/fd/2 diff --git a/resources/tools/dockerwebcontainer/template/images/elasticsearch/Dockerfile b/resources/tools/dockerwebcontainer/template/images/elasticsearch/Dockerfile new file mode 100644 index 000000000..3d6610990 --- /dev/null +++ b/resources/tools/dockerwebcontainer/template/images/elasticsearch/Dockerfile @@ -0,0 +1,2 @@ +FROM docker.elastic.co/elasticsearch/elasticsearch:8.10.2 +RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu diff --git a/resources/tools/dockerwebcontainer/template/images/php-fpm/Dockerfile b/resources/tools/dockerwebcontainer/template/images/php-fpm/Dockerfile index 12ba4acdf..36cc86301 100644 --- a/resources/tools/dockerwebcontainer/template/images/php-fpm/Dockerfile +++ b/resources/tools/dockerwebcontainer/template/images/php-fpm/Dockerfile @@ -18,13 +18,13 @@ RUN apt update \ && echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ondrej-php.list \ && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C +# Add Nodejs Repository RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list RUN apt update RUN apt -y --no-install-recommends install \ - ca-certificates \ unzip \ git \ php$phpversion-apcu \ -- 2.39.5