refactor(plugin): rebrand as MT3SMarketingProgram, release 0.17.0
Rename the plugin's vendor/namespace from experiential/Program to mt3s/MT3SMarketingProgram (composer: mt3s/mautic-marketing-program-bundle): - ProgramBundle -> MT3SMarketingProgramBundle; extension, integration, config support, permissions, events and twig extension renamed likewise - Initiative* -> Program*: controller (InitiativeController -> ProgramController), model, entities, repositories, form types and views (new _tabs/_task_table/_tab_table_filter partials, details page) - Settings config form theme -> _config_mt3smarketingprogramconfig_widget; routes and translations re-prefixed (mt3s_marketing_program_*) - Assets: icon.svg -> mt3s-mp-icon.svg; program.js -> mt3s-mp-program.js (OnLoad hooks renamed mt3sMpProgram*) - Add Command/RefreshStatsCommand; Migrations/Version_0_17_0.php renames the tables to mt3s_mp_program_*
This commit is contained in:
1 parent
687d33d30c
commit
ea88b7a772
131 files changed
+3238
-2836
No files matched your search
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Twig;
|
||||
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Audience;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\AudienceType;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\AudienceRepository;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Service\CurrencyProvider;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Service\ItemTypeProvider;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Service\AudienceAttributes;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Twig functions for the plan templates (kind: "description", "allocation", "objective" or "task"):
|
||||
* mt3s_marketing_program_item_type_name(kind, key) localized type name, or null for an unknown key
|
||||
* mt3s_marketing_program_item_type_description(kind, key) localized type description ('' when none)
|
||||
* mt3s_marketing_program_item_type_icon(kind, key) the type's pictogram (Remix Icon class), or null
|
||||
* mt3s_marketing_program_currency() the general currency code, e.g. EUR
|
||||
* mt3s_marketing_program_money(amount) an amount with 2 decimals, e.g. 12,500.00
|
||||
* mt3s_marketing_program_audience_channel_label(key) the label key of an audience channel, e.g. "Email"
|
||||
* mt3s_marketing_program_audience_decision_role_label(key) the localized name of a decision role value, or null
|
||||
* mt3s_marketing_program_audience_tone_label(key) the localized name of a tone value, or null
|
||||
* mt3s_marketing_program_audience_attributes() the togglable audience attribute keys, in form order
|
||||
* mt3s_marketing_program_audience_attribute_toggle(key) the local.php parameter name of an attribute's toggle
|
||||
* mt3s_marketing_program_audience_segment_counts(items) contact counts of the segments of the listed audiences,
|
||||
* keyed audience id => (segment id => count)
|
||||
* mt3s_marketing_program_audience_segment_count(segmentId) the contact count of one segment
|
||||
*
|
||||
* Filters:
|
||||
* mt3s_marketing_program_linkify(text) plain text as HTML, with the URLs in it as links opening in a new tab
|
||||
* mt3s_marketing_program_audience_type_icon(value) the pictogram of an AudienceType case value ('persona'…)
|
||||
*/
|
||||
class MT3SMarketingProgramExtension extends AbstractExtension
|
||||
{
|
||||
public function __construct(
|
||||
private ItemTypeProvider $typeProvider,
|
||||
private CurrencyProvider $currencyProvider,
|
||||
private AudienceAttributes $audienceAttributes,
|
||||
private AudienceRepository $audienceRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
// The filter escapes everything itself, so its output is safe for templates.
|
||||
new TwigFilter('mt3s_marketing_program_linkify', fn (?string $text): string => self::linkify($text), ['is_safe' => ['html']]),
|
||||
new TwigFilter('mt3s_marketing_program_audience_type_icon', fn ($value): string => self::audienceTypeIcon($value)),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('mt3s_marketing_program_item_type_name', fn (string $kind, ?string $key): ?string => $this->typeProvider->getName($kind, $key)),
|
||||
new TwigFunction('mt3s_marketing_program_item_type_description', fn (string $kind, ?string $key): ?string => $this->typeProvider->getDescription($kind, $key)),
|
||||
new TwigFunction('mt3s_marketing_program_item_type_icon', fn (string $kind, ?string $key): ?string => $this->typeProvider->getIcon($kind, $key)),
|
||||
new TwigFunction('mt3s_marketing_program_currency', fn (): string => $this->currencyProvider->getCurrency()),
|
||||
new TwigFunction('mt3s_marketing_program_money', fn ($amount): string => number_format((float) $amount, 2)),
|
||||
new TwigFunction('mt3s_marketing_program_audience_channel_label', fn (string $key): string => Audience::CHANNELS[$key] ?? $key),
|
||||
new TwigFunction('mt3s_marketing_program_audience_decision_role_label', fn (?string $key): ?string => $this->typeProvider->getName(ItemTypeProvider::KIND_AUDIENCE_DECISION_ROLE, $key)),
|
||||
new TwigFunction('mt3s_marketing_program_audience_tone_label', fn (?string $key): ?string => $this->typeProvider->getName(ItemTypeProvider::KIND_AUDIENCE_TONE, $key)),
|
||||
new TwigFunction('mt3s_marketing_program_audience_attributes', fn (): array => array_keys(AudienceAttributes::ATTRIBUTES)),
|
||||
new TwigFunction('mt3s_marketing_program_audience_attribute_toggle', fn (string $attribute): string => AudienceAttributes::toggleParameter($attribute)),
|
||||
new TwigFunction('mt3s_marketing_program_audience_segment_counts', fn (iterable $items): array => $this->audienceRepository->getSegmentContactCountsForAudiences(
|
||||
array_map(
|
||||
static fn (Audience $audience): int => $audience->getId(),
|
||||
is_array($items) ? $items : iterator_to_array($items)
|
||||
)
|
||||
)),
|
||||
new TwigFunction('mt3s_marketing_program_audience_segment_count', fn (int $leadlistId): int => $this->audienceRepository->getSegmentContactCount($leadlistId)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The pictogram of an audience type. Accepts the enum itself (what the form's and entity's value
|
||||
* holds) or its backing value ('persona'); null defaults to Persona, the form's default.
|
||||
*/
|
||||
private static function audienceTypeIcon($value): string
|
||||
{
|
||||
if ($value instanceof AudienceType) {
|
||||
return $value->getIcon();
|
||||
}
|
||||
|
||||
try {
|
||||
return AudienceType::from((string) ($value ?? 'persona'))->getIcon();
|
||||
} catch (\ValueError) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plain text as HTML, with the URLs in it (https://… and www.…) turned into links that open in a
|
||||
* new tab. For the description fields of plans and tasks, which stay plain text: typing or pasting
|
||||
* a URL is enough, no editor needed. Everything is escaped here, so no HTML can be injected.
|
||||
*/
|
||||
public static function linkify(?string $text): string
|
||||
{
|
||||
if (null === $text || '' === $text) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// One capture group: preg_split then alternates plain text (even) and URLs (odd).
|
||||
$parts = preg_split('~((?:https?://|(?<![\w.])www\.)[^\s<>"\']+)~i', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$html = '';
|
||||
|
||||
foreach ($parts as $i => $part) {
|
||||
$html .= $i % 2 ? self::urlAnchor($part) : htmlspecialchars($part, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* One URL as a link. Sentence punctuation that follows the URL (".", ")", "!", …) stays outside
|
||||
* the link, and a bare "www." address gets the https:// prefix.
|
||||
*/
|
||||
private static function urlAnchor(string $url): string
|
||||
{
|
||||
$after = '';
|
||||
|
||||
while ('' !== $url && str_contains('.,;:!?', substr($url, -1))) {
|
||||
$after = substr($url, -1).$after;
|
||||
$url = substr($url, 0, -1);
|
||||
}
|
||||
|
||||
// An unbalanced closing parenthesis belongs to the sentence, not the URL.
|
||||
if (str_ends_with($url, ')') && !str_contains($url, '(')) {
|
||||
$after = ')'.$after;
|
||||
$url = substr($url, 0, -1);
|
||||
}
|
||||
|
||||
// Only a prefix is left ("www.", "https://"): not a link after all.
|
||||
if ('' === $url || 'www.' === $url || 'http://' === $url || 'https://' === $url) {
|
||||
return htmlspecialchars($url.$after, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
$href = preg_match('~^https?://~i', $url) ? $url : 'https://'.$url;
|
||||
|
||||
return sprintf(
|
||||
'<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>%s',
|
||||
htmlspecialchars($href, ENT_QUOTES, 'UTF-8'),
|
||||
htmlspecialchars($url, ENT_QUOTES, 'UTF-8'),
|
||||
htmlspecialchars($after, ENT_QUOTES, 'UTF-8')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\ProgramBundle\Twig;
|
||||
|
||||
use MauticPlugin\ProgramBundle\Entity\Audience;
|
||||
use MauticPlugin\ProgramBundle\Entity\AudienceType;
|
||||
use MauticPlugin\ProgramBundle\Entity\AudienceRepository;
|
||||
use MauticPlugin\ProgramBundle\Service\CurrencyProvider;
|
||||
use MauticPlugin\ProgramBundle\Service\ItemTypeProvider;
|
||||
use MauticPlugin\ProgramBundle\Service\AudienceAttributes;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Twig functions for the plan templates (kind: "description", "allocation", "objective" or "task"):
|
||||
* program_item_type_name(kind, key) localized type name, or null for an unknown key
|
||||
* program_item_type_description(kind, key) localized type description ('' when none)
|
||||
* program_item_type_icon(kind, key) the type's pictogram (Remix Icon class), or null
|
||||
* program_currency() the general currency code, e.g. EUR
|
||||
* program_money(amount) an amount with 2 decimals, e.g. 12,500.00
|
||||
* program_audience_channel_label(key) the label key of an audience channel, e.g. "Email"
|
||||
* program_audience_decision_role_label(key) the localized name of a decision role value, or null
|
||||
* program_audience_tone_label(key) the localized name of a tone value, or null
|
||||
* program_audience_attributes() the togglable audience attribute keys, in form order
|
||||
* program_audience_attribute_toggle(key) the local.php parameter name of an attribute's toggle
|
||||
* program_audience_segment_counts(items) contact counts of the segments of the listed audiences,
|
||||
* keyed audience id => (segment id => count)
|
||||
* program_audience_segment_count(segmentId) the contact count of one segment
|
||||
*
|
||||
* Filters:
|
||||
* program_linkify(text) plain text as HTML, with the URLs in it as links opening in a new tab
|
||||
* program_audience_type_icon(value) the pictogram of an AudienceType case value ('persona'…)
|
||||
*/
|
||||
class ProgramExtension extends AbstractExtension
|
||||
{
|
||||
public function __construct(
|
||||
private ItemTypeProvider $typeProvider,
|
||||
private CurrencyProvider $currencyProvider,
|
||||
private AudienceAttributes $audienceAttributes,
|
||||
private AudienceRepository $audienceRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
// The filter escapes everything itself, so its output is safe for templates.
|
||||
new TwigFilter('program_linkify', fn (?string $text): string => self::linkify($text), ['is_safe' => ['html']]),
|
||||
new TwigFilter('program_audience_type_icon', fn ($value): string => self::audienceTypeIcon($value)),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('program_item_type_name', fn (string $kind, ?string $key): ?string => $this->typeProvider->getName($kind, $key)),
|
||||
new TwigFunction('program_item_type_description', fn (string $kind, ?string $key): ?string => $this->typeProvider->getDescription($kind, $key)),
|
||||
new TwigFunction('program_item_type_icon', fn (string $kind, ?string $key): ?string => $this->typeProvider->getIcon($kind, $key)),
|
||||
new TwigFunction('program_currency', fn (): string => $this->currencyProvider->getCurrency()),
|
||||
new TwigFunction('program_money', fn ($amount): string => number_format((float) $amount, 2)),
|
||||
new TwigFunction('program_audience_channel_label', fn (string $key): string => Audience::CHANNELS[$key] ?? $key),
|
||||
new TwigFunction('program_audience_decision_role_label', fn (?string $key): ?string => $this->typeProvider->getName(ItemTypeProvider::KIND_AUDIENCE_DECISION_ROLE, $key)),
|
||||
new TwigFunction('program_audience_tone_label', fn (?string $key): ?string => $this->typeProvider->getName(ItemTypeProvider::KIND_AUDIENCE_TONE, $key)),
|
||||
new TwigFunction('program_audience_attributes', fn (): array => array_keys(AudienceAttributes::ATTRIBUTES)),
|
||||
new TwigFunction('program_audience_attribute_toggle', fn (string $attribute): string => AudienceAttributes::toggleParameter($attribute)),
|
||||
new TwigFunction('program_audience_segment_counts', fn (iterable $items): array => $this->audienceRepository->getSegmentContactCountsForAudiences(
|
||||
array_map(
|
||||
static fn (Audience $audience): int => $audience->getId(),
|
||||
is_array($items) ? $items : iterator_to_array($items)
|
||||
)
|
||||
)),
|
||||
new TwigFunction('program_audience_segment_count', fn (int $leadlistId): int => $this->audienceRepository->getSegmentContactCount($leadlistId)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The pictogram of an audience type. Accepts the enum itself (what the form's and entity's value
|
||||
* holds) or its backing value ('persona'); null defaults to Persona, the form's default.
|
||||
*/
|
||||
private static function audienceTypeIcon($value): string
|
||||
{
|
||||
if ($value instanceof AudienceType) {
|
||||
return $value->getIcon();
|
||||
}
|
||||
|
||||
try {
|
||||
return AudienceType::from((string) ($value ?? 'persona'))->getIcon();
|
||||
} catch (\ValueError) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plain text as HTML, with the URLs in it (https://… and www.…) turned into links that open in a
|
||||
* new tab. For the description fields of plans and tasks, which stay plain text: typing or pasting
|
||||
* a URL is enough, no editor needed. Everything is escaped here, so no HTML can be injected.
|
||||
*/
|
||||
public static function linkify(?string $text): string
|
||||
{
|
||||
if (null === $text || '' === $text) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// One capture group: preg_split then alternates plain text (even) and URLs (odd).
|
||||
$parts = preg_split('~((?:https?://|(?<![\w.])www\.)[^\s<>"\']+)~i', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$html = '';
|
||||
|
||||
foreach ($parts as $i => $part) {
|
||||
$html .= $i % 2 ? self::urlAnchor($part) : htmlspecialchars($part, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* One URL as a link. Sentence punctuation that follows the URL (".", ")", "!", …) stays outside
|
||||
* the link, and a bare "www." address gets the https:// prefix.
|
||||
*/
|
||||
private static function urlAnchor(string $url): string
|
||||
{
|
||||
$after = '';
|
||||
|
||||
while ('' !== $url && str_contains('.,;:!?', substr($url, -1))) {
|
||||
$after = substr($url, -1).$after;
|
||||
$url = substr($url, 0, -1);
|
||||
}
|
||||
|
||||
// An unbalanced closing parenthesis belongs to the sentence, not the URL.
|
||||
if (str_ends_with($url, ')') && !str_contains($url, '(')) {
|
||||
$after = ')'.$after;
|
||||
$url = substr($url, 0, -1);
|
||||
}
|
||||
|
||||
// Only a prefix is left ("www.", "https://"): not a link after all.
|
||||
if ('' === $url || 'www.' === $url || 'http://' === $url || 'https://' === $url) {
|
||||
return htmlspecialchars($url.$after, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
$href = preg_match('~^https?://~i', $url) ? $url : 'https://'.$url;
|
||||
|
||||
return sprintf(
|
||||
'<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>%s',
|
||||
htmlspecialchars($href, ENT_QUOTES, 'UTF-8'),
|
||||
htmlspecialchars($url, ENT_QUOTES, 'UTF-8'),
|
||||
htmlspecialchars($after, ENT_QUOTES, 'UTF-8')
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user