This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
514 lines (457 loc) · 11.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
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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<?php
//Define the Child Template Directory
define('CHILD_TEMPLATE_DIR', plugin_dir_path(__FILE__));
define('ERUDITE_CHILD_THEME_PATH', plugin_dir_path(__FILE__));
define('ERUDITE_CHILD_THEME_URI', get_stylesheet_directory_uri());
//Require the Theme Options
require_once(CHILD_TEMPLATE_DIR."library/theme-options.php");
/**
* add_stylesheets function.
*
* @access public
* @return void
*/
function add_stylesheets() {
wp_register_style( 'erudite-child.min', ERUDITE_CHILD_THEME_URI."/css/erudite-child.min.css");
wp_enqueue_style( 'erudite-child.min' );
wp_register_style( 'hubinfo.min', ERUDITE_CHILD_THEME_URI."/css/hubinfo.min.css");
wp_enqueue_style( 'hubinfo.min' );
}
/**
* [add_scripts description]
*/
function add_scripts() {
if(internet_defense_league_status()):
wp_enqueue_script(
'internet_defense_league.min',
get_stylesheet_directory_uri() . '/js/internet_defense_league.min.js'
);
endif;
}
/**
* add_my_open_id_information function.
*
* @access public
* @return void
*/
function add_my_open_id_information(){
$options = get_theme_options();
if(isset($options['open_id_server']) && !is_null($options['open_id_server']) && isset($options['open_id_delegate']) && !is_null($options['open_id_delegate'])):
?>
<link rel="openid2.provider" href="<?php echo $options['open_id_server']; ?>" />
<link rel="openid2.local_id" href="<?php echo $options['open_id_delegate']; ?>" />
<link rel="openid.server" href="<?php echo $options['open_id_server']; ?>" />
<link rel="openid.delegate" href="<?php echo $options['open_id_delegate']; ?>" />
<?php
else:
endif;
}
/**
* add_favicons function.
*
* @access public
* @return void
*/
function add_favicons(){
?>
<link href="<?php echo home_url(); ?>/favicon.ico" rel="shortcut icon" />
<?php if(get_iphone_non_retina_icon()): ?>
<link rel="apple-touch-icon" sizes="57x57" href="<?php echo home_url(); ?>/apple-touch-icon-57x57-precomposed.png" />
<?php endif; ?>
<?php if(get_iphone_retina_icon()): ?>
<link rel="apple-touch-icon" sizes="72x72" href="<?php echo home_url(); ?>/apple-touch-icon-72x72-precomposed.png" />
<?php endif; ?>
<?php if(get_ipad_non_retina_icon()): ?>
<link rel="apple-touch-icon" sizes="114x114" href="<?php echo home_url(); ?>/apple-touch-icon-114x114-precomposed.png" />
<?php endif; ?>
<?php if(get_ipad_retina_icon()): ?>
<link rel="apple-touch-icon" sizes="144x144" href="<?php echo home_url(); ?>/apple-touch-icon-144x144-precomposed.png" />
<?php endif; ?>
<?php
}
/**
* [hubinfo description]
* @param [type] $atts [description]
* @return [type] [description]
*/
function hubinfo($atts) {
extract( shortcode_atts( array(
'user' => 'jtyost2',
'repo' => 'Erudite-Child-Theme',
'twitter' => '',
), $atts ) );
wp_enqueue_script(
'hubinfo.min',
get_stylesheet_directory_uri() . '/js/hubinfo.min.js',
array('jquery')
);
require_once(CHILD_TEMPLATE_DIR."library/hubinfo_buttons.php");
return hubinfo_button($user, $repo, $twitter);
}
/**
* add_meta_tags function.
*
* @access public
* @return void
*/
function add_meta_tags(){
global $post;
$options = get_theme_options();
if(is_single()){
?>
<meta name="description" content="<?php echo $post->post_excerpt; ?>" />
<meta name="revised" content="<?php echo $post->post_modified_gmt; ?>" />
<meta name="author" content="<?php echo get_author_complete_name($post->post_author); ?>" />
<meta name="keywords" content="<?php echo get_post_tags($post->ID); ?>" />
<meta property="og:title" content="<?php echo $post->post_title; ?>" />
<meta property="og:url" content="<?php echo get_permalink($post->ID); ?>" />
<?php
} else if(is_front_page()) {
?>
<meta name="description" content="<?php echo get_option('blogdescription', "Just another WordPress Blog."); ?>" />
<?php
} else if(is_page()) {
} else {
}
?>
<meta property="og:site_name" content="<?php echo get_option('blogname'); ?>" />
<meta property="og:type" content="blog" />
<?php
}
/**
* get_post_tags function.
*
* @access public
* @param mixed $post_ID (default: null)
* @return void
*/
function get_post_tags($post_ID = null){
$tags = wp_get_post_tags($post_ID);
$tags_string = null;
foreach($tags as $tag){
$tags_string = $tags_string.$tag->name.", ";
}
$tags_string = rtrim($tags_string, ', ');
return $tags_string;
}
/**
* insert_short_url function.
*
* @access public
* @return void
*/
function insert_short_url(){
global $post;
if(is_single()){
$shortURL = return_short_url();
?>
<link rel="shortlink" href="<?php echo $shortURL; ?>" />
<?php
}
}
/**
* get_author_complete_name function.
*
* @access public
* @param mixed $author_ID (default: null)
* @return void
*/
function get_author_complete_name($author_ID = null){
$author_info = get_userdata($author_ID);
$author_name = $author_info->display_name;
return $author_name;
}
/**
* get_iphone_non_retina_icon function.
*
* @access public
* @return void
*/
function get_iphone_non_retina_icon() {
$options = get_theme_options();
return $options['apple_touch_icon_iphone_non_retina'];
}
/**
* get_iphone_retina_icon function.
*
* @access public
* @return void
*/
function get_iphone_retina_icon() {
$options = get_theme_options();
return $options['apple_touch_icon_iphone_retina'];
}
/**
* get_ipad_non_retina_icon function.
*
* @access public
* @return void
*/
function get_ipad_non_retina_icon() {
$options = get_theme_options();
return $options['apple_touch_icon_ipad_non_retina'];
}
/**
* get_ipad_retina_icon function.
*
* @access public
* @return void
*/
function get_ipad_retina_icon() {
$options = get_theme_options();
return $options['apple_touch_icon_ipad_retina'];
}
/**
* [internet_defense_league_status description]
* @return [type] [description]
*/
function internet_defense_league_status() {
$options = get_theme_options();
return $options['internet_defense_league'];
}
/**
* create_short_url function.
*
* Creates a Short Url for the Post
*
* @access private
* @param mixed $post_ID (default: null)
* @return void
*/
function create_short_url($post_ID = null){
$longURL = home_url().'?p='.$post_ID;
$shortURL = null;
if( is_bitly_information_set() ) {
$options = get_theme_options();
$login = $options['bitly_username'];
$apikey = $options['bitly_api_key'];
$shortURL = get_bitly_url($longURL, $login, $apikey);
} else {
$shortURL = $longURL;
}
// adding the short URL to a custom field called bitlyURL
update_post_meta($post_ID, 'bitlyURL', $shortURL);
}
/**
* is_bitly_information_set function.
*
* Return if the Bit.ly Information is set
*
* @access private
* @return void
*/
function is_bitly_information_set(){
$options = get_theme_options();
return (
isset($options['bitly_username'])
&& isset($options['bitly_api_key'])
&& !empty($options['bitly_username'])
&& !empty($options['bitly_api_key'])
);
}
/**
* get_bitly_url function.
*
* Generate the Bitly Short URL
*
* @access private
* @param mixed $longURL
* @param mixed $login
* @param mixed $apikey
* @return void
*/
function get_bitly_url($longURL, $login, $apikey){
// This is the API call to fetch the shortened URL
$apiurl = 'http://api.bit.ly/v3/shorten?longUrl='.urlencode($longURL).'&login='.$login.'&apiKey='.$apikey.'&format=json';
// Use cURL to return from the API
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $apiurl);
$results = json_decode(curl_exec($curl));
curl_close($curl);
$shortURL = $results->data->url;
return $shortURL;
}
/**
* extra_contact_info function.
*
* Set Extra Contact Information
*
* @access public
* @param mixed $contactmethods
* @return void
*/
function extra_contact_info($contactmethods) {
unset($contactmethods['aim']);
unset($contactmethods['yim']);
unset($contactmethods['jabber']);
$contactmethods['facebook'] = 'Facebook';
$contactmethods['twitter'] = 'Twitter';
$contactmethods['linkedin'] = 'LinkedIn';
return $contactmethods;
}
/**
* return_short_url function.
*
* @access public
* @return void
*/
function return_short_url() {
global $post;
$shortURL = get_post_meta($post->ID, 'bitlyURL', true);
if(isset($shortURL) && !empty($shortURL)) {
return $shortURL;
} else {
return home_url().'?p='.$post->ID;
}
}
/**
* return_short_url function.
*
* @access public
* @return void
*/
function return_quickie_link() {
global $post;
$quickLink = get_post_meta($post->ID, 'quickLink', true);
if(isset($quickLink) && !empty($quickLink)) {
return $quickLink;
} else {
return NULL;
}
}
/**
* return_short_link function.
*
* @access public
* @return void
*/
function return_short_link(){
$shortURL = return_short_url();
global $post;
$shortLink = '<a rel="shortlink" title="'.$shortURL.'" href="'.$shortURL.'">'.$shortURL.'</a>';
return $shortLink;
}
/**
* censored_bar function.
*
* @access public
* @return void
*/
function censored_bar(){
$options = get_theme_options();
if($options['censored_bar'] == TRUE){
?><a style="width:50%;height:77px;vertical-align:middle;text-align:center;background-color:#000;position:absolute;z-index:5555;top:0px;left:0px;background-image:url(http://americancensorship.org/images/stop-censorship-small.png);background-position:center center;background-repeat:no-repeat;margin:0 25%;" href="http://americancensorship.org"></a><?php
}
}
function comments_status() {
$options = get_theme_options();
if(array_key_exists('comments_disabled', $options) && $options['comments_disabled']) {
return FALSE;
} else {
return TRUE;
}
}
/**
* add_to_head function.
*
* @access public
* @return void
*/
function add_to_head(){
add_stylesheets();
add_my_open_id_information();
insert_short_url();
add_favicons();
add_meta_tags();
add_scripts();
}
/**
* add_to_sidebar function.
*
* @access public
* @return void
*/
function add_to_sidebar(){
}
/**
* add_to_footer function.
*
* @access public
* @return void
*/
function add_to_footer(){
censored_bar();
}
/**
* add_on_publish function.
*
* @access public
* @param mixed $post_ID
* @return void
*/
function add_on_publish($post_ID) {
create_short_url($post_ID);
}
/**
* get_theme_options function.
*
* @access public
* @return void
*/
function get_theme_options() {
$options = get_option('erdt_child_theme_options');
if(!$options) {
return array();
}
return $options;
}
//Add Filters
add_filter('wp_head', 'add_to_head');
add_filter('wp_sidebar', 'add_to_sidebar');
add_filter('wp_footer', 'add_to_footer');
add_filter('wp_get_shortlink', 'return_short_url');
add_filter('user_contactmethods', 'extra_contact_info');
//Remove Actions
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 );
//Add Actions
add_action('publish_post', 'add_on_publish');
//Add Shortcodes
add_shortcode( 'hubinfo', 'hubinfo' );
class EruditeChildThemeFunctions {
private static $instance = false;
public function __construct() {
//self::$instance = &$this;
add_action('init', array(&$this, 'init'));
}
/**
* [init description]
* @return [type] [description]
*/
public function init() {
//Add Filters
add_filter('the_permalink_rss', array(&$this, 'quick_link_permalink_rss'));
}
public function quick_link_permalink_rss($content) {
$link = get_post_meta($this->_return_post_id, 'quickLink', true);
if(is_feed()) {
if($link !== '') {
$content = $link;
} else {
$content = get_permalink($postid);
}
}
return $content;
}
public function _return_post_id() {
global $wp_query;
$postId = $wp_query->post->ID;
return $postId;
}
}
if (class_exists('EruditeChildThemeFunctions')) {
$_EruditeChildThemeFunctions = new EruditeChildThemeFunctions();
$_EruditeChildThemeFunctions->init();
}
?>