Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Bitter authored and Fabian Bitter committed Aug 27, 2023
1 parent 12bbeb5 commit 8c37024
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 171 deletions.
1 change: 1 addition & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 2.6.0
==================================================
- Add support for multi sites

Version 2.5.0
==================================================
- V9 compatible
Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module.exports = function (grunt) {
{src: ['routes/**'], dest: "dist/"},
{src: ['single_pages/**'], dest: "dist/"},
{src: ['src/**'], dest: "dist/"},
{src: ['views/**'], dest: "dist/"},
{src: ['languages/**'], dest: "dist/"},
{src: ['icon.png'], dest: "dist/"},
{src: ['CHANGELOG'], dest: "dist/"}
Expand Down
2 changes: 1 addition & 1 deletion controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Controller extends Package
{
protected $pkgHandle = 'app_icon';
protected $pkgVersion = '2.5.0';
protected $pkgVersion = '2.6.0';
protected $appVersionRequired = '9.0.0';
protected $pkgAutoloaderRegistries = [
'src/Bitter/AppIcon' => 'Bitter\AppIcon',
Expand Down
3 changes: 1 addition & 2 deletions controllers/dialog/support/create_ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ public function submit()

$rawData = $response->getBody()->getContents();

/** @noinspection PhpComposerExtensionStubsInspection */
$json = json_decode($rawData, true);

if ($json["error"]) {
if (isset($json["error"])) {
foreach ($json["errors"] as $errorMessage) {
$errorList->add($errorMessage);
}
Expand Down
13 changes: 5 additions & 8 deletions controllers/single_page/dashboard/system/app_icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@

namespace Concrete\Package\AppIcon\Controller\SinglePage\Dashboard\System;

use Concrete\Core\Page\Controller\DashboardPageController;
use Bitter\AppIcon\Settings;
use Concrete\Core\Page\Controller\DashboardSitePageController;

/** @noinspection PhpUnused */

class AppIcon extends DashboardPageController
class AppIcon extends DashboardSitePageController
{
public function view()
{
/** @var Settings $settings */
$settings = $this->app->make(Settings::class);
$config = $this->getSite()->getConfigRepository();

/** @noinspection PhpUndefinedMethodInspection */
if ($this->request->getMethod() === "POST") {
$settings->setAppIconFileId($this->post("appIcon"));
$config->save("settings.app_icon_file_id", (int)$this->request->request->get("appIcon", 0));
}

$this->set("appIcon", $settings->getAppIconFile());
$this->set("appIcon", $config->get("settings.app_icon_file_id"));
}
}
23 changes: 22 additions & 1 deletion single_pages/dashboard/system/app_icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Concrete\Core\Entity\File\File;
use Concrete\Core\Form\Service\Form;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\View\View;
use Concrete\Core\Support\Facade\Url;

/** @var File $appIcon */

Expand All @@ -26,6 +26,27 @@

?>

<div class="ccm-dashboard-header-buttons">
<a class="btn btn-secondary" href="javascript:void(0);" id="ccm-report-bug">
<?php echo t('Get Help') ?>
</a>
</div>


<script>
(function ($) {
$("#ccm-report-bug").click(function () {
jQuery.fn.dialog.open({
href: "<?php echo (string)\Concrete\Core\Support\Facade\Url::to("/ccm/system/dialogs/app_icon/create_ticket"); ?>",
modal: true,
width: 500,
title: "<?php echo h(t("Support"));?>",
height: '80%'
});
});
})(jQuery);
</script>

<div class="row">
<div class="col-xs-12">
<form action="#" method="post">
Expand Down
114 changes: 57 additions & 57 deletions src/Bitter/AppIcon/Provider/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Bitter\AppIcon\Provider;

use Bitter\AppIcon\Settings;
use Concrete\Core\Cache\Level\ExpensiveCache;
use Concrete\Core\Entity\File\File;
use Concrete\Core\Entity\File\Version;
Expand Down Expand Up @@ -51,16 +50,23 @@ private function initializeRoutes()
$list->loadRoutes($router);
}

private function getIconFile(): ?File
{
/** @var SiteService $siteService */
$siteService = $this->app->make(SiteService::class);
$site = $siteService->getSite();
$config = $site->getConfigRepository();

return \Concrete\Core\File\File::getByID($config->get("settings.app_icon_file_id"));
}

private function getResizedAppIconUrl($width, $height)
{
$resizedAppIconUrl = '';

/** @var Settings $settings */
$settings = $this->app->make(Settings::class);
$file = $this->getIconFile();

$file = $settings->getAppIconFile();

if ($settings->hasAppIconFile()) {
if ($file instanceof File) {
try {
/** @var ImageHelper $imageHelper */
/** @noinspection PhpDeprecationInspection */
Expand All @@ -83,78 +89,70 @@ private function getRealResizedAppIconUrl()
{
$retVal = null;

/** @var Settings $settings */
$settings = $this->app->make(Settings::class);

if ($settings->hasAppIconFile()) {
$file = $settings->getAppIconFile();

if ($file instanceof File) {
$filesystem = $file->getFileStorageLocationObject()->getFileSystemObject();
$file = $this->getIconFile();
if ($file instanceof File) {
$filesystem = $file->getFileStorageLocationObject()->getFileSystemObject();

$configuration = $file->getFileStorageLocationObject()->getConfigurationObject();
$configuration = $file->getFileStorageLocationObject()->getConfigurationObject();

$fID = $file->getFileID();
$fID = $file->getFileID();

$fileVersion = $file->getApprovedVersion();
$fileVersion = $file->getApprovedVersion();

if ($fileVersion instanceof Version) {
try {
$timestamp = $fileVersion->getFileResource()->getTimestamp();
$icoFileName = '/cache/thumbnails/' . md5(implode(':', [$fID, $timestamp])) . ".ico";
if ($fileVersion instanceof Version) {
try {
$timestamp = $fileVersion->getFileResource()->getTimestamp();
$icoFileName = '/cache/thumbnails/' . md5(implode(':', [$fID, $timestamp])) . ".ico";

if ($filesystem->has($icoFileName) === false) {
$fileData = $fileVersion->getFileContents();
if ($filesystem->has($icoFileName) === false) {
$fileData = $fileVersion->getFileContents();

$imagine = new Imagine();
$imagine = new Imagine();

$resizedImage = $imagine->load($fileData)->resize(new Box(16, 16))->crop(new Point(0, 0), new Box(16, 16));
$resizedImage = $imagine->load($fileData)->resize(new Box(16, 16))->crop(new Point(0, 0), new Box(16, 16));

if ($resizedImage instanceof Image) {
// https://msdn.microsoft.com/de-de/library/windows/desktop/dd183376(v=vs.85).aspx
$bitmapData = pack("VVVvvVVVVVV", 40, 16, 32, 1, 32, 0, 0, 0, 0, 0, 0);
if ($resizedImage instanceof Image) {
// https://msdn.microsoft.com/de-de/library/windows/desktop/dd183376(v=vs.85).aspx
$bitmapData = pack("VVVvvVVVVVV", 40, 16, 32, 1, 32, 0, 0, 0, 0, 0, 0);

for ($y = 15; $y >= 0; $y--) {
for ($x = 0; $x < 16; $x++) {
/** @noinspection PhpComposerExtensionStubsInspection */
$bitmapData .= pack('V', imagecolorat($resizedImage->getGdResource(), $x, $y) & 0xFFFFFF);
}
for ($y = 15; $y >= 0; $y--) {
for ($x = 0; $x < 16; $x++) {
/** @noinspection PhpComposerExtensionStubsInspection */
$bitmapData .= pack('V', imagecolorat($resizedImage->getGdResource(), $x, $y) & 0xFFFFFF);
}
}

// https://msdn.microsoft.com/en-us/library/ms997538.aspx
$icoHeader = pack("vvvCCCCvvVV", 0, 1, 1, 16, 16, 0, 0, 1, 32, strlen($bitmapData), 22);
// https://msdn.microsoft.com/en-us/library/ms997538.aspx
$icoHeader = pack("vvvCCCCvvVV", 0, 1, 1, 16, 16, 0, 0, 1, 32, strlen($bitmapData), 22);

// Merge ico header + bitmap data together
$icoFileContent = $icoHeader . $bitmapData;
// Merge ico header + bitmap data together
$icoFileContent = $icoHeader . $bitmapData;

// write to file
try {
$filesystem->write($icoFileName, $icoFileContent);
} catch (FileExistsException $e) {
// Skip issue
}
// write to file
try {
$filesystem->write($icoFileName, $icoFileContent);
} catch (FileExistsException $e) {
// Skip issue
}
}

$retVal = $configuration->getPublicURLToFile($icoFileName);
} catch (FileNotFoundException $e) {
// Skip issue
}

$retVal = $configuration->getPublicURLToFile($icoFileName);
} catch (FileNotFoundException $e) {
// Skip issue
}
}
}


return $retVal;
}

private function getMimeType()
{
/** @var Settings $settings */
$settings = $this->app->make(Settings::class);

if ($settings->hasAppIconFile()) {
$file = $settings->getAppIconFile();
$file = $this->getIconFile();

if ($file instanceof File) {
$fileVersion = $file->getApprovedVersion();

if ($fileVersion instanceof Version) {
Expand Down Expand Up @@ -251,7 +249,12 @@ private function getIconHtml()
/** @var $cache ExpensiveCache */
$cache = $this->app->make(ExpensiveCache::class);

$cacheItem = $cache->getItem('bitter.app_icon.icon_html');
/** @var SiteService $siteService */
$siteService = $this->app->make(SiteService::class);
$site = $siteService->getSite();
$siteId = $site->getSiteID();

$cacheItem = $cache->getItem('bitter.app_icon.icon_html_' . $siteId);

if ($cacheItem->isMiss()) {
$cacheItem->lock();
Expand All @@ -274,10 +277,7 @@ private function injectToHeader()
$page = $pageEvent->getPageObject();

if ($page instanceof Page) {
/** @var Settings $settings */
$settings = $this->app->make(Settings::class);

if ($settings->hasAppIconFile()) {
if ($this->getIconFile() instanceof File) {
View::getInstance()->addHeaderItem($this->getIconHtml());
}
}
Expand Down
93 changes: 0 additions & 93 deletions src/Bitter/AppIcon/Settings.php

This file was deleted.

Loading

0 comments on commit 8c37024

Please sign in to comment.