summaryrefslogtreecommitdiff
blob: 5658a254a2e32483a4d6360632d6c8b38a5eca0f (plain)
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
<?php
/**
 * Misc functions breadcrumbs / pagination / transient data /back to top button
 *
 * @package mantra
 * @subpackage Functions
 */


/**
* Loads necessary scripts
* Adds HTML5 tags for IE8
* Used in header.php
*/
function mantra_header_scripts() {
	?><!--[if lt IE 9]> 
	<script>
	document.createElement('header');
	document.createElement('nav');
	document.createElement('section');
	document.createElement('article');
	document.createElement('aside');
	document.createElement('footer');
	document.createElement('hgroup');
	</script>
	<![endif]--> <?php
}
add_action( 'wp_head', 'mantra_header_scripts', 100 );

 /**
 * Adds title and description to heaer
 * Used in header.php
*/
function mantra_title_and_description() {
	global $mantra_options;
	extract( $mantra_options );

	// Header styling and image loading
	// Check if this is a post or page, if it has a thumbnail, and if it's a big one

	global $post;

	if (get_header_image() != '') { $header_image = get_header_image(); }
	if ( is_singular() && has_post_thumbnail( $post->ID ) && ($mantra_fheader == "Enable") && ($image = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'header' ) ) && (intval($image[1]) >= HEADER_IMAGE_WIDTH) ):
		$header_image = $image[0];
	endif;

	if (isset($header_image) && ($header_image != '')) {
		printf( '<img id="bg_image" alt="%1$s" title="" src="%2$s" />', esc_attr( get_bloginfo( 'name', 'display' ) ), $header_image );
	}
	?>
	
	<div id="header-container">
	
	<?php
	switch ($mantra_siteheader) {

		case 'Site Title and Description': 
			$heading_tag = ( ( is_home() || is_front_page() ) && !is_page() ) ? 'h1' : 'div'; ?>
			<div>
				<<?php echo $heading_tag ?> id="site-title">
					<span> <a href="<?php echo esc_url( home_url( '/' ) ) ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ) ?>" rel="home"><?php echo esc_attr( get_bloginfo( 'name' ) ) ?></a> </span>
				</<?php echo $heading_tag ?>>
				<div id="site-description" ><?php echo esc_attr( get_bloginfo( 'description' ) ) ?></div>
			</div> <?php
		break;

		case 'Clickable header image': ?>
			<a href="<?php echo esc_url( home_url( '/' ) ) ?>" id="linky"></a>
			<?php
		break;

		case 'Custom Logo' :
			if (!empty($mantra_logoupload)) { ?>
			<div>
				<a id="logo" href="<?php echo esc_url( home_url( '/' ) ) ?>"> <img title="" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ) ?>" src="<?php echo $mantra_logoupload ?>" /> </a>
			</div> 
			<?php }
		break;

		case 'Empty' :
			// nothing to do here
		break;
	}

	if ($mantra_socialsdisplay0): mantra_header_socials(); endif;
	?>
	</div> <!-- #header-container -->
	<?php

} // mantra_title_and_description()
add_action( 'cryout_branding_hook', 'mantra_title_and_description' );

/**
* Add social icons in header / undermneu left / undermenu right / footer
* Used in header.php and footer.php
*/
function mantra_header_socials() {
	mantra_set_social_icons('sheader');
}

function mantra_smenul_socials() {
	mantra_set_social_icons('smenul');
}

function mantra_smenur_socials() {
	mantra_set_social_icons('smenur');
}

function mantra_footer_socials() {
	mantra_set_social_icons('sfooter');
}

//if ($mantra_socialsdisplay0) add_action( 'cryout_branding_hook', 'mantra_header_socials' );
if ($mantra_socialsdisplay1) add_action( 'cryout_forbottom_hook', 'mantra_smenul_socials' );
if ($mantra_socialsdisplay2) add_action( 'cryout_forbottom_hook', 'mantra_smenur_socials' );
if ($mantra_socialsdisplay3) add_action( 'cryout_footer_hook', 'mantra_footer_socials', 13 );


/**
 * Social icons function
 */
if ( ! function_exists( 'mantra_set_social_icons' ) ) :
function mantra_set_social_icons($location){
	$cryout_special_keys = array('Mail', 'Skype');
	global $mantra_options;
	extract( $mantra_options ); ?>
	<div class="socials" id="<?php echo $location ?>"> 
	<?php
	for ($i=1; $i<=9; $i+=2) {
		$j=$i+1;
		if ( ${"mantra_social$j"} ) {
			if ( in_array(${"mantra_social$i"}, $cryout_special_keys) ) :
				$cryout_current_social = esc_html( ${"mantra_social$j"} );
			else :
				$cryout_current_social = esc_url( ${"mantra_social$j"} );
			endif;	?>

			<a target="_blank" rel="nofollow" href="<?php echo $cryout_current_social; ?>" class="socialicons social-<?php echo esc_attr(${"mantra_social$i"}); ?>" title="<?php echo esc_attr(${"mantra_social$i"}); ?>">
				<img alt="<?php echo esc_attr(${"mantra_social$i"}); ?>" src="<?php echo get_template_directory_uri().'/resources/images/socials/'.${"mantra_social$i"}.'.png'; ?>" />
			</a>
            <?php
		} // $j
	} // $i
	?>
	</div>
	<?php
}
endif;


/**
 * Mantra back to top button
 * Creates div for js
*/
function mantra_back_top() { 
	?>
    <div id="toTop"><i class="crycon-back2top"></i> </div>
	<?php
}
if ($mantra_backtop=="Enable") add_action( 'cryout_body_hook', 'mantra_back_top' );


 /**
 * Creates breadcrumns with page sublevels and category sublevels.
 */
function mantra_breadcrumbs() {
	global $mantra_options; 
	global $post;
	
	echo '<div class="breadcrumbs">';
	if (is_page() && !is_front_page() || is_single() || is_category() || is_archive()) {
		echo '<a href="'.esc_url( home_url() ) .'">' . esc_attr( get_bloginfo('name') ).'</a> &raquo; ';

		if (is_page()) {
			$ancestors = get_post_ancestors($post);
			if (!empty($ancestors)) {
				$ancestors = array_reverse($ancestors);
				foreach ($ancestors as $crumb) {
					echo '<a href="' . esc_url( get_permalink($crumb) ) . '">' . esc_attr( get_the_title($crumb) ) . ' </a> &raquo; ';
				}
			}
		}

		if (is_single() && has_category()) { 
			$category = get_the_category();
			echo '<a href="' . get_category_link($category[0]->cat_ID) . '">' . $category[0]->cat_name . '</a> &raquo; ';
		}

		if (is_category()) {
			$category = get_the_category();
			echo $category[0]->cat_name;
		}

		if (is_tag()) {
			echo __('Tag','mantra') . ' &raquo; ' . single_tag_title('', false);
		}

		// Current page
		if (is_page() || is_single()) {
			echo get_the_title();
		}
		echo '';
	} elseif (is_home() && $mantra_options['mantra_frontpage']!="Enable" ) {
		// Front page
		echo '';
		echo '<a href="' . esc_url( home_url() ) .'">' . esc_attr( get_bloginfo('name') ).'</a> &raquo; ' . __('Home Page','mantra');
		echo '';
	}
	echo '</div>';
}
if ($mantra_breadcrumbs=="Enable")  add_action( 'cryout_before_content_hook', 'mantra_breadcrumbs', 0 );


/**
 * Creates pagination for blog pages.
 */
if ( ! function_exists( 'mantra_pagination' ) ) :
function mantra_pagination($pages = '', $range = 2, $prefix ='') {
    $showitems = ($range * 2)+1;

    global $paged;
    if(empty($paged)) $paged = 1;

    if ($pages == '') {
        global $wp_query;
        $pages = $wp_query->max_num_pages;
        if(!$pages) {
            $pages = 1;
        }
    }

    if (1 != $pages) {
		echo "<div class='pagination_container'><nav class='pagination'>";
		if ($prefix) echo "<span id='paginationPrefix'>$prefix </span>";
		if ($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
		if ($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";

		for ($i=1; $i <= $pages; $i++) {
			if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
				echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
			}
		}

		if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";
		if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
		echo "</nav></div>\n";
    }
}
endif;

function mantra_nextpage_links($defaults) {
    $args = array(
    'link_before'      => '<em>',
    'link_after'       => '</em>',
    );
    $r = wp_parse_args($args, $defaults);
    return $r;
}
add_filter( 'wp_link_pages_args', 'mantra_nextpage_links' );


/**
 * Site info
 */
function mantra_site_info() { ?>
<div style="text-align:center;clear:both;padding-top:4px;" >
	<a href="<?php echo esc_url( home_url( '/' ) ) ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
		<?php bloginfo( 'name' ); ?></a> | <?php _e('Powered by','mantra')?> <a target="_blank" href="<?php echo 'http://www.cryoutcreations.eu';?>" title="<?php echo 'Mantra Theme by '.
		'Cryout Creations';?>"><?php echo 'Mantra' ?></a> &amp; <a target="_blank" href="<?php echo esc_url('http://wordpress.org/' ); ?>"
		title="<?php esc_attr_e('Semantic Personal Publishing Platform', 'mantra'); ?>"> <?php printf(' %s.', 'WordPress' ); ?>
	</a>
</div><!-- #site-info --> <?php 
}
add_action( 'cryout_footer_hook', 'mantra_site_info', 12 );


/**
 * Copyright text
 */
function mantra_copyright() {
	global $mantra_options; ?>
	<div id="site-copyright"> 
		<?php echo $mantra_options['mantra_copyright'] ?>
	</div>
	<?php
}
if (!empty($mantra_copyright)) add_action( 'cryout_footer_hook', 'mantra_copyright', 11 );


/**
* Retrieves the IDs for images in a gallery.
* @since mantra 2.1.1
* @return array List of image IDs from the post gallery.
*/
function mantra_get_gallery_images() {
       $images = array();

       if ( function_exists( 'get_post_galleries' ) ) {
               $galleries = get_post_galleries( get_the_ID(), false );
               if ( isset( $galleries[0]['ids'] ) )
                       $images = explode( ',', $galleries[0]['ids'] );
       } else {
               $pattern = get_shortcode_regex();
               preg_match( "/$pattern/s", get_the_content(), $match );
               $atts = shortcode_parse_atts( $match[3] );
               if ( isset( $atts['ids'] ) )
                       $images = explode( ',', $atts['ids'] );
       }

       if ( ! $images ) {
               $images = get_posts( array(
                       'fields'         => 'ids',
                       'numberposts'    => 999,
                       'order'          => 'ASC',
                       'orderby'        => 'menu_order',
                       'post_mime_type' => 'image',
                       'post_parent'    => get_the_ID(),
                       'post_type'      => 'attachment',
               ) );
       }

       return $images;
} // mantra_get_gallery_images()


/**
* Checks the browser agent string for mobile ids and adds "mobile" class to body if true
* @since mantra 2.2.3
* @return array list of classes.
*/
function mantra_mobile_body_class($classes){
	global $mantra_options;
	if ($mantra_options['mantra_mobile']=="Enable") {
		$browser = $_SERVER['HTTP_USER_AGENT'];
		if ( preg_match("/(mobile|android|mobi|tablet|ipad|opera mini|series 60|s60|blackberry)/i", $browser) ) $classes[] = 'mobile'; // mobile browser detected
	}
	return $classes;
}
add_filter('body_class', 'mantra_mobile_body_class');


// Favicon
function mantra_fav_icon() {
	global $mantra_options;
	echo '<link rel="shortcut icon" href="'.esc_url($mantra_options['mantra_favicon']).'" />';
	echo '<link rel="apple-touch-icon" href="'.esc_url($mantra_options['mantra_favicon']).'" />';
}

if ($mantra_options['mantra_favicon']) add_action( 'cryout_header_hook', 'mantra_fav_icon' );

// FIN