18use Luracast\Restler\RestException;
20require_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
21require_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
22require_once DOL_DOCUMENT_ROOT.
'/core/lib/website.lib.php';
23require_once DOL_DOCUMENT_ROOT.
'/core/lib/website2.lib.php';
57 $this->website =
new Website($this->db);
58 $this->websitepage =
new WebsitePage($this->db);
76 public function get(
$id)
120 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
122 if (!DolibarrApiAccess::$user->hasRight(
'website',
'read')) {
123 throw new RestException(403);
128 $sql =
"SELECT t.rowid, t.ref";
129 $sql .=
" FROM ".$this->db->prefix().
"website as t";
130 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
137 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
141 $sqlTotals = str_replace(
'SELECT t.rowid, t.ref',
'SELECT count(t.rowid) as total', $sql);
143 $sql .= $this->db->order($sortfield, $sortorder);
148 $offset = $limit * $page;
149 $sql .= $this->db->plimit($limit + 1, $offset);
152 $result = $this->db->query($sql);
154 $num = $this->db->num_rows($result);
155 $min = min($num, ($limit <= 0 ? $num : $limit));
158 $obj = $this->db->fetch_object($result);
159 $website_static =
new Website($this->db);
160 if ($website_static->fetch($obj->rowid)) {
166 throw new RestException(503,
'Error when retrieve website list : '.$this->db->lasterror());
171 $totalsResult = $this->db->query($sqlTotals);
172 $total = $this->db->fetch_object($totalsResult)->total;
177 $obj_ret[
'data'] = $tmp;
178 $obj_ret[
'pagination'] = array(
179 'total' => (
int) $total,
181 'page_count' => (
int) ceil((
int) $total / $limit),
212 public function indexPages(
$id, $sortfield =
"t.pageurl", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
214 if (!DolibarrApiAccess::$user->hasRight(
'website',
'read')) {
215 throw new RestException(403);
218 $result = $this->website->fetch(
$id);
220 throw new RestException(404,
'Website not found');
224 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
229 $sql =
"SELECT t.rowid, t.pageurl";
230 $sql .=
" FROM ".$this->db->prefix().
"website_page as t";
231 $sql .=
" WHERE t.fk_website = ".((int)
$id);
238 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
242 $sqlTotals = str_replace(
'SELECT t.rowid, t.pageurl',
'SELECT count(t.rowid) as total', $sql);
244 $sql .= $this->db->order($sortfield, $sortorder);
249 $offset = $limit * $page;
250 $sql .= $this->db->plimit($limit + 1, $offset);
253 $result = $this->db->query($sql);
255 $num = $this->db->num_rows($result);
256 $min = min($num, ($limit <= 0 ? $num : $limit));
259 $obj = $this->db->fetch_object($result);
260 $page_static =
new WebsitePage($this->db);
261 if ($page_static->fetch($obj->rowid)) {
267 throw new RestException(503,
'Error when retrieve page list : '.$this->db->lasterror());
271 $totalsResult = $this->db->query($sqlTotals);
272 $total = $this->db->fetch_object($totalsResult)->total;
277 $obj_ret[
'data'] = $tmp;
278 $obj_ret[
'pagination'] = array(
279 'total' => (
int) $total,
281 'page_count' => (
int) ceil((
int) $total / $limit),
307 if (!DolibarrApiAccess::$user->hasRight(
'website',
'read')) {
308 throw new RestException(403);
311 $result = $this->website->fetch(
$id);
313 throw new RestException(404,
'Website not found');
317 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
320 $result = $this->websitepage->fetch($pageid);
322 throw new RestException(404,
'Page not found');
326 if ($this->websitepage->fk_website != $this->website->id) {
327 throw new RestException(404,
'Page not found for this website');
356 if (!DolibarrApiAccess::$user->hasRight(
'website',
'write')) {
357 throw new RestException(403);
360 $result = $this->website->fetch(
$id);
362 throw new RestException(404,
'Website not found');
366 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
369 $result = $this->websitepage->fetch($pageid);
371 throw new RestException(404,
'Page not found');
375 if ($this->websitepage->fk_website != $this->website->id) {
376 throw new RestException(404,
'Page not found for this website');
383 foreach ($request_data as $field => $value) {
384 if ($field ==
'id' || $field ==
'rowid') {
387 if ($field ==
'fk_website') {
391 if ($field ===
'caller') {
392 $this->websitepage->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
395 if ($field ==
'array_options' && is_array($value)) {
396 foreach ($value as $index => $val) {
401 $this->websitepage->$field = $this->
_checkValForAPI($field, $value, $this->websitepage);
406 if ($phpfullcodestringold != $phpfullcodestring) {
407 if (!DolibarrApiAccess::$user->hasRight(
'website',
'writephp')) {
408 throw new RestException(403,
'NotAllowedToAddDynamicContent');
413 $this->websitepage->content = preg_replace(
'/<head>.*<\/head>/ims',
'', $this->websitepage->content);
416 $result = $this->websitepage->update(DolibarrApiAccess::$user);
418 throw new RestException(500, $this->websitepage->errorsToString());
455 unset(
$object->barcode_type_coder);
458 unset(
$object->total_localtax1);
459 unset(
$object->total_localtax2);
463 unset(
$object->shipping_method_id);
465 unset(
$object->label_incoterms);
466 unset(
$object->location_incoterms);
467 unset(
$object->multicurrency_code);
468 unset(
$object->multicurrency_tx);
469 unset(
$object->multicurrency_total_ht);
470 unset(
$object->multicurrency_total_ttc);
471 unset(
$object->multicurrency_total_tva);
472 unset(
$object->multicurrency_total_localtax1);
473 unset(
$object->multicurrency_total_localtax2);
475 unset(
$object->mode_reglement_id);
476 unset(
$object->cond_reglement_id);
477 unset(
$object->demand_reason_id);
478 unset(
$object->transport_mode_id);
479 unset(
$object->shipping_method);
483 unset(
$object->actiontypecode);
486 unset(
$object->user_closing_id);
488 unset(
$object->totalpaid_multicurrency);
489 unset(
$object->cond_reglement_supplier_id);
490 unset(
$object->deposit_percent);
492 unset(
$object->array_languages);
494 unset(
$object->contacts_ids_internal);
495 unset(
$object->other_linked_objects);
496 unset(
$object->linkedObjectsIds);
503 unset(
$object->user_validation_id);
524 if (empty(
$id) && empty($ref)) {
525 throw new RestException(400,
'bad value for parameter id or ref');
528 if (!DolibarrApiAccess::$user->hasRight(
'website',
'read')) {
529 throw new RestException(403);
532 $result = $this->website->fetch(
$id, $ref);
534 throw new RestException(404,
'Website not found');
538 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
556 global $dolibarr_main_data_root;
558 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$website->ref;
560 $filemaster = $pathofwebsite.
'/master.inc.php';
561 $filealias = $pathofwebsite.
'/'.$websitepage->pageurl.
'.php';
562 $filetpl = $pathofwebsite.
'/page'.$websitepage->id.
'.tpl.php';
569 dol_syslog(
"Failed to write the master file ".$filemaster, LOG_WARNING);
575 dol_syslog(
"Failed to write the alias file ".basename($filealias), LOG_WARNING);
581 dol_syslog(
"Failed to write the tpl file ".$filetpl, LOG_WARNING);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
_checkValExtrafieldsForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
Check access by user to a given resource.
indexPages($id, $sortfield="t.pageurl", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
List pages of a website.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
List websites.
getByRef($ref)
Get properties of a website object by ref.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
putPage($id, $pageid, $request_data=null)
Update a website page.
__construct()
Constructor.
getPage($id, $pageid)
Get properties of a website page by id.
_regeneratePageFiles($website, $websitepage)
Regenerate static page files on disk (master.inc.php, alias, tpl content).
_fetchWebsite($id, $ref='')
Get properties of a website object.
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
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)
dolSaveMasterFile($filemaster)
Save content of a page on disk.
dolSavePageAlias($filealias, $object, $objectpage)
Save an alias page on disk (A page that include the reference page).
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold=0)
Save content of a page on disk (page name is generally ID_of_page.php).