load->driver('cache', array('adapter' => 'apc', 'backup' => 'file', 'key_prefix' => PROJECT)); if( ! $config = $CI->cache->get('site_config') ) { $result = $CI->db->get("config"); $config_list = $result->result_array(); $config = array(); foreach( $config_list as $row ) { $config[$row['cfg_key']] = $row['cfg_value']; } $CI->cache->save('site_config', $config); } return element($column, $config, NULL); } /** * 사이트 메뉴를 가져온다 */ public function menu() { $CI =& get_instance(); $CI->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file', 'key_prefix' => PROJECT)); if( ! $menu = $CI->cache->get('site_menu_'. $this->viewmode ) ) { $menu = $CI->db->where('mnu_'.$this->viewmode, 'Y')->where('mnu_parent','0')->order_by('mnu_order ASC')->get('menu')->result_array(); // 2차메뉴 가져오기 foreach($menu as &$row) { $row['children']= $CI->db->where('mnu_'.$this->viewmode, 'Y')->where('mnu_parent',$row['mnu_idx'])->order_by('mnu_order ASC')->get('menu')->result_array(); foreach( $row['children'] as &$rw ) { $rw['children']= $CI->db->where('mnu_'.$this->viewmode, 'Y')->where('mnu_parent',$rw['mnu_idx'])->order_by('mnu_order ASC')->get('menu')->result_array(); } } $CI->cache->save('site_menu_'. $this->viewmode, $menu); } // active foreach($menu as &$mnu) { $mnu['active'] = (! empty($mnu['mnu_active_key']) && $CI->active == $mnu['mnu_active_key']); foreach($mnu['children'] as &$mnu2) { foreach($mnu['children'] as &$mnu3) { $mnu3['active'] = (! empty($mnu3['mnu_active_key']) && $CI->active == $mnu3['mnu_active_key']); if( $mnu3['active'] ) { $mnu2['active'] = TRUE; $mnu['active'] = TRUE; break; } } if(! empty($mnu2['mnu_active_key']) && $CI->active == $mnu2['mnu_active_key'] ) { $mnu2['active'] = TRUE; $mnu['active'] = TRUE; } } if(! empty($mnu['mnu_active_key']) && $CI->active == $mnu['mnu_active_key'] ) { $mnu['active'] = TRUE; } } return $menu; } /********************************************************* * 현재 접속 기기에 따라 필요한 레이아웃을 가져온다. *********************************************************/ public function get_layout() { return ( $this->viewmode == DEVICE_MOBILE ) ? THEME_MOBILE : THEME_DESKTOP; } /********************************************************* * 사이트에 사용할 CSS를 추가합니다. * @param $url 추가할 CSS * @param bool $insert_last 마지막에 추가할지 처음에 추가할지 ********************************************************/ public function add_css( $url, $insert_first = FALSE) { if(!empty($url) && ! in_array($url, $this->css_after) && !in_array($url, $this->css_before)) { if( $insert_first ) { array_push($this->css_before, $url); } else { array_push($this->css_after, $url); } } } /********************************************************* * 사이트에 사용할 JS를 추가한다. * @param $url 추가할 JS * @param bool $insert_last 마지막에 추가할것인가? ********************************************************/ public function add_js( $url, $insert_first = FALSE ) { if(!empty($url) && ! in_array($url, $this->js_before) && ! in_array($url, $this->js_after)) { if( $insert_first ) { array_push($this->js_before, $url); } else { array_push($this->js_after, $url); } } } /********************************************************* * 배열에 담긴 CSS를 메타태그와 함께 같이 출력한다. * @return string ********************************************************/ public function display_css() { $CI =& get_instance(); $return = ''; // Layout 기본 CSS가 있다면 추가한다. if( $CI->skin_type && $CI->skin && file_exists(VIEWPATH.'/'.DIR_SKIN.'/'.$CI->skin_type.'/'.$CI->skin.'/skin.min.css')) { $this->add_css( base_url("views/".DIR_SKIN."/".$CI->skin_type.'/'.$CI->skin."/skin.min.css"), TRUE); } else if( $CI->skin_type && $CI->skin && file_exists(VIEWPATH.'/'.DIR_SKIN.'/'.$CI->skin_type.'/'.$CI->skin.'/skin.css')) { $this->add_css( base_url("views/".DIR_SKIN."/".$CI->skin_type.'/'.$CI->skin."/skin.css"), TRUE); } $css_array = array_merge($this->css_before, $this->css_after); $css_array = array_unique($css_array); foreach($css_array as $css) { if( is_my_domain( $css ) ) { $filepath = str_replace(base_url(), "/", $css); $css .= "?" . date('YmdHis', filemtime( FCPATH.ltrim($filepath,DIRECTORY_SEPARATOR) )); if( ! (strpos($css, base_url()) !== FALSE) ) { $css = base_url($css); } } $return .= ''.PHP_EOL; } return $return; } /********************************************************* * 배열에 담긴 JS를 메타태그와 함께 같이 출력한다. * @return string ********************************************************/ public function display_js() { $CI =& get_instance(); $return = ''; if( $CI->skin_type && $CI->skin && file_exists(VIEWPATH.'/'.DIR_SKIN.'/'.$CI->skin_type.'/'.$CI->skin.'/skin.min.js')) { $this->add_js(base_url("views/".DIR_SKIN."/".$CI->skin_type.'/'.$CI->skin."/skin.min.js"), TRUE); } else if ($CI->skin_type && $CI->skin && file_exists(VIEWPATH.'/'.DIR_SKIN.'/'.$CI->skin_type.'/'.$CI->skin.'/skin.js')) { $this->add_js(base_url("views/".DIR_SKIN."/".$CI->skin_type.'/'.$CI->skin."/skin.js"), TRUE); } $js_array = array_merge($this->js_before, $this->js_after); $js_array = array_unique($js_array); foreach($js_array as $js) { if( is_my_domain( $js ) ) { $filepath = str_replace(base_url(), "/", $js); $js .= "?" . date('YmdHis', filemtime( FCPATH.ltrim($filepath,DIRECTORY_SEPARATOR) )); if( ! (strpos($js, base_url()) !== FALSE) ) { $js = base_url($js); } } $return .= ''.PHP_EOL; } // 사이트를 위한 javascript $return .= ''; return $return; } /********************************************************* * 페이지의 타이틀을 가져온다. ********************************************************/ public function page_title() { $this->meta_title = str_replace(' :: '.$this->config('site_title'), "", $this->meta_title); $this->meta_title = $this->meta_title ? $this->meta_title : $this->config('site_subtitle'); if( ! empty($this->meta_title) ) $this->meta_title .= ' :: '; $this->meta_title .= $this->config('site_title'); return $this->meta_title; } /********************************************************* * 메타태그를 자동으로 생성하여 표시한다. ********************************************************/ public function display_meta(){ // Default 값 설정 $this->page_title(); $this->meta_description = $this->meta_description ? $this->meta_description : $this->config('site_meta_description'); $this->meta_keywords = $this->meta_keywords ? $this->meta_keywords : ""; $this->meta_image = $this->meta_image ? $this->meta_image : str_replace(DIRECTORY_SEPARATOR, "/", $this->config('site_meta_image' ) ? base_url(str_replace(DIRECTORY_SEPARATOR, "/", $this->config('site_meta_image' ))) : NULL); $default_keywords = explode(",", $this->config('site_meta_keywords')); $in_keywords = explode(",", $this->meta_keywords); foreach($in_keywords as $keyword) { $keyword = trim($keyword); if(! in_array($keyword, $default_keywords)) { array_push($default_keywords, $keyword); } } $default_keywords = array_unique($default_keywords); $this->meta_keywords = ""; // 합친 키워드를 다시 직렬화 foreach($default_keywords as $keyword) { $this->meta_keywords .= $keyword.","; } $this->meta_keywords = rtrim($this->meta_keywords,","); // 기본태그 $return = ""; $return .= ''.PHP_EOL; $return .= (($this->viewmode == DEVICE_DESKTOP) ? '' : '') .PHP_EOL; $return .= ''.PHP_EOL; // 기본 메타 태그 $return .= '' . $this->meta_title . ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ($this->meta_image ? '': '') .PHP_EOL; // 페이스북 메타 태그 $return .= '' .PHP_EOL; $return .= '' .PHP_EOL; $return .= '' .PHP_EOL; $return .= ($this->meta_image ? '': '') .PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; // 트위터 메타 태그 $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ($this->meta_image ? '' : '').PHP_EOL; $return .= ''.PHP_EOL; // 네이트온 메타 태그 $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ($this->meta_image ? '' : '').PHP_EOL; // 파비콘 $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; $return .= ''.PHP_EOL; // Verification 이 있다면 메타태그 추가 if(! empty($this->config('verification_google')) ) $return .= $this->config('verification_google') .PHP_EOL; if(! empty($this->config('verification_naver')) ) $return .= $this->config('verification_naver').PHP_EOL; $CI =& get_instance(); return $return; } }