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