xref: /dokuwiki/inc/compatibility.php (revision dccd6b2bba7367e4d1d2d7aa84c9f9d15584b593)
1<?php
2/**
3 * compatibility functions
4 *
5 * This file contains a few functions that might be missing from the PHP build
6 */
7
8if(!function_exists('ctype_space')) {
9    /**
10     * Check for whitespace character(s)
11     *
12     * @see ctype_space
13     * @param string $text
14     * @return bool
15     */
16    function ctype_space($text)
17    {
18        if(!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
19        if(trim($text) === '') return true;
20        return false;
21    }
22}
23
24if(!function_exists('ctype_digit')) {
25    /**
26     * Check for numeric character(s)
27     *
28     * @see ctype_digit
29     * @param string $text
30     * @return bool
31     */
32    function ctype_digit($text)
33    {
34        if(!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
35        if(preg_match('/^\d+$/', $text)) return true;
36        return false;
37    }
38}
39
40if(!function_exists('gzopen') && function_exists('gzopen64')) {
41    /**
42     * work around for PHP compiled against certain zlib versions #865
43     *
44     * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
45     *
46     * @param string $filename
47     * @param string $mode
48     * @param int    $use_include_path
49     * @return mixed
50     */
51    function gzopen($filename, $mode, $use_include_path = 0)
52    {
53        return gzopen64($filename, $mode, $use_include_path);
54    }
55}
56
57if(!function_exists('gzseek') && function_exists('gzseek64')) {
58    /**
59     * work around for PHP compiled against certain zlib versions #865
60     *
61     * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
62     *
63     * @param resource $zp
64     * @param int      $offset
65     * @param int      $whence
66     * @return int
67     */
68    function gzseek($zp, $offset, $whence = SEEK_SET)
69    {
70        return gzseek64($zp, $offset, $whence);
71    }
72}
73
74if(!function_exists('gztell') && function_exists('gztell64')) {
75    /**
76     * work around for PHP compiled against certain zlib versions #865
77     *
78     * @link   http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
79     *
80     * @param resource $zp
81     * @return int
82     */
83    function gztell($zp)
84    {
85        return gztell64($zp);
86    }
87}
88