-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
240 lines (184 loc) · 8.09 KB
/
Copy pathfunctions.php
File metadata and controls
240 lines (184 loc) · 8.09 KB
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
<?php
// require_once("regioni_e_zone/regione_zone_utils.php");
function add_bootstrap_style()
{
// Register the style like this for a theme:
wp_register_style( 'bootstrap-style', get_template_directory_uri() . '/styles/bootstrap.min.css' );
// For either a plugin or a theme, you can then enqueue the style:
wp_enqueue_style( 'bootstrap-style' );
}
add_action( 'wp_enqueue_scripts', 'add_bootstrap_style' );
if(!function_exists('_log')){
function _log( $message ) {
if( WP_DEBUG === true ){
if( is_array( $message ) || is_object( $message ) ){
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
}
}
}
function child_override(){
// override
remove_action('cryout_before_content_hook' , 'tempera_above_widget');
add_action ('cryout_before_content_hook','my_tempera_above_widget');
};
// add hook for overload function
add_action( 'after_setup_theme', 'child_override' );
function my_tempera_above_widget() {
if ( is_active_sidebar( 'above-content-widget-area' ) && is_home() ) { ?>
<ul class="yoyo">
<?php dynamic_sidebar( 'above-content-widget-area' ); ?>
</ul>
<?php } }
// API: sfida_permalink?completa
// ESEMPIO: http://returntodreamland.agesci.org/blog/sfida_event/viaggio-nel-tempo/?completa
function completa_sfida(){
global $current_user;
$post = get_post();
if(is_single() && get_post_type() == 'sfida_event' && isset($_GET['completa'])){
_log("Landing su completamento della sfida " . get_the_ID() . " per utente " . $current_user->ID);
if(isset($_SESSION['wordpress']['user_id'])
&& $_SESSION['wordpress']['user_id'] == $current_user->ID ){
$status = get_iscrizione_status($post, $current_user->ID);
if($status != StatusIscrizione::RICHIESTA){
wp_die('La sfida che stai concludendo risulta "'. $status . '"'.
'. Per poterla completare la sfida deve essere nello stato "Attiva". '.
'Se pensi che sia un errore per favore contatta lo staff di Return to Dreamland.<br>\n'.
'<a href="'. get_admin_url() .'">Torna alla bacheca.', 'Qualcosa non va..');
}
$get_is_sfida = filter_input(INPUT_GET, 'sfida', FILTER_SANITIZE_STRING);
$tiposfida = filter_input(INPUT_GET, 'tipo', FILTER_SANITIZE_STRING);
$superata = filter_input(INPUT_GET, 'successo', FILTER_SANITIZE_STRING);
if($get_is_sfida === null || $tiposfida === null || $superata === null){
_log("Completamento sfida (u:". $current_user->ID ." s:" . $post->ID ."): argomenti della richiesta mancanti: " . $get_is_sfida.", ". $tiposfida .", ". $superata );
wp_die("Si è verificato un'errore nel completamento della sfida.".
" Per favore contatta lo staff di Return to Dreamland.".
"(Parametri mancanti nella richiesta)", "Errore tecnico");
}
$is_sfida = $get_is_sfida === 'true';
$newpost = rtd_completa_sfida(get_post(get_the_ID()), $current_user->ID, $is_sfida, $tiposfida, $superata);
_log("Completata s: " . get_the_ID() . " u:" . $current_user->ID . " racc:" . $newpost . " superata:" . $superata);
$_SESSION['portal'] = array();
if( $superata != 'true'){
wp_redirect( admin_url() );
exit();
}
wp_redirect(get_edit_post_link($newpost, 'do_not_encode_ampersand'));
exit;
}
wp_redirect(post_permalink(get_the_ID()));
exit;
}
}
add_action('wp_head', 'completa_sfida');
// API: sfida_permalink?iscritto
// ESEMPIO: http://returntodreamland.agesci.org/blog/sfida_event/viaggio-nel-tempo/?iscritto
function iscrizione_sfida_completata(){
global $current_user;
if(is_single() && get_post_type() == 'sfida_event' && isset($_GET['iscritto'])){
_log("Landing su completamento iscrizione sfida " . get_the_ID() . " per utente " . $current_user->ID);
if(isset($_SESSION['portal']['request']['sfidaid'])
&& $_SESSION['portal']['request']['sfidaid'] == get_the_ID()){
// salva iscrizione completata
_log("Completata iscrizione sfida " . get_the_ID() . " per utente " . $current_user->ID);
add_user_meta($current_user->ID, '_iscrizioni', get_the_ID(), False);
add_user_meta($current_user->ID,'_iscrizione_'.get_the_ID(), StatusIscrizione::RICHIESTA, True);
$_SESSION['portal'] = array();
} else {
_log(var_export($_SESSION,true));
}
wp_redirect(post_permalink(get_the_ID()));
}
}
add_action('wp_head', 'iscrizione_sfida_completata');
function diiscrizione_sfida(){
global $current_user;
$post = get_post();
if(is_single() && get_post_type() == 'sfida_event' && isset($_GET['disiscrivi'])){
_log("Landing su disiscrizione sfida " . get_the_ID() . " per utente " . $current_user->ID);
if(!is_sfida_subscribed($post) || get_iscrizione_status($post) != StatusIscrizione::RICHIESTA){
wp_die("Non sei iscritto alla sfida o l'hai già completata", "Errore", array('back_link' => true));
}
disiscriviti();
}
}
add_action('wp_head', 'diiscrizione_sfida');
function disiscriviti(){
global $current_user;
rtd_disiscrivi_utente_da_sfida(get_the_ID(), $current_user->ID);
wp_redirect(post_permalink(get_the_ID()));
}
// API: sfida_permalink?iscriviti
// ESEMPIO: http://returntodreamland.agesci.org/blog/sfida_event/viaggio-nel-tempo/?iscriviti
function richiedi_iscrizione_sfida(){
global $current_user;
if(is_single() && get_post_type() === 'sfida_event' && isset($_GET['iscriviti'])){
if(!is_user_logged_in()){
wp_die("Solo gli Esploratori o Guide registrati possono iscriversi alle sfide.");
exit();
}
$user_id = $current_user->ID;
if($user_id == 0){
wp_redirect("wp-login.php");
exit();
}
// login_portal( $user->user_login, $user );
// BYPASS_CHECKS_PSWD is defined in wp-config.php
$bypass_checks = (filter_input(INPUT_GET, 'pswd', FILTER_SANITIZE_STRING) === BYPASS_CHECKS_PSWD);
$post = get_post();
if(!is_sfida_for_me($post) && ! $bypass_checks){
wp_die("Non puoi partecipare a questa sfida.", "Sfida a partecipazione limitata", array('back_link' => True));
exit();
}
if(!is_sfida_alive($post) && ! $bypass_checks){
wp_die("Questa sfida non è più attiva.", "Sfida scaduta", array('back_link' => True));
exit();
}
// controlla se non è già iscritto
if(is_sfida_subscribed($post)){
wp_die("Sei già iscritto a questa sfida.", "Qualcosa non va...", array('back_link' => True));
exit();
}
$u_p = get_user_meta($user_id, 'punteggio');
$ncomponenti_p = get_user_meta($user_id, 'numerocomponenti');
$nspecialita_p = get_user_meta($user_id, 'nspecialita');
$nbrevetti_p = get_user_meta($user_id, 'nbrevetti');
$_SESSION['sfide'] = array(
'sfida_url' => post_permalink($post->ID),
'sfida_titolo' => get_the_title($post->ID),
'sfida_id' => $post->ID,
'sfidaspeciale' => is_sfida_speciale($post),
'categoria' => get_elenco_categorie_sfida($post),
'punteggio_attuale' => ($u_p) ? reset($u_p) : $u_p,
'numero_componenti' => ($ncomponenti_p) ? reset($ncomponenti_p) : $ncomponenti_p,
'numero_specialita' => ($nspecialita_p) ? reset($nspecialita_p) : $nspecialita_p,
'numero_brevetti' => ($nbrevetti_p) ? reset($nbrevetti_p) : $nbrevetti_p
);
_log('Richiesta iscrizione per evento '.$post->ID.' da parte dello user '.$current_user->ID);
$url = site_url('../portal/api/sfide/iscrizione/'. $post->ID);
_log('Redirect to '.$url);
wp_redirect($url);
exit();
}
}
add_action('wp_head', 'richiedi_iscrizione_sfida');
function no_nopaging($query) {
if (is_post_type_archive('sfida_event')) {
$query->set('nopaging', 1);
}
}
add_action('parse_query', 'no_nopaging');
//// @see http://codex.wordpress.org/Template_Hierarchy
//// @see http://codex.wordpress.org/images/9/96/wp-template-hierarchy.jpg
function custom_single_template($single_template) {
global $post;
$newPath = dirname( __FILE__ ) . '/single-'.$post->post_type.'.php';
if ( file_exists($newPath) ) {
$single_template = dirname( __FILE__ ) . '/single-'.$post->post_type.'.php';
}
return $single_template;
}
add_filter('single_template', 'custom_single_template');
?>