29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $element =
'website';
46 public $table_element =
'website';
51 public $ismultientitymanaged = 1;
56 public $picto =
'globe';
91 public $date_creation;
96 public $date_modification;
101 public $fk_default_home;
106 public $fk_user_creat;
116 public $use_manifest;
131 const STATUS_DRAFT = 0;
132 const STATUS_VALIDATED = 1;
156 global $conf, $langs;
164 if (isset($this->entity)) {
165 $this->entity = (int) $this->entity;
167 if (isset($this->
ref)) {
168 $this->
ref = trim($this->
ref);
173 if (isset($this->status)) {
174 $this->status = (int) $this->status;
176 if (empty($this->date_creation)) {
177 $this->date_creation = $now;
179 if (empty($this->date_modification)) {
180 $this->date_modification = $now;
183 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
184 $tmparray = explode(
',', $this->otherlang);
185 if (is_array($tmparray)) {
186 foreach ($tmparray as $key => $val) {
188 if (empty(trim($val))) {
189 unset($tmparray[$key]);
192 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
194 $this->otherlang = join(
',', $tmparray);
198 if (empty($this->entity)) {
199 $this->entity = $conf->entity;
201 if (empty($this->lang)) {
202 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
207 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'(';
210 $sql .=
'description,';
212 $sql .=
'otherlang,';
214 $sql .=
'fk_default_home,';
215 $sql .=
'virtualhost,';
216 $sql .=
'fk_user_creat,';
217 $sql .=
'date_creation,';
220 $sql .=
') VALUES (';
221 $sql .=
' '.((empty($this->entity) && $this->entity !=
'0') ?
'NULL' : $this->entity).
',';
222 $sql .=
' '.(!isset($this->
ref) ?
'NULL' :
"'".$this->db->escape($this->
ref).
"'").
',';
224 $sql .=
' '.(!isset($this->lang) ?
'NULL' :
"'".$this->db->escape($this->lang).
"'").
',';
225 $sql .=
' '.(!isset($this->otherlang) ?
'NULL' :
"'".$this->db->escape($this->otherlang).
"'").
',';
226 $sql .=
' '.(!isset($this->status) ?
'1' : $this->status).
',';
227 $sql .=
' '.(!isset($this->fk_default_home) ?
'NULL' : $this->fk_default_home).
',';
228 $sql .=
' '.(!isset($this->virtualhost) ?
'NULL' :
"'".$this->db->escape($this->virtualhost).
"'").
",";
229 $sql .=
' '.(!isset($this->fk_user_creat) ? $user->id : $this->fk_user_creat).
',';
230 $sql .=
' '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_creation).
"'").
",";
231 $sql .=
' '.((int) $this->position).
",";
232 $sql .=
' '.(!isset($this->date_modification) ||
dol_strlen($this->date_modification) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_modification).
"'");
240 $this->errors[] =
'Error '.$this->db->lasterror();
241 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
245 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
248 $tmplangarray = explode(
',', $this->otherlang);
249 if (is_array($tmplangarray)) {
250 dol_mkdir($conf->website->dir_output.
'/'.$this->ref);
251 foreach ($tmplangarray as $val) {
252 if (trim($val) == $this->lang) {
255 dol_mkdir($conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
271 $stringtodolibarrfile =
"# Some properties for Dolibarr web site CMS\n";
272 $stringtodolibarrfile .=
"param=value\n";
274 file_put_contents($conf->website->dir_output.
'/'.$this->ref.
'/.dolibarr', $stringtodolibarrfile);
279 $this->
db->rollback();
296 public function fetch($id, $ref =
null)
302 $sql .=
" t.entity,";
304 $sql .=
" t.position,";
305 $sql .=
" t.description,";
307 $sql .=
" t.otherlang,";
308 $sql .=
" t.status,";
309 $sql .=
" t.fk_default_home,";
310 $sql .=
" t.use_manifest,";
311 $sql .=
" t.virtualhost,";
312 $sql .=
" t.fk_user_creat,";
313 $sql .=
" t.fk_user_modif,";
314 $sql .=
" t.date_creation,";
315 $sql .=
" t.tms as date_modification";
316 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
317 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
319 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
321 $sql .=
" AND t.rowid = ".(int) $id;
326 $numrows = $this->
db->num_rows(
$resql);
328 $obj = $this->
db->fetch_object(
$resql);
330 $this->
id = $obj->rowid;
332 $this->entity = $obj->entity;
333 $this->
ref = $obj->ref;
334 $this->position = $obj->position;
336 $this->lang = $obj->lang;
337 $this->otherlang = $obj->otherlang;
338 $this->status = $obj->status;
339 $this->fk_default_home = $obj->fk_default_home;
340 $this->virtualhost = $obj->virtualhost;
341 $this->use_manifest = $obj->use_manifest;
342 $this->fk_user_creat = $obj->fk_user_creat;
343 $this->fk_user_modif = $obj->fk_user_modif;
344 $this->date_creation = $this->
db->jdate($obj->date_creation);
345 $this->date_modification = $this->
db->jdate($obj->date_modification);
360 $this->errors[] =
'Error '.$this->db->lasterror();
361 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
374 $this->lines = array();
378 return count($this->lines) ? 1 : 0;
394 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
400 $sql .=
" t.entity,";
402 $sql .=
" t.description,";
404 $sql .=
" t.otherlang,";
405 $sql .=
" t.status,";
406 $sql .=
" t.fk_default_home,";
407 $sql .=
" t.virtualhost,";
408 $sql .=
" t.fk_user_creat,";
409 $sql .=
" t.fk_user_modif,";
410 $sql .=
" t.date_creation,";
411 $sql .=
" t.tms as date_modification";
412 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
413 $sql .=
" WHERE t.entity IN (".getEntity(
'website').
")";
416 if (count($filter) > 0) {
417 foreach ($filter as $key => $value) {
418 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
421 if (count($sqlwhere) > 0) {
422 $sql .=
' AND '.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere);
425 if (!empty($sortfield)) {
426 $sql .= $this->
db->order($sortfield, $sortorder);
428 if (!empty($limit)) {
429 $sql .= $this->
db->plimit($limit, $offset);
431 $this->records = array();
437 while ($obj = $this->
db->fetch_object(
$resql)) {
438 $line =
new self($this->db);
440 $line->id = $obj->rowid;
442 $line->entity = $obj->entity;
443 $line->ref = $obj->ref;
444 $line->description = $obj->description;
445 $line->lang = $obj->lang;
446 $line->otherlang = $obj->otherlang;
447 $line->status = $obj->status;
448 $line->fk_default_home = $obj->fk_default_home;
449 $line->virtualhost = $obj->virtualhost;
450 $this->fk_user_creat = $obj->fk_user_creat;
451 $this->fk_user_modif = $obj->fk_user_modif;
452 $line->date_creation = $this->
db->jdate($obj->date_creation);
453 $line->date_modification = $this->
db->jdate($obj->date_modification);
455 $this->records[$line->id] = $line;
461 $this->errors[] =
'Error '.$this->db->lasterror();
462 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
478 global $conf, $langs;
486 if (isset($this->entity)) {
487 $this->entity = (int) $this->entity;
489 if (isset($this->
ref)) {
490 $this->
ref = trim($this->
ref);
495 if (isset($this->status)) {
496 $this->status = (int) $this->status;
500 $this->lang = preg_replace(
'/[_-].*$/',
'', trim($this->lang));
501 $tmparray = explode(
',', $this->otherlang);
502 if (is_array($tmparray)) {
503 foreach ($tmparray as $key => $val) {
505 if (empty(trim($val))) {
506 unset($tmparray[$key]);
509 $tmparray[$key] = preg_replace(
'/[_-].*$/',
'', trim($val));
511 $this->otherlang = join(
',', $tmparray);
513 if (empty($this->lang)) {
514 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MainLanguage"));
522 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
523 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
524 $sql .=
' ref = '.(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
',';
525 $sql .=
' description = '.(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
',';
526 $sql .=
' lang = '.(isset($this->lang) ?
"'".$this->db->escape($this->lang).
"'" :
"null").
',';
527 $sql .=
' otherlang = '.(isset($this->otherlang) ?
"'".$this->db->escape($this->otherlang).
"'" :
"null").
',';
528 $sql .=
' status = '.(isset($this->status) ? $this->status :
"null").
',';
529 $sql .=
' fk_default_home = '.(($this->fk_default_home > 0) ? $this->fk_default_home :
"null").
',';
530 $sql .=
' use_manifest = '.((int) $this->use_manifest).
',';
531 $sql .=
' virtualhost = '.(($this->virtualhost !=
'') ?
"'".$this->
db->escape($this->virtualhost).
"'" :
"null").
',';
532 $sql .=
' fk_user_modif = '.(!isset($this->fk_user_modif) ? $user->id : $this->fk_user_modif).
',';
533 $sql .=
' date_creation = '.(!isset($this->date_creation) ||
dol_strlen($this->date_creation) != 0 ?
"'".$this->db->idate($this->date_creation).
"'" :
'null').
',';
534 $sql .=
' tms = '.(dol_strlen($this->date_modification) != 0 ?
"'".$this->db->idate($this->date_modification).
"'" :
"'".$this->db->idate(
dol_now()).
"'");
535 $sql .=
' WHERE rowid='.((int) $this->
id);
542 $this->errors[] =
'Error '.$this->db->lasterror();
543 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
546 if (!$error && !$notrigger) {
551 $tmplangarray = explode(
',', $this->otherlang);
552 if (is_array($tmplangarray)) {
553 dol_mkdir($conf->website->dir_output.
'/'.$this->ref);
554 foreach ($tmplangarray as $val) {
555 if (trim($val) == $this->lang) {
558 dol_mkdir($conf->website->dir_output.
'/'.$this->ref.
'/'.trim($val));
570 $this->
db->rollback();
588 public function delete(
User $user, $notrigger =
false)
611 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
612 $sql .=
' WHERE rowid='.((int) $this->
id);
617 $this->errors[] =
'Error '.$this->db->lasterror();
618 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
622 if (!$error && !empty($this->
ref)) {
623 $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$this->
ref;
630 $this->
db->rollback();
652 global $conf, $langs;
653 global $dolibarr_main_data_root;
662 if (empty($newref)) {
663 $this->error =
'ErrorBadParameter';
667 $object =
new self($this->db);
670 if ($object->fetch(0, $newref) > 0) {
671 $this->error =
'ErrorNewRefIsAlreadyUsed';
678 $object->fetch($fromid);
680 $oldidforhome = $object->fk_default_home;
681 $oldref = $object->ref;
683 $pathofwebsiteold = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($oldref);
684 $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.
dol_sanitizeFileName($newref);
687 $fileindex = $pathofwebsitenew.
'/index.php';
691 unset($object->fk_user_creat);
692 unset($object->import_key);
695 $object->ref = $newref;
696 $object->fk_default_home = 0;
697 $object->virtualhost =
'';
698 $object->date_creation = $now;
699 $object->fk_user_creat = $user->id;
700 $object->position = ((int) $object->position) + 1;
701 $object->status = self::STATUS_DRAFT;
702 if (empty($object->lang)) {
703 $object->lang = substr($langs->defaultlang, 0, 2);
707 $object->context[
'createfromclone'] =
'createfromclone';
708 $result = $object->create($user);
711 $this->error = $object->error;
712 $this->errors = $object->errors;
713 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
717 dolCopyDir($pathofwebsiteold, $pathofwebsitenew, $conf->global->MAIN_UMASK, 0,
null, 2);
720 $pathtomedias = DOL_DATA_ROOT.
'/medias';
721 $pathtomediasinwebsite = $pathofwebsitenew.
'/medias';
723 dol_syslog(
"Create symlink for ".$pathtomedias.
" into name ".$pathtomediasinwebsite);
724 dol_mkdir(dirname($pathtomediasinwebsite));
725 $result = symlink($pathtomedias, $pathtomediasinwebsite);
729 $pathofmediasjsold = DOL_DATA_ROOT.
'/medias/js/'.$oldref;
730 $pathofmediasjsnew = DOL_DATA_ROOT.
'/medias/js/'.$newref;
731 dolCopyDir($pathofmediasjsold, $pathofmediasjsnew, $conf->global->MAIN_UMASK, 0);
733 $pathofmediasimageold = DOL_DATA_ROOT.
'/medias/image/'.$oldref;
734 $pathofmediasimagenew = DOL_DATA_ROOT.
'/medias/image/'.$newref;
735 dolCopyDir($pathofmediasimageold, $pathofmediasimagenew, $conf->global->MAIN_UMASK, 0);
741 $listofpages = $objectpages->fetchAll($fromid);
742 foreach ($listofpages as $pageid => $objectpageold) {
744 $filetplold = $pathofwebsitenew.
'/page'.$pageid.
'.tpl.php';
748 $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl,
'', 0, $object->id, 1);
751 if (is_object($objectpagenew) && $objectpagenew->pageurl) {
752 $filealias = $pathofwebsitenew.
'/'.$objectpagenew->pageurl.
'.php';
753 $filetplnew = $pathofwebsitenew.
'/page'.$objectpagenew->id.
'.tpl.php';
766 if ($pageid == $oldidforhome) {
767 $newidforhome = $objectpagenew->id;
778 $object->fk_default_home = $newidforhome;
779 $res = $object->update($user);
786 $filetpl = $pathofwebsitenew.
'/page'.$newidforhome.
'.tpl.php';
787 $filewrapper = $pathofwebsitenew.
'/wrapper.php';
791 $result =
dolSaveIndexPage($pathofwebsitenew, $fileindex, $filetpl, $filewrapper, $object);
795 unset($object->context[
'createfromclone']);
803 $this->
db->rollback();
820 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'')
822 global $langs, $conf, $db;
823 global $dolibarr_main_authentication, $dolibarr_main_demo;
830 $label =
'<u>'.$langs->trans(
"WebSite").
'</u>';
832 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
833 $label .=
'<b>'.$langs->trans(
'MainLanguage').
':</b> '.$this->lang;
835 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/website/card.php?id='.$this->
id.
'"';
836 $linkstart .= ($notooltip ?
'' :
' title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"');
840 $linkstart = $linkend =
'';
843 $result .= ($linkstart.img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ?
'' :
'class="classfortooltip"')).$linkend);
844 if ($withpicto != 2) {
848 $result .= $linkstart.$this->ref.$linkend;
860 return $this->
LibStatut($this->status, $mode);
876 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
879 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Disabled');
880 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
881 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Disabled');
882 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
885 $statusType =
'status5';
886 if ($status == self::STATUS_VALIDATED) {
887 $statusType =
'status4';
890 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
907 $this->
ref =
'myspecimenwebsite';
910 $this->otherlang =
'fr,es';
912 $this->fk_default_home =
null;
913 $this->virtualhost =
'http://myvirtualhost';
914 $this->fk_user_creat = $user->id;
915 $this->fk_user_modif = $user->id;
916 $this->date_creation =
dol_now();
928 global $conf, $mysoc;
932 if (empty($website->id) || empty($website->ref)) {
937 dol_syslog(
"Create temp dir ".$conf->website->dir_temp);
939 if (!is_writable($conf->website->dir_temp)) {
940 setEventMessages(
"Temporary dir ".$conf->website->dir_temp.
" is not writable",
null,
'errors');
944 $destdir = $conf->website->dir_temp.
'/'.$website->ref;
947 $count = 0; $countreallydeleted = 0;
949 if ($counttodelete != $countreallydeleted) {
950 setEventMessages(
"Failed to clean temp directory ".$destdir,
null,
'errors');
954 $arrayreplacementinfilename = array();
955 $arrayreplacementincss = array();
956 $arrayreplacementincss[
'file=image/'.$website->ref.
'/'] =
"file=image/__WEBSITE_KEY__/";
957 $arrayreplacementincss[
'file=js/'.$website->ref.
'/'] =
"file=js/__WEBSITE_KEY__/";
958 $arrayreplacementincss[
'medias/image/'.$website->ref.
'/'] =
"medias/image/__WEBSITE_KEY__/";
959 $arrayreplacementincss[
'medias/js/'.$website->ref.
'/'] =
"medias/js/__WEBSITE_KEY__/";
960 if ($mysoc->logo_small) {
961 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_small] =
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__";
963 if ($mysoc->logo_mini) {
964 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini] =
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__";
967 $arrayreplacementincss[
'file=logos%2Fthumbs%2F'.$mysoc->logo] =
"file=logos%2Fthumbs%2F__LOGO_KEY__";
972 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/containers');
973 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey');
974 dol_mkdir($conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey');
977 $srcdir = $conf->website->dir_output.
'/'.$website->ref;
978 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers';
980 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
981 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename, 2);
984 $srcdir = DOL_DATA_ROOT.
'/medias/image/'.$website->ref;
985 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/medias/image/websitekey';
987 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
988 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename);
991 $srcdir = DOL_DATA_ROOT.
'/medias/js/'.$website->ref;
992 $destdir = $conf->website->dir_temp.
'/'.$website->ref.
'/medias/js/websitekey';
994 dol_syslog(
"Copy content from ".$srcdir.
" into ".$destdir);
995 dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename);
998 $cssindestdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers/styles.css.php';
1001 $htmldeaderindestdir = $conf->website->dir_temp.
'/'.$website->ref.
'/containers/htmlheader.html';
1005 $filesql = $conf->website->dir_temp.
'/'.$website->ref.
'/website_pages.sql';
1006 $fp = fopen($filesql,
"w");
1013 $listofpages = $objectpages->fetchAll($website->id);
1017 foreach ($listofpages as $pageid => $objectpageold) {
1018 $objectpageold->newid = $i;
1022 foreach ($listofpages as $pageid => $objectpageold) {
1025 foreach ($listofpages as $pageid2 => $objectpageold2) {
1026 if ($pageid2 == $objectpageold->fk_page) {
1027 $newfk_page = $objectpageold2->newid;
1031 $objectpageold->newfk_page = $newfk_page;
1034 foreach ($listofpages as $pageid => $objectpageold) {
1035 $allaliases = $objectpageold->pageurl;
1036 $allaliases .= ($objectpageold->aliasalt ?
','.$objectpageold->aliasalt :
'');
1038 $line =
'-- Page ID '.$objectpageold->id.
' -> '.$objectpageold->newid.
'__+MAX_llx_website_page__ - Aliases '.$allaliases.
' --;';
1043 $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)';
1045 $line .=
" VALUES(";
1046 $line .= $objectpageold->newid.
"__+MAX_llx_website_page__, ";
1047 $line .= ($objectpageold->newfk_page ? $this->
db->escape($objectpageold->newfk_page).
"__+MAX_llx_website_page__" :
"null").
", ";
1048 $line .=
"__WEBSITE_ID__, ";
1049 $line .=
"'".$this->db->escape($objectpageold->pageurl).
"', ";
1050 $line .=
"'".$this->db->escape($objectpageold->aliasalt).
"', ";
1051 $line .=
"'".$this->db->escape($objectpageold->title).
"', ";
1052 $line .=
"'".$this->db->escape($objectpageold->description).
"', ";
1053 $line .=
"'".$this->db->escape($objectpageold->lang).
"', ";
1054 $line .=
"'".$this->db->escape($objectpageold->image).
"', ";
1055 $line .=
"'".$this->db->escape($objectpageold->keywords).
"', ";
1056 $line .=
"'".$this->db->escape($objectpageold->status).
"', ";
1057 $line .=
"'".$this->db->idate($objectpageold->date_creation).
"', ";
1058 $line .=
"'".$this->db->idate($objectpageold->date_modification).
"', ";
1059 $line .= ($objectpageold->import_key ?
"'".$this->db->escape($objectpageold->import_key).
"'" :
"null").
", ";
1060 $line .=
"'".$this->db->escape($objectpageold->grabbed_from).
"', ";
1061 $line .=
"'".$this->db->escape($objectpageold->type_container).
"', ";
1063 $stringtoexport = $objectpageold->htmlheader;
1064 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1065 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1066 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1067 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1068 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1069 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1070 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1071 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1072 $line .=
"'".$this->db->escape(str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport)).
"', ";
1074 $stringtoexport = $objectpageold->content;
1075 $stringtoexport = str_replace(array(
"\r\n",
"\r",
"\n"),
"__N__", $stringtoexport);
1076 $stringtoexport = str_replace(
'file=image/'.$website->ref.
'/',
"file=image/__WEBSITE_KEY__/", $stringtoexport);
1077 $stringtoexport = str_replace(
'file=js/'.$website->ref.
'/',
"file=js/__WEBSITE_KEY__/", $stringtoexport);
1078 $stringtoexport = str_replace(
'medias/image/'.$website->ref.
'/',
"medias/image/__WEBSITE_KEY__/", $stringtoexport);
1079 $stringtoexport = str_replace(
'medias/js/'.$website->ref.
'/',
"medias/js/__WEBSITE_KEY__/", $stringtoexport);
1080 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_small,
"file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__", $stringtoexport);
1081 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo_mini,
"file=logos%2Fthumbs%2F__LOGO_MINI_KEY__", $stringtoexport);
1082 $stringtoexport = str_replace(
'file=logos%2Fthumbs%2F'.$mysoc->logo,
"file=logos%2Fthumbs%2F__LOGO_KEY__", $stringtoexport);
1085 $stringtoexport = str_replace(
'="image/'.$website->ref.
'/',
'="image/__WEBSITE_KEY__/', $stringtoexport);
1087 $line .=
"'".$this->db->escape($stringtoexport).
"', ";
1088 $line .=
"'".$this->db->escape($objectpageold->author_alias).
"', ";
1089 $line .= (int) $objectpageold->allowed_in_frames;
1097 if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) {
1099 $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__;";
1105 $line =
"\n-- For Dolibarr v14+ --;\n";
1106 $line .=
"UPDATE llx_website SET lang = '".$this->db->escape($this->lang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1107 $line .=
"UPDATE llx_website SET otherlang = '".$this->db->escape($this->otherlang).
"' WHERE rowid = __WEBSITE_ID__;\n";
1112 if (!empty($conf->global->MAIN_UMASK)) {
1113 @chmod($filesql, octdec($conf->global->MAIN_UMASK));
1117 $filedir = $conf->website->dir_temp.
'/'.$website->ref.
'/.';
1118 $fileglob = $conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-*.zip';
1119 $filename = $conf->website->dir_temp.
'/'.$website->ref.
'/website_'.$website->ref.
'-'.
dol_print_date(
dol_now(),
'dayhourlog').
'-V'.((
float) DOL_VERSION).
'.zip';
1122 $result = dol_compress_file($filedir, $filename,
'zip');
1128 $this->error = $errormsg;
1142 global $conf, $mysoc;
1147 if (empty($object->ref)) {
1148 $this->error =
'Function importWebSite called on object not loaded (object->ref is empty)';
1153 dol_mkdir($conf->website->dir_temp.
'/'.$object->ref);
1155 $filename = basename($pathtofile);
1156 if (!preg_match(
'/^website_(.*)-(.*)$/', $filename, $reg)) {
1157 $this->errors[] =
'Bad format for filename '.$filename.
'. Must be website_XXX-VERSION.';
1161 $result =
dol_uncompress($pathtofile, $conf->website->dir_temp.
'/'.$object->ref);
1163 if (!empty($result[
'error'])) {
1164 $this->errors[] =
'Failed to unzip file '.$pathtofile.
'.';
1168 $arrayreplacement = array();
1169 $arrayreplacement[
'__WEBSITE_ID__'] = $object->id;
1170 $arrayreplacement[
'__WEBSITE_KEY__'] = $object->ref;
1171 $arrayreplacement[
'__N__'] = $this->
db->escape(
"\n");
1172 $arrayreplacement[
'__LOGO_SMALL_KEY__'] = $this->
db->escape($mysoc->logo_small);
1173 $arrayreplacement[
'__LOGO_MINI_KEY__'] = $this->
db->escape($mysoc->logo_mini);
1174 $arrayreplacement[
'__LOGO_KEY__'] = $this->
db->escape($mysoc->logo);
1177 dolCopyDir($conf->website->dir_temp.
'/'.$object->ref.
'/containers', $conf->website->dir_output.
'/'.$object->ref, 0, 1);
1180 $cssindestdir = $conf->website->dir_output.
'/'.$object->ref.
'/styles.css.php';
1183 $htmldeaderindestdir = $conf->website->dir_output.
'/'.$object->ref.
'/htmlheader.html';
1187 $filemaster = $conf->website->dir_output.
'/'.$object->ref.
'/master.inc.php';
1190 $this->errors[] =
'Failed to write file '.$filemaster;
1194 dolCopyDir($conf->website->dir_temp.
'/'.$object->ref.
'/medias/image/websitekey', $conf->website->dir_output.
'/'.$object->ref.
'/medias/image/'.$object->ref, 0, 1);
1195 dolCopyDir($conf->website->dir_temp.
'/'.$object->ref.
'/medias/js/websitekey', $conf->website->dir_output.
'/'.$object->ref.
'/medias/js/'.$object->ref, 0, 1);
1197 $sqlfile = $conf->website->dir_temp.
"/".$object->ref.
'/website_pages.sql';
1204 $sqlgetrowid =
'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.
'website_page';
1205 $resql = $this->
db->query($sqlgetrowid);
1207 $obj = $this->
db->fetch_object(
$resql);
1208 $maxrowid = $obj->max;
1212 $runsql =
run_sql($sqlfile, 1,
'', 0,
'',
'none', 0, 1, 0, 0, 1);
1214 $this->errors[] =
'Failed to load sql file '.$sqlfile.
' (ret='.((int) $runsql).
')';
1221 $fp = fopen($sqlfile,
"r");
1223 while (!feof($fp)) {
1227 $buf = fgets($fp, 65000);
1228 if (preg_match(
'/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.*)\s--;/i', $buf, $reg)) {
1230 $newid = ($reg[2] + $maxrowid);
1231 $aliasesarray = explode(
',', $reg[3]);
1233 dol_syslog(
"Found ID ".$oldid.
" to replace with ID ".$newid.
" and shortcut aliases to create: ".$reg[3]);
1235 dol_move($conf->website->dir_output.
'/'.$object->ref.
'/page'.$oldid.
'.tpl.php', $conf->website->dir_output.
'/'.$object->ref.
'/page'.$newid.
'.tpl.php', 0, 1, 0, 0);
1237 $objectpagestatic->fetch($newid);
1240 $filetpl = $conf->website->dir_output.
'/'.$object->ref.
'/page'.$newid.
'.tpl.php';
1243 $this->errors[] =
'Failed to write file '.basename($filetpl);
1248 if (is_array($aliasesarray)) {
1249 foreach ($aliasesarray as $aliasshortcuttocreate) {
1250 if (trim($aliasshortcuttocreate)) {
1251 $filealias = $conf->website->dir_output.
'/'.$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1254 $this->errors[] =
'Failed to write file '.basename($filealias);
1266 $sql =
"SELECT fk_default_home FROM ".MAIN_DB_PREFIX.
"website WHERE rowid = ".((int) $object->id);
1269 $obj = $this->
db->fetch_object(
$resql);
1271 $object->fk_default_home = $obj->fk_default_home;
1279 $pathofwebsite = $conf->website->dir_output.
'/'.$object->ref;
1280 dolSaveIndexPage($pathofwebsite, $pathofwebsite.
'/index.php', $pathofwebsite.
'/page'.$object->fk_default_home.
'.tpl.php', $pathofwebsite.
'/wrapper.php', $object);
1283 $this->
db->rollback();
1286 $this->
db->commit();
1304 if (empty($object->ref)) {
1305 $this->error =
'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)';
1311 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"website_page WHERE fk_website = ".((int) $this->
id);
1315 $this->error = $this->
db->lasterror();
1319 $num = $this->
db->num_rows(
$resql);
1324 $obj = $this->
db->fetch_object(
$resql);
1326 $newid = $obj->rowid;
1328 $objectpagestatic->fetch($newid);
1330 $aliasesarray = explode(
',', $objectpagestatic->aliasalt);
1332 $filetpl = $conf->website->dir_output.
'/'.$object->ref.
'/page'.$newid.
'.tpl.php';
1335 $this->errors[] =
'Failed to write file '.basename($filetpl);
1340 if (!empty($objectpagestatic->pageurl) && !in_array($objectpagestatic->pageurl, $aliasesarray)) {
1341 $aliasesarray[] = $objectpagestatic->pageurl;
1345 if (is_array($aliasesarray)) {
1346 foreach ($aliasesarray as $aliasshortcuttocreate) {
1347 if (trim($aliasshortcuttocreate)) {
1348 $filealias = $conf->website->dir_output.
'/'.$object->ref.
'/'.trim($aliasshortcuttocreate).
'.php';
1351 $this->errors[] =
'Failed to write file '.basename($filealias);
1363 $pathofwebsite = $conf->website->dir_output.
'/'.$object->ref;
1364 $fileindex = $pathofwebsite.
'/index.php';
1366 if ($object->fk_default_home > 0) {
1367 $filetpl = $pathofwebsite.
'/page'.$object->fk_default_home.
'.tpl.php';
1369 $filewrapper = $pathofwebsite.
'/wrapper.php';
1370 dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object);
1387 return (empty($this->otherlang) ?
false :
true);
1401 global $websitepagefile, $website;
1403 if (!is_object($weblangs)) {
1404 return 'ERROR componentSelectLang called with parameter $weblangs not defined';
1407 $arrayofspecialmainlanguages = array(
1438 if (!empty($websitepagefile)) {
1439 $websitepagefileshort = basename($websitepagefile);
1440 if ($websitepagefileshort ==
'index.php') {
1441 $pageid = $website->fk_default_home;
1443 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), $websitepagefileshort);
1446 $tmppage->fetch($pageid);
1451 if (!is_array($languagecodes) && $pageid > 0) {
1452 $languagecodes = array();
1454 $sql =
"SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
1455 $sql .=
" FROM ".MAIN_DB_PREFIX.
"website_page as wp";
1456 $sql .=
" WHERE wp.fk_website = ".((int) $website->id);
1457 $sql .=
" AND (wp.fk_page = ".((int) $pageid).
" OR wp.rowid = ".((int) $pageid);
1458 if ($tmppage->fk_page > 0) {
1459 $sql .=
" OR wp.fk_page = ".((int) $tmppage->fk_page).
" OR wp.rowid = ".((int) $tmppage->fk_page);
1465 while ($obj = $this->
db->fetch_object(
$resql)) {
1466 $newlang = $obj->lang;
1467 if ($obj->rowid == $pageid) {
1468 $newlang = $obj->lang;
1470 if (!in_array($newlang, $languagecodes)) {
1471 $languagecodes[] = $newlang;
1478 $languagecodeselected = substr($weblangs->defaultlang, 0, 2);
1479 if (!empty($websitepagefile)) {
1480 $pageid = str_replace(array(
'.tpl.php',
'page'), array(
'',
''), basename($websitepagefile));
1482 $pagelang = substr($tmppage->lang, 0, 2);
1483 $languagecodeselected = substr($pagelang, 0, 2);
1484 if (!in_array($pagelang, $languagecodes)) {
1485 $languagecodes[] = $pagelang;
1490 $weblangs->load(
'languages');
1493 $url = $_SERVER[
"REQUEST_URI"];
1494 $url = preg_replace(
'/(\?|&)l=([a-zA-Z_]*)/',
'', $url);
1496 $url .= (preg_match(
'/\?/', $url) ?
'&' :
'?').
'l=';
1497 if (!preg_match(
'/^\//', $url)) {
1502 $MAXHEIGHT = 4 * $HEIGHTOPTION;
1503 $nboflanguage = count($languagecodes);
1505 $out =
'<!-- componentSelectLang'.$htmlname.
' -->'.
"\n";
1508 $out .=
'.componentSelectLang'.$htmlname.
':hover { height: '.min($MAXHEIGHT, ($HEIGHTOPTION * $nboflanguage)).
'px; overflow-x: hidden; overflow-y: '.((($HEIGHTOPTION * $nboflanguage) > $MAXHEIGHT) ?
' scroll' :
'hidden').
'; }'.
"\n";
1509 $out .=
'.componentSelectLang'.$htmlname.
' li { line-height: '.$HEIGHTOPTION.
'px; }'.
"\n";
1510 $out .=
'.componentSelectLang'.$htmlname.
' {
1511 display: inline-block;
1513 height: '.$HEIGHTOPTION.
'px;
1515 transition: all .3s ease;
1517 vertical-align: top;
1519 .componentSelectLang'.$htmlname.
':hover, .componentSelectLang'.$htmlname.
':hover a { background-color: #fff; color: #000 !important; }
1520 ul.componentSelectLang'.$htmlname.
' { width: 150px; }
1521 ul.componentSelectLang'.$htmlname.
':hover .fa { visibility: hidden; }
1522 .componentSelectLang'.$htmlname.
' a { text-decoration: none; width: 100%; }
1523 .componentSelectLang'.$htmlname.
' li { display: block; padding: 0px 15px; margin-left: 0; margin-right: 0; }
1524 .componentSelectLang'.$htmlname.
' li:hover { background-color: #EEE; }
1527 $out .=
'<ul class="componentSelectLang'.$htmlname.($morecss ?
' '.$morecss :
'').
'">';
1529 if ($languagecodeselected) {
1531 if (strlen($languagecodeselected) == 2) {
1532 $languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.
'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
1535 $countrycode = strtolower(substr($languagecodeselected, -2));
1536 $label = $weblangs->trans(
"Language_".$languagecodeselected);
1537 if ($countrycode ==
'us') {
1538 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1540 $out .=
'<a href="'.$url.substr($languagecodeselected, 0, 2).
'"><li><img height="12px" src="/medias/image/common/flags/'.$countrycode.
'.png" style="margin-right: 5px;"/><span class="websitecomponentlilang">'.$label.
'</span>';
1541 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1542 $out .=
'</li></a>';
1545 if (is_array($languagecodes)) {
1546 foreach ($languagecodes as $languagecode) {
1548 if (strlen($languagecode) == 2) {
1549 $languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.
'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
1552 if ($languagecode == $languagecodeselected) {
1556 $countrycode = strtolower(substr($languagecode, -2));
1557 $label = $weblangs->trans(
"Language_".$languagecode);
1558 if ($countrycode ==
'us') {
1559 $label = preg_replace(
'/\s*\(.*\)/',
'', $label);
1561 $out .=
'<a href="'.$url.substr($languagecode, 0, 2).
'"><li><img height="12px" src="/medias/image/common/flags/'.$countrycode.
'.png" style="margin-right: 5px;"/><span class="websitecomponentlilang">'.$label.
'</span>';
1562 if (empty($i) && empty($languagecodeselected)) {
1563 $out .=
'<span class="fa fa-caret-down" style="padding-left: 5px;" />';
1565 $out .=
'</li></a>';