This repository was archived by the owner on Apr 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
219 lines (171 loc) · 6.64 KB
/
Copy pathfunctions.php
File metadata and controls
219 lines (171 loc) · 6.64 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
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
<?php
/* WordPress Unix Theme
*
* Unix-like Interface theme for Wordpress
*
* Copyright (C) 2012 Benjamin J. Balter ( ben@balter.com -- http://ben.balter.com )
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright 2012
* @license GPL v3
* @version 1.0.8
* @author Benjamin J. Balter <ben@balter.com>
* @package wp-unix
*/
//init markdownify
require_once dirname( __FILE__ ) . '/markdownify/markdownify.php';
$markdownify = new Markdownify( null, null, false ); //last arg: don't output unparsable HTML
//this is meaningless, but we need it to pass validation, so here goes...
if ( ! isset( $content_width ) ) $content_width = 900;
add_theme_support( 'automatic-feed-links' );
/**
* Returns current version of theme
* @return int the current version number
*/
function wp_unix_version() {
return '1.0.8';
}
/**
* Verifies JSON_API is installed and active
*/
function wp_unix_json_api_check() {
if ( !class_exists( 'JSON_API') )
wp_die( 'Please install and activate the plugin JSON API prior to using this theme' );
}
add_action( 'plugins_loaded', 'wp_unix_json_api_check' );
/**
* Enqueue Javascripts
*/
function wp_unix_enqueue() {
$suffix = ( WP_DEBUG ) ? '.dev' : '';
//css
wp_enqueue_style( 'boilerplate', get_template_directory_uri() . '/boilerplate.css' );
wp_enqueue_style( 'cli', get_stylesheet_directory_uri() . '/style.css', null, wp_unix_version() );
//modernizr
wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/js/modernizr-2.5.3-respond-1.1.0.min.js', wp_unix_version(), true );
//js
wp_enqueue_script( 'jquery-hotkeys', null, array( 'jquery' ), wp_unix_version(), true );
wp_enqueue_script( 'jquery-browser', get_template_directory_uri() . '/js/jquery.browser.js', array( 'jquery' ), wp_unix_version(), true );
wp_enqueue_script( 'jquery-dateformat', get_template_directory_uri() . '/js/jquery.dateformat.js', array( 'jquery' ), wp_unix_version(), true );
wp_enqueue_script( 'cli', get_template_directory_uri() . "/js/cli{$suffix}.js", array( 'jquery' ), wp_unix_version(), true );
wp_enqueue_script( 'wp_unix', get_template_directory_uri() . "/js/wp-unix{$suffix}.js", array( 'cli', 'jquery' ), wp_unix_version(), true );
//validation...
if ( is_singular() ) wp_enqueue_script( "comment-reply" );
}
add_action ( 'wp_enqueue_scripts', 'wp_unix_enqueue' );
/**
* Returns welcome message
* @TODO make this an option
* @return string the welcome message
*/
function wp_unix_welcome_message() {
$msg = '';
$title = get_bloginfo('title');
$subtitle = get_bloginfo( 'description' );
$len = ( strlen( $title ) > strlen( $subtitle ) ) ? strlen( $title ) : strlen( $subtitle );
$title = wp_unix_center_string( $title, $len );
$subtitle = wp_unix_center_string( $subtitle, $len );
$len = $len + 4;
$msg .= str_pad( '', $len, '*' ) . "\n";
$msg .= "* $title *\n";
$msg .= "* $subtitle *\n";
$msg .= str_pad( '', $len, '*' ) . "\n";
return $msg;
}
/**
* Given a string, centers it with spaces to a given length
* @param string $str the input string
* @param int $len the string length
* @return string the centered string
*/
function wp_unix_center_string( $str, $len ) {
if ( strlen( $str ) == $len )
return $str;
//calc diff and halve
$len = $len - strlen( $str );
$len = floor( $len / 2 );
//pad
$str = str_pad( ' ', $len, ' ' ) . $str . str_pad( ' ', $len, ' ' );
//check if rounded down
if ( strlen( $str ) < $len ) $str .= ' ';
return $str;
}
/**
* Output i18n info to browser
*/
function wp_unix_i18n() {
global $current_user;
global $json_api;
require_once $json_api->controller_path( 'core' );
$pages = JSON_API_Core_Controller::get_page_index();
$pages = $pages['pages'];
load_theme_textdomain( 'wp-unix', dirname( __FILE__ ) . '/languages/' );
get_currentuserinfo();
if ( is_user_logged_in() )
$user = $current_user->user_nicename;
else
$user = __( 'anon', 'wp_unix' );
$host = get_bloginfo( 'url' );
$host = str_replace( 'http://', '', $host );
$data = array(
'prompt' => "{$user}@{$host}:/$ ",
'home' => get_bloginfo( 'url' ),
'welcome_message' => wp_unix_welcome_message(),
'error' => __( 'An error occurred', 'wp-unix' ),
'invalid_post' => __( 'Invalid post', 'wp-unix' ),
'bad_command' => __( 'Unrecognized command. Type "help" for assistance.', 'wp-unix' ),
'help' => __( 'help', 'wp-unix' ),
'post_usage' => __( 'Usage: post [postID]', 'wp-unix' ),
'posted' => 'Posted on ',
'date_format' => 'MMMM dd, yyyy',
'meta' => __( 'This entry was posted in %1$s and tagged %2$s by %3$s.', 'wp-unix' ),
'search_error' => __( 'Usage: search [search term(s)]', 'wp-unix' ),
'no_results' => __( 'No posts found' , 'wp-unix' ),
'touch_message' => __( 'Tap screen to begin...', 'wp-unix' ),
'query' => $json_api->introspector->get_posts(),
'tags' => get_terms( 'post_tag' ),
'categories' => get_terms( 'category' ),
'pages' => $pages,
'not_root' => __( 'Must be root to execute that command. Perhaps "sudo" can help?', 'wp-unix' ),
'going_down' => __( 'The system is going down for maintenance NOW!', 'wp-unix' ),
'command_not_found' => __( 'command not found', 'wp-unix' ),
'sudo_what' => __( 'sudo what?', 'wp-unix' ),
'sandwich' => __( 'make me a sandwich', 'wp-unix' ),
'broadcast_msg' => __( 'Broadcast message from %s', 'wp-unix' ),
);
wp_localize_script( 'cli', 'wp_unix_i18n', $data );
}
add_action( 'wp_enqueue_scripts', 'wp_unix_i18n' );
/**
* Converts HTML pages to markdown
* @param return string the content (plain text)
* @param string $content the content (HTML)
* @return unknown
*/
function wp_unix_markdownify( $content ) {
global $markdownify;
return $markdownify->parseString( $content );
}
add_filter( 'the_content', 'wp_unix_markdownify', 100, 1 );
/**
* Remove jetpack sharing links from posts
* @param unknown $content
* @return unknown
*/
function wp_unix_no_sharing( $content ) {
remove_filter( 'the_content', 'sharing_display', 19 );
return $content;
}
add_action( 'the_content', 'wp_unix_no_sharing', 1 );