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);
269 $stringtodolibarrfile =
"# Some properties for Dolibarr web site CMS\n";
270 $stringtodolibarrfile .=
"param=value\n";
272 file_put_contents(
$conf->website->dir_output.
'/'.$this->ref.
'/.dolibarr', $stringtodolibarrfile);
277 $this->db->rollback();
278 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
297 public function fetch($id, $ref =
null)
303 $sql .=
" t.entity,";
305 $sql .=
" t.position,";
306 $sql .=
" t.description,";
308 $sql .=
" t.otherlang,";
309 $sql .=
" t.status,";
310 $sql .=
" t.fk_default_home,";
311 $sql .=
" t.use_manifest,";
312 $sql .=
" t.virtualhost,";
313 $sql .=
" t.fk_user_creat,";
314 $sql .=
" t.fk_user_modif,";
315 $sql .=
" t.date_creation,";
316 $sql .=
" t.tms as date_modification,";
317 $sql .=
" t.name_template";
318 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
319 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
321 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
323 $sql .=
" AND t.rowid = ".(int) $id;
326 $resql = $this->db->query($sql);
328 $numrows = $this->db->num_rows($resql);
330 $obj = $this->db->fetch_object($resql);
332 $this->
id = $obj->rowid;
334 $this->entity = $obj->entity;
335 $this->
ref = $obj->ref;
338 $this->lang = $obj->lang;
339 $this->otherlang = $obj->otherlang;
340 $this->
status = $obj->status;
341 $this->fk_default_home = $obj->fk_default_home;
342 $this->virtualhost = $obj->virtualhost;
343 $this->use_manifest = $obj->use_manifest;
344 $this->fk_user_creat = $obj->fk_user_creat;
345 $this->fk_user_modif = $obj->fk_user_modif;
346 $this->date_creation = $this->db->jdate($obj->date_creation);
347 $this->date_modification = $this->db->jdate($obj->date_modification);
348 $this->name_template = $obj->name_template;
350 $this->db->free($resql);
358 $this->errors[] =
'Error '.$this->db->lasterror();
359 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
377 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
385 $sql .=
" t.entity,";
387 $sql .=
" t.description,";
389 $sql .=
" t.otherlang,";
390 $sql .=
" t.status,";
391 $sql .=
" t.fk_default_home,";
392 $sql .=
" t.virtualhost,";
393 $sql .=
" t.fk_user_creat,";
394 $sql .=
" t.fk_user_modif,";
395 $sql .=
" t.date_creation,";
396 $sql .=
" t.tms as date_modification";
397 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
398 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
401 if (is_array($filter)) {
403 if (count($filter) > 0) {
404 foreach ($filter as $key => $value) {
405 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
408 if (count($sqlwhere) > 0) {
409 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
419 $this->errors[] = $errormessage;
420 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
424 if (!empty($sortfield)) {
425 $sql .= $this->db->order($sortfield, $sortorder);
427 if (!empty($limit)) {
428 $sql .= $this->db->plimit($limit, $offset);
431 $resql = $this->db->query($sql);
433 $num = $this->db->num_rows($resql);
435 while ($obj = $this->db->fetch_object($resql)) {
436 $record =
new self($this->db);
438 $record->id = $obj->rowid;
440 $record->entity = $obj->entity;
441 $record->ref = $obj->ref;
442 $record->description = $obj->description;
443 $record->lang = $obj->lang;
444 $record->otherlang = $obj->otherlang;
445 $record->status = $obj->status;
446 $record->fk_default_home = $obj->fk_default_home;
447 $record->virtualhost = $obj->virtualhost;
448 $record->fk_user_creat = $obj->fk_user_creat;
449 $record->fk_user_modif = $obj->fk_user_modif;
450 $record->date_creation = $this->db->jdate($obj->date_creation);
451 $record->date_modification = $this->db->jdate($obj->date_modification);
453 $records[$record->id] = $record;
455 $this->db->free($resql);
459 $this->errors[] =
'Error '.$this->db->lasterror();
460 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
475 global
$conf, $langs;
483 if (isset($this->entity)) {
484 $this->entity = (int) $this->entity;
486 if (isset($this->
ref)) {
487 $this->
ref = trim($this->
ref);
492 if (isset($this->
status)) {
497 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
498 $tmparray = explode(
',', $this->otherlang);
499 if (is_array($tmparray)) {
500 foreach ($tmparray as $key => $val) {
502 if (empty(trim($val))) {
503 unset($tmparray[$key]);
506 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
508 $this->otherlang = implode(
',', $tmparray);
510 if (empty($this->lang)) {
511 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
519 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
520 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
521 $sql .=
' ref = '.(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
',';
522 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
523 $sql .=
' lang = '.(isset($this->lang) ?
"'".$this->db->escape($this->lang).
"'" :
"null").
',';
524 $sql .=
' otherlang = '.(isset($this->otherlang) ?
"'".$this->db->escape($this->otherlang).
"'" :
"null").
',';
525 $sql .=
' status = '.(isset($this->
status) ? $this->
status :
"null").
',';
526 $sql .=
' fk_default_home = '.(($this->fk_default_home > 0) ? $this->fk_default_home :
"null").
',';
527 $sql .=
' use_manifest = '.((int) $this->use_manifest).
',';
528 $sql .=
' virtualhost = '.(($this->virtualhost !=
'') ?
"'".$this->db->escape($this->virtualhost).
"'" :
"null").
',';
529 $sql .=
' fk_user_modif = '.(!isset($this->fk_user_modif) ? $user->id : $this->fk_user_modif).
',';
530 $sql .=
' date_creation = '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
',';
531 $sql .=
' tms = '.(dol_strlen($this->date_modification) != 0 ?
"'".$this->db->idate($this->date_modification).
"'" :
"'".$this->db->idate(
dol_now()).
"'");
532 $sql .=
' WHERE rowid='.((int) $this->
id);
536 $resql = $this->db->query($sql);
539 $this->errors[] =
'Error '.$this->db->lasterror();
540 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
543 if (!$error && !$notrigger) {
548 $tmplangarray = explode(
',', $this->otherlang);
549 if (is_array($tmplangarray)) {
551 foreach ($tmplangarray as $val) {
552 if (trim($val) == $this->lang) {
555 dol_mkdir(
$conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
567 $this->db->rollback();
584 public function delete(
User $user, $notrigger = 0)
595 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'categorie_website_page';
596 $sql .=
' WHERE fk_website_page IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'website_page WHERE fk_website = '.((int) $this->
id).
')';
598 $resql = $this->db->query($sql);
601 $this->errors[] =
'Error '.$this->db->lasterror();
602 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
607 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
608 $sql .=
' WHERE fk_website = '.((int) $this->
id);
610 $resql = $this->db->query($sql);
613 $this->errors[] =
'Error '.$this->db->lasterror();
614 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
624 if (!$error && !empty($this->
ref)) {
625 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
632 $this->db->rollback();
660 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
661 $sql .=
' WHERE fk_website = '.((int) $this->
id);
663 $resql = $this->db->query($sql);
666 $this->errors[] =
'Error '.$this->db->lasterror();
667 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
671 if (!$error && !empty($this->
ref)) {
672 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
679 $this->db->rollback();
701 global
$conf, $langs;
702 global $dolibarr_main_data_root;
711 if (empty($newref)) {
712 $this->error =
'ErrorBadParameter newref';
719 if (
$object->fetch(0, $newref) > 0) {
720 $this->error =
'ErrorNewRefIsAlreadyUsed';
729 $oldidforhome =
$object->fk_default_home;
732 $pathofwebsiteold = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($oldref);
733 $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($newref);
736 $fileindex = $pathofwebsitenew.
'/index.php';
748 $object->fk_user_creat = $user->id;
750 $object->status = self::STATUS_DRAFT;
752 $object->lang = substr($langs->defaultlang, 0, 2);
756 $object->context[
'createfromclone'] =
'createfromclone';
757 $result =
$object->create($user);
761 $this->errors =
$object->errors;
762 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
770 $pathtomedias = DOL_DATA_ROOT.
'/medias';
771 $pathtomediasinwebsite = $pathofwebsitenew.
'/medias';
773 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
774 dol_mkdir(dirname($pathtomediasinwebsite));
775 $result = symlink($pathtomedias, $pathtomediasinwebsite);
779 $pathofmediasjsold = DOL_DATA_ROOT.
'/medias/js/'.$oldref;
780 $pathofmediasjsnew = DOL_DATA_ROOT.
'/medias/js/'.$newref;
783 $pathofmediasimageold = DOL_DATA_ROOT.
'/medias/image/'.$oldref;
784 $pathofmediasimagenew = DOL_DATA_ROOT.
'/medias/image/'.$newref;
791 $listofpages = $objectpages->fetchAll($fromid);
792 foreach ($listofpages as $pageid => $objectpageold) {
794 $filetplold = $pathofwebsitenew.
'/page'.$pageid.
'.tpl.php';
798 $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl,
'', 0,
$object->id, 1);
801 if (is_object($objectpagenew) && $objectpagenew->pageurl) {
802 $filealias = $pathofwebsitenew.
'/'.$objectpagenew->pageurl.
'.php';
803 $filetplnew = $pathofwebsitenew.
'/page'.$objectpagenew->id.
'.tpl.php';
816 if ($pageid == $oldidforhome) {
817 $newidforhome = $objectpagenew->id;
828 $object->fk_default_home = $newidforhome;
836 $filetpl = $pathofwebsitenew.
'/page'.$newidforhome.
'.tpl.php';
837 $filewrapper = $pathofwebsitenew.
'/wrapper.php';
845 unset(
$object->context[
'createfromclone']);
853 $this->db->rollback();
870 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
876 $label =
'<u>'.$langs->trans(
"WebSite").
'</u>';
878 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
879 $label .=
'<b>'.$langs->trans(
'MainLanguage').
':</b> '.$this->lang;
881 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/website/card.php?id='.$this->
id.
'"';
882 $linkstart .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
886 $linkstart = $linkend =
'';
889 $result .= ($linkstart.img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
890 if ($withpicto != 2) {
894 $result .= $linkstart.$this->ref.$linkend;
922 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
925 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
926 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
927 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
928 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
931 $statusType =
'status5';
932 if ($status == self::STATUS_VALIDATED) {
933 $statusType =
'status4';
936 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
953 $this->
ref =
'myspecimenwebsite';
956 $this->otherlang =
'fr,es';
958 $this->fk_default_home = 0;
959 $this->virtualhost =
'http://myvirtualhost';
960 $this->fk_user_creat = $user->id;
961 $this->fk_user_modif = $user->id;
962 $this->date_creation =
dol_now();
976 global
$conf, $mysoc;
980 if (empty($website->id) || empty($website->ref)) {
987 if (!is_writable(
$conf->website->dir_temp)) {
992 $destdir =
$conf->website->dir_temp.
'/'.$website->ref;
995 $countreallydeleted = 0;
997 if ($counttodelete != $countreallydeleted) {
998 setEventMessages(
"Failed to clean temp directory ".$destdir,
null,
'errors');
1002 $arrayreplacementinfilename = array();
1003 $arrayreplacementincss = array();
1004 $arrayreplacementincss[
'file=image/'.$website->ref.
'/'] =
"file=image/__WEBSITE_KEY__/";
1005 $arrayreplacementincss[
'file=js/'.$website->ref.
'/'] =
"file=js/__WEBSITE_KEY__/";
1006 $arrayreplacementincss[
'medias/image/'.$website->ref.
'/'] =
"medias/image/__WEBSITE_KEY__/";
1007 $arrayreplacementincss[
'medias/js/'.$website->ref.
'/'] =
"medias/js/__WEBSITE_KEY__/";
1008 if ($mysoc->logo_small) {
1009 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_small] =
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__";
1011 if ($mysoc->logo_mini) {
1012 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini] =
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__";
1015 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo] =
"file=logos%2Fthumbs%2F__LOGO_KEY__";
1020 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers');
1021 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey');
1022 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey');
1025 $srcdir =
$conf->website->dir_output.
'/'.$website->ref;
1026 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers';
1028 dol_syslog(
"Copy pages from ".$srcdir.
" into ".$destdir);
1029 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename, 2, array(
'old',
'back'), 1);
1032 if (
dol_is_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md')) {
1033 dol_copy(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md',
$conf->website->dir_temp.
'/'.$website->ref.
'/README.md');
1035 if (
dol_is_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE')) {
1036 dol_copy(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE',
$conf->website->dir_temp.
'/'.$website->ref.
'/LICENSE');
1040 $srcdir = DOL_DATA_ROOT.
'/medias/image/'.$website->ref;
1041 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey';
1043 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1044 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename);
1047 $srcdir = DOL_DATA_ROOT.
'/medias/js/'.$website->ref;
1048 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey';
1050 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1051 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename);
1054 $cssindestdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/styles.css.php';
1059 $htmldeaderindestdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/htmlheader.html';
1065 $filesql =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_pages.sql';
1066 $fp = fopen($filesql,
"w");
1073 $listofpages = $objectpages->fetchAll($website->id);
1078 foreach ($listofpages as $pageid => $objectpageold) {
1079 $objectpageold->newid = $i;
1083 foreach ($listofpages as $pageid => $objectpageold) {
1086 foreach ($listofpages as $pageid2 => $objectpageold2) {
1087 if ($pageid2 == $objectpageold->fk_page) {
1088 $newfk_page = $objectpageold2->newid;
1092 $objectpageold->newfk_page = $newfk_page;
1096 $line =
'-- File generated by Dolibarr '.DOL_VERSION.
' --;'.
"\n";
1100 foreach ($listofpages as $pageid => $objectpageold) {
1101 $oldpageid = $objectpageold->id;
1103 $allaliases = $objectpageold->pageurl;
1104 $allaliases .= ($objectpageold->aliasalt ?
','.$objectpageold->aliasalt :
'');
1109 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/page'.$objectpageold->id.
'.tpl.php', 0, 0, 0,
null,
false, 0);
1111 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1112 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1114 $arrayofaliases = explode(
',', $objectpageold->aliasalt);
1115 foreach ($arrayofaliases as $tmpaliasalt) {
1116 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1117 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1122 $line =
'-- Page ID '.$objectpageold->newid.
'__+MAX_llx_website_page__ - Aliases '.$allaliases.
' --;';
1127 $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)';
1128 $line .=
" VALUES(";
1129 $line .= $objectpageold->newid.
"__+MAX_llx_website_page__, ";
1130 $line .= ($objectpageold->newfk_page ? $this->db->escape($objectpageold->newfk_page).
"__+MAX_llx_website_page__" :
"null").
", ";
1131 $line .=
"__WEBSITE_ID__, ";
1132 $line .=
"'".$this->db->escape($objectpageold->pageurl).
"', ";
1133 $line .=
"'".$this->db->escape($objectpageold->aliasalt).
"', ";
1134 $line .=
"'".$this->db->escape($objectpageold->title).
"', ";
1135 $line .=
"'".$this->db->escape($objectpageold->description).
"', ";
1136 $line .=
"'".$this->db->escape($objectpageold->lang).
"', ";
1137 $line .=
"'".$this->db->escape($objectpageold->image).
"', ";
1138 $line .=
"'".$this->db->escape($objectpageold->keywords).
"', ";
1139 $line .=
"'".$this->db->escape($objectpageold->status).
"', ";
1140 $line .=
"'".$this->db->idate($objectpageold->date_creation).
"', ";
1141 $line .=
"'".$this->db->idate($objectpageold->date_modification).
"', ";
1142 $line .= ($objectpageold->import_key ?
"'".$this->db->escape($objectpageold->import_key).
"'" :
"null").
", ";
1143 $line .=
"'".$this->db->escape($objectpageold->grabbed_from).
"', ";
1144 $line .=
"'".$this->db->escape($objectpageold->type_container).
"', ";
1147 $stringtoexport = $objectpageold->htmlheader;
1148 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1149 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1150 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1151 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1152 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1154 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1155 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1156 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1157 $line .=
"'".$this->db->escape(str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport)).
"', ";
1160 $stringtoexport = $objectpageold->content;
1161 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1162 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1163 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1164 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1165 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1166 $stringtoexport = str_replace(
'"image/'.$website->ref.
'/',
'"image/__WEBSITE_KEY__/', $stringtoexport);
1167 $stringtoexport = str_replace(
'"/image/'.$website->ref.
'/',
'"/image/__WEBSITE_KEY__/', $stringtoexport);
1168 $stringtoexport = str_replace(
'"js/'.$website->ref.
'/',
'"js/__WEBSITE_KEY__/', $stringtoexport);
1169 $stringtoexport = str_replace(
'"/js/'.$website->ref.
'/',
'"/js/__WEBSITE_KEY__/', $stringtoexport);
1171 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1172 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1173 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1176 $line .=
"'".$this->db->escape($stringtoexport).
"', ";
1177 $line .=
"'".$this->db->escape($objectpageold->author_alias).
"', ";
1178 $line .= (int) $objectpageold->allowed_in_frames;
1186 if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) {
1188 $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__;";
1196 $line =
"\n-- For Dolibarr v14+ --;\n";
1197 $line .=
"UPDATE llx_website SET lang = '".$this->db->escape($this->lang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1198 $line .=
"UPDATE llx_website SET otherlang = '".$this->db->escape($this->otherlang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1207 $filedir =
$conf->website->dir_temp.
'/'.$website->ref.
'/.';
1208 $fileglob =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-*.zip';
1209 $filename =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-'.
dol_print_date(
dol_now(),
'dayhourlog').
'-V'.((float) DOL_VERSION).
'.zip';
1213 $result = dol_compress_dir($filedir, $filename,
'zip');
1219 $this->error = $errormsg;
1231 public function importWebSite($pathtofile)
1233 global
$conf, $mysoc;
1240 $this->error =
'Function importWebSite called on object not loaded (object->ref is empty)';
1247 $filename = basename($pathtofile);
1248 if (!preg_match(
'/^website_(.*)-(.*)$/', $filename, $reg)) {
1249 $this->errors[] =
'Bad format for filename '.$filename.
'. Must be website_XXX-VERSION.';
1255 if (!empty($result[
'error'])) {
1256 $this->errors[] =
'Failed to unzip file '.$pathtofile.
'.';
1260 $arrayreplacement = array();
1261 $arrayreplacement[
'__WEBSITE_ID__'] =
$object->id;
1262 $arrayreplacement[
'__WEBSITE_KEY__'] =
$object->ref;
1263 $arrayreplacement[
'__N__'] = $this->db->escape(
"\n");
1264 $arrayreplacement[
'__LOGO_SMALL_KEY__'] = $this->db->escape($mysoc->logo_small);
1265 $arrayreplacement[
'__LOGO_MINI_KEY__'] = $this->db->escape($mysoc->logo_mini);
1266 $arrayreplacement[
'__LOGO_KEY__'] = $this->db->escape($mysoc->logo);
1273 $cssindestdir =
$conf->website->dir_output.
'/'.
$object->ref.
'/styles.css.php';
1276 $htmldeaderindestdir =
$conf->website->dir_output.
'/'.
$object->ref.
'/htmlheader.html';
1280 $filemaster =
$conf->website->dir_output.
'/'.
$object->ref.
'/master.inc.php';
1283 $this->errors[] =
'Failed to write file '.$filemaster;
1291 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/image/'.
$object->ref.
'.';
1293 $this->errors[] = $this->error;
1302 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/js/'.
$object->ref.
'.';
1304 $this->errors[] = $this->error;
1309 $sqlfile =
$conf->website->dir_temp.
"/".
$object->ref.
'/website_pages.sql';
1316 $sqlgetrowid =
'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.
'website_page';
1317 $resql = $this->db->query($sqlgetrowid);
1319 $obj = $this->db->fetch_object($resql);
1320 $maxrowid = $obj->max;
1324 $runsql =
run_sql($sqlfile, 1, 0, 0,
'',
'none', 0, 1, 0, 0, 1);
1326 $this->errors[] =
'Failed to load sql file '.$sqlfile.
' (ret='.((int) $runsql).
')';
1333 $fp = fopen($sqlfile,
"r");
1335 while (!feof($fp)) {
1339 $buf = fgets($fp, 65000);
1343 if (preg_match(
'/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.+)\s--;/i', $buf, $reg)) {
1345 $oldid = (int) $reg[1];
1346 $newid = ((int) $reg[2] + $maxrowid);
1347 $aliasesarray = explode(
',', $reg[3]);
1349 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]);
1352 } elseif (preg_match(
'/^-- Page ID (\d+).*Aliases\s(.*)\s--;/i', $buf, $reg)) {
1354 $newid = ((int) $reg[1] + $maxrowid);
1355 $aliasesarray = explode(
',', $reg[2]);
1357 dol_syslog(
"In sql source file, we have the page with the new ID ".$newid.
", and we must create the shortcut aliases: ".$reg[2]);
1361 $objectpagestatic->fetch($newid);
1364 $filetpl =
$conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1367 $this->errors[] =
'Failed to write file '.basename($filetpl);
1372 if (is_array($aliasesarray)) {
1373 foreach ($aliasesarray as $aliasshortcuttocreate) {
1374 if (trim($aliasshortcuttocreate)) {
1375 $filealias =
$conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1378 $this->errors[] =
'Failed to write file '.basename($filealias);
1390 $sql =
"SELECT fk_default_home FROM ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int)
$object->id);
1391 $resql = $this->db->query($sql);
1393 $obj = $this->db->fetch_object($resql);
1395 $object->fk_default_home = $obj->fk_default_home;
1403 $pathofwebsite =
$conf->website->dir_output.
'/'.
$object->ref;
1404 dolSaveIndexPage($pathofwebsite, $pathofwebsite.
'/index.php', $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php', $pathofwebsite.
'/wrapper.php',
$object);
1409 $this->db->rollback();
1412 $this->db->commit();
1431 $this->error =
'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)';
1437 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $this->
id);
1439 $resql = $this->db->query($sql);
1441 $this->error = $this->db->lasterror();
1445 $num = $this->db->num_rows($resql);
1450 $obj = $this->db->fetch_object($resql);
1452 $newid = $obj->rowid;
1454 $objectpagestatic->fetch($newid);
1456 $aliasesarray = explode(
',', $objectpagestatic->aliasalt);
1458 $filetpl =
$conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1461 $this->errors[] =
'Failed to write file '.basename($filetpl);
1466 if (!empty($objectpagestatic->pageurl) && !in_array($objectpagestatic->pageurl, $aliasesarray)) {
1467 $aliasesarray[] = $objectpagestatic->pageurl;
1471 if (is_array($aliasesarray)) {
1472 foreach ($aliasesarray as $aliasshortcuttocreate) {
1473 if (trim($aliasshortcuttocreate)) {
1474 $filealias =
$conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1477 $this->errors[] =
'Failed to write file '.basename($filealias);
1489 $pathofwebsite =
$conf->website->dir_output.
'/'.
$object->ref;
1490 $fileindex = $pathofwebsite.
'/index.php';
1492 if (
$object->fk_default_home > 0) {
1493 $filetpl = $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php';
1495 $filewrapper = $pathofwebsite.
'/wrapper.php';
1513 return !empty($this->otherlang);
1527 global $websitepagefile, $website;
1528 '@phan-var-force Website $website';
1530 if (!is_object($weblangs)) {
1531 return 'ERROR componentSelectLang called with parameter $weblangs not defined';
1534 $arrayofspecialmainlanguages = array(
1565 if (!empty($websitepagefile)) {
1566 $websitepagefileshort = basename($websitepagefile);
1567 if ($websitepagefileshort ==
'index.php') {
1568 $pageid = $website->fk_default_home;
1570 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), $websitepagefileshort);
1573 $tmppage->fetch($pageid);
1578 if (!is_array($languagecodes) && $pageid > 0) {
1579 $languagecodes = array();
1581 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
1582 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
1583 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
1584 $sql .=
" AND (wp.fk_page = ".((int) $pageid).
" OR wp.rowid = ".((int) $pageid);
1585 if ($tmppage->fk_page > 0) {
1586 $sql .=
" OR wp.fk_page = ".((int) $tmppage->fk_page).
" OR wp.rowid = ".((int) $tmppage->fk_page);
1590 $resql = $this->db->query($sql);
1592 while ($obj = $this->db->fetch_object($resql)) {
1593 $newlang = $obj->lang;
1594 if ($obj->rowid == $pageid) {
1595 $newlang = $obj->lang;
1597 if (!in_array($newlang, $languagecodes)) {
1598 $languagecodes[] = $newlang;
1605 $languagecodeselected = substr($weblangs->defaultlang, 0, 2);
1606 if (!empty($websitepagefile)) {
1607 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
1609 $pagelang = substr($tmppage->lang, 0, 2);
1610 $languagecodeselected = substr($pagelang, 0, 2);
1611 if (!in_array($pagelang, $languagecodes)) {
1612 $languagecodes[] = $pagelang;
1617 $weblangs->load(
'languages');
1620 $url = $_SERVER[
"REQUEST_URI"];
1621 $url = preg_replace(
'/(\?|&)l=([a-zA-Z_]*)/',
'', $url);
1623 $url .= (preg_match(
'/\?/', $url) ?
'&' :
'?').
'l=';
1624 if (!preg_match(
'/^\//', $url)) {
1629 $MAXHEIGHT = 4 * $HEIGHTOPTION;
1630 $nboflanguage = count($languagecodes);
1632 $out =
'<!-- componentSelectLang'.$htmlname.
' -->'.
"\n";
1635 $out .=
'.componentSelectLang'.$htmlname.
':hover { height: '.min($MAXHEIGHT, ($HEIGHTOPTION * $nboflanguage)).
'px; overflow-x: hidden; overflow-y: '.((($HEIGHTOPTION * $nboflanguage) > $MAXHEIGHT) ?
' scroll' :
'hidden').
'; }'.
"\n";
1636 $out .=
'.componentSelectLang'.$htmlname.
' li { line-height: '.$HEIGHTOPTION.
'px; }'.
"\n";
1637 $out .=
'.componentSelectLang'.$htmlname.
' {
1638 display: inline-block;
1640 height: '.$HEIGHTOPTION.
'px;
1642 transition: all .3s ease;
1644 vertical-align: top;
1646 .componentSelectLang'.$htmlname.
':hover, .componentSelectLang'.$htmlname.
':hover a { background-color: #fff; color: #000 !important; }
1647 ul.componentSelectLang'.$htmlname.
' { width: 150px; }
1648 ul.componentSelectLang'.$htmlname.
':hover .fa { visibility: hidden; }
1649 .componentSelectLang'.$htmlname.
' a { text-decoration: none; width: 100%; }
1650 .componentSelectLang'.$htmlname.
' li { display: block; padding: 0px 15px; margin-left: 0; margin-right: 0; }
1651 .componentSelectLang'.$htmlname.
' li:hover { background-color: #EEE; }
1654 $out .=
'<ul class="componentSelectLang'.$htmlname.($morecss ?
' '.$morecss :
'').
'">';
1656 if ($languagecodeselected) {
1658 if (strlen($languagecodeselected) == 2) {
1659 $languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.
'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
1662 $countrycode = strtolower(substr($languagecodeselected, -2));
1663 $label = $weblangs->trans(
"Language_".$languagecodeselected);
1664 if ($countrycode ==
'us') {
1665 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1667 $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>';
1668 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1669 $out .=
'</a></li>';
1672 if (is_array($languagecodes)) {
1673 foreach ($languagecodes as $languagecode) {
1675 if (strlen($languagecode) == 2) {
1676 $languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.
'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
1679 if ($languagecode == $languagecodeselected) {
1683 $countrycode = strtolower(substr($languagecode, -2));
1684 $label = $weblangs->trans(
"Language_".$languagecode);
1685 if ($countrycode ==
'us') {
1686 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1688 $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>';
1689 if (empty($i) && empty($languagecodeselected)) {
1690 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1692 $out .=
'</a></li>';
1715 if (empty($website->id) || empty($website->ref)) {
1719 if (empty($website->name_template) && empty($exportPath)) {
1720 setEventMessages(
"To export the website template into a directory of the server, the name of the directory/template must be provided.",
null,
'errors');
1723 if (!is_writable(
$conf->website->dir_temp)) {
1731 if (empty($exportPath)) {
1732 $destdirrel =
'install/doctemplates/websites/'.$website->name_template;
1733 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1735 $exportPath = rtrim($exportPath,
'/');
1736 if (strpos($exportPath,
'..') !==
false) {
1741 if (strpos($exportPath,
'/') === 0 || preg_match(
'/^[a-zA-Z]:/', $exportPath)) {
1742 if (!is_dir($exportPath)) {
1743 setEventMessages(
"The specified absolute path does not exist.",
null,
'errors');
1747 if (!is_writable($exportPath)) {
1748 setEventMessages(
"The specified absolute path is not writable.",
null,
'errors');
1751 $destdirrel = $exportPath;
1752 $destdir = $exportPath;
1755 $destdirrel =
'install/doctemplates/websites/'.$exportPath;
1756 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1763 if (!is_writable($destdir)) {
1764 setEventMessages(
"The specified path ".$destdir.
" is not writable.",
null,
'errors');
1772 if (
dol_is_file($destdir.
'/containers/README.md')) {
1773 dol_move($destdir.
'/containers/README.md', $destdir.
'/README.md',
'0', 1, 0, 0);
1775 if (
dol_is_file($destdir.
'/containers/LICENSE')) {
1776 dol_move($destdir.
'/containers/LICENSE', $destdir.
'/LICENSE',
'0', 1, 0, 0);
1792 if (!empty($resultarray)) {
1793 setEventMessages(
"Error, failed to unzip the export into target dir ".$destdir.
": ".implode(
',', $resultarray),
null,
'errors');
1795 setEventMessages(
"Website content written into ".$destdirrel,
null,
'mesgs');
1798 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?website='.$website->ref);
1810 if (preg_match(
'/page(\d+)\.tpl\.php/', $filename, $matches)) {
1811 return (
int) $matches[1];
1823 $sql =
"UPDATE ".$this->db->prefix().
"website SET";
1824 $sql .=
" name_template = '".$this->db->escape($name_template).
"'";
1825 $sql .=
" WHERE rowid = ".(int) $this->
id;
1826 $result = $this->db->query($sql);
1829 $this->db->commit();
1832 $this->db->rollback();
1844 if (!file_exists($pathname)) {
1845 if (touch($pathname)) {
1850 return unserialize(file_get_contents($pathname));
1862 return file_put_contents($pathname, serialize($etat));
1875 $fichiersSource = [];
1876 $fichiersDestination = [];
1878 $fichierWithNoPage = [];
1879 $fichierWithNoPageInDest = [];
1882 foreach (
dol_dir_list($dossierSource,
"files") as $file) {
1883 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1884 $fichiersSource[] = $file;
1886 $fichierWithNoPage[] = $file;
1891 foreach (
dol_dir_list($dossierDestination,
"all", 1) as $file) {
1892 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1893 $fichiersDestination[] = $file;
1895 $fichierWithNoPageInDest[] = $file;
1900 $numOfPageSource = 0;
1901 foreach ($fichiersSource as $index => $file) {
1902 if ($file[
'name'] == basename($fichierModifie[
'fullname'])) {
1909 $filesFound = array();
1910 foreach ($fichierWithNoPage as $filesource) {
1911 $fileContent = file_get_contents($filesource[
'fullname']);
1912 if (strpos($fileContent,
"require './page".$numOfPageSource.
".tpl.php'") !==
false) {
1913 $filesFound = $filesource;
1918 $numPagesFound =
'';
1919 foreach ($fichierWithNoPageInDest as $filedest) {
1920 if ($filedest[
'name'] === $filesFound[
'name']) {
1921 $fileContent = file_get_contents($filedest[
'fullname']);
1922 if (preg_match(
"/page\d+\.tpl\.php/", $fileContent, $matches)) {
1923 $numPagesFound = $matches[0];
1929 $fileNeeded = array();
1930 foreach ($fichiersDestination as $index => $file) {
1931 if ($file[
'name'] == $numPagesFound) {
1932 $fileNeeded = $file;
1937 if (isset($fileNeeded)) {
1938 $sourceContent = file_get_contents($fichierModifie[
'fullname']);
1939 if (file_exists($fileNeeded[
'fullname'])) {
1940 $destContent = file_get_contents($fileNeeded[
'fullname']);
1943 $differences = $this->
showDifferences($destContent, $sourceContent, array($numOfPageDest,$numOfPageSource));
1944 $differences[
'file_destination'] = $fileNeeded;
1946 $differences = array();
1948 return $differences;
1960 $str = str_replace(
"\r\n",
"\n", $str);
1961 $str = str_replace(
"\r",
"\n", $str);
1978 $lines1 = explode(
"\n", $str1);
1979 $lines2 = explode(
"\n", $str2);
1981 $linesShouldChange = array();
1982 $linesShouldNotChange = array();
1983 $linefound = array();
1984 $countNumPage = count($exceptNumPge);
1986 for ($i = 0;$i < $countNumPage; $i++) {
1987 $linefound[$i] = array();
1988 $linefound[$i][
'meta'] =
'/content="' . preg_quote((
string) $exceptNumPge[$i],
'/') .
'" \/>/';
1989 $linefound[$i][
'output'] =
'/dolWebsiteOutput\(\$tmp, "html", ' . preg_quote((
string) $exceptNumPge[$i],
'/') .
'\);/';
1992 if (isset($linefound[1])) {
1993 $maxLines = max(count($lines1), count($lines2));
1994 for ($lineNum = 0; $lineNum < $maxLines; $lineNum++) {
1995 $lineContent1 = $lines1[$lineNum] ??
'';
1996 $lineContent2 = $lines2[$lineNum] ??
'';
1997 if (preg_match($linefound[0][
'output'], $lineContent1)) {
1998 $linesShouldChange[] = $lineContent1;
2000 if (preg_match($linefound[0][
'meta'], $lineContent1)) {
2001 $linesShouldChange[] = $lineContent1;
2003 if (preg_match($linefound[1][
'output'], $lineContent2)) {
2004 $linesShouldNotChange[] = $lineContent2;
2006 if (preg_match($linefound[1][
'meta'], $lineContent2)) {
2007 $linesShouldNotChange[] = $lineContent2;
2009 if ($lineContent1 !== $lineContent2) {
2010 if (isset($lines1[$lineNum]) && !isset($lines2[$lineNum])) {
2012 $diff[
"Supprimée à la ligne " . ($lineNum + 1)] = $lineContent1;
2013 } elseif (!isset($lines1[$lineNum]) && isset($lines2[$lineNum])) {
2015 $diff[
"Ajoutée à la ligne " . ($lineNum + 1)] = $lineContent2;
2018 $diff[
"Modifiée à la ligne " . ($lineNum + 1)] = $lineContent2;
2025 if (empty($linesShouldChange)) {
2026 $linesShouldChange[0] =
'<meta name="dolibarr:pageid" content="'.$exceptNumPge[0].
'" />';
2027 $linesShouldChange[1] =
'$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$exceptNumPge[0].
');';
2030 $replacementMapping = array();
2031 if (!empty($linesShouldNotChange)) {
2033 foreach ($linesShouldNotChange as $numLigne => $ligneRemplacement) {
2034 if (isset($linesShouldChange[$numLigne])) {
2035 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$numLigne];
2037 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$i];
2041 $diff[
'lignes_dont_change'] = $replacementMapping;
2044 $pattern =
'/medias\/image\/'.preg_quote($this->
ref,
'/').
'\/([^\'"\s]+)/';
2046 foreach ($diff as $key => $value) {
2048 if (is_string($value)) {
2049 if (preg_match($pattern, $value)) {
2050 $newValue = preg_replace($pattern,
'medias/image/'.$this->name_template.
'/$1', $value);
2051 $diff[$key] = $newValue;
2067 if (file_exists($inplaceFile)) {
2070 if (!is_writable($inplaceFile)) {
2074 unset($differences[
'file_destination']);
2075 $contentDest = file($inplaceFile, FILE_IGNORE_NEW_LINES);
2076 foreach ($differences as $key => $ligneSource) {
2078 if (preg_match(
'/(Ajoutée|Modifiée) à la ligne (\d+)/', $key, $matches)) {
2079 $typeModification = $matches[1];
2080 $numLigne = (int) $matches[2] - 1;
2082 if ($typeModification ===
'Ajoutée') {
2083 array_splice($contentDest, $numLigne, 0, $ligneSource);
2084 } elseif ($typeModification ===
'Modifiée') {
2085 $contentDest[$numLigne] = $ligneSource;
2087 } elseif (preg_match(
'/Supprimée à la ligne (\d+)/', $key, $matches)) {
2088 $numLigne = (int) $matches[1] - 1;
2089 unset($contentDest[$numLigne]);
2093 $contentDest = array_values($contentDest);
2094 $stringreplacement = implode(
"\n", $contentDest);
2095 file_put_contents($inplaceFile, $stringreplacement);
2096 foreach ($differences[
'lignes_dont_change'] as $linechanged => $line) {
2097 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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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_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).