Merge branch 'develop' into patch-13

This commit is contained in:
Laurent Destailleur 2025-03-04 22:58:49 +01:00 committed by GitHub
commit 3f7329a18e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 64 additions and 1197 deletions

View file

@ -41,7 +41,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
require_once DOL_DOCUMENT_ROOT.'/admin/remotestore/class/dolistore.class.php';
require_once DOL_DOCUMENT_ROOT.'/admin/remotestore/class/externalModules.class.php';
'
@ -1273,7 +1272,6 @@ if ($mode == 'marketplace') {
print '<tr class="liste_titre">'."\n";
print '<td class="hideonsmartphone">'.$form->textwithpicto($langs->trans("Provider"), $langs->trans("WebSiteDesc")).'</td>';
print '<td></td>';
print '<td>'.$langs->trans("URL").'</td>';
print '<td></td>';
print '</tr>';
@ -1281,21 +1279,26 @@ if ($mode == 'marketplace') {
print '<tr class="oddeven">'."\n";
$url = 'https://www.dolistore.com';
print '<td class="hideonsmartphone center"><a href="'.$url.'" target="_blank" rel="noopener noreferrer external"><img border="0" class="imgautosize imgmaxwidth180" src="'.DOL_URL_ROOT.'/theme/dolistore_logo.svg"></a></td>';
print '<td><span class="opacitymedium">'.$langs->trans("DoliStoreDesc").'</span></td>';
print '<td>'.img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.$url.'" target="_blank" rel="noopener noreferrer external">'.$url.'</a></td>';
print '<td><span class="opacitymedium">'.$langs->trans("DoliStoreDesc").'</span><br>';
print img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.$url.'" target="_blank" rel="noopener noreferrer external">'.$url.'</a></td>';
print '<td class="center">';
if (!getDolGlobalString('MAIN_DISABLE_DOLISTORE_SEARCH') && getDolGlobalInt('MAIN_ENABLE_DOLISTORE')) {
$messagetoadd = '';
$messagetoadd = '<br><span class="small">';
if ($remotestore->dolistoreApiStatus <= 0) {
$messagetoadd = '<br>'.$remotestore->dolistoreApiError.'<br>Failed to login to: '.$remotestore->dolistore_api_url;
$messagetoadd .= '<br>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 .= '<br>using basic auth login: base64('.$basicAuthLogin.':'.$basicAuthPassword.')';
}
$messagetoadd = '<br>'.$remotestore->dolistoreApiError.'<br>Failed to get answer of remote API server<br>';
}
$messagetoadd .= '<br>Using Shop address MAIN_MODULE_DOLISTORE_SHOP_URL = '.$remotestore->shop_url;
$messagetoadd .= '<br>Using Remote API addtess MAIN_MODULE_DOLISTORE_API_URL = '.$remotestore->dolistore_api_url;
$messagetoadd .= '<br>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 .= '<br>Using basic auth login: base64('.$basicAuthLogin.':'.$basicAuthPassword.')';
}
$messagetoadd .= '</span>';
print $remotestore->libStatus($remotestore->dolistoreApiStatus, 2, $messagetoadd);
}
print '</td>';
@ -1305,11 +1308,12 @@ if ($mode == 'marketplace') {
print '<tr class="oddeven">'."\n";
$url = 'https://github.com/Dolibarr/dolibarr-community-modules';
print '<td class="hideonsmartphone center"><a href="'.$url.'" target="_blank" rel="noopener noreferrer external"><img border="0" class="imgautosize imgmaxwidth180" src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg"></a></td>';
print '<td><span class="opacitymedium">'.$langs->trans("CommunityModulesDesc").'</span></td>';
print '<td>'.img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.$url.'" target="_blank" rel="noopener noreferrer external">'.$url.'</a></td>';
print '<td><span class="opacitymedium">'.$langs->trans("CommunityModulesDesc").'</span><br>';
print img_picto('', 'url', 'class="pictofixedwidth"').'<a href="'.$url.'" target="_blank" rel="noopener noreferrer external">'.$url.'</a></td>';
print '<td class="center">';
if (!getDolGlobalString('MAIN_DISABLE_DOLISTORE_SEARCH') && getDolGlobalInt('MAIN_ENABLE_COMMUNITY_REPO')) {
print $remotestore->libStatus($remotestore->githubFileStatus, 2, '<br><small>Content of repository file '.$remotestore->file_source_url.' is in the cache file '.$remotestore->cache_file.'</small>');
$messagetoadd = '<br><br><span class="small">Content of the repository index file '.$remotestore->file_source_url.' is in the local cache file '.$remotestore->cache_file.'</span>';
print $remotestore->libStatus($remotestore->githubFileStatus, 2, $messagetoadd);
}
print '</td>';
print '</tr>';
@ -1335,19 +1339,21 @@ if ($mode == 'marketplace') {
print '<span class="opacitymedium">'.$langs->trans('DOLISTOREdescriptionLong').'</span><br><br>';
//$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 '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
print '<form method="POST" class="centpercent" id="searchFormList" action="'.$remotestore->url.'">'; ?>
<input type="hidden" name="token" value="<?php echo newToken(); ?>">
<input type="hidden" name="mode" value="marketplace">
<input type="hidden" name="page_y" value="">
<div class="divsearchfield">
<input name="search_keyword" placeholder="<?php echo $langs->trans('Keyword') ?>" id="search_keyword" type="text" class="minwidth200" value="<?php echo dol_escape_htmltag($options['search']) ?>">
<!-- Add a check box to filter by source -->
@ -1370,8 +1376,8 @@ if ($mode == 'marketplace') {
</div>
<div class="divsearchfield">
<input class="button buttongen" value="<?php echo $langs->trans('Rechercher') ?>" type="submit">
<a class="buttonreset" href="<?php echo $_SERVER["PHP_SELF"].'?mode=marketplace'; ?>"><?php echo $langs->trans('Reset') ?></a>
<input class="button buttongen reposition" value="<?php echo $langs->trans('Rechercher') ?>" type="submit">
<a class="buttonreset reposition" href="<?php echo $_SERVER["PHP_SELF"].'?mode=marketplace'; ?>"><?php echo $langs->trans('Reset') ?></a>
&nbsp;
</div>

View file

@ -29,7 +29,6 @@ if (!defined('NOTOKENRENEWAL')) {
*/
require "../../../main.inc.php";
require_once DOL_DOCUMENT_ROOT.'/admin/remotestore/class/dolistore.class.php';
/*

View file

@ -1,542 +0,0 @@
<?php
/* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*/
/*
* 2007-2022 PrestaShop SA and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2022 PrestaShop SA
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* PrestaShop Webservice Library
* @package PrestaShopWebservice
*/
/**
* @package PrestaShopWebservice
*/
class PrestaShopWebservice
{
/** @var string Shop URL */
protected $url;
/** @var string Authentication key */
protected $key;
/** @var boolean is debug activated */
protected $debug;
/** @var string PS version */
protected $version;
/** @var string Minimal version of PrestaShop to use with this library */
const PS_COMPATIBLE_VERSIONS_MIN = '1.4.0.0';
/** @var string Maximal version of PrestaShop to use with this library */
const PS_COMPATIBLE_VERSIONS_MAX = '8.1.1';
/**
* PrestaShopWebservice constructor. Throw an exception when CURL is not installed/activated
* <code>
* <?php
* require_once('./PrestaShopWebservice.php');
* try
* {
* $ws = new PrestaShopWebservice('https://mystore.com/', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ', false);
* // Now we have a webservice object to play with
* }
* catch (PrestaShopWebserviceException $ex)
* {
* echo 'Error : '.$ex->getMessage();
* }
* ?>
* </code>
*
* @param string $url Root URL for the shop
* @param string $key Authentication key
* @param bool $debug Debug mode Activated (true) or deactivated (false)
*
* @throws PrestaShopWebserviceException if curl is not loaded
*/
public function __construct($url, $key, $debug = true)
{
if (!extension_loaded('curl')) {
throw new PrestaShopWebserviceException(
'Please activate the PHP extension \'curl\' to allow use of PrestaShop webservice library'
);
}
$this->url = $url;
$this->key = $key;
$this->debug = $debug;
$this->version = 'unknown';
}
/**
* Take the status code and throw an exception if the server didn't return 200 or 201 code
* <p>Unique parameter must take : <br><br>
* 'status_code' => Status code of an HTTP return<br>
* 'response' => CURL response
* </p>
*
* @param array{status_code:int,response:string} $request Response elements of CURL request
*
* @return void
* @throws PrestaShopWebserviceException if HTTP status code is not 200 or 201
*/
protected function checkStatusCode($request)
{
switch ($request['status_code']) {
case 200:
case 201:
break;
case 204:
$error_message = 'No content';
break;
case 400:
$error_message = 'Bad Request';
break;
case 401:
$error_message = 'Unauthorized';
break;
case 404:
$error_message = 'Not Found';
break;
case 405:
$error_message = 'Method Not Allowed';
break;
case 500:
$error_message = 'Internal Server Error';
break;
default:
throw new PrestaShopWebserviceException(
'This call to PrestaShop Web Services returned an unexpected HTTP status of:' . $request['status_code']
);
}
if (!empty($error_message)) {
$response = $this->parseXML($request['response']);
$errors = $response->children()->children();
if ($errors && count($errors) > 0) {
foreach ($errors as $error) {
$error_message .= ' - (Code ' . $error->code . '): ' . $error->message;
}
}
$error_label = 'This call to PrestaShop Web Services failed and returned an HTTP status of %d. That means: %s.';
throw new PrestaShopWebserviceException(sprintf($error_label, $request['status_code'], $error_message));
}
}
/**
* Provides default parameters for the curl connection(s)
* @return array<int,bool|int|string|string[]|array<int,string>> Default parameters for curl connection(s)
*/
protected function getCurlDefaultParams()
{
$defaultParams = array(
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => $this->key . ':',
CURLOPT_HTTPHEADER => array('Expect:'),
//CURLOPT_SSL_VERIFYPEER => false, // reminder, in dev environment sometimes self-signed certificates are used
//CURLOPT_CAINFO => "PATH2CAINFO", // ssl certificate chain checking
//CURLOPT_CAPATH => "PATH2CAPATH",
);
return $defaultParams;
}
/**
* Handles a CURL request to PrestaShop Webservice. Can throw exception.
*
* @param string $url Resource name
* @param array<int,null|int|bool|string|float> $curl_params CURL parameters (sent to curl_set_opt)
*
* @return array{status_code:int,response:?string,header:string}
*
* @throws PrestaShopWebserviceException
*/
public function executeRequest($url, $curl_params = array())
{
$defaultParams = $this->getCurlDefaultParams();
dol_syslog("curl_init url=".$url);
$session = curl_init($url);
$curl_options = array();
foreach ($defaultParams as $defkey => $defval) {
if (isset($curl_params[$defkey])) {
$curl_options[$defkey] = $curl_params[$defkey];
} else {
$curl_options[$defkey] = $defaultParams[$defkey];
}
}
foreach ($curl_params as $defkey => $defval) {
if (!isset($curl_options[$defkey])) {
$curl_options[$defkey] = $curl_params[$defkey];
}
}
dol_syslog("curl curl_options = ".var_export($curl_options, true));
curl_setopt_array($session, $curl_options);
$response = curl_exec($session);
$index = strpos($response, "\r\n\r\n");
if ($index === false && $curl_params[CURLOPT_CUSTOMREQUEST] != 'HEAD') {
throw new PrestaShopWebserviceException('Bad HTTP response ' . $response . curl_error($session));
}
$header = substr($response, 0, $index);
$body = substr($response, $index + 4);
$headerArrayTmp = explode("\n", $header);
$headerArray = array();
foreach ($headerArrayTmp as &$headerItem) {
$tmp = explode(':', $headerItem);
$tmp = array_map('trim', $tmp);
if (count($tmp) == 2) {
$headerArray[$tmp[0]] = $tmp[1];
}
}
if (array_key_exists('PSWS-Version', $headerArray)) {
$this->version = $headerArray['PSWS-Version'];
if (
version_compare(PrestaShopWebservice::PS_COMPATIBLE_VERSIONS_MIN, $headerArray['PSWS-Version']) == 1 ||
version_compare(PrestaShopWebservice::PS_COMPATIBLE_VERSIONS_MAX, $headerArray['PSWS-Version']) == -1
) {
throw new PrestaShopWebserviceException(
'This library is not compatible with this version of PrestaShop. Please upgrade/downgrade this library'
);
}
}
if ($this->debug) {
$this->printDebug('HTTP REQUEST HEADER', curl_getinfo($session, CURLINFO_HEADER_OUT));
$this->printDebug('HTTP RESPONSE HEADER', $header);
}
$status_code = curl_getinfo($session, CURLINFO_HTTP_CODE);
if ($status_code === 0) {
throw new PrestaShopWebserviceException('CURL Error: ' . curl_error($session));
}
curl_close($session);
if ($this->debug) {
if ($curl_params[CURLOPT_CUSTOMREQUEST] == 'PUT' || $curl_params[CURLOPT_CUSTOMREQUEST] == 'POST') {
$this->printDebug('XML SENT', urldecode($curl_params[CURLOPT_POSTFIELDS]));
}
if ($curl_params[CURLOPT_CUSTOMREQUEST] != 'DELETE' && $curl_params[CURLOPT_CUSTOMREQUEST] != 'HEAD') {
$this->printDebug('RETURN HTTP BODY', $body);
}
}
return array('status_code' => $status_code, 'response' => $body, 'header' => $header);
}
/**
* Output debug info
*
* @param string $title Title
* @param string $content Content
* @return void
*/
public function printDebug($title, $content)
{
if (php_sapi_name() == 'cli') {
echo $title . PHP_EOL . $content;
} else {
echo '<div style="display:table;background:#CCC;font-size:8pt;padding:7px"><h6 style="font-size:9pt;margin:0">'
. $title
. '</h6><pre>'
. htmlentities($content)
. '</pre></div>';
}
}
/**
* Return version
*
* @return string Version
*/
public function getVersion()
{
return $this->version;
}
/**
* Load XML from string. Can throw exception
*
* @param string $response String from a CURL response
*
* @return SimpleXMLElement status_code, response
* @throws PrestaShopWebserviceException
*/
protected function parseXML($response)
{
if ($response != '') {
libxml_clear_errors();
libxml_use_internal_errors(true);
if (LIBXML_VERSION < 20900) {
// Avoid load of external entities (security problem).
// Required only if LIBXML_VERSION < 20900
// @phan-suppress-next-line PhanDeprecatedFunctionInternal
libxml_disable_entity_loader(true);
}
$xml = simplexml_load_string(trim($response), 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NONET);
if (libxml_get_errors()) {
$msg = var_export(libxml_get_errors(), true);
libxml_clear_errors();
throw new PrestaShopWebserviceException('HTTP XML response is not parsable: ' . $msg);
}
return $xml;
} else {
throw new PrestaShopWebserviceException('HTTP response is empty');
}
}
/**
* Add (POST) a resource
* <p>Unique parameter must take : <br><br>
* 'resource' => Resource name<br>
* 'postXml' => Full XML string to add resource<br><br>
* Examples are given in the tutorial</p>
*
* @param array{url?:string,resource?:string,id?:string,id_shop?:string,id_group_shop?:string,postXml:mixed} $options Array representing resource to add.
*
* @return SimpleXMLElement status_code, response
* @throws PrestaShopWebserviceException
*/
public function add($options)
{
$xml = '';
if (isset($options['resource'], $options['postXml']) || isset($options['url'], $options['postXml'])) {
$url = (isset($options['resource']) ? $this->url . '/api/' . $options['resource'] : $options['url']);
$xml = $options['postXml'];
if (isset($options['id_shop'])) {
$url .= '&id_shop=' . $options['id_shop'];
}
if (isset($options['id_group_shop'])) {
$url .= '&id_group_shop=' . $options['id_group_shop'];
}
} else {
throw new PrestaShopWebserviceException('Bad parameters given');
}
$request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $xml));
$this->checkStatusCode($request);
return $this->parseXML($request['response']);
}
/**
* Retrieve (GET) a resource
* <p>Unique parameter must take : <br><br>
* 'url' => Full URL for a GET request of Webservice (ex: https://mystore.com/api/customers/1/)<br>
* OR<br>
* 'resource' => Resource name,<br>
* 'id' => ID of a resource you want to get<br><br>
* </p>
* <code>
* <?php
* require_once('./PrestaShopWebservice.php');
* try
* {
* $ws = new PrestaShopWebservice('https://mystore.com/', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ', false);
* $xml = $ws->get(array('resource' => 'orders', 'id' => 1));
* // Here in $xml, a SimpleXMLElement object you can parse
* foreach ($xml->children()->children() as $attName => $attValue)
* echo $attName.' = '.$attValue.'<br>';
* }
* catch (PrestaShopWebserviceException $ex)
* {
* echo 'Error : '.$ex->getMessage();
* }
* ?>
* </code>
*
* @param array<string,string> $options Array representing resource to get.
*
* @return SimpleXMLElement status_code, response
* @throws PrestaShopWebserviceException
*/
public function get($options)
{
if (isset($options['url'])) {
$url = $options['url'];
} elseif (isset($options['resource'])) {
$url = $this->url . '/api/' . $options['resource'];
$url_params = array();
if (isset($options['id'])) {
$url .= '/' . $options['id'];
}
$params = array('filter', 'display', 'sort', 'limit', 'id_shop', 'id_group_shop', 'schema', 'language', 'date', 'price');
foreach ($params as $p) {
foreach ($options as $k => $o) {
if (strpos($k, $p) !== false) {
$url_params[$k] = $options[$k];
}
}
}
if (count($url_params) > 0) {
$url .= '?' . http_build_query($url_params);
}
} else {
throw new PrestaShopWebserviceException('Bad parameters given');
}
$request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET'));
$this->checkStatusCode($request);// check the response validity
return $this->parseXML($request['response']);
}
/**
* Head method (HEAD) a resource
*
* @param array<string,string> $options Array representing resource for head request.
*
* @return string
* @throws PrestaShopWebserviceException
*/
public function head($options)
{
if (isset($options['url'])) {
$url = $options['url'];
} elseif (isset($options['resource'])) {
$url = $this->url . '/api/' . $options['resource'];
$url_params = array();
if (isset($options['id'])) {
$url .= '/' . $options['id'];
}
$params = array('filter', 'display', 'sort', 'limit');
foreach ($params as $p) {
foreach ($options as $k => $o) {
if (strpos($k, $p) !== false) {
$url_params[$k] = $options[$k];
}
}
}
if (count($url_params) > 0) {
$url .= '?' . http_build_query($url_params);
}
} else {
throw new PrestaShopWebserviceException('Bad parameters given');
}
$request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'HEAD', CURLOPT_NOBODY => true));
$this->checkStatusCode($request);// check the response validity
return $request['header'];
}
/**
* Edit (PUT) a resource
* <p>Unique parameter must take : <br><br>
* 'resource' => Resource name ,<br>
* 'id' => ID of a resource you want to edit,<br>
* 'putXml' => Modified XML string of a resource<br><br>
* Examples are given in the tutorial</p>
*
* @param array{url?:string,resource?:string,id?:string,id_shop?:string,id_group_shop?:string,putXml:mixed} $options Array representing resource to edit.
*
* @return SimpleXMLElement
* @throws PrestaShopWebserviceException
*/
public function edit($options)
{
$xml = '';
if (isset($options['url'])) {
$url = $options['url'];
} elseif ((isset($options['resource'], $options['id']) || isset($options['url'])) && $options['putXml']) {
$url = (isset($options['url']) ? $options['url'] :
$this->url . '/api/' . $options['resource'] . '/' . $options['id']);
$xml = $options['putXml'];
if (isset($options['id_shop'])) {
$url .= '&id_shop=' . $options['id_shop'];
}
if (isset($options['id_group_shop'])) {
$url .= '&id_group_shop=' . $options['id_group_shop'];
}
} else {
throw new PrestaShopWebserviceException('Bad parameters given');
}
$request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $xml));
$this->checkStatusCode($request);// check the response validity
return $this->parseXML($request['response']);
}
/**
* Delete (DELETE) a resource.
* Unique parameter must take : <br><br>
* 'resource' => Resource name<br>
* 'id' => ID or array which contains IDs of a resource(s) you want to delete<br><br>
* <code>
* <?php
* require_once('./PrestaShopWebservice.php');
* try
* {
* $ws = new PrestaShopWebservice('https://mystore.com/', 'ZQ88PRJX5VWQHCWE4EE7SQ7HPNX00RAJ', false);
* $xml = $ws->delete(array('resource' => 'orders', 'id' => 1));
* // Following code will not be executed if an exception is thrown.
* echo 'Successfully deleted.';
* }
* catch (PrestaShopWebserviceException $ex)
* {
* echo 'Error : '.$ex->getMessage();
* }
* ?>
* </code>
*
* @param array{url?:string,resource?:string,id?:string,id_shop?:string,id_group_shop?:string} $options Array representing resource to delete.
*
* @return bool
* @throws PrestaShopWebserviceException
*/
public function delete($options)
{
if (isset($options['url'])) {
$url = $options['url'];
} elseif (isset($options['resource']) && isset($options['id'])) {
$url = (is_array($options['id']))
? $this->url . '/api/' . $options['resource'] . '/?id=[' . implode(',', $options['id']) . ']'
: $this->url . '/api/' . $options['resource'] . '/' . $options['id'];
} else {
throw new PrestaShopWebserviceException('Bad parameters given');
}
if (isset($options['id_shop'])) {
$url .= '&id_shop=' . $options['id_shop'];
}
if (isset($options['id_group_shop'])) {
$url .= '&id_group_shop=' . $options['id_group_shop'];
}
$request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'DELETE'));
$this->checkStatusCode($request);// check the response validity
return true;
}
}
/**
* @package PrestaShopWebservice
*/
class PrestaShopWebserviceException extends Exception
{
}

View file

@ -1,52 +0,0 @@
# Open Software License v. 3.0 (OSL-3.0)
This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
Licensed under the Open Software License version 3.0
1) **Grant of Copyright License.** Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
a) to reproduce the Original Work in copies, either alone or as part of a collective work;
b) to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
c) to distribute or communicate copies of the Original Work and Derivative Works to the public, _with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License_;
d) to perform the Original Work publicly; and
e) to display the Original Work publicly.
2) **Grant** of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
3) **Grant** of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
4) **Exclusions From License Grant.** Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2\. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
5) **External Deployment.** The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
6) **Attribution Rights.** You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
7) **Warranty of Provenance and Disclaimer of Warranty.** Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
8) **Limitation of Liability.** Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
9) **Acceptance and Termination.** If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
10) **Termination for Patent Action.** This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
11) **Jurisdiction, Venue and Governing Law.** Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
12) **Attorneys' Fees.** In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
13) **Miscellaneous.** If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
14) **Definition of "You" in This License.** "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15) **Right to Use.** You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
16) **Modification of This License.** This License is Copyright (c) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here\>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
[A brief explanation of this license is available][0].
[0]: http://rosenlaw.com/OSL3.0-explained.htm

View file

@ -1,530 +0,0 @@
<?php
/*
* Copyright (C) 2017 Oscss-Shop <support@oscss-shop.fr>.
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modifyion 2.0 (the "License");
* it under the terms of the GNU General Public License as published bypliance with the License.
* the Free Software Foundation; either version 3 of the License, or
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
if (!class_exists('PrestaShopWebservice')) { // We keep this because some modules add this lib too into a different path. This is to avoid "Cannot declare class PrestaShopWebservice" errors.
include_once DOL_DOCUMENT_ROOT.'/admin/remotestore/class/PSWebServiceLibrary.class.php';
}
/**
* Class Dolistore
*/
class Dolistore
{
/**
* beginning of pagination
* @var int
*/
public $start;
/**
* end of pagination
* @var int
*/
public $end;
/**
* @var int Pagination: display per page
*/
public $per_page;
/**
* @var int The current categorie
*/
public $categorie;
/**
* @var ?SimpleXMLElement
*/
public $categories; // an array of categories
/**
* @var string The search keywords
*/
public $search;
// setups
/**
* @var string
*/
public $url; // the url of this page
/**
* @var string
*/
public $shop_url; // the url of the shop
/**
* @var int
*/
public $lang; // the integer representing the lang in the store
/**
* @var bool
*/
public $debug_api; // useful if no dialog
/**
* @var PrestaShopWebservice
*/
public $api;
/**
* @var ?SimpleXMLElement
*/
public $products;
/**
* Constructor
*
* @param boolean $debug Enable debug of request on screen
*/
public function __construct($debug = false)
{
global $langs;
$this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace';
$this->shop_url = 'https://www.dolistore.com/index.php?controller=product&id_product=';
$this->debug_api = $debug;
$langtmp = explode('_', $langs->defaultlang);
$lang = $langtmp[0];
$lang_array = array('en' => 1, 'fr' => 2, 'es' => 3, 'it' => 4, 'de' => 5); // Into table ps_lang of Prestashop - 1
if (!in_array($lang, array_keys($lang_array))) {
$lang = 'en';
}
$this->lang = $lang_array[$lang];
}
/**
* Load data from remote Dolistore market place.
* This fills ->categories
*
* @return void
*/
public function getRemoteCategories()
{
global $conf;
try {
$this->api = new PrestaShopWebservice(getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV'), getDolGlobalString('MAIN_MODULE_DOLISTORE_API_KEY'), $this->debug_api);
dol_syslog("Call API with MAIN_MODULE_DOLISTORE_API_SRV = ".getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV'));
// conf MAIN_MODULE_DOLISTORE_API_KEY is for the login of basic auth. There is no password as it is public data.
// Here we set the option array for the Webservice : we want categories resources
$opt = array();
$opt['resource'] = 'categories';
$opt['display'] = '[id,id_parent,nb_products_recursive,active,is_root_category,name,description]';
$opt['sort'] = 'id_asc';
// Call
dol_syslog("Call API with opt = ".var_export($opt, true));
$xml = $this->api->get($opt);
// @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
$this->categories = $xml->categories->children();
} catch (PrestaShopWebserviceException $e) {
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) {
die('Bad ID');
} elseif ($trace[0]['args'][0] == 401) {
die('Bad auth key');
} else {
print 'Can not access to ' . getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV').'<br>';
print $e->getMessage();
}
}
}
/**
* Load data from remote Dolistore market place.
* This fills ->products
*
* @param array{start:int,end:int,per_page:int,categorie:int,search:string} $options Options. If 'categorie' is defined, we filter products on this category id
* @return void
*/
public function getRemoteProducts($options = array('start' => 0, 'end' => 10, 'per_page' => 50, 'categorie' => 0, 'search' => ''))
{
global $conf;
$this->start = $options['start'];
$this->end = $options['end'];
$this->per_page = $options['per_page'];
$this->categorie = $options['categorie'];
$this->search = $options['search'];
if ($this->end == 0) {
$this->end = $this->per_page;
}
try {
$this->api = new PrestaShopWebservice(getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV'), getDolGlobalString('MAIN_MODULE_DOLISTORE_API_KEY'), $this->debug_api);
dol_syslog("Call API with MAIN_MODULE_DOLISTORE_API_SRV = ".getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV'));
// conf MAIN_MODULE_DOLISTORE_API_KEY is for the login of basic auth. There is no password as it is public data.
// Here we set the option array for the Webservice : we want products resources
$opt = array();
$opt['resource'] = 'products';
$opt2 = array();
// make a search to limit the id returned.
if ($this->search != '') {
$opt2['url'] = getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV') . '/api/search?query='.$this->search.'&language='.$this->lang; // It seems for search, key start with
// Call
dol_syslog("Call API with opt2 = ".var_export($opt2, true));
$xml = $this->api->get($opt2);
$products = array();
// @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
foreach ($xml->products->children() as $product) {
$products[] = (int) $product['id'];
}
$opt['filter[id]'] = '['.implode('|', $products).']';
} elseif ($this->categorie != 0) { // We filter on category, so we first get list of product id in this category
// $opt2['url'] is set by default to $this->url.'/api/'.$options['resource'];
$opt2['resource'] = 'categories';
$opt2['id'] = $this->categorie;
// Call
dol_syslog("Call API with opt2 = ".var_export($opt2, true));
$xml = $this->api->get($opt2);
$products = array();
// @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
foreach ($xml->category->associations->products->children() as $product) {
$products[] = (int) $product->id;
}
$opt['filter[id]'] = '['.implode('|', $products).']';
}
$opt['display'] = '[id,name,id_default_image,id_category_default,reference,price,condition,show_price,date_add,date_upd,description_short,description,module_version,dolibarr_min,dolibarr_max]';
$opt['sort'] = 'id_desc';
$opt['filter[active]'] = '[1]';
$opt['limit'] = "$this->start,$this->end";
// $opt['filter[id]'] contains list of product id that are result of search
// Call API to get the detail
dol_syslog("Call API with opt = ".var_export($opt, true));
$xml = $this->api->get($opt);
// @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
$this->products = $xml->products->children();
} catch (PrestaShopWebserviceException $e) {
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) {
die('Bad ID');
} elseif ($trace[0]['args'][0] == 401) {
die('Bad auth key');
} else {
print 'Can not access to ' . getDolGlobalString('MAIN_MODULE_DOLISTORE_API_SRV').'<br>';
print $e->getMessage();
}
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return tree of Dolistore categories. $this->categories must have been loaded before.
*
* @param int $parent Id of parent category
* @return string
*/
public function get_categories($parent = 0)
{
// phpcs:enable
if (!isset($this->categories)) {
die('not possible');
}
if ($parent != 0) {
$html = '<ul>';
} else {
$html = '';
}
$nbofcateg = count($this->categories);
for ($i = 0; $i < $nbofcateg; $i++) {
$cat = $this->categories[$i];
if ((string) $cat->name->language[$this->lang - 1] == 'Goodies') {
continue;
}
if ($cat->is_root_category == 1 && $parent == 0) {
$html .= '<li class="root"><h3 class="nomargesupinf marginleftonly"><a class="nomargesupinf link2cat" href="?mode=marketplace&categorie='.((int) $cat->id).'" ';
$html .= 'title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang - 1])).'">';
//$html .= dol_escape_htmltag($cat->name->language[$this->lang - 1]);
$html .= 'DoliStore';
$html .= ' &nbsp;<span class="opacitymedium small valignmiddle">('.dol_escape_htmltag($cat->nb_products_recursive).')</span></a></h3>';
$html .= self::get_categories((int) $cat->id);
$html .= "</li>\n";
} elseif (trim($cat->id_parent) == $parent && $cat->active == 1 && trim($cat->id_parent) != 0) { // si cat est de ce niveau
$select = ($cat->id == $this->categorie) ? ' selected' : '';
$html .= '<li><a class="link2cat'.$select.'" href="?mode=marketplace&categorie='.((int) $cat->id).'"';
$html .= ' title="'.dol_escape_htmltag(strip_tags($cat->description->language[$this->lang - 1])).'" ';
$html .= '>'.dol_escape_htmltag($cat->name->language[$this->lang - 1]);
$html .= ' &nbsp;<span class="opacitymedium small valignmiddle">('.dol_escape_htmltag($cat->nb_products_recursive).')</span></a>';
$html .= self::get_categories((int) $cat->id);
$html .= "</li>\n";
}
}
if ($html == '<ul>') {
return '';
}
if ($parent != 0) {
return $html.'</ul>';
} else {
return $html;
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of product formatted for output
*
* @param int $nbmaxtoshow Nb max of product to show
* @return string HTML output
*/
public function get_products($nbmaxtoshow = 10)
{
// phpcs:enable
global $langs;
$html = "";
$last_month = dol_now() - (30 * 24 * 60 * 60);
$dolibarrversiontouse = DOL_VERSION;
//$dolibarrversiontouse = 20.0;
$i = 0;
foreach ($this->products as $product) {
$i++;
if ($i > $nbmaxtoshow) {
break;
}
// check new product ?
$newapp = '';
if ($last_month < strtotime($product->date_add)) {
$newapp .= '<span class="newApp">'.$langs->trans('New').'</span> ';
}
// check updated ?
if ($last_month < strtotime($product->date_upd) && $newapp == '') {
$newapp .= '<span class="updatedApp">'.$langs->trans('Updated').'</span> ';
}
// add image or default ?
if ($product->id_default_image != '') {
$image_url = DOL_URL_ROOT.'/admin/remotestore/ajax/image.php?id_product='.urlencode((string) (((int) $product->id))).'&id_image='.urlencode((string) (((int) $product->id_default_image)));
$images = '<a href="'.$image_url.'" class="documentpreview" target="_blank" rel="noopener noreferrer" mime="image/png" title="'.dol_escape_htmltag($product->name->language[$this->lang - 1].', '.$langs->trans('Version').' '.$product->module_version).'">';
$images .= '<img class="imgstore" src="'.$image_url.'&quality=home_default" alt="" /></a>';
} else {
$images = '<img class="imgstore" src="'.DOL_URL_ROOT.'/admin/dolistore/img/NoImageAvailable.png" />';
}
// free or pay ?
if ($product->price > 0) {
$price = '<h3>'.price(price2num($product->price, 'MT'), 0, $langs, 1, -1, -1, 'EUR').' '.$langs->trans("HT").'</h3>';
$download_link = '<a target="_blank" href="'.$this->shop_url.urlencode($product->id).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
} else {
$price = '<h3>'.$langs->trans('Free').'</h3>';
$download_link = '<a class="paddingleft paddingright" target="_blank" href="'.$this->shop_url.urlencode($product->id).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
$download_link .= '<a class="paddingleft paddingright" target="_blank" rel="noopener noreferrer" href="'.$this->shop_url.urlencode($product->id).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/dolistore/img/Download-128.png" /></a>';
}
// Set and check version
$version = '';
if ($this->version_compare($product->dolibarr_min, $dolibarrversiontouse) <= 0) {
if ($this->version_compare($product->dolibarr_max, $dolibarrversiontouse) >= 0) {
//compatible
$version = '<span class="compatible">'.$langs->trans(
'CompatibleUpTo',
$product->dolibarr_max,
$product->dolibarr_min,
$product->dolibarr_max
).'</span>';
$compatible = '';
} else {
//never compatible, module expired
$version = '<span class="notcompatible">'.$langs->trans(
'NotCompatible',
$dolibarrversiontouse,
$product->dolibarr_min,
$product->dolibarr_max
).'</span>';
$compatible = 'NotCompatible';
}
} else {
//need update
$version = '<span class="compatibleafterupdate">'.$langs->trans(
'CompatibleAfterUpdate',
$dolibarrversiontouse,
$product->dolibarr_min,
$product->dolibarr_max
).'</span>';
$compatible = 'NotCompatible';
}
//output template
$html .= '<tr class="app oddeven '.dol_escape_htmltag($compatible).'">';
$html .= '<td class="center" width="160"><div class="newAppParent">';
$html .= $newapp.$images; // No dol_escape_htmltag, it is already escape html
$html .= '</div></td>';
$html .= '<td class="margeCote"><h2 class="appTitle">';
$html .= dol_escape_htmltag(dol_string_nohtmltag($product->name->language[$this->lang - 1]));
$html .= '<br><small>';
$html .= $version; // No dol_escape_htmltag, it is already escape html
$html .= '</small></h2>';
$html .= '<small> '.dol_print_date(dol_stringtotime($product->date_upd), 'dayhour').' - '.$langs->trans('Ref').': '.dol_escape_htmltag($product->reference).' - '.dol_escape_htmltag($langs->trans('Id')).': '.((int) $product->id).'</small><br>';
$html .= '<br>'.dol_escape_htmltag(dol_string_nohtmltag($product->description_short->language[$this->lang - 1]));
$html.= '</td>';
// do not load if display none
$html .= '<td class="margeCote center amount">';
$html .= $price;
$html .= '</td>';
$html .= '<td class="margeCote nowraponall">'.$download_link.'</td>';
$html .= '</tr>';
}
if (empty($this->products)) {
$html .= '<tr class=""><td colspan="3" class="center">';
$html .= '<br><br>';
$langs->load("website");
$html .= $langs->trans("noResultsWereFound").'...';
$html .= '<br><br>';
$html .= '</td></tr>';
}
if (count($this->products) > $nbmaxtoshow) {
$html .= '<tr class=""><td colspan="3" class="center">';
$html .= '<br><br>';
$html .= $langs->trans("ThereIsMoreThanXAnswers", $nbmaxtoshow).'...';
$html .= '<br><br>';
$html .= '</td></tr>';
}
return $html;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* get previous link
*
* @param string $text symbol previous
* @return string html previous link
*/
public function get_previous_link($text = '<<')
{
// phpcs:enable
return '<a href="'.$this->get_previous_url().'" class="button">'.dol_escape_htmltag($text).'</a>';
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* get next link
*
* @param string $text symbol next
* @return string html next link
*/
public function get_next_link($text = '>>')
{
// phpcs:enable
return '<a href="'.$this->get_next_url().'" class="button">'.dol_escape_htmltag($text).'</a>';
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* get previous url
*
* @return string previous url
*/
public function get_previous_url()
{
// phpcs:enable
$param_array = array();
if ($this->start < $this->per_page) {
$sub = 0;
} else {
$sub = $this->per_page;
}
$param_array['start'] = $this->start - $sub;
$param_array['end'] = $this->end - $sub;
if ($this->categorie != 0) {
$param_array['categorie'] = $this->categorie;
}
$param = http_build_query($param_array);
return $this->url."&".$param;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* get next url
*
* @return string next url
*/
public function get_next_url()
{
// phpcs:enable
$param_array = array();
if ($this->products !== null && count($this->products) < $this->per_page) {
$add = 0;
} else {
$add = $this->per_page;
}
$param_array['start'] = $this->start + $add;
$param_array['end'] = $this->end + $add;
if ($this->categorie != 0) {
$param_array['categorie'] = $this->categorie;
}
$param = http_build_query($param_array);
return $this->url."&".$param;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* version compare
*
* @param string $v1 version 1
* @param string $v2 version 2
* @return int result of compare
*/
public function version_compare($v1, $v2)
{
// phpcs:enable
$v1 = explode('.', $v1);
$v2 = explode('.', $v2);
$ret = 0;
$level = 0;
$count1 = count($v1);
$count2 = count($v2);
$maxcount = max($count1, $count2);
while ($level < $maxcount) {
$operande1 = isset($v1[$level]) ? $v1[$level] : 'x';
$operande2 = isset($v2[$level]) ? $v2[$level] : 'x';
$level++;
if (strtoupper($operande1) == 'X' || strtoupper($operande2) == 'X' || $operande1 == '*' || $operande2 == '*') {
break;
}
if ($operande1 < $operande2) {
$ret = -$level;
break;
}
if ($operande1 > $operande2) {
$ret = $level;
break;
}
}
//print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'<br>'."\n";
return $ret;
}
}

View file

@ -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';
@ -166,14 +165,14 @@ class ExternalModules
*
* @param string $resource Resource name
* @param array<string, mixed>|false $options Options for the request
* @return array{status_code:int,response:null|string|array<string,mixed>,header:string}
* @return array{status_code:int,response:null|string|array<string,mixed>}
*/
public function callApi($resource, $options = false)
{
// If no dolistore_api_key is set, we can't access the API
if (empty($this->dolistore_api_key) || empty($this->dolistore_api_url)) {
return array('status_code' => 0, 'response' => null, 'header' => '');
return array('status_code' => 0, 'response' => null);
}
// Add basic auth if needed
@ -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 = '<h3>'.price(price2num($product["price_ttc"], 'MT'), 0, $langs, 1, -1, -1, 'EUR').' '.$langs->trans("TTC").'</h3>';
$download_link = '<a target="_blank" href="'.$this->shop_url.urlencode($product['id']).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
$download_link = '<a target="_blank" href="'.$this->shop_url.'/product.php?id='.((int) $product['id']).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
} else {
$download_link = '#';
$price = '<h3>'.$langs->trans('Free').'</h3>';
@ -377,7 +382,7 @@ class ExternalModules
}
if ($product['source'] === 'dolistore') {
$download_link = '<a class="paddingleft paddingright" target="_blank" href="'.$this->shop_url.urlencode($product["id"]).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
$download_link = '<a class="paddingleft paddingright" target="_blank" href="'.$this->shop_url.'/product.php?id='.((int) $product["id"]).'"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/follow.png" /></a>';
if (!empty($product['direct-download']) && $product['direct-download'] == 'yes') {
$download_link .= '<a class="paddingleft paddingright" target="_blank" href="'.$product["download_link"].'" rel="noopener noreferrer"><img width="32" src="'.DOL_URL_ROOT.'/admin/remotestore/img/Download-128.png" /></a>';
}
@ -603,8 +608,7 @@ class ExternalModules
/**
* Check the status code of the request
*
* @param array{status_code:int,response:null|string|array{errors:array{code:int,message:string}[]},header:string} $request Response elements of CURL request
*
* @param array{status_code:int,response:null|string|array{errors:array{code:int,message:string}[]}} $request Response elements of CURL request
* @return string|null
*/
protected function checkStatusCode($request)
@ -655,6 +659,8 @@ class ExternalModules
dol_mkdir($cache_folder, DOL_DATA_ROOT);
}
$yaml = '';
if (!file_exists($cache_file) || filemtime($cache_file) < (dol_now() - $cache_time)) {
// We get remote url
$result = getURLContent($file_source_url);
@ -746,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;
@ -824,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'
];

View file

@ -193,36 +193,10 @@ h2.appTitle small{
font-weight: normal;
}
tr.NotCompatible{
/* IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=25)";
/* IE 5-7 */
filter: alpha(opacity=25);
/* Netscape */
-moz-opacity: 0.25;
/* Safari 1.x */
-khtml-opacity: 0.25;
/* Good browsers */
opacity: 0.25;
opacity: 0.5;
}
tr.NotCompatible:hover{
/* IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
/* IE 5-7 */
filter: alpha(opacity=100);
/* Netscape */
-moz-opacity: 1;
/* Safari 1.x */
-khtml-opacity: 1;
/* Good browsers */
opacity: 1;
opacity: 0.7;
}
@media only screen and (min-width: 1150px) {
#categorieArea{

View file

@ -5225,7 +5225,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0, $srco
'email' => 'at', 'establishment' => 'building', 'edit' => 'pencil-alt', 'entity' => 'globe',
'graph' => 'chart-line', 'grip_title' => 'arrows-alt', 'grip' => 'arrows-alt', 'help' => 'question-circle',
'generic' => 'file', 'holiday' => 'umbrella-beach',
'info' => 'info-circle', 'inventory' => 'boxes', 'intracommreport' => 'globe-europe', 'jobprofile' => 'cogs',
'info' => 'info-circle', 'info_black' => 'info-circle', 'inventory' => 'boxes', 'intracommreport' => 'globe-europe', 'jobprofile' => 'cogs',
'knowledgemanagement' => 'ticket-alt', 'label' => 'layer-group', 'layout' => 'columns', 'line' => 'bars', 'loan' => 'money-bill-alt',
'member' => 'user-alt', 'meeting' => 'chalkboard-teacher', 'mrp' => 'cubes', 'next' => 'arrow-alt-circle-right',
'trip' => 'wallet', 'expensereport' => 'wallet', 'group' => 'users', 'movement' => 'people-carry',
@ -5291,7 +5291,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0, $srco
if (in_array($pictowithouttext, array('dollyrevert', 'member', 'members', 'contract', 'group', 'resource', 'shipment', 'reception'))) {
$morecss .= ' em092';
}
if (in_array($pictowithouttext, array('conferenceorbooth', 'collab', 'eventorganization', 'holiday', 'info', 'project', 'workstation'))) {
if (in_array($pictowithouttext, array('conferenceorbooth', 'collab', 'eventorganization', 'holiday', 'info', 'info_black', 'project', 'workstation'))) {
$morecss .= ' em088';
}
if (in_array($pictowithouttext, array('asset', 'intervention', 'payment', 'loan', 'partnership', 'stock', 'technic'))) {
@ -5325,7 +5325,7 @@ function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0, $srco
'order' => 'infobox-commande',
'user' => 'infobox-adherent', 'users' => 'infobox-adherent',
'error' => 'pictoerror', 'warning' => 'pictowarning', 'switch_on' => 'font-status4', 'switch_on_warning' => 'font-status4 warning', 'switch_on_red' => 'font-status8',
'holiday' => 'infobox-holiday', 'info' => 'opacityhigh', 'invoice' => 'infobox-commande',
'holiday' => 'infobox-holiday', 'info' => 'opacityhigh', 'info_black' => 'font-status1', 'invoice' => 'infobox-commande',
'knowledgemanagement' => 'infobox-contrat rotate90', 'loan' => 'infobox-bank_account',
'payment' => 'infobox-bank_account', 'payment_vat' => 'infobox-bank_account', 'poll' => 'infobox-adherent', 'pos' => 'infobox-bank_account', 'project' => 'infobox-project', 'projecttask' => 'infobox-project',
'propal' => 'infobox-propal', 'proposal' => 'infobox-propal','private' => 'infobox-project',
@ -5449,7 +5449,7 @@ function getImgPictoNameList()
'filter', 'file', 'file-o', 'file-code', 'file-export', 'file-import', 'file-upload', 'autofill', 'folder', 'folder-open', 'folder-plus', 'font',
'gears', 'generate', 'generic', 'globe', 'globe-americas', 'graph', 'grip', 'grip_title', 'group',
'hands-helping', 'help', 'holiday',
'id-card', 'images', 'incoterm', 'info', 'intervention', 'inventory', 'intracommreport', 'jobprofile',
'id-card', 'images', 'incoterm', 'info', 'info_black', 'intervention', 'inventory', 'intracommreport', 'jobprofile',
'key', 'knowledgemanagement',
'label', 'language', 'layout', 'line', 'link', 'list', 'list-alt', 'listlight', 'loan', 'lock', 'lot', 'long-arrow-alt-right',
'margin', 'map-marker-alt', 'member', 'meeting', 'minus', 'money-bill-alt', 'movement', 'mrp', 'note', 'next',

View file

@ -234,7 +234,7 @@ Updated=Updated
AchatTelechargement=Buy / Download
GoModuleSetupArea=To deploy/install a new module, go to the Module setup area: <a href="%s">%s</a>.
DoliStoreDesc=DoliStore, the official market place for Dolibarr ERP/CRM external modules
CommunityModulesDesc=dolibarr-community-modules, This repository contains all community modules for Dolibarr ERP CRM.
CommunityModulesDesc=Dolibarr community modules repository. This repository contains all community modules for Dolibarr ERP CRM.
DoliPartnersDesc=List of companies providing custom-developed modules or features.<br>Note: since Dolibarr is an open source application, <i>anyone</i> experienced in PHP programming should be able to develop a module.
WebSiteDesc=External websites for more add-on (non-core) modules...
DevelopYourModuleDesc=Some solutions to develop your own module...
@ -2635,3 +2635,4 @@ SelectFeatureToTest=Select the feature to test
AIModelForFeature=AI model for features (AI service %s)
communityRepo=Community repository
online=Online
NotConnected=Not connected

View file

@ -267,6 +267,12 @@ if (getDolGlobalString('THIRDPARTY_QUICKSEARCH_ON_FIELDS')) {
$fieldstosearchall = dolExplodeIntoArray($conf->global->THIRDPARTY_QUICKSEARCH_ON_FIELDS);
}
$parameters = ['fieldstosearchall' => $fieldstosearchall];
$reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action);
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
$fieldstosearchall = array_merge($fieldstosearchall, $hookmanager->resArray);
// Define list of fields to show into list
$checkedcustomercode = (in_array($contextpage, array('thirdpartylist', 'customerlist', 'prospectlist', 'poslist')) ? '1' : '0');