From 32bf8c5cd54512fc67117cbe8114371ec9281798 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 26 Feb 2025 23:14:28 +0100 Subject: [PATCH] Qual: Fix phan notices (website) --- dev/tools/phan/baseline.txt | 5 -- htdocs/accountancy/admin/categories_list.php | 4 +- htdocs/adherents/admin/website.php | 5 +- htdocs/admin/website.php | 4 +- htdocs/core/ajax/editinline.php | 3 +- htdocs/core/class/html.formwebsite.class.php | 4 +- htdocs/core/db/Database.interface.php | 4 +- htdocs/core/db/mysqli.class.php | 2 +- htdocs/core/db/pgsql.class.php | 2 +- htdocs/core/db/sqlite3.class.php | 4 +- htdocs/core/lib/admin.lib.php | 4 +- htdocs/core/lib/files.lib.php | 4 +- htdocs/core/lib/modulebuilder.lib.php | 8 +-- htdocs/core/lib/website.lib.php | 10 ++-- htdocs/debugbar/class/TraceableDB.php | 4 +- htdocs/modulebuilder/index.php | 20 +++---- htdocs/website/class/website.class.php | 10 ++-- htdocs/website/index.php | 55 +++++++++++--------- htdocs/website/samples/wrapper.php | 7 +-- 19 files changed, 82 insertions(+), 77 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index eb971083041..6b38b07dd29 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -365,13 +365,11 @@ return [ 'htdocs/core/lib/images.lib.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/core/lib/invoice.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/loan.lib.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/lib/modulebuilder.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/pdf.lib.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/core/lib/product.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/project.lib.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/core/lib/security.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/sendings.lib.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/lib/website.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/xcal.lib.php' => ['PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/core/login/functions_dolibarr.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/login/functions_ldap.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], @@ -672,9 +670,6 @@ return [ 'htdocs/webservices/server_supplier_invoice.php' => ['PhanUndeclaredProperty'], 'htdocs/webservices/server_thirdparty.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/webservices/server_user.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], - 'htdocs/website/class/website.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullableInternal'], - 'htdocs/website/index.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], - 'htdocs/website/samples/wrapper.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/website/websiteaccount_card.php' => ['PhanUndeclaredProperty'], 'htdocs/workstation/class/api_workstations.class.php' => ['PhanPluginUnknownArrayMethodReturnType'], 'htdocs/workstation/class/workstation.class.php' => ['PhanUndeclaredProperty'], diff --git a/htdocs/accountancy/admin/categories_list.php b/htdocs/accountancy/admin/categories_list.php index 45bb66e8d23..ccc9d90da61 100644 --- a/htdocs/accountancy/admin/categories_list.php +++ b/htdocs/accountancy/admin/categories_list.php @@ -2,7 +2,7 @@ /* Copyright (C) 2004-2023 Laurent Destailleur * Copyright (C) 2011-2024 Alexandre Spangaro * Copyright (C) 2024 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,7 +67,7 @@ $actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"') $listoffset = GETPOST('listoffset', 'alpha'); $listlimit = GETPOSTINT('listlimit') > 0 ? GETPOSTINT('listlimit') : 1000; -$sortfield = GETPOST("sortfield", 'aZ09comma'); +$sortfield = (string) GETPOST("sortfield", 'aZ09comma'); $sortorder = GETPOST("sortorder", 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { diff --git a/htdocs/adherents/admin/website.php b/htdocs/adherents/admin/website.php index 401cb68a4b6..1c45e25c404 100644 --- a/htdocs/adherents/admin/website.php +++ b/htdocs/adherents/admin/website.php @@ -5,6 +5,7 @@ * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2024 Alexandre Spangaro * Copyright (C) 2024 Frédéric France + * Copyright (C) 2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -273,7 +274,7 @@ if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) { print ''; print $langs->trans("MembersShowMembershipTypesTable"); print ''; - print $form->selectyesno("MEMBER_SHOW_TABLE", !$skiptable, 1, false, 0, 1); // Reverse the logic "hide -> show" for retrocompatibility + print $form->selectyesno("MEMBER_SHOW_TABLE", (int) !$skiptable, 1, false, 0, 1); // Reverse the logic "hide -> show" for retrocompatibility print "\n"; // Show "vote allowed" setting for membership types @@ -281,7 +282,7 @@ if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) { print ''; print $langs->trans("MembersShowVotesAllowed"); print ''; - print $form->selectyesno("MEMBER_SHOW_VOTE_ALLOWED", !$hidevoteallowed, 1, false, 0, 1); // Reverse the logic "hide -> show" for retrocompatibility + print $form->selectyesno("MEMBER_SHOW_VOTE_ALLOWED", (int) !$hidevoteallowed, 1, false, 0, 1); // Reverse the logic "hide -> show" for retrocompatibility print "\n"; // Jump to an online payment page diff --git a/htdocs/admin/website.php b/htdocs/admin/website.php index 8979ee62e67..ed762155d01 100644 --- a/htdocs/admin/website.php +++ b/htdocs/admin/website.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -258,7 +258,7 @@ if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) { // Modifie valeur des champs if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) { $sql .= $tabrowid[$id]."="; - $sql .= "'".$db->escape($rowid)."', "; + $sql .= "'".$db->escape((string) $rowid)."', "; } $i = 0; foreach ($listfieldmodify as $field) { diff --git a/htdocs/core/ajax/editinline.php b/htdocs/core/ajax/editinline.php index 6ed0ecae1b9..75810a9f8c5 100644 --- a/htdocs/core/ajax/editinline.php +++ b/htdocs/core/ajax/editinline.php @@ -1,6 +1,7 @@ * Copyright (C) 2024 Frédéric France + * Copyright (C) 2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -72,7 +73,7 @@ top_httphead(); if (!empty($action) && $action === 'updatedElementContent' && $usercanmodify && !empty($content) && !empty($element_id) && !empty($website_ref) && !empty($page_id)) { // Page object $objectpage = new WebsitePage($db); - $res = $objectpage->fetch($page_id); + $res = $objectpage->fetch((int) $page_id); if (!$res) { print "Cannot find page with ID = " . $page_id . "."; exit; diff --git a/htdocs/core/class/html.formwebsite.class.php b/htdocs/core/class/html.formwebsite.class.php index afea3d81e3c..1ce7e41cccc 100644 --- a/htdocs/core/class/html.formwebsite.class.php +++ b/htdocs/core/class/html.formwebsite.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -258,7 +258,7 @@ class FormWebsite * @param int<0,1> $showempty Show empty record * @param string $action Action on page that use this select list * @param string $morecss More CSS - * @param null|string[] $excludeids Exclude some ID in list + * @param ?array $excludeids Exclude some ID in list * @return string HTML select component with list of block containers */ public function selectContainer($website, $htmlname = 'pageid', $pageid = 0, $showempty = 0, $action = '', $morecss = 'minwidth200', $excludeids = null) diff --git a/htdocs/core/db/Database.interface.php b/htdocs/core/db/Database.interface.php index 046f8504722..d60fcde4962 100644 --- a/htdocs/core/db/Database.interface.php +++ b/htdocs/core/db/Database.interface.php @@ -5,7 +5,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2014-2015 Raphaël Doursenaud - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -338,7 +338,7 @@ interface Database * Create a table into database * * @param string $table Name of table - * @param array|string,position:int,notnull?:int,visible:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> $fields Associative table [field name][table of descriptions] + * @param array|string,position?:int,notnull?:int,visible?:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> $fields Associative table [field name][table of descriptions] * @param string $primary_key Name of the field that will be the primary key * @param string $type Type of the table * @param ?array $unique_keys Associative array Name of fields that will be unique key => value diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 160805761bc..1d7d7c083cc 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -825,7 +825,7 @@ class DoliDBMysqli extends DoliDB * Create a table into database * * @param string $table Name of table - * @param array|string,position:int,notnull?:int,visible:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> $fields Tableau associatif [nom champ][tableau des descriptions] + * @param array|string,position?:int,notnull?:int,visible?:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> $fields Tableau associatif [nom champ][tableau des descriptions] * @param string $primary_key Nom du champ qui sera la clef primaire * @param string $type Type de la table * @param ?array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 02288a05e21..9f7e0134397 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1058,7 +1058,7 @@ class DoliDBPgsql extends DoliDB * Create a table into database * * @param string $table Nom de la table - * @param array|string,position:int,notnull?:int,visible:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> $fields Tableau associatif [nom champ][tableau des descriptions] + * @param array|string,position?:int,notnull?:int,visible?:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> $fields Tableau associatif [nom champ][tableau des descriptions] * @param string $primary_key Nom du champ qui sera la clef primaire * @param string $type Type de la table * @param ?array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur diff --git a/htdocs/core/db/sqlite3.class.php b/htdocs/core/db/sqlite3.class.php index e10cda471b0..3f44a73de5d 100644 --- a/htdocs/core/db/sqlite3.class.php +++ b/htdocs/core/db/sqlite3.class.php @@ -5,7 +5,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -966,7 +966,7 @@ class DoliDBSqlite3 extends DoliDB * Create a table into database * * @param string $table Nom de la table - * @param array|string,position:int,notnull?:int,visible:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>,value?:string,attribute?:string,null?:string,extra?:string}> $fields Tableau associatif [nom champ][tableau des descriptions] + * @param array|string,position?:int,notnull?:int,visible?:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>,value?:string,attribute?:string,null?:string,extra?:string}> $fields Tableau associatif [nom champ][tableau des descriptions] * @param string $primary_key Nom du champ qui sera la clef primaire * @param string $type Type de la table * @param ?array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 7d9beb89411..690e1e2c106 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -4,7 +4,7 @@ * Copyright (C) 2012 J. Fernando Lagrange * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2023 Eric Seigne - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -1380,7 +1380,7 @@ function unActivateModule($value, $requiredby = 1) * @param string[] $tabrowid Tabrowid * @param bool[] $tabcond Tabcond * @param array> $tabhelp Tabhelp - * @param array>> $tabcomplete Tab complete (will replace all other in future). Key is table name. + * @param array>> $tabcomplete Tab complete (will replace all other in future). Key is table name. * @return int 1 */ function complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index da18964bf1b..fd7a61cec39 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -6,7 +6,7 @@ * Copyright (C) 2016 Raphaël Doursenaud * Copyright (C) 2019-2024 Frédéric France * Copyright (C) 2023 Lenin Rivas - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -685,7 +685,7 @@ function dol_fileperm($pathoffile) * Make replacement of strings into a file. * * @param string $srcfile Source file (can't be a directory) - * @param array $arrayreplacement Array with strings to replace. Example: array('valuebefore'=>'valueafter', ...) + * @param array $arrayreplacement Array with strings to replace. Example: array('valuebefore'=>'valueafter', ...) * @param string $destfile Destination file (can't be a directory). If empty, will be same than source file. * @param string $newmask Mask for new file. '0' by default means getDolGlobalString('MAIN_UMASK'). Example: '0666'. * @param int $indexdatabase 1=index new file into database. diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 67d57193729..eb7cfa1ad56 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -143,10 +143,10 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = $texttoinsert .= " 'notnull' => ".(empty($val['notnull']) ? 0 : (int) $val['notnull']).","; $texttoinsert .= ' "visible" => "'.($val['visible'] !== '' ? dol_escape_js($val['visible']) : -1).'",'; if (!empty($val['noteditable'])) { - $texttoinsert .= ' "noteditable" => "'.dol_escape_php($val['noteditable']).'",'; + $texttoinsert .= ' "noteditable" => "'.dol_escape_php((string) $val['noteditable']).'",'; } if (!empty($val['alwayseditable'])) { - $texttoinsert .= ' "alwayseditable" => "'.dol_escape_php($val['alwayseditable']).'",'; + $texttoinsert .= ' "alwayseditable" => "'.dol_escape_php((string) $val['alwayseditable']).'",'; } if (array_key_exists('default', $val) && (!empty($val['default']) || $val['default'] === '0')) { $texttoinsert .= ' "default" => "'.dol_escape_php($val['default']).'",'; @@ -555,7 +555,7 @@ function deletePerms($file) * @param int|string $a value 1 * @param int|string $b value 2 * @return int<-1,1> <=0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal. -*/ + */ function compareFirstValue($a, $b) { return strcmp($a[0], $b[0]); diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index ae13e84ebe6..1590d5a0bf4 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -1,7 +1,7 @@ * Copyright (C) 2024 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -530,7 +530,7 @@ function redirectToContainer($containerref, $containeraliasalt = '', $containeri include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; $tmpwebsitepage = new WebsitePage($db); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition - $result = $tmpwebsitepage->fetch(0, $website->id, '', $containeraliasalt); + $result = $tmpwebsitepage->fetch(0, (string) $website->id, '', $containeraliasalt); if ($result > 0) { $containerref = $tmpwebsitepage->pageurl; } else { @@ -554,7 +554,7 @@ function redirectToContainer($containerref, $containeraliasalt = '', $containeri include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; $tmpwebsitepage = new WebsitePage($db); // @phan-suppress-next-line PhanPluginSuspiciousParamPosition - $result = $tmpwebsitepage->fetch(0, $website->id, $containerref); + $result = $tmpwebsitepage->fetch(0, (string) $website->id, $containerref); unset($tmpwebsitepage); } if ($result > 0) { @@ -622,7 +622,7 @@ function includeContainer($containerref, $once = 0, $cachedelay = 0, $cachekey = $fullpathcache = ''; // If we ask to use the cache delay if ($cachedelay > 0 && !getDolGlobalString("WEBSITE_DISABLE_CACHE_OF_CONTAINERS")) { - $fullpathcache = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/temp/'.$websitekey.'-'.$websitepage->id.'-'.$containerref.($cachekey ? '-'.$cachekey: '').'.cache'; + $fullpathcache = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/website/temp/'.$websitekey.'-'.$websitepage->id.'-'.$containerref.($cachekey ? '-'.$cachekey : '').'.cache'; } if (empty($includehtmlcontentopened)) { @@ -638,7 +638,7 @@ function includeContainer($containerref, $once = 0, $cachedelay = 0, $cachekey = // We don't print info messages for pages of type library or service if (!empty($websitepage->type_container) && !in_array($websitepage->type_container, array('library', 'service'))) { - print "\n".''."\n"; + print "\n".''."\n"; } $tmpoutput = ''; diff --git a/htdocs/debugbar/class/TraceableDB.php b/htdocs/debugbar/class/TraceableDB.php index a7b45a7da6b..577abd4dd3a 100644 --- a/htdocs/debugbar/class/TraceableDB.php +++ b/htdocs/debugbar/class/TraceableDB.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -496,7 +496,7 @@ class TraceableDB extends DoliDB * Create a table into database * * @param string $table Name of table - * @param array|string,position:int,notnull?:int,visible:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> $fields Associative table [field name][table of descriptions] + * @param array|string,position?:int,notnull?:int,visible?:int<-2,5>|string,alwayseditable?:int<0,1>,noteditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int<0,1>,isameasure?:int<0,1>,css?:string,csslist?:string,help?:string,showoncombobox?:int<0,2>,disabled?:int<0,1>,arrayofkeyval?:array,autofocusoncreate?:int<0,1>,comment?:string,copytoclipboard?:int<1,2>,validate?:int<0,1>}> $fields Associative table [field name][table of descriptions] * @param string $primary_key Nom du champ qui sera la clef primaire * @param string $type Type de la table * @param ?array $unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index a947d497024..630ee86f467 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -66,7 +66,7 @@ $cancel = GETPOST('cancel', 'alpha'); $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'aZ09'); -$module = GETPOST('module', 'alpha'); +$module = (string) GETPOST('module', 'alpha'); $tab = (string) GETPOST('tab', 'aZ09'); $tabobj = GETPOST('tabobj', 'alpha'); $tabdic = GETPOST('tabdic', 'alpha'); @@ -90,12 +90,12 @@ $find = GETPOST('find', 'alpha'); $modulename = dol_sanitizeFileName(GETPOST('modulename', 'alpha')); $objectname = dol_sanitizeFileName(GETPOST('objectname', 'alpha')); $dicname = dol_sanitizeFileName(GETPOST('dicname', 'alpha')); -$editorname = GETPOST('editorname', 'alpha'); -$editorurl = GETPOST('editorurl', 'alpha'); -$version = GETPOST('version', 'alpha'); -$family = GETPOST('family', 'alpha'); -$picto = GETPOST('idpicto', 'alpha'); -$idmodule = GETPOST('idmodule', 'alpha'); +$editorname = (string) GETPOST('editorname', 'alpha'); +$editorurl = (string) GETPOST('editorurl', 'alpha'); +$version = (string) GETPOST('version', 'alpha'); +$family = (string) GETPOST('family', 'alpha'); +$picto = (string) GETPOST('idpicto', 'alpha'); +$idmodule = (string) GETPOST('idmodule', 'alpha'); $format = ''; // Prevent undefined in css tab // Security check @@ -418,7 +418,7 @@ if ($dirins && $action == 'initmodule' && $modulename && $user->hasRight("module } // @phan-suppress-next-line PhanPluginSuspiciousParamPosition - $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); + $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); // @phpstan-ignore-line //var_dump($result); if ($result < 0) { setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors'); @@ -1655,7 +1655,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname && $user->hasRi $arrayreplacement['---Replace with your own copyright and developer email---'] = dol_print_date($now, '%Y').' ' . getDolGlobalString('MODULEBUILDER_SPECIFIC_AUTHOR'); } - $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); + $result = dolReplaceInFile($phpfileval['fullname'], $arrayreplacement); // @phpstan-ignore-line //var_dump($result); if ($result < 0) { setEventMessages($langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname']), null, 'errors'); @@ -3297,7 +3297,7 @@ $h++; $linktoenabledisable = ''; -if (is_array($listofmodules) && count($listofmodules) > 0) { +if (/* is_array($listofmodules) && */ count($listofmodules) > 0) { // Define $linktoenabledisable $modulelowercase = strtolower($module); diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index ae56eae9af4..1bf31f5f394 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -4,7 +4,7 @@ * Copyright (C) 2015 Florian Henry * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2018-2024 Frédéric France - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -823,7 +823,7 @@ class Website extends CommonObject dol_delete_file($filetplold); // Create new file - $objectpagenew = $objectpageold->createFromClone($user, $pageid, $objectpageold->pageurl, '', 0, $object->id, 1); + $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) { @@ -1170,7 +1170,7 @@ class Website extends CommonObject $line .= "'".$this->db->escape($objectpageold->lang)."', "; $line .= "'".$this->db->escape($objectpageold->image)."', "; $line .= "'".$this->db->escape($objectpageold->keywords)."', "; - $line .= "'".$this->db->escape($objectpageold->status)."', "; + $line .= "'".$this->db->escape((string) $objectpageold->status)."', "; $line .= "'".$this->db->idate($objectpageold->date_creation)."', "; $line .= "'".$this->db->idate($objectpageold->date_modification)."', "; $line .= ($objectpageold->import_key ? "'".$this->db->escape((string) $objectpageold->import_key)."'" : "null").", "; @@ -1219,7 +1219,7 @@ class Website extends CommonObject //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 page that is set as the 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 = "UPDATE llx_website SET fk_default_home = ".($objectpageold->newid > 0 ? $this->db->escape((string) $objectpageold->newid)."__+MAX_llx_website_page__" : "null")." WHERE rowid = __WEBSITE_ID__;"; $line .= "\n"; fwrite($fp, $line); } @@ -1698,7 +1698,7 @@ class Website extends CommonObject if ($languagecodeselected) { // Convert $languagecodeselected into a long language code if (strlen($languagecodeselected) == 2) { - $languagecodeselected = (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]); + $languagecodeselected = (string) (empty($arrayofspecialmainlanguages[$languagecodeselected]) ? $languagecodeselected.'_'.strtoupper($languagecodeselected) : $arrayofspecialmainlanguages[$languagecodeselected]); } $countrycode = strtolower(substr($languagecodeselected, -2)); diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 5d6e26e1631..6019924597a 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -1,7 +1,7 @@ * Copyright (C) 2020 Nicolas ZABOURI - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024-2025 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -158,7 +158,7 @@ if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x // Load variable for pagination $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortfield = (string) GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); if (empty($page) || $page == -1) { @@ -167,8 +167,6 @@ if (empty($page) || $page == -1) { $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -//if (! $sortfield) $sortfield='name'; -//if (! $sortorder) $sortorder='ASC'; if (empty($action)) { $action = 'preview'; @@ -208,12 +206,12 @@ if (($pageid > 0 || $pageref) && $action != 'addcontainer') { 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 + $res = $objectpage->fetch($object->fk_default_home, (string) $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 + $res = $objectpage->fetch(0, (string) $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. @@ -343,7 +341,9 @@ if (GETPOST('optionsitefiles')) { $algo .= 'sitefiles'; } -if (empty($sortfield)) { +$searchkey = GETPOST('searchstring', 'restricthtmlallowunvalid'); // or 'none', must be same as $searchstring + +if ($sortfield == '') { if ($action == 'file_manager') { // Test on permission not required $sortfield = 'name'; $sortorder = 'ASC'; @@ -352,13 +352,15 @@ if (empty($sortfield)) { $sortorder = 'ASC'; } } +'@phan-var-force string $sortfield'; -$searchkey = GETPOST('searchstring', 'restricthtmlallowunvalid'); // or 'none', must be same then $searchstring +$langcode = ''; +$containertype = ''; +$otherfilters = array(); if ($action == 'replacesite' || $mode == 'replacesite') { // Test on permission not required $containertype = GETPOST('optioncontainertype', 'aZ09') != '-1' ? GETPOST('optioncontainertype', 'aZ09') : ''; $langcode = GETPOST('optionlanguage', 'aZ09'); - $otherfilters = array(); if (GETPOSTINT('optioncategory') > 0) { $otherfilters['category'] = GETPOSTINT('optioncategory'); } @@ -723,6 +725,7 @@ if ($action == 'addsite' && $usercanedit) { setEventMessages($langs->transnoentities("ErrorFieldCanNotContainSpecialCharacters", $langs->transnoentities("Ref")), null, 'errors'); } + $tmpobject = null; if (!$error) { $arrayotherlang = explode(',', GETPOST('WEBSITE_OTHERLANG', 'alphanohtml')); foreach ($arrayotherlang as $key => $val) { @@ -750,7 +753,7 @@ if ($action == 'addsite' && $usercanedit) { } } - if (!$error) { + if (!$error && $tmpobject !== null) { $db->commit(); setEventMessages($langs->trans("SiteAdded", $object->ref), null, 'mesgs'); $action = ''; @@ -800,6 +803,8 @@ if ($action == 'addcontainer' && $usercanedit) { } $pageurl = ''; + $urltograbdirwithoutslash = ''; + $urltograbdirrootwithoutslash = ''; 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 @@ -820,7 +825,7 @@ if ($action == 'addcontainer' && $usercanedit) { // Check pageurl is not already used if ($pageurl) { $tmpwebsitepage = new WebsitePage($db); - $result = $tmpwebsitepage->fetch(0, $object->id, $pageurl); + $result = $tmpwebsitepage->fetch(0, (string) $object->id, $pageurl); if ($result > 0) { setEventMessages($langs->trans("AliasPageAlreadyExists", $pageurl), null, 'errors'); $error++; @@ -1140,7 +1145,7 @@ if ($action == 'addcontainer' && $usercanedit) { $action = 'createcontainer'; break; } else { - $result = $websitepagetemp->fetch(0, $object->id, $aliastotest); + $result = $websitepagetemp->fetch(0, (string) $object->id, $aliastotest); if ($result < 0) { $error++; $langs->load("errors"); @@ -1448,7 +1453,7 @@ if (GETPOSTISSET('pageid') && $action == 'delete' && $permissiontodelete && !GET $res = $object->fetch(0, $websitekey); $website = $object; - $res = $objectpage->fetch($pageid, $object->id); + $res = $objectpage->fetch($pageid, (string) $object->id); if ($res > 0) { $res = $objectpage->delete($user); @@ -2105,7 +2110,7 @@ if ($action == 'updatemeta' && $usercanedit) { $action = 'editmeta'; } - $res = $objectpage->fetch($pageid, $object->id); + $res = $objectpage->fetch($pageid, (string) $object->id); if ($res <= 0) { $error++; setEventMessages('Page not found '.$objectpage->error, $objectpage->errors, 'errors'); @@ -2114,7 +2119,7 @@ if ($action == 'updatemeta' && $usercanedit) { // Check alias not exists if (!$error && GETPOST('WEBSITE_PAGENAME', 'alpha')) { $websitepagetemp = new WebsitePage($db); - $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, GETPOST('WEBSITE_PAGENAME', 'alpha')); + $result = $websitepagetemp->fetch(-1 * $objectpage->id, (string) $object->id, GETPOST('WEBSITE_PAGENAME', 'alpha')); if ($result < 0) { $error++; $langs->load("errors"); @@ -2145,7 +2150,7 @@ if ($action == 'updatemeta' && $usercanedit) { $action = 'editmeta'; break; } else { - $result = $websitepagetemp->fetch(-1 * $objectpage->id, $object->id, $aliastotest); + $result = $websitepagetemp->fetch(-1 * $objectpage->id, (string) $object->id, $aliastotest); if ($result < 0) { $error++; $langs->load("errors"); @@ -2446,7 +2451,7 @@ if ((($action == 'updatesource' || $action == 'updatecontent' || $action == 'con $res = $objectpage->fetch($object->fk_default_home); } if (!($res > 0)) { - $res = $objectpage->fetch(0, $object->id); + $res = $objectpage->fetch(0, (string) $object->id); } } } @@ -2927,7 +2932,7 @@ if ($action == 'generatesitemaps' && $usercanedit) { // URL of sitemaps must end with trailing slash if page is '' $loc = $domtree->createElement('loc', $domainname.'/'.$pageurl); - $lastmod = $domtree->createElement('lastmod', dol_print_date($db->jdate(dol_now()), 'dayrfc', 'gmt')); + $lastmod = $domtree->createElement('lastmod', dol_print_date(dol_now(), 'dayrfc', 'gmt')); $url->appendChild($loc); $url->appendChild($lastmod); @@ -3152,8 +3157,8 @@ if ($action != 'preview' && $action != 'editcontent' && $action != 'editsource' } +$disabled = ''; if (!GETPOST('hide_websitemenu')) { - $disabled = ''; if (!$user->hasRight('website', 'write')) { $disabled = ' disabled="disabled"'; } @@ -3651,7 +3656,7 @@ if (!GETPOST('hide_websitemenu')) { } $formquestion = array( array('type' => 'hidden', 'name' => 'sourcepageurl', 'value' => $objectpage->pageurl), - array('type' => 'other', 'tdclass' => 'fieldrequired', 'name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite($object->id, 'newwebsite', 0)), + array('type' => 'other', 'tdclass' => 'fieldrequired', 'name' => 'newwebsite', 'label' => $langs->trans("WebSite"), 'value' => $formwebsite->selectWebsite((string) $object->id, 'newwebsite', 0)), array('type' => 'text', 'tdclass' => 'maxwidth200 fieldrequired', 'moreattr' => 'autofocus="autofocus"', 'name' => 'newtitle', 'label' => $langs->trans("WEBSITE_TITLE"), 'value' => $langs->trans("CopyOf").' '.$objectpage->title), array('type' => 'text', 'tdclass' => 'maxwidth200', 'name' => 'newpageurl', 'label' => $langs->trans("WEBSITE_PAGENAME"), 'value' => '') ); @@ -3842,7 +3847,7 @@ if (!GETPOST('hide_websitemenu')) { } else { print 'console.log("A change has been detected, but saving is not enabled by option WEBSITE_EDITINLINE_SAVE_CKEDITOR_EDIT, so no ajax update is done");'; } - print ' + print ' $(this).removeClass(\'modified\'); } @@ -4738,7 +4743,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties $pagelang = $objectpage->lang; $pageallowedinframes = $objectpage->allowed_in_frames; $pagehtmlheader = $objectpage->htmlheader; - $pagedatecreation = $objectpage->date_creation; + $pagedatecreation = (string) $objectpage->date_creation; $pagedatemodification = $objectpage->date_modification; $pageauthorid = $objectpage->fk_user_creat; $pageusermodifid = $objectpage->fk_user_modif; @@ -4933,7 +4938,7 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties } } if (empty($object->lang) && empty($object->otherlang)) { - $onlykeys = null; // We keep full list of languages + $onlykeys = array(); // We keep full list of languages } print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($pagelang ? $pagelang : '', 'WEBSITE_LANG', 0, array(), '1', 0, 0, 'minwidth200', 0, 0, 0, $onlykeys, 1); $htmltext = $langs->trans("AvailableLanguagesAreDefinedIntoWebsiteProperties"); @@ -5009,12 +5014,14 @@ if ($action == 'editmeta' || $action == 'createcontainer') { // Edit properties // Categories if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) { + $disabled = ''; $langs->load('categories'); + $cate_arbo = array(); + $arrayselected = array(); if (!GETPOSTISSET('categories')) { $c = new Categorie($db); $cats = $c->containing($objectpage->id, Categorie::TYPE_WEBSITE_PAGE); - $arrayselected = array(); if (is_array($cats)) { foreach ($cats as $cat) { $arrayselected[] = $cat->id; diff --git a/htdocs/website/samples/wrapper.php b/htdocs/website/samples/wrapper.php index 49e6440b8d7..462b2bbe030 100644 --- a/htdocs/website/samples/wrapper.php +++ b/htdocs/website/samples/wrapper.php @@ -1,5 +1,6 @@ + * Copyright (C) 2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -151,11 +152,11 @@ if ($rss) { $website = new Website($db); $websitepage = new WebsitePage($db); - $website->fetch('', $websitekey); + $website->fetch(0, $websitekey); - $filters = array('type_container'=>'blogpost', 'status'=>1); + $filters = array('type_container' => 'blogpost', 'status' => '1'); if ($l) { - $filters['lang'] = $l; + $filters['lang'] = (string) $l; } $MAXNEWS = $limit;