| @@ 99-120 (lines=22) @@ | ||
| 96 | * @param $isbn |
|
| 97 | * @throws MsgException |
|
| 98 | */ |
|
| 99 | public static function checkIsbn10Number($isbn) |
|
| 100 | { |
|
| 101 | $isbn = trim($isbn); |
|
| 102 | if (mb_strlen($isbn) !== 10 || preg_match('/0{10}/', $isbn)) { |
|
| 103 | throw new MsgException("ISBN10 형식에 맞지 않습니다."); |
|
| 104 | } |
|
| 105 | ||
| 106 | $total = 0; |
|
| 107 | for ($i = 0; $i < 9; $i++) { |
|
| 108 | $digit = intval(substr($isbn, $i, 1)); |
|
| 109 | $total += ((10 - $i) * $digit); |
|
| 110 | } |
|
| 111 | ||
| 112 | $check_sum = (11 - ($total % 11)) % 11; |
|
| 113 | if ($check_sum === 10) { |
|
| 114 | $check_sum = 'X'; |
|
| 115 | } |
|
| 116 | ||
| 117 | if ($check_sum != substr($isbn, 9)) { |
|
| 118 | throw new MsgException("ISBN10 형식에 맞지 않습니다."); |
|
| 119 | } |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|
| 123 | * ISBN13 값 유효성 체크한다. |
|
| @@ 187-210 (lines=24) @@ | ||
| 184 | * @param $issn |
|
| 185 | * @throws MsgException |
|
| 186 | */ |
|
| 187 | public static function checkIssn($issn) |
|
| 188 | { |
|
| 189 | $issn = trim(StringUtils::removeHyphen($issn)); |
|
| 190 | ||
| 191 | if (mb_strlen($issn) !== 8 || preg_match('/0{8}/', $issn)) { |
|
| 192 | throw new MsgException('ISSN 형식에 맞지 않습니다.'); |
|
| 193 | } |
|
| 194 | ||
| 195 | $total = 0; |
|
| 196 | ||
| 197 | for ($i = 0; $i < 7; $i++) { |
|
| 198 | $digit = intval(substr($issn, $i, 1)); |
|
| 199 | $total += ((8 - $i) * $digit); |
|
| 200 | } |
|
| 201 | ||
| 202 | $check_sum = 11 - ($total % 11); |
|
| 203 | if ($check_sum === 10) { |
|
| 204 | $check_sum = 'X'; |
|
| 205 | } |
|
| 206 | ||
| 207 | if ($check_sum != substr($issn, -1)) { |
|
| 208 | throw new MsgException("ISSN 형식에 맞지 않습니다."); |
|
| 209 | } |
|
| 210 | } |
|
| 211 | ||
| 212 | public static function checkHtml($html, $msg) |
|
| 213 | { |
|