xref: /dokuwiki/inc/compatibility.php (revision 3f6872b1fc0e676dafffb7488df32f2425bbd29f)
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);
518457f8ceSAndreas Gohr    }
528457f8ceSAndreas Gohr}
538457f8ceSAndreas Gohr
548457f8ceSAndreas Gohrif(!function_exists('gzseek') && function_exists('gzseek64')) {
558457f8ceSAndreas Gohr    /**
568457f8ceSAndreas Gohr     * work around for PHP compiled against certain zlib versions #865
578457f8ceSAndreas Gohr     *
588457f8ceSAndreas Gohr     * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
598457f8ceSAndreas Gohr     *
608457f8ceSAndreas Gohr     * @param resource $zp
618457f8ceSAndreas Gohr     * @param int      $offset
628457f8ceSAndreas Gohr     * @param int      $whence
638457f8ceSAndreas Gohr     * @return int
648457f8ceSAndreas Gohr     */
658457f8ceSAndreas Gohr    function gzseek($zp, $offset, $whence = SEEK_SET) {
668457f8ceSAndreas Gohr        return gzseek64($zp, $offset, $whence);
678457f8ceSAndreas Gohr    }
688457f8ceSAndreas Gohr}
698457f8ceSAndreas Gohr
708457f8ceSAndreas Gohrif(!function_exists('gztell') && function_exists('gztell64')) {
718457f8ceSAndreas Gohr    /**
728457f8ceSAndreas Gohr     * work around for PHP compiled against certain zlib versions #865
738457f8ceSAndreas Gohr     *
748457f8ceSAndreas Gohr     * @link   http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
758457f8ceSAndreas Gohr     *
768457f8ceSAndreas Gohr     * @param resource $zp
778457f8ceSAndreas Gohr     * @return int
788457f8ceSAndreas Gohr     */
798457f8ceSAndreas Gohr    function gztell($zp) {
808457f8ceSAndreas Gohr        return gztell64($zp);
8192b9f196SAndreas Gohr    }
8292b9f196SAndreas Gohr}
83*3f6872b1SMyron Turner
84