mambax7 /
chess
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | |||
| 3 | // ------------------------------------------------------------------------- // |
||
| 4 | // This program is free software; you can redistribute it and/or modify // |
||
| 5 | // it under the terms of the GNU General Public License as published by // |
||
| 6 | // the Free Software Foundation; either version 2 of the License, or // |
||
| 7 | // (at your option) any later version. // |
||
| 8 | // // |
||
| 9 | // You may not change or alter any portion of this comment or credits // |
||
| 10 | // of supporting developers from this source code or any supporting // |
||
| 11 | // source code which is considered copyrighted (c) material of the // |
||
| 12 | // original comment or credit authors. // |
||
| 13 | // // |
||
| 14 | // This program is distributed in the hope that it will be useful, // |
||
| 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
| 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
| 17 | // GNU General Public License for more details. // |
||
| 18 | // // |
||
| 19 | // You should have received a copy of the GNU General Public License // |
||
| 20 | // along with this program; if not, write to the Free Software // |
||
| 21 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
| 22 | // ------------------------------------------------------------------------ // |
||
| 23 | |||
| 24 | /** |
||
| 25 | * General functions. |
||
| 26 | * |
||
| 27 | * @param mixed $text |
||
| 28 | * @param mixed $allowed_characters |
||
| 29 | * @package chess |
||
| 30 | * @subpackage functions |
||
| 31 | */ |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Remove unsafe characters from text. |
||
| 35 | * |
||
| 36 | * @param string $text Text to be sanitized |
||
| 37 | * @param string $allowed_characters Characters permitted in text; |
||
| 38 | * must not contain any regex symbols such as \w or \s, since preg_quote() mishandles those. But \' and \" are ok. |
||
| 39 | * @return string Sanitized text |
||
| 40 | */ |
||
| 41 | function chess_sanitize($text, $allowed_characters = 'A-Za-z0-9') |
||
| 42 | { |
||
| 43 | $char_class = preg_replace('/(\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:\#)/', '\\${1}', $allowed_characters); |
||
| 44 | //$char_class = preg_quote($allowed_characters, '/'); |
||
| 45 | return preg_replace("/[^$char_class]/i", '_', $text); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get chess module configuration option value. |
||
| 50 | * |
||
| 51 | * @param string $option Name of configuration option |
||
| 52 | * @return string Value of configuration option |
||
| 53 | */ |
||
| 54 | function chess_moduleConfig($option) |
||
| 55 | { |
||
| 56 | global $xoopsModule, $xoopsModuleConfig; |
||
| 57 | |||
| 58 | $value = null; |
||
| 59 | |||
| 60 | if (is_object($xoopsModule) && 'chess' == $xoopsModule->getVar('dirname') && isset($xoopsModuleConfig[$option])) { |
||
| 61 | $value = $xoopsModuleConfig[$option]; |
||
| 62 | } else { // for use within a block |
||
| 63 | $moduleHandler = xoops_getHandler('module'); |
||
| 64 | |||
| 65 | $module = $moduleHandler->getByDirname('chess'); |
||
| 66 | |||
| 67 | $configHandler = xoops_getHandler('config'); |
||
| 68 | |||
| 69 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 70 | |||
| 71 | if (isset($moduleConfig[$option])) { |
||
| 72 | $value = $moduleConfig[$option]; |
||
| 73 | } else { |
||
| 74 | trigger_error("configuration option '$option' not found", E_USER_ERROR); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return $value; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Check whether a user has the play-chess right. |
||
| 83 | * |
||
| 84 | * @param int $uid User ID to check, defaults to current user |
||
| 85 | * @return bool True if user has play-chess right, otherwise false |
||
| 86 | */ |
||
| 87 | function chess_can_play($uid = null) |
||
| 88 | { |
||
| 89 | global $xoopsUser; |
||
| 90 | |||
| 91 | if (isset($uid)) { |
||
| 92 | $memberHandler = xoops_getHandler('member'); |
||
| 93 | |||
| 94 | $user = $memberHandler->getUser($uid); |
||
| 95 | } elseif (is_object($xoopsUser)) { |
||
| 96 | $user = $xoopsUser; |
||
| 97 | } else { |
||
| 98 | $user = null; |
||
| 99 | } |
||
| 100 | |||
| 101 | $groups_play = chess_moduleConfig('groups_play'); |
||
| 102 | |||
| 103 | $can_play = false; |
||
| 104 | |||
| 105 | if (in_array(XOOPS_GROUP_ANONYMOUS, $groups_play)) { |
||
| 106 | $can_play = true; |
||
| 107 | } elseif (is_object($user)) { |
||
| 108 | $can_play = count(array_intersect($user->getGroups(), $groups_play)) > 0; |
||
| 109 | } |
||
| 110 | |||
| 111 | return $can_play; |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Check whether a user has the delete-game right. |
||
| 116 | * |
||
| 117 | * @param int $uid User ID to check, defaults to current user |
||
| 118 | * @return bool True if user has delete-game right, otherwise false |
||
| 119 | */ |
||
| 120 | function chess_can_delete($uid = null) |
||
| 121 | { |
||
| 122 | global $xoopsUser; |
||
| 123 | |||
| 124 | if (isset($uid)) { |
||
| 125 | $memberHandler = xoops_getHandler('member'); |
||
| 126 | |||
| 127 | $user = $memberHandler->getUser($uid); |
||
| 128 | } elseif (is_object($xoopsUser)) { |
||
| 129 | $user = $xoopsUser; |
||
| 130 | } else { |
||
| 131 | $user = null; |
||
| 132 | } |
||
| 133 | |||
| 134 | $groups_delete = chess_moduleConfig('groups_delete'); |
||
| 135 | |||
| 136 | $can_delete = false; |
||
| 137 | |||
| 138 | if (in_array(XOOPS_GROUP_ANONYMOUS, $groups_delete)) { |
||
| 139 | $can_delete = true; |
||
| 140 | } elseif (is_object($user)) { |
||
| 141 | $can_delete = count(array_intersect($user->getGroups(), $groups_delete)) > 0; |
||
| 142 | } |
||
| 143 | |||
| 144 | return $can_delete; |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Build string suitable for output as .pgn (Portable Game Notation) file. |
||
| 149 | * |
||
| 150 | * @param array $data Array with keys: |
||
| 151 | * |
||
| 152 | * - 'datetime' - 'YYYY-MM-DD HH:MM:SS' |
||
| 153 | * Use '?' for each unknown digit. If the entire datetime is unknown, use either '????-??-?? ??:??:??' or '0000-00-00 00:00:00'. |
||
| 154 | * - 'event', 'site', 'round', 'white', 'black', 'result', 'setup', 'fen', 'movetext' - strings (use '?' for entire string if value unknown) |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | function chess_to_pgn_string($data) |
||
| 158 | { |
||
| 159 | #var_dump('chess_to_pgn_string, data=', $data);#*#DEBUG# |
||
| 160 | |||
| 161 | if ('0000-00-00 00:00:00' == $data['datetime']) { |
||
| 162 | $datetime = '????.??.?? ??:??:??'; |
||
| 163 | } else { |
||
| 164 | $datetime = str_replace('-', '.', $data['datetime']); |
||
| 165 | } |
||
| 166 | |||
| 167 | [$date, $time] = explode(' ', $datetime); |
||
| 168 | |||
| 169 | $movetext = wordwrap($data['movetext'], 75); |
||
| 170 | |||
| 171 | $rtn = <<<END |
||
| 172 | [Event "{$data['event']}"] |
||
| 173 | [Site "{$data['site']}"] |
||
| 174 | [Date "$date"] |
||
| 175 | [Time "$time"] |
||
| 176 | [Round "{$data['round']}"] |
||
| 177 | [White "{$data['white']}"] |
||
| 178 | [Black "{$data['black']}"] |
||
| 179 | [Result "{$data['result']}"] |
||
| 180 | |||
| 181 | END; |
||
| 182 | |||
| 183 | if ($data['setup'] && $data['fen']) { |
||
| 184 | $rtn .= "[Setup \"1\"]\n[FEN \"{$data['fen']}\"]\n"; |
||
| 185 | } |
||
| 186 | |||
| 187 | $rtn .= "\n$movetext\n"; |
||
| 188 | |||
| 189 | return $rtn; |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Get user ID corresponding to the specified username. |
||
| 194 | * |
||
| 195 | * @param string $uname Username (unsanitized) |
||
| 196 | * @return int User ID, or '0' if user not found |
||
| 197 | */ |
||
| 198 | function chess_uname_to_uid($uname) |
||
| 199 | { |
||
| 200 | $criteria = new \CriteriaCompo(); |
||
| 201 | |||
| 202 | $criteria->add(new \Criteria('uname', MyTextSanitizer::addSlashes($uname))); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 203 | |||
| 204 | $criteria->setLimit(1); |
||
| 205 | |||
| 206 | $memberHandler = xoops_getHandler('member'); |
||
| 207 | |||
| 208 | $users = $memberHandler->getUserList($criteria); |
||
| 209 | |||
| 210 | $uids = array_keys($users); |
||
| 211 | |||
| 212 | return $uids[0] ?? 0; |
||
| 213 | } |
||
| 214 | |||
| 215 | /*** #*#DEBUG# testing something |
||
| 216 | * SELECT |
||
| 217 | * g.game_id,g.white_uid AS white_uid, g.black_uid AS black_uid, g.pgn_result AS pgn_result, w.rating AS white_rating, b.rating AS black_rating, |
||
| 218 | * (w.games_won+w.games_lost+w.games_drawn) AS white_games, (b.games_won+b.games_lost+b.games_drawn) AS black_games |
||
| 219 | * FROM xoops_chess_games AS g |
||
| 220 | * LEFT JOIN xoops_chess_ratings AS w ON w.player_uid = g.white_uid |
||
| 221 | * LEFT JOIN xoops_chess_ratings AS b ON b.player_uid = g.black_uid |
||
| 222 | * WHERE g.pgn_result != '*' AND g.is_rated='1' AND (w.player_uid IS NULL OR b.player_uid IS NULL OR w.player_uid != b.player_uid) LIMIT 0, 30 |
||
| 223 | ***/ |
||
| 224 |