-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpmb-design-easy.php
134 lines (130 loc) · 5.99 KB
/
pmb-design-easy.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
<?php
/*
Plugin Name: Print My Blog - Sample Easy Design
Plugin URI: https://github.com/mnelson4/pmb-sample-design-easy
Description: A simple example design that does not support dividing projects into parts or front and back matter.
Works with PMB 3.21.0 and higher.
Author: Mike Nelson
Version: 1.1.0
Author URI: https://printmy.blog
*/
use PrintMyBlog\entities\DesignTemplate;
use PrintMyBlog\orm\entities\Design;
use Twine\forms\base\FormSection;
use Twine\forms\inputs\AdminFileUploaderInput;
use Twine\forms\inputs\ColorInput;
use Twine\forms\inputs\DatepickerInput;
use Twine\forms\inputs\TextAreaInput;
use Twine\forms\inputs\TextInput;
use Twine\forms\strategies\validation\TextValidation;
define('PMBE_MAIN_FILE', __FILE__);
define('PMBE_MAIN_DIR', __DIR__);
add_action( 'pmb_register_designs', 'pmbe_register_design', 1 );
register_activation_hook(PMBE_MAIN_FILE,'pmbe_activation');
/**
* Called when this plugin is activated, and gets PMB to check this design exists in the database (and if not, adds it)
*/
function pmbe_activation(){
pmbe_register_design();
pmb_check_db();
}
/**
* Registers the design and design template. This should be done on every request so PMB knows they exist.
*/
function pmbe_register_design() {
if(! function_exists('pmb_register_design')){
return;
}
pmb_register_design_template(
'easy_template',
function () {
return [
'title' => __('Easy Digital PDF'),
'format' => 'digital_pdf',
'dir' => PMBE_MAIN_DIR . '/design/',
'default' => 'easy',
'url' => plugins_url('design/', PMBE_MAIN_FILE),
'docs' => '',
'supports' => [
],
'design_form_callback' => function () {
return (new FormSection([
'subsections' =>
[
'internal_footnote_text' => new TextInput([
'html_label_text' => __('Internal Footnote Text', 'print-my-blog'),
'html_help_text' => __('Text to use when replacing a hyperlink with a footnote. "%s" will be replaced with the page number.', 'print-my-blog'),
'default' => __('See page %s.', 'print-my-blog'),
'validation_strategies' => [
new TextValidation(__('You must include "%s" in the footnote text so we know where to put the URL.', 'print-my-blog'), '~.*\%s.*~')
]
]),
'footnote_text' => new TextInput([
'html_label_text' => __('External Footnote Text', 'print-my-blog'),
'html_help_text' => __('Text to use when replacing a hyperlink with a footnote. "%s" will be replaced with the URL', 'print-my-blog'),
'default' => __('See %s.', 'print-my-blog'),
'validation_strategies' => [
new TextValidation(__('You must include "%s" in the footnote text so we know where to put the URL.', 'print-my-blog'), '~.*\%s.*~')
]
])
],
]))->merge(pmb_generic_design_form());
},
'project_form_callback' => function (Design $design) {
return new FormSection([
'subsections' => [
'institution' => new TextInput(
[
'html_label_text' => __('Issue', 'print-my-blog'),
'html_help_text' => __('Text that appears at the top-right of the cover'),
]
),
'authors' => new TextAreaInput(
[
'html_label_text' => __('ByLine', 'print-my-blog'),
'html_help_text' => __('Project Author(s)', 'print-my-blog'),
]
),
'date' => new DatepickerInput([
'html_label_text' => __('Date Issued', 'print-my-blog'),
'html_help_text' => __('Text that appears under the byline', 'print-my-blog'),
]),
]
]);
}
];
}
);
pmb_register_design(
'easy_template',
'easy',
function (DesignTemplate $design_template) {
$preview_folder_url = plugins_url('/design/assets/', PMBE_MAIN_FILE);
return [
'title' => __('Easy Academic Paper', 'print-my-blog'),
'quick_description' => __('An easy design', 'print-my-blog'),
'description' => pmb_get_contents(PMBE_MAIN_DIR . '/design/description.php'),
'author' => [
'name' => 'Mike Nelson',
'url' => 'https://printmy.blog'
],
'previews' => [
[
'url' => $preview_folder_url . '/preview1.jpg',
'desc' => __('Title page, showing the double-spaced text.', 'print-my-blog')
],
[
'url' => $preview_folder_url . '/preview2.jpg',
'desc' => __('Main matter, showing smaller images and double-spaced text.', 'print-my-blog')
]
],
'design_defaults' => [
'custom_css' => ''
],
'project_defaults' => [
'institution' => 'Print My Blog'
],
];
}
);
}