30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43 public $element =
'website';
48 public $table_element =
'website';
50 protected $childtablesoncascade = array();
55 public $picto =
'globe';
90 public $fk_default_home;
95 public $fk_user_creat;
100 public $fk_user_modif;
110 public $use_manifest;
120 public $name_template;
122 const STATUS_DRAFT = 0;
123 const STATUS_VALIDATED = 1;
135 $this->ismultientitymanaged = 1;
147 global $conf, $langs;
155 if (isset($this->entity)) {
156 $this->entity = (int) $this->entity;
158 if (isset($this->
ref)) {
159 $this->
ref = trim($this->
ref);
164 if (isset($this->
status)) {
167 if (empty($this->date_creation)) {
168 $this->date_creation = $now;
170 if (empty($this->date_modification)) {
171 $this->date_modification = $now;
174 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
175 $tmparray = explode(
',', $this->otherlang);
176 if (is_array($tmparray)) {
177 foreach ($tmparray as $key => $val) {
179 if (empty(trim($val))) {
180 unset($tmparray[$key]);
183 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
185 $this->otherlang = implode(
',', $tmparray);
189 if (empty($this->entity)) {
190 $this->entity = $conf->entity;
192 if (empty($this->lang)) {
193 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
198 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
201 $sql .=
'description,';
203 $sql .=
'otherlang,';
205 $sql .=
'fk_default_home,';
206 $sql .=
'virtualhost,';
207 $sql .=
'fk_user_creat,';
208 $sql .=
'date_creation,';
211 $sql .=
') VALUES (';
212 $sql .=
' '.((empty($this->entity) && $this->entity !=
'0') ?
'NULL' : $this->entity).
',';
213 $sql .=
' '.(!isset($this->
ref) ?
'NULL' :
"'".$this->db->escape($this->
ref).
"'").
',';
215 $sql .=
' '.(!isset($this->lang) ?
'NULL' :
"'".$this->db->escape($this->lang).
"'").
',';
216 $sql .=
' '.(!isset($this->otherlang) ?
'NULL' :
"'".$this->db->escape($this->otherlang).
"'").
',';
217 $sql .=
' '.(!isset($this->
status) ?
'1' : $this->status).
',';
218 $sql .=
' '.(!isset($this->fk_default_home) ?
'NULL' : $this->fk_default_home).
',';
219 $sql .=
' '.(!isset($this->virtualhost) ?
'NULL' :
"'".$this->db->escape($this->virtualhost).
"'").
",";
220 $sql .=
' '.(!isset($this->fk_user_creat) ? $user->id : $this->fk_user_creat).
',';
221 $sql .=
' '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_creation).
"'").
",";
222 $sql .=
' '.((int) $this->
position).
",";
223 $sql .=
' '.(!isset($this->date_modification) ||
dol_strlen($this->date_modification) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_modification).
"'");
228 $resql = $this->db->query($sql);
231 $this->errors[] =
'Error '.$this->db->lasterror();
232 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
236 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
239 $tmplangarray = explode(
',', $this->otherlang);
240 if (is_array($tmplangarray)) {
241 dol_mkdir($conf->website->dir_output.
'/'.$this->ref);
242 foreach ($tmplangarray as $val) {
243 if (trim($val) == $this->lang) {
246 dol_mkdir($conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val), DOL_DATA_ROOT);
251 dol_mkdir($conf->medias->multidir_output[$conf->entity].
'/image/'.$this->ref, DOL_DATA_ROOT);
252 dol_mkdir($conf->medias->multidir_output[$conf->entity].
'/js/'.$this->ref, DOL_DATA_ROOT);
266 $stringtodolibarrfile =
"# Some properties for Dolibarr web site CMS\n";
267 $stringtodolibarrfile .=
"param=value\n";
269 file_put_contents($conf->website->dir_output.
'/'.$this->ref.
'/.dolibarr', $stringtodolibarrfile);
274 $this->db->rollback();
275 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
294 public function fetch($id, $ref =
null)
300 $sql .=
" t.entity,";
302 $sql .=
" t.position,";
303 $sql .=
" t.description,";
305 $sql .=
" t.otherlang,";
306 $sql .=
" t.status,";
307 $sql .=
" t.fk_default_home,";
308 $sql .=
" t.use_manifest,";
309 $sql .=
" t.virtualhost,";
310 $sql .=
" t.fk_user_creat,";
311 $sql .=
" t.fk_user_modif,";
312 $sql .=
" t.date_creation,";
313 $sql .=
" t.tms as date_modification,";
314 $sql .=
" t.name_template";
315 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
316 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
318 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
320 $sql .=
" AND t.rowid = ".(int) $id;
323 $resql = $this->db->query($sql);
325 $numrows = $this->db->num_rows($resql);
327 $obj = $this->db->fetch_object($resql);
329 $this->
id = $obj->rowid;
331 $this->entity = $obj->entity;
332 $this->
ref = $obj->ref;
335 $this->lang = $obj->lang;
336 $this->otherlang = $obj->otherlang;
337 $this->
status = $obj->status;
338 $this->fk_default_home = $obj->fk_default_home;
339 $this->virtualhost = $obj->virtualhost;
340 $this->use_manifest = $obj->use_manifest;
341 $this->fk_user_creat = $obj->fk_user_creat;
342 $this->fk_user_modif = $obj->fk_user_modif;
343 $this->date_creation = $this->db->jdate($obj->date_creation);
344 $this->date_modification = $this->db->jdate($obj->date_modification);
345 $this->name_template = $obj->name_template;
347 $this->db->free($resql);
355 $this->errors[] =
'Error '.$this->db->lasterror();
356 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
374 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
382 $sql .=
" t.entity,";
384 $sql .=
" t.description,";
386 $sql .=
" t.otherlang,";
387 $sql .=
" t.status,";
388 $sql .=
" t.fk_default_home,";
389 $sql .=
" t.virtualhost,";
390 $sql .=
" t.fk_user_creat,";
391 $sql .=
" t.fk_user_modif,";
392 $sql .=
" t.date_creation,";
393 $sql .=
" t.tms as date_modification";
394 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
395 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
398 if (is_array($filter)) {
400 if (count($filter) > 0) {
401 foreach ($filter as $key => $value) {
402 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
405 if (count($sqlwhere) > 0) {
406 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
416 $this->errors[] = $errormessage;
417 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
421 if (!empty($sortfield)) {
422 $sql .= $this->db->order($sortfield, $sortorder);
424 if (!empty($limit)) {
425 $sql .= $this->db->plimit($limit, $offset);
428 $resql = $this->db->query($sql);
430 $num = $this->db->num_rows($resql);
432 while ($obj = $this->db->fetch_object($resql)) {
433 $record =
new self($this->db);
435 $record->id = $obj->rowid;
437 $record->entity = $obj->entity;
438 $record->ref = $obj->ref;
439 $record->description = $obj->description;
440 $record->lang = $obj->lang;
441 $record->otherlang = $obj->otherlang;
442 $record->status = $obj->status;
443 $record->fk_default_home = $obj->fk_default_home;
444 $record->virtualhost = $obj->virtualhost;
445 $record->fk_user_creat = $obj->fk_user_creat;
446 $record->fk_user_modif = $obj->fk_user_modif;
447 $record->date_creation = $this->db->jdate($obj->date_creation);
448 $record->date_modification = $this->db->jdate($obj->date_modification);
450 $records[$record->id] = $record;
452 $this->db->free($resql);
456 $this->errors[] =
'Error '.$this->db->lasterror();
457 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
472 global $conf, $langs;
480 if (isset($this->entity)) {
481 $this->entity = (int) $this->entity;
483 if (isset($this->
ref)) {
484 $this->
ref = trim($this->
ref);
489 if (isset($this->
status)) {
494 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
495 $tmparray = explode(
',', $this->otherlang);
496 if (is_array($tmparray)) {
497 foreach ($tmparray as $key => $val) {
499 if (empty(trim($val))) {
500 unset($tmparray[$key]);
503 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
505 $this->otherlang = implode(
',', $tmparray);
507 if (empty($this->lang)) {
508 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
516 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
517 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
518 $sql .=
' ref = '.(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
',';
519 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
520 $sql .=
' lang = '.(isset($this->lang) ?
"'".$this->db->escape($this->lang).
"'" :
"null").
',';
521 $sql .=
' otherlang = '.(isset($this->otherlang) ?
"'".$this->db->escape($this->otherlang).
"'" :
"null").
',';
522 $sql .=
' status = '.(isset($this->
status) ? $this->
status :
"null").
',';
523 $sql .=
' fk_default_home = '.(($this->fk_default_home > 0) ? $this->fk_default_home :
"null").
',';
524 $sql .=
' use_manifest = '.((int) $this->use_manifest).
',';
525 $sql .=
' virtualhost = '.(($this->virtualhost !=
'') ?
"'".$this->db->escape($this->virtualhost).
"'" :
"null").
',';
526 $sql .=
' fk_user_modif = '.(!isset($this->fk_user_modif) ? $user->id : $this->fk_user_modif).
',';
527 $sql .=
' date_creation = '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
',';
528 $sql .=
' tms = '.(dol_strlen($this->date_modification) != 0 ?
"'".$this->db->idate($this->date_modification).
"'" :
"'".$this->db->idate(
dol_now()).
"'");
529 $sql .=
' WHERE rowid='.((int) $this->
id);
533 $resql = $this->db->query($sql);
536 $this->errors[] =
'Error '.$this->db->lasterror();
537 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
540 if (!$error && !$notrigger) {
545 $tmplangarray = explode(
',', $this->otherlang);
546 if (is_array($tmplangarray)) {
547 dol_mkdir($conf->website->dir_output.
'/'.$this->ref);
548 foreach ($tmplangarray as $val) {
549 if (trim($val) == $this->lang) {
552 dol_mkdir($conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
564 $this->db->rollback();
581 public function delete(
User $user, $notrigger = 0)
592 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'categorie_website_page';
593 $sql .=
' WHERE fk_website_page IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'website_page WHERE fk_website = '.((int) $this->
id).
')';
595 $resql = $this->db->query($sql);
598 $this->errors[] =
'Error '.$this->db->lasterror();
599 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
604 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
605 $sql .=
' WHERE fk_website = '.((int) $this->
id);
607 $resql = $this->db->query($sql);
610 $this->errors[] =
'Error '.$this->db->lasterror();
611 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
621 if (!$error && !empty($this->
ref)) {
622 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
629 $this->db->rollback();
651 global $conf, $langs;
652 global $dolibarr_main_data_root;
661 if (empty($newref)) {
662 $this->error =
'ErrorBadParameter';
669 if (
$object->fetch(0, $newref) > 0) {
670 $this->error =
'ErrorNewRefIsAlreadyUsed';
679 $oldidforhome =
$object->fk_default_home;
682 $pathofwebsiteold = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($oldref);
683 $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($newref);
686 $fileindex = $pathofwebsitenew.
'/index.php';
698 $object->fk_user_creat = $user->id;
700 $object->status = self::STATUS_DRAFT;
702 $object->lang = substr($langs->defaultlang, 0, 2);
706 $object->context[
'createfromclone'] =
'createfromclone';
707 $result =
$object->create($user);
711 $this->errors =
$object->errors;
712 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
720 $pathtomedias = DOL_DATA_ROOT.
'/medias';
721 $pathtomediasinwebsite = $pathofwebsitenew.
'/medias';
723 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
724 dol_mkdir(dirname($pathtomediasinwebsite));
725 $result = symlink($pathtomedias, $pathtomediasinwebsite);
729 $pathofmediasjsold = DOL_DATA_ROOT.
'/medias/js/'.$oldref;
730 $pathofmediasjsnew = DOL_DATA_ROOT.
'/medias/js/'.$newref;
733 $pathofmediasimageold = DOL_DATA_ROOT.
'/medias/image/'.$oldref;
734 $pathofmediasimagenew = DOL_DATA_ROOT.
'/medias/image/'.$newref;
741 $listofpages = $objectpages->fetchAll($fromid);
742 foreach ($listofpages as $pageid => $objectpageold) {
744 $filetplold = $pathofwebsitenew.
'/page'.$pageid.
'.tpl.php';
748 $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl,
'', 0,
$object->id, 1);
751 if (is_object($objectpagenew) && $objectpagenew->pageurl) {
752 $filealias = $pathofwebsitenew.
'/'.$objectpagenew->pageurl.
'.php';
753 $filetplnew = $pathofwebsitenew.
'/page'.$objectpagenew->id.
'.tpl.php';
766 if ($pageid == $oldidforhome) {
767 $newidforhome = $objectpagenew->id;
778 $object->fk_default_home = $newidforhome;
786 $filetpl = $pathofwebsitenew.
'/page'.$newidforhome.
'.tpl.php';
787 $filewrapper = $pathofwebsitenew.
'/wrapper.php';
795 unset(
$object->context[
'createfromclone']);
803 $this->db->rollback();
820 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
826 $label =
'<u>'.$langs->trans(
"WebSite").
'</u>';
828 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
829 $label .=
'<b>'.$langs->trans(
'MainLanguage').
':</b> '.$this->lang;
831 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/website/card.php?id='.$this->
id.
'"';
832 $linkstart .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
836 $linkstart = $linkend =
'';
839 $result .= ($linkstart.img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
840 if ($withpicto != 2) {
844 $result .= $linkstart.$this->ref.$linkend;
872 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
875 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
876 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
877 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
878 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
881 $statusType =
'status5';
882 if ($status == self::STATUS_VALIDATED) {
883 $statusType =
'status4';
886 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
903 $this->
ref =
'myspecimenwebsite';
906 $this->otherlang =
'fr,es';
908 $this->fk_default_home = 0;
909 $this->virtualhost =
'http://myvirtualhost';
910 $this->fk_user_creat = $user->id;
911 $this->fk_user_modif = $user->id;
912 $this->date_creation =
dol_now();
926 global $conf, $mysoc;
930 if (empty($website->id) || empty($website->ref)) {
935 dol_syslog(
"Create temp dir ".$conf->website->dir_temp);
937 if (!is_writable($conf->website->dir_temp)) {
938 setEventMessages(
"Temporary dir ".$conf->website->dir_temp.
" is not writable",
null,
'errors');
942 $destdir = $conf->website->dir_temp.
'/'.$website->ref;
945 $countreallydeleted = 0;
947 if ($counttodelete != $countreallydeleted) {
948 setEventMessages(
"Failed to clean temp directory ".$destdir,
null,
'errors');
952 $arrayreplacementinfilename = array();
953 $arrayreplacementincss = array();
954 $arrayreplacementincss[
'file=image/'.$website->ref.
'/'] =
"file=image/__WEBSITE_KEY__/";
955 $arrayreplacementincss[
'file=js/'.$website->ref.
'/'] =
"file=js/__WEBSITE_KEY__/";
956 $arrayreplacementincss[
'medias/image/'.$website->ref.
'/'] =
"medias/image/__WEBSITE_KEY__/";
957 $arrayreplacementincss[
'medias/js/'.$website->ref.
'/'] =
"medias/js/__WEBSITE_KEY__/";
958 if ($mysoc->logo_small) {
959 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_small] =
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__";
961 if ($mysoc->logo_mini) {
962 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini] =
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__";
965 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo] =
"file=logos%2Fthumbs%2F__LOGO_KEY__";
970 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/containers');
971 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey');
972 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey');
975 $srcdir = $conf->website->dir_output.
'/'.$website->ref;
976 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers';
978 dol_syslog(
"Copy pages from ".$srcdir.
" into ".$destdir);
979 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename, 2, array(
'old',
'back'), 1);
982 if (
dol_is_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md')) {
983 dol_copy($conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md', $conf->website->dir_temp.
'/'.$website->ref.
'/README.md');
985 if (
dol_is_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE')) {
986 dol_copy($conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE', $conf->website->dir_temp.
'/'.$website->ref.
'/LICENSE');
990 $srcdir = DOL_DATA_ROOT.
'/medias/image/'.$website->ref;
991 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey';
993 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
994 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename);
997 $srcdir = DOL_DATA_ROOT.
'/medias/js/'.$website->ref;
998 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey';
1000 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1001 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename);
1004 $cssindestdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers/styles.css.php';
1009 $htmldeaderindestdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers/htmlheader.html';
1015 $filesql = $conf->website->dir_temp.
'/'.$website->ref.
'/website_pages.sql';
1016 $fp = fopen($filesql,
"w");
1023 $listofpages = $objectpages->fetchAll($website->id);
1028 foreach ($listofpages as $pageid => $objectpageold) {
1029 $objectpageold->newid = $i;
1033 foreach ($listofpages as $pageid => $objectpageold) {
1036 foreach ($listofpages as $pageid2 => $objectpageold2) {
1037 if ($pageid2 == $objectpageold->fk_page) {
1038 $newfk_page = $objectpageold2->newid;
1042 $objectpageold->newfk_page = $newfk_page;
1046 $line =
'-- File generated by Dolibarr '.DOL_VERSION.
' --;'.
"\n";
1050 foreach ($listofpages as $pageid => $objectpageold) {
1051 $oldpageid = $objectpageold->id;
1053 $allaliases = $objectpageold->pageurl;
1054 $allaliases .= ($objectpageold->aliasalt ?
','.$objectpageold->aliasalt :
'');
1059 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/page'.$objectpageold->id.
'.tpl.php', 0, 0, 0,
null,
false, 0);
1061 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1062 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1064 $arrayofaliases = explode(
',', $objectpageold->aliasalt);
1065 foreach ($arrayofaliases as $tmpaliasalt) {
1066 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1067 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1072 $line =
'-- Page ID '.$objectpageold->newid.
'__+MAX_llx_website_page__ - Aliases '.$allaliases.
' --;';
1077 $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)';
1078 $line .=
" VALUES(";
1079 $line .= $objectpageold->newid.
"__+MAX_llx_website_page__, ";
1080 $line .= ($objectpageold->newfk_page ? $this->db->escape($objectpageold->newfk_page).
"__+MAX_llx_website_page__" :
"null").
", ";
1081 $line .=
"__WEBSITE_ID__, ";
1082 $line .=
"'".$this->db->escape($objectpageold->pageurl).
"', ";
1083 $line .=
"'".$this->db->escape($objectpageold->aliasalt).
"', ";
1084 $line .=
"'".$this->db->escape($objectpageold->title).
"', ";
1085 $line .=
"'".$this->db->escape($objectpageold->description).
"', ";
1086 $line .=
"'".$this->db->escape($objectpageold->lang).
"', ";
1087 $line .=
"'".$this->db->escape($objectpageold->image).
"', ";
1088 $line .=
"'".$this->db->escape($objectpageold->keywords).
"', ";
1089 $line .=
"'".$this->db->escape($objectpageold->status).
"', ";
1090 $line .=
"'".$this->db->idate($objectpageold->date_creation).
"', ";
1091 $line .=
"'".$this->db->idate($objectpageold->date_modification).
"', ";
1092 $line .= ($objectpageold->import_key ?
"'".$this->db->escape($objectpageold->import_key).
"'" :
"null").
", ";
1093 $line .=
"'".$this->db->escape($objectpageold->grabbed_from).
"', ";
1094 $line .=
"'".$this->db->escape($objectpageold->type_container).
"', ";
1097 $stringtoexport = $objectpageold->htmlheader;
1098 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1099 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1100 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1101 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1102 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1104 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1105 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1106 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1107 $line .=
"'".$this->db->escape(str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport)).
"', ";
1110 $stringtoexport = $objectpageold->content;
1111 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1112 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1113 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1114 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1115 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1116 $stringtoexport = str_replace(
'"image/'.$website->ref.
'/',
'"image/__WEBSITE_KEY__/', $stringtoexport);
1117 $stringtoexport = str_replace(
'"/image/'.$website->ref.
'/',
'"/image/__WEBSITE_KEY__/', $stringtoexport);
1118 $stringtoexport = str_replace(
'"js/'.$website->ref.
'/',
'"js/__WEBSITE_KEY__/', $stringtoexport);
1119 $stringtoexport = str_replace(
'"/js/'.$website->ref.
'/',
'"/js/__WEBSITE_KEY__/', $stringtoexport);
1121 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1122 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1123 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1126 $line .=
"'".$this->db->escape($stringtoexport).
"', ";
1127 $line .=
"'".$this->db->escape($objectpageold->author_alias).
"', ";
1128 $line .= (int) $objectpageold->allowed_in_frames;
1136 if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) {
1138 $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__;";
1146 $line =
"\n-- For Dolibarr v14+ --;\n";
1147 $line .=
"UPDATE llx_website SET lang = '".$this->db->escape($this->lang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1148 $line .=
"UPDATE llx_website SET otherlang = '".$this->db->escape($this->otherlang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1157 $filedir = $conf->website->dir_temp.
'/'.$website->ref.
'/.';
1158 $fileglob = $conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-*.zip';
1159 $filename = $conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-'.
dol_print_date(
dol_now(),
'dayhourlog').
'-V'.((float) DOL_VERSION).
'.zip';
1163 $result = dol_compress_dir($filedir, $filename,
'zip');
1169 $this->error = $errormsg;
1181 public function importWebSite($pathtofile)
1183 global $conf, $mysoc;
1190 $this->error =
'Function importWebSite called on object not loaded (object->ref is empty)';
1197 $filename = basename($pathtofile);
1198 if (!preg_match(
'/^website_(.*)-(.*)$/', $filename, $reg)) {
1199 $this->errors[] =
'Bad format for filename '.$filename.
'. Must be website_XXX-VERSION.';
1205 if (!empty($result[
'error'])) {
1206 $this->errors[] =
'Failed to unzip file '.$pathtofile.
'.';
1210 $arrayreplacement = array();
1211 $arrayreplacement[
'__WEBSITE_ID__'] =
$object->id;
1212 $arrayreplacement[
'__WEBSITE_KEY__'] =
$object->ref;
1213 $arrayreplacement[
'__N__'] = $this->db->escape(
"\n");
1214 $arrayreplacement[
'__LOGO_SMALL_KEY__'] = $this->db->escape($mysoc->logo_small);
1215 $arrayreplacement[
'__LOGO_MINI_KEY__'] = $this->db->escape($mysoc->logo_mini);
1216 $arrayreplacement[
'__LOGO_KEY__'] = $this->db->escape($mysoc->logo);
1220 dolCopyDir($conf->website->dir_temp.
'/'.
$object->ref.
'/containers', $conf->website->dir_output.
'/'.
$object->ref, 0, 1);
1223 $cssindestdir = $conf->website->dir_output.
'/'.
$object->ref.
'/styles.css.php';
1226 $htmldeaderindestdir = $conf->website->dir_output.
'/'.
$object->ref.
'/htmlheader.html';
1230 $filemaster = $conf->website->dir_output.
'/'.
$object->ref.
'/master.inc.php';
1233 $this->errors[] =
'Failed to write file '.$filemaster;
1238 if (
dol_is_dir($conf->website->dir_temp.
'/'.
$object->ref.
'/medias/image/websitekey')) {
1239 $result =
dolCopyDir($conf->website->dir_temp.
'/'.
$object->ref.
'/medias/image/websitekey', $conf->website->dir_output.
'/'.
$object->ref.
'/medias/image/'.
$object->ref, 0, 1);
1241 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/image/'.
$object->ref.
'.';
1243 $this->errors[] = $this->error;
1249 if (
dol_is_dir($conf->website->dir_temp.
'/'.
$object->ref.
'/medias/js/websitekey')) {
1250 $result =
dolCopyDir($conf->website->dir_temp.
'/'.
$object->ref.
'/medias/js/websitekey', $conf->website->dir_output.
'/'.
$object->ref.
'/medias/js/'.
$object->ref, 0, 1);
1252 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/js/'.
$object->ref.
'.';
1254 $this->errors[] = $this->error;
1259 $sqlfile = $conf->website->dir_temp.
"/".
$object->ref.
'/website_pages.sql';
1266 $sqlgetrowid =
'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.
'website_page';
1267 $resql = $this->db->query($sqlgetrowid);
1269 $obj = $this->db->fetch_object($resql);
1270 $maxrowid = $obj->max;
1274 $runsql =
run_sql($sqlfile, 1,
'', 0,
'',
'none', 0, 1, 0, 0, 1);
1276 $this->errors[] =
'Failed to load sql file '.$sqlfile.
' (ret='.((int) $runsql).
')';
1283 $fp = fopen($sqlfile,
"r");
1285 while (!feof($fp)) {
1289 $buf = fgets($fp, 65000);
1293 if (preg_match(
'/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.+)\s--;/i', $buf, $reg)) {
1295 $oldid = (int) $reg[1];
1296 $newid = ((int) $reg[2] + $maxrowid);
1297 $aliasesarray = explode(
',', $reg[3]);
1299 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]);
1302 } elseif (preg_match(
'/^-- Page ID (\d+).*Aliases\s(.*)\s--;/i', $buf, $reg)) {
1304 $newid = ((int) $reg[1] + $maxrowid);
1305 $aliasesarray = explode(
',', $reg[2]);
1307 dol_syslog(
"In sql source file, we have the page with the new ID ".$newid.
", and we must create the shortcut aliases: ".$reg[2]);
1311 $objectpagestatic->fetch($newid);
1314 $filetpl = $conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1317 $this->errors[] =
'Failed to write file '.basename($filetpl);
1322 if (is_array($aliasesarray)) {
1323 foreach ($aliasesarray as $aliasshortcuttocreate) {
1324 if (trim($aliasshortcuttocreate)) {
1325 $filealias = $conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1328 $this->errors[] =
'Failed to write file '.basename($filealias);
1340 $sql =
"SELECT fk_default_home FROM ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int)
$object->id);
1341 $resql = $this->db->query($sql);
1343 $obj = $this->db->fetch_object($resql);
1345 $object->fk_default_home = $obj->fk_default_home;
1353 $pathofwebsite = $conf->website->dir_output.
'/'.
$object->ref;
1354 dolSaveIndexPage($pathofwebsite, $pathofwebsite.
'/index.php', $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php', $pathofwebsite.
'/wrapper.php',
$object);
1359 $this->db->rollback();
1362 $this->db->commit();
1381 $this->error =
'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)';
1387 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $this->
id);
1389 $resql = $this->db->query($sql);
1391 $this->error = $this->db->lasterror();
1395 $num = $this->db->num_rows($resql);
1400 $obj = $this->db->fetch_object($resql);
1402 $newid = $obj->rowid;
1404 $objectpagestatic->fetch($newid);
1406 $aliasesarray = explode(
',', $objectpagestatic->aliasalt);
1408 $filetpl = $conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1411 $this->errors[] =
'Failed to write file '.basename($filetpl);
1416 if (!empty($objectpagestatic->pageurl) && !in_array($objectpagestatic->pageurl, $aliasesarray)) {
1417 $aliasesarray[] = $objectpagestatic->pageurl;
1421 if (is_array($aliasesarray)) {
1422 foreach ($aliasesarray as $aliasshortcuttocreate) {
1423 if (trim($aliasshortcuttocreate)) {
1424 $filealias = $conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1427 $this->errors[] =
'Failed to write file '.basename($filealias);
1439 $pathofwebsite = $conf->website->dir_output.
'/'.
$object->ref;
1440 $fileindex = $pathofwebsite.
'/index.php';
1442 if (
$object->fk_default_home > 0) {
1443 $filetpl = $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php';
1445 $filewrapper = $pathofwebsite.
'/wrapper.php';
1463 return !empty($this->otherlang);
1477 global $websitepagefile, $website;
1479 if (!is_object($weblangs)) {
1480 return 'ERROR componentSelectLang called with parameter $weblangs not defined';
1483 $arrayofspecialmainlanguages = array(
1514 if (!empty($websitepagefile)) {
1515 $websitepagefileshort = basename($websitepagefile);
1516 if ($websitepagefileshort ==
'index.php') {
1517 $pageid = $website->fk_default_home;
1519 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), $websitepagefileshort);
1522 $tmppage->fetch($pageid);
1527 if (!is_array($languagecodes) && $pageid > 0) {
1528 $languagecodes = array();
1530 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
1531 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
1532 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
1533 $sql .=
" AND (wp.fk_page = ".((int) $pageid).
" OR wp.rowid = ".((int) $pageid);
1534 if ($tmppage->fk_page > 0) {
1535 $sql .=
" OR wp.fk_page = ".((int) $tmppage->fk_page).
" OR wp.rowid = ".((int) $tmppage->fk_page);
1539 $resql = $this->db->query($sql);
1541 while ($obj = $this->db->fetch_object($resql)) {
1542 $newlang = $obj->lang;
1543 if ($obj->rowid == $pageid) {
1544 $newlang = $obj->lang;
1546 if (!in_array($newlang, $languagecodes)) {
1547 $languagecodes[] = $newlang;
1554 $languagecodeselected = substr($weblangs->defaultlang, 0, 2);
1555 if (!empty($websitepagefile)) {
1556 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
1558 $pagelang = substr($tmppage->lang, 0, 2);
1559 $languagecodeselected = substr($pagelang, 0, 2);
1560 if (!in_array($pagelang, $languagecodes)) {
1561 $languagecodes[] = $pagelang;
1566 $weblangs->load(
'languages');
1569 $url = $_SERVER[
"REQUEST_URI"];
1570 $url = preg_replace(
'/(\?|&)l=([a-zA-Z_]*)/',
'', $url);
1572 $url .= (preg_match(
'/\?/', $url) ?
'&' :
'?').
'l=';
1573 if (!preg_match(
'/^\//', $url)) {
1578 $MAXHEIGHT = 4 * $HEIGHTOPTION;
1579 $nboflanguage = count($languagecodes);
1581 $out =
'<!-- componentSelectLang'.$htmlname.
' -->'.
"\n";
1584 $out .=
'.componentSelectLang'.$htmlname.
':hover { height: '.min($MAXHEIGHT, ($HEIGHTOPTION * $nboflanguage)).
'px; overflow-x: hidden; overflow-y: '.((($HEIGHTOPTION * $nboflanguage) > $MAXHEIGHT) ?
' scroll' :
'hidden').
'; }'.
"\n";
1585 $out .=
'.componentSelectLang'.$htmlname.
' li { line-height: '.$HEIGHTOPTION.
'px; }'.
"\n";
1586 $out .=
'.componentSelectLang'.$htmlname.
' {
1587 display: inline-block;
1589 height: '.$HEIGHTOPTION.
'px;
1591 transition: all .3s ease;
1593 vertical-align: top;
1595 .componentSelectLang'.$htmlname.
':hover, .componentSelectLang'.$htmlname.
':hover a { background-color: #fff; color: #000 !important; }
1596 ul.componentSelectLang'.$htmlname.
' { width: 150px; }
1597 ul.componentSelectLang'.$htmlname.
':hover .fa { visibility: hidden; }
1598 .componentSelectLang'.$htmlname.
' a { text-decoration: none; width: 100%; }
1599 .componentSelectLang'.$htmlname.
' li { display: block; padding: 0px 15px; margin-left: 0; margin-right: 0; }
1600 .componentSelectLang'.$htmlname.
' li:hover { background-color: #EEE; }
1603 $out .=
'<ul class="componentSelectLang'.$htmlname.($morecss ?
' '.$morecss :
'').
'">';
1605 if ($languagecodeselected) {
1607 if (strlen($languagecodeselected) == 2) {
1608 $languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.
'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
1611 $countrycode = strtolower(substr($languagecodeselected, -2));
1612 $label = $weblangs->trans(
"Language_".$languagecodeselected);
1613 if ($countrycode ==
'us') {
1614 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1616 $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>';
1617 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1618 $out .=
'</a></li>';
1621 if (is_array($languagecodes)) {
1622 foreach ($languagecodes as $languagecode) {
1624 if (strlen($languagecode) == 2) {
1625 $languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.
'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
1628 if ($languagecode == $languagecodeselected) {
1632 $countrycode = strtolower(substr($languagecode, -2));
1633 $label = $weblangs->trans(
"Language_".$languagecode);
1634 if ($countrycode ==
'us') {
1635 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1637 $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>';
1638 if (empty($i) && empty($languagecodeselected)) {
1639 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1641 $out .=
'</a></li>';
1664 if (empty($website->id) || empty($website->ref)) {
1668 if (empty($website->name_template) && empty($exportPath)) {
1669 setEventMessages(
"To export the website template into a directory of the server, the name of the directory/template must be provided.",
null,
'errors');
1672 if (!is_writable($conf->website->dir_temp)) {
1673 setEventMessages(
"Temporary dir ".$conf->website->dir_temp.
" is not writable",
null,
'errors');
1680 if (empty($exportPath)) {
1681 $destdirrel =
'install/doctemplates/websites/'.$website->name_template;
1682 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1684 $exportPath = rtrim($exportPath,
'/');
1685 if (strpos($exportPath,
'..') !==
false) {
1690 if (strpos($exportPath,
'/') === 0 || preg_match(
'/^[a-zA-Z]:/', $exportPath)) {
1691 if (!is_dir($exportPath)) {
1692 setEventMessages(
"The specified absolute path does not exist.",
null,
'errors');
1696 if (!is_writable($exportPath)) {
1697 setEventMessages(
"The specified absolute path is not writable.",
null,
'errors');
1700 $destdirrel = $exportPath;
1701 $destdir = $exportPath;
1704 $destdirrel =
'install/doctemplates/websites/'.$exportPath;
1705 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1712 if (!is_writable($destdir)) {
1713 setEventMessages(
"The specified path ".$destdir.
" is not writable.",
null,
'errors');
1721 if (
dol_is_file($destdir.
'/containers/README.md')) {
1722 dol_move($destdir.
'/containers/README.md', $destdir.
'/README.md',
'0', 1, 0, 0);
1724 if (
dol_is_file($destdir.
'/containers/LICENSE')) {
1725 dol_move($destdir.
'/containers/LICENSE', $destdir.
'/LICENSE',
'0', 1, 0, 0);
1741 if (!empty($resultarray)) {
1742 setEventMessages(
"Error, failed to unzip the export into target dir ".$destdir.
": ".implode(
',', $resultarray),
null,
'errors');
1744 setEventMessages(
"Website content written into ".$destdirrel,
null,
'mesgs');
1747 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?website='.$website->ref);
1759 if (preg_match(
'/page(\d+)\.tpl\.php/', $filename, $matches)) {
1760 return (
int) $matches[1];
1772 $sql =
"UPDATE ".$this->db->prefix().
"website SET";
1773 $sql .=
" name_template = '".$this->db->escape($name_template).
"'";
1774 $sql .=
" WHERE rowid = ".(int) $this->
id;
1775 $result = $this->db->query($sql);
1778 $this->db->commit();
1781 $this->db->rollback();
1793 if (!file_exists($pathname)) {
1794 if (touch($pathname)) {
1799 return unserialize(file_get_contents($pathname));
1811 return file_put_contents($pathname, serialize($etat));
1824 $fichiersSource = [];
1825 $fichiersDestination = [];
1827 $fichierWithNoPage = [];
1828 $fichierWithNoPageInDest = [];
1831 foreach (
dol_dir_list($dossierSource,
"files") as $file) {
1832 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1833 $fichiersSource[] = $file;
1835 $fichierWithNoPage[] = $file;
1840 foreach (
dol_dir_list($dossierDestination,
"all", 1) as $file) {
1841 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1842 $fichiersDestination[] = $file;
1844 $fichierWithNoPageInDest[] = $file;
1849 $numOfPageSource = 0;
1850 foreach ($fichiersSource as $index => $file) {
1851 if ($file[
'name'] == basename($fichierModifie[
'fullname'])) {
1858 $filesFound = array();
1859 foreach ($fichierWithNoPage as $filesource) {
1860 $fileContent = file_get_contents($filesource[
'fullname']);
1861 if (strpos($fileContent,
"require './page".$numOfPageSource.
".tpl.php'") !==
false) {
1862 $filesFound = $filesource;
1867 $numPagesFound =
'';
1868 foreach ($fichierWithNoPageInDest as $filedest) {
1869 if ($filedest[
'name'] === $filesFound[
'name']) {
1870 $fileContent = file_get_contents($filedest[
'fullname']);
1871 if (preg_match(
"/page\d+\.tpl\.php/", $fileContent, $matches)) {
1872 $numPagesFound = $matches[0];
1878 $fileNeeded = array();
1879 foreach ($fichiersDestination as $index => $file) {
1880 if ($file[
'name'] == $numPagesFound) {
1881 $fileNeeded = $file;
1886 if (isset($fileNeeded)) {
1887 $sourceContent = file_get_contents($fichierModifie[
'fullname']);
1888 if (file_exists($fileNeeded[
'fullname'])) {
1889 $destContent = file_get_contents($fileNeeded[
'fullname']);
1892 $differences = $this->
showDifferences($destContent, $sourceContent, array($numOfPageDest,$numOfPageSource));
1893 $differences[
'file_destination'] = $fileNeeded;
1895 $differences = array();
1897 return $differences;
1909 $str = str_replace(
"\r\n",
"\n", $str);
1910 $str = str_replace(
"\r",
"\n", $str);
1927 $lines1 = explode(
"\n", $str1);
1928 $lines2 = explode(
"\n", $str2);
1930 $linesShouldChange = array();
1931 $linesShouldNotChange = array();
1932 $linefound = array();
1933 $countNumPage = count($exceptNumPge);
1935 for ($i = 0;$i < $countNumPage; $i++) {
1936 $linefound[$i] = array();
1937 $linefound[$i][
'meta'] =
'/content="' . preg_quote($exceptNumPge[$i],
'/') .
'" \/>/';
1938 $linefound[$i][
'output'] =
'/dolWebsiteOutput\(\$tmp, "html", ' . preg_quote($exceptNumPge[$i],
'/') .
'\);/';
1941 if (isset($linefound[1])) {
1942 $maxLines = max(count($lines1), count($lines2));
1943 for ($lineNum = 0; $lineNum < $maxLines; $lineNum++) {
1944 $lineContent1 = $lines1[$lineNum] ??
'';
1945 $lineContent2 = $lines2[$lineNum] ??
'';
1946 if (preg_match($linefound[0][
'output'], $lineContent1)) {
1947 $linesShouldChange[] = $lineContent1;
1949 if (preg_match($linefound[0][
'meta'], $lineContent1)) {
1950 $linesShouldChange[] = $lineContent1;
1952 if (preg_match($linefound[1][
'output'], $lineContent2)) {
1953 $linesShouldNotChange[] = $lineContent2;
1955 if (preg_match($linefound[1][
'meta'], $lineContent2)) {
1956 $linesShouldNotChange[] = $lineContent2;
1958 if ($lineContent1 !== $lineContent2) {
1959 if (isset($lines1[$lineNum]) && !isset($lines2[$lineNum])) {
1961 $diff[
"Supprimée à la ligne " . ($lineNum + 1)] = $lineContent1;
1962 } elseif (!isset($lines1[$lineNum]) && isset($lines2[$lineNum])) {
1964 $diff[
"Ajoutée à la ligne " . ($lineNum + 1)] = $lineContent2;
1967 $diff[
"Modifiée à la ligne " . ($lineNum + 1)] = $lineContent2;
1974 if (empty($linesShouldChange)) {
1975 $linesShouldChange[0] =
'<meta name="dolibarr:pageid" content="'.$exceptNumPge[0].
'" />';
1976 $linesShouldChange[1] =
'$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$exceptNumPge[0].
');';
1979 $replacementMapping = array();
1980 if (!empty($linesShouldNotChange)) {
1982 foreach ($linesShouldNotChange as $numLigne => $ligneRemplacement) {
1983 if (isset($linesShouldChange[$numLigne])) {
1984 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$numLigne];
1986 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$i];
1990 $diff[
'lignes_dont_change'] = $replacementMapping;
1993 $pattern =
'/medias\/image\/'.preg_quote($this->
ref,
'/').
'\/([^\'"\s]+)/';
1995 foreach ($diff as $key => $value) {
1997 if (is_string($value)) {
1998 if (preg_match($pattern, $value)) {
1999 $newValue = preg_replace($pattern,
'medias/image/'.$this->name_template.
'/$1', $value);
2000 $diff[$key] = $newValue;
2016 if (file_exists($inplaceFile)) {
2019 if (!is_writable($inplaceFile)) {
2023 unset($differences[
'file_destination']);
2024 $contentDest = file($inplaceFile, FILE_IGNORE_NEW_LINES);
2025 foreach ($differences as $key => $ligneSource) {
2027 if (preg_match(
'/(Ajoutée|Modifiée) à la ligne (\d+)/', $key, $matches)) {
2028 $typeModification = $matches[1];
2029 $numLigne = (int) $matches[2] - 1;
2031 if ($typeModification ===
'Ajoutée') {
2032 array_splice($contentDest, $numLigne, 0, $ligneSource);
2033 } elseif ($typeModification ===
'Modifiée') {
2034 $contentDest[$numLigne] = $ligneSource;
2036 } elseif (preg_match(
'/Supprimée à la ligne (\d+)/', $key, $matches)) {
2037 $numLigne = (int) $matches[1] - 1;
2038 unset($contentDest[$numLigne]);
2042 $contentDest = array_values($contentDest);
2043 $stringreplacement = implode(
"\n", $contentDest);
2044 file_put_contents($inplaceFile, $stringreplacement);
2045 foreach ($differences[
'lignes_dont_change'] as $linechanged => $line) {
2046 if (in_array($linechanged, $contentDest)) {
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.
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 $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.
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).
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return 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)
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).