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.

79 lines
3.2 KiB

7 years ago
7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. *
  5. * HookPostControllerConstructor.php
  6. *
  7. * 컨트롤러가 인스턴스화 직후 가동되는 후킹 클래스.
  8. *
  9. */
  10. class HookDisplayOverride {
  11. function init()
  12. {
  13. $this->CI =& get_instance();
  14. $output = !( $this->CI->uri->segment(1) == 'rss' OR strpos($this->CI->uri->segment(1), "sitemap") !== FALSE ) ? $this->set_layout( $this->CI->output->get_output() ) : $this->CI->output->get_output();
  15. $this->CI->output->_display($output);
  16. }
  17. function set_layout($output)
  18. {
  19. if( PAGE_AJAX OR PAGE_INSTALL OR $this->CI->theme === FALSE ) return $output;
  20. // Script Tag를 모두 가져와서 body 밑으로
  21. preg_match_all("/<script\\b[^>]*>([\\s\\S]*?)<\\/script>/", $output, $matches);
  22. $output = preg_replace("/<script\\b[^>]*>([\\s\\S]*?)<\\/script>/","", $output);
  23. $head = '<!DOCTYPE html>'.PHP_EOL;
  24. $head .= '<html lang="'.LANG.'">'.PHP_EOL;
  25. $head .= '<head>'.PHP_EOL;
  26. $head .= $this->CI->site->display_meta();
  27. $head .= $this->CI->site->display_css();
  28. $head .= '</head>'.PHP_EOL;
  29. $head .= '<body>';
  30. $foot = "";
  31. $foot .= $this->CI->site->display_js() . PHP_EOL;
  32. foreach($matches[0] as $match) $foot .= $match;
  33. // 구글애널리틱스 코드가 있다면?
  34. if( $this->CI->uri->segment(1) != 'admin' && ! $this->CI->input->is_ajax_request() && ! $this->CI->agent->is_robot() && ! $this->CI->member->is_super() )
  35. {
  36. $foot .= (! empty($this->CI->site->config('analytics_google')) ) ? $this->CI->site->config('analytics_google').PHP_EOL : '';
  37. $foot .= (! empty($this->CI->site->config('analytics_naver')) ) ? $this->CI->site->config('analytics_naver').PHP_EOL : '';
  38. $foot .= (! empty($this->CI->site->config('analytics_etc')) ) ? $this->CI->site->config('analytics_etc').PHP_EOL : '';
  39. }
  40. // 사이트 채널 연동
  41. $channel = array();
  42. $channel_type_array = array('facebook','instagram','itunes','naver_blog','naver_cafe','naver_pholar','naver_post','naver_storefarm','playstore');
  43. $channel_type = $this->CI->site->config('channel_type') == 'Organization' ? 'Organization' : 'Person';
  44. foreach($channel_type_array as $c)
  45. {
  46. if( $this->CI->site->config('channel_'.$c) ) $channel[] = $this->CI->site->config('channel_'.$c);
  47. }
  48. if( count($channel) > 0 )
  49. {
  50. $channel_arr = array(
  51. "@context" => "http://schema.org",
  52. "@type" => $channel_type,
  53. "name" => $this->CI->site->config('site_title'),
  54. "url" => base_url(),
  55. "sameAS" => $channel
  56. );
  57. $foot .= '<script type="application/ld+json">'.PHP_EOL;
  58. $foot .= json_encode($channel_arr, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE).PHP_EOL;
  59. $foot .= '</script>';
  60. }
  61. $foot .= "<script src='".base_url('helptool/lang')."'></script>";
  62. $foot .= '</body>'.PHP_EOL;
  63. $foot .= '</html>';
  64. $output = $head.PHP_EOL.$output.PHP_EOL.$foot;
  65. return $output;
  66. }
  67. }