dolibarr  16.0.5
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
29 require_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 
53 
57  public $fk_website;
58 
59  public $pageurl;
60  public $aliasalt;
61  public $type_container;
62 
66  public $title;
70  public $description;
74  public $image;
78  public $keywords;
82  public $lang;
83 
84  public $allowed_in_frames;
85  public $htmlheader;
86  public $content;
87  public $grabbed_from;
88 
92  public $status;
93 
97  public $date_creation;
98 
102  public $date_modification;
103 
107  public $author_alias;
108 
112  public $object_type;
113 
117  public $fk_object;
118 
119  const STATUS_DRAFT = 0;
120  const STATUS_VALIDATED = 1;
121 
122 
147  // BEGIN MODULEBUILDER PROPERTIES
151  public $fields = array(
152  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
153  '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'),
154  'aliasalt' =>array('type'=>'varchar(255)', 'label'=>'AliasAlt', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>11, 'searchall'=>0, 'comment'=>'Alias alternative of page'),
155  'type_container' =>array('type'=>'varchar(16)', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>12, 'comment'=>'Type of container'),
156  'title' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'help'=>'UseTextBetween5And70Chars'),
157  'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1),
158  '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"'),
159  'keywords' =>array('type'=>'varchar(255)', 'label'=>'Keywords', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
160  'lang' =>array('type'=>'varchar(6)', 'label'=>'Lang', 'enabled'=>1, 'notnull'=>-1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
161  //'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
162  'fk_website' =>array('type'=>'integer', 'label'=>'WebsiteId', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>40, 'searchall'=>0, 'foreignkey'=>'websitepage.rowid'),
163  'fk_page' =>array('type'=>'integer', 'label'=>'ParentPageId', 'enabled'=>1, 'visible'=>1, 'notnull'=>-1, 'position'=>45, 'searchall'=>0, 'foreignkey'=>'website.rowid'),
164  'allowed_in_frames' =>array('type'=>'integer', 'label'=>'AllowedInFrames', 'enabled'=>1, 'visible'=>-1, 'position'=>48, 'searchall'=>0, 'default'=>0),
165  'htmlheader' =>array('type'=>'text', 'label'=>'HtmlHeader', 'enabled'=>1, 'visible'=>0, 'position'=>50, 'searchall'=>0),
166  'content' =>array('type'=>'mediumtext', 'label'=>'Content', 'enabled'=>1, 'visible'=>0, 'position'=>51, 'searchall'=>0),
167  'grabbed_from' =>array('type'=>'varchar(255)', 'label'=>'GrabbedFrom', 'enabled'=>1, 'visible'=>1, 'index'=>1, 'position'=>400, 'comment'=>'URL page content was grabbed from'),
168  'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500),
169  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>501),
170  //'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
171  'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>510),
172  'author_alias' =>array('type'=>'varchar(64)', 'label'=>'AuthorAlias', 'enabled'=>1, 'visible'=>-1, 'index'=>0, 'position'=>511, 'comment'=>'Author alias'),
173  'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
174  //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
175  'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>1, 'position'=>1000, 'notnull'=>-1),
176  'object_type' => array('type' => 'varchar(255)', 'label' => 'ObjectType', 'enabled'=>1, 'visible'=>0, 'position'=>46, 'searchall'=>0, 'help'=>''),
177  'fk_object' => array('type' => 'varchar(255)', 'label' => 'ObjectId', 'enabled'=>1, 'visible'=>0, 'position'=>47, 'searchall'=>0, 'help'=>'')
178  );
179  // END MODULEBUILDER PROPERTIES
180 
181 
182  // If this object has a subtable with lines
183 
184  // /**
185  // * @var string Name of subtable line
186  // */
187  //public $table_element_line = 'mymodule_myobjectline';
188 
192  public $fk_element = 'fk_website_page';
193 
194  // /**
195  // * @var string Name of subtable class that manage subtable lines
196  // */
197  //public $class_element_line = 'MyObjectline';
198 
202  //protected $childtables=array();
203 
207  protected $childtablesoncascade = array('categorie_website_page');
208 
209 
210 
216  public function __construct(DoliDB $db)
217  {
218  $this->db = $db;
219  }
220 
228  public function create(User $user, $notrigger = false)
229  {
230  $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
231  $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
232  if ($this->aliasalt) {
233  $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
234  }
235 
236  $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
237  $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
238  $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
239 
240  // Remove spaces and be sure we have main language only
241  $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
242 
243  return $this->createCommon($user, $notrigger);
244  }
245 
258  public function fetch($id, $website_id = null, $page = null, $aliasalt = null)
259  {
260  dol_syslog(__METHOD__, LOG_DEBUG);
261 
262  $sql = 'SELECT';
263  $sql .= ' t.rowid,';
264  $sql .= " t.fk_website,";
265  $sql .= ' t.type_container,';
266  $sql .= " t.pageurl,";
267  $sql .= " t.aliasalt,";
268  $sql .= " t.title,";
269  $sql .= " t.description,";
270  $sql .= " t.image,";
271  $sql .= " t.keywords,";
272  $sql .= " t.htmlheader,";
273  $sql .= " t.content,";
274  $sql .= " t.lang,";
275  $sql .= " t.fk_page,";
276  $sql .= " t.allowed_in_frames,";
277  $sql .= " t.status,";
278  $sql .= " t.grabbed_from,";
279  $sql .= " t.date_creation,";
280  $sql .= " t.tms as date_modification,";
281  $sql .= " t.fk_user_creat,";
282  $sql .= " t.author_alias,";
283  $sql .= " t.fk_user_modif,";
284  $sql .= " t.import_key,";
285  $sql .= " t.object_type,";
286  $sql .= " t.fk_object";
287  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
288  //$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
289  $sql .= ' WHERE 1 = 1';
290  if ($id > 0) {
291  $sql .= ' AND t.rowid = '.((int) $id);
292  } else {
293  if ($id < 0) {
294  $sql .= ' AND t.rowid <> '.abs($id);
295  }
296  if (null !== $website_id) {
297  $sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'";
298  if ($page) {
299  $pagetouse = $page;
300  $langtouse = '';
301  $tmppage = explode('/', $page);
302  if (!empty($tmppage[1])) {
303  $pagetouse = $tmppage[1];
304  if (strlen($tmppage[0])) {
305  $langtouse = $tmppage[0];
306  }
307  }
308  $sql .= " AND t.pageurl = '".$this->db->escape($pagetouse)."'";
309  if ($langtouse) {
310  $sql .= " AND t.lang = '".$this->db->escape($langtouse)."'";
311  }
312  }
313  if ($aliasalt) {
314  $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')";
315  }
316  }
317  }
318  $sql .= $this->db->plimit(1);
319 
320  $resql = $this->db->query($sql);
321  if ($resql) {
322  $numrows = $this->db->num_rows($resql);
323  if ($numrows) {
324  $obj = $this->db->fetch_object($resql);
325 
326  $this->id = $obj->rowid;
327 
328  $this->fk_website = $obj->fk_website;
329  $this->type_container = $obj->type_container;
330 
331  $this->pageurl = $obj->pageurl;
332  $this->ref = $obj->pageurl;
333  $this->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
334 
335  $this->title = $obj->title;
336  $this->description = $obj->description;
337  $this->image = $obj->image;
338  $this->keywords = $obj->keywords;
339  $this->htmlheader = $obj->htmlheader;
340  $this->content = $obj->content;
341  $this->lang = $obj->lang;
342  $this->fk_page = $obj->fk_page;
343  $this->allowed_in_frames = $obj->allowed_in_frames;
344  $this->status = $obj->status;
345  $this->grabbed_from = $obj->grabbed_from;
346  $this->date_creation = $this->db->jdate($obj->date_creation);
347  $this->date_modification = $this->db->jdate($obj->date_modification);
348  $this->fk_user_creat = $obj->fk_user_creat;
349  $this->author_alias = $obj->author_alias;
350  $this->fk_user_modif = $obj->fk_user_modif;
351  $this->import_key = $obj->import_key;
352  $this->object_type = $obj->object_type;
353  $this->fk_object = $obj->fk_object;
354  }
355  $this->db->free($resql);
356 
357  if ($numrows) {
358  return 1;
359  } else {
360  return 0;
361  }
362  } else {
363  $this->errors[] = 'Error '.$this->db->lasterror();
364  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
365 
366  return -1;
367  }
368  }
369 
382  public function fetchAll($websiteid, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
383  {
384  dol_syslog(__METHOD__, LOG_DEBUG);
385 
386  $records = array();
387 
388  $sql = 'SELECT';
389  $sql .= ' t.rowid,';
390  $sql .= " t.fk_website,";
391  $sql .= " t.type_container,";
392  $sql .= " t.pageurl,";
393  $sql .= " t.aliasalt,";
394  $sql .= " t.title,";
395  $sql .= " t.description,";
396  $sql .= " t.image,";
397  $sql .= " t.keywords,";
398  $sql .= " t.htmlheader,";
399  $sql .= " t.content,";
400  $sql .= " t.lang,";
401  $sql .= " t.fk_page,";
402  $sql .= " t.allowed_in_frames,";
403  $sql .= " t.status,";
404  $sql .= " t.grabbed_from,";
405  $sql .= " t.date_creation,";
406  $sql .= " t.tms as date_modification,";
407  $sql .= " t.fk_user_creat,";
408  $sql .= " t.author_alias,";
409  $sql .= " t.fk_user_modif,";
410  $sql .= " t.import_key,";
411  $sql .= " t.object_type,";
412  $sql .= " t.fk_object";
413  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
414  $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
415  // Manage filter (same than into countAll)
416  $sqlwhere = array();
417  if (count($filter) > 0) {
418  foreach ($filter as $key => $value) {
419  if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
420  $sqlwhere[] = $key." = ".((int) $value);
421  } elseif ($key == 'type_container' || $key == 't.type_container') {
422  $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
423  } elseif ($key == 'lang' || $key == 't.lang') {
424  $listoflang = array();
425  $foundnull = 0;
426  foreach (explode(',', $value) as $tmpvalue) {
427  if ($tmpvalue == 'null') {
428  $foundnull++;
429  continue;
430  }
431  $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
432  }
433  $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
434  if ($foundnull) {
435  $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
436  }
437  $sqlwhere[] = $stringtouse;
438  } else {
439  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
440  }
441  }
442  }
443  if (count($sqlwhere) > 0) {
444  $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
445  }
446 
447  if (!empty($sortfield)) {
448  $sql .= $this->db->order($sortfield, $sortorder);
449  }
450  if (!empty($limit)) {
451  $sql .= $this->db->plimit($limit, $offset);
452  }
453 
454  $resql = $this->db->query($sql);
455  if ($resql) {
456  $num = $this->db->num_rows($resql);
457 
458  while ($obj = $this->db->fetch_object($resql)) {
459  $record = new self($this->db);
460 
461  $record->id = $obj->rowid;
462  $record->fk_website = $obj->fk_website;
463  $record->type_container = $obj->type_container;
464  $record->pageurl = $obj->pageurl;
465  $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
466  $record->title = $obj->title;
467  $record->description = $obj->description;
468  $record->image = $obj->image;
469  $record->keywords = $obj->keywords;
470  $record->htmlheader = $obj->htmlheader;
471  $record->content = $obj->content;
472  $record->lang = $obj->lang;
473  $record->fk_page = $obj->fk_page;
474  $record->allowed_in_frames = $obj->allowed_in_frames;
475  $record->status = $obj->status;
476  $record->grabbed_from = $obj->grabbed_from;
477  $record->date_creation = $this->db->jdate($obj->date_creation);
478  $record->date_modification = $this->db->jdate($obj->date_modification);
479  $record->fk_user_creat = $obj->fk_user_creat;
480  $record->author_alias = $obj->author_alias;
481  $record->fk_user_modif = $obj->fk_user_modif;
482  $record->import_key = $obj->import_key;
483  $record->object_type = $obj->object_type;
484  $record->fk_object = $obj->fk_object;
485  //var_dump($record->id);
486  $records[$record->id] = $record;
487  }
488  $this->db->free($resql);
489 
490  return $records;
491  } else {
492  $this->error = 'Error '.$this->db->lasterror();
493  $this->errors[] = $this->error;
494  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
495 
496  return -1;
497  }
498  }
499 
508  public function countAll($websiteid, array $filter = array(), $filtermode = 'AND')
509  {
510  dol_syslog(__METHOD__, LOG_DEBUG);
511 
512  $result = 0;
513 
514  $sql = 'SELECT COUNT(t.rowid) as nb';
515  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
516  $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
517  // Manage filter (same than into fetchAll)
518  $sqlwhere = array();
519  if (count($filter) > 0) {
520  foreach ($filter as $key => $value) {
521  if ($key == 't.rowid' || $key == 't.fk_website' || $key == 'status') {
522  $sqlwhere[] = $key." = ".((int) $value);
523  } elseif ($key == 'type_container') {
524  $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
525  } elseif ($key == 'lang' || $key == 't.lang') {
526  $listoflang = array();
527  $foundnull = 0;
528  foreach (explode(',', $value) as $tmpvalue) {
529  if ($tmpvalue == 'null') {
530  $foundnull++;
531  continue;
532  }
533  $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
534  }
535  $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
536  if ($foundnull) {
537  $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
538  }
539  $sqlwhere[] = $stringtouse;
540  } else {
541  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
542  }
543  }
544  }
545  if (count($sqlwhere) > 0) {
546  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
547  }
548 
549  $resql = $this->db->query($sql);
550  if ($resql) {
551  $obj = $this->db->fetch_object($resql);
552  if ($obj) {
553  $result = $obj->nb;
554  }
555 
556  $this->db->free($resql);
557 
558  return $result;
559  } else {
560  $this->error = 'Error '.$this->db->lasterror();
561  $this->errors[] = $this->error;
562  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
563 
564  return -1;
565  }
566  }
567 
575  public function update(User $user, $notrigger = false)
576  {
577  $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
578  $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
579  if ($this->aliasalt) {
580  $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
581  }
582 
583  $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
584  $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
585  $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
586 
587  // Remove spaces and be sure we have main language only
588  $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
589 
590  if ($this->fk_page > 0) {
591  if (empty($this->lang)) {
592  $this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
593  return -1;
594  }
595  $tmppage = new WebsitePage($this->db);
596  $tmppage->fetch($this->fk_page);
597  if ($tmppage->lang == $this->lang) {
598  $this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
599  return -1;
600  }
601  }
602 
603  return $this->updateCommon($user, $notrigger);
604  }
605 
613  public function delete(User $user, $notrigger = false)
614  {
615  global $conf;
616 
617  $error = 0;
618 
619  // Delete all child tables
620  if (!$error) {
621  foreach ($this->childtablesoncascade as $table) {
622  $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
623  $sql .= " WHERE fk_website_page = ".(int) $this->id;
624 
625  $result = $this->db->query($sql);
626  if (!$result) {
627  $error++;
628  $this->errors[] = $this->db->lasterror();
629  break;
630  }
631  }
632  }
633 
634  if (!$error) {
635  $result = $this->deleteCommon($user, $notrigger);
636  if ($result <= 0) {
637  $error++;
638  }
639  }
640 
641  if (!$error) {
642  $websiteobj = new Website($this->db);
643  $result = $websiteobj->fetch($this->fk_website);
644 
645  if ($result > 0) {
646  global $dolibarr_main_data_root;
647  $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websiteobj->ref;
648 
649  $filealias = $pathofwebsite.'/'.$this->pageurl.'.php';
650  $filetpl = $pathofwebsite.'/page'.$this->id.'.tpl.php';
651 
652  dol_delete_file($filealias);
653  dol_delete_file($filetpl);
654  } else {
655  $this->error = $websiteobj->error;
656  $this->errors = $websiteobj->errors;
657  }
658  }
659 
660  if (!$error) {
661  return 1;
662  } else {
663  return -1;
664  }
665  }
666 
679  public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '')
680  {
681  global $hookmanager, $langs;
682 
683  $now = dol_now();
684  $error = 0;
685 
686  dol_syslog(__METHOD__, LOG_DEBUG);
687 
688  $object = new self($this->db);
689 
690  // Clean parameters
691  if (empty($newref) && !empty($newtitle)) {
692  $newref = strtolower(dol_sanitizeFileName(preg_replace('/\s+/', '-', $newtitle), '-', 1));
693  }
694 
695  // Check parameters
696  if (empty($newref)) {
697  $langs->load("errors");
698  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE"));
699  return -1;
700  }
701 
702  $this->db->begin();
703 
704  // Load source object
705  $object->fetch($fromid);
706  // Reset object
707  $object->id = 0;
708 
709  // Clear fields
710  $object->ref = $newref;
711  $object->pageurl = $newref;
712  $object->aliasalt = '';
713  $object->fk_user_creat = $user->id;
714  $object->author_alias = '';
715  $object->date_creation = $now;
716  $object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
717  $object->description = $object->title;
718  if (!empty($newlang)) {
719  $object->lang = $newlang;
720  }
721  if ($istranslation) {
722  $object->fk_page = $fromid;
723  } else {
724  $object->fk_page = 0;
725  }
726  if (!empty($newwebsite)) {
727  $object->fk_website = $newwebsite;
728  }
729  $object->import_key = '';
730  $object->status = self::STATUS_DRAFT;
731 
732  // Create clone
733  $object->context['createfromclone'] = 'createfromclone';
734  $result = $object->create($user);
735  if ($result < 0) {
736  $error++;
737  $this->error = $object->error;
738  $this->errors = $object->errors;
739  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
740  }
741 
742  unset($object->context['createfromclone']);
743 
744  // End
745  if (!$error) {
746  $this->db->commit();
747 
748  return $object;
749  } else {
750  $this->db->rollback();
751 
752  return -1;
753  }
754  }
755 
767  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
768  {
769  global $langs, $conf, $db;
770  global $dolibarr_main_authentication, $dolibarr_main_demo;
771  global $menumanager;
772 
773  $result = '';
774 
775  $label = '<u>'.$langs->trans("Page").'</u>';
776  $label .= '<br>';
777  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
778  $label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
779  $label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
780  $label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
781 
782  $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
783 
784  $linkclose = '';
785  if (empty($notooltip)) {
786  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
787  $label = $langs->trans("ShowMyObject");
788  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
789  }
790  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
791  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
792  } else {
793  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
794  }
795 
796  $linkstart = '<a href="'.$url.'"';
797  $linkstart .= $linkclose.'>';
798  $linkend = '</a>';
799 
800  //$linkstart = $linkend = '';
801 
802  $result .= $linkstart;
803  if ($withpicto) {
804  $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);
805  }
806  if ($withpicto != 2) {
807  $result .= $this->ref;
808  }
809  $result .= $linkend;
810 
811  return $result;
812  }
813 
820  public function getLibStatut($mode = 0)
821  {
822  return $this->LibStatut($this->status, $mode);
823  }
824 
825  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
833  public function LibStatut($status, $mode = 0)
834  {
835  // phpcs:enable
836  global $langs;
837 
838  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
839  global $langs;
840  //$langs->load("mymodule");
841  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Disabled');
842  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
843  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Disabled');
844  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
845  }
846 
847  $statusType = 'status5';
848  if ($status == self::STATUS_VALIDATED) {
849  $statusType = 'status4';
850  }
851 
852  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
853  }
854 
865  public function setCategories($categories)
866  {
867  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
868  return $this->setCategoriesCommon($categories, Categorie::TYPE_WEBSITE_PAGE);
869  }
870 
877  public function initAsSpecimen()
878  {
879  global $user;
880 
881  $this->id = 0;
882 
883  $now = dol_now();
884 
885  $this->fk_website = '';
886  $this->type_container = 'page';
887  $this->pageurl = 'specimen';
888  $this->aliasalt = 'specimenalt';
889  $this->title = 'My Page';
890  $this->description = 'This is my page';
891  $this->image = '';
892  $this->keywords = 'keyword1, keyword2';
893  $this->allowed_in_frames = 1;
894  $this->htmlheader = '';
895  $this->content = '<html><body>This is a html content</body></html>';
896  $this->status = '';
897  $this->grabbed_from = '';
898  $this->date_creation = $now - (24 * 30 * 3600);
899  $this->date_modification = $now - (24 * 7 * 3600);
900  $this->fk_user_creat = $user->id;
901  $this->author_alias = 'mypublicpseudo';
902  }
903 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
WebsitePage\create
create(User $user, $notrigger=false)
Create object into database.
Definition: websitepage.class.php:228
WebsitePage\fetchAll
fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Return array of all web site pages.
Definition: websitepage.class.php:382
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_trunc
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.
Definition: functions.lib.php:3805
WebsitePage
Class Websitepage.
Definition: websitepage.class.php:36
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
WebsitePage\getLibStatut
getLibStatut($mode=0)
Retourne le libelle du status d'un user (actif, inactif)
Definition: websitepage.class.php:820
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
WebsitePage\createFromClone
createFromClone(User $user, $fromid, $newref, $newlang='', $istranslation=0, $newwebsite=0, $newtitle='')
Load an object from its id and create a new one in database.
Definition: websitepage.class.php:679
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
ref
$object ref
Definition: info.php:77
WebsitePage\countAll
countAll($websiteid, array $filter=array(), $filtermode='AND')
Count objects in the database.
Definition: websitepage.class.php:508
WebsitePage\fetch
fetch($id, $website_id=null, $page=null, $aliasalt=null)
Load object in memory from the database.
Definition: websitepage.class.php:258
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_delete_file
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.
Definition: files.lib.php:1231
WebsitePage\LibStatut
LibStatut($status, $mode=0)
Renvoi le libelle d'un status donne.
Definition: websitepage.class.php:833
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
WebsitePage\setCategories
setCategories($categories)
Sets object to given categories.
Definition: websitepage.class.php:865
WebsitePage\__construct
__construct(DoliDB $db)
Constructor.
Definition: websitepage.class.php:216
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9308
WebsitePage\getNomUrl
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,...
Definition: websitepage.class.php:767
Website
Class Website.
Definition: website.class.php:36
User
Class to manage Dolibarr users.
Definition: user.class.php:44
WebsitePage\update
update(User $user, $notrigger=false)
Update object into database.
Definition: websitepage.class.php:575
WebsitePage\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: websitepage.class.php:877
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
CommonObject\setCategoriesCommon
setCategoriesCommon($categories, $type_categ='', $remove_existing=true)
Sets object to given categories.
Definition: commonobject.class.php:9860