dolibarr  x.y.z
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 
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 
119  public $author_alias;
120 
124  public $object_type;
125 
129  public $fk_object;
130 
131  const STATUS_DRAFT = 0; // offline
132  const STATUS_VALIDATED = 1; // online
133 
134 
159  // BEGIN MODULEBUILDER PROPERTIES
163  public $fields = array(
164  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
165  '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'),
166  'aliasalt' =>array('type'=>'varchar(255)', 'label'=>'AliasAlt', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>11, 'searchall'=>0, 'comment'=>'Alias alternative of page'),
167  'type_container' =>array('type'=>'varchar(16)', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'index'=>0, 'position'=>12, 'comment'=>'Type of container'),
168  'title' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'help'=>'UseTextBetween5And70Chars'),
169  'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1),
170  '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"'),
171  'keywords' =>array('type'=>'varchar(255)', 'label'=>'Keywords', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
172  'lang' =>array('type'=>'varchar(6)', 'label'=>'Lang', 'enabled'=>1, 'notnull'=>-1, 'visible'=>1, 'position'=>45, 'searchall'=>0),
173  //'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
174  'fk_website' =>array('type'=>'integer', 'label'=>'WebsiteId', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>40, 'searchall'=>0, 'foreignkey'=>'websitepage.rowid'),
175  'fk_page' =>array('type'=>'integer', 'label'=>'ParentPageId', 'enabled'=>1, 'visible'=>1, 'notnull'=>-1, 'position'=>45, 'searchall'=>0, 'foreignkey'=>'website.rowid'),
176  'allowed_in_frames' =>array('type'=>'integer', 'label'=>'AllowedInFrames', 'enabled'=>1, 'visible'=>-1, 'position'=>48, 'searchall'=>0, 'default'=>0),
177  'htmlheader' =>array('type'=>'text', 'label'=>'HtmlHeader', 'enabled'=>1, 'visible'=>0, 'position'=>50, 'searchall'=>0),
178  'content' =>array('type'=>'mediumtext', 'label'=>'Content', 'enabled'=>1, 'visible'=>0, 'position'=>51, 'searchall'=>0),
179  'grabbed_from' =>array('type'=>'varchar(255)', 'label'=>'GrabbedFrom', 'enabled'=>1, 'visible'=>1, 'index'=>1, 'position'=>400, 'comment'=>'URL page content was grabbed from'),
180  'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500),
181  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>501),
182  //'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
183  'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>510),
184  'author_alias' =>array('type'=>'varchar(64)', 'label'=>'AuthorAlias', 'enabled'=>1, 'visible'=>-1, 'index'=>0, 'position'=>511, 'comment'=>'Author alias'),
185  'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
186  //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
187  'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>1, 'position'=>1000, 'notnull'=>-1),
188  'object_type' => array('type' => 'varchar(255)', 'label' => 'ObjectType', 'enabled'=>1, 'visible'=>0, 'position'=>46, 'searchall'=>0, 'help'=>''),
189  'fk_object' => array('type' => 'varchar(255)', 'label' => 'ObjectId', 'enabled'=>1, 'visible'=>0, 'position'=>47, 'searchall'=>0, 'help'=>'')
190  );
191  // END MODULEBUILDER PROPERTIES
192 
193 
199  public function __construct(DoliDB $db)
200  {
201  $this->db = $db;
202  }
203 
211  public function create(User $user, $notrigger = false)
212  {
213  $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
214  $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
215  if ($this->aliasalt) {
216  $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
217  }
218 
219  $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
220  $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
221  $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
222 
223  // Remove spaces and be sure we have main language only
224  $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
225 
226  return $this->createCommon($user, $notrigger);
227  }
228 
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__.' '.join(',', $this->errors), LOG_ERR);
348 
349  return -1;
350  }
351  }
352 
365  public function fetchAll($websiteid, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
366  {
367  dol_syslog(__METHOD__, LOG_DEBUG);
368 
369  $records = array();
370 
371  $sql = 'SELECT';
372  $sql .= ' t.rowid,';
373  $sql .= " t.fk_website,";
374  $sql .= " t.type_container,";
375  $sql .= " t.pageurl,";
376  $sql .= " t.aliasalt,";
377  $sql .= " t.title,";
378  $sql .= " t.description,";
379  $sql .= " t.image,";
380  $sql .= " t.keywords,";
381  $sql .= " t.htmlheader,";
382  $sql .= " t.content,";
383  $sql .= " t.lang,";
384  $sql .= " t.fk_page,";
385  $sql .= " t.allowed_in_frames,";
386  $sql .= " t.status,";
387  $sql .= " t.grabbed_from,";
388  $sql .= " t.date_creation,";
389  $sql .= " t.tms as date_modification,";
390  $sql .= " t.fk_user_creat,";
391  $sql .= " t.author_alias,";
392  $sql .= " t.fk_user_modif,";
393  $sql .= " t.import_key,";
394  $sql .= " t.object_type,";
395  $sql .= " t.fk_object";
396  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
397  $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
398  // Manage filter (same than into countAll)
399  $sqlwhere = array();
400  if (count($filter) > 0) {
401  foreach ($filter as $key => $value) {
402  if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') {
403  $sqlwhere[] = $key." = ".((int) $value);
404  } elseif ($key == 'type_container' || $key == 't.type_container') {
405  $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
406  } elseif ($key == 'lang' || $key == 't.lang') {
407  $listoflang = array();
408  $foundnull = 0;
409  foreach (explode(',', $value) as $tmpvalue) {
410  if ($tmpvalue == 'null') {
411  $foundnull++;
412  continue;
413  }
414  $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
415  }
416  $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
417  if ($foundnull) {
418  $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
419  }
420  $sqlwhere[] = $stringtouse;
421  } else {
422  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
423  }
424  }
425  }
426  if (count($sqlwhere) > 0) {
427  $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
428  }
429 
430  if (!empty($sortfield)) {
431  $sql .= $this->db->order($sortfield, $sortorder);
432  }
433  if (!empty($limit)) {
434  $sql .= $this->db->plimit($limit, $offset);
435  }
436 
437  $resql = $this->db->query($sql);
438  if ($resql) {
439  $num = $this->db->num_rows($resql);
440 
441  while ($obj = $this->db->fetch_object($resql)) {
442  $record = new self($this->db);
443 
444  $record->id = $obj->rowid;
445  $record->fk_website = $obj->fk_website;
446  $record->type_container = $obj->type_container;
447  $record->pageurl = $obj->pageurl;
448  $record->aliasalt = preg_replace('/,+$/', '', preg_replace('/^,+/', '', $obj->aliasalt));
449  $record->title = $obj->title;
450  $record->description = $obj->description;
451  $record->image = $obj->image;
452  $record->keywords = $obj->keywords;
453  $record->htmlheader = $obj->htmlheader;
454  $record->content = $obj->content;
455  $record->lang = $obj->lang;
456  $record->fk_page = $obj->fk_page;
457  $record->allowed_in_frames = $obj->allowed_in_frames;
458  $record->status = $obj->status;
459  $record->grabbed_from = $obj->grabbed_from;
460  $record->date_creation = $this->db->jdate($obj->date_creation);
461  $record->date_modification = $this->db->jdate($obj->date_modification);
462  $record->fk_user_creat = $obj->fk_user_creat;
463  $record->author_alias = $obj->author_alias;
464  $record->fk_user_modif = $obj->fk_user_modif;
465  $record->import_key = $obj->import_key;
466  $record->object_type = $obj->object_type;
467  $record->fk_object = $obj->fk_object;
468  //var_dump($record->id);
469  $records[$record->id] = $record;
470  }
471  $this->db->free($resql);
472 
473  return $records;
474  } else {
475  $this->error = 'Error '.$this->db->lasterror();
476  $this->errors[] = $this->error;
477  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
478 
479  return -1;
480  }
481  }
482 
491  public function countAll($websiteid, array $filter = array(), $filtermode = 'AND')
492  {
493  dol_syslog(__METHOD__, LOG_DEBUG);
494 
495  $result = 0;
496 
497  $sql = 'SELECT COUNT(t.rowid) as nb';
498  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
499  $sql .= ' WHERE t.fk_website = '.((int) $websiteid);
500  // Manage filter (same than into fetchAll)
501  $sqlwhere = array();
502  if (count($filter) > 0) {
503  foreach ($filter as $key => $value) {
504  if ($key == 't.rowid' || $key == 't.fk_website' || $key == 'status') {
505  $sqlwhere[] = $key." = ".((int) $value);
506  } elseif ($key == 'type_container') {
507  $sqlwhere[] = $key." = '".$this->db->escape($value)."'";
508  } elseif ($key == 'lang' || $key == 't.lang') {
509  $listoflang = array();
510  $foundnull = 0;
511  foreach (explode(',', $value) as $tmpvalue) {
512  if ($tmpvalue == 'null') {
513  $foundnull++;
514  continue;
515  }
516  $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
517  }
518  $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")";
519  if ($foundnull) {
520  $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)";
521  }
522  $sqlwhere[] = $stringtouse;
523  } else {
524  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
525  }
526  }
527  }
528  if (count($sqlwhere) > 0) {
529  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
530  }
531 
532  $resql = $this->db->query($sql);
533  if ($resql) {
534  $obj = $this->db->fetch_object($resql);
535  if ($obj) {
536  $result = $obj->nb;
537  }
538 
539  $this->db->free($resql);
540 
541  return $result;
542  } else {
543  $this->error = 'Error '.$this->db->lasterror();
544  $this->errors[] = $this->error;
545  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
546 
547  return -1;
548  }
549  }
550 
558  public function update(User $user, $notrigger = false)
559  {
560  $this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
561  $this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
562  if ($this->aliasalt) {
563  $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
564  }
565 
566  $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl);
567  $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl);
568  $this->pageurl = preg_replace('/^\-/', '', $this->pageurl);
569 
570  // Remove spaces and be sure we have main language only
571  $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
572 
573  if ($this->fk_page > 0) {
574  if (empty($this->lang)) {
575  $this->error = "ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
576  return -1;
577  }
578  $tmppage = new WebsitePage($this->db);
579  $tmppage->fetch($this->fk_page);
580  if ($tmppage->lang == $this->lang) {
581  $this->error = "ErrorLanguageOfTranslatedPageIsSameThanThisPage";
582  return -1;
583  }
584  }
585 
586  return $this->updateCommon($user, $notrigger);
587  }
588 
596  public function delete(User $user, $notrigger = false)
597  {
598  global $conf;
599 
600  $error = 0;
601 
602  // Delete all child tables
603  if (!$error) {
604  foreach ($this->childtablesoncascade as $table) {
605  $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
606  $sql .= " WHERE fk_website_page = ".(int) $this->id;
607 
608  $result = $this->db->query($sql);
609  if (!$result) {
610  $error++;
611  $this->errors[] = $this->db->lasterror();
612  break;
613  }
614  }
615  }
616 
617  if (!$error) {
618  $result = $this->deleteCommon($user, $notrigger);
619  if ($result <= 0) {
620  $error++;
621  }
622  }
623 
624  if (!$error) {
625  $websiteobj = new Website($this->db);
626  $result = $websiteobj->fetch($this->fk_website);
627 
628  if ($result > 0) {
629  global $dolibarr_main_data_root;
630  $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websiteobj->ref;
631 
632  $filealias = $pathofwebsite.'/'.$this->pageurl.'.php';
633  $filetpl = $pathofwebsite.'/page'.$this->id.'.tpl.php';
634 
635  dol_delete_file($filealias);
636  dol_delete_file($filetpl);
637  } else {
638  $this->error = $websiteobj->error;
639  $this->errors = $websiteobj->errors;
640  }
641  }
642 
643  if (!$error) {
644  return 1;
645  } else {
646  return -1;
647  }
648  }
649 
662  public function createFromClone(User $user, $fromid, $newref, $newlang = '', $istranslation = 0, $newwebsite = 0, $newtitle = '')
663  {
664  global $hookmanager, $langs;
665 
666  $now = dol_now();
667  $error = 0;
668 
669  dol_syslog(__METHOD__, LOG_DEBUG);
670 
671  $object = new self($this->db);
672 
673  // Clean parameters
674  if (empty($newref) && !empty($newtitle)) {
675  $newref = strtolower(dol_sanitizeFileName(preg_replace('/\s+/', '-', $newtitle), '-', 1));
676  }
677 
678  // Check parameters
679  if (empty($newref)) {
680  $langs->load("errors");
681  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_TITLE"));
682  return -1;
683  }
684 
685  $this->db->begin();
686 
687  // Load source object
688  $object->fetch($fromid);
689  // Reset object
690  $object->id = 0;
691 
692  // Clear fields
693  $object->ref = $newref;
694  $object->pageurl = $newref;
695  $object->aliasalt = '';
696  $object->fk_user_creat = $user->id;
697  $object->author_alias = '';
698  $object->date_creation = $now;
699  $object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
700  $object->description = $object->title;
701  if (!empty($newlang)) {
702  $object->lang = $newlang;
703  }
704  if ($istranslation) {
705  $object->fk_page = $fromid;
706  } else {
707  $object->fk_page = 0;
708  }
709  if (!empty($newwebsite)) {
710  $object->fk_website = $newwebsite;
711  }
712  $object->import_key = '';
713  $object->status = self::STATUS_DRAFT;
714 
715  // Create clone
716  $object->context['createfromclone'] = 'createfromclone';
717  $result = $object->create($user);
718  if ($result < 0) {
719  $error++;
720  $this->error = $object->error;
721  $this->errors = $object->errors;
722  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
723  }
724 
725  unset($object->context['createfromclone']);
726 
727  // End
728  if (!$error) {
729  $this->db->commit();
730 
731  return $object;
732  } else {
733  $this->db->rollback();
734 
735  return -1;
736  }
737  }
738 
750  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '')
751  {
752  global $langs, $conf, $db;
753  global $dolibarr_main_authentication, $dolibarr_main_demo;
754  global $menumanager;
755 
756  $result = '';
757 
758  $label = '<u>'.$langs->trans("Page").'</u>';
759  $label .= '<br>';
760  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
761  $label .= '<b>'.$langs->trans('ID').':</b> '.$this->id.'<br>';
762  $label .= '<b>'.$langs->trans('Title').':</b> '.$this->title.'<br>';
763  $label .= '<b>'.$langs->trans('Language').':</b> '.$this->lang;
764 
765  $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
766 
767  $linkclose = '';
768  if (empty($notooltip)) {
769  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
770  $label = $langs->trans("ShowMyObject");
771  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
772  }
773  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
774  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
775  } else {
776  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
777  }
778 
779  $linkstart = '<a href="'.$url.'"';
780  $linkstart .= $linkclose.'>';
781  $linkend = '</a>';
782 
783  //$linkstart = $linkend = '';
784 
785  $result .= $linkstart;
786  if ($withpicto) {
787  $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);
788  }
789  if ($withpicto != 2) {
790  $result .= $this->ref;
791  }
792  $result .= $linkend;
793 
794  return $result;
795  }
796 
803  public function getLibStatut($mode = 0)
804  {
805  return $this->LibStatut($this->status, $mode);
806  }
807 
808  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
816  public function LibStatut($status, $mode = 0)
817  {
818  // phpcs:enable
819  global $langs;
820 
821  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
822  global $langs;
823  //$langs->load("mymodule");
824  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
825  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
826  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline');
827  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online');
828  }
829 
830  $statusType = 'status5';
831  if ($status == self::STATUS_VALIDATED) {
832  $statusType = 'status4';
833  }
834 
835  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
836  }
837 
848  public function setCategories($categories)
849  {
850  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
851  return $this->setCategoriesCommon($categories, Categorie::TYPE_WEBSITE_PAGE);
852  }
853 
860  public function initAsSpecimen()
861  {
862  global $user;
863 
864  $this->id = 0;
865 
866  $now = dol_now();
867 
868  $this->fk_website = '';
869  $this->type_container = 'page';
870  $this->pageurl = 'specimen';
871  $this->aliasalt = 'specimenalt';
872  $this->title = 'My Page';
873  $this->description = 'This is my page';
874  $this->image = '';
875  $this->keywords = 'keyword1, keyword2';
876  $this->allowed_in_frames = 1;
877  $this->htmlheader = '';
878  $this->content = '<html><body>This is a html content</body></html>';
879  $this->status = '';
880  $this->grabbed_from = '';
881  $this->date_creation = $now - (24 * 30 * 3600);
882  $this->date_modification = $now - (24 * 7 * 3600);
883  $this->fk_user_creat = $user->id;
884  $this->author_alias = 'mypublicpseudo';
885  }
886 }
$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.
Definition: user.class.php:45
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)
Renvoi le libelle d'un status donne.
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)
Retourne le libelle du status d'un user (actif, inactif)
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,...
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
print *****$script_file(".$version.") pid 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.
Definition: files.lib.php:1250
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)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
$conf db
API class for accounts.
Definition: inc.php:41