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 = $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" />';
464 if (array_key_exists(
'price_ht', $product) &&
price2num($product[
"price_ht"]) > 0) {
465 $price =
'<h3>'.price(
price2num($product[
"price_ht"],
'MT'), 0, $langs, 1, -1, -1,
'EUR').
' '.$langs->trans(
"HT").
'</h3>';
467 $download_link =
'<a class="paddingleft paddingright" target="_blank" title="'.$langs->trans(
"View").
'" href="'.$this->shop_url.
'/product.php?id='.((int) $product[
'id']).
'">';
468 $download_link .=
img_picto(
'',
'url',
'class="size2x paddingright"');
469 $download_link .=
'</a>';
471 $download_link =
'#';
472 if ($product[
'source'] ===
'dolistore') {
473 $urlview = $this->shop_url.
'/product.php?id='.((int) $product[
"id"]);
474 $price =
'<h3><a href="'.$urlview.
'" target="_blank">'.$langs->trans(
'SeeOnDoliStore').
'</a></h3>';
475 } elseif ($product[
'source'] ===
'githubcommunity') {
476 if (array_key_exists(
'price_ht', $product) && empty($product[
'price_ht'])) {
477 if ($product[
'status'] ==
'soon') {
478 $price =
'<h3>'.$langs->trans(
'StillInDevelopment').
'</h3>';
480 $price =
'<h3>'.$langs->trans(
'Free').
'</h3>';
483 if ($product[
"dolistore-download"]) {
484 $price =
'<h3><a href="'.$product[
"dolistore-download"].
'" target="_blank">'.$langs->trans(
'SeeOnDoliStore').
'</a></h3>';
486 $price =
'<h3>'.$langs->trans(
'Unknown').
'</h3>';
490 $price =
'<h3>'.$langs->trans(
'Unknown').
'</h3>';
493 if ($product[
'source'] ===
'githubcommunity') {
494 $download_link =
'<a class="paddingleft paddingright" target="_blank" title="'.$langs->trans(
"Sources").
'" href="'.$product[
"link"].
'">';
495 $download_link .=
img_picto(
'',
'file-code',
'class="size2x paddingright colorgrey"');
496 $download_link .=
'</a>';
498 $urlview = $product[
"dolistore-download"];
500 $download_link .=
'<a class="paddingleft paddingright" target="_blank" title="'.$langs->trans(
"View").
'" href="'.$urlview.
'" rel="noopener noreferrer">';
501 $download_link .=
img_picto(
'',
'url',
'class="size2x"');
502 $download_link .=
'</a>';
505 if (!empty($product[
'direct-download']) && $product[
'direct-download'] ==
'yes') {
507 if (preg_match(
'/https:.*\?id=(\d+)$/', $urlview, $reg)) {
508 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p='.$reg[1];
509 $download_link .=
'<a class="paddingleft paddingright" target="_blank" title="'.$langs->trans(
"Download").
'" href="'.$urldownload.
'" rel="noopener noreferrer">';
510 $download_link .=
img_picto(
'',
'download',
'class="size2x paddingright"');
512 $download_link .=
'</a>';
515 } elseif ($product[
'source'] ===
'dolistore') {
516 $urlview = $this->shop_url.
'/product.php?id='.((int) $product[
"id"]);
517 $urldownload =
'https://www.dolistore.com/_service_download.php?t=free&p=' . $product[
'id'];
518 $download_link =
'<a class="paddingleft paddingright" target="_blank" title="'.$langs->trans(
"View").
'" href="'.$urlview.
'">';
519 $download_link .=
img_picto(
'',
'url',
'class="size2x"');
520 $download_link .=
'</a>';
521 $download_link .=
'<a class="paddingleft paddingright" target="_blank" title="'.$langs->trans(
"Download").
'" href="'.$urldownload.
'" rel="noopener noreferrer">';
522 $download_link .=
img_picto(
'',
'download',
'class="size2x paddingright"');
524 $download_link .=
'</a>';
531 if ($product[
"status"] ==
'soon' || $product[
"status"] ==
'development' || $product[
"status"] ==
'experimental') {
532 $version =
'<span class="warning">'.$langs->trans(
"NotYetAvailable").
' - '.$langs->trans(
"StillInDevelopment").
'</span>';
533 $compatible =
'NotCompatible';
534 } elseif ($this->
versionCompare($product[
"dolibarr_min"], $dolibarrversiontouse) <= 0) {
535 if (!empty($product[
"dolibarr_max"]) && $product[
"dolibarr_max"] !=
'auto' && $product[
"dolibarr_max"] !=
'unknown' && $this->
versionCompare($product[
"dolibarr_max"], $dolibarrversiontouse) >= 0) {
537 $version =
'<span class="compatible hideonsmartphone">'.$langs->trans(
539 $dolibarrversiontouse,
540 $product[
"dolibarr_min"],
541 $product[
"dolibarr_max"]
546 $version =
'<span class="warning">'.$langs->trans(
548 $dolibarrversiontouse,
549 $product[
"dolibarr_min"],
550 $product[
"dolibarr_max"]
552 $compatible =
'NotCompatible';
555 if ($product[
"dolibarr_min"] ==
'auto' || $product[
"dolibarr_min"] !=
'unknown') {
557 $version =
'<span class="warning">'.$langs->trans(
559 $dolibarrversiontouse,
560 $product[
"dolibarr_min"],
561 $product[
"dolibarr_max"]
563 $compatible =
'NotCompatible';
566 $version =
'<span class="compatibleafterupdate">'.$langs->trans(
567 'CompatibleAfterUpdate',
568 $dolibarrversiontouse,
569 $product[
"dolibarr_min"],
570 $product[
"dolibarr_max"]
572 $compatible =
'NotCompatible';
577 $html .=
'<tr class="'.(getDolOptimizeSmallScreen() ?
'app' :
'app app2').
' oddeven nohover '.
dol_escape_htmltag($compatible).
'">';
580 $html .=
'<td class="center width150"><div class="newAppParent">';
581 $html .= $newapp.$images;
582 $html .=
'</div></td>';
585 $html .=
'<td class="margeCote minwidth500imp"><h2 class="appTitle">';
587 if (!empty($product[
'author']) && $product[
'author'] !=
'unkownauthor') {
588 $html .=
'<span class="small"> - '.img_picto(
'',
'company',
'class="pictofixedwidth"');
589 if (!empty($product[
'author_url'])) {
590 $html .=
'<a href="'.$product[
'author_url'].
'" target="_blank">'.$product[
'author'].
'</a>';
592 $html .= $product[
'author'];
596 $html .=
'<br><span class="small">';
601 $html .=
'<small class="appDateCreation appRef"> ';
602 if (empty($product[
'tms'])) {
603 $html .=
img_picto($langs->trans(
'DateCreation'),
'calendar',
'class="pictofixedwidth"').
'<span class="opacitymedium"><span class="hideonsmartphone">'.$langs->trans(
"DateCreation").
': </span>';
606 $html .=
img_picto($langs->trans(
'DateModification'),
'calendar',
'class="pictofixedwidth"').
'<span class="opacitymedium">'.
dol_print_date(
dol_stringtotime($product[
'tms']),
'day').
'</span>';
608 $html .=
' '.$langs->trans(
'Ref').
' '.
dolPrintHTML(preg_replace(
'/@.*$/',
'', $product[
"ref"]));
610 $html .=
'</small><br>';
612 $html .=
'<div class="appSource valignmiddle inline-block">';
613 if ($product[
"source"] ==
'dolistore') {
615 $html .=
'<img border="0" title="'.dolPrintHTML($langs->trans(
'Source').
": DoliStore").
'" class="imgautosize imgmaxwidth100 valignmiddle" style="height: 14px" src="'.DOL_URL_ROOT.
'/theme/dolistore_squarred.svg">';
616 } elseif ($product[
"source"] ==
'githubcommunity') {
617 $html .=
img_picto($langs->trans(
'Source').
': GitHub community repo',
'group',
'class="pictofixedwidth valignmiddle"');
619 $html .=
img_picto($langs->trans(
'Source').
': '.$langs->trans(
'Other'),
'generic',
'class="pictofixedwidth"');
622 $html .=
'</div> ';
623 if (!empty($product[
'phpmin']) && $product[
'phpmin'] !=
'unknown') {
624 $html .=
' <span class="badge-secondary small" style="padding: 3px; border-radius: 5px">PHP min '.$product[
'phpmin'].
'</span>';
626 if (!empty($product[
'phpmax']) && $product[
'phpmax'] !=
'unknown') {
627 $html .=
' <span class="badge-secondary small" style="padding: 3px; border-radius: 5px">PHP max '.$product[
'phpmax'].
'</span>';
632 $html .=
'<div class="storedesc">'.dolPrintHTML(
dol_string_nohtmltag($product[
"description"])).
'</div>';
636 $html .=
'</tr><tr class="app2 oddeven nohover borderbottom '.dol_escape_htmltag($compatible).
'">';
640 $html .=
'<td class="margeCote center amount'.(getDolOptimizeSmallScreen() ?
' left" colspan="2"' :
'"').
'>';
645 $html .=
'<td class="margeCote nowraponall">';
649 $html .= $download_link;
655 if (empty($this->products)) {
657 $langs->load(
"website");
659 $html .=
'<tr class=""><td colspan="'.$colspan.
'" class="center">';
661 $html .= $langs->trans(
"noResultsWereFound").
'...';
663 $html .=
'</td></tr>';
666 $this->numberOfProducts = count($this->products);
685 function (array $a, array $b) use ($key) {
686 $valA = isset($a[$key]) && is_scalar($a[$key]) ? (string) $a[$key] :
'';
687 $valB = isset($b[$key]) && is_scalar($b[$key]) ? (string) $b[$key] :
'';
689 return strnatcmp($valA, $valB);
703 $v1 = str_replace(array(
'v',
'V'),
'', $v1);
704 $v2 = str_replace(array(
'v',
'V'),
'', $v2);
706 $v1 = explode(
'.', $v1);
707 $v2 = explode(
'.', $v2);
710 $count1 = count($v1);
711 $count2 = count($v2);
712 $maxcount = max($count1, $count2);
713 while ($level < $maxcount) {
714 $operande1 = isset($v1[$level]) ? $v1[$level] :
'x';
715 $operande2 = isset($v2[$level]) ? $v2[$level] :
'x';
717 if (strtoupper($operande1) ==
'X' || strtoupper($operande2) ==
'X' || $operande1 ==
'*' || $operande2 ==
'*') {
720 if ($operande1 < $operande2) {
724 if ($operande1 > $operande2) {
743 return '<a href="'.$this->get_previous_url().
'" class="button">'.
dol_escape_htmltag($text).
'</a>';
756 return '<a href="'.$this->get_next_url().
'" class="button">'.
dol_escape_htmltag($text).
'</a>';
768 $param_array = array();
769 if ($this->no_page > 1) {
774 if (!empty($this->search)) {
775 $param_array[
'search_keyword'] = $this->search;
777 $param_array[
'no_page'] = $this->no_page - $sub;
778 if ($this->categorie != 0) {
779 $param_array[
'categorie'] = $this->categorie;
781 $param = http_build_query($param_array);
782 return $this->url.
"&".$param;
794 $param_array = array();
795 if ($this->products !==
null && count($this->products) < $this->per_page) {
800 if (!empty($this->search)) {
801 $param_array[
'search_keyword'] = $this->search;
803 $param_array[
'no_page'] = $this->no_page + $add;
804 if ($this->categorie != 0) {
805 $param_array[
'categorie'] = $this->categorie;
807 $param = http_build_query($param_array);
808 return $this->url.
"&".$param;
821 $page = $this->no_page;
822 $limit = $this->per_page;
823 $totalnboflines = $this->numberTotalOfProducts ?: 0;
824 $num = $this->numberOfProducts;
830 if ($page > 0 || $num > $limit) {
831 if ($totalnboflines) {
833 $nbpages = $this->numberTotalOfPages;
840 $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>';
843 $pagelist .=
'<li class="pagination">';
844 $pagelist .=
'<label for="page_input">Page </label>';
845 if ($this->categorie != 0) {
846 $pagelist .=
'<input type="hidden" name="categorie" value="' . $this->categorie .
'">';
848 $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.
'">';
849 $pagelist .=
' / '.$nbpages;
850 $pagelist .=
'</li>';
853 if ($page < $nbpages) {
854 $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>';
859 if ($limit || $pagelist) {
860 $html .=
'<div class="pagination" style="padding: 7px;">';
883 400 =>
'Bad Request',
884 401 =>
'Unauthorized',
886 405 =>
'Method Not Allowed',
887 500 =>
'Internal Server Error',
891 if ($request[
'status_code'] === 200 || $request[
'status_code'] === 201) {
896 $error_message = $error_messages[$request[
'status_code']] ??
'Unexpected HTTP status: ' . $request[
'status_code'];
899 if (!empty($request[
'response']) && isset($request[
'response'][
'errors']) && is_array($request[
'response'][
'errors'])) {
900 foreach ($request[
'response'][
'errors'] as $error) {
901 $error_message .=
' - (Code ' . $error[
'code'] .
'): ' . $error[
'message'];
905 if (!empty($request[
'curl_error_msg'])) {
906 $error_message .=
' - ' . $request[
'curl_error_msg'];
910 return sprintf(
'This call to the API failed and returned an HTTP status of %d. That means: %s.', $request[
'status_code'], $error_message);
923 $cache_file = $this->cache_file;
924 $cache_folder = dirname($cache_file);
931 if (!file_exists($cache_file) || filemtime($cache_file) < (
dol_now() - $cache_time)) {
933 $addheaders = array();
934 $result =
getURLContent($file_source_url,
'GET',
'', 1, $addheaders);
935 if (!empty($result) && $result[
'http_code'] == 200) {
936 $yaml = $result[
'content'];
937 $result = file_put_contents($cache_file, $yaml);
938 if ($result ===
false) {
939 $this->error =
'Failed to create cache file: ' . $cache_file;
945 $yaml = file_get_contents($cache_file);
961 $currentPackage =
null;
962 $currentSection =
null;
964 foreach (explode(
"\n", trim($yaml)) as $line) {
965 $trimmedLine = trim($line);
968 if ($trimmedLine ===
'' || strpos($trimmedLine,
'#') === 0) {
974 if (preg_match(
'/^\s*-\s*modulename:\s*["\']?(.*?)["\']?$/', $trimmedLine, $matches)) {
975 if ($currentPackage !==
null) {
977 if (!empty($currentPackage[
'status']) && in_array($currentPackage[
'status'], array(
'enabled',
'soon'))) {
978 $data[] = $currentPackage;
981 $currentPackage = [
'modulename' => $matches[1]];
982 $currentSection =
null;
987 if (!preg_match(
'/^\s*(fr|en|es|it|de):\s*["\']?(.*?)["\']?$/', $trimmedLine)) {
988 $currentSection =
null;
992 if (preg_match(
'/^(\w[\w-]*):\s*["\']?(.*?)["\']?$/', $trimmedLine, $matches)) {
993 if ($currentPackage !==
null) {
994 if ($currentSection) {
996 $currentPackage[$currentSection][$matches[1]] = $matches[2] ===
'' ? null : $matches[2];
999 $currentPackage[$matches[1]] = $matches[2] ===
'' ? null : $matches[2];
1004 if (preg_match(
'/^\s*(label|description):\s*$/', $trimmedLine, $matches)) {
1005 $currentSection = $matches[1];
1006 $currentPackage[$currentSection] = [];
1014 if ($currentPackage !==
null) {
1015 if (!empty($currentPackage[
'status']) && in_array($currentPackage[
'status'], array(
'enabled',
'soon'))) {
1016 $data[] = $currentPackage;
1034 if (!is_array($data) || empty($data) || empty($source)) {
1035 return $adaptedData;
1038 if ($source ===
'githubcommunity') {
1039 foreach ($data as $package) {
1040 if (empty($package[
'modulename'])) {
1047 if (!empty($package[
'dolistore-download']) && preg_match(
'/www\.dolistore\.com\/product\.php\?id=(\d+)/', (
string) $package[
'dolistore-download'], $reg)) {
1053 'ref' => str_replace(
' ',
'', $package[
'modulename'] .
'-' . $package[
'current_version'] .
'@' .
1054 (array_key_exists(
'author', $package) ? $package[
'author'] :
'unkownauthor')),
1055 'label' => !empty($package[
'label'][substr($this->lang, 0, 2)])
1056 ? $package[
'label'][substr($this->lang, 0, 2)]
1057 : (!empty($package[
'label'][
'en']) ? $package[
'label'][
'en'] : $package[
'modulename']),
1058 'description' => !empty($package[
'description'][substr($this->lang, 0, 2)])
1059 ? $package[
'description'][substr($this->lang, 0, 2)]
1060 : (!empty($package[
'description'][
'en']) ? $package[
'description'][
'en'] :
''),
1061 'datec' => (!empty($package[
'created_at']) && is_string($package[
'created_at']))
1062 ?
date(
'Y-m-d H:i:s', strtotime($package[
'created_at']))
1064 'tms' => (!empty($package[
'last_updated_at']) && is_string($package[
'last_updated_at']))
1065 ?
date(
'Y-m-d H:i:s', strtotime($package[
'last_updated_at']))
1067 'author' => array_key_exists(
'author', $package) ? $package[
'author'] :
'',
1068 'author_url' => array_key_exists(
'author_url', $package) ? $package[
'author_url'] :
'',
1069 'dolibarr_min' => !empty($package[
'dolibarrmin'])
1070 ? $package[
'dolibarrmin']
1072 'dolibarr_max' => !empty($package[
'dolibarrmax'])
1073 ? $package[
'dolibarrmax']
1075 'phpmin' => !empty($package[
'phpmin'])
1076 ? $package[
'phpmin']
1078 'phpmax' => !empty($package[
'phpmax'])
1079 ? $package[
'phpmax']
1081 'module_version' => !empty($package[
'current_version'])
1082 ? $package[
'current_version']
1084 'cover_photo_url' => !empty($package[
'cover'])
1087 'category' => (!empty($package[
'category']) && is_string($package[
'category']))
1088 ? explode(
',', str_replace(
' ',
'', (
string) $package[
'category']))
1090 'link' => !empty($package[
'git'])
1093 'source' =>
'githubcommunity',
1094 'status' => !empty($package[
'status']) ? $package[
'status'] :
'',
1095 'direct-download' => !empty($package[
'direct-download'])
1096 ? $package[
'direct-download']
1098 'dolistore-download' => !empty($package[
'dolistore-download'])
1099 ? $package[
'dolistore-download']
1104 if (array_key_exists(
'price', $package) && $package[
'price'] !=
null) {
1105 $adaptedPackage[
'price_ht'] = $package[
'price'];
1108 $adaptedData[] = $adaptedPackage;
1112 if ($source ===
'dolistore') {
1113 foreach ($data as $package) {
1114 $urlphoto = $this->shop_url.$package[
'cover_photo_url'];
1116 if (preg_match(
'/^\/?wrapper\.php\?hashp=/', $package[
'cover_photo_url']) && !preg_match(
'/attachment=/', $package[
'cover_photo_url'])) {
1117 $urlphoto .=
'&attachment=0';
1121 'id' => $package[
'id'],
1122 'ref' => $package[
'ref'],
1123 'label' => $package[
'label'],
1124 'description' => $package[
'description'],
1125 'datec' => $package[
'datec'],
1126 'tms' => $package[
'tms'],
1127 'author' => array_key_exists(
'author', $package) ? $package[
'author'] :
'',
1128 'author_url' => array_key_exists(
'author_url', $package) ? $package[
'author_url'] :
'',
1129 'price_ttc' => $package[
'price_ttc'],
1130 'price_ht' => $package[
'price_ht'],
1131 'dolibarr_min' => $package[
'dolibarr_min'],
1132 'dolibarr_max' => $package[
'dolibarr_max'],
1133 'phpmin' => empty($package[
'phpmin']) ?
'' : $package[
'phpmin'],
1134 'phpmax' => empty($package[
'phpmax']) ?
'' : $package[
'phpmax'],
1135 'module_version' => $package[
'module_version'],
1136 'cover_photo_url' => $urlphoto,
1137 'source' =>
'dolistore',
1138 'status' => empty($package[
'status']) ?
'' : $package[
'status']
1141 $adaptedData[$package[
'id']] = $adaptedPackage;
1145 return $adaptedData;
1157 $filteredData = $list;
1169 static function ($a, $b) {
1170 return strtotime($b[
'datec'] ??
'0') - strtotime($a[
'datec'] ??
'0');
1174 if (!empty($options[
'search'])) {
1175 $filteredData = array_filter(
1184 static function ($package) use ($options) {
1185 return stripos($package[
'label'], $options[
'search']) !==
false || stripos($package[
'description'], $options[
'search']) !==
false;
1190 if (!empty($options[
'categorieid'])) {
1191 $filteredData = array_filter(
1200 static function ($package) use ($options) {
1201 return in_array($options[
'categorieid'], $package[
'category']);
1206 $total = count($filteredData);
1209 $filteredData = array_values($filteredData);
1210 $filteredData = array_slice($filteredData, ($options[
'page'] - 1) * $options[
'limit'], $options[
'limit']);
1212 return [
'total' => $total,
'data' => $filteredData];
1223 $testRequest = $this->
callApi(
'categories');
1225 if (!isset($testRequest[
'response']) || !is_array($testRequest[
'response']) || ($testRequest[
'status_code'] != 200 && $testRequest[
'status_code'] != 201)) {
1241 public function libStatus($status, $mode = 3, $moretext =
'')
1245 $statusType =
'status4';
1247 $statusType =
'status8';
1251 $labelStatusShort = [];
1253 $labelStatus[0] = $langs->transnoentitiesnoconv(
"NotConnected");
1254 $labelStatus[1] = $langs->transnoentitiesnoconv(
"online");
1255 $labelStatusShort[0] = $langs->transnoentitiesnoconv(
"NotConnected");
1256 $labelStatusShort[1] = $langs->transnoentitiesnoconv(
"online");
1258 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'', $statusType, $mode,
'', array(
'badgeParams' => array(
'attr' => array(
'class' =>
'classfortooltip',
'title' => $labelStatusShort[$status].$moretext))));
$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.
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.
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.
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)
Return a string (that can be on several lines) ready to be output on a HTML page.
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.
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_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)
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...
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0, $otherCurlOptions=array())
Function to get a content from an URL (use proxy if proxy defined).
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date