<?php
//emoticon
if ( ! function_exists('get_emoticon') ) {
    function get_emoticon() {
        global $board_skin_path, $board_skin_url;
        
        $return = array();
        
        //emoticon dir
        $dir = $board_skin_path.'/emoticon';
        $handle  = opendir($dir);
        $emoti_dir = array();
        while (false !== ($dirname = readdir($handle))) {
            if($dirname == "." || $dirname == ".."){
                continue;
            }
            $emoti_dir[] = $dirname;
        }
        closedir($handle);
        
        //emotiocon image
        $emoticon = array();
        foreach($emoti_dir as $v) {
            $dir = $board_skin_path.'/emoticon/'.$v;
            $emoti_url = $board_skin_url.'/emoticon/'.$v;
            $handle  = opendir($dir);
            while (false !== ($filename = readdir($handle))) {
                if($filename == "." || $filename == ".."){
                    continue;
                }
                $size = getimagesize($dir.'/'.$filename);
                if ($size['mime'] == "image/jpeg" || $size['mime'] == "image/png" || $size['mime'] == "image/gif") {
                    $emoticon[$v][] = $emoti_url.'/'.$filename;
                }
            }
        }
        $return['dir'] = $emoti_dir;
        $return['emoticon'] = $emoticon;

        return $return;
    }
}
//movie_id. 귀차니즘..utv만
if ( ! function_exists('get_movie_id') ) {
    function get_movie_id($url) {
        
        $return = '';
        
        $movie_url = parse_url($url);
        if($movie_url['query']) {
            $tmp = explode('&',$movie_url['query']);
            foreach($tmp as $key=>$val) {
                $watch = explode('=',$val);
                if($watch[0] == 'v') {
                    $return = $watch[1];
                }
            }
        }
        
        return $return;
    }
}

if ( ! function_exists('board_table_replace') ) {
    function board_table_replace() {
        global $g5, $board;

        $table = $g5['write_prefix'].$board['bo_table'];
        //동영상 필드 추가
        if(!sql_query(" select wr_movie_url from {$table} limit 1 ", false)) {
            $sql = " ALTER TABLE `{$table}`  ADD `wr_movie_url` varchar(255) NOT NULL DEFAULT ''";
            sql_query($sql, false);
        }
        //댓글용 필드 추가
        if(!sql_query(" select wr_cmt_parent from {$table} limit 1 ", false)) {
            $sql = " ALTER TABLE `{$table}`  ADD `wr_cmt_parent` int(11) NOT NULL DEFAULT '0'";
            sql_query($sql, false);
        }
        if(!sql_query(" select wr_cmt_depth from {$table} limit 1 ", false)) {
            $sql = " ALTER TABLE `{$table}`  ADD `wr_cmt_depth` int(11) NOT NULL DEFAULT '0'";
            sql_query($sql, false);
        }
        if(!sql_query(" select wr_cmt_order from {$table} limit 1 ", false)) {
            $sql = " ALTER TABLE `{$table}`  ADD `wr_cmt_order` int(11) NOT NULL DEFAULT '0'";
            sql_query($sql, false);
        }
        if(!sql_query(" select wr_cmt_num from {$table} limit 1 ", false)) {
            $sql = " ALTER TABLE `{$table}`  ADD `wr_cmt_num` int(11) NOT NULL DEFAULT '0'";
            sql_query($sql, false);
        }
        if(!sql_query(" select wr_cmt_del from {$table} limit 1 ", false)) {
            $sql = " ALTER TABLE `{$table}`  ADD `wr_cmt_del` tinyint(1) NOT NULL DEFAULT '0'";
            sql_query($sql, false);
        }
    }
}