null,
'id' => null,
'height' => get_option('documentcloud_default_height', 600),
'width' => get_option('documentcloud_default_width', 620),
'format' => 'normal',
'sidebar' => 'false',
'text' => 'true',
'pdf' => 'true'
);
}
function add_options_page() {
add_options_page('DocumentCloud', 'DocumentCloud', 'manage_options',
'documentcloud', array(&$this, 'render_options_page'));
}
function render_options_page() { ?>
DocumentCloud Options
";
}
function default_width_field() {
$option = intval(get_option( 'documentcloud_default_width', 620 ));
echo "";
}
function full_width_field() {
$option = intval(get_option( 'documentcloud_full_width', 620 ));
echo "";
}
function settings_section() {}
function save($post_id) {
// tell the post if we're carrying a wide load
$post = get_post($post_id);
// avoid autosave
if ( !in_array( $post->post_status, array(
'publish', 'draft', 'private', 'future', 'pending'
))
) { return; }
$defaults = $this->get_defaults();
$wide_assets = get_post_meta($post_id, 'wide_assets', true);
$documents = get_post_meta($post_id, 'documentcloud', true);
$matches = array();
preg_match_all('/'.get_shortcode_regex().'/', $post->post_content, $matches);
$tags = $matches[2];
$args = $matches[3];
foreach($tags as $i => $tag) {
if ($tag == "documentcloud") {
$atts = shortcode_parse_atts($args[$i]);
$atts = shortcode_atts($defaults, $atts);
// get a doc id to keep array keys consistent
if ( isset($atts['url']) && !isset($atts['id']) ) {
$atts['id'] = $this->parse_id_from_url($atts['url']);
}
// if no id, don't bother storing because it's wrong
if ($atts['id'] != null) {
if ( $atts['format'] == "wide" || $atts['width'] > $defaults['width']) {
$wide_assets[$atts['id']] = true;
} else {
$wide_assets[$atts['id']] = false;
}
$documents[$atts['id']] = $atts;
}
}
}
update_post_meta($post_id, 'documents', $documents);
update_post_meta($post_id, 'wide_assets', $wide_assets);
}
function parse_id_from_url($url) {
$regex = '{^https://www\.documentcloud\.org/documents/(?P.+)\.html}';
$matches = array();
if (preg_match($regex, $url, $matches)) {
return $matches['id'];
} else {
return null;
}
}
function embed_shortcode($atts, $content, $code) {
global $post;
$defaults = $this->get_defaults();
extract( shortcode_atts($defaults, $atts));
// we need a document ID or URL, or it's a no op
if ($url && !$id) {
// parse id from url
$id = $this->parse_id_from_url($url);
}
// still no id? nothin doing
if (!$id) return;
# we only deal with integers
$height = intval($height);
$width = intval($width);
if ($format == "wide") {
$width = get_option('documentcloud_full_width', 940);
}
$is_wide = $width > $defaults['width'];
// full control in single templates
if (is_single()) {
return "
";
} else {
// index view is always normal width, no sidebar
return "
";
}
}
}
new Navis_DocumentCloud;