29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $element =
'websitepage';
46 public $table_element =
'website_page';
51 public $picto =
'file-code';
63 public $type_container;
86 public $allowed_in_frames;
99 public $date_creation;
104 public $date_modification;
109 public $author_alias;
121 const STATUS_DRAFT = 0;
122 const STATUS_VALIDATED = 1;
153 public $fields = array(
154 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
155 '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'),
156 'aliasalt' =>array(
'type'=>
'varchar(255)',
'label'=>
'AliasAlt',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'index'=>0,
'position'=>11,
'searchall'=>0,
'comment'=>
'Alias alternative of page'),
157 'type_container' =>array(
'type'=>
'varchar(16)',
'label'=>
'Type',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'index'=>0,
'position'=>12,
'comment'=>
'Type of container'),
158 'title' =>array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>1,
'position'=>30,
'searchall'=>1,
'help'=>
'UseTextBetween5And70Chars'),
159 'description' =>array(
'type'=>
'varchar(255)',
'label'=>
'Description',
'enabled'=>1,
'visible'=>1,
'position'=>30,
'searchall'=>1),
160 '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"'),
161 'keywords' =>array(
'type'=>
'varchar(255)',
'label'=>
'Keywords',
'enabled'=>1,
'visible'=>1,
'position'=>45,
'searchall'=>0),
162 'lang' =>array(
'type'=>
'varchar(6)',
'label'=>
'Lang',
'enabled'=>1,
'notnull'=>-1,
'visible'=>1,
'position'=>45,
'searchall'=>0),
164 'fk_website' =>array(
'type'=>
'integer',
'label'=>
'WebsiteId',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>40,
'searchall'=>0,
'foreignkey'=>
'websitepage.rowid'),
165 'fk_page' =>array(
'type'=>
'integer',
'label'=>
'ParentPageId',
'enabled'=>1,
'visible'=>1,
'notnull'=>-1,
'position'=>45,
'searchall'=>0,
'foreignkey'=>
'website.rowid'),
166 'allowed_in_frames' =>array(
'type'=>
'integer',
'label'=>
'AllowedInFrames',
'enabled'=>1,
'visible'=>-1,
'position'=>48,
'searchall'=>0,
'default'=>0),
167 'htmlheader' =>array(
'type'=>
'text',
'label'=>
'HtmlHeader',
'enabled'=>1,
'visible'=>0,
'position'=>50,
'searchall'=>0),
168 'content' =>array(
'type'=>
'mediumtext',
'label'=>
'Content',
'enabled'=>1,
'visible'=>0,
'position'=>51,
'searchall'=>0),
169 'grabbed_from' =>array(
'type'=>
'varchar(255)',
'label'=>
'GrabbedFrom',
'enabled'=>1,
'visible'=>1,
'index'=>1,
'position'=>400,
'comment'=>
'URL page content was grabbed from'),
170 'date_creation' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>500),
171 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>501),
173 'fk_user_creat' =>array(
'type'=>
'integer',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-1,
'notnull'=>
true,
'position'=>510),
174 'author_alias' =>array(
'type'=>
'varchar(64)',
'label'=>
'AuthorAlias',
'enabled'=>1,
'visible'=>-1,
'index'=>0,
'position'=>511,
'comment'=>
'Author alias'),
175 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-1,
'position'=>512),
177 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-1,
'index'=>1,
'position'=>1000,
'notnull'=>-1),
178 'object_type' => array(
'type' =>
'varchar(255)',
'label' =>
'ObjectType',
'enabled'=>1,
'visible'=>0,
'position'=>46,
'searchall'=>0,
'help'=>
''),
179 'fk_object' => array(
'type' =>
'varchar(255)',
'label' =>
'ObjectId',
'enabled'=>1,
'visible'=>0,
'position'=>47,
'searchall'=>0,
'help'=>
'')
194 public $fk_element =
'fk_website_page';
209 protected $childtablesoncascade = array(
'categorie_website_page');
233 $this->keywords =
dol_trunc($this->keywords, 255,
'right',
'utf-8', 1);
234 if ($this->aliasalt) {
235 $this->aliasalt =
','.preg_replace(
'/,+$/',
'', preg_replace(
'/^,+/',
'', $this->aliasalt)).
',';
238 $this->pageurl = preg_replace(
'/[^a-z0-9\-\_]/i',
'', $this->pageurl);
239 $this->pageurl = preg_replace(
'/\-\-+/',
'-', $this->pageurl);
240 $this->pageurl = preg_replace(
'/^\-/',
'', $this->pageurl);
243 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
260 public function fetch($id, $website_id =
null, $page =
null, $aliasalt =
null)
266 $sql .=
" t.fk_website,";
267 $sql .=
' t.type_container,';
268 $sql .=
" t.pageurl,";
269 $sql .=
" t.aliasalt,";
271 $sql .=
" t.description,";
273 $sql .=
" t.keywords,";
274 $sql .=
" t.htmlheader,";
275 $sql .=
" t.content,";
277 $sql .=
" t.fk_page,";
278 $sql .=
" t.allowed_in_frames,";
279 $sql .=
" t.status,";
280 $sql .=
" t.grabbed_from,";
281 $sql .=
" t.date_creation,";
282 $sql .=
" t.tms as date_modification,";
283 $sql .=
" t.fk_user_creat,";
284 $sql .=
" t.author_alias,";
285 $sql .=
" t.fk_user_modif,";
286 $sql .=
" t.import_key,";
287 $sql .=
" t.object_type,";
288 $sql .=
" t.fk_object";
289 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
291 $sql .=
' WHERE 1 = 1';
293 $sql .=
' AND t.rowid = '.((int) $id);
296 $sql .=
' AND t.rowid <> '.abs($id);
298 if (
null !== $website_id) {
299 $sql .=
" AND t.fk_website = '".$this->db->escape($website_id).
"'";
303 $tmppage = explode(
'/', $page);
304 if (!empty($tmppage[1])) {
305 $pagetouse = $tmppage[1];
306 if (strlen($tmppage[0])) {
307 $langtouse = $tmppage[0];
310 $sql .=
" AND t.pageurl = '".$this->db->escape($pagetouse).
"'";
312 $sql .=
" AND t.lang = '".$this->db->escape($langtouse).
"'";
316 $sql .=
" AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).
",%' OR t.aliasalt LIKE '%, ".$this->
db->escape($aliasalt).
",%')";
320 $sql .= $this->
db->plimit(1);
324 $numrows = $this->
db->num_rows(
$resql);
326 $obj = $this->
db->fetch_object(
$resql);
328 $this->
id = $obj->rowid;
330 $this->fk_website = $obj->fk_website;
331 $this->type_container = $obj->type_container;
333 $this->pageurl = $obj->pageurl;
334 $this->
ref = $obj->pageurl;
335 $this->aliasalt = preg_replace(
'/,+$/',
'', preg_replace(
'/^,+/',
'', $obj->aliasalt));
337 $this->title = $obj->title;
339 $this->image = $obj->image;
340 $this->keywords = $obj->keywords;
341 $this->htmlheader = $obj->htmlheader;
342 $this->content = $obj->content;
343 $this->lang = $obj->lang;
344 $this->fk_page = $obj->fk_page;
345 $this->allowed_in_frames = $obj->allowed_in_frames;
346 $this->status = $obj->status;
347 $this->grabbed_from = $obj->grabbed_from;
348 $this->date_creation = $this->
db->jdate($obj->date_creation);
349 $this->date_modification = $this->
db->jdate($obj->date_modification);
350 $this->fk_user_creat = $obj->fk_user_creat;
351 $this->author_alias = $obj->author_alias;
352 $this->fk_user_modif = $obj->fk_user_modif;
353 $this->import_key = $obj->import_key;
354 $this->object_type = $obj->object_type;
355 $this->fk_object = $obj->fk_object;
365 $this->errors[] =
'Error '.$this->db->lasterror();
366 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
384 public function fetchAll($websiteid, $sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
392 $sql .=
" t.fk_website,";
393 $sql .=
" t.type_container,";
394 $sql .=
" t.pageurl,";
395 $sql .=
" t.aliasalt,";
397 $sql .=
" t.description,";
399 $sql .=
" t.keywords,";
400 $sql .=
" t.htmlheader,";
401 $sql .=
" t.content,";
403 $sql .=
" t.fk_page,";
404 $sql .=
" t.allowed_in_frames,";
405 $sql .=
" t.status,";
406 $sql .=
" t.grabbed_from,";
407 $sql .=
" t.date_creation,";
408 $sql .=
" t.tms as date_modification,";
409 $sql .=
" t.fk_user_creat,";
410 $sql .=
" t.author_alias,";
411 $sql .=
" t.fk_user_modif,";
412 $sql .=
" t.import_key,";
413 $sql .=
" t.object_type,";
414 $sql .=
" t.fk_object";
415 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
416 $sql .=
' WHERE t.fk_website = '.((int) $websiteid);
419 if (count($filter) > 0) {
420 foreach ($filter as $key => $value) {
421 if ($key ==
't.rowid' || $key ==
'rowid' || $key ==
't.fk_website' || $key ==
'fk_website' || $key ==
'status' || $key ==
't.status') {
422 $sqlwhere[] = $key.
" = ".((int) $value);
423 } elseif ($key ==
'type_container' || $key ==
't.type_container') {
424 $sqlwhere[] = $key.
" = '".$this->
db->escape($value).
"'";
425 } elseif ($key ==
'lang' || $key ==
't.lang') {
426 $listoflang = array();
428 foreach (explode(
',', $value) as $tmpvalue) {
429 if ($tmpvalue ==
'null') {
433 $listoflang[] =
"'".$this->db->escape(substr(str_replace(
"'",
'', $tmpvalue), 0, 2)).
"'";
435 $stringtouse = $key.
" IN (".$this->
db->sanitize(join(
',', $listoflang), 1).
")";
437 $stringtouse =
"(".$stringtouse.
" OR ".$key.
" IS NULL)";
439 $sqlwhere[] = $stringtouse;
441 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
445 if (count($sqlwhere) > 0) {
446 $sql .=
" AND (".implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
449 if (!empty($sortfield)) {
450 $sql .= $this->
db->order($sortfield, $sortorder);
452 if (!empty($limit)) {
453 $sql .= $this->
db->plimit($limit, $offset);
460 while ($obj = $this->
db->fetch_object(
$resql)) {
461 $record =
new self($this->db);
463 $record->id = $obj->rowid;
464 $record->fk_website = $obj->fk_website;
465 $record->type_container = $obj->type_container;
466 $record->pageurl = $obj->pageurl;
467 $record->aliasalt = preg_replace(
'/,+$/',
'', preg_replace(
'/^,+/',
'', $obj->aliasalt));
468 $record->title = $obj->title;
469 $record->description = $obj->description;
470 $record->image = $obj->image;
471 $record->keywords = $obj->keywords;
472 $record->htmlheader = $obj->htmlheader;
473 $record->content = $obj->content;
474 $record->lang = $obj->lang;
475 $record->fk_page = $obj->fk_page;
476 $record->allowed_in_frames = $obj->allowed_in_frames;
477 $record->status = $obj->status;
478 $record->grabbed_from = $obj->grabbed_from;
479 $record->date_creation = $this->
db->jdate($obj->date_creation);
480 $record->date_modification = $this->
db->jdate($obj->date_modification);
481 $record->fk_user_creat = $obj->fk_user_creat;
482 $record->author_alias = $obj->author_alias;
483 $record->fk_user_modif = $obj->fk_user_modif;
484 $record->import_key = $obj->import_key;
485 $record->object_type = $obj->object_type;
486 $record->fk_object = $obj->fk_object;
488 $records[$record->id] = $record;
494 $this->error =
'Error '.$this->db->lasterror();
495 $this->errors[] = $this->error;
496 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
510 public function countAll($websiteid, array $filter = array(), $filtermode =
'AND')
516 $sql =
'SELECT COUNT(t.rowid) as nb';
517 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
518 $sql .=
' WHERE t.fk_website = '.((int) $websiteid);
521 if (count($filter) > 0) {
522 foreach ($filter as $key => $value) {
523 if ($key ==
't.rowid' || $key ==
't.fk_website' || $key ==
'status') {
524 $sqlwhere[] = $key.
" = ".((int) $value);
525 } elseif ($key ==
'type_container') {
526 $sqlwhere[] = $key.
" = '".$this->
db->escape($value).
"'";
527 } elseif ($key ==
'lang' || $key ==
't.lang') {
528 $listoflang = array();
530 foreach (explode(
',', $value) as $tmpvalue) {
531 if ($tmpvalue ==
'null') {
535 $listoflang[] =
"'".$this->db->escape(substr(str_replace(
"'",
'', $tmpvalue), 0, 2)).
"'";
537 $stringtouse = $key.
" IN (".$this->
db->sanitize(join(
',', $listoflang), 1).
")";
539 $stringtouse =
"(".$stringtouse.
" OR ".$key.
" IS NULL)";
541 $sqlwhere[] = $stringtouse;
543 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
547 if (count($sqlwhere) > 0) {
548 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
553 $obj = $this->
db->fetch_object(
$resql);
562 $this->error =
'Error '.$this->db->lasterror();
563 $this->errors[] = $this->error;
564 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
580 $this->keywords =
dol_trunc($this->keywords, 255,
'right',
'utf-8', 1);
581 if ($this->aliasalt) {
582 $this->aliasalt =
','.preg_replace(
'/,+$/',
'', preg_replace(
'/^,+/',
'', $this->aliasalt)).
',';
585 $this->pageurl = preg_replace(
'/[^a-z0-9\-\_]/i',
'', $this->pageurl);
586 $this->pageurl = preg_replace(
'/\-\-+/',
'-', $this->pageurl);
587 $this->pageurl = preg_replace(
'/^\-/',
'', $this->pageurl);
590 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
592 if ($this->fk_page > 0) {
593 if (empty($this->lang)) {
594 $this->error =
"ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
598 $tmppage->fetch($this->fk_page);
599 if ($tmppage->lang == $this->lang) {
600 $this->error =
"ErrorLanguageOfTranslatedPageIsSameThanThisPage";
615 public function delete(
User $user, $notrigger =
false)
623 foreach ($this->childtablesoncascade as $table) {
624 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$table;
625 $sql .=
" WHERE fk_website_page = ".(int) $this->
id;
627 $result = $this->
db->query($sql);
630 $this->errors[] = $this->
db->lasterror();
645 $result = $websiteobj->fetch($this->fk_website);
648 global $dolibarr_main_data_root;
649 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$websiteobj->ref;
651 $filealias = $pathofwebsite.
'/'.$this->pageurl.
'.php';
652 $filetpl = $pathofwebsite.
'/page'.$this->id.
'.tpl.php';
657 $this->error = $websiteobj->error;
658 $this->errors = $websiteobj->errors;
681 public function createFromClone(
User $user, $fromid, $newref, $newlang =
'', $istranslation = 0, $newwebsite = 0, $newtitle =
'')
683 global $hookmanager, $langs;
690 $object =
new self($this->db);
693 if (empty($newref) && !empty($newtitle)) {
698 if (empty($newref)) {
699 $langs->load(
"errors");
700 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"WEBSITE_TITLE"));
707 $object->fetch($fromid);
712 $object->ref = $newref;
713 $object->pageurl = $newref;
714 $object->aliasalt =
'';
715 $object->fk_user_creat = $user->id;
716 $object->author_alias =
'';
717 $object->date_creation = $now;
718 $object->title = ($newtitle ==
'1' ? $object->title : ($newtitle ? $newtitle : $object->title));
719 $object->description = $object->title;
720 if (!empty($newlang)) {
721 $object->lang = $newlang;
723 if ($istranslation) {
724 $object->fk_page = $fromid;
726 $object->fk_page = 0;
728 if (!empty($newwebsite)) {
729 $object->fk_website = $newwebsite;
731 $object->import_key =
'';
732 $object->status = self::STATUS_DRAFT;
735 $object->context[
'createfromclone'] =
'createfromclone';
736 $result = $object->create($user);
739 $this->error = $object->error;
740 $this->errors = $object->errors;
741 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
744 unset($object->context[
'createfromclone']);
752 $this->
db->rollback();
769 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
771 global $langs, $conf, $db;
772 global $dolibarr_main_authentication, $dolibarr_main_demo;
777 $label =
'<u>'.$langs->trans(
"Page").
'</u>';
779 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
780 $label .=
'<b>'.$langs->trans(
'ID').
':</b> '.$this->
id.
'<br>';
781 $label .=
'<b>'.$langs->trans(
'Title').
':</b> '.$this->title.
'<br>';
782 $label .=
'<b>'.$langs->trans(
'Language').
':</b> '.$this->lang;
784 $url = DOL_URL_ROOT.
'/website/index.php?websiteid='.$this->fk_website.
'&pageid='.$this->id;
787 if (empty($notooltip)) {
788 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
789 $label = $langs->trans(
"ShowMyObject");
790 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
792 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
793 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
795 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
798 $linkstart =
'<a href="'.$url.
'"';
799 $linkstart .= $linkclose.
'>';
804 $result .= $linkstart;
806 $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);
808 if ($withpicto != 2) {
809 $result .= $this->ref;
824 return $this->
LibStatut($this->status, $mode);
840 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
843 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
844 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
845 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
846 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
849 $statusType =
'status5';
850 if ($status == self::STATUS_VALIDATED) {
851 $statusType =
'status4';
854 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
869 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
887 $this->fk_website =
'';
888 $this->type_container =
'page';
889 $this->pageurl =
'specimen';
890 $this->aliasalt =
'specimenalt';
891 $this->title =
'My Page';
894 $this->keywords =
'keyword1, keyword2';
895 $this->allowed_in_frames = 1;
896 $this->htmlheader =
'';
897 $this->content =
'<html><body>This is a html content</body></html>';
899 $this->grabbed_from =
'';
900 $this->date_creation = $now - (24 * 30 * 3600);
901 $this->date_modification = $now - (24 * 7 * 3600);
902 $this->fk_user_creat = $user->id;
903 $this->author_alias =
'mypublicpseudo';