PageRenderTime 73ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 1ms

/webapp/lib/util/util.php

https://github.com/openpne/OpenPNE2
PHP | 1143 lines | 847 code | 127 blank | 169 comment | 131 complexity | 8cb7fadd7842373c50c6b9f3e21893e7 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * @copyright 2005-2008 OpenPNE Project
  4. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  5. */
  6. /**
  7. * リダイレクト
  8. *
  9. * @param string $module
  10. * @param string $action
  11. * @param array $params
  12. */
  13. function openpne_redirect($module, $action = '', $params = array())
  14. {
  15. if ($module == 'ktai') {
  16. if (session_id()) {
  17. $params['ksid'] = session_id();
  18. }
  19. }
  20. $url = openpne_gen_url($module, $action, $params);
  21. client_redirect_absolute($url);
  22. }
  23. /**
  24. * クライアントリダイレクト
  25. *
  26. * @param string $dest ジャンプ先URI(絶対パス)
  27. */
  28. function client_redirect_absolute($dest)
  29. {
  30. // 改行文字を削除
  31. $dest = str_replace(array("\r", "\n"), '', $dest);
  32. header('Location: '. $dest);
  33. exit;
  34. }
  35. /**
  36. * クライアントリダイレクト(ログインページ)
  37. */
  38. function client_redirect_login()
  39. {
  40. client_redirect_absolute(get_login_url());
  41. }
  42. /**
  43. * ログインページを取得
  44. *
  45. * @return string ログインページURL
  46. */
  47. function get_login_url()
  48. {
  49. if (LOGIN_URL_PC) {
  50. return LOGIN_URL_PC;
  51. } else {
  52. return openpne_gen_url('pc', 'page_o_login');
  53. }
  54. }
  55. //---
  56. /**
  57. * URLを生成
  58. */
  59. function openpne_gen_url($module, $action = '', $params = array(), $absolute = true, $force = false)
  60. {
  61. switch ($force) {
  62. case 'ssl':
  63. $url = OPENPNE_SSL_URL;
  64. break;
  65. case 'nonssl':
  66. $url = OPENPNE_URL;
  67. break;
  68. default:
  69. $url = openpne_gen_url_head($module, $action, $absolute);
  70. break;
  71. }
  72. $p = array('m' => $module, 'a' => $action) + (array)$params;
  73. if (need_ssl_param($module, $action, $force)) {
  74. $p['ssl_param'] = 1;
  75. } else {
  76. unset($p['ssl_param']);
  77. }
  78. if ($p['m'] == 'admin') {
  79. $p['m'] = ADMIN_MODULE_NAME;
  80. }
  81. if ($q = http_build_query($p)) {
  82. $url .= '?' . $q;
  83. }
  84. return $url;
  85. }
  86. function openpne_gen_url_head($module, $action = '', $absolute = true)
  87. {
  88. if (OPENPNE_USE_PARTIAL_SSL) {
  89. switch (openpne_ssl_type($module, $action)) {
  90. case 'SSL_REQUIRED':
  91. $head = ($absolute || !is_ssl()) ? OPENPNE_SSL_URL : './';
  92. break;
  93. case 'SSL_SELECTABLE':
  94. if ($absolute) {
  95. $head = (is_ssl()) ? OPENPNE_SSL_URL : OPENPNE_URL;
  96. } else {
  97. $head = './';
  98. }
  99. break;
  100. case 'SSL_DISABLED':
  101. $head = ($absolute || is_ssl()) ? OPENPNE_URL : './';
  102. break;
  103. }
  104. } else {
  105. $head = ($absolute) ? OPENPNE_URL : './';
  106. }
  107. return $head;
  108. }
  109. //---
  110. /**
  111. * module / action が部分SSL対象かどうかを判別する
  112. */
  113. function openpne_ssl_type($m, $a)
  114. {
  115. if (in_array($a, (array)$GLOBALS['_OPENPNE_SSL_REQUIRED'][$m]) ||
  116. in_array($m, (array)$GLOBALS['_OPENPNE_SSL_REQUIRED_MODULES'])
  117. ) {
  118. $type = 'SSL_REQUIRED';
  119. } elseif (in_array($a, (array)$GLOBALS['_OPENPNE_SSL_SELECTABLE'][$m])) {
  120. $type = 'SSL_SELECTABLE';
  121. } else {
  122. $type = 'SSL_DISABLED';
  123. }
  124. return $type;
  125. }
  126. /**
  127. * 現在のリクエストがSSL通信であるかどうかを判別
  128. */
  129. function is_ssl()
  130. {
  131. static $is_ssl;
  132. if (!isset($is_ssl)) {
  133. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
  134. $is_ssl = true;
  135. } elseif (OPENPNE_USE_SSL_PARAM && !empty($_REQUEST['ssl_param'])) {
  136. $is_ssl = true;
  137. } else {
  138. $is_ssl = false;
  139. }
  140. }
  141. return $is_ssl;
  142. }
  143. function need_ssl_param($module, $action = '', $force = false)
  144. {
  145. $need = false;
  146. if (OPENPNE_USE_PARTIAL_SSL && OPENPNE_USE_SSL_PARAM) {
  147. switch ($force) {
  148. case 'ssl':
  149. $need = true;
  150. break;
  151. case 'nonssl':
  152. $need = false;
  153. break;
  154. default:
  155. switch (openpne_ssl_type($module, $action)) {
  156. case 'SSL_REQUIRED':
  157. $need = true;
  158. break;
  159. case 'SSL_SELECTABLE':
  160. $need = is_ssl();
  161. break;
  162. case 'SSL_DISABLED':
  163. break;
  164. }
  165. break;
  166. }
  167. }
  168. return $need;
  169. }
  170. //---
  171. function is_ktai_mail_address($mail)
  172. {
  173. $pieces = explode('@', $mail);
  174. $domain = array_pop($pieces);
  175. return in_array($domain, $GLOBALS['OpenPNE']['KTAI_DOMAINS']);
  176. }
  177. function db_common_is_mailaddress($value)
  178. {
  179. if (preg_match('/^[^:;@,\s\x80-\xFF]+@\w[\w\-.]*\.[a-zA-Z]+$/', $value)) {
  180. return true;
  181. } else {
  182. return false;
  183. }
  184. }
  185. //---
  186. function _mt_srand()
  187. {
  188. if (version_compare(phpversion(), '4.2.0', '<')) {
  189. list($usec, $sec) = explode(' ', microtime());
  190. $seed = (float)$sec + ((float)$usec * 100000);
  191. mt_srand($seed);
  192. }
  193. }
  194. function do_common_create_password($length = 8)
  195. {
  196. // パスワードに使用する文字
  197. $elem = 'abcdefghkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ2345679';
  198. $max = strlen($elem) - 1;
  199. _mt_srand();
  200. $password = '';
  201. for ($i = 0; $i < $length; $i++) {
  202. $password .= substr($elem, mt_rand(0, $max), 1);
  203. }
  204. return $password;
  205. }
  206. function create_hash()
  207. {
  208. _mt_srand();
  209. return md5(uniqid(mt_rand(), true));
  210. }
  211. //---
  212. function &get_crypt_blowfish()
  213. {
  214. static $singleton;
  215. if (empty($singleton)) {
  216. if (OPENPNE_USE_OLD_CRYPT_BLOWFISH) {
  217. include_once 'Crypt/BlowfishOld.php';
  218. $singleton = new Crypt_BlowfishOld(ENCRYPT_KEY);
  219. } else {
  220. include_once 'Crypt/Blowfish.php';
  221. $singleton = new Crypt_Blowfish(ENCRYPT_KEY);
  222. }
  223. }
  224. return $singleton;
  225. }
  226. /**
  227. * 可逆的な暗号化をする
  228. *
  229. * @param string $str 平文
  230. * @return string 暗号文
  231. */
  232. function t_encrypt($str)
  233. {
  234. if (!$str) return '';
  235. $bf =& get_crypt_blowfish();
  236. $str = $bf->encrypt($str);
  237. //base64
  238. $str = base64_encode($str);
  239. return $str;
  240. }
  241. /**
  242. * 可逆的な暗号を復号化する
  243. *
  244. * @param string $str 暗号文
  245. * @return string 平文
  246. */
  247. function t_decrypt($str)
  248. {
  249. if (!$str) return '';
  250. //base64
  251. $str = base64_decode($str);
  252. $bf =& get_crypt_blowfish();
  253. return rtrim($bf->decrypt($str));
  254. }
  255. function t_wordwrap($str, $width = 80, $break = "\n")
  256. {
  257. if (!$width) {
  258. return $str;
  259. }
  260. $lines = explode($break, $str);
  261. foreach ($lines as $key => $line) {
  262. if (mb_strwidth($line) > $width) {
  263. $new_line = '';
  264. do {
  265. if ($new_line) {
  266. $new_line .= $break;
  267. }
  268. $tmp = mb_strimwidth($line, 0, $width);
  269. $new_line .= $tmp;
  270. $line = substr($line, strlen($tmp));
  271. } while (strlen($line) > 0);
  272. $lines[$key] = $new_line;
  273. }
  274. }
  275. return implode($break, $lines);
  276. }
  277. function util_is_unused_mail($name)
  278. {
  279. $unused = explode(',', UNUSED_MAILS);
  280. return in_array($name, $unused);
  281. }
  282. function util_get_c_navi($navi_type = 'h')
  283. {
  284. switch ($navi_type) {
  285. case 'global':
  286. $navi_type = 'global';
  287. $navi = array(
  288. array('url' => '?m=pc&a=page_h_search', 'caption' => 'メンバー検索'),
  289. array('url' => '?m=pc&a=page_h_com_find_all', 'caption' => WORD_COMMUNITY . '検索'),
  290. array('url' => '?m=pc&a=page_h_review_search', 'caption' => 'レビュー検索'),
  291. array('url' => '?m=pc&a=page_h_home', 'caption' => 'マイホーム'),
  292. array('url' => '?m=pc&a=page_h_invite', 'caption' => '友人を誘う'),
  293. array('url' => '?m=pc&a=page_h_diary_list_all', 'caption' => '最新' . WORD_DIARY),
  294. array('url' => '?m=pc&a=page_h_ranking', 'caption' => 'ランキング'),
  295. array('url' => '?m=pc&a=page_h_config', 'caption' => '設定変更'),
  296. );
  297. break;
  298. case 'h':
  299. default:
  300. $navi_type = 'h';
  301. $navi = array(
  302. array('url' => '?m=pc&a=page_h_home', 'caption' => 'ホーム'),
  303. array('url' => '?m=pc&a=page_fh_friend_list', 'caption' => WORD_MY_FRIEND),
  304. array('url' => '?m=pc&a=page_fh_diary_list', 'caption' => WORD_DIARY),
  305. array('url' => '?m=pc&a=page_h_message_box', 'caption' => 'メッセージ'),
  306. array('url' => '?m=pc&a=page_h_ashiato', 'caption' => 'あしあと'),
  307. array('url' => '?m=pc&a=page_h_bookmark_list', 'caption' => 'お気に入り'),
  308. array('url' => '?m=pc&a=page_fh_review_list_member', 'caption' => 'マイレビュー'),
  309. array('url' => '?m=pc&a=page_h_prof', 'caption' => 'マイページ確認'),
  310. array('url' => '?m=pc&a=page_h_config_prof', 'caption' => 'プロフィール変更'),
  311. );
  312. break;
  313. case 'f':
  314. $navi = array(
  315. array('url' => '?m=pc&a=page_f_home', 'caption' => 'ホーム'),
  316. array('url' => '?m=pc&a=page_fh_friend_list', 'caption' => WORD_FRIEND),
  317. array('url' => '?m=pc&a=page_fh_diary_list', 'caption' => WORD_DIARY . 'を読む'),
  318. array('url' => '?m=pc&a=page_f_message_send', 'caption' => 'メッセージを送る'),
  319. array('url' => '?m=pc&a=page_f_bookmark_add', 'caption' => 'お気に入りに追加'),
  320. array('url' => '?m=pc&a=page_fh_review_list_member', 'caption' => 'レビュー'),
  321. array('url' => '?m=pc&a=page_f_invite', 'caption' => WORD_MY_FRIEND.'に紹介'),
  322. array('url' => '?m=pc&a=page_f_link_request', 'caption' => WORD_MY_FRIEND.'に追加'),
  323. array('url' => '?m=pc&a=page_f_intro_edit', 'caption' => '紹介文を書く'),
  324. );
  325. break;
  326. case 'c':
  327. $navi = array(
  328. array('url' => '?m=pc&a=page_c_home', 'caption' => WORD_COMMUNITY . 'トップ'),
  329. array('url' => '?m=pc&a=page_c_topic_list', 'caption' => '掲示板'),
  330. array('url' => '?m=pc&a=page_c_member_review', 'caption' => 'おすすめレビュー'),
  331. array('url' => '?m=pc&a=page_c_join_commu', 'caption' => WORD_COMMUNITY . 'に参加'),
  332. array('url' => '?m=pc&a=page_c_invite', 'caption' => WORD_MY_FRIEND.'に紹介'),
  333. array('url' => '?m=pc&a=page_c_leave_commu', 'caption' => WORD_COMMUNITY . 'を退会'),
  334. );
  335. break;
  336. }
  337. $db = db_get_c_navi($navi_type);
  338. foreach ($db as $value) {
  339. $i = $value['sort_order'] - 1;
  340. $navi[$i] = array('url' => $value['url'], 'caption' => $value['caption']);
  341. }
  342. return $navi;
  343. }
  344. /**
  345. * checkdate の wrapper function
  346. * Warning 対策
  347. */
  348. function t_checkdate($month, $day, $year)
  349. {
  350. return checkdate(intval($month), intval($day), intval($year));
  351. }
  352. /**
  353. * Date_Calc::isFutureDate の wrapper function
  354. */
  355. function t_isFutureDate($day, $month, $year)
  356. {
  357. include_once 'Date/Calc.php';
  358. return Date_Calc::isFutureDate(intval($day), intval($month), intval($year));
  359. }
  360. //---
  361. /**
  362. * Check c_diary.public_flag
  363. *
  364. * @param int $c_diary_id
  365. * @param int $c_member_id
  366. * @return bool allowed or not
  367. */
  368. function pne_check_diary_public_flag($c_diary_id, $c_member_id)
  369. {
  370. $c_diary = db_diary_get_c_diary4id($c_diary_id);
  371. if ($c_diary['c_member_id'] == $c_member_id) {
  372. return true;
  373. }
  374. switch ($c_diary['public_flag']) {
  375. case 'public':
  376. $allowed = true;
  377. break;
  378. case 'friend':
  379. $allowed = db_friend_is_friend($c_diary['c_member_id'], $c_member_id);
  380. break;
  381. case 'private':
  382. default:
  383. $allowed = false;
  384. break;
  385. }
  386. return $allowed;
  387. }
  388. function pne_url2a($url, $target = '_blank')
  389. {
  390. $length = 60;
  391. $etc = '...';
  392. if (strlen($url) > $length) {
  393. $length -= strlen($etc);
  394. $urlstr = substr($url, 0, $length) . $etc;
  395. } else {
  396. $urlstr = $url;
  397. }
  398. if ($target) {
  399. $target = sprintf(' target="%s"', $target);
  400. }
  401. $url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
  402. $urlstr = htmlspecialchars($urlstr, ENT_QUOTES, 'UTF-8');
  403. return sprintf('<a href="%s"%s>%s</a>', $url, $target, $urlstr);
  404. }
  405. function get_auth_config($is_ktai = false)
  406. {
  407. if (OPENPNE_AUTH_MODE == 'slavepne') {
  408. $config = $GLOBALS['_OPENPNE_AUTH_CONFIG'];
  409. } elseif (OPENPNE_AUTH_MODE == 'pneid') {
  410. $config['storage'] = 'DB';
  411. $config['is_lowercase_username'] = true;
  412. $config['options'] = array(
  413. 'dsn' => db_get_dsn(),
  414. 'auto_quote' => false,
  415. 'table' => 'c_member_secure AS cms INNER JOIN c_username AS cu USING (c_member_id)',
  416. 'db_fields' => 'cms.hashed_password AS hashed_password, cu.username AS username',
  417. 'usernamecol' => 'username',
  418. 'passwordcol' => 'hashed_password',
  419. 'cryptType' => 'md5',
  420. );
  421. } else {
  422. $config['storage'] = 'DB';
  423. $config['is_encrypt_username'] = true;
  424. if ($is_ktai) {
  425. $config['options'] = array(
  426. 'dsn' => db_get_dsn(),
  427. 'table' => 'c_member_secure',
  428. 'usernamecol' => 'ktai_address',
  429. 'passwordcol' => 'hashed_password',
  430. 'cryptType' => 'md5',
  431. );
  432. } else {
  433. $config['options'] = array(
  434. 'dsn' => db_get_dsn(),
  435. 'table' => 'c_member_secure',
  436. 'usernamecol' => 'pc_address',
  437. 'passwordcol' => 'hashed_password',
  438. 'cryptType' => 'md5',
  439. );
  440. }
  441. }
  442. $config['is_ktai'] = $is_ktai;
  443. if ($is_ktai) {
  444. $config['is_check_user_agent'] = OPENPNE_SESSION_CHECK_KTAI_USER_AGENT;
  445. } else {
  446. $config['is_check_user_agent'] = OPENPNE_SESSION_CHECK_PC_USER_AGENT;
  447. }
  448. return $config;
  449. }
  450. function crypt_func($raw_value,$cryptType)
  451. {
  452. if ( isset($cryptType)
  453. && $cryptType == 'none') {
  454. $cryptFunction = 'strval';
  455. } elseif ( isset($cryptType)
  456. && function_exists($cryptType)) {
  457. $cryptFunction = $cryptType;
  458. } else {
  459. $cryptFunction = 'md5';
  460. }
  461. return $cryptFunction($raw_value);
  462. }
  463. function check_action4pne_slave($is_ktai = false)
  464. {
  465. if (OPENPNE_AUTH_MODE == 'slavepne') {
  466. if ($is_ktai) {
  467. openpne_redirect('ktai');
  468. } else {
  469. openpne_redirect('pc');
  470. }
  471. }
  472. }
  473. function util_include_php_files($dir)
  474. {
  475. if (!is_dir($dir)) {
  476. return;
  477. }
  478. if ($dh = opendir($dir)) {
  479. while (($file = readdir($dh)) !== false) {
  480. if ($file[0] === '.') {
  481. continue;
  482. }
  483. $path = realpath($dir . '/' . $file);
  484. if (is_dir($path)) {
  485. util_include_php_files($path);
  486. } else {
  487. if (substr($file, -4, 4) === '.php') {
  488. include_once $path;
  489. }
  490. }
  491. }
  492. closedir($dh);
  493. }
  494. }
  495. function util_cast_public_flag_diary($public_flag, $default = 'public')
  496. {
  497. switch ($public_flag) {
  498. case 'public':
  499. case 'friend':
  500. case 'private':
  501. break;
  502. default:
  503. $public_flag = $default;
  504. break;
  505. }
  506. return $public_flag;
  507. }
  508. /**
  509. * 登録してもよいメールアドレスかどうか
  510. */
  511. function util_is_regist_mail_address($mail_address, $c_member_id = 0)
  512. {
  513. if (!db_common_is_mailaddress($mail_address)) {
  514. return false;
  515. }
  516. if (!db_member_is_limit_domain4mail_address($mail_address)) {
  517. return false;
  518. }
  519. if (db_member_is_sns_join4mail_address($mail_address, $c_member_id)) {
  520. return false;
  521. }
  522. return true;
  523. }
  524. /**
  525. * アップロード可能な拡張子のリストを取得
  526. */
  527. function util_get_file_allowed_extensions($format = null)
  528. {
  529. $list = array();
  530. if (FILE_ALLOWED_EXTENTIONS) {
  531. $exts = explode(',', FILE_ALLOWED_EXTENTIONS);
  532. foreach ((array)$exts as $ext) {
  533. if (trim($ext) !== '') {
  534. $list[] = trim($ext);
  535. }
  536. }
  537. }
  538. if ($format === 'string') {
  539. if ($list) {
  540. foreach ($list as $key => $value) {
  541. $list[$key] = '*.' . $value;
  542. }
  543. $list = implode('; ', $list);
  544. } else {
  545. $list = '';
  546. }
  547. }
  548. return $list;
  549. }
  550. /**
  551. * アップロード可能な拡張子かどうか
  552. */
  553. function util_check_file_extention($filename)
  554. {
  555. $extension = pathinfo($filename, PATHINFO_EXTENSION);
  556. $list = util_get_file_allowed_extensions();
  557. return (!$list || in_array($extension, $list));
  558. }
  559. /**
  560. * 参照可能なメッセージかどうか
  561. *
  562. * ・指定メンバーが送信者で、完全削除済でない
  563. * ・指定メンバーが受信者で、送信済であり完全削除済でない
  564. *
  565. * @param int $c_member_id
  566. * @param int $c_message_id
  567. * @return bool
  568. */
  569. function util_is_readable_message($c_member_id, $c_message_id)
  570. {
  571. $c_message = db_message_c_message4c_message_id($c_message_id);
  572. if ($c_message['c_member_id_from'] == $c_member_id) { // 自分が送信者
  573. if (!$c_message['is_kanzen_sakujo_from']) { // 完全削除済でない
  574. return true;
  575. }
  576. } elseif ($c_message['c_member_id_to'] == $c_member_id) { // 自分が受信者
  577. if ($c_message['is_send'] && !$c_message['is_kanzen_sakujo_to']) { // 送信済であり完全削除済でない
  578. return true;
  579. }
  580. }
  581. return false;
  582. }
  583. /**
  584. * DB内配色設定の未設定項目をデフォルトの配色設定で埋める
  585. *
  586. * @param array $c_config_color DB内配色設定
  587. * @param string $mode
  588. * @return array
  589. */
  590. function util_apply_color_default2current($c_config_color, $mode = 'pc')
  591. {
  592. if ($mode == 'ktai') {
  593. $default_color['color_23'] = $c_config_color['color_1'];
  594. $default_color['color_24'] = $c_config_color['color_14'];
  595. $default_color['color_25'] = $c_config_color['color_14'];
  596. $default_color['color_26'] = $c_config_color['color_14'];
  597. $default_color['color_27'] = $c_config_color['color_3'];
  598. $default_color['color_28'] = $c_config_color['color_14'];
  599. } else {
  600. $default_color['color_19'] = $c_config_color['color_13'];
  601. }
  602. $c_config_color = array_map('trim', $c_config_color);
  603. $empty_keys = array_keys($c_config_color, '');
  604. foreach ($empty_keys as $key) {
  605. if (array_key_exists($key, $default_color)) {
  606. $c_config_color[$key] = $default_color[$key];
  607. }
  608. }
  609. return $c_config_color;
  610. }
  611. function util_get_color_config()
  612. {
  613. $c_config_color = db_etc_c_config_color();
  614. $c_config_color = util_apply_color_default2current($c_config_color);
  615. $color_config = array(
  616. 'border_01' => $c_config_color['color_1'],
  617. 'border_07' => $c_config_color['color_2'],
  618. 'border_10' => $c_config_color['color_3'],
  619. 'bg_00' => $c_config_color['color_4'],
  620. 'bg_01' => $c_config_color['color_5'],
  621. 'bg_02' => $c_config_color['color_6'],
  622. 'bg_03' => $c_config_color['color_7'],
  623. 'bg_04' => $c_config_color['color_8'],
  624. 'bg_05' => $c_config_color['color_9'],
  625. 'bg_06' => $c_config_color['color_10'],
  626. 'bg_07' => $c_config_color['color_11'],
  627. 'bg_08' => $c_config_color['color_12'],
  628. 'bg_09' => $c_config_color['color_13'],
  629. 'bg_10' => $c_config_color['color_14'],
  630. 'bg_11' => $c_config_color['color_15'],
  631. 'bg_12' => $c_config_color['color_16'],
  632. 'bg_13' => $c_config_color['color_17'],
  633. 'bg_14' => $c_config_color['color_18'],
  634. 'color_19' => $c_config_color['color_19'],
  635. );
  636. return $color_config;
  637. }
  638. function util_get_color_config_ktai()
  639. {
  640. $c_config_color = db_etc_c_config_color_ktai();
  641. $c_config_color = util_apply_color_default2current($c_config_color, 'ktai');
  642. $color_config = array(
  643. 'bg_01' => $c_config_color['color_1'],
  644. 'bg_02' => $c_config_color['color_2'],
  645. 'bg_03' => $c_config_color['color_3'],
  646. 'bg_04' => $c_config_color['color_4'],
  647. 'bg_05' => $c_config_color['color_5'],
  648. 'bg_06' => $c_config_color['color_6'],
  649. 'bg_07' => $c_config_color['color_7'],
  650. 'bg_08' => $c_config_color['color_8'],
  651. 'bg_09' => $c_config_color['color_9'],
  652. 'bg_10' => $c_config_color['color_10'],
  653. 'border_01' => $c_config_color['color_11'],
  654. 'border_02' => $c_config_color['color_12'],
  655. 'border_03' => $c_config_color['color_13'],
  656. 'font_01' => $c_config_color['color_14'],
  657. 'font_02' => $c_config_color['color_15'],
  658. 'font_03' => $c_config_color['color_23'],
  659. 'font_04' => $c_config_color['color_17'],
  660. 'font_05' => $c_config_color['color_18'],
  661. 'font_06' => $c_config_color['color_19'],
  662. 'font_07' => $c_config_color['color_20'],
  663. 'font_08' => $c_config_color['color_21'],
  664. 'font_09' => $c_config_color['color_22'],
  665. 'color_24' => $c_config_color['color_24'],
  666. 'color_25' => $c_config_color['color_25'],
  667. 'color_26' => $c_config_color['color_26'],
  668. 'color_27' => $c_config_color['color_27'],
  669. 'color_28' => $c_config_color['color_28'],
  670. );
  671. return $color_config;
  672. }
  673. /**
  674. * メンバー登録を行う
  675. *
  676. * @param array $c_member
  677. * @param array $c_member_secure
  678. * @param array $c_member_profile_list
  679. * @param bool $is_password_encrypted パスワードが既に暗号化済みかどうか
  680. * @return int
  681. */
  682. function util_regist_c_member($c_member, $c_member_secure, $c_member_profile_list = array(), $is_password_encrypted = false)
  683. {
  684. // メール受信設定をデフォルト値に
  685. $c_member['is_receive_mail'] = 1;
  686. $c_member['is_receive_ktai_mail'] = 1;
  687. $c_member['is_receive_daily_news'] = 1;
  688. // メンバー登録
  689. $u = db_member_insert_c_member($c_member, $c_member_secure, $is_password_encrypted);
  690. if ($u === false) { // メンバー登録に失敗した場合
  691. return false;
  692. }
  693. if (OPENPNE_USE_POINT_RANK) {
  694. //入会者にポイント加算
  695. $point = db_action_get_point4c_action_id(1);
  696. db_point_add_point($u, $point);
  697. //メンバー招待をした人にポイント加算
  698. $point = db_action_get_point4c_action_id(7);
  699. db_point_add_point($c_member['c_member_id_invite'], $point);
  700. }
  701. // c_member_profile
  702. db_member_update_c_member_profile($u, $c_member_profile_list);
  703. // 招待者とフレンドリンク
  704. db_friend_insert_c_friend($u, $c_member['c_member_id_invite']);
  705. //管理画面で指定したコミュニティに強制参加
  706. $c_commu_id_list = db_commu_regist_join_list();
  707. foreach ($c_commu_id_list as $c_commu_id) {
  708. db_commu_join_c_commu($c_commu_id, $u);
  709. }
  710. // ログインIDを登録
  711. if (OPENPNE_AUTH_MODE == 'pneid') {
  712. $login_id = strtolower($c_member['login_id']);
  713. db_member_insert_username($u, $login_id);
  714. }
  715. return $u;
  716. }
  717. function util_get_preset_color_list($dir = 'pc')
  718. {
  719. $color_list_dir = OPENPNE_WEBAPP_DIR . '/lib/color/' . $dir . '/';
  720. $color_list = array();
  721. if ($dh = opendir($color_list_dir)) {
  722. while (($file = readdir($dh)) !== false) {
  723. if (array_pop(explode('.', $file)) == 'ini') {
  724. $color_list[$file] = parse_ini_file($color_list_dir . $file);
  725. }
  726. }
  727. closedir($dh);
  728. }
  729. ksort($color_list);
  730. return array_values($color_list);
  731. }
  732. function util_get_module_config($module)
  733. {
  734. $config = array();
  735. if ($file = openpne_ext_search($module . '/config.ini')) {
  736. $config = parse_ini_file($file, true);
  737. }
  738. return $config;
  739. }
  740. function util_get_validate_rules_profile($disp = 'config')
  741. {
  742. $disp_key = 'disp_' . $disp;
  743. $rules = array();
  744. $profile_list = db_member_c_profile_list4null();
  745. foreach ($profile_list as $profile) {
  746. if ($profile[$disp_key]) {
  747. $rule = array(
  748. 'type' => 'int',
  749. 'required' => $profile['is_required'],
  750. 'caption' => $profile['caption'],
  751. );
  752. switch ($profile['form_type']) {
  753. case 'text':
  754. case 'textlong':
  755. case 'textarea':
  756. $rule['type'] = $profile['val_type'];
  757. $rule['regexp'] = $profile['val_regexp'];
  758. $rule['min'] = $profile['val_min'];
  759. if ($profile['val_max']) {
  760. $rule['max'] = $profile['val_max'];
  761. }
  762. break;
  763. case 'checkbox':
  764. $rule['is_array'] = '1';
  765. break;
  766. }
  767. $rules[$profile['name']] = $rule;
  768. }
  769. }
  770. return $rules;
  771. }
  772. function util_send_header_internal_server_error()
  773. {
  774. header('HTTP/1.0 500 Internal Server Error');
  775. exit;
  776. }
  777. function util_output_xml4array($data, $root, $is_escape = true)
  778. {
  779. require_once 'XML/Serializer.php';
  780. $option = array(
  781. 'rootName' => $root,
  782. );
  783. $serializer = new XML_Serializer($option);
  784. if ($is_escape) {
  785. $data = util_escape4output_xml($data);
  786. }
  787. $result = $serializer->serialize($data);
  788. if ($result === true) {
  789. $xml = $serializer->getSerializedData();
  790. header('Content-Type: application/xml');
  791. echo $xml;
  792. exit;
  793. }
  794. util_send_header_internal_server_error();
  795. }
  796. function util_escape4output_xml($data)
  797. {
  798. if (is_array($data)) {
  799. foreach ($data as $key => $value) {
  800. $data[$key] = util_escape4output_xml($value);
  801. }
  802. return $data;
  803. } elseif (is_string($data)) {
  804. return htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
  805. } else {
  806. return $data;
  807. }
  808. }
  809. function util_get_img_url($filename, $width, $height)
  810. {
  811. require_once 'smarty_plugins/function.t_img_url.php';
  812. $params = array(
  813. 'filename' => $filename,
  814. 'w' => $width,
  815. 'h' => $height,
  816. );
  817. return smarty_function_t_img_url($params, $dummy);
  818. }
  819. function util_get_c_member_config_default()
  820. {
  821. $default_config = array(
  822. 'SEND_DIARY_COMMENT_MAIL_KTAI' => 0,
  823. 'IS_DISPLAY_NEWDIARY_HOME' => 1,
  824. 'IS_DISPLAY_NEWTOPIC_HOME' => 1,
  825. 'IS_DISPLAY_NEWDIARY_HOME_KTAI' => 1,
  826. 'IS_DISPLAY_NEWTOPIC_HOME_KTAI' => 1,
  827. 'IS_DISPLAY_BOOKMARK_DIARY_HOME' => 1,
  828. 'IS_DISPLAY_BOOKMARK_BLOG_HOME' => 1,
  829. 'IS_DISPLAY_SCHEDULE_HOME' => 1,
  830. 'SEND_RANK_UP_MAIL_PC' => 1,
  831. 'SEND_RANK_UP_MAIL_KTAI' => 1,
  832. 'IS_SEARCH_RESULT' => 1,
  833. );
  834. return $default_config;
  835. }
  836. function util_get_c_member_config($c_member_id)
  837. {
  838. $default_config = util_get_c_member_config_default();
  839. $member_config = array_merge($default_config, db_member_c_member_config4c_member_id($c_member_id));
  840. return $member_config;
  841. }
  842. /**
  843. * ページャの作成
  844. *
  845. * @param int $page
  846. * @param int $page_size
  847. * @param int $total_num
  848. * @return mixed $total_num が 0 の場合は null、それ以外の場合はページャ用の連想配列
  849. */
  850. function util_make_pager($page, $page_size, $total_num)
  851. {
  852. if ($total_num == 0) {
  853. return;
  854. }
  855. $pager = array(
  856. 'page' => $page,
  857. 'page_size' => $page_size,
  858. 'total_num' => $total_num,
  859. 'start_num' => ($page - 1) * $page_size + 1,
  860. 'end_num' => $page * $page_size,
  861. 'total_page' => ceil($total_num / $page_size),
  862. 'prev_page' => 0,
  863. 'next_page' => 0,
  864. );
  865. // 表示している最後の番号
  866. if ($pager['end_num'] > $pager['total_num'])
  867. $pager['end_num'] = $pager['total_num'];
  868. // 前ページ
  869. if ($pager['page'] > 1)
  870. $pager['prev_page'] = $page - 1;
  871. // 次ページ
  872. if ($pager['end_num'] < $pager['total_num'])
  873. $pager['next_page'] = $page + 1;
  874. $disp_first = max(($page - 10), 1);
  875. $disp_last = min(($page + 9), $pager['total_page']);
  876. for (; $disp_first <= $disp_last; $disp_first++) {
  877. $pager['disp_pages'][] = $disp_first;
  878. }
  879. return $pager;
  880. }
  881. /**
  882. * debug_backtrace() の結果を、出力用にフィルタリングする
  883. *
  884. * @param array $backtrace
  885. * @return array
  886. */
  887. function util_filter_backtrace($backtrace)
  888. {
  889. $result = $backtrace;
  890. $base_regex = '/^' . preg_quote(OPENPNE_DIR, '/') . '/';
  891. foreach ($backtrace as $key => $value) {
  892. // 関数・メソッドの引数
  893. if (!empty($value['args'])) {
  894. foreach ($value['args'] as $arg_num => $arg) {
  895. if (is_object($arg)) {
  896. $result[$key]['args'][$arg_num] = 'object(' . get_class($arg) . ')';
  897. } elseif (is_array($arg)) {
  898. $result[$key]['args'][$arg_num] = 'Array(' . count($arg) . ')';
  899. }
  900. }
  901. }
  902. // メソッドが所属しているクラス
  903. if (isset($value['object'])) {
  904. unset($result[$key]['object']);
  905. }
  906. // 関数・メソッドが定義されているファイル名を相対パスに変更
  907. $result[$key]['file'] = preg_replace($base_regex, '.', $value['file']);
  908. }
  909. return $result;
  910. }
  911. /**
  912. * マッチングした文字列を一時的に退避する
  913. *
  914. * $patterns に指定された正規表現のパターンにマッチするものをマーカーに置換し、
  915. * 置換後の文字列、マーカーと元の文字列の対応テーブルを返す。
  916. *
  917. * @param string $subject
  918. * @param array $patterns
  919. * @return array
  920. */
  921. function util_replace_patterns_to_marker($subject, $patterns = array())
  922. {
  923. $i = 0;
  924. $list = array();
  925. if (empty($patterns)) {
  926. $patterns = array(
  927. '/<input[^>]+>/is',
  928. '/<textarea.*?<\/textarea>/is',
  929. '/<option.*?<\/option>/is',
  930. '/<img[^>]+>/is',
  931. '/<head.*?<\/head>/is',
  932. '/response_comment_format\(\'.*?\'\)/is',
  933. );
  934. }
  935. foreach ($patterns as $pattern) {
  936. if (preg_match_all($pattern, $subject, $matches)) {
  937. foreach ($matches[0] as $match) {
  938. $replacement = '<<<MARKER:'.$i.'>>>';
  939. $list[$replacement] = $match;
  940. $i++;
  941. }
  942. }
  943. }
  944. $subject = str_replace(array_values($list), array_keys($list), $subject);
  945. return array($list, $subject);
  946. }
  947. /**
  948. * 連続投稿チェック用の情報を取得する
  949. *
  950. * @param int $u
  951. * @return array
  952. */
  953. function util_get_post_info($u)
  954. {
  955. $last_post_time = '';
  956. $post_count = 0;
  957. if (OPENPNE_POST_USE_DB) {
  958. list($last_post_time, $post_count) = db_etc_get_post_info($u);
  959. } else {
  960. $last_post_time = $_SESSION['last_post_time'];
  961. $post_count = $_SESSION['post_count'];
  962. }
  963. return array($last_post_time, $post_count);
  964. }
  965. /**
  966. * 連続投稿チェック用の情報を設定する
  967. *
  968. * @param int $u
  969. * @param int $post_time
  970. * @param int $post_count
  971. */
  972. function util_set_post_info($u, $post_time, $post_count)
  973. {
  974. if (OPENPNE_POST_USE_DB) {
  975. db_etc_set_post_info($u, $post_time, $post_count);
  976. } else {
  977. $_SESSION['last_post_time'] = $post_time;
  978. $_SESSION['post_count'] = $post_count;
  979. }
  980. }
  981. /**
  982. * 連続投稿確認用
  983. *
  984. * @param string $module
  985. * @param string $action
  986. * @param int $u
  987. * @return bool true : post OK
  988. * false : post NG
  989. */
  990. function util_do_post_interval_ok($module, $action, $u)
  991. {
  992. // チェックしない
  993. if (!OPENPNE_POST_INTERVAL_UNFAIR_SECOND || !isset($GLOBALS['CHECK_POST_ACTIONS'])) {
  994. return true;
  995. }
  996. if (in_array($action, $GLOBALS['CHECK_POST_ACTIONS'][$module])) {
  997. // 最終投稿時間と投稿回数を取得
  998. list($last_post_time, $post_count) = util_get_post_info($u);
  999. $now_time = time();
  1000. $interval = $now_time - (int)$last_post_time;
  1001. if (!$last_post_time || $interval > OPENPNE_POST_INTERVAL_UNFAIR_COUNT_RESET_SECOND) {
  1002. // 最終投稿時間が不明か、前回投稿から一定時間経過しているためカウントをリセットする
  1003. $post_count = 1;
  1004. } elseif ($interval < OPENPNE_POST_INTERVAL_UNFAIR_SECOND) {
  1005. $post_count++;
  1006. }
  1007. // 情報更新
  1008. util_set_post_info($u, $now_time, $post_count);
  1009. // 投稿回数が一定数以上のため、連続投稿であるとみなす
  1010. if ($post_count > OPENPNE_POST_INTERVAL_UNFAIR_COUNT) {
  1011. return false;
  1012. }
  1013. }
  1014. return true;
  1015. }
  1016. ?>