forked from pressbooks/pressbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
172 lines (130 loc) · 3.2 KB
/
functions.php
File metadata and controls
172 lines (130 loc) · 3.2 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
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
<?php
/**
* Shortcuts for template designers who don't use real namespaces, and other helper functions.
*
* @author PressBooks <code@pressbooks.org>
* @license GPLv2 (or any later version)
*/
/**
* Shortcut to \PressBooks\Book::get( 'prev' );
*
* @return string URL of previous post
*/
function pb_get_prev() {
return \PressBooks\Book::get( 'prev' );
}
/**
* Shortcut to \PressBooks\Book::get( 'next' );
*
* @return string URL of next post
*/
function pb_get_next() {
return \PressBooks\Book::get( 'next' );
}
/**
* Shortcut to \PressBooks\Book::get( 'first' );
*
* @return string URL of first post
*/
function pb_get_first() {
return \PressBooks\Book::get( 'first' );
}
/**
* Shortcut to \PressBooks\Book::getBookInformation();
*
* @return array
*/
function pb_get_book_information() {
return \PressBooks\Book::getBookInformation();
}
/**
* Shortcut to \PressBooks\Book::getBookStructure();
*
* @return array
*/
function pb_get_book_structure() {
return \PressBooks\Book::getBookStructure();
}
/**
* Shortcut to \PressBooks\Sanitize\decode();
*
* @param $val
*
* @return mixed
*/
function pb_decode( $val ) {
return \PressBooks\Sanitize\decode( $val );
}
/**
* Shortcut to \PressBooks\CustomCss::isCustomCss();
*
* @return bool
*/
function pb_is_custom_theme() {
return \PressBooks\CustomCss::isCustomCss();
}
/**
* Get url to the custom stylesheet for web.
*
* @see: \PressBooks\CustomCss
* @return string
*/
function pb_get_custom_stylesheet_url() {
$current_blog_id = get_current_blog_id();
if ( is_file( WP_CONTENT_DIR . "/blogs.dir/{$current_blog_id}/files/custom-css/web.css" ) ) {
return WP_CONTENT_URL . "/blogs.dir/{$current_blog_id}/files/custom-css/web.css";
} elseif ( is_file( WP_CONTENT_DIR . "/uploads/sites/{$current_blog_id}/custom-css/web.css" ) ) {
return WP_CONTENT_URL . "/uploads/sites/{$current_blog_id}/custom-css/web.css";
} else {
return PB_PLUGIN_URL . "themes-book/pressbooks-custom-css/style.css";
}
}
/**
* Get path to hyphenation dictionary in a book's language.
*
* @return bool|string
*/
function pb_get_hyphens_path() {
$loc = false;
$compare_with = scandir( PB_PLUGIN_DIR . '/symbionts/dictionaries/' );
$book_lang = \PressBooks\Book::getBookInformation();
$book_lang = @$book_lang['pb_language'];
foreach ( $compare_with as $compare ) {
if ( strpos( $compare, 'hyph_' ) !== 0 ) continue; // Skip
$c = str_replace( 'hyph_', '', $compare );
list( $check_me ) = explode( '_', $c );
// We only care about the first two letters
if ( strpos( $book_lang, $check_me ) === 0 ) {
$loc = $compare;
break;
}
}
if ( $loc ) {
$loc = PB_PLUGIN_DIR . "symbionts/dictionaries/$loc";
}
return $loc;
}
/**
* Get "real" chapter number
*
* @param $post_name
*
* @return int
*/
function pb_get_chapter_number( $post_name ) {
$options = get_option( 'pressbooks_theme_options_global' );
if ( ! @$options['chapter_numbers'] )
return 0;
$lookup = \PressBooks\Book::getBookStructure();
$lookup = $lookup['__export_lookup'];
if ( 'chapter' != @$lookup[$post_name] )
return 0;
$i = 0;
foreach ( $lookup as $key => $val ) {
if ( 'chapter' == $val ) {
++$i;
if ( $key == $post_name ) break;
}
}
return $i;
}