xref: /dokuwiki/inc/compatibility.php (revision 8457f8cee42b57b7f708f23cbbfc50b1939de30d)
16589c60cSAndreas Gohr<?php
26589c60cSAndreas Gohr/**
36589c60cSAndreas Gohr * compatibility functions
46589c60cSAndreas Gohr *
56589c60cSAndreas Gohr * This file contains a few functions that might be missing from the PHP build
66589c60cSAndreas Gohr */
76589c60cSAndreas Gohr
86589c60cSAndreas Gohrif(!function_exists('ctype_space')) {
96589c60cSAndreas Gohr    /**
106589c60cSAndreas Gohr     * Check for whitespace character(s)
116589c60cSAndreas Gohr     *
126589c60cSAndreas Gohr     * @see ctype_space
136589c60cSAndreas Gohr     * @param string $text
146589c60cSAndreas Gohr     * @return bool
156589c60cSAndreas Gohr     */
166589c60cSAndreas Gohr    function ctype_space($text) {
176589c60cSAndreas Gohr        if(!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
186589c60cSAndreas Gohr        if(trim($text) === '') return true;
196589c60cSAndreas Gohr        return false;
206589c60cSAndreas Gohr    }
216589c60cSAndreas Gohr}
226589c60cSAndreas Gohr
236589c60cSAndreas Gohrif(!function_exists('ctype_digit')) {
246589c60cSAndreas Gohr    /**
256589c60cSAndreas Gohr     * Check for numeric character(s)
266589c60cSAndreas Gohr     *
276589c60cSAndreas Gohr     * @see ctype_digit
286589c60cSAndreas Gohr     * @param string $text
296589c60cSAndreas Gohr     * @return bool
306589c60cSAndreas Gohr     */
316589c60cSAndreas Gohr    function ctype_digit($text) {
326589c60cSAndreas Gohr        if(!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
336589c60cSAndreas Gohr        if(preg_match('/^\d+$/', $text)) return true;
346589c60cSAndreas Gohr        return false;
356589c60cSAndreas Gohr    }
366589c60cSAndreas Gohr}
3792b9f196SAndreas Gohr
3892b9f196SAndreas Gohrif(!function_exists('gzopen') && function_exists('gzopen64')) {
3992b9f196SAndreas Gohr    /**
4092b9f196SAndreas Gohr     * work around for PHP compiled against certain zlib versions #865
4192b9f196SAndreas Gohr     *
4292b9f196SAndreas Gohr     * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
4392b9f196SAndreas Gohr     *
4492b9f196SAndreas Gohr     * @param string $filename
4592b9f196SAndreas Gohr     * @param string $mode
4692b9f196SAndreas Gohr     * @param int    $use_include_path
4792b9f196SAndreas Gohr     * @return mixed
4892b9f196SAndreas Gohr     */
4992b9f196SAndreas Gohr    function gzopen($filename, $mode, $use_include_path = 0) {
5092b9f196SAndreas Gohr        return gzopen64($filename, $mode, $use_include_path);
51*8457f8ceSAndreas Gohr    }
52*8457f8ceSAndreas Gohr}
53*8457f8ceSAndreas Gohr
54*8457f8ceSAndreas Gohrif(!function_exists('gzseek') && function_exists('gzseek64')) {
55*8457f8ceSAndreas Gohr    /**
56*8457f8ceSAndreas Gohr     * work around for PHP compiled against certain zlib versions #865
57*8457f8ceSAndreas Gohr     *
58*8457f8ceSAndreas Gohr     * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
59*8457f8ceSAndreas Gohr     *
60*8457f8ceSAndreas Gohr     * @param resource $zp
61*8457f8ceSAndreas Gohr     * @param int      $offset
62*8457f8ceSAndreas Gohr     * @param int      $whence
63*8457f8ceSAndreas Gohr     * @return int
64*8457f8ceSAndreas Gohr     */
65*8457f8ceSAndreas Gohr    function gzseek($zp, $offset, $whence = SEEK_SET) {
66*8457f8ceSAndreas Gohr        return gzseek64($zp, $offset, $whence);
67*8457f8ceSAndreas Gohr    }
68*8457f8ceSAndreas Gohr}
69*8457f8ceSAndreas Gohr
70*8457f8ceSAndreas Gohrif(!function_exists('gztell') && function_exists('gztell64')) {
71*8457f8ceSAndreas Gohr    /**
72*8457f8ceSAndreas Gohr     * work around for PHP compiled against certain zlib versions #865
73*8457f8ceSAndreas Gohr     *
74*8457f8ceSAndreas Gohr     * @link   http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
75*8457f8ceSAndreas Gohr     *
76*8457f8ceSAndreas Gohr     * @param resource $zp
77*8457f8ceSAndreas Gohr     * @return int
78*8457f8ceSAndreas Gohr     */
79*8457f8ceSAndreas Gohr    function gztell($zp) {
80*8457f8ceSAndreas Gohr        return gztell64($zp);
8192b9f196SAndreas Gohr    }
8292b9f196SAndreas Gohr}