[11/06/2024] Les premières modifs + installation de quelques modules indispensables

This commit is contained in:
2024-06-11 14:57:59 +02:00
parent 5ac5653ae5
commit 77cf2c7cc6
1626 changed files with 171457 additions and 131 deletions

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<hooks>
<hook id="storeseo.hook" class="StoreSeo\Hook\StoreSeoHook" scope="request">
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfig" />
</hook>
</hooks>
<forms>
<form name="storeseo_form_config" class="StoreSeo\Form\StoreSeoForm" />
</forms>
</config>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="http://thelia.net/schema/dic/module"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
<fullnamespace>StoreSeo\StoreSeo</fullnamespace>
<descriptive locale="en_US">
<title>Manage translations for your store main SEO meta</title>
</descriptive>
<descriptive locale="fr_FR">
<title>Gère les traductions des principales metas SEO de votre boutique</title>
</descriptive>
<languages>
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.0.1</version>
<authors>
<author>
<name>Etienne Perriere</name>
<email>eperriere@openstudio.fr</email>
</author>
</authors>
<type>classic</type>
<thelia>2.5.0</thelia>
<stability>other</stability>
</module>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
</routes>

View File

@@ -0,0 +1,97 @@
<?php
namespace StoreSeo\Controller;
use StoreSeo\StoreSeo;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Form\Exception\FormValidationException;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class StoreSeoConfigController
* @package StoreSeo\Controller
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
class StoreSeoConfigController extends BaseAdminController
{
/**
* @Route("/admin/module/StoreSeo", name="storeseo_configuration_default", methods="GET")
*/
public function defaultAction()
{
if (null !== $response = $this->checkAuth([AdminResources::MODULE], ["storeseo"], AccessManager::VIEW)) {
return $response;
}
// Get current edition language locale
$locale = $this->getCurrentEditionLocale();
$form = $this->createForm(
"storeseo_form_config",
FormType::class,
[
'title' => StoreSeo::getConfigValue('title', null, $locale),
'description' => StoreSeo::getConfigValue('description', null, $locale),
'keywords' => StoreSeo::getConfigValue('keywords', null, $locale)
]
);
$this->getParserContext()->addForm($form);
return $this->render("storeseo-configuration");
}
/**
* @Route("/admin/module/StoreSeo", name="storeseo_configuration_save", methods="POST")
*/
public function saveAction()
{
if (null !== $response = $this->checkAuth([AdminResources::MODULE], ["storeseo"], AccessManager::UPDATE)) {
return $response;
}
$baseForm = $this->createForm("storeseo_form_config");
$errorMessage = null;
// Get current edition language locale
$locale = $this->getCurrentEditionLocale();
try {
$form = $this->validateForm($baseForm);
$data = $form->getData();
// Save data
StoreSeo::setConfigValue('title', $data["title"], $locale);
StoreSeo::setConfigValue('description', $data["description"], $locale);
StoreSeo::setConfigValue('keywords', $data["keywords"], $locale);
} catch (FormValidationException $ex) {
// Invalid data entered
$errorMessage = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$errorMessage = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()], StoreSeo::DOMAIN_NAME, $locale);
}
if (null !== $errorMessage) {
// Mark the form as with error
$baseForm->setErrorMessage($errorMessage);
// Send the form and the error to the parser
$this->getParserContext()
->addForm($baseForm)
->setGeneralError($errorMessage)
;
} else {
$this->getParserContext()
->set("success", true)
;
}
return $this->defaultAction();
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace StoreSeo\Form;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Thelia\Form\BaseForm;
class StoreSeoForm extends BaseForm
{
public static function getName()
{
return 'storeseo_form_config';
}
/**
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add(
'title',
TextType::class,
['label' => $this->translator->trans('Store name', [], 'storeseo.fo.default')]
)
->add(
'description',
TextType::class,
['label' => $this->translator->trans('Store description', [], 'storeseo.fo.default')]
)
->add(
'keywords',
TextType::class,
['label' => $this->translator->trans('Keywords', [], 'storeseo.fo.default')]
)
;
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace StoreSeo\Hook;
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
/**
* Class StoreSeoHook
* @package StoreSeo\Hook
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
class StoreSeoHook extends BaseHook
{
public function onModuleConfig(HookRenderEvent $event)
{
$event->add($this->render('storeseo-configuration.html'));
}
}

View File

@@ -0,0 +1,9 @@
<?php
return array(
'Configuration correctly saved' => 'Configuration correctly saved',
'Configure StoreSEO' => 'Configure StoreSEO',
'Home' => 'Home',
'Modules' => 'Modules',
'StoreSeo configuration' => 'StoreSEO configuration',
);

View File

@@ -0,0 +1,9 @@
<?php
return array(
'Configuration correctly saved' => 'Configuration correctement sauvegardée',
'Configure StoreSEO' => 'Configurer StoreSEO',
'Home' => 'Accueil',
'Modules' => 'Modules',
'StoreSeo configuration' => 'Configuration de StoreSEO',
);

View File

@@ -0,0 +1,8 @@
<?php
return array(
'Keywords' => 'Keywords',
'Sorry, an error occurred: %err' => 'Sorry, an error occurred: %err',
'Store description' => 'Store description',
'Store name' => 'Store name',
);

View File

@@ -0,0 +1,8 @@
<?php
return array(
'Keywords' => 'Mots-clés',
'Sorry, an error occurred: %err' => 'Désolé, une erreur s\'est produite : %err',
'Store description' => 'Description de la boutique',
'Store name' => 'Nom de la boutique',
);

View File

@@ -0,0 +1,56 @@
# Store Seo
Manage translation for your store SEO meta.
## Installation
### Manually
* Copy the module into ```<thelia_root>/local/modules/``` directory and be sure that the name of the module is StoreSeo.
* Activate it in your thelia administration panel
### Composer
Add it in your main thelia composer.json file
```
composer require thelia/store-seo-module:~1.2.0
```
## Usage
Once activated, click on the configuration button of the module.
Then, select one of your store available language and fill inputs with your store title, description and keywords. Save and do it for each of your language.
They will be used on pages with no SEO meta configured.
## Integration
Open the layout.tpl file of your template.
Check the ```Define some stuff for Smarty``` section at the top of the file, and be sur that you have this assignation:
```
{assign var="lang_locale" value={lang attr="locale"}}
```
Add this line in the ```<head>``` section, before the ```<title>``` tag :
```
{store_seo_meta locale=$lang_locale}
```
Also add this in the ```{block name="meta"}```, after the ```<meta name="description">``` tag :
```
{if $page_keywords}
<meta name="keywords" content="{$page_keywords}">
{else}
<meta name="keywords" content="{$default_keywords}">
{/if}
```
Finally, be sure that you have no ```{$page_title = {config key="store_name"}}``` declaration in your other template files.

View File

@@ -0,0 +1,48 @@
<?php
namespace StoreSeo\Smarty\Plugins;
use StoreSeo\StoreSeo;
use Thelia\Model\ConfigQuery;
use TheliaSmarty\Template\AbstractSmartyPlugin;
use TheliaSmarty\Template\SmartyPluginDescriptor;
/**
* Class StoreSeoPlugin
* @package StoreSeo\Smarty\Plugins
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
class StoreSeoPlugin extends AbstractSmartyPlugin
{
/**
* @return SmartyPluginDescriptor[] an array of SmartyPluginDescriptor
*/
public function getPluginDescriptors()
{
return [
new SmartyPluginDescriptor("function", "store_seo_meta", $this, "changeSeoMeta")
];
}
/**
* Assign meta title, description and keyword for the template
*
* @param array $params
* @param \Smarty $smarty
*/
public function changeSeoMeta($params, &$smarty)
{
// Get language and moduleConfig
$locale = $params['locale'];
// Get store title
$smarty->assign("store_name", StoreSeo::getConfigValue('title', null, $locale));
// Get store description
$smarty->assign("store_description", StoreSeo::getConfigValue('description', null, $locale));
// Get store keywords
$smarty->assign("default_keywords", StoreSeo::getConfigValue('keywords', null, $locale));
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace StoreSeo;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
use Thelia\Module\BaseModule;
/**
* Class StoreSeo
* @package StoreSeo
* @author Etienne Perriere <eperriere@openstudio.fr>
*/
class StoreSeo extends BaseModule
{
/** @var string */
const DOMAIN_NAME = 'storeseo';
/*
* You may now override BaseModuleInterface methods, such as:
* install, destroy, preActivation, postActivation, preDeactivation, postDeactivation
*
* Have fun !
*/
public static function configureServices(ServicesConfigurator $servicesConfigurator): void
{
$servicesConfigurator->load(self::getModuleCode().'\\', __DIR__)
->exclude([THELIA_MODULE_DIR . ucfirst(self::getModuleCode()). "/I18n/*"])
->autowire(true)
->autoconfigure(true);
}
}

View File

@@ -0,0 +1,11 @@
{
"name": "thelia/store-seo-module",
"license": "LGPL-3.0+",
"type": "thelia-module",
"require": {
"thelia/installer": "~1.1"
},
"extra": {
"installer-name": "StoreSeo"
}
}

View File

@@ -0,0 +1,98 @@
{extends file="admin-layout.tpl"}
{block name="no-return-functions"}
{$admin_current_location = 'modules'}
{/block}
{block name="page-title"}{intl d="storeseo.bo.default" l='StoreSeo configuration'}{/block}
{block name="check-resource"}admin.module{/block}
{block name="check-access"}view{/block}
{block name="check-module"}StoreSeo{/block}
{block name="main-content"}
<div class="container" id="wrapper">
<ul class="breadcrumb">
<li><a href="{url path='/admin'}">{intl l="Home" d="storeseo.bo.default"}</a></li>
<li><a href="{url path='/admin/modules'}">{intl l="Modules" d="storeseo.bo.default"}</a></li>
<li>{intl l="StoreSeo configuration" d="storeseo.bo.default"}</li>
</ul>
<div class="general-block-decorator">
<div class="title title-without-tabs">
{intl l="Configure StoreSEO" d="storeseo.bo.default"}
</div>
<div class="row">
<div class="col-md-12">
{if $success|default:false}
<div class="alert alert-success">
{intl l="Configuration correctly saved" d="storeseo.bo.default"}
</div>
{/if}
<div class="form-container">
{form name='storeseo_form_config'}
<form method="post" action="{url path='/admin/module/StoreSeo'}">
{form_hidden_fields form=$form}
{include "includes/inner-form-toolbar.html" close_url={url path='/admin/modules'}}
<br/>
{form_field form=$form field="title"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="title"}
<br />
<span class="error">{$message|default:null}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="description"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="description"}
<br />
<span class="error">{$message|default:null}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
{form_field form=$form field="keywords"}
<div class="form-group {if $error}has-error{/if}">
<label class="control-label">
{$label}
{form_error form=$form field="keywords"}
<br />
<span class="error">{$message|default:null}</span>
{/form_error}
</label>
<input type="text" class="form-control" name="{$name}" value="{$value}" />
</div>
{/form_field}
</form>
{/form}
</div>
</div>
</div>
</div>
</div>
{/block}