You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1224 lines
43 KiB

7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. /******************************************************************************************
  3. * print_r 예쁘게 출력해준다.
  4. * @param $str
  5. *****************************************************************************************/
  6. function print_r2($str) {
  7. echo "<pre>";
  8. print_r($str);
  9. echo "</pre>";
  10. }
  11. /*****************************************************************************************
  12. * Alert 창을 띄우고 특정 URL로 이동합니다.
  13. * @param string $msg
  14. * @param string $url
  15. ****************************************************************************************/
  16. function alert($msg = '', $url = '')
  17. {
  18. $CI =&get_instance();
  19. if (empty($msg)) {
  20. $msg = lang('common_invalid_request');
  21. }
  22. echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
  23. echo '<script type="text/javascript">alert("' . $msg . '");';
  24. if (empty($url)) {
  25. echo 'history.go(-1);';
  26. }
  27. if ($url) {
  28. echo 'document.location.href="' . $url . '"';
  29. }
  30. echo '</script>';
  31. exit;
  32. }
  33. /*****************************************************************************************
  34. * Alert 창을 띄우고 현재 팝업창을 닫습니다.
  35. * @param string $msg
  36. ****************************************************************************************/
  37. function alert_close($msg='', $refresh_parent = FALSE)
  38. {
  39. $CI =&get_instance();
  40. if (empty($msg)) {
  41. $msg = lang('common_invalid_request');
  42. }
  43. echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
  44. echo '<script type="text/javascript">alert("' . $msg . '");';
  45. if( $refresh_parent ) {
  46. echo 'opener.location.reload();';
  47. }
  48. echo 'window.close();';
  49. echo '</script>';
  50. exit;
  51. }
  52. /*****************************************************************************************
  53. * 로그인이 필요한 페이지임을 알리고, 로그인 페이지로 이동합니다.
  54. * @param string $msg
  55. ****************************************************************************************/
  56. function alert_login($url="members/login")
  57. {
  58. $CI =&get_instance();
  59. $url = base_url($url)."?reurl=".current_full_url(TRUE);
  60. echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
  61. echo '<script type="text/javascript">';
  62. echo 'document.location.href="' . $url . '"';
  63. echo '</script>';
  64. exit;
  65. }
  66. /*****************************************************************************************
  67. * 관리자용 MODAL 창을 닫고, 메시지를 띄운다.
  68. * @param string $msg
  69. * @param mixed $refresh TRUE : 부모창을 새로고침 FALSE : 아무행동안함 String : 입력한 String을 자바스크립트로 실행
  70. ****************************************************************************************/
  71. function alert_modal_close($msg="", $refresh=FALSE)
  72. {
  73. if (empty($msg)) {
  74. $msg = lang('common_invalid_request');
  75. }
  76. echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
  77. echo '<script type="text/javascript">alert("' . $msg . '");';
  78. echo 'parent.APP.MODAL.callback();';
  79. if($refresh === TRUE) {
  80. echo "parent.location.reload();";
  81. }
  82. else if (is_string($refresh) && $refresh ) {
  83. echo $refresh;
  84. }
  85. echo '</script>';
  86. exit;
  87. }
  88. /*****************************************************************************************
  89. * 관리자용 MODAL 창을 닫고, 메시지를 띄운다.
  90. * @param string $msg
  91. * @param mixed $refresh TRUE : 부모창을 새로고침 FALSE : 아무행동안함 String : 입력한 String을 자바스크립트로 실행
  92. ****************************************************************************************/
  93. function alert_modal2_close($msg="", $refresh=TRUE)
  94. {
  95. $CI =&get_instance();
  96. if (empty($msg)) {
  97. $msg = lang('common_invalid_request');
  98. }
  99. echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
  100. echo '<script type="text/javascript">alert("' . $msg . '");';
  101. echo 'parent.APP.MODAL2.callback();';
  102. if($refresh === TRUE) {
  103. echo "parent.location.reload();";
  104. }
  105. else if (is_string($refresh) && $refresh ) {
  106. echo $refresh;
  107. }
  108. echo '</script>';
  109. exit;
  110. }
  111. /******************************************************************************************
  112. * 특정문자열을 암호화하여 내보낸다.
  113. * @param $string
  114. * @return string
  115. *****************************************************************************************/
  116. function get_password_hash($string)
  117. {
  118. $CI =& get_instance();
  119. return hash('md5', $CI->config->item('encryption_key') . $string );
  120. }
  121. /****************************************************************************************
  122. * 배열의 특정 키값을 가져옵니다.
  123. * @param $item
  124. * @param $array
  125. * @param null $default
  126. * @return mixed|null
  127. ***************************************************************************************/
  128. function element($item, $array, $default = NULL)
  129. {
  130. return is_array($array) && array_key_exists($item, $array) && $array[$item] ? $array[$item] : $default;
  131. }
  132. /*****************************************************************************************
  133. * 현재 주소를 Parameter 포함해서 가져온다.
  134. * @return string
  135. ****************************************************************************************/
  136. function current_full_url($urlencode = FALSE)
  137. {
  138. $CI =& get_instance();
  139. $url = $CI->config->site_url($CI->uri->uri_string());
  140. $return = ($CI->input->server('QUERY_STRING'))
  141. ? $url . '?' . $CI->input->server('QUERY_STRING') : $url;
  142. return $urlencode ? urlencode($return) : $return;
  143. }
  144. /******************************************************************************************
  145. * 해당 URL이 우리 서버 도메인을 가르키는지 확인한다.
  146. * @param $url 체크할 URL
  147. * @param bool $check_file_exist 파일존재 여부까지 확인한다.
  148. * @return bool
  149. *****************************************************************************************/
  150. function is_my_domain($url, $check_file_exist = TRUE) {
  151. // 처음 시작이 / 이고 두번제 문자가 /이 아닐경우
  152. if( substr($url,0,1) === '/' && substr($url,1,1) !== '/' )
  153. {
  154. if( $check_file_exist ) {
  155. return file_exists( FCPATH . $url );
  156. }
  157. return TRUE;
  158. }
  159. if( strpos( $url, base_url()) !== FALSE ) {
  160. if( $check_file_exist ) {
  161. return file_exists( FCPATH . str_replace( base_url(), "", $url ));
  162. }
  163. return TRUE;
  164. }
  165. return FALSE;
  166. }
  167. /******************************************************************************************
  168. * 업로드를 위한 폴더를 생성한다.
  169. * @param string $dir
  170. *****************************************************************************************/
  171. function make_dir($dir = "", $make_date = TRUE, $return_only_filepath = FALSE)
  172. {
  173. $dir = str_replace("/", DIRECTORY_SEPARATOR, $dir);
  174. $dirs = explode(DIRECTORY_SEPARATOR, $dir);
  175. $now_dir = FCPATH;
  176. foreach($dirs as $dr)
  177. {
  178. if( empty($dr) ) continue;
  179. $now_dir .= DIRECTORY_SEPARATOR . $dr;
  180. if (is_dir($now_dir) === false) {
  181. $old = umask(0);
  182. mkdir($now_dir, 0777);
  183. umask($old);
  184. }
  185. }
  186. if( $make_date )
  187. {
  188. $now_dir .= DIRECTORY_SEPARATOR . date('Y');
  189. if( is_dir($now_dir) === false )
  190. {
  191. $old = umask(0);
  192. mkdir($now_dir, 0777);
  193. umask($old);
  194. }
  195. $now_dir .= DIRECTORY_SEPARATOR . date('m');
  196. if( is_dir($now_dir) === false )
  197. {
  198. $old = umask(0);
  199. mkdir($now_dir, 0777);
  200. umask($old);
  201. }
  202. }
  203. $now_dir .= DIRECTORY_SEPARATOR;
  204. $now_dir = str_replace(DIRECTORY_SEPARATOR, "/", $now_dir);
  205. if($return_only_filepath) {
  206. $fcpath = str_replace(DIRECTORY_SEPARATOR, "/", FCPATH);
  207. $now_dir = str_replace($fcpath, "", $now_dir);
  208. $now_dir = str_replace(FCPATH, "", $now_dir);
  209. }
  210. return $now_dir;
  211. }
  212. /******************************************************************************************
  213. * HTML 태그를 제거하고 일반 텍스트로 변경
  214. *****************************************************************************************/
  215. function get_text($str, $html=0, $restore=false)
  216. {
  217. $source[] = "<";
  218. $target[] = "&lt;";
  219. $source[] = ">";
  220. $target[] = "&gt;";
  221. $source[] = "\"";
  222. $target[] = "&#034;";
  223. $source[] = "\'";
  224. $target[] = "&#039;";
  225. if($restore)
  226. $str = str_replace($target, $source, $str);
  227. // 3.31
  228. // TEXT 출력일 경우 &amp; &nbsp; 등의 코드를 정상으로 출력해 주기 위함
  229. if ($html === 0) {
  230. $str = html_symbol($str);
  231. }
  232. if ($html) {
  233. $source[] = "\n";
  234. $target[] = "<br/>";
  235. }
  236. return str_replace($source, $target, $str);
  237. }
  238. /**
  239. * HTML 포함된 내용에서 요약본을 TEXT 형태로 뽑아낸다.
  240. * @param $str
  241. * @param bool $nl2br
  242. * @return mixed
  243. */
  244. function get_summary($str, $nl2br = FALSE)
  245. {
  246. $str = html_entity_decode($str);
  247. $str = strip_tags($str);
  248. if($nl2br) {
  249. $str = nl2br($str);
  250. }
  251. else {
  252. $str = str_replace("\n","",$str);
  253. }
  254. return get_text($str, $nl2br);
  255. }
  256. /**
  257. * 파일 사이즈를 알기쉽게 표기
  258. * @param $bytes
  259. * @param int $decimals
  260. * @return string
  261. */
  262. function format_size($bytes, $decimals = 2) {
  263. $size = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  264. $factor = floor((strlen($bytes) - 1) / 3);
  265. return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
  266. }
  267. /******************************************************************************************
  268. * HTML SYMBOL 변환
  269. * &nbsp; &amp; &middot; 등을 정상으로 출력
  270. *****************************************************************************************/
  271. function html_symbol($str)
  272. {
  273. return preg_replace("/\&([a-z0-9]{1,20}|\#[0-9]{0,3});/i", "&#038;\\1;", $str);
  274. }
  275. /******************************************************************************************
  276. * 에디터를 호출한다.
  277. *****************************************************************************************/
  278. function get_editor($name, $contents="", $class="", $is_dhtml_editor = true, $editor_type = 'ckeditor')
  279. {
  280. $param['id'] = $name;
  281. $param['name'] = $name;
  282. $param['height'] = '300px';
  283. $param['contents'] = $contents;
  284. $CI =& get_instance();
  285. if( $editor_type == 'smarteditor' && $is_dhtml_editor )
  286. {
  287. $param['editor_url'] = base_url('/plugins/smarteditor-2.9.0');
  288. $CI->site->add_js( $param['editor_url'] . "/js/service/HuskyEZCreator.js");
  289. $return = $CI->load->view("tools/".$editor_type, $param, TRUE);
  290. }
  291. else if ( $editor_type == 'ckeditor' && $is_dhtml_editor )
  292. {
  293. $param['editor_url'] = base_url('/plugins/ckeditor');
  294. $CI->site->add_js( $param['editor_url'] . "/ckeditor.js");
  295. $CI->site->add_js( $param['editor_url'] . "/config.js");
  296. $return = $CI->load->view("tools/".$editor_type, $param, TRUE);
  297. }
  298. else {
  299. $return = "\n<textarea id=\"" . $name . "\" name=\"" . $name . "\" class=\"" . $class . "\">" . $contents . "</textarea>";
  300. }
  301. return $return;
  302. }
  303. /*****************************************************************************************
  304. * 글자수를 잘라서 보여줍니다.
  305. * @param string $msg
  306. ****************************************************************************************/
  307. function cut_str($str = '', $len = '', $suffix = '…')
  308. {
  309. return mb_substr($str,0,$len) . $suffix;
  310. }
  311. /***************************************************************************************
  312. * 날짜를 일정 형식으로 보여줍니다.
  313. * @param $date
  314. * @return false|string
  315. **************************************************************************************/
  316. function display_datetime($datetime = '', $type = '', $custom = '')
  317. {
  318. $CI =& get_instance();
  319. if (empty($datetime)) {
  320. return false;
  321. }
  322. $datetime = is_int($datetime) ? $datetime : strtotime($datetime);
  323. if ($type === 'sns') {
  324. $diff = time() - $datetime;
  325. $s = 60; //1분 = 60초
  326. $h = $s * 60; //1시간 = 60분
  327. $d = $h * 24; //1일 = 24시간
  328. $y = $d * 10; //1년 = 1일 * 10일
  329. if ($diff < $s) {
  330. $result = $diff . langs('공통/time/second_ago');
  331. } elseif ($h > $diff && $diff >= $s) {
  332. $result = round($diff/$s) . langs('공통/time/minute_ago');
  333. } elseif ($d > $diff && $diff >= $h) {
  334. $result = round($diff/$h) . langs('공통/time/hour_ago');
  335. } elseif ($y > $diff && $diff >= $d) {
  336. $result = round($diff/$d) . langs('공통/time/days_ago');
  337. } else {
  338. if (date('Y-m-d', $datetime) == date('Y-m-d')) {
  339. $result = date('H:i', $datetime);
  340. } else {
  341. $result = date('Y.m.d', $datetime);
  342. }
  343. }
  344. } elseif ($type === 'user' && $custom) {
  345. return date($custom, $datetime);
  346. } elseif ($type === 'full') {
  347. if (date('Y-m-d', $datetime) == date('Y-m-d')) {
  348. $result = date('H:i', $datetime);
  349. } elseif (date('Y', $datetime) === date('Y')) {
  350. $result = date('m-d H:i', $datetime);
  351. } else {
  352. $result = date('Y-m-d', $datetime);
  353. }
  354. } else {
  355. if (date('Y-m-d', $datetime) === date('Y-m-d')) {
  356. $result = date('H:i', $datetime);
  357. } else {
  358. $result = date('Y.m.d', $datetime);
  359. }
  360. }
  361. return $result;
  362. }
  363. /****************************************************
  364. * IP를 일정형식으로 변환하여 보여줍니다.
  365. * @param string $ip
  366. * @param string $type
  367. * @return bool|mixed
  368. ***************************************************/
  369. function display_ipaddress($ip = '', $type = '0001')
  370. {
  371. if( empty($type) )
  372. {
  373. $CI =& get_instance();
  374. $type = $CI->site->config('style_ip_display');
  375. }
  376. if (empty($ip)) {
  377. return false;
  378. }
  379. $regex = '';
  380. $regex .= ($type[0] === '1') ? '\\1' : '&#9825;';
  381. $regex .= '.';
  382. $regex .= ($type[1] === '1') ? '\\2' : '&#9825;';
  383. $regex .= '.';
  384. $regex .= ($type[2] === '1') ? '\\3' : '&#9825;';
  385. $regex .= '.';
  386. $regex .= ($type[3] === '1') ? '\\4' : '&#9825;';
  387. return preg_replace("/([0-9]+).([0-9]+).([0-9]+).([0-9]+)/", $regex, $ip);
  388. }
  389. /**
  390. * HTML 스타일의 내용을 가공해서 가져온다.
  391. * @param string $content HTML태그를 포함한 내용
  392. * @param int $thumb_width 썸네일 너비
  393. * @param bool $autolink URL에 자동링크 여부
  394. * @param bool $popup 링크를 팝업으로 띄울것인가?
  395. * @param bool $writer_is_admin 작성자가 관리자인가?
  396. * @return mixed|string
  397. */
  398. function display_html_content($content = '', $thumb_width=700)
  399. {
  400. $source = array();
  401. $target = array();
  402. $source[] = '//';
  403. $target[] = '';
  404. $source[] = "/<\?xml:namespace prefix = o ns = \"urn:schemas-microsoft-com:office:office\" \/>/";
  405. $target[] = '';
  406. // 테이블 태그의 갯수를 세어 테이블이 깨지지 않도록 한다.
  407. $table_begin_count = substr_count(strtolower($content), '<table');
  408. $table_end_count = substr_count(strtolower($content), '</table');
  409. for ($i = $table_end_count; $i < $table_begin_count; $i++) {
  410. $content .= '</table>';
  411. }
  412. // 반응형에서 iframe의 비율을 맞추기위해 iframe을 div 태그로 감싼다.
  413. $content = preg_replace("/<iframe/","<div class=\"iframe-content\"><iframe", $content);
  414. $content = preg_replace("/<\/iframe>/","</iframe></div>", $content);
  415. $content = preg_replace($source, $target, $content);
  416. $content = url_auto_link($content);
  417. $content = html_purifier($content);
  418. $content = get_view_thumbnail($content, $thumb_width);
  419. $content = preg_replace_callback(
  420. "/{&#51648;&#46020;\:([^}]*)}/is", function($match) {
  421. global $thumb_width;
  422. return get_google_map($match[1], $thumb_width);
  423. }, $content);
  424. return $content;
  425. }
  426. function get_view_thumbnail($contents = '', $thumb_width= 0)
  427. {
  428. if (empty($contents)) {
  429. return false;
  430. }
  431. $CI = & get_instance();
  432. if (empty($thumb_width)) {
  433. $thumb_width = 700;
  434. }
  435. // $contents 중 img 태그 추출
  436. $matches = get_editor_image($contents, true);
  437. if (empty($matches) ) {
  438. return $contents;
  439. }
  440. $end = count(element(1, $matches, array()));
  441. for ($i = 0; $i < $end; $i++) {
  442. $img = $matches[1][$i];
  443. preg_match("/src=[\'\"]?([^>\'\"]+[^>\'\"]+)/i", $img, $m);
  444. $src = isset($m[1]) ? $m[1] : '';
  445. preg_match("/style=[\"\']?([^\"\'>]+)/i", $img, $m);
  446. $style = isset($m[1]) ? $m[1] : '';
  447. preg_match("/width:\s*(\d+)px/", $style, $m);
  448. $width = isset($m[1]) ? $m[1] : '';
  449. preg_match("/height:\s*(\d+)px/", $style, $m);
  450. $height = isset($m[1]) ? $m[1] : '';
  451. preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $img, $m);
  452. $alt = isset($m[1]) ? html_escape($m[1]) : '';
  453. if (empty($width)) {
  454. preg_match("/width=[\"\']?([^\"\']*)[\"\']?/", $img, $m);
  455. $width = isset($m[1]) ? html_escape($m[1]) : '';
  456. }
  457. if (empty($height)) {
  458. preg_match("/height=[\"\']?([^\"\']*)[\"\']?/", $img, $m);
  459. $height = isset($m[1]) ? html_escape($m[1]) : '';
  460. }
  461. // 이미지 path 구함
  462. $p = parse_url($src);
  463. if (isset($p['host']) && $p['host'] === $CI->input->server('HTTP_HOST') && strpos($p['path'], '/' . DIR_UPLOAD) !== false) {
  464. $src = str_replace(base_url('/') , '', $src);
  465. $thumb_tag = '<img src="' . thumbnail($src, $thumb_width) . '" ';
  466. } else {
  467. $thumb_tag = '<img src="' . $src . '" ';
  468. }
  469. if ($width) {
  470. $thumb_tag .= ' width="' . $width . '" ';
  471. }
  472. $thumb_tag .= 'alt="' . $alt . '" style="max-width:100%;"/>';
  473. $img_tag = $matches[0][$i];
  474. $contents = str_replace($img_tag, $thumb_tag, $contents);
  475. if ($width) {
  476. $thumb_tag .= ' width="' . $width . '" ';
  477. }
  478. $thumb_tag .= 'alt="' . $alt . '" style="max-width:100%;"/>';
  479. $img_tag = $matches[0][$i];
  480. $contents = str_replace($img_tag, $thumb_tag, $contents);
  481. }
  482. return $contents;
  483. }
  484. function html_purifier($html)
  485. {
  486. $CI = & get_instance();
  487. $white_iframe = $CI->site->config('allow_host');;
  488. $white_iframe = preg_replace("/[\r|\n|\r\n]+/", ",", $white_iframe);
  489. $white_iframe = preg_replace("/\s+/", "", $white_iframe);
  490. if ($white_iframe) {
  491. $white_iframe = explode(',', trim($white_iframe, ','));
  492. $white_iframe = array_unique($white_iframe);
  493. }
  494. $domains = array();
  495. if ($white_iframe) {
  496. foreach ($white_iframe as $domain) {
  497. $domain = trim($domain);
  498. if ($domain) {
  499. array_push($domains, $domain);
  500. }
  501. }
  502. }
  503. // 내 도메인도 추가
  504. array_push($domains, $CI->input->server('HTTP_HOST') . '/');
  505. $safeiframe = implode('|', $domains);
  506. if ( ! defined('INC_HTMLPurifier')) {
  507. include_once(APPPATH . 'third_party/htmlpurifier/HTMLPurifier.standalone.php');
  508. define('INC_HTMLPurifier', true);
  509. }
  510. $config = HTMLPurifier_Config::createDefault();
  511. // cache 디렉토리에 CSS, HTML, URI 디렉토리 등을 만든다.
  512. $cache_path = config_item('cache_path') ? config_item('cache_path') : APPPATH . 'cache/';
  513. $config->set('Cache.SerializerPath', $cache_path);
  514. $config->set('HTML.SafeEmbed', false);
  515. $config->set('HTML.SafeObject', false);
  516. $config->set('HTML.SafeIframe', true);
  517. $config->set('URI.SafeIframeRegexp','%^(https?:)?//(' . $safeiframe . ')%');
  518. $config->set('Attr.AllowedFrameTargets', array('_blank'));
  519. $config->set('Core.Encoding', 'utf-8');
  520. $config->set('Core.EscapeNonASCIICharacters', true);
  521. $config->set('HTML.MaxImgLength', null);
  522. $config->set('CSS.MaxImgLength', null);
  523. $purifier = new HTMLPurifier($config);
  524. return $purifier->purify($html);
  525. }
  526. function url_auto_link($str = '', $popup = true)
  527. {
  528. if (empty($str)) {
  529. return false;
  530. }
  531. $target = $popup ? 'target="_blank"' : '';
  532. $str = str_replace(
  533. array("&lt;", "&gt;", "&amp;", "&quot;", "&nbsp;", "&#039;"),
  534. array("\t_lt_\t", "\t_gt_\t", "&", "\"", "\t_nbsp_\t", "'"),
  535. $str
  536. );
  537. $str = preg_replace(
  538. "/([^(href=\"?'?)|(src=\"?'?)]|\(|^)((http|https|ftp|telnet|news|mms):\/\/[a-zA-Z0-9\.-]+\.[가-힣\xA1-\xFEa-zA-Z0-9\.:&#=_\?\/~\+%@;\-\|\,\(\)]+)/i",
  539. "\\1<a href=\"\\2\" {$target}>\\2</A>",
  540. $str
  541. );
  542. $str = preg_replace(
  543. "/(^|[\"'\s(])(www\.[^\"'\s()]+)/i",
  544. "\\1<a href=\"http://\\2\" {$target}>\\2</A>",
  545. $str
  546. );
  547. $str = preg_replace(
  548. "/[0-9a-z_-]+@[a-z0-9._-]{4,}/i",
  549. "<a href=\"mailto:\\0\">\\0</a>",
  550. $str
  551. );
  552. $str = str_replace(
  553. array("\t_nbsp_\t", "\t_lt_\t", "\t_gt_\t", "'"),
  554. array("&nbsp;", "&lt;", "&gt;", "&#039;"),
  555. $str
  556. );
  557. return $str;
  558. }
  559. function change_key_case($str)
  560. {
  561. $str = stripcslashes($str);
  562. preg_match_all('@(?P<attribute>[^\s\'\"]+)\s*=\s*(\'|\")?(?P<value>[^\s\'\"]+)(\'|\")?@i', $str, $match);
  563. $value = @array_change_key_case(array_combine($match['attribute'], $match['value']));
  564. return $value;
  565. }
  566. function get_google_map($geo_data = '', $maxwidth = '')
  567. {
  568. if (empty($geo_data)) {
  569. return;
  570. }
  571. $maxwidth = (int) $maxwidth;
  572. if (empty($maxwidth)) {
  573. $maxwidth = 700;
  574. }
  575. $geo_data = stripslashes($geo_data);
  576. $geo_data = str_replace('&quot;', '', $geo_data);
  577. if (empty($geo_data)) {
  578. return;
  579. }
  580. $map = array();
  581. $map = change_key_case($geo_data);
  582. if (isset($map['loc'])) {
  583. list($lat, $lng) = explode(',', element('loc', $map));
  584. $zoom = element('z', $map);
  585. } else {
  586. list($lat, $lng, $zoom) = explode(',', element('geo', $map));
  587. }
  588. if (empty($lat) OR empty($lng)) {
  589. return;
  590. }
  591. //Map
  592. $map['geo'] = $lat . ',' . $lng . ',' . $zoom;
  593. //Marker
  594. preg_match("/m=\"([^\"]*)\"/is", $geo_data, $marker);
  595. $map['m'] = element(1, $marker);
  596. $google_map = '<div style="width:100%; margin:0 auto 15px; max-width:'
  597. . $maxwidth . 'px;">' . PHP_EOL;
  598. $google_map .= '<iframe width="100%" height="480" src="'
  599. . base_url('popup/googlemap?geo=' . urlencode($map['geo'])
  600. . '&marker=' . urlencode($map['m']))
  601. . '" frameborder="0" scrolling="no"></iframe>' . PHP_EOL;
  602. $google_map .= '</div>' . PHP_EOL;
  603. return $google_map;
  604. }
  605. function get_array_query($str) {
  606. $str = stripcslashes($str);
  607. preg_match_all('@(?P<attribute>[^\s\'\"]+)\s*=\s*(\'|\")?(?P<value>[^\s\'\"]+)(\'|\")?@i', $str, $match);
  608. $value = @array_change_key_case(array_combine($match['attribute'], $match['value']));
  609. return $value;
  610. }
  611. function get_video_info($video_url) {
  612. $video = array();
  613. $query = array();
  614. $option = array();
  615. $video_url = trim(strip_tags($video_url));
  616. list($url, $opt) = explode("|", $video_url."|");
  617. $url = trim($url);
  618. if($url) {
  619. if(!preg_match('/(http|https)\:\/\//i', $url)) {
  620. $url = 'http:'.$url;
  621. }
  622. } else {
  623. return;
  624. }
  625. $video['video'] = str_replace(array("&nbsp;", " "), array("", ""), $url);
  626. $video['video_url'] = str_replace(array("&nbsp;", "&amp;", " "), array("", "&", ""), $url);
  627. if($opt) $option = get_array_query($opt);
  628. if( element("file", $option)) { //jwplayer
  629. $video['type'] = 'file';
  630. $video['vid'] = 'file';
  631. $video['img'] = (isset($option['img']) && $option['img']) ? str_replace(array("&nbsp;", " "), array("", ""), trim(strip_tags($option['img']))) : '';
  632. $video['caption'] = (isset($option['caption']) && $option['caption']) ? str_replace(array("&nbsp;", " "), array("", ""), trim(strip_tags($option['caption']))) : '';
  633. } else {
  634. $info = @parse_url($video['video_url']);
  635. if(isset($info['query']) && $info['query']) parse_str($info['query'], $query);
  636. if($info['host'] == "youtu.be") { //유튜브
  637. $video['type'] = 'youtube';
  638. $video['vid'] = trim(str_replace("/","", trim($info['path'])));
  639. $video['vid'] = substr($video['vid'], 0, 11);
  640. $video['vlist'] = element("list", $query);
  641. $query['autoplay'] = element("autoplay", $query);
  642. $video['auto'] = element("auto", $option, $query['autoplay']);
  643. $video['s'] = element("s", $option, $query['s']);
  644. } else if($info['host'] == "www.youtube.com" || $info['host'] == "m.youtube.com") { //유튜브
  645. $video['type'] = 'youtube';
  646. if(preg_match('/\/embed\//i', $video['video_url'])) {
  647. list($youtube_url, $youtube_opt) = explode("/embed/", $video['video_url']);
  648. $vids = explode("?", $youtube_opt);
  649. $video['vid'] = $vids[0];
  650. } else {
  651. $video['vid'] = element("v", $query);
  652. $video['vlist'] = element("list", $query);
  653. }
  654. $query['autoplay'] = element("autoplay", $query);
  655. $video['auto'] = element("auto", $option, $query['autoplay']);
  656. $video['s'] = element("s", $option, element("s", $query));
  657. } else if($info['host'] == "vimeo.com") { //비메오
  658. $video['type'] = 'vimeo';
  659. $vquery = explode("/",$video['video_url']);
  660. $num = count($vquery) - 1;
  661. list($video['vid']) = explode("#",$vquery[$num]);
  662. if(strpos($video['vid'],'?') !== FALSE)
  663. {
  664. $tmp = explode("?", $video['vid']);
  665. $video['vid'] = $tmp[0];
  666. }
  667. } else if($info['host'] == "www.ted.com") { //테드
  668. $video['type'] = 'ted';
  669. $vids = explode("?", $video['video_url']);
  670. $vquery = explode("/",$vids[0]);
  671. $num = count($vquery) - 1;
  672. list($video['vid']) = explode(".", $vquery[$num]);
  673. list($rid) = explode(".", trim($info['path']));
  674. $rid = str_replace($video['vid'], '', $rid);
  675. $lang = (isset($query['language']) && $query['language']) ? 'lang/'.$query['language'].'/' : '';
  676. if($lang) {
  677. $rid = (stripos($rid, $lang) === false) ? $rid.$lang : $rid;
  678. }
  679. $video['rid'] = trim($rid.$video['vid']).'.html';
  680. } else if($info['host'] == "tvpot.daum.net") { //다음tv
  681. $video['type'] = 'daum';
  682. if(isset($query['vid']) && $query['vid']) {
  683. $video['vid'] = $query['vid'];
  684. $video['rid'] = $video['vid'];
  685. } else {
  686. if(isset($query['clipid']) && $query['clipid']) {
  687. $video['vid'] = $query['clipid'];
  688. } else {
  689. $video['vid'] = trim(str_replace("/v/","",$info['path']));
  690. }
  691. $play = get_vid($video['video_url'], $video['vid'], $video['type']);
  692. $video['rid'] = $play['rid'];
  693. }
  694. } else if($info['host'] == "channel.pandora.tv") { //판도라tv
  695. $video['type'] = 'pandora';
  696. $video['ch_userid'] = (isset($query['ch_userid']) && $query['ch_userid']) ? $query['ch_userid'] : '';
  697. $video['prgid'] = (isset($query['prgid']) && $query['prgid']) ? $query['prgid'] : '';
  698. $video['vid'] = $video['ch_userid'].'_'.$video['prgid'];
  699. } else if($info['host'] == "pann.nate.com") { //네이트tv
  700. $video['type'] = 'nate';
  701. $video['vid'] = trim(str_replace("/video/","",$info['path']));
  702. $play = get_vid($video['video_url'], $video['vid'], $video['type']);
  703. $video['mov_id'] = (isset($play['mov_id']) && $play['mov_id']) ? $play['mov_id'] : '';
  704. $video['vs_keys'] = (isset($play['vs_keys']) && $play['vs_keys']) ? $play['vs_keys'] : '';
  705. } else if($info['host'] == "www.tagstory.com") { //Tagstory
  706. $video['type'] = 'tagstory';
  707. $vquery = explode("/",$video['video_url']);
  708. $num = count($vquery) - 1;
  709. $video['vid'] = $vquery[$num];
  710. } else if($info['host'] == "dai.ly" || $info['host'] == "www.dailymotion.com") { //Dailymotion
  711. $video['type'] = 'dailymotion';
  712. if($info['host'] == "dai.ly") {
  713. $video['vid'] = trim($info['path']);
  714. } else {
  715. $vurl = explode("#", $video['video_url']);
  716. $vquery = explode("/", $vurl[0]);
  717. $num = count($vquery) - 1;
  718. list($video['vid']) = explode("_", $vquery[$num]);
  719. }
  720. } else if($info['host'] == "www.facebook.com") { //Facebook - 라니안님 코드 반영
  721. $video['type'] = 'facebook';
  722. if(isset($query['video_id']) && $query['video_id']){
  723. $video['vid'] = $query['video_id'];
  724. } else if(isset($query['v']) && $query['v']) {
  725. $video['vid'] = $query['v'];
  726. } else {
  727. $vtmp = explode("/videos/", trim($info['path']));
  728. $vquery = explode("/", $vtmp[1]);
  729. $video['vid'] = $vquery[0];
  730. }
  731. if(!is_numeric($video['vid'])) $video = NULL;
  732. } else if($info['host'] == "serviceapi.nmv.naver.com") { // 네이버 - 라니안님 코드 반영
  733. $video['type'] = 'naver';
  734. $video['vid'] = (isset($query['vid']) && $query['vid']) ? $query['vid'] : '';
  735. $video['outKey'] = (isset($query['outKey']) && $query['outKey']) ? $query['outKey'] : '';
  736. } else if($info['host'] == "serviceapi.rmcnmv.naver.com") { // 네이버 - 라니안님 코드 반영
  737. $video['type'] = 'tvcast';
  738. $video['vid'] = (isset($query['vid']) && $query['vid']) ? $query['vid'] : '';
  739. $video['outKey'] = (isset($query['outKey']) && $query['outKey']) ? $query['outKey'] : '';
  740. } else if($info['host'] == "tvcast.naver.com") { // 네이버 tvcast 단축주소 - 라니안님 코드 반영
  741. $video['type'] = 'tvcast';
  742. $video['clipNo'] = trim(str_replace("/v/","",$info['path']));
  743. $play = get_vid($video['video_url'], $video['clipNo'], $video['type']);
  744. $video['vid'] = (isset($play['vid']) && $play['vid']) ? $play['vid'] : '';
  745. $video['outKey'] = (isset($play['outKey']) && $play['outKey']) ? $play['outKey'] : '';
  746. } else if($info['host'] == "www.slideshare.net") { // slidershare
  747. $video['type'] = 'slidershare';
  748. $play = get_vid($video['video_url'], 1, $video['type']);
  749. $video['play_url'] = (isset($play['play_url']) && $play['play_url']) ? $play['play_url'] : '';
  750. $video['vid'] = (isset($play['vid']) && $play['vid']) ? $play['vid'] : '';
  751. } else if($info['host'] == "vid.me") { // vid.me
  752. $video['type'] = 'vid';
  753. $video['vid'] = trim(str_replace("/","",$info['path']));
  754. $query['autoplay'] = (isset($query['autoplay']) && $query['autoplay']) ? $query['autoplay'] : '';
  755. $video['auto'] = (isset($option['auto']) && $option['auto']) ? $option['auto'] : $query['autoplay'];
  756. } else if($info['host'] == "sendvid.com") { // sendvid.com
  757. $video['type'] = 'sendvid';
  758. $video['vid'] = trim(str_replace("/","",$info['path']));
  759. } else if($info['host'] == "vine.co") { // vine.co
  760. $video['type'] = 'vine';
  761. $vtmp = explode("/v/", trim($info['path']));
  762. $vquery = explode("/", $vtmp[1]);
  763. $video['vid'] = $vquery[0];
  764. }
  765. }
  766. $video['thumb'] = "";
  767. if( isset($video) && isset($video['video_url']) && isset($video['vid']) && $video['type'] ) {
  768. $video['thumb'] = get_video_imgurl( $video['video_url'], $video['vid'], $video['type'] );
  769. }
  770. return $video;
  771. }
  772. function get_vid($url, $vid, $type) {
  773. $play = array();
  774. $info = array();
  775. $query = array();
  776. if (!$url || !$vid || !$type || ($type == 'file')) return;
  777. $ch = curl_init();
  778. curl_setopt($ch, CURLOPT_URL, $url);
  779. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  780. curl_setopt($ch, CURLOPT_HEADER, 0);
  781. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  782. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  783. $output = curl_exec($ch);
  784. curl_close($ch);
  785. if($type == "tvcast"){
  786. preg_match('/nhn.rmcnmv.RMCVideoPlayer\("(?P<vid>[A-Z0-9]+)", "(?P<inKey>[a-z0-9]+)"/i', $output, $video);
  787. $play['vid'] = element("vid", $video);
  788. $play['inkey'] = element("inKey", $video);
  789. $ch = curl_init();
  790. curl_setopt($ch, CURLOPT_URL, "http://serviceapi.rmcnmv.naver.com/flash/getExternSwfUrl.nhn?vid=".$play['vid'].'&inKey='.$play['inkey']);
  791. curl_setopt($ch, CURLOPT_HEADER, 0);
  792. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  793. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  794. $output = curl_exec($ch);
  795. curl_close($ch);
  796. preg_match('/&outKey=(?P<outKey>[a-zA-Z0-9]+)&/i', $output, $video);
  797. $play['outKey']= (isset($video['outKey']) && $video['outKey']) ? $video['outKey'] : '';
  798. } else if($type == "daum") {
  799. preg_match('/\<meta property=\"og\:video\"([^\<\>])*\>/i', $output, $video);
  800. if($video) {
  801. $video = get_array_query($video[0]);
  802. $$video['content'] = preg_replace("/&amp;/", "&", $video['content']);
  803. $info = @parse_url($video['content']);
  804. $info['query'] = element("query", $info);
  805. parse_str($info['query'], $query);
  806. $play['rid'] = $query['vid'];
  807. }
  808. } else if($type == "nate") {
  809. preg_match('/mov_id = \"([^\"]*)\"/i', $output, $video);
  810. $play['mov_id'] = $video[0];
  811. preg_match('/vs_keys = \"([^\"]*)\"/i', $output, $video);
  812. $play['vs_keys'] = $video[0];
  813. if($play) {
  814. $meta = "<meta {$play[mov_id]} {$play[vs_keys]} >";
  815. $video = get_array_query($meta);
  816. $play['mov_id'] = element("mov_id", $video);
  817. $play['vs_keys'] = element("vs_keys", $video);;
  818. }
  819. } else if($type == "slidershare") {
  820. preg_match('/\<meta class=\"twitter_player\"([^\<\>])*\>/i', $output, $video);
  821. if($video) {
  822. $video = get_array_query($video[0]);
  823. $play['play_url'] = (isset($video['value']) && $video['value']) ? str_replace("&amp;", "&", $video['value']) : '';
  824. $info = @parse_url($play['play_url']);
  825. $play['vid'] = trim(str_replace("/slideshow/embed_code/","",$info['path']));
  826. }
  827. }
  828. return $play;
  829. }
  830. function get_video_imgurl($url, $vid, $type) {
  831. $imgurl = '';
  832. if($type == "file") { //JWPLAYER
  833. return;
  834. } else if($type == "vimeo") { //비메오
  835. $ch = curl_init();
  836. curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/".$vid.".php");
  837. curl_setopt($ch, CURLOPT_HEADER, 0);
  838. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  839. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  840. $output = unserialize(curl_exec($ch));
  841. curl_close($ch);
  842. $imgurl = $output[0]['thumbnail_large'];
  843. } else if($type == "youtube") { //유튜브
  844. $imgurl = 'http://img.youtube.com/vi/'.$vid.'/hqdefault.jpg';
  845. } else if($type == "sendvid") { //Sendvid
  846. $imgurl = 'https://sendvid.com/'.$vid.'.jpg';
  847. } else if($type == "facebook"){
  848. /*
  849. if(!defined('APMS_FACEBOOK_ACCESS_TOCKEN') || !APMS_FACEBOOK_ACCESS_TOCKEN) return;
  850. $ch = curl_init();
  851. curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.5/".$vid."?fields=id,picture&access_token=".APMS_FACEBOOK_ACCESS_TOCKEN);
  852. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  853. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  854. curl_setopt($ch, CURLOPT_HEADER, 0);
  855. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
  856. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  857. $output = json_decode(curl_exec($ch));
  858. curl_close($ch);
  859. $imgurl = $output->picture;
  860. */
  861. } else if($type == "naver" || $type == "tvcast"){ //라니안님 코드 반영
  862. $info = @parse_url($url);
  863. if($info['host'] == "tvcast.naver.com") {
  864. $ch = curl_init();
  865. curl_setopt($ch, CURLOPT_URL, $url);
  866. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  867. curl_setopt($ch, CURLOPT_HEADER, 0);
  868. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  869. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  870. $output = curl_exec($ch);
  871. curl_close($ch);
  872. preg_match('/property=\"og\:image\"[^\<\>]*\>/i', $output, $video);
  873. if($video) {
  874. $video = get_array_query($video[0]);
  875. if($video['content']) $imgurl = str_replace("type=f240", "type=f640", $video['content']); //640 사이즈로 변경
  876. }
  877. } else {
  878. $url_type = ($type == "naver") ? "nmv" : "rmcnmv"; // 네이버 블로그 영상과 tvcast 영상 구분
  879. parse_str($info['query'], $query);
  880. $vid .= "&outKey=".$query['outKey'];
  881. $ch = curl_init();
  882. curl_setopt($ch, CURLOPT_URL, "http://serviceapi.{$url_type}.naver.com/flash/videoInfo.nhn?vid=".$vid);
  883. curl_setopt($ch, CURLOPT_HEADER, 0);
  884. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  885. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  886. $output = curl_exec($ch);
  887. curl_close($ch);
  888. preg_match('/\<CoverImage\>\<\!\[CDATA\[(?P<img_url>[^\s\'\"]+)\]\]\>\<\/CoverImage\>/i', $output, $video);
  889. $imgurl = element("img_url", $video);
  890. }
  891. } else {
  892. $ch = curl_init();
  893. curl_setopt($ch, CURLOPT_URL, $url);
  894. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  895. curl_setopt($ch, CURLOPT_HEADER, 0);
  896. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  897. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  898. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  899. $output = curl_exec($ch);
  900. curl_close($ch);
  901. if($type == "slidershare") {
  902. preg_match('/<meta name=\"thumbnail\"[^\<\>]*\>/i', $output, $video);
  903. } else {
  904. preg_match("/<meta[^>]*content=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*property=\"og\:image\"/i", $output, $video);
  905. if($video[1]) {
  906. $imgurl = $video[1];
  907. } else {
  908. preg_match('/property=\"og\:image\"[^\<\>]*\>/i', $output, $video);
  909. }
  910. }
  911. if(!$imgurl && $video[0]) {
  912. $video = get_array_query($video[0]);
  913. $imgurl = $video['content'];
  914. }
  915. }
  916. return $imgurl;
  917. }
  918. function get_editor_image($contents = '', $view = true)
  919. {
  920. if (empty($contents)) {
  921. return false;
  922. }
  923. // $contents 중 img 태그 추출
  924. if ($view) {
  925. $pattern = "/<img([^>]*)>/iS";
  926. } else {
  927. $pattern = "/<img[^>]*src=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*>/i";
  928. }
  929. preg_match_all($pattern, $contents, $matchs);
  930. return $matchs;
  931. }
  932. function check_social_setting($provider="")
  933. {
  934. $CI=&get_instance();
  935. if( strtolower($provider) == 'facebook' ) return ($CI->site->config('social_facebook_use')=='Y' && $CI->site->config('social_facebook_appid') && $CI->site->config('social_facebook_appsecret'));
  936. else if( strtolower($provider) == 'google' ) return ($CI->site->config('social_google_use')=='Y' && $CI->site->config('social_google_clientid') && $CI->site->config('social_google_clientsecret'));
  937. else if( strtolower($provider) == 'naver') return ($CI->site->config('social_naver_use')=='Y' && $CI->site->config('social_naver_clientid') && $CI->site->config('social_naver_clientsecret'));
  938. else if( strtolower($provider) == 'kakao') return ($CI->site->config('social_kakao_use')=='Y' && $CI->site->config('social_kakao_clientid'));
  939. else if( empty($provider)) return ( check_social_setting('facebook') OR check_social_setting('google') OR check_social_setting('naver') OR check_social_setting('kakao') );
  940. else return FALSE;
  941. }
  942. /**
  943. * 회원 포인트 타입
  944. * @param bool $return
  945. * @return array|mixed
  946. */
  947. function point_type($return = FALSE)
  948. {
  949. $point = array(
  950. "NONE" => "기타",
  951. "POST_READ" => "게시글 읽기",
  952. "POST_WRITE" => "게시글 작성",
  953. "POST_LIKE" => "게시글 추천",
  954. "POST_ATTACH_DOWNLOAD" => "첨부파일 다운로드",
  955. "CMT_WRITE" => "댓글 작성",
  956. "CMT_LIKE" => "댓글 추천",
  957. "TODAY_LOGIN" => "오늘 첫 로그인",
  958. "JOIN" => "회원가입"
  959. );
  960. if( is_string($return) )
  961. {
  962. return $point[$return];
  963. }
  964. else if (is_bool($return) )
  965. {
  966. if( $return === TRUE )
  967. {
  968. return $point;
  969. }
  970. else {
  971. $return_val = array();
  972. foreach($point as $key=>$val)
  973. {
  974. $return_val[] = $key;
  975. }
  976. return $return_val;
  977. }
  978. }
  979. return array();
  980. }
  981. /**
  982. * 이미지가 존재한다면 해당 이미지의 태그를 리턴한다.
  983. * @param $thumb_path
  984. * @param string $add_class
  985. * @param string $add_attr
  986. * @return null|string
  987. */
  988. function thumb_img($thumb_path, $add_class="img-thumbnail", $add_attr="")
  989. {
  990. if(empty($thumb_path) ) return NULL;
  991. if(file_exists(FCPATH.$thumb_path)) {
  992. return '<img class="'.$add_class.'" src="'.base_url($thumb_path).'" '.$add_attr.'>';
  993. }
  994. }
  995. /**
  996. * 해당하는 파일을 삭제합니다.
  997. * @param string $filepath
  998. */
  999. function file_delete($filepath ="") {
  1000. if(empty($filepath))
  1001. return;
  1002. if($filepath && file_exists(FCPATH.$filepath) && is_file(FCPATH.$filepath)) {
  1003. @unlink(FCPATH.$filepath);
  1004. }
  1005. }
  1006. /**
  1007. * DB에 등록된 파일을 삭제하고 해당 DB의 파일 부분을 빈값으로 대체한다.
  1008. * @param $table
  1009. * @param $pk_column
  1010. * @param $pk
  1011. * @param $filepath_column
  1012. */
  1013. function db_file_delete($table, $pk_column, $pk, $filepath_column)
  1014. {
  1015. if(empty($table) OR empty($pk_column) OR empty($pk) OR empty($filepath_column)){
  1016. return FALSE;
  1017. }
  1018. $CI =& get_instance();
  1019. $original = $CI->db->where($pk_column, $pk)->get($table)->row_array();
  1020. if(! $original OR empty($original)) return false;
  1021. if(! isset($original[$filepath_column])) return false;
  1022. file_delete($original[$filepath_column]);
  1023. $CI->db->set($filepath_column, '');
  1024. $CI->db->where($pk_column, $pk);
  1025. $CI->db->update($table);
  1026. }
  1027. /**
  1028. * 내용 요약본을 가져온다.
  1029. * @param string $post_content
  1030. * @param int $length
  1031. * @return string
  1032. */
  1033. function get_post_summary($post_content="", $length=300)
  1034. {
  1035. return cut_str( trim( strip_tags( str_replace("&nbsp;", " ", $post_content)) ) ,$length);
  1036. }
  1037. /**
  1038. * 유일키 얻는다.
  1039. */
  1040. function get_uniqid()
  1041. {
  1042. $CI =& get_instance();
  1043. $tb = $CI->db->dbprefix('uniqid');
  1044. // 일주일 이상된 자료는 삭제한다.
  1045. $tmp_val = date('YmdHis', strtotime('-1 weeks')) . '00';
  1046. $CI->db->where('uq_id <=', $tmp_val);
  1047. $CI->db->delete('uniqid');
  1048. $CI->db->query("LOCK TABLE {$tb} WRITE ");
  1049. $key = null;
  1050. while (1) {
  1051. // 년월일시분초에 100분의 1초 두자리를 추가함 (1/100 초 앞에 자리가 모자르면 0으로 채움)
  1052. $key = date('YmdHis') . sprintf('%02d', (int)(microtime()*100));
  1053. $ip_addr = ip2long($CI->input->ip_address());
  1054. $result = $CI->db->set('uq_id', $key)->set('uq_ip', $ip_addr)->insert('uniqid');
  1055. if ($result) break; // 쿼리가 정상이면 빠진다.
  1056. // insert 하지 못했으면 일정시간 쉰다음 다시 유일키를 만든다.
  1057. usleep(10000); // 100분의 1초를 쉰다
  1058. }
  1059. $CI->db->query(" UNLOCK TABLES ");
  1060. return $key;
  1061. }