2626use Joomla \CMS \Object \CMSObject ;
2727use Joomla \CMS \Plugin \PluginHelper ;
2828use Joomla \CMS \Uri \Uri ;
29+ use Joomla \Database \ParameterType ;
2930use Joomla \Utilities \ArrayHelper ;
3031
3132/**
@@ -108,8 +109,12 @@ abstract class UserHelper
108109 */
109110 public static function addUserToGroup ($ userId , $ groupId )
110111 {
112+ // Cast as integer until method is typehinted.
113+ $ userId = (int ) $ userId ;
114+ $ groupId = (int ) $ groupId ;
115+
111116 // Get the user object.
112- $ user = new User (( int ) $ userId );
117+ $ user = new User ($ userId );
113118
114119 // Add the user to the group if necessary.
115120 if (!in_array ($ groupId , $ user ->groups ))
@@ -119,7 +124,8 @@ public static function addUserToGroup($userId, $groupId)
119124 $ query = $ db ->getQuery (true )
120125 ->select ($ db ->quoteName ('id ' ))
121126 ->from ($ db ->quoteName ('#__usergroups ' ))
122- ->where ($ db ->quoteName ('id ' ) . ' = ' . (int ) $ groupId );
127+ ->where ($ db ->quoteName ('id ' ) . ' = :groupId ' )
128+ ->bind (':groupId ' , $ groupId , ParameterType::INTEGER );
123129 $ db ->setQuery ($ query );
124130
125131 // If the group does not exist, return an exception.
@@ -136,7 +142,7 @@ public static function addUserToGroup($userId, $groupId)
136142 }
137143
138144 // Set the group data for any preloaded user objects.
139- $ temp = User::getInstance (( int ) $ userId );
145+ $ temp = User::getInstance ($ userId );
140146 $ temp ->groups = $ user ->groups ;
141147
142148 if (Factory::getSession ()->getId ())
@@ -234,9 +240,9 @@ public static function setUserGroups($userId, $groups)
234240 // Get the titles for the user groups.
235241 $ db = Factory::getDbo ();
236242 $ query = $ db ->getQuery (true )
237- ->select ($ db ->quoteName ('id ' ) . ' , ' . $ db -> quoteName ( ' title ' ))
243+ ->select ($ db ->quoteName ([ 'id ' , 'title ' ] ))
238244 ->from ($ db ->quoteName ('#__usergroups ' ))
239- ->where ($ db ->quoteName ('id ' ) . ' = ' . implode ( ' OR ' . $ db -> quoteName ( ' id ' ) . ' = ' , $ user ->groups ) );
245+ ->whereIn ($ db ->quoteName ('id ' ), $ user ->groups );
240246 $ db ->setQuery ($ query );
241247 $ results = $ db ->loadObjectList ();
242248
@@ -307,22 +313,25 @@ public static function getProfile($userId = 0)
307313 */
308314 public static function activateUser ($ activation )
309315 {
310- $ db = Factory::getDbo ();
316+ $ db = Factory::getDbo ();
317+ $ nullDate = $ db ->getNullDate ();
311318
312319 // Let's get the id of the user we want to activate
313320 $ query = $ db ->getQuery (true )
314321 ->select ($ db ->quoteName ('id ' ))
315322 ->from ($ db ->quoteName ('#__users ' ))
316- ->where ($ db ->quoteName ('activation ' ) . ' = ' . $ db -> quote ( $ activation) )
323+ ->where ($ db ->quoteName ('activation ' ) . ' = : activation ' )
317324 ->where ($ db ->quoteName ('block ' ) . ' = 1 ' )
318- ->where ($ db ->quoteName ('lastvisitDate ' ) . ' = ' . $ db ->quote ($ db ->getNullDate ()));
325+ ->where ($ db ->quoteName ('lastvisitDate ' ) . ' = :nullDate ' )
326+ ->bind (':activation ' , $ activation )
327+ ->bind (':nullDate ' , $ nullDate );
319328 $ db ->setQuery ($ query );
320329 $ id = (int ) $ db ->loadResult ();
321330
322331 // Is it a valid user to activate?
323332 if ($ id )
324333 {
325- $ user = User::getInstance (( int ) $ id );
334+ $ user = User::getInstance ($ id );
326335
327336 $ user ->set ('block ' , '0 ' );
328337 $ user ->set ('activation ' , '' );
@@ -361,8 +370,10 @@ public static function getUserId($username)
361370 $ query = $ db ->getQuery (true )
362371 ->select ($ db ->quoteName ('id ' ))
363372 ->from ($ db ->quoteName ('#__users ' ))
364- ->where ($ db ->quoteName ('username ' ) . ' = ' . $ db ->quote ($ username ));
365- $ db ->setQuery ($ query , 0 , 1 );
373+ ->where ($ db ->quoteName ('username ' ) . ' = :username ' )
374+ ->bind (':username ' , $ username )
375+ ->setLimit (1 );
376+ $ db ->setQuery ($ query );
366377
367378 return $ db ->loadResult ();
368379 }
0 commit comments