/
functions.php
374 lines (322 loc) · 14.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
<?php
function theme_404_content_cat($args = '') {
$args = wp_parse_args($args, array(
'error_title' => __('Pàgina no trobada', THEME_NS),
'error_message' => __('No s\'ha trobat la pàgina que busques. Vols provar a cercar alguna cosa ?', THEME_NS),
'focus_script' => '<script type="text/javascript">jQuery(\'div.mmb-content input[name="s"]\').focus();</script>'
)
);
extract($args);
theme_post_wrapper(
array(
'title' => $error_title,
'content' => '<p class="center">' . $error_message . '</p>' . "\n" . theme_get_search() . $focus_script
)
);
if (theme_get_option('theme_show_random_posts_on_404_page')) {
theme_ob_start();
echo '<h4 class="box-title">' . theme_get_option('theme_show_random_posts_title_on_404_page') . '</h4>';
?>
<ul>
<?php
global $post;
$rand_posts = get_posts('numberposts=5&orderby=rand');
foreach ($rand_posts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php
theme_post_wrapper(array('content' => theme_ob_get_clean()));
}
if (theme_get_option('theme_show_tags_on_404_page')) {
theme_ob_start();
echo '<h4 class="box-title">' . theme_get_option('theme_show_tags_title_on_404_page') . '</h4>';
wp_tag_cloud('smallest=9&largest=22&unit=pt&number=200&format=flat&orderby=name&order=ASC');
theme_post_wrapper(array('content' => theme_ob_get_clean()));
}
}
function theme_get_metadata_icons($icons = '', $class = '') {
global $post;
if (!is_string($icons) || theme_strlen($icons) == 0)
return;
$icons = explode(",", str_replace(' ', '', $icons));
if (!is_array($icons) || count($icons) == 0)
return;
$result = array();
for ($i = 0; $i < count($icons); $i++) {
$icon = $icons[$i];
switch ($icon) {
case 'date':
$result[] = '<span class="mmb-postdateicon">' . sprintf(__('<span class="%1$s"></span> %2$s', THEME_NS),
'date',
sprintf( '<span class="entry-date" title="%1$s">%2$s</span>',
esc_attr( get_the_time() ),
get_the_date()
)
) . '</span>';
break;
case 'author':
$result[] = '<span class="mmb-postauthoricon">' . sprintf(__('<span class="%1$s">By</span> %2$s', THEME_NS),
'author',
sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr(__( 'View all posts by %s', THEME_NS )), get_the_author() ),
get_the_author()
)
) . '</span>';
break;
case 'category':
$categories = get_the_category_list(', ');
if (theme_strlen($categories) == 0)
break;
$result[] = '<span class="mmb-postcategoryicon">' . sprintf(__('<span class="%1$s">Posted in</span> %2$s', THEME_NS), 'categories', get_the_category_list(', ')) . '</span>';
break;
case 'tag':
$tags_list = get_the_tag_list('', ', ');
if (!$tags_list)
break;
$result[] = '<span class="mmb-posttagicon">' . sprintf(__('<span class="%1$s">Tagged</span> %2$s', THEME_NS), 'tags', $tags_list) . '</span>';
break;
case 'comments':
if (!comments_open() || !theme_get_option('theme_allow_comments'))
break;
theme_ob_start();
comments_popup_link(__('Leave a comment', THEME_NS), __('1 Comment', THEME_NS), __('% Comments', THEME_NS));
$result[] = '<span class="mmb-postcommentsicon">' . theme_ob_get_clean() . '</span>';
break;
case 'edit':
if (!current_user_can('edit_post', $post->ID))
break;
theme_ob_start();
edit_post_link(__('Edit', THEME_NS), '');
$result[] = '<span class="mmb-postediticon">' . theme_ob_get_clean() . '</span>';
break;
}
}
$result = implode(theme_get_option('theme_metadata_separator'), $result);
if (theme_is_empty_html($result))
return;
return "<div class=\"mmb-post{$class}icons mmb-metadata-icons\">{$result}</div>";
}
//Apply .thumbnail class to WP avatars
add_filter('get_avatar', 'change_avatar_css');
function change_avatar_css($class) {
//$class = str_replace('class="', 'class="img-circle img-thumbnail ', $class);
$class = str_replace('class="', 'class="img-responsive ', $class);
return $class;
}
function hasSecondarySidebar() {
//Determino si s'ha de mostrar el 2on sidebar a la variable secondary
global $post;;
// Pagina home 2 barres laterals
if (is_home()) return true;
//Pagines que explicitament no han de mostrar segona barra
$only_primary_sidebar_posts = array(73 /*Categoria cançons */);
if (in_array($post->ID, $only_primary_sidebar_posts)) return false;
// Resta de casos:
// es mostra la barra secundaria per defecte sempre excepte per $secondary = 0 (es a dir si esta deshabilitada al template de la pagina)
$secondary = get_post_meta($post->ID, '_theme_layout_template_secondary_sidebar', $single = true);
$secondary = ($secondary == "0") ? false : true;
return $secondary;
}
//Cridant aquesta funcio en comptes de theme_get_next_post, si el tema te un thumbnail nomes mostrarem un extracte
function theme_get_next_excerpt() {
static $ended = false;
if (!$ended) {
if (have_posts()) {
the_post();
if (has_post_thumbnail()) {
get_template_part('excerpt', get_post_format());
} else {
get_template_part('content', get_post_format());
}
} else {
$ended = true;
}
}
}
function mm_custom_scripts() {
wp_deregister_script('jquery');
wp_deregister_script('jquery-ui');
wp_deregister_script('jquery-ui-core');
wp_deregister_script('jquery-ui-widget');
wp_deregister_script('jquery-ui-position');
wp_deregister_script('jquery-ui-mouse');
wp_deregister_script('jquery-ui-sortable');
wp_deregister_script('jquery-ui-datepicker');
wp_deregister_script('jquery-ui-menu');
wp_deregister_script('jquery-ui-autocomplete');
wp_deregister_script('jquery-ui-ui.resizable');
wp_deregister_script('jquery-ui-ui.draggable');
wp_deregister_script('jquery-ui-ui.button');
wp_deregister_script('jquery-ui-dialog');
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js');
//<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
wp_enqueue_script('jqueryui', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js');
//wp_enqueue_script('jqueryui', get_stylesheet_directory_uri().'/js/jquery-ui-1.10.4.custom.min.js');
// Loads Bootstrap minified JavaScript file.
wp_enqueue_script('bootstrapjs', '//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js', array('jquery'),'3.0.0');
//wp_enqueue_script('events', 'http://mondemusica2.local/wp-content/plugins/events-manager/includes/js/events-manager.js', array('jquery','jqueryui'),'5.52');
// Loads Bootstrap minified CSS file.
wp_enqueue_style('bootstrapwp', '//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css', false ,'3.0.0');
// Loads our main stylesheet.
wp_enqueue_script('mm', get_stylesheet_directory_uri().'/js/mm.js', array('jquery','bootstrapjs'));
}
add_action('wp_enqueue_scripts', 'mm_custom_scripts');
/* Botons Google plus, Twitter i Facebook */
//add_action ('wp_enqueue_scripts','google_plus_script');
function google_plus_script() {
wp_enqueue_script('google-plus', 'https://apis.google.com/js/plusone.js', array(), null);
}
function social_buttons ($content) {
//if (is_single()) {
$content .= '<div class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-layout="box_count" data-action="like" data-show-faces="true" data-share="false"></div>';
$content .= '<g:plusone size="tall" href="'.get_permalink().'"></g:plusone>';
$content .= '<a href="https://twitter.com/share" class="twitter-share-button" data-count="vertical" data-lang="ca">Tweet</a>';
//}
return $content;
}
//add_filter("the_content", "social_buttons");
function facebook_meta_tags_posts() {
if(is_single()) {
global $post;
$content = $post->post_content;
$images = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
$image = $matches [1] [0];
if (!$image)
$image = 'HTTP://YOUR DEFAULT IMAGE LOCATION HERE';
?>
<meta property="og:title" content="<?php the_title(); ?>"/>
<meta property="og:description" content="<?php echo get_post_meta($post->ID, 'thesis_description', true) ?>"/>
<meta property="og:url" content="<?php the_permalink(); ?>"/>
<meta property="og:image" content="<?php echo $image; ?>"/>
<meta property="og:type" content="article"/>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>"/>
<?php }
}
add_action('wp_head', 'facebook_meta_tags_posts');
/*Filtrar els posst de la categoria Cançons de l'arxiu */
add_filter( 'getarchives_where', 'customarchives_where' );
add_filter( 'getarchives_join', 'customarchives_join' );
function customarchives_join( $x ) {
global $wpdb;
return $x . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
}
function customarchives_where( $x ) {
global $wpdb;
$exclude = '3'; // category id to exclude
return $x . " AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id NOT IN ($exclude)";
}
/* Fi filtre */
include "widgets/AuthorProfile.php";
include "widgets/FacebookLikeBox.php";
include "widgets/CategoriesThumbs.php";
//include "widgets/Outline.php";
function hidden_submenu_init() {
register_sidebar( array(
'name' => 'Hidden Submenu Area',
'id' => 'submenu',
'before_widget' => '<div class="hidden-submenu">',
'after_widget' => '</div>',
'before_title' => '<h3 class="t" style="margin-bottom: 10px;">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'hidden_submenu_init' );
/* Afegir area de widget a sota del header */
function below_header_init() {
register_sidebar( array(
'name' => 'After Header Widget Area',
'id' => 'sections',
'before_widget' => '<div class="seccions">',
'after_widget' => '</div>',
'before_title' => '<h3 class="t" style="margin-bottom: 10px;">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'below_header_init' );
/* Afegir area de widget a la zona central de la capçalera */
function outline1_init() {
register_sidebar( array(
'name' => 'Header Outline Widget Area 1',
'id' => 'outline-1',
'before_widget' => '<div class="destacat-1">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
/* Afegir area de widget a la zona central de la capçalera */
function outline2_init() {
register_sidebar( array(
'name' => 'Header Outline Widget Area 2',
'id' => 'outline-2',
'before_widget' => '<div class="destacat-2">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'outline1_init' );
add_action( 'widgets_init', 'outline2_init' );
/* Totes les imatges del contingut responsives */
function add_image_responsive_class($content) {
global $post;
$pattern ="/<img(.*?)class=\"(.*?)\"(.*?)>/i";
$replacement = '<img$1class="$2 img-responsive"$3>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'add_image_responsive_class');
/*Mostrar thumbs ajustats a ample de contenidor */
add_filter('post_thumbnail_html','add_img_thumbnail_class');
function add_img_thumbnail_class($thumb) {
//if( is_single() )
$thumb = str_replace('class="', 'class="img-thumbnail ', $thumb);
return $thumb;
}
//Elimina els <p> que afegeix el WP automaticament en els posts i pagines
remove_filter( 'the_content', 'wpautop' );
function html_widget_title( $title ) {
/*
//HTML tag opening/closing brackets
$title = str_replace( '[', '<', $title );
$title = str_replace( '[/', '</', $title );
// bold -- changed from 's' to 'strong' because of strikethrough code
$title = str_replace( 'strong]', 'strong>', $title );
$title = str_replace( 'b]', 'b>', $title );
// italic
$title = str_replace( 'em]', 'em>', $title );
$title = str_replace( 'i]', 'i>', $title );
// underline
// $title = str_replace( 'u]', 'u>', $title ); // could use this, but it is deprecated so use the following instead
$title = str_replace( '<u]', '<span style="text-decoration:underline;">', $title );
$title = str_replace( '</u]', '</span>', $title );
// superscript
$title = str_replace( 'sup]', 'sup>', $title );
// subscript
$title = str_replace( 'sub]', 'sub>', $title );
// del
$title = str_replace( 'del]', 'del>', $title ); // del is like strike except it is not deprecated, but strike has wider browser support -- you might want to replace the following 'strike' section to replace all with 'del' instead
// strikethrough or <s></s>
$title = str_replace( 'strike]', 'strike>', $title );
$title = str_replace( 's]', 'strike>', $title ); // <s></s> was deprecated earlier than so we will convert it
$title = str_replace( 'strikethrough]', 'strike>', $title ); // just in case you forget that it is 'strike', not 'strikethrough'
// tt
$title = str_replace( 'tt]', 'tt>', $title ); // Will not look different in some themes, like Twenty Eleven -- FYI: http://reference.sitepoint.com/html/tt
// marquee
$title = str_replace( 'marquee]', 'marquee>', $title );
// blink
$title = str_replace( 'blink]', 'blink>', $title ); // only Firefox and Opera support this tag
*/
// wtitle1 (to be styled in style.css using .wtitle1 class)
$title = str_replace( '[wtitle1]', '<span class="wtitle1">', $title );
$title = str_replace( '[/wtitle1]', '</span>', $title );
// wtitle2 (to be styled in style.css using .wtitle2 class)
$title = str_replace( '[wtitle2]', '<span class="wtitle2">', $title );
$title = str_replace( '[/wtitle2]', '</span>', $title );
return $title;
}
add_filter( 'widget_title', 'html_widget_title' );
?>