Skip to content

Commit

Permalink
Merge pull request #12 from menatwork/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
davidmaack authored Mar 31, 2021
2 parents d79661a + d1f468d commit 8dca5a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 109 deletions.
111 changes: 3 additions & 108 deletions src/Contao/PiwikTrackingTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,38 +54,7 @@ public static function getSettings()
*/
public function findPiwikTemplates($objDC, $blnOneDimension = false)
{
$arrReturn = array();
// Get all templates
$arrTemplates = $this->getTemplateGroup('mod_matomo');
// Get path
foreach ($arrTemplates as $key => $value)
{
// Clean up
$mixPath = $this->getTemplate($value);

// Remove TL_ROOT
$mixPath = str_replace(array(TL_ROOT), '', $mixPath);
// Remove vendor/menatwork/contao-matomotrackingtag-bundle/src/Resources/contao and co from path
if (stripos($mixPath, 'vendor/menatwork/contao-matomotrackingtag-bundle/src/Resources/contao/') !== false)
{
$mixPath = str_replace(array('vendor/menatwork/contao-matomotrackingtag-bundle/src/Resources/contao/', 'templates'), '', $mixPath);
}

$mixPath = explode('/', $mixPath);
array_pop($mixPath);
$mixPath = implode("/", array_filter($mixPath));

if ($blnOneDimension)
{
$arrReturn[$value] = $value;
}
else
{
$arrReturn[$mixPath][$value] = $value;
}
}

return $arrReturn;
return $this->getTemplateGroup('mod_matomo');
}

/**
Expand Down Expand Up @@ -263,7 +232,6 @@ public function generatePage($objPage, $objLayout, \PageRegular $pageRegular)
}

$objSettings = static::$objSettings;
$this->setCurrentTemplate($objSettings->piwikTemplate);

// Check if user/members should not be counted
if (!$objSettings->piwikCountAdmins AND $this->Input->Cookie('BE_USER_AUTH'))
Expand All @@ -279,7 +247,7 @@ public function generatePage($objPage, $objLayout, \PageRegular $pageRegular)
else
{
// Create Piwiki JS
$objTemplate = new \FrontendTemplate($this->strTemplate);
$objTemplate = new \FrontendTemplate($objSettings->piwikTemplate);
$objTemplate->id = $objSettings->piwikSiteID;
$objTemplate->title = $objPage->title;
$objTemplate->url = $objSettings->piwikPath;
Expand Down Expand Up @@ -311,42 +279,12 @@ public function generatePage($objPage, $objLayout, \PageRegular $pageRegular)
$objTemplate->searchWords = '';
}

$GLOBALS[$this->strScriptType][] = $objTemplate->parse();
$GLOBALS[$this->strScriptType][] = $this->replaceInsertTags($objTemplate->parse());
}

return;
}

/**
* Check if we have a valid value and if the template exist.
*
* @param string $strTemplate
*/
protected function setCurrentTemplate($strTemplate)
{
// Load all templates
$arrTemplates = $this->findPiwikTemplates(null, true);

// Check if we have a valid value
if (!empty($strTemplate) && in_array($strTemplate, $arrTemplates))
{
$this->strTemplate = $strTemplate;
return;
}

// Check if we have another in the theme template folder
$arrTemplates = $this->findPiwikTemplates(null, false);

// If we have no value and a theme template use it
if (empty($strTemplate) && key_exists('templates', $arrTemplates))
{
$this->strTemplate = array_shift($arrTemplates['templates']);
return;
}

$this->strTemplate = 'mod_matomo_TrackingTagSynchron';
}

/**
* Check if the address is realy a http or https address and if there is a server with piwik.
*
Expand Down Expand Up @@ -434,49 +372,6 @@ public function validateIP($strRegexp, $varValue, \Widget $objWidget)
return false;
}

/**
* Check the required extensions and files for syncCto
*
* @param string $strContent
* @param string $strTemplate
* @return string
*/
public function checkExtensions($strContent, $strTemplate)
{
if ($strTemplate == 'be_main')
{
if (!is_array($_SESSION["TL_INFO"]))
{
$_SESSION["TL_INFO"] = array();
}

// required extensions
$arrRequiredExtensions = array(
'MultiColumnWizard' => 'multicolumnwizard'
);

// check for required extensions
foreach ($arrRequiredExtensions as $key => $val)
{
$bundles = array_keys(\System::getContainer()->getParameter('kernel.bundles'));

if (!in_array($val, $bundles))
{
$_SESSION["TL_INFO"] = array_merge($_SESSION["TL_INFO"], array($val => 'Please install the required extension <strong>' . $key . '</strong>'));
}
else
{
if (is_array($_SESSION["TL_INFO"]) && key_exists($val, $_SESSION["TL_INFO"]))
{
unset($_SESSION["TL_INFO"][$val]);
}
}
}
}

return $strContent;
}

/**
* Add hint in the backend that AjaxOptOut plugin has to be installed.
*
Expand Down
1 change: 0 additions & 1 deletion src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
$GLOBALS['TL_HOOKS']['addCustomRegexp'][] = array('MenAtWork\\MatomoTrackingTagBundle\\Contao\\PiwikTrackingTag', 'validatePath');
$GLOBALS['TL_HOOKS']['addCustomRegexp'][] = array('MenAtWork\\MatomoTrackingTagBundle\\Contao\\PiwikTrackingTag', 'validateUrl');
$GLOBALS['TL_HOOKS']['addCustomRegexp'][] = array('MenAtWork\\MatomoTrackingTagBundle\\Contao\\PiwikTrackingTag', 'validateIP');
$GLOBALS['TL_HOOKS']['parseBackendTemplate'][] = array('MenAtWork\\MatomoTrackingTagBundle\\Contao\\PiwikTrackingTag', 'checkExtensions');

/**
* Download extensions
Expand Down

0 comments on commit 8dca5a0

Please sign in to comment.