SkypeManager.php in Skype 8
File
src/Manager/SkypeManager.php
View source
<?php
namespace Drupal\skype\Manager;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\path_alias\AliasManagerInterface;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Path\PathMatcherInterface;
use Drupal\Core\Template\Attribute;
class SkypeManager {
protected $config;
protected $currentPath;
protected $aliasManager;
protected $pathMatcher;
public function __construct(ConfigFactoryInterface $config_factory, CurrentPathStack $current_path, AliasManagerInterface $alias_manager, PathMatcherInterface $path_matcher) {
$this->config = $config_factory
->get('skype.settings');
$this->currentPath = $current_path;
$this->aliasManager = $alias_manager;
$this->pathMatcher = $path_matcher;
}
public function loadSkypeChatCanvas() {
$page_match =& drupal_static(__FUNCTION__);
if (!$this->config
->get('enable_chat')) {
return FALSE;
}
if (!isset($page_match)) {
$visibility_path_mode = $this->config
->get('exclude_mode');
$visibility_path_pages = $this->config
->get('exclude_pages');
if (!empty($visibility_path_pages)) {
$pages = mb_strtolower($visibility_path_pages);
$path = $this->currentPath
->getPath();
$path_alias = mb_strtolower($this->aliasManager
->getAliasByPath($path));
$page_match = $this->pathMatcher
->matchPath($path_alias, $pages) || $path != $path_alias && $this->pathMatcher
->matchPath($path, $pages);
$page_match = !($visibility_path_mode xor $page_match);
}
else {
$page_match = TRUE;
}
}
return $page_match;
}
public function getMessageRecipient() {
return $this->config
->get('message_recipient');
}
public function getChatId() {
return $this->config
->get('chat_id');
}
public function getAttributes() {
$attributes = [];
$classes = [
$this->config
->get('initiate_chat'),
];
$initiate_chat = $this->config
->get('initiate_chat');
$button_style = $this->config
->get('button_style');
if ($initiate_chat == 'skype-button') {
array_push($classes, $button_style);
if ($button_style == 'rectangle' || $button_style == 'rounded') {
if ($button_text = $this->config
->get('button_text')) {
$attributes['data-text'] = $button_text;
}
if ($button_color = $this->config
->get('button_color')) {
$attributes['data-color'] = $button_color;
}
if ($this->config
->get('text_only')) {
array_push($classes, 'textonly');
}
}
}
elseif ($initiate_chat == 'skype-chat') {
$attributes['data-can-collapse'] = $this->config
->get('chat_can_collapse') ? 'true' : 'false';
$attributes['data-can-close'] = $this->config
->get('chat_can_close') ? 'true' : 'false';
$attributes['data-can-upload-file'] = $this->config
->get('chat_can_upload_file') ? 'true' : 'false';
$attributes['data-entry-animation'] = $this->config
->get('chat_enable_animation') ? 'true' : 'false';
$attributes['data-show-header'] = $this->config
->get('chat_enable_header') ? 'true' : 'false';
}
$attributes['class'] = $classes;
return new Attribute($attributes);
}
}