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 $date_creation;
95 public $date_modification;
100 public $fk_default_home;
105 public $fk_user_creat;
110 public $fk_user_modif;
120 public $use_manifest;
130 public $name_template;
132 const STATUS_DRAFT = 0;
133 const STATUS_VALIDATED = 1;
145 $this->ismultientitymanaged = 1;
157 global $conf, $langs;
165 if (isset($this->entity)) {
166 $this->entity = (int) $this->entity;
168 if (isset($this->
ref)) {
169 $this->
ref = trim($this->
ref);
174 if (isset($this->
status)) {
177 if (empty($this->date_creation)) {
178 $this->date_creation = $now;
180 if (empty($this->date_modification)) {
181 $this->date_modification = $now;
184 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
185 $tmparray = explode(
',', $this->otherlang);
186 if (is_array($tmparray)) {
187 foreach ($tmparray as $key => $val) {
189 if (empty(trim($val))) {
190 unset($tmparray[$key]);
193 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
195 $this->otherlang = implode(
',', $tmparray);
199 if (empty($this->entity)) {
200 $this->entity = $conf->entity;
202 if (empty($this->lang)) {
203 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
208 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
211 $sql .=
'description,';
213 $sql .=
'otherlang,';
215 $sql .=
'fk_default_home,';
216 $sql .=
'virtualhost,';
217 $sql .=
'fk_user_creat,';
218 $sql .=
'date_creation,';
221 $sql .=
') VALUES (';
222 $sql .=
' '.((empty($this->entity) && $this->entity !=
'0') ?
'NULL' : $this->entity).
',';
223 $sql .=
' '.(!isset($this->
ref) ?
'NULL' :
"'".$this->db->escape($this->
ref).
"'").
',';
225 $sql .=
' '.(!isset($this->lang) ?
'NULL' :
"'".$this->db->escape($this->lang).
"'").
',';
226 $sql .=
' '.(!isset($this->otherlang) ?
'NULL' :
"'".$this->db->escape($this->otherlang).
"'").
',';
227 $sql .=
' '.(!isset($this->
status) ?
'1' : $this->status).
',';
228 $sql .=
' '.(!isset($this->fk_default_home) ?
'NULL' : $this->fk_default_home).
',';
229 $sql .=
' '.(!isset($this->virtualhost) ?
'NULL' :
"'".$this->db->escape($this->virtualhost).
"'").
",";
230 $sql .=
' '.(!isset($this->fk_user_creat) ? $user->id : $this->fk_user_creat).
',';
231 $sql .=
' '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_creation).
"'").
",";
232 $sql .=
' '.((int) $this->
position).
",";
233 $sql .=
' '.(!isset($this->date_modification) ||
dol_strlen($this->date_modification) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_modification).
"'");
238 $resql = $this->db->query($sql);
241 $this->errors[] =
'Error '.$this->db->lasterror();
242 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
246 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
249 $tmplangarray = explode(
',', $this->otherlang);
250 if (is_array($tmplangarray)) {
251 dol_mkdir($conf->website->dir_output.
'/'.$this->ref);
252 foreach ($tmplangarray as $val) {
253 if (trim($val) == $this->lang) {
256 dol_mkdir($conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val), DOL_DATA_ROOT);
261 dol_mkdir($conf->medias->multidir_output[$conf->entity].
'/image/'.$this->ref, DOL_DATA_ROOT);
262 dol_mkdir($conf->medias->multidir_output[$conf->entity].
'/js/'.$this->ref, DOL_DATA_ROOT);
276 $stringtodolibarrfile =
"# Some properties for Dolibarr web site CMS\n";
277 $stringtodolibarrfile .=
"param=value\n";
279 file_put_contents($conf->website->dir_output.
'/'.$this->ref.
'/.dolibarr', $stringtodolibarrfile);
284 $this->db->rollback();
285 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
304 public function fetch($id, $ref =
null)
310 $sql .=
" t.entity,";
312 $sql .=
" t.position,";
313 $sql .=
" t.description,";
315 $sql .=
" t.otherlang,";
316 $sql .=
" t.status,";
317 $sql .=
" t.fk_default_home,";
318 $sql .=
" t.use_manifest,";
319 $sql .=
" t.virtualhost,";
320 $sql .=
" t.fk_user_creat,";
321 $sql .=
" t.fk_user_modif,";
322 $sql .=
" t.date_creation,";
323 $sql .=
" t.tms as date_modification,";
324 $sql .=
" t.name_template";
325 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
326 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
328 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
330 $sql .=
" AND t.rowid = ".(int) $id;
333 $resql = $this->db->query($sql);
335 $numrows = $this->db->num_rows($resql);
337 $obj = $this->db->fetch_object($resql);
339 $this->
id = $obj->rowid;
341 $this->entity = $obj->entity;
342 $this->
ref = $obj->ref;
345 $this->lang = $obj->lang;
346 $this->otherlang = $obj->otherlang;
347 $this->
status = $obj->status;
348 $this->fk_default_home = $obj->fk_default_home;
349 $this->virtualhost = $obj->virtualhost;
350 $this->use_manifest = $obj->use_manifest;
351 $this->fk_user_creat = $obj->fk_user_creat;
352 $this->fk_user_modif = $obj->fk_user_modif;
353 $this->date_creation = $this->db->jdate($obj->date_creation);
354 $this->date_modification = $this->db->jdate($obj->date_modification);
355 $this->name_template = $obj->name_template;
357 $this->db->free($resql);
365 $this->errors[] =
'Error '.$this->db->lasterror();
366 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
384 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
392 $sql .=
" t.entity,";
394 $sql .=
" t.description,";
396 $sql .=
" t.otherlang,";
397 $sql .=
" t.status,";
398 $sql .=
" t.fk_default_home,";
399 $sql .=
" t.virtualhost,";
400 $sql .=
" t.fk_user_creat,";
401 $sql .=
" t.fk_user_modif,";
402 $sql .=
" t.date_creation,";
403 $sql .=
" t.tms as date_modification";
404 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
405 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
408 if (is_array($filter)) {
410 if (count($filter) > 0) {
411 foreach ($filter as $key => $value) {
412 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
415 if (count($sqlwhere) > 0) {
416 $sql .=
' AND '.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere);
426 $this->errors[] = $errormessage;
427 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
431 if (!empty($sortfield)) {
432 $sql .= $this->db->order($sortfield, $sortorder);
434 if (!empty($limit)) {
435 $sql .= $this->db->plimit($limit, $offset);
438 $resql = $this->db->query($sql);
440 $num = $this->db->num_rows($resql);
442 while ($obj = $this->db->fetch_object($resql)) {
443 $record =
new self($this->db);
445 $record->id = $obj->rowid;
447 $record->entity = $obj->entity;
448 $record->ref = $obj->ref;
449 $record->description = $obj->description;
450 $record->lang = $obj->lang;
451 $record->otherlang = $obj->otherlang;
452 $record->status = $obj->status;
453 $record->fk_default_home = $obj->fk_default_home;
454 $record->virtualhost = $obj->virtualhost;
455 $record->fk_user_creat = $obj->fk_user_creat;
456 $record->fk_user_modif = $obj->fk_user_modif;
457 $record->date_creation = $this->db->jdate($obj->date_creation);
458 $record->date_modification = $this->db->jdate($obj->date_modification);
460 $records[$record->id] = $record;
462 $this->db->free($resql);
466 $this->errors[] =
'Error '.$this->db->lasterror();
467 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
482 global $conf, $langs;
490 if (isset($this->entity)) {
491 $this->entity = (int) $this->entity;
493 if (isset($this->
ref)) {
494 $this->
ref = trim($this->
ref);
499 if (isset($this->
status)) {
504 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
505 $tmparray = explode(
',', $this->otherlang);
506 if (is_array($tmparray)) {
507 foreach ($tmparray as $key => $val) {
509 if (empty(trim($val))) {
510 unset($tmparray[$key]);
513 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
515 $this->otherlang = implode(
',', $tmparray);
517 if (empty($this->lang)) {
518 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
526 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
527 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
528 $sql .=
' ref = '.(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
',';
529 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
530 $sql .=
' lang = '.(isset($this->lang) ?
"'".$this->db->escape($this->lang).
"'" :
"null").
',';
531 $sql .=
' otherlang = '.(isset($this->otherlang) ?
"'".$this->db->escape($this->otherlang).
"'" :
"null").
',';
532 $sql .=
' status = '.(isset($this->
status) ? $this->
status :
"null").
',';
533 $sql .=
' fk_default_home = '.(($this->fk_default_home > 0) ? $this->fk_default_home :
"null").
',';
534 $sql .=
' use_manifest = '.((int) $this->use_manifest).
',';
535 $sql .=
' virtualhost = '.(($this->virtualhost !=
'') ?
"'".$this->db->escape($this->virtualhost).
"'" :
"null").
',';
536 $sql .=
' fk_user_modif = '.(!isset($this->fk_user_modif) ? $user->id : $this->fk_user_modif).
',';
537 $sql .=
' date_creation = '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
',';
538 $sql .=
' tms = '.(dol_strlen($this->date_modification) != 0 ?
"'".$this->db->idate($this->date_modification).
"'" :
"'".$this->db->idate(
dol_now()).
"'");
539 $sql .=
' WHERE rowid='.((int) $this->
id);
543 $resql = $this->db->query($sql);
546 $this->errors[] =
'Error '.$this->db->lasterror();
547 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
550 if (!$error && !$notrigger) {
555 $tmplangarray = explode(
',', $this->otherlang);
556 if (is_array($tmplangarray)) {
557 dol_mkdir($conf->website->dir_output.
'/'.$this->ref);
558 foreach ($tmplangarray as $val) {
559 if (trim($val) == $this->lang) {
562 dol_mkdir($conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
574 $this->db->rollback();
591 public function delete(
User $user, $notrigger = 0)
602 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'categorie_website_page';
603 $sql .=
' WHERE fk_website_page IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'website_page WHERE fk_website = '.((int) $this->
id).
')';
605 $resql = $this->db->query($sql);
608 $this->errors[] =
'Error '.$this->db->lasterror();
609 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
614 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'website_page';
615 $sql .=
' WHERE fk_website = '.((int) $this->
id);
617 $resql = $this->db->query($sql);
620 $this->errors[] =
'Error '.$this->db->lasterror();
621 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
631 if (!$error && !empty($this->
ref)) {
632 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
639 $this->db->rollback();
661 global $conf, $langs;
662 global $dolibarr_main_data_root;
671 if (empty($newref)) {
672 $this->error =
'ErrorBadParameter newref';
679 if (
$object->fetch(0, $newref) > 0) {
680 $this->error =
'ErrorNewRefIsAlreadyUsed';
689 $oldidforhome =
$object->fk_default_home;
692 $pathofwebsiteold = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($oldref);
693 $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($newref);
696 $fileindex = $pathofwebsitenew.
'/index.php';
708 $object->fk_user_creat = $user->id;
710 $object->status = self::STATUS_DRAFT;
712 $object->lang = substr($langs->defaultlang, 0, 2);
716 $object->context[
'createfromclone'] =
'createfromclone';
717 $result =
$object->create($user);
721 $this->errors =
$object->errors;
722 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
730 $pathtomedias = DOL_DATA_ROOT.
'/medias';
731 $pathtomediasinwebsite = $pathofwebsitenew.
'/medias';
733 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
734 dol_mkdir(dirname($pathtomediasinwebsite));
735 $result = symlink($pathtomedias, $pathtomediasinwebsite);
739 $pathofmediasjsold = DOL_DATA_ROOT.
'/medias/js/'.$oldref;
740 $pathofmediasjsnew = DOL_DATA_ROOT.
'/medias/js/'.$newref;
743 $pathofmediasimageold = DOL_DATA_ROOT.
'/medias/image/'.$oldref;
744 $pathofmediasimagenew = DOL_DATA_ROOT.
'/medias/image/'.$newref;
751 $listofpages = $objectpages->fetchAll($fromid);
752 foreach ($listofpages as $pageid => $objectpageold) {
754 $filetplold = $pathofwebsitenew.
'/page'.$pageid.
'.tpl.php';
758 $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl,
'', 0,
$object->id, 1);
761 if (is_object($objectpagenew) && $objectpagenew->pageurl) {
762 $filealias = $pathofwebsitenew.
'/'.$objectpagenew->pageurl.
'.php';
763 $filetplnew = $pathofwebsitenew.
'/page'.$objectpagenew->id.
'.tpl.php';
776 if ($pageid == $oldidforhome) {
777 $newidforhome = $objectpagenew->id;
788 $object->fk_default_home = $newidforhome;
796 $filetpl = $pathofwebsitenew.
'/page'.$newidforhome.
'.tpl.php';
797 $filewrapper = $pathofwebsitenew.
'/wrapper.php';
805 unset(
$object->context[
'createfromclone']);
813 $this->db->rollback();
830 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
836 $label =
'<u>'.$langs->trans(
"WebSite").
'</u>';
838 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
839 $label .=
'<b>'.$langs->trans(
'MainLanguage').
':</b> '.$this->lang;
841 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/website/card.php?id='.$this->
id.
'"';
842 $linkstart .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
846 $linkstart = $linkend =
'';
849 $result .= ($linkstart.img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
850 if ($withpicto != 2) {
854 $result .= $linkstart.$this->ref.$linkend;
882 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
885 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
886 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
887 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Offline');
888 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Online');
891 $statusType =
'status5';
892 if ($status == self::STATUS_VALIDATED) {
893 $statusType =
'status4';
896 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
913 $this->
ref =
'myspecimenwebsite';
916 $this->otherlang =
'fr,es';
918 $this->fk_default_home = 0;
919 $this->virtualhost =
'http://myvirtualhost';
920 $this->fk_user_creat = $user->id;
921 $this->fk_user_modif = $user->id;
922 $this->date_creation =
dol_now();
936 global $conf, $mysoc;
940 if (empty($website->id) || empty($website->ref)) {
945 dol_syslog(
"Create temp dir ".$conf->website->dir_temp);
947 if (!is_writable($conf->website->dir_temp)) {
948 setEventMessages(
"Temporary dir ".$conf->website->dir_temp.
" is not writable",
null,
'errors');
952 $destdir = $conf->website->dir_temp.
'/'.$website->ref;
955 $countreallydeleted = 0;
957 if ($counttodelete != $countreallydeleted) {
958 setEventMessages(
"Failed to clean temp directory ".$destdir,
null,
'errors');
962 $arrayreplacementinfilename = array();
963 $arrayreplacementincss = array();
964 $arrayreplacementincss[
'file=image/'.$website->ref.
'/'] =
"file=image/__WEBSITE_KEY__/";
965 $arrayreplacementincss[
'file=js/'.$website->ref.
'/'] =
"file=js/__WEBSITE_KEY__/";
966 $arrayreplacementincss[
'medias/image/'.$website->ref.
'/'] =
"medias/image/__WEBSITE_KEY__/";
967 $arrayreplacementincss[
'medias/js/'.$website->ref.
'/'] =
"medias/js/__WEBSITE_KEY__/";
968 if ($mysoc->logo_small) {
969 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_small] =
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__";
971 if ($mysoc->logo_mini) {
972 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini] =
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__";
975 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo] =
"file=logos%2Fthumbs%2F__LOGO_KEY__";
980 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/containers');
981 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey');
982 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey');
985 $srcdir = $conf->website->dir_output.
'/'.$website->ref;
986 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers';
988 dol_syslog(
"Copy pages from ".$srcdir.
" into ".$destdir);
989 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename, 2, array(
'old',
'back'), 1);
992 if (
dol_is_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md')) {
993 dol_copy($conf->website->dir_temp.
'/'.$website->ref.
'/containers/README.md', $conf->website->dir_temp.
'/'.$website->ref.
'/README.md');
995 if (
dol_is_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE')) {
996 dol_copy($conf->website->dir_temp.
'/'.$website->ref.
'/containers/LICENSE', $conf->website->dir_temp.
'/'.$website->ref.
'/LICENSE');
1000 $srcdir = DOL_DATA_ROOT.
'/medias/image/'.$website->ref;
1001 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey';
1003 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1004 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename);
1007 $srcdir = DOL_DATA_ROOT.
'/medias/js/'.$website->ref;
1008 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey';
1010 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
1011 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename);
1014 $cssindestdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers/styles.css.php';
1019 $htmldeaderindestdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers/htmlheader.html';
1025 $filesql = $conf->website->dir_temp.
'/'.$website->ref.
'/website_pages.sql';
1026 $fp = fopen($filesql,
"w");
1033 $listofpages = $objectpages->fetchAll($website->id);
1038 foreach ($listofpages as $pageid => $objectpageold) {
1039 $objectpageold->newid = $i;
1043 foreach ($listofpages as $pageid => $objectpageold) {
1046 foreach ($listofpages as $pageid2 => $objectpageold2) {
1047 if ($pageid2 == $objectpageold->fk_page) {
1048 $newfk_page = $objectpageold2->newid;
1052 $objectpageold->newfk_page = $newfk_page;
1056 $line =
'-- File generated by Dolibarr '.DOL_VERSION.
' --;'.
"\n";
1060 foreach ($listofpages as $pageid => $objectpageold) {
1061 $oldpageid = $objectpageold->id;
1063 $allaliases = $objectpageold->pageurl;
1064 $allaliases .= ($objectpageold->aliasalt ?
','.$objectpageold->aliasalt :
'');
1069 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/page'.$objectpageold->id.
'.tpl.php', 0, 0, 0,
null,
false, 0);
1071 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1072 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.$objectpageold->pageurl.
'.php', 0, 0, 0,
null,
false, 0);
1074 $arrayofaliases = explode(
',', $objectpageold->aliasalt);
1075 foreach ($arrayofaliases as $tmpaliasalt) {
1076 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1077 dol_delete_file($conf->website->dir_temp.
'/'.$website->ref.
'/containers/*/'.trim($tmpaliasalt).
'.php', 0, 0, 0,
null,
false, 0);
1082 $line =
'-- Page ID '.$objectpageold->newid.
'__+MAX_llx_website_page__ - Aliases '.$allaliases.
' --;';
1087 $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)';
1088 $line .=
" VALUES(";
1089 $line .= $objectpageold->newid.
"__+MAX_llx_website_page__, ";
1090 $line .= ($objectpageold->newfk_page ? $this->db->escape($objectpageold->newfk_page).
"__+MAX_llx_website_page__" :
"null").
", ";
1091 $line .=
"__WEBSITE_ID__, ";
1092 $line .=
"'".$this->db->escape($objectpageold->pageurl).
"', ";
1093 $line .=
"'".$this->db->escape($objectpageold->aliasalt).
"', ";
1094 $line .=
"'".$this->db->escape($objectpageold->title).
"', ";
1095 $line .=
"'".$this->db->escape($objectpageold->description).
"', ";
1096 $line .=
"'".$this->db->escape($objectpageold->lang).
"', ";
1097 $line .=
"'".$this->db->escape($objectpageold->image).
"', ";
1098 $line .=
"'".$this->db->escape($objectpageold->keywords).
"', ";
1099 $line .=
"'".$this->db->escape($objectpageold->status).
"', ";
1100 $line .=
"'".$this->db->idate($objectpageold->date_creation).
"', ";
1101 $line .=
"'".$this->db->idate($objectpageold->date_modification).
"', ";
1102 $line .= ($objectpageold->import_key ?
"'".$this->db->escape($objectpageold->import_key).
"'" :
"null").
", ";
1103 $line .=
"'".$this->db->escape($objectpageold->grabbed_from).
"', ";
1104 $line .=
"'".$this->db->escape($objectpageold->type_container).
"', ";
1107 $stringtoexport = $objectpageold->htmlheader;
1108 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1109 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1110 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1111 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1112 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1114 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1115 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1116 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1117 $line .=
"'".$this->db->escape(str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport)).
"', ";
1120 $stringtoexport = $objectpageold->content;
1121 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1122 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1123 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1124 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1125 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1126 $stringtoexport = str_replace(
'"image/'.$website->ref.
'/',
'"image/__WEBSITE_KEY__/', $stringtoexport);
1127 $stringtoexport = str_replace(
'"/image/'.$website->ref.
'/',
'"/image/__WEBSITE_KEY__/', $stringtoexport);
1128 $stringtoexport = str_replace(
'"js/'.$website->ref.
'/',
'"js/__WEBSITE_KEY__/', $stringtoexport);
1129 $stringtoexport = str_replace(
'"/js/'.$website->ref.
'/',
'"/js/__WEBSITE_KEY__/', $stringtoexport);
1131 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1132 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1133 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1136 $line .=
"'".$this->db->escape($stringtoexport).
"', ";
1137 $line .=
"'".$this->db->escape($objectpageold->author_alias).
"', ";
1138 $line .= (int) $objectpageold->allowed_in_frames;
1146 if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) {
1148 $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__;";
1156 $line =
"\n-- For Dolibarr v14+ --;\n";
1157 $line .=
"UPDATE llx_website SET lang = '".$this->db->escape($this->lang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1158 $line .=
"UPDATE llx_website SET otherlang = '".$this->db->escape($this->otherlang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1167 $filedir = $conf->website->dir_temp.
'/'.$website->ref.
'/.';
1168 $fileglob = $conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-*.zip';
1169 $filename = $conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-'.
dol_print_date(
dol_now(),
'dayhourlog').
'-V'.((float) DOL_VERSION).
'.zip';
1173 $result = dol_compress_dir($filedir, $filename,
'zip');
1179 $this->error = $errormsg;
1191 public function importWebSite($pathtofile)
1193 global $conf, $mysoc;
1200 $this->error =
'Function importWebSite called on object not loaded (object->ref is empty)';
1207 $filename = basename($pathtofile);
1208 if (!preg_match(
'/^website_(.*)-(.*)$/', $filename, $reg)) {
1209 $this->errors[] =
'Bad format for filename '.$filename.
'. Must be website_XXX-VERSION.';
1215 if (!empty($result[
'error'])) {
1216 $this->errors[] =
'Failed to unzip file '.$pathtofile.
'.';
1220 $arrayreplacement = array();
1221 $arrayreplacement[
'__WEBSITE_ID__'] =
$object->id;
1222 $arrayreplacement[
'__WEBSITE_KEY__'] =
$object->ref;
1223 $arrayreplacement[
'__N__'] = $this->db->escape(
"\n");
1224 $arrayreplacement[
'__LOGO_SMALL_KEY__'] = $this->db->escape($mysoc->logo_small);
1225 $arrayreplacement[
'__LOGO_MINI_KEY__'] = $this->db->escape($mysoc->logo_mini);
1226 $arrayreplacement[
'__LOGO_KEY__'] = $this->db->escape($mysoc->logo);
1230 dolCopyDir($conf->website->dir_temp.
'/'.
$object->ref.
'/containers', $conf->website->dir_output.
'/'.
$object->ref, 0, 1);
1233 $cssindestdir = $conf->website->dir_output.
'/'.
$object->ref.
'/styles.css.php';
1236 $htmldeaderindestdir = $conf->website->dir_output.
'/'.
$object->ref.
'/htmlheader.html';
1240 $filemaster = $conf->website->dir_output.
'/'.
$object->ref.
'/master.inc.php';
1243 $this->errors[] =
'Failed to write file '.$filemaster;
1248 if (
dol_is_dir($conf->website->dir_temp.
'/'.
$object->ref.
'/medias/image/websitekey')) {
1249 $result =
dolCopyDir($conf->website->dir_temp.
'/'.
$object->ref.
'/medias/image/websitekey', $conf->website->dir_output.
'/'.
$object->ref.
'/medias/image/'.
$object->ref, 0, 1);
1251 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/image/'.
$object->ref.
'.';
1253 $this->errors[] = $this->error;
1259 if (
dol_is_dir($conf->website->dir_temp.
'/'.
$object->ref.
'/medias/js/websitekey')) {
1260 $result =
dolCopyDir($conf->website->dir_temp.
'/'.
$object->ref.
'/medias/js/websitekey', $conf->website->dir_output.
'/'.
$object->ref.
'/medias/js/'.
$object->ref, 0, 1);
1262 $this->error =
'Failed to copy files into '.$conf->website->dir_output.
'/'.
$object->ref.
'/medias/js/'.
$object->ref.
'.';
1264 $this->errors[] = $this->error;
1269 $sqlfile = $conf->website->dir_temp.
"/".
$object->ref.
'/website_pages.sql';
1276 $sqlgetrowid =
'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.
'website_page';
1277 $resql = $this->db->query($sqlgetrowid);
1279 $obj = $this->db->fetch_object($resql);
1280 $maxrowid = $obj->max;
1284 $runsql =
run_sql($sqlfile, 1,
'', 0,
'',
'none', 0, 1, 0, 0, 1);
1286 $this->errors[] =
'Failed to load sql file '.$sqlfile.
' (ret='.((int) $runsql).
')';
1293 $fp = fopen($sqlfile,
"r");
1295 while (!feof($fp)) {
1299 $buf = fgets($fp, 65000);
1303 if (preg_match(
'/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.+)\s--;/i', $buf, $reg)) {
1305 $oldid = (int) $reg[1];
1306 $newid = ((int) $reg[2] + $maxrowid);
1307 $aliasesarray = explode(
',', $reg[3]);
1309 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]);
1312 } elseif (preg_match(
'/^-- Page ID (\d+).*Aliases\s(.*)\s--;/i', $buf, $reg)) {
1314 $newid = ((int) $reg[1] + $maxrowid);
1315 $aliasesarray = explode(
',', $reg[2]);
1317 dol_syslog(
"In sql source file, we have the page with the new ID ".$newid.
", and we must create the shortcut aliases: ".$reg[2]);
1321 $objectpagestatic->fetch($newid);
1324 $filetpl = $conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1327 $this->errors[] =
'Failed to write file '.basename($filetpl);
1332 if (is_array($aliasesarray)) {
1333 foreach ($aliasesarray as $aliasshortcuttocreate) {
1334 if (trim($aliasshortcuttocreate)) {
1335 $filealias = $conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1338 $this->errors[] =
'Failed to write file '.basename($filealias);
1350 $sql =
"SELECT fk_default_home FROM ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int)
$object->id);
1351 $resql = $this->db->query($sql);
1353 $obj = $this->db->fetch_object($resql);
1355 $object->fk_default_home = $obj->fk_default_home;
1363 $pathofwebsite = $conf->website->dir_output.
'/'.
$object->ref;
1364 dolSaveIndexPage($pathofwebsite, $pathofwebsite.
'/index.php', $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php', $pathofwebsite.
'/wrapper.php',
$object);
1369 $this->db->rollback();
1372 $this->db->commit();
1391 $this->error =
'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)';
1397 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $this->
id);
1399 $resql = $this->db->query($sql);
1401 $this->error = $this->db->lasterror();
1405 $num = $this->db->num_rows($resql);
1410 $obj = $this->db->fetch_object($resql);
1412 $newid = $obj->rowid;
1414 $objectpagestatic->fetch($newid);
1416 $aliasesarray = explode(
',', $objectpagestatic->aliasalt);
1418 $filetpl = $conf->website->dir_output.
'/'.
$object->ref.
'/page'.$newid.
'.tpl.php';
1421 $this->errors[] =
'Failed to write file '.basename($filetpl);
1426 if (!empty($objectpagestatic->pageurl) && !in_array($objectpagestatic->pageurl, $aliasesarray)) {
1427 $aliasesarray[] = $objectpagestatic->pageurl;
1431 if (is_array($aliasesarray)) {
1432 foreach ($aliasesarray as $aliasshortcuttocreate) {
1433 if (trim($aliasshortcuttocreate)) {
1434 $filealias = $conf->website->dir_output.
'/'.
$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1437 $this->errors[] =
'Failed to write file '.basename($filealias);
1449 $pathofwebsite = $conf->website->dir_output.
'/'.
$object->ref;
1450 $fileindex = $pathofwebsite.
'/index.php';
1452 if (
$object->fk_default_home > 0) {
1453 $filetpl = $pathofwebsite.
'/page'.
$object->fk_default_home.
'.tpl.php';
1455 $filewrapper = $pathofwebsite.
'/wrapper.php';
1473 return !empty($this->otherlang);
1487 global $websitepagefile, $website;
1489 if (!is_object($weblangs)) {
1490 return 'ERROR componentSelectLang called with parameter $weblangs not defined';
1493 $arrayofspecialmainlanguages = array(
1524 if (!empty($websitepagefile)) {
1525 $websitepagefileshort = basename($websitepagefile);
1526 if ($websitepagefileshort ==
'index.php') {
1527 $pageid = $website->fk_default_home;
1529 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), $websitepagefileshort);
1532 $tmppage->fetch($pageid);
1537 if (!is_array($languagecodes) && $pageid > 0) {
1538 $languagecodes = array();
1540 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
1541 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
1542 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
1543 $sql .=
" AND (wp.fk_page = ".((int) $pageid).
" OR wp.rowid = ".((int) $pageid);
1544 if ($tmppage->fk_page > 0) {
1545 $sql .=
" OR wp.fk_page = ".((int) $tmppage->fk_page).
" OR wp.rowid = ".((int) $tmppage->fk_page);
1549 $resql = $this->db->query($sql);
1551 while ($obj = $this->db->fetch_object($resql)) {
1552 $newlang = $obj->lang;
1553 if ($obj->rowid == $pageid) {
1554 $newlang = $obj->lang;
1556 if (!in_array($newlang, $languagecodes)) {
1557 $languagecodes[] = $newlang;
1564 $languagecodeselected = substr($weblangs->defaultlang, 0, 2);
1565 if (!empty($websitepagefile)) {
1566 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
1568 $pagelang = substr($tmppage->lang, 0, 2);
1569 $languagecodeselected = substr($pagelang, 0, 2);
1570 if (!in_array($pagelang, $languagecodes)) {
1571 $languagecodes[] = $pagelang;
1576 $weblangs->load(
'languages');
1579 $url = $_SERVER[
"REQUEST_URI"];
1580 $url = preg_replace(
'/(\?|&)l=([a-zA-Z_]*)/',
'', $url);
1582 $url .= (preg_match(
'/\?/', $url) ?
'&' :
'?').
'l=';
1583 if (!preg_match(
'/^\//', $url)) {
1588 $MAXHEIGHT = 4 * $HEIGHTOPTION;
1589 $nboflanguage = count($languagecodes);
1591 $out =
'<!-- componentSelectLang'.$htmlname.
' -->'.
"\n";
1594 $out .=
'.componentSelectLang'.$htmlname.
':hover { height: '.min($MAXHEIGHT, ($HEIGHTOPTION * $nboflanguage)).
'px; overflow-x: hidden; overflow-y: '.((($HEIGHTOPTION * $nboflanguage) > $MAXHEIGHT) ?
' scroll' :
'hidden').
'; }'.
"\n";
1595 $out .=
'.componentSelectLang'.$htmlname.
' li { line-height: '.$HEIGHTOPTION.
'px; }'.
"\n";
1596 $out .=
'.componentSelectLang'.$htmlname.
' {
1597 display: inline-block;
1599 height: '.$HEIGHTOPTION.
'px;
1601 transition: all .3s ease;
1603 vertical-align: top;
1605 .componentSelectLang'.$htmlname.
':hover, .componentSelectLang'.$htmlname.
':hover a { background-color: #fff; color: #000 !important; }
1606 ul.componentSelectLang'.$htmlname.
' { width: 150px; }
1607 ul.componentSelectLang'.$htmlname.
':hover .fa { visibility: hidden; }
1608 .componentSelectLang'.$htmlname.
' a { text-decoration: none; width: 100%; }
1609 .componentSelectLang'.$htmlname.
' li { display: block; padding: 0px 15px; margin-left: 0; margin-right: 0; }
1610 .componentSelectLang'.$htmlname.
' li:hover { background-color: #EEE; }
1613 $out .=
'<ul class="componentSelectLang'.$htmlname.($morecss ?
' '.$morecss :
'').
'">';
1615 if ($languagecodeselected) {
1617 if (strlen($languagecodeselected) == 2) {
1618 $languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.
'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
1621 $countrycode = strtolower(substr($languagecodeselected, -2));
1622 $label = $weblangs->trans(
"Language_".$languagecodeselected);
1623 if ($countrycode ==
'us') {
1624 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1626 $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>';
1627 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1628 $out .=
'</a></li>';
1631 if (is_array($languagecodes)) {
1632 foreach ($languagecodes as $languagecode) {
1634 if (strlen($languagecode) == 2) {
1635 $languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.
'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
1638 if ($languagecode == $languagecodeselected) {
1642 $countrycode = strtolower(substr($languagecode, -2));
1643 $label = $weblangs->trans(
"Language_".$languagecode);
1644 if ($countrycode ==
'us') {
1645 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1647 $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>';
1648 if (empty($i) && empty($languagecodeselected)) {
1649 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1651 $out .=
'</a></li>';
1674 if (empty($website->id) || empty($website->ref)) {
1678 if (empty($website->name_template) && empty($exportPath)) {
1679 setEventMessages(
"To export the website template into a directory of the server, the name of the directory/template must be provided.",
null,
'errors');
1682 if (!is_writable($conf->website->dir_temp)) {
1683 setEventMessages(
"Temporary dir ".$conf->website->dir_temp.
" is not writable",
null,
'errors');
1690 if (empty($exportPath)) {
1691 $destdirrel =
'install/doctemplates/websites/'.$website->name_template;
1692 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1694 $exportPath = rtrim($exportPath,
'/');
1695 if (strpos($exportPath,
'..') !==
false) {
1700 if (strpos($exportPath,
'/') === 0 || preg_match(
'/^[a-zA-Z]:/', $exportPath)) {
1701 if (!is_dir($exportPath)) {
1702 setEventMessages(
"The specified absolute path does not exist.",
null,
'errors');
1706 if (!is_writable($exportPath)) {
1707 setEventMessages(
"The specified absolute path is not writable.",
null,
'errors');
1710 $destdirrel = $exportPath;
1711 $destdir = $exportPath;
1714 $destdirrel =
'install/doctemplates/websites/'.$exportPath;
1715 $destdir = DOL_DOCUMENT_ROOT.
'/'.$destdirrel;
1722 if (!is_writable($destdir)) {
1723 setEventMessages(
"The specified path ".$destdir.
" is not writable.",
null,
'errors');
1731 if (
dol_is_file($destdir.
'/containers/README.md')) {
1732 dol_move($destdir.
'/containers/README.md', $destdir.
'/README.md',
'0', 1, 0, 0);
1734 if (
dol_is_file($destdir.
'/containers/LICENSE')) {
1735 dol_move($destdir.
'/containers/LICENSE', $destdir.
'/LICENSE',
'0', 1, 0, 0);
1751 if (!empty($resultarray)) {
1752 setEventMessages(
"Error, failed to unzip the export into target dir ".$destdir.
": ".implode(
',', $resultarray),
null,
'errors');
1754 setEventMessages(
"Website content written into ".$destdirrel,
null,
'mesgs');
1757 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?website='.$website->ref);
1769 if (preg_match(
'/page(\d+)\.tpl\.php/', $filename, $matches)) {
1770 return (
int) $matches[1];
1782 $sql =
"UPDATE ".$this->db->prefix().
"website SET";
1783 $sql .=
" name_template = '".$this->db->escape($name_template).
"'";
1784 $sql .=
" WHERE rowid = ".(int) $this->
id;
1785 $result = $this->db->query($sql);
1788 $this->db->commit();
1791 $this->db->rollback();
1803 if (!file_exists($pathname)) {
1804 if (touch($pathname)) {
1809 return unserialize(file_get_contents($pathname));
1821 return file_put_contents($pathname, serialize($etat));
1834 $fichiersSource = [];
1835 $fichiersDestination = [];
1837 $fichierWithNoPage = [];
1838 $fichierWithNoPageInDest = [];
1841 foreach (
dol_dir_list($dossierSource,
"files") as $file) {
1842 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1843 $fichiersSource[] = $file;
1845 $fichierWithNoPage[] = $file;
1850 foreach (
dol_dir_list($dossierDestination,
"all", 1) as $file) {
1851 if (preg_match(
'/^page\d+/', $file[
'name']) && !str_contains($file[
'name'],
'.old')) {
1852 $fichiersDestination[] = $file;
1854 $fichierWithNoPageInDest[] = $file;
1859 $numOfPageSource = 0;
1860 foreach ($fichiersSource as $index => $file) {
1861 if ($file[
'name'] == basename($fichierModifie[
'fullname'])) {
1868 $filesFound = array();
1869 foreach ($fichierWithNoPage as $filesource) {
1870 $fileContent = file_get_contents($filesource[
'fullname']);
1871 if (strpos($fileContent,
"require './page".$numOfPageSource.
".tpl.php'") !==
false) {
1872 $filesFound = $filesource;
1877 $numPagesFound =
'';
1878 foreach ($fichierWithNoPageInDest as $filedest) {
1879 if ($filedest[
'name'] === $filesFound[
'name']) {
1880 $fileContent = file_get_contents($filedest[
'fullname']);
1881 if (preg_match(
"/page\d+\.tpl\.php/", $fileContent, $matches)) {
1882 $numPagesFound = $matches[0];
1888 $fileNeeded = array();
1889 foreach ($fichiersDestination as $index => $file) {
1890 if ($file[
'name'] == $numPagesFound) {
1891 $fileNeeded = $file;
1896 if (isset($fileNeeded)) {
1897 $sourceContent = file_get_contents($fichierModifie[
'fullname']);
1898 if (file_exists($fileNeeded[
'fullname'])) {
1899 $destContent = file_get_contents($fileNeeded[
'fullname']);
1902 $differences = $this->
showDifferences($destContent, $sourceContent, array($numOfPageDest,$numOfPageSource));
1903 $differences[
'file_destination'] = $fileNeeded;
1905 $differences = array();
1907 return $differences;
1919 $str = str_replace(
"\r\n",
"\n", $str);
1920 $str = str_replace(
"\r",
"\n", $str);
1937 $lines1 = explode(
"\n", $str1);
1938 $lines2 = explode(
"\n", $str2);
1940 $linesShouldChange = array();
1941 $linesShouldNotChange = array();
1942 $linefound = array();
1943 $countNumPage = count($exceptNumPge);
1945 for ($i = 0;$i < $countNumPage; $i++) {
1946 $linefound[$i] = array();
1947 $linefound[$i][
'meta'] =
'/content="' . preg_quote($exceptNumPge[$i],
'/') .
'" \/>/';
1948 $linefound[$i][
'output'] =
'/dolWebsiteOutput\(\$tmp, "html", ' . preg_quote($exceptNumPge[$i],
'/') .
'\);/';
1951 if (isset($linefound[1])) {
1952 $maxLines = max(count($lines1), count($lines2));
1953 for ($lineNum = 0; $lineNum < $maxLines; $lineNum++) {
1954 $lineContent1 = $lines1[$lineNum] ??
'';
1955 $lineContent2 = $lines2[$lineNum] ??
'';
1956 if (preg_match($linefound[0][
'output'], $lineContent1)) {
1957 $linesShouldChange[] = $lineContent1;
1959 if (preg_match($linefound[0][
'meta'], $lineContent1)) {
1960 $linesShouldChange[] = $lineContent1;
1962 if (preg_match($linefound[1][
'output'], $lineContent2)) {
1963 $linesShouldNotChange[] = $lineContent2;
1965 if (preg_match($linefound[1][
'meta'], $lineContent2)) {
1966 $linesShouldNotChange[] = $lineContent2;
1968 if ($lineContent1 !== $lineContent2) {
1969 if (isset($lines1[$lineNum]) && !isset($lines2[$lineNum])) {
1971 $diff[
"Supprimée à la ligne " . ($lineNum + 1)] = $lineContent1;
1972 } elseif (!isset($lines1[$lineNum]) && isset($lines2[$lineNum])) {
1974 $diff[
"Ajoutée à la ligne " . ($lineNum + 1)] = $lineContent2;
1977 $diff[
"Modifiée à la ligne " . ($lineNum + 1)] = $lineContent2;
1984 if (empty($linesShouldChange)) {
1985 $linesShouldChange[0] =
'<meta name="dolibarr:pageid" content="'.$exceptNumPge[0].
'" />';
1986 $linesShouldChange[1] =
'$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp, "html", '.$exceptNumPge[0].
');';
1989 $replacementMapping = array();
1990 if (!empty($linesShouldNotChange)) {
1992 foreach ($linesShouldNotChange as $numLigne => $ligneRemplacement) {
1993 if (isset($linesShouldChange[$numLigne])) {
1994 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$numLigne];
1996 $replacementMapping[$ligneRemplacement] = $linesShouldChange[$i];
2000 $diff[
'lignes_dont_change'] = $replacementMapping;
2003 $pattern =
'/medias\/image\/'.preg_quote($this->
ref,
'/').
'\/([^\'"\s]+)/';
2005 foreach ($diff as $key => $value) {
2007 if (is_string($value)) {
2008 if (preg_match($pattern, $value)) {
2009 $newValue = preg_replace($pattern,
'medias/image/'.$this->name_template.
'/$1', $value);
2010 $diff[$key] = $newValue;
2026 if (file_exists($inplaceFile)) {
2029 if (!is_writable($inplaceFile)) {
2033 unset($differences[
'file_destination']);
2034 $contentDest = file($inplaceFile, FILE_IGNORE_NEW_LINES);
2035 foreach ($differences as $key => $ligneSource) {
2037 if (preg_match(
'/(Ajoutée|Modifiée) à la ligne (\d+)/', $key, $matches)) {
2038 $typeModification = $matches[1];
2039 $numLigne = (int) $matches[2] - 1;
2041 if ($typeModification ===
'Ajoutée') {
2042 array_splice($contentDest, $numLigne, 0, $ligneSource);
2043 } elseif ($typeModification ===
'Modifiée') {
2044 $contentDest[$numLigne] = $ligneSource;
2046 } elseif (preg_match(
'/Supprimée à la ligne (\d+)/', $key, $matches)) {
2047 $numLigne = (int) $matches[1] - 1;
2048 unset($contentDest[$numLigne]);
2052 $contentDest = array_values($contentDest);
2053 $stringreplacement = implode(
"\n", $contentDest);
2054 file_put_contents($inplaceFile, $stringreplacement);
2055 foreach ($differences[
'lignes_dont_change'] as $linechanged => $line) {
2056 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).