XoopsModules25x /
xfguestbook
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | // $Id: msg.php, v 2.20 2005/08/12 C. Felix alias the Cat |
||
| 3 | // ------------------------------------------------------------------------ // |
||
| 4 | // XOOPS - PHP Content Management System // |
||
| 5 | // Copyright (c) 2000 XOOPS.org // |
||
| 6 | // <http://www.xoops.org/> // |
||
| 7 | // ------------------------------------------------------------------------- // |
||
| 8 | // This program is free software; you can redistribute it and/or modify // |
||
| 9 | // it under the terms of the GNU General Public License as published by // |
||
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
||
| 11 | // (at your option) any later version. // |
||
| 12 | // // |
||
| 13 | // You may not change or alter any portion of this comment or credits // |
||
| 14 | // of supporting developers from this source code or any supporting // |
||
| 15 | // source code which is considered copyrighted (c) material of the // |
||
| 16 | // original comment or credit authors. // |
||
| 17 | // // |
||
| 18 | // This program is distributed in the hope that it will be useful, // |
||
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
| 21 | // GNU General Public License for more details. // |
||
| 22 | // // |
||
| 23 | // You should have received a copy of the GNU General Public License // |
||
| 24 | // along with this program; if not, write to the Free Software // |
||
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
| 26 | // ------------------------------------------------------------------------ // |
||
| 27 | |||
| 28 | defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Class xfguestbookMsg |
||
| 32 | */ |
||
| 33 | class xfguestbookMsg extends XoopsObject |
||
| 34 | { |
||
| 35 | // constructor |
||
| 36 | /** |
||
| 37 | * xfguestbookMsg constructor. |
||
| 38 | */ |
||
| 39 | public function __construct() |
||
| 40 | { |
||
| 41 | parent::__construct(); |
||
| 42 | $this->initVar('msg_id', XOBJ_DTYPE_INT, null, false); |
||
| 43 | $this->initVar('user_id', XOBJ_DTYPE_INT, null, false); |
||
| 44 | $this->initVar('uname', XOBJ_DTYPE_TXTBOX, '', false); |
||
| 45 | $this->initVar('title', XOBJ_DTYPE_TXTBOX, '', true); |
||
| 46 | $this->initVar('message', XOBJ_DTYPE_TXTAREA, '', false); |
||
| 47 | $this->initVar('note', XOBJ_DTYPE_TXTAREA, '', false); |
||
| 48 | $this->initVar('post_time', XOBJ_DTYPE_STIME, null, false); |
||
| 49 | $this->initVar('email', XOBJ_DTYPE_EMAIL, '', false); |
||
| 50 | $this->initVar('url', XOBJ_DTYPE_URL, '', false); |
||
| 51 | $this->initVar('poster_ip', XOBJ_DTYPE_OTHER, '', false); |
||
| 52 | $this->initVar('moderate', XOBJ_DTYPE_INT, null, false); |
||
| 53 | $this->initVar('gender', XOBJ_DTYPE_TXTBOX, '', false, 1); |
||
| 54 | $this->initVar('country', XOBJ_DTYPE_TXTBOX, '', false, 5); |
||
| 55 | $this->initVar('photo', XOBJ_DTYPE_TXTBOX, '', false); // added v2.20 |
||
| 56 | $this->initVar('flagdir', XOBJ_DTYPE_TXTBOX, '', false); // added v2.30 |
||
| 57 | $this->initVar('other', XOBJ_DTYPE_TXTBOX, '', false); // added v2.30 |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Class xfguestbookMsgHandler |
||
| 63 | */ |
||
| 64 | class xfguestbookMsgHandler |
||
| 65 | { |
||
| 66 | public $db; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * xfguestbookMsgHandler constructor. |
||
| 70 | * @param $db |
||
| 71 | */ |
||
| 72 | public function __construct($db) |
||
| 73 | { |
||
| 74 | $this->db = $db; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @return xfguestbookMsg |
||
| 79 | */ |
||
| 80 | public function create() |
||
| 81 | { |
||
| 82 | return new xfguestbookMsg(); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param $id |
||
| 87 | * @return bool|xfguestbookMsg |
||
| 88 | */ |
||
| 89 | public function get($id) |
||
| 90 | { |
||
| 91 | $id = (int)$id; |
||
| 92 | if ($id > 0) { |
||
| 93 | $sql = 'SELECT * FROM ' . $this->db->prefix('xfguestbook_msg') . ' WHERE msg_id=' . $id; |
||
| 94 | if (!$result = $this->db->query($sql)) { |
||
| 95 | return false; |
||
| 96 | } |
||
| 97 | $numrows = $this->db->getRowsNum($result); |
||
| 98 | if (1 == $numrows) { |
||
| 99 | $msg = new xfguestbookMsg(); |
||
| 100 | $msg->assignVars($this->db->fetchArray($result)); |
||
| 101 | |||
| 102 | return $msg; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return false; |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param $msg |
||
| 111 | * @return bool |
||
| 112 | */ |
||
| 113 | public function insert($msg) |
||
| 114 | { |
||
| 115 | if ('xfguestbookmsg' !== strtolower(get_class($msg))) { |
||
| 116 | return false; |
||
| 117 | } |
||
| 118 | if (!$msg->cleanVars()) { |
||
| 119 | return false; |
||
| 120 | } |
||
| 121 | foreach ($msg->cleanVars as $k => $v) { |
||
| 122 | ${$k} = $v; |
||
| 123 | } |
||
| 124 | if (empty($msg_id)) { |
||
| 125 | $msg_id = $this->db->genId('xfguestbook_msg_msg_id_seq'); |
||
| 126 | $sql = 'INSERT INTO ' . $this->db->prefix('xfguestbook_msg') |
||
| 127 | . ' (msg_id, user_id, uname, title, message, note, post_time, email, url, poster_ip, moderate, gender, country, photo, flagdir, other) VALUES (' . $msg_id . ',' . $user_id . ', ' |
||
|
0 ignored issues
–
show
|
|||
| 128 | . $this->db->quoteString($uname) . ', ' . $this->db->quoteString($title) . ', ' . $this->db->quoteString($message) . ', ' . $this->db->quoteString($note) . ', ' . $post_time |
||
|
0 ignored issues
–
show
|
|||
| 129 | . ', ' . $this->db->quoteString($email) . ', ' . $this->db->quoteString($url) . ', ' . $this->db->quoteString($poster_ip) . ', ' . $moderate . ', ' |
||
|
0 ignored issues
–
show
|
|||
| 130 | . $this->db->quoteString($gender) . ', ' . $this->db->quoteString($country) . ', ' . $this->db->quoteString($photo) . ', ' . $this->db->quoteString($flagdir) . ', ' |
||
|
0 ignored issues
–
show
|
|||
| 131 | . $this->db->quoteString($other) . ')'; |
||
|
0 ignored issues
–
show
|
|||
| 132 | } else { |
||
| 133 | $sql = |
||
| 134 | 'UPDATE ' . $this->db->prefix('xfguestbook_msg') . ' SET user_id=' . $user_id . ', uname=' . $this->db->quoteString($uname) . ', title=' . $this->db->quoteString($title) . ', message=' |
||
| 135 | . $this->db->quoteString($message) . ', note=' . $this->db->quoteString($note) . ', email=' . $this->db->quoteString($email) . ', url=' . $this->db->quoteString($url) . ', moderate=' |
||
| 136 | . $moderate . ', gender=' . $this->db->quoteString($gender) . ', country=' . $this->db->quoteString($country) . ', photo=' . $this->db->quoteString($photo) . ', flagdir=' |
||
| 137 | . $this->db->quoteString($flagdir) . ', other=' . $this->db->quoteString($other) . ' WHERE msg_id=' . $msg_id; |
||
| 138 | } |
||
| 139 | if (!$result = $this->db->queryF($sql)) { |
||
| 140 | return false; |
||
| 141 | } |
||
| 142 | if (empty($msg_id)) { |
||
| 143 | $msg_id = $this->db->getInsertId(); |
||
| 144 | } |
||
| 145 | $msg->assignVar('msg_id', $msg_id); |
||
| 146 | |||
| 147 | return $msg_id; |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @param $msg |
||
| 152 | * @return bool |
||
| 153 | */ |
||
| 154 | public function delete($msg) |
||
| 155 | { |
||
| 156 | global $xoopsModule; |
||
| 157 | if ('xfguestbookmsg' !== strtolower(get_class($msg))) { |
||
| 158 | return false; |
||
| 159 | } |
||
| 160 | $sql = sprintf('DELETE FROM %s WHERE msg_id = %u', $this->db->prefix('xfguestbook_msg'), $msg->getVar('msg_id')); |
||
| 161 | if (isset($this->commentstable) && $this->commentstable !== '') { |
||
| 162 | xoops_comment_delete($xoopsModule->getVar('mid'), $msg_id); |
||
| 163 | } |
||
| 164 | |||
| 165 | if (!$result = $this->db->query($sql)) { |
||
| 166 | return false; |
||
| 167 | } |
||
| 168 | |||
| 169 | return true; |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @param null $criteria |
||
| 174 | * @return array |
||
| 175 | */ |
||
| 176 | public function &getObjects($criteria = null) |
||
| 177 | { |
||
| 178 | $ret = array(); |
||
| 179 | $limit = $start = 0; |
||
| 180 | $sql = 'SELECT * FROM ' . $this->db->prefix('xfguestbook_msg'); |
||
| 181 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
| 182 | $sql .= ' ' . $criteria->renderWhere(); |
||
| 183 | $sort = ($criteria->getSort() !== '') ? $criteria->getSort() : 'msg_id'; |
||
| 184 | $sql .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder(); |
||
| 185 | $limit = $criteria->getLimit(); |
||
| 186 | $start = $criteria->getStart(); |
||
| 187 | } |
||
| 188 | $result = $this->db->query($sql, $limit, $start); |
||
| 189 | if (!$result) { |
||
| 190 | return $ret; |
||
| 191 | } |
||
| 192 | while ($myrow = $this->db->fetchArray($result)) { |
||
| 193 | $msg = new xfguestbookMsg(); |
||
| 194 | $msg->assignVars($myrow); |
||
| 195 | $ret[] = $msg; |
||
| 196 | unset($msg); |
||
| 197 | } |
||
| 198 | |||
| 199 | return $ret; |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param null $criteria |
||
| 204 | * @return int |
||
| 205 | */ |
||
| 206 | public function countMsg($criteria = null) |
||
| 207 | { |
||
| 208 | $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('xfguestbook_msg'); |
||
| 209 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
| 210 | $sql .= ' ' . $criteria->renderWhere(); |
||
| 211 | } |
||
| 212 | if (!$result = $this->db->query($sql)) { |
||
| 213 | return 0; |
||
| 214 | } |
||
| 215 | list($count) = $this->db->fetchRow($result); |
||
| 216 | |||
| 217 | return $count; |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param null $criteria |
||
| 222 | * @return array|bool |
||
| 223 | */ |
||
| 224 | public function countMsgByCountry($criteria = null) |
||
| 225 | { |
||
| 226 | $arr = array(); |
||
| 227 | $sql = 'SELECT country, flagdir FROM ' . $this->db->prefix('xfguestbook_msg'); |
||
| 228 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
|
0 ignored issues
–
show
|
|||
| 229 | $sql .= ' ' . $criteria->renderWhere(); |
||
| 230 | } |
||
| 231 | if (!$result = $this->db->query($sql)) { |
||
| 232 | return false; |
||
| 233 | } |
||
| 234 | while (list($country, $flagdir) = $this->db->fetchRow($result)) { |
||
| 235 | $arr[] = $flagdir . '/' . $country; |
||
| 236 | } |
||
| 237 | $ret = array_count_values($arr); |
||
| 238 | arsort($ret); |
||
| 239 | |||
| 240 | return $ret; |
||
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @param null $criteria |
||
| 245 | * @return array|bool |
||
| 246 | */ |
||
| 247 | public function countMsgByGender($criteria = null) |
||
| 248 | { |
||
| 249 | $arr = array(); |
||
| 250 | $sql = 'SELECT gender FROM ' . $this->db->prefix('xfguestbook_msg'); |
||
| 251 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
| 252 | $sql .= ' ' . $criteria->renderWhere(); |
||
| 253 | } |
||
| 254 | if (!$result = $this->db->query($sql)) { |
||
| 255 | return false; |
||
| 256 | } |
||
| 257 | while (list($gender) = $this->db->fetchRow($result)) { |
||
| 258 | $arr[] = $gender; |
||
| 259 | } |
||
| 260 | $ret = array_count_values($arr); |
||
| 261 | |||
| 262 | return $ret; |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @param null $criteria |
||
| 267 | * @return array|int |
||
| 268 | */ |
||
| 269 | public function getMsgImg($criteria = null) |
||
| 270 | { |
||
| 271 | $arr = array(); |
||
| 272 | $sql = 'SELECT photo FROM ' . $this->db->prefix('xfguestbook_msg') . " WHERE `photo` LIKE 'msg_%'"; |
||
| 273 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
| 274 | $sql .= ' ' . $criteria->renderWhere(); |
||
| 275 | } |
||
| 276 | if (!$result = $this->db->query($sql)) { |
||
| 277 | return 0; |
||
| 278 | } |
||
| 279 | while (list($photo) = $this->db->fetchRow($result)) { |
||
| 280 | $arr[] = $photo; |
||
| 281 | } |
||
| 282 | |||
| 283 | return $arr; |
||
| 284 | } |
||
| 285 | } |
||
| 286 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.