21include_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
55 public $file_source_url;
82 public $dolistore_api_url;
86 public $dolistore_api_key;
91 public $dolistoreApiStatus;
96 public $dolistoreApiError;
101 public $githubFileStatus;
106 public $githubFileError;
116 public $numberOfProviders;
126 public $numberTotalOfProducts;
131 public $numberTotalOfPages;
136 public $numberOfProducts;
147 $this->debug_api = $debug;
149 $this->url = DOL_URL_ROOT.
'/admin/modules.php?mode=marketplace';
152 $this->dolistore_api_url =
getDolGlobalString(
'MAIN_MODULE_DOLISTORE_API_SRV',
'https://www.dolistore.com/api/');
153 $this->dolistore_api_key =
getDolGlobalString(
'MAIN_MODULE_DOLISTORE_API_KEY',
'dolistorepublicapi');
154 $this->shop_url =
getDolGlobalString(
'MAIN_MODULE_DOLISTORE_SHOP_URL',
'https://www.dolistore.com');
157 $this->file_source_url =
"https://raw.githubusercontent.com/Dolibarr/dolibarr-community-modules/refs/heads/main/index.yaml";
158 $this->cache_file = DOL_DATA_ROOT.
'/admin/temp/remote_github_modules_file.yaml';
160 $lang = $langs->defaultlang;
161 $lang_array = array(
'en_US',
'fr_FR',
'es_ES',
'it_IT',
'de_DE');
162 if (!in_array($lang, $lang_array)) {
178 $cachedelayforgithubrepo =
getDolGlobalInt(
'MAIN_REMOTE_GITHUBREPO_CACHE_DELAY', 86400);
182 $this->githubFileError = $this->error;
183 $this->githubFileStatus =
dol_is_file($this->cache_file) ? 1 : 0;
192 $this->numberOfProviders = $this->dolistoreApiStatus + $this->githubFileStatus;
202 public function callApi($resource, $options =
false)
205 if (empty($this->dolistore_api_key) || empty($this->dolistore_api_url)) {
206 return array(
'status_code' => 0,
'response' =>
null);
213 $httpheader = array(
'DOLAPIKEY: '.$this->dolistore_api_key);
214 if ($basicAuthLogin) {
215 $httpheader[] =
'Authorization: Basic '.base64_encode($basicAuthLogin.
':'.$basicAuthPassword);
218 $url = $this->dolistore_api_url . (preg_match(
'/\/$/', $this->dolistore_api_url) ?
'' :
'/') . $resource;
220 $options[
'apikey'] = $this->dolistore_api_key;
223 $url .=
'?' . http_build_query($options);
226 $response =
getURLContent($url,
'GET',
'', 1, $httpheader, array(
'https'), 0, -1, 5, 5);
228 $status_code = $response[
'http_code'];
231 if ($status_code == 200) {
232 $body = $response[
'content'];
233 $body = json_decode($body,
true);
234 $returnarray = array(
235 'status_code' => $status_code,
239 $returnarray = array(
240 'status_code' => $status_code,
243 if (!empty($response[
'curl_error_no'])) {
244 $returnarray[
'curl_error_no'] = $response[
'curl_error_no'];
246 if (!empty($response[
'curl_error_msg'])) {
247 $returnarray[
'curl_error_msg'] = $response[
'curl_error_msg'];
264 if (!empty($this->cache_file) && file_exists($this->cache_file)) {
265 dol_syslog(__METHOD__ .
" - Loading cache file: " . $this->cache_file, LOG_DEBUG);
267 $content = file_get_contents($this->cache_file);
268 if ($content !==
false) {
269 $modules = $this->
readYaml($content);
271 dol_syslog(__METHOD__ .
" - Error reading cache file", LOG_ERR);
286 $organized_tree = array();
290 'lang' => $this->lang
295 $resCategories = $this->
callApi(
'categories', $data);
296 if (isset($resCategories[
'response']) && is_array($resCategories[
'response'])) {
297 $organized_tree = $resCategories[
'response'];
303 foreach ($organized_tree as $key => $value) {
304 if ($value[
'label'] !=
"Versions" && $value[
'label'] !=
"Specials") {
305 $html .=
'<li' . ($current == $value[
'rowid'] ?
' class="active"' :
'') .
'>';
306 $html .=
'<a href="?mode=marketplace&categorie=' . $value[
'rowid'] .
'">' . $value[
'label'] .
'</a>';
307 if (isset($value[
'children'])) {
309 usort($value[
'children'], $this->
buildSorter(
'position'));
310 foreach ($value[
'children'] as $key_children => $value_children) {
311 $html .=
'<li' . ($current == $value_children[
'rowid'] ?
' class="active"' :
'') .
'>';
312 $html .=
'<a href="?mode=marketplace&categorie=' . $value_children[
'rowid'] .
'" title="' .
dol_escape_htmltag(strip_tags($value_children[
'description'])) .
'">' . $value_children[
'label'] .
'</a>';
333 $langs->load(
"products");
336 $last_month =
dol_now() - (30 * 24 * 60 * 60);
337 $dolibarrversiontouse = DOL_VERSION;
339 $this->products = array();
341 $this->categorie = $options[
'categorie'] ?? 0;
342 $this->per_page = $options[
'per_page'] ?? 11;
343 $this->no_page = $options[
'no_page'] ?? 1;
344 $this->search = $options[
'search'] ??
'';
346 $this->per_page = 11;
349 if (!empty($this->search) && strlen(str_replace(
' ',
'', (
string) $this->search)) < 2) {
350 $html .=
'<tr class=""><td colspan="3" class="center">';
352 $html .= $langs->trans(
"SearchStringMinLength").
'...';
354 $html .=
'</td></tr>';
359 'categorieid' => $this->categorie,
360 'limit' => $this->per_page,
361 'page' => $this->no_page,
362 'search' => $this->search,
363 'lang' => $this->lang
367 $this->numberTotalOfProducts = 0;
370 if ($this->categorie == 87) {
371 $html =
'<div class="shop-container">
372 <div class="shop-image">
373 <a href="https://merch.dolibarr.org/" target="_blank">
374 <img src="https://www.dolistore.com/medias/image/marketplace/img/goodies-shop.jpg" width="50%" alt="DoliStore Merch and Gifts" />
375 <div class="shop-overlay">
376 <button target="new" class="shop-button">'.$langs->trans(
"GoodiesButtonTitle").
' <i class="icon-chevron-right"></i></button>
387 $dolistoreProducts = array();
388 $dolistoreProductsTotal = 0;
389 if ($this->dolistoreApiStatus > 0 &&
getDolGlobalInt(
'MAIN_ENABLE_EXTERNALMODULES_DOLISTORE')) {
390 $getDolistoreProducts = $this->
callApi(
'products', $data);
392 if (!isset($getDolistoreProducts[
'response']) || !is_array($getDolistoreProducts[
'response']) || ($getDolistoreProducts[
'status_code'] != 200 && $getDolistoreProducts[
'status_code'] != 201)) {
393 $dolistoreProducts = array();
394 $dolistoreProductsTotal = 0;
396 $dolistoreProducts = $this->
adaptData($getDolistoreProducts[
'response'][
'products'],
'dolistore');
397 $dolistoreProductsTotal = (int) $getDolistoreProducts[
'response'][
'total'];
398 $this->numberTotalOfProducts += $dolistoreProductsTotal;
404 $fileProducts = array();
405 $fileProductsTotal = 0;
406 if (!empty($this->githubFileStatus) &&
getDolGlobalInt(
'MAIN_ENABLE_EXTERNALMODULES_COMMUNITY')) {
409 $fileProducts = $this->
adaptData($fileProducts,
'githubcommunity');
411 $fileProducts = $this->
applyFilters($fileProducts, $data);
413 $fileProductsTotal = $fileProducts[
'total'];
415 $this->numberTotalOfProducts += $fileProductsTotal;
417 $fileProducts = $fileProducts[
'data'];
421 $this->numberTotalOfPages = (int) ceil(max($fileProductsTotal / $this->per_page, $dolistoreProductsTotal / $this->per_page));
424 $this->products = $dolistoreProducts;
425 foreach ($fileProducts as $fileProduct) {
426 $id = $fileProduct[
'id'];
428 if (empty($this->products[
$id])) {
429 array_unshift($this->products, $fileProduct);
431 $this->products[
$id] = $fileProduct;
432 $this->products[
$id][
'category'] = $fileProduct[
'category'];
435 array_unshift($this->products, $fileProduct);
441 foreach ($this->products as $product) {
446 if ($last_month < strtotime($product[
'datec']) && $product[
"status"] !=
'soon' && $product[
"status"] !=
'development' && $product[
"status"] !=
'experimental') {
447 $newapp .=
'<span class="newApp" title="'.$product[
'tms'].
'">'.$langs->trans(
'New').
'</span> ';
451 if ($newapp ==
'' && $last_month < strtotime($product[
'tms']) && $product[
"status"] !=
'soon' && $product[
"status"] !=
'development' && $product[
"status"] !=
'experimental') {
452 $newapp .=
'<span class="updatedApp" title="'.$product[
'tms'].
'">'.$langs->trans(
'UpdatedRecently').
'</span> ';
456 if ($product[
"cover_photo_url"] !=
'' && $product[
"cover_photo_url"] !=
'#') {
457 $images =
'<a href="'.$product[
"cover_photo_url"].
'" class="documentpreview" target="_blank" rel="noopener noreferrer" mime="image/png" title="'.
dol_escape_htmltag($product[
"label"].
', '.$langs->trans(
'Version').
' '.$product[
"module_version"]).
'">';
458 $images .=
'<img class="imgstore" src="'.$product[
"cover_photo_url"].
'" alt="" /></a>';
460 $images =
'<img class="imgstore" src="'.DOL_URL_ROOT.
'/public/theme/common/nophoto.png" />';
466 if ($product[
"status"] ==
'soon' || $product[
"status"] ==
'development' || $product[
"status"] ==
'experimental') {
467 $version =
'<span class="warning">'.$langs->trans(
"NotYetAvailable").
' - '.$langs->trans(
"StillInDevelopment").
'</span>';
468 $compatible =
'NotCompatible';
469 } elseif ($this->
versionCompare($product[
"dolibarr_min"], $dolibarrversiontouse) <= 0) {
470 if (!empty($product[
"dolibarr_max"]) && $product[
"dolibarr_max"] !=
'auto' && $product[
"dolibarr_max"] !=
'unknown' && $this->
versionCompare($product[
"dolibarr_max"], $dolibarrversiontouse) >= 0) {
472 $version =
'<span class="compatible hideonsmartphone">'.$langs->trans(
474 $dolibarrversiontouse,
475 $product[
"dolibarr_min"],
476 $product[
"dolibarr_max"]
481 $version =
'<span class="warning">'.$langs->trans(
483 $dolibarrversiontouse,
484 $product[
"dolibarr_min"],
485 $product[
"dolibarr_max"]
487 $compatible =
'NotCompatible';
490 if ($product[
"dolibarr_min"] ==
'auto' || $product[
"dolibarr_min"] !=
'unknown') {
492 $version =
'<span class="warning">'.$langs->trans(
494 $dolibarrversiontouse,
495 $product[
"dolibarr_min"],
496 $product[
"dolibarr_max"]
498 $compatible =
'NotCompatible';
501 $version =
'<span class="compatibleafterupdate">'.$langs->trans(
502 'CompatibleAfterUpdate',
503 $dolibarrversiontouse,
504 $product[
"dolibarr_min"],
505 $product[
"dolibarr_max"]
507 $compatible =
'NotCompatible';
513 if (array_key_exists(
'price_ht', $product) &&
price2num($product[
"price_ht"]) > 0) {
514 $price =
'<h3>'.price(
price2num($product[
"price_ht"],
'MT'), 0, $langs, 1, -1, -1,
'EUR').
' '.$langs->trans(
"HT").
'</h3>';
516 $download_link =
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"View").
'" href="'.$this->shop_url.
'/product.php?id='.((int) $product[
'id']).
'">';
517 $download_link .=
img_picto(
'',
'url',
'class="size2x paddingright"');
518 $download_link .=
'</a>';
520 $download_link =
'#';
521 if ($product[
'source'] ===
'dolistore') {
522 $urlview = $this->shop_url.
'/product.php?id='.((int) $product[
"id"]);
523 $price =
'<h3><a href="'.$urlview.
'" target="_blank">'.$langs->trans(
'SeeOnDoliStore').
'</a></h3>';
524 } elseif ($product[
'source'] ===
'githubcommunity') {
525 if (array_key_exists(
'price_ht', $product) && empty($product[
'price_ht'])) {
526 if ($product[
'status'] ==
'soon') {
527 $price =
'<h3>'.$langs->trans(
'StillInDevelopment').
'</h3>';
529 $price =
'<h3>'.$langs->trans(
'Free').
'</h3>';
532 if ($product[
"dolistore-download"]) {
533 $price =
'<h3><a href="'.$product[
"dolistore-download"].
'" target="_blank">'.$langs->trans(
'SeeOnDoliStore').
'</a></h3>';
535 $price =
'<h3>'.$langs->trans(
'Unknown').
'</h3>';
539 $price =
'<h3>'.$langs->trans(
'Unknown').
'</h3>';
542 if ($product[
'source'] ===
'githubcommunity') {
543 $download_link =
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"Sources").
'" href="'.$product[
"link"].
'">';
544 $download_link .=
img_picto(
'',
'file-code',
'class="size2x paddingright colorgrey"');
545 $download_link .=
'</a>';
547 $urlview = $product[
"dolistore-download"];
549 $download_link .=
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"View").
'" href="'.$urlview.
'" rel="noopener noreferrer">';
550 $download_link .=
img_picto(
'',
'url',
'class="size2x"');
551 $download_link .=
'</a>';
554 if (!empty($product[
'direct-download']) && $product[
'direct-download'] ==
'yes') {
556 if (preg_match(
'/https:.*\?id=(\d+)$/', $urlview, $reg)) {
557 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p='.$reg[1];
558 $download_link .=
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"Download").
'" href="'.$urldownload.
'" rel="noopener noreferrer">';
559 $download_link .=
img_picto(
'',
'download',
'class="size2x paddingright"');
560 $download_link .=
'</a>';
563 } elseif ($product[
'source'] ===
'dolistore') {
564 $urlview = $this->shop_url.
'/product.php?id='.((int) $product[
"id"]);
565 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p=' . $product[
'id'];
566 $download_link =
'<a class="paddingleft paddingright valignmiddle" target="_blank" title="'.$langs->trans(
"View").
'" href="'.$urlview.
'">';
567 $download_link .=
img_picto(
'',
'url',
'class="size2x"');
568 $download_link .=
'</a>';
569 $download_link .=
'<a class="paddingleft paddingright" target="_blank" title="'.$langs->trans(
"Download").
'" href="'.$urldownload.
'" rel="noopener noreferrer">';
570 $download_link .=
img_picto(
'',
'download',
'class="size2x paddingright"');
571 $download_link .=
'</a>';
575 if (($product[
'direct-download'] && in_array($product[
'direct-download'], array(
'yes',
'dolistore'))) || $product[
'source'] ===
'dolistore') {
578 if ($product[
'source'] ===
'githubcommunity') {
579 $current_version = $product[
'module_version'] ??
'';
580 $module_name = strtolower(preg_replace(
'/@.*$/',
'', $product[
'ref'] ??
''));
583 $module_name = preg_replace(
'/-' . preg_quote($current_version,
'/') .
'$/',
'', $module_name);
585 $urldownload =
'https://github.com/Dolibarr/dolibarr-community-modules/raw/refs/heads/main/dev/build/bin/module_' . $module_name .
'-' . $current_version .
'.zip';
588 $urlview = $product[
"dolistore-download"];
592 if ($product[
"direct-download"] ==
'dolistore' ||
getDolGlobalString(
"MAIN_DOWNLOAD_FROM_DOLISTORE_IN_PRIORITY")) {
593 if (preg_match(
'/https:.*\?id=(\d+)$/', $urlview, $reg)) {
594 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p='.$reg[1];
598 if ($product[
'source'] ===
'dolistore') {
599 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p=' . $product[
'id'];
603 $disableInstall = ($compatible ===
'NotCompatible') && !
getDolGlobalInt(
'MAIN_FEATURES_LEVEL');
606 $fields = [
'action' =>
'install',
'token' =>
newToken()];
607 foreach ($product as $key => $value) {
608 $fields[
'producttoinstall['.$key.
']'] = $value;
611 $installConfirmMessage = $langs->transnoentities(
612 "extModuleConfirmInstallText",
613 $product[
'label'] ??
'',
614 $product[
'module_version'] ??
'',
615 $product[
'ref'] ??
'',
616 !empty($product[
'tms']) ?
dol_print_date($product[
'tms'],
'%d/%m/%Y') :
''
618 $installConfirmMessage .= $langs->trans(
"Path").
' : '.$urldownload;
620 $install_link =
'<button class="valignmiddle ' . ($disableInstall ?
'butActionRefused' :
'butAction') .
' paddingleft paddingright"'
622 . (!$disableInstall ?
' data-confirm' :
'')
623 . (!$disableInstall ?
' data-fields="' .
dol_escape_htmltag(json_encode($fields)) .
'"' :
'')
625 . (!$disableInstall ?
' data-confirm-title="' .
dol_escape_htmltag($langs->trans(
"extModuleConfirmInstallTitle")) .
'"' :
'')
626 . (!$disableInstall ?
' data-confirm-text="' .
dol_escape_htmltag($installConfirmMessage) .
'"' :
'')
627 .
'>' . $langs->trans(
"Install") .
'</button>';
632 $html .=
'<tr class="'.(getDolOptimizeSmallScreen() ?
'app' :
'app app2').
' oddeven nohover '.
dol_escape_htmltag($compatible).
'">';
635 $html .=
'<td class="center width150"><div class="newAppParent">';
636 $html .= $newapp.$images;
637 $html .=
'</div></td>';
640 $html .=
'<td class="margeCote minwidth400imp"><h2 class="appTitle">';
642 if (!empty($product[
'author']) && $product[
'author'] !=
'unkownauthor') {
643 $html .=
'<span class="small"> - '.img_picto(
'',
'company',
'class="pictofixedwidth"');
644 if (!empty($product[
'author_url'])) {
645 $html .=
'<a href="'.$product[
'author_url'].
'" target="_blank">'.$product[
'author'].
'</a>';
647 $html .= $product[
'author'];
651 $html .=
'<br><span class="small">';
656 $html .=
'<small class="appDateCreation appRef"> ';
657 if (empty($product[
'tms'])) {
658 $html .=
img_picto($langs->trans(
'DateCreation'),
'calendar',
'class="pictofixedwidth"').
'<span class="opacitymedium"><span class="hideonsmartphone">'.$langs->trans(
"DateCreation").
': </span>';
661 $html .=
img_picto($langs->trans(
'DateModification'),
'calendar',
'class="pictofixedwidth"').
'<span class="opacitymedium">'.
dol_print_date(
dol_stringtotime($product[
'tms']),
'day').
'</span>';
663 $html .=
' ';
665 $html .=
'<div class="appSource inline-block valigntop">';
666 if ($product[
"source"] ==
'dolistore') {
667 $html .=
'<img border="0" title="'.dolPrintHTML($langs->trans(
'Source').
": DoliStore").
'" class="imgautosize valignmiddle inline-block pictofixedwidth" style="height: 14px" src="'.DOL_URL_ROOT.
'/theme/dolistore_squarred.svg">';
668 } elseif ($product[
"source"] ==
'githubcommunity') {
669 $html .=
img_picto($langs->trans(
'Source').
': GitHub community repo',
'group',
'class="pictofixedwidth valignmiddle"');
671 $html .=
img_picto($langs->trans(
'Source').
': '.$langs->trans(
'Other'),
'generic',
'class="pictofixedwidth"');
675 $html .= $langs->trans(
'Ref').
' '.
dolPrintHTML(preg_replace(
'/@.*$/',
'', $product[
"ref"]));
676 $html .=
'</small><br>';
680 if (!empty($product[
'phpmin']) && $product[
'phpmin'] !=
'unknown') {
681 $html .=
' <span class="badge-secondary small" style="padding: 3px; border-radius: 5px">PHP min '.$product[
'phpmin'].
'</span>';
683 if (!empty($product[
'phpmax']) && $product[
'phpmax'] !=
'unknown') {
684 $html .=
' <span class="badge-secondary small" style="padding: 3px; border-radius: 5px">PHP max '.$product[
'phpmax'].
'</span>';
689 $html .=
'<div class="storedesc">'.dolPrintHTML(
dol_string_nohtmltag($product[
"description"])).
'</div>';
693 $html .=
'</tr><tr class="app2 oddeven nohover borderbottom '.dol_escape_htmltag($compatible).
'">';
697 $html .=
'<td class="margeCote center amount'.(getDolOptimizeSmallScreen() ?
' left" colspan="2"' :
'"').
'>';
699 if (($product[
'direct-download'] && in_array($product[
'direct-download'], array(
'yes',
'dolistore'))) || ($product[
'source'] ===
'dolistore' && empty((
float) $product[
'price_ht']))) {
701 $html .= $install_link;
707 $html .=
'<td class="margeCote nowraponall">';
711 $html .= $download_link;
717 if (empty($this->products)) {
719 $langs->load(
"website");
721 $html .=
'<tr class=""><td colspan="'.$colspan.
'" class="center">';
723 $html .= $langs->trans(
"noResultsWereFound").
'...';
725 $html .=
'</td></tr>';
732 $(document).on("click","[data-confirm]",function(){
733 var button = $(this);
734 var confirmTitle = button.data("confirm-title");
735 var confirmText = button.data("confirm-text");
737 buttons[button.data("confirm-label")||"' . $confirmLabel .
'"] = function(){
738 var form = $("<form method=\'POST\' style=\'display:none\'>").attr("action", button.data("url"));
739 $.each(button.data("fields"), function(name, value){
740 form.append($("<input type=\'hidden\'>").attr("name", name).val(value));
742 $("body").append(form);
744 $(this).dialog("close");
746 buttons["' . $cancelLabel .
'"] = function(){$(this).dialog("close");};
747 $("<div>").html(confirmText).dialog({
756 $this->numberOfProducts = count($this->products);
775 function (array $a, array $b) use ($key) {
776 $valA = isset($a[$key]) && is_scalar($a[$key]) ? (
string) $a[$key] :
'';
777 $valB = isset($b[$key]) && is_scalar($b[$key]) ? (
string) $b[$key] :
'';
779 return strnatcmp($valA, $valB);
793 $v1 = str_replace(array(
'v',
'V'),
'', $v1);
794 $v2 = str_replace(array(
'v',
'V'),
'', $v2);
796 $v1 = explode(
'.', $v1);
797 $v2 = explode(
'.', $v2);
800 $count1 = count($v1);
801 $count2 = count($v2);
802 $maxcount = max($count1, $count2);
803 while ($level < $maxcount) {
804 $operande1 = isset($v1[$level]) ? $v1[$level] :
'x';
805 $operande2 = isset($v2[$level]) ? $v2[$level] :
'x';
807 if (strtoupper($operande1) ==
'X' || strtoupper($operande2) ==
'X' || $operande1 ==
'*' || $operande2 ==
'*') {
810 if ($operande1 < $operande2) {
814 if ($operande1 > $operande2) {
833 return '<a href="'.$this->get_previous_url().
'" class="button">'.
dol_escape_htmltag($text).
'</a>';
846 return '<a href="'.$this->get_next_url().
'" class="button">'.
dol_escape_htmltag($text).
'</a>';
858 $param_array = array();
859 if ($this->no_page > 1) {
864 if (!empty($this->search)) {
865 $param_array[
'search_keyword'] = $this->search;
867 $param_array[
'no_page'] = $this->no_page - $sub;
868 if ($this->categorie != 0) {
869 $param_array[
'categorie'] = $this->categorie;
871 $param = http_build_query($param_array);
872 return $this->url.
"&".$param;
884 $param_array = array();
885 if ($this->products !==
null && count($this->products) < $this->per_page) {
890 if (!empty($this->search)) {
891 $param_array[
'search_keyword'] = $this->search;
893 $param_array[
'no_page'] = $this->no_page + $add;
894 if ($this->categorie != 0) {
895 $param_array[
'categorie'] = $this->categorie;
897 $param = http_build_query($param_array);
898 return $this->url.
"&".$param;
911 $page = $this->no_page;
912 $limit = $this->per_page;
913 $totalnboflines = $this->numberTotalOfProducts ?: 0;
914 $num = $this->numberOfProducts;
920 if ($page > 0 || $num > $limit) {
921 if ($totalnboflines) {
923 $nbpages = $this->numberTotalOfPages;
930 $pagelist .=
'<li class="pagination paginationpage paginationpageleft"><a class="paginationprevious reposition" href="'.$this->get_previous_url().
'"><i class="fa fa-chevron-left" title="'.
dol_escape_htmltag($langs->trans(
"Previous")).
'"></i></a></li>';
933 $pagelist .=
'<li class="pagination">';
934 $pagelist .=
'<label for="page_input">Page </label>';
935 if ($this->categorie != 0) {
936 $pagelist .=
'<input type="hidden" name="categorie" value="' . $this->categorie .
'">';
938 $pagelist .=
'<input type="text" id="page_input" name="no_page" value="'.($page).
'" min="1" max="'.$nbpages.
'" class="width40 page_input right" oninput="if(this.value > '.$nbpages.
') this.value='.$nbpages.
'">';
939 $pagelist .=
' / '.$nbpages;
940 $pagelist .=
'</li>';
943 if ($page < $nbpages) {
944 $pagelist .=
'<li class="pagination paginationpage paginationpageright"><a class="paginationnext reposition" href="'.$this->get_next_url().
'"><i class="fa fa-chevron-right" title="'.
dol_escape_htmltag($langs->trans(
"Next")).
'"></i></a></li>';
949 if ($limit || $pagelist) {
950 $html .=
'<div class="pagination" style="padding: 7px;">';
973 400 =>
'Bad Request',
974 401 =>
'Unauthorized',
976 405 =>
'Method Not Allowed',
977 500 =>
'Internal Server Error',
981 if ($request[
'status_code'] === 200 || $request[
'status_code'] === 201) {
986 $error_message = $error_messages[$request[
'status_code']] ??
'Unexpected HTTP status: ' . $request[
'status_code'];
989 if (!empty($request[
'response']) && isset($request[
'response'][
'errors']) && is_array($request[
'response'][
'errors'])) {
990 foreach ($request[
'response'][
'errors'] as $error) {
991 $error_message .=
' - (Code ' . $error[
'code'] .
'): ' . $error[
'message'];
995 if (!empty($request[
'curl_error_msg'])) {
996 $error_message .=
' - ' . $request[
'curl_error_msg'];
1000 return sprintf(
'This call to the API failed and returned an HTTP status of %d. That means: %s.', $request[
'status_code'], $error_message);
1013 $cache_file = $this->cache_file;
1014 $cache_folder = dirname($cache_file);
1018 dol_mkdir($cache_folder, DOL_DATA_ROOT);
1021 if (!file_exists($cache_file) || filemtime($cache_file) < (
dol_now() - $cache_time)) {
1023 $addheaders = array();
1024 $result =
getURLContent($file_source_url,
'GET',
'', 1, $addheaders);
1025 if (!empty($result) && $result[
'http_code'] == 200) {
1026 $yaml = $result[
'content'];
1027 $result = file_put_contents($cache_file, $yaml);
1028 if ($result ===
false) {
1029 $this->error =
'Failed to create cache file: ' . $cache_file;
1035 $yaml = file_get_contents($cache_file);
1051 $currentPackage =
null;
1052 $currentSection =
null;
1054 foreach (explode(
"\n", trim($yaml)) as $line) {
1055 $trimmedLine = trim($line);
1058 if ($trimmedLine ===
'' || strpos($trimmedLine,
'#') === 0) {
1064 if (preg_match(
'/^\s*-\s*modulename:\s*["\']?(.*?)["\']?$/', $trimmedLine, $matches)) {
1065 if ($currentPackage !==
null) {
1067 if (!empty($currentPackage[
'status']) && in_array($currentPackage[
'status'], array(
'enabled',
'soon'))) {
1068 $data[] = $currentPackage;
1071 $currentPackage = [
'modulename' => $matches[1]];
1072 $currentSection =
null;
1077 if (!preg_match(
'/^\s*(fr|en|es|it|de):\s*["\']?(.*?)["\']?$/', $trimmedLine)) {
1078 $currentSection =
null;
1082 if (preg_match(
'/^(\w[\w-]*):\s*["\']?(.*?)["\']?$/', $trimmedLine, $matches)) {
1083 if ($currentPackage !==
null) {
1084 if ($currentSection) {
1086 $currentPackage[$currentSection][$matches[1]] = $matches[2] ===
'' ? null : $matches[2];
1089 $currentPackage[$matches[1]] = $matches[2] ===
'' ? null : $matches[2];
1094 if (preg_match(
'/^\s*(label|description):\s*$/', $trimmedLine, $matches)) {
1095 $currentSection = $matches[1];
1096 $currentPackage[$currentSection] = [];
1104 if ($currentPackage !==
null) {
1105 if (!empty($currentPackage[
'status']) && in_array($currentPackage[
'status'], array(
'enabled',
'soon'))) {
1106 $data[] = $currentPackage;
1124 if (!is_array($data) || empty($data) || empty($source)) {
1125 return $adaptedData;
1128 if ($source ===
'githubcommunity') {
1129 foreach ($data as $package) {
1130 if (empty($package[
'modulename'])) {
1137 if (!empty($package[
'dolistore-download']) && preg_match(
'/www\.dolistore\.com\/product\.php\?id=(\d+)/', (
string) $package[
'dolistore-download'], $reg)) {
1143 'ref' => str_replace(
' ',
'', $package[
'modulename'] .
'-' . $package[
'current_version'] .
'@' .
1144 (array_key_exists(
'author', $package) ? $package[
'author'] :
'unkownauthor')),
1145 'label' => !empty($package[
'label'][substr($this->lang, 0, 2)])
1146 ? $package[
'label'][substr($this->lang, 0, 2)]
1147 : (!empty($package[
'label'][
'en']) ? $package[
'label'][
'en'] : $package[
'modulename']),
1148 'description' => !empty($package[
'description'][substr($this->lang, 0, 2)])
1149 ? $package[
'description'][substr($this->lang, 0, 2)]
1150 : (!empty($package[
'description'][
'en']) ? $package[
'description'][
'en'] :
''),
1151 'datec' => (!empty($package[
'created_at']) && is_string($package[
'created_at']))
1152 ?
date(
'Y-m-d H:i:s', strtotime($package[
'created_at']))
1154 'tms' => (!empty($package[
'last_updated_at']) && is_string($package[
'last_updated_at']))
1155 ?
date(
'Y-m-d H:i:s', strtotime($package[
'last_updated_at']))
1157 'author' => array_key_exists(
'author', $package) ? $package[
'author'] :
'',
1158 'author_url' => array_key_exists(
'author_url', $package) ? $package[
'author_url'] :
'',
1159 'dolibarr_min' => !empty($package[
'dolibarrmin'])
1160 ? $package[
'dolibarrmin']
1162 'dolibarr_max' => !empty($package[
'dolibarrmax'])
1163 ? $package[
'dolibarrmax']
1165 'phpmin' => !empty($package[
'phpmin'])
1166 ? $package[
'phpmin']
1168 'phpmax' => !empty($package[
'phpmax'])
1169 ? $package[
'phpmax']
1171 'module_version' => !empty($package[
'current_version'])
1172 ? $package[
'current_version']
1174 'cover_photo_url' => !empty($package[
'cover'])
1177 'category' => (!empty($package[
'category']) && is_string($package[
'category']))
1178 ? explode(
',', str_replace(
' ',
'', (
string) $package[
'category']))
1180 'link' => !empty($package[
'git'])
1183 'source' =>
'githubcommunity',
1184 'status' => !empty($package[
'status']) ? $package[
'status'] :
'',
1185 'direct-download' => !empty($package[
'direct-download'])
1186 ? $package[
'direct-download']
1188 'dolistore-download' => !empty($package[
'dolistore-download'])
1189 ? $package[
'dolistore-download']
1194 if (array_key_exists(
'price', $package) && $package[
'price'] !=
null) {
1195 $adaptedPackage[
'price_ht'] = $package[
'price'];
1198 $adaptedData[] = $adaptedPackage;
1202 if ($source ===
'dolistore') {
1203 foreach ($data as $package) {
1204 $urlphoto = $this->shop_url.$package[
'cover_photo_url'];
1206 if (preg_match(
'/^\/?wrapper\.php\?hashp=/', $package[
'cover_photo_url']) && !preg_match(
'/attachment=/', $package[
'cover_photo_url'])) {
1207 $urlphoto .=
'&attachment=0';
1211 'id' => $package[
'id'],
1212 'ref' => $package[
'ref'],
1213 'label' => $package[
'label'],
1214 'description' => $package[
'description'],
1215 'datec' => $package[
'datec'],
1216 'tms' => $package[
'tms'],
1217 'author' => array_key_exists(
'author', $package) ? $package[
'author'] :
'',
1218 'author_url' => array_key_exists(
'author_url', $package) ? $package[
'author_url'] :
'',
1219 'price_ttc' => $package[
'price_ttc'],
1220 'price_ht' => $package[
'price_ht'],
1221 'dolibarr_min' => $package[
'dolibarr_min'],
1222 'dolibarr_max' => $package[
'dolibarr_max'],
1223 'phpmin' => empty($package[
'phpmin']) ?
'' : $package[
'phpmin'],
1224 'phpmax' => empty($package[
'phpmax']) ?
'' : $package[
'phpmax'],
1225 'module_version' => $package[
'module_version'],
1226 'cover_photo_url' => $urlphoto,
1227 'source' =>
'dolistore',
1228 'status' => empty($package[
'status']) ?
'' : $package[
'status']
1231 $adaptedData[$package[
'id']] = $adaptedPackage;
1235 return $adaptedData;
1247 $filteredData = $list;
1259 static function ($a, $b) {
1260 return strtotime($b[
'datec'] ??
'0') - strtotime($a[
'datec'] ??
'0');
1264 if (!empty($options[
'search'])) {
1265 $filteredData = array_filter(
1274 static function ($package) use ($options) {
1275 return stripos($package[
'label'], $options[
'search']) !==
false || stripos($package[
'description'], $options[
'search']) !==
false;
1280 if (!empty($options[
'categorieid'])) {
1281 $filteredData = array_filter(
1290 static function ($package) use ($options) {
1291 return in_array($options[
'categorieid'], $package[
'category']);
1296 $total = count($filteredData);
1299 $filteredData = array_values($filteredData);
1300 $filteredData = array_slice($filteredData, ($options[
'page'] - 1) * $options[
'limit'], $options[
'limit']);
1302 return [
'total' => $total,
'data' => $filteredData];
1313 $testRequest = $this->
callApi(
'categories');
1315 if (!isset($testRequest[
'response']) || !is_array($testRequest[
'response']) || ($testRequest[
'status_code'] != 200 && $testRequest[
'status_code'] != 201)) {
1331 public function libStatus($status, $mode = 3, $moretext =
'')
1335 $statusType =
'status4';
1337 $statusType =
'status8';
1341 $labelStatusShort = [];
1343 $labelStatus[0] = $langs->transnoentitiesnoconv(
"NotConnected");
1344 $labelStatus[1] = $langs->transnoentitiesnoconv(
"online");
1345 $labelStatusShort[0] = $langs->transnoentitiesnoconv(
"NotConnected");
1346 $labelStatusShort[1] = $langs->transnoentitiesnoconv(
"online");
1348 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'', $statusType, $mode,
'', array(
'badgeParams' => array(
'attr' => array(
'class' =>
'classfortooltip',
'title' => $labelStatusShort[$status].$moretext))));
1363 if (!function_exists(
'curl_init')) {
1364 dol_syslog(__METHOD__ .
': cURL is not available', LOG_ERR);
1369 if (empty($producttoinstall[
'ref'])) {
1370 dol_syslog(__METHOD__ .
': Missing producttoinstall', LOG_ERR);
1374 $current_version = $producttoinstall[
'module_version'] ??
'';
1375 $module_name = strtolower(preg_replace(
'/@.*$/',
'', $producttoinstall[
'ref'] ??
''));
1378 $module_name = preg_replace(
'/-' . preg_quote($current_version,
'/') .
'$/',
'', $module_name);
1380 if (empty($module_name) || empty($current_version) || $current_version ==
'unknown') {
1381 dol_syslog(__METHOD__ .
': Missing or unknown module name/version for product', LOG_ERR);
1386 $tmpdir =
$conf->admin->dir_temp .
'/remotestoredl';
1389 $downloaded =
false;
1390 switch ($producttoinstall[
'source']) {
1392 if ($producttoinstall[
'id'] > 0) {
1393 $source_url =
'https://www.dolistore.com/_service_download.php?t=free&p=' . $producttoinstall[
'id'];
1396 dol_syslog(__METHOD__ .
': Dolistore download failed: ' . $source_url, LOG_ERR);
1400 dol_syslog(__METHOD__ .
': Invalid product ID for Dolistore download: ' . $producttoinstall[
'id'], LOG_ERR);
1404 case 'githubcommunity':
1405 if ($producttoinstall[
'direct-download'] && in_array($producttoinstall[
'direct-download'], array(
'yes',
'dolistore'))) {
1406 $source_url =
'https://github.com/Dolibarr/dolibarr-community-modules/raw/refs/heads/main/dev/build/bin/module_' . $module_name .
'-' . $current_version .
'.zip';
1409 dol_syslog(__METHOD__ .
': GitHub community module download failed: ' . $source_url .
', Try to find a Dolistore link', LOG_WARNING);
1410 if ($producttoinstall[
'id'] > 0) {
1411 $source_url =
'https://www.dolistore.com/_service_download.php?t=free&p=' . $producttoinstall[
'id'];
1414 dol_syslog(__METHOD__ .
': Dolistore download failed: ' . $source_url, LOG_ERR);
1418 dol_syslog(__METHOD__ .
': No direct download available for this GitHub community module', LOG_ERR);
1423 dol_syslog(__METHOD__ .
': No direct download available for this GitHub community module', LOG_ERR);
1428 dol_syslog(__METHOD__ .
': Unsupported source type: ' . $producttoinstall[
'source'], LOG_ERR);
1432 dol_syslog(__METHOD__ .
': Module downloaded successfully to: ' . $downloaded, LOG_DEBUG);
1450 if (!empty($head[
'header'])) {
1451 if (preg_match_all(
'/Content-Disposition:.*filename=["\']?([^"\';\r\n]+)/i', $head[
'header'], $m)) {
1452 $filename = trim(end($m[1]),
" \t\"'");
1457 if (empty($filename)) {
1458 $filename = basename(parse_url($url, PHP_URL_PATH));
1462 if (empty($filename) || !preg_match(
'/^module_[a-z0-9_]+-[0-9]+\.[0-9]+\.[0-9]+\.zip$/i', $filename)) {
1463 dol_syslog(__METHOD__ .
': Cannot determine filename from URL: ' . $url, LOG_ERR);
1469 if (empty($response[
'content']) || (isset($response[
'http_code']) && $response[
'http_code'] !== 200)) {
1471 __METHOD__ .
': Download failed — HTTP ' . ($response[
'http_code'] ??
'unknown') .
' — ' . $url,
1478 $dest_file = $dest_path .
'/' . $filename;
1483 $writtenfile = file_put_contents(
dol_osencode($dest_file), $response[
'content']);
1484 if ($writtenfile ===
false || $writtenfile === 0) {
1485 dol_syslog(__METHOD__ .
': Cannot write file: ' . $dest_file, LOG_ERR);
1490 dol_syslog(__METHOD__ .
': Downloaded successfully to: ' . $dest_file, LOG_DEBUG);
$id
Support class for third parties, contacts, members, users or resources.
__construct($debug=false)
Constructor.
libStatus($status, $mode=3, $moretext='')
Retrieve the status icon.
checkApiStatus()
Check if an Dolistore API is up.
getProducts($options)
Generate HTML for products.
versionCompare($v1, $v2)
version compare
getPagination()
Generate pagination for navigating through pages of products.
get_next_url()
get next url
getRemoteYamlFile($file_source_url, $cache_time)
Get YAML file from remote source and put it into the cache file.
get_previous_link($text='<<')
get previous link
buildSorter(string $key)
Sort an array by a key.
getModuleZIP($producttoinstall=array())
Download a Dolibarr module from a Git repository URL or Dolistore download URL.
getCategories($active=0)
Generate HTML for categories and their children.
applyFilters($list, $options)
Apply filters to the data.
get_next_link($text='> >')
get next link
fetchModulesFromFile($options=array())
Fetch modules from a cache YAML file.
checkStatusCode($request)
Check the status code of the request.
_downloadFile(string $url, string $dest_path)
Download a remote URL to a local file using getURLContent (native Dolibarr).
readYaml($yaml)
Read a YAML string and convert it to an array.
callApi($resource, $options=false)
Test if we can access to remote Dolistore market place.
adaptData($data, $source)
Adapter data fetched from github remote source to the expected format.
loadRemoteSources($debug=false)
loadRemoteSources
get_previous_url()
get previous url
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_now($mode='gmt')
Return date for now.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getDolOptimizeSmallScreen()
Return if render must be optimized for small screen.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0, $otherCurlOptions=array(), $morelogsuffix='')
Function to get a content from an URL (use proxy if proxy defined).
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date