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.

1271 lines
45 KiB

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. /**
  606. * 게시물중에서
  607. * @param $post
  608. * @param string $thumb_width
  609. * @param string $thumb_height
  610. * @return string|void
  611. */
  612. function get_post_thumbnail($post, $thumb_width = '', $thumb_height = '')
  613. {
  614. $CI = & get_instance();
  615. if(empty($post) OR !is_array($post)) return '';
  616. // 첨부파일중 이미지중 첫번째를 가져온다.
  617. if( isset($post['file']) && count($post['file'])>0)
  618. {
  619. foreach($post['file'] as $file)
  620. {
  621. if($file['att_is_image'] == 'Y')
  622. {
  623. return thumbnail($file['att_filename'], $thumb_width, $thumb_height);
  624. }
  625. }
  626. }
  627. $matches = get_editor_image($post['post_content']);
  628. if (! empty($matches)) {
  629. $img = element(0, element(1, $matches));
  630. if (! empty($img)) {
  631. preg_match("/src=[\'\"]?([^>\'\"]+[^>\'\"]+)/i", $img, $m);
  632. $src = isset($m[1]) ? $m[1] : '';
  633. $p = parse_url($src);
  634. if (isset($p['host']) && $p['host'] === $CI->input->server('HTTP_HOST')
  635. && strpos($p['path'], '/' . DIR_UPLOAD) !== false) {
  636. $src = str_replace(base_url('/') , '', $src);
  637. $src = thumbnail( $src , $thumb_width, $thumb_height);
  638. }
  639. return $src;
  640. }
  641. }
  642. // 본문 내용중에 iframe 동영상 포함여부를 확인한다.
  643. preg_match_all("/<iframe[^>]*src=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*>/i", $post['post_content'], $matches);
  644. for($i=0; $i<count($matches[1]); $i++) {
  645. if(! isset($matches[1][$i]) ) continue;
  646. $video = get_video_info( $matches[1][$i] );
  647. // 비디오 타입이 아니거나, 알려지지 않은 비디오 일경우 건너뛴다.
  648. if(! $video['type'] OR ! $video['thumb']) continue;
  649. if($video['thumb']) {
  650. return $video['thumb'];
  651. }
  652. }
  653. // 본문내용중에 embed 태그 포함여부를 확인한다.
  654. preg_match_all("/<embed[^>]*src=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*>/i", $post['post_content'], $matches);
  655. for($i=0; $i<count($matches[1]); $i++) {
  656. if(! isset($matches[1][$i]) ) continue;
  657. $video = get_video_info( $matches[1][$i] );
  658. // 비디오 타입이 아니거나, 알려지지 않은 비디오 일경우 건너뛴다.
  659. if(! $video['type'] OR ! $video['thumb']) continue;
  660. if($video['thumb']) {
  661. return $video['thumb'];
  662. }
  663. }
  664. return '';
  665. }
  666. function get_array_query($str) {
  667. $str = stripcslashes($str);
  668. preg_match_all('@(?P<attribute>[^\s\'\"]+)\s*=\s*(\'|\")?(?P<value>[^\s\'\"]+)(\'|\")?@i', $str, $match);
  669. $value = @array_change_key_case(array_combine($match['attribute'], $match['value']));
  670. return $value;
  671. }
  672. function get_video_info($video_url) {
  673. $video = array();
  674. $query = array();
  675. $option = array();
  676. $video_url = trim(strip_tags($video_url));
  677. list($url, $opt) = explode("|", $video_url."|");
  678. $url = trim($url);
  679. if($url) {
  680. if(!preg_match('/(http|https)\:\/\//i', $url)) {
  681. $url = 'http:'.$url;
  682. }
  683. } else {
  684. return;
  685. }
  686. $video['video'] = str_replace(array("&nbsp;", " "), array("", ""), $url);
  687. $video['video_url'] = str_replace(array("&nbsp;", "&amp;", " "), array("", "&", ""), $url);
  688. if($opt) $option = get_array_query($opt);
  689. if( element("file", $option)) { //jwplayer
  690. $video['type'] = 'file';
  691. $video['vid'] = 'file';
  692. $video['img'] = (isset($option['img']) && $option['img']) ? str_replace(array("&nbsp;", " "), array("", ""), trim(strip_tags($option['img']))) : '';
  693. $video['caption'] = (isset($option['caption']) && $option['caption']) ? str_replace(array("&nbsp;", " "), array("", ""), trim(strip_tags($option['caption']))) : '';
  694. } else {
  695. $info = @parse_url($video['video_url']);
  696. if(isset($info['query']) && $info['query']) parse_str($info['query'], $query);
  697. if($info['host'] == "youtu.be") { //유튜브
  698. $video['type'] = 'youtube';
  699. $video['vid'] = trim(str_replace("/","", trim($info['path'])));
  700. $video['vid'] = substr($video['vid'], 0, 11);
  701. $video['vlist'] = element("list", $query);
  702. $query['autoplay'] = element("autoplay", $query);
  703. $video['auto'] = element("auto", $option, $query['autoplay']);
  704. $video['s'] = element("s", $option, $query['s']);
  705. } else if($info['host'] == "www.youtube.com" || $info['host'] == "m.youtube.com") { //유튜브
  706. $video['type'] = 'youtube';
  707. if(preg_match('/\/embed\//i', $video['video_url'])) {
  708. list($youtube_url, $youtube_opt) = explode("/embed/", $video['video_url']);
  709. $vids = explode("?", $youtube_opt);
  710. $video['vid'] = $vids[0];
  711. } else {
  712. $video['vid'] = element("v", $query);
  713. $video['vlist'] = element("list", $query);
  714. }
  715. $query['autoplay'] = element("autoplay", $query);
  716. $video['auto'] = element("auto", $option, $query['autoplay']);
  717. $video['s'] = element("s", $option, element("s", $query));
  718. } else if($info['host'] == "vimeo.com") { //비메오
  719. $video['type'] = 'vimeo';
  720. $vquery = explode("/",$video['video_url']);
  721. $num = count($vquery) - 1;
  722. list($video['vid']) = explode("#",$vquery[$num]);
  723. if(strpos($video['vid'],'?') !== FALSE)
  724. {
  725. $tmp = explode("?", $video['vid']);
  726. $video['vid'] = $tmp[0];
  727. }
  728. } else if($info['host'] == "www.ted.com") { //테드
  729. $video['type'] = 'ted';
  730. $vids = explode("?", $video['video_url']);
  731. $vquery = explode("/",$vids[0]);
  732. $num = count($vquery) - 1;
  733. list($video['vid']) = explode(".", $vquery[$num]);
  734. list($rid) = explode(".", trim($info['path']));
  735. $rid = str_replace($video['vid'], '', $rid);
  736. $lang = (isset($query['language']) && $query['language']) ? 'lang/'.$query['language'].'/' : '';
  737. if($lang) {
  738. $rid = (stripos($rid, $lang) === false) ? $rid.$lang : $rid;
  739. }
  740. $video['rid'] = trim($rid.$video['vid']).'.html';
  741. } else if($info['host'] == "tvpot.daum.net") { //다음tv
  742. $video['type'] = 'daum';
  743. if(isset($query['vid']) && $query['vid']) {
  744. $video['vid'] = $query['vid'];
  745. $video['rid'] = $video['vid'];
  746. } else {
  747. if(isset($query['clipid']) && $query['clipid']) {
  748. $video['vid'] = $query['clipid'];
  749. } else {
  750. $video['vid'] = trim(str_replace("/v/","",$info['path']));
  751. }
  752. $play = get_vid($video['video_url'], $video['vid'], $video['type']);
  753. $video['rid'] = $play['rid'];
  754. }
  755. } else if($info['host'] == "channel.pandora.tv") { //판도라tv
  756. $video['type'] = 'pandora';
  757. $video['ch_userid'] = (isset($query['ch_userid']) && $query['ch_userid']) ? $query['ch_userid'] : '';
  758. $video['prgid'] = (isset($query['prgid']) && $query['prgid']) ? $query['prgid'] : '';
  759. $video['vid'] = $video['ch_userid'].'_'.$video['prgid'];
  760. } else if($info['host'] == "pann.nate.com") { //네이트tv
  761. $video['type'] = 'nate';
  762. $video['vid'] = trim(str_replace("/video/","",$info['path']));
  763. $play = get_vid($video['video_url'], $video['vid'], $video['type']);
  764. $video['mov_id'] = (isset($play['mov_id']) && $play['mov_id']) ? $play['mov_id'] : '';
  765. $video['vs_keys'] = (isset($play['vs_keys']) && $play['vs_keys']) ? $play['vs_keys'] : '';
  766. } else if($info['host'] == "www.tagstory.com") { //Tagstory
  767. $video['type'] = 'tagstory';
  768. $vquery = explode("/",$video['video_url']);
  769. $num = count($vquery) - 1;
  770. $video['vid'] = $vquery[$num];
  771. } else if($info['host'] == "dai.ly" || $info['host'] == "www.dailymotion.com") { //Dailymotion
  772. $video['type'] = 'dailymotion';
  773. if($info['host'] == "dai.ly") {
  774. $video['vid'] = trim($info['path']);
  775. } else {
  776. $vurl = explode("#", $video['video_url']);
  777. $vquery = explode("/", $vurl[0]);
  778. $num = count($vquery) - 1;
  779. list($video['vid']) = explode("_", $vquery[$num]);
  780. }
  781. } else if($info['host'] == "www.facebook.com") { //Facebook - 라니안님 코드 반영
  782. $video['type'] = 'facebook';
  783. if(isset($query['video_id']) && $query['video_id']){
  784. $video['vid'] = $query['video_id'];
  785. } else if(isset($query['v']) && $query['v']) {
  786. $video['vid'] = $query['v'];
  787. } else {
  788. $vtmp = explode("/videos/", trim($info['path']));
  789. $vquery = explode("/", $vtmp[1]);
  790. $video['vid'] = $vquery[0];
  791. }
  792. if(!is_numeric($video['vid'])) $video = NULL;
  793. } else if($info['host'] == "serviceapi.nmv.naver.com") { // 네이버 - 라니안님 코드 반영
  794. $video['type'] = 'naver';
  795. $video['vid'] = (isset($query['vid']) && $query['vid']) ? $query['vid'] : '';
  796. $video['outKey'] = (isset($query['outKey']) && $query['outKey']) ? $query['outKey'] : '';
  797. } else if($info['host'] == "serviceapi.rmcnmv.naver.com") { // 네이버 - 라니안님 코드 반영
  798. $video['type'] = 'tvcast';
  799. $video['vid'] = (isset($query['vid']) && $query['vid']) ? $query['vid'] : '';
  800. $video['outKey'] = (isset($query['outKey']) && $query['outKey']) ? $query['outKey'] : '';
  801. } else if($info['host'] == "tvcast.naver.com") { // 네이버 tvcast 단축주소 - 라니안님 코드 반영
  802. $video['type'] = 'tvcast';
  803. $video['clipNo'] = trim(str_replace("/v/","",$info['path']));
  804. $play = get_vid($video['video_url'], $video['clipNo'], $video['type']);
  805. $video['vid'] = (isset($play['vid']) && $play['vid']) ? $play['vid'] : '';
  806. $video['outKey'] = (isset($play['outKey']) && $play['outKey']) ? $play['outKey'] : '';
  807. } else if($info['host'] == "www.slideshare.net") { // slidershare
  808. $video['type'] = 'slidershare';
  809. $play = get_vid($video['video_url'], 1, $video['type']);
  810. $video['play_url'] = (isset($play['play_url']) && $play['play_url']) ? $play['play_url'] : '';
  811. $video['vid'] = (isset($play['vid']) && $play['vid']) ? $play['vid'] : '';
  812. } else if($info['host'] == "vid.me") { // vid.me
  813. $video['type'] = 'vid';
  814. $video['vid'] = trim(str_replace("/","",$info['path']));
  815. $query['autoplay'] = (isset($query['autoplay']) && $query['autoplay']) ? $query['autoplay'] : '';
  816. $video['auto'] = (isset($option['auto']) && $option['auto']) ? $option['auto'] : $query['autoplay'];
  817. } else if($info['host'] == "sendvid.com") { // sendvid.com
  818. $video['type'] = 'sendvid';
  819. $video['vid'] = trim(str_replace("/","",$info['path']));
  820. } else if($info['host'] == "vine.co") { // vine.co
  821. $video['type'] = 'vine';
  822. $vtmp = explode("/v/", trim($info['path']));
  823. $vquery = explode("/", $vtmp[1]);
  824. $video['vid'] = $vquery[0];
  825. }
  826. }
  827. $video['thumb'] = "";
  828. if( isset($video) && isset($video['video_url']) && isset($video['vid']) && $video['type'] ) {
  829. $video['thumb'] = get_video_imgurl( $video['video_url'], $video['vid'], $video['type'] );
  830. }
  831. return $video;
  832. }
  833. function get_vid($url, $vid, $type) {
  834. $play = array();
  835. $info = array();
  836. $query = array();
  837. if (!$url || !$vid || !$type || ($type == 'file')) return;
  838. $ch = curl_init();
  839. curl_setopt($ch, CURLOPT_URL, $url);
  840. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  841. curl_setopt($ch, CURLOPT_HEADER, 0);
  842. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  843. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  844. $output = curl_exec($ch);
  845. curl_close($ch);
  846. if($type == "tvcast"){
  847. preg_match('/nhn.rmcnmv.RMCVideoPlayer\("(?P<vid>[A-Z0-9]+)", "(?P<inKey>[a-z0-9]+)"/i', $output, $video);
  848. $play['vid'] = element("vid", $video);
  849. $play['inkey'] = element("inKey", $video);
  850. $ch = curl_init();
  851. curl_setopt($ch, CURLOPT_URL, "http://serviceapi.rmcnmv.naver.com/flash/getExternSwfUrl.nhn?vid=".$play['vid'].'&inKey='.$play['inkey']);
  852. curl_setopt($ch, CURLOPT_HEADER, 0);
  853. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  854. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  855. $output = curl_exec($ch);
  856. curl_close($ch);
  857. preg_match('/&outKey=(?P<outKey>[a-zA-Z0-9]+)&/i', $output, $video);
  858. $play['outKey']= (isset($video['outKey']) && $video['outKey']) ? $video['outKey'] : '';
  859. } else if($type == "daum") {
  860. preg_match('/\<meta property=\"og\:video\"([^\<\>])*\>/i', $output, $video);
  861. if($video) {
  862. $video = get_array_query($video[0]);
  863. $$video['content'] = preg_replace("/&amp;/", "&", $video['content']);
  864. $info = @parse_url($video['content']);
  865. $info['query'] = element("query", $info);
  866. parse_str($info['query'], $query);
  867. $play['rid'] = $query['vid'];
  868. }
  869. } else if($type == "nate") {
  870. preg_match('/mov_id = \"([^\"]*)\"/i', $output, $video);
  871. $play['mov_id'] = $video[0];
  872. preg_match('/vs_keys = \"([^\"]*)\"/i', $output, $video);
  873. $play['vs_keys'] = $video[0];
  874. if($play) {
  875. $meta = "<meta {$play[mov_id]} {$play[vs_keys]} >";
  876. $video = get_array_query($meta);
  877. $play['mov_id'] = element("mov_id", $video);
  878. $play['vs_keys'] = element("vs_keys", $video);;
  879. }
  880. } else if($type == "slidershare") {
  881. preg_match('/\<meta class=\"twitter_player\"([^\<\>])*\>/i', $output, $video);
  882. if($video) {
  883. $video = get_array_query($video[0]);
  884. $play['play_url'] = (isset($video['value']) && $video['value']) ? str_replace("&amp;", "&", $video['value']) : '';
  885. $info = @parse_url($play['play_url']);
  886. $play['vid'] = trim(str_replace("/slideshow/embed_code/","",$info['path']));
  887. }
  888. }
  889. return $play;
  890. }
  891. function get_video_imgurl($url, $vid, $type) {
  892. $imgurl = '';
  893. if($type == "file") { //JWPLAYER
  894. return;
  895. } else if($type == "vimeo") { //비메오
  896. $ch = curl_init();
  897. curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/".$vid.".php");
  898. curl_setopt($ch, CURLOPT_HEADER, 0);
  899. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  900. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  901. $output = unserialize(curl_exec($ch));
  902. curl_close($ch);
  903. $imgurl = $output[0]['thumbnail_large'];
  904. } else if($type == "youtube") { //유튜브
  905. $imgurl = 'http://img.youtube.com/vi/'.$vid.'/hqdefault.jpg';
  906. } else if($type == "sendvid") { //Sendvid
  907. $imgurl = 'https://sendvid.com/'.$vid.'.jpg';
  908. } else if($type == "facebook"){
  909. /*
  910. if(!defined('APMS_FACEBOOK_ACCESS_TOCKEN') || !APMS_FACEBOOK_ACCESS_TOCKEN) return;
  911. $ch = curl_init();
  912. curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.5/".$vid."?fields=id,picture&access_token=".APMS_FACEBOOK_ACCESS_TOCKEN);
  913. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  914. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  915. curl_setopt($ch, CURLOPT_HEADER, 0);
  916. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
  917. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  918. $output = json_decode(curl_exec($ch));
  919. curl_close($ch);
  920. $imgurl = $output->picture;
  921. */
  922. } else if($type == "naver" || $type == "tvcast"){ //라니안님 코드 반영
  923. $info = @parse_url($url);
  924. if($info['host'] == "tvcast.naver.com") {
  925. $ch = curl_init();
  926. curl_setopt($ch, CURLOPT_URL, $url);
  927. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  928. curl_setopt($ch, CURLOPT_HEADER, 0);
  929. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  930. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  931. $output = curl_exec($ch);
  932. curl_close($ch);
  933. preg_match('/property=\"og\:image\"[^\<\>]*\>/i', $output, $video);
  934. if($video) {
  935. $video = get_array_query($video[0]);
  936. if($video['content']) $imgurl = str_replace("type=f240", "type=f640", $video['content']); //640 사이즈로 변경
  937. }
  938. } else {
  939. $url_type = ($type == "naver") ? "nmv" : "rmcnmv"; // 네이버 블로그 영상과 tvcast 영상 구분
  940. parse_str($info['query'], $query);
  941. $vid .= "&outKey=".$query['outKey'];
  942. $ch = curl_init();
  943. curl_setopt($ch, CURLOPT_URL, "http://serviceapi.{$url_type}.naver.com/flash/videoInfo.nhn?vid=".$vid);
  944. curl_setopt($ch, CURLOPT_HEADER, 0);
  945. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  946. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  947. $output = curl_exec($ch);
  948. curl_close($ch);
  949. preg_match('/\<CoverImage\>\<\!\[CDATA\[(?P<img_url>[^\s\'\"]+)\]\]\>\<\/CoverImage\>/i', $output, $video);
  950. $imgurl = element("img_url", $video);
  951. }
  952. } else {
  953. $ch = curl_init();
  954. curl_setopt($ch, CURLOPT_URL, $url);
  955. @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  956. curl_setopt($ch, CURLOPT_HEADER, 0);
  957. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  958. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  959. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  960. $output = curl_exec($ch);
  961. curl_close($ch);
  962. if($type == "slidershare") {
  963. preg_match('/<meta name=\"thumbnail\"[^\<\>]*\>/i', $output, $video);
  964. } else {
  965. preg_match("/<meta[^>]*content=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*property=\"og\:image\"/i", $output, $video);
  966. if($video[1]) {
  967. $imgurl = $video[1];
  968. } else {
  969. preg_match('/property=\"og\:image\"[^\<\>]*\>/i', $output, $video);
  970. }
  971. }
  972. if(!$imgurl && $video[0]) {
  973. $video = get_array_query($video[0]);
  974. $imgurl = $video['content'];
  975. }
  976. }
  977. return $imgurl;
  978. }
  979. function get_editor_image($contents = '', $view = true)
  980. {
  981. if (empty($contents)) {
  982. return false;
  983. }
  984. // $contents 중 img 태그 추출
  985. if ($view) {
  986. $pattern = "/<img([^>]*)>/iS";
  987. } else {
  988. $pattern = "/<img[^>]*src=[\'\"]?([^>\'\"]+[^>\'\"]+)[\'\"]?[^>]*>/i";
  989. }
  990. preg_match_all($pattern, $contents, $matchs);
  991. return $matchs;
  992. }
  993. function check_social_setting($provider="")
  994. {
  995. $CI=&get_instance();
  996. if( strtolower($provider) == 'facebook' ) return ($CI->site->config('social_facebook_use')=='Y' && $CI->site->config('social_facebook_appid') && $CI->site->config('social_facebook_appsecret'));
  997. 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'));
  998. 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'));
  999. else if( strtolower($provider) == 'kakao') return ($CI->site->config('social_kakao_use')=='Y' && $CI->site->config('social_kakao_clientid'));
  1000. else if( empty($provider)) return ( check_social_setting('facebook') OR check_social_setting('google') OR check_social_setting('naver') OR check_social_setting('kakao') );
  1001. else return FALSE;
  1002. }
  1003. /**
  1004. * 회원 포인트 타입
  1005. * @param bool $return
  1006. * @return array|mixed
  1007. */
  1008. function point_type($return = FALSE)
  1009. {
  1010. $point = array(
  1011. "NONE" => "기타",
  1012. "POST_READ" => "게시글 읽기",
  1013. "POST_WRITE" => "게시글 작성",
  1014. "POST_LIKE" => "게시글 추천",
  1015. "POST_ATTACH_DOWNLOAD" => "첨부파일 다운로드",
  1016. "CMT_WRITE" => "댓글 작성",
  1017. "CMT_LIKE" => "댓글 추천",
  1018. "TODAY_LOGIN" => "오늘 첫 로그인",
  1019. "JOIN" => "회원가입"
  1020. );
  1021. if( is_string($return) )
  1022. {
  1023. return $point[$return];
  1024. }
  1025. else if (is_bool($return) )
  1026. {
  1027. if( $return === TRUE )
  1028. {
  1029. return $point;
  1030. }
  1031. else {
  1032. $return_val = array();
  1033. foreach($point as $key=>$val)
  1034. {
  1035. $return_val[] = $key;
  1036. }
  1037. return $return_val;
  1038. }
  1039. }
  1040. return array();
  1041. }
  1042. /**
  1043. * 이미지가 존재한다면 해당 이미지의 태그를 리턴한다.
  1044. * @param $thumb_path
  1045. * @param string $add_class
  1046. * @param string $add_attr
  1047. * @return null|string
  1048. */
  1049. function thumb_img($thumb_path, $add_class="img-thumbnail", $add_attr="")
  1050. {
  1051. if(empty($thumb_path) ) return NULL;
  1052. if(file_exists(FCPATH.$thumb_path)) {
  1053. return '<img class="'.$add_class.'" src="'.base_url($thumb_path).'" '.$add_attr.'>';
  1054. }
  1055. }
  1056. /**
  1057. * 해당하는 파일을 삭제합니다.
  1058. * @param string $filepath
  1059. */
  1060. function file_delete($filepath ="") {
  1061. if(empty($filepath))
  1062. return;
  1063. if($filepath && file_exists(FCPATH.$filepath) && is_file(FCPATH.$filepath)) {
  1064. @unlink(FCPATH.$filepath);
  1065. }
  1066. }
  1067. /**
  1068. * DB에 등록된 파일을 삭제하고 해당 DB의 파일 부분을 빈값으로 대체한다.
  1069. * @param $table
  1070. * @param $pk_column
  1071. * @param $pk
  1072. * @param $filepath_column
  1073. */
  1074. function db_file_delete($table, $pk_column, $pk, $filepath_column)
  1075. {
  1076. if(empty($table) OR empty($pk_column) OR empty($pk) OR empty($filepath_column)){
  1077. return FALSE;
  1078. }
  1079. $CI =& get_instance();
  1080. $original = $CI->db->where($pk_column, $pk)->get($table)->row_array();
  1081. if(! $original OR empty($original)) return false;
  1082. if(! isset($original[$filepath_column])) return false;
  1083. file_delete($original[$filepath_column]);
  1084. $CI->db->set($filepath_column, '');
  1085. $CI->db->where($pk_column, $pk);
  1086. $CI->db->update($table);
  1087. }
  1088. /**
  1089. * 내용 요약본을 가져온다.
  1090. * @param string $post_content
  1091. * @param int $length
  1092. * @return string
  1093. */
  1094. function get_post_summary($post_content="", $length=300)
  1095. {
  1096. return cut_str( trim( strip_tags( str_replace("&nbsp;", " ", $post_content)) ) ,$length);
  1097. }