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';
93 public $fk_default_home;
98 public $fk_user_creat;
103 public $fk_user_modif;
113 public $use_manifest;
123 public $name_template;
125 const STATUS_DRAFT = 0;
126 const STATUS_VALIDATED = 1;
138 $this->ismultientitymanaged = 1;
150 global
$conf, $langs;
158 if (isset($this->entity)) {
159 $this->entity = (int) $this->entity;
161 if (isset($this->
ref)) {
162 $this->
ref = trim($this->
ref);
167 if (isset($this->
status)) {
170 if (empty($this->date_creation)) {
171 $this->date_creation = $now;
173 if (empty($this->date_modification)) {
174 $this->date_modification = $now;
177 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
178 $tmparray = explode(
',', $this->otherlang);
179 if (is_array($tmparray)) {
180 foreach ($tmparray as $key => $val) {
182 if (empty(trim($val))) {
183 unset($tmparray[$key]);
186 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
188 $this->otherlang = implode(
',', $tmparray);
192 if (empty($this->entity)) {
193 $this->entity =
$conf->entity;
195 if (empty($this->lang)) {
196 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
201 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
204 $sql .=
'description,';
206 $sql .=
'otherlang,';
208 $sql .=
'fk_default_home,';
209 $sql .=
'virtualhost,';
210 $sql .=
'fk_user_creat,';
211 $sql .=
'date_creation,';
214 $sql .=
') VALUES (';
215 $sql .=
' '.((empty($this->entity) && $this->entity !=
'0') ?
'NULL' : $this->entity).
',';
216 $sql .=
' '.(!isset($this->
ref) ?
'NULL' :
"'".$this->db->escape($this->
ref).
"'").
',';
218 $sql .=
' '.(!isset($this->lang) ?
'NULL' :
"'".$this->db->escape($this->lang).
"'").
',';
219 $sql .=
' '.(!isset($this->otherlang) ?
'NULL' :
"'".$this->db->escape($this->otherlang).
"'").
',';
220 $sql .=
' '.(!isset($this->
status) ?
'1' : $this->status).
',';
221 $sql .=
' '.(!isset($this->fk_default_home) ?
'NULL' : $this->fk_default_home).
',';
222 $sql .=
' '.(!isset($this->virtualhost) ?
'NULL' :
"'".$this->db->escape($this->virtualhost).
"'").
",";
223 $sql .=
' '.(!isset($this->fk_user_creat) ? $user->id : $this->fk_user_creat).
',';
224 $sql .=
' '.(!isset($this->date_creation) ||
dol_strlen((
string) $this->date_creation) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_creation).
"'").
",";
225 $sql .=
' '.((int) $this->
position).
",";
226 $sql .=
' '.(!isset($this->date_modification) ||
dol_strlen((
string) $this->date_modification) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_modification).
"'");
231 $resql = $this->db->query($sql);
234 $this->errors[] =
'Error '.$this->db->lasterror();
235 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
239 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
242 $tmplangarray = explode(
',', $this->otherlang);
243 if (is_array($tmplangarray)) {
245 foreach ($tmplangarray as $val) {
246 if (trim($val) == $this->lang) {
249 dol_mkdir(
$conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val), DOL_DATA_ROOT);
254 dol_mkdir(
$conf->medias->multidir_output[
$conf->entity].
'/image/'.$this->ref, DOL_DATA_ROOT);
257 $pathofwebsite =
$conf->website->dir_output.
'/'.$this->ref;
261 $pathtomedias = DOL_DATA_ROOT.
'/medias';
262 $pathtomediasinwebsite = $pathofwebsite.
'/medias';
264 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
265 dol_mkdir(dirname($pathtomediasinwebsite));
266 $result = symlink($pathtomedias, $pathtomediasinwebsite);
268 $langs->load(
"errors");
283 $stringtodolibarrfile =
"# Some properties for Dolibarr web site CMS\n";
284 $stringtodolibarrfile .=
"param=value\n";
286 file_put_contents(
$conf->website->dir_output.
'/'.$this->ref.
'/.dolibarr', $stringtodolibarrfile);
291 $this->db->rollback();
292 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
311 public function fetch($id, $ref =
null)
317 $sql .=
" t.entity,";
319 $sql .=
" t.position,";
320 $sql .=
" t.description,";
322 $sql .=
" t.otherlang,";
323 $sql .=
" t.status,";
324 $sql .=
" t.fk_default_home,";
325 $sql .=
" t.use_manifest,";
326 $sql .=
" t.virtualhost,";
327 $sql .=
" t.fk_user_creat,";
328 $sql .=
" t.fk_user_modif,";
329 $sql .=
" t.date_creation,";
330 $sql .=
" t.tms as date_modification,";
331 $sql .=
" t.name_template";
332 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
333 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
335 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
337 $sql .=
" AND t.rowid = ".(int) $id;
340 $resql = $this->db->query($sql);
342 $numrows = $this->db->num_rows($resql);
344 $obj = $this->db->fetch_object($resql);
346 $this->
id = $obj->rowid;
348 $this->entity = $obj->entity;
349 $this->
ref = $obj->ref;
352 $this->lang = $obj->lang;
353 $this->otherlang = $obj->otherlang;
354 $this->
status = $obj->status;
355 $this->fk_default_home = $obj->fk_default_home;
356 $this->virtualhost = $obj->virtualhost;
357 $this->use_manifest = $obj->use_manifest;
358 $this->fk_user_creat = $obj->fk_user_creat;
359 $this->fk_user_modif = $obj->fk_user_modif;
360 $this->date_creation = $this->db->jdate($obj->date_creation);
361 $this->date_modification = $this->db->jdate($obj->date_modification);
362 $this->name_template = $obj->name_template;
364 $this->db->free($resql);
372 $this->errors[] =
'Error '.$this->db->lasterror();
373 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
391 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
399 $sql .=
" t.entity,";
401 $sql .=
" t.description,";
403 $sql .=
" t.otherlang,";
404 $sql .=
" t.status,";
405 $sql .=
" t.fk_default_home,";
406 $sql .=
" t.virtualhost,";
407 $sql .=
" t.fk_user_creat,";
408 $sql .=
" t.fk_user_modif,";
409 $sql .=
" t.date_creation,";
410 $sql .=
" t.tms as date_modification";
411 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
412 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
415 if (is_array($filter)) {
417 if (count($filter) > 0) {
418 foreach ($filter as $key => $value) {
419 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
422 if (count($sqlwhere) > 0) {
423 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
433 $this->errors[] = $errormessage;
434 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
438 if (!empty($sortfield)) {
439 $sql .= $this->db->order($sortfield, $sortorder);
441 if (!empty($limit)) {
442 $sql .= $this->db->plimit($limit, $offset);
445 $resql = $this->db->query($sql);
447 $num = $this->db->num_rows($resql);
449 while ($obj = $this->db->fetch_object($resql)) {
450 $record =
new self($this->db);
452 $record->id = $obj->rowid;
454 $record->entity = $obj->entity;
455 $record->ref = $obj->ref;
456 $record->description = $obj->description;
457 $record->lang = $obj->lang;
458 $record->otherlang = $obj->otherlang;
459 $record->status = $obj->status;
460 $record->fk_default_home = $obj->fk_default_home;
461 $record->virtualhost = $obj->virtualhost;
462 $record->fk_user_creat = $obj->fk_user_creat;
463 $record->fk_user_modif = $obj->fk_user_modif;
464 $record->date_creation = $this->db->jdate($obj->date_creation);
465 $record->date_modification = $this->db->jdate($obj->date_modification);
467 $records[$record->id] = $record;
469 $this->db->free($resql);
473 $this->errors[] =
'Error '.$this->db->lasterror();
474 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
489 global
$conf, $langs;
497 if (isset($this->entity)) {
498 $this->entity = (int) $this->entity;
500 if (isset($this->
ref)) {
501 $this->
ref = trim($this->
ref);
506 if (isset($this->
status)) {
511 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
512 $tmparray = explode(
',', $this->otherlang);
513 if (is_array($tmparray)) {
514 foreach ($tmparray as $key => $val) {
516 if (empty(trim($val))) {
517 unset($tmparray[$key]);
520 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
522 $this->otherlang = implode(
',', $tmparray);
524 if (empty($this->lang)) {
525 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
533 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
534 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
535 $sql .=
' ref = '.(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
',';
536 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
537 $sql .=
' lang = '.(isset($this->lang) ?
"'".$this->db->escape($this->lang).
"'" :
"null").
',';
538 $sql .=
' otherlang = '.(isset($this->otherlang) ?
"'".$this->db->escape($this->otherlang).
"'" :
"null").
',';
539 $sql .=
' status = '.(isset($this->
status) ? $this->
status :
"null").
',';
540 $sql .=
' fk_default_home = '.(($this->fk_default_home > 0) ? $this->fk_default_home :
"null").
',';
541 $sql .=
' use_manifest = '.((int) $this->use_manifest).
',';
542 $sql .=
' virtualhost = '.(($this->virtualhost !=
'') ?
"'".$this->db->escape($this->virtualhost).
"'" :
"null").
',';
543 $sql .=
' fk_user_modif = '.(!isset($this->fk_user_modif) ? $user->id : $this->fk_user_modif).
',';
544 $sql .=
' date_creation = '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
',';
545 $sql .=
' tms = '.(dol_strlen($this->date_modification) != 0 ?
"'".$this->db->idate($this->date_modification).
"'" :
"'".$this->db->idate(
dol_now()).
"'");
546 $sql .=
' WHERE rowid='.((int) $this->
id);
550 $resql = $this->db->query($sql);
553 $this->errors[] =
'Error '.$this->db->lasterror();
554 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
557 if (!$error && !$notrigger) {
562 $tmplangarray = explode(
',', $this->otherlang);
563 if (is_array($tmplangarray)) {
565 foreach ($tmplangarray as $val) {
566 if (trim($val) == $this->lang) {
569 dol_mkdir(
$conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
581 $this->db->rollback();
598 public function delete(
User $user, $notrigger = 0)
609 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'categorie_website_page';
610 $sql .=
' WHERE fk_website_page IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'website_page WHERE fk_website = '.((int) $this->
id).
')';
612 $resql = $this->db->query($sql);
615 $this->errors[] =
'Error '.$this->db->lasterror();
616 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
621 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
622 $sql .=
' WHERE fk_website = '.((int) $this->
id);
624 $resql = $this->db->query($sql);
627 $this->errors[] =
'Error '.$this->db->lasterror();
628 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
638 if (!$error && !empty($this->
ref)) {
639 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
646 $this->db->rollback();
674 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
675 $sql .=
' WHERE fk_website = '.((int) $this->
id);
677 $resql = $this->db->query($sql);
680 $this->errors[] =
'Error '.$this->db->lasterror();
681 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
685 if (!$error && !empty($this->
ref)) {
686 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
693 $this->db->rollback();
715 global
$conf, $langs;
716 global $dolibarr_main_data_root;
725 if (empty($newref)) {
726 $this->error =
'ErrorBadParameter newref';
733 if (
$object->fetch(0, $newref) > 0) {
734 $this->error =
'ErrorNewRefIsAlreadyUsed';
743 $oldidforhome =
$object->fk_default_home;
746 $pathofwebsiteold = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($oldref);
747 $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($newref);
750 $fileindex = $pathofwebsitenew.
'/index.php';
762 $object->fk_user_creat = $user->id;
764 $object->status = self::STATUS_DRAFT;
766 $object->lang = substr($langs->defaultlang, 0, 2);
770 $object->context[
'createfromclone'] =
'createfromclone';
771 $result =
$object->create($user);
775 $this->errors =
$object->errors;
776 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
784 $pathtomedias = DOL_DATA_ROOT.
'/medias';
785 $pathtomediasinwebsite = $pathofwebsitenew.
'/medias';
787 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
788 dol_mkdir(dirname($pathtomediasinwebsite));
789 $result = symlink($pathtomedias, $pathtomediasinwebsite);
793 $pathofmediasjsold = DOL_DATA_ROOT.
'/medias/js/'.$oldref;
794 $pathofmediasjsnew = DOL_DATA_ROOT.
'/medias/js/'.$newref;
797 $pathofmediasimageold = DOL_DATA_ROOT.
'/medias/image/'.$oldref;
798 $pathofmediasimagenew = DOL_DATA_ROOT.
'/medias/image/'.$newref;
805 $listofpages = $objectpages->fetchAll($fromid);
806 foreach ($listofpages as $pageid => $objectpageold) {
808 $filetplold = $pathofwebsitenew.
'/page'.$pageid.
'.tpl.php';
812 $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl,
'', 0,
$object->id, 1);
815 if (is_object($objectpagenew) && $objectpagenew->pageurl) {
816 $filealias = $pathofwebsitenew.
'/'.$objectpagenew->pageurl.
'.php';
817 $filetplnew = $pathofwebsitenew.
'/page'.$objectpagenew->id.
'.tpl.php';
830 if ($pageid == $oldidforhome) {
831 $newidforhome = $objectpagenew->id;
842 $object->fk_default_home = $newidforhome;
850 $filetpl = $pathofwebsitenew.
'/page'.$newidforhome.
'.tpl.php';
851 $filewrapper = $pathofwebsitenew.
'/wrapper.php';
859 unset(
$object->context[
'createfromclone']);
867 $this->db->rollback();
884 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
890 $label =
'<u>'.$langs->trans(
"WebSite").
'</u>';
892 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
893 $label .=
'<b>'.$langs->trans(
'MainLanguage').
':</b> '.$this->lang;
895 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/website/card.php?id='.$this->
id.
'"';
896 $linkstart .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
900 $linkstart = $linkend =
'';
903 $result .= ($linkstart.img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
904 if ($withpicto != 2) {
908 $result .= $linkstart.$this->ref.$linkend;
936 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
939 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
940 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
941 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
942 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
945 $statusType =
'status5';
946 if ($status == self::STATUS_VALIDATED) {
947 $statusType =
'status4';
950 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
967 $this->
ref =
'myspecimenwebsite';
970 $this->otherlang =
'fr,es';
972 $this->fk_default_home = 0;
973 $this->virtualhost =
'http://myvirtualhost';
974 $this->fk_user_creat = $user->id;
975 $this->fk_user_modif = $user->id;
976 $this->date_creation =
dol_now();
990 global
$conf, $mysoc;
994 if (empty($website->id) || empty($website->ref)) {
1001 if (!is_writable(
$conf->website->dir_temp)) {
1006 $destdir =
$conf->website->dir_temp.
'/'.$website->ref;
1009 $countreallydeleted = 0;
1011 if ($counttodelete != $countreallydeleted) {
1012 setEventMessages(
"Failed to clean temp directory ".$destdir,
null,
'errors');
1016 $arrayreplacementinfilename = array();
1017 $arrayreplacementincss = array();
1018 $arrayreplacementincss[
'file=image/'.$website->ref.
'/'] =
"file=image/__WEBSITE_KEY__/";
1019 $arrayreplacementincss[
'file=js/'.$website->ref.
'/'] =
"file=js/__WEBSITE_KEY__/";
1020 $arrayreplacementincss[
'medias/image/'.$website->ref.
'/'] =
"medias/image/__WEBSITE_KEY__/";
1021 $arrayreplacementincss[
'medias/js/'.$website->ref.
'/'] =
"medias/js/__WEBSITE_KEY__/";
1022 if ($mysoc->logo_small) {
1023 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_small] =
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__";
1025 if ($mysoc->logo_mini) {
1026 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini] =
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__";
1029 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo] =
"file=logos%2Fthumbs%2F__LOGO_KEY__";
1034 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers');
1035 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey');
1036 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey');
1039 $srcdir =
$conf->website->dir_output.
'/'.$website->ref;
1040 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers';
1042 dol_syslog(
"Copy pages from ".$srcdir.
" into ".$destdir);
1043 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename, 2, array(
'old',
'back'), 1);
1046 if (
dol_is_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md')) {
1047 dol_copy(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md',
$conf->website->dir_temp.
'/'.$website->ref.
'/README.md');
1049 if (
dol_is_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE')) {
1050 dol_copy(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE',
$conf->website->dir_temp.
'/'.$website->ref.
'/LICENSE');
1054 $srcdir = DOL_DATA_ROOT.
'/medias/image/'.$website->ref;
1055 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey';
1057 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1058 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename);
1061 $srcdir = DOL_DATA_ROOT.
'/medias/js/'.$website->ref;
1062 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey';
1064 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1065 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename);
1068 $cssindestdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/styles.css.php';
1073 $htmldeaderindestdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/htmlheader.html';
1079 $filesql =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_pages.sql';
1080 $fp = fopen($filesql,
"w");
1087 $listofpages = $objectpages->fetchAll($website->id);
1092 foreach ($listofpages as $pageid => $objectpageold) {
1093 $objectpageold->newid = $i;
1097 foreach ($listofpages as $pageid => $objectpageold) {
1100 foreach ($listofpages as $pageid2 => $objectpageold2) {
1101 if ($pageid2 == $objectpageold->fk_page) {
1102 $newfk_page = $objectpageold2->newid;
1106 $objectpageold->newfk_page = $newfk_page;
1110 $line =
'-- File generated by Dolibarr '.DOL_VERSION.
' --;'.
"\n";
1114 foreach ($listofpages as $pageid => $objectpageold) {
1115 $oldpageid = $objectpageold->id;
1117 $allaliases = $objectpageold->pageurl;
1118 $allaliases .= ($objectpageold->aliasalt ?
','.$objectpageold->aliasalt :
'');
1123 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/page'.$objectpageold->id.
'.tpl.php', 0, 0, 0,
null,
false, 0);
1125 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1126 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1128 $arrayofaliases = explode(
',', $objectpageold->aliasalt);
1129 foreach ($arrayofaliases as $tmpaliasalt) {
1130 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1131 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1136 $line =
'-- Page ID '.$objectpageold->newid.
'__+MAX_llx_website_page__ - Aliases '.$allaliases.
' --;';
1141 $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)';
1142 $line .=
" VALUES(";
1143 $line .= $objectpageold->newid.
"__+MAX_llx_website_page__, ";
1144 $line .= ($objectpageold->newfk_page ? $this->db->escape($objectpageold->newfk_page).
"__+MAX_llx_website_page__" :
"null").
", ";
1145 $line .=
"__WEBSITE_ID__, ";
1146 $line .=
"'".$this->db->escape($objectpageold->pageurl).
"', ";
1147 $line .=
"'".$this->db->escape($objectpageold->aliasalt).
"', ";
1148 $line .=
"'".$this->db->escape($objectpageold->title).
"', ";
1149 $line .=
"'".$this->db->escape($objectpageold->description).
"', ";
1150 $line .=
"'".$this->db->escape($objectpageold->lang).
"', ";
1151 $line .=
"'".$this->db->escape($objectpageold->image).
"', ";
1152 $line .=
"'".$this->db->escape($objectpageold->keywords).
"', ";
1153 $line .=
"'".$this->db->escape($objectpageold->status).
"', ";
1154 $line .=
"'".$this->db->idate($objectpageold->date_creation).
"', ";
1155 $line .=
"'".$this->db->idate($objectpageold->date_modification).
"', ";
1156 $line .= ($objectpageold->import_key ?
"'".$this->db->escape($objectpageold->import_key).
"'" :
"null").
", ";
1157 $line .=
"'".$this->db->escape($objectpageold->grabbed_from).
"', ";
1158 $line .=
"'".$this->db->escape($objectpageold->type_container).
"', ";
1161 $stringtoexport = $objectpageold->htmlheader;
1162 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1163 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1164 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1165 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1166 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1168 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1169 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1170 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1171 $line .=
"'".$this->db->escape(str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport)).
"', ";
1174 $stringtoexport = $objectpageold->content;
1175 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1176 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1177 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1178 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1179 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1180 $stringtoexport = str_replace(
'"image/'.$website->ref.
'/',
'"image/__WEBSITE_KEY__/', $stringtoexport);
1181 $stringtoexport = str_replace(
'"/image/'.$website->ref.
'/',
'"/image/__WEBSITE_KEY__/', $stringtoexport);
1182 $stringtoexport = str_replace(
'"js/'.$website->ref.
'/',
'"js/__WEBSITE_KEY__/', $stringtoexport);
1183 $stringtoexport = str_replace(
'"/js/'.$website->ref.
'/',
'"/js/__WEBSITE_KEY__/', $stringtoexport);
1185 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1186 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1187 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1190 $line .=
"'".$this->db->escape($stringtoexport).
"', ";
1191 $line .=
"'".$this->db->escape($objectpageold->author_alias).
"', ";
1192 $line .= (int) $objectpageold->allowed_in_frames;
1200 if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) {
1202 $line =
"UPDATE llx_website SET fk_default_home = ".($objectpageold->newid > 0 ? $this->db->escape($objectpageold->newid).
"__+MAX_llx_website_page__" :
"null").
" WHERE rowid = __WEBSITE_ID__;";
1210 $line =
"\n-- For Dolibarr v14+ --;\n";
1211 $line .=
"UPDATE llx_website SET lang = '".$this->db->escape($this->lang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1212 $line .=
"UPDATE llx_website SET otherlang = '".$this->db->escape($this->otherlang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1221 $filedir =
$conf->website->dir_temp.
'/'.$website->ref.
'/.';
1222 $fileglob =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-*.zip';
1223 $filename =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-'.
dol_print_date(
dol_now(),
'dayhourlog').
'-V'.((float) DOL_VERSION).
'.zip';
1227 $result = dol_compress_dir($filedir, $filename,
'zip');
1233 $this->error = $errormsg;
1245 public function importWebSite($pathtofile)
1247 global
$conf, $mysoc;
1254 $this->error =
'Function importWebSite called on object not loaded (object->ref is empty)';
1261 $filename = basename($pathtofile);
1263 if (!preg_match(
'/^website_(.*)-(.*)$/', $filename, $reg)) {
1264 $this->errors[] =
'Bad format for filename '.$filename.
'. Must be website_XXX-VERSION.';
1271 if (!empty($result[
'error'])) {
1272 $this->errors[] =
'Failed to unzip file '.$pathtofile;
1276 $arrayreplacement = array();
1277 $arrayreplacement[
'__WEBSITE_ID__'] =
$object->id;
1278 $arrayreplacement[
'__WEBSITE_KEY__'] =
$object->ref;
1279 $arrayreplacement[
'__N__'] = $this->db->escape(
"\n");
1280 $arrayreplacement[
'__LOGO_SMALL_KEY__'] = $this->db->escape($mysoc->logo_small);
1281 $arrayreplacement[
'__LOGO_MINI_KEY__'] = $this->db->escape($mysoc->logo_mini);
1282 $arrayreplacement[
'__LOGO_KEY__'] = $this->db->escape($mysoc->logo);
1289 $cssindestdir =
$conf->website->dir_output.
'/'.
$object->ref.
'/styles.css.php';
1292 $htmldeaderindestdir =
$conf->website->dir_output.
'/'.
$object->ref.
'/htmlheader.html';
1296 $filemaster =
$conf->website->dir_output.
'/'.
$object->ref.
'/master.inc.php';
1299 $this->errors[] =
'Failed to write file '.$filemaster;
1307 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/image/'.
$object->ref.
'.';
1309 $this->errors[] = $this->error;
1318 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/js/'.
$object->ref.
'.';
1320 $this->errors[] = $this->error;
1325 $sqlfile =
$conf->website->dir_temp.
"/".
$object->ref.
'/website_pages.sql';
1332 $sqlgetrowid =
'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.
'website_page';
1333 $resql = $this->db->query($sqlgetrowid);
1335 $obj = $this->db->fetch_object($resql);
1336 $maxrowid = $obj->max;
1340 $runsql =
run_sql($sqlfile, 1, 0, 0,
'',
'none', 0, 1, 0, 0, 1);
1342 $this->errors[] =
'Failed to load sql file '.$sqlfile.
' (ret='.((int) $runsql).
')';
1349 $fp = fopen($sqlfile,
"r");
1351 while (!feof($fp)) {
1355 $buf = fgets($fp, 65000);
1359 if (preg_match(
'/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.+)\s--;/i', $buf, $reg)) {
1361 $oldid = (int) $reg[1];
1362 $newid = ((int) $reg[2] + $maxrowid);
1363 $aliasesarray = explode(
',', $reg[3]);
1365 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]);
1368 } elseif (preg_match(
'/^-- Page ID (\d+).*Aliases\s(.*)\s--;/i', $buf, $reg)) {
1370 $newid = ((int) $reg[1] + $maxrowid);
1371 $aliasesarray = explode(
',', $reg[2]);
1373 dol_syslog(
"In sql source file, we have the page with the new ID ".$newid.
", and we must create the shortcut aliases: ".$reg[2]);
1377 $objectpagestatic->fetch($newid);
1380 $filetpl =
$conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1383 $this->errors[] =
'Failed to write file '.basename($filetpl);
1388 if (is_array($aliasesarray)) {
1389 foreach ($aliasesarray as $aliasshortcuttocreate) {
1390 if (trim($aliasshortcuttocreate)) {
1391 $filealias =
$conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1394 $this->errors[] =
'Failed to write file '.basename($filealias);
1406 $sql =
"SELECT fk_default_home FROM ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int)
$object->id);
1407 $resql = $this->db->query($sql);
1409 $obj = $this->db->fetch_object($resql);
1411 $object->fk_default_home = $obj->fk_default_home;
1419 $pathofwebsite =
$conf->website->dir_output.
'/'.
$object->ref;
1420 dolSaveIndexPage($pathofwebsite, $pathofwebsite.
'/index.php', $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php', $pathofwebsite.
'/wrapper.php',
$object);
1425 $this->db->rollback();
1428 $this->db->commit();
1447 $this->error =
'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)';
1453 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $this->
id);
1455 $resql = $this->db->query($sql);
1457 $this->error = $this->db->lasterror();
1461 $num = $this->db->num_rows($resql);
1466 $obj = $this->db->fetch_object($resql);
1468 $newid = $obj->rowid;
1470 $objectpagestatic->fetch($newid);
1472 $aliasesarray = explode(
',', $objectpagestatic->aliasalt);
1474 $filetpl =
$conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1477 $this->errors[] =
'Failed to write file '.basename($filetpl);
1482 if (!empty($objectpagestatic->pageurl) && !in_array($objectpagestatic->pageurl, $aliasesarray)) {
1483 $aliasesarray[] = $objectpagestatic->pageurl;
1487 if (is_array($aliasesarray)) {
1488 foreach ($aliasesarray as $aliasshortcuttocreate) {
1489 if (trim($aliasshortcuttocreate)) {
1490 $filealias =
$conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1493 $this->errors[] =
'Failed to write file '.basename($filealias);
1505 $pathofwebsite =
$conf->website->dir_output.
'/'.
$object->ref;
1506 $fileindex = $pathofwebsite.
'/index.php';
1508 if (
$object->fk_default_home > 0) {
1509 $filetpl = $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php';
1511 $filewrapper = $pathofwebsite.
'/wrapper.php';
1529 return !empty($this->otherlang);
1543 global $websitepagefile, $website;
1544 '@phan-var-force Website $website';
1546 if (!is_object($weblangs)) {
1547 return 'ERROR componentSelectLang called with parameter $weblangs not defined';
1550 $arrayofspecialmainlanguages = array(
1581 if (!empty($websitepagefile)) {
1582 $websitepagefileshort = basename($websitepagefile);
1583 if ($websitepagefileshort ==
'index.php') {
1584 $pageid = $website->fk_default_home;
1586 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), $websitepagefileshort);
1589 $tmppage->fetch($pageid);
1594 if (!is_array($languagecodes) && $pageid > 0) {
1595 $languagecodes = array();
1597 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
1598 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
1599 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
1600 $sql .=
" AND (wp.fk_page = ".((int) $pageid).
" OR wp.rowid = ".((int) $pageid);
1601 if ($tmppage->fk_page > 0) {
1602 $sql .=
" OR wp.fk_page = ".((int) $tmppage->fk_page).
" OR wp.rowid = ".((int) $tmppage->fk_page);
1606 $resql = $this->db->query($sql);
1608 while ($obj = $this->db->fetch_object($resql)) {
1609 $newlang = $obj->lang;
1610 if ($obj->rowid == $pageid) {
1611 $newlang = $obj->lang;
1613 if (!in_array($newlang, $languagecodes)) {
1614 $languagecodes[] = $newlang;
1621 $languagecodeselected = substr($weblangs->defaultlang, 0, 2);
1622 if (!empty($websitepagefile)) {
1623 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
1625 $pagelang = substr($tmppage->lang, 0, 2);
1626 $languagecodeselected = substr($pagelang, 0, 2);
1627 if (!in_array($pagelang, $languagecodes)) {
1628 $languagecodes[] = $pagelang;
1633 $weblangs->load(
'languages');
1636 $url = $_SERVER[
"REQUEST_URI"];
1637 $url = preg_replace(
'/(\?|&)l=([a-zA-Z_]*)/',
'', $url);
1639 $url .= (preg_match(
'/\?/', $url) ?
'&' :
'?').
'l=';
1640 if (!preg_match(
'/^\//', $url)) {
1645 $MAXHEIGHT = 4 * $HEIGHTOPTION;
1646 $nboflanguage = count($languagecodes);
1648 $out =
'<!-- componentSelectLang'.$htmlname.
' -->'.
"\n";
1651 $out .=
'.componentSelectLang'.$htmlname.
':hover { height: '.min($MAXHEIGHT, ($HEIGHTOPTION * $nboflanguage)).
'px; overflow-x: hidden; overflow-y: '.((($HEIGHTOPTION * $nboflanguage) > $MAXHEIGHT) ?
' scroll' :
'hidden').
'; }'.
"\n";
1652 $out .=
'.componentSelectLang'.$htmlname.
' li { line-height: '.$HEIGHTOPTION.
'px; }'.
"\n";
1653 $out .=
'.componentSelectLang'.$htmlname.
' {
1654 display: inline-block;
1656 height: '.$HEIGHTOPTION.
'px;
1658 transition: all .3s ease;
1660 vertical-align: top;
1662 .componentSelectLang'.$htmlname.
':hover, .componentSelectLang'.$htmlname.
':hover a { background-color: #fff; color: #000 !important; }
1663 ul.componentSelectLang'.$htmlname.
' { width: 150px; }
1664 ul.componentSelectLang'.$htmlname.
':hover .fa { visibility: hidden; }
1665 .componentSelectLang'.$htmlname.
' a { text-decoration: none; width: 100%; }
1666 .componentSelectLang'.$htmlname.
' li { display: block; padding: 0px 15px; margin-left: 0; margin-right: 0; }
1667 .componentSelectLang'.$htmlname.
' li:hover { background-color: #EEE; }
1670 $out .=
'<ul class="componentSelectLang'.$htmlname.($morecss ?
' '.$morecss :
'').
'">';
1672 if ($languagecodeselected) {
1674 if (strlen($languagecodeselected) == 2) {
1675 $languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.
'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
1678 $countrycode = strtolower(substr($languagecodeselected, -2));
1679 $label = $weblangs->trans(
"Language_".$languagecodeselected);
1680 if ($countrycode ==
'us') {
1681 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1683 $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>';
1684 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1685 $out .=
'</a></li>';
1688 if (is_array($languagecodes)) {
1689 foreach ($languagecodes as $languagecode) {
1691 if (strlen($languagecode) == 2) {
1692 $languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.
'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
1695 if ($languagecode == $languagecodeselected) {
1699 $countrycode = strtolower(substr($languagecode, -2));
1700 $label = $weblangs->trans(
"Language_".$languagecode);
1701 if ($countrycode ==
'us') {
1702 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1704 $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>';
1705 if (empty($i) && empty($languagecodeselected)) {
1706 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1708 $out .=
'</a></li>';
1731 if (empty($website->id) || empty($website->ref)) {
1735 if (empty($website->name_template) && empty($exportPath)) {
1736 setEventMessages(
"To export the website template into a directory of the server, the name of the directory/template must be provided.",
null,
'errors');
1739 if (!is_writable(
$conf->website->dir_temp)) {
1747 if (empty($exportPath)) {
1748 $destdirrel =
'install/doctemplates/websites/'.$website->name_template;
1749 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1751 $exportPath = rtrim($exportPath,
'/');
1752 if (strpos($exportPath,
'..') !==
false) {
1757 if (strpos($exportPath,
'/') === 0 || preg_match(
'/^[a-zA-Z]:/', $exportPath)) {
1758 if (!is_dir($exportPath)) {
1759 setEventMessages(
"The specified absolute path does not exist.",
null,
'errors');
1763 if (!is_writable($exportPath)) {
1764 setEventMessages(
"The specified absolute path is not writable.",
null,
'errors');
1767 $destdirrel = $exportPath;
1768 $destdir = $exportPath;
1771 $destdirrel =
'install/doctemplates/websites/'.$exportPath;
1772 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1779 if (!is_writable($destdir)) {
1780 setEventMessages(
"The specified path ".$destdir.
" is not writable.",
null,
'errors');
1788 if (
dol_is_file($destdir.
'/containers/README.md')) {
1789 dol_move($destdir.
'/containers/README.md', $destdir.
'/README.md',
'0', 1, 0, 0);
1791 if (
dol_is_file($destdir.
'/containers/LICENSE')) {
1792 dol_move($destdir.
'/containers/LICENSE', $destdir.
'/LICENSE',
'0', 1, 0, 0);
1808 if (!empty($resultarray)) {
1809 setEventMessages(
"Error, failed to unzip the export into target dir ".$destdir.
": ".implode(
',', $resultarray),
null,
'errors');
1811 setEventMessages(
"Website content written into ".$destdirrel,
null,
'mesgs');
1814 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?website='.$website->ref);
1826 if (preg_match(
'/page(\d+)\.tpl\.php/', $filename, $matches)) {
1827 return (
int) $matches[1];
1841 $sql =
"UPDATE ".$this->db->prefix().
"website SET";
1842 $sql .=
" name_template = '".$this->db->escape($name_template).
"'";
1843 $sql .=
" WHERE rowid = ".(int) $this->
id;
1844 $result = $this->db->query($sql);
1847 $this->db->commit();
1850 $this->db->rollback();
1862 if (!file_exists($pathname)) {
1863 if (touch($pathname)) {
1868 return unserialize(file_get_contents($pathname));
1880 return file_put_contents($pathname, serialize($etat));
1893 $fichiersSource = [];
1894 $fichiersDestination = [];
1896 $fichierWithNoPage = [];
1897 $fichierWithNoPageInDest = [];
1900 foreach (
dol_dir_list($dossierSource,
"files") as $file) {
1901 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1902 $fichiersSource[] = $file;
1904 $fichierWithNoPage[] = $file;
1909 foreach (
dol_dir_list($dossierDestination,
"all", 1) as $file) {
1910 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1911 $fichiersDestination[] = $file;
1913 $fichierWithNoPageInDest[] = $file;
1918 $numOfPageSource = 0;
1919 foreach ($fichiersSource as $index => $file) {
1920 if ($file[
'name'] == basename($fichierModifie[
'fullname'])) {
1927 $filesFound = array();
1928 foreach ($fichierWithNoPage as $filesource) {
1929 $fileContent = file_get_contents($filesource[
'fullname']);
1930 if (strpos($fileContent,
"require './page".$numOfPageSource.
".tpl.php'") !==
false) {
1931 $filesFound = $filesource;
1936 $numPagesFound =
'';
1937 foreach ($fichierWithNoPageInDest as $filedest) {
1938 if ($filedest[
'name'] === $filesFound[
'name']) {
1939 $fileContent = file_get_contents($filedest[
'fullname']);
1940 if (preg_match(
"/page\d+\.tpl\.php/", $fileContent, $matches)) {
1941 $numPagesFound = $matches[0];
1947 $fileNeeded = array();
1948 foreach ($fichiersDestination as $index => $file) {
1949 if ($file[
'name'] == $numPagesFound) {
1950 $fileNeeded = $file;
1955 if (isset($fileNeeded)) {
1956 $sourceContent = file_get_contents($fichierModifie[
'fullname']);
1957 if (file_exists($fileNeeded[
'fullname'])) {
1958 $destContent = file_get_contents($fileNeeded[
'fullname']);
1961 $differences = $this->
showDifferences($destContent, $sourceContent, array($numOfPageDest,$numOfPageSource));
1962 $differences[
'file_destination'] = $fileNeeded;
1964 $differences = array();
1966 return $differences;
1978 $str = str_replace(
"\r\n",
"\n", $str);
1979 $str = str_replace(
"\r",
"\n", $str);
1996 $lines1 = explode(
"\n", $str1);
1997 $lines2 = explode(
"\n", $str2);
1999 $linesShouldChange = array();
2000 $linesShouldNotChange = array();
2001 $linefound = array();
2002 $countNumPage = count($exceptNumPge);
2004 for ($i = 0;$i < $countNumPage; $i++) {
2005 $linefound[$i] = array();
2006 $linefound[$i][
'meta'] =
'/content="' . preg_quote((
string) $exceptNumPge[$i],
'/') .
'" \/>/';
2007 $linefound[$i][
'output'] =
'/dolWebsiteOutput\(\$tmp, "html", ' . preg_quote((
string) $exceptNumPge[$i],
'/') .
'\);/';
2010 if (isset($linefound[1])) {
2011 $maxLines = max(count($lines1), count($lines2));
2012 for ($lineNum = 0; $lineNum < $maxLines; $lineNum++) {
2013 $lineContent1 = $lines1[$lineNum] ??
'';
2014 $lineContent2 = $lines2[$lineNum] ??
'';
2015 if (preg_match($linefound[0][
'output'], $lineContent1)) {
2016 $linesShouldChange[] = $lineContent1;
2018 if (preg_match($linefound[0][
'meta'], $lineContent1)) {
2019 $linesShouldChange[] = $lineContent1;
2021 if (preg_match($linefound[1][
'output'], $lineContent2)) {
2022 $linesShouldNotChange[] = $lineContent2;
2024 if (preg_match($linefound[1][
'meta'], $lineContent2)) {
2025 $linesShouldNotChange[] = $lineContent2;
2027 if ($lineContent1 !== $lineContent2) {
2028 if (isset($lines1[$lineNum]) && !isset($lines2[$lineNum])) {
2030 $diff[
"Supprimée à la ligne " . ($lineNum + 1)] = $lineContent1;
2031 } elseif (!isset($lines1[$lineNum]) && isset($lines2[$lineNum])) {
2033 $diff[
"Ajoutée à la ligne " . ($lineNum + 1)] = $lineContent2;
2036 $diff[
"Modifiée à la ligne " . ($lineNum + 1)] = $lineContent2;
2043 if (empty($linesShouldChange)) {
2044 $linesShouldChange[0] =
'<meta name="dolibarr:pageid" content="'.$exceptNumPge[0].
'" />';
2045 $linesShouldChange[1] =
'$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$exceptNumPge[0].
');';
2048 $replacementMapping = array();
2049 if (!empty($linesShouldNotChange)) {
2051 foreach ($linesShouldNotChange as $numLigne => $ligneRemplacement) {
2052 if (isset($linesShouldChange[$numLigne])) {
2053 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$numLigne];
2055 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$i];
2059 $diff[
'lignes_dont_change'] = $replacementMapping;
2062 $pattern =
'/medias\/image\/'.preg_quote($this->
ref,
'/').
'\/([^\'"\s]+)/';
2064 foreach ($diff as $key => $value) {
2066 if (is_string($value)) {
2067 if (preg_match($pattern, $value)) {
2068 $newValue = preg_replace($pattern,
'medias/image/'.$this->name_template.
'/$1', $value);
2069 $diff[$key] = $newValue;
2085 if (file_exists($inplaceFile)) {
2088 if (!is_writable($inplaceFile)) {
2092 unset($differences[
'file_destination']);
2093 $contentDest = file($inplaceFile, FILE_IGNORE_NEW_LINES);
2094 foreach ($differences as $key => $ligneSource) {
2096 if (preg_match(
'/(Ajoutée|Modifiée) à la ligne (\d+)/', $key, $matches)) {
2097 $typeModification = $matches[1];
2098 $numLigne = (int) $matches[2] - 1;
2100 if ($typeModification ===
'Ajoutée') {
2101 array_splice($contentDest, $numLigne, 0, $ligneSource);
2102 } elseif ($typeModification ===
'Modifiée') {
2103 $contentDest[$numLigne] = $ligneSource;
2105 } elseif (preg_match(
'/Supprimée à la ligne (\d+)/', $key, $matches)) {
2106 $numLigne = (int) $matches[1] - 1;
2107 unset($contentDest[$numLigne]);
2111 $contentDest = array_values($contentDest);
2112 $stringreplacement = implode(
"\n", $contentDest);
2113 file_put_contents($inplaceFile, $stringreplacement);
2114 foreach ($differences[
'lignes_dont_change'] as $linechanged => $line) {
2115 if (in_array($linechanged, $contentDest)) {
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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.
saveState($etat, $pathname)
Save state for File.
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
checkPreviousState($pathname)
check previous state for file
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...
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_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.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
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_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dolSaveMasterFile($filemaster)
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).
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold=0)
Save content of a page on disk (page name is generally ID_of_page.php).