Skip to content

Commit

Permalink
add separate header and footer tracking code inputs (#3882)
Browse files Browse the repository at this point in the history
* add separate header and footer tracking code inputs

* PSR

* Migrate tracking code

* Safer migration of tracking codes


Former-commit-id: 9d75501
Former-commit-id: 746d4461eed6837c287b115dd86eacf96b55fbf9
  • Loading branch information
MrKarlDilkington authored and aembler committed Jun 3, 2016
1 parent b5db692 commit 3211d2b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 75 deletions.
15 changes: 6 additions & 9 deletions concrete/controllers/single_page/dashboard/system/seo/codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ class Codes extends DashboardPageController
{
public function view()
{
$this->set('tracking_code', Config::get('concrete.seo.tracking.code'));
$tracking_code_position = Config::get('concrete.seo.tracking.code_position');
if (!$tracking_code_position) {
$tracking_code_position = 'bottom';
}
$this->set('tracking_code_position', $tracking_code_position);
$this->set('tracking_code_header', Config::get('concrete.seo.tracking.code.header'));
$this->set('tracking_code_footer', Config::get('concrete.seo.tracking.code.footer'));

if ($this->isPost()) {
if ($this->token->validate('update_tracking_code')) {
Config::save('concrete.seo.tracking.code', $this->post('tracking_code'));
Config::save('concrete.seo.tracking.code_position', $this->post('tracking_code_position'));
Config::save('concrete.seo.tracking.code.header', $this->post('tracking_code_header'));
Config::save('concrete.seo.tracking.code.footer', $this->post('tracking_code_footer'));

$pageCache = PageCache::getLibrary();
if (is_object($pageCache)) {
$pageCache->flush();
Expand All @@ -35,7 +32,7 @@ public function saved()
{
$this->set('message', implode(PHP_EOL, array(
t('Tracking code settings updated successfully.'),
t('Cached files removed.'),
t('Cached files removed.')
)));
$this->view();
}
Expand Down
6 changes: 2 additions & 4 deletions concrete/elements/footer_required.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

defined('C5_EXECUTE') or die("Access Denied.");

$c = Page::getCurrentPage();
Expand All @@ -8,9 +7,8 @@
View::element('page_controls_footer', array('cp' => $cp, 'c' => $c));
}

$_trackingCodePosition = Config::get('concrete.seo.tracking.code_position');
if (empty($disableTrackingCode) && (empty($_trackingCodePosition) || $_trackingCodePosition === 'bottom')) {
echo Config::get('concrete.seo.tracking.code');
if (empty($disableTrackingCode)) {
echo Config::get('concrete.seo.tracking.code.footer');
}

View::getInstance()->markFooterAssetPosition();
Expand Down
7 changes: 4 additions & 3 deletions concrete/elements/header_required.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@

$v = View::getInstance();
$v->markHeaderAssetPosition();
$_trackingCodePosition = Config::get('concrete.seo.tracking.code_position');
if (empty($disableTrackingCode) && $_trackingCodePosition === 'top') {
echo Config::get('concrete.seo.tracking.code');

if (empty($disableTrackingCode)) {
echo Config::get('concrete.seo.tracking.code.header');
}

echo $c->getAttribute('header_extra_content');
50 changes: 23 additions & 27 deletions concrete/single_pages/dashboard/system/seo/codes.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<form id="tracking-code-form" action="<?=$view->action('')?>" method="post">
<?=Core::make('helper/validation/token')->output('update_tracking_code')?>

<div class="row">
<div class="col-md-12">
<div class="form-group">
<?=$form->label('tracking_code', t('Tracking Codes'))?>
<div class="input">
<?=$form->textarea('tracking_code', $tracking_code, array('class' => 'xxlarge', 'rows' => 12, 'cols' => 50))?>
<span class="help-block"><?=t('Any HTML you paste here will be inserted at either the bottom or top of every page in your website automatically.')?></span>
</div>
</div>

<div class="form-group">
<div class="radio"><label><?=$form->radio('tracking_code_position', 'top', $tracking_code_position)?> <span><?=t('Header of the page')?></span></label></div>
<div class="radio"><label><?=$form->radio('tracking_code_position', 'bottom', $tracking_code_position)?> <span><?=t('Footer of the page')?></span></label></div>
</div>

<div class="ccm-dashboard-form-actions-wrapper">
<div class="ccm-dashboard-form-actions">
<button type="submit" class="btn btn-primary pull-right" name="tracking-code-form"><?=t('Save')?></button>
</div>
</div>
</div>
</div>
</form>
<?php defined('C5_EXECUTE') or die('Access Denied.'); ?>

<p class="help-block"><?php echo t('Any HTML you paste here will be inserted at either the bottom or top of every page in your website automatically.'); ?></p>

<form id="tracking-code-form" action="<?php echo $view->action(''); ?>" method="post">
<?php echo Core::make('helper/validation/token')->output('update_tracking_code'); ?>

<div class="form-group">
<?php echo $form->label('tracking_code_header', t('Header Tracking Codes')); ?>
<?php echo $form->textarea('tracking_code_header', $tracking_code_header, array('style' => 'height: 250px;')); ?>
</div>

<div class="form-group">
<?php echo $form->label('tracking_code_footer', t('Footer Tracking Codes')); ?>
<?php echo $form->textarea('tracking_code_footer', $tracking_code_footer, array('style' => 'height: 250px;')); ?>
</div>

<div class="ccm-dashboard-form-actions-wrapper">
<div class="ccm-dashboard-form-actions">
<button type="submit" class="btn btn-primary pull-right" name="tracking-code-form"><?php echo t('Save'); ?></button>
</div>
</div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
use Concrete\Core\Page\Page;
use Concrete\Core\Page\Single as SinglePage;
use Concrete\Block\ExpressForm\Controller as ExpressFormBlockController;
use Concrete\Core\Support\Facade\Facade;

class Version20160420000000 extends AbstractMigration
{

protected function renameProblematicTables()
{
if (!$this->connection->tableExists('_AttributeKeys')) {
Expand Down Expand Up @@ -86,7 +86,6 @@ protected function installEntities()
}

$sm->installDatabaseFor($metadatas);

}

protected function importAttributeKeys()
Expand All @@ -96,7 +95,7 @@ protected function importAttributeKeys()
while ($row = $r->fetch()) {
$table = false;
$akCategory = null;
switch($row['akCategoryHandle']) {
switch ($row['akCategoryHandle']) {
case 'collection':
$table = 'CollectionAttributeKeys';
$akCategory = 'pagekey';
Expand Down Expand Up @@ -135,7 +134,7 @@ protected function importAttributeKeys()
}

$this->importAttributeKeyType($row['atID'], $row['akID']);
switch($akCategory) {
switch ($akCategory) {
case 'pagekey':
$rb = $this->connection->executeQuery("select * from _CollectionAttributeValues where akID = ?", array($row['akID']));
while ($rowB = $rb->fetch()) {
Expand All @@ -144,7 +143,7 @@ protected function importAttributeKeys()
$this->connection->insert('CollectionAttributeValues', [
'cID' => $rowB['cID'],
'cvID' => $rowB['cvID'],
'avrID' => $avrID
'avrID' => $avrID,
]);
}
}
Expand All @@ -155,7 +154,7 @@ protected function importAttributeKeys()

protected function loadAttributeValue($atHandle, $legacyAVID, $avID)
{
switch($atHandle) {
switch ($atHandle) {
case 'address':
$row = $this->connection->fetchAssoc('select * from atAddress where avID = ?', [$legacyAVID]);
$row['avID'] = $avID;
Expand Down Expand Up @@ -184,21 +183,21 @@ protected function loadAttributeValue($atHandle, $legacyAVID, $avID)
case 'select':
$this->connection->insert('SelectAttributeValues', array('avID' => $avID));
$options = $this->connection->fetchAll('select * from atSelectOptionsSelected where avID = ?', [$legacyAVID]);
foreach($options as $option) {
foreach ($options as $option) {
$this->connection->insert('SelectAttributeValueSelectedOptions', array(
'avSelectOptionID' => $option['atSelectOptionID'],
'avID' => $avID
'avID' => $avID,
));
}
break;
case 'social_links':
$this->connection->insert('SocialLinksAttributeValues', array('avID' => $avID));
$links = $this->connection->fetchAll('select * from atSocialLinks where avID = ?', [$legacyAVID]);
foreach($links as $link) {
foreach ($links as $link) {
$this->connection->insert('SocialLinksAttributeSelectedLinks', array(
'service' => $link['service'],
'serviceInfo' => $link['serviceInfo'],
'avID' => $avID
'avID' => $avID,
));
}
break;
Expand All @@ -215,10 +214,10 @@ protected function loadAttributeValue($atHandle, $legacyAVID, $avID)
case 'topics':
$this->connection->insert('TopicAttributeValues', array('avID' => $avID));
$topics = $this->connection->fetchAll('select * from atSocialLinks where avID = ?', [$legacyAVID]);
foreach($topics as $topic) {
foreach ($topics as $topic) {
$this->connection->insert('TopicAttributeSelectedTopics', array(
'treeNodeID' => $topic['TopicNodeID'],
'avID' => $avID
'avID' => $avID,
));
}
break;
Expand All @@ -243,7 +242,7 @@ protected function addAttributeValue($atID, $akID, $legacyAVID, $type)
$this->connection->insert('AttributeValues', [
'akID' => $akID,
'avID' => $avID,
'type' => $type
'type' => $type,
]);

return $this->connection->lastInsertId();
Expand All @@ -260,7 +259,7 @@ protected function importAttributeKeyType($atID, $akID)
$this->connection->insert('AttributeKeyTypes', ['akTypeHandle' => $row['atHandle'], 'akID' => $akID, 'type' => $type]);
$akTypeID = $this->connection->lastInsertId();
}
switch($row['atHandle']) {
switch ($row['atHandle']) {
case 'address':
$count = $this->connection->fetchColumn('select count(*) from AddressAttributeKeyTypes where akTypeID = ?', array($akTypeID));
if (!$count) {
Expand Down Expand Up @@ -319,7 +318,7 @@ protected function importAttributeKeyType($atID, $akID)
]);

$options = $this->connection->fetchAll('select * from atSelectOptions where akID = ?', array($akID));
foreach($options as $option) {
foreach ($options as $option) {
$this->connection->insert('SelectAttributeValueOptions', [
'isEndUserAdded' => $option['isEndUserAdded'],
'displayOrder' => $option['displayOrder'],
Expand Down Expand Up @@ -400,20 +399,18 @@ protected function importAttributeTypes()
'url' => 'URL',
);
$categories = array('file', 'user', 'collection');
foreach($types as $handle => $name) {
foreach ($types as $handle => $name) {
$type = Type::getByHandle($handle);
if (!is_object($type)) {
$type = Type::add($handle, $name);
foreach($categories as $category) {
foreach ($categories as $category) {
$cat = Category::getByHandle($category);
$cat->getController()->associateAttributeKeyType($type);
}
}
}
}



protected function addDashboard()
{
$page = Page::getByPath('/dashboard/express');
Expand Down Expand Up @@ -540,13 +537,11 @@ protected function addBlockTypes()
BlockType::installBlockType('express_entry_detail');
}


$bt = BlockType::getByHandle('desktop_waiting_for_me');
if (!is_object($bt)) {
BlockType::installBlockType('desktop_waiting_for_me');
}


$bt = BlockType::getByHandle('page_title');
if (is_object($bt)) {
$bt->refresh();
Expand All @@ -556,22 +551,18 @@ protected function addBlockTypes()
if (is_object($bt)) {
$bt->refresh();
}




}

protected function addTreeNodeTypes()
{
$this->connection->Execute('update TreeNodeTypes set treeNodeTypeHandle = ? where treeNodeTypeHandle = ?', array(
'category', 'topic_category'
'category', 'topic_category',
));
$this->connection->Execute('update PermissionKeys set pkHandle = ? where pkHandle = ?', array(
'view_category_tree_node', 'view_topic_category_tree_node'
'view_category_tree_node', 'view_topic_category_tree_node',
));
$this->connection->Execute('update PermissionKeyCategories set pkCategoryHandle = ? where pkCategoryHandle = ?', array(
'category_tree_node', 'topic_category_tree_node'
'category_tree_node', 'topic_category_tree_node',
));
$results = NodeType::getByHandle('express_entry_results');
if (!is_object($results)) {
Expand Down Expand Up @@ -615,7 +606,6 @@ protected function installDesktops()
$desktop->moveToTrash();
}


$desktop = Page::getByPath('/desktop');
if (is_object($desktop) && !$desktop->isError()) {
$desktop->moveToTrash();
Expand All @@ -631,13 +621,11 @@ protected function installDesktops()

$ci = new ContentImporter();
$ci->importContentFile(DIR_BASE_CORE . '/config/install/base/desktops.xml');


$desktop = Page::getByPath('/dashboard/welcome');
$desktop->movePageDisplayOrderToTop();

\Config::save('concrete.misc.login_redirect', 'DESKTOP');

}

protected function updateWorkflows()
Expand All @@ -652,6 +640,28 @@ protected function updateWorkflows()
}
}

protected function splittedTrackingCode()
{
$config = Facade::getFacadeApplication()->make('config');
$tracking = (array) $config->get('concrete.seo.tracking', []);
$trackingCode = array_get($tracking, 'code');
if (!is_array($trackingCode)) {
array_set($tracking, 'code', ['header' => '', 'footer' => '']);
$trackingCode = (string) $trackingCode;
switch (array_get($tracking, 'code_position')) {
case 'top':
array_set($tracking, 'code.header', $trackingCode);
break;
case 'bottom':
default:
array_set($tracking, 'code.footer', $trackingCode);
break;
}
}
unset($tracking['code_position']);
$config->save('concrete.seo.tracking', $tracking);
}

public function up(Schema $schema)
{
$this->connection->Execute('set foreign_key_checks = 0');
Expand All @@ -665,8 +675,8 @@ public function up(Schema $schema)
$this->updateWorkflows();
$this->addTreeNodeTypes();
$this->installDesktops();
$this->splittedTrackingCode();
$this->connection->Execute('set foreign_key_checks = 1');

}

public function down(Schema $schema)
Expand Down

0 comments on commit 3211d2b

Please sign in to comment.