Initial commit: CloudOps infrastructure platform

This commit is contained in:
root
2026-04-09 19:58:57 +02:00
commit 1166a52f26
7762 changed files with 839452 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Mautic\PageBundle\Helper;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
final class PageConfig implements PageConfigInterface
{
public function __construct(private CoreParametersHelper $coreParametersHelper)
{
}
public function isDraftEnabled(): bool
{
return (bool) $this->coreParametersHelper->get('page_draft_enabled', false);
}
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Mautic\PageBundle\Helper;
interface PageConfigInterface
{
public function isDraftEnabled(): bool;
}

View File

@@ -0,0 +1,115 @@
<?php
namespace Mautic\PageBundle\Helper;
use Doctrine\ORM\EntityManagerInterface;
use Mautic\PageBundle\Entity\Hit;
use Mautic\PageBundle\Entity\Page;
class PointActionHelper
{
public function __construct(private EntityManagerInterface $entityManager)
{
}
public static function validatePageHit($eventDetails, $action): bool
{
$pageHit = $eventDetails->getPage();
if ($pageHit instanceof Page) {
[$parent, $children] = $pageHit->getVariants();
// use the parent (self or configured parent)
$pageHitId = $parent->getId();
} else {
$pageHitId = 0;
}
// If no pages are selected, the pages array does not exist
if (isset($action['properties']['pages'])) {
$limitToPages = $action['properties']['pages'];
}
if (!empty($limitToPages) && !in_array($pageHitId, $limitToPages)) {
// no points change
return false;
}
return true;
}
public function validateUrlHit($eventDetails, $action): bool
{
$changePoints = [];
$url = $eventDetails->getUrl();
$limitToUrl = html_entity_decode(trim($action['properties']['page_url']));
if (!$limitToUrl || !fnmatch($limitToUrl, $url)) {
// no points change
return false;
}
$hitRepository = $this->entityManager->getRepository(Hit::class);
$lead = $eventDetails->getLead();
$urlWithSqlWC = str_replace('*', '%', $limitToUrl);
if (isset($action['properties']['first_time']) && true === $action['properties']['first_time']) {
$hitStats = $hitRepository->getDwellTimesForUrl($urlWithSqlWC, ['leadId' => $lead->getId()]);
if (isset($hitStats['count']) && $hitStats['count']) {
$changePoints['first_time'] = false;
} else {
$changePoints['first_time'] = true;
}
}
$now = new \DateTime();
if ($action['properties']['returns_within'] || $action['properties']['returns_after']) {
// get the latest hit only when it's needed
$latestHit = $hitRepository->getLatestHit(['leadId' => $lead->getId(), $urlWithSqlWC, 'second_to_last' => $eventDetails->getId()]);
} else {
$latestHit = null;
}
if ($action['properties']['accumulative_time']) {
if (!isset($hitStats)) {
$hitStats = $hitRepository->getDwellTimesForUrl($urlWithSqlWC, ['leadId' => $lead->getId()]);
}
if (isset($hitStats['sum'])) {
if ($action['properties']['accumulative_time'] <= $hitStats['sum']) {
$changePoints['accumulative_time'] = true;
} else {
$changePoints['accumulative_time'] = false;
}
} else {
$changePoints['accumulative_time'] = false;
}
}
if ($action['properties']['page_hits']) {
if (!isset($hitStats)) {
$hitStats = $hitRepository->getDwellTimesForUrl($urlWithSqlWC, ['leadId' => $lead->getId()]);
}
if (isset($hitStats['count']) && $hitStats['count'] >= $action['properties']['page_hits']) {
$changePoints['page_hits'] = true;
} else {
$changePoints['page_hits'] = false;
}
}
if ($action['properties']['returns_within']) {
if ($latestHit && $now->getTimestamp() - $latestHit->getTimestamp() <= $action['properties']['returns_within']) {
$changePoints['returns_within'] = true;
} else {
$changePoints['returns_within'] = false;
}
}
if ($action['properties']['returns_after']) {
if ($latestHit && $now->getTimestamp() - $latestHit->getTimestamp() >= $action['properties']['returns_after']) {
$changePoints['returns_after'] = true;
} else {
$changePoints['returns_after'] = false;
}
}
// return true only if all configured options are true
return !in_array(false, $changePoints);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Mautic\PageBundle\Helper;
use Mautic\PageBundle\Model\PageModel;
class TokenHelper
{
public const REGEX = '/{pagelink=(.*?)}/';
public function __construct(
protected PageModel $model,
) {
}
public function findPageTokens($content, $clickthrough = []): array
{
preg_match_all(self::REGEX, $content, $matches);
$tokens = [];
if (!empty($matches[1])) {
foreach ($matches[1] as $key => $pageId) {
$token = $matches[0][$key];
if (!empty($tokens[$token])) {
continue;
}
$page = $this->model->getEntity($pageId);
if (!$page) {
continue;
}
$tokens[$token] = $this->model->generateUrl($page, true, $clickthrough);
}
unset($matches);
}
return $tokens;
}
}

View File

@@ -0,0 +1,133 @@
<?php
namespace Mautic\PageBundle\Helper;
use Mautic\CacheBundle\Cache\CacheProvider;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Mautic\CoreBundle\Helper\Serializer;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Tracker\ContactTracker;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\HttpFoundation\RequestStack;
class TrackingHelper
{
public function __construct(
protected ContactTracker $contactTracker,
protected CacheProvider $cache,
protected CoreParametersHelper $coreParametersHelper,
protected RequestStack $requestStack,
) {
}
/**
* @return array<string, 'facebook_pixel'|'google_analytics'>
*/
public function getEnabledServices(): array
{
$keys = [
'google_analytics' => 'Google Analytics',
'facebook_pixel' => 'Facebook Pixel',
];
$result = [];
foreach ($keys as $key => $service) {
if ($id = $this->coreParametersHelper->get($key.'_id')) {
$result[$service] = $key;
}
}
return $result;
}
/**
* @return string|null
*/
private function getCacheKey()
{
$lead = $this->contactTracker->getContact();
return $lead instanceof Lead ? 'mtc-tracking-pixel-events-'.$lead->getId() : null;
}
/**
* @param mixed[] $values
*
* @throws InvalidArgumentException
*/
public function updateCacheItem(array $values): void
{
$cacheKey = $this->getCacheKey();
if (null !== $cacheKey) {
$item = $this->cache->getItem($cacheKey);
$item->set(serialize(array_merge($values, $this->getCacheItem())));
$item->expiresAfter(86400); // one day in seconds
$this->cache->save($item);
}
}
/**
* @return mixed[]
*
* @throws InvalidArgumentException
*/
public function getCacheItem(bool $remove = false): array
{
$cacheKey = $this->getCacheKey();
$cacheValue = [];
/* @var CacheItemInterface $item */
if (null !== $cacheKey) {
$item = $this->cache->getItem($cacheKey);
if ($item->isHit()) {
$cacheValue = Serializer::decode($item->get(), ['allowed_classes' => false]);
if ($remove) {
$this->cache->deleteItem($cacheKey);
}
}
}
return (array) $cacheValue;
}
/**
* @return bool|mixed
*/
public function displayInitCode($service)
{
$pixelId = $this->coreParametersHelper->get($service.'_id');
if ($pixelId && $this->coreParametersHelper->get($service.'_landingpage_enabled') && $this->isLandingPage()) {
return $pixelId;
}
if ($pixelId && $this->coreParametersHelper->get($service.'_trackingpage_enabled') && !$this->isLandingPage()) {
return $pixelId;
}
return false;
}
/**
* @return Lead|null
*/
public function getLead()
{
return $this->contactTracker->getContact();
}
public function getAnonymizeIp()
{
return $this->coreParametersHelper->get('google_analytics_anonymize_ip');
}
protected function isLandingPage(): bool
{
$server = $this->requestStack->getCurrentRequest()->server;
if (!str_contains((string) $server->get('HTTP_REFERER'), $this->coreParametersHelper->get('site_url'))) {
return false;
}
return true;
}
}