dolibarr 18.0.8
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 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
31//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
32
37{
41 public $element = 'websitepage';
42
46 public $table_element = 'website_page';
47
51 public $picto = 'file-code';
52
56 public $fk_element = 'fk_website_page';
57
61 protected $childtablesoncascade = array('categorie_website_page');
62
63
67 public $fk_website;
68
69 public $fk_page; // If translation of another page
70
71 public $pageurl;
72 public $aliasalt;
73 public $type_container;
74
78 public $title;
82 public $description;
86 public $image;
90 public $keywords;
94 public $lang;
95
96 public $allowed_in_frames;
97 public $htmlheader;
98 public $content;
99 public $grabbed_from;
100
104 public $status;
105
109 public $date_creation;
110
114 public $date_modification;
115
116 public $fk_user_creat;
117 public $fk_user_modif;
118
122 public $author_alias;
123
127 public $object_type;
128
132 public $fk_object;
133
134 const STATUS_DRAFT = 0; // offline
135 const STATUS_VALIDATED = 1; // online
136
137
162 // BEGIN MODULEBUILDER PROPERTIES
166 public $fields = array(
167 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
168 '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'),
169 'aliasalt' =>array('type'=>'varchar(255)', 'label'=>'AliasAlt', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>11, 'searchall'=>0, 'comment'=>'Alias alternative of page'),
170 'type_container' =>array('type'=>'varchar(16)', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>12, 'comment'=>'Type of container'),
171 'title' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'help'=>'UseTextBetween5And70Chars'),
172 'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1),
173 '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"'),
174 'keywords' =>array('type'=>'varchar(255)', 'label'=>'Keywords', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
175 'lang' =>array('type'=>'varchar(6)', 'label'=>'Lang', 'enabled'=>1, 'notnull'=>-1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
176 //'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
177 'fk_website' =>array('type'=>'integer', 'label'=>'WebsiteId', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>40, 'searchall'=>0, 'foreignkey'=>'websitepage.rowid'),
178 'fk_page' =>array('type'=>'integer', 'label'=>'ParentPageId', 'enabled'=>1, 'visible'=>1, 'notnull'=>-1, 'position'=>45, 'searchall'=>0, 'foreignkey'=>'website.rowid'),
179 'allowed_in_frames' =>array('type'=>'integer', 'label'=>'AllowedInFrames', 'enabled'=>1, 'visible'=>-1, 'position'=>48, 'searchall'=>0, 'default'=>0),
180 'htmlheader' =>array('type'=>'html', 'label'=>'HtmlHeader', 'enabled'=>1, 'visible'=>0, 'position'=>50, 'searchall'=>0),
181 'content' =>array('type'=>'mediumtext', 'label'=>'Content', 'enabled'=>1, 'visible'=>0, 'position'=>51, 'searchall'=>0),
182 'grabbed_from' =>array('type'=>'varchar(255)', 'label'=>'GrabbedFrom', 'enabled'=>1, 'visible'=>1, 'index'=>1, 'position'=>400, 'comment'=>'URL page content was grabbed from'),
183 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500),
184 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>501),
185 //'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
186 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>510),
187 'author_alias' =>array('type'=>'varchar(64)', 'label'=>'AuthorAlias', 'enabled'=>1, 'visible'=>-1, 'index'=>0, 'position'=>511, 'comment'=>'Author alias'),
188 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
189 //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
190 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>1, 'position'=>1000, 'notnull'=>-1),
191 'object_type' => array('type' => 'varchar(255)', 'label' => 'ObjectType', 'enabled'=>1, 'visible'=>0, 'position'=>46, 'searchall'=>0, 'help'=>''),
192 'fk_object' => array('type' => 'varchar(255)', 'label' => 'ObjectId', 'enabled'=>1, 'visible'=>0, 'position'=>47, 'searchall'=>0, 'help'=>'')
193 );
194 // END MODULEBUILDER PROPERTIES
195
196
202 public function __construct(DoliDB $db)
203 {
204 $this->db = $db;
205 }
206
214 public function create(User $user, $notrigger = false)
215 {
216 $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
217 $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
218 if ($this->aliasalt) {
219 $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
220 }
221
222 $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
223 $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
224 $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
225
226 // Remove spaces and be sure we have main language only
227 $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
228
229 // Test if page contains dynamic PHP content
230 if (!$user->hasRight('website', 'writephp')) {
231 // Check there is no PHP content into the imported file (must be only HTML + JS)
232 $phpcontent = dolKeepOnlyPhpCode($this->content);
233
234 if ($phpcontent) {
235 $this->error = 'Error: you try to create a page with PHP content without having permissions for that.';
236 $this->errors = $this->error;
237 return -1;
238 }
239 }
240
241 return $this->createCommon($user, $notrigger);
242 }
243
256 public function fetch($id, $website_id = null, $page = null, $aliasalt = null)
257 {
258 dol_syslog(__METHOD__, LOG_DEBUG);
259
260 $sql = 'SELECT';
261 $sql .= ' t.rowid,';
262 $sql .= " t.fk_website,";
263 $sql .= ' t.type_container,';
264 $sql .= " t.pageurl,";
265 $sql .= " t.aliasalt,";
266 $sql .= " t.title,";
267 $sql .= " t.description,";
268 $sql .= " t.image,";
269 $sql .= " t.keywords,";
270 $sql .= " t.htmlheader,";
271 $sql .= " t.content,";
272 $sql .= " t.lang,";
273 $sql .= " t.fk_page,";
274 $sql .= " t.allowed_in_frames,";
275 $sql .= " t.status,";
276 $sql .= " t.grabbed_from,";
277 $sql .= " t.date_creation,";
278 $sql .= " t.tms as date_modification,";
279 $sql .= " t.fk_user_creat,";
280 $sql .= " t.author_alias,";
281 $sql .= " t.fk_user_modif,";
282 $sql .= " t.import_key,";
283 $sql .= " t.object_type,";
284 $sql .= " t.fk_object";
285 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
286 //$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
287 $sql .= ' WHERE 1 = 1';
288 if ($id > 0) {
289 $sql .= ' AND t.rowid = '.((int) $id);
290 } else {
291 if ($id < 0) {
292 $sql .= ' AND t.rowid <> '.abs($id);
293 }
294 if (null !== $website_id) {
295 $sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'";
296 if ($page) {
297 $pagetouse = $page;
298 $langtouse = '';
299 $tmppage = explode('/', $page);
300 if (!empty($tmppage[1])) {
301 $pagetouse = $tmppage[1];
302 if (strlen($tmppage[0])) {
303 $langtouse = $tmppage[0];
304 }
305 }
306 $sql .= " AND t.pageurl = '".$this->db->escape($pagetouse)."'";
307 if ($langtouse) {
308 $sql .= " AND t.lang = '".$this->db->escape($langtouse)."'";
309 }
310 }
311 if ($aliasalt) {
312 $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')";
313 }
314 }
315 }
316 $sql .= $this->db->plimit(1);
317
318 $resql = $this->db->query($sql);
319 if ($resql) {
320 $numrows = $this->db->num_rows($resql);
321 if ($numrows) {
322 $obj = $this->db->fetch_object($resql);
323
324 $this->id = $obj->rowid;
325
326 $this->fk_website = $obj->fk_website;
327 $this->type_container = $obj->type_container;
328
329 $this->pageurl = $obj->pageurl;
330 $this->ref = $obj->pageurl;
331 $this->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
332
333 $this->title = $obj->title;
334 $this->description = $obj->description;
335 $this->image = $obj->image;
336 $this->keywords = $obj->keywords;
337 $this->htmlheader = $obj->htmlheader;
338 $this->content = $obj->content;
339 $this->lang = $obj->lang;
340 $this->fk_page = $obj->fk_page;
341 $this->allowed_in_frames = $obj->allowed_in_frames;
342 $this->status = $obj->status;
343 $this->grabbed_from = $obj->grabbed_from;
344 $this->date_creation = $this->db->jdate($obj->date_creation);
345 $this->date_modification = $this->db->jdate($obj->date_modification);
346 $this->fk_user_creat = $obj->fk_user_creat;
347 $this->author_alias = $obj->author_alias;
348 $this->fk_user_modif = $obj->fk_user_modif;
349 $this->import_key = $obj->import_key;
350 $this->object_type = $obj->object_type;
351 $this->fk_object = $obj->fk_object;
352 }
353 $this->db->free($resql);
354
355 if ($numrows) {
356 return 1;
357 } else {
358 return 0;
359 }
360 } else {
361 $this->errors[] = 'Error '.$this->db->lasterror();
362 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
363
364 return -1;
365 }
366 }
367
380 public function fetchAll($websiteid, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
381 {
382 dol_syslog(__METHOD__, LOG_DEBUG);
383
384 $records = array();
385
386 $sql = 'SELECT';
387 $sql .= ' t.rowid,';
388 $sql .= " t.fk_website,";
389 $sql .= " t.type_container,";
390 $sql .= " t.pageurl,";
391 $sql .= " t.aliasalt,";
392 $sql .= " t.title,";
393 $sql .= " t.description,";
394 $sql .= " t.image,";
395 $sql .= " t.keywords,";
396 $sql .= " t.htmlheader,";
397 $sql .= " t.content,";
398 $sql .= " t.lang,";
399 $sql .= " t.fk_page,";
400 $sql .= " t.allowed_in_frames,";
401 $sql .= " t.status,";
402 $sql .= " t.grabbed_from,";
403 $sql .= " t.date_creation,";
404 $sql .= " t.tms as date_modification,";
405 $sql .= " t.fk_user_creat,";
406 $sql .= " t.author_alias,";
407 $sql .= " t.fk_user_modif,";
408 $sql .= " t.import_key,";
409 $sql .= " t.object_type,";
410 $sql .= " t.fk_object";
411 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
412 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
413 // Manage filter (same than into countAll)
414 $sqlwhere = array();
415 if (count($filter) > 0) {
416 foreach ($filter as $key => $value) {
417 if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
418 $sqlwhere[] = $key." = ".((int) $value);
419 } elseif ($key == 'type_container' || $key == 't.type_container') {
420 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
421 } elseif ($key == 'lang' || $key == 't.lang') {
422 $listoflang = array();
423 $foundnull = 0;
424 foreach (explode(',', $value) as $tmpvalue) {
425 if ($tmpvalue == 'null') {
426 $foundnull++;
427 continue;
428 }
429 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
430 }
431 $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
432 if ($foundnull) {
433 $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
434 }
435 $sqlwhere[] = $stringtouse;
436 } else {
437 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
438 }
439 }
440 }
441 if (count($sqlwhere) > 0) {
442 $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
443 }
444
445 if (!empty($sortfield)) {
446 $sql .= $this->db->order($sortfield, $sortorder);
447 }
448 if (!empty($limit)) {
449 $sql .= $this->db->plimit($limit, $offset);
450 }
451
452 $resql = $this->db->query($sql);
453 if ($resql) {
454 $num = $this->db->num_rows($resql);
455
456 while ($obj = $this->db->fetch_object($resql)) {
457 $record = new self($this->db);
458
459 $record->id = $obj->rowid;
460 $record->fk_website = $obj->fk_website;
461 $record->type_container = $obj->type_container;
462 $record->pageurl = $obj->pageurl;
463 $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
464 $record->title = $obj->title;
465 $record->description = $obj->description;
466 $record->image = $obj->image;
467 $record->keywords = $obj->keywords;
468 $record->htmlheader = $obj->htmlheader;
469 $record->content = $obj->content;
470 $record->lang = $obj->lang;
471 $record->fk_page = $obj->fk_page;
472 $record->allowed_in_frames = $obj->allowed_in_frames;
473 $record->status = $obj->status;
474 $record->grabbed_from = $obj->grabbed_from;
475 $record->date_creation = $this->db->jdate($obj->date_creation);
476 $record->date_modification = $this->db->jdate($obj->date_modification);
477 $record->fk_user_creat = $obj->fk_user_creat;
478 $record->author_alias = $obj->author_alias;
479 $record->fk_user_modif = $obj->fk_user_modif;
480 $record->import_key = $obj->import_key;
481 $record->object_type = $obj->object_type;
482 $record->fk_object = $obj->fk_object;
483 //var_dump($record->id);
484 $records[$record->id] = $record;
485 }
486 $this->db->free($resql);
487
488 return $records;
489 } else {
490 $this->error = 'Error '.$this->db->lasterror();
491 $this->errors[] = $this->error;
492 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
493
494 return -1;
495 }
496 }
497
506 public function countAll($websiteid, array $filter = array(), $filtermode = 'AND')
507 {
508 dol_syslog(__METHOD__, LOG_DEBUG);
509
510 $result = 0;
511
512 $sql = 'SELECT COUNT(t.rowid) as nb';
513 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
514 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
515 // Manage filter (same than into fetchAll)
516 $sqlwhere = array();
517 if (count($filter) > 0) {
518 foreach ($filter as $key => $value) {
519 if ($key == 't.rowid' || $key == 't.fk_website' || $key == 'status') {
520 $sqlwhere[] = $key." = ".((int) $value);
521 } elseif ($key == 'type_container') {
522 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
523 } elseif ($key == 'lang' || $key == 't.lang') {
524 $listoflang = array();
525 $foundnull = 0;
526 foreach (explode(',', $value) as $tmpvalue) {
527 if ($tmpvalue == 'null') {
528 $foundnull++;
529 continue;
530 }
531 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
532 }
533 $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
534 if ($foundnull) {
535 $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
536 }
537 $sqlwhere[] = $stringtouse;
538 } else {
539 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
540 }
541 }
542 }
543 if (count($sqlwhere) > 0) {
544 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
545 }
546
547 $resql = $this->db->query($sql);
548 if ($resql) {
549 $obj = $this->db->fetch_object($resql);
550 if ($obj) {
551 $result = $obj->nb;
552 }
553
554 $this->db->free($resql);
555
556 return $result;
557 } else {
558 $this->error = 'Error '.$this->db->lasterror();
559 $this->errors[] = $this->error;
560 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
561
562 return -1;
563 }
564 }
565
573 public function update(User $user, $notrigger = false)
574 {
575 $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
576 $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
577 if ($this->aliasalt) {
578 $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
579 }
580
581 $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
582 $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
583 $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
584
585 // Remove spaces and be sure we have main language only
586 $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
587
588 if ($this->fk_page > 0) {
589 if (empty($this->lang)) {
590 $this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
591 return -1;
592 }
593 $tmppage = new WebsitePage($this->db);
594 $tmppage->fetch($this->fk_page);
595 if ($tmppage->lang == $this->lang) {
596 $this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
597 return -1;
598 }
599 }
600
601 return $this->updateCommon($user, $notrigger);
602 }
603
611 public function delete(User $user, $notrigger = false)
612 {
613 global $conf;
614
615 $error = 0;
616
617 // Delete all child tables
618 if (!$error) {
619 foreach ($this->childtablesoncascade as $table) {
620 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
621 $sql .= " WHERE fk_website_page = ".(int) $this->id;
622
623 $result = $this->db->query($sql);
624 if (!$result) {
625 $error++;
626 $this->errors[] = $this->db->lasterror();
627 break;
628 }
629 }
630 }
631
632 if (!$error) {
633 $result = $this->deleteCommon($user, $notrigger);
634 if ($result <= 0) {
635 $error++;
636 }
637 }
638
639 if (!$error) {
640 $websiteobj = new Website($this->db);
641 $result = $websiteobj->fetch($this->fk_website);
642
643 if ($result > 0) {
644 global $dolibarr_main_data_root;
645 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websiteobj->ref;
646
647 $filealias = $pathofwebsite.'/'.$this->pageurl.'.php';
648 $filetpl = $pathofwebsite.'/page'.$this->id.'.tpl.php';
649
650 dol_delete_file($filealias);
651 dol_delete_file($filetpl);
652 } else {
653 $this->error = $websiteobj->error;
654 $this->errors = $websiteobj->errors;
655 }
656 }
657
658 if (!$error) {
659 return 1;
660 } else {
661 return -1;
662 }
663 }
664
677 public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '')
678 {
679 global $hookmanager, $langs;
680
681 $now = dol_now();
682 $error = 0;
683
684 dol_syslog(__METHOD__, LOG_DEBUG);
685
686 $object = new self($this->db);
687
688 // Clean parameters
689 if (empty($newref) && !empty($newtitle)) {
690 $newref = strtolower(dol_sanitizeFileName(preg_replace('/\s+/', '-', $newtitle), '-', 1));
691 }
692
693 // Check parameters
694 if (empty($newref)) {
695 $langs->load("errors");
696 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE"));
697 return -1;
698 }
699
700 $this->db->begin();
701
702 // Load source object
703 $object->fetch($fromid);
704 // Reset object
705 $object->id = 0;
706
707 // Clear fields
708 $object->ref = $newref;
709 $object->pageurl = $newref;
710 $object->aliasalt = '';
711 $object->fk_user_creat = $user->id;
712 $object->author_alias = '';
713 $object->date_creation = $now;
714 $object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
715 $object->description = $object->title;
716 if (!empty($newlang)) {
717 $object->lang = $newlang;
718 }
719 if ($istranslation) {
720 $object->fk_page = $fromid;
721 } else {
722 $object->fk_page = 0;
723 }
724 if (!empty($newwebsite)) {
725 $object->fk_website = $newwebsite;
726 }
727 $object->import_key = '';
728 $object->status = self::STATUS_DRAFT;
729
730 // Create clone
731 $object->context['createfromclone'] = 'createfromclone';
732 $result = $object->create($user);
733 if ($result < 0) {
734 $error++;
735 $this->error = $object->error;
736 $this->errors = $object->errors;
737 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
738 }
739
740 unset($object->context['createfromclone']);
741
742 // End
743 if (!$error) {
744 $this->db->commit();
745
746 return $object;
747 } else {
748 $this->db->rollback();
749
750 return -1;
751 }
752 }
753
765 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
766 {
767 global $langs, $conf, $db;
768 global $dolibarr_main_authentication, $dolibarr_main_demo;
769 global $menumanager;
770
771 $result = '';
772
773 $label = '<u>'.$langs->trans("Page").'</u>';
774 $label .= '<br>';
775 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
776 $label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
777 $label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
778 $label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
779
780 $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
781
782 $linkclose = '';
783 if (empty($notooltip)) {
784 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
785 $label = $langs->trans("ShowMyObject");
786 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
787 }
788 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
789 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
790 } else {
791 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
792 }
793
794 $linkstart = '<a href="'.$url.'"';
795 $linkstart .= $linkclose.'>';
796 $linkend = '</a>';
797
798 //$linkstart = $linkend = '';
799
800 $result .= $linkstart;
801 if ($withpicto) {
802 $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);
803 }
804 if ($withpicto != 2) {
805 $result .= $this->ref;
806 }
807 $result .= $linkend;
808
809 return $result;
810 }
811
818 public function getLibStatut($mode = 0)
819 {
820 return $this->LibStatut($this->status, $mode);
821 }
822
823 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
831 public function LibStatut($status, $mode = 0)
832 {
833 // phpcs:enable
834 global $langs;
835
836 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
837 global $langs;
838 //$langs->load("mymodule");
839 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
840 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
841 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
842 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
843 }
844
845 $statusType = 'status5';
846 if ($status == self::STATUS_VALIDATED) {
847 $statusType = 'status4';
848 }
849
850 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
851 }
852
863 public function setCategories($categories)
864 {
865 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
866 return $this->setCategoriesCommon($categories, Categorie::TYPE_WEBSITE_PAGE);
867 }
868
875 public function initAsSpecimen()
876 {
877 global $user;
878
879 $this->id = 0;
880
881 $now = dol_now();
882
883 $this->fk_website = '';
884 $this->type_container = 'page';
885 $this->pageurl = 'specimen';
886 $this->aliasalt = 'specimenalt';
887 $this->title = 'My Page';
888 $this->description = 'This is my page';
889 $this->image = '';
890 $this->keywords = 'keyword1, keyword2';
891 $this->allowed_in_frames = 1;
892 $this->htmlheader = '';
893 $this->content = '<html><body>This is a html content</body></html>';
894 $this->status = '';
895 $this->grabbed_from = '';
896 $this->date_creation = $now - (24 * 30 * 3600);
897 $this->date_modification = $now - (24 * 7 * 3600);
898 $this->fk_user_creat = $user->id;
899 $this->author_alias = 'mypublicpseudo';
900 }
901}
$object ref
Definition info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
updateCommon(User $user, $notrigger=false)
Update object into database.
setCategoriesCommon($categories, $type_categ='', $remove_existing=true)
Sets object to given categories.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
Class Website.
Class Websitepage.
update(User $user, $notrigger=false)
Update object into database.
__construct(DoliDB $db)
Constructor.
countAll($websiteid, array $filter=array(), $filtermode='AND')
Count objects in the database.
fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Return array of all web site pages.
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.
create(User $user, $notrigger=false)
Create object into database.
createFromClone(User $user, $fromid, $newref, $newlang='', $istranslation=0, $newwebsite=0, $newtitle='')
Load an object from its id and create a new one in database.
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 optionaly the picto) Use this->id,this->lastname,...
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.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.