30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43 public $element =
'website';
48 public $table_element =
'website';
53 protected $childtablesoncascade = array();
58 public $picto =
'globe';
93 public $fk_default_home;
98 public $fk_user_creat;
103 public $fk_user_modif;
113 public $use_manifest;
123 public $name_template;
125 const STATUS_DRAFT = 0;
126 const STATUS_VALIDATED = 1;
138 $this->ismultientitymanaged = 1;
150 global
$conf, $langs;
158 if (isset($this->entity)) {
159 $this->entity = (int) $this->entity;
161 if (isset($this->
ref)) {
162 $this->
ref = trim($this->
ref);
167 if (isset($this->
status)) {
170 if (empty($this->date_creation)) {
171 $this->date_creation = $now;
173 if (empty($this->date_modification)) {
174 $this->date_modification = $now;
177 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
178 $tmparray = explode(
',', $this->otherlang);
179 if (is_array($tmparray)) {
180 foreach ($tmparray as $key => $val) {
182 if (empty(trim($val))) {
183 unset($tmparray[$key]);
186 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
188 $this->otherlang = implode(
',', $tmparray);
192 if (empty($this->entity)) {
193 $this->entity =
$conf->entity;
195 if (empty($this->lang)) {
196 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
201 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
204 $sql .=
'description,';
206 $sql .=
'otherlang,';
208 $sql .=
'fk_default_home,';
209 $sql .=
'virtualhost,';
210 $sql .=
'fk_user_creat,';
211 $sql .=
'date_creation,';
214 $sql .=
') VALUES (';
215 $sql .=
' '.((empty($this->entity) && $this->entity !=
'0') ?
'NULL' : $this->entity).
',';
216 $sql .=
' '.(!isset($this->
ref) ?
'NULL' :
"'".$this->db->escape($this->
ref).
"'").
',';
218 $sql .=
' '.(!isset($this->lang) ?
'NULL' :
"'".$this->db->escape($this->lang).
"'").
',';
219 $sql .=
' '.(!isset($this->otherlang) ?
'NULL' :
"'".$this->db->escape($this->otherlang).
"'").
',';
220 $sql .=
' '.(!isset($this->
status) ?
'1' : $this->status).
',';
221 $sql .=
' '.(!isset($this->fk_default_home) ?
'NULL' : $this->fk_default_home).
',';
222 $sql .=
' '.(!isset($this->virtualhost) ?
'NULL' :
"'".$this->db->escape($this->virtualhost).
"'").
",";
223 $sql .=
' '.(!isset($this->fk_user_creat) ? $user->id : $this->fk_user_creat).
',';
224 $sql .=
' '.(!isset($this->date_creation) ||
dol_strlen((
string) $this->date_creation) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_creation).
"'").
",";
225 $sql .=
' '.((int) $this->
position).
",";
226 $sql .=
' '.(!isset($this->date_modification) ||
dol_strlen((
string) $this->date_modification) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_modification).
"'");
231 $resql = $this->db->query($sql);
234 $this->errors[] =
'Error '.$this->db->lasterror();
235 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
239 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
242 $tmplangarray = explode(
',', $this->otherlang);
243 if (is_array($tmplangarray)) {
245 foreach ($tmplangarray as $val) {
246 if (trim($val) == $this->lang) {
249 dol_mkdir(
$conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val), DOL_DATA_ROOT);
254 dol_mkdir(
$conf->medias->multidir_output[
$conf->entity].
'/image/'.$this->ref, DOL_DATA_ROOT);
257 $pathofwebsite =
$conf->website->dir_output.
'/'.$this->ref;
261 $pathtomedias = DOL_DATA_ROOT.
'/medias';
262 $pathtomediasinwebsite = $pathofwebsite.
'/medias';
264 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
265 dol_mkdir(dirname($pathtomediasinwebsite));
266 $result = symlink($pathtomedias, $pathtomediasinwebsite);
268 $langs->load(
"errors");
283 $stringtodolibarrfile =
"# Some properties for Dolibarr web site CMS\n";
284 $stringtodolibarrfile .=
"param=value\n";
286 file_put_contents(
$conf->website->dir_output.
'/'.$this->ref.
'/.dolibarr', $stringtodolibarrfile);
291 $this->db->rollback();
292 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
311 public function fetch($id, $ref =
null)
317 $sql .=
" t.entity,";
319 $sql .=
" t.position,";
320 $sql .=
" t.description,";
322 $sql .=
" t.otherlang,";
323 $sql .=
" t.status,";
324 $sql .=
" t.fk_default_home,";
325 $sql .=
" t.use_manifest,";
326 $sql .=
" t.virtualhost,";
327 $sql .=
" t.fk_user_creat,";
328 $sql .=
" t.fk_user_modif,";
329 $sql .=
" t.date_creation,";
330 $sql .=
" t.tms as date_modification,";
331 $sql .=
" t.name_template";
332 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
333 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
335 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
337 $sql .=
" AND t.rowid = ".(int) $id;
340 $resql = $this->db->query($sql);
342 $numrows = $this->db->num_rows($resql);
344 $obj = $this->db->fetch_object($resql);
346 $this->
id = $obj->rowid;
348 $this->entity = $obj->entity;
349 $this->
ref = $obj->ref;
352 $this->lang = $obj->lang;
353 $this->otherlang = $obj->otherlang;
354 $this->
status = $obj->status;
355 $this->fk_default_home = $obj->fk_default_home;
356 $this->virtualhost = $obj->virtualhost;
357 $this->use_manifest = $obj->use_manifest;
358 $this->fk_user_creat = $obj->fk_user_creat;
359 $this->fk_user_modif = $obj->fk_user_modif;
360 $this->date_creation = $this->db->jdate($obj->date_creation);
361 $this->date_modification = $this->db->jdate($obj->date_modification);
362 $this->name_template = $obj->name_template;
364 $this->db->free($resql);
372 $this->errors[] =
'Error '.$this->db->lasterror();
373 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
391 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
399 $sql .=
" t.entity,";
401 $sql .=
" t.description,";
403 $sql .=
" t.otherlang,";
404 $sql .=
" t.status,";
405 $sql .=
" t.fk_default_home,";
406 $sql .=
" t.virtualhost,";
407 $sql .=
" t.fk_user_creat,";
408 $sql .=
" t.fk_user_modif,";
409 $sql .=
" t.date_creation,";
410 $sql .=
" t.tms as date_modification";
411 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
412 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
415 if (is_array($filter)) {
417 if (count($filter) > 0) {
418 foreach ($filter as $key => $value) {
419 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
422 if (count($sqlwhere) > 0) {
423 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
433 $this->errors[] = $errormessage;
434 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
438 if (!empty($sortfield)) {
439 $sql .= $this->db->order($sortfield, $sortorder);
441 if (!empty($limit)) {
442 $sql .= $this->db->plimit($limit, $offset);
445 $resql = $this->db->query($sql);
447 $num = $this->db->num_rows($resql);
449 while ($obj = $this->db->fetch_object($resql)) {
450 $record =
new self($this->db);
452 $record->id = $obj->rowid;
454 $record->entity = $obj->entity;
455 $record->ref = $obj->ref;
456 $record->description = $obj->description;
457 $record->lang = $obj->lang;
458 $record->otherlang = $obj->otherlang;
459 $record->status = $obj->status;
460 $record->fk_default_home = $obj->fk_default_home;
461 $record->virtualhost = $obj->virtualhost;
462 $record->fk_user_creat = $obj->fk_user_creat;
463 $record->fk_user_modif = $obj->fk_user_modif;
464 $record->date_creation = $this->db->jdate($obj->date_creation);
465 $record->date_modification = $this->db->jdate($obj->date_modification);
467 $records[$record->id] = $record;
469 $this->db->free($resql);
473 $this->errors[] =
'Error '.$this->db->lasterror();
474 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
489 global
$conf, $langs;
497 if (isset($this->entity)) {
498 $this->entity = (int) $this->entity;
500 if (isset($this->
ref)) {
501 $this->
ref = trim($this->
ref);
506 if (isset($this->
status)) {
511 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
512 $tmparray = explode(
',', $this->otherlang);
513 if (is_array($tmparray)) {
514 foreach ($tmparray as $key => $val) {
516 if (empty(trim($val))) {
517 unset($tmparray[$key]);
520 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
522 $this->otherlang = implode(
',', $tmparray);
524 if (empty($this->lang)) {
525 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
533 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
534 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
535 $sql .=
' ref = '.(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
',';
536 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
537 $sql .=
' lang = '.(isset($this->lang) ?
"'".$this->db->escape($this->lang).
"'" :
"null").
',';
538 $sql .=
' otherlang = '.(isset($this->otherlang) ?
"'".$this->db->escape($this->otherlang).
"'" :
"null").
',';
539 $sql .=
' status = '.(isset($this->
status) ? $this->
status :
"null").
',';
540 $sql .=
' fk_default_home = '.(($this->fk_default_home > 0) ? $this->fk_default_home :
"null").
',';
541 $sql .=
' use_manifest = '.((int) $this->use_manifest).
',';
542 $sql .=
' virtualhost = '.(($this->virtualhost !=
'') ?
"'".$this->db->escape($this->virtualhost).
"'" :
"null").
',';
543 $sql .=
' fk_user_modif = '.(!isset($this->fk_user_modif) ? $user->id : $this->fk_user_modif).
',';
544 $sql .=
' date_creation = '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
',';
545 $sql .=
' tms = '.(dol_strlen($this->date_modification) != 0 ?
"'".$this->db->idate($this->date_modification).
"'" :
"'".$this->db->idate(
dol_now()).
"'");
546 $sql .=
' WHERE rowid='.((int) $this->
id);
550 $resql = $this->db->query($sql);
553 $this->errors[] =
'Error '.$this->db->lasterror();
554 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
557 if (!$error && !$notrigger) {
562 $tmplangarray = explode(
',', $this->otherlang);
563 if (is_array($tmplangarray)) {
565 foreach ($tmplangarray as $val) {
566 if (trim($val) == $this->lang) {
569 dol_mkdir(
$conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
581 $this->db->rollback();
598 public function delete(
User $user, $notrigger = 0)
609 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'categorie_website_page';
610 $sql .=
' WHERE fk_website_page IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'website_page WHERE fk_website = '.((int) $this->
id).
')';
612 $resql = $this->db->query($sql);
615 $this->errors[] =
'Error '.$this->db->lasterror();
616 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
621 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
622 $sql .=
' WHERE fk_website = '.((int) $this->
id);
624 $resql = $this->db->query($sql);
627 $this->errors[] =
'Error '.$this->db->lasterror();
628 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
638 if (!$error && !empty($this->
ref)) {
639 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
646 $this->db->rollback();
665 global
$conf, $langs;
674 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
675 $sql .=
' WHERE fk_website = '.((int) $this->
id);
677 $resql = $this->db->query($sql);
680 $this->errors[] =
'Error '.$this->db->lasterror();
681 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
685 if (!$error && !empty($this->
ref)) {
686 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
692 $pathtomedias = DOL_DATA_ROOT.
'/medias';
693 $pathtomediasinwebsite = $pathofwebsite.
'/medias';
695 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
696 dol_mkdir(dirname($pathtomediasinwebsite));
697 $result = symlink($pathtomedias, $pathtomediasinwebsite);
699 $this->errors[] = $langs->trans(
"ErrorFailedToCreateSymLinkToMedias", $pathtomediasinwebsite, $pathtomedias);
707 $this->db->rollback();
729 global
$conf, $langs;
730 global $dolibarr_main_data_root;
739 if (empty($newref)) {
740 $this->error =
'ErrorBadParameter newref';
747 if (
$object->fetch(0, $newref) > 0) {
748 $this->error =
'ErrorNewRefIsAlreadyUsed';
757 $oldidforhome =
$object->fk_default_home;
760 $pathofwebsiteold = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($oldref);
761 $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($newref);
764 $fileindex = $pathofwebsitenew.
'/index.php';
776 $object->fk_user_creat = $user->id;
778 $object->status = self::STATUS_DRAFT;
780 $object->lang = substr($langs->defaultlang, 0, 2);
784 $object->context[
'createfromclone'] =
'createfromclone';
785 $result =
$object->create($user);
789 $this->errors =
$object->errors;
790 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
798 $pathtomedias = DOL_DATA_ROOT.
'/medias';
799 $pathtomediasinwebsite = $pathofwebsitenew.
'/medias';
801 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
802 dol_mkdir(dirname($pathtomediasinwebsite));
803 $result = symlink($pathtomedias, $pathtomediasinwebsite);
807 $pathofmediasjsold = DOL_DATA_ROOT.
'/medias/js/'.$oldref;
808 $pathofmediasjsnew = DOL_DATA_ROOT.
'/medias/js/'.$newref;
811 $pathofmediasimageold = DOL_DATA_ROOT.
'/medias/image/'.$oldref;
812 $pathofmediasimagenew = DOL_DATA_ROOT.
'/medias/image/'.$newref;
819 $listofpages = $objectpages->fetchAll($fromid);
820 foreach ($listofpages as $pageid => $objectpageold) {
822 $filetplold = $pathofwebsitenew.
'/page'.$pageid.
'.tpl.php';
826 $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl,
'', 0,
$object->id, 1);
829 if (is_object($objectpagenew) && $objectpagenew->pageurl) {
830 $filealias = $pathofwebsitenew.
'/'.$objectpagenew->pageurl.
'.php';
831 $filetplnew = $pathofwebsitenew.
'/page'.$objectpagenew->id.
'.tpl.php';
844 if ($pageid == $oldidforhome) {
845 $newidforhome = $objectpagenew->id;
856 $object->fk_default_home = $newidforhome;
864 $filetpl = $pathofwebsitenew.
'/page'.$newidforhome.
'.tpl.php';
865 $filewrapper = $pathofwebsitenew.
'/wrapper.php';
873 unset(
$object->context[
'createfromclone']);
881 $this->db->rollback();
898 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
904 $label =
'<u>'.img_picto(
'',
'website',
'class="pictofixedwidth"').$langs->trans(
"WebSite").
'</u>';
906 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
907 $label .=
'<b>'.$langs->trans(
'MainLanguage').
':</b> '.$this->lang;
915 if (!empty($this->virtualhost)) {
916 $linkstart =
'<a target="_blank" rel="noopener" href="'.$this->virtualhost.
'">';
919 $linkstart = $linkend =
'';
922 $result .= $linkstart;
924 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'),
'class="pictofixedwidth'.($notooltip ?
'' :
' classfortooltip').
'"');
926 $result .= $this->ref;
956 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
959 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
960 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
961 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
962 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
965 $statusType =
'status5';
966 if ($status == self::STATUS_VALIDATED) {
967 $statusType =
'status4';
970 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
987 $this->
ref =
'myspecimenwebsite';
990 $this->otherlang =
'fr,es';
992 $this->fk_default_home = 0;
993 $this->virtualhost =
'http://myvirtualhost';
994 $this->fk_user_creat = $user->id;
995 $this->fk_user_modif = $user->id;
996 $this->date_creation =
dol_now();
1010 global
$conf, $mysoc;
1014 if (empty($website->id) || empty($website->ref)) {
1021 if (!is_writable(
$conf->website->dir_temp)) {
1026 $destdir =
$conf->website->dir_temp.
'/'.$website->ref;
1029 $countreallydeleted = 0;
1031 if ($counttodelete != $countreallydeleted) {
1032 setEventMessages(
"Failed to clean temp directory ".$destdir,
null,
'errors');
1036 $arrayreplacementinfilename = array();
1037 $arrayreplacementincss = array();
1038 $arrayreplacementincss[
'file=image/'.$website->ref.
'/'] =
"file=image/__WEBSITE_KEY__/";
1039 $arrayreplacementincss[
'file=js/'.$website->ref.
'/'] =
"file=js/__WEBSITE_KEY__/";
1040 $arrayreplacementincss[
'medias/image/'.$website->ref.
'/'] =
"medias/image/__WEBSITE_KEY__/";
1041 $arrayreplacementincss[
'medias/js/'.$website->ref.
'/'] =
"medias/js/__WEBSITE_KEY__/";
1042 if ($mysoc->logo_small) {
1043 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_small] =
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__";
1045 if ($mysoc->logo_mini) {
1046 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini] =
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__";
1049 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo] =
"file=logos%2Fthumbs%2F__LOGO_KEY__";
1054 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers');
1055 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey');
1056 dol_mkdir(
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey');
1059 $srcdir =
$conf->website->dir_output.
'/'.$website->ref;
1060 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers';
1062 dol_syslog(
"Copy pages from ".$srcdir.
" into ".$destdir);
1063 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename, 2, array(
'old',
'back'), 1);
1066 if (
dol_is_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md')) {
1067 dol_copy(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md',
$conf->website->dir_temp.
'/'.$website->ref.
'/README.md');
1069 if (
dol_is_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE')) {
1070 dol_copy(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE',
$conf->website->dir_temp.
'/'.$website->ref.
'/LICENSE');
1074 $srcdir = DOL_DATA_ROOT.
'/medias/image/'.$website->ref;
1075 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey';
1077 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1078 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename);
1081 $srcdir = DOL_DATA_ROOT.
'/medias/js/'.$website->ref;
1082 $destdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey';
1084 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1085 dolCopyDir($srcdir, $destdir,
'0', 1, $arrayreplacementinfilename);
1088 $cssindestdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/styles.css.php';
1093 $htmldeaderindestdir =
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/htmlheader.html';
1099 $filesql =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_pages.sql';
1100 $fp = fopen($filesql,
"w");
1107 $listofpages = $objectpages->fetchAll($website->id);
1112 foreach ($listofpages as $pageid => $objectpageold) {
1113 $objectpageold->newid = $i;
1117 foreach ($listofpages as $pageid => $objectpageold) {
1120 foreach ($listofpages as $pageid2 => $objectpageold2) {
1121 if ($pageid2 == $objectpageold->fk_page) {
1122 $newfk_page = $objectpageold2->newid;
1126 $objectpageold->newfk_page = $newfk_page;
1130 $line =
'-- File generated by Dolibarr '.DOL_VERSION.
' --;'.
"\n";
1134 foreach ($listofpages as $pageid => $objectpageold) {
1135 $oldpageid = $objectpageold->id;
1137 $allaliases = $objectpageold->pageurl;
1138 $allaliases .= ($objectpageold->aliasalt ?
','.$objectpageold->aliasalt :
'');
1143 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/page'.$objectpageold->id.
'.tpl.php', 0, 0, 0,
null,
false, 0);
1145 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1146 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1148 $arrayofaliases = explode(
',', $objectpageold->aliasalt);
1149 foreach ($arrayofaliases as $tmpaliasalt) {
1150 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1151 dol_delete_file(
$conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1156 $line =
'-- Page ID '.$objectpageold->newid.
'__+MAX_llx_website_page__ - Aliases '.$allaliases.
' --;';
1161 $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)';
1162 $line .=
" VALUES(";
1163 $line .= $objectpageold->newid.
"__+MAX_llx_website_page__, ";
1164 $line .= ($objectpageold->newfk_page ? $this->db->escape($objectpageold->newfk_page).
"__+MAX_llx_website_page__" :
"null").
", ";
1165 $line .=
"__WEBSITE_ID__, ";
1166 $line .=
"'".$this->db->escape($objectpageold->pageurl).
"', ";
1167 $line .=
"'".$this->db->escape($objectpageold->aliasalt).
"', ";
1168 $line .=
"'".$this->db->escape($objectpageold->title).
"', ";
1169 $line .=
"'".$this->db->escape($objectpageold->description).
"', ";
1170 $line .=
"'".$this->db->escape($objectpageold->lang).
"', ";
1171 $line .=
"'".$this->db->escape($objectpageold->image).
"', ";
1172 $line .=
"'".$this->db->escape($objectpageold->keywords).
"', ";
1173 $line .=
"'".$this->db->escape($objectpageold->status).
"', ";
1174 $line .=
"'".$this->db->idate($objectpageold->date_creation).
"', ";
1175 $line .=
"'".$this->db->idate($objectpageold->date_modification).
"', ";
1176 $line .= ($objectpageold->import_key ?
"'".$this->db->escape($objectpageold->import_key).
"'" :
"null").
", ";
1177 $line .=
"'".$this->db->escape($objectpageold->grabbed_from).
"', ";
1178 $line .=
"'".$this->db->escape($objectpageold->type_container).
"', ";
1181 $stringtoexport = $objectpageold->htmlheader;
1182 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1183 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1184 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1185 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1186 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1188 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1189 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1190 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1191 $line .=
"'".$this->db->escape(str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport)).
"', ";
1194 $stringtoexport = $objectpageold->content;
1195 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1196 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1197 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1198 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1199 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1200 $stringtoexport = str_replace(
'"image/'.$website->ref.
'/',
'"image/__WEBSITE_KEY__/', $stringtoexport);
1201 $stringtoexport = str_replace(
'"/image/'.$website->ref.
'/',
'"/image/__WEBSITE_KEY__/', $stringtoexport);
1202 $stringtoexport = str_replace(
'"js/'.$website->ref.
'/',
'"js/__WEBSITE_KEY__/', $stringtoexport);
1203 $stringtoexport = str_replace(
'"/js/'.$website->ref.
'/',
'"/js/__WEBSITE_KEY__/', $stringtoexport);
1205 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1206 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1207 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1210 $line .=
"'".$this->db->escape($stringtoexport).
"', ";
1211 $line .=
"'".$this->db->escape($objectpageold->author_alias).
"', ";
1212 $line .= (int) $objectpageold->allowed_in_frames;
1220 if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) {
1222 $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__;";
1230 $line =
"\n-- For Dolibarr v14+ --;\n";
1231 $line .=
"UPDATE llx_website SET lang = '".$this->db->escape($this->lang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1232 $line .=
"UPDATE llx_website SET otherlang = '".$this->db->escape($this->otherlang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1241 $filedir =
$conf->website->dir_temp.
'/'.$website->ref.
'/.';
1242 $fileglob =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-*.zip';
1243 $filename =
$conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-'.
dol_print_date(
dol_now(),
'dayhourlog').
'-V'.((float) DOL_VERSION).
'.zip';
1247 $result = dol_compress_dir($filedir, $filename,
'zip');
1253 $this->error = $errormsg;
1265 public function importWebSite($pathtofile)
1267 global
$conf, $mysoc;
1274 $this->error =
'Function importWebSite called on object not loaded (object->ref is empty)';
1281 $filename = basename($pathtofile);
1283 if (!preg_match(
'/^website_(.*)-(.*)$/', $filename, $reg)) {
1284 $this->errors[] =
'Bad format for filename '.$filename.
'. Must be website_XXX-VERSION.';
1291 if (!empty($result[
'error'])) {
1292 $this->errors[] =
'Failed to unzip file '.$pathtofile;
1296 $arrayreplacement = array();
1297 $arrayreplacement[
'__WEBSITE_ID__'] =
$object->id;
1298 $arrayreplacement[
'__WEBSITE_KEY__'] =
$object->ref;
1299 $arrayreplacement[
'__N__'] = $this->db->escape(
"\n");
1300 $arrayreplacement[
'__LOGO_SMALL_KEY__'] = $this->db->escape($mysoc->logo_small);
1301 $arrayreplacement[
'__LOGO_MINI_KEY__'] = $this->db->escape($mysoc->logo_mini);
1302 $arrayreplacement[
'__LOGO_KEY__'] = $this->db->escape($mysoc->logo);
1309 $cssindestdir =
$conf->website->dir_output.
'/'.
$object->ref.
'/styles.css.php';
1312 $htmldeaderindestdir =
$conf->website->dir_output.
'/'.
$object->ref.
'/htmlheader.html';
1316 $filemaster =
$conf->website->dir_output.
'/'.
$object->ref.
'/master.inc.php';
1319 $this->errors[] =
'Failed to write file '.$filemaster;
1327 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/image/'.
$object->ref.
'.';
1329 $this->errors[] = $this->error;
1338 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/js/'.
$object->ref.
'.';
1340 $this->errors[] = $this->error;
1345 $sqlfile =
$conf->website->dir_temp.
"/".
$object->ref.
'/website_pages.sql';
1352 $sqlgetrowid =
'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.
'website_page';
1353 $resql = $this->db->query($sqlgetrowid);
1355 $obj = $this->db->fetch_object($resql);
1356 $maxrowid = $obj->max;
1360 $runsql =
run_sql($sqlfile, 1, 0, 0,
'',
'none', 0, 1, 0, 0, 1);
1362 $this->errors[] =
'Failed to load sql file '.$sqlfile.
' (ret='.((int) $runsql).
')';
1369 $fp = fopen($sqlfile,
"r");
1371 while (!feof($fp)) {
1375 $buf = fgets($fp, 65000);
1379 if (preg_match(
'/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.+)\s--;/i', $buf, $reg)) {
1381 $oldid = (int) $reg[1];
1382 $newid = ((int) $reg[2] + $maxrowid);
1383 $aliasesarray = explode(
',', $reg[3]);
1385 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]);
1388 } elseif (preg_match(
'/^-- Page ID (\d+).*Aliases\s(.*)\s--;/i', $buf, $reg)) {
1390 $newid = ((int) $reg[1] + $maxrowid);
1391 $aliasesarray = explode(
',', $reg[2]);
1393 dol_syslog(
"In sql source file, we have the page with the new ID ".$newid.
", and we must create the shortcut aliases: ".$reg[2]);
1397 $objectpagestatic->fetch($newid);
1400 $filetpl =
$conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1403 $this->errors[] =
'Failed to write file '.basename($filetpl);
1408 if (is_array($aliasesarray)) {
1409 foreach ($aliasesarray as $aliasshortcuttocreate) {
1410 if (trim($aliasshortcuttocreate)) {
1411 $filealias =
$conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1414 $this->errors[] =
'Failed to write file '.basename($filealias);
1426 $sql =
"SELECT fk_default_home FROM ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int)
$object->id);
1427 $resql = $this->db->query($sql);
1429 $obj = $this->db->fetch_object($resql);
1431 $object->fk_default_home = $obj->fk_default_home;
1439 $pathofwebsite =
$conf->website->dir_output.
'/'.
$object->ref;
1440 dolSaveIndexPage($pathofwebsite, $pathofwebsite.
'/index.php', $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php', $pathofwebsite.
'/wrapper.php',
$object);
1445 $this->db->rollback();
1448 $this->db->commit();
1467 $this->error =
'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)';
1473 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $this->
id);
1475 $resql = $this->db->query($sql);
1477 $this->error = $this->db->lasterror();
1481 $num = $this->db->num_rows($resql);
1486 $obj = $this->db->fetch_object($resql);
1488 $newid = $obj->rowid;
1490 $objectpagestatic->fetch($newid);
1492 $aliasesarray = explode(
',', $objectpagestatic->aliasalt);
1494 $filetpl =
$conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1497 $this->errors[] =
'Failed to write file '.basename($filetpl);
1502 if (!empty($objectpagestatic->pageurl) && !in_array($objectpagestatic->pageurl, $aliasesarray)) {
1503 $aliasesarray[] = $objectpagestatic->pageurl;
1507 if (is_array($aliasesarray)) {
1508 foreach ($aliasesarray as $aliasshortcuttocreate) {
1509 if (trim($aliasshortcuttocreate)) {
1510 $filealias =
$conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1513 $this->errors[] =
'Failed to write file '.basename($filealias);
1525 $pathofwebsite =
$conf->website->dir_output.
'/'.
$object->ref;
1526 $fileindex = $pathofwebsite.
'/index.php';
1528 if (
$object->fk_default_home > 0) {
1529 $filetpl = $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php';
1531 $filewrapper = $pathofwebsite.
'/wrapper.php';
1536 $filecacheglob =
$conf->website->dir_output.
'/temp/'.
$object->ref.
'-*.php.cache';
1553 return !empty($this->otherlang);
1567 global $websitepagefile, $website;
1568 '@phan-var-force Website $website';
1570 if (!is_object($weblangs)) {
1571 return 'ERROR componentSelectLang called with parameter $weblangs not defined';
1574 $arrayofspecialmainlanguages = array(
1605 if (!empty($websitepagefile)) {
1606 $websitepagefileshort = basename($websitepagefile);
1607 if ($websitepagefileshort ==
'index.php') {
1608 $pageid = $website->fk_default_home;
1610 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), $websitepagefileshort);
1613 $tmppage->fetch($pageid);
1618 if (!is_array($languagecodes) && $pageid > 0) {
1619 $languagecodes = array();
1621 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
1622 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
1623 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
1624 $sql .=
" AND (wp.fk_page = ".((int) $pageid).
" OR wp.rowid = ".((int) $pageid);
1625 if ($tmppage->fk_page > 0) {
1626 $sql .=
" OR wp.fk_page = ".((int) $tmppage->fk_page).
" OR wp.rowid = ".((int) $tmppage->fk_page);
1630 $resql = $this->db->query($sql);
1632 while ($obj = $this->db->fetch_object($resql)) {
1633 $newlang = $obj->lang;
1634 if ($obj->rowid == $pageid) {
1635 $newlang = $obj->lang;
1637 if (!in_array($newlang, $languagecodes)) {
1638 $languagecodes[] = $newlang;
1645 $languagecodeselected = substr($weblangs->defaultlang, 0, 2);
1646 if (!empty($websitepagefile)) {
1647 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
1649 $pagelang = substr($tmppage->lang, 0, 2);
1650 $languagecodeselected = substr($pagelang, 0, 2);
1651 if (!in_array($pagelang, $languagecodes)) {
1652 $languagecodes[] = $pagelang;
1657 $weblangs->load(
'languages');
1660 $url = $_SERVER[
"REQUEST_URI"];
1661 $url = preg_replace(
'/(\?|&)l=([a-zA-Z_]*)/',
'', $url);
1663 $url .= (preg_match(
'/\?/', $url) ?
'&' :
'?').
'l=';
1664 if (!preg_match(
'/^\//', $url)) {
1669 $MAXHEIGHT = 4 * $HEIGHTOPTION;
1670 $nboflanguage = count($languagecodes);
1672 $out =
'<!-- componentSelectLang'.$htmlname.
' -->'.
"\n";
1675 $out .=
'.componentSelectLang'.$htmlname.
':hover { height: '.min($MAXHEIGHT, ($HEIGHTOPTION * $nboflanguage)).
'px; overflow-x: hidden; overflow-y: '.((($HEIGHTOPTION * $nboflanguage) > $MAXHEIGHT) ?
' scroll' :
'hidden').
'; }'.
"\n";
1676 $out .=
'.componentSelectLang'.$htmlname.
' li { line-height: '.$HEIGHTOPTION.
'px; }'.
"\n";
1677 $out .=
'.componentSelectLang'.$htmlname.
' {
1678 display: inline-block;
1680 height: '.$HEIGHTOPTION.
'px;
1682 transition: all .3s ease;
1684 vertical-align: top;
1686 .componentSelectLang'.$htmlname.
':hover, .componentSelectLang'.$htmlname.
':hover a { background-color: #fff; color: #000 !important; }
1687 ul.componentSelectLang'.$htmlname.
' { width: 150px; }
1688 ul.componentSelectLang'.$htmlname.
':hover .fa { visibility: hidden; }
1689 .componentSelectLang'.$htmlname.
' a { text-decoration: none; width: 100%; }
1690 .componentSelectLang'.$htmlname.
' li { display: block; padding: 0px 15px; margin-left: 0; margin-right: 0; }
1691 .componentSelectLang'.$htmlname.
' li:hover { background-color: #EEE; }
1694 $out .=
'<ul class="componentSelectLang'.$htmlname.($morecss ?
' '.$morecss :
'').
'">';
1696 if ($languagecodeselected) {
1698 if (strlen($languagecodeselected) == 2) {
1699 $languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.
'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
1702 $countrycode = strtolower(substr($languagecodeselected, -2));
1703 $label = $weblangs->trans(
"Language_".$languagecodeselected);
1704 if ($countrycode ==
'us') {
1705 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1707 $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>';
1708 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1709 $out .=
'</a></li>';
1712 if (is_array($languagecodes)) {
1713 foreach ($languagecodes as $languagecode) {
1715 if (strlen($languagecode) == 2) {
1716 $languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.
'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
1719 if ($languagecode == $languagecodeselected) {
1723 $countrycode = strtolower(substr($languagecode, -2));
1724 $label = $weblangs->trans(
"Language_".$languagecode);
1725 if ($countrycode ==
'us') {
1726 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1728 $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>';
1729 if (empty($i) && empty($languagecodeselected)) {
1730 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1732 $out .=
'</a></li>';
1755 if (empty($website->id) || empty($website->ref)) {
1759 if (empty($website->name_template) && empty($exportPath)) {
1760 setEventMessages(
"To export the website template into a directory of the server, the name of the directory/template must be provided.",
null,
'errors');
1763 if (!is_writable(
$conf->website->dir_temp)) {
1771 if (empty($exportPath)) {
1772 $destdirrel =
'install/doctemplates/websites/'.$website->name_template;
1773 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1775 $exportPath = rtrim($exportPath,
'/');
1776 if (strpos($exportPath,
'..') !==
false) {
1781 if (strpos($exportPath,
'/') === 0 || preg_match(
'/^[a-zA-Z]:/', $exportPath)) {
1782 if (!is_dir($exportPath)) {
1783 setEventMessages(
"The specified absolute path does not exist.",
null,
'errors');
1787 if (!is_writable($exportPath)) {
1788 setEventMessages(
"The specified absolute path is not writable.",
null,
'errors');
1791 $destdirrel = $exportPath;
1792 $destdir = $exportPath;
1795 $destdirrel =
'install/doctemplates/websites/'.$exportPath;
1796 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1803 if (!is_writable($destdir)) {
1804 setEventMessages(
"The specified path ".$destdir.
" is not writable.",
null,
'errors');
1812 if (
dol_is_file($destdir.
'/containers/README.md')) {
1813 dol_move($destdir.
'/containers/README.md', $destdir.
'/README.md',
'0', 1, 0, 0);
1815 if (
dol_is_file($destdir.
'/containers/LICENSE')) {
1816 dol_move($destdir.
'/containers/LICENSE', $destdir.
'/LICENSE',
'0', 1, 0, 0);
1832 if (!empty($resultarray)) {
1833 setEventMessages(
"Error, failed to unzip the export into target dir ".$destdir.
": ".implode(
',', $resultarray),
null,
'errors');
1835 setEventMessages(
"Website content written into ".$destdirrel,
null,
'mesgs');
1838 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?website='.$website->ref);
1850 if (preg_match(
'/page(\d+)\.tpl\.php/', $filename, $matches)) {
1851 return (
int) $matches[1];
1865 $sql =
"UPDATE ".$this->db->prefix().
"website SET";
1866 $sql .=
" name_template = '".$this->db->escape($name_template).
"'";
1867 $sql .=
" WHERE rowid = ".(int) $this->
id;
1868 $result = $this->db->query($sql);
1871 $this->db->commit();
1874 $this->db->rollback();
1886 if (!file_exists($pathname)) {
1887 if (touch($pathname)) {
1892 return unserialize(file_get_contents($pathname));
1904 return file_put_contents($pathname, serialize($etat));
1917 $fichiersSource = [];
1918 $fichiersDestination = [];
1920 $fichierWithNoPage = [];
1921 $fichierWithNoPageInDest = [];
1924 foreach (
dol_dir_list($dossierSource,
"files") as $file) {
1925 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1926 $fichiersSource[] = $file;
1928 $fichierWithNoPage[] = $file;
1933 foreach (
dol_dir_list($dossierDestination,
"all", 1) as $file) {
1934 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1935 $fichiersDestination[] = $file;
1937 $fichierWithNoPageInDest[] = $file;
1942 $numOfPageSource = 0;
1943 foreach ($fichiersSource as $index => $file) {
1944 if ($file[
'name'] == basename($fichierModifie[
'fullname'])) {
1951 $filesFound = array();
1952 foreach ($fichierWithNoPage as $filesource) {
1953 $fileContent = file_get_contents($filesource[
'fullname']);
1954 if (strpos($fileContent,
"require './page".$numOfPageSource.
".tpl.php'") !==
false) {
1955 $filesFound = $filesource;
1960 $numPagesFound =
'';
1961 foreach ($fichierWithNoPageInDest as $filedest) {
1962 if ($filedest[
'name'] === $filesFound[
'name']) {
1963 $fileContent = file_get_contents($filedest[
'fullname']);
1964 if (preg_match(
"/page\d+\.tpl\.php/", $fileContent, $matches)) {
1965 $numPagesFound = $matches[0];
1971 $fileNeeded = array();
1972 foreach ($fichiersDestination as $index => $file) {
1973 if ($file[
'name'] == $numPagesFound) {
1974 $fileNeeded = $file;
1979 if (isset($fileNeeded)) {
1980 $sourceContent = file_get_contents($fichierModifie[
'fullname']);
1981 if (file_exists($fileNeeded[
'fullname'])) {
1982 $destContent = file_get_contents($fileNeeded[
'fullname']);
1985 $differences = $this->
showDifferences($destContent, $sourceContent, array($numOfPageDest,$numOfPageSource));
1986 $differences[
'file_destination'] = $fileNeeded;
1988 $differences = array();
1990 return $differences;
2002 $str = str_replace(
"\r\n",
"\n", $str);
2003 $str = str_replace(
"\r",
"\n", $str);
2020 $lines1 = explode(
"\n", $str1);
2021 $lines2 = explode(
"\n", $str2);
2023 $linesShouldChange = array();
2024 $linesShouldNotChange = array();
2025 $linefound = array();
2026 $countNumPage = count($exceptNumPge);
2028 for ($i = 0;$i < $countNumPage; $i++) {
2029 $linefound[$i] = array();
2030 $linefound[$i][
'meta'] =
'/content="' . preg_quote((
string) $exceptNumPge[$i],
'/') .
'" \/>/';
2031 $linefound[$i][
'output'] =
'/dolWebsiteOutput\(\$tmp, "html", ' . preg_quote((
string) $exceptNumPge[$i],
'/') .
'\);/';
2034 if (isset($linefound[1])) {
2035 $maxLines = max(count($lines1), count($lines2));
2036 for ($lineNum = 0; $lineNum < $maxLines; $lineNum++) {
2037 $lineContent1 = $lines1[$lineNum] ??
'';
2038 $lineContent2 = $lines2[$lineNum] ??
'';
2039 if (preg_match($linefound[0][
'output'], $lineContent1)) {
2040 $linesShouldChange[] = $lineContent1;
2042 if (preg_match($linefound[0][
'meta'], $lineContent1)) {
2043 $linesShouldChange[] = $lineContent1;
2045 if (preg_match($linefound[1][
'output'], $lineContent2)) {
2046 $linesShouldNotChange[] = $lineContent2;
2048 if (preg_match($linefound[1][
'meta'], $lineContent2)) {
2049 $linesShouldNotChange[] = $lineContent2;
2051 if ($lineContent1 !== $lineContent2) {
2052 if (isset($lines1[$lineNum]) && !isset($lines2[$lineNum])) {
2054 $diff[
"Supprimée à la ligne " . ($lineNum + 1)] = $lineContent1;
2055 } elseif (!isset($lines1[$lineNum]) && isset($lines2[$lineNum])) {
2057 $diff[
"Ajoutée à la ligne " . ($lineNum + 1)] = $lineContent2;
2060 $diff[
"Modifiée à la ligne " . ($lineNum + 1)] = $lineContent2;
2067 if (empty($linesShouldChange)) {
2068 $linesShouldChange[0] =
'<meta name="dolibarr:pageid" content="'.$exceptNumPge[0].
'" />';
2069 $linesShouldChange[1] =
'$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$exceptNumPge[0].
');';
2072 $replacementMapping = array();
2073 if (!empty($linesShouldNotChange)) {
2075 foreach ($linesShouldNotChange as $numLigne => $ligneRemplacement) {
2076 if (isset($linesShouldChange[$numLigne])) {
2077 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$numLigne];
2079 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$i];
2083 $diff[
'lignes_dont_change'] = $replacementMapping;
2086 $pattern =
'/medias\/image\/'.preg_quote($this->
ref,
'/').
'\/([^\'"\s]+)/';
2088 foreach ($diff as $key => $value) {
2090 if (is_string($value)) {
2091 if (preg_match($pattern, $value)) {
2092 $newValue = preg_replace($pattern,
'medias/image/'.$this->name_template.
'/$1', $value);
2093 $diff[$key] = $newValue;
2109 if (file_exists($inplaceFile)) {
2112 if (!is_writable($inplaceFile)) {
2116 unset($differences[
'file_destination']);
2117 $contentDest = file($inplaceFile, FILE_IGNORE_NEW_LINES);
2118 foreach ($differences as $key => $ligneSource) {
2120 if (preg_match(
'/(Ajoutée|Modifiée) à la ligne (\d+)/', $key, $matches)) {
2121 $typeModification = $matches[1];
2122 $numLigne = (int) $matches[2] - 1;
2124 if ($typeModification ===
'Ajoutée') {
2125 array_splice($contentDest, $numLigne, 0, $ligneSource);
2126 } elseif ($typeModification ===
'Modifiée') {
2127 $contentDest[$numLigne] = $ligneSource;
2129 } elseif (preg_match(
'/Supprimée à la ligne (\d+)/', $key, $matches)) {
2130 $numLigne = (int) $matches[1] - 1;
2131 unset($contentDest[$numLigne]);
2135 $contentDest = array_values($contentDest);
2136 $stringreplacement = implode(
"\n", $contentDest);
2137 file_put_contents($inplaceFile, $stringreplacement);
2138 foreach ($differences[
'lignes_dont_change'] as $linechanged => $line) {
2139 if (in_array($linechanged, $contentDest)) {
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
isMultiLang()
Return if web site is a multilanguage web site.
setTemplateName($name_template)
update name_template in table after import template
create(User $user, $notrigger=0)
Create object into database.
rebuildWebSiteFiles()
Rebuild all files of all the pages/containers of a website.
exportWebSite()
Generate a zip with all data of web site.
replaceLineUsingNum($inplaceFile, $differences)
Replace line by line in file using numbers of the lines.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
componentSelectLang($languagecodes, $weblangs, $morecss='', $htmlname='')
Component to select language inside a container (Full CSS Only)
extractNumberFromFilename($filename)
extract num of page
createFromClone($user, $fromid, $newref, $newlang='')
Load a website its id and create a new one in database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load all object in memory ($this->records) from the database.
overwriteTemplate(string $pathtotmpzip, $exportPath='')
Overite template by copying all files.
__construct(DoliDB $db)
Constructor.
saveState($etat, $pathname)
Save state for File.
getLibStatut($mode=0)
Return the label of the status.
LibStatut($status, $mode=0)
Return the label of a given status.
purge(User $user)
Purge website Delete website directory content and all pages and medias.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='')
Return a link to the user card (with optionally the picto) Use this->id,this->lastname,...
normalizeString($str)
Remove spaces in string.
update(User $user, $notrigger=0)
Update object into database.
fetch($id, $ref=null)
Load object in memory from the database.
compareFichierModifie($dossierSource, $dossierDestination, $fichierModifie)
Compare two files has not same name but same content.
showDifferences($str1, $str2, $exceptNumPge=array())
show difference between to string
checkPreviousState($pathname)
check previous state for file
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask='0', $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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, $includequotes=0)
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).