Skip to content

Commit

Permalink
fix: normalize base domain
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Carlsen <[email protected]>
  • Loading branch information
sjelfull committed Jun 29, 2023
1 parent 603ea6c commit c2419cb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/PluginTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function(RegisterComponentTypesEvent $event) {
$encodedSettings = Json::encode([
'sessionSourceId' => $settings->sessionSourceId,
'deploymentSiteId' => $settings->deploymentSiteId,
'qbankBaseDomain' => $settings->qbankBaseDomain,
'qbankBaseDomain' => $settings->getBaseDomain(),
'qbankBaseUrl' => $settings->qbankBaseUrl,
]);
$view = Craft::$app->getView();
Expand Down
46 changes: 46 additions & 0 deletions src/helpers/UrlHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* QBank Connector plugin for Craft CMS 3.x
*
* Connect Craft to QBank's DAM
*
* @link https://superbig.co
* @copyright Copyright (c) 2019 Superbig
* @since 1.1.0
*/

namespace superbig\qbankconnector\helpers;

use craft\helpers\Json;
use QBNK\QBank\API\Exception\RequestException;
use QBNK\QBank\API\Model\MediaUsage;
use superbig\qbankconnector\models\DeleteReference;
use superbig\qbankconnector\models\NewUsageReference;
use superbig\qbankconnector\models\UsageModel;
use superbig\qbankconnector\models\UserInfo;
use superbig\qbankconnector\QbankConnector;

use Craft;
use craft\queue\BaseJob;
use superbig\qbankconnector\records\QbankConnectorUsageRecord;

/**
* @author Superbig
* @package QbankConnector
* @since 1.0.0
*
* @property NewUsageReference[] newUsageReferences
* @property DeleteReference[] $deleteUsageReferences
*/
class UrlHelper extends \craft\helpers\UrlHelper {
public static function getBaseHost(string $url, $default = null)
{
$parsedUrl = parse_url($url);

if ($parsedUrl && isset($parsedUrl['host'])) {
return $parsedUrl['host'];
}

return $default;
}
}
13 changes: 5 additions & 8 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use craft\elements\Entry;
use craft\elements\MatrixBlock;
use craft\elements\User;
use superbig\qbankconnector\helpers\UrlHelper;
use superbig\qbankconnector\QbankConnector;

use Craft;
Expand All @@ -25,9 +26,6 @@
*/
class Settings extends Model
{
// Public Properties
// =========================================================================

public $connectionTimeout = 10;
public $clientId = '';
public $sessionSourceId = '';
Expand All @@ -49,12 +47,11 @@ class Settings extends Model
MatrixBlock::class,
];

// Public Methods
// =========================================================================
public function getBaseDomain()
{
return UrlHelper::getBaseHost($this->qbankBaseDomain, 'sales.qbank.se');
}

/**
* @inheritdoc
*/
public function rules()
{
return [
Expand Down

0 comments on commit c2419cb

Please sign in to comment.