Skip to content

Commit

Permalink
refactor: moved frontend Twig templates into folder default( (#2969)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jul 7, 2024
1 parent ecf2d4a commit e46043d
Show file tree
Hide file tree
Showing 58 changed files with 50 additions and 88 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ phpmyfaq/admin/assets/js/editor/*
phpmyfaq/assets/dist
phpmyfaq/assets/js/libs
phpmyfaq/assets/svg/*.svg
phpmyfaq/assets/themes/default/css/*.css
phpmyfaq/assets/themes/default/css/*.map
phpmyfaq/assets/themes/default/js/*
!phpmyfaq/assets/templates/admin
!phpmyfaq/assets/templates/default
!phpmyfaq/assets/templates/setup

# Twig caches
phpmyfaq/admin/assets/cache/
Expand All @@ -74,7 +74,6 @@ phpmyfaq/admin/assets/cache/
node_modules/*
.pnpm-store


# Backup folder
backup/*

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/404.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@

$faqSession->userTracking(SessionActionType::NOT_FOUND->value, 0);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./404.twig');
2 changes: 1 addition & 1 deletion phpmyfaq/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
$category = new Category($faqConfig);
$categories = $category->getAllCategoryIds();

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./add.twig');

Expand Down
3 changes: 1 addition & 2 deletions phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use phpMyFAQ\Services\Gravatar;
use phpMyFAQ\Session\Token;
use phpMyFAQ\System;
use phpMyFAQ\Template;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
use phpMyFAQ\User\CurrentUser;
Expand Down Expand Up @@ -262,7 +261,7 @@
'version' => System::getVersion(),
'currentYear' => date('Y'),
'metaRobots' => $faqConfig->get('seo.metaTagsAdmin'),
'templateSetName' => Template::getTplSetName(),
'templateSetName' => TwigWrapper::getTemplateSetName(),
'pageDirection' => Translation::get('dir'),
'userHasAccessPermission' => $adminHelper->canAccessContent($user),
'msgSessionExpiration' => Translation::get('ad_session_expiration'),
Expand Down
9 changes: 5 additions & 4 deletions phpmyfaq/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @link https://www.phpmyfaq.de
* @since 2002-09-16
*/

use phpMyFAQ\Administration\AdminLog;
use phpMyFAQ\Attachment\AttachmentFactory;
use phpMyFAQ\Configuration;
Expand All @@ -27,7 +28,7 @@
use phpMyFAQ\Session\Token;
use phpMyFAQ\Strings;
use phpMyFAQ\System;
use phpMyFAQ\Template;
use phpMyFAQ\Template\TwigWrapper;
use phpMyFAQ\Translation;
use phpMyFAQ\User\CurrentUser;
use phpMyFAQ\User\TwoFactor;
Expand Down Expand Up @@ -87,14 +88,14 @@
//
// Set actual template set name
//
Template::setTplSetName($faqConfig->get('main.templateSet'));
TwigWrapper::setTemplateSetName($faqConfig->get('main.templateSet'));

//
// Initialize attachment factory
//
AttachmentFactory::init(
$faqConfig->get('records.defaultAttachmentEncKey'),
$faqConfig->get('records.enableAttachmentEncryption')
$faqConfig->get('records.defaultAttachmentEncKey'),
$faqConfig->get('records.enableAttachmentEncryption')
);

//
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/ask.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

$categories = $category->getAllCategoryIds();

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./ask.twig');

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{% else %}
<li><a class="dropdown-item" href="./user/ucp">{{ msgUserControlDropDown }}</a></li>
<li><a class="dropdown-item" href="./user/bookmarks">{{ msgBookmarks }}</a></li>
<li><a class="dropdown-item" href="./admin">{{ msgAdmin }}</a></li>
<li><a class="dropdown-item" href="../admin">{{ msgAdmin }}</a></li>
<li><a class="dropdown-item" href="./user/request-removal">{{ msgUserRemoval }}</a></li>
<li>
<hr class="dropdown-divider">
Expand Down Expand Up @@ -156,9 +156,6 @@
<li class="nav-item">
<a class="pmf-nav-link-footer {{ item['active'] }}" href="{{ item['link'] }}">{{ item['name'] }}</a>
</li>
<li class="nav-item">{{ msgContact }}</li>
<li class="nav-item">{{ privacyLink }}</li>
<li class="nav-item">{{ cookiePreferences }}</li>
{% endfor %}
{% if isPrivacyLinkEnabled %}
<li class="nav-item">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<label class="form-check-label" for="faqrememberme">{{ rememberMe }}</label>
</div>
<div class="d-flex align-items-center justify-content-between mt-4 mb-0">
<a class="small" href="../?action=password">{{ sendPassword }}</a>
<a class="small" href="../..?action=password">{{ sendPassword }}</a>
<button type="submit" class="btn btn-primary">{{ loginHeader }}</button>
</div>
</form>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion phpmyfaq/attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
}

// If we're here, there was an error with file download
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./attachment.twig');

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/bookmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

$bookmark = new Bookmark($faqConfig, $user);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./bookmarks.twig');

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
$contactText = nl2br($faqConfig->get('main.contactInformation'));
}

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./contact.twig');

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
'csrfTokenAddBookmark' => Token::getInstance()->getTokenString('add-bookmark')
];

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./faq.twig');

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
];
$pagination = new Pagination($options);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./glossary.twig');

Expand Down
12 changes: 0 additions & 12 deletions phpmyfaq/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use phpMyFAQ\Strings;
use phpMyFAQ\System;
use phpMyFAQ\Tags;
use phpMyFAQ\Template;
use phpMyFAQ\Translation;
use phpMyFAQ\User\CurrentUser;
use phpMyFAQ\User\TwoFactor;
Expand Down Expand Up @@ -505,17 +504,6 @@
$indexSet = 'maintenance.page.html';
}

//
// Load template files and set template variables
//
$template = new Template(
[
'index' => $indexSet,
'mainPageContent' => $includeTemplate,
],
$faqConfig->get('main.templateSet')
);

$categoryRelation = new Relation($faqConfig, $category);

$categoryHelper = new HelperCategory();
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

$faqSession->userTracking('login', 0);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twigTemplate = $twig->loadTemplate('./login.twig');

$templateVars = [
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
$comment = new Comments($faqConfig);
$comments = $comment->getCommentsData($newsId, CommentType::NEWS);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twigTemplate = $twig->loadTemplate('./news.twig');

$templateVars = [
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/open-questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$questionHelper = new QuestionHelper($faqConfig);
$questionHelper->setCategory($category);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twigTemplate = $twig->loadTemplate('./open-questions.twig');

$templateVars = [
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
$faq->setUser($currentUser);
$faq->setGroups($currentGroups);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twig->addExtension(new CategoryNameTwigExtension());
$twigTemplate = $twig->loadTemplate('./overview.twig');
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/password.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

$faqSession->userTracking('forgot_password', 0);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twigTemplate = $twig->loadTemplate('./password.twig');

$templateVars = [
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

$captchaHelper = CaptchaHelper::getInstance($faqConfig);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./register.twig');

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/request-removal.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

$faqSession->userTracking('request_removal', 0);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./request-removal.twig');

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
$confPerPage = $faqConfig->get('records.numberOfRecordsPerPage');
$totalPages = (int)ceil($numOfResults / $confPerPage);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twig->addExtension(new TagNameTwigExtension());
$twigTemplate = $twig->loadTemplate('./search.twig');
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/send2friend.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
urlencode((string) $faqLanguage)
);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./share-by-email.twig');

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
$categoryHelper = new CategoryHelper();
$categoryHelper->setPlurals(new Plurals());

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./show.twig');

Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
$siteMap->setUser($currentUser);
$siteMap->setGroups($currentGroups);

$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates');
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates/' . TwigWrapper::getTemplateSetName());
$twig->addExtension(new DebugExtension());
$twigTemplate = $twig->loadTemplate('./sitemap.twig');

Expand Down
16 changes: 0 additions & 16 deletions phpmyfaq/src/phpMyFAQ/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ abstract class Helper
*/
protected ?Tags $Tags = null;

/**
* Template class.
*/
protected ?Template $Template = null;

/**
* Plurals class.
*/
Expand Down Expand Up @@ -84,17 +79,6 @@ public function setTags(Tags $Tags): Helper
return $this;
}

/**
* Template Setter.
*
* @param Template $Template Template object
*/
public function setTemplate(Template $Template): Helper
{
$this->Template = $Template;
return $this;
}

/**
* Plurals setter.
*
Expand Down
8 changes: 4 additions & 4 deletions phpmyfaq/src/phpMyFAQ/Instance/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,17 @@ public function copyConstantsFile(string $destination): bool
}

/**
* Copies a defined template folder to a new client instance, by default
* the default template located at ./assets/themes/default/ will be copied.
* Copies a defined template folder to a new client instance, by default,
* the default template located at ./assets/templates/default/ will be copied.
*
* @param string $destination Destination folder
* @param string $templateDir Template folder
* @throws Exception
*/
public function copyTemplateFolder(string $destination, string $templateDir = 'default'): void
{
$sourceTpl = $this->filesystem->getRootPath() . '/assets/themes/' . $templateDir;
$destTpl = $destination . '/assets/themes/';
$sourceTpl = $this->filesystem->getRootPath() . '/assets/templates/' . $templateDir;
$destTpl = $destination . '/assets/templates/';

$this->filesystem->recursiveCopy($sourceTpl, $destTpl);
}
Expand Down
9 changes: 7 additions & 2 deletions phpmyfaq/src/phpMyFAQ/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use DirectoryIterator;
use Exception;
use phpMyFAQ\Database\DatabaseDriver;
use phpMyFAQ\Template\TwigWrapper;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -204,16 +205,20 @@ public function setDatabase(DatabaseDriver $databaseDriver): System
public function getAvailableTemplates(): array
{
$templates = [];
$systemFolder = ['admin', 'setup'];

foreach (new DirectoryIterator(PMF_ROOT_DIR . '/assets/themes/') as $item) {
foreach (new DirectoryIterator(PMF_ROOT_DIR . '/assets/templates/') as $item) {
$basename = $item->getBasename();
if ($item->isDot()) {
continue;
}
if (!$item->isDir()) {
continue;
}
$templates[$basename] = Template::getTplSetName() === $basename;
if (in_array($basename, $systemFolder)) {
continue;
}
$templates[$basename] = TwigWrapper::getTemplateSetName() === $basename;
}

return $templates;
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TwigWrapper
private Environment $twigEnvironment;

/** @var string Name of an active template set. */
private static string $templateSetName = '';
private static string $templateSetName = 'default';

public function __construct(string $templatePath)
{
Expand Down
Loading

0 comments on commit e46043d

Please sign in to comment.