34require
'../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/socialnetwork.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/modules/modSocialNetworks.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/infobox.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/fediverseparser.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/boxes/box_fediverse.php';
45$langs->loadLangs(array(
'admin',
'users',
'dict'));
47$action =
GETPOST(
'action',
'aZ09');
53if (!isModEnabled(
'socialnetworks')) {
58$oauthservices = array();
60foreach ($conf->global as $key => $val) {
61 if (!empty($val) && preg_match(
'/^OAUTH_.*_ID$/', $key)) {
62 $key = preg_replace(
'/^OAUTH_/',
'', $key);
63 $key = preg_replace(
'/_ID$/',
'', $key);
64 if (preg_match(
'/^.*-/', $key)) {
65 $name = preg_replace(
'/^.*-/',
'', $key);
67 $name = $langs->trans(
"NoName");
69 $provider = preg_replace(
'/-.*$/',
'', $key);
70 $provider = ucfirst(strtolower($provider));
72 $oauthservices[$key] = $name.
" (".$provider.
")";
80if ($action ==
'add') {
83 if (empty(
GETPOST(
'socialnetwork_name')) || empty(
GETPOST(
'socialnetwork_url'))) {
87 $socialNetworkName =
GETPOST(
'socialnetwork_name',
'alpha');
88 $socialNetworkUrl =
GETPOST(
'socialnetwork_url',
'alpha');
89 if (GETPOSTISSET(
"OAUTH_SERVICE_SOCIAL_NETWORK")) {
90 dolibarr_set_const($db,
"OAUTH_SERVICE_SOCIAL_NETWORK",
GETPOST(
"OAUTH_SERVICE_SOCIAL_NETWORK",
'alphanohtml'),
'chaine', 0,
'', $conf->entity);
94 $paramNames =
GETPOST(
'param_name',
'array');
95 $paramValues =
GETPOST(
'param_value',
'array');
97 $additionalParams = [];
98 if (!empty($paramNames) && is_array($paramNames)) {
99 foreach ($paramNames as $index => $paramName) {
100 if (!empty($paramName) && isset($paramValues[$index])) {
101 $additionalParams[$paramName] = $paramValues[$index];
108 $socialNetworkData = array(
109 'title' => $socialNetworkName,
110 'url' => $socialNetworkUrl
113 $socialNetworkData = array_merge($socialNetworkData, $additionalParams);
115 $boxlabel =
'(SocialNetwoksInformations)';
117 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes_def (file, note)";
118 $sql .=
" VALUES ('box_fediverse.php', '".$db->escape($socialNetworkName).
"')";
120 if (!$db->query($sql)) {
124 $jsonData = json_encode($socialNetworkData);
125 $result =
dolibarr_set_const($db,
"SOCIAL_NETWORKS_DATA_".$socialNetworkName, $jsonData,
'chaine', 0,
'', $conf->entity);
130 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
138if ($action ==
'confirm_delete' &&
GETPOST(
'confirm') ==
'yes') {
140 $key =
GETPOST(
'key',
'alpha');
142 $sqlgetName =
"SELECT note FROM ".MAIN_DB_PREFIX.
"boxes_def WHERE rowid=".((int) $key);
144 $resqName = $db->query($sqlgetName);
146 $objName = $db->fetch_object($resqName);
147 $name = $objName->note;
152 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes";
153 $sql .=
" WHERE entity = ".$conf->entity;
154 $sql .=
" AND box_id = ".((int) $key);
155 $resql1 = $db->query($sql);
157 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def";
158 $sql .=
" WHERE rowid = ".((int) $key);
159 $resql2 = $db->query($sql);
161 if (!$resql1 || !$resql2) {
169 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
178if ($action ==
'updatesocialnetwork') {
181 $name =
GETPOST(
'socialnetwork_name');
182 $url =
GETPOST(
'socialnetwork_url');
183 $paramsKey =
GETPOST(
'paramsKey',
'array');
184 $paramsVal =
GETPOST(
'paramsVal',
'array');
187 $socialNetworkData = json_decode($result,
true);
189 foreach ($paramsKey as $index => $key) {
190 if (empty($key) || empty($paramsVal[$index])) {
195 foreach ($socialNetworkData as $key => $value) {
196 if ($key !=
'title' && $key !=
'url') {
197 unset($socialNetworkData[$key]);
202 $mergedParams = array();
203 foreach ($paramsKey as $index => $key) {
204 if (isset($paramsVal[$index])) {
205 $mergedParams[$key] = $paramsVal[$index];
210 foreach ($mergedParams as $newKey => $newValue) {
211 if (!isset($socialNetworkData[$newKey]) || $socialNetworkData[$newKey] !== $newValue) {
212 $socialNetworkData[$newKey] = $newValue;
216 $newData = json_encode($socialNetworkData);
217 $result =
dolibarr_set_const($db,
"SOCIAL_NETWORKS_DATA_".$name, $newData,
'chaine', 0,
'', $conf->entity);
220 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
228 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?action=editsocialnetwork&token='.
newToken().
'&key='.
$id);
233if ($action ==
'editsocialnetwork' &&
GETPOST(
'confirm') ==
'yes') {
234 $paramKey =
GETPOST(
'paramkey',
'alpha');
235 $key =
GETPOST(
'key',
'alpha');
238 $socialNetworkData = json_decode($result,
true);
240 unset($socialNetworkData[$paramKey]);
241 $newData = json_encode($socialNetworkData);
243 $result =
dolibarr_set_const($db,
"SOCIAL_NETWORKS_DATA_".$name, $newData,
'chaine', 0,
'', $conf->entity);
246 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?action=editsocialnetwork&token='.
newToken().
'&key='.urlencode($key));
260$form =
new Form($db);
262llxHeader(
'', $langs->trans(
"FediverseSetup"),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-dict');
264$head = socialnetwork_prepare_head();
266$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
267print
dol_get_fiche_head($head,
'divers', $langs->trans(
'MenuDict'), -1,
'user', 0, $linkback,
'', 0,
'', 0);
269$title = $langs->trans(
"ConfigImportSocialNetwork");
271print_barre_liste($title,
'', $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', -1,
'',
'tools', 0,
'',
'', -1, 0, 0, 0,
'');
274print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
275print
'<input type="hidden" name="token" value="'.newToken().
'">';
277print
'<div class="div-table-responsive-no-min">';
278print
'<table class="noborder centpercent">';
280print
'<tr class="liste_titre">';
281print
'<td colspan="2">'.$langs->trans(
"NewSocialNetwork").
'</td>';
282print
'<td>'.$langs->trans(
"Example").
'</td>';
285print
'<tr class="oddeven">';
286print
'<td>'.$langs->trans(
"Title").
'</td>';
287print
'<td><input type="text" class="flat minwidth300" name="socialnetwork_name"></td>';
288print
'<td>Mastodon</td>';
291print
'<tr class="oddeven">';
292print
'<td>'.$langs->trans(
'SocialNetworkUrl').
'</td>';
293print
'<td><input type="text" class="flat minwidth300" name="socialnetwork_url"></td>';
294print
'<td>https://mastodon.social/api/v1/accounts/id_user</td>';
296$vartosmtpstype =
'MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING';
299$(document).ready(function() {
300 function toggleOAuthServiceDisplay() {
301 if ($("#radio_oauth").is(":checked")) {
302 $("#oauth_service_div").show();
304 $("#oauth_service_div").hide();
308 toggleOAuthServiceDisplay();
310 $("input[name=\"'.$vartosmtpstype.
'\"]").change(function() {
311 toggleOAuthServiceDisplay();
317print
'<tr><td>'.$langs->trans(
"MAIN_MAIL_SMTPS_AUTH_TYPE").
'</td>';
319print
'<input type="radio" id="radio_oauth" name="'.$vartosmtpstype.
'" value="XOAUTH2"'.(
getDolGlobalString($vartosmtpstype) ==
'XOAUTH2' ?
' checked' :
'').(isModEnabled(
'oauth') ?
'' :
' disabled').
'>';
320print
'<label for="radio_oauth">'.$form->textwithpicto($langs->trans(
"UseOauth"), $langs->trans(
"OauthNotAvailableForAllAndHadToBeCreatedBefore")).
'</label>';
321if (!isModEnabled(
'oauth')) {
322 print
' <a href="'.DOL_URL_ROOT.
'/admin/modules.php?search_keyword=oauth">'.$langs->trans(
"EnableModuleX",
"OAuth").
'</a>';
324 print
' <a href="'.DOL_URL_ROOT.
'/admin/oauth.php">'.$langs->trans(
"SetupModuleX",
" OAuth").
'</a>';
329print
'<tr class="oddeven" id="oauth_service_div" style="display: none;">';
330print
'<td>'.$langs->trans(
"MAIN_MAIL_SMTPS_OAUTH_SERVICE").
'</td>';
333$oauthservicesStringKeys = [];
334foreach ($oauthservices as $key => $value) {
335 $key = (string) $key;
336 $oauthservicesStringKeys[$key] = $value;
340if (!isModEnabled(
'multicompany') || ($user->admin && !$user->entity)) {
341 print $form->selectarray(
'OAUTH_SERVICE_SOCIAL_NETWORK', $oauthservicesStringKeys, (
string) $conf->global->OAUTH_SERVICE_SOCIAL_NETWORK);
344 $text = isset($oauthservicesStringKeys[$selectedKey]) ? $oauthservicesStringKeys[$selectedKey][
'label'] :
'';
346 $text = $langs->trans(
"Undefined");
348 $htmltext = $langs->trans(
"ContactSuperAdminForChange");
349 print $form->textwithpicto($text, $htmltext, 1,
'superadmin');
350 print
'<input type="hidden" name="OAUTH_SERVICE_SOCIAL_NETWORK" value="'.$selectedKey.
'">';
355print
'<tr class="oddeven" id="add_param_row"><td>';
356print $form->textwithpicto($langs->trans(
"Others"), $langs->trans(
"AddMoreParams"));
357print
'</td><td><button type="button" id="addParamButton">'.img_picto($langs->trans(
"AddMoreParams"),
'add',
'pictofixedwidth').
'</button></td>';
358print
'<td>Token : ****<br>Cookie : ****</td>';
361print
'<tr class="oddeven">';
362print
'<td colspan="2">';
363print
'<div id="additionalParams"></div>';
373print $form->buttonsSaveCancel(
"Add",
'');
374print
'<input type="hidden" name="action" value="add">';
375print
'<script type="text/javascript">
376 $(document).ready(function() {
377 function toggleOAuthServiceDisplay() {
378 if ($("#radio_oauth").is(":checked")) {
379 $("#oauth_service_div").show(); // Afficher le sélecteur OAuth
381 $("#oauth_service_div").hide(); // Cacher le sélecteur OAuth
385 function toggleAddParamRow() {
386 if ($("#radio_oauth").is(":checked")) {
387 $("#add_param_row").hide(); // Cacher toute la ligne
389 $("#add_param_row").show(); // Afficher toute la ligne
393 toggleOAuthServiceDisplay();
396 $("input[name=\"'.$vartosmtpstype.
'\"]").change(function() {
397 toggleOAuthServiceDisplay();
401 $("#addParamButton").click(function() {
402 var container = $("#additionalParams");
403 var index = container.children().length;
404 var newParam = $("<div class=\'pair-group\'><input type=\'text\' class=\'flat minwidth300\' name=\'param_name[]\' placeholder=\''.$langs->trans(
"ParamName").
'\' class=\
'flat\' /> <input type=\'text\' class=\'flat minwidth300\' name=\'param_value[]\' placeholder=\''.$langs->trans(
"ParamValue").
'\' class=\
'flat\' /></div>");
405 container.append(newParam);
412print
'<span class="opacitymedium">'.$langs->trans(
'SocialNetworksNote').
'</span>';
414print
'<a href="'.DOL_URL_ROOT.
'/admin/boxes.php?backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'">'.$langs->trans(
'JumpToBoxes').
'</a>';
418if ($action ==
'deletesocialnetwork') {
419 $formconfirm = $form->formconfirm(
420 $_SERVER[
"PHP_SELF"].
'?key='.urlencode(
GETPOST(
'key',
'alpha')),
421 $langs->trans(
'Delete'),
422 $langs->trans(
'ConfirmDeleteSocialNetwork',
GETPOST(
'key',
'alpha')),
431if ($action ==
'editsocialnetwork' &&
GETPOST(
'paramkey',
'alpha')) {
432 $paramKey =
GETPOST(
'paramkey',
'alpha');
433 $name =
GETPOST(
'name',
'alpha');
435 $formconfirm = $form->formconfirm(
436 $_SERVER[
"PHP_SELF"].
'?key='.urlencode(
GETPOST(
'key',
'alpha')).
'¶mkey='.urlencode($paramKey).
'&name='.urlencode($name),
437 $langs->trans(
'Delete'),
438 $langs->trans(
'ConfirmDeleteParamOfSocialNetwork', $paramKey),
446$sql =
"SELECT rowid, file, note FROM ".MAIN_DB_PREFIX.
"boxes_def";
447$sql .=
" WHERE file = 'box_fediverse.php'";
448$sql .=
" ORDER BY note";
450dol_syslog(
"select socialnetworks boxes", LOG_DEBUG);
451$resql = $db->query($sql);
454 $num = $db->num_rows($resql);
457 $obj = $db->fetch_object($resql);
461 $socialNetworkData = json_decode($jsonData,
true);
463 $socialNetworkTitle = $socialNetworkData[
'title'];
464 $socialNetworkUrl = $socialNetworkData[
'url'];
465 $socialNetworkId = $obj->rowid;
468 $path_fediverse = DOL_DATA_ROOT.
'/fediverse/temp/'.$socialNetworkTitle;
472 foreach ($socialNetworkData as $key => $value) {
473 if ($key !==
'title' && $key !==
'url') {
474 $authParams[$key] = $value;
478 $result = $fediverseparser->fetchPosts($socialNetworkUrl, 5, 300, $path_fediverse, $authParams);
481 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
482 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
484 print
'<table class="noborder centpercent">'.
"\n";
486 print
'<tr class="liste_titre">';
487 print
"<td>".$langs->trans(
"SocialNetworks").
" ".($i + 1).
"</td>";
488 print
'<td class="right">';
489 print
'<a class="viewfielda reposition marginleftonly marginrighttonly showInputBtn" href="'.$_SERVER[
"PHP_SELF"].
'?action=editsocialnetwork&token='.
newToken().
'&key='.urlencode($socialNetworkId).
'">'.
img_edit().
'</a>';
490 print
'<a class="deletefielda reposition marginleftonly right" href="'.$_SERVER[
"PHP_SELF"].
'?action=deletesocialnetwork&token='.
newToken().
'&key='.urlencode($socialNetworkId).
'">'.
img_delete().
'</a>';
491 print
'<input type="hidden" name="id" value="'.$socialNetworkId.
'">';
495 print
'<tr class="oddeven">';
496 print
'<td>'.$langs->trans(
"Title").
"</td>";
497 print
'<td><input type="text" class="flat minwidth300" name="socialnetwork_name" value="'.dol_escape_htmltag($socialNetworkTitle).
'" '.($action !=
"editsocialnetwork" ?
'disabled' :
'').
'></td>';
500 print
'<tr class="oddeven">';
501 print
"<td>".$langs->trans(
"URL").
"</td>";
502 print
'<td><input type="text" class="flat minwidth300" name="socialnetwork_url" value="'.dol_escape_htmltag($socialNetworkUrl).
'" '.($action !=
"editsocialnetwork" ?
'disabled' :
'').
'></td>';
505 print
'<tr class="oddeven">';
506 print
"<td>".$langs->trans(
"Status").
"</td>";
508 if ($result > 0 && empty($fediverseparser->error)) {
509 print
'<span class="ok">'.img_picto($langs->trans(
"Online"),
'tick',
'class="pictofixedwidth"').$langs->trans(
"Online").
'</div>';
511 print
'<span class="error">'.$langs->trans(
"Offline");
512 $langs->load(
"errors");
513 if ($fediverseparser->error) {
514 print
' - '.$langs->trans($fediverseparser->error);
522 $active = _isInBoxListFediverse((
int) $socialNetworkId, $boxlist) ?
'yes' :
'no';
524 print
'<tr class="oddeven">';
525 print
'<td>'.$langs->trans(
'WidgetAvailable').
'</td>';
526 print
'<td>'.yn($active);
527 print
' - <a href="'.DOL_URL_ROOT.
'/admin/boxes.php?backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'">';
528 print $langs->trans(
"JumpToBoxes");
533 if ($action ==
'editsocialnetwork' && $socialNetworkId ==
GETPOST(
'key')) {
534 foreach ($socialNetworkData as $k => $val) {
535 if ($k !=
'title' && $k !=
'url') {
536 print
'<tr class="oddeven">';
537 print
'<td><input type="text" class="flat minwidth200" name="paramsKey[]" value="'.dol_escape_htmltag($k).
'"</td>';
538 if ($k ==
'password') {
539 print
'<td><input type="password" class="flat minwidth300" name="paramsVal[]" value="'.dol_escape_htmltag($val).
'" />';
541 print
'<td><input type="text" class="flat minwidth300" name="paramsVal[]" value="'.dol_escape_htmltag($val).
'" />';
543 print
'<button type="button" class="delete-param-btn" data-paramkey="'.htmlspecialchars($k).
'">'.
img_delete().
'</button>';
550 print
'<tr class="oddeven">';
551 print
'<td><input type="hidden" name="action" value="updatesocialnetwork" /></td>';
552 print
'<td><input class="button " type="submit" name="update" value="'.$langs->trans(
'Modify').
'" /></td>';
556 $(document).ready(function() {
557 $(\'.delete-param-btn\').on(\'click\', function() {
558 var paramKey = $(this).data(\'paramkey\');
559 var socialNetworkId = \''.htmlspecialchars($socialNetworkId).
'\';
560 var socialNetworkName = \
''.htmlspecialchars($socialNetworkTitle).
'\';
561 window.location.href = \
''.$_SERVER[
"PHP_SELF"].
'?action=editsocialnetwork&token='.
newToken().
'¶mkey=\' + encodeURIComponent(paramKey) + \'&key=\' + encodeURIComponent(socialNetworkId) + \'&name=\' + encodeURIComponent(socialNetworkName);
567 print
'</table>'.
"\n";
589function _isInBoxListFediverse(
int $id, array $boxlist)
591 foreach ($boxlist as $box) {
592 if ($box->boxcode ===
"lastfediverseinfos") {
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
dolibarr_get_const($db, $name, $entity=1)
Get the value of a setup constant from database.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
static listBoxes($dbs, $mode, $zone, $user=null, $excludelist=array(), $includehidden=1)
Return array of boxes qualified for area and user.
Class to manage Social network posts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.