forked from inclusive-design/idi-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
159 lines (137 loc) · 6 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
<?php
add_theme_support( 'post-thumbnails' );
// Override the default UIO strings
$uio_strings_custom = 'showText: "Preferences", hideText: "Preferences"';
// This site uses The Twitter Feed Wordpress Plugin found at
// http://pleer.co.uk/wordpress/plugins/wp-twitter-feed/
$twitter_feed_opts = ' followlink="no" num="1" linktotweet="no" tweetintent="no" img="no" tprefix="" tsuffix="ago" other=”yes” ulclass="twitter-list" liclass="twitter-tweet"';
/**
* Add IDI-specific JS files to the header
*/
function add_idi_files() {
$baseurl = get_stylesheet_directory_uri();
// The font fix for Chrome and Firefox on windows
// Lato font is too light to read with chrome on windows, use arial/helvetica instead
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($userAgent, "windows") && (strpos($userAgent, "chrome") || strpos($userAgent, "firefox"))) {
echo '<link rel="stylesheet" type="text/css" media="all" href="'. $baseurl. '/style-windows.css" />'. "\n";
}
echo '<script type="text/javascript" src="' . $baseurl . '/lib/parallax-scrolling.js" ></script>' . "\n";
echo '<script type="text/javascript" src="' . $baseurl . '/idi.js" ></script>' . "\n";
echo '<!--[if lt IE 8]>' . "\n";
echo '<script type="text/javascript" src="' . $baseurl . '/idi-ltie8.js" ></script>' . "\n";
echo '<![endif]-->' . "\n";
}
add_action('wp_head', 'add_idi_files');
/**
* Customize the 'more' link at the end of a post excerpt
*/
function idi_excerpt_more($more) {
global $post;
return '<p><a class="idi-more idi-no-tab-focus" title="'. $post->post_title .'" alt="'. $post->post_title .'" href="'. get_permalink($post->ID) . '">read article</a></p>';
}
add_filter('excerpt_more', 'idi_excerpt_more');
/**
* Brand the login page with IDI-specific styling
*/
function brand_login_page() {
echo '<link rel="stylesheet" type="text/css" media="all" href="'. get_stylesheet_directory_uri() .'/login-page.css" />';
echo '<script type="text/javascript" src="' . get_template_directory_uri() .'/infusion/MyInfusion.js"></script>';
echo '<script type="text/javascript">
function loginalt() {
var logoLink = $("#login a");
logoLink.attr({
href: "' . site_url() . '",
title: "' . get_bloginfo('name') . '"
});
}
window.onload=loginalt;
</script>';
}
add_action('login_head', 'brand_login_page');
/**
* Taken from the Wordpress Codex documentation for conditional tags
* Determines if the current page or post is a descendent of the given page
*/
function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
global $post; // load details about this page
$anc = get_post_ancestors( $post->ID );
foreach($anc as $ancestor) {
if(is_page() && $ancestor == $pid) {
return true;
}
}
if(is_page()&&(is_page($pid)))
return true; // we're at the page or at a sub page
else
return false; // we're elsewhere
};
function idi_generate_top_nav() {
$pages = get_pages( array ('parent' => '0', 'sort_column' => 'menu_order'));
$out = "<ul>";
foreach ( $pages as $pagg ) {
$out .= '<li><a class="idi-nav-' . $pagg->post_name;
if (is_tree($pagg->ID)) {
$out .= ' current_page_item';
}
$out .= '" href="' . get_page_link($pagg->ID) . '">';
$out .= $pagg->post_name . '</a></li>';
}
$out .= "</ul>";
echo $out;
}
/**
* Removed the attribute id="content" that's inherited from the parent theme "wordpress-fss-theme"
* if the idi-theme template needs to have "skip to content" link leads to a more specific content
* section.
*/
function remove_parent_contentID() {
echo '<script type="text/javascript">' . "\n";
echo '$(document).ready(function () {' . "\n";
echo ' $(".fl-site-main-body[id=\'content\']").removeAttr("id");' . "\n";
echo '});' . "\n";
echo '</script>' . "\n";
}
/**
* Stay on login panel when login errors occur, instead of redirecting to login screen
*/
add_action( 'wp_login_failed', 'panel_login_fail' ); // hook failed login
function panel_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER'];
// if there's a valid referrer, and it's not the default log-in screen
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
$referrer = explode('?', $referrer);
parse_str($referrer[1], $referrer_args);
unset($referrer_args['idilogout']); //unset old idilogout arg if set
$referrer_args['idilogin'] = "failed"; //let theme know there are errors
wp_redirect( $referrer[0]."?".http_build_query($referrer_args) );
exit;
}
}
function idi_display_twitter_feed($twitter_un) {
require_once("wp-content/plugins/twitteroauth/twitteroauth/twitteroauth.php");
$num_tweets = 1;
$consumerkey = "luK78NyRjDEmMVhi6sgIw";
$consumersecret = "E6bY0ShFmtibIqWU0oHokCVZKYtPEvZcNyACBPzYqo";
$accesstoken = "123905660-DBVNC6meqlD4KgZrQcAuynwYaMxJsLqLiyrtkArR";
$accesstokensecret = "UhlTPgNowuNOsC0Oaw89PM29PcVRD4N14sAdkAUk";
$connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = array_filter($connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitter_un."&count=".$num_tweets));
echo '<div class="idi-box idi-highlight-box twitter-feed-group">
<div class="idi-box-text">
<a class="twitter-follow-button" rel="external nofollow" href="http://twitter.com/'.$twitter_un.'" title="Follow @'.$twitter_un.'">@'.$twitter_un.'</a>
<ul>
';
if(!empty($tweets)){
foreach($tweets as $tweet) {
echo '<li class="tweet">'.$tweet->text.
'<div class="tweet-date">'.substr($tweet->created_at, 0, 16).'</div></li>';
}
} else{
echo "<p>no tweets found</p>";
}
echo '</ul>
</div>
</div>';
}
?>