-
Notifications
You must be signed in to change notification settings - Fork 1
/
glossario.php
212 lines (199 loc) · 7.2 KB
/
glossario.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
<?php
/*
* Plugin Name: Glossario
* Plugin URI: http://github.com/wpbrasil/glossario
* Description: A glossary for managing terms in collaborative translations
* Version: 0.01
* Author: Brazilian and Portuguese WordPress Communities
* Author URI: http://github.com/wpbrasil/glossario
*/
include( dirname( __FILE__ ) . '/glossario-metabox.php' );
class Glossario {
public static $slug = 'glossario';
var $post_term = 'glossario_term';
var $post_po_file = 'glossario_po_file';
var $tax_language = 'glossario_term_language';
var $tax_class = 'glossario_term_class';
var $tax_status = 'glossario_term_status';
function Glossario() {
add_action( 'init', array( $this, 'init' ) );
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
}
function activate() {
// @TODO: write plugin data if not exists
}
function deactivate() {
// @TODO: flush plugin data
}
function uninstall() {
// @TODO: remove plugin data
}
function init() {
$this->register_custom_post_types();
$this->register_custom_taxonomies();
}
/**
* Add Glossary term info meta box
*/
function add_meta_boxes() {
$meta_box = array(
'id' => Glossario::$slug . '_term_info',
'title' => __( 'Glossary term info', 'glossario' ),
'post_types' => array( $this->post_term ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'type' => 'text',
'id' => Glossario::$slug . '_original_term_singular',
'name' => __( 'Original term singular', 'glossario' ),
'desc' => __( 'Non-translated term in its singular form.', 'glossario' ),
'std' => ''
), array(
'type' => 'text',
'id' => Glossario::$slug . '_original_term_plural',
'name' => __( 'Original term plural', 'glossario' ),
'desc' => __( 'Non-translated term in its plural form.', 'glossario' ),
'std' => ''
), array(
'type' => 'text',
'id' => Glossario::$slug . '_term_singular',
'name' => __( 'Singular translation', 'glossario' ),
'desc' => __( 'Translated term in its singular form.', 'glossario' ),
'std' => ''
), array(
'type' => 'text',
'id' => Glossario::$slug . '_term_plural',
'name' => __( 'Plural translation', 'glossario' ),
'desc' => __( 'Translated term in its plural form.', 'glossario' ),
'std' => ''
), array(
'type' => 'textarea',
'id' => Glossario::$slug . '_translation_notes',
'name' => __( 'Translation notes', 'glossario' ),
'desc' => __( 'Optional notes or explanation about the translation above.' ),
'std' => '',
),
),
);
new Glossario_Metabox( $meta_box );
}
function register_custom_post_types() {
$post_types = array(
$this->post_term => array(
'labels' => array(
'name' => __( 'Glossary', 'glossario' ),
'singular_name' => __( 'Glossary', 'glossario' ),
'add_new' => __( 'Add new glossary term', 'glossario' ),
'add_new_item' => __( 'Add new glossary term', 'glossario' ),
'edit_item' => __( 'Edit glossary term', 'glossario' ),
'view_item' => __( 'View glossary term', 'glossario' ),
'search_items' => __( 'Search for glossary terms', 'glossario' ),
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'rewrite' => array(
'slug' => 'glossario/term',
'with_front' => false
),
'has_archive' => true,
'menu_position' => null,
'supports' => array( 'comments' )
),
$this->post_po_file => array(
'labels' => array(
'name' => __( 'PO files', 'glossario' ),
'singular_name' => __( 'PO file', 'glossario' ),
'menu_name' => __( 'PO files', 'glossario' ),
'add_new' => __( 'Add new PO file', 'glossario' ),
'add_new_item' => __( 'Add new PO file', 'glossario' ),
'edit_item' => __( 'Edit PO file', 'glossario' ),
'view_item' => __( 'View PO file', 'glossario' ),
'search_items' => __( 'Search for PO files', 'glossario' ),
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=' . $this->post_term,
'rewrite' => array(
'slug' => 'glossario/po-file',
'with_front' => false,
),
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'comments' )
)
);
foreach ( $post_types as $type => $args ) {
register_post_type( $type, $args );
}
}
function register_custom_taxonomies() {
$taxonomies = array(
$this->tax_language => array(
'object_types' => array( 'glossario_term', 'glossario_po_file' ),
'labels' => array(
'name' => __( 'Glossary languages', 'glossario' ),
'singular_name' => __( 'Glossary language', 'glossario' ),
'all_items' => __( 'All glossary languages', 'glossario' ),
'edit_item' => __( 'Edit glossary language', 'glossario' ),
'view_item' => __( 'View glossary language', 'glossario' ),
'update_item' => __( 'Update glossary language', 'glossario' ),
'add_new_item' => __( 'Add new glossary language', 'glossario' ),
'new_item_name' => __( 'New glossary language', 'glossario' ),
),
'hierarchical' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'glossario/language' ),
),
$this->tax_class => array(
'object_types' => array( 'glossario_term' ),
'labels' => array(
'name' => __( 'Morphology classes', 'glossario' ),
'singular_name' => __( 'Morphology class', 'glossario' ),
'all_items' => __( 'All morphology classes', 'glossario' ),
'edit_item' => __( 'Edit morphology class', 'glossario' ),
'view_item' => __( 'View morphology class', 'glossario' ),
'update_item' => __( 'Update morphology class', 'glossario' ),
'add_new_item' => __( 'Add new morphology class', 'glossario' ),
'new_item_name' => __( 'New morphology class', 'glossario' ),
),
'hierarchical' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'glossario/class' ),
),
$this->tax_status => array(
'object_types' => array( 'glossario_term' ),
'labels' => array(
'name' => __( 'Translation status', 'glossario' ),
'singular_name' => __( 'Translation status', 'glossario' ),
'all_items' => __( 'All glossary term status', 'glossario' ),
'edit_item' => __( 'Edit glossary term status', 'glossario' ),
'view_item' => __( 'View glossary term status', 'glossario' ),
'update_item' => __( 'Update glossary term status', 'glossario' ),
'add_new_item' => __( 'Add new glossary term status', 'glossario' ),
'new_item_name' => __( 'New glossary term status', 'glossario' ),
),
'hierarchical' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'glossario/status' ),
),
);
foreach ( $taxonomies as $taxonomy => $args ) {
register_taxonomy( $taxonomy, $args['object_types'], $args );
}
}
}
function better_front_page_ui_init() {
new Glossario();
}
add_action( 'plugins_loaded', 'better_front_page_ui_init' );
register_activation_hook( __FILE__, array( 'Glossario', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'Glossario', 'deactivate' ) );
register_uninstall_hook( __FILE__, array( 'Glossario', 'uninstall' ) );