Code Duplication    Length = 60-61 lines in 2 locations

class/wall.php 1 location

@@ 49-108 (lines=60) @@
46
     * @param $followers
47
     * @return array|bool
48
     */
49
    public function Updates($last, $uid, $followers)
50
    {
51
        global $xoopsUser, $xoopsDB, $moduleConfig;
52
        $hm        = smallworld_GetModuleOption('msgtoshow');
53
        $set       = smallworld_checkPrivateOrPublic();
54
        $followers = is_array($followers) ? $followers : [$followers];
55
        $followers = array_unique(Smallworld_array_flatten($followers, 0));
56
57
        $i = 0;
58
        if (0 == $last) {
59
            $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "'";
60
        } elseif ($last > 0) {
61
            $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "' AND M.msg_id < '" . $last . "'";
62
        } elseif ('a' === $last) {
63
            $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "'";
64
        }
65
66
        if (is_array($followers)) {
67
            foreach ($followers as $k => $v) {
68
                if ($last > 0) {
69
                    $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $v . "' and M.msg_id < '" . $last . "'";
70
                } elseif (0 == $last) {
71
                    $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $v . "'";
72
                } elseif ('a' === $last) {
73
                    $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $v . "'";
74
                }
75
                ++$i;
76
            }
77
        }
78
        if (!is_array($followers)) {
79
            $followers = $uid;
80
            if ($last > 0) {
81
                $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $followers . "' and M.msg_id < '" . $last . "'";
82
            } elseif (0 == $last) {
83
                $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $followers . "'";
84
            } elseif ('a' === $last) {
85
                $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $followers . "'";
86
            }
87
        }
88
89
        if ($last > 0) {
90
            $query .= ' order by created DESC LIMIT ' . $hm;
91
        } elseif ('a' === $last) {
92
            $query .= ' order by M.msg_id DESC LIMIT ' . $hm;
93
        } else {
94
            $query .= ' order by created DESC LIMIT ' . $hm;
95
        }
96
        $result = $xoopsDB->queryF($query);
97
        $count  = $xoopsDB->getRowsNum($result);
98
        if (0 == $count) {
99
            return false;
100
        } else {
101
            while ($row = $xoopsDB->fetchArray($result)) {
102
                $data[] = $row;
103
            }
104
            if (!empty($data)) {
105
                return $data;
106
            }
107
        }
108
    }
109
110
    /**
111
     * @Get comments based on msg id

class/WallUpdates.php 1 location

@@ 53-113 (lines=61) @@
50
     * @param $followers
51
     * @return array|bool
52
     */
53
    public function Updates($last, $uid, $followers)
54
    {
55
        global $xoopsUser, $xoopsDB, $moduleConfig;
56
        $query = '';
57
        $hm        = smallworld_GetModuleOption('msgtoshow');
58
        $set       = smallworld_checkPrivateOrPublic();
59
        $followers = is_array($followers) ? $followers : [$followers];
60
        $followers = array_unique(Smallworld_array_flatten($followers, 0));
61
62
        $i = 0;
63
        if (0 == $last) {
64
            $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "'";
65
        } elseif ($last > 0) {
66
            $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "' AND M.msg_id < '" . $last . "'";
67
        } elseif ('a' === $last) {
68
            $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "'";
69
        }
70
71
        if (is_array($followers)) {
72
            foreach ($followers as $k => $v) {
73
                if ($last > 0) {
74
                    $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $v . "' and M.msg_id < '" . $last . "'";
75
                } elseif (0 == $last) {
76
                    $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $v . "'";
77
                } elseif ('a' === $last) {
78
                    $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $v . "'";
79
                }
80
                ++$i;
81
            }
82
        }
83
        if (!is_array($followers)) {
84
            $followers = $uid;
85
            if ($last > 0) {
86
                $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $followers . "' and M.msg_id < '" . $last . "'";
87
            } elseif (0 == $last) {
88
                $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $followers . "'";
89
            } elseif ('a' === $last) {
90
                $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $followers . "'";
91
            }
92
        }
93
94
        if ($last > 0) {
95
            $query .= ' order by created DESC LIMIT ' . $hm;
96
        } elseif ('a' === $last) {
97
            $query .= ' order by M.msg_id DESC LIMIT ' . $hm;
98
        } else {
99
            $query .= ' order by created DESC LIMIT ' . $hm;
100
        }
101
        $result = $xoopsDB->queryF($query);
102
        $count  = $xoopsDB->getRowsNum($result);
103
        if (0 == $count) {
104
            return false;
105
        } else {
106
            while ($row = $xoopsDB->fetchArray($result)) {
107
                $data[] = $row;
108
            }
109
            if (!empty($data)) {
110
                return $data;
111
            }
112
        }
113
    }
114
115
    /**
116
     * @Get comments based on msg id