-
Notifications
You must be signed in to change notification settings - Fork 21
/
functions.php
420 lines (371 loc) · 15.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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<?php
require (get_template_directory() . '/include/widget.php');
require (get_template_directory() . '/include/pagination.php');
include_once( get_template_directory() . '/vendor/autoload.php' );
WP_Dependency_Installer::instance()->run( __DIR__ );
add_action('init', 'load_modules'); //ocio!
function load_modules() {
require (get_template_directory() . '/include/welcome-pasw2015.php' );
if (get_option('pasw_mcolumn') != 0) { require ( get_template_directory() . '/include/moduli/pasw2015-multiple-columns.php' ); }
if (get_option('pasw_catpage') != 0) { require ( get_template_directory() . '/include/moduli/pasw2015-category-page.php' ); }
if (get_option('pasw_taxdest') != 0) { require ( get_template_directory() . '/include/moduli/pasw2015-destinatari.php' ); }
if (get_option('pasw_msidebar') != 0) {
require ( get_template_directory() . '/include/moduli/pasw2015-multiple-sidebars.php' );
pasw_sidebar_generator::init();
}
if (get_option('pasw_eulaw') != 0) { require ( get_template_directory() . '/include/moduli/pasw2015-eulaw.php' ); }
if (get_option('pasw_post_tpl') != 0) { require ( get_template_directory() . '/include/moduli/pasw2015-post-templates.php' ); }
}
add_action('admin_init', function() {
require (get_template_directory() . '/include/moduli-pasw2015.php' );
register_setting( 'pasw2015_options', 'pasw_social');
register_setting( 'pasw2015_options', 'pasw_email_scuola');
register_setting( 'pasw2015_options', 'pasw_pec_scuola');
register_setting( 'pasw2015_options', 'pasw_recapito_scuola');
register_setting( 'pasw2015_options', 'pasw_indirizzo_scuola');
register_setting( 'pasw2015_options', 'pasw_fluid_width');
register_setting( 'pasw2015_options', 'pasw_loghi_footer');
register_setting( 'pasw2015_options', 'pasw_testo_footer');
register_setting( 'pasw2015_options', 'pasw_secondo_menu');
register_setting( 'pasw2015_options', 'pasw_menu_login');
register_setting( 'pasw2015_options', 'pasw_ga_id');
register_setting( 'pasw2015_options', 'pasw_ga_profile_id');
register_setting( 'pasw2015_options', 'pasw_ga_user');
register_setting( 'pasw2015_options', 'pasw_key');
register_setting( 'pasw2015_options', 'pasw_ga_password');
register_setting( 'pasw2015_options', 'pasw_logo');
register_setting( 'pasw2015_options', 'pasw_submenu', 'intval');
register_setting( 'pasw2015_functions', 'pasw_mcolumn', 'intval');
register_setting( 'pasw2015_functions', 'pasw_catpage', 'intval');
register_setting( 'pasw2015_functions', 'pasw_taxdest', 'intval');
register_setting( 'pasw2015_functions', 'pasw_msidebar', 'intval');
if (!get_option('pasw_key')) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < 10; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
update_option( 'pasw_key', $randomString);
if( -1 != get_option('page_on_front') ) {
update_post_meta( get_option('page_on_front'), '_wp_page_template', 'tmpl_home.php' );
} // end if
}
add_option( 'pasw2015_version');
if (version_compare(get_option('pasw2015_version'), get_pasw2015_version(), "<")) {
if (get_option('pasw2015_version') == '') {
update_option( 'pasw_logo', get_bloginfo("template_url").'/images/repubblica-italiana.png');
}
update_option('pasw2015_version', get_pasw2015_version());
update_option('pasw2015_versionalert', get_pasw2015_version());
delete_option( 'pasw_favicon' );
wpgov_update();
wp_safe_redirect(admin_url('/admin.php?page=pasw2015', 'http'), 301);
}
} );
add_action('admin_notices', function() {
if ( isset($_GET['pasw2015alert'])) {
update_option( 'pasw2015_versionalert', '0' );
}
if ( get_option('pasw2015_versionalert') == '1.6.6') {
echo '
<div class="updated">
<p>La versione <b>1.7</b> di Pasw2015 porta alcune importanti novità:
<br>
<li><b>Nuovo sistema di Google Analytics</b>: supporteremo il vecchio ancora per qualche tempo. Per passare al nuovo, vai nelle impostazioni e segui le istruzioni.</li>
<li><b>Icona del Sito</b>: abbiamo rimosso il campo per l\'icona del sito. Da questo momento non funzionerà più. Per reimpostarla, vai nelle impostazioni e segui le istruzioni.</li>
<br><a href="?pasw2015alert=0">Ok, ho capito e sistemerò al più presto!</a>
</p>
</div>';
}
} );
add_action( 'after_setup_theme', 'pasw2015_setup' );
add_action('admin_notices', 'pasw_alerts');
function pasw_alerts() {
if (is_admin() && get_option('pasw_wrongdirectory') == 1) {
echo '<div class="error"><p>Pasw2015 è installato nella directory "<b>' . get_template() . '</b>". Per un corretto funzionamento è necessario cambiare il nome della cartella in "pasw2015".<br/>
Questo messaggio scomparirà automaticamente correggendo il problema.</p></div>';
}
}
function pasw2015_setup() {
if (get_template() != 'pasw2015') {
update_option('pasw_wrongdirectory', 1);
} else {
delete_option('pasw_wrongdirectory');
}
}
function get_pasw2015_version() {
$p2015_theme = wp_get_theme( 'pasw2015' );
if ( $p2015_theme->exists() ) {
return wp_get_theme('pasw2015')->get( 'Version' );
} else {
update_option('pasw_wrongdirectory', 1);
return wp_get_theme()->get( 'Version' );
}
}
function is_pasw2015_child() {
if (( wp_get_theme( 'pasw2015-child' )->exists() ) && (wp_get_theme()->name !== 'PASW 2015')){
return true;
} else {
return false;
}
}
function version_child() {
$r = '';
if ( get_option('pasw_responsive_layout') ) { $r = '+R'; }
if (is_pasw2015_child()) {
return apply_filters( 'pasw2015childedition', 'C').$r;
} else {
return ''.$r;
}
}
add_action( 'wp_enqueue_scripts', function() {
if ( get_option('pasw_responsive_layout') ) {
wp_enqueue_style( 'pasw2015_styles-responsive', get_template_directory_uri() . '/responsive.css', array(), null, 'all' );
}
wp_enqueue_style( 'pasw2015_styles-fonts', get_template_directory_uri() . '/font/css/font-awesome.min.css', array(), null, 'all' );
wp_enqueue_style( 'pasw2015_styles', get_stylesheet_uri() , array());
wp_enqueue_style( 'pasw2015_styles-print', get_template_directory_uri() . '/print.css', array(), null, 'print' );
wp_enqueue_script( 'pasw2015-script', get_template_directory_uri() . '/js/pasw2015.js', array( 'jquery' ), '20151227', true );
} );
add_action( 'after_setup_theme', function() {
$defaults = array(
'default-color' => 'white',
'default-image' => get_template_directory_uri() . '/images/pattern_default_pasw2015.jpg',
'default-repeat' => 'repeat'
);
add_theme_support( 'custom-background', $defaults );
$args = array(
'width' => 1150,
'height' => 125,
'flex-height' => true,
'flex-width' => true,
'default-image' => get_template_directory_uri() . '/images/header-default-pasw2015.jpg',
'default-repeat'=> 'repeat',
'default-text-color' => '#00004d'
);
add_theme_support( 'custom-header', $args );
add_theme_support('post-thumbnails');
add_theme_support( 'title-tag' );
} );
add_action('init', function() { // Menu
if (get_option('pasw_secondo_menu')) {
$array_menu = array('menu-1' => 'Menù Superiore', 'menu-2' => 'Menù Principale', 'menu-4' => 'Menù Principale Secondario', 'menu-3' => 'Menù Inferiore');
} else {
$array_menu = array('menu-1' => 'Menù Superiore', 'menu-2' => 'Menù Principale', 'menu-3' => 'Menù Inferiore');
}
register_nav_menus($array_menu);
} );
function pasw2015_widgets_init() {
register_sidebar( array(
'name' => 'Barra laterale (SX)',
'id' => 'sidebar-1',
'description' => 'Sidebar sinistra del sito web.'
) );
register_sidebar( array(
'name' => 'Barra laterale (DX)',
'id' => 'sidebar-2',
'description' => 'Sidebar destra del sito web.'
) );
register_sidebar( array(
'name' => 'Home (SX)',
'id' => 'sidebar-6',
'description' => 'Area Widget (1) della homepage.'
) );
register_sidebar( array(
'name' => 'Home (CX)',
'id' => 'sidebar-7',
'description' => 'Area Widget (2) della homepage.'
) );
register_sidebar( array(
'name' => 'Home (DX)',
'id' => 'sidebar-8',
'description' => 'Area Widget (3) della homepage.'
) );
register_sidebar( array(
'name' => 'Sotto home (SX)',
'id' => 'sidebar-3',
'description' => 'Area Widget (1) sotto la homepage.'
) );
register_sidebar( array(
'name' => 'Sotto home (CX)',
'id' => 'sidebar-4',
'description' => 'Area Widget (2) sotto la homepage.'
) );
register_sidebar( array(
'name' => 'Sotto home (DX)',
'id' => 'sidebar-5',
'description' => 'Area Widget (3) sotto la homepage.'
) );
}
add_action( 'widgets_init', 'pasw2015_widgets_init' );
/* returns the count of comments or pings depending */
function comment_count_special($post_id, $comment_type)
{
$the_post_comments = get_comments('post_id=' . $post_id);
$comments_by_type = separate_comments($the_post_comments);
return count($comments_by_type[$comment_type]);
}
/* Only return comment counts */
add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count )
{
global $id;
global $nearlysprung;
if ($nearlysprung && $nearlysprung->option['splitpings'] != "yes")
{
return $count;
}
else
{
return comment_count_special($id, 'comment');
}
}
function ns_comments($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php echo get_avatar($comment->comment_author_email, $size = '40', $comment->comment_author_link); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">said,</span>'), get_comment_author_link()) ?>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.') ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadataa">
<?php comment_date('F j, Y') ?>
@ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a>
<?php edit_comment_link(__("Edit"), ' · ', ''); ?>
</div>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php
}
function ns_trackbacks($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-trackbackping-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php printf(__('<cite class="fn">%s</cite> <span class="says">said,</span>'), get_comment_author_link()) ?>
</div>
<div class="comment-meta commentmetadataa">
<?php comment_date('F j, Y') ?>
@ <a href="#trackbackping-<?php comment_ID() ?>"><?php comment_time() ?></a>
<?php edit_comment_link(__("Edit"), ' · ', ''); ?>
</div>
<?php comment_text() ?>
</div>
<?php
}
function pasw2015_colors_register_theme_customizer( $wp_customize ) {
$wp_customize->add_setting( 'pasw2015_colore_principale', array( 'default' => '#00004d', 'transport' => 'postMessage' ));
$wp_customize->add_setting( 'pasw2015_colore_secondario', array( 'default' => '#C2E2ED', 'transport' => 'postMessage' ));
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'colore-principale',
array(
'label' => 'Colore principale',
'section' => 'colors',
'settings' => 'pasw2015_colore_principale'
)
)
);
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'colore-secondario',
array(
'label' => 'Colore secondario',
'section' => 'colors',
'settings' => 'pasw2015_colore_secondario'
)
)
);
}
add_action( 'customize_register', 'pasw2015_colors_register_theme_customizer' );
function pasw2015_customizer_css() { ?>
<style type="text/css">
<?php
$c_principale = get_theme_mod( 'pasw2015_colore_principale', '#00004d');
$c_secondario = get_theme_mod( 'pasw2015_colore_secondario', '#C2E2ED');
if ( ! display_header_text() ) {
echo '.site-title, .site-description { display:none; }';
}
?>
h1, h2, h3, h4 {
color: <?php echo $c_principale; ?>;
}
input, textarea, select {
box-shadow: 0 0 3px <?php echo $c_principale; ?>;
}
a:link, a:visited, a:hover, a:active {
color: <?php echo $c_principale; ?>;
}
#topbar, #header ul.sito, #footer, #rightsidebar h2, .hdate, .sotto-pagine li:hover, #centrecontent a img:hover, .showall_widget a:hover {
background-color: <?php echo $c_principale; ?>;
}
#wrapper, #topbar, #header ul.sito, #footer {
box-shadow: 0 0 1px <?php echo $c_principale; ?>;
}
.posttitle, .pagetitle, #leftsidebar h2 {
border-color: <?php echo $c_principale; ?>;
}
#centrecontent img {
border-color: <?php echo $c_secondario; ?>;
}
#sidebarleft-100-background, #topbar ul li a:hover, #topbar ul li.current_page_item a, .showall_widget, #centrecontent table td {
background-color: <?php echo $c_secondario; ?>;
}
.col-com2, .sotto-pagine, .pagecat, .riassunto, .postmeta, .secondo-menu {
background-color: <?php echo $c_secondario; ?>;
}
input#submit{
background-color: <?php echo $c_secondario; ?>;
border-bottom: 1px solid <?php echo $c_principale; ?>;
}
</style>
<?php
}
add_action( 'wp_head', 'pasw2015_customizer_css' );
function pasw2015_customizer_live_preview() {
wp_enqueue_script(
'pasw2015-theme-customizer',
get_template_directory_uri() . '/js/theme-customizer.js',
array( 'jquery', 'customize-preview' ),
'0.3.0',
true
);
}
add_action( 'customize_preview_init', 'pasw2015_customizer_live_preview' );
function wpgov_update() {
$options = array(
'name' => get_bloginfo('name'),
'key' => md5(get_option('pasw_key')),
'address' => get_option('pasw_indirizzo_scuola'),
'version' => get_option('pasw2015_version'),
'domain' => site_url());
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_URL,'http://pasw2015.wpgov.it/welcome.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
$result = curl_exec($ch);
curl_close($ch);
}
// Replaces the excerpt "more" text by a link
function new_excerpt_more($more) {
global $post;
return ' <a class="moretag" href="'. get_permalink($post->ID) . '" title="Leggi l´intero articolo">»</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
// abilita lo style css nell'area admin
function pasw_admin_head() {
echo '<link rel="stylesheet" type="text/css" href="'.get_template_directory_uri() . '/font/css/font-awesome.min.css">';
}
add_action('admin_head', 'pasw_admin_head');
?>