--- /tmp/dsg/dolibarr/htdocs/website/class/github_19.0.3_website.class.php +++ /tmp/dsg/dolibarr/htdocs/website/class/client_website.class.php @@ -33 +32,0 @@ - @@ -50,2 +49 @@ - * @var int Does this object support multicompany module ? - * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table + * @var array Does website support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe @@ -55,4 +52,0 @@ - - protected $childtablesoncascade = array(); - - @@ -95 +89 @@ - * @var integer date_creation + * @var integer|string date_creation @@ -100 +94 @@ - * @var integer date_modification + * @var integer|string date_modification @@ -103,7 +97,3 @@ - /** - * @var integer date_modification - */ - public $tms; - - /** - * @var integer Default home page + + /** + * @var integer @@ -112,4 +101,0 @@ - - /** - * @var int User Create Id - */ @@ -119,6 +105 @@ - * @var int User Modification Id - */ - public $fk_user_modif; - - /** - * @var string Virtual host + * @var string @@ -129 +110 @@ - * @var int Use a manifest file + * @var int @@ -134,6 +115,3 @@ - * @var int Postion - */ - public $position; - - /** - * @var array List of containers + * List of containers + * + * @var array @@ -155,0 +134 @@ + return 1; @@ -161,4 +140,4 @@ - * @param User $user User that creates - * @param bool $notrigger false=launch triggers after, true=disable triggers - * - * @return int Return integer <0 if KO, 0 if already exists, ID of created object if OK + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, Id of created object if OK @@ -177 +156 @@ - $this->entity = (int) $this->entity; + $this->entity = (int) $this->entity; @@ -180 +159 @@ - $this->ref = trim($this->ref); + $this->ref = trim($this->ref); @@ -183 +162 @@ - $this->description = trim($this->description); + $this->description = trim($this->description); @@ -186,11 +165,11 @@ - $this->status = (int) $this->status; - } - if (empty($this->date_creation)) { - $this->date_creation = $now; - } - if (empty($this->date_modification)) { - $this->date_modification = $now; - } - // Remove spaces and be sure we have main language only - $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en - $tmparray = explode(',', $this->otherlang); + $this->status = (int) $this->status; + } + if (empty($this->date_creation)) { + $this->date_creation = $now; + } + if (empty($this->date_modification)) { + $this->date_modification = $now; + } + // Remove spaces and be sure we have main language only + $this->lang = preg_replace('/[_-].*$/', '', trim($this->lang)); // en_US or en-US -> en + $tmparray = explode(',', $this->otherlang); @@ -199,5 +177,0 @@ - // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,' - if (empty(trim($val))) { - unset($tmparray[$key]); - continue; - } @@ -209,8 +183,8 @@ - // Check parameters - if (empty($this->entity)) { - $this->entity = $conf->entity; - } - if (empty($this->lang)) { - $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MainLanguage")); - return -1; - } + // Check parameters + if (empty($this->entity)) { + $this->entity = $conf->entity; + } + if (empty($this->lang)) { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MainLanguage")); + return -1; + } @@ -230 +203,0 @@ - $sql .= 'position,'; @@ -243 +215,0 @@ - $sql .= ' '.((int) $this->position).","; @@ -259 +231 @@ - // Create a subdirectory for each language (except main language) + // Create subdirectory per language @@ -264,4 +236,2 @@ - if (trim($val) == $this->lang) { - continue; - } - dol_mkdir($conf->website->dir_output.'/'.$this->ref.'/'.trim($val), DOL_DATA_ROOT); + if (trim($val) == $this->lang) continue; + dol_mkdir($conf->website->dir_output.'/'.$this->ref.'/'.trim($val)); @@ -271,21 +241,17 @@ - // Create subdirectory for images and js - dol_mkdir($conf->medias->multidir_output[$conf->entity].'/image/'.$this->ref, DOL_DATA_ROOT); - dol_mkdir($conf->medias->multidir_output[$conf->entity].'/js/'.$this->ref, DOL_DATA_ROOT); - - // Uncomment this and change WEBSITE to your own tag if you - // want this action to call a trigger. - // if (!$notrigger) { - - // // Call triggers - // $result = $this->call_trigger('WEBSITE_CREATE',$user); - // if ($result < 0) $error++; - // // End call triggers - // } - } - - if (!$error) { - $stringtodolibarrfile = "# Some properties for Dolibarr web site CMS\n"; - $stringtodolibarrfile .= "param=value\n"; - //print $conf->website->dir_output.'/'.$this->ref.'/.dolibarr';exit; - file_put_contents($conf->website->dir_output.'/'.$this->ref.'/.dolibarr', $stringtodolibarrfile); - } + // Uncomment this and change MYOBJECT to your own tag if you + // want this action to call a trigger. + // if (!$notrigger) { + + // // Call triggers + // $result = $this->call_trigger('MYOBJECT_CREATE',$user); + // if ($result < 0) $error++; + // // End call triggers + // } + } + + if (! $error) { + $stringtodolibarrfile = "# Some properties for Dolibarr web site CMS\n"; + $stringtodolibarrfile .= "param=value\n"; + //print $conf->website->dir_output.'/'.$this->ref.'/.dolibarr';exit; + file_put_contents($conf->website->dir_output.'/'.$this->ref.'/.dolibarr', $stringtodolibarrfile); + } @@ -296,5 +262,2 @@ - if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - return 0; - } else { - return -1 * $error; - } + + return -1 * $error; @@ -313 +276 @@ - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @return int <0 if KO, 0 if not found, >0 if OK @@ -319,2 +282,2 @@ - $sql = "SELECT"; - $sql .= " t.rowid,"; + $sql = 'SELECT'; + $sql .= ' t.rowid,'; @@ -323 +285,0 @@ - $sql .= " t.position,"; @@ -335,2 +297,2 @@ - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; - $sql .= " WHERE t.entity IN (".getEntity('website').")"; + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' WHERE t.entity IN ('.getEntity('website').')'; @@ -340 +302 @@ - $sql .= " AND t.rowid = ".(int) $id; + $sql .= ' AND t.rowid = '.(int) $id; @@ -353 +314,0 @@ - $this->position = $obj->position; @@ -389 +350 @@ - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @return int <0 if KO, 0 if not found, >0 if OK @@ -404,7 +365,8 @@ - * @param string $sortorder Sort Order - * @param string $sortfield Sort field - * @param int $limit offset limit - * @param int $offset offset limit - * @param array $filter filter array - * @param string $filtermode filter mode (AND or OR) - * @return array|int int <0 if KO, array of pages if OK + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * + * @return int <0 if KO, >0 if OK @@ -416,4 +378,2 @@ - $records = array(); - - $sql = "SELECT"; - $sql .= " t.rowid,"; + $sql = 'SELECT'; + $sql .= ' t.rowid,'; @@ -432,2 +392,2 @@ - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; - $sql .= " WHERE t.entity IN (".getEntity('website').")"; + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= ' WHERE t.entity IN ('.getEntity('website').')'; @@ -438 +398 @@ - $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'"; + $sqlwhere [] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; @@ -442 +402 @@ - $sql .= ' AND '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere); + $sql .= ' AND '.implode(' '.$filtermode.' ', $sqlwhere); @@ -449,2 +409,3 @@ - $sql .= $this->db->plimit($limit, $offset); - } + $sql .= ' '.$this->db->plimit($limit, $offset); + } + $this->records = array(); @@ -457,18 +418,18 @@ - $record = new self($this->db); - - $record->id = $obj->rowid; - - $record->entity = $obj->entity; - $record->ref = $obj->ref; - $record->description = $obj->description; - $record->lang = $obj->lang; - $record->otherlang = $obj->otherlang; - $record->status = $obj->status; - $record->fk_default_home = $obj->fk_default_home; - $record->virtualhost = $obj->virtualhost; - $record->fk_user_creat = $obj->fk_user_creat; - $record->fk_user_modif = $obj->fk_user_modif; - $record->date_creation = $this->db->jdate($obj->date_creation); - $record->date_modification = $this->db->jdate($obj->date_modification); - - $records[$record->id] = $record; + $line = new self($this->db); + + $line->id = $obj->rowid; + + $line->entity = $obj->entity; + $line->ref = $obj->ref; + $line->description = $obj->description; + $line->lang = $obj->lang; + $line->otherlang = $obj->otherlang; + $line->status = $obj->status; + $line->fk_default_home = $obj->fk_default_home; + $line->virtualhost = $obj->virtualhost; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + $line->date_creation = $this->db->jdate($obj->date_creation); + $line->date_modification = $this->db->jdate($obj->date_modification); + + $this->records[$line->id] = $line; @@ -478 +439 @@ - return $records; + return $num; @@ -493 +454 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -506 +467 @@ - $this->entity = (int) $this->entity; + $this->entity = (int) $this->entity; @@ -509 +470 @@ - $this->ref = trim($this->ref); + $this->ref = trim($this->ref); @@ -512 +473 @@ - $this->description = trim($this->description); + $this->description = trim($this->description); @@ -515 +476 @@ - $this->status = (int) $this->status; + $this->status = (int) $this->status; @@ -523,5 +483,0 @@ - // It possible we have empty val here if postparam WEBSITE_OTHERLANG is empty or set like this : 'en,,sv' or 'en,sv,' - if (empty(trim($val))) { - unset($tmparray[$key]); - continue; - } @@ -554 +510 @@ - $sql .= ' WHERE rowid='.((int) $this->id); + $sql .= ' WHERE rowid='.$this->id; @@ -574,3 +530 @@ - if (trim($val) == $this->lang) { - continue; - } + if (trim($val) == $this->lang) continue; @@ -582 +536 @@ - //$result=$this->call_trigger('WEBSITE_MODIFY',$user); + //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); @@ -602,4 +556,4 @@ - * @param User $user User that deletes - * @param bool $notrigger false=launch triggers, true=disable triggers - * - * @return int Return integer <0 if KO, >0 if OK + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, >0 if OK @@ -609,2 +562,0 @@ - global $conf; - @@ -618,2 +570,14 @@ - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'website_page'; - $sql .= ' WHERE fk_website = '.((int) $this->id); + if (!$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_DELETE',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + } + } + + if (!$error) { + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql .= ' WHERE rowid='.$this->id; @@ -629,8 +593,3 @@ - // Delete common code. This include execution of trigger. - $result = $this->deleteCommon($user, $notrigger); - if ($result <= 0) { - $error++; - } - - if (!$error && !empty($this->ref)) { - $pathofwebsite = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$this->ref; + if (!$error && !empty($this->ref)) + { + $pathofwebsite = DOL_DATA_ROOT.'/website/'.$this->ref; @@ -654 +613 @@ - * Load a website its id and create a new one in database. + * Load an object from its id and create a new one in database. @@ -665 +624 @@ - global $conf, $langs; + global $conf; @@ -671,8 +630 @@ - dol_syslog(__METHOD__, LOG_DEBUG); - - $newref = dol_sanitizeFileName($newref); - - if (empty($newref)) { - $this->error = 'ErrorBadParameter'; - return -1; - } + dol_syslog(__METHOD__, LOG_DEBUG); @@ -682,2 +634,3 @@ - // Check no site with ref exists - if ($object->fetch(0, $newref) > 0) { + // Check no site with ref exists + if ($object->fetch(0, $newref) > 0) + { @@ -696,2 +649,2 @@ - $pathofwebsiteold = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.dol_sanitizeFileName($oldref); - $pathofwebsitenew = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.dol_sanitizeFileName($newref); + $pathofwebsiteold = $dolibarr_main_data_root.'/website/'.$oldref; + $pathofwebsitenew = $dolibarr_main_data_root.'/website/'.$newref; @@ -713,5 +665,0 @@ - $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 - } @@ -724 +671,0 @@ - $this->error = $object->error; @@ -729 +676,2 @@ - if (!$error) { + if (!$error) + { @@ -735 +683,2 @@ - if (!is_link(dol_osencode($pathtomediasinwebsite))) { + if (!is_link(dol_osencode($pathtomediasinwebsite))) + { @@ -755 +704,2 @@ - foreach ($listofpages as $pageid => $objectpageold) { + foreach ($listofpages as $pageid => $objectpageold) + { @@ -764,2 +714,3 @@ - if (is_object($objectpagenew) && $objectpagenew->pageurl) { - $filealias = $pathofwebsitenew.'/'.$objectpagenew->pageurl.'.php'; + if (is_object($objectpagenew) && $objectpagenew->pageurl) + { + $filealias = $pathofwebsitenew.'/'.$objectpagenew->pageurl.'.php'; @@ -770,3 +721 @@ - if (!$result) { - setEventMessages('Failed to write file '.$filealias, null, 'errors'); - } + if (!$result) setEventMessages('Failed to write file '.$filealias, null, 'errors'); @@ -775,5 +724,4 @@ - if (!$result) { - setEventMessages('Failed to write file '.$filetplnew, null, 'errors'); - } - - if ($pageid == $oldidforhome) { + if (!$result) setEventMessages('Failed to write file '.$filetplnew, null, 'errors'); + + if ($pageid == $oldidforhome) + { @@ -782 +730,3 @@ - } else { + } + else + { @@ -789 +739,2 @@ - if (!$error) { + if (!$error) + { @@ -792,14 +743,16 @@ - $res = $object->update($user); - if (!($res > 0)) { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - - if (!$error) { - $filetpl = $pathofwebsitenew.'/page'.$newidforhome.'.tpl.php'; - $filewrapper = $pathofwebsitenew.'/wrapper.php'; - - // Re-generates the index.php page to be the home page, and re-generates the wrapper.php - //-------------------------------------------------------------------------------------- - $result = dolSaveIndexPage($pathofwebsitenew, $fileindex, $filetpl, $filewrapper, $object); - } + $res = $object->update($user); + if (!$res > 0) + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + + if (!$error) + { + $filetpl = $pathofwebsitenew.'/page'.$newidforhome.'.tpl.php'; + $filewrapper = $pathofwebsitenew.'/wrapper.php'; + + // Generate the index.php page to be the home page + //------------------------------------------------- + $result = dolSaveIndexPage($pathofwebsitenew, $fileindex, $filetpl, $filewrapper); + } @@ -828,3 +781,3 @@ - * @param integer $notooltip 1=Disable tooltip - * @param int $maxlen Max length of visible user name - * @param string $morecss Add more css on link + * @param integer $notooltip 1=Disable tooltip + * @param int $maxlen Max length of visible user name + * @param string $morecss Add more css on link @@ -836,15 +789,15 @@ - global $dolibarr_main_authentication, $dolibarr_main_demo; - global $menumanager; - - - $result = ''; - $companylink = ''; - - $label = ''.$langs->trans("WebSite").''; - $label .= '
'; - $label .= ''.$langs->trans('Ref').': '.$this->ref.'
'; - $label .= ''.$langs->trans('MainLanguage').': '.$this->lang; - - $linkstart = 'trans("WebSite").''; + $label .= '
'; + $label .= ''.$langs->trans('Ref').': '.$this->ref.'
'; + $label .= ''.$langs->trans('MainLanguage').': '.$this->lang; + + $linkstart = '
picto ? $this->picto : 'generic'), ($notooltip ? '' : 'class="classfortooltip"')).$linkend); - if ($withpicto != 2) { - $result .= ' '; - } + if ($withpicto) + { + $result .= ($linkstart.img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? '' : 'class="classfortooltip"')).$linkend); + if ($withpicto != 2) $result .= ' '; @@ -866,3 +818,3 @@ - * Return the label of the status - * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * Retourne le libelle du status d'un user (actif, inactif) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto @@ -876,7 +828,7 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return the label of a given status - * - * @param int $status Id status - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un status donne + * + * @param int $status Id status + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of status @@ -886 +838 @@ - // phpcs:enable + // phpcs:enable @@ -889 +841,2 @@ - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { @@ -892,4 +845,4 @@ - $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline'); - $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online'); - $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline'); - $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online'); + $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Disabled'); + $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled'); + $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Disabled'); + $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled'); @@ -899,3 +852 @@ - if ($status == self::STATUS_VALIDATED) { - $statusType = 'status4'; - } + if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; @@ -915 +866 @@ - global $user; + global $user; @@ -918 +869 @@ - $this->specimen = 1; + @@ -924 +875 @@ - $this->status = 1; + $this->status = ''; @@ -945 +896,2 @@ - if (empty($website->id) || empty($website->ref)) { + if (empty($website->id) || empty($website->ref)) + { @@ -952 +904,2 @@ - if (!is_writable($conf->website->dir_temp)) { + if (!is_writable($conf->website->dir_temp)) + { @@ -960,2 +913 @@ - $count = 0; - $countreallydeleted = 0; + $count = 0; $countreallydeleted = 0; @@ -963 +915,2 @@ - if ($counttodelete != $countreallydeleted) { + if ($counttodelete != $countreallydeleted) + { @@ -975 +928 @@ - $arrayreplacementincss['file=logos%2Fthumbs%2F'.$mysoc->logo_small] = "file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__"; + $arrayreplacementincss['file=logos%2Fthumbs%2F'.$mysoc->logo_small] = "file=logos%2Fthumbs%2F__LOGO_SMALL_KEY__"; @@ -978 +931 @@ - $arrayreplacementincss['file=logos%2Fthumbs%2F'.$mysoc->logo_mini] = "file=logos%2Fthumbs%2F__LOGO_MINI_KEY__"; + $arrayreplacementincss['file=logos%2Fthumbs%2F'.$mysoc->logo_mini] = "file=logos%2Fthumbs%2F__LOGO_MINI_KEY__"; @@ -981 +934 @@ - $arrayreplacementincss['file=logos%2Fthumbs%2F'.$mysoc->logo] = "file=logos%2Fthumbs%2F__LOGO_KEY__"; + $arrayreplacementincss['file=logos%2Fthumbs%2F'.$mysoc->logo] = "file=logos%2Fthumbs%2F__LOGO_KEY__"; @@ -994,10 +947,2 @@ - dol_syslog("Copy pages from ".$srcdir." into ".$destdir); - dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename, 2, array('old', 'back')); - - // Copy file README.md and LICENSE from directory containers into directory root - if (dol_is_file($conf->website->dir_temp.'/'.$website->ref.'/containers/README.md')) { - dol_copy($conf->website->dir_temp.'/'.$website->ref.'/containers/README.md', $conf->website->dir_temp.'/'.$website->ref.'/README.md'); - } - if (dol_is_file($conf->website->dir_temp.'/'.$website->ref.'/containers/LICENSE')) { - dol_copy($conf->website->dir_temp.'/'.$website->ref.'/containers/LICENSE', $conf->website->dir_temp.'/'.$website->ref.'/LICENSE'); - } + dol_syslog("Copy content from ".$srcdir." into ".$destdir); + dolCopyDir($srcdir, $destdir, 0, 1, $arrayreplacementinfilename, 2); @@ -1021,3 +966 @@ - if (dol_is_file($cssindestdir)) { - dolReplaceInFile($cssindestdir, $arrayreplacementincss); - } + dolReplaceInFile($cssindestdir, $arrayreplacementincss); @@ -1026,3 +969 @@ - if (dol_is_file($htmldeaderindestdir)) { - dolReplaceInFile($htmldeaderindestdir, $arrayreplacementincss); - } + dolReplaceInFile($htmldeaderindestdir, $arrayreplacementincss); @@ -1033 +974,2 @@ - if (empty($fp)) { + if (empty($fp)) + { @@ -1043 +985,2 @@ - foreach ($listofpages as $pageid => $objectpageold) { + foreach ($listofpages as $pageid => $objectpageold) + { @@ -1048 +991,2 @@ - foreach ($listofpages as $pageid => $objectpageold) { + foreach ($listofpages as $pageid => $objectpageold) + { @@ -1051,2 +995,4 @@ - foreach ($listofpages as $pageid2 => $objectpageold2) { - if ($pageid2 == $objectpageold->fk_page) { + foreach ($listofpages as $pageid2 => $objectpageold2) + { + if ($pageid2 == $objectpageold->fk_page) + { @@ -1060 +1006,2 @@ - foreach ($listofpages as $pageid => $objectpageold) { + foreach ($listofpages as $pageid => $objectpageold) + { @@ -1064,4 +1011 @@ - $line = '-- File generated by Dolibarr '.DOL_VERSION.' -- '.dol_print_date(dol_now('gmt'), 'standard', 'gmt').' UTC --;'; - $line .= "\n"; - - $line .= '-- Page ID '.$objectpageold->id.' -> '.$objectpageold->newid.'__+MAX_llx_website_page__ - Aliases '.$allaliases.' --;'; // newid start at 1, 2... + $line = '-- Page ID '.$objectpageold->id.' -> '.$objectpageold->newid.'__+MAX_llx_website_page__ - Aliases '.$allaliases.' --;'; // newid start at 1, 2... @@ -1072 +1016 @@ - $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)'; + $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)'; @@ -1092 +1035,0 @@ - // Make substitution with a generic path into htmlheader content @@ -1099 +1041,0 @@ - @@ -1105 +1046,0 @@ - // Make substitution with a generic path into page content @@ -1112,5 +1052,0 @@ - $stringtoexport = str_replace('"image/'.$website->ref.'/', '"image/__WEBSITE_KEY__/', $stringtoexport); // When we have a link src="image/websiteref/file.png" into html content - $stringtoexport = str_replace('"/image/'.$website->ref.'/', '"/image/__WEBSITE_KEY__/', $stringtoexport); // When we have a link src="/image/websiteref/file.png" into html content - $stringtoexport = str_replace('"js/'.$website->ref.'/', '"js/__WEBSITE_KEY__/', $stringtoexport); - $stringtoexport = str_replace('"/js/'.$website->ref.'/', '"/js/__WEBSITE_KEY__/', $stringtoexport); - @@ -1120,0 +1057,2 @@ + // When we have a link src="image/websiteref/file.png" into html content + $stringtoexport = str_replace('="image/'.$website->ref.'/', '="image/__WEBSITE_KEY__/', $stringtoexport); @@ -1123,2 +1061 @@ - $line .= "'".$this->db->escape($objectpageold->author_alias)."', "; - $line .= (int) $objectpageold->allowed_in_frames; + $line .= "'".$this->db->escape($objectpageold->author_alias)."'"; @@ -1127 +1063,0 @@ - @@ -1132,3 +1068,4 @@ - 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__;"; + 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__;"; @@ -1140,6 +1076,0 @@ - $line = "\n-- For Dolibarr v14+ --;\n"; - $line .= "UPDATE llx_website SET lang = '".$this->db->escape($this->lang)."' WHERE rowid = __WEBSITE_ID__;\n"; - $line .= "UPDATE llx_website SET otherlang = '".$this->db->escape($this->otherlang)."' WHERE rowid = __WEBSITE_ID__;\n"; - $line .= "\n"; - fputs($fp, $line); - @@ -1147 +1078,2 @@ - dolChmod($filesql); + if (!empty($conf->global->MAIN_UMASK)) + @chmod($filesql, octdec($conf->global->MAIN_UMASK)); @@ -1157 +1089,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -1159 +1092,3 @@ - } else { + } + else + { @@ -1170,2 +1105,2 @@ - * @param string $pathtofile Full path of zip file - * @return int Return integer <0 if KO, Id of new website if OK + * @param string $pathtofile Path of zip file + * @return int <0 if KO, Id of new website if OK @@ -1179,2 +1113,0 @@ - $pathtofile = dol_sanitizePathName($pathtofile); - @@ -1182 +1115,2 @@ - if (empty($object->ref)) { + if (empty($object->ref)) + { @@ -1184,4 +1118,4 @@ - return -2; - } - - dol_delete_dir_recursive($conf->website->dir_temp."/".$object->ref); + return -1; + } + + dol_delete_dir_recursive($conf->website->dir_temp.'/'.$object->ref); @@ -1191 +1125,2 @@ - if (!preg_match('/^website_(.*)-(.*)$/', $filename, $reg)) { + if (!preg_match('/^website_(.*)-(.*)$/', $filename, $reg)) + { @@ -1193 +1128 @@ - return -3; + return -1; @@ -1198 +1133,2 @@ - if (!empty($result['error'])) { + if (!empty($result['error'])) + { @@ -1200 +1136 @@ - return -4; + return -1; @@ -1224 +1160,2 @@ - if (!$result) { + if (!$result) + { @@ -1232 +1169 @@ - $sqlfile = $conf->website->dir_temp."/".$object->ref.'/website_pages.sql'; + $sqlfile = $conf->website->dir_temp.'/'.$object->ref.'/website_pages.sql'; @@ -1241 +1178,2 @@ - if ($resql) { + if ($resql) + { @@ -1247,3 +1185,4 @@ - $runsql = run_sql($sqlfile, 1, '', 0, '', 'none', 0, 1, 0, 0, 1); // The maxrowid of table is searched into this function two - if ($runsql <= 0) { - $this->errors[] = 'Failed to load sql file '.$sqlfile.' (ret='.((int) $runsql).')'; + $runsql = run_sql($sqlfile, 1, '', 0, '', 'none', 0, 1); // The maxrowid of table is searched into this function two + if ($runsql <= 0) + { + $this->errors[] = 'Failed to load sql file '.$sqlfile; @@ -1257,2 +1196,4 @@ - if ($fp) { - while (!feof($fp)) { + if ($fp) + { + while (!feof($fp)) + { @@ -1263 +1204,2 @@ - 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)) + { @@ -1283,3 +1225,6 @@ - if (is_array($aliasesarray)) { - foreach ($aliasesarray as $aliasshortcuttocreate) { - if (trim($aliasshortcuttocreate)) { + if (is_array($aliasesarray)) + { + foreach ($aliasesarray as $aliasshortcuttocreate) + { + if (trim($aliasshortcuttocreate)) + { @@ -1301 +1246 @@ - $sql = "SELECT fk_default_home FROM ".MAIN_DB_PREFIX."website WHERE rowid = ".((int) $object->id); + $sql = 'SELECT fk_default_home FROM '.MAIN_DB_PREFIX.'website WHERE rowid = '.$object->id; @@ -1315,3 +1260,4 @@ - dolSaveIndexPage($pathofwebsite, $pathofwebsite.'/index.php', $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php', $pathofwebsite.'/wrapper.php', $object); - - if ($error) { + dolSaveIndexPage($pathofwebsite, $pathofwebsite.'/index.php', $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php', $pathofwebsite.'/wrapper.php'); + + if ($error) + { @@ -1320 +1266,3 @@ - } else { + } + else + { @@ -1327 +1275 @@ - * Rebuild all files of all the pages/containers of a website. Rebuild also the index and wrapper.php file. + * Rebuild all files of a containers of a website. TODO Add other files too. @@ -1330 +1278 @@ - * @return int Return integer <0 if KO, >=0 if OK + * @return int <0 if KO, >=0 if OK @@ -1339,2 +1287,3 @@ - if (empty($object->ref)) { - $this->error = 'Function rebuildWebSiteFiles called on object not loaded (object->ref is empty)'; + if (empty($object->ref)) + { + $this->error = 'Function importWebSite called on object not loaded (object->ref is empty)'; @@ -1346 +1295 @@ - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."website_page WHERE fk_website = ".((int) $this->id); + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'website_page WHERE fk_website = '.$this->id; @@ -1349 +1298 @@ - if (!$resql) { + if (! $resql) { @@ -1356,2 +1305 @@ - // Loop on each container/page - $i = 0; + $i=0; @@ -1374,9 +1322,7 @@ - // Add main alias to list of alternative aliases - if (!empty($objectpagestatic->pageurl) && !in_array($objectpagestatic->pageurl, $aliasesarray)) { - $aliasesarray[] = $objectpagestatic->pageurl; - } - - // Regenerate also all aliases pages (pages with a natural name) by calling dolSavePageAlias() - if (is_array($aliasesarray)) { - foreach ($aliasesarray as $aliasshortcuttocreate) { - if (trim($aliasshortcuttocreate)) { + // Regenerate alternative aliases pages + if (is_array($aliasesarray)) + { + foreach ($aliasesarray as $aliasshortcuttocreate) + { + if (trim($aliasshortcuttocreate)) + { @@ -1384 +1330 @@ - $result = dolSavePageAlias($filealias, $object, $objectpagestatic); // This includes also a copy into sublanguage directories. + $result = dolSavePageAlias($filealias, $object, $objectpagestatic); @@ -1396,13 +1342,2 @@ - if (!$error) { - // Save index.php and wrapper.php - $pathofwebsite = $conf->website->dir_output.'/'.$object->ref; - $fileindex = $pathofwebsite.'/index.php'; - $filetpl = ''; - if ($object->fk_default_home > 0) { - $filetpl = $pathofwebsite.'/page'.$object->fk_default_home.'.tpl.php'; - } - $filewrapper = $pathofwebsite.'/wrapper.php'; - dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper, $object); // This includes also a version of index.php into sublanguage directories - } - - if ($error) { + if ($error) + { @@ -1410 +1345,3 @@ - } else { + } + else + { @@ -1438,3 +1375 @@ - 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'; @@ -1450 +1385 @@ - 'zh'=>'zh_CN', + 'zh'=>'zh_TW', @@ -1473,8 +1408,7 @@ - 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 (!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) + { @@ -1486 +1420,2 @@ - if (!is_array($languagecodes) && $pageid > 0) { + if (!is_array($languagecodes) && $pageid > 0) + { @@ -1491,5 +1426,3 @@ - $sql .= " WHERE wp.fk_website = ".((int) $website->id); - $sql .= " AND (wp.fk_page = ".((int) $pageid)." OR wp.rowid = ".((int) $pageid); - if ($tmppage->fk_page > 0) { - $sql .= " OR wp.fk_page = ".((int) $tmppage->fk_page)." OR wp.rowid = ".((int) $tmppage->fk_page); - } + $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; @@ -1499,2 +1432,4 @@ - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { @@ -1502,6 +1437,2 @@ - 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; @@ -1514 +1445,2 @@ - if (!empty($websitepagefile)) { + if (!empty($websitepagefile)) + { @@ -1516 +1448,2 @@ - if ($pageid > 0) { + if ($pageid > 0) + { @@ -1519,3 +1452 @@ - 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 @@ -1532,3 +1463 @@ - if (!preg_match('/^\//', $url)) { - $url = '/'.$url; - } + if (! preg_match('/^\//', $url)) $url = '/'.$url; @@ -1564 +1493,2 @@ - if ($languagecodeselected) { + if ($languagecodeselected) + { @@ -1572,4 +1502,2 @@ - if ($countrycode == 'us') { - $label = preg_replace('/\s*\(.*\)/', '', $label); - } - $out .= '
  • '.$label.''; + if ($countrycode == 'us') $label = preg_replace('/\s*\(.*\)/', '', $label); + $out .= '
  • '.$label.''; @@ -1577 +1505 @@ - $out .= '
  • '; + $out .= ''; @@ -1580,28 +1508,24 @@ - 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 - } - - $countrycode = strtolower(substr($languagecode, -2)); - $label = $weblangs->trans("Language_".$languagecode); - if ($countrycode == 'us') { - $label = preg_replace('/\s*\(.*\)/', '', $label); - } - $out .= '
  • '.$label.''; - if (empty($i) && empty($languagecodeselected)) { - $out .= ''; - } - $out .= '
  • '; - $i++; - } - } - $out .= ''; - - return $out; - } + 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 + + $countrycode = strtolower(substr($languagecode, -2)); + $label = $weblangs->trans("Language_".$languagecode); + if ($countrycode == 'us') $label = preg_replace('/\s*\(.*\)/', '', $label); + $out .= '
  • '.$label.''; + if (empty($i) && empty($languagecodeselected)) $out .= ''; + $out .= '
  • '; + $i++; + } + } + $out .= ''; + + return $out; + } --- /tmp/dsg/dolibarr/htdocs/website/class/github_19.0.3_websitepage.class.php +++ /tmp/dsg/dolibarr/htdocs/website/class/client_websitepage.class.php @@ -6 +5,0 @@ - * Copyright (C) 2020 Nicolas ZABOURI @@ -53,14 +52,4 @@ - /** - * @var string Field with ID of parent key if this field has a parent or for child tables - */ - public $fk_element = 'fk_website_page'; - - /** - * @var array List of child tables. To know object to delete on cascade. - */ - protected $childtablesoncascade = array('categorie_website_page'); - - - /** - * @var int ID - */ + + /** + * @var int ID + */ @@ -68,2 +56,0 @@ - - public $fk_page; // If translation of another page @@ -96 +82,0 @@ - public $allowed_in_frames; @@ -116,3 +101,0 @@ - public $fk_user_creat; - public $fk_user_modif; - @@ -124,12 +107,3 @@ - /** - * @var string path of external object - */ - public $object_type; - - /** - * @var string id of external object - */ - public $fk_object; - - const STATUS_DRAFT = 0; // offline - const STATUS_VALIDATED = 1; // online + + const STATUS_DRAFT = 0; + const STATUS_VALIDATED = 1; @@ -156 +130 @@ - * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") + * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") @@ -164,2 +138,2 @@ - * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. - */ + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. + */ @@ -167 +141 @@ - 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), + 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), @@ -172 +146 @@ - 'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1), + 'description' =>array('type'=>'varchar(255)', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1), @@ -177,5 +151,4 @@ - 'fk_website' =>array('type'=>'integer', 'label'=>'WebsiteId', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>40, 'searchall'=>0, 'foreignkey'=>'websitepage.rowid'), - 'fk_page' =>array('type'=>'integer', 'label'=>'ParentPageId', 'enabled'=>1, 'visible'=>1, 'notnull'=>-1, 'position'=>45, 'searchall'=>0, 'foreignkey'=>'website.rowid'), - 'allowed_in_frames' =>array('type'=>'integer', 'label'=>'AllowedInFrames', 'enabled'=>1, 'visible'=>-1, 'position'=>48, 'searchall'=>0, 'default'=>0), - 'htmlheader' =>array('type'=>'html', 'label'=>'HtmlHeader', 'enabled'=>1, 'visible'=>0, 'position'=>50, 'searchall'=>0), - 'content' =>array('type'=>'mediumtext', 'label'=>'Content', 'enabled'=>1, 'visible'=>0, 'position'=>51, 'searchall'=>0), + 'fk_website' =>array('type'=>'integer', 'label'=>'WebsiteId', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>40, 'searchall'=>0, 'foreignkey'=>'websitepage.rowid'), + 'fk_page' =>array('type'=>'integer', 'label'=>'ParentPageId', 'enabled'=>1, 'visible'=>1, 'notnull'=>-1, 'position'=>45, 'searchall'=>0, 'foreignkey'=>'website.rowid'), + 'htmlheader' =>array('type'=>'text', 'label'=>'HtmlHeader', 'enabled'=>1, 'visible'=>0, 'position'=>50, 'searchall'=>0), + 'content' =>array('type'=>'mediumtext', 'label'=>'Content', 'enabled'=>1, 'visible'=>0, 'position'=>51, 'searchall'=>0), @@ -183 +156 @@ - 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500), + 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500), @@ -191,2 +163,0 @@ - 'object_type' => array('type' => 'varchar(255)', 'label' => 'ObjectType', 'enabled'=>1, 'visible'=>0, 'position'=>46, 'searchall'=>0, 'help'=>''), - 'fk_object' => array('type' => 'varchar(255)', 'label' => 'ObjectId', 'enabled'=>1, 'visible'=>0, 'position'=>47, 'searchall'=>0, 'help'=>'') @@ -196,0 +168,29 @@ + // If this object has a subtable with lines + + /** + * @var int Name of subtable line + */ + //public $table_element_line = 'mymodule_myobjectline'; + + /** + * @var int Field with ID of parent key if this field has a parent or for child tables + */ + public $fk_element = 'fk_website_page'; + + /** + * @var int Name of subtable class that manage subtable lines + */ + //public $class_element_line = 'MyObjectline'; + + /** + * @var array List of child tables. To test if we can delete object. + */ + //protected $childtables=array(); + + /** + * @var array List of child tables. To know object to delete on cascade. + */ + protected $childtablesoncascade = array('categorie_website_page'); + + + @@ -212 +212 @@ - * @return int Return integer <0 if KO, Id of created object if OK + * @return int <0 if KO, Id of created object if OK @@ -218,7 +218 @@ - if ($this->aliasalt) { - $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,' - } - - $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl); - $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl); - $this->pageurl = preg_replace('/^\-/', '', $this->pageurl); + if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,' @@ -242 +236 @@ - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @return int <0 if KO, 0 if not found, >0 if OK @@ -262 +255,0 @@ - $sql .= " t.allowed_in_frames,"; @@ -270,3 +263 @@ - $sql .= " t.import_key,"; - $sql .= " t.object_type,"; - $sql .= " t.fk_object"; + $sql .= " t.import_key"; @@ -276,6 +267,7 @@ - if ($id > 0) { - $sql .= ' AND t.rowid = '.((int) $id); - } else { - if ($id < 0) { - $sql .= ' AND t.rowid <> '.abs($id); - } + if ($id > 0) + { + $sql .= ' AND t.rowid = '.$id; + } + else + { + if ($id < 0) $sql .= ' AND t.rowid <> '.abs($id); @@ -283,22 +275,16 @@ - $sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'"; - if ($page) { - $pagetouse = $page; - $langtouse = ''; - $tmppage = explode('/', $page); - if (!empty($tmppage[1])) { - $pagetouse = $tmppage[1]; - 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 ($aliasalt) { - $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')"; - } - } - } - $sql .= $this->db->plimit(1); + $sql .= " AND t.fk_website = '".$this->db->escape($website_id)."'"; + if ($page) { + $pagetouse = $page; + $langtouse = ''; + $tmppage = explode('/', $page); + if (!empty($tmppage[1])) { + $pagetouse = $tmppage[1]; + 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 ($aliasalt) $sql .= " AND (t.aliasalt LIKE '%,".$this->db->escape($aliasalt).",%' OR t.aliasalt LIKE '%, ".$this->db->escape($aliasalt).",%')"; + } + } + $sql .= $this->db->plimit(1); @@ -329 +314,0 @@ - $this->allowed_in_frames = $obj->allowed_in_frames; @@ -338,2 +322,0 @@ - $this->object_type = $obj->object_type; - $this->fk_object = $obj->fk_object; @@ -388 +370,0 @@ - $sql .= " t.allowed_in_frames,"; @@ -396,3 +378 @@ - $sql .= " t.import_key,"; - $sql .= " t.object_type,"; - $sql .= " t.fk_object"; + $sql .= " t.import_key"; @@ -400,2 +380,2 @@ - $sql .= ' WHERE t.fk_website = '.((int) $websiteid); - // Manage filter (same than into countAll) + $sql .= ' WHERE t.fk_website = '.$websiteid; + // Manage filter @@ -405,4 +385,4 @@ - if ($key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status') { - $sqlwhere[] = $key." = ".((int) $value); - } elseif ($key == 'type_container' || $key == 't.type_container') { - $sqlwhere[] = $key." = '".$this->db->escape($value)."'"; + if ($key == 't.rowid' || $key == 't.fk_website' || $key == 'status') { + $sqlwhere[] = $key.'='.$value; + } elseif ($key == 'type_container') { + $sqlwhere[] = $key."='".$value."'"; @@ -412 +392 @@ - foreach (explode(',', $value) as $tmpvalue) { + foreach(explode(',', $value) as $tmpvalue) { @@ -419,4 +399,2 @@ - $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")"; - if ($foundnull) { - $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)"; - } + $stringtouse = $key." IN (".join(',', $listoflang).")"; + if ($foundnull) $stringtouse = '('.$stringtouse.' OR '.$key.' IS NULL)'; @@ -425 +403 @@ - $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'"; + $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; @@ -430 +408 @@ - $sql .= " AND (".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')'; + $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')'; @@ -437 +415 @@ - $sql .= $this->db->plimit($limit, $offset); + $sql .= ' '.$this->db->plimit($limit, $offset); @@ -444 +422,2 @@ - while ($obj = $this->db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) + { @@ -460 +438,0 @@ - $record->allowed_in_frames = $obj->allowed_in_frames; @@ -469,2 +446,0 @@ - $record->object_type = $obj->object_type; - $record->fk_object = $obj->fk_object; @@ -502,2 +478,2 @@ - $sql .= ' WHERE t.fk_website = '.((int) $websiteid); - // Manage filter (same than into fetchAll) + $sql .= ' WHERE t.fk_website = '.$websiteid; + // Manage filter @@ -507,4 +483,2 @@ - if ($key == 't.rowid' || $key == 't.fk_website' || $key == 'status') { - $sqlwhere[] = $key." = ".((int) $value); - } elseif ($key == 'type_container') { - $sqlwhere[] = $key." = '".$this->db->escape($value)."'"; + if ($key == 't.rowid' || $key == 't.fk_website') { + $sqlwhere[] = $key.'='.$value; @@ -512,14 +486 @@ - $listoflang = array(); - $foundnull = 0; - foreach (explode(',', $value) as $tmpvalue) { - if ($tmpvalue == 'null') { - $foundnull++; - continue; - } - $listoflang[] = "'".$this->db->escape(substr(str_replace("'", '', $tmpvalue), 0, 2))."'"; - } - $stringtouse = $key." IN (".$this->db->sanitize(join(',', $listoflang), 1).")"; - if ($foundnull) { - $stringtouse = "(".$stringtouse." OR ".$key." IS NULL)"; - } - $sqlwhere[] = $stringtouse; + $sqlwhere[] = $key." = '".$this->db->escape(substr($value, 0, 2))."'"; @@ -527 +488 @@ - $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'"; + $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; @@ -532 +493 @@ - $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')'; + $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')'; @@ -559 +520 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -565,7 +526 @@ - if ($this->aliasalt) { - $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,' - } - - $this->pageurl = preg_replace('/[^a-z0-9\-\_]/i', '', $this->pageurl); - $this->pageurl = preg_replace('/\-\-+/', '-', $this->pageurl); - $this->pageurl = preg_replace('/^\-/', '', $this->pageurl); + if ($this->aliasalt) $this->aliasalt = ','.preg_replace('/,+$/', '', preg_replace('/^,+/', '', $this->aliasalt)).','; // content in database must be ',xxx,...,yyy,' @@ -597 +552 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -601,2 +555,0 @@ - global $conf; - @@ -607 +560,2 @@ - foreach ($this->childtablesoncascade as $table) { + foreach ($this->childtablesoncascade as $table) + { @@ -621,2 +575,3 @@ - $result = $this->deleteCommon($user, $notrigger); - if ($result <= 0) { + $result = $this->deleteCommon($user, $trigger); + if ($result <= 0) + { @@ -627 +582,2 @@ - if (!$error) { + if (!$error) + { @@ -631 +587,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -633 +590 @@ - $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/'.$websiteobj->ref; + $pathofwebsite = $dolibarr_main_data_root.'/website/'.$websiteobj->ref; @@ -646 +603 @@ - if (!$error) { + if (! $error) { @@ -703,12 +660,4 @@ - $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; @@ -716 +664,0 @@ - $object->status = self::STATUS_DRAFT; @@ -748,3 +696,3 @@ - * @param integer $notooltip 1=Disable tooltip - * @param int $maxlen Max length of visible user name - * @param string $morecss Add more css on link + * @param integer $notooltip 1=Disable tooltip + * @param int $maxlen Max length of visible user name + * @param string $morecss Add more css on link @@ -756,28 +704,29 @@ - global $dolibarr_main_authentication, $dolibarr_main_demo; - global $menumanager; - - $result = ''; - - $label = ''.$langs->trans("Page").''; - $label .= '
    '; - $label .= ''.$langs->trans('Ref').': '.$this->ref.'
    '; - $label .= ''.$langs->trans('ID').': '.$this->id.'
    '; - $label .= ''.$langs->trans('Title').': '.$this->title.'
    '; - $label .= ''.$langs->trans('Language').': '.$this->lang; - - $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id; - - $linkclose = ''; - if (empty($notooltip)) { - if (getDolGlobalString('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.'"' : ''); - } - - $linkstart = ''; + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; + + $result = ''; + + $label = ''.$langs->trans("Page").''; + $label .= '
    '; + $label .= ''.$langs->trans('Ref').': '.$this->ref.'
    '; + $label .= ''.$langs->trans('ID').': '.$this->id.'
    '; + $label .= ''.$langs->trans('Title').': '.$this->title.'
    '; + $label .= ''.$langs->trans('Language').': '.$this->lang; + + $url = DOL_URL_ROOT.'/website/index.php?websiteid='.$this->fk_website.'&pageid='.$this->id; + + $linkclose = ''; + 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.'"' : ''); + + $linkstart = '
    '; @@ -789,6 +738,2 @@ - 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; @@ -801,3 +746,3 @@ - * Return the label of the status - * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * Retourne le libelle du status d'un user (actif, inactif) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto @@ -811,7 +756,7 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return the label of a given status - * - * @param int $status Id status - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un status donne + * + * @param int $status Id status + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of status @@ -821 +766 @@ - // phpcs:enable + // phpcs:enable @@ -824 +769,2 @@ - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { @@ -827,4 +773,4 @@ - $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline'); - $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online'); - $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Offline'); - $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Online'); + $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Disabled'); + $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled'); + $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Disabled'); + $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled'); @@ -834,3 +780 @@ - if ($status == self::STATUS_VALIDATED) { - $statusType = 'status4'; - } + if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; @@ -841,15 +784,0 @@ - /** - * Sets object to given categories. - * - * Deletes object from existing categories not supplied. - * Adds it to non existing supplied categories. - * Existing categories are left untouch. - * - * @param int[]|int $categories Category ID or array of Categories IDs - * @return int Return integer <0 if KO, >0 if OK - */ - public function setCategories($categories) - { - require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - return $this->setCategoriesCommon($categories, Categorie::TYPE_WEBSITE_PAGE); - } @@ -871 +800 @@ - $this->fk_website = 0; + $this->fk_website = ''; @@ -879 +807,0 @@ - $this->allowed_in_frames = 1; @@ -882 +810 @@ - $this->status = self::STATUS_DRAFT; + $this->status = '';