-
Notifications
You must be signed in to change notification settings - Fork 0
/
onpubapi.php
83 lines (65 loc) · 1.35 KB
/
onpubapi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/* Onpub (TM)
* Copyright (C) 2015 Onpub.com <http://onpub.com/>
* Author: Corey H.M. Taylor <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2.
*/
define("ONPUBAPI_VERSION", "1.7");
define("ONPUBAPI_SCHEMA_VERSION", 1);
// Useful string functions
// Outputs a string with newline(s) at the end.
function en($string, $n = 1, $b = 0)
{
echo $string;
if ($b) {
br($b, $n - 1);
}
while ($n > 0) {
echo "\n";
$n--;
}
}
// Outputs an HTML break tag(s) and also newline(s).
function br($b = 1, $n = 1)
{
$br = '';
while ($b > 0) {
$br .= '<br>';
$b--;
}
en($br, $n);
}
function hasTrailingSlash($in_str)
{
$in_str_trm = trim($in_str);
$pos = strrpos($in_str_trm, '/');
if ($pos !== FALSE) {
if (($pos + 1) == strlen($in_str_trm)) {
return TRUE;
}
}
$pos = strrpos($in_str_trm, '\\');
if ($pos !== FALSE) {
if (($pos + 1) == strlen($in_str_trm)) {
return TRUE;
}
}
return FALSE;
}
function addTrailingSlash($in_str)
{
if ($in_str === "") {
return $in_str;
}
if (hasTrailingSlash($in_str)) {
return $in_str;
}
if (substr($in_str, 1, 1) == ':') {
return $in_str . '\\';
}
return $in_str . '/';
}
?>