dolibarr 20.0.2
websitepage.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2018 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
6 * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
33//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
34
39{
43 public $element = 'websitepage';
44
48 public $table_element = 'website_page';
49
53 public $picto = 'file-code';
54
58 public $fk_element = 'fk_website_page';
59
63 protected $childtablesoncascade = array('categorie_website_page');
64
65
69 public $fk_website;
70
71 public $fk_page; // If translation of another page
72
73 public $pageurl;
74 public $aliasalt;
75 public $type_container;
76
80 public $title;
84 public $description;
88 public $image;
92 public $keywords;
96 public $lang;
97
98 public $allowed_in_frames;
99 public $htmlheader;
100 public $content;
101 public $grabbed_from;
102
106 public $status;
107
108 public $fk_user_creat;
109 public $fk_user_modif;
110
114 public $author_alias;
115
119 public $object_type;
120
124 public $fk_object;
125
129 public $newid;
130
131
132 const STATUS_DRAFT = 0; // offline
133 const STATUS_VALIDATED = 1; // online
134
135
160 // BEGIN MODULEBUILDER PROPERTIES
164 public $fields = array(
165 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id'),
166 'pageurl' => array('type' => 'varchar(16)', 'label' => 'WEBSITE_PAGENAME', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1, 'comment' => 'Ref/alias of page'),
167 'aliasalt' => array('type' => 'varchar(255)', 'label' => 'AliasAlt', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'index' => 0, 'position' => 11, 'searchall' => 0, 'comment' => 'Alias alternative of page'),
168 'type_container' => array('type' => 'varchar(16)', 'label' => 'Type', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'index' => 0, 'position' => 12, 'comment' => 'Type of container'),
169 'title' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1, 'help' => 'UseTextBetween5And70Chars'),
170 'description' => array('type' => 'varchar(255)', 'label' => 'Description', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'searchall' => 1),
171 'image' => array('type' => 'varchar(255)', 'label' => 'Image', 'enabled' => 1, 'visible' => 1, 'position' => 32, 'searchall' => 0, 'help' => 'Relative path of media. Used if Type is "blogpost"'),
172 'keywords' => array('type' => 'varchar(255)', 'label' => 'Keywords', 'enabled' => 1, 'visible' => 1, 'position' => 45, 'searchall' => 0),
173 'lang' => array('type' => 'varchar(6)', 'label' => 'Lang', 'enabled' => 1, 'notnull' => -1, 'visible' => 1, 'position' => 45, 'searchall' => 0),
174 //'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
175 'fk_website' => array('type' => 'integer', 'label' => 'WebsiteId', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 40, 'searchall' => 0, 'foreignkey' => 'websitepage.rowid'),
176 'fk_page' => array('type' => 'integer', 'label' => 'ParentPageId', 'enabled' => 1, 'visible' => 1, 'notnull' => -1, 'position' => 45, 'searchall' => 0, 'foreignkey' => 'website.rowid'),
177 'allowed_in_frames' => array('type' => 'integer', 'label' => 'AllowedInFrames', 'enabled' => 1, 'visible' => -1, 'position' => 48, 'searchall' => 0, 'default' => '0'),
178 'htmlheader' => array('type' => 'html', 'label' => 'HtmlHeader', 'enabled' => 1, 'visible' => 0, 'position' => 50, 'searchall' => 0),
179 'content' => array('type' => 'mediumtext', 'label' => 'Content', 'enabled' => 1, 'visible' => 0, 'position' => 51, 'searchall' => 0),
180 'grabbed_from' => array('type' => 'varchar(255)', 'label' => 'GrabbedFrom', 'enabled' => 1, 'visible' => 1, 'index' => 1, 'position' => 400, 'comment' => 'URL page content was grabbed from'),
181 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500),
182 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 501),
183 //'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
184 'fk_user_creat' => array('type' => 'integer', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -1, 'notnull' => true, 'position' => 510),
185 'author_alias' => array('type' => 'varchar(64)', 'label' => 'AuthorAlias', 'enabled' => 1, 'visible' => -1, 'index' => 0, 'position' => 511, 'comment' => 'Author alias'),
186 'fk_user_modif' => array('type' => 'integer', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -1, 'position' => 512),
187 //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
188 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -1, 'index' => 1, 'position' => 1000, 'notnull' => -1),
189 'object_type' => array('type' => 'varchar(255)', 'label' => 'ObjectType', 'enabled' => 1, 'visible' => 0, 'position' => 46, 'searchall' => 0, 'help' => ''),
190 'fk_object' => array('type' => 'varchar(255)', 'label' => 'ObjectId', 'enabled' => 1, 'visible' => 0, 'position' => 47, 'searchall' => 0, 'help' => '')
191 );
192 // END MODULEBUILDER PROPERTIES
193
194
200 public function __construct(DoliDB $db)
201 {
202 $this->db = $db;
203 }
204
212 public function create(User $user, $notrigger = 0)
213 {
214 $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
215 $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
216 if ($this->aliasalt) {
217 $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
218 }
219
220 $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
221 $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
222 $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
223
224 // Remove spaces and be sure we have main language only
225 $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
226
227 return $this->createCommon($user, $notrigger);
228 }
229
241 public function fetch($id, $website_id = null, $page = null, $aliasalt = null)
242 {
243 dol_syslog(__METHOD__, LOG_DEBUG);
244
245 $sql = 'SELECT';
246 $sql .= ' t.rowid,';
247 $sql .= " t.fk_website,";
248 $sql .= ' t.type_container,';
249 $sql .= " t.pageurl,";
250 $sql .= " t.aliasalt,";
251 $sql .= " t.title,";
252 $sql .= " t.description,";
253 $sql .= " t.image,";
254 $sql .= " t.keywords,";
255 $sql .= " t.htmlheader,";
256 $sql .= " t.content,";
257 $sql .= " t.lang,";
258 $sql .= " t.fk_page,";
259 $sql .= " t.allowed_in_frames,";
260 $sql .= " t.status,";
261 $sql .= " t.grabbed_from,";
262 $sql .= " t.date_creation,";
263 $sql .= " t.tms as date_modification,";
264 $sql .= " t.fk_user_creat,";
265 $sql .= " t.author_alias,";
266 $sql .= " t.fk_user_modif,";
267 $sql .= " t.import_key,";
268 $sql .= " t.object_type,";
269 $sql .= " t.fk_object";
270 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
271 //$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
272 $sql .= ' WHERE 1 = 1';
273 if ($id > 0) {
274 $sql .= ' AND t.rowid = '.((int) $id);
275 } else {
276 if ($id < 0) {
277 $sql .= ' AND t.rowid <> '.abs($id);
278 }
279 if (null !== $website_id) {
280 $sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'";
281 if ($page) {
282 $pagetouse = $page;
283 $langtouse = '';
284 $tmppage = explode('/', $page);
285 if (!empty($tmppage[1])) {
286 $pagetouse = $tmppage[1];
287 if (strlen($tmppage[0])) {
288 $langtouse = $tmppage[0];
289 }
290 }
291 $sql .= " AND t.pageurl = '".$this->db->escape($pagetouse)."'";
292 if ($langtouse) {
293 $sql .= " AND t.lang = '".$this->db->escape($langtouse)."'";
294 }
295 }
296 if ($aliasalt) {
297 $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')";
298 }
299 }
300 }
301 $sql .= $this->db->plimit(1);
302
303 $resql = $this->db->query($sql);
304 if ($resql) {
305 $numrows = $this->db->num_rows($resql);
306 if ($numrows) {
307 $obj = $this->db->fetch_object($resql);
308
309 $this->id = $obj->rowid;
310
311 $this->fk_website = $obj->fk_website;
312 $this->type_container = $obj->type_container;
313
314 $this->pageurl = $obj->pageurl;
315 $this->ref = $obj->pageurl;
316 $this->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
317
318 $this->title = $obj->title;
319 $this->description = $obj->description;
320 $this->image = $obj->image;
321 $this->keywords = $obj->keywords;
322 $this->htmlheader = $obj->htmlheader;
323 $this->content = $obj->content;
324 $this->lang = $obj->lang;
325 $this->fk_page = $obj->fk_page;
326 $this->allowed_in_frames = $obj->allowed_in_frames;
327 $this->status = $obj->status;
328 $this->grabbed_from = $obj->grabbed_from;
329 $this->date_creation = $this->db->jdate($obj->date_creation);
330 $this->date_modification = $this->db->jdate($obj->date_modification);
331 $this->fk_user_creat = $obj->fk_user_creat;
332 $this->author_alias = $obj->author_alias;
333 $this->fk_user_modif = $obj->fk_user_modif;
334 $this->import_key = $obj->import_key;
335 $this->object_type = $obj->object_type;
336 $this->fk_object = $obj->fk_object;
337 }
338 $this->db->free($resql);
339
340 if ($numrows) {
341 return 1;
342 } else {
343 return 0;
344 }
345 } else {
346 $this->errors[] = 'Error '.$this->db->lasterror();
347 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
348
349 return -1;
350 }
351 }
352
366 public function fetchAll($websiteid = '', $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
367 {
368 dol_syslog(__METHOD__, LOG_DEBUG);
369
370 $records = array();
371
372 $sql = 'SELECT';
373 $sql .= ' t.rowid,';
374 $sql .= " t.fk_website,";
375 $sql .= " t.type_container,";
376 $sql .= " t.pageurl,";
377 $sql .= " t.aliasalt,";
378 $sql .= " t.title,";
379 $sql .= " t.description,";
380 $sql .= " t.image,";
381 $sql .= " t.keywords,";
382 $sql .= " t.htmlheader,";
383 $sql .= " t.content,";
384 $sql .= " t.lang,";
385 $sql .= " t.fk_page,";
386 $sql .= " t.allowed_in_frames,";
387 $sql .= " t.status,";
388 $sql .= " t.grabbed_from,";
389 $sql .= " t.date_creation,";
390 $sql .= " t.tms as date_modification,";
391 $sql .= " t.fk_user_creat,";
392 $sql .= " t.author_alias,";
393 $sql .= " t.fk_user_modif,";
394 $sql .= " t.import_key,";
395 $sql .= " t.object_type,";
396 $sql .= " t.fk_object";
397 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
398 if (!empty($websiteid)) {
399 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
400 }
401
402 // Deprecated. If we receive an array, we use it. Prefer using the USF syntax.
403 if (is_array($filter)) {
404 $sqlwhere = array();
405
406 if (count($filter) > 0) {
407 foreach ($filter as $key => $value) {
408 if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
409 $sqlwhere[] = $key." = ".((int) $value);
410 } elseif ($key == 'type_container' || $key == 't.type_container') {
411 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
412 } elseif ($key == 'lang' || $key == 't.lang') {
413 $listoflang = array();
414 $foundnull = 0;
415 foreach (explode(',', $value) as $tmpvalue) {
416 if ($tmpvalue == 'null') {
417 $foundnull++;
418 continue;
419 }
420 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
421 }
422 $stringtouse = $this->db->sanitize($key)." IN (".$this->db->sanitize(implode(',', $listoflang), 1).")";
423 if ($foundnull) {
424 $stringtouse = "(".$stringtouse." OR ".$this->db->sanitize($key)." IS NULL)";
425 }
426 $sqlwhere[] = $stringtouse;
427 } else {
428 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($value)."%'";
429 }
430 }
431 }
432 if (count($sqlwhere) > 0) {
433 if (!empty($websiteid)) {
434 $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
435 } else {
436 $sql .= " WHERE ".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
437 }
438 }
439
440 $filter = '';
441 }
442
443 $errormessage = '';
444 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
445 if ($errormessage) {
446 $this->errors[] = $errormessage;
447 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
448 return -1;
449 }
450
451 if (!empty($sortfield)) {
452 $sql .= $this->db->order($sortfield, $sortorder);
453 }
454 if (!empty($limit)) {
455 $sql .= $this->db->plimit($limit, $offset);
456 }
457
458 $resql = $this->db->query($sql);
459 if ($resql) {
460 $num = $this->db->num_rows($resql);
461
462 while ($obj = $this->db->fetch_object($resql)) {
463 $record = new self($this->db);
464
465 $record->id = $obj->rowid;
466 $record->fk_website = $obj->fk_website;
467 $record->type_container = $obj->type_container;
468 $record->pageurl = $obj->pageurl;
469 $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
470 $record->title = $obj->title;
471 $record->description = $obj->description;
472 $record->image = $obj->image;
473 $record->keywords = $obj->keywords;
474 $record->htmlheader = $obj->htmlheader;
475 $record->content = $obj->content;
476 $record->lang = $obj->lang;
477 $record->fk_page = $obj->fk_page;
478 $record->allowed_in_frames = $obj->allowed_in_frames;
479 $record->status = $obj->status;
480 $record->grabbed_from = $obj->grabbed_from;
481 $record->date_creation = $this->db->jdate($obj->date_creation);
482 $record->date_modification = $this->db->jdate($obj->date_modification);
483 $record->fk_user_creat = $obj->fk_user_creat;
484 $record->author_alias = $obj->author_alias;
485 $record->fk_user_modif = $obj->fk_user_modif;
486 $record->import_key = $obj->import_key;
487 $record->object_type = $obj->object_type;
488 $record->fk_object = $obj->fk_object;
489 //var_dump($record->id);
490 $records[$record->id] = $record;
491 }
492 $this->db->free($resql);
493
494 return $records;
495 } else {
496 $this->error = 'Error '.$this->db->lasterror();
497 $this->errors[] = $this->error;
498 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
499
500 return -1;
501 }
502 }
503
513 public function countAll($websiteid, $filter = '', $filtermode = 'AND')
514 {
515 dol_syslog(__METHOD__, LOG_DEBUG);
516
517 $result = 0;
518
519 $sql = 'SELECT COUNT(t.rowid) as nb';
520 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
521 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
522
523 // Deprecated. If we receive an array, we use it. Prefer using the USF syntax.
524 if (is_array($filter)) {
525 $sqlwhere = array();
526
527 if (count($filter) > 0) {
528 foreach ($filter as $key => $value) {
529 if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
530 $sqlwhere[] = $key." = ".((int) $value);
531 } elseif ($key == 'type_container' || $key == 't.type_container') {
532 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
533 } elseif ($key == 'lang' || $key == 't.lang') {
534 $listoflang = array();
535 $foundnull = 0;
536 foreach (explode(',', $value) as $tmpvalue) {
537 if ($tmpvalue == 'null') {
538 $foundnull++;
539 continue;
540 }
541 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
542 }
543 $stringtouse = $this->db->sanitize($key)." IN (".$this->db->sanitize(implode(',', $listoflang), 1).")";
544 if ($foundnull) {
545 $stringtouse = "(".$stringtouse." OR ".$this->db->sanitize($key)." IS NULL)";
546 }
547 $sqlwhere[] = $stringtouse;
548 } else {
549 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($value)."%'";
550 }
551 }
552 }
553 if (count($sqlwhere) > 0) {
554 if (!empty($websiteid)) {
555 $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
556 } else {
557 $sql .= " WHERE ".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
558 }
559 }
560
561 $filter = '';
562 }
563
564 $errormessage = '';
565 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
566 if ($errormessage) {
567 $this->errors[] = $errormessage;
568 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
569 return -1;
570 }
571
572 $resql = $this->db->query($sql);
573 if ($resql) {
574 $obj = $this->db->fetch_object($resql);
575 if ($obj) {
576 $result = $obj->nb;
577 }
578
579 $this->db->free($resql);
580
581 return $result;
582 } else {
583 $this->error = 'Error '.$this->db->lasterror();
584 $this->errors[] = $this->error;
585 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
586
587 return -1;
588 }
589 }
590
598 public function update(User $user, $notrigger = 0)
599 {
600 $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
601 $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
602 if ($this->aliasalt) {
603 $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
604 }
605
606 $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
607 $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
608 $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
609
610 // Remove spaces and be sure we have main language only
611 $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
612
613 if ($this->fk_page > 0) {
614 if (empty($this->lang)) {
615 $this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
616 return -1;
617 }
618 $tmppage = new WebsitePage($this->db);
619 $tmppage->fetch($this->fk_page);
620 if ($tmppage->lang == $this->lang) {
621 $this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
622 return -1;
623 }
624 }
625
626 return $this->updateCommon($user, $notrigger);
627 }
628
636 public function delete(User $user, $notrigger = 0)
637 {
638 global $conf;
639
640 $error = 0;
641
642 // Delete all child tables
643 if (!$error) {
644 foreach ($this->childtablesoncascade as $table) {
645 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
646 $sql .= " WHERE fk_website_page = ".(int) $this->id;
647
648 $result = $this->db->query($sql);
649 if (!$result) {
650 $error++;
651 $this->errors[] = $this->db->lasterror();
652 break;
653 }
654 }
655 }
656
657 if (!$error) {
658 $result = $this->deleteCommon($user, $notrigger);
659 if ($result <= 0) {
660 $error++;
661 }
662 }
663
664 if (!$error) {
665 $websiteobj = new Website($this->db);
666 $result = $websiteobj->fetch($this->fk_website);
667
668 if ($result > 0) {
669 global $dolibarr_main_data_root;
670 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websiteobj->ref;
671
672 $filealias = $pathofwebsite.'/'.$this->pageurl.'.php';
673 $filetpl = $pathofwebsite.'/page'.$this->id.'.tpl.php';
674
675 dol_delete_file($filealias);
676 dol_delete_file($filetpl);
677 } else {
678 $this->error = $websiteobj->error;
679 $this->errors = $websiteobj->errors;
680 }
681 }
682
683 if (!$error) {
684 return 1;
685 } else {
686 return -1;
687 }
688 }
689
703 public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '', $website = null)
704 {
705 global $hookmanager, $langs;
706
707 $now = dol_now();
708 $error = 0;
709
710 dol_syslog(__METHOD__, LOG_DEBUG);
711
712 $object = new self($this->db);
713
714 // Clean parameters
715 if (empty($newref) && !empty($newtitle)) {
716 $newref = strtolower(dol_sanitizeFileName(preg_replace('/\s+/', '-', $newtitle), '-', 1));
717 }
718
719 // Check parameters
720 if (empty($newref)) {
721 $langs->load("errors");
722 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE"));
723 return -1;
724 }
725
726 if ($istranslation) {
727 if (is_null($website)) {
728 $website = new Website($this->db);
729 }
730 $website->fetch($object->fk_website);
731
732 if ($website->id != $newwebsite) {
733 $langs->load("errors");
734 $this->error = $langs->trans("WebsiteMustBeSameThanClonedPageIfTranslation");
735 return -1;
736 }
737 }
738
739 $this->db->begin();
740
741 // Load source object
742 $object->fetch($fromid);
743 // Reset object
744 $object->id = 0;
745
746 // Clear fields
747 $object->ref = $newref;
748 $object->pageurl = $newref;
749 $object->aliasalt = '';
750 $object->fk_user_creat = $user->id;
751 $object->author_alias = '';
752 $object->date_creation = $now;
753 $object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
754 $object->description = $object->title;
755 if (!empty($newlang)) {
756 $object->lang = $newlang;
757 }
758
759 if ($istranslation) {
760 if ($website->lang == $newlang) {
761 // The new page is into the website language, the parent page will be 0, and we must instead update the source page later.
762 $object->fk_page = 0;
763 } else {
764 $object->fk_page = $fromid;
765 }
766 } else {
767 $object->fk_page = 0;
768 }
769
770 if (!empty($newwebsite)) {
771 $object->fk_website = $newwebsite;
772 }
773 $object->import_key = '';
774 $object->status = self::STATUS_DRAFT;
775
776 // Create clone
777 $object->context['createfromclone'] = 'createfromclone';
778 $result = $object->create($user);
779 if ($result < 0) {
780 $error++;
781 $this->error = $object->error;
782 $this->errors = $object->errors;
783 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
784 }
785
786 if ($istranslation) {
787 if ($website->lang == $newlang) {
788 // We must now update the source page to link to the new page as a translation of.
789 $sql = "UPDATE ".MAIN_DB_PREFIX."website_page SET fk_page = ".((int) $result)." WHERE rowid = ".((int) $fromid);
790
791 $result = $this->db->query($sql);
792 if (!$result) {
793 $error++;
794 $this->error = $this->db->lasterror();
795 }
796 }
797 }
798
799 unset($object->context['createfromclone']);
800
801 // End
802 if (!$error) {
803 $this->db->commit();
804
805 return $object;
806 } else {
807 $this->db->rollback();
808
809 return -1;
810 }
811 }
812
824 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
825 {
826 global $langs, $conf, $db;
827 global $dolibarr_main_authentication, $dolibarr_main_demo;
828 global $menumanager;
829
830 $result = '';
831
832 $label = '<u>'.$langs->trans("Page").'</u>';
833 $label .= '<br>';
834 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
835 $label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
836 $label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
837 $label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
838
839 $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
840
841 $linkclose = '';
842 if (empty($notooltip)) {
843 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
844 $label = $langs->trans("ShowMyObject");
845 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
846 }
847 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
848 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
849 } else {
850 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
851 }
852
853 $linkstart = '<a href="'.$url.'"';
854 $linkstart .= $linkclose.'>';
855 $linkend = '</a>';
856
857 //$linkstart = $linkend = '';
858
859 $result .= $linkstart;
860 if ($withpicto) {
861 $result .= img_picto(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
862 }
863 if ($withpicto != 2) {
864 $result .= $this->ref;
865 }
866 $result .= $linkend;
867
868 return $result;
869 }
870
877 public function getLibStatut($mode = 0)
878 {
879 return $this->LibStatut($this->status, $mode);
880 }
881
882 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
890 public function LibStatut($status, $mode = 0)
891 {
892 // phpcs:enable
893 global $langs;
894
895 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
896 global $langs;
897 //$langs->load("mymodule");
898 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
899 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
900 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
901 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
902 }
903
904 $statusType = 'status5';
905 if ($status == self::STATUS_VALIDATED) {
906 $statusType = 'status4';
907 }
908
909 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
910 }
911
922 public function setCategories($categories)
923 {
924 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
925 return $this->setCategoriesCommon($categories, Categorie::TYPE_WEBSITE_PAGE);
926 }
927
934 public function initAsSpecimen()
935 {
936 global $user;
937
938 $this->id = 0;
939
940 $now = dol_now();
941
942 $this->fk_website = 0;
943 $this->type_container = 'page';
944 $this->pageurl = 'specimen';
945 $this->aliasalt = 'specimenalt';
946 $this->title = 'My Page';
947 $this->description = 'This is my page';
948 $this->image = '';
949 $this->keywords = 'keyword1, keyword2';
950 $this->allowed_in_frames = 1;
951 $this->htmlheader = '';
952 $this->content = '<html><body>This is a html content</body></html>';
953 $this->status = self::STATUS_DRAFT;
954 $this->grabbed_from = '';
955 $this->date_creation = $now - (24 * 30 * 3600);
956 $this->date_modification = $now - (24 * 7 * 3600);
957 $this->fk_user_creat = $user->id;
958 $this->author_alias = 'mypublicpseudo';
959
960 return 1;
961 }
962}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:637
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
setCategoriesCommon($categories, $type_categ='', $remove_existing=true)
Sets object to given categories.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
Class Website.
Class Websitepage.
__construct(DoliDB $db)
Constructor.
update(User $user, $notrigger=0)
Update object into database.
create(User $user, $notrigger=0)
Create object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id, $website_id=null, $page=null, $aliasalt=null)
Load object in memory from the database.
LibStatut($status, $mode=0)
Return the label of a given status.
createFromClone(User $user, $fromid, $newref, $newlang='', $istranslation=0, $newwebsite=0, $newtitle='', $website=null)
Load an object from its id and create a new one in database.
fetchAll($websiteid='', $sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Return array of all web site pages.
getLibStatut($mode=0)
Return the label of the status.
setCategories($categories)
Sets object to given categories.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the user card (with optionally the picto) Use this->id,this->lastname,...
countAll($websiteid, $filter='', $filtermode='AND')
Count objects in the database.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.