-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
executable file
·180 lines (170 loc) · 5.92 KB
/
functions.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/**
* Chronolabs Feeds File
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Chronolabs Cooperative http://labs.coop
* @license General Public License version 3 (http://labs.coop/briefs/legal/general-public-licence/13,3.html)
* @package feeds
* @since 1.1.2
* @author Simon Roberts <wishcraft@users.sourceforge.net>
* @version $Id: index.php 1000 2013-06-07 01:20:22Z mynamesnot $
* @subpackage time
* @description Multiple Calendars on RSS Feed for the Here and Now
*/
if (!function_exists("checkForErrorResponse")) {
function checkForErrorResponse($array = array(), $mode = 'twitter', $die = true)
{
if (!isset($GLOBALS['reponses'])||!is_array($GLOBALS['reponses']))
$GLOBALS['reponses'] = array('errors' => array());
switch($mode)
{
default:
case 'twitter':
if (isset($array['errors']) && count($array['errors']) > 0)
{
foreach($array['errors'] as $key => $error)
$GLOBALS['reponses']['errors'][$mode.'-'.$key.'-'.$error['code']] = "Twitter API Error (" . $error['code'] . ') ~ ' . $error['message'];
}
break;
}
if (count($errors)>0 && $die == true)
die("\n\nErrors Occured:\n\n" .implode("\n", $GLOBALS['reponses']['errors']));
elseif (count($errors)>0 && $die == false)
return true;
else
return false;
}
}
/**
* xoStripeKey()
* Stripes a checksum for guid
*
* @param string $time_key Checksum to be striped
* @return string
*/
function xoStripeKey($time_key)
{
$uu = 0;
$num = 6;
$length = strlen($time_key);
$strip = floor(strlen($time_key) / 6);
for ($i = 0; $i < strlen($time_key); $i++) {
if ($i < $length) {
$uu++;
if ($uu == $strip) {
$ret .= substr($time_key, $i, 1) . '-';
$uu = 0;
} else {
if (substr($time_key, $i, 1) != '-') {
$ret .= substr($time_key, $i, 1);
} else {
$uu--;
}
}
}
}
$ret = str_replace('--', '-', $ret);
if (substr($ret, 0, 1) == '-') {
$ret = substr($ret, 2, strlen($ret));
}
if (substr($ret, strlen($ret), 1) == '-') {
$ret = substr($ret, 0, strlen($ret) - 1);
}
return $ret;
}
/**
* xoFindDateZone()
* Finds from Data a PHP Datezone
*
* @param array $terms Terms to base find on
* @param array $zones Date Zone Array from xoGetDateZones()
* @param string $node Contextual Array Node
* @param string $basis Contextual Array Node
* @return string
*/
function xoFindDateZone($terms = array(), $zones = array(), $node = "", $basis = 'regions')
{
$result = "";
foreach($terms as $id => $term)
{
if (!empty($term))
{
if (in_array(strtolower($term), array_keys($zones['places'])))
{
if (isset($zones['zones'][$zones['places'][$term]]['code']) && !empty($zones['zones'][$zones['places'][$term]]['code']))
return $zones['zones'][$zones['places'][$term]]['code'];
}
switch($basis)
{
case "regions":
default:
if (in_array(strtolower($term), array_keys($zones['regions'])))
{
$tterm = $terms;
unset($tterm[$id]);
if (strlen($result = xoFindDateZone($tterm, $zones, $term, 'areas'))>0)
return $result;
}
break;
case "areas":
if (in_array(strtolower($term), array_keys($zones['areas'][$node])))
{
if (isset($zones['zones'][$zones['areas'][$node][$term]]['code']) && !empty($zones['zones'][$zones['areas'][$node][$term]]['code']))
return $zones['zones'][$zones['areas'][$node][$term]]['code'];
}
break;
}
foreach($zones['zones'] as $key => $values)
{
if (strpos($key, strtolower($term))>0)
{
return $values['code'];
}
}
}
}
return "";
}
/**
* xoGetDateZones()
* Imports Datezones
*
* @param string $filename File to be imported
* @return array
*/
function xoGetDateZones($filename = '')
{
if (!file_exists($filename))
return array();
static $ret = array();
if (!isset($ret[md5($filename)]))
{
foreach(file($filename) as $line)
{
$parts = explode("/", $line = trim($line));
if (isset($parts[1]) && !empty($parts[1]))
{
if ($parts[1]!=$parts[0]) {
$ret[md5($filename)]['areas'][strtolower($parts[0])][strtolower($parts[1])] = strtolower($line);
$ret[md5($filename)]['places'][strtolower($parts[1])] = strtolower($line);
$ret[md5($filename)]['zones'][strtolower($line)] = array('region'=>$parts[0], 'area' => $parts[1], 'code' => ucfirst(strtolower($parts[0])) . '/' . ucfirst(strtolower($parts[1])));
} else {
$ret[md5($filename)]['zones'][strtolower($line)] = array('region'=>$parts[0], 'area' => $parts[0], 'code' => ucfirst(strtolower($parts[0])));
}
$ret[md5($filename)]['regions'][strtolower($parts[0])] = $parts[0];
} elseif (isset($parts[0]) && !empty($parts[0])) {
$ret[md5($filename)]['zones'][strtolower($line)] = array('region'=>$parts[0], 'area' => $parts[0], 'code' => ucfirst(strtolower($parts[0])));
$ret[md5($filename)]['regions'][strtolower($parts[0])] = $parts[0];
}
}
}
return $ret[md5($filename)];
}
?>