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';
61 public $type_container;
84 public $allowed_in_frames;
97 public $date_creation;
102 public $date_modification;
107 public $author_alias;
119 const STATUS_DRAFT = 0;
120 const STATUS_VALIDATED = 1;
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),
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),
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),
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'=>
'')
192 public $fk_element =
'fk_website_page';
207 protected $childtablesoncascade = array(
'categorie_website_page');
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)).
',';
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);
241 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
258 public function fetch($id, $website_id =
null, $page =
null, $aliasalt =
null)
264 $sql .=
" t.fk_website,";
265 $sql .=
' t.type_container,';
266 $sql .=
" t.pageurl,";
267 $sql .=
" t.aliasalt,";
269 $sql .=
" t.description,";
271 $sql .=
" t.keywords,";
272 $sql .=
" t.htmlheader,";
273 $sql .=
" t.content,";
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';
289 $sql .=
' WHERE 1 = 1';
291 $sql .=
' AND t.rowid = '.((int) $id);
294 $sql .=
' AND t.rowid <> '.abs($id);
296 if (
null !== $website_id) {
297 $sql .=
" AND t.fk_website = '".$this->db->escape($website_id).
"'";
301 $tmppage = explode(
'/', $page);
302 if (!empty($tmppage[1])) {
303 $pagetouse = $tmppage[1];
304 if (strlen($tmppage[0])) {
305 $langtouse = $tmppage[0];
308 $sql .=
" AND t.pageurl = '".$this->db->escape($pagetouse).
"'";
310 $sql .=
" AND t.lang = '".$this->db->escape($langtouse).
"'";
314 $sql .=
" AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).
",%' OR t.aliasalt LIKE '%, ".$this->
db->escape($aliasalt).
",%')";
318 $sql .= $this->
db->plimit(1);
322 $numrows = $this->
db->num_rows(
$resql);
324 $obj = $this->
db->fetch_object(
$resql);
326 $this->
id = $obj->rowid;
328 $this->fk_website = $obj->fk_website;
329 $this->type_container = $obj->type_container;
331 $this->pageurl = $obj->pageurl;
332 $this->
ref = $obj->pageurl;
333 $this->aliasalt = preg_replace(
'/,+$/',
'', preg_replace(
'/^,+/',
'', $obj->aliasalt));
335 $this->title = $obj->title;
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;
363 $this->errors[] =
'Error '.$this->db->lasterror();
364 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
382 public function fetchAll($websiteid, $sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
390 $sql .=
" t.fk_website,";
391 $sql .=
" t.type_container,";
392 $sql .=
" t.pageurl,";
393 $sql .=
" t.aliasalt,";
395 $sql .=
" t.description,";
397 $sql .=
" t.keywords,";
398 $sql .=
" t.htmlheader,";
399 $sql .=
" t.content,";
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);
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();
426 foreach (explode(
',', $value) as $tmpvalue) {
427 if ($tmpvalue ==
'null') {
431 $listoflang[] =
"'".$this->db->escape(substr(str_replace(
"'",
'', $tmpvalue), 0, 2)).
"'";
433 $stringtouse = $key.
" IN (".$this->
db->sanitize(join(
',', $listoflang), 1).
")";
435 $stringtouse =
"(".$stringtouse.
" OR ".$key.
" IS NULL)";
437 $sqlwhere[] = $stringtouse;
439 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
443 if (count($sqlwhere) > 0) {
444 $sql .=
" AND (".implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
447 if (!empty($sortfield)) {
448 $sql .= $this->
db->order($sortfield, $sortorder);
450 if (!empty($limit)) {
451 $sql .= $this->
db->plimit($limit, $offset);
458 while ($obj = $this->
db->fetch_object(
$resql)) {
459 $record =
new self($this->db);
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;
486 $records[$record->id] = $record;
492 $this->error =
'Error '.$this->db->lasterror();
493 $this->errors[] = $this->error;
494 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
508 public function countAll($websiteid, array $filter = array(), $filtermode =
'AND')
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);
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();
528 foreach (explode(
',', $value) as $tmpvalue) {
529 if ($tmpvalue ==
'null') {
533 $listoflang[] =
"'".$this->db->escape(substr(str_replace(
"'",
'', $tmpvalue), 0, 2)).
"'";
535 $stringtouse = $key.
" IN (".$this->
db->sanitize(join(
',', $listoflang), 1).
")";
537 $stringtouse =
"(".$stringtouse.
" OR ".$key.
" IS NULL)";
539 $sqlwhere[] = $stringtouse;
541 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
545 if (count($sqlwhere) > 0) {
546 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
551 $obj = $this->
db->fetch_object(
$resql);
560 $this->error =
'Error '.$this->db->lasterror();
561 $this->errors[] = $this->error;
562 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
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)).
',';
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);
588 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
590 if ($this->fk_page > 0) {
591 if (empty($this->lang)) {
592 $this->error =
"ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother";
596 $tmppage->fetch($this->fk_page);
597 if ($tmppage->lang == $this->lang) {
598 $this->error =
"ErrorLanguageOfTranslatedPageIsSameThanThisPage";
613 public function delete(
User $user, $notrigger =
false)
621 foreach ($this->childtablesoncascade as $table) {
622 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$table;
623 $sql .=
" WHERE fk_website_page = ".(int) $this->
id;
625 $result = $this->
db->query($sql);
628 $this->errors[] = $this->
db->lasterror();
643 $result = $websiteobj->fetch($this->fk_website);
646 global $dolibarr_main_data_root;
647 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$websiteobj->ref;
649 $filealias = $pathofwebsite.
'/'.$this->pageurl.
'.php';
650 $filetpl = $pathofwebsite.
'/page'.$this->id.
'.tpl.php';
655 $this->error = $websiteobj->error;
656 $this->errors = $websiteobj->errors;
679 public function createFromClone(
User $user, $fromid, $newref, $newlang =
'', $istranslation = 0, $newwebsite = 0, $newtitle =
'')
681 global $hookmanager, $langs;
688 $object =
new self($this->db);
691 if (empty($newref) && !empty($newtitle)) {
696 if (empty($newref)) {
697 $langs->load(
"errors");
698 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"WEBSITE_TITLE"));
705 $object->fetch($fromid);
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;
721 if ($istranslation) {
722 $object->fk_page = $fromid;
724 $object->fk_page = 0;
726 if (!empty($newwebsite)) {
727 $object->fk_website = $newwebsite;
729 $object->import_key =
'';
730 $object->status = self::STATUS_DRAFT;
733 $object->context[
'createfromclone'] =
'createfromclone';
734 $result = $object->create($user);
737 $this->error = $object->error;
738 $this->errors = $object->errors;
739 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
742 unset($object->context[
'createfromclone']);
750 $this->
db->rollback();
767 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
769 global $langs, $conf, $db;
770 global $dolibarr_main_authentication, $dolibarr_main_demo;
775 $label =
'<u>'.$langs->trans(
"Page").
'</u>';
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;
782 $url = DOL_URL_ROOT.
'/website/index.php?websiteid='.$this->fk_website.
'&pageid='.$this->id;
785 if (empty($notooltip)) {
786 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
787 $label = $langs->trans(
"ShowMyObject");
788 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
790 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
791 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
793 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
796 $linkstart =
'<a href="'.$url.
'"';
797 $linkstart .= $linkclose.
'>';
802 $result .= $linkstart;
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);
806 if ($withpicto != 2) {
807 $result .= $this->ref;
822 return $this->
LibStatut($this->status, $mode);
838 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
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');
847 $statusType =
'status5';
848 if ($status == self::STATUS_VALIDATED) {
849 $statusType =
'status4';
852 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
867 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
885 $this->fk_website =
'';
886 $this->type_container =
'page';
887 $this->pageurl =
'specimen';
888 $this->aliasalt =
'specimenalt';
889 $this->title =
'My Page';
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>';
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';