@@ -51,7 +51,7 @@ function __construct() {
51
51
// add_shortcode('documentcloud', array(&$this, 'embed_shortcode'));
52
52
53
53
// Store metadata upon post save
54
- // add_action('save_post', array(&$this, 'save'));
54
+ add_action ('save_post ' , array (&$ this , 'save ' ));
55
55
}
56
56
57
57
function register_dc_oembed_provider () {
@@ -190,21 +190,8 @@ function register_button($buttons) {
190
190
return $ buttons ;
191
191
}
192
192
193
- function get_defaults () {
194
- // add admin options to adjust these defaults
195
- // storing js params as strings instead of real booleans
196
- return array (
197
- 'url ' => null ,
198
- 'id ' => null ,
199
- 'height ' => get_option ('documentcloud_default_height ' , 600 ),
200
- 'width ' => get_option ('documentcloud_default_width ' , 620 ),
201
- 'format ' => 'normal ' ,
202
- 'sidebar ' => 'false ' ,
203
- 'text ' => 'true ' ,
204
- 'pdf ' => 'true '
205
- );
206
- }
207
-
193
+ // Setup settings for plugin
194
+
208
195
function add_options_page () {
209
196
add_options_page ('DocumentCloud ' , 'DocumentCloud ' , 'manage_options ' ,
210
197
'documentcloud ' , array (&$ this , 'render_options_page ' ));
@@ -257,8 +244,6 @@ function full_width_field() {
257
244
258
245
function settings_section () {}
259
246
260
- // Hopefully can remove from here down?
261
-
262
247
function save ($ post_id ) {
263
248
// tell the post if we're carrying a wide load
264
249
@@ -270,7 +255,7 @@ function save($post_id) {
270
255
))
271
256
) { return ; }
272
257
273
- $ defaults = $ this ->get_defaults ();
258
+ $ defaults = $ this ->get_default_atts ();
274
259
$ wide_assets = get_post_meta ($ post_id , 'wide_assets ' , true );
275
260
$ documents = get_post_meta ($ post_id , 'documentcloud ' , true );
276
261
$ matches = array ();
@@ -283,14 +268,20 @@ function save($post_id) {
283
268
$ atts = shortcode_parse_atts ($ args [$ i ]);
284
269
$ atts = shortcode_atts ($ defaults , $ atts );
285
270
271
+ // TODO: Reconsider using document ID as array key,
272
+ // because we'll be using this same shortcode to
273
+ // consume more than just documents in the future.
274
+ // Perhaps we can use `url` as key?
275
+
286
276
// get a doc id to keep array keys consistent
287
277
if (isset ($ atts ['url ' ]) && !isset ($ atts ['id ' ]) ) {
288
278
$ atts ['id ' ] = $ this ->parse_id_from_url ($ atts ['url ' ]);
289
279
}
290
280
291
281
// if no id, don't bother storing because it's wrong
292
282
if ($ atts ['id ' ] != null ) {
293
- if ($ atts ['format ' ] == "wide " || $ atts ['width ' ] > $ defaults ['width ' ]) {
283
+ $ width = isset ($ atts ['width ' ]) ? $ atts ['width ' ] : $ atts ['maxwidth ' ];
284
+ if ($ atts ['format ' ] == "wide " || $ width > $ defaults ['maxwidth ' ]) {
294
285
$ wide_assets [$ atts ['id ' ]] = true ;
295
286
} else {
296
287
$ wide_assets [$ atts ['id ' ]] = false ;
@@ -303,7 +294,6 @@ function save($post_id) {
303
294
}
304
295
update_post_meta ($ post_id , 'documents ' , $ documents );
305
296
update_post_meta ($ post_id , 'wide_assets ' , $ wide_assets );
306
-
307
297
}
308
298
309
299
function parse_id_from_url ($ url ) {
@@ -316,6 +306,26 @@ function parse_id_from_url($url) {
316
306
}
317
307
}
318
308
309
+ // TODO: Remove this once we've ensured `handle_dc_shortcode()`
310
+ // replicates all the functionality properly. Note that `save()`
311
+ // has been adjusted to use `get_default_atts()`, but I left
312
+ // `embed_shortcode()` using `get_defaults()` for inspection.
313
+
314
+ function get_defaults () {
315
+ // add admin options to adjust these defaults
316
+ // storing js params as strings instead of real booleans
317
+ return array (
318
+ 'url ' => null ,
319
+ 'id ' => null ,
320
+ 'height ' => get_option ('documentcloud_default_height ' , 600 ),
321
+ 'width ' => get_option ('documentcloud_default_width ' , 620 ),
322
+ 'format ' => 'normal ' ,
323
+ 'sidebar ' => 'false ' ,
324
+ 'text ' => 'true ' ,
325
+ 'pdf ' => 'true '
326
+ );
327
+ }
328
+
319
329
function embed_shortcode ($ atts , $ content , $ code ) {
320
330
global $ post ;
321
331
$ defaults = $ this ->get_defaults ();
0 commit comments