diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 868743630e5..dec5fec8e39 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -1286,14 +1286,16 @@ if ($mode == 'marketplace') { if (!getDolGlobalString('MAIN_DISABLE_DOLISTORE_SEARCH') && getDolGlobalInt('MAIN_ENABLE_DOLISTORE')) { $messagetoadd = ''; if ($remotestore->dolistoreApiStatus <= 0) { - $messagetoadd = '
'.$remotestore->dolistoreApiError.'
Failed to login to: '.$remotestore->dolistore_api_url; - $messagetoadd .= '
using API public key: '.$remotestore->dolistore_api_key; - // Add basic auth if needed - $basicAuthLogin = getDolGlobalString('MAIN_MODULE_DOLISTORE_BASIC_LOGIN'); - $basicAuthPassword = getDolGlobalString('MAIN_MODULE_DOLISTORE_BASIC_PASSWORD'); - if ($basicAuthLogin) { - $messagetoadd .= '
using basic auth login: base64('.$basicAuthLogin.':'.$basicAuthPassword.')'; - } + $messagetoadd = '
'.$remotestore->dolistoreApiError.'
Failed to get answer of remote API server
'; + } + + $messagetoadd .= '
Using Remote API URL MAIN_MODULE_DOLISTORE_API_URL: '.$remotestore->dolistore_api_url; + $messagetoadd .= '
Using API public key MAIN_MODULE_DOLISTORE_API_KEY = '.$remotestore->dolistore_api_key; + // Add basic auth if needed + $basicAuthLogin = getDolGlobalString('MAIN_MODULE_DOLISTORE_BASIC_LOGIN'); + $basicAuthPassword = getDolGlobalString('MAIN_MODULE_DOLISTORE_BASIC_PASSWORD'); + if ($basicAuthLogin) { + $messagetoadd .= '
Using basic auth login: base64('.$basicAuthLogin.':'.$basicAuthPassword.')'; } print $remotestore->libStatus($remotestore->dolistoreApiStatus, 2, $messagetoadd); } @@ -1334,19 +1336,21 @@ if ($mode == 'marketplace') { print ''.$langs->trans('DOLISTOREdescriptionLong').'

'; - //$previouslink = $remotestore->get_previous_link(); - //$nextlink = $remotestore->get_next_link(); + $categories_tree = $remotestore->getCategories(); // Call API to get the categories - $categories_tree = $remotestore->getCategories(); $products_list = $remotestore->getProducts($options); + $previouslink = $remotestore->get_previous_link(); + $nextlink = $remotestore->get_next_link(); + print '
'; print '
'; ?> +
@@ -1369,8 +1373,8 @@ if ($mode == 'marketplace') {
diff --git a/htdocs/admin/remotestore/class/externalModules.class.php b/htdocs/admin/remotestore/class/externalModules.class.php index e4f6ca47fb0..5596c44de62 100644 --- a/htdocs/admin/remotestore/class/externalModules.class.php +++ b/htdocs/admin/remotestore/class/externalModules.class.php @@ -120,14 +120,13 @@ class ExternalModules { global $langs; - $this->dolistore_api_url = getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV'); - $this->dolistore_api_key = getDolGlobalString('MAIN_MODULE_DOLISTORE_API_KEY'); - - $this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace'; - $this->shop_url = 'https://www.dolistore.com/product.php?id='; + $this->dolistore_api_url = getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV', 'https://admin2.dolibarr.org/api/index.php/marketplace'); + $this->dolistore_api_key = getDolGlobalString('MAIN_MODULE_DOLISTORE_API_KEY', 'dolistorepublicapi'); + $this->shop_url = getDolGlobalString('MAIN_MODULE_DOLISTORE_SHOP_URL', 'https://www.dolistore.com'); $this->debug_api = $debug; + $this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace'; $this->file_source_url = "https://raw.githubusercontent.com/Dolibarr/dolibarr-community-modules/refs/heads/main/index.yaml"; $this->cache_file = DOL_DATA_ROOT.'/admin/temp/remote_github_modules_file.yaml'; @@ -190,13 +189,16 @@ class ExternalModules if ($options) { $url .= '?' . http_build_query($options); } - - $response = getURLContent($url, 'POST', '', 1, $httpheader); - - $body = $response['content']; - $body = json_decode($body, true); + $url .= (preg_match('/\?/', $url) ? '&' : '?').'apikey='.$this->dolistore_api_key; + $response = getURLContent($url, 'GET', '', 1, $httpheader); $status_code = $response['http_code']; + $body = 'Error'; + + if ($status_code == 200) { + $body = $response['content']; + $body = json_decode($body, true); + } return array('status_code' => $status_code, 'response' => $body); } @@ -300,6 +302,7 @@ class ExternalModules $dolistoreProducts = array(); if ($this->dolistoreApiStatus > 0 && $options['search_source_dolistore'] == 1) { $getDolistoreProducts = $this->callApi('products', $data); + if (!isset($getDolistoreProducts['response']) || !is_array($getDolistoreProducts['response']) || ($getDolistoreProducts['status_code'] != 200 && $getDolistoreProducts['status_code'] != 201)) { $dolistoreProducts = array(); } else { @@ -311,7 +314,9 @@ class ExternalModules $fileProducts = array(); if (!empty($this->githubFileStatus) && $options['search_source_github'] == 1) { $fileProducts = $this->fetchModulesFromFile($data); // Return an array with all modules from the cache filecontent in $data + $fileProducts = $this->adaptData($fileProducts, 'githubcommunity'); + $fileProducts = $this->applyFilters($fileProducts, $data); } @@ -359,7 +364,7 @@ class ExternalModules // free or pay ? if ($product["price_ttc"] > 0) { $price = '

'.price(price2num($product["price_ttc"], 'MT'), 0, $langs, 1, -1, -1, 'EUR').' '.$langs->trans("TTC").'

'; - $download_link = ''; + $download_link = ''; } else { $download_link = '#'; $price = '

'.$langs->trans('Free').'

'; @@ -377,7 +382,7 @@ class ExternalModules } if ($product['source'] === 'dolistore') { - $download_link = ''; + $download_link = ''; if (!empty($product['direct-download']) && $product['direct-download'] == 'yes') { $download_link .= ''; } @@ -747,7 +752,6 @@ class ExternalModules public function adaptData($data, $source) { $adaptedData = []; - $urldolibarrmodules = 'https://www.dolistore.com'; if (!is_array($data) || empty($data) || empty($source)) { return $adaptedData; @@ -825,7 +829,7 @@ class ExternalModules 'phpmin' => $package['phpmin'], 'phpmax' => $package['phpmax'], 'module_version' => $package['module_version'], - 'cover_photo_url' => $urldolibarrmodules.$package['cover_photo_url'], + 'cover_photo_url' => $this->shop_url.$package['cover_photo_url'], 'source' => 'dolistore' ];