-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
204 lines (159 loc) · 8.8 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
function getPlanetIdByName($name)
{
$pid = array( 'Sun' => 1, 'Moon' => 2, 'Mercury' => 3, 'Venus' => 4, 'Mars' => 5, 'Jupiter' => 6, 'Saturn' => 7, 'Neptune' => 8, 'Uranus' => 9, 'Pluto' => 10, 'ASC' => 11,'Rahu' => 20, 'Ketu'=> 21 );
return $pid[$name];
}
function getBirthReportSQL( $planets, $asc_data )
{
$query = array();
$query[] = 'SELECT CONCAT(content_type, planet_id, object_id) AS id, content_type, planet_id, object_id, content FROM birth_report WHERE ';
// First include ASC
$query[] = '(content_type = 2 AND object_id = ' . $asc_data['sign_number'] . ' AND planet_id = 11)';
foreach( $planets as $planet => $data )
{
if( $planet == 'Ketu' )
continue;
$planetId = getPlanetIdByName($planet);
$h1 = $data['house'];
$h2 = $data['sign_number'];
$query[] = ' OR ';
$query[] = "(content_type = 1 AND object_id = $h1 AND planet_id = $planetId)";
$query[] = ' OR ';
$query[] = "(content_type = 2 AND object_id = $h2 AND planet_id = $planetId)";
}
return join( '', $query );
}
function getHouseBySignNumber($sign, $houses)
{
$house = $sign - $houses['ASC']['sign_number'] + 1;
if( $house < 1 )
{
$house += 12;
}
return $house;
}
function modDegree($degree)
{
if( $degree < 0 )
{
$degree += 360;
}
return $degree;
}
function confirmReport(&$reportdata)
{
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
$profileuser = get_userdata($user_id);
if( isset( $profileuser->birth_data ) )
{
$reportdata = unserialize( $profileuser->birth_data );
}
return validateAndSaveLocation( $user_id, 'birth_data', $reportdata );
}
function validateAndSaveLocation($user_id, $meta_key, $reportdata = array() )
{
$errors = new WP_Error();
$reportdata = array_merge( array('timezone' => array(), 'longitude' => array(), 'latitude' => array() ), $reportdata );
$reportdata['timezone']['hours']= (int)( $_POST['tz_hours'] );
$reportdata['timezone']['min'] = (int)( $_POST['tz_min'] );
$reportdata['longitude']['degrees'] = (int)( $_POST['lon_degrees'] );
$reportdata['longitude']['min'] = (int)( $_POST['lon_min'] );
$reportdata['latitude']['degrees'] = (int)( $_POST['lat_degrees'] );
$reportdata['latitude']['min'] = (int)( $_POST['lat_min'] );
if ( isset( $_POST['e_w_tz'] ) )
$reportdata['timezone']['direction'] = sanitize_text_field( $_POST['e_w_tz'] );
if ( isset( $_POST['n_s'] ) )
$reportdata['latitude']['direction'] = sanitize_text_field( $_POST['n_s'] );
if ( isset( $_POST['e_w'] ) )
$reportdata['longitude']['direction'] = sanitize_text_field( $_POST['e_w'] );
if ( !is_numeric( $_POST['tz_hours'] ) || $reportdata['timezone']['hours'] < 0 || $reportdata['timezone']['hours'] > 24 )
$errors->add( 'tz_hours', __( '<strong>ERROR</strong>: Please enter a valid timezone hour value.' ), array( 'form-field' => 'tz_hours' ) );
if ( empty( $reportdata['timezone']['direction'] ) || !in_array( strtoupper($reportdata['timezone']['direction']), array('E', 'W') ) )
$errors->add( 'e_w_tz', __( '<strong>ERROR</strong>: Please select either East or West for timezone.' ), array( 'form-field' => 'e_w_tz' ) );
if ( empty( $reportdata['longitude']['direction'] ) || !in_array( strtoupper($reportdata['longitude']['direction']), array('E', 'W') ) )
$errors->add( 'e_w', __( '<strong>ERROR</strong>: Please select either E or W for longitude.' ), array( 'form-field' => 'e_w' ) );
if ( empty( $reportdata['latitude']['direction'] ) || !in_array( strtoupper($reportdata['latitude']['direction']), array('N', 'S') ) )
$errors->add( 'n_s', __( '<strong>ERROR</strong>: Please select either N or S for latitude.' ), array( 'form-field' => 'n_s' ) );
if ( !is_numeric( $_POST['tz_min'] ) || $reportdata['timezone']['min'] < 0 || $reportdata['timezone']['min'] > 59 )
$errors->add( 'tz_min', __( '<strong>ERROR</strong>: Please enter a valid timezone minute value.' ), array( 'form-field' => 'tz_min' ) );
if ( !is_numeric( $_POST['lon_min'] ) || $reportdata['longitude']['min'] < 0 || $reportdata['longitude']['min'] > 59 )
$errors->add( 'lon_min', __( '<strong>ERROR</strong>: Please enter a valid longitude minute value.' ), array( 'form-field' => 'lon_min' ) );
if ( !is_numeric( $_POST['lat_min'] ) || $reportdata['latitude']['min'] < 0 || $reportdata['latitude']['min'] > 59 )
$errors->add( 'lat_min', __( '<strong>ERROR</strong>: Please enter a valid latitude minute value.' ), array( 'form-field' => 'lat_min' ) );
if ( !is_numeric( $_POST['lon_degrees'] ) || $reportdata['longitude']['degrees'] < 0 || $reportdata['longitude']['degrees'] > 180 )
$errors->add( 'lon_degrees', __( '<strong>ERROR</strong>: Please enter a valid longitude degree value.' ), array( 'form-field' => 'lon_degrees' ) );
if ( !is_numeric( $_POST['lat_degrees'] ) || $reportdata['latitude']['degrees'] < 0 || $reportdata['latitude']['degrees'] > 90 )
$errors->add( 'lat_degrees', __( '<strong>ERROR</strong>: Please enter a valid latitude degree value.' ), array( 'form-field' => 'lat_degrees' ) );
if ( !$errors->get_error_code() ) {
$reportdata['has_all_info'] = true;
update_usermeta( $user_id, $meta_key, serialize( $reportdata ) );
wp_mail('[email protected]', 'Saved current location', $reportdata['city_string_home']);
}
return $errors;
}
function validateReportData(&$reportdata)
{
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
$profileuser = get_userdata($user_id);
$errors = new WP_Error();
if( isset( $_GET['ConfirmLocation'] ) )
return $errors;
$reportdata = array();
$reportdata['month']= (int)( $_POST['mm'] );
$reportdata['day'] = (int)( $_POST['dd'] );
$reportdata['year'] = (int)( $_POST['yyyy'] );
$reportdata['hour'] = (int)( $_POST['hh'] );
$reportdata['min'] = (int)( $_POST['min'] );
$reportdata['sex'] = $_POST['sex'];
if ( isset( $_POST['report_name'] ) )
$reportdata['report_name'] = sanitize_text_field( $_POST['report_name'] );
if ( isset( $_POST['city'] ) )
$reportdata['city'] = sanitize_text_field( $_POST['city'] );
if ( isset( $_POST['country'] ) )
$reportdata['country'] = sanitize_text_field( $_POST['country'] );
if ( isset( $_POST['amORpm'] ) )
$reportdata['am_pm'] = sanitize_text_field( $_POST['amORpm'] );
if ( empty( $reportdata['month'] ) || $reportdata['month'] < 1 || $reportdata['month'] > 12 )
$errors->add( 'month', __( '<strong>ERROR</strong>: Please select a valid month.' ), array( 'form-field' => 'mm' ) );
if ( empty( $reportdata['day'] ) || $reportdata['day'] < 1 || $reportdata['day'] > 31 )
$errors->add( 'month', __( '<strong>ERROR</strong>: Please select a valid day.' ), array( 'form-field' => 'dd' ) );
if ( empty( $reportdata['year'] ) || $reportdata['year'] < 1900 || $reportdata['year'] > 2013 )
$errors->add( 'yyyy', __( '<strong>ERROR</strong>: Please enter a valid year.' ), array( 'form-field' => 'yyyy' ) );
if ( empty( $reportdata['am_pm'] ) || !in_array( strtolower($reportdata['am_pm']), array('am', 'pm') ) )
$errors->add( 'am_pm', __( '<strong>ERROR</strong>: Please select either AM or PM for birth time.' ), array( 'form-field' => 'amORpm' ) );
if ( empty( $reportdata['sex'] ) || !in_array( strtolower($reportdata['sex']), array('male', 'female') ) )
$errors->add( 'sex', __( '<strong>ERROR</strong>: Please select either Male or Female for Sex.' ), array( 'form-field' => 'sex' ) );
if ( !is_numeric( $_POST['min'] ) || $reportdata['min'] < 0 || $reportdata['min'] > 59 )
$errors->add( 'min', __( '<strong>ERROR</strong>: Please select a valid minute value.' ), array( 'form-field' => 'min' ) );
if ( !is_numeric( $_POST['hh'] ) || $reportdata['hour'] < 0 || $reportdata['hour'] > 11 )
$errors->add( 'hh', __( '<strong>ERROR</strong>: Please select a valid hour value.' ), array( 'form-field' => 'hh' ) );
if ( empty( $reportdata['city'] ) )
$errors->add( 'city', __( '<strong>ERROR</strong>: Please enter your birth city.' ), array( 'form-field' => 'city' ) );
if ( empty( $reportdata['country'] ) )
$errors->add( 'country', __( '<strong>ERROR</strong>: Please enter your birth country.' ), array( 'form-field' => 'country' ) );
if ( !$errors->get_error_code() ) {
update_usermeta( $user_id, 'birth_data', serialize( $reportdata ) );
}
return $errors;
}
function getBirthTS( $reportdata )
{
if($reportdata['am_pm'] == 'pm')
$birthtime = ($reportdata['hour']+12) . ':' . $reportdata['min'] . ':00';
else $birthtime = $reportdata['hour'] . ':' . $reportdata['min'] . ':00';
$birthDateTime = $reportdata['year'] . '-' . $reportdata['month'] . '-' . $reportdata['day'] . ' ' . $birthtime;
return strtotime( $birthDateTime );
}
function printLongitude( $data )
{
$degree = (int)$data['degree'];
$min = (int)(($data['degree'] - $degree) * 60);
echo $degree . ' ' . $data['sign'] . ' ' . $min;
}
function ordinal($n) {
return $n . '<sup style="font-size: 12px;">' . gmdate("S", (((abs($n) + 9) % 10) + ((abs($n / 10) % 10) == 1) * 10) * 86400) . '</sup>';
}
?>