Code Duplication    Length = 10-14 lines in 4 locations

include/functions.php 4 locations

@@ 598-609 (lines=12) @@
595
 * @param $msg_id_fk
596
 * @return bool|int false if not found, integer of uid otherwise
597
 */
598
function smallworld_getOwnerFromComment($msg_id_fk)
599
{
600
    $owner = false;
601
    /** @todo looks like this should have LIMIT set to 1 to reduce execution time & possible ambiguity */
602
    $sql    = 'SELECT uid_fk FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . " WHERE msg_id = '" . $msg_id_fk . "'";
603
    $result = $GLOBALS['xoopsDB']->queryF($sql);
604
    while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
605
        $owner = $r['uid_fk'];
606
    }
607
608
    return $owner;
609
}
610
611
/**
612
 * Get username from userID
@@ 1005-1014 (lines=10) @@
1002
 * @param $id
1003
 * @return mixed
1004
 */
1005
function smallworldCheckPriv($id)
1006
{
1007
    $public = 'SELECT priv FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . ' WHERE msg_id = ' . $id . '';
1008
    $result = $GLOBALS['xoopsDB']->queryF($public);
1009
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
1010
        $priv = $row['priv'];
1011
    }
1012
1013
    return $priv;
1014
}
1015
1016
/**
1017
 * Function to calculate remaining seconds until user's birthday
@@ 1167-1180 (lines=14) @@
1164
 * @param int $userid
1165
 * @return bool|string  false if no image found
1166
 */
1167
function smallworld_getRndImg($userid)
1168
{
1169
    $sql    = 'SELECT imgname FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_images')
1170
            . ' WHERE userid = ' . (int)$userid . ' AND time BETWEEN UNIX_TIMESTAMP( ) - 3000 AND UNIX_TIMESTAMP() ORDER BY rand() LIMIT 1';
1171
    $result = $GLOBALS['xoopsDB']->queryF($sql);
1172
    while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
1173
        $img = $r['imgname'];
1174
    }
1175
    if (!empty($img)) {
1176
        return $img;
1177
    }
1178
1179
    return false;
1180
}
1181
1182
/**
1183
 * Get url of smallworld
@@ 1606-1616 (lines=11) @@
1603
 * @param $name
1604
 * @return array @users
1605
 */
1606
function smallworld_getUidFromName($name)
1607
{
1608
    $id     = [];
1609
    $sql    = 'SELECT userid FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " WHERE username = '" . $name . "'";
1610
    $result = $GLOBALS['xoopsDB']->queryF($sql);
1611
    while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
1612
        $id = $r['userid'];
1613
    }
1614
1615
    return $id;
1616
}
1617
1618
/**
1619
 * Extract users from @tags