function anno_media_upload_form()
{
    if (!anno_current_user_can_edit()) {
        echo '<div style="text-align:center;">' . _x('You do not have proper permissions to upload a new image', 'Permissions warning for image uplaod', 'anno') . '</div>';
        return;
    }
    global $type, $tab, $pagenow;
    $flash_action_url = admin_url('async-upload.php');
    // If Mac and mod_security, no Flash. :(
    $flash = true;
    if (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'mac') && apache_mod_loaded('mod_security')) {
        $flash = false;
    }
    $flash = apply_filters('flash_uploader', $flash);
    $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
    $upload_size_unit = $max_upload_size = wp_max_upload_size();
    $sizes = array('KB', 'MB', 'GB');
    for ($u = -1; $upload_size_unit > 1024 && $u < count($sizes) - 1; $u++) {
        $upload_size_unit /= 1024;
    }
    if ($u < 0) {
        $upload_size_unit = 0;
        $u = 0;
    } else {
        $upload_size_unit = (int) $upload_size_unit;
    }
    ?>
	<script type="text/javascript">
	//<![CDATA[
	var uploaderMode = 0;
	jQuery(document).ready(function($){
		uploaderMode = getUserSetting('uploader');
		$('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});
		$('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});
	});
	//]]>
	</script>
	<div id="media-upload-notice">
	<?php 
    if (isset($errors['upload_notice'])) {
        ?>
		<?php 
        echo $errors['upload_notice'];
        ?>
	<?php 
    }
    ?>
	</div>
	<div id="media-upload-error">
	<?php 
    if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) {
        ?>
		<?php 
        echo $errors['upload_error']->get_error_message();
        ?>
	<?php 
    }
    ?>
	</div>
	<?php 
    // Check quota for this blog if multisite
    if (is_multisite() && !is_upload_space_available()) {
        echo '<p>' . sprintf(_x('Sorry, you have filled your storage quota (%s MB).', 'Media upload error text', 'anno'), get_space_allowed()) . '</p>';
        return;
    }
    do_action('pre-upload-ui');
    if ($flash) {
        // Set the post params, which SWFUpload will post back with the file, and pass
        // them through a filter.
        $post_params = array('post_id' => anno_get_post_id(), 'auth_cookie' => is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE], 'logged_in_cookie' => $_COOKIE[LOGGED_IN_COOKIE], '_wpnonce' => wp_create_nonce('media-form'), 'type' => $type, 'tab' => $tab, 'short' => '1', 'action' => 'tinymce_upload');
        $post_params = apply_filters('swfupload_post_params', $post_params);
        $p = array();
        foreach ($post_params as $param => $val) {
            $p[] = "\t\t'{$param}' : '{$val}'";
        }
        $post_params_str = implode(", \n", $p);
        // #8545. wmode=transparent cannot be used with SWFUpload
        if ('media-new.php' == $pagenow) {
            $upload_image_path = get_user_option('admin_color');
            if ('classic' != $upload_image_path) {
                $upload_image_path = 'fresh';
            }
            $upload_image_path = admin_url('images/upload-' . $upload_image_path . '.png?ver=20101205');
        } else {
            $upload_image_path = includes_url('images/upload.png?ver=20100531');
        }
        ?>
	<script type="text/javascript">
	//<![CDATA[
	var swfu;
	SWFUpload.onload = function() {
		var settings = {
				button_text: '<span class="button"><?php 
        _ex('Select Files', 'Media upload text', 'anno');
        ?>
<\/span>',
				button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; font-size: 11px; text-shadow: 0 1px 0 #FFFFFF; color:#464646;}',
				button_height: "23",
				button_width: "132",
				button_text_top_padding: 3,
				button_image_url: '<?php 
        echo $upload_image_path;
        ?>
',
				button_placeholder_id: "flash-browse-button",
				upload_url : "<?php 
        echo esc_attr($flash_action_url);
        ?>
",
				flash_url : "<?php 
        echo includes_url('js/swfupload/swfupload.swf');
        ?>
",
				file_post_name: "async-upload",
				post_params : {
					<?php 
        echo $post_params_str;
        ?>
				},
				file_size_limit : "<?php 
        echo $max_upload_size;
        ?>
b",
				file_dialog_start_handler : fileDialogStart,
				file_queued_handler : annoFileQueued,
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : <?php 
        echo apply_filters('swfupload_success_handler', 'uploadSuccess');
        ?>
,
				upload_complete_handler : uploadComplete,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				swfupload_pre_load_handler: swfuploadPreLoad,
				swfupload_load_failed_handler: swfuploadLoadFailed,
				custom_settings : {
					degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
					swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
				},
				file_types : "*.jpg;*.gif;*.png;*.jpeg;*.bmp;",
				debug: false
			};
			swfu = new SWFUpload(settings);
	};
	//]]>
	</script>

	<div id="flash-upload-ui" class="tinymce-uploader hide-if-no-js">
	<?php 
        do_action('pre-flash-upload-ui');
        ?>
		<div>
		<?php 
        _ex('Choose files to upload', 'Media upload dialog', 'anno');
        ?>
		<div id="flash-browse-button"></div>
		<span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php 
        _ex('Cancel Upload', 'Media cancel button text', 'anno');
        ?>
" class="button" /></span>
		</div>
	<?php 
        do_action('post-plupload-upload-ui');
        ?>
	</div>
	<?php 
    }
    // $flash
    ?>

	<div id="html-upload-ui" class="tinymce-uploader<?php 
    if ($flash) {
        echo ' hide-if-js';
    }
    ?>
">
	<?php 
    do_action('pre-html-upload-ui');
    ?>
		<p id="async-upload-wrap">
			<label class="screen-reader-text" for="async-upload"><?php 
    _ex('Upload', 'Media upload text', 'anno');
    ?>
</label>
			<input type="file" name="async-upload" id="async-upload" accept="image/gif, image/jpeg, image/jpg, image/png" />
			<?php 
    submit_button(_x('Upload', 'Media upload text', 'anno'), 'button', 'html-upload', false);
    ?>
		</p>
		<div class="clear"></div>
		<?php 
    if (is_lighttpd_before_150()) {
        ?>
		<p><?php 
        _ex('If you want to use all capabilities of the uploader, like uploading multiple files at once, please update to lighttpd 1.5.', 'Media upload error text', 'anno');
        ?>
</p>
		<?php 
    }
    ?>
	<?php 
    do_action('post-html-upload-ui', $flash);
    ?>
	</div>
	<?php 
    do_action('post-upload-ui');
    ?>
	<?php 
}
Ejemplo n.º 2
0
/**
 * Popup dialog for references in the tinyMCE
 */
function anno_popup_references()
{
    global $post;
    $references = get_post_meta($post->ID, '_anno_references', true);
    ?>
	<div id="anno-popup-references" class="anno-mce-popup">
		<div class="anno-mce-popup-fields">
			<table id="anno-references">
				<thead>
					<tr>
						<th class="reference-checkbox"></th>
						<th class="reference-text"></th>
						<th class="reference-actions"></th>
					</tr>
				</thead>
				<tbody>
<?php 
    $doi_enabled = anno_doi_lookup_enabled();
    if (!empty($references) && is_array($references)) {
        foreach ($references as $reference_key => $reference) {
            //prevent undefined index errors;
            $reference_keys = array('text', 'doi', 'pmid', 'url', 'figures');
            foreach ($reference_keys as $key_val) {
                $reference[$key_val] = isset($reference[$key_val]) ? $reference[$key_val] : '';
            }
            anno_popup_reference_row($reference_key, $reference, $post->ID, $doi_enabled);
        }
    }
    if (anno_current_user_can_edit()) {
        ?>
					<tr id="<?php 
        echo esc_attr('reference-new');
        ?>
">
						<td colspan="3">
							<?php 
        anno_popup_references_row_edit('new', array('text' => '', 'doi' => '', 'pmid' => '', 'url' => '', 'figures' => ''), $post->ID, $doi_enabled);
        ?>
						</td>
					<tr>
						<td colspan="3" class="anno-mce-popup-footer">
							<?php 
        _anno_popup_submit_button('anno-references-new', _x('New Reference', 'button value', 'anno'));
        ?>
						</td>
					</tr>
<?php 
    }
    ?>
				</tbody>
			</table>
		</div>
		<div class="anno-mce-popup-footer">
			<?php 
    _anno_popup_submit_button('anno-references-submit', _x('Insert Reference(s)', 'button value', 'anno'));
    ?>
		</div>
	</div>
<?php 
}
function anno_popup_images_row_edit($attachment)
{
    $img_url = wp_get_attachment_image_src($attachment->ID, 'anno_img_edit');
    $description = $attachment->post_content;
    $caption = $attachment->post_excerpt;
    $alt_text = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
    $display = get_post_meta($attachment->ID, '_anno_attachment_image_display', true);
    if (empty($display)) {
        $display = 'figure';
    }
    //@TODO worth storing all this data in a single meta row as a serialized array
    $label = get_post_meta($attachment->ID, '_anno_attachment_image_label', true);
    $copyright_statement = get_post_meta($attachment->ID, '_anno_attachment_image_copyright_statement', true);
    $copyright_holder = get_post_meta($attachment->ID, '_anno_attachment_image_copyright_holder', true);
    $license = get_post_meta($attachment->ID, '_anno_attachment_image_license', true);
    $url = get_post_meta($attachment->ID, '_anno_attachment_image_url', true);
    $file_url = wp_get_attachment_url($attachment->ID);
    $link = get_attachment_link($attachment->ID);
    $img_size = get_post_meta($attachment->ID, '_anno_attachment_image_size', true);
    if (!$img_size) {
        $img_size = 'thumbnail';
    }
    ?>
			<tr>
				<td class="img-edit-td" colspan="3">
					<form id="<?php 
    echo esc_attr('img-edit-' . $attachment->ID);
    ?>
" class="anno-img-edit">
						<div class="img-edit-details">
							<img src="<?php 
    echo esc_url($img_url[0]);
    ?>
" alt="<?php 
    echo esc_attr($attachment->post_title);
    ?>
" class="img-list-img" />
							<label for="<?php 
    echo esc_attr('img-alttext-' . $attachment->ID);
    ?>
">
								<div><?php 
    _ex('Alt Text', 'input label', 'anno');
    ?>
</div>
								<input name="alt_text" type="text" id="<?php 
    echo esc_attr('img-alttext-' . $attachment->ID);
    ?>
" value="<?php 
    echo esc_attr($alt_text);
    ?>
" />
							</label>
							<label for="<?php 
    echo esc_attr('img-description-' . $attachment->ID);
    ?>
">
								<div><?php 
    _ex('Description', 'input label', 'anno');
    ?>
</div>
								<textarea name="description" id="<?php 
    echo esc_attr('img-description-' . $attachment->ID);
    ?>
"><?php 
    echo esc_textarea($description);
    ?>
</textarea>
							</label>
						</div>
<?php 
    /*						@TODO Find a way to maintain wrapping URL data while adhering to DTD
    						<div class="img-url-input">
    							<label for="<?php echo esc_attr('img-url-'.$attachment->ID); ?>">
    								<input id="<?php echo esc_attr('img-url-'.$attachment->ID); ?>" type="text" name="url" value="<?php echo esc_attr($url); ?>" /><span><?php _e('URL', 'anno'); ?></span>
    							</label>
    							<div id="<?php echo esc_attr('img-url-buttons-'.$attachment->ID); ?>" class="img-url-buttons">
    								<button type="button" class="button" title=""><?php _e('None', 'anno'); ?></button>
    								<button type="button" class="button" title="<?php echo esc_attr($file_url); ?>"> <?php _e('File URL', 'anno'); ?></button>
    								<button type="button" class="button" title="<?php echo esc_attr($link); ?>"><?php _e('Attachment Post URL', 'anno'); ?></button>
    							</div>
    						</div>
    */
    ?>
						<fieldset class="img-display">
							<legend><?php 
    _ex('Display', 'legend', 'anno');
    ?>
</legend>
							<label for="<?php 
    echo esc_attr('img-display-figure-' . $attachment->ID);
    ?>
" class="radio">
								<input type="radio" value="figure" name="display" class="img-display-selection img-display-figure" id="<?php 
    echo esc_attr('img-display-figure-' . $attachment->ID);
    ?>
"<?php 
    checked($display, 'figure', true);
    ?>
 />
								<span><?php 
    _ex('Display as Figure', 'input label', 'anno');
    ?>
</span>
							</label>
							<label for="<?php 
    echo esc_attr('img-display-inline-' . $attachment->ID);
    ?>
" class="radio">
								<input type="radio" value="inline" name="display" class="img-display-selection img-display-inline" id="<?php 
    echo esc_attr('img-display-inline-' . $attachment->ID);
    ?>
"<?php 
    checked($display, 'inline', true);
    ?>
 />
								<span><?php 
    _ex('Display Inline', 'input label', 'anno');
    ?>
</span>
							</label>
							<div id="<?php 
    echo esc_attr('img-figure-details-' . $attachment->ID);
    ?>
">
								<label for="<?php 
    echo esc_attr('img-label-' . $attachment->ID);
    ?>
">
									<span><?php 
    _ex('Label', 'input label', 'anno');
    ?>
</span>
									<input type="text" name="label" id="<?php 
    echo esc_attr('img-label-' . $attachment->ID);
    ?>
" value="<?php 
    echo esc_attr($label);
    ?>
" />
								</label>
								<label for="<?php 
    echo esc_attr('img-caption-' . $attachment->ID);
    ?>
">
									<span><?php 
    _ex('Caption', 'input label', 'anno');
    ?>
</span>
									<textarea id="<?php 
    echo esc_attr('img-caption-' . $attachment->ID);
    ?>
" name="caption"><?php 
    echo esc_textarea($caption);
    ?>
</textarea>
								</label>
							</div>
						</fieldset>
						<fieldset>
							<legend><?php 
    _ex('Permissions', 'legend', 'anno');
    ?>
</legend>
							<label for="<?php 
    echo esc_attr('img-copystatement-' . $attachment->ID);
    ?>
">
								<span><?php 
    _ex('Copyright Statement', 'input label', 'anno');
    ?>
</span>
								<input type="text" name="copyright_statement" id="<?php 
    echo esc_attr('img-copystatement-' . $attachment->ID);
    ?>
" value="<?php 
    echo esc_attr($copyright_statement);
    ?>
" />
							</label>
							<label for="<?php 
    echo esc_attr('img-copyholder-' . $attachment->ID);
    ?>
">
								<span><?php 
    _ex('Copyright Holder', 'input label', 'anno');
    ?>
</span>
								<input type="text" name="copyright_holder" id="<?php 
    echo esc_attr('img-copyholder-' . $attachment->ID);
    ?>
" value="<?php 
    echo esc_attr($copyright_holder);
    ?>
" />
							</label>
							<label for="<?php 
    echo esc_attr('img-license-' . $attachment->ID);
    ?>
">
								<span><?php 
    _ex('License', 'input label', 'anno');
    ?>
</span>
								<input type="text" name="license" id="<?php 
    echo esc_attr('img-license-' . $attachment->ID);
    ?>
" value="<?php 
    echo esc_attr($license);
    ?>
" />
							</label>
						</fieldset>
						<fieldset class="img-sizes">
							<legend><?php 
    _ex('Size', 'legend for image size', 'anno');
    ?>
</legend>
							<?php 
    $sizes = array('thumbnail' => _x('Thumbnail', 'size label for images', 'anno'), 'medium' => _x('Medium', 'size label for images', 'anno'), 'large' => _x('Large', 'size label for images', 'anno'));
    // For small images, we won't have any image sizes displayed.
    $size_displayed = false;
    foreach ($sizes as $size_key => $size_label) {
        $downsize = image_downsize($attachment->ID, $size_key);
        $enabled = $downsize[3];
        if ($enabled) {
            $img_size_url = wp_get_attachment_image_src($attachment->ID, $size_key);
            $img_size_url = $img_size_url[0];
            $size_displayed = true;
        } else {
            $img_size_url = '';
        }
        if (!empty($img_size_url)) {
            ?>
									<label for="<?php 
            echo esc_attr('img-size-' . $size_key . '-' . $attachment->ID);
            ?>
">
										<input type="radio" name="size" id="<?php 
            echo esc_attr('img-size-' . $size_key . '-' . $attachment->ID);
            ?>
" value="<?php 
            echo esc_attr($size_key);
            ?>
" data-url="<?php 
            echo esc_attr($img_size_url);
            ?>
"<?php 
            checked($size_key, $img_size, true);
            ?>
/> <?php 
            echo esc_html($size_label);
            ?>
									</label>
<?php 
        }
    }
    // No size data displayed because the original image was too small
    if (!$size_displayed) {
        $img_size_url = wp_get_attachment_image_src($attachment->ID, 'full');
        $img_size_url = $img_size_url[0];
        if ($img_size_url) {
            ?>
										
										<label for="<?php 
            echo esc_attr('img-size-full-' . $attachment->ID);
            ?>
">
											<input type="radio" name="size" id="<?php 
            echo esc_attr('img-size-full-' . $attachment->ID);
            ?>
" value="full" data-url="<?php 
            echo esc_attr($img_size_url);
            ?>
"<?php 
            checked(true, true, true);
            ?>
 /> <?php 
            _ex('Full', 'size label for images', 'anno');
            ?>
										</label>
<?php 
        }
    }
    ?>
						</fieldset>
<?php 
    if (anno_current_user_can_edit()) {
        ?>
						<div class="anno-mce-popup-footer">
							<?php 
        _anno_popup_submit_button('anno-image-save', _x('Save', 'button value', 'anno'), 'submit');
        ?>
							<input type="button" id="<?php 
        echo esc_attr('anno-image-insert-' . $attachment->ID);
        ?>
" class="anno-image-insert button" value="<?php 
        _ex('Insert', 'button value', 'anno');
        ?>
" />
							<input type="hidden" name="action" value="anno-img-save" />
							<input type="hidden" name="attachment_id" value="<?php 
        echo esc_attr($attachment->ID);
        ?>
" />
						</div>
<?php 
    }
    ?>
						
					</form>
				</td>
			</tr>
<?php 
}