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