mirror of
https://github.com/Mibew/mibew.git
synced 2025-01-31 13:24:41 +03:00
Make possible to switch tracking for each type of button (also, fix #239)
This commit is contained in:
parent
5e90541918
commit
67439317c4
@ -24,7 +24,9 @@ use Mibew\Asset\Generator\UrlGeneratorInterface as AssetUrlGeneratorInterface;
|
|||||||
use Mibew\EventDispatcher\EventDispatcher;
|
use Mibew\EventDispatcher\EventDispatcher;
|
||||||
use Mibew\EventDispatcher\Events;
|
use Mibew\EventDispatcher\Events;
|
||||||
use Mibew\Routing\Generator\SecureUrlGeneratorInterface as RouteUrlGeneratorInterface;
|
use Mibew\Routing\Generator\SecureUrlGeneratorInterface as RouteUrlGeneratorInterface;
|
||||||
|
use Mibew\Settings;
|
||||||
use Mibew\Style\ChatStyle;
|
use Mibew\Style\ChatStyle;
|
||||||
|
use Mibew\Style\InvitationStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains base button generation functionality.
|
* Contains base button generation functionality.
|
||||||
@ -246,4 +248,54 @@ abstract class AbstractGenerator implements GeneratorInterface
|
|||||||
|
|
||||||
return $fragment;
|
return $fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates HTML markup for Mibew Messenger Widget.
|
||||||
|
*
|
||||||
|
* @return \Canteen\HTML5\Fragment
|
||||||
|
*/
|
||||||
|
protected function getWidgetCode()
|
||||||
|
{
|
||||||
|
$widget_data = array();
|
||||||
|
|
||||||
|
// Get actual invitation style instance
|
||||||
|
$style_name = $this->getOption('invitation_style')
|
||||||
|
? $this->getOption('invitation_style')
|
||||||
|
: InvitationStyle::getCurrentStyle();
|
||||||
|
$style = new InvitationStyle($style_name);
|
||||||
|
|
||||||
|
// URL of file with additional CSS rules for invitation popup
|
||||||
|
$widget_data['inviteStyle'] = $this->generateAssetUrl(
|
||||||
|
$style->getFilesPath() . '/invite.css'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Time between requests to the server in milliseconds
|
||||||
|
$widget_data['requestTimeout'] = Settings::get('updatefrequency_tracking') * 1000;
|
||||||
|
|
||||||
|
// URL for requests
|
||||||
|
$widget_data['requestURL'] = $this->generateUrl('widget_gateway');
|
||||||
|
|
||||||
|
// Locale for invitation
|
||||||
|
$widget_data['locale'] = $this->getOption('locale');
|
||||||
|
|
||||||
|
// Name of the cookie to track user. It is used if third-party cookie
|
||||||
|
// blocked
|
||||||
|
$widget_data['visitorCookieName'] = VISITOR_COOKIE_NAME;
|
||||||
|
|
||||||
|
$markup = HTML5\html('fragment');
|
||||||
|
$markup->addChild(HTML5\html('div#mibew-invitation'));
|
||||||
|
$markup->addChild(
|
||||||
|
HTML5\html('script')->setAttributes(array(
|
||||||
|
'type' => 'text/javascript',
|
||||||
|
'src' => $this->generateAssetUrl('js/compiled/widget.js'),
|
||||||
|
))
|
||||||
|
);
|
||||||
|
$markup->addChild(
|
||||||
|
HTML5\html('script')
|
||||||
|
->setAttribute('type', 'text/javascript')
|
||||||
|
->addChild('Mibew.Widget.init(' . json_encode($widget_data) . ')')
|
||||||
|
);
|
||||||
|
|
||||||
|
return $markup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ namespace Mibew\Button\Generator;
|
|||||||
|
|
||||||
use Canteen\HTML5;
|
use Canteen\HTML5;
|
||||||
use Mibew\Settings;
|
use Mibew\Settings;
|
||||||
use Mibew\Style\InvitationStyle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an Image button.
|
* Generates an Image button.
|
||||||
@ -57,61 +56,11 @@ class ImageGenerator extends TextGenerator
|
|||||||
$button = HTML5\html('fragment');
|
$button = HTML5\html('fragment');
|
||||||
$button->addChild(HTML5\html('comment', 'mibew button'));
|
$button->addChild(HTML5\html('comment', 'mibew button'));
|
||||||
$button->addChild($this->getPopupLink($image));
|
$button->addChild($this->getPopupLink($image));
|
||||||
if (Settings::get('enabletracking')) {
|
if (Settings::get('enabletracking') && !$this->getOption('disable_tracking')) {
|
||||||
$button->addChild($this->getWidgetCode());
|
$button->addChild($this->getWidgetCode());
|
||||||
}
|
}
|
||||||
$button->addChild(HTML5\html('comment', '/ mibew button'));
|
$button->addChild(HTML5\html('comment', '/ mibew button'));
|
||||||
|
|
||||||
return $button;
|
return $button;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates HTML markup for Mibew Messenger Widget.
|
|
||||||
*
|
|
||||||
* @return \Canteen\HTML5\Fragment
|
|
||||||
*/
|
|
||||||
protected function getWidgetCode()
|
|
||||||
{
|
|
||||||
$widget_data = array();
|
|
||||||
|
|
||||||
// Get actual invitation style instance
|
|
||||||
$style_name = $this->getOption('invitation_style')
|
|
||||||
? $this->getOption('invitation_style')
|
|
||||||
: InvitationStyle::getCurrentStyle();
|
|
||||||
$style = new InvitationStyle($style_name);
|
|
||||||
|
|
||||||
// URL of file with additional CSS rules for invitation popup
|
|
||||||
$widget_data['inviteStyle'] = $this->generateAssetUrl(
|
|
||||||
$style->getFilesPath() . '/invite.css'
|
|
||||||
);
|
|
||||||
|
|
||||||
// Time between requests to the server in milliseconds
|
|
||||||
$widget_data['requestTimeout'] = Settings::get('updatefrequency_tracking') * 1000;
|
|
||||||
|
|
||||||
// URL for requests
|
|
||||||
$widget_data['requestURL'] = $this->generateUrl('widget_gateway');
|
|
||||||
|
|
||||||
// Locale for invitation
|
|
||||||
$widget_data['locale'] = $this->getOption('locale');
|
|
||||||
|
|
||||||
// Name of the cookie to track user. It is used if third-party cookie
|
|
||||||
// blocked
|
|
||||||
$widget_data['visitorCookieName'] = VISITOR_COOKIE_NAME;
|
|
||||||
|
|
||||||
$markup = HTML5\html('fragment');
|
|
||||||
$markup->addChild(HTML5\html('div#mibew-invitation'));
|
|
||||||
$markup->addChild(
|
|
||||||
HTML5\html('script')->setAttributes(array(
|
|
||||||
'type' => 'text/javascript',
|
|
||||||
'src' => $this->generateAssetUrl('js/compiled/widget.js'),
|
|
||||||
))
|
|
||||||
);
|
|
||||||
$markup->addChild(
|
|
||||||
HTML5\html('script')
|
|
||||||
->setAttribute('type', 'text/javascript')
|
|
||||||
->addChild('Mibew.Widget.init(' . json_encode($widget_data) . ')')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $markup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
namespace Mibew\Button\Generator;
|
namespace Mibew\Button\Generator;
|
||||||
|
|
||||||
use Canteen\HTML5;
|
use Canteen\HTML5;
|
||||||
|
use Mibew\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an Operator's Code field.
|
* Generates an Operator's Code field.
|
||||||
@ -57,6 +58,9 @@ class OperatorCodeGenerator extends AbstractGenerator
|
|||||||
$button->addChild($form);
|
$button->addChild($form);
|
||||||
$button->addChild($this->getPopup());
|
$button->addChild($this->getPopup());
|
||||||
$button->addChild(HTML5\html('comment', '/ mibew operator code field'));
|
$button->addChild(HTML5\html('comment', '/ mibew operator code field'));
|
||||||
|
if (Settings::get('enabletracking') && !$this->getOption('disable_tracking')) {
|
||||||
|
$button->addChild($this->getWidgetCode());
|
||||||
|
}
|
||||||
|
|
||||||
return $button;
|
return $button;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
namespace Mibew\Button\Generator;
|
namespace Mibew\Button\Generator;
|
||||||
|
|
||||||
use Canteen\HTML5;
|
use Canteen\HTML5;
|
||||||
|
use Mibew\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a Text button.
|
* Generates a Text button.
|
||||||
@ -65,6 +66,9 @@ class TextGenerator extends AbstractGenerator
|
|||||||
$fragment = HTML5\html('fragment');
|
$fragment = HTML5\html('fragment');
|
||||||
$fragment->addChild($link);
|
$fragment->addChild($link);
|
||||||
$fragment->addChild($this->getPopup());
|
$fragment->addChild($this->getPopup());
|
||||||
|
if (Settings::get('enabletracking') && !$this->getOption('disable_tracking')) {
|
||||||
|
$fragment->addChild($this->getWidgetCode());
|
||||||
|
}
|
||||||
|
|
||||||
return $fragment;
|
return $fragment;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,8 @@ class ButtonCodeController extends AbstractController
|
|||||||
$mod_security = $request->query->get('modsecurity') == 'on';
|
$mod_security = $request->query->get('modsecurity') == 'on';
|
||||||
$force_windows = $request->query->get('forcewindows') == 'on';
|
$force_windows = $request->query->get('forcewindows') == 'on';
|
||||||
|
|
||||||
|
$disable_tracking = $request->query->get('disabletracking') == 'on';
|
||||||
|
|
||||||
$code_type = $request->query->get('codetype', 'button');
|
$code_type = $request->query->get('codetype', 'button');
|
||||||
if (!in_array($code_type, array('button', 'operator_code', 'text_link'))) {
|
if (!in_array($code_type, array('button', 'operator_code', 'text_link'))) {
|
||||||
throw new BadRequestException('Wrong value of "codetype" param.');
|
throw new BadRequestException('Wrong value of "codetype" param.');
|
||||||
@ -103,6 +105,8 @@ class ButtonCodeController extends AbstractController
|
|||||||
'force_secure' => $force_secure,
|
'force_secure' => $force_secure,
|
||||||
'mod_security' => $mod_security,
|
'mod_security' => $mod_security,
|
||||||
'prefer_iframe' => !$force_windows,
|
'prefer_iframe' => !$force_windows,
|
||||||
|
'invitation_style' => $invitation_style,
|
||||||
|
'disable_tracking' => $disable_tracking
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($operator_code) {
|
if ($operator_code) {
|
||||||
@ -127,7 +131,6 @@ class ButtonCodeController extends AbstractController
|
|||||||
|
|
||||||
// Set generator-specific options
|
// Set generator-specific options
|
||||||
$button_generator->setOption('image', $image);
|
$button_generator->setOption('image', $image);
|
||||||
$button_generator->setOption('invitation_style', $invitation_style);
|
|
||||||
} else {
|
} else {
|
||||||
// Make sure locale exists
|
// Make sure locale exists
|
||||||
if (!$lang || !in_array($lang, $locales_list)) {
|
if (!$lang || !in_array($lang, $locales_list)) {
|
||||||
@ -172,6 +175,7 @@ class ButtonCodeController extends AbstractController
|
|||||||
$page['formmodsecurity'] = $mod_security;
|
$page['formmodsecurity'] = $mod_security;
|
||||||
$page['formcodetype'] = $code_type;
|
$page['formcodetype'] = $code_type;
|
||||||
$page['formforcewindows'] = $force_windows;
|
$page['formforcewindows'] = $force_windows;
|
||||||
|
$page['formdisabletracking'] = $disable_tracking;
|
||||||
|
|
||||||
$page['enabletracking'] = Settings::get('enabletracking');
|
$page['enabletracking'] = Settings::get('enabletracking');
|
||||||
$page['operator_code'] = $operator_code;
|
$page['operator_code'] = $operator_code;
|
||||||
|
@ -70,8 +70,18 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br clear="all"/>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#if enabletracking}}
|
{{#if enabletracking}}
|
||||||
|
<div class="field-in-row">
|
||||||
|
<label for="disable-tracking" class="field-label">{{l10n "Disable tracking"}}</label>
|
||||||
|
<div class="field-value-no-description">
|
||||||
|
<input id="disable-tracking" type="checkbox" name="disabletracking" value="on"{{#if formdisabletracking}} checked="checked"{{/if}} onchange="this.form.submit();"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{#unless formdisabletracking}}
|
||||||
<div class="field-in-row">
|
<div class="field-in-row">
|
||||||
<label for="invitation-style" class="field-label">{{l10n "Invitation style"}}</label>
|
<label for="invitation-style" class="field-label">{{l10n "Invitation style"}}</label>
|
||||||
<div class="field-value-no-description">
|
<div class="field-value-no-description">
|
||||||
@ -82,8 +92,7 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/unless}}
|
||||||
|
|
||||||
<br clear="all"/>
|
<br clear="all"/>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
@ -70,8 +70,18 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br clear="all"/>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#if enabletracking}}
|
{{#if enabletracking}}
|
||||||
|
<div class="field-in-row">
|
||||||
|
<label for="disable-tracking" class="field-label">{{l10n "Disable tracking"}}</label>
|
||||||
|
<div class="field-value-no-description">
|
||||||
|
<input id="disable-tracking" type="checkbox" name="disabletracking" value="on"{{#if formdisabletracking}} checked="checked"{{/if}} onchange="this.form.submit();"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{#unless formdisabletracking}}
|
||||||
<div class="field-in-row">
|
<div class="field-in-row">
|
||||||
<label for="invitation-style" class="field-label">{{l10n "Invitation style"}}</label>
|
<label for="invitation-style" class="field-label">{{l10n "Invitation style"}}</label>
|
||||||
<div class="field-value-no-description">
|
<div class="field-value-no-description">
|
||||||
@ -82,8 +92,7 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/unless}}
|
||||||
|
|
||||||
<br clear="all"/>
|
<br clear="all"/>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user