30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43 public $element =
'website';
48 public $table_element =
'website';
53 protected $childtablesoncascade = array();
58 public $picto =
'globe';
88 public $fk_default_home;
93 public $fk_user_creat;
98 public $fk_user_modif;
108 public $use_manifest;
118 public $name_template;
120 const STATUS_DRAFT = 0;
121 const STATUS_VALIDATED = 1;
133 $this->ismultientitymanaged = 1;
145 global
$conf, $langs;
153 if (isset($this->entity)) {
154 $this->entity = (int) $this->entity;
156 if (isset($this->
ref)) {
157 $this->
ref = trim($this->
ref);
162 if (isset($this->
status)) {
165 if (empty($this->date_creation)) {
166 $this->date_creation = $now;
168 if (empty($this->date_modification)) {
169 $this->date_modification = $now;
172 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
173 $tmparray = explode(
',', $this->otherlang);
174 if (is_array($tmparray)) {
175 foreach ($tmparray as $key => $val) {
177 if (empty(trim($val))) {
178 unset($tmparray[$key]);
181 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
183 $this->otherlang = implode(
',', $tmparray);
187 if (empty($this->entity)) {
188 $this->entity =
$conf->entity;
190 if (empty($this->lang)) {
191 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
195 $pathofwebsite =
$conf->website->dir_output.
'/'.$this->ref;
198 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
201 $sql .=
'description,';
203 $sql .=
'otherlang,';
205 $sql .=
'fk_default_home,';
206 $sql .=
'virtualhost,';
207 $sql .=
'fk_user_creat,';
208 $sql .=
'date_creation,';
211 $sql .=
') VALUES (';
212 $sql .=
' '.((empty($this->entity) && $this->entity !=
'0') ?
'NULL' : ((int) $this->entity)).
',';
213 $sql .=
' '.(!isset($this->
ref) ?
'NULL' :
"'".$this->db->escape($this->
ref).
"'").
',';
215 $sql .=
' '.(!isset($this->lang) ?
'NULL' :
"'".$this->db->escape($this->lang).
"'").
',';
216 $sql .=
' '.(!isset($this->otherlang) ?
'NULL' :
"'".$this->db->escape($this->otherlang).
"'").
',';
217 $sql .=
' '.(!isset($this->
status) ?
'1' : ((int) $this->
status)).
',';
218 $sql .=
' '.(!isset($this->fk_default_home) ?
'NULL' : ((int) $this->fk_default_home)).
',';
219 $sql .=
' '.(!isset($this->virtualhost) ?
'NULL' :
"'".$this->db->escape($this->virtualhost).
"'").
",";
220 $sql .=
' '.(!isset($this->fk_user_creat) ? ((int) $user->id) : ((int) $this->fk_user_creat)).
',';
221 $sql .=
' '.(!isset($this->date_creation) ||
dol_strlen((
string) $this->date_creation) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_creation).
"'").
",";
222 $sql .=
' '.((int) $this->
position).
",";
223 $sql .=
' '.(!isset($this->date_modification) ||
dol_strlen((
string) $this->date_modification) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_modification).
"'");
228 $resql = $this->db->query($sql);
231 $this->errors[] =
'Error '.$this->db->lasterror();
232 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
236 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
239 $tmplangarray = explode(
',', $this->otherlang);
240 if (is_array($tmplangarray)) {
242 foreach ($tmplangarray as $val) {
243 if (trim($val) == $this->lang) {
246 dol_mkdir(
$conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val), DOL_DATA_ROOT);
251 dol_mkdir(
$conf->medias->multidir_output[
$conf->entity].
'/image/'.$this->ref, DOL_DATA_ROOT);
256 $pathtomedias = DOL_DATA_ROOT.
'/medias';
257 $pathtomediasinwebsite = $pathofwebsite.
'/medias';
259 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
260 dol_mkdir(dirname($pathtomediasinwebsite));
261 $result = symlink($pathtomedias, $pathtomediasinwebsite);
263 $langs->load(
"errors");
278 $stringtodolibarrfile =
"# Some properties for Dolibarr web site CMS\n";
279 $stringtodolibarrfile .=
"param=value\n";
281 file_put_contents($pathofwebsite.
'/.dolibarr', $stringtodolibarrfile);
282 dolChmod($pathofwebsite.
'/.dolibarr');
284 $filelicense = $pathofwebsite.
'/LICENSE';
286 $licensecontent =
"LICENSE\n-------\nThis website template content (HTML and PHP code) is published under the license CC-BY-SA - https://creativecommons.org/licenses/by/4.0/";
293 $this->db->rollback();
294 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
313 public function fetch($id, $ref =
null)
319 $sql .=
" t.entity,";
321 $sql .=
" t.position,";
322 $sql .=
" t.description,";
324 $sql .=
" t.otherlang,";
325 $sql .=
" t.status,";
326 $sql .=
" t.fk_default_home,";
327 $sql .=
" t.use_manifest,";
328 $sql .=
" t.virtualhost,";
329 $sql .=
" t.fk_user_creat,";
330 $sql .=
" t.fk_user_modif,";
331 $sql .=
" t.date_creation,";
332 $sql .=
" t.tms as date_modification,";
333 $sql .=
" t.name_template";
334 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
335 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
337 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
339 $sql .=
" AND t.rowid = ".(int) $id;
342 $resql = $this->db->query($sql);
344 $numrows = $this->db->num_rows($resql);
346 $obj = $this->db->fetch_object($resql);
348 $this->
id = $obj->rowid;
350 $this->entity = $obj->entity;
351 $this->
ref = $obj->ref;
354 $this->lang = $obj->lang;
355 $this->otherlang = $obj->otherlang;
356 $this->
status = $obj->status;
357 $this->fk_default_home = $obj->fk_default_home;
358 $this->virtualhost = $obj->virtualhost;
359 $this->use_manifest = $obj->use_manifest;
360 $this->fk_user_creat = $obj->fk_user_creat;
361 $this->fk_user_modif = $obj->fk_user_modif;
362 $this->date_creation = $this->db->jdate($obj->date_creation);
363 $this->date_modification = $this->db->jdate($obj->date_modification);
364 $this->name_template = $obj->name_template;
366 $this->db->free($resql);
374 $this->errors[] =
'Error '.$this->db->lasterror();
375 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
393 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
401 $sql .=
" t.entity,";
403 $sql .=
" t.description,";
405 $sql .=
" t.otherlang,";
406 $sql .=
" t.status,";
407 $sql .=
" t.fk_default_home,";
408 $sql .=
" t.virtualhost,";
409 $sql .=
" t.fk_user_creat,";
410 $sql .=
" t.fk_user_modif,";
411 $sql .=
" t.date_creation,";
412 $sql .=
" t.tms as date_modification";
413 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
414 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
417 if (is_array($filter)) {
419 if (count($filter) > 0) {
420 foreach ($filter as $key => $value) {
421 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($value).
"%'";
424 if (count($sqlwhere) > 0) {
425 $sql .=
' AND '.implode(
' '.$this->db->sanitize($filtermode).
' ', $sqlwhere);
435 $this->errors[] = $errormessage;
436 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
440 if (!empty($sortfield)) {
441 $sql .= $this->db->order($sortfield, $sortorder);
443 if (!empty($limit)) {
444 $sql .= $this->db->plimit($limit, $offset);
447 $resql = $this->db->query($sql);
449 $num = $this->db->num_rows($resql);
451 while ($obj = $this->db->fetch_object($resql)) {
452 $record =
new self($this->db);
454 $record->id = $obj->rowid;
456 $record->entity = $obj->entity;
457 $record->ref = $obj->ref;
458 $record->description = $obj->description;
459 $record->lang = $obj->lang;
460 $record->otherlang = $obj->otherlang;
461 $record->status = $obj->status;
462 $record->fk_default_home = $obj->fk_default_home;
463 $record->virtualhost = $obj->virtualhost;
464 $record->fk_user_creat = $obj->fk_user_creat;
465 $record->fk_user_modif = $obj->fk_user_modif;
466 $record->date_creation = $this->db->jdate($obj->date_creation);
467 $record->date_modification = $this->db->jdate($obj->date_modification);
469 $records[$record->id] = $record;
471 $this->db->free($resql);
475 $this->errors[] =
'Error '.$this->db->lasterror();
476 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
491 global
$conf, $langs;
499 if (isset($this->entity)) {
500 $this->entity = (int) $this->entity;
502 if (isset($this->
ref)) {
503 $this->
ref = trim($this->
ref);
508 if (isset($this->
status)) {
513 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
514 $tmparray = explode(
',', $this->otherlang);
515 if (is_array($tmparray)) {
516 foreach ($tmparray as $key => $val) {
518 if (empty(trim($val))) {
519 unset($tmparray[$key]);
522 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
524 $this->otherlang = implode(
',', $tmparray);
526 if (empty($this->lang)) {
527 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
535 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
536 $sql .=
' entity = '.(isset($this->entity) ? ((int) $this->entity) :
"null").
',';
537 $sql .=
' ref = '.(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
',';
538 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
539 $sql .=
' lang = '.(isset($this->lang) ?
"'".$this->db->escape($this->lang).
"'" :
"null").
',';
540 $sql .=
' otherlang = '.(isset($this->otherlang) ?
"'".$this->db->escape($this->otherlang).
"'" :
"null").
',';
541 $sql .=
' status = '.(isset($this->
status) ? ((int) $this->
status) :
"null").
',';
542 $sql .=
' fk_default_home = '.(($this->fk_default_home > 0) ? ((
int) $this->fk_default_home) :
"null").
',';
543 $sql .=
' use_manifest = '.((int) $this->use_manifest).
',';
544 $sql .=
' virtualhost = '.(($this->virtualhost !=
'') ?
"'".$this->db->escape($this->virtualhost).
"'" :
"null").
',';
545 $sql .=
' fk_user_modif = '.(!isset($this->fk_user_modif) ? ((int) $user->id) : ((int) $this->fk_user_modif)).
',';
546 $sql .=
' date_creation = '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
',';
547 $sql .=
' tms = '.(dol_strlen($this->date_modification) != 0 ?
"'".$this->db->idate($this->date_modification).
"'" :
"'".$this->db->idate(
dol_now()).
"'");
548 $sql .=
' WHERE rowid='.((int) $this->
id);
552 $resql = $this->db->query($sql);
555 $this->errors[] =
'Error '.$this->db->lasterror();
556 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
559 if (!$error && !$notrigger) {
564 $tmplangarray = explode(
',', $this->otherlang);
565 if (is_array($tmplangarray)) {
567 foreach ($tmplangarray as $val) {
568 if (trim($val) == $this->lang) {
571 dol_mkdir(
$conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
583 $this->db->rollback();
600 public function delete(
User $user, $notrigger = 0)
611 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'categorie_website_page';
612 $sql .=
' WHERE fk_website_page IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'website_page WHERE fk_website = '.((int) $this->
id).
')';
614 $resql = $this->db->query($sql);
617 $this->errors[] =
'Error '.$this->db->lasterror();
618 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
623 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
624 $sql .=
' WHERE fk_website = '.((int) $this->
id);
626 $resql = $this->db->query($sql);
629 $this->errors[] =
'Error '.$this->db->lasterror();
630 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
640 if (!$error && !empty($this->
ref)) {
641 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
648 $this->db->rollback();
667 global
$conf, $langs;
676 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
677 $sql .=
' WHERE fk_website = '.((int) $this->
id);
679 $resql = $this->db->query($sql);
682 $this->errors[] =
'Error '.$this->db->lasterror();
683 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
687 if (!$error && !empty($this->
ref)) {
688 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
694 $pathtomedias = DOL_DATA_ROOT.
'/medias';
695 $pathtomediasinwebsite = $pathofwebsite.
'/medias';
697 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
698 dol_mkdir(dirname($pathtomediasinwebsite));
699 $result = symlink($pathtomedias, $pathtomediasinwebsite);
701 $this->errors[] = $langs->trans(
"ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias);
709 $this->db->rollback();
731 global
$conf, $langs;
732 global $dolibarr_main_data_root;
741 if (empty($newref)) {
742 $this->error =
'ErrorBadParameter newref';
749 if (
$object->fetch(0, $newref) > 0) {
750 $this->error =
'ErrorNewRefIsAlreadyUsed';
759 $oldidforhome =
$object->fk_default_home;
762 $pathofwebsiteold = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($oldref);
763 $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($newref);
766 $fileindex = $pathofwebsitenew.
'/index.php';
778 $object->fk_user_creat = $user->id;
780 $object->status = self::STATUS_DRAFT;
782 $object->lang = substr($langs->defaultlang, 0, 2);
786 $object->context[
'createfromclone'] =
'createfromclone';
787 $result =
$object->create($user);
791 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
801 $pathtomedias = DOL_DATA_ROOT.
'/medias';
802 $pathtomediasinwebsite = $pathofwebsitenew.
'/medias';
804 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
805 dol_mkdir(dirname($pathtomediasinwebsite));
806 $result = symlink($pathtomedias, $pathtomediasinwebsite);
810 $pathofmediasjsold = DOL_DATA_ROOT.
'/medias/js/'.$oldref;
811 $pathofmediasjsnew = DOL_DATA_ROOT.
'/medias/js/'.$newref;
814 $pathofmediasimageold = DOL_DATA_ROOT.
'/medias/image/'.$oldref;
815 $pathofmediasimagenew = DOL_DATA_ROOT.
'/medias/image/'.$newref;
819 $objectpages =
new WebsitePage($this->db);
820 $listofpages = $objectpages->fetchAll($fromid);
821 foreach ($listofpages as $pageid => $objectpageold) {
823 $filetplold = $pathofwebsitenew.
'/page'.$pageid.
'.tpl.php';
827 $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl,
'', 0,
$object->id,
'1');
830 if (is_object($objectpagenew) && $objectpagenew->pageurl) {
831 $filealias = $pathofwebsitenew.
'/'.$objectpagenew->pageurl.
'.php';
832 $filetplnew = $pathofwebsitenew.
'/page'.$objectpagenew->id.
'.tpl.php';
845 if ($pageid == $oldidforhome) {
846 $newidforhome = $objectpagenew->id;
857 $object->fk_default_home = $newidforhome;
865 $filetpl = $pathofwebsitenew.
'/page'.$newidforhome.
'.tpl.php';
866 $filewrapper = $pathofwebsitenew.
'/wrapper.php';
874 unset(
$object->context[
'createfromclone']);
882 $this->db->rollback();
899 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
905 $label =
'<u>'.img_picto(
'',
'website',
'class="pictofixedwidth"').$langs->trans(
"WebSite").
'</u>';
907 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
908 $label .=
'<b>'.$langs->trans(
'MainLanguage').
':</b> '.$this->lang;
916 if (!empty($this->virtualhost)) {
917 $linkstart =
'<a target="_blank" rel="noopener" href="'.$this->virtualhost.
'">';
920 $linkstart = $linkend =
'';
923 $result .= $linkstart;
925 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'),
'class="pictofixedwidth'.($notooltip ?
'' :
' classfortooltip').
'"');
927 $result .= $this->ref;
957 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
960 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
961 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
962 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
963 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
966 $statusType =
'status5';
967 if ($status == self::STATUS_VALIDATED) {
968 $statusType =
'status4';
971 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
988 $this->
ref =
'myspecimenwebsite';
991 $this->otherlang =
'fr,es';
993 $this->fk_default_home = 0;
994 $this->virtualhost =
'http://myvirtualhost';
995 $this->fk_user_creat = $user->id;
996 $this->fk_user_modif = $user->id;
997 $this->date_creation =
dol_now();
1016 if (empty($website->id) || empty($website->ref)) {
1023 if (!is_writable(
$conf->website->dir_temp)) {
1028 $destdir =
$conf->website->dir_temp.
'/'.$website->ref;
1031 $countreallydeleted = 0;
1033 if ($counttodelete != $countreallydeleted) {
1034 setEventMessages(
"Failed to clean temp directory ".$destdir,
null,
'errors');
1038 $arrayreplacementinfilename = array();
1039 $arrayreplacementincss = array();
1040 $arrayreplacementincss[
'file=image/'.$website->ref.
'/'] =
"file=image/__WEBSITE_KEY__/";
1041 $arrayreplacementincss[
'file=js/'.$website->ref.
'/'] =
"file=js/__WEBSITE_KEY__/";
1042 $arrayreplacementincss[
'medias/image/'.$website->ref.
'/'] =
"medias/image/__WEBSITE_KEY__/";
1043 $arrayreplacementincss[
'medias/js/'.$website->ref.
'/'] =
"medias/js/__WEBSITE_KEY__/";
1044 if (
$mysoc->logo_small) {
1045 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_small] =
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__";
1048 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini] =
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__";
1051 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo] =
"file=logos%2Fthumbs%2F__LOGO_KEY__";
1056 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers');
1057 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey');
1058 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey');
1061 $srcdir =
$conf->website->dir_output.
'/'.$website->ref;
1062 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers';
1064 dol_syslog(
"Copy pages from ".$srcdir.
" into ".$destdir);
1065 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename, 2, array(
'old',
'back'), 1);
1071 if (
dol_is_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md')) {
1072 dol_copy(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md',
$conf->website->dir_temp.
'/'.$website->ref.
'/README.md');
1074 if (
dol_is_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE')) {
1075 dol_copy(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE',
$conf->website->dir_temp.
'/'.$website->ref.
'/LICENSE');
1079 $srcdir = DOL_DATA_ROOT.
'/medias/image/'.$website->ref;
1080 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey';
1082 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1083 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename);
1086 $srcdir = DOL_DATA_ROOT.
'/medias/js/'.$website->ref;
1087 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey';
1089 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1090 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename);
1093 $cssindestdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/styles.css.php';
1098 $htmldeaderindestdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/htmlheader.html';
1104 $filesql_path =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_pages.sql';
1105 $fp = fopen($filesql_path,
"w");
1111 $objectpages =
new WebsitePage($this->db);
1112 $listofpages = $objectpages->fetchAll($website->id);
1117 foreach ($listofpages as $pageid => $objectpageold) {
1118 $objectpageold->newid = $i;
1122 foreach ($listofpages as $pageid => $objectpageold) {
1125 foreach ($listofpages as $pageid2 => $objectpageold2) {
1126 if ($pageid2 == $objectpageold->fk_page) {
1127 $newfk_page = $objectpageold2->newid;
1131 $objectpageold->newfk_page = $newfk_page;
1135 $line =
'-- File generated by Dolibarr '.DOL_VERSION.
' --;'.
"\n";
1139 foreach ($listofpages as $pageid => $objectpageold) {
1140 $oldpageid = $objectpageold->id;
1142 $allaliases = $objectpageold->pageurl;
1143 $allaliases .= ($objectpageold->aliasalt ?
','.$objectpageold->aliasalt :
'');
1148 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/page'.$objectpageold->id.
'.tpl.php', 0, 0, 0,
null,
false, 0);
1150 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1151 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1153 $arrayofaliases = explode(
',', $objectpageold->aliasalt);
1154 foreach ($arrayofaliases as $tmpaliasalt) {
1155 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1156 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1161 $line =
'-- Page ID '.$objectpageold->newid.
'__+MAX_llx_website_page__ - Aliases '.$allaliases.
' --;';
1166 $line =
'INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, aliasalt, title, description, lang, image, keywords, status, date_creation, tms, import_key, grabbed_from, type_container, htmlheader, content, author_alias, allowed_in_frames)';
1167 $line .=
" VALUES(";
1168 $line .= $objectpageold->newid.
"__+MAX_llx_website_page__, ";
1169 $line .= ($objectpageold->newfk_page ? $this->db->escape($objectpageold->newfk_page).
"__+MAX_llx_website_page__" :
"null").
", ";
1170 $line .=
"__WEBSITE_ID__, ";
1171 $line .=
"'".$this->db->escape($objectpageold->pageurl).
"', ";
1172 $line .=
"'".$this->db->escape($objectpageold->aliasalt).
"', ";
1173 $line .=
"'".$this->db->escape($objectpageold->title).
"', ";
1174 $line .=
"'".$this->db->escape($objectpageold->description).
"', ";
1175 $line .=
"'".$this->db->escape($objectpageold->lang).
"', ";
1176 $line .=
"'".$this->db->escape($objectpageold->image).
"', ";
1177 $line .=
"'".$this->db->escape($objectpageold->keywords).
"', ";
1178 $line .=
"'".$this->db->escape((
string) $objectpageold->status).
"', ";
1179 $line .=
"'".$this->db->idate($objectpageold->date_creation).
"', ";
1180 $line .=
"'".$this->db->idate($objectpageold->date_modification).
"', ";
1181 $line .= ($objectpageold->import_key ?
"'".$this->db->escape((
string) $objectpageold->import_key).
"'" :
"null").
", ";
1182 $line .=
"'".$this->db->escape($objectpageold->grabbed_from).
"', ";
1183 $line .=
"'".$this->db->escape($objectpageold->type_container).
"', ";
1186 $stringtoexport = $objectpageold->htmlheader;
1187 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1188 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1189 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1190 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1191 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1193 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.
$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1194 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.
$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1195 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.
$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1198 $line .=
"/* new line */\n";
1200 $line .=
"'".$this->db->escape($stringtoexport).
"', ";
1203 $stringtoexport = $objectpageold->content;
1204 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1205 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1206 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1207 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1208 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1209 $stringtoexport = str_replace(
'"image/'.$website->ref.
'/',
'"image/__WEBSITE_KEY__/', $stringtoexport);
1210 $stringtoexport = str_replace(
'"/image/'.$website->ref.
'/',
'"/image/__WEBSITE_KEY__/', $stringtoexport);
1211 $stringtoexport = str_replace(
'"js/'.$website->ref.
'/',
'"js/__WEBSITE_KEY__/', $stringtoexport);
1212 $stringtoexport = str_replace(
'"/js/'.$website->ref.
'/',
'"/js/__WEBSITE_KEY__/', $stringtoexport);
1214 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.
$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1215 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.
$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1216 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.
$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1219 $line .=
"/* new line */\n";
1221 $line .=
"'".$this->db->escape($stringtoexport).
"', ";
1223 $line .=
"'".$this->db->escape($objectpageold->author_alias).
"', ";
1224 $line .= (int) $objectpageold->allowed_in_frames;
1232 if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) {
1234 $line =
"UPDATE llx_website SET fk_default_home = ".($objectpageold->newid > 0 ? $this->db->escape((
string) $objectpageold->newid).
"__+MAX_llx_website_page__" :
"null").
" WHERE rowid = __WEBSITE_ID__;";
1242 $line =
"\n-- For Dolibarr v14+ --;\n";
1243 $line .=
"UPDATE llx_website SET lang = '".$this->db->escape($this->lang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1244 $line .=
"UPDATE llx_website SET otherlang = '".$this->db->escape($this->otherlang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1253 $filedir =
$conf->website->dir_temp.
'/'.$website->ref.
'/.';
1254 $fileglob =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-*.zip';
1255 $filename =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-'.
dol_print_date(
dol_now(),
'dayhourlog').
'-V'.((float) DOL_VERSION).
'.zip';
1259 $result = dol_compress_dir($filedir, $filename,
'zip');
1265 $this->error = $errormsg;
1278 public function importWebSite($pathtofile)
1285 if (!file_exists($pathtofile)) {
1286 $this->error =
'The zip file "'.$pathtofile.
'" is not found';
1292 $this->error =
'Function importWebSite called on object not loaded (object->ref is empty)';
1299 $filename = basename($pathtofile);
1301 if (!preg_match(
'/^website_(.*)-(.*)$/', $filename, $reg)) {
1302 $this->errors[] =
'Bad format for filename '.$filename.
'. Must be website_XXX-VERSION.';
1309 if (!empty($result[
'error'])) {
1310 $this->errors[] =
'Failed to unzip file '.$pathtofile;
1314 $arrayreplacement = array();
1315 $arrayreplacement[
'__WEBSITE_ID__'] =
$object->id;
1316 $arrayreplacement[
'__WEBSITE_KEY__'] =
$object->ref;
1317 $arrayreplacement[
'__N__'] = $this->db->escape(
"\n");
1318 $arrayreplacement[
'__LOGO_SMALL_KEY__'] = $this->db->escape(
$mysoc->logo_small);
1319 $arrayreplacement[
'__LOGO_MINI_KEY__'] = $this->db->escape(
$mysoc->logo_mini);
1320 $arrayreplacement[
'__LOGO_KEY__'] = $this->db->escape(
$mysoc->logo);
1324 $cssinsrcdir =
$conf->website->dir_temp.
'/'.
$object->ref.
'/containers/styles.css.php';
1328 if (!$user->hasRight(
'website',
'writephp')) {
1330 $csscontent = file_get_contents($newpathofsrcfile);
1336 $this->error =
'Error: you try to import a website with a page with PHP dynamic content in style sheet without having permissions for that.';
1337 $this->errors[] = $this->error;
1345 $htmldeaderinsrcdir =
$conf->website->dir_output.
'/'.
$object->ref.
'/containers/htmlheader.html';
1349 if (!$user->hasRight(
'website',
'writephp')) {
1351 $htmlcontent = file_get_contents($newpathofsrcfile);
1357 $this->error =
'Error: you try to import a website with a page with PHP dynamic content in htmlheader.html without having permissions for that.';
1358 $this->errors[] = $this->error;
1369 foreach (array(
'robots.txt',
'.dolibarr',
'.htaccess',
'LICENSE',
'README.md') as $filename) {
1372 $filecontent = file_get_contents($newpathofsrcfile);
1378 $this->error =
'Error: you try to import a website with a page with PHP dynamic content in '.$filename.
'.';
1379 $this->errors[] = $this->error;
1388 $jscontent = @file_get_contents($filejs);
1390 $jscontent = preg_replace(
'/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims',
'', $jscontent);
1393 $this->error =
'Error: you try to import a website with a page with PHP dynamic content in '.$filename.
'.';
1394 $this->errors[] = $this->error;
1402 $manifestjsoncontent = @file_get_contents($filemanifestjson);
1404 $manifestjsoncontent = preg_replace(
'/<\?php \/\/ BEGIN PHP[^\?]*END PHP( \?>)?\n*/ims',
'', $manifestjsoncontent);
1408 $this->error =
'Error: you try to import a website with a page with PHP dynamic content in '.$filename.
'.';
1409 $this->errors[] = $this->error;
1416 $filemaster =
$conf->website->dir_output.
'/'.
$object->ref.
'/master.inc.php';
1419 $this->errors[] =
'Failed to write file '.$filemaster;
1428 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/image/'.
$object->ref.
'.';
1430 $this->errors[] = $this->error;
1439 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/js/'.
$object->ref.
'.';
1441 $this->errors[] = $this->error;
1446 $sqlfile =
$conf->website->dir_temp.
"/".
$object->ref.
'/website_pages.sql';
1453 $sqlgetrowid =
'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.
'website_page';
1455 $resql = $this->db->query($sqlgetrowid);
1457 $obj = $this->db->fetch_object($resql);
1458 $maxrowid = $obj->max;
1462 $resqlrun =
run_sql($sqlfile, 1, 0, 0,
'',
'none', 0, 1, 0, 0, 1,
'');
1463 if ($resqlrun <= 0) {
1464 $this->errors[] =
'Failed to load sql file '.$sqlfile.
' (ret='.((int) $resqlrun).
')';
1468 $objectpagestatic =
new WebsitePage($this->db);
1469 $aliasesarray =
null;
1472 $fp = fopen($sqlfile,
"r");
1474 while (!feof($fp)) {
1478 $buf = fgets($fp, 65000);
1482 if (preg_match(
'/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.+)\s--;/i', $buf, $reg)) {
1484 $oldid = (int) $reg[1];
1485 $newid = ((int) $reg[2] + $maxrowid);
1486 $aliasesarray = explode(
',', $reg[3]);
1488 dol_syslog(
"In sql source file, we have the page ID ".$oldid.
" to replace with the new ID ".$newid.
", and we must create the shortcut aliases: ".$reg[3]);
1491 } elseif (preg_match(
'/^-- Page ID (\d+).*Aliases\s(.*)\s--;/i', $buf, $reg)) {
1493 $newid = ((int) $reg[1] + $maxrowid);
1494 $aliasesarray = explode(
',', $reg[2]);
1496 dol_syslog(
"In sql source file, we have the page with the new ID ".$newid.
", and we must create the shortcut aliases: ".$reg[2]);
1500 $objectpagestatic->fetch($newid);
1503 $filetpl =
$conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1506 $this->errors[] =
'Failed to write file '.basename($filetpl);
1511 if (!$user->hasRight(
'website',
'writephp')) {
1513 $tplcontent = file_get_contents($newpathofsrcfile);
1519 $this->error =
'Error: you try to import a website with a page with PHP dynamic content without having permissions for that.';
1520 $this->errors[] = $this->error;
1526 if (is_array($aliasesarray)) {
1527 foreach ($aliasesarray as $aliasshortcuttocreate) {
1528 if (trim($aliasshortcuttocreate)) {
1529 $filealias =
$conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1532 $this->errors[] =
'Failed to write file '.basename($filealias);
1544 $sql =
"SELECT fk_default_home FROM ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int)
$object->id);
1545 $resql = $this->db->query($sql);
1547 $obj = $this->db->fetch_object($resql);
1549 $object->fk_default_home = $obj->fk_default_home;
1557 $pathofwebsite =
$conf->website->dir_output.
'/'.
$object->ref;
1558 dolSaveIndexPage($pathofwebsite, $pathofwebsite.
'/index.php', $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php', $pathofwebsite.
'/wrapper.php',
$object);
1563 $this->db->rollback();
1566 $this->db->commit();
1585 $this->error =
'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)';
1589 $objectpagestatic =
new WebsitePage($this->db);
1591 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $this->
id);
1593 $resql = $this->db->query($sql);
1595 $this->error = $this->db->lasterror();
1599 $num = $this->db->num_rows($resql);
1604 $obj = $this->db->fetch_object($resql);
1606 $newid = $obj->rowid;
1608 $objectpagestatic->fetch($newid);
1610 $aliasesarray = explode(
',', $objectpagestatic->aliasalt);
1612 $filetpl =
$conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1615 $this->errors[] =
'Failed to write file '.basename($filetpl);
1620 if (!empty($objectpagestatic->pageurl) && !in_array($objectpagestatic->pageurl, $aliasesarray)) {
1621 $aliasesarray[] = $objectpagestatic->pageurl;
1625 if (is_array($aliasesarray)) {
1626 foreach ($aliasesarray as $aliasshortcuttocreate) {
1627 if (trim($aliasshortcuttocreate)) {
1628 $filealias =
$conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1631 $this->errors[] =
'Failed to write file '.basename($filealias);
1643 $pathofwebsite =
$conf->website->dir_output.
'/'.
$object->ref;
1644 $fileindex = $pathofwebsite.
'/index.php';
1646 if (
$object->fk_default_home > 0) {
1647 $filetpl = $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php';
1649 $filewrapper = $pathofwebsite.
'/wrapper.php';
1654 $filecacheglob =
$conf->website->dir_output.
'/temp/'.
$object->ref.
'-*.php.cache';
1671 return !empty($this->otherlang);
1685 global $websitepagefile, $website;
1686 '@phan-var-force Website $website';
1688 if (!is_object($weblangs)) {
1689 return 'ERROR componentSelectLang called with parameter $weblangs not defined';
1692 $arrayofspecialmainlanguages = array(
1720 $tmppage =
new WebsitePage($this->db);
1723 if (!empty($websitepagefile)) {
1724 $websitepagefileshort = basename($websitepagefile);
1725 if ($websitepagefileshort ==
'index.php') {
1726 $pageid = $website->fk_default_home;
1728 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), $websitepagefileshort);
1731 $tmppage->fetch($pageid);
1736 if (!is_array($languagecodes) && $pageid > 0) {
1737 $languagecodes = array();
1739 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
1740 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
1741 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
1742 $sql .=
" AND (wp.fk_page = ".((int) $pageid).
" OR wp.rowid = ".((int) $pageid);
1743 if ($tmppage->fk_page > 0) {
1744 $sql .=
" OR wp.fk_page = ".((int) $tmppage->fk_page).
" OR wp.rowid = ".((int) $tmppage->fk_page);
1748 $resql = $this->db->query($sql);
1750 while ($obj = $this->db->fetch_object($resql)) {
1751 $newlang = $obj->lang;
1752 if ($obj->rowid == $pageid) {
1753 $newlang = $obj->lang;
1755 if (!in_array($newlang, $languagecodes)) {
1756 $languagecodes[] = $newlang;
1763 $languagecodeselected = substr($weblangs->defaultlang, 0, 2);
1764 if (!empty($websitepagefile)) {
1765 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
1767 $pagelang = substr($tmppage->lang, 0, 2);
1768 $languagecodeselected = substr($pagelang, 0, 2);
1769 if (!in_array($pagelang, $languagecodes)) {
1770 $languagecodes[] = $pagelang;
1775 $weblangs->load(
'languages');
1778 $url = $_SERVER[
"REQUEST_URI"];
1779 $url = preg_replace(
'/(\?|&)l=([a-zA-Z_]*)/',
'', $url);
1781 $url .= (preg_match(
'/\?/', $url) ?
'&' :
'?').
'l=';
1782 if (!preg_match(
'/^\//', $url)) {
1787 $MAXHEIGHT = 4 * $HEIGHTOPTION;
1788 $nboflanguage = count($languagecodes);
1790 $out =
'<!-- componentSelectLang'.$htmlname.
' -->'.
"\n";
1793 $out .=
'.componentSelectLang'.$htmlname.
':hover { height: '.min($MAXHEIGHT, ($HEIGHTOPTION * $nboflanguage)).
'px; overflow-x: hidden; overflow-y: '.((($HEIGHTOPTION * $nboflanguage) > $MAXHEIGHT) ?
' scroll' :
'hidden').
'; }'.
"\n";
1794 $out .=
'.componentSelectLang'.$htmlname.
' li { line-height: '.$HEIGHTOPTION.
'px; }'.
"\n";
1795 $out .=
'.componentSelectLang'.$htmlname.
' {
1796 display: inline-block;
1798 height: '.$HEIGHTOPTION.
'px;
1800 transition: all .3s ease;
1802 vertical-align: top;
1804 .componentSelectLang'.$htmlname.
':hover, .componentSelectLang'.$htmlname.
':hover a { background-color: #fff; color: #000 !important; }
1805 ul.componentSelectLang'.$htmlname.
' { width: 150px; }
1806 ul.componentSelectLang'.$htmlname.
':hover .fa { visibility: hidden; }
1807 .componentSelectLang'.$htmlname.
' a { text-decoration: none; width: 100%; }
1808 .componentSelectLang'.$htmlname.
' li { display: block; padding: 0px 15px; margin-left: 0; margin-right: 0; }
1809 .componentSelectLang'.$htmlname.
' li:hover { background-color: #EEE; }
1812 $out .=
'<ul class="componentSelectLang'.$htmlname.($morecss ?
' '.$morecss :
'').
'">';
1814 if ($languagecodeselected) {
1816 if (strlen($languagecodeselected) == 2) {
1817 $languagecodeselected = (
string) (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.
'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
1820 $countrycode = strtolower(substr($languagecodeselected, -2));
1821 $label = $weblangs->trans(
"Language_".$languagecodeselected);
1822 if ($countrycode ==
'us') {
1823 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1825 $out .=
'<li><a href="'.$url.substr($languagecodeselected, 0, 2).
'"><img height="12px" src="/medias/image/common/flags/'.$countrycode.
'.png" style="margin-right: 5px;"/><span class="websitecomponentlilang">'.$label.
'</span>';
1826 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1827 $out .=
'</a></li>';
1830 if (is_array($languagecodes)) {
1831 foreach ($languagecodes as $languagecode) {
1833 if (strlen($languagecode) == 2) {
1834 $languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.
'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
1837 if ($languagecode == $languagecodeselected) {
1841 $countrycode = strtolower(substr($languagecode, -2));
1842 $label = $weblangs->trans(
"Language_".$languagecode);
1843 if ($countrycode ==
'us') {
1844 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1846 $out .=
'<li><a href="'.$url.substr($languagecode, 0, 2).
'"><img height="12px" src="/medias/image/common/flags/'.$countrycode.
'.png" style="margin-right: 5px;"/><span class="websitecomponentlilang">'.$label.
'</span>';
1847 if (empty($i) && empty($languagecodeselected)) {
1848 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1850 $out .=
'</a></li>';
1871 if (empty($website->id) || empty($website->ref)) {
1875 if (empty($website->name_template) && empty($exportPath)) {
1876 setEventMessages(
"To export the website template into a directory of the server, the name of the directory/template must be provided.",
null,
'errors');
1879 if (!is_writable(
$conf->website->dir_temp)) {
1889 if (empty($exportPath)) {
1890 $destdirrel =
'install/doctemplates/websites/'.$website->name_template;
1891 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1893 $exportPath = rtrim($exportPath,
'/');
1894 if (strpos($exportPath,
'..') !==
false) {
1899 if (strpos($exportPath,
'/') === 0 || preg_match(
'/^[a-zA-Z]:/', $exportPath)) {
1900 if (!is_dir($exportPath)) {
1901 setEventMessages(
"The specified absolute path does not exist.",
null,
'errors');
1905 if (!is_writable($exportPath)) {
1906 setEventMessages(
"The specified absolute path is not writable.",
null,
'errors');
1909 $destdirrel = $exportPath;
1910 $destdir = $exportPath;
1913 $destdirrel =
'install/doctemplates/websites/'.$exportPath;
1914 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1919 if ($destdir ===
null) {
1920 setEventMessages(
"The destination path is not determined.",
null,
'errors');
1926 if (!is_writable($destdir)) {
1927 setEventMessages(
"The specified path ".$destdir.
" is not writable.",
null,
'errors');
1935 if (
dol_is_file($destdir.
'/containers/README.md')) {
1936 dol_move($destdir.
'/containers/README.md', $destdir.
'/README.md',
'0', 1, 0, 0);
1938 if (
dol_is_file($destdir.
'/containers/LICENSE')) {
1939 dol_move($destdir.
'/containers/LICENSE', $destdir.
'/LICENSE',
'0', 1, 0, 0);
1955 if (!empty($resultarray)) {
1956 setEventMessages(
"Error, failed to unzip the export into target dir ".$destdir.
": ".implode(
',', $resultarray),
null,
'errors');
1958 setEventMessages(
"Website content written into ".$destdirrel,
null,
'mesgs');
1961 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?website='.$website->ref);
1973 if (preg_match(
'/page(\d+)\.tpl\.php/', $filename, $matches)) {
1974 return (
int) $matches[1];
1988 $sql =
"UPDATE ".$this->db->prefix().
"website SET";
1989 $sql .=
" name_template = '".$this->db->escape($name_template).
"'";
1990 $sql .=
" WHERE rowid = ".(int) $this->
id;
1991 $result = $this->db->query($sql);
1994 $this->db->commit();
1997 $this->db->rollback();
2012 $fichiersSource = [];
2013 $fichiersDestination = [];
2015 $fichierWithNoPage = [];
2016 $fichierWithNoPageInDest = [];
2019 foreach (
dol_dir_list($dossierSource,
"files") as $file) {
2020 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
2021 $fichiersSource[] = $file;
2023 $fichierWithNoPage[] = $file;
2028 foreach (
dol_dir_list($dossierDestination,
"all", 1) as $file) {
2029 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
2030 $fichiersDestination[] = $file;
2032 $fichierWithNoPageInDest[] = $file;
2037 $numOfPageSource = 0;
2038 foreach ($fichiersSource as $index => $file) {
2039 if ($file[
'name'] == basename($fichierModifie[
'fullname'])) {
2046 $filesFound = array();
2047 foreach ($fichierWithNoPage as $filesource) {
2048 $fileContent = file_get_contents($filesource[
'fullname']);
2049 if (strpos($fileContent,
"require './page".$numOfPageSource.
".tpl.php'") !==
false) {
2050 $filesFound = $filesource;
2055 $numPagesFound =
'';
2056 foreach ($fichierWithNoPageInDest as $filedest) {
2057 if ($filedest[
'name'] === $filesFound[
'name']) {
2058 $fileContent = file_get_contents($filedest[
'fullname']);
2059 if (preg_match(
"/page\d+\.tpl\.php/", $fileContent, $matches)) {
2060 $numPagesFound = $matches[0];
2066 $fileNeeded = array();
2067 foreach ($fichiersDestination as $index => $file) {
2068 if ($file[
'name'] == $numPagesFound) {
2069 $fileNeeded = $file;
2074 if (isset($fileNeeded)) {
2075 $sourceContent = file_get_contents($fichierModifie[
'fullname']);
2076 if (file_exists($fileNeeded[
'fullname'])) {
2077 $destContent = file_get_contents($fileNeeded[
'fullname']);
2080 $differences = $this->
showDifferences($destContent, $sourceContent, array($numOfPageDest,$numOfPageSource));
2081 $differences[
'file_destination'] = $fileNeeded;
2083 $differences = array();
2085 return $differences;
2097 $str = str_replace(
"\r\n",
"\n", $str);
2098 $str = str_replace(
"\r",
"\n", $str);
2115 $lines1 = explode(
"\n", $str1);
2116 $lines2 = explode(
"\n", $str2);
2118 $linesShouldChange = array();
2119 $linesShouldNotChange = array();
2120 $linefound = array();
2121 $countNumPage = count($exceptNumPge);
2123 for ($i = 0;$i < $countNumPage; $i++) {
2124 $linefound[$i] = array();
2125 $linefound[$i][
'meta'] =
'/content="' . preg_quote((
string) $exceptNumPge[$i],
'/') .
'" \/>/';
2126 $linefound[$i][
'output'] =
'/dolWebsiteOutput\(\$tmp, "html", ' . preg_quote((
string) $exceptNumPge[$i],
'/') .
'\);/';
2129 if (isset($linefound[1])) {
2130 $maxLines = max(count($lines1), count($lines2));
2131 for ($lineNum = 0; $lineNum < $maxLines; $lineNum++) {
2132 $lineContent1 = $lines1[$lineNum] ??
'';
2133 $lineContent2 = $lines2[$lineNum] ??
'';
2134 if (preg_match($linefound[0][
'output'], $lineContent1)) {
2135 $linesShouldChange[] = $lineContent1;
2137 if (preg_match($linefound[0][
'meta'], $lineContent1)) {
2138 $linesShouldChange[] = $lineContent1;
2140 if (preg_match($linefound[1][
'output'], $lineContent2)) {
2141 $linesShouldNotChange[] = $lineContent2;
2143 if (preg_match($linefound[1][
'meta'], $lineContent2)) {
2144 $linesShouldNotChange[] = $lineContent2;
2146 if ($lineContent1 !== $lineContent2) {
2147 if (isset($lines1[$lineNum]) && !isset($lines2[$lineNum])) {
2149 $diff[
"Supprimée à la ligne " . ($lineNum + 1)] = $lineContent1;
2150 } elseif (!isset($lines1[$lineNum]) && isset($lines2[$lineNum])) {
2152 $diff[
"Ajoutée à la ligne " . ($lineNum + 1)] = $lineContent2;
2155 $diff[
"Modifiée à la ligne " . ($lineNum + 1)] = $lineContent2;
2162 if (empty($linesShouldChange)) {
2163 $linesShouldChange[0] =
'<meta name="dolibarr:pageid" content="'.$exceptNumPge[0].
'" />';
2164 $linesShouldChange[1] =
'$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$exceptNumPge[0].
');';
2167 $replacementMapping = array();
2168 if (!empty($linesShouldNotChange)) {
2170 foreach ($linesShouldNotChange as $numLigne => $ligneRemplacement) {
2171 if (isset($linesShouldChange[$numLigne])) {
2172 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$numLigne];
2174 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$i];
2178 $diff[
'lignes_dont_change'] = $replacementMapping;
2181 $pattern =
'/medias\/image\/'.preg_quote($this->
ref,
'/').
'\/([^\'"\s]+)/';
2183 foreach ($diff as $key => $value) {
2185 if (is_string($value)) {
2186 if (preg_match($pattern, $value)) {
2187 $newValue = preg_replace($pattern,
'medias/image/'.$this->name_template.
'/$1', $value);
2188 $diff[$key] = $newValue;
2204 if (file_exists($inplaceFile)) {
2207 if (!is_writable($inplaceFile)) {
2211 unset($differences[
'file_destination']);
2212 $contentDest = file($inplaceFile, FILE_IGNORE_NEW_LINES);
2213 foreach ($differences as $key => $ligneSource) {
2215 if (preg_match(
'/(Ajoutée|Modifiée) à la ligne (\d+)/', $key, $matches)) {
2216 $typeModification = $matches[1];
2217 $numLigne = (int) $matches[2] - 1;
2219 if ($typeModification ===
'Ajoutée') {
2220 array_splice($contentDest, $numLigne, 0, $ligneSource);
2221 } elseif ($typeModification ===
'Modifiée') {
2222 $contentDest[$numLigne] = $ligneSource;
2224 } elseif (preg_match(
'/Supprimée à la ligne (\d+)/', $key, $matches)) {
2225 $numLigne = (int) $matches[1] - 1;
2226 unset($contentDest[$numLigne]);
2230 $contentDest = array_values($contentDest);
2231 $stringreplacement = implode(
"\n", $contentDest);
2233 file_put_contents($inplaceFile, $stringreplacement);
2236 foreach ($differences[
'lignes_dont_change'] as $linechanged => $line) {
2237 if (in_array($linechanged, $contentDest)) {
if(! $sortfield) if(! $sortorder) $object
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
setErrorsFromObject($object)
setErrorsFromObject
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
isMultiLang()
Return if web site is a multilanguage web site.
setTemplateName($name_template)
update name_template in table after import template
create(User $user, $notrigger=0)
Create object into database.
rebuildWebSiteFiles()
Rebuild all files of all the pages/containers of a website.
exportWebSite()
Generate a zip with all data of web site.
replaceLineUsingNum($inplaceFile, $differences)
Replace line by line in file using numbers of the lines.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
componentSelectLang($languagecodes, $weblangs, $morecss='', $htmlname='')
Component to select language inside a container (Full CSS Only)
extractNumberFromFilename($filename)
extract num of page
createFromClone($user, $fromid, $newref, $newlang='')
Load a website its id and create a new one in database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load all object in memory ($this->records) from the database.
overwriteTemplate(string $pathtotmpzip, $exportPath='')
Overite template by copying all files.
__construct(DoliDB $db)
Constructor.
getLibStatut($mode=0)
Return the label of the status.
LibStatut($status, $mode=0)
Return the label of a given status.
purge(User $user)
Purge website Delete website directory content and all pages and medias.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the user card (with optionally the picto) Use this->id,this->lastname,...
normalizeString($str)
Remove spaces in string.
update(User $user, $notrigger=0)
Update object into database.
fetch($id, $ref=null)
Load object in memory from the database.
compareFichierModifie($dossierSource, $dossierDestination, $fichierModifie)
Compare two files has not same name but same content.
showDifferences($str1, $str2, $exceptNumPge=array())
show difference between to string
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another 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.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask='0', $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_now($mode='gmt')
Return date for now.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
dolSaveMasterFile($filemaster)
Save content of a page on disk.
dolSaveLicense($file, $content)
Save content of a page on disk.
dolSaveManifestJson($file, $content)
Save content of a page on disk.
dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object=null)
Save content of the index.php and/or the wrapper.php page.
dolSavePageAlias($filealias, $object, $objectpage)
Save an alias page on disk (A page that include the reference page).
dolSaveJsFile($filejs, $jscontent)
Save content of a page on disk.
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold=0)
Save content of a page on disk (page name is generally ID_of_page.php).