/
commonsocialnetworks.class.php
111 lines (99 loc) · 4.02 KB
/
commonsocialnetworks.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/class/commonsocialnetworks.class.php
* \ingroup core
* \brief File of the superclass of object classes that support socialnetworks
*/
/**
* Superclass for social networks
*/
trait CommonSocialNetworks
{
/**
* @var array array of socialnetworks
*/
public $socialnetworks;
/**
* Show social network part if the module is enabled with hiding functionality
*
* @param array $socialnetworks Array of social networks
* @param int $colspan Colspan
* @return void
*/
public function showSocialNetwork($socialnetworks, $colspan = 4)
{
global $object, $form, $langs;
$nbofnetworks = count($socialnetworks);
$nbactive = 0;
foreach ($socialnetworks as $key => $value) {
if (!empty($object->socialnetworks[$key])) {
$nbactive++;
}
}
if ($nbofnetworks > 1) {
print '<tr><td><br><a class="paddingtop paddingbottom socialnetworklnk onreposition" colspan="'.$colspan.'" id="socialnetworklnk" href="#"></a>';
//print '</td>';
//print '<td'.($colspan ? ' colspan="'.($colspan-1).'"' : '').'>';
//print '<br>';
print ' <a class="paddingtop paddingbottom socialnetworklnk onreposition" href="#"><span class="badge badge-secondary socialnetworklnk">'.$nbactive.'</span></a>';
print '</td>';
print '</tr>';
}
foreach ($socialnetworks as $key => $value) {
if ($value['active'] || $nbofnetworks == 1) {
print '<tr class="soc_network">';
print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
print '<td colspan="3">';
if (!empty($value['icon'])) {
print '<span class="fab '.$value['icon'].' pictofixedwidth"></span>';
}
print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100 maxwidth300 widthcentpercentminusx" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alphanohtml') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key])).'">';
print '</td>';
print '</tr>';
} elseif (!empty($object->socialnetworks[$key])) {
print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
}
}
print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>';
if ($nbofnetworks > 1) {
print '<script nonce="'.getNonce().'" type="text/javascript">
$("document").ready(function() { toogleSocialNetwork(false); });
jQuery(".socialnetworklnk").click(function() {
console.log("Click on link");
toogleSocialNetwork(true);
return false;
});
function toogleSocialNetwork(chgCookieState) {
const lnk = $("#socialnetworklnk");
const items = $(".soc_network");
var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_SOCIALNETWORKS_SHOW=true")) == true;
if (!chgCookieState) cookieState = !cookieState ;
if (cookieState) {
items.hide();
lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("ShowSocialNetworks")).'...");
if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=false; SameSite=Strict"};
} else {
items.show();
lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("HideSocialNetworks")).'...");
if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=true; SameSite=Strict";}
}
}
</script>';
}
}
}