WebAPI
[ class tree: WebAPI ] [ index: WebAPI ] [ all elements ]

Source for file WebAPI.php

Documentation is available at WebAPI.php

  1. <?php
  2. /**
  3.  * Project: WebAPI:: String API class for WEB<br>
  4.  * File:    WebAPI.php
  5.  *
  6.  * WebAPI 패키지는 WEB에서 사용되는 문자열 관련 API를 제공한다.
  7.  *
  8.  * 예제:
  9.  * {@example HTTPRelay/tests/test.php}
  10.  *
  11.  * @category    HTTP
  12.  * @package     WebAPI
  13.  * @author      JoungKyun.Kim <http://oops.org>
  14.  * @copyright   (c) 2018, OOPS.org
  15.  * @license     BSD License
  16.  * @link        http://pear.oops.org/package/WebAPI
  17.  * @since       File available since release 0.0.1
  18.  * @filesource
  19.  */
  20.  
  21. /**
  22.  * import oops/HTTPRelay pear package
  23.  */
  24. require_once 'HTTPRelay.php';
  25. /**
  26.  * import WebAPI_Autolink API
  27.  */
  28. require_once 'WebAPI/WebAPI_Autolink.php';
  29. /**
  30.  * import WebAPI_Filtering API
  31.  */
  32. require_once 'WebAPI/WebAPI_Filter.php';
  33.  
  34. /**
  35.  * import WebAPI_Browser API
  36.  */
  37. require_once 'WebAPI/WebAPI_Browser.php';
  38.  
  39. /**
  40.  * import WebAPI_Mimetype API
  41.  */
  42. require_once 'WebAPI/WebAPI_Mimetype.php';
  43.  
  44. /**
  45.  * import WebAPI_JSON API
  46.  */
  47. require_once 'WebAPI/WebAPI_JSON.php';
  48.  
  49.  
  50. /**
  51.  * WebAPI 패키지는 WEB에서 사용되는 문자열 관련 API를 제공한다.
  52.  *
  53.  * @package WebAPI
  54.  */
  55. Class WebAPI {
  56.     // {{{ properties
  57.     /**#@+
  58.      * @access public
  59.      */
  60.  
  61.     /**
  62.      * @const WebAPI::UTF8 1
  63.      */
  64.     const UTF8 1;
  65.     /**
  66.      * @const WebAPI::EUCKR 2
  67.      */
  68.     const EUCKR 2;
  69.  
  70.     /**
  71.      * UTF8 처리 여부. 기본값 true
  72.      * @var bool 
  73.      */
  74.     static public $utf8 = true;
  75.  
  76.     /**
  77.      * XSS check후 status를 저장
  78.      * @var object 
  79.      */
  80.     static public $xssinfo = null;
  81.     /**#@-*/
  82.     // }}}
  83.  
  84.     // {{{ +-- static public (boolean) is_injection (&$s)
  85.     /**
  86.      * URL parameter 값에 inject 공격이 가능한 코드 감지
  87.      * 막을 대상:
  88.      *      - ..   이전 경로
  89.      *      - semi colon
  90.      *      - single or double quote
  91.      *      - %00 (null byte)
  92.      *      - %25 (%)
  93.      *      - %27 (')
  94.      *      - %2e (.)
  95.      *
  96.      * @access public
  97.      * @return boolean 
  98.      * @param  string 
  99.      */
  100.     static public function is_injection (&$s{
  101.         if preg_match ('/\.\.\/|[;\'"]|%(00|25|27|2e)/i'$s) ) {
  102.             return true;
  103.         }
  104.  
  105.         return false;
  106.     }
  107.     // }}}
  108.  
  109.     // {{{ +-- static public (bool) is_alpha (&$c)
  110.     /**
  111.      * 주어진 문자열에 숫자, 알파벳, whtie space만으로 구성이
  112.      * 되어 있는지 확인
  113.      *
  114.      * @access public
  115.      * @return bool 
  116.      * @param string 입력값의 처음 1byte만 판단함
  117.      */
  118.     static public function is_alpha (&$c{
  119.         return preg_match ('/^[0-9a-z]+$/i'$c);
  120.     }
  121.     // }}}
  122.  
  123.     // {{{ +-- static public (boolean) is_hangul (&$s, $division = false)
  124.     /**
  125.      * 주어진 값에 한글(UTF8/EUC-KR)이 포함 되어 있는지를 판단
  126.      *
  127.      * 이 method의 경우에는 한글이 아닌 다른 연속된 multibyte 문자의
  128.      * 마지막 바이트와 첫번째 바이트에 의한 오차가 발생할 수 있으므로
  129.      * 정확도가 필요할 경우에는 KSC5601::is_ksc5601 method를 이용하기
  130.      * 바란다.
  131.      *
  132.      * @access public
  133.      * @return bool 
  134.      * @param  string 
  135.      * @param  bool   (optional) true로 설정할 경우, EUC-KR과 UTF-8을
  136.      *                 구분하여 결과값을 반환한다.
  137.      *      - ASCII returns false
  138.      *      - UTF-8 returns WebAPI::UTF8
  139.      *      - EUC-KR returns WebAPI::EUCKR
  140.      * @since 1.0.1 added 2th parameter.
  141.      */
  142.     static public function is_hangul (&$s$division false{
  143.         // UTF-8 case
  144.         if preg_match ('/[\x{1100}-\x{11FF}\x{3130}-\x{318F}\x{AC00}-\x{D7AF}]/u'$s) )
  145.             return $division self::UTF8 true;
  146.  
  147.         // EUC-KR case
  148.         if preg_match ('/[\xA1-\xFE]/'$s) )
  149.             return $division self::EUCKR true;
  150.  
  151.         return false;
  152.     }
  153.     // }}}
  154.  
  155.     // {{{ +-- static public (boolean) is_proxy (void)
  156.     /**
  157.      * Check this connection whethad access through Proxy server.
  158.      *
  159.      * @access public
  160.      * @return boolean 
  161.      * @param  array (options) User define 헤더. '-'는 '_'로 표시 해야 함.
  162.      */
  163.     static public function is_proxy ($udef null{
  164.         foreach $_SERVER as $k => $v {
  165.             switch ($k{
  166.                 case 'HTTP_VIA':
  167.                 case 'HTTP_CLIENT_IP':
  168.                 case 'HTTP_PROXY':
  169.                 case 'HTTP_SP_HOST':
  170.                 case 'HTTP_COMING_FROM':
  171.                 case 'HTTP_X_COMING_FROM':
  172.                 case 'HTTP_FORWARDED':
  173.                 case 'HTTP_X_FORWARDED':
  174.                 case 'HTTP_FORWARDED_FOR':
  175.                 case 'HTTP_X_FORWARDED_FOR':
  176.                     return true;
  177.             }
  178.         }
  179.  
  180.         if $udef === null )
  181.             return false;
  182.  
  183.         foreach $udef as $v {
  184.             if $_SERVER[$v)
  185.                 return true;
  186.         }
  187.  
  188.         return false;
  189.     }
  190.     // }}}
  191.  
  192.     // {{{ +-- static public (boolean) is_email (&$v)
  193.     /**
  194.      * 주어진 이메일이 valid한지 확인
  195.      *
  196.      * 도메인 파트의 경우 MX record가 있거나 또는 inverse domain이 설정되어 있어야
  197.      * true로 판별한다. 도메인 파트가 IP주소일 경우에는 MX record나 inverse domain
  198.      * 을 체크하지 않는다.
  199.      *
  200.      * 다음의 형식을 체크한다.
  201.      *
  202.      *     - id@domain.com
  203.      *     - id@[IPv4]
  204.      *     - name <id@domain.com>
  205.      *     - id@domain.com?subject=title&cc=...
  206.      *     - name <id@domain.com?subject=title&cc=...>
  207.      *
  208.      * 이메일 parameter가 존재할 경우에는, CC, BCC, SUBJECT, BODY 만 허가가 된다. 만약,
  209.      * 이메일 parameter를 체크하고 싶지 않다면, 이 method에 넘기는 값에서 parameter를
  210.      * 제거하고 넘겨야 한다.
  211.      *
  212.      * @access public
  213.      * @return boolean 
  214.      * @param string check email address
  215.      */
  216.     static public function is_email (&$v{
  217.         WebAPI_Autolink::$utf8 self::$utf8;
  218.         return WebAPI_Autolink::is_email ($v);
  219.     }
  220.     // }}}
  221.  
  222.     // {{{ +-- static public (boolean) is_url (&$v)
  223.     /**
  224.      * 주어진 url이 valid한지 확인
  225.      *
  226.      * @access public
  227.      * @return boolean 
  228.      * @param string check url address
  229.      */
  230.     static public function is_url (&$v{
  231.         WebAPI_Autolink::$utf8 self::$utf8;
  232.         return WebAPI_Autolink::is_url ($v);
  233.     }
  234.     // }}}
  235.  
  236.     // {{{ +-- static public (boolean) is_protocol (&$v)
  237.     /**
  238.      * 주어진 protocol이 valid한지 확인
  239.      *
  240.      * @access public
  241.      * @return boolean 
  242.      * @param string check url address
  243.      */
  244.     static public function is_protocol (&$v{
  245.         WebAPI_Autolink::$utf8 self::$utf8;
  246.         return WebAPI_Autolink::is_protocol ($v);
  247.     }
  248.     // }}}
  249.  
  250.     // {{{ +-- static public (string) client_ip ($udef_haeder = false)
  251.     /**
  252.      * Client의 IP를 구한다. Proxy header가 존재할 경우, 첫번째
  253.      * Proxy의 forward IP를 반환한다.
  254.      *
  255.      * @access public
  256.      * @return string CIDR
  257.      * @param  array  (optional) User Define additional Proxy Header list
  258.      */
  259.     static public function client_ip ($udef_haeder false{
  260.         $myip $_SERVER['REMOTE_ADDR'];
  261.  
  262.         $headers array (
  263.             'HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_X_COMING_FROM',
  264.             'HTTP_X_FORWARDED','HTTP_FORWARDED_FOR','HTTP_FORWARDED',
  265.             'HTTP_VIA''HTTP_COMING_FROM','HTTP_PROXY','HTTP_SP_HOST',
  266.         );
  267.  
  268.         if is_array ($udef_header) )
  269.             $headers array_merge ($headers$udef_header);
  270.  
  271.         foreach $headers as $v {
  272.             if $_SERVER[$v)
  273.                 return preg_replace ('/[\s,]+/'''$myip);
  274.         }
  275.         
  276.         return $myip;
  277.     }
  278.     // }}}
  279.  
  280.     // {{{ +-- static public (void) autolink (&$str)
  281.     /**
  282.      * 주어진 문장속의 URL을 hyper link로 변경
  283.      *
  284.      * @access public
  285.      * @return void 
  286.      * @param string 
  287.      */
  288.     static public function autolink (&$str{
  289.         WebAPI_Autolink::$utf8 self::$utf8;
  290.         WebAPI_Autolink::execute ($str);
  291.     }
  292.     // }}}
  293.  
  294.     // {{{ +-- static public strlen ($str)
  295.     /**
  296.      * Return length of strings
  297.      *
  298.      * 기본적인 사용법은 php의 native strlen과 동일하다.
  299.      *
  300.      * native strlen 과의 차이는, UTF-8 인코딩의 한글 1글자를 CP949와 같이
  301.      * 2byte 로 계산을 한다.
  302.      *
  303.      * @return integer 
  304.      * @param string The input string.
  305.      */
  306.     static public function strlen ($str{
  307.         if ($type self::is_hangul ($strtrue)) )
  308.             return strlen ($str);
  309.  
  310.         if $type == self::UTF8 )
  311.             $str iconv ('UTF-8''CP949'$str);
  312.  
  313.         return strlen ($str);
  314.     }
  315.     // }}}
  316.  
  317.     // {{{ +-- static public (string) substr ($data, $start, $end = false)
  318.     /**
  319.      * Return part of a string
  320.      *
  321.      * 사용법은 php의 native substr과 동일하다.
  322.      *
  323.      * native substr과의 차이는, 시작과 끝은 한글이 깨지는 문제를 해결을
  324.      * 한다. 이 함수는 한글을 2byte로 처리를 하며, UTF-8이라도 한글을 길이는
  325.      * 2byte로 계산을 하여 반환한다.
  326.      *
  327.      * @return string 
  328.      * @param string  The input string. Must be one character or longer.
  329.      * @param int     start position
  330.      * @param int     (optional) length of returning part.
  331.      */
  332.     static public function substr ($data$start$end false{
  333.         if ($type self::is_hangul ($datatrue)) )
  334.             return substr ($data$start$end);
  335.  
  336.         if $end === )
  337.             return null;
  338.  
  339.         if $type == self::UTF8 )
  340.             $data iconv ('UTF-8''CP949'$data);
  341.  
  342.         if $start )
  343.             $start strlen ($data$start;
  344.  
  345.         if $end === false )
  346.             $end strlen ($data$start;
  347.         else if $end )
  348.             $end strlen ($data$end $start;
  349.  
  350.         if $end )
  351.             return null;
  352.  
  353.         if $start {
  354.             $buf substr ($data0$start);
  355.             $buf preg_replace ('/[a-z0-9]|([\x80-\xFE].)/'''$buf);
  356.             if strlen ($buf!= )
  357.                 $start--;
  358.         }
  359.  
  360.         if intval ($data[$start 1]0x80 )
  361.             $start--;
  362.  
  363.         $data substr ($data$start$end);
  364.         $data preg_replace ('/(([\x80-\xFE].)*)[\x80-\xFE]?$/''\\1'$data);
  365.  
  366.         if $type === self::UTF8 )
  367.             return iconv ('CP949''UTF-8'$data);
  368.  
  369.         return $data;
  370.     }
  371.     // }}}
  372.  
  373.     // {{{ +-- static public (boolean) xss (&$str)
  374.     /**
  375.      * XSS 탐지
  376.      *
  377.      *  - Javascript event(onmouseover 등)가 존재할 경우
  378.      *  - iframe, frame, script, style, link, meta, head tag가 있을 경우
  379.      *  - src 또는 href attribute에 javascript를 사용할 경우
  380.      *  - css background* 나 html background* attribute가 존재할 경우
  381.      *
  382.      *  - 예외 사항
  383.      *    . youtube link 예외 처리 (iframe)
  384.      *
  385.      * @access public
  386.      * @return boolean XSS 탐지시 true
  387.      * @param string 
  388.      */
  389.     static public function xss (&$str{
  390.         if self::$xssinfo === null )
  391.             self::$xssinfo new stdClass;
  392.  
  393.         // javascritp event
  394.         $event =
  395.             'abort|activate|afterprint|afterupdate|beforeactivate|beforecopy|' .
  396.             'beforecut|beforedeactivate|beforeeditfocus|beforepaste|beforeprint|' .
  397.             'beforeunload|beforeupdate|blur|bounce|cellchange|change|click|' .
  398.             'contextmenu|controlselect|copy|cut|dataavailable|datasetchanged|' .
  399.             'datasetcomplete|dblclick|deactivate|drag|dragend|dragenter|' .
  400.             'dragleave|dragover|dragstart|drop|error|errorupdate|filterchange|' .
  401.             'finish|focus|focusin|focusout|help|keydown|keypress|keyup|' .
  402.             'layoutcomplete|load|losecapture|mousedown|mouseenter|mouseleave|' .
  403.             'mousemove|mouseout|mouseover|mouseup|mousewheel|move|moveend|' .
  404.             'movestart|paste|propertychange|readystatechange|reset|resize|' .
  405.             'resizeend|resizestart|rowenter|rowexit|rowsdelete|rowsinserted|' .
  406.             'scroll|select|selectionchange|selectstart|start|stop|submit|unload';
  407.  
  408.         $src array (
  409.             '/<[\s]*(iframe)[\s>]+/i',
  410.             '/<[\s]*(script|frame|style|link|meta|head)[\s>]+/i',
  411.             '/background[\s]*(:[\s]*url|=)/i',
  412.             '/(src|href)[\s]*=["\'\s]*(javascript|&#106;|&#74;|%6A|%4A)/i',
  413.             '/on(' $event ')[\s]*=/i'
  414.         );
  415.  
  416.         foreach $src as $filter {
  417.             if preg_match ($filter$str$m) ) {
  418.                 if self::xss_youtube_ext ($m[1]$str=== true )
  419.                     continue;
  420.  
  421.                 self::$xssinfo->status true;
  422.                 self::$xssinfo->msg sprintf (
  423.                     '\'%s\' pattern is matched. This is strongly doubt XSS attack.',
  424.                     $filter
  425.                 );
  426.                 return true;
  427.             }
  428.         }
  429.  
  430.         # img src에 image가 아닌 소스 확인
  431.         $imgs self::img_tags ($str'img');
  432.         $http new HTTPRelay;
  433.         foreach $imgs as $path {
  434.             // 외부 URL이 아닐 경우에는 skip
  435.             if preg_match ('!^(http[s]?)*//!i'$path) )
  436.                 continue;
  437.  
  438.             if preg_match ('!^//!'$path) )
  439.                 $path sprintf ('%s:%s'$_SERVER['HTTPS''https' 'http'$path);
  440.  
  441.             if ( ($buf $http->head ($path1)) === false )
  442.                 continue;
  443.  
  444.             if preg_match ('!^image/!i'$buf->{'Content-Type'}) ) {
  445.                 self::$xssinfo->status true;
  446.                 self::$xssinfo->msg sprintf (
  447.                     'The value of image src property (%s) is assumed that is not image.' .
  448.                     'This is storngly doubt XSS attack.',
  449.                     $path
  450.                 );
  451.                 return true;
  452.             }
  453.         }
  454.  
  455.         return false;
  456.     }
  457.     // }}}
  458.  
  459.     // {{{ +-- private xss_youtube_ext ($filter, &$data)
  460.     /*
  461.      * self::xss 체크시에 youbute의 iframe은 허가
  462.      */
  463.     private function xss_youtube_ext ($filter&$data{
  464.         if strtolower ($filter!= 'iframe' )
  465.             return false;
  466.  
  467.         if preg_match_all ('/<iframe[^>]+>/i'$data$m) )
  468.             return false;
  469.  
  470.         $dom new DOMDocument ();
  471.         $dom->encoding 'utf-8';
  472.         $dom->formatOutput true;
  473.  
  474.         foreach $m as $v {
  475.             @$dom->loadHTML ($v[0'</iframe>');
  476.             $iframe $dom->getElementsByTagName ('iframe');
  477.             if $iframe->length )
  478.                 continue;
  479.  
  480.             $src $iframe->item(0)->getAttribute ('src');
  481.  
  482.             if preg_match ('!^(http[s]?:)?//(www\.)?youtube(-nocookie)?\.(be|com)/!i'trim ($src)) )
  483.                 return false;
  484.         }
  485.  
  486.         return true;
  487.     }
  488.     // }}}
  489.  
  490.     // {{{ +-- private (array) img_tags ($buf)
  491.     /**
  492.      * 주어진 문장에서 img의 src property 값을 배열로 반환한다.
  493.      *
  494.      * @access private
  495.      * @return array 
  496.      * @param string 
  497.      * @param string 
  498.      */
  499.     private function img_tags ($buf{
  500.         $buf preg_replace ('/\r?\n/'' '$buf);
  501.         $p preg_match_all ('/<[\s]*img[^>]*src=[\'"\s]*([^\'"\s>]+)/i'$buf$matches);
  502.  
  503.         if $p )
  504.             return array ();
  505.  
  506.         return $matches[1];
  507.     }
  508.     // }}}
  509.  
  510.     /**
  511.      * File fucntions
  512.      */
  513.     // {{{ +-- static public (string) get_file_extension ($f, $post = false)
  514.     /**
  515.      * 파일의 확장자를 반환
  516.      *
  517.      * @access public
  518.      * @return string  파일 확장자. 확장자가 없을 경우 null 반환.
  519.      * @param  string  파일 이름 또는 경로
  520.      * @param  boolean (optional) true로 설정시에 $_FILES[첫번째인자값]['name']의
  521.      *          값에서 확장자를 반환.
  522.      */
  523.     static public function get_file_extension ($f$post false{
  524.         if $post === true {
  525.             if defined ($_FILES[$f]) )
  526.                 $f $_FILES[$f]['name'];
  527.         }
  528.  
  529.         if preg_match ('/\./'$f) )
  530.             return null;
  531.  
  532.         $ext preg_split ('/\./'$f);
  533.         $tail $ext[count ($ext1];
  534.  
  535.         return $tail strtolower ($tailnull;
  536.     }
  537.     // }}}
  538.  
  539.     // {{{ +-- static public (string) mimetype ($name)
  540.     /**
  541.      * 주어진 파일의 mimetype을 결정한다.
  542.      *
  543.      * @access public
  544.      * @param string mimetype 정보를 확인할 파일경로
  545.      * @param WebAPI::browser br (optional) WebAPI::browser 의 반환값.
  546.      *         비워 놓으면 내부적으로 다시 확인한다.
  547.      * @return string 
  548.      */
  549.     static public function mimetype ($name$br null{
  550.         $name basename ($name);
  551.         $name preg_replace ('/\.(code|exeobj)$/'''$name);
  552.  
  553.         $r WebAPI_Mimetype::mime ($name);
  554.  
  555.         if preg_match ('/^text\//'$r) )
  556.             $r 'text/plain';
  557.  
  558.         if is_object ($br) )
  559.             $br self::browser ();
  560.  
  561.         if $r )
  562.             $r ($br->name == 'MSIE' && $br->version == '5.5'?
  563.                 'doesn/matter' :
  564.                 'application/octet-stream';
  565.  
  566.         return $r;
  567.     }
  568.     // }}}
  569.  
  570.     // {{{ +-- static public (void) mimeHeader ($name)
  571.     /**
  572.      * 주어진 파일의 mimetype을 결정하여 다운로드 전송한다.
  573.      *
  574.      * Unix/Linux의 숨김 속성 파일은 처리하지 않는다.
  575.      *
  576.      * @access public
  577.      * @param string name 다운로드 시킬 파일 경로
  578.      * @param WebAPI::browser br (optional) WebAPI::browser 의 반환값.
  579.      *         비워 놓으면 내부적으로 다시 확인한다.
  580.      * @return void 
  581.      * @since 1.0.3
  582.      */
  583.     static public function mimeHeader ($name$br null{
  584.         // 숨김 파일은 전송 막음
  585.         if preg_match ('/^\./'basename ($name)) ) {
  586.             $err 'Secured problems! download error' PHP_EOL;
  587.             Header ('Content-Type: text/plain');
  588.             Header ('Accept-Ranges: bytes');
  589.             Header ('Content-Length: ' strlen ($err));
  590.             Header ('Content-Description: WebAPI File sending API');
  591.  
  592.             echo $err;
  593.             return;
  594.         }
  595.  
  596.         if is_object ($br) )
  597.             $br self::browser ();
  598.  
  599.         $mime self::mimetype ($name$br);
  600.  
  601.         if $br->name == 'MSIE' && $br->version == '5.5' )
  602.             Header ('Content-Transfer-Encoding: binary');
  603.  
  604.         Header ('Content-Description: WebAPI File sending API');
  605.  
  606.         $dnname rawurlencode (basename ($name));
  607.         $dnname preg_replace ('/\.(code|exeobj)$/'''$dnname);
  608.  
  609.         switch ($br->name{
  610.             case 'Firefox' :
  611.                 $dnname sprintf ('filename*0*=%s'$dnname);
  612.                 break;
  613.             case 'Opera' :
  614.                 if $br->version {
  615.                     $dnname sprintf ('filename*0*=%s'$dnname);
  616.                     break;
  617.                 }
  618.             default:
  619.                 $dnname 'filename="' $dnname '"';
  620.         }
  621.  
  622.         Header ('Content-Type: ' $mime);
  623.         Header ('Accept-Ranges: bytes');
  624.         header ('Content-Length: ' filesize ($name));
  625.  
  626.         switch ($mime{
  627.             case 'text/plain' :
  628.             case 'image/jpeg' :
  629.             case 'image/png' :
  630.             case 'image/gif' :
  631.             case 'application/pdf' :
  632.                 break;
  633.             default:
  634.                 Header ('Content-Disposition: attachment; '$dnname);
  635.         }
  636.  
  637.         Header ('Pragma: no-cache');
  638.         Header ('Expires: 0');
  639.  
  640.         readfile ($name);
  641.     }
  642.     // }}}
  643.  
  644.     /**
  645.      * Filtering context
  646.      */
  647.  
  648.     // {{{ +-- static public (boolean) filter_context (&$text, &$pattern)
  649.     /**
  650.      * 정규식을 이용하여 필터링
  651.      *
  652.      * @access public
  653.      * @return boolean 
  654.      * @param string 필터링할 문자열
  655.      * @param string 필터링 패턴. 패턴은 PCRE 정규 표현식을 이용한다.
  656.      */
  657.     static public function filter_context (&$text&$pattern{
  658.         return WebAPI_Filter::context ($text$pattern);
  659.     }
  660.     // }}}
  661.  
  662.     // {{{ +-- static public (boolean) filter_context_file (&$text, &$patfile)
  663.     /**
  664.      * 필터링 파일을 이용하여 필터링
  665.      *
  666.      * @access public
  667.      * @return boolean 
  668.      * @param string 필터링할 문자열
  669.      * @param string 필터링 패턴 파일. 패턴은 PCRE 정규 표현식을 이용한다.
  670.      */
  671.     static public function filter_context_file (&$text&$patfile{
  672.         return WebAPI_Filter::context_file ($text$patfile);
  673.     }
  674.     // }}}
  675.  
  676.     // {{{ +-- static public (boolean) filter_ip (&$ip)
  677.     /**
  678.      * 접속 IP($_SERVER['REMOTE_ADDR'])가 주어진 CIDR/MASK에 포함이 되는지 확인
  679.      *
  680.      * @access public
  681.      * @return boolean 
  682.      * @param  string  매칭시킬 IP 또는 IP 블럭
  683.      *      - 허가된 표현식
  684.      *        - 1.1.1.1
  685.      *        - 1.1.1.1/24
  686.      *        - 1.1.1.1/255.255.255.0
  687.      *        - 1.1.1. (1.1.1.0/24)
  688.      *        - 1.1. (1.1.0.0/16)
  689.      *        - 1.1.1.1 - 2.2.2.2 (range)
  690.      */
  691.     static public function filter_ip (&$ip{
  692.         return WebAPI_Filter::ip ($ip);
  693.     }
  694.     // }}}
  695.  
  696.     // {{{ +-- static public (stdClass) browser (void)
  697.     /**
  698.      * Broswer API
  699.      *
  700.      * Browser 정보를 구함
  701.      *
  702.      * @access public
  703.      * @return stdClass 
  704.      * @since 1.0.2
  705.      */
  706.     static public function browser ($u null{
  707.         return WebAPI_Browser::exec ($u);
  708.     }
  709.     // }}}
  710.  
  711.     /**
  712.      * JSON function
  713.      */
  714.  
  715.     // {{{ +-- static public (string) json_encode ($text, $nopretty = false)
  716.     /**
  717.      * utf8 conflict 및 binary data 를 해결한 json encode wrapper
  718.      *
  719.      * @access public
  720.      * @return string 
  721.      * @param mixed encode할 변수
  722.      * @param bool pretty 출력 여부. 기본값 false이며 이는 pretty 출력
  723.      *              을 의미한다. pretty 인자는 php 5.4 부터 지원한다. [기본값 false]
  724.      * @param bool (optional) binary safe를 위한 normalize를 할지 여부 [기본값 true]
  725.      * @since 1.0.3
  726.      */
  727.     static public function json_encode ($text$nopretty false$normal true{
  728.         return WebAPI_JSON::encode ($text$nopretty$normal);
  729.     }
  730.     // }}}
  731.  
  732.     // {{{ +-- static public (string) json_decode ($text)
  733.     /**
  734.      * utf8 conflict 및 binary data 를 해결한 json decode wrapper
  735.      *
  736.      * @access public
  737.      * @return object 
  738.      * @param string json string data
  739.      * @param bool   (optional) When TRUE, returned objects will be converted
  740.      *                into associative arrays.
  741.      * @param int    (optional) User specified recursion depth (default: 512)
  742.      * @param int    (optional) Bitmask of JSON decode options. Currently only
  743.      *                JSON_BIGINT_AS_STRING is supported (default is
  744.      *                to cast large integers as floats)
  745.      * @since 1.0.5
  746.      */
  747.     static public function json_decode ($data$assoc false$depth 512$options 0{
  748.         return WebAPI_JSON::decode ($data$assoc$depth$options);
  749.     }
  750.     // }}}
  751. }
  752.  
  753. /*
  754.  * Local variables:
  755.  * tab-width: 4
  756.  * c-basic-offset: 4
  757.  * End:
  758.  * vim: set filetype=php noet sw=4 ts=4 fdm=marker:
  759.  * vim600: noet sw=4 ts=4 fdm=marker
  760.  * vim<600: noet sw=4 ts=4
  761.  */
  762. ?>

Documentation generated on Tue, 14 May 2019 02:00:48 +0900 by phpDocumentor 1.4.4