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';
51$langs->loadLangs(array(
'admin',
'users',
'dict'));
53$action =
GETPOST(
'action',
'aZ09');
59if (!isModEnabled(
'socialnetworks')) {
64$oauthservices = array();
66foreach (
$conf->global as $key => $val) {
67 if (!empty($val) && preg_match(
'/^OAUTH_.*_ID$/', $key)) {
68 $key = preg_replace(
'/^OAUTH_/',
'', $key);
69 $key = preg_replace(
'/_ID$/',
'', $key);
70 if (preg_match(
'/^.*-/', $key)) {
71 $name = preg_replace(
'/^.*-/',
'', $key);
73 $name = $langs->trans(
"NoName");
75 $provider = preg_replace(
'/-.*$/',
'', $key);
76 $provider = ucfirst(strtolower($provider));
78 $oauthservices[$key] = $name.
" (".$provider.
")";
86if ($action ==
'add') {
89 if (empty(
GETPOST(
'socialnetwork_name')) || empty(
GETPOST(
'socialnetwork_url'))) {
93 $socialNetworkName =
GETPOST(
'socialnetwork_name',
'alpha');
94 $socialNetworkUrl =
GETPOST(
'socialnetwork_url',
'alpha');
95 if (GETPOSTISSET(
"OAUTH_SERVICE_SOCIAL_NETWORK")) {
100 $paramNames =
GETPOST(
'param_name',
'array');
101 $paramValues =
GETPOST(
'param_value',
'array');
103 $additionalParams = [];
104 if (!empty($paramNames) && is_array($paramNames)) {
105 foreach ($paramNames as $index => $paramName) {
106 if (!empty($paramName) && isset($paramValues[$index])) {
107 $additionalParams[$paramName] = $paramValues[$index];
114 $socialNetworkData = array(
115 'title' => $socialNetworkName,
116 'url' => $socialNetworkUrl
119 $socialNetworkData = array_merge($socialNetworkData, $additionalParams);
121 $boxlabel =
'(SocialNetwoksInformations)';
123 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"boxes_def (file, note)";
124 $sql .=
" VALUES ('box_fediverse.php', '".$db->escape($socialNetworkName).
"')";
126 if (!$db->query($sql)) {
130 $jsonData = json_encode($socialNetworkData);
131 $result =
dolibarr_set_const($db,
"SOCIAL_NETWORKS_DATA_".$socialNetworkName, $jsonData,
'chaine', 0,
'',
$conf->entity);
136 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
144if ($action ==
'confirm_delete' &&
GETPOST(
'confirm') ==
'yes') {
146 $key =
GETPOST(
'key',
'alpha');
148 $sqlgetName =
"SELECT note FROM ".MAIN_DB_PREFIX.
"boxes_def WHERE rowid=".((int) $key);
150 $resqName = $db->query($sqlgetName);
152 $objName = $db->fetch_object($resqName);
153 $name = $objName->note;
158 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes";
159 $sql .=
" WHERE entity = ".$conf->entity;
160 $sql .=
" AND box_id = ".((int) $key);
161 $resql1 = $db->query($sql);
163 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def";
164 $sql .=
" WHERE rowid = ".((int) $key);
165 $resql2 = $db->query($sql);
167 if (!$resql1 || !$resql2) {
175 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
184if ($action ==
'updatesocialnetwork') {
187 $name =
GETPOST(
'socialnetwork_name');
188 $url =
GETPOST(
'socialnetwork_url');
189 $paramsKey =
GETPOST(
'paramsKey',
'array');
190 $paramsVal =
GETPOST(
'paramsVal',
'array');
193 $socialNetworkData = json_decode($result,
true);
195 foreach ($paramsKey as $index => $key) {
196 if (empty($key) || empty($paramsVal[$index])) {
201 foreach ($socialNetworkData as $key => $value) {
202 if ($key !=
'title' && $key !=
'url') {
203 unset($socialNetworkData[$key]);
208 $mergedParams = array();
209 foreach ($paramsKey as $index => $key) {
210 if (isset($paramsVal[$index])) {
211 $mergedParams[$key] = $paramsVal[$index];
216 foreach ($mergedParams as $newKey => $newValue) {
217 if (!isset($socialNetworkData[$newKey]) || $socialNetworkData[$newKey] !== $newValue) {
218 $socialNetworkData[$newKey] = $newValue;
222 $newData = json_encode($socialNetworkData);
226 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
234 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?action=editsocialnetwork&token='.
newToken().
'&key='.
$id);
239if ($action ==
'editsocialnetwork' &&
GETPOST(
'confirm') ==
'yes') {
240 $paramKey =
GETPOST(
'paramkey',
'alpha');
241 $key =
GETPOST(
'key',
'alpha');
244 $socialNetworkData = json_decode($result,
true);
246 unset($socialNetworkData[$paramKey]);
247 $newData = json_encode($socialNetworkData);
252 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?action=editsocialnetwork&token='.
newToken().
'&key='.urlencode($key));
266$form =
new Form($db);
268llxHeader(
'', $langs->trans(
"FediverseSetup"),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-dict');
270$head = socialnetwork_prepare_head();
272$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
273print
dol_get_fiche_head($head,
'divers', $langs->trans(
'MenuDict'), -1,
'user', 0, $linkback,
'', 0,
'', 0);
275$title = $langs->trans(
"ConfigImportSocialNetwork");
277print_barre_liste($title, 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', -1,
'',
'tools', 0,
'',
'', -1, 0, 0, 0,
'');
280print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
281print
'<input type="hidden" name="token" value="'.newToken().
'">';
283print
'<div class="div-table-responsive-no-min">';
284print
'<table class="noborder centpercent">';
286print
'<tr class="liste_titre">';
287print
'<td colspan="2">'.$langs->trans(
"NewSocialNetwork").
'</td>';
288print
'<td>'.$langs->trans(
"Example").
'</td>';
291print
'<tr class="oddeven">';
292print
'<td>'.$langs->trans(
"Title").
'</td>';
293print
'<td><input type="text" class="flat minwidth300" name="socialnetwork_name"></td>';
294print
'<td>Mastodon</td>';
297print
'<tr class="oddeven">';
298print
'<td>'.$langs->trans(
'SocialNetworkUrl').
'</td>';
299print
'<td><input type="text" class="flat minwidth300" name="socialnetwork_url"></td>';
300print
'<td>https://mastodon.social/api/v1/accounts/id_user</td>';
302$vartosmtpstype =
'MAIN_MAIL_SMTPS_AUTH_TYPE_EMAILING';
305$(document).ready(function() {
306 function toggleOAuthServiceDisplay() {
307 if ($("#radio_oauth").is(":checked")) {
308 $("#oauth_service_div").show();
310 $("#oauth_service_div").hide();
314 toggleOAuthServiceDisplay();
316 $("input[name=\"'.$vartosmtpstype.
'\"]").change(function() {
317 toggleOAuthServiceDisplay();
323print
'<tr><td>'.$langs->trans(
"MAIN_MAIL_SMTPS_AUTH_TYPE").
'</td>';
325print
'<input type="radio" id="radio_oauth" name="'.$vartosmtpstype.
'" value="XOAUTH2"'.(
getDolGlobalString($vartosmtpstype) ==
'XOAUTH2' ?
' checked' :
'').(isModEnabled(
'oauth') ?
'' :
' disabled').
'>';
326print
'<label for="radio_oauth">'.$form->textwithpicto($langs->trans(
"UseOauth"), $langs->trans(
"OauthNotAvailableForAllAndHadToBeCreatedBefore")).
'</label>';
327if (!isModEnabled(
'oauth')) {
328 print
' <a href="'.DOL_URL_ROOT.
'/admin/modules.php?search_keyword=oauth">'.$langs->trans(
"EnableModuleX",
"OAuth").
'</a>';
330 print
' <a href="'.DOL_URL_ROOT.
'/admin/oauth.php">'.$langs->trans(
"SetupModuleX",
" OAuth").
'</a>';
335print
'<tr class="oddeven" id="oauth_service_div" style="display: none;">';
336print
'<td>'.$langs->trans(
"MAIN_MAIL_SMTPS_OAUTH_SERVICE").
'</td>';
339$oauthservicesStringKeys = [];
340foreach ($oauthservices as $key => $value) {
341 $key = (string) $key;
342 $oauthservicesStringKeys[$key] = $value;
346if (!isModEnabled(
'multicompany') || ($user->admin && !$user->entity)) {
347 print $form->selectarray(
'OAUTH_SERVICE_SOCIAL_NETWORK', $oauthservicesStringKeys, (
string)
$conf->global->OAUTH_SERVICE_SOCIAL_NETWORK);
350 $text = isset($oauthservicesStringKeys[$selectedKey]) ? $oauthservicesStringKeys[$selectedKey][
'label'] :
'';
352 $text = $langs->trans(
"Undefined");
354 $htmltext = $langs->trans(
"ContactSuperAdminForChange");
355 print $form->textwithpicto($text, $htmltext, 1,
'superadmin');
356 print
'<input type="hidden" name="OAUTH_SERVICE_SOCIAL_NETWORK" value="'.$selectedKey.
'">';
361print
'<tr class="oddeven" id="add_param_row"><td>';
362print $form->textwithpicto($langs->trans(
"Others"), $langs->trans(
"AddMoreParams"));
363print
'</td><td><button type="button" id="addParamButton">'.img_picto($langs->trans(
"AddMoreParams"),
'add',
'pictofixedwidth').
'</button></td>';
364print
'<td>Token : ****<br>Cookie : ****</td>';
367print
'<tr class="oddeven">';
368print
'<td colspan="2">';
369print
'<div id="additionalParams"></div>';
379print $form->buttonsSaveCancel(
"Add",
'');
380print
'<input type="hidden" name="action" value="add">';
381print
'<script type="text/javascript">
382 $(document).ready(function() {
383 function toggleOAuthServiceDisplay() {
384 if ($("#radio_oauth").is(":checked")) {
385 $("#oauth_service_div").show(); // Afficher le sélecteur OAuth
387 $("#oauth_service_div").hide(); // Cacher le sélecteur OAuth
391 function toggleAddParamRow() {
392 if ($("#radio_oauth").is(":checked")) {
393 $("#add_param_row").hide(); // Cacher toute la ligne
395 $("#add_param_row").show(); // Afficher toute la ligne
399 toggleOAuthServiceDisplay();
402 $("input[name=\"'.$vartosmtpstype.
'\"]").change(function() {
403 toggleOAuthServiceDisplay();
407 $("#addParamButton").click(function() {
408 var container = $("#additionalParams");
409 var index = container.children().length;
410 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>");
411 container.append(newParam);
418print
'<span class="opacitymedium">'.$langs->trans(
'SocialNetworksNote').
'</span>';
420print
'<a href="'.DOL_URL_ROOT.
'/admin/boxes.php?backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'">'.$langs->trans(
'JumpToBoxes').
'</a>';
424if ($action ==
'deletesocialnetwork') {
425 $formconfirm = $form->formconfirm(
426 $_SERVER[
"PHP_SELF"].
'?key='.urlencode(
GETPOST(
'key',
'alpha')),
427 $langs->trans(
'Delete'),
428 $langs->trans(
'ConfirmDeleteSocialNetwork',
GETPOST(
'key',
'alpha')),
437if ($action ==
'editsocialnetwork' &&
GETPOST(
'paramkey',
'alpha')) {
438 $paramKey =
GETPOST(
'paramkey',
'alpha');
439 $name =
GETPOST(
'name',
'alpha');
441 $formconfirm = $form->formconfirm(
442 $_SERVER[
"PHP_SELF"].
'?key='.urlencode(
GETPOST(
'key',
'alpha')).
'¶mkey='.urlencode($paramKey).
'&name='.urlencode($name),
443 $langs->trans(
'Delete'),
444 $langs->trans(
'ConfirmDeleteParamOfSocialNetwork', $paramKey),
452$sql =
"SELECT rowid, file, note FROM ".MAIN_DB_PREFIX.
"boxes_def";
453$sql .=
" WHERE file = 'box_fediverse.php'";
454$sql .=
" ORDER BY note";
456dol_syslog(
"select socialnetworks boxes", LOG_DEBUG);
457$resql = $db->query($sql);
460 $num = $db->num_rows($resql);
463 $obj = $db->fetch_object($resql);
467 $socialNetworkData = json_decode($jsonData,
true);
469 $socialNetworkTitle = $socialNetworkData[
'title'];
470 $socialNetworkUrl = $socialNetworkData[
'url'];
471 $socialNetworkId = $obj->rowid;
474 $path_fediverse = DOL_DATA_ROOT.
'/fediverse/temp/'.$socialNetworkTitle;
478 foreach ($socialNetworkData as $key => $value) {
479 if ($key !==
'title' && $key !==
'url') {
480 $authParams[$key] = $value;
484 $result = $fediverseparser->fetchPosts($socialNetworkUrl, 5, 300, $path_fediverse, $authParams);
487 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
488 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
490 print
'<table class="noborder centpercent">'.
"\n";
492 print
'<tr class="liste_titre">';
493 print
"<td>".$langs->trans(
"SocialNetworks").
" ".($i + 1).
"</td>";
494 print
'<td class="right">';
495 print
'<a class="viewfielda reposition marginleftonly marginrighttonly showInputBtn" href="'.$_SERVER[
"PHP_SELF"].
'?action=editsocialnetwork&token='.
newToken().
'&key='.urlencode($socialNetworkId).
'">'.
img_edit().
'</a>';
496 print
'<a class="deletefielda reposition marginleftonly right" href="'.$_SERVER[
"PHP_SELF"].
'?action=deletesocialnetwork&token='.
newToken().
'&key='.urlencode($socialNetworkId).
'">'.
img_delete().
'</a>';
497 print
'<input type="hidden" name="id" value="'.$socialNetworkId.
'">';
501 print
'<tr class="oddeven">';
502 print
'<td>'.$langs->trans(
"Title").
"</td>";
503 print
'<td><input type="text" class="flat minwidth300" name="socialnetwork_name" value="'.dol_escape_htmltag($socialNetworkTitle).
'" '.($action !=
"editsocialnetwork" ?
'disabled' :
'').
'></td>';
506 print
'<tr class="oddeven">';
507 print
"<td>".$langs->trans(
"URL").
"</td>";
508 print
'<td><input type="text" class="flat minwidth300" name="socialnetwork_url" value="'.dol_escape_htmltag($socialNetworkUrl).
'" '.($action !=
"editsocialnetwork" ?
'disabled' :
'').
'></td>';
511 print
'<tr class="oddeven">';
512 print
"<td>".$langs->trans(
"Status").
"</td>";
514 if ($result > 0 && empty($fediverseparser->error)) {
515 print
'<span class="ok">'.img_picto($langs->trans(
"Online"),
'tick',
'class="pictofixedwidth"').$langs->trans(
"Online").
'</div>';
517 print
'<span class="error">'.$langs->trans(
"Offline");
518 $langs->load(
"errors");
519 if ($fediverseparser->error) {
520 print
' - '.$langs->trans($fediverseparser->error);
528 $active = _isInBoxListFediverse((
int) $socialNetworkId, $boxlist) ?
'yes' :
'no';
530 print
'<tr class="oddeven">';
531 print
'<td>'.$langs->trans(
'WidgetAvailable').
'</td>';
532 print
'<td>'.yn($active);
533 print
' - <a href="'.DOL_URL_ROOT.
'/admin/boxes.php?backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'">';
534 print $langs->trans(
"JumpToBoxes");
539 if ($action ==
'editsocialnetwork' && $socialNetworkId ==
GETPOST(
'key')) {
540 foreach ($socialNetworkData as $k => $val) {
541 if ($k !=
'title' && $k !=
'url') {
542 print
'<tr class="oddeven">';
543 print
'<td><input type="text" class="flat minwidth200" name="paramsKey[]" value="'.dol_escape_htmltag($k).
'"</td>';
544 if ($k ==
'password') {
545 print
'<td><input type="password" class="flat minwidth300" name="paramsVal[]" value="'.dol_escape_htmltag($val).
'" />';
547 print
'<td><input type="text" class="flat minwidth300" name="paramsVal[]" value="'.dol_escape_htmltag($val).
'" />';
549 print
'<button type="button" class="delete-param-btn" data-paramkey="'.htmlspecialchars($k).
'">'.
img_delete().
'</button>';
556 print
'<tr class="oddeven">';
557 print
'<td><input type="hidden" name="action" value="updatesocialnetwork" /></td>';
558 print
'<td><input class="button " type="submit" name="update" value="'.$langs->trans(
'Modify').
'" /></td>';
562 $(document).ready(function() {
563 $(\'.delete-param-btn\').on(\'click\', function() {
564 var paramKey = $(this).data(\'paramkey\');
565 var socialNetworkId = \''.htmlspecialchars($socialNetworkId).
'\';
566 var socialNetworkName = \
''.htmlspecialchars($socialNetworkTitle).
'\';
567 window.location.href = \
''.$_SERVER[
"PHP_SELF"].
'?action=editsocialnetwork&token='.
newToken().
'¶mkey=\' + encodeURIComponent(paramKey) + \'&key=\' + encodeURIComponent(socialNetworkId) + \'&name=\' + encodeURIComponent(socialNetworkName);
573 print
'</table>'.
"\n";
595function _isInBoxListFediverse(
int $id, array $boxlist)
597 foreach ($boxlist as $box) {
598 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.