[2] | 1 | <?php |
---|
| 2 | /** |
---|
[4933] | 3 | * @copyright 2005-2008 OpenPNE Project |
---|
[2] | 4 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | /** |
---|
| 8 | * リダイレクト |
---|
| 9 | * |
---|
| 10 | * @param string $module |
---|
| 11 | * @param string $action |
---|
| 12 | * @param array $params |
---|
| 13 | */ |
---|
| 14 | function openpne_redirect($module, $action = '', $params = array()) |
---|
| 15 | { |
---|
| 16 | if ($module == 'ktai') { |
---|
| 17 | if (session_id()) { |
---|
| 18 | $params['ksid'] = session_id(); |
---|
| 19 | } |
---|
| 20 | } |
---|
| 21 | $url = openpne_gen_url($module, $action, $params); |
---|
| 22 | client_redirect_absolute($url); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | * クライアントリダイレクト |
---|
| 27 | * |
---|
| 28 | * @param string $dest ジャンプ先URI(絶対パス) |
---|
| 29 | */ |
---|
| 30 | function client_redirect_absolute($dest) |
---|
| 31 | { |
---|
| 32 | // 改行文字を削除 |
---|
| 33 | $dest = str_replace(array("\r", "\n"), '', $dest); |
---|
| 34 | header('Location: '. $dest); |
---|
| 35 | exit; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | /** |
---|
| 39 | * クライアントリダイレクト(ログインページ) |
---|
| 40 | */ |
---|
| 41 | function client_redirect_login() |
---|
| 42 | { |
---|
| 43 | client_redirect_absolute(get_login_url()); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | * ログインページを取得 |
---|
| 48 | * |
---|
| 49 | * @return string ログインページURL |
---|
| 50 | */ |
---|
| 51 | function get_login_url() |
---|
| 52 | { |
---|
| 53 | if (LOGIN_URL_PC) { |
---|
| 54 | return LOGIN_URL_PC; |
---|
| 55 | } else { |
---|
| 56 | return openpne_gen_url('pc', 'page_o_login'); |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | //--- |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * URLを生成 |
---|
| 64 | */ |
---|
| 65 | function openpne_gen_url($module, $action = '', $params = array(), $absolute = true, $force = false) |
---|
| 66 | { |
---|
| 67 | switch ($force) { |
---|
| 68 | case 'ssl': |
---|
| 69 | $url = OPENPNE_SSL_URL; |
---|
| 70 | break; |
---|
| 71 | case 'nonssl': |
---|
| 72 | $url = OPENPNE_URL; |
---|
| 73 | break; |
---|
| 74 | default: |
---|
| 75 | $url = openpne_gen_url_head($module, $action, $absolute); |
---|
| 76 | break; |
---|
| 77 | } |
---|
| 78 | |
---|
[2643] | 79 | $p = array('m' => $module, 'a' => $action) + (array)$params; |
---|
[2] | 80 | if (need_ssl_param($module, $action, $force)) { |
---|
| 81 | $p['ssl_param'] = 1; |
---|
| 82 | } else { |
---|
| 83 | unset($p['ssl_param']); |
---|
| 84 | } |
---|
| 85 | if ($q = http_build_query($p)) { |
---|
| 86 | $url .= '?' . $q; |
---|
| 87 | } |
---|
| 88 | return $url; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | function openpne_gen_url_head($module, $action = '', $absolute = true) |
---|
| 92 | { |
---|
| 93 | if (OPENPNE_USE_PARTIAL_SSL) { |
---|
| 94 | switch (openpne_ssl_type($module, $action)) { |
---|
| 95 | case 'SSL_REQUIRED': |
---|
| 96 | $head = ($absolute || !is_ssl()) ? OPENPNE_SSL_URL : './'; |
---|
| 97 | break; |
---|
| 98 | case 'SSL_SELECTABLE': |
---|
| 99 | if ($absolute) { |
---|
| 100 | $head = (is_ssl()) ? OPENPNE_SSL_URL : OPENPNE_URL; |
---|
| 101 | } else { |
---|
| 102 | $head = './'; |
---|
| 103 | } |
---|
| 104 | break; |
---|
| 105 | case 'SSL_DISABLED': |
---|
| 106 | $head = ($absolute || is_ssl()) ? OPENPNE_URL : './'; |
---|
| 107 | break; |
---|
| 108 | } |
---|
| 109 | } else { |
---|
| 110 | $head = ($absolute) ? OPENPNE_URL : './'; |
---|
| 111 | } |
---|
| 112 | return $head; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | //--- |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * module / action が部分SSL対象かどうかを判別する |
---|
| 119 | */ |
---|
| 120 | function openpne_ssl_type($m, $a) |
---|
| 121 | { |
---|
[116] | 122 | if (in_array($a, (array)$GLOBALS['_OPENPNE_SSL_REQUIRED'][$m]) || |
---|
| 123 | in_array($m, (array)$GLOBALS['_OPENPNE_SSL_REQUIRED_MODULES']) |
---|
| 124 | ) { |
---|
[2] | 125 | $type = 'SSL_REQUIRED'; |
---|
| 126 | } elseif (in_array($a, (array)$GLOBALS['_OPENPNE_SSL_SELECTABLE'][$m])) { |
---|
| 127 | $type = 'SSL_SELECTABLE'; |
---|
| 128 | } else { |
---|
| 129 | $type = 'SSL_DISABLED'; |
---|
| 130 | } |
---|
| 131 | return $type; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * 現在のリクエストがSSL通信であるかどうかを判別 |
---|
| 136 | */ |
---|
| 137 | function is_ssl() |
---|
| 138 | { |
---|
| 139 | static $is_ssl; |
---|
| 140 | if (!isset($is_ssl)) { |
---|
| 141 | if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
---|
| 142 | $is_ssl = true; |
---|
| 143 | } elseif (OPENPNE_USE_SSL_PARAM && !empty($_REQUEST['ssl_param'])) { |
---|
| 144 | $is_ssl = true; |
---|
| 145 | } else { |
---|
| 146 | $is_ssl = false; |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | return $is_ssl; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | function need_ssl_param($module, $action = '', $force = false) |
---|
| 153 | { |
---|
| 154 | $need = false; |
---|
| 155 | if (OPENPNE_USE_PARTIAL_SSL && OPENPNE_USE_SSL_PARAM) { |
---|
| 156 | switch ($force) { |
---|
| 157 | case 'ssl': |
---|
| 158 | $need = true; |
---|
| 159 | break; |
---|
| 160 | case 'nonssl': |
---|
| 161 | $need = false; |
---|
| 162 | break; |
---|
| 163 | default: |
---|
| 164 | switch (openpne_ssl_type($module, $action)) { |
---|
| 165 | case 'SSL_REQUIRED': |
---|
| 166 | $need = true; |
---|
| 167 | break; |
---|
| 168 | case 'SSL_SELECTABLE': |
---|
| 169 | $need = is_ssl(); |
---|
| 170 | break; |
---|
| 171 | case 'SSL_DISABLED': |
---|
| 172 | break; |
---|
| 173 | } |
---|
| 174 | break; |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | return $need; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | //--- |
---|
| 181 | |
---|
| 182 | function is_ktai_mail_address($mail) |
---|
| 183 | { |
---|
| 184 | $pieces = explode('@', $mail); |
---|
| 185 | $domain = array_pop($pieces); |
---|
| 186 | |
---|
| 187 | return in_array($domain, $GLOBALS['OpenPNE']['KTAI_DOMAINS']); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | function db_common_is_mailaddress($value) |
---|
| 191 | { |
---|
[2811] | 192 | if (preg_match('/^[^:;@,\s\x80-\xFF]+@\w[\w\-.]*\.[a-zA-Z]+$/', $value)) { |
---|
[2] | 193 | return true; |
---|
| 194 | } else { |
---|
| 195 | return false; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | //--- |
---|
| 200 | |
---|
| 201 | function _mt_srand() |
---|
| 202 | { |
---|
| 203 | if (version_compare(phpversion(), '4.2.0', '<')) { |
---|
| 204 | list($usec, $sec) = explode(' ', microtime()); |
---|
| 205 | $seed = (float)$sec + ((float)$usec * 100000); |
---|
| 206 | |
---|
| 207 | mt_srand($seed); |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | function do_common_create_password($length = 8) |
---|
| 212 | { |
---|
| 213 | // パスワードに使用する文字 |
---|
| 214 | $elem = 'abcdefghkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ2345679'; |
---|
| 215 | $max = strlen($elem) - 1; |
---|
| 216 | |
---|
| 217 | _mt_srand(); |
---|
| 218 | $password = ''; |
---|
| 219 | for ($i = 0; $i < $length; $i++) { |
---|
| 220 | $password .= substr($elem, mt_rand(0, $max), 1); |
---|
| 221 | } |
---|
| 222 | return $password; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | function create_hash() |
---|
| 226 | { |
---|
| 227 | _mt_srand(); |
---|
| 228 | return md5(uniqid(mt_rand(), true)); |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | //--- |
---|
| 232 | |
---|
| 233 | function &get_crypt_blowfish() |
---|
| 234 | { |
---|
| 235 | static $singleton; |
---|
| 236 | if (empty($singleton)) { |
---|
[252] | 237 | if (OPENPNE_USE_OLD_CRYPT_BLOWFISH) { |
---|
| 238 | include_once 'Crypt/BlowfishOld.php'; |
---|
| 239 | $singleton = new Crypt_BlowfishOld(ENCRYPT_KEY); |
---|
| 240 | } else { |
---|
| 241 | include_once 'Crypt/Blowfish.php'; |
---|
| 242 | $singleton = new Crypt_Blowfish(ENCRYPT_KEY); |
---|
| 243 | } |
---|
[2] | 244 | } |
---|
| 245 | return $singleton; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | /** |
---|
| 249 | * 可逆的な暗号化をする |
---|
| 250 | * |
---|
| 251 | * @param string $str 平文 |
---|
| 252 | * @return string 暗号文 |
---|
| 253 | */ |
---|
| 254 | function t_encrypt($str) |
---|
| 255 | { |
---|
| 256 | if (!$str) return ''; |
---|
| 257 | |
---|
| 258 | $bf =& get_crypt_blowfish(); |
---|
| 259 | $str = $bf->encrypt($str); |
---|
| 260 | |
---|
| 261 | //base64 |
---|
| 262 | $str = base64_encode($str); |
---|
| 263 | |
---|
| 264 | return $str; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | /** |
---|
| 268 | * 可逆的な暗号を復号化する |
---|
| 269 | * |
---|
| 270 | * @param string $str 暗号文 |
---|
| 271 | * @return string 平文 |
---|
| 272 | */ |
---|
| 273 | function t_decrypt($str) |
---|
| 274 | { |
---|
| 275 | if (!$str) return ''; |
---|
| 276 | |
---|
| 277 | //base64 |
---|
| 278 | $str = base64_decode($str); |
---|
| 279 | |
---|
| 280 | $bf =& get_crypt_blowfish(); |
---|
| 281 | return rtrim($bf->decrypt($str)); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | function t_wordwrap($str, $width = 80, $break = "\n") |
---|
| 285 | { |
---|
| 286 | if (!$width) { |
---|
| 287 | return $str; |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | $lines = explode($break, $str); |
---|
| 291 | foreach ($lines as $key => $line) { |
---|
| 292 | if (mb_strwidth($line) > $width) { |
---|
| 293 | $new_line = ''; |
---|
| 294 | do { |
---|
| 295 | if ($new_line) { |
---|
| 296 | $new_line .= $break; |
---|
| 297 | } |
---|
| 298 | $tmp = mb_strimwidth($line, 0, $width); |
---|
| 299 | $new_line .= $tmp; |
---|
| 300 | $line = substr($line, strlen($tmp)); |
---|
| 301 | } while (strlen($line) > 0); |
---|
| 302 | $lines[$key] = $new_line; |
---|
| 303 | } |
---|
| 304 | } |
---|
| 305 | return implode($break, $lines); |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | function util_is_unused_mail($name) |
---|
| 309 | { |
---|
| 310 | $unused = explode(',', UNUSED_MAILS); |
---|
| 311 | return in_array($name, $unused); |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | function util_get_c_navi($navi_type = 'h') |
---|
| 315 | { |
---|
| 316 | switch ($navi_type) { |
---|
| 317 | case 'global': |
---|
| 318 | $navi_type = 'global'; |
---|
| 319 | $navi = array( |
---|
| 320 | array('url' => '?m=pc&a=page_h_search', 'caption' => 'メンバー検索'), |
---|
| 321 | array('url' => '?m=pc&a=page_h_com_find_all', 'caption' => 'コミュニティ検索'), |
---|
| 322 | array('url' => '?m=pc&a=page_h_review_search', 'caption' => 'レビュー検索'), |
---|
| 323 | array('url' => '?m=pc&a=page_h_home', 'caption' => 'マイホーム'), |
---|
| 324 | array('url' => '?m=pc&a=page_h_invite', 'caption' => '友人を誘う'), |
---|
| 325 | array('url' => '?m=pc&a=page_h_diary_list_all', 'caption' => '最新日記'), |
---|
| 326 | array('url' => '?m=pc&a=page_h_ranking', 'caption' => 'ランキング'), |
---|
| 327 | array('url' => '?m=pc&a=page_h_config', 'caption' => '設定変更'), |
---|
| 328 | ); |
---|
| 329 | break; |
---|
| 330 | case 'h': |
---|
| 331 | default: |
---|
| 332 | $navi_type = 'h'; |
---|
| 333 | $navi = array( |
---|
| 334 | array('url' => '?m=pc&a=page_h_home', 'caption' => 'ホーム'), |
---|
| 335 | array('url' => '?m=pc&a=page_fh_friend_list', 'caption' => WORD_MY_FRIEND), |
---|
| 336 | array('url' => '?m=pc&a=page_fh_diary_list', 'caption' => '日記'), |
---|
| 337 | array('url' => '?m=pc&a=page_h_message_box', 'caption' => 'メッセージ'), |
---|
| 338 | array('url' => '?m=pc&a=page_h_ashiato', 'caption' => 'あしあと'), |
---|
| 339 | array('url' => '?m=pc&a=page_h_bookmark_list', 'caption' => 'お気に入り'), |
---|
| 340 | array('url' => '?m=pc&a=page_fh_review_list_member', 'caption' => 'マイレビュー'), |
---|
| 341 | array('url' => '?m=pc&a=page_h_prof', 'caption' => 'マイページ確認'), |
---|
| 342 | array('url' => '?m=pc&a=page_h_config_prof', 'caption' => 'プロフィール変更'), |
---|
| 343 | ); |
---|
| 344 | break; |
---|
| 345 | case 'f': |
---|
| 346 | $navi = array( |
---|
| 347 | array('url' => '?m=pc&a=page_f_home', 'caption' => 'ホーム'), |
---|
| 348 | array('url' => '?m=pc&a=page_fh_friend_list', 'caption' => WORD_FRIEND), |
---|
| 349 | array('url' => '?m=pc&a=page_fh_diary_list', 'caption' => '日記を読む'), |
---|
| 350 | array('url' => '?m=pc&a=page_f_message_send', 'caption' => 'メッセージを送る'), |
---|
| 351 | array('url' => '?m=pc&a=page_f_bookmark_add', 'caption' => 'お気に入りに追加'), |
---|
| 352 | array('url' => '?m=pc&a=page_fh_review_list_member', 'caption' => 'レビュー'), |
---|
| 353 | array('url' => '?m=pc&a=page_f_invite', 'caption' => WORD_MY_FRIEND.'に紹介'), |
---|
| 354 | array('url' => '?m=pc&a=page_f_link_request', 'caption' => WORD_MY_FRIEND.'に追加'), |
---|
| 355 | array('url' => '?m=pc&a=page_f_intro_edit', 'caption' => '紹介文を書く'), |
---|
| 356 | ); |
---|
| 357 | break; |
---|
| 358 | case 'c': |
---|
| 359 | $navi = array( |
---|
| 360 | array('url' => '?m=pc&a=page_c_home', 'caption' => 'コミュニティトップ'), |
---|
| 361 | array('url' => '?m=pc&a=page_c_topic_list', 'caption' => '掲示板'), |
---|
| 362 | array('url' => '?m=pc&a=page_c_member_review', 'caption' => 'おすすめレビュー'), |
---|
| 363 | array('url' => '?m=pc&a=page_c_join_commu', 'caption' => 'コミュニティに参加'), |
---|
| 364 | array('url' => '?m=pc&a=page_c_invite', 'caption' => WORD_MY_FRIEND.'に紹介'), |
---|
| 365 | array('url' => '?m=pc&a=page_c_leave_commu', 'caption' => 'コミュニティを退会'), |
---|
| 366 | ); |
---|
| 367 | break; |
---|
| 368 | } |
---|
| 369 | $db = db_get_c_navi($navi_type); |
---|
| 370 | foreach ($db as $value) { |
---|
| 371 | $i = $value['sort_order'] - 1; |
---|
| 372 | $navi[$i] = array('url' => $value['url'], 'caption' => $value['caption']); |
---|
| 373 | } |
---|
| 374 | return $navi; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | /** |
---|
| 378 | * checkdate の wrapper function |
---|
| 379 | * Warning 対策 |
---|
| 380 | */ |
---|
| 381 | function t_checkdate($month, $day, $year) |
---|
| 382 | { |
---|
| 383 | return checkdate(intval($month), intval($day), intval($year)); |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | /** |
---|
| 387 | * Date_Calc::isFutureDate の wrapper function |
---|
| 388 | */ |
---|
| 389 | function t_isFutureDate($day, $month, $year) |
---|
| 390 | { |
---|
[102] | 391 | include_once 'Date/Calc.php'; |
---|
[2] | 392 | return Date_Calc::isFutureDate(intval($day), intval($month), intval($year)); |
---|
| 393 | } |
---|
| 394 | |
---|
[62] | 395 | //--- |
---|
| 396 | |
---|
| 397 | /** |
---|
[260] | 398 | * Check c_diary.public_flag |
---|
| 399 | * |
---|
| 400 | * @param int $c_diary_id |
---|
| 401 | * @param int $c_member_id |
---|
| 402 | * @return bool allowed or not |
---|
| 403 | */ |
---|
| 404 | function pne_check_diary_public_flag($c_diary_id, $c_member_id) |
---|
| 405 | { |
---|
| 406 | $c_diary = db_diary_get_c_diary4id($c_diary_id); |
---|
| 407 | if ($c_diary['c_member_id'] == $c_member_id) { |
---|
| 408 | return true; |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | switch ($c_diary['public_flag']) { |
---|
| 412 | case 'public': |
---|
| 413 | $allowed = true; |
---|
| 414 | break; |
---|
| 415 | case 'friend': |
---|
| 416 | $allowed = db_friend_is_friend($c_diary['c_member_id'], $c_member_id); |
---|
| 417 | break; |
---|
| 418 | case 'private': |
---|
| 419 | default: |
---|
| 420 | $allowed = false; |
---|
| 421 | break; |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | return $allowed; |
---|
| 425 | } |
---|
| 426 | |
---|
[264] | 427 | function pne_url2a($url, $target = '_blank') |
---|
| 428 | { |
---|
| 429 | $length = 60; |
---|
| 430 | $etc = '...'; |
---|
| 431 | |
---|
| 432 | if (strlen($url) > $length) { |
---|
| 433 | $length -= strlen($etc); |
---|
| 434 | $urlstr = substr($url, 0, $length) . $etc; |
---|
| 435 | } else { |
---|
| 436 | $urlstr = $url; |
---|
| 437 | } |
---|
[266] | 438 | if ($target) { |
---|
| 439 | $target = sprintf(' target="%s"', $target); |
---|
| 440 | } |
---|
[2734] | 441 | |
---|
| 442 | $url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8'); |
---|
| 443 | $urlstr = htmlspecialchars($urlstr, ENT_QUOTES, 'UTF-8'); |
---|
| 444 | |
---|
[264] | 445 | return sprintf('<a href="%s"%s>%s</a>', $url, $target, $urlstr); |
---|
| 446 | } |
---|
| 447 | |
---|
[1380] | 448 | function get_auth_config($is_ktai = false) |
---|
[1263] | 449 | { |
---|
[5568] | 450 | if (OPENPNE_AUTH_MODE == 'slavepne') { |
---|
[2951] | 451 | $config = $GLOBALS['_OPENPNE_AUTH_CONFIG']; |
---|
[5568] | 452 | } elseif (OPENPNE_AUTH_MODE == 'pneid') { |
---|
| 453 | $config['storage'] = 'DB'; |
---|
| 454 | $config['is_lowercase_username'] = true; |
---|
| 455 | $config['options'] = array( |
---|
| 456 | 'dsn' => db_get_dsn(), |
---|
| 457 | 'auto_quote' => false, |
---|
| 458 | 'table' => 'c_member_secure AS cms INNER JOIN c_username AS cu USING (c_member_id)', |
---|
| 459 | 'db_fields' => 'cms.hashed_password AS hashed_password, cu.username AS username', |
---|
| 460 | 'usernamecol' => 'username', |
---|
| 461 | 'passwordcol' => 'hashed_password', |
---|
| 462 | 'cryptType' => 'md5', |
---|
| 463 | ); |
---|
[1380] | 464 | } else { |
---|
[2951] | 465 | $config['storage'] = 'DB'; |
---|
[4917] | 466 | $config['is_encrypt_username'] = true; |
---|
[1380] | 467 | if ($is_ktai) { |
---|
| 468 | $config['options'] = array( |
---|
| 469 | 'dsn' => db_get_dsn(), |
---|
| 470 | 'table' => 'c_member_secure', |
---|
| 471 | 'usernamecol' => 'ktai_address', |
---|
| 472 | 'passwordcol' => 'hashed_password', |
---|
| 473 | 'cryptType' => 'md5', |
---|
| 474 | ); |
---|
| 475 | } else { |
---|
| 476 | $config['options'] = array( |
---|
| 477 | 'dsn' => db_get_dsn(), |
---|
| 478 | 'table' => 'c_member_secure', |
---|
| 479 | 'usernamecol' => 'pc_address', |
---|
| 480 | 'passwordcol' => 'hashed_password', |
---|
| 481 | 'cryptType' => 'md5', |
---|
| 482 | ); |
---|
| 483 | } |
---|
[1263] | 484 | } |
---|
[4917] | 485 | $config['is_ktai'] = $is_ktai; |
---|
[1263] | 486 | return $config; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | function crypt_func($raw_value,$cryptType) |
---|
| 490 | { |
---|
| 491 | if ( isset($cryptType) |
---|
| 492 | && $cryptType == 'none') { |
---|
| 493 | $cryptFunction = 'strval'; |
---|
| 494 | } elseif ( isset($cryptType) |
---|
| 495 | && function_exists($cryptType)) { |
---|
| 496 | $cryptFunction = $cryptType; |
---|
| 497 | } else { |
---|
| 498 | $cryptFunction = 'md5'; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | return $cryptFunction($raw_value); |
---|
| 502 | } |
---|
| 503 | |
---|
[1380] | 504 | function check_action4pne_slave($is_ktai = false) |
---|
| 505 | { |
---|
[5568] | 506 | if (OPENPNE_AUTH_MODE == 'slavepne') { |
---|
[2951] | 507 | if ($is_ktai) { |
---|
| 508 | openpne_redirect('ktai'); |
---|
| 509 | } else { |
---|
| 510 | openpne_redirect('pc'); |
---|
| 511 | } |
---|
[1380] | 512 | } |
---|
| 513 | } |
---|
| 514 | |
---|
[1858] | 515 | function util_include_php_files($dir) |
---|
| 516 | { |
---|
| 517 | if (!is_dir($dir)) { |
---|
| 518 | return; |
---|
| 519 | } |
---|
| 520 | if ($dh = opendir($dir)) { |
---|
| 521 | while (($file = readdir($dh)) !== false) { |
---|
| 522 | if ($file[0] === '.') { |
---|
| 523 | continue; |
---|
| 524 | } |
---|
| 525 | $path = realpath($dir . '/' . $file); |
---|
| 526 | if (is_dir($path)) { |
---|
| 527 | util_include_php_files($path); |
---|
| 528 | } else { |
---|
| 529 | if (substr($file, -4, 4) === '.php') { |
---|
| 530 | include_once $path; |
---|
| 531 | } |
---|
| 532 | } |
---|
| 533 | } |
---|
| 534 | closedir($dh); |
---|
| 535 | } |
---|
| 536 | } |
---|
| 537 | |
---|
[2906] | 538 | function util_cast_public_flag_diary($public_flag, $default = 'public') |
---|
| 539 | { |
---|
| 540 | switch ($public_flag) { |
---|
| 541 | case 'public': |
---|
| 542 | case 'friend': |
---|
| 543 | case 'private': |
---|
| 544 | break; |
---|
| 545 | default: |
---|
| 546 | $public_flag = $default; |
---|
| 547 | break; |
---|
| 548 | } |
---|
| 549 | return $public_flag; |
---|
| 550 | } |
---|
| 551 | |
---|
[2913] | 552 | /** |
---|
| 553 | * 登録してもよいメールアドレスかどうか |
---|
| 554 | */ |
---|
[2929] | 555 | function util_is_regist_mail_address($mail_address, $c_member_id = 0) |
---|
[2913] | 556 | { |
---|
| 557 | if (!db_common_is_mailaddress($mail_address)) { |
---|
| 558 | return false; |
---|
| 559 | } |
---|
[4267] | 560 | |
---|
| 561 | if (!db_member_is_limit_domain4mail_address($mail_address)) { |
---|
[2913] | 562 | return false; |
---|
| 563 | } |
---|
[4267] | 564 | |
---|
| 565 | if (db_member_is_sns_join4mail_address($mail_address, $c_member_id)) { |
---|
[2913] | 566 | return false; |
---|
| 567 | } |
---|
[4267] | 568 | |
---|
[2913] | 569 | return true; |
---|
| 570 | } |
---|
| 571 | |
---|
[2923] | 572 | /** |
---|
| 573 | * アップロード可能な拡張子のリストを取得 |
---|
| 574 | */ |
---|
| 575 | function util_get_file_allowed_extensions($format = null) |
---|
| 576 | { |
---|
| 577 | $list = array(); |
---|
| 578 | if (FILE_ALLOWED_EXTENTIONS) { |
---|
| 579 | $exts = explode(',', FILE_ALLOWED_EXTENTIONS); |
---|
| 580 | foreach ((array)$exts as $ext) { |
---|
| 581 | if (trim($ext) !== '') { |
---|
| 582 | $list[] = trim($ext); |
---|
| 583 | } |
---|
| 584 | } |
---|
| 585 | } |
---|
| 586 | if ($format === 'string') { |
---|
| 587 | if ($list) { |
---|
| 588 | foreach ($list as $key => $value) { |
---|
| 589 | $list[$key] = '*.' . $value; |
---|
| 590 | } |
---|
| 591 | $list = implode('; ', $list); |
---|
| 592 | } else { |
---|
| 593 | $list = ''; |
---|
| 594 | } |
---|
| 595 | } |
---|
| 596 | return $list; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | /** |
---|
| 600 | * アップロード可能な拡張子かどうか |
---|
| 601 | */ |
---|
| 602 | function util_check_file_extention($filename) |
---|
| 603 | { |
---|
| 604 | $extension = pathinfo($filename, PATHINFO_EXTENSION); |
---|
| 605 | $list = util_get_file_allowed_extensions(); |
---|
| 606 | return (!$list || in_array($extension, $list)); |
---|
| 607 | } |
---|
| 608 | |
---|
[3942] | 609 | /** |
---|
| 610 | * 参照可能なメッセージかどうか |
---|
| 611 | * |
---|
| 612 | * ・指定メンバーが送信者で、完全削除済でない |
---|
| 613 | * ・指定メンバーが受信者で、送信済であり完全削除済でない |
---|
| 614 | * |
---|
| 615 | * @param int $c_member_id |
---|
| 616 | * @param int $c_message_id |
---|
| 617 | * @return bool |
---|
| 618 | */ |
---|
| 619 | function util_is_readable_message($c_member_id, $c_message_id) |
---|
| 620 | { |
---|
| 621 | $c_message = db_message_c_message4c_message_id($c_message_id); |
---|
| 622 | |
---|
| 623 | if ($c_message['c_member_id_from'] == $c_member_id) { // 自分が送信者 |
---|
| 624 | if (!$c_message['is_kanzen_sakujo_from']) { // 完全削除済でない |
---|
| 625 | return true; |
---|
| 626 | } |
---|
| 627 | } elseif ($c_message['c_member_id_to'] == $c_member_id) { // 自分が受信者 |
---|
| 628 | if ($c_message['is_send'] && !$c_message['is_kanzen_sakujo_to']) { // 送信済であり完全削除済でない |
---|
| 629 | return true; |
---|
| 630 | } |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | return false; |
---|
| 634 | } |
---|
| 635 | |
---|
[4390] | 636 | /** |
---|
| 637 | * DB内配色設定の未設定項目をデフォルトの配色設定で埋める |
---|
| 638 | * |
---|
| 639 | * @param array $c_config_color DB内配色設定 |
---|
[4402] | 640 | * @param string $mode |
---|
[4390] | 641 | * @return array |
---|
| 642 | */ |
---|
[4402] | 643 | function util_apply_color_default2current($c_config_color, $mode = 'pc') |
---|
[4390] | 644 | { |
---|
[4402] | 645 | if ($mode == 'ktai') { |
---|
| 646 | $default_color['color_23'] = $c_config_color['color_1']; |
---|
| 647 | $default_color['color_24'] = $c_config_color['color_14']; |
---|
| 648 | $default_color['color_25'] = $c_config_color['color_14']; |
---|
| 649 | $default_color['color_26'] = $c_config_color['color_14']; |
---|
| 650 | $default_color['color_27'] = $c_config_color['color_3']; |
---|
| 651 | $default_color['color_28'] = $c_config_color['color_14']; |
---|
| 652 | } else { |
---|
| 653 | $default_color['color_19'] = $c_config_color['color_13']; |
---|
| 654 | } |
---|
[4390] | 655 | |
---|
[4611] | 656 | $c_config_color = array_map('trim', $c_config_color); |
---|
[4390] | 657 | $empty_keys = array_keys($c_config_color, ''); |
---|
| 658 | foreach ($empty_keys as $key) { |
---|
| 659 | if (array_key_exists($key, $default_color)) { |
---|
| 660 | $c_config_color[$key] = $default_color[$key]; |
---|
| 661 | } |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | return $c_config_color; |
---|
| 665 | } |
---|
| 666 | |
---|
[4270] | 667 | function util_get_color_config() |
---|
| 668 | { |
---|
| 669 | $c_config_color = db_etc_c_config_color(); |
---|
[4390] | 670 | $c_config_color = util_apply_color_default2current($c_config_color); |
---|
[4359] | 671 | |
---|
[4270] | 672 | $color_config = array( |
---|
| 673 | 'border_01' => $c_config_color['color_1'], |
---|
| 674 | 'border_07' => $c_config_color['color_2'], |
---|
[4390] | 675 | 'border_10' => $c_config_color['color_3'], |
---|
[4270] | 676 | 'bg_00' => $c_config_color['color_4'], |
---|
[4271] | 677 | 'bg_01' => $c_config_color['color_5'], |
---|
| 678 | 'bg_02' => $c_config_color['color_6'], |
---|
| 679 | 'bg_03' => $c_config_color['color_7'], |
---|
| 680 | 'bg_04' => $c_config_color['color_8'], |
---|
| 681 | 'bg_05' => $c_config_color['color_9'], |
---|
| 682 | 'bg_06' => $c_config_color['color_10'], |
---|
| 683 | 'bg_07' => $c_config_color['color_11'], |
---|
| 684 | 'bg_08' => $c_config_color['color_12'], |
---|
| 685 | 'bg_09' => $c_config_color['color_13'], |
---|
| 686 | 'bg_10' => $c_config_color['color_14'], |
---|
| 687 | 'bg_11' => $c_config_color['color_15'], |
---|
| 688 | 'bg_12' => $c_config_color['color_16'], |
---|
| 689 | 'bg_13' => $c_config_color['color_17'], |
---|
| 690 | 'bg_14' => $c_config_color['color_18'], |
---|
[4359] | 691 | 'color_19' => $c_config_color['color_19'], |
---|
[4270] | 692 | ); |
---|
| 693 | return $color_config; |
---|
| 694 | } |
---|
| 695 | |
---|
| 696 | function util_get_color_config_ktai() |
---|
| 697 | { |
---|
| 698 | $c_config_color = db_etc_c_config_color_ktai(); |
---|
[4390] | 699 | $c_config_color = util_apply_color_default2current($c_config_color, 'ktai'); |
---|
[4309] | 700 | |
---|
[4270] | 701 | $color_config = array( |
---|
| 702 | 'bg_01' => $c_config_color['color_1'], |
---|
| 703 | 'bg_02' => $c_config_color['color_2'], |
---|
| 704 | 'bg_03' => $c_config_color['color_3'], |
---|
| 705 | 'bg_04' => $c_config_color['color_4'], |
---|
| 706 | 'bg_05' => $c_config_color['color_5'], |
---|
| 707 | 'bg_06' => $c_config_color['color_6'], |
---|
| 708 | 'bg_07' => $c_config_color['color_7'], |
---|
| 709 | 'bg_08' => $c_config_color['color_8'], |
---|
| 710 | 'bg_09' => $c_config_color['color_9'], |
---|
| 711 | 'bg_10' => $c_config_color['color_10'], |
---|
| 712 | 'border_01' => $c_config_color['color_11'], |
---|
| 713 | 'border_02' => $c_config_color['color_12'], |
---|
| 714 | 'border_03' => $c_config_color['color_13'], |
---|
| 715 | 'font_01' => $c_config_color['color_14'], |
---|
| 716 | 'font_02' => $c_config_color['color_15'], |
---|
[4309] | 717 | 'font_03' => $c_config_color['color_23'], |
---|
[4270] | 718 | 'font_04' => $c_config_color['color_17'], |
---|
| 719 | 'font_05' => $c_config_color['color_18'], |
---|
| 720 | 'font_06' => $c_config_color['color_19'], |
---|
| 721 | 'font_07' => $c_config_color['color_20'], |
---|
| 722 | 'font_08' => $c_config_color['color_21'], |
---|
| 723 | 'font_09' => $c_config_color['color_22'], |
---|
[4364] | 724 | 'color_24' => $c_config_color['color_24'], |
---|
| 725 | 'color_25' => $c_config_color['color_25'], |
---|
| 726 | 'color_26' => $c_config_color['color_26'], |
---|
| 727 | 'color_27' => $c_config_color['color_27'], |
---|
| 728 | 'color_28' => $c_config_color['color_28'], |
---|
[4270] | 729 | ); |
---|
| 730 | return $color_config; |
---|
| 731 | } |
---|
| 732 | |
---|
[4316] | 733 | /** |
---|
| 734 | * メンバー登録を行う |
---|
| 735 | * |
---|
| 736 | * @param array $c_member |
---|
| 737 | * @param array $c_member_secure |
---|
| 738 | * @param array $c_member_profile_list |
---|
[4341] | 739 | * @param bool $is_password_encrypted パスワードが既に暗号化済みかどうか |
---|
[4316] | 740 | * @return int |
---|
| 741 | */ |
---|
[4341] | 742 | function util_regist_c_member($c_member, $c_member_secure, $c_member_profile_list = array(), $is_password_encrypted = false) |
---|
[4316] | 743 | { |
---|
| 744 | // メール受信設定をデフォルト値に |
---|
| 745 | $c_member['is_receive_mail'] = 1; |
---|
| 746 | $c_member['is_receive_ktai_mail'] = 1; |
---|
| 747 | $c_member['is_receive_daily_news'] = 1; |
---|
| 748 | |
---|
| 749 | // メンバー登録 |
---|
[4341] | 750 | $u = db_member_insert_c_member($c_member, $c_member_secure, $is_password_encrypted); |
---|
[4316] | 751 | if ($u === false) { // メンバー登録に失敗した場合 |
---|
| 752 | return false; |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | if (OPENPNE_USE_POINT_RANK) { |
---|
| 756 | //入会者にポイント加算 |
---|
| 757 | $point = db_action_get_point4c_action_id(1); |
---|
| 758 | db_point_add_point($u, $point); |
---|
| 759 | |
---|
| 760 | //メンバー招待をした人にポイント加算 |
---|
| 761 | $point = db_action_get_point4c_action_id(7); |
---|
| 762 | db_point_add_point($c_member['c_member_id_invite'], $point); |
---|
| 763 | } |
---|
| 764 | |
---|
| 765 | // c_member_profile |
---|
| 766 | db_member_update_c_member_profile($u, $c_member_profile_list); |
---|
| 767 | |
---|
| 768 | // 招待者とフレンドリンク |
---|
| 769 | db_friend_insert_c_friend($u, $c_member['c_member_id_invite']); |
---|
| 770 | |
---|
| 771 | //管理画面で指定したコミュニティに強制参加 |
---|
| 772 | $c_commu_id_list = db_commu_regist_join_list(); |
---|
| 773 | foreach ($c_commu_id_list as $c_commu_id) { |
---|
| 774 | db_commu_join_c_commu($c_commu_id, $u); |
---|
| 775 | } |
---|
| 776 | |
---|
[5568] | 777 | // ログインIDを登録 |
---|
| 778 | if (OPENPNE_AUTH_MODE == 'pneid') { |
---|
| 779 | $login_id = strtolower($c_member['login_id']); |
---|
| 780 | db_member_insert_username($u, $login_id); |
---|
| 781 | } |
---|
| 782 | |
---|
[4316] | 783 | return $u; |
---|
| 784 | } |
---|
| 785 | |
---|
[4346] | 786 | function util_get_preset_color_list($dir = 'pc') |
---|
| 787 | { |
---|
| 788 | $color_list_dir = OPENPNE_WEBAPP_DIR . '/lib/color/' . $dir . '/'; |
---|
| 789 | $color_list = array(); |
---|
| 790 | |
---|
| 791 | if ($dh = opendir($color_list_dir)) { |
---|
| 792 | while (($file = readdir($dh)) !== false) { |
---|
| 793 | if (array_pop(explode('.', $file)) == 'ini') { |
---|
[4363] | 794 | $color_list[$file] = parse_ini_file($color_list_dir . $file); |
---|
[4346] | 795 | } |
---|
| 796 | } |
---|
| 797 | closedir($dh); |
---|
| 798 | } |
---|
| 799 | |
---|
[4363] | 800 | ksort($color_list); |
---|
| 801 | |
---|
| 802 | return array_values($color_list); |
---|
[4346] | 803 | } |
---|
[2] | 804 | ?> |
---|