dolibarr 22.0.5
commonsocialnetworks.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
30{
34 public $socialnetworks;
35
36
44 public function showSocialNetwork($socialnetworks, $colspan = 4)
45 {
46 global $object, $form, $langs;
47
48 '@phan-var-force CommonSocialNetworks $object';
49
50 $nbofnetworks = count($socialnetworks);
51 $nbactive = 0;
52 foreach ($socialnetworks as $key => $value) {
53 if (!empty($object->socialnetworks[$key])) {
54 $nbactive++;
55 }
56 }
57
58 if ($nbofnetworks > 1) {
59 print '<tr><td colspan="'.$colspan.'"><br><a class="paddingtop paddingbottom socialnetworklnk onreposition" id="socialnetworklnk" href="#"></a>';
60 //print '</td>';
61 //print '<td'.($colspan ? ' colspan="'.($colspan-1).'"' : '').'>';
62 //print '<br>';
63 print ' <a class="paddingtop paddingbottom socialnetworklnk onreposition" href="#"><span class="badge badge-secondary socialnetworklnk">'.$nbactive.'</span></a>';
64 print '</td>';
65 print '</tr>';
66 }
67 foreach ($socialnetworks as $key => $value) {
68 if ($value['active'] || $nbofnetworks == 1) {
69 print '<tr class="soc_network">';
70 print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
71 print '<td colspan="3">';
72 if (!empty($value['icon'])) {
73 print '<span class="fab '.$value['icon'].' pictofixedwidth"></span>';
74 }
75 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])).'">';
76 print '</td>';
77 print '</tr>';
78 } elseif (!empty($object->socialnetworks[$key])) {
79 print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
80 }
81 }
82
83 if ($nbofnetworks > 1) {
84 print '<script nonce="'.getNonce().'" type="text/javascript">
85 $("document").ready(function() { toogleSocialNetwork(false); });
86
87 jQuery(".socialnetworklnk").click(function() {
88 console.log("Click on link");
89 toogleSocialNetwork(true);
90 return false;
91 });
92
93 function toogleSocialNetwork(chgCookieState) {
94 const lnk = $("#socialnetworklnk");
95 const items = $(".soc_network");
96 var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_SOCIALNETWORKS_SHOW=true")) == true;
97
98 if (!chgCookieState) cookieState = !cookieState ;
99
100 if (cookieState) {
101 items.hide();
102 lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("ShowSocialNetworks")).'...");
103 if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=false; SameSite=Strict"};
104 } else {
105 items.show();
106 lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("HideSocialNetworks")).'...");
107 if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=true; SameSite=Strict";}
108 }
109 }
110 </script>';
111 }
112 }
113}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
showSocialNetwork($socialnetworks, $colspan=4)
Show social network part if the module is enabled with hiding functionality.
trait CommonSocialNetworks
Superclass for social networks.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...