본문 바로가기

Web/PHP

[self] 클래스 공통사용

<?
class Common
{
    var $nY;
    var $nTotal;

    #             메세지     주소     열곳
    function msg($message, $url=NULL, $pos='self')
    {
        $string = "<script>window.alert (\"$message\");";
        if(!$url)
        {
            $string .= "history.back();";
        }
        else if( $url == 'close' )
        {
            $string .= "self.close();";
        }
        else if( $url == 'none' )
        {
            
        }
        else
        {
            $string .= "$pos.location.href=\"$url\";";
        }
        $string .= "</script>";

        echo $string;
        exit;
    }

    #     주소있으면 부모창에서 염
    function closed( $url = NULL )
    {
        $str = "<script> self.close(); ";
        if( $url )
            $str .= "opener.location.reload();";
        $str .="</script>";
        echo $str;
        exit;
    }

            # 주소    리턴             딜레이
    function go($url, $time=0, $isReturn = false)
    {
        $string = "<meta http-equiv='Refresh' content='$time; URL=$url'>";

        if ($isReturn)
        {
            return $string;
        }
        else
        {
            echo $string;
        }

        exit;
    }

    function printR(&$mixed, $bExit = FALSE)
    {
        echo "<pre>";
        print_r($mixed);
        echo "</pre>";

        if ($bExit) exit;
    }

    function strcut($strMessage, $nCutSize, $strTail = "...")
    {
        # $nCutSize 가 0 이하이면 $strMessage를 리턴
        if ($nCutSize <= 0)
        {
            return $strMessage;
        }
        else
        {
            # $strMessage 의 바이트 수를 구한다.
            $dwMessage=strlen($strMessage);

            # 문자열이 자르고자 하는 길이보다 적을땐 전체 문자열을 리턴
            if ($dwMessage > $nCutSize)
            {
                for($i=0; $i<$nCutSize; $i++)
                {
                    # $strMessage[$i]가 한글이면 자르는 길이를 1증가시킨 후에 다음 문자로 이동
                    if (ord($strMessage[$i])>126)
                    {
                        $nCutSize++;
                        $i++;

                        if ($dwMessage <= $nCutSize)
                        {
                            return $strMessage;
                        }
                    }
                }

                return substr($strMessage, 0, $nCutSize).$strTail;
            }
            else
            {
                return $strMessage;
            }
        }
    }

    function expDate( $date, $his=NULL ) {
        if( !$his )
        {
            $yy = substr( $date, 0, 4 );
            $mm = substr( $date, 4, 2 );
            $dd = substr( $date, 6, 2 );
            return "$yy-$mm-$dd";
        }
        else
        {
            $yy = substr( $date, 0, 4 );
            $mm = substr( $date, 4, 2 );
            $dd = substr( $date, 6, 2 );
            $h = substr( $date, 8, 2 );
            $i = substr( $date, 10, 2 );
            $s = substr( $date, 12, 2 );

            return "$yy-$mm-$dd $h:$i:$s";
        }
    }
    
    function expTime( $nTime, $his=NULL )
    {
        if( !$his )
        {
            return strftime( "%Y-%m-%d" , $nTime );
        }
        else
        {
            return strftime( "%Y-%m-%d (%H:%M)" , $nTime );
        }
    }

    function getExt( $filename ) {
        $data = pathinfo( $filename );
        return $data[extension];
    }

    function getToday()
    {
        $nY = date(Y);
        $nM = date(m);
        $nD = date(d);
        $today = array(
            '일','월','화','수','목','금','토'
        );
        $ntoday = date(w,mktime(0,0,0,$nM,$nD,$nY));
        echo "${nY}년 ${nM}월 ${nD}일 ($today[$ntoday])";
    }

    
    # nType = 1.그림, 2파일, 3소리
    function prvUpload( $sPage, $nType , $sUpload = NULL )
    {
        if( !$sPage ) $this->msg('아따 페이지명넣어 sPage');
        if( !$nType ) $this->msg('아따 종류는 먼지 넣어야제 1.그림, 2파일, 3소리');

        if( $nType == 1 )
        {
            if( $sUpload )
            {
                $aPathInfo = pathinfo( $sUpload );
                $ext = $aPathInfo[extension];
                if( $ext == 'swf' )
                {
                    $imgType = getimagesize("$_SERVER[DOCUMENT_ROOT]/UploadFiles/$sPage/$sUpload");

                    echo "<span id=prevImages><embed src='/UploadFiles/$sPage/$sUpload' width='$imgType[0]' height='$imgType[1]' border='0'></span>";
                }
                else
                    echo "<span id=prevImages><img src='/UploadFiles/$sPage/$sUpload' border='0' /></span>";
            }
            else
            {
                echo "<span id=prevImages></span>";
            }
        }
        else if( $nType == 2 )
        {
            if( $sUpload )
            {
                # 다운로드 파일에 urlencode추가하기
                $sUpload = urlencode( $sUpload );
                echo "
                <a href='/include/function/down.php?download=$sUpload&sPage=$sPage'>$sUpload</a>";
            }
            else
            {
                echo " ";
            }
        }
        else if( $nType == 3 )
        {
            if( $sUpload )
            {
                $sUpload = urlencode( $sUpload );
                echo"
                <embed EnableContextMenu='0' src='/UploadFiles/$sPage/$sUpload'></embed>";
            }
            else
            {
                echo " ";
            }
        }
    }


    # 빈칸 채우기 수
    function blankTbl( $nTotal, $nTblCut )
    {
        $this->nTotal = $nTotal;
        $nX = $nTotal % $nTblCut;
        $this->nY = $nTblCut - $nX;        
    }

    function writeTbl( $i )
    {
        if( $i == $this->nTotal )
        {
            for( $i=0; $i<$this->nY; $i++ )
            {
                echo "<td> </td>";
            }
        }
    }
}

if( !$objCommon )
{
    $objCommon = & new Common;
}
?>

'Web > PHP' 카테고리의 다른 글

[self] 클래스 파일컨트롤  (0) 2013.09.26
[self] 클래스 데이터체크  (0) 2013.09.26
[self] 클래스 카테고리  (0) 2013.09.26
[문법][팁] 변수이름 자체를 변수로 가공하기  (0) 2013.09.26
[self] 클래스 업로드  (0) 2013.09.26