forked from LeoColomb/yourls-full-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.php
More file actions
120 lines (109 loc) · 3.58 KB
/
theme.php
File metadata and controls
120 lines (109 loc) · 3.58 KB
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
<?php
/**
* Bootstrap Theme for YOURLS
*
* @author Leo Colombaro
* @package YOURLS
*/
// Is there things to display? If so, let's add our stuff
yourls_add_action( 'init_theme', 'lc_full_bootstrap_init' );
/**
* Init Bootstrap Theme
*/
function lc_full_bootstrap_init() {
yourls_add_filter( 'template_content', 'lc_full_bootstrap_template' );
lc_full_bootstrap_add_css();
yourls_add_filter( 'admin_menu_start', 'lc_full_bootstrap_menu_start' );
yourls_add_filter( 'admin_menu_end', 'lc_full_bootstrap_menu_end' );
yourls_add_filter( 'logout_link', 'lc_full_bootstrap_logout_link' );
}
/**
* Rewrite template
*
* @param array $elements Default template
* @return array New structure
*/
function lc_full_bootstrap_template( $elements ) {
lc_full_bootstrap_replace_in_array( $elements, 'yourls_sidebar_start', 'lc_full_bootstrap_nav_start' );
lc_full_bootstrap_remove_from_array( $elements, 'yourls_html_global_stats' );
lc_full_bootstrap_remove_from_array( $elements, 'yourls_html_footer' );
lc_full_bootstrap_replace_in_array( $elements, 'yourls_sidebar_end', 'lc_full_bootstrap_nav_end' );
return $elements;
}
/**
* Add required Styles
*/
function lc_full_bootstrap_add_css() {
yourls_enqueue_style( 'lc_full_bootstrap_css', yourls_get_active_theme_url() . '/css/bootstrap.min.css' );
}
/**
* Rewrite Nav begining
*/
function lc_full_bootstrap_nav_start() {
echo '<header class="navbar navbar-inverse navbar-fixed-top" role="banner"><div class="container">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>';
}
/**
* Rewrite Nav ending
*/
function lc_full_bootstrap_nav_end() {
echo '</div></header>';
}
/**
* Rewrite admin-menu begining
*/
function lc_full_bootstrap_menu_start( $menu ) {
return '<nav class="collapse navbar-collapse navbar-ex1-collapse" role="navigation"><ul class="nav navbar-nav">';
}
/**
* Rewrite admin-menu ending
*/
function lc_full_bootstrap_menu_end( $menu ) {
return '</ul>' . lc_full_bootstrap_logout_link( '', true ) . '</nav>' ;
}
/**
* Rewrite logout link
*
* @param string $link Default element
* @param string $show Allow muting
* @return string Logout element (HTML)
*/
function lc_full_bootstrap_logout_link( $link, $show = false ) {
if( $show && yourls_is_private() && defined( 'YOURLS_USER' ) ) {
return '<div class="navbar-right"><p class="navbar-text">' . sprintf( yourls__( 'Hello <strong>%s</strong>' ), YOURLS_USER ) . '</p><a href="?action=logout" title="' . yourls_esc_attr__( 'Logout' ) . '" class="btn btn-default navbar-btn"><i class="icon-signout"></i> ' . yourls__( 'Logout' ) . '</a></div>';
} else
return '';
}
/**
* Helper unction to remove an element, based on its value, from a multidimensional array
*/
function lc_full_bootstrap_remove_from_array( &$array, $remove ) {
foreach( $array as $key => &$value ) {
if( is_array( $value ) ) {
lc_full_bootstrap_remove_from_array( $value, $remove );
} else {
if( $remove == $value ) {
unset( $array[ $key ] );
}
}
}
}
/**
* Helper function to replace an element, based on its value, by another one, inside a multidimensional array
*/
function lc_full_bootstrap_replace_in_array( &$array, $replace, $with ) {
foreach( $array as $key => &$value ) {
if( is_array( $value ) ) {
lc_full_bootstrap_replace_in_array( $value, $replace, $with );
} else {
if( $replace == $value ) {
$array[ $key ] = $with;
}
}
}
}