Skip to content

Commit

Permalink
Optimize domain check; Add correct translation for en
Browse files Browse the repository at this point in the history
  • Loading branch information
MDevster committed Sep 30, 2022
1 parent 79267b6 commit c4e677f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Types of changes
Security in case of vulnerabilities.
)

## [1.5.2](https://github.com/pdir/contao-theme-helper-bundle/tree/1.5.2) – 2022-09-30

- [Fixed] Optimize domain check
- [Changed] Add correct translation for en

## [1.5.1](https://github.com/pdir/contao-theme-helper-bundle/tree/1.5.1) – 2022-09-05

- [Fixed] Remove deprecated request token
Expand Down
3 changes: 3 additions & 0 deletions contao/languages/de/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
$GLOBALS['TL_LANG']['MSC']['th_insert_domain'] = 'Bitte Domain angeben';
$GLOBALS['TL_LANG']['MSC']['th_domain_tip'] = 'Hier kannst du die Domain angeben. (Bsp. contao-themes.net oder meissen.online, ohne http(s)://)';
$GLOBALS['TL_LANG']['MSC']['th_button_check'] = 'Check Domain';

$GLOBALS['TL_LANG']['MSC']['th_readonly_message'] = 'Bitte bearbeiten Sie das Theme und tragen im Feld <strong>Theme Code</strong> den entsprechenden Theme Code ein.<br><br>MATE Theme: <strong>mate</strong><br>ODD Theme: <strong>odd</strong><br>NATURE Theme: <strong>nature</strong><br>0.1 Theme: <strong>0.1</strong><br>CONVERT Theme: <strong>convert</strong><br><br>Danach sollten Sie Ihre Domain registrieren können.<br><br>Detaillierte Informationen finden Sie auch auf:<a href="https://docs.contao-themes.net/#/" target="_blank" rel="noopener" style="color:orange;font-weight:700;">docs.contao-themes.net</a>.';
$GLOBALS['TL_LANG']['MSC']['th_domain_note'] = 'Bitte geben Sie die Domain <strong>ohne http(s):// und www</strong> ein, z. B. meinedomain.de. Subdomains müssen explizit angegeben werden, z. B. shop.meinedomain.de.';
3 changes: 3 additions & 0 deletions contao/languages/en/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
$GLOBALS['TL_LANG']['MSC']['th_insert_domain'] = 'Please insert Domain';
$GLOBALS['TL_LANG']['MSC']['th_domain_tip'] = 'Here you can define the domain. (ex. contao-themes.net or meissen.online, without http(s)://)';
$GLOBALS['TL_LANG']['MSC']['th_button_check'] = 'Check Domain';

$GLOBALS['TL_LANG']['MSC']['th_readonly_message'] = 'Please edit the theme and enter the appropriate theme code in the <strong>Theme Code</strong> field.<br><br>MATE Theme: <strong>mate</strong><br>ODD Theme: <strong>odd</strong><br>NATURE Theme: <strong>nature</strong><br>0.1 Theme: <strong>0.1</strong><br>CONVERT Theme: <strong>convert</strong><br><br>After that you should be able to register your domain.<br><br>You can also find detailed information on:<a href="https://docs.contao-themes.net/#/" target="_blank" rel="noopener" style="color:orange;font-weight:700;">docs.contao-themes.net</a>.';
$GLOBALS['TL_LANG']['MSC']['th_domain_note'] = 'Please enter the domain <strong>without http(s):// and www</strong>, e.g. mydomain.com. Subdomains must be specified explicitly, e.g. store.meinedomain.de.';
20 changes: 6 additions & 14 deletions contao/templates/backend/be_th_check_domain.html5
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,7 @@

<?php if($this->readonly): ?>
<p style="font-size:16px;line-height:22px;">
Bitte bearbeiten Sie das Theme und tragen im Feld <strong>Theme Code</strong> den entsprechenden Theme Code ein.<br><br>

MATE Theme: <strong>mate</strong><br>
ODD Theme: <strong>odd</strong><br>
NATURE Theme: <strong>nature</strong><br>
0.1 Theme: <strong>0.1</strong><br>
CONVERT Theme: <strong>convert</strong>

<br><br>Danach sollten Sie Ihre Domain registrieren können.<br><br>
Detaillierte Informationen finden Sie auch auf:
<a href="https://docs.contao-themes.net/#/" target="_blank" rel="noopener" style="color:orange;font-weight:700;">docs.contao-themes.net</a>.
<?= $GLOBALS['TL_LANG']['MSC']['th_readonly_message'] ?>
</p>
<?php else: ?>
<div class="widget">
Expand All @@ -32,8 +22,9 @@
<input type="text" name="domain" id="ctrl_domain" class="tl_text" value="" required="" maxlength="255" onfocus="Backend.getScrollOffset()">
<p class="tl_help tl_tip" title=""><?= $this->domainTip ?></p>
</div>
<p class="note clr">Bitte geben Sie die Domain <strong>ohne http(s):// und www</strong> ein, z. B. meinedomain.de. Subdomains
müssen explizit angegeben werden, z. B. shop.meinedomain.de.</p>
<p class="note clr">
<?= $GLOBALS['TL_LANG']['MSC']['th_domain_note'] ?>
</p>
<div class="clr tl_formbody_submit">
<div class="tl_submit_container">
<button type="submit" name="check" id="save" class="tl_submit" accesskey="s"><?= $this->buttonCheck ?></button>
Expand All @@ -48,7 +39,7 @@

// Don't follow the link
event.preventDefault();
window.parent.location.reload();
window.top.location.reload();
}, false);

document.getElementById('save').addEventListener('click', function (e) {
Expand All @@ -60,6 +51,7 @@
}
}, false);
</script>
<?php if ($this->reloadPage): ?><script>setTimeout(function() {window.top.location.reload();}, 3000);</script><?php endif; ?>
</div>
<?php endif; ?>
</div>
26 changes: 21 additions & 5 deletions src/Backend/Licence.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class Licence extends BackendModule
{
protected string $strTemplate = 'be_th_check_domain';
protected $strTemplate = 'be_th_check_domain';

/**
* Generate the module
Expand All @@ -38,9 +38,10 @@ protected function compile()
$this->Template->domainTip = $GLOBALS['TL_LANG']['MSC']['th_domain_tip'];
$this->Template->buttonCheck = $GLOBALS['TL_LANG']['MSC']['th_button_check'];
$this->Template->shortCode = Input::get('shortCode') ? : Input::post('shortCode');
$this->Template->theme = Input::get('theme');
$this->Template->theme = Input::get('theme') ? : Input::post('theme');;
$this->Template->message = null;
$this->Template->requestToken = System::getContainer()->get('contao.csrf.token_manager')->getDefaultTokenValue();
$this->Template->reloadPage = false;

switch (Input::get('act')) {
case 'checkDomain':
Expand All @@ -54,13 +55,27 @@ protected function compile()

$url .= \http_build_query($params);

error_reporting(E_ALL);
ini_set('display_errors','1');

$ch = \curl_init($url);
\curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept:application/json, Content-Type:application/json']);
\curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
\curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = \curl_exec($ch);
$errNo = \curl_errno($ch);
$err = \curl_error($ch);
\curl_close($ch);

if (0 !== $errNo) {
$this->Template->message = $err . " [Error No $errNo]";
break;
}

// response
$response = \json_decode(\curl_exec($ch), true);
$response = \json_decode($result, true);

if(isset($response['message']) && Input::post('theme'))
{
Expand All @@ -71,8 +86,9 @@ protected function compile()
$objTheme = ThemeModel::findById(Input::post('theme'));
$objTheme->pdir_th_license_domain = $response['domain'];
$objTheme->save();
}

$this->Template->reloadPage = true;
}

$this->Template->message = $response['message'];
break;
Expand Down

0 comments on commit c4e677f

Please sign in to comment.