dolibarr 19.0.4
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 return $this->createCommon($user, $notrigger);
230 }
231
244 public function fetch($id, $website_id = null, $page = null, $aliasalt = null)
245 {
246 dol_syslog(__METHOD__, LOG_DEBUG);
247
248 $sql = 'SELECT';
249 $sql .= ' t.rowid,';
250 $sql .= " t.fk_website,";
251 $sql .= ' t.type_container,';
252 $sql .= " t.pageurl,";
253 $sql .= " t.aliasalt,";
254 $sql .= " t.title,";
255 $sql .= " t.description,";
256 $sql .= " t.image,";
257 $sql .= " t.keywords,";
258 $sql .= " t.htmlheader,";
259 $sql .= " t.content,";
260 $sql .= " t.lang,";
261 $sql .= " t.fk_page,";
262 $sql .= " t.allowed_in_frames,";
263 $sql .= " t.status,";
264 $sql .= " t.grabbed_from,";
265 $sql .= " t.date_creation,";
266 $sql .= " t.tms as date_modification,";
267 $sql .= " t.fk_user_creat,";
268 $sql .= " t.author_alias,";
269 $sql .= " t.fk_user_modif,";
270 $sql .= " t.import_key,";
271 $sql .= " t.object_type,";
272 $sql .= " t.fk_object";
273 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
274 //$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
275 $sql .= ' WHERE 1 = 1';
276 if ($id > 0) {
277 $sql .= ' AND t.rowid = '.((int) $id);
278 } else {
279 if ($id < 0) {
280 $sql .= ' AND t.rowid <> '.abs($id);
281 }
282 if (null !== $website_id) {
283 $sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'";
284 if ($page) {
285 $pagetouse = $page;
286 $langtouse = '';
287 $tmppage = explode('/', $page);
288 if (!empty($tmppage[1])) {
289 $pagetouse = $tmppage[1];
290 if (strlen($tmppage[0])) {
291 $langtouse = $tmppage[0];
292 }
293 }
294 $sql .= " AND t.pageurl = '".$this->db->escape($pagetouse)."'";
295 if ($langtouse) {
296 $sql .= " AND t.lang = '".$this->db->escape($langtouse)."'";
297 }
298 }
299 if ($aliasalt) {
300 $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')";
301 }
302 }
303 }
304 $sql .= $this->db->plimit(1);
305
306 $resql = $this->db->query($sql);
307 if ($resql) {
308 $numrows = $this->db->num_rows($resql);
309 if ($numrows) {
310 $obj = $this->db->fetch_object($resql);
311
312 $this->id = $obj->rowid;
313
314 $this->fk_website = $obj->fk_website;
315 $this->type_container = $obj->type_container;
316
317 $this->pageurl = $obj->pageurl;
318 $this->ref = $obj->pageurl;
319 $this->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
320
321 $this->title = $obj->title;
322 $this->description = $obj->description;
323 $this->image = $obj->image;
324 $this->keywords = $obj->keywords;
325 $this->htmlheader = $obj->htmlheader;
326 $this->content = $obj->content;
327 $this->lang = $obj->lang;
328 $this->fk_page = $obj->fk_page;
329 $this->allowed_in_frames = $obj->allowed_in_frames;
330 $this->status = $obj->status;
331 $this->grabbed_from = $obj->grabbed_from;
332 $this->date_creation = $this->db->jdate($obj->date_creation);
333 $this->date_modification = $this->db->jdate($obj->date_modification);
334 $this->fk_user_creat = $obj->fk_user_creat;
335 $this->author_alias = $obj->author_alias;
336 $this->fk_user_modif = $obj->fk_user_modif;
337 $this->import_key = $obj->import_key;
338 $this->object_type = $obj->object_type;
339 $this->fk_object = $obj->fk_object;
340 }
341 $this->db->free($resql);
342
343 if ($numrows) {
344 return 1;
345 } else {
346 return 0;
347 }
348 } else {
349 $this->errors[] = 'Error '.$this->db->lasterror();
350 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
351
352 return -1;
353 }
354 }
355
368 public function fetchAll($websiteid, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
369 {
370 dol_syslog(__METHOD__, LOG_DEBUG);
371
372 $records = array();
373
374 $sql = 'SELECT';
375 $sql .= ' t.rowid,';
376 $sql .= " t.fk_website,";
377 $sql .= " t.type_container,";
378 $sql .= " t.pageurl,";
379 $sql .= " t.aliasalt,";
380 $sql .= " t.title,";
381 $sql .= " t.description,";
382 $sql .= " t.image,";
383 $sql .= " t.keywords,";
384 $sql .= " t.htmlheader,";
385 $sql .= " t.content,";
386 $sql .= " t.lang,";
387 $sql .= " t.fk_page,";
388 $sql .= " t.allowed_in_frames,";
389 $sql .= " t.status,";
390 $sql .= " t.grabbed_from,";
391 $sql .= " t.date_creation,";
392 $sql .= " t.tms as date_modification,";
393 $sql .= " t.fk_user_creat,";
394 $sql .= " t.author_alias,";
395 $sql .= " t.fk_user_modif,";
396 $sql .= " t.import_key,";
397 $sql .= " t.object_type,";
398 $sql .= " t.fk_object";
399 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
400 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
401 // Manage filter (same than into countAll)
402 $sqlwhere = array();
403 if (count($filter) > 0) {
404 foreach ($filter as $key => $value) {
405 if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
406 $sqlwhere[] = $key." = ".((int) $value);
407 } elseif ($key == 'type_container' || $key == 't.type_container') {
408 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
409 } elseif ($key == 'lang' || $key == 't.lang') {
410 $listoflang = array();
411 $foundnull = 0;
412 foreach (explode(',', $value) as $tmpvalue) {
413 if ($tmpvalue == 'null') {
414 $foundnull++;
415 continue;
416 }
417 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
418 }
419 $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
420 if ($foundnull) {
421 $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
422 }
423 $sqlwhere[] = $stringtouse;
424 } else {
425 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
426 }
427 }
428 }
429 if (count($sqlwhere) > 0) {
430 $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
431 }
432
433 if (!empty($sortfield)) {
434 $sql .= $this->db->order($sortfield, $sortorder);
435 }
436 if (!empty($limit)) {
437 $sql .= $this->db->plimit($limit, $offset);
438 }
439
440 $resql = $this->db->query($sql);
441 if ($resql) {
442 $num = $this->db->num_rows($resql);
443
444 while ($obj = $this->db->fetch_object($resql)) {
445 $record = new self($this->db);
446
447 $record->id = $obj->rowid;
448 $record->fk_website = $obj->fk_website;
449 $record->type_container = $obj->type_container;
450 $record->pageurl = $obj->pageurl;
451 $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
452 $record->title = $obj->title;
453 $record->description = $obj->description;
454 $record->image = $obj->image;
455 $record->keywords = $obj->keywords;
456 $record->htmlheader = $obj->htmlheader;
457 $record->content = $obj->content;
458 $record->lang = $obj->lang;
459 $record->fk_page = $obj->fk_page;
460 $record->allowed_in_frames = $obj->allowed_in_frames;
461 $record->status = $obj->status;
462 $record->grabbed_from = $obj->grabbed_from;
463 $record->date_creation = $this->db->jdate($obj->date_creation);
464 $record->date_modification = $this->db->jdate($obj->date_modification);
465 $record->fk_user_creat = $obj->fk_user_creat;
466 $record->author_alias = $obj->author_alias;
467 $record->fk_user_modif = $obj->fk_user_modif;
468 $record->import_key = $obj->import_key;
469 $record->object_type = $obj->object_type;
470 $record->fk_object = $obj->fk_object;
471 //var_dump($record->id);
472 $records[$record->id] = $record;
473 }
474 $this->db->free($resql);
475
476 return $records;
477 } else {
478 $this->error = 'Error '.$this->db->lasterror();
479 $this->errors[] = $this->error;
480 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
481
482 return -1;
483 }
484 }
485
494 public function countAll($websiteid, array $filter = array(), $filtermode = 'AND')
495 {
496 dol_syslog(__METHOD__, LOG_DEBUG);
497
498 $result = 0;
499
500 $sql = 'SELECT COUNT(t.rowid) as nb';
501 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
502 $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
503 // Manage filter (same than into fetchAll)
504 $sqlwhere = array();
505 if (count($filter) > 0) {
506 foreach ($filter as $key => $value) {
507 if ($key == 't.rowid' || $key == 't.fk_website' || $key == 'status') {
508 $sqlwhere[] = $key." = ".((int) $value);
509 } elseif ($key == 'type_container') {
510 $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
511 } elseif ($key == 'lang' || $key == 't.lang') {
512 $listoflang = array();
513 $foundnull = 0;
514 foreach (explode(',', $value) as $tmpvalue) {
515 if ($tmpvalue == 'null') {
516 $foundnull++;
517 continue;
518 }
519 $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
520 }
521 $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
522 if ($foundnull) {
523 $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
524 }
525 $sqlwhere[] = $stringtouse;
526 } else {
527 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
528 }
529 }
530 }
531 if (count($sqlwhere) > 0) {
532 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
533 }
534
535 $resql = $this->db->query($sql);
536 if ($resql) {
537 $obj = $this->db->fetch_object($resql);
538 if ($obj) {
539 $result = $obj->nb;
540 }
541
542 $this->db->free($resql);
543
544 return $result;
545 } else {
546 $this->error = 'Error '.$this->db->lasterror();
547 $this->errors[] = $this->error;
548 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
549
550 return -1;
551 }
552 }
553
561 public function update(User $user, $notrigger = false)
562 {
563 $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
564 $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
565 if ($this->aliasalt) {
566 $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
567 }
568
569 $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
570 $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
571 $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
572
573 // Remove spaces and be sure we have main language only
574 $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
575
576 if ($this->fk_page > 0) {
577 if (empty($this->lang)) {
578 $this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
579 return -1;
580 }
581 $tmppage = new WebsitePage($this->db);
582 $tmppage->fetch($this->fk_page);
583 if ($tmppage->lang == $this->lang) {
584 $this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
585 return -1;
586 }
587 }
588
589 return $this->updateCommon($user, $notrigger);
590 }
591
599 public function delete(User $user, $notrigger = false)
600 {
601 global $conf;
602
603 $error = 0;
604
605 // Delete all child tables
606 if (!$error) {
607 foreach ($this->childtablesoncascade as $table) {
608 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
609 $sql .= " WHERE fk_website_page = ".(int) $this->id;
610
611 $result = $this->db->query($sql);
612 if (!$result) {
613 $error++;
614 $this->errors[] = $this->db->lasterror();
615 break;
616 }
617 }
618 }
619
620 if (!$error) {
621 $result = $this->deleteCommon($user, $notrigger);
622 if ($result <= 0) {
623 $error++;
624 }
625 }
626
627 if (!$error) {
628 $websiteobj = new Website($this->db);
629 $result = $websiteobj->fetch($this->fk_website);
630
631 if ($result > 0) {
632 global $dolibarr_main_data_root;
633 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websiteobj->ref;
634
635 $filealias = $pathofwebsite.'/'.$this->pageurl.'.php';
636 $filetpl = $pathofwebsite.'/page'.$this->id.'.tpl.php';
637
638 dol_delete_file($filealias);
639 dol_delete_file($filetpl);
640 } else {
641 $this->error = $websiteobj->error;
642 $this->errors = $websiteobj->errors;
643 }
644 }
645
646 if (!$error) {
647 return 1;
648 } else {
649 return -1;
650 }
651 }
652
665 public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '')
666 {
667 global $hookmanager, $langs;
668
669 $now = dol_now();
670 $error = 0;
671
672 dol_syslog(__METHOD__, LOG_DEBUG);
673
674 $object = new self($this->db);
675
676 // Clean parameters
677 if (empty($newref) && !empty($newtitle)) {
678 $newref = strtolower(dol_sanitizeFileName(preg_replace('/\s+/', '-', $newtitle), '-', 1));
679 }
680
681 // Check parameters
682 if (empty($newref)) {
683 $langs->load("errors");
684 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE"));
685 return -1;
686 }
687
688 $this->db->begin();
689
690 // Load source object
691 $object->fetch($fromid);
692 // Reset object
693 $object->id = 0;
694
695 // Clear fields
696 $object->ref = $newref;
697 $object->pageurl = $newref;
698 $object->aliasalt = '';
699 $object->fk_user_creat = $user->id;
700 $object->author_alias = '';
701 $object->date_creation = $now;
702 $object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
703 $object->description = $object->title;
704 if (!empty($newlang)) {
705 $object->lang = $newlang;
706 }
707 if ($istranslation) {
708 $object->fk_page = $fromid;
709 } else {
710 $object->fk_page = 0;
711 }
712 if (!empty($newwebsite)) {
713 $object->fk_website = $newwebsite;
714 }
715 $object->import_key = '';
716 $object->status = self::STATUS_DRAFT;
717
718 // Create clone
719 $object->context['createfromclone'] = 'createfromclone';
720 $result = $object->create($user);
721 if ($result < 0) {
722 $error++;
723 $this->error = $object->error;
724 $this->errors = $object->errors;
725 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
726 }
727
728 unset($object->context['createfromclone']);
729
730 // End
731 if (!$error) {
732 $this->db->commit();
733
734 return $object;
735 } else {
736 $this->db->rollback();
737
738 return -1;
739 }
740 }
741
753 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
754 {
755 global $langs, $conf, $db;
756 global $dolibarr_main_authentication, $dolibarr_main_demo;
757 global $menumanager;
758
759 $result = '';
760
761 $label = '<u>'.$langs->trans("Page").'</u>';
762 $label .= '<br>';
763 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
764 $label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
765 $label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
766 $label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
767
768 $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
769
770 $linkclose = '';
771 if (empty($notooltip)) {
772 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
773 $label = $langs->trans("ShowMyObject");
774 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
775 }
776 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
777 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
778 } else {
779 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
780 }
781
782 $linkstart = '<a href="'.$url.'"';
783 $linkstart .= $linkclose.'>';
784 $linkend = '</a>';
785
786 //$linkstart = $linkend = '';
787
788 $result .= $linkstart;
789 if ($withpicto) {
790 $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);
791 }
792 if ($withpicto != 2) {
793 $result .= $this->ref;
794 }
795 $result .= $linkend;
796
797 return $result;
798 }
799
806 public function getLibStatut($mode = 0)
807 {
808 return $this->LibStatut($this->status, $mode);
809 }
810
811 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
819 public function LibStatut($status, $mode = 0)
820 {
821 // phpcs:enable
822 global $langs;
823
824 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
825 global $langs;
826 //$langs->load("mymodule");
827 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
828 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
829 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
830 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
831 }
832
833 $statusType = 'status5';
834 if ($status == self::STATUS_VALIDATED) {
835 $statusType = 'status4';
836 }
837
838 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
839 }
840
851 public function setCategories($categories)
852 {
853 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
854 return $this->setCategoriesCommon($categories, Categorie::TYPE_WEBSITE_PAGE);
855 }
856
863 public function initAsSpecimen()
864 {
865 global $user;
866
867 $this->id = 0;
868
869 $now = dol_now();
870
871 $this->fk_website = 0;
872 $this->type_container = 'page';
873 $this->pageurl = 'specimen';
874 $this->aliasalt = 'specimenalt';
875 $this->title = 'My Page';
876 $this->description = 'This is my page';
877 $this->image = '';
878 $this->keywords = 'keyword1, keyword2';
879 $this->allowed_in_frames = 1;
880 $this->htmlheader = '';
881 $this->content = '<html><body>This is a html content</body></html>';
882 $this->status = self::STATUS_DRAFT;
883 $this->grabbed_from = '';
884 $this->date_creation = $now - (24 * 30 * 3600);
885 $this->date_modification = $now - (24 * 7 * 3600);
886 $this->fk_user_creat = $user->id;
887 $this->author_alias = 'mypublicpseudo';
888 }
889}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
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.
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.