-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfunctions.php
254 lines (196 loc) · 8.32 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
show_admin_bar(false);
function neobcb21_enqueue_scripts()
{
wp_enqueue_script("jquery");
wp_enqueue_script("fittext", get_bloginfo('template_url') . "/scripts/FitText/jquery.fittext.js");
wp_enqueue_script("my_script", get_bloginfo('template_url') . "/scripts/script.js");
wp_enqueue_script("bootstrap-js", "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js");
wp_enqueue_style('bootstrap', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css');
// wp_enqueue_style('font-awesome', get_bloginfo('template_url') . "/font-awesome-4.7.0/css/font-awesome.min.css");
wp_enqueue_style('font-awesome', get_bloginfo('template_url') . "/fontawesome-free-5.15.2-web/css/all.css");
wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css?family=Lato');
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'neobcb21_enqueue_scripts');
// register menu
function register_my_menus()
{
register_nav_menu('menu_part1', "Menu Part 1");
register_nav_menu('menu_part2', "Menu Part 2");
register_nav_menu('menu_part3', "Menu Part 3");
}
add_action('after_setup_theme', 'register_my_menus');
function mytheme_comment($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment;
?>
<li <?php comment_class();?> id="li-comment-<?php comment_ID()?>">
<div id="comment-<?php comment_ID();?>" class="comment-body">
<?php echo get_avatar($comment->comment_author_email, 48); ?>
<div class="comment-body-inner">
<div class="comment-author vcard">
<cite class="fn"><a href="<?php echo get_author_posts_url(get_user_by('email', get_comment_author_email())->ID); ?>"><?php echo get_user_by('email', get_comment_author_email())->data->user_nicename; ?></a></cite>
</div>
<?php if ($comment->comment_approved == '0'): ?>
<em><?php _e('Your comment is awaiting moderation.')?></em>
<br>
<?php endif;?>
<?php comment_text()?>
<div class="comment_footer">
<span class="comment-meta commentmetadata"><a href="<?php echo esc_url(get_comment_link($comment->comment_ID)) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time())?></a><?php edit_comment_link(__('Edit'), ' ∘ ', '')?></span>
∘
<span class="reply">
<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'])))?>
</span>
</div>
</div>
<div style="clear: both"></div>
</div>
</li>
<?php
}
/**************************************************************
*
* Functions for the Attending System
*
**************************************************************/
add_action("wp_ajax_toggle_attend", "neo_attend_toggle_attend");
add_action("wp_ajax_nopriv_toggle_attend", "neo_attend_toggle_attend_nologin");
function neo_attend_toggle_attend()
{
global $current_user;
$result = array();
// if ( !wp_verify_nonce( $_REQUEST['nonce'], "neo_attend_nonce")) {
// exit("No naughty business please");
// }
if (is_user_logged_in()) {
$attendingusers = attending_users($_REQUEST['post_id']);
if (array_search($current_user->user_login, $attendingusers) !== false) {
delete_post_meta($_REQUEST['post_id'], 'user_attending', $current_user->user_login);
} else {
add_post_meta($_REQUEST['post_id'], 'user_attending', $current_user->user_login);
}
$result['status'] = "OK";
$result['button_text'] = get_my_attending_button($_REQUEST['post_id']);
$result['attendees_list'] = get_attending_users_links($_REQUEST['post_id'], "", "•");
$result['attendees_count'] = attending_users_count($_REQUEST['post_id']);
} else {
$result['status'] = 'ERROR! User must be logged in';
}
echo json_encode($result);
die();
}
function neo_attend_toggle_attend_nologin()
{
$result = array();
$result['status'] = 'Please log in to mark your preferences';
$result['button_text'] = get_my_attending_button($_REQUEST['post_id']);
echo json_encode($result);
die;
}
function attending_users($postid)
{
return get_post_meta($postid, 'user_attending');
}
function attending_users_count($postid)
{
return count(attending_users($postid));
}
function get_attending_users_links($postid, $prev = 'Who is attending : ', $separator = ', ')
{
$result = "";
$attendingusers = attending_users($postid);
$first_item_flag = true;
if (count($attendingusers) > 0) {
//$result.='<h2>'.count($attendingusers).' people are attending :</h2> ';
$result .= '<div class="attending_users_wrapper">';
foreach ($attendingusers as $user) {
if ($first_item_flag) {
$first_item_flag = false;
} else {
$result .= $separator;
}
$user = get_user_by('login', $user);
$result .= '<a class="attending_user" href="' . get_author_posts_url($user->ID) . '">' . get_the_author_meta('user_nicename', $user->ID) . '</a>';
}
$result .= '</div>';
} else {
$result .= '<div class="attending_users_wrapper">(None Yet)</div>';
}
return $result;
}
function get_my_attending_button($postid)
{
global $current_user;
$result = "";
$attendingusers = attending_users($postid);
if (array_search($current_user->user_login, $attendingusers) !== false) {
$result .= '<div class="neo_attend_button neo_button_attending" data-postid="' . $postid . '" >'
. '<img src="' . get_bloginfo('template_url') . '/images/icons-19.png" title="I am Attending" /></div>';
} else {
$result .= '<div class="neo_attend_button neo_button_wanna_attend" data-postid="' . $postid . '" >'
. '<img src="' . get_bloginfo('template_url') . '/images/icons-18.png" title="I wanna Attend" /></div>';
}
return $result;
}
function get_my_attending_button_single($postid)
{
global $current_user;
$result = "";
$attendingusers = attending_users($postid);
if (array_search($current_user->user_login, $attendingusers) !== false) {
$result .= '<div class="neo_attend_button neo_button_attending" data-postid="' . $postid . '" >'
. '<img src="' . get_bloginfo('template_url') . '/images/icons-19.png" title="I am Attending" /><div class="attend_text">Click to Cancel</div></div>';
} else {
$result .= '<div class="neo_attend_button neo_button_wanna_attend" data-postid="' . $postid . '" >'
. '<img src="' . get_bloginfo('template_url') . '/images/icons-18.png" title="I wanna Attend" /><div class="attend_text">Click to Attend</div></div>';
}
return $result;
}
/**************************************************************
*
* END Functions for Attending System
*
**************************************************************/
add_action('rest_api_init', function() {
register_rest_route('custom', '/sessions', array(
'methods' => 'GET',
'callback' => 'getSessions'
));
});
function getSessions($data) {
$post = get_posts(array(
'name' => $data->get_param('slug'),
'post_status' => 'any'
));
return $post;
}
/**************************************************************
*
* Functions for Active Category and tracks management
*
**************************************************************/
function get_current_cats(bool $get_as_string)
{
// NOTE - The Order of the categories matters! It has to be same as the icons on the sessions page.
// Tech, Design, Mobile & Web, Bangalore LIfestyle, Scaling Infra, Entrepreneurship, Rest of world
$tracks = array(2012, 2006, 2008, 2005, 2010, 2007, 2009);
// $tracks = array(1971, 1972, 1973, 1974, 1975, 1976, 1977);
if ($get_as_string) {
return implode(", ", $tracks);
} else {
return $tracks;
}
}
/**
* Return array of post ids of 2 chosen tracks.
* If tracks not chosen, return empty array
*/
function get_chosen_track_ids() {
return array(7354, 7363);
// return array(7300, 7302);
}
function get_archived_track_ids() {
return array();
}