diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php
index d0ffc3ccc03..fe2e6aab4cf 100644
--- a/htdocs/website/class/website.class.php
+++ b/htdocs/website/class/website.class.php
@@ -244,7 +244,9 @@ class Website extends CommonObject
if (is_array($tmplangarray)) {
dol_mkdir($conf->website->dir_output.'/'.$this->ref);
foreach ($tmplangarray as $val) {
- if (trim($val) == $this->lang) continue;
+ if (trim($val) == $this->lang) {
+ continue;
+ }
dol_mkdir($conf->website->dir_output.'/'.$this->ref.'/'.trim($val));
}
}
@@ -540,7 +542,9 @@ class Website extends CommonObject
if (is_array($tmplangarray)) {
dol_mkdir($conf->website->dir_output.'/'.$this->ref);
foreach ($tmplangarray as $val) {
- if (trim($val) == $this->lang) continue;
+ if (trim($val) == $this->lang) {
+ continue;
+ }
dol_mkdir($conf->website->dir_output.'/'.$this->ref.'/'.trim($val));
}
}
@@ -603,8 +607,7 @@ class Website extends CommonObject
}
}
- if (!$error && !empty($this->ref))
- {
+ if (!$error && !empty($this->ref)) {
$pathofwebsite = DOL_DATA_ROOT.'/website/'.$this->ref;
dol_delete_dir_recursive($pathofwebsite);
@@ -645,8 +648,7 @@ class Website extends CommonObject
$object = new self($this->db);
// Check no site with ref exists
- if ($object->fetch(0, $newref) > 0)
- {
+ if ($object->fetch(0, $newref) > 0) {
$this->error = 'ErrorNewRefIsAlreadyUsed';
return -1;
}
@@ -678,7 +680,9 @@ class Website extends CommonObject
$object->fk_user_creat = $user->id;
$object->position = ((int) $object->position) + 1;
$object->status = self::STATUS_DRAFT;
- if (empty($object->lang)) $object->lang = substr($langs->defaultlang, 0, 2); // Should not happen. Protection for corrupted site with no languages
+ if (empty($object->lang)) {
+ $object->lang = substr($langs->defaultlang, 0, 2); // Should not happen. Protection for corrupted site with no languages
+ }
// Create clone
$object->context['createfromclone'] = 'createfromclone';
@@ -690,15 +694,13 @@ class Website extends CommonObject
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
}
- if (!$error)
- {
+ if (!$error) {
dolCopyDir($pathofwebsiteold, $pathofwebsitenew, $conf->global->MAIN_UMASK, 0, null, 2);
// Check symlink to medias and restore it if ko
$pathtomedias = DOL_DATA_ROOT.'/medias'; // Target
$pathtomediasinwebsite = $pathofwebsitenew.'/medias'; // Source / Link name
- if (!is_link(dol_osencode($pathtomediasinwebsite)))
- {
+ if (!is_link(dol_osencode($pathtomediasinwebsite))) {
dol_syslog("Create symlink for ".$pathtomedias." into name ".$pathtomediasinwebsite);
dol_mkdir(dirname($pathtomediasinwebsite)); // To be sure dir for website exists
$result = symlink($pathtomedias, $pathtomediasinwebsite);
@@ -718,8 +720,7 @@ class Website extends CommonObject
// Duplicate pages
$objectpages = new WebsitePage($this->db);
$listofpages = $objectpages->fetchAll($fromid);
- foreach ($listofpages as $pageid => $objectpageold)
- {
+ foreach ($listofpages as $pageid => $objectpageold) {
// Delete old file
$filetplold = $pathofwebsitenew.'/page'.$pageid.'.tpl.php';
dol_delete_file($filetplold);
@@ -728,43 +729,41 @@ class Website extends CommonObject
$objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl, '', 0, $object->id, 1);
//print $pageid.' = '.$objectpageold->pageurl.' -> '.$objectpagenew->id.' = '.$objectpagenew->pageurl.'
';
- if (is_object($objectpagenew) && $objectpagenew->pageurl)
- {
+ if (is_object($objectpagenew) && $objectpagenew->pageurl) {
$filealias = $pathofwebsitenew.'/'.$objectpagenew->pageurl.'.php';
$filetplnew = $pathofwebsitenew.'/page'.$objectpagenew->id.'.tpl.php';
// Save page alias
$result = dolSavePageAlias($filealias, $object, $objectpagenew);
- if (!$result) setEventMessages('Failed to write file '.$filealias, null, 'errors');
+ if (!$result) {
+ setEventMessages('Failed to write file '.$filealias, null, 'errors');
+ }
$result = dolSavePageContent($filetplnew, $object, $objectpagenew);
- if (!$result) setEventMessages('Failed to write file '.$filetplnew, null, 'errors');
+ if (!$result) {
+ setEventMessages('Failed to write file '.$filetplnew, null, 'errors');
+ }
- if ($pageid == $oldidforhome)
- {
+ if ($pageid == $oldidforhome) {
$newidforhome = $objectpagenew->id;
}
- }
- else {
+ } else {
setEventMessages($objectpageold->error, $objectpageold->errors, 'errors');
$error++;
}
}
}
- if (!$error)
- {
+ if (!$error) {
// Restore id of home page
$object->fk_default_home = $newidforhome;
$res = $object->update($user);
- if (!($res > 0))
- {
+ if (!($res > 0)) {
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
- if (!$error)
- {
+ if (!$error) {
$filetpl = $pathofwebsitenew.'/page'.$newidforhome.'.tpl.php';
$filewrapper = $pathofwebsitenew.'/wrapper.php';
@@ -821,10 +820,11 @@ class Website extends CommonObject
$linkstart = $linkend = '';
- if ($withpicto)
- {
+ if ($withpicto) {
$result .= ($linkstart.img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? '' : 'class="classfortooltip"')).$linkend);
- if ($withpicto != 2) $result .= ' ';
+ if ($withpicto != 2) {
+ $result .= ' ';
+ }
}
$result .= $linkstart.$this->ref.$linkend;
return $result;
@@ -854,8 +854,7 @@ class Website extends CommonObject
// phpcs:enable
global $langs;
- if (empty($this->labelStatus) || empty($this->labelStatusShort))
- {
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
//$langs->load("mymodule");
$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Disabled');
@@ -865,7 +864,9 @@ class Website extends CommonObject
}
$statusType = 'status5';
- if ($status == self::STATUS_VALIDATED) $statusType = 'status4';
+ if ($status == self::STATUS_VALIDATED) {
+ $statusType = 'status4';
+ }
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
@@ -909,16 +910,14 @@ class Website extends CommonObject
$website = $this;
- if (empty($website->id) || empty($website->ref))
- {
+ if (empty($website->id) || empty($website->ref)) {
setEventMessages("Website id or ref is not defined", null, 'errors');
return '';
}
dol_syslog("Create temp dir ".$conf->website->dir_temp);
dol_mkdir($conf->website->dir_temp);
- if (!is_writable($conf->website->dir_temp))
- {
+ if (!is_writable($conf->website->dir_temp)) {
setEventMessages("Temporary dir ".$conf->website->dir_temp." is not writable", null, 'errors');
return '';
}
@@ -928,8 +927,7 @@ class Website extends CommonObject
dol_syslog("Clear temp dir ".$destdir);
$count = 0; $countreallydeleted = 0;
$counttodelete = dol_delete_dir_recursive($destdir, $count, 1, 0, $countreallydeleted);
- if ($counttodelete != $countreallydeleted)
- {
+ if ($counttodelete != $countreallydeleted) {
setEventMessages("Failed to clean temp directory ".$destdir, null, 'errors');
return '';
}
@@ -987,8 +985,7 @@ class Website extends CommonObject
// Build sql file
$filesql = $conf->website->dir_temp.'/'.$website->ref.'/website_pages.sql';
$fp = fopen($filesql, "w");
- if (empty($fp))
- {
+ if (empty($fp)) {
setEventMessages("Failed to create file ".$filesql, null, 'errors');
return '';
}
@@ -998,20 +995,16 @@ class Website extends CommonObject
// Assign ->newid and ->newfk_page
$i = 1;
- foreach ($listofpages as $pageid => $objectpageold)
- {
+ foreach ($listofpages as $pageid => $objectpageold) {
$objectpageold->newid = $i;
$i++;
}
$i = 1;
- foreach ($listofpages as $pageid => $objectpageold)
- {
+ foreach ($listofpages as $pageid => $objectpageold) {
// Search newid
$newfk_page = 0;
- foreach ($listofpages as $pageid2 => $objectpageold2)
- {
- if ($pageid2 == $objectpageold->fk_page)
- {
+ foreach ($listofpages as $pageid2 => $objectpageold2) {
+ if ($pageid2 == $objectpageold->fk_page) {
$newfk_page = $objectpageold2->newid;
break;
}
@@ -1019,8 +1012,7 @@ class Website extends CommonObject
$objectpageold->newfk_page = $newfk_page;
$i++;
}
- foreach ($listofpages as $pageid => $objectpageold)
- {
+ foreach ($listofpages as $pageid => $objectpageold) {
$allaliases = $objectpageold->pageurl;
$allaliases .= ($objectpageold->aliasalt ? ','.$objectpageold->aliasalt : '');
@@ -1081,8 +1073,7 @@ class Website extends CommonObject
// Add line to update home page id during import
//var_dump($this->fk_default_home.' - '.$objectpageold->id.' - '.$objectpageold->newid);exit;
- if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) // This is the record with home page
- {
+ if ($this->fk_default_home > 0 && ($objectpageold->id == $this->fk_default_home) && ($objectpageold->newid > 0)) { // This is the record with home page
// Warning: We must keep llx_ here. It is a generic SQL.
$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__;";
$line .= "\n";
@@ -1091,8 +1082,9 @@ class Website extends CommonObject
}
fclose($fp);
- if (!empty($conf->global->MAIN_UMASK))
+ if (!empty($conf->global->MAIN_UMASK)) {
@chmod($filesql, octdec($conf->global->MAIN_UMASK));
+ }
// Build zip file
$filedir = $conf->website->dir_temp.'/'.$website->ref.'/.';
@@ -1102,11 +1094,9 @@ class Website extends CommonObject
dol_delete_file($fileglob, 0);
$result = dol_compress_file($filedir, $filename, 'zip');
- if ($result > 0)
- {
+ if ($result > 0) {
return $filename;
- }
- else {
+ } else {
global $errormsg;
$this->error = $errormsg;
return '';
@@ -1127,8 +1117,7 @@ class Website extends CommonObject
$error = 0;
$object = $this;
- if (empty($object->ref))
- {
+ if (empty($object->ref)) {
$this->error = 'Function importWebSite called on object not loaded (object->ref is empty)';
return -1;
}
@@ -1137,16 +1126,14 @@ class Website extends CommonObject
dol_mkdir($conf->website->dir_temp.'/'.$object->ref);
$filename = basename($pathtofile);
- if (!preg_match('/^website_(.*)-(.*)$/', $filename, $reg))
- {
+ if (!preg_match('/^website_(.*)-(.*)$/', $filename, $reg)) {
$this->errors[] = 'Bad format for filename '.$filename.'. Must be website_XXX-VERSION.';
return -1;
}
$result = dol_uncompress($pathtofile, $conf->website->dir_temp.'/'.$object->ref);
- if (!empty($result['error']))
- {
+ if (!empty($result['error'])) {
$this->errors[] = 'Failed to unzip file '.$pathtofile.'.';
return -1;
}
@@ -1172,8 +1159,7 @@ class Website extends CommonObject
// Now generate the master.inc.php page
$filemaster = $conf->website->dir_output.'/'.$object->ref.'/master.inc.php';
$result = dolSaveMasterFile($filemaster);
- if (!$result)
- {
+ if (!$result) {
$this->errors[] = 'Failed to write file '.$filemaster;
$error++;
}
@@ -1190,16 +1176,14 @@ class Website extends CommonObject
// Search the $maxrowid because we need it later
$sqlgetrowid = 'SELECT MAX(rowid) as max from '.MAIN_DB_PREFIX.'website_page';
$resql = $this->db->query($sqlgetrowid);
- if ($resql)
- {
+ if ($resql) {
$obj = $this->db->fetch_object($resql);
$maxrowid = $obj->max;
}
// Load sql record
$runsql = run_sql($sqlfile, 1, '', 0, '', 'none', 0, 1); // The maxrowid of table is searched into this function two
- if ($runsql <= 0)
- {
+ if ($runsql <= 0) {
$this->errors[] = 'Failed to load sql file '.$sqlfile;
$error++;
}
@@ -1208,16 +1192,13 @@ class Website extends CommonObject
// Make replacement of IDs
$fp = fopen($sqlfile, "r");
- if ($fp)
- {
- while (!feof($fp))
- {
+ if ($fp) {
+ while (!feof($fp)) {
$reg = array();
// Warning fgets with second parameter that is null or 0 hang.
$buf = fgets($fp, 65000);
- if (preg_match('/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.*)\s--;/i', $buf, $reg))
- {
+ if (preg_match('/^-- Page ID (\d+)\s[^\s]+\s(\d+).*Aliases\s(.*)\s--;/i', $buf, $reg)) {
$oldid = $reg[1];
$newid = ($reg[2] + $maxrowid);
$aliasesarray = explode(',', $reg[3]);
@@ -1237,12 +1218,9 @@ class Website extends CommonObject
}
// Regenerate alternative aliases pages
- if (is_array($aliasesarray))
- {
- foreach ($aliasesarray as $aliasshortcuttocreate)
- {
- if (trim($aliasshortcuttocreate))
- {
+ if (is_array($aliasesarray)) {
+ foreach ($aliasesarray as $aliasshortcuttocreate) {
+ if (trim($aliasshortcuttocreate)) {
$filealias = $conf->website->dir_output.'/'.$object->ref.'/'.trim($aliasshortcuttocreate).'.php';
$result = dolSavePageAlias($filealias, $object, $objectpagestatic);
if (!$result) {
@@ -1274,12 +1252,10 @@ class Website extends CommonObject
$pathofwebsite = $conf->website->dir_output.'/'.$object->ref;
dolSaveIndexPage($pathofwebsite, $pathofwebsite.'/index.php', $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php', $pathofwebsite.'/wrapper.php');
- if ($error)
- {
+ if ($error) {
$this->db->rollback();
return -1;
- }
- else {
+ } else {
$this->db->commit();
return $object->id;
}
@@ -1298,8 +1274,7 @@ class Website extends CommonObject
$error = 0;
$object = $this;
- if (empty($object->ref))
- {
+ if (empty($object->ref)) {
$this->error = 'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)';
return -1;
}
@@ -1386,7 +1361,9 @@ class Website extends CommonObject
{
global $websitepagefile, $website;
- if (!is_object($weblangs)) return 'ERROR componentSelectLang called with parameter $weblangs not defined';
+ if (!is_object($weblangs)) {
+ return 'ERROR componentSelectLang called with parameter $weblangs not defined';
+ }
$arrayofspecialmainlanguages = array(
'en'=>'en_US',
@@ -1419,51 +1396,55 @@ class Website extends CommonObject
$tmppage = new WebsitePage($this->db);
$pageid = 0;
- if (!empty($websitepagefile))
- {
+ if (!empty($websitepagefile)) {
$websitepagefileshort = basename($websitepagefile);
- if ($websitepagefileshort == 'index.php') $pageid = $website->fk_default_home;
- else $pageid = str_replace(array('.tpl.php', 'page'), array('', ''), $websitepagefileshort);
- if ($pageid > 0)
- {
+ if ($websitepagefileshort == 'index.php') {
+ $pageid = $website->fk_default_home;
+ } else {
+ $pageid = str_replace(array('.tpl.php', 'page'), array('', ''), $websitepagefileshort);
+ }
+ if ($pageid > 0) {
$tmppage->fetch($pageid);
}
}
// Fill $languagecodes array with existing translation, nothing if none
- if (!is_array($languagecodes) && $pageid > 0)
- {
+ if (!is_array($languagecodes) && $pageid > 0) {
$languagecodes = array();
$sql = "SELECT wp.rowid, wp.lang, wp.pageurl, wp.fk_page";
$sql .= " FROM ".MAIN_DB_PREFIX."website_page as wp";
$sql .= " WHERE wp.fk_website = ".$website->id;
$sql .= " AND (wp.fk_page = ".$pageid." OR wp.rowid = ".$pageid;
- if ($tmppage->fk_page > 0) $sql .= " OR wp.fk_page = ".$tmppage->fk_page." OR wp.rowid = ".$tmppage->fk_page;
+ if ($tmppage->fk_page > 0) {
+ $sql .= " OR wp.fk_page = ".$tmppage->fk_page." OR wp.rowid = ".$tmppage->fk_page;
+ }
$sql .= ")";
$resql = $this->db->query($sql);
- if ($resql)
- {
- while ($obj = $this->db->fetch_object($resql))
- {
+ if ($resql) {
+ while ($obj = $this->db->fetch_object($resql)) {
$newlang = $obj->lang;
- if ($obj->rowid == $pageid) $newlang = $obj->lang;
- if (!in_array($newlang, $languagecodes)) $languagecodes[] = $newlang;
+ if ($obj->rowid == $pageid) {
+ $newlang = $obj->lang;
+ }
+ if (!in_array($newlang, $languagecodes)) {
+ $languagecodes[] = $newlang;
+ }
}
}
}
// Now $languagecodes is always an array. Example array('en', 'fr', 'es');
$languagecodeselected = substr($weblangs->defaultlang, 0, 2); // Because we must init with a value, but real value is the lang of main parent container
- if (!empty($websitepagefile))
- {
+ if (!empty($websitepagefile)) {
$pageid = str_replace(array('.tpl.php', 'page'), array('', ''), basename($websitepagefile));
- if ($pageid > 0)
- {
+ if ($pageid > 0) {
$pagelang = substr($tmppage->lang, 0, 2);
$languagecodeselected = substr($pagelang, 0, 2);
- if (!in_array($pagelang, $languagecodes)) $languagecodes[] = $pagelang; // We add language code of page into combo list
+ if (!in_array($pagelang, $languagecodes)) {
+ $languagecodes[] = $pagelang; // We add language code of page into combo list
+ }
}
}
@@ -1474,7 +1455,9 @@ class Website extends CommonObject
$url = preg_replace('/(\?|&)l=([a-zA-Z_]*)/', '', $url); // We remove param l from url
//$url = preg_replace('/(\?|&)lang=([a-zA-Z_]*)/', '', $url); // We remove param lang from url
$url .= (preg_match('/\?/', $url) ? '&' : '?').'l=';
- if (!preg_match('/^\//', $url)) $url = '/'.$url;
+ if (!preg_match('/^\//', $url)) {
+ $url = '/'.$url;
+ }
$HEIGHTOPTION = 40;
$MAXHEIGHT = 4 * $HEIGHTOPTION;
@@ -1504,8 +1487,7 @@ class Website extends CommonObject
$out .= '';
$out .= '
';
- if ($languagecodeselected)
- {
+ if ($languagecodeselected) {
// Convert $languagecodeselected into a long language code
if (strlen($languagecodeselected) == 2) {
$languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]);
@@ -1513,28 +1495,34 @@ class Website extends CommonObject
$countrycode = strtolower(substr($languagecodeselected, -2));
$label = $weblangs->trans("Language_".$languagecodeselected);
- if ($countrycode == 'us') $label = preg_replace('/\s*\(.*\)/', '', $label);
+ if ($countrycode == 'us') {
+ $label = preg_replace('/\s*\(.*\)/', '', $label);
+ }
$out .= '
'.$label.'';
$out .= '';
$out .= ' ';
}
$i = 0;
- if (is_array($languagecodes))
- {
- foreach ($languagecodes as $languagecode)
- {
+ if (is_array($languagecodes)) {
+ foreach ($languagecodes as $languagecode) {
// Convert $languagecode into a long language code
if (strlen($languagecode) == 2) {
$languagecode = (empty($arrayofspecialmainlanguages[$languagecode]) ? $languagecode.'_'.strtoupper($languagecode) : $arrayofspecialmainlanguages[$languagecode]);
}
- if ($languagecode == $languagecodeselected) continue; // Already output
+ if ($languagecode == $languagecodeselected) {
+ continue; // Already output
+ }
$countrycode = strtolower(substr($languagecode, -2));
$label = $weblangs->trans("Language_".$languagecode);
- if ($countrycode == 'us') $label = preg_replace('/\s*\(.*\)/', '', $label);
+ if ($countrycode == 'us') {
+ $label = preg_replace('/\s*\(.*\)/', '', $label);
+ }
$out .= '
'.$label.'';
- if (empty($i) && empty($languagecodeselected)) $out .= '';
+ if (empty($i) && empty($languagecodeselected)) {
+ $out .= '';
+ }
$out .= ' ';
$i++;
}
diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php
index bacc4664791..c6c4d81d04e 100644
--- a/htdocs/website/class/websitepage.class.php
+++ b/htdocs/website/class/websitepage.class.php
@@ -106,9 +106,9 @@ class WebsitePage extends CommonObject
*/
public $author_alias;
- /**
- * @var string path of external object
- */
+ /**
+ * @var string path of external object
+ */
public $object_type;
/**
@@ -229,7 +229,9 @@ class WebsitePage extends CommonObject
{
$this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
$this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
- if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
+ if ($this->aliasalt) {
+ $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
+ }
// Remove spaces and be sure we have main language only
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
@@ -281,12 +283,12 @@ class WebsitePage extends CommonObject
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
//$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
$sql .= ' WHERE 1 = 1';
- if ($id > 0)
- {
+ if ($id > 0) {
$sql .= ' AND t.rowid = '.$id;
- }
- else {
- if ($id < 0) $sql .= ' AND t.rowid <> '.abs($id);
+ } else {
+ if ($id < 0) {
+ $sql .= ' AND t.rowid <> '.abs($id);
+ }
if (null !== $website_id) {
$sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'";
if ($page) {
@@ -295,12 +297,18 @@ class WebsitePage extends CommonObject
$tmppage = explode('/', $page);
if (!empty($tmppage[1])) {
$pagetouse = $tmppage[1];
- if (strlen($tmppage[0])) $langtouse = $tmppage[0];
+ if (strlen($tmppage[0])) {
+ $langtouse = $tmppage[0];
+ }
}
$sql .= " AND t.pageurl = '".$this->db->escape($pagetouse)."'";
- if ($langtouse) $sql .= " AND t.lang = '".$this->db->escape($langtouse)."'";
+ if ($langtouse) {
+ $sql .= " AND t.lang = '".$this->db->escape($langtouse)."'";
+ }
+ }
+ if ($aliasalt) {
+ $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')";
}
- if ($aliasalt) $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')";
}
}
$sql .= $this->db->plimit(1);
@@ -419,7 +427,9 @@ class WebsitePage extends CommonObject
$listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
}
$stringtouse = $key." IN (".join(',', $listoflang).")";
- if ($foundnull) $stringtouse = '('.$stringtouse.' OR '.$key.' IS NULL)';
+ if ($foundnull) {
+ $stringtouse = '('.$stringtouse.' OR '.$key.' IS NULL)';
+ }
$sqlwhere[] = $stringtouse;
} else {
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
@@ -441,8 +451,7 @@ class WebsitePage extends CommonObject
if ($resql) {
$num = $this->db->num_rows($resql);
- while ($obj = $this->db->fetch_object($resql))
- {
+ while ($obj = $this->db->fetch_object($resql)) {
$record = new self($this->db);
$record->id = $obj->rowid;
@@ -520,7 +529,9 @@ class WebsitePage extends CommonObject
$listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'";
}
$stringtouse = $key." IN (".join(',', $listoflang).")";
- if ($foundnull) $stringtouse = '('.$stringtouse.' OR '.$key.' IS NULL)';
+ if ($foundnull) {
+ $stringtouse = '('.$stringtouse.' OR '.$key.' IS NULL)';
+ }
$sqlwhere[] = $stringtouse;
} else {
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
@@ -561,7 +572,9 @@ class WebsitePage extends CommonObject
{
$this->description = dol_trunc($this->description, 255, 'right', 'utf-8', 1);
$this->keywords = dol_trunc($this->keywords, 255, 'right', 'utf-8', 1);
- if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
+ if ($this->aliasalt) {
+ $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,'
+ }
// Remove spaces and be sure we have main language only
$this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en
@@ -595,8 +608,7 @@ class WebsitePage extends CommonObject
// Delete all child tables
if (!$error) {
- foreach ($this->childtablesoncascade as $table)
- {
+ foreach ($this->childtablesoncascade as $table) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
$sql .= " WHERE fk_website_page = ".(int) $this->id;
@@ -611,19 +623,16 @@ class WebsitePage extends CommonObject
if (!$error) {
$result = $this->deleteCommon($user, $trigger);
- if ($result <= 0)
- {
+ if ($result <= 0) {
$error++;
}
}
- if (!$error)
- {
+ if (!$error) {
$websiteobj = new Website($this->db);
$result = $websiteobj->fetch($this->fk_website);
- if ($result > 0)
- {
+ if ($result > 0) {
global $dolibarr_main_data_root;
$pathofwebsite = $dolibarr_main_data_root.'/website/'.$websiteobj->ref;
@@ -696,10 +705,17 @@ class WebsitePage extends CommonObject
$object->date_creation = $now;
$object->title = ($newtitle == '1' ? $object->title : ($newtitle ? $newtitle : $object->title));
$object->description = $object->title;
- if (!empty($newlang)) $object->lang = $newlang;
- if ($istranslation) $object->fk_page = $fromid;
- else $object->fk_page = 0;
- if (!empty($newwebsite)) $object->fk_website = $newwebsite;
+ if (!empty($newlang)) {
+ $object->lang = $newlang;
+ }
+ if ($istranslation) {
+ $object->fk_page = $fromid;
+ } else {
+ $object->fk_page = 0;
+ }
+ if (!empty($newwebsite)) {
+ $object->fk_website = $newwebsite;
+ }
$object->import_key = '';
// Create clone
@@ -755,17 +771,16 @@ class WebsitePage extends CommonObject
$url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id;
$linkclose = '';
- if (empty($notooltip))
- {
- if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
- {
+ if (empty($notooltip)) {
+ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowMyObject");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
+ } else {
+ $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
- else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '';
@@ -774,8 +789,12 @@ class WebsitePage extends CommonObject
//$linkstart = $linkend = '';
$result .= $linkstart;
- if ($withpicto) $result .= img_picto(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
- if ($withpicto != 2) $result .= $this->ref;
+ if ($withpicto) {
+ $result .= img_picto(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
+ }
+ if ($withpicto != 2) {
+ $result .= $this->ref;
+ }
$result .= $linkend;
return $result;
@@ -805,8 +824,7 @@ class WebsitePage extends CommonObject
// phpcs:enable
global $langs;
- if (empty($this->labelStatus) || empty($this->labelStatusShort))
- {
+ if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
//$langs->load("mymodule");
$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Disabled');
@@ -816,7 +834,9 @@ class WebsitePage extends CommonObject
}
$statusType = 'status5';
- if ($status == self::STATUS_VALIDATED) $statusType = 'status4';
+ if ($status == self::STATUS_VALIDATED) {
+ $statusType = 'status4';
+ }
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
diff --git a/htdocs/website/index.php b/htdocs/website/index.php
index 46dfd49ed0a..425af726c24 100644
--- a/htdocs/website/index.php
+++ b/htdocs/website/index.php
@@ -44,7 +44,9 @@ require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$langs->loadLangs(array("admin", "other", "website", "errors"));
-if (!$user->rights->website->read) accessforbidden();
+if (!$user->rights->website->read) {
+ accessforbidden();
+}
$conf->dol_hide_leftmenu = 1; // Force hide of left menu.
@@ -70,38 +72,78 @@ $section_dir = GETPOST('section_dir', 'alpha');
$file_manager = GETPOST('file_manager', 'alpha');
$replacesite = GETPOST('replacesite', 'alpha');
-if (GETPOST('deletesite', 'alpha')) { $action = 'deletesite'; }
-if (GETPOST('delete', 'alpha')) { $action = 'delete'; }
-if (GETPOST('preview', 'alpha')) $action = 'preview';
-if (GETPOST('createsite', 'alpha')) { $action = 'createsite'; }
-if (GETPOST('createcontainer', 'alpha')) { $action = 'createcontainer'; }
-if (GETPOST('editcss', 'alpha')) { $action = 'editcss'; }
-if (GETPOST('editmenu', 'alpha')) { $action = 'editmenu'; }
-if (GETPOST('setashome', 'alpha')) { $action = 'setashome'; }
-if (GETPOST('editmeta', 'alpha')) { $action = 'editmeta'; }
-if (GETPOST('editsource', 'alpha')) { $action = 'editsource'; }
-if (GETPOST('editcontent', 'alpha')) { $action = 'editcontent'; }
-if (GETPOST('exportsite', 'alpha')) { $action = 'exportsite'; }
-if (GETPOST('importsite', 'alpha')) { $action = 'importsite'; }
-if (GETPOST('createfromclone', 'alpha')) { $action = 'createfromclone'; }
-if (GETPOST('createpagefromclone', 'alpha')) { $action = 'createpagefromclone'; }
-if (empty($action) && $file_manager) $action = 'file_manager';
-if (empty($action) && $replacesite) $action = 'replacesite';
-if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x')) $pageid = 0;
+if (GETPOST('deletesite', 'alpha')) {
+ $action = 'deletesite';
+}
+if (GETPOST('delete', 'alpha')) {
+ $action = 'delete';
+}
+if (GETPOST('preview', 'alpha')) {
+ $action = 'preview';
+}
+if (GETPOST('createsite', 'alpha')) {
+ $action = 'createsite';
+}
+if (GETPOST('createcontainer', 'alpha')) {
+ $action = 'createcontainer';
+}
+if (GETPOST('editcss', 'alpha')) {
+ $action = 'editcss';
+}
+if (GETPOST('editmenu', 'alpha')) {
+ $action = 'editmenu';
+}
+if (GETPOST('setashome', 'alpha')) {
+ $action = 'setashome';
+}
+if (GETPOST('editmeta', 'alpha')) {
+ $action = 'editmeta';
+}
+if (GETPOST('editsource', 'alpha')) {
+ $action = 'editsource';
+}
+if (GETPOST('editcontent', 'alpha')) {
+ $action = 'editcontent';
+}
+if (GETPOST('exportsite', 'alpha')) {
+ $action = 'exportsite';
+}
+if (GETPOST('importsite', 'alpha')) {
+ $action = 'importsite';
+}
+if (GETPOST('createfromclone', 'alpha')) {
+ $action = 'createfromclone';
+}
+if (GETPOST('createpagefromclone', 'alpha')) {
+ $action = 'createpagefromclone';
+}
+if (empty($action) && $file_manager) {
+ $action = 'file_manager';
+}
+if (empty($action) && $replacesite) {
+ $action = 'replacesite';
+}
+if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x')) {
+ $pageid = 0;
+}
// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
-if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
+if (empty($page) || $page == -1) {
+ $page = 0;
+} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
//if (! $sortfield) $sortfield='name';
//if (! $sortorder) $sortorder='ASC';
-if (empty($action)) $action = 'preview';
+if (empty($action)) {
+ $action = 'preview';
+}
$object = new Website($db);
$objectpage = new WebsitePage($db);
@@ -109,16 +151,13 @@ $objectpage = new WebsitePage($db);
$object->fetchAll('ASC', 'position'); // Init $object->records with list of websites
// If website not defined, we take first found
-if (!($websiteid > 0) && empty($websitekey) && $action != 'createsite')
-{
- foreach ($object->records as $key => $valwebsite)
- {
+if (!($websiteid > 0) && empty($websitekey) && $action != 'createsite') {
+ foreach ($object->records as $key => $valwebsite) {
$websitekey = $valwebsite->ref;
break;
}
}
-if ($websiteid > 0 || $websitekey)
-{
+if ($websiteid > 0 || $websitekey) {
$res = $object->fetch($websiteid, $websitekey);
$websitekey = $object->ref;
}
@@ -126,38 +165,33 @@ if ($websiteid > 0 || $websitekey)
$website = $object;
// Check pageid received as parameter
-if ($pageid < 0) $pageid = 0;
-if (($pageid > 0 || $pageref) && $action != 'addcontainer')
-{
+if ($pageid < 0) {
+ $pageid = 0;
+}
+if (($pageid > 0 || $pageref) && $action != 'addcontainer') {
$res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
- if ($res == 0)
- {
+ if ($res == 0) {
$res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), null, $pageref);
}
// Check if pageid is inside the new website, if not we reset param pageid
- if ($res >= 0 && $object->id > 0)
- {
- if ($objectpage->fk_website != $object->id) // We have a bad page that does not belong to web site
- {
- if ($object->fk_default_home > 0)
- {
+ if ($res >= 0 && $object->id > 0) {
+ if ($objectpage->fk_website != $object->id) { // We have a bad page that does not belong to web site
+ if ($object->fk_default_home > 0) {
$res = $objectpage->fetch($object->fk_default_home, $object->id, ''); // We search first page of web site
- if ($res > 0) $pageid = $object->fk_default_home;
- }
- else {
- $res = $objectpage->fetch(0, $object->id, ''); // We search first page of web site
- if ($res == 0) // Page was not found, we reset it
- {
- $objectpage = new WebsitePage($db);
+ if ($res > 0) {
+ $pageid = $object->fk_default_home;
}
- else // We found a page, we set pageid to it.
+ } else {
+ $res = $objectpage->fetch(0, $object->id, ''); // We search first page of web site
+ if ($res == 0) { // Page was not found, we reset it
+ $objectpage = new WebsitePage($db);
+ } else // We found a page, we set pageid to it.
{
$pageid = $objectpage->id;
}
}
- }
- else // We have a valid page. We force pageid for the case we got the page with a fetch on ref.
+ } else // We have a valid page. We force pageid for the case we got the page with a fetch on ref.
{
$pageid = $objectpage->id;
}
@@ -165,20 +199,23 @@ if (($pageid > 0 || $pageref) && $action != 'addcontainer')
}
// Define pageid if pageid and pageref not received as parameter or was wrong
-if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createcontainer')
-{
+if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createcontainer') {
$pageid = $object->fk_default_home;
- if (empty($pageid))
- {
+ if (empty($pageid)) {
$array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
- if (!is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors);
+ if (!is_array($array) && $array < 0) {
+ dol_print_error('', $objectpage->error, $objectpage->errors);
+ }
$atleastonepage = (is_array($array) && count($array) > 0);
$firstpageid = 0; $homepageid = 0;
- foreach ($array as $key => $valpage)
- {
- if (empty($firstpageid)) $firstpageid = $valpage->id;
- if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid = $valpage->id;
+ foreach ($array as $key => $valpage) {
+ if (empty($firstpageid)) {
+ $firstpageid = $valpage->id;
+ }
+ if ($object->fk_default_home && $key == $object->fk_default_home) {
+ $homepageid = $valpage->id;
+ }
}
$pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
}
@@ -267,9 +304,15 @@ $manifestjsoncontentdefault .= '{
$listofpages = array();
$algo = '';
-if (GETPOST('optionmeta')) $algo .= 'meta';
-if (GETPOST('optioncontent')) $algo .= 'content';
-if (GETPOST('optionsitefiles')) $algo .= 'sitefiles';
+if (GETPOST('optionmeta')) {
+ $algo .= 'meta';
+}
+if (GETPOST('optioncontent')) {
+ $algo .= 'content';
+}
+if (GETPOST('optionsitefiles')) {
+ $algo .= 'sitefiles';
+}
if (empty($sortfield)) {
if ($action == 'file_manager') {
@@ -301,43 +344,49 @@ $permissiontodelete = $user->rights->website->delete;
*/
// Protections
-if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x'))
-{
+if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) {
$action = 'preview'; // To avoid to make an action on another page or another site when we click on button to select another site or page.
}
-if (GETPOST('refreshsite', 'alpha') || GETPOST('refreshsite.x', 'alpha') || GETPOST('refreshsite_x', 'alpha')) // If we change the site, we reset the pageid and cancel addsite action.
-{
- if ($action == 'addsite') $action = 'preview';
- if ($action == 'updatesource') $action = 'preview';
+if (GETPOST('refreshsite', 'alpha') || GETPOST('refreshsite.x', 'alpha') || GETPOST('refreshsite_x', 'alpha')) { // If we change the site, we reset the pageid and cancel addsite action.
+ if ($action == 'addsite') {
+ $action = 'preview';
+ }
+ if ($action == 'updatesource') {
+ $action = 'preview';
+ }
$pageid = $object->fk_default_home;
- if (empty($pageid))
- {
+ if (empty($pageid)) {
$array = $objectpage->fetchAll($object->id, 'ASC,ASC', 'type_container,pageurl');
- if (!is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors);
+ if (!is_array($array) && $array < 0) {
+ dol_print_error('', $objectpage->error, $objectpage->errors);
+ }
$atleastonepage = (is_array($array) && count($array) > 0);
$firstpageid = 0; $homepageid = 0;
- foreach ($array as $key => $valpage)
- {
- if (empty($firstpageid)) $firstpageid = $valpage->id;
- if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid = $valpage->id;
+ foreach ($array as $key => $valpage) {
+ if (empty($firstpageid)) {
+ $firstpageid = $valpage->id;
+ }
+ if ($object->fk_default_home && $key == $object->fk_default_home) {
+ $homepageid = $valpage->id;
+ }
}
$pageid = ($homepageid ? $homepageid : $firstpageid); // We choose home page and if not defined yet, we take first page
}
}
-if (GETPOST('refreshpage', 'alpha') && !in_array($action, array('updatecss'))) $action = 'preview';
+if (GETPOST('refreshpage', 'alpha') && !in_array($action, array('updatecss'))) {
+ $action = 'preview';
+}
if ($cancel && $action == 'renamefile') {
$cancel = '';
}
// Cancel
-if ($cancel)
-{
+if ($cancel) {
$action = 'preview';
- if ($backtopage)
- {
+ if ($backtopage) {
header("Location: ".$backtopage);
exit;
}
@@ -345,8 +394,12 @@ if ($cancel)
$savbacktopage = $backtopage;
$backtopage = $_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid.(GETPOST('section_dir', 'alpha') ? '§ion_dir='.urlencode(GETPOST('section_dir', 'alpha')) : ''); // used after a confirm_deletefile into actions_linkedfiles.inc.php
-if ($sortfield) $backtopage .= '&sortfield='.$sortfield;
-if ($sortorder) $backtopage .= '&sortorder='.$sortorder;
+if ($sortfield) {
+ $backtopage .= '&sortfield='.$sortfield;
+}
+if ($sortorder) {
+ $backtopage .= '&sortorder='.$sortorder;
+}
include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
$backtopage = $savbacktopage;
@@ -354,43 +407,37 @@ if ($action == 'renamefile') { // Must be after include DOL_DOCUMENT_ROOT.'/core
$action = 'file_manager';
}
-if ($action == 'seteditinline')
-{
+if ($action == 'seteditinline') {
dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 1);
setEventMessages($langs->trans("FeatureNotYetAvailable"), null, 'warnings');
//dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 0); // Force disable of 'Include dynamic content'
header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
exit;
}
-if ($action == 'unseteditinline')
-{
+if ($action == 'unseteditinline') {
dolibarr_del_const($db, 'WEBSITE_EDITINLINE');
header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
exit;
}
-if ($action == 'setshowsubcontainers')
-{
+if ($action == 'setshowsubcontainers') {
dolibarr_set_const($db, 'WEBSITE_SUBCONTAINERSINLINE', 1);
//dolibarr_set_const($db, 'WEBSITE_EDITINLINE', 0); // Force disable of edit inline
header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
exit;
}
-if ($action == 'unsetshowsubcontainers')
-{
+if ($action == 'unsetshowsubcontainers') {
dolibarr_del_const($db, 'WEBSITE_SUBCONTAINERSINLINE');
header("Location: ".$_SERVER["PHP_SELF"].'?website='.GETPOST('website', 'alphanohtml').'&pageid='.GETPOST('pageid', 'int'));
exit;
}
-if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && !$searchkey)
-{
+if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha') && !$searchkey) {
$action = 'replacesite';
$massaction = '';
}
// Set category
-if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit)
-{
+if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $usercanedit) {
$error = 0;
$nbupdate = 0;
@@ -429,17 +476,14 @@ if ($massaction == 'setcategory' && GETPOST('confirmmassaction', 'alpha') && $us
}
// Replacement of string into pages
-if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha'))
-{
+if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha')) {
$replacestring = GETPOST('replacestring', 'none');
if (empty($user->rights->website->writephp)) {
setEventMessages("NotAllowedToAddDynamicContent", null, 'errors');
- }
- elseif (!$replacestring) {
+ } elseif (!$replacestring) {
setEventMessages("ErrorReplaceStringEmpty", null, 'errors');
- }
- else {
+ } else {
$nbreplacement = 0;
foreach ($toselect as $keyselected) {
@@ -461,15 +505,13 @@ if ($massaction == 'replace' && GETPOST('confirmmassaction', 'alpha'))
// Save page alias
$result = dolSavePageAlias($filealias, $object, $objectpage);
- if (!$result)
- {
+ if (!$result) {
setEventMessages('Failed to write file '.basename($filealias), null, 'errors');
}
// Save page of content
$result = dolSavePageContent($filetpl, $object, $objectpage);
- if ($result)
- {
+ if ($result) {
$nbreplacement++;
//var_dump($objectpage->content);exit;
$objectpage->update($user);
@@ -524,31 +566,26 @@ if ($action == 'adddir' && $permtouploadfile)
*/
// Add site
-if ($action == 'addsite')
-{
+if ($action == 'addsite') {
$db->begin();
- if (GETPOST('virtualhost', 'alpha') && !preg_match('/^http/', GETPOST('virtualhost', 'alpha')))
- {
+ if (GETPOST('virtualhost', 'alpha') && !preg_match('/^http/', GETPOST('virtualhost', 'alpha'))) {
$error++;
setEventMessages($langs->trans('ErrorURLMustStartWithHttp', $langs->transnoentitiesnoconv("VirtualHost")), null, 'errors');
}
- if (!$error && !GETPOST('WEBSITE_REF', 'alpha'))
- {
+ if (!$error && !GETPOST('WEBSITE_REF', 'alpha')) {
$error++;
$langs->load("errors");
setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
}
- if (!$error && !preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF', 'alpha')))
- {
+ if (!$error && !preg_match('/^[a-z0-9_\-\.]+$/i', GETPOST('WEBSITE_REF', 'alpha'))) {
$error++;
$langs->load("errors");
setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors');
}
- if (!$error)
- {
+ if (!$error) {
$arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml'));
foreach ($arrayotherlang as $key => $val) {
$arrayotherlang[$key] = substr(trim($val), 0, 2); // Kept short language code only
@@ -562,75 +599,64 @@ if ($action == 'addsite')
$tmpobject->virtualhost = GETPOST('virtualhost', 'alpha');
$result = $tmpobject->create($user);
- if ($result <= 0)
- {
+ if ($result <= 0) {
$error++;
setEventMessages($tmpobject->error, $tmpobject->errors, 'errors');
}
}
- if (!$error)
- {
+ if (!$error) {
$db->commit();
setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs');
$action = '';
header("Location: ".$_SERVER["PHP_SELF"].'?website='.$tmpobject->ref);
exit;
- }
- else {
+ } else {
$db->rollback();
$action = 'createsite';
}
- if (!$error)
- {
+ if (!$error) {
$action = 'preview';
$id = $object->id;
}
}
// Add page/container
-if ($action == 'addcontainer')
-{
+if ($action == 'addcontainer') {
dol_mkdir($pathofwebsite);
$db->begin();
$objectpage->fk_website = $object->id;
- if (GETPOSTISSET('fetchexternalurl')) // Fetch from external url
- {
+ if (GETPOSTISSET('fetchexternalurl')) { // Fetch from external url
$urltograb = GETPOST('externalurl', 'alpha');
$grabimages = GETPOST('grabimages', 'alpha');
$grabimagesinto = GETPOST('grabimagesinto', 'alpha');
include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
- if (empty($urltograb))
- {
+ if (empty($urltograb)) {
$error++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("URL")), null, 'errors');
$action = 'createcontainer';
- }
- elseif (!preg_match('/^http/', $urltograb))
- {
+ } elseif (!preg_match('/^http/', $urltograb)) {
$error++;
$langs->load("errors");
setEventMessages('Error URL must start with http:// or https://', null, 'errors');
$action = 'createcontainer';
}
- if (!$error)
- {
+ if (!$error) {
// Clean url to grab, so url can be
// http://www.example.com/ or http://www.example.com/dir1/ or http://www.example.com/dir1/aaa
$urltograbwithoutdomainandparam = preg_replace('/^https?:\/\/[^\/]+\/?/i', '', $urltograb);
//$urltograbwithoutdomainandparam = preg_replace('/^file:\/\/[^\/]+\/?/i', '', $urltograb);
$urltograbwithoutdomainandparam = preg_replace('/\?.*$/', '', $urltograbwithoutdomainandparam);
- if (empty($urltograbwithoutdomainandparam) && !preg_match('/\/$/', $urltograb))
- {
+ if (empty($urltograbwithoutdomainandparam) && !preg_match('/\/$/', $urltograb)) {
$urltograb .= '/';
}
$pageurl = dol_sanitizeFileName(preg_replace('/[\/\.]/', '-', preg_replace('/\/+$/', '', $urltograbwithoutdomainandparam)));
@@ -642,34 +668,27 @@ if ($action == 'addcontainer')
}
// Check pageurl is not already used
- if ($pageurl)
- {
+ if ($pageurl) {
$tmpwebsitepage = new WebsitePage($db);
$result = $tmpwebsitepage->fetch(0, $object->id, $pageurl);
- if ($result > 0)
- {
+ if ($result > 0) {
setEventMessages($langs->trans("AliasPageAlreadyExists", $pageurl), null, 'errors');
$error++;
$action = 'createcontainer';
}
}
- if (!$error)
- {
+ if (!$error) {
$tmp = getURLContent($urltograb);
- if ($tmp['curl_error_no'])
- {
+ if ($tmp['curl_error_no']) {
$error++;
setEventMessages('Error getting '.$urltograb.': '.$tmp['curl_error_msg'], null, 'errors');
$action = 'createcontainer';
- }
- elseif ($tmp['http_code'] != '200')
- {
+ } elseif ($tmp['http_code'] != '200') {
$error++;
setEventMessages('Error getting '.$urltograb.': '.$tmp['http_code'], null, 'errors');
$action = 'createcontainer';
- }
- else {
+ } else {
// Remove comments
$tmp['content'] = removeHtmlComment($tmp['content']);
@@ -679,36 +698,34 @@ if ($action == 'addcontainer')
$head = $regs[1];
$objectpage->type_container = 'page';
- $objectpage->pageurl = $pageurl;
- if (empty($objectpage->pageurl))
- {
- $tmpdomain = getDomainFromURL($urltograb);
- $objectpage->pageurl = $tmpdomain.'-home';
- }
+ $objectpage->pageurl = $pageurl;
+ if (empty($objectpage->pageurl)) {
+ $tmpdomain = getDomainFromURL($urltograb);
+ $objectpage->pageurl = $tmpdomain.'-home';
+ }
- $objectpage->aliasalt = '';
+ $objectpage->aliasalt = '';
- if (preg_match('/^(\d+)\-/', basename($urltograb), $regs)) $objectpage->aliasalt = $regs[1];
+ if (preg_match('/^(\d+)\-/', basename($urltograb), $regs)) {
+ $objectpage->aliasalt = $regs[1];
+ }
- $regtmp = array();
- if (preg_match('/(.*)<\/title>/ims', $head, $regtmp))
- {
+ $regtmp = array();
+ if (preg_match('/(.*)<\/title>/ims', $head, $regtmp)) {
$objectpage->title = $regtmp[1];
}
- if (preg_match('/title)) $objectpage->title = $regtmp[1]; // If title not found into , we get it from
+ if (preg_match('/title)) {
+ $objectpage->title = $regtmp[1]; // If title not found into , we get it from
+ }
}
- if (preg_match('/description = $regtmp[1];
}
- if (preg_match('/keywords = $regtmp[1];
}
- if (preg_match('/lang = $tmplang[0].($tmplang[1] ? '_'.strtoupper($tmplang[1]) : '');
}
@@ -749,22 +766,18 @@ if ($action == 'addcontainer')
// We grab files found into