forked from chnm/anthologize
/
anthologize.php
executable file
·435 lines (336 loc) · 15.7 KB
/
anthologize.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
<?php
/*
Plugin Name: Anthologize
Plugin URI: http://anthologize.org
Description: Use the power of WordPress to transform your content into a book.
Version: 0.6.2-alpha
Author: One Week | One Tool
Author URI: http://oneweekonetool.org
*/
/*
Copyright (C) 2010 Center for History and New Media, George Mason University
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/>.
Anthologize includes TCPDF, which is released under the LGPL Use and
modifications of TDPDF must comply with its license.
*/
if ( !defined( 'ANTHOLOGIZE_VERSION' ) )
define( 'ANTHOLOGIZE_VERSION', '0.6.2' );
if ( !class_exists( 'Anthologize_Loader' ) ) :
class Anthologize_Loader {
/**
* The main Anthologize loader. Hooks our stuff into WP
*/
function anthologize_loader () {
session_start();
// If the PHP version is less than 5, print a message and stop the plugin from
// loading
if ( version_compare( phpversion(), '5', '<' ) ) {
add_action( 'admin_notices', array ( $this, 'phpversion_nag' ) );
return;
}
// Give me something to believe in
add_action( 'plugins_loaded', array ( $this, 'loaded' ) );
add_action( 'init', array ( $this, 'init' ) );
// Load the post types
add_action( 'anthologize_init', array ( $this, 'register_post_types' ) );
// Load constants
add_action( 'anthologize_init', array ( $this, 'load_constants' ) );
// Load the custom feed
add_action( 'do_feed_customfeed', array ( $this, 'register_custom_feed' ) );
// Include the necessary files
add_action( 'anthologize_loaded', array ( $this, 'includes' ) );
// Attach textdomain for localization
add_action( 'anthologize_init', array ( $this, 'textdomain' ) );
add_action( 'anthologize_init', array ( $this, 'load_template' ), 999 );
// Register the built-in export formats
add_action( 'anthologize_init', array( $this, 'default_export_formats' ) );
add_filter( 'custom_menu_order', array( $this, 'custom_menu_order_function' ) );
add_filter( 'menu_order', array( $this, 'menu_order_my_function' ) );
// activation sequence
register_activation_hook( __FILE__, array( $this, 'activation' ) );
// deactivation sequence
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
}
// Load constants
function load_constants() {
if ( !defined( 'ANTHOLOGIZE_INSTALL_PATH' ) )
define( 'ANTHOLOGIZE_INSTALL_PATH', WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'anthologize' . DIRECTORY_SEPARATOR );
if ( !defined( 'ANTHOLOGIZE_INCLUDES_PATH' ) )
define( 'ANTHOLOGIZE_INCLUDES_PATH', ANTHOLOGIZE_INSTALL_PATH . 'includes' . DIRECTORY_SEPARATOR );
if ( !defined( 'ANTHOLOGIZE_TEIDOM_PATH' ) )
define( 'ANTHOLOGIZE_TEIDOM_PATH', WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'anthologize' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'class-tei-dom.php' );
if ( !defined( 'ANTHOLOGIZE_TEIDOMAPI_PATH' ) )
define( 'ANTHOLOGIZE_TEIDOMAPI_PATH', WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'anthologize' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'class-tei-api.php' );
if ( !defined('ANTHOLOGIZE_CREATORS_ALL'))
define('ANTHOLOGIZE_CREATORS_ALL', 1);
if ( !defined('ANTHOLOGIZE_CREATORS_ASSERTED'))
define('ANTHOLOGIZE_CREATORS_ASSERTED', 2);
}
// Let plugins know that we're initializing
function init() {
do_action( 'anthologize_init' );
}
// Allow this plugin to be translated by specifying text domain
// Todo: Make the logic a bit more complex to allow for custom text within a given language
function textdomain() {
$locale = get_locale();
// First look in wp-content/anthologize-files/languages, where custom language files will not be overwritten by Anthologize upgrades. Then check the packaged language file directory.
$mofile_custom = WP_CONTENT_DIR . "/anthologize-files/languages/anthologize-$locale.mo";
$mofile_packaged = WP_PLUGIN_DIR . "/anthologize/languages/anthologize-$locale.mo";
if ( file_exists( $mofile_custom ) ) {
load_textdomain( 'anthologize', $mofile_custom );
return;
} else if ( file_exists( $mofile_packaged ) ) {
load_textdomain( 'anthologize', $mofile_packaged );
return;
}
}
// The next two functions are a hack to make WordPress hide the menu items for Parts and Library Items
function custom_menu_order_function(){
return true;
}
function menu_order_my_function( $menu_order ){
global $menu;
foreach ( $menu as $mkey => $m ) {
$key = array_search( 'edit.php?post_type=anth_part', $m, true );
$keyb = array_search( 'edit.php?post_type=anth_library_item', $m, true );
if ( $key || $keyb ) {
unset( $menu[$mkey] );
}
}
return $menu_order;
}
// Custom post types - Oh, Oh, Oh, It's Magic
function register_post_types() {
register_post_type( 'anth_project', array(
'label' => __( 'Projects', 'anthologize' ),
'exclude_from_search' => true,
'publicly_queryable' => false,
'_builtin' => false,
'show_ui' => false,
'capability_type' => 'page',
'hierarchical' => false,
'supports' => array('title', 'editor', 'revisions'),
'rewrite' => array("slug" => "project"), // Permalinks format
));
$parts_labels = array(
'name' => _x('Parts', 'post type general name'),
'singular_name' => _x('Part', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New Part'),
'edit_item' => __('Edit Part'),
'new_item' => __('New Part'),
'view_item' => __('View Part'),
'search_items' => __('Search Parts'),
'not_found' => __('No parts found'),
'not_found_in_trash' => __('No parts found in Trash'),
'parent_item_colon' => ''
);
register_post_type( 'anth_part', array(
'label' => __( 'Parts', 'anthologize' ),
'labels' => $parts_labels,
'exclude_from_search' => true,
'publicly_queryable' => false,
'_builtin' => false,
'show_ui' => true, // todo: hide
'capability_type' => 'page',
'hierarchical' => true,
'supports' => array('title'),
'rewrite' => array("slug" => "part"), // Permalinks format
));
$library_items_labels = array(
'name' => _x('Library Items', 'post type general name'),
'singular_name' => _x('Library Item', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New Library Item'),
'edit_item' => __('Edit Anthologize Library Item'),
'new_item' => __('New Anthologize Library Item'),
'view_item' => __('View Anthologize Library Item'),
'search_items' => __('Search Library Items'),
'not_found' => __('No library items found'),
'not_found_in_trash' => __('No library items found in Trash'),
'parent_item_colon' => ''
);
register_post_type( 'anth_library_item', array(
'label' => __('Library Items', 'anthologize' ),
'labels' => $library_items_labels,
'exclude_from_search' => true,
'publicly_queryable' => false,
'_builtin' => false,
'show_ui' => true,
'capability_type' => 'page',
'hierarchical' => true,
'supports' => array('title', 'editor', 'revisions', 'comments'),
'rewrite' => array("slug" => "library_item"), // Permalinks format
));
$imported_items_labels = array(
'name' => _x('Imported Items', 'post type general name'),
'singular_name' => _x('Imported Item', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New Imported Item'),
'edit_item' => __('Edit Imported Item'),
'new_item' => __('New Imported Item'),
'view_item' => __('View Imported Item'),
'search_items' => __('Search Imported Items'),
'not_found' => __('No imported items found'),
'not_found_in_trash' => __('No imported items found in Trash'),
'parent_item_colon' => ''
);
register_post_type( 'anth_imported_item', array(
'label' => __('Imported Items', 'anthologize' ),
'labels' => $imported_items_labels,
'exclude_from_search' => true,
'publicly_queryable' => false,
'_builtin' => false,
'show_ui' => true, // todo: hide
'capability_type' => 'page',
'hierarchical' => true,
'supports' => array('title', 'editor', 'revisions'),
'rewrite' => array("slug" => "imported_item"), // Permalinks format
));
}
function default_export_formats() {
// Defining the default options for export formats
$d_page_size = array(
'letter' => __( 'Letter', 'anthologize' ),
'a4' => __( 'A4', 'anthologize' )
);
$d_font_size = array(
'9' => __( '9 pt', 'anthologize' ),
'10' => __( '10 pt', 'anthologize' ),
'11' => __( '11 pt', 'anthologize' ),
'12' => __( '12 pt', 'anthologize' ),
'13' => __( '13 pt', 'anthologize' ),
'14' => __( '14 pt', 'anthologize' )
);
$d_font_face = array(
'times' => __( 'Times New Roman', 'anthologize' ),
'helvetica' => __( 'Helvetica', 'anthologize' ),
'courier' => __( 'Courier', 'anthologize' )
);
$d_font_face_pdf = array(
'times' => __( 'Times New Roman', 'anthologize' ),
'helvetica' => __( 'Helvetica', 'anthologize' ),
'courier' => __( 'Courier', 'anthologize' ),
'dejavusans' => __( 'Deja Vu Sans', 'anthologize' ),
'arialunicid0-cj' => __( 'Chinese and Japanese', 'anthologize' ),
'arialunicid0-ko' => __( 'Korean', 'anthologize' )
);
$d_font_face_epub = array(
'Times New Roman' => __( 'Times New Roman', 'anthologize' ),
'Helvetica' => __( 'Helvetica', 'anthologize' ),
'Courier' => __( 'Courier', 'anthologize' )
);
// Register PDF + options
anthologize_register_format( 'pdf', __( 'PDF', 'anthologize' ), WP_PLUGIN_DIR . '/anthologize/templates/pdf/base.php' );
anthologize_register_format_option( 'pdf', 'page-size', __( 'Page Size', 'anthologize' ), 'dropdown', $d_page_size, 'letter' );
anthologize_register_format_option( 'pdf', 'font-size', __( 'Base Font Fize', 'anthologize' ), 'dropdown', $d_font_size, '12' );
anthologize_register_format_option( 'pdf', 'font-face', __( 'Font Face', 'anthologize' ), 'dropdown', $d_font_face_pdf, 'Times New Roman' );
anthologize_register_format_option( 'pdf', 'break-parts', __( 'Page break before parts?', 'anthologize' ), 'checkbox' );
anthologize_register_format_option( 'pdf', 'break-items', __( 'Page break before items?', 'anthologize' ), 'checkbox' );
anthologize_register_format_option( 'pdf', 'colophon', __( 'Include Anthologize colophon page?', 'anthologize' ), 'checkbox' );
// Register RTF + options
anthologize_register_format( 'rtf', __( 'RTF', 'anthologize' ), WP_PLUGIN_DIR . '/anthologize/templates/rtf/base.php' );
anthologize_register_format_option( 'rtf', 'page-size', __( 'Page Size', 'anthologize' ), 'dropdown', $d_page_size, 'letter' );
anthologize_register_format_option( 'rtf', 'font-size', __( 'Base Font Fize', 'anthologize' ), 'dropdown', $d_font_size, '12' );
anthologize_register_format_option( 'rtf', 'font-face', __( 'Font Face', 'anthologize' ), 'dropdown', $d_font_face_pdf, 'Times New Roman' );
anthologize_register_format_option( 'rtf', 'break-parts', __( 'Page break before parts?', 'anthologize' ), 'checkbox' );
anthologize_register_format_option( 'rtf', 'break-items', __( 'Page break before items?', 'anthologize' ), 'checkbox' );
anthologize_register_format_option( 'rtf', 'colophon', __( 'Include Anthologize colophon page?', 'anthologize' ), 'checkbox' );
// Register ePub.
anthologize_register_format( 'epub', __( 'ePub', 'anthologize' ), WP_PLUGIN_DIR . '/anthologize/templates/epub/index.php' );
anthologize_register_format_option( 'epub', 'font-size', __( 'Base Font Fize', 'anthologize' ), 'dropdown', $d_font_size, '12' );
anthologize_register_format_option( 'epub', 'font-family', __( 'Font Family', 'anthologize' ), 'dropdown', $d_font_face_epub, 'Times New Roman' );
anthologize_register_format_option( 'epub', 'colophon', __( 'Include Anthologize colophon page?', 'anthologize' ), 'checkbox' );
//build the covers list for selection
$coversArray = array();
$coversArray['none'] = 'None';
//scan the covers directory and return the array
$filesArray = scandir(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'anthologize' .
DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'epub' . DIRECTORY_SEPARATOR . 'covers');
foreach($filesArray as $file) {
if(! is_dir($file)) {
$coversArray[$file] = $file;
}
}
anthologize_register_format_option( 'epub', 'cover', __( 'Cover Image', 'anthologize' ), 'dropdown', $coversArray);
//epub colophon commented out until we get the XSLTs working for it
//anthologize_register_format_option( 'epub', 'colophon', __( 'Include Anthologize colophon page?', 'anthologize' ), 'checkbox' );
// Register HTML
anthologize_register_format( 'html', __( 'HTML', 'anthologize' ), WP_PLUGIN_DIR . '/anthologize/templates/html/output.php' );
$htmlFontSizes = array('48pt'=>'48 pt', '36pt'=>'36 pt', '18pt'=>'18 pt', '14'=>'14 pt', '12'=>'12 pt');
anthologize_register_format_option( 'html', 'font-size', __( 'Font Size', 'anthologize' ), 'dropdown', $htmlFontSizes, '14pt' );
anthologize_register_format_option( 'html', 'download', __('Download HTML?', 'anthologize'), 'checkbox', array('Download'=>'download'), 'download');
// Register TEI. No options for this one
anthologize_register_format( 'tei', __( 'Anthologize TEI', 'anthologize' ), WP_PLUGIN_DIR . '/anthologize/templates/tei/base.php' );
}
function includes() {
if ( is_admin() ) {
require( dirname( __FILE__ ) . '/includes/class-admin-main.php' );
require( dirname( __FILE__ ) . '/includes/class-ajax-handlers.php' );
$ajax_handlers = new Anthologize_Ajax_Handlers();
}
require_once( dirname( __FILE__ ) . '/includes/class-format-api.php' );
require_once( dirname( __FILE__ ) . '/includes/functions.php' );
}
// Let plugins know that we're done loading
function loaded() {
do_action( 'anthologize_loaded' );
}
function load_template() {
global $anthologize_formats;
$return = true;
if ( isset( $_GET['anth_preview'] ) ) {
load_template( dirname(__FILE__) . '/templates/html_preview/preview.php' );
die();
}
if ( isset( $_POST['export-step'] ) ) {
if ( $_POST['export-step'] == 3 )
$return = false;
}
if ( $return )
return;
anthologize_save_project_meta();
require_once( dirname(__FILE__) . '/includes/class-export-panel.php' );
Anthologize_Export_Panel::save_session();
$type = $_SESSION['filetype'];
if ( !is_array( $anthologize_formats[$type] ) )
return;
$project_id = $_SESSION['project_id'];
load_template( $anthologize_formats[$type]['loader-path'] );
return false;
}
function activation() {
require_once( dirname( __FILE__ ) . '/includes/class-activation.php' );
$activation = new Anthologize_Activation();
}
function deactivation() {}
/**
* Prints a warning to the screen when the PHP version is insufficient
*
* Anthologize requires at least PHP version 5.0. If the currently running version of PHP is
* less than 5.0, this function will warn the user to upgrade.
*
* @package Anthologize
* @since 0.6
*/
function phpversion_nag() {
?>
<div id="message" class="updated fade">
<p style="line-height: 150%"><?php printf( __( "<strong>Anthologize will not work with your version of PHP</strong>. You are currently running PHP v%s, and Anthologize requires version 5.0 or greater. Please contact your host if you would like to use Anthologize. ", 'buddypress' ), phpversion() ) ?></p>
</div>
<?php
}
}
endif; // class exists
$anthologize_loader = new Anthologize_Loader();
?>