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.

1249 lines
44 KiB

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. $content = preg_replace($source, $target, $content);
  413. $content = url_auto_link($content);
  414. $content = html_purifier($content);
  415. $content = get_view_thumbnail($content, $thumb_width);
  416. $content = preg_replace_callback(
  417. "/{&#51648;&#46020;\:([^}]*)}/is", function($match) {
  418. global $thumb_width;
  419. return get_google_map($match[1], $thumb_width);
  420. }, $content);
  421. return $content;
  422. }
  423. function get_view_thumbnail($contents = '', $thumb_width= 0)
  424. {
  425. if (empty($contents)) {
  426. return false;
  427. }
  428. $CI = & get_instance();
  429. if (empty($thumb_width)) {
  430. $thumb_width = 700;
  431. }
  432. // $contents 중 img 태그 추출
  433. $matches = get_editor_image($contents, true);
  434. if (empty($matches) ) {
  435. return $contents;
  436. }
  437. $end = count(element(1, $matches, array()));
  438. for ($i = 0; $i < $end; $i++) {
  439. $img = $matches[1][$i];
  440. preg_match("/src=[\'\"]?([^>\'\"]+[^>\'\"]+)/i", $img, $m);
  441. $src = isset($m[1]) ? $m[1] : '';
  442. preg_match("/style=[\"\']?([^\"\'>]+)/i", $img, $m);
  443. $style = isset($m[1]) ? $m[1] : '';
  444. preg_match("/width:\s*(\d+)px/", $style, $m);
  445. $width = isset($m[1]) ? $m[1] : '';
  446. preg_match("/height:\s*(\d+)px/", $style, $m);
  447. $height = isset($m[1]) ? $m[1] : '';
  448. preg_match("/alt=[\"\']?([^\"\']*)[\"\']?/", $img, $m);
  449. $alt = isset($m[1]) ? html_escape($m[1]) : '';
  450. if (empty($width)) {
  451. preg_match("/width=[\"\']?([^\"\']*)[\"\']?/", $img, $m);
  452. $width = isset($m[1]) ? html_escape($m[1]) : '';
  453. }
  454. if (empty($height)) {
  455. preg_match("/height=[\"\']?([^\"\']*)[\"\']?/", $img, $m);
  456. $height = isset($m[1]) ? html_escape($m[1]) : '';
  457. }
  458. // 이미지 path 구함
  459. $p = parse_url($src);
  460. if (isset($p['host']) && $p['host'] === $CI->input->server('HTTP_HOST') && strpos($p['path'], '/' . DIR_UPLOAD) !== false) {
  461. $src = str_replace(base_url('/') , '', $src);
  462. $thumb_tag = '<img src="' . thumbnail($src, $thumb_width) . '" ';
  463. } else {
  464. $thumb_tag = '<img src="' . $src . '" ';
  465. }
  466. if ($width) {
  467. $thumb_tag .= ' width="' . $width . '" ';
  468. }
  469. $thumb_tag .= 'alt="' . $alt . '" style="max-width:100%;"/>';
  470. $img_tag = $matches[0][$i];
  471. $contents = str_replace($img_tag, $thumb_tag, $contents);
  472. if ($width) {
  473. $thumb_tag .= ' width="' . $width . '" ';
  474. }
  475. $thumb_tag .= 'alt="' . $alt . '" style="max-width:100%;"/>';
  476. $img_tag = $matches[0][$i];
  477. $contents = str_replace($img_tag, $thumb_tag, $contents);
  478. }
  479. return $contents;
  480. }
  481. function html_purifier($html)
  482. {
  483. $CI = & get_instance();
  484. $white_iframe = $CI->site->config('allow_host');;
  485. $white_iframe = preg_replace("/[\r|\n|\r\n]+/", ",", $white_iframe);
  486. $white_iframe = preg_replace("/\s+/", "", $white_iframe);
  487. if ($white_iframe) {
  488. $white_iframe = explode(',', trim($white_iframe, ','));
  489. $white_iframe = array_unique($white_iframe);
  490. }
  491. $domains = array();
  492. if ($white_iframe) {
  493. foreach ($white_iframe as $domain) {
  494. $domain = trim($domain);
  495. if ($domain) {
  496. array_push($domains, $domain);
  497. }
  498. }
  499. }
  500. // 내 도메인도 추가
  501. array_push($domains, $CI->input->server('HTTP_HOST') . '/');
  502. $safeiframe = implode('|', $domains);
  503. if ( ! defined('INC_HTMLPurifier')) {
  504. include_once(APPPATH . 'third_party/htmlpurifier/HTMLPurifier.standalone.php');
  505. define('INC_HTMLPurifier', true);
  506. }
  507. $config = HTMLPurifier_Config::createDefault();
  508. // cache 디렉토리에 CSS, HTML, URI 디렉토리 등을 만든다.
  509. $cache_path = config_item('cache_path') ? config_item('cache_path') : APPPATH . 'cache/';
  510. $config->set('Cache.SerializerPath', $cache_path);
  511. $config->set('HTML.SafeEmbed', false);
  512. $config->set('HTML.SafeObject', false);
  513. $config->set('HTML.SafeIframe', true);
  514. $config->set('URI.SafeIframeRegexp','%^(https?:)?//(' . $safeiframe . ')%');
  515. $config->set('Attr.AllowedFrameTargets', array('_blank'));
  516. $config->set('Core.Encoding', 'utf-8');
  517. $config->set('Core.EscapeNonASCIICharacters', true);
  518. $config->set('HTML.MaxImgLength', null);
  519. $config->set('CSS.MaxImgLength', null);
  520. $purifier = new HTMLPurifier($config);
  521. return $purifier->purify($html);
  522. }
  523. function url_auto_link($str = '', $popup = true)
  524. {
  525. if (empty($str)) {
  526. return false;
  527. }
  528. $target = $popup ? 'target="_blank"' : '';
  529. $str = str_replace(
  530. array("&lt;", "&gt;", "&amp;", "&quot;", "&nbsp;", "&#039;"),
  531. array("\t_lt_\t", "\t_gt_\t", "&", "\"", "\t_nbsp_\t", "'"),
  532. $str
  533. );
  534. $str = preg_replace(
  535. "/([^(href=\"?'?)|(src=\"?'?)]|\(|^)((http|https|ftp|telnet|news|mms):\/\/[a-zA-Z0-9\.-]+\.[가-힣\xA1-\xFEa-zA-Z0-9\.:&#=_\?\/~\+%@;\-\|\,\(\)]+)/i",
  536. "\\1<a href=\"\\2\" {$target}>\\2</A>",
  537. $str
  538. );
  539. $str = preg_replace(
  540. "/(^|[\"'\s(])(www\.[^\"'\s()]+)/i",
  541. "\\1<a href=\"http://\\2\" {$target}>\\2</A>",
  542. $str
  543. );
  544. $str = preg_replace(
  545. "/[0-9a-z_-]+@[a-z0-9._-]{4,}/i",
  546. "<a href=\"mailto:\\0\">\\0</a>",
  547. $str
  548. );
  549. $str = str_replace(
  550. array("\t_nbsp_\t", "\t_lt_\t", "\t_gt_\t", "'"),
  551. array("&nbsp;", "&lt;", "&gt;", "&#039;"),
  552. $str
  553. );
  554. return $str;
  555. }
  556. function change_key_case($str)
  557. {
  558. $str = stripcslashes($str);
  559. preg_match_all('@(?P<attribute>[^\s\'\"]+)\s*=\s*(\'|\")?(?P<value>[^\s\'\"]+)(\'|\")?@i', $str, $match);
  560. $value = @array_change_key_case(array_combine($match['attribute'], $match['value']));
  561. return $value;
  562. }
  563. function get_google_map($geo_data = '', $maxwidth = '')
  564. {
  565. if (empty($geo_data)) {
  566. return;
  567. }
  568. $maxwidth = (int) $maxwidth;
  569. if (empty($maxwidth)) {
  570. $maxwidth = 700;
  571. }
  572. $geo_data = stripslashes($geo_data);
  573. $geo_data = str_replace('&quot;', '', $geo_data);
  574. if (empty($geo_data)) {
  575. return;
  576. }
  577. $map = array();
  578. $map = change_key_case($geo_data);
  579. if (isset($map['loc'])) {
  580. list($lat, $lng) = explode(',', element('loc', $map));
  581. $zoom = element('z', $map);
  582. } else {
  583. list($lat, $lng, $zoom) = explode(',', element('geo', $map));
  584. }
  585. if (empty($lat) OR empty($lng)) {
  586. return;
  587. }
  588. //Map
  589. $map['geo'] = $lat . ',' . $lng . ',' . $zoom;
  590. //Marker
  591. preg_match("/m=\"([^\"]*)\"/is", $geo_data, $marker);
  592. $map['m'] = element(1, $marker);
  593. $google_map = '<div style="width:100%; margin:0 auto 15px; max-width:'
  594. . $maxwidth . 'px;">' . PHP_EOL;
  595. $google_map .= '<iframe width="100%" height="480" src="'
  596. . base_url('popup/googlemap?geo=' . urlencode($map['geo'])
  597. . '&marker=' . urlencode($map['m']))
  598. . '" frameborder="0" scrolling="no"></iframe>' . PHP_EOL;
  599. $google_map .= '</div>' . PHP_EOL;
  600. return $google_map;
  601. }
  602. /**
  603. * 게시물중에서
  604. * @param $post
  605. * @param string $thumb_width
  606. * @param string $thumb_height
  607. * @return string|void
  608. */
  609. function get_post_thumbnail($post, $thumb_width = '', $thumb_height = '')
  610. {
  611. $CI = & get_instance();
  612. if(empty($post) OR !is_array($post)) return '';
  613. // 첨부파일중 이미지중 첫번째를 가져온다.
  614. if( isset($post['file']) && count($post['file'])>0)
  615. {
  616. foreach($post['file'] as $file)
  617. {
  618. if($file['att_is_image'] == 'Y')
  619. {
  620. return thumbnail($file['att_filename'], $thumb_width, $thumb_height);
  621. }
  622. }
  623. }
  624. $matches = get_editor_image($post['post_content']);
  625. if (! empty($matches)) {
  626. $img = element(0, element(1, $matches));
  627. if (! empty($img)) {
  628. preg_match("/src=[\'\"]?([^>\'\"]+[^>\'\"]+)/i", $img, $m);
  629. $src = isset($m[1]) ? $m[1] : '';
  630. $p = parse_url($src);
  631. if (isset($p['host']) && $p['host'] === $CI->input->server('HTTP_HOST')
  632. && strpos($p['path'], '/' . DIR_UPLOAD) !== false) {
  633. $src = str_replace(base_url('/') , '', $src);
  634. $src = thumbnail( $src , $thumb_width, $thumb_height);
  635. }
  636. return $src;
  637. }
  638. }
  639. // 본문 내용중에 iframe 동영상 포함여부를 확인한다.
  640. preg_match_all("/<iframe[^>]*src=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*>/i", $post['post_content'], $matches);
  641. for($i=0; $i<count($matches[1]); $i++) {
  642. if(! isset($matches[1][$i]) ) continue;
  643. $video = get_video_info( $matches[1][$i] );
  644. // 비디오 타입이 아니거나, 알려지지 않은 비디오 일경우 건너뛴다.
  645. if(! $video['type'] OR ! $video['thumb']) continue;
  646. if($video['thumb']) {
  647. return $video['thumb'];
  648. }
  649. }
  650. // 본문내용중에 embed 태그 포함여부를 확인한다.
  651. preg_match_all("/<embed[^>]*src=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*>/i", $post['post_content'], $matches);
  652. for($i=0; $i<count($matches[1]); $i++) {
  653. if(! isset($matches[1][$i]) ) continue;
  654. $video = get_video_info( $matches[1][$i] );
  655. // 비디오 타입이 아니거나, 알려지지 않은 비디오 일경우 건너뛴다.
  656. if(! $video['type'] OR ! $video['thumb']) continue;
  657. if($video['thumb']) {
  658. return $video['thumb'];
  659. }
  660. }
  661. return '';
  662. }
  663. function get_array_query($str) {
  664. $str = stripcslashes($str);
  665. preg_match_all('@(?P<attribute>[^\s\'\"]+)\s*=\s*(\'|\")?(?P<value>[^\s\'\"]+)(\'|\")?@i', $str, $match);
  666. $value = @array_change_key_case(array_combine($match['attribute'], $match['value']));
  667. return $value;
  668. }
  669. function get_video_info($video_url) {
  670. $video = array();
  671. $query = array();
  672. $option = array();
  673. $video_url = trim(strip_tags($video_url));
  674. list($url, $opt) = explode("|", $video_url."|");
  675. $url = trim($url);
  676. if($url) {
  677. if(!preg_match('/(http|https)\:\/\//i', $url)) {
  678. $url = 'http:'.$url;
  679. }
  680. } else {
  681. return;
  682. }
  683. $video['video'] = str_replace(array("&nbsp;", " "), array("", ""), $url);
  684. $video['video_url'] = str_replace(array("&nbsp;", "&amp;", " "), array("", "&", ""), $url);
  685. if($opt) $option = get_array_query($opt);
  686. if( element("file", $option)) { //jwplayer
  687. $video['type'] = 'file';
  688. $video['vid'] = 'file';
  689. $video['img'] = (isset($option['img']) && $option['img']) ? str_replace(array("&nbsp;", " "), array("", ""), trim(strip_tags($option['img']))) : '';
  690. $video['caption'] = (isset($option['caption']) && $option['caption']) ? str_replace(array("&nbsp;", " "), array("", ""), trim(strip_tags($option['caption']))) : '';
  691. } else {
  692. $info = @parse_url($video['video_url']);
  693. if(isset($info['query']) && $info['query']) parse_str($info['query'], $query);
  694. if($info['host'] == "youtu.be") { //유튜브
  695. $video['type'] = 'youtube';
  696. $video['vid'] = trim(str_replace("/","", trim($info['path'])));
  697. $video['vid'] = substr($video['vid'], 0, 11);
  698. $video['vlist'] = element("list", $query);
  699. $query['autoplay'] = element("autoplay", $query);
  700. $video['auto'] = element("auto", $option, $query['autoplay']);
  701. $video['s'] = element("s", $option, $query['s']);
  702. } else if($info['host'] == "www.youtube.com" || $info['host'] == "m.youtube.com") { //유튜브
  703. $video['type'] = 'youtube';
  704. if(preg_match('/\/embed\//i', $video['video_url'])) {
  705. list($youtube_url, $youtube_opt) = explode("/embed/", $video['video_url']);
  706. $vids = explode("?", $youtube_opt);
  707. $video['vid'] = $vids[0];
  708. } else {
  709. $video['vid'] = element("v", $query);
  710. $video['vlist'] = element("list", $query);
  711. }
  712. $query['autoplay'] = element("autoplay", $query);
  713. $video['auto'] = element("auto", $option, $query['autoplay']);
  714. $video['s'] = element("s", $option, element("s", $query));
  715. } else if($info['host'] == "vimeo.com") { //비메오
  716. $video['type'] = 'vimeo';
  717. $vquery = explode("/",$video['video_url']);
  718. $num = count($vquery) - 1;
  719. list($video['vid']) = explode("#",$vquery[$num]);
  720. } else if($info['host'] == "www.ted.com") { //테드
  721. $video['type'] = 'ted';
  722. $vids = explode("?", $video['video_url']);
  723. $vquery = explode("/",$vids[0]);
  724. $num = count($vquery) - 1;
  725. list($video['vid']) = explode(".", $vquery[$num]);
  726. list($rid) = explode(".", trim($info['path']));
  727. $rid = str_replace($video['vid'], '', $rid);
  728. $lang = (isset($query['language']) && $query['language']) ? 'lang/'.$query['language'].'/' : '';
  729. if($lang) {
  730. $rid = (stripos($rid, $lang) === false) ? $rid.$lang : $rid;
  731. }
  732. $video['rid'] = trim($rid.$video['vid']).'.html';
  733. } else if($info['host'] == "tvpot.daum.net") { //다음tv
  734. $video['type'] = 'daum';
  735. if(isset($query['vid']) && $query['vid']) {
  736. $video['vid'] = $query['vid'];
  737. $video['rid'] = $video['vid'];
  738. } else {
  739. if(isset($query['clipid']) && $query['clipid']) {
  740. $video['vid'] = $query['clipid'];
  741. } else {
  742. $video['vid'] = trim(str_replace("/v/","",$info['path']));
  743. }
  744. $play = get_vid($video['video_url'], $video['vid'], $video['type']);
  745. $video['rid'] = $play['rid'];
  746. }
  747. } else if($info['host'] == "channel.pandora.tv") { //판도라tv
  748. $video['type'] = 'pandora';
  749. $video['ch_userid'] = (isset($query['ch_userid']) && $query['ch_userid']) ? $query['ch_userid'] : '';
  750. $video['prgid'] = (isset($query['prgid']) && $query['prgid']) ? $query['prgid'] : '';
  751. $video['vid'] = $video['ch_userid'].'_'.$video['prgid'];
  752. } else if($info['host'] == "pann.nate.com") { //네이트tv
  753. $video['type'] = 'nate';
  754. $video['vid'] = trim(str_replace("/video/","",$info['path']));
  755. $play = get_vid($video['video_url'], $video['vid'], $video['type']);
  756. $video['mov_id'] = (isset($play['mov_id']) && $play['mov_id']) ? $play['mov_id'] : '';
  757. $video['vs_keys'] = (isset($play['vs_keys']) && $play['vs_keys']) ? $play['vs_keys'] : '';
  758. } else if($info['host'] == "www.tagstory.com") { //Tagstory
  759. $video['type'] = 'tagstory';
  760. $vquery = explode("/",$video['video_url']);
  761. $num = count($vquery) - 1;
  762. $video['vid'] = $vquery[$num];
  763. } else if($info['host'] == "dai.ly" || $info['host'] == "www.dailymotion.com") { //Dailymotion
  764. $video['type'] = 'dailymotion';
  765. if($info['host'] == "dai.ly") {
  766. $video['vid'] = trim($info['path']);
  767. } else {
  768. $vurl = explode("#", $video['video_url']);
  769. $vquery = explode("/", $vurl[0]);
  770. $num = count($vquery) - 1;
  771. list($video['vid']) = explode("_", $vquery[$num]);
  772. }
  773. } else if($info['host'] == "www.facebook.com") { //Facebook - 라니안님 코드 반영
  774. $video['type'] = 'facebook';
  775. if(isset($query['video_id']) && $query['video_id']){
  776. $video['vid'] = $query['video_id'];
  777. } else if(isset($query['v']) && $query['v']) {
  778. $video['vid'] = $query['v'];
  779. } else {
  780. $vtmp = explode("/videos/", trim($info['path']));
  781. $vquery = explode("/", $vtmp[1]);
  782. $video['vid'] = $vquery[0];
  783. }
  784. if(!is_numeric($video['vid'])) $video = NULL;
  785. } else if($info['host'] == "serviceapi.nmv.naver.com") { // 네이버 - 라니안님 코드 반영
  786. $video['type'] = 'naver';
  787. $video['vid'] = (isset($query['vid']) && $query['vid']) ? $query['vid'] : '';
  788. $video['outKey'] = (isset($query['outKey']) && $query['outKey']) ? $query['outKey'] : '';
  789. } else if($info['host'] == "serviceapi.rmcnmv.naver.com") { // 네이버 - 라니안님 코드 반영
  790. $video['type'] = 'tvcast';
  791. $video['vid'] = (isset($query['vid']) && $query['vid']) ? $query['vid'] : '';
  792. $video['outKey'] = (isset($query['outKey']) && $query['outKey']) ? $query['outKey'] : '';
  793. } else if($info['host'] == "tvcast.naver.com") { // 네이버 tvcast 단축주소 - 라니안님 코드 반영
  794. $video['type'] = 'tvcast';
  795. $video['clipNo'] = trim(str_replace("/v/","",$info['path']));
  796. $play = get_vid($video['video_url'], $video['clipNo'], $video['type']);
  797. $video['vid'] = (isset($play['vid']) && $play['vid']) ? $play['vid'] : '';
  798. $video['outKey'] = (isset($play['outKey']) && $play['outKey']) ? $play['outKey'] : '';
  799. } else if($info['host'] == "www.slideshare.net") { // slidershare
  800. $video['type'] = 'slidershare';
  801. $play = get_vid($video['video_url'], 1, $video['type']);
  802. $video['play_url'] = (isset($play['play_url']) && $play['play_url']) ? $play['play_url'] : '';
  803. $video['vid'] = (isset($play['vid']) && $play['vid']) ? $play['vid'] : '';
  804. } else if($info['host'] == "vid.me") { // vid.me
  805. $video['type'] = 'vid';
  806. $video['vid'] = trim(str_replace("/","",$info['path']));
  807. $query['autoplay'] = (isset($query['autoplay']) && $query['autoplay']) ? $query['autoplay'] : '';
  808. $video['auto'] = (isset($option['auto']) && $option['auto']) ? $option['auto'] : $query['autoplay'];
  809. } else if($info['host'] == "sendvid.com") { // sendvid.com
  810. $video['type'] = 'sendvid';
  811. $video['vid'] = trim(str_replace("/","",$info['path']));
  812. } else if($info['host'] == "vine.co") { // vine.co
  813. $video['type'] = 'vine';
  814. $vtmp = explode("/v/", trim($info['path']));
  815. $vquery = explode("/", $vtmp[1]);
  816. $video['vid'] = $vquery[0];
  817. }
  818. }
  819. $video['thumb'] = "";
  820. if( isset($video) && isset($video['video_url']) && isset($video['vid']) && $video['type'] ) {
  821. $video['thumb'] = get_video_imgurl( $video['video_url'], $video['vid'], $video['type'] );
  822. }
  823. return $video;
  824. }
  825. function get_vid($url, $vid, $type) {
  826. $play = array();
  827. $info = array();
  828. $query = array();
  829. if (!$url || !$vid || !$type || ($type == 'file')) return;
  830. $ch = curl_init();
  831. curl_setopt($ch, CURLOPT_URL, $url);
  832. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  833. curl_setopt($ch, CURLOPT_HEADER, 0);
  834. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  835. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  836. $output = curl_exec($ch);
  837. curl_close($ch);
  838. if($type == "tvcast"){
  839. preg_match('/nhn.rmcnmv.RMCVideoPlayer\("(?P<vid>[A-Z0-9]+)", "(?P<inKey>[a-z0-9]+)"/i', $output, $video);
  840. $play['vid'] = element("vid", $video);
  841. $play['inkey'] = element("inKey", $video);
  842. $ch = curl_init();
  843. curl_setopt($ch, CURLOPT_URL, "http://serviceapi.rmcnmv.naver.com/flash/getExternSwfUrl.nhn?vid=".$play['vid'].'&inKey='.$play['inkey']);
  844. curl_setopt($ch, CURLOPT_HEADER, 0);
  845. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  846. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  847. $output = curl_exec($ch);
  848. curl_close($ch);
  849. preg_match('/&outKey=(?P<outKey>[a-zA-Z0-9]+)&/i', $output, $video);
  850. $play['outKey']= (isset($video['outKey']) && $video['outKey']) ? $video['outKey'] : '';
  851. } else if($type == "daum") {
  852. preg_match('/\<meta property=\"og\:video\"([^\<\>])*\>/i', $output, $video);
  853. if($video) {
  854. $video = get_array_query($video[0]);
  855. $$video['content'] = preg_replace("/&amp;/", "&", $video['content']);
  856. $info = @parse_url($video['content']);
  857. $info['query'] = element("query", $info);
  858. parse_str($info['query'], $query);
  859. $play['rid'] = $query['vid'];
  860. }
  861. } else if($type == "nate") {
  862. preg_match('/mov_id = \"([^\"]*)\"/i', $output, $video);
  863. $play['mov_id'] = $video[0];
  864. preg_match('/vs_keys = \"([^\"]*)\"/i', $output, $video);
  865. $play['vs_keys'] = $video[0];
  866. if($play) {
  867. $meta = "<meta {$play[mov_id]} {$play[vs_keys]} >";
  868. $video = get_array_query($meta);
  869. $play['mov_id'] = element("mov_id", $video);
  870. $play['vs_keys'] = element("vs_keys", $video);;
  871. }
  872. } else if($type == "slidershare") {
  873. preg_match('/\<meta class=\"twitter_player\"([^\<\>])*\>/i', $output, $video);
  874. if($video) {
  875. $video = get_array_query($video[0]);
  876. $play['play_url'] = (isset($video['value']) && $video['value']) ? str_replace("&amp;", "&", $video['value']) : '';
  877. $info = @parse_url($play['play_url']);
  878. $play['vid'] = trim(str_replace("/slideshow/embed_code/","",$info['path']));
  879. }
  880. }
  881. return $play;
  882. }
  883. function get_video_imgurl($url, $vid, $type) {
  884. $imgurl = '';
  885. if($type == "file") { //JWPLAYER
  886. return;
  887. } else if($type == "vimeo") { //비메오
  888. $ch = curl_init();
  889. curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/".$vid.".php");
  890. curl_setopt($ch, CURLOPT_HEADER, 0);
  891. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  892. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  893. $output = unserialize(curl_exec($ch));
  894. curl_close($ch);
  895. $imgurl = $output[0]['thumbnail_large'];
  896. } else if($type == "youtube") { //유튜브
  897. $imgurl = 'http://img.youtube.com/vi/'.$vid.'/hqdefault.jpg';
  898. } else if($type == "sendvid") { //Sendvid
  899. $imgurl = 'https://sendvid.com/'.$vid.'.jpg';
  900. } else if($type == "facebook"){
  901. /*
  902. if(!defined('APMS_FACEBOOK_ACCESS_TOCKEN') || !APMS_FACEBOOK_ACCESS_TOCKEN) return;
  903. $ch = curl_init();
  904. curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.5/".$vid."?fields=id,picture&access_token=".APMS_FACEBOOK_ACCESS_TOCKEN);
  905. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  906. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  907. curl_setopt($ch, CURLOPT_HEADER, 0);
  908. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
  909. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  910. $output = json_decode(curl_exec($ch));
  911. curl_close($ch);
  912. $imgurl = $output->picture;
  913. */
  914. } else if($type == "naver" || $type == "tvcast"){ //라니안님 코드 반영
  915. $info = @parse_url($url);
  916. if($info['host'] == "tvcast.naver.com") {
  917. $ch = curl_init();
  918. curl_setopt($ch, CURLOPT_URL, $url);
  919. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  920. curl_setopt($ch, CURLOPT_HEADER, 0);
  921. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  922. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  923. $output = curl_exec($ch);
  924. curl_close($ch);
  925. preg_match('/property=\"og\:image\"[^\<\>]*\>/i', $output, $video);
  926. if($video) {
  927. $video = get_array_query($video[0]);
  928. if($video['content']) $imgurl = str_replace("type=f240", "type=f640", $video['content']); //640 사이즈로 변경
  929. }
  930. } else {
  931. $url_type = ($type == "naver") ? "nmv" : "rmcnmv"; // 네이버 블로그 영상과 tvcast 영상 구분
  932. parse_str($info['query'], $query);
  933. $vid .= "&outKey=".$query['outKey'];
  934. $ch = curl_init();
  935. curl_setopt($ch, CURLOPT_URL, "http://serviceapi.{$url_type}.naver.com/flash/videoInfo.nhn?vid=".$vid);
  936. curl_setopt($ch, CURLOPT_HEADER, 0);
  937. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  938. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  939. $output = curl_exec($ch);
  940. curl_close($ch);
  941. preg_match('/\<CoverImage\>\<\!\[CDATA\[(?P<img_url>[^\s\'\"]+)\]\]\>\<\/CoverImage\>/i', $output, $video);
  942. $imgurl = element("img_url", $video);
  943. }
  944. } else {
  945. $ch = curl_init();
  946. curl_setopt($ch, CURLOPT_URL, $url);
  947. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  948. curl_setopt($ch, CURLOPT_HEADER, 0);
  949. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  950. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  951. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  952. $output = curl_exec($ch);
  953. curl_close($ch);
  954. if($type == "slidershare") {
  955. preg_match('/<meta name=\"thumbnail\"[^\<\>]*\>/i', $output, $video);
  956. } else {
  957. preg_match("/<meta[^>]*content=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*property=\"og\:image\"/i", $output, $video);
  958. if($video[1]) {
  959. $imgurl = $video[1];
  960. } else {
  961. preg_match('/property=\"og\:image\"[^\<\>]*\>/i', $output, $video);
  962. }
  963. }
  964. if(!$imgurl && $video[0]) {
  965. $video = get_array_query($video[0]);
  966. $imgurl = $video['content'];
  967. }
  968. }
  969. return $imgurl;
  970. }
  971. function get_editor_image($contents = '', $view = true)
  972. {
  973. if (empty($contents)) {
  974. return false;
  975. }
  976. // $contents 중 img 태그 추출
  977. if ($view) {
  978. $pattern = "/<img([^>]*)>/iS";
  979. } else {
  980. $pattern = "/<img[^>]*src=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*>/i";
  981. }
  982. preg_match_all($pattern, $contents, $matchs);
  983. return $matchs;
  984. }
  985. function check_social_setting($provider="")
  986. {
  987. $CI=&get_instance();
  988. if( strtolower($provider) == 'facebook' ) return ($CI->site->config('social_facebook_use')=='Y' && $CI->site->config('social_facebook_appid') && $CI->site->config('social_facebook_appsecret'));
  989. 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'));
  990. 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'));
  991. else if( strtolower($provider) == 'kakao') return ($CI->site->config('social_kakao_use')=='Y' && $CI->site->config('social_kakao_clientid'));
  992. else if( empty($provider)) return ( check_social_setting('facebook') OR check_social_setting('google') OR check_social_setting('naver') OR check_social_setting('kakao') );
  993. else return FALSE;
  994. }
  995. /**
  996. * 회원 포인트 타입
  997. * @param bool $return
  998. * @return array|mixed
  999. */
  1000. function point_type($return = FALSE)
  1001. {
  1002. $point = array(
  1003. "NONE" => "기타",
  1004. "POST_READ" => "게시글 읽기",
  1005. "POST_WRITE" => "게시글 작성",
  1006. "POST_LIKE" => "게시글 추천",
  1007. "POST_ATTACH_DOWNLOAD" => "첨부파일 다운로드",
  1008. "CMT_WRITE" => "댓글 작성",
  1009. "CMT_LIKE" => "댓글 추천",
  1010. "TODAY_LOGIN" => "오늘 첫 로그인",
  1011. "JOIN" => "회원가입"
  1012. );
  1013. if( is_string($return) )
  1014. {
  1015. return $point[$return];
  1016. }
  1017. else if (is_bool($return) )
  1018. {
  1019. if( $return === TRUE )
  1020. {
  1021. return $point;
  1022. }
  1023. else {
  1024. $return_val = array();
  1025. foreach($point as $key=>$val)
  1026. {
  1027. $return_val[] = $key;
  1028. }
  1029. return $return_val;
  1030. }
  1031. }
  1032. return array();
  1033. }
  1034. /**
  1035. * 이미지가 존재한다면 해당 이미지의 태그를 리턴한다.
  1036. * @param $thumb_path
  1037. * @param string $add_class
  1038. * @param string $add_attr
  1039. * @return null|string
  1040. */
  1041. function thumb_img($thumb_path, $add_class="img-thumbnail", $add_attr="")
  1042. {
  1043. if(empty($thumb_path) ) return NULL;
  1044. if(file_exists(FCPATH.$thumb_path)) {
  1045. return '<img class="'.$add_class.'" src="'.base_url($thumb_path).'" '.$add_attr.'>';
  1046. }
  1047. }
  1048. /**
  1049. * 해당하는 파일을 삭제합니다.
  1050. * @param string $filepath
  1051. */
  1052. function file_delete($filepath ="") {
  1053. if(empty($filepath))
  1054. return;
  1055. if($filepath && file_exists(FCPATH.$filepath) && is_file(FCPATH.$filepath)) {
  1056. @unlink(FCPATH.$filepath);
  1057. }
  1058. }
  1059. /**
  1060. * DB에 등록된 파일을 삭제하고 해당 DB의 파일 부분을 빈값으로 대체한다.
  1061. * @param $table
  1062. * @param $pk_column
  1063. * @param $pk
  1064. * @param $filepath_column
  1065. */
  1066. function db_file_delete($table, $pk_column, $pk, $filepath_column)
  1067. {
  1068. if(empty($table) OR empty($pk_column) OR empty($pk) OR empty($filepath_column)){
  1069. return FALSE;
  1070. }
  1071. $CI =& get_instance();
  1072. $original = $CI->db->where($pk_column, $pk)->get($table)->row_array();
  1073. if(! $original OR empty($original)) return false;
  1074. if(! isset($original[$filepath_column])) return false;
  1075. file_delete($original[$filepath_column]);
  1076. $CI->db->set($filepath_column, '');
  1077. $CI->db->where($pk_column, $pk);
  1078. $CI->db->update($table);
  1079. }