コード例 #1
0
ファイル: AdminBar.php プロジェクト: parsonsc/dofe
 static function AdminBar()
 {
     global $wp_admin_bar;
     WPFB_Core::PrintJS();
     $wp_admin_bar->add_menu(array('id' => WPFB, 'title' => WPFB_PLUGIN_NAME, 'href' => admin_url('admin.php?page=wpfilebase_manage')));
     $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-add-file', 'title' => __('Add File', WPFB), 'href' => admin_url('admin.php?page=wpfilebase_files#addfile')));
     $current_object = get_queried_object();
     $is_filebrowser = false;
     if (!empty($current_object) && !empty($current_object->post_type) && $current_object->ID > 0) {
         $is_filebrowser = $current_object->ID == WPFB_Core::$settings->file_browser_post_id;
         $link = esc_attr(WPFB_Core::PluginUrl('editor_plugin.php?manage_attachments=1&post_id=' . $current_object->ID));
         $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-attachments', 'title' => __('Manage attachments', WPFB), 'href' => $link, 'meta' => array('onclick' => 'window.open("' . $link . '", "wpfb-manage-attachments", "width=680,height=400,menubar=no,location=no,resizable=no,status=no,toolbar=no,scrollbars=yes");return false;')));
     }
     $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-add-file', 'title' => __('Sync Filebase', WPFB), 'href' => admin_url('admin.php?page=wpfilebase_manage&action=sync')));
     $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-toggle-context-menu', 'title' => !empty(WPFB_Core::$settings->file_context_menu) ? __('Disable file context menu', WPFB) : __('Enable file context menu', WPFB), 'href' => 'javascript:;', 'meta' => array('onclick' => 'return wpfb_toggleContextMenu();')));
     if ($is_filebrowser) {
         $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-toggle-drag-drop', 'title' => get_user_option('wpfb_set_fbdd') ? __('Disable file browser Drag & Drop', WPFB) : __('Enable file browser Drag & Drop', WPFB), 'href' => 'javascript:;', 'meta' => array('onclick' => 'jQuery.ajax({url:wpfbConf.ajurl,type:"POST",data:{action:"set-user-setting",name:"fbdd",value:' . (get_user_option('wpfb_set_fbdd') ? 0 : 1) . '},async:false});location.reload();return false;')));
     }
 }
コード例 #2
0
 function GetIconUrl($size = null)
 {
     // todo: remove file operations!
     if ($this->is_category) {
         // add mtime for cache updates
         return empty($this->cat_icon) ? WP_CONTENT_URL . WPFB_Core::$settings->folder_icon : WPFB_Core::PluginUrl("wp-filebase_thumb.php?cid={$this->cat_id}&t=" . @filemtime($this->GetThumbPath()));
     }
     if (!empty($this->file_thumbnail)) {
         return WPFB_Core::PluginUrl('wp-filebase_thumb.php?fid=' . $this->file_id . '&name=' . $this->file_thumbnail);
         // name var only for correct caching!
     }
     $type = $this->GetType();
     $ext = substr($this->GetExtension(), 1);
     $img_path = ABSPATH . WPINC . '/images/';
     $img_url = get_option('siteurl') . '/' . WPINC . '/images/';
     $custom_folder = '/images/fileicons/';
     // check for custom icons
     if (file_exists(WP_CONTENT_DIR . $custom_folder . $ext . '.png')) {
         return WP_CONTENT_URL . $custom_folder . $ext . '.png';
     }
     if (file_exists(WP_CONTENT_DIR . $custom_folder . $type . '.png')) {
         return WP_CONTENT_URL . $custom_folder . $type . '.png';
     }
     // todo: cache file_exists
     if (file_exists($img_path . 'crystal/' . $ext . '.png')) {
         return $img_url . 'crystal/' . $ext . '.png';
     }
     if (file_exists($img_path . 'crystal/' . $type . '.png')) {
         return $img_url . 'crystal/' . $type . '.png';
     }
     if (file_exists($img_path . $ext . '.png')) {
         return $img_url . $ext . '.png';
     }
     if (file_exists($img_path . $type . '.png')) {
         return $img_url . $type . '.png';
     }
     // fallback to default
     if (file_exists($img_path . 'crystal/default.png')) {
         return $img_url . 'crystal/default.png';
     }
     if (file_exists($img_path . 'default.png')) {
         return $img_url . 'default.png';
     }
     // fallback to blank :(
     return $img_url . 'blank.gif';
 }
コード例 #3
0
 static function InitClass()
 {
     self::$ajax_url = WPFB_Core::PluginUrl('wpfb-ajax.php');
     if (defined('WPFB_NO_CORE_INIT')) {
         return;
     }
     // used with CSS proxy
     //Load settings
     self::$settings = (object) get_option(WPFB_OPT_NAME);
     // load lang
     $lang_dir = defined('WPFB_LANG_DIR') ? '../../' . WPFB_LANG_DIR : basename(WPFB_PLUGIN_ROOT) . '/languages';
     load_plugin_textdomain(WPFB, 'wp-content/plugins/' . $lang_dir, $lang_dir);
     add_action('parse_query', array(__CLASS__, 'ParseQuery'));
     // search
     add_action('wp_enqueue_scripts', array(__CLASS__, 'EnqueueScripts'));
     add_action('wp_footer', array(__CLASS__, 'Footer'));
     add_action('generate_rewrite_rules', array(__CLASS__, 'GenRewriteRules'));
     add_action(WPFB . '_cron', array(__CLASS__, 'Cron'));
     add_action('wpfilebase_sync', array(__CLASS__, 'Sync'));
     // for Developers: New wp-filebase actions
     add_shortcode('wpfilebase', array(__CLASS__, 'ShortCode'));
     // for attachments and file browser
     add_filter('the_content', array(__CLASS__, 'ContentFilter'), 10);
     // must be lower than 11 (before do_shortcode) and after wpautop (>9)
     add_filter('ext2type', array(__CLASS__, 'Ext2TypeFilter'));
     add_filter('pre_set_site_transient_update_plugins', array(__CLASS__, 'PreSetPluginsTransientFilter'));
     add_filter('plugins_api', array(__CLASS__, 'PluginsApiFilter'), 10, 3);
     // register treeview stuff
     //wp_register_script('jquery-cookie', WPFB_PLUGIN_URI.'extras/jquery/jquery.cookie.js', array('jquery'));
     wp_register_script('jquery-treeview', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.js', array('jquery'), WPFB_VERSION);
     wp_register_script('jquery-treeview-edit', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.edit.js', array('jquery-treeview'), WPFB_VERSION);
     wp_register_script('jquery-treeview-async', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.async.js', array('jquery-treeview-edit'), WPFB_VERSION);
     wp_register_style('jquery-treeview', WPFB_PLUGIN_URI . 'extras/jquery/treeview/jquery.treeview.css', array(), WPFB_VERSION);
     // DataTables
     wp_register_script('jquery-dataTables', WPFB_PLUGIN_URI . 'extras/jquery/dataTables/js/jquery.dataTables.min.js', array('jquery'), WPFB_VERSION);
     wp_register_style('jquery-dataTables', WPFB_PLUGIN_URI . 'extras/jquery/dataTables/css/jquery.dataTables.css', array(), WPFB_VERSION);
     wp_register_script('jquery-dataTables-columnFilter', WPFB_PLUGIN_URI . 'extras/jquery/dataTables/js/jquery.dataTables.columnFilter.js', array('jquery-dataTables'), WPFB_VERSION);
     wp_register_script(WPFB, WPFB_PLUGIN_URI . 'js/common.js', array('jquery'), WPFB_VERSION);
     // cond loading (see Footer)
     if (empty(WPFB_Core::$settings->disable_css)) {
         $wpfb_css = get_option('wpfb_css');
         if ($wpfb_css) {
             // static file?
             wp_enqueue_style(WPFB, strstr($wpfb_css, '//'), array(), WPFB_VERSION, 'all');
         } else {
             $upload_path = path_is_absolute(WPFB_Core::$settings->upload_path) ? '' : WPFB_Core::$settings->upload_path;
             wp_enqueue_style(WPFB, WPFB_Core::PluginUrl("wp-filebase_css.php?rp={$upload_path}"), array(), WPFB_VERSION, 'all');
         }
     }
     $wpfb_admin_page = is_admin() && !empty($_GET['page']) && strpos($_GET['page'], 'wpfilebase_') !== false || defined('WPFB_EDITOR_PLUGIN');
     if ($wpfb_admin_page) {
         wpfb_loadclass('Admin');
     }
     // live admin
     if ($wpfb_admin_page && @$_GET['page'] == 'wpfilebase_filebrowser' || (WPFB_Core::CurUserCanCreateCat() || WPFB_Core::CurUserCanUpload()) && !is_admin()) {
         wp_enqueue_script(WPFB . '-live-admin', WPFB_PLUGIN_URI . 'js/live-admin.js', array('jquery'), WPFB_VERSION);
         if (self::GetOpt('admin_bar')) {
             add_action('admin_bar_menu', array(__CLASS__, 'AdminBar'), 80);
         }
         if (self::GetOpt('file_context_menu')) {
             wp_enqueue_script('jquery-contextmenu', WPFB_PLUGIN_URI . 'extras/jquery/contextmenu/jquery.contextmenu.js', array('jquery'));
             wp_enqueue_style('jquery-contextmenu', WPFB_PLUGIN_URI . 'extras/jquery/contextmenu/jquery.contextmenu.css', array(), WPFB_VERSION);
         }
         wp_enqueue_style('wpfb-live-admin', WPFB_PLUGIN_URI . 'css/live-admin.css', array(), WPFB_VERSION);
     }
     // for admin
     if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
         self::MceAddBtns();
     }
     self::DownloadRedirect();
     if ((WPFB_Core::$settings->frontend_upload || current_user_can('upload_files')) && (!empty($_GET['wpfb_upload_file']) || !empty($_GET['wpfb_add_cat']))) {
         wpfb_call('Admin', empty($_GET['wpfb_upload_file']) ? 'ProcessWidgetAddCat' : 'ProcessWidgetUpload');
     }
 }
コード例 #4
0
ファイル: AdvUploader.php プロジェクト: parsonsc/dofe
    function PrintScripts($prefix = '', $auto_submit = false)
    {
        $this->Scripts($prefix);
        $minify = true;
        if ($minify) {
            ob_start();
        }
        ?>
<script type="text/javascript">
/* <![CDATA[ */


function fileQueued(fileObj) {
	jQuery('#file-upload-progress').show().html('<div class="progress"><div class="percent">0%</div><div class="bar" style="width: 30px"></div></div><div class="filename original"> ' + fileObj.name + '</div>');

	jQuery('.progress', '#file-upload-progress').show();
	jQuery('.filename', '#file-upload-progress').show();

	jQuery("#media-upload-error").empty();
	jQuery('.upload-flash-bypass').hide();
	
	jQuery('#file-submit').prop('disabled', true);
	jQuery('#cancel-upload').show().prop('disabled', false);

	 /* delete already uploaded temp file */
	if(jQuery('#file_flash_upload').val() != '0') {
		jQuery.ajax({type: 'POST', async: true, url:"<?php 
        echo esc_attr(WPFB_Core::PluginUrl('wpfb-async-upload.php'));
        ?>
",
		data: {<?php 
        echo $this->GetAjaxAuthData(true);
        ?>
 , "delupload": jQuery('#file_flash_upload').val()},
		success: (function(data){})
		});
		jQuery('#file_flash_upload').val(0);
	}
}
           
function wpFileError(fileObj, message) {
	jQuery('#media-upload-error').show().html(message);
	jQuery('.upload-flash-bypass').show();
	jQuery("#file-upload-progress").hide().empty();
	jQuery('#cancel-upload').hide().prop('disabled', true);
}


function uploadError(fileObj, errorCode, message, uploader) {
	wpFileError(fileObj, "Error "+errorCode+": "+message);
}

function uploadSuccess(fileObj, serverData) {
	/* if async-upload returned an error message, place it in the media item div and return */
	if ( serverData.match('media-upload-error') || serverData.match('error-div') ) {
		wpFileError(fileObj, serverData);
		return;
	}
	
	var file_obj = jQuery.parseJSON(serverData);
	
	if(file_obj && 'undefined' != typeof(file_obj.file_id)) {		
		jQuery('#file_form_action').val("updatefile");
		jQuery('#file_id').val(file_obj.file_id);
		
		if(file_obj.file_thumbnail) {
			jQuery('#file_thumbnail_wrap').show();
			jQuery('#file_thumbnail_wrap').children('img').attr('src', file_obj.file_thumbnail_url);
			jQuery('#file_thumbnail_name').html(file_obj.file_thumbnail);
		} else {
			jQuery('#file_thumbnail_wrap').hide();
		}
		
		jQuery('#file_display_name').val(file_obj.file_display_name);
		jQuery('#file_version').val(file_obj.file_version);
		
		jQuery('#wpfb-file-nonce').val(file_obj.nonce);
	} else {
		jQuery('#file_flash_upload').val(serverData);
	}
	
	jQuery('#file-submit').prop('disabled', false);

	<?php 
        if ($auto_submit) {
            ?>
	jQuery('#file_flash_upload').closest("form").submit();
	<?php 
        }
        ?>
}

function uploadComplete(fileObj) {
	jQuery('#cancel-upload').hide().prop('disabled', true);
}

	
/* ]]> */
</script>
<?php 
        if ($minify) {
            // todo: remove // comments!!
            echo str_replace(array(" /* <![CDATA[ */ ", " /* ]]> */ "), array("\r\n/* <![CDATA[ */\r\n", "\r\n/* ]]> */\r\n"), str_replace(array("\r\n", "\n"), " ", ob_get_clean()));
        }
    }
コード例 #5
0
    function Display()
    {
        // #8545. wmode=transparent cannot be used with SWFUpload
        $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');
        ?>
<script type="text/javascript">
//<![CDATA[
var swfu;
SWFUpload.onload = function() {
	var settings = {
			button_text: '<span class="button"><?php 
        _e('Select Files');
        ?>
<\/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(WPFB_Core::PluginUrl('wpfb-async-upload.php'));
        ?>
",
			flash_url : "<?php 
        echo includes_url('js/swfupload/swfupload.swf');
        ?>
",
			file_post_name: "async-upload",
			file_types: "<?php 
        echo apply_filters('upload_file_glob', '*.*');
        ?>
",
			post_params : { <?php 
        echo $this->GetAjaxAuthData();
        ?>
 },
			file_size_limit : "<?php 
        require_once ABSPATH . 'wp-admin/includes/template.php';
        echo wp_max_upload_size();
        ?>
b",
			file_queue_limit: 1,
			
			file_dialog_start_handler : (function(){}),
			
			file_queued_handler : fileQueued,
			//upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_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
			},
			debug: !!<?php 
        echo (int) WP_DEBUG;
        ?>
		};
		swfu = new SWFUpload(settings);
};
//]]>
</script>


<?php 
        do_action('pre-flash-upload-ui');
        ?>
	<div>
	<input type="hidden" id="file_flash_upload" name="file_flash_upload" value="0" />
	<div id="flash-browse-button"></div>
	<span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php 
        esc_attr_e('Cancel Upload');
        ?>
" class="button" /></span>
	</div>
	<div id="media-upload-error"></div>
	<div id="file-upload-progress" class="media-item" style="width: auto;"></div>
<?php 
        do_action('post-flash-upload-ui');
    }
コード例 #6
0
    static function TplsTable($type, $exclude = array(), $include = array())
    {
        global $user_identity;
        $cat = $type == 'cat';
        $list = $type == 'list';
        $tpls = $list ? get_option(WPFB_OPT_NAME . '_list_tpls') : WPFB_Core::GetTpls($type);
        if (!$list) {
            $tpls['default'] = WPFB_Core::GetOpt("template_{$type}");
        }
        $item = $cat ? self::$sample_cat : self::$sample_file;
        ?>
<table class="widefat post fixed" cellspacing="0">
	<thead>
	<tr>
	<th scope="col" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
	<th scope="col" class="manage-column" style="width:200px"><?php 
        _e('Name');
        ?>
</th>
	<th scope="col" class="manage-column column-title" style=""><?php 
        _e('Preview');
        ?>
</th>
	</tr>
	</thead>

	<tfoot>
	<tr>
	<th scope="col" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
	<th scope="col" class="manage-column" style=""><?php 
        _e('Name');
        ?>
</th>
	<th scope="col" class="manage-column column-title" style=""><?php 
        _e('Preview');
        ?>
</th>
	</tr>
	</tfoot>

	<tbody>
<?php 
        foreach ($tpls as $tpl_tag => $tpl_src) {
            if (!empty($include) && !in_array($tpl_tag, $include) || !empty($exclude) && in_array($tpl_tag, $exclude)) {
                continue;
            }
            $edit_link = add_query_arg(array('action' => 'edit', 'type' => $type, 'tpl' => $tpl_tag));
            if ($list) {
                $tpl = WPFB_ListTpl::Get($tpl_tag);
            }
            ?>
	<tr id="tpl-<?php 
            echo "{$type}-{$tpl_tag}";
            ?>
" class="iedit" valign="top">
		<th scope="row" class="check-column"><input type="checkbox" name="tpl[]" value="<?php 
            echo esc_attr($tpl_tag);
            ?>
" /></th>
		<td class="column-title">
			<strong><a class="row-title" href="<?php 
            echo $edit_link;
            ?>
" title="<?php 
            printf(__('Edit &#8220;%s&#8221;'), $tpl_tag);
            ?>
"><?php 
            echo self::TplTitle($tpl_tag);
            ?>
</a></strong><br />
			<code>tpl=<?php 
            echo $tpl_tag;
            ?>
</code>
			<div class="row-actions"><span class='edit'><a href="<?php 
            echo $edit_link;
            ?>
" title="<?php 
            _e('Edit this item');
            ?>
"><?php 
            _e('Edit');
            ?>
</a></span>
			<?php 
            if (!in_array($tpl_tag, self::$protected_tags)) {
                ?>
<span class='trash'>| <a class='submitdelete' title='<?php 
                _e('Delete this item permanently');
                ?>
' href='<?php 
                echo wp_nonce_url(add_query_arg(array('action' => 'del', 'type' => $type, 'tpl' => $tpl_tag)), 'del-' . $type, 'wpfb-tpl-nonce') . '#' . $type;
                ?>
'><?php 
                _e('Delete');
                ?>
</a></span><?php 
            }
            ?>
			</div>
		</td>
		<td>
			<div class="entry-content wpfilebase-tpl-preview">
				<div id="tpl-preview_<?php 
            echo $tpl_tag;
            ?>
">
					<?php 
            if (!empty($_GET['iframe-preview'])) {
                ?>
					
					<iframe src="<?php 
                echo WPFB_Core::PluginUrl("tpl-preview.php?type={$type}&tag={$tpl_tag}");
                ?>
" style="width:100%;height:220px;"></iframe>
					<?php 
            } else {
                $table_found = !$list && strpos($tpl_src, '<table') !== false;
                if (!$list && !$table_found && strpos($tpl_src, '<tr') !== false) {
                    $tpl_src = "<table>{$tpl_src}</table>";
                }
                echo do_shortcode($list ? $tpl->Sample(self::$sample_cat, self::$sample_file) : $item->GenTpl(WPFB_TplLib::Parse($tpl_src), 'sample'));
            }
            ?>
				</div>
					
				<div style="height: 50px; float: left;"></div>
				<div class="clear"></div>
			</div>
		</td>
	</tr>
		
	<?php 
        }
        ?>
	</tbody>
</table>
<?php 
        self::TplForm($type);
    }
コード例 #7
0
ファイル: PLUpload.php プロジェクト: parsonsc/dofe
    function Display()
    {
        global $is_IE, $is_opera;
        $id = $this->id;
        $upload_size_unit = $max_upload_size = WPFB_Core::GetMaxUlSize();
        $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;
        }
        do_action('pre-upload-ui');
        $plupload_init = array('runtimes' => 'html5,silverlight,flash,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'multiple_queues' => false, 'max_file_size' => $max_upload_size . 'b', 'url' => WPFB_Core::PluginUrl('wpfb-async-upload.php'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => __('Allowed Files'), 'extensions' => '*')), 'multipart' => true, 'urlstream_upload' => true, 'multipart_params' => $this->GetAjaxAuthData());
        $plupload_init = apply_filters('plupload_init', $plupload_init);
        ?>

<script type="text/javascript">
var resize_height = 1024, resize_width = 1024, // this is for img resizing (not used here!)
wpUploaderInit = <?php 
        echo json_encode($plupload_init);
        ?>
;
</script>

<input type="hidden" id="file_flash_upload" name="file_flash_upload" value="0" />

<div id="plupload-upload-ui" class="hide-if-no-js">
<?php 
        do_action('pre-plupload-upload-ui');
        // hook change, old name: 'pre-flash-upload-ui'
        ?>
<div id="drag-drop-area">
	<div class="drag-drop-inside">
	<p class="drag-drop-info">
		<?php 
        _e('Drop files here - or -', WPFB);
        ?>
		<span class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php 
        esc_attr_e('Select Files');
        ?>
" class="button" /></span>
		<span class="drag-drop-info-spacer"></span>
	</p>
	</div>
</div>
	<p class="upload-flash-bypass">
	<?php 
        printf(__('You are using the multi-file uploader. Problems? Try the <a href="%1$s">browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)));
        ?>
	</p>
	
</div>

<?php 
        if (($is_IE || $is_opera) && $max_upload_size > 100 * 1024 * 1024) {
            ?>
	<span class="big-file-warning"><?php 
            _e('Your browser has some limitations uploading large files with the multi-file uploader. Please use the browser uploader for files over 100MB.');
            ?>
</span>
<?php 
        }
        ?>
	<div id="media-upload-error"></div>
	<div id="file-upload-progress" class="media-item" style="width: auto;"></div>
<?php 
        //do_action('post-upload-ui');
    }
コード例 #8
0
ファイル: PLUploader.php プロジェクト: parsonsc/dofe
    public function Init($cotainer_id, $browser_btn_id = '', $error_el_id = null, $drop_el_id = null)
    {
        if (empty($drop_el_id)) {
            $drop_el_id = $cotainer_id;
        }
        if (empty($browser_btn_id)) {
            $browser_btn_id = $cotainer_id . '-btn';
            echo '<input type="button" value="Select Files" id="' . $browser_btn_id . '" style="display:none;" />';
        }
        $max_upload_size = WPFB_Core::GetMaxUlSize();
        if (is_admin()) {
            self::PrintScripts();
        }
        $plupload_init = array('runtimes' => 'html5,gears,silverlight,flash,html4', 'browse_button' => $browser_btn_id, 'container' => $cotainer_id, 'drop_element' => $drop_el_id, 'file_data_name' => 'async-upload', 'multiple_queues' => $this->multi, 'max_file_size' => $max_upload_size . 'b', 'url' => WPFB_Core::PluginUrl('wpfb-async-upload.php'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => $this->images_only ? __('Images') : __('Allowed Files'), 'extensions' => $this->images_only ? 'jpg,gif,png,bmp' : '*')), 'multipart' => true, 'urlstream_upload' => true, 'multipart_params' => array_merge($this->GetAjaxAuthData(), $this->post_params));
        $jss = md5(uniqid());
        ?>
<script type="text/javascript">
	init_<?php 
        echo $jss;
        ?>
 = (function() {
		if('undefined' == typeof plupload) {
			setTimeout(init_<?php 
        echo $jss;
        ?>
, 100);
			return;
		}
		var uploader = new plupload.Uploader(<?php 
        echo json_encode($plupload_init);
        ?>
);
		
		uploader.bind('Init', function(up) {
			var uploaddiv = jQuery('#<?php 
        echo $cotainer_id;
        ?>
');
			var dropdiv = jQuery('#<?php 
        echo $drop_el_id;
        ?>
');
			
			uploaddiv.data('uploader', up);

			if ( !jQuery(document.body).hasClass('mobile') ) {
				dropdiv.addClass('drag-drop');
				dropdiv.bind('dragover', function(e){ dropdiv.addClass('drag-over'); })
						  .bind('dragleave', function(e){ dropdiv.removeClass('drag-over'); })
						  .bind('drop', function(e){	dropdiv.removeClass('drag-over'); });
			} else {
				dropdiv.removeClass('drag-drop');
				//dropdiv.hide();
			}

//			if ( up.runtime == 'html4' )
//				jQuery('.upload-flash-bypass').hide();
		});
		
		uploader.init();
		
		var mobile = <?php 
        echo (int) wp_is_mobile();
        ?>
;
		var supported = <?php 
        echo (int) (!wp_is_mobile() || function_exists('_device_can_upload') && _device_can_upload());
        ?>
;
			
		var supports_dragdrop = uploader.features.dragdrop && !mobile;

		// Generate drag/drop helper classes.
		(function( dropzone, supported ) {
			var timer, active;

			if ( ! dropzone )
				return;

			dropzone.toggleClass( 'supports-drag-drop', !! supported );

			if ( ! supported )
				return dropzone.unbind('.wp-uploader');

			// 'dragenter' doesn't fire correctly,
			// simulate it with a limited 'dragover'
			dropzone.bind( 'dragover.wp-uploader', function(){
				if ( timer )
					clearTimeout( timer );

				if ( active )
					return;

				dropzone.trigger('dropzone:enter').addClass('drag-over');
				active = true;
			});

			dropzone.bind('dragleave.wp-uploader, drop.wp-uploader', function(){
				// Using an instant timer prevents the drag-over class from
				// being quickly removed and re-added when elements inside the
				// dropzone are repositioned.
				//
				// See http://core.trac.wordpress.org/ticket/21705
				timer = setTimeout( function() {
					active = false;
					dropzone.trigger('dropzone:leave').removeClass('drag-over');
				}, 0 );
			});
		}( jQuery('#<?php 
        echo $drop_el_id;
        ?>
'), supports_dragdrop ));
		
		uploader.bind('FilesAdded', function(up, files) {
			var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);

			<?php 
        if (!empty($error_el_id)) {
            ?>
 jQuery('#<?php 
            echo $error_el_id;
            ?>
').html('');<?php 
        }
        ?>
			
			<?php 
        if (!empty($this->js_files_queued)) {
            echo $this->js_files_queued . '(up, files)';
        }
        ?>

			plupload.each(files, function(file){
				if ( max > hundredmb && file.size > hundredmb && up.runtime != 'html5' )
					wpfbPlUploadSizeError( up, file, true );
				else {
					file.dom_id = '<?php 
        echo $cotainer_id;
        ?>
-ul'+file.id;
					<?php 
        echo $this->js_file_queued;
        ?>
(up, file);
				}
			});

			up.refresh();
			up.start();
		});

		uploader.bind('BeforeUpload', function(up, file) {
			// something
		});

		uploader.bind('UploadFile', function(up, file) {
			wpfbPlFileUploading(up, file);
		});

		uploader.bind('UploadProgress', function(up, file) {
			var item = jQuery('#'+file.dom_id);
			jQuery('.bar', item).width( (200 * file.loaded) / file.size );
			jQuery('.percent', item).html( file.percent + '%' );
			<?php 
        if (!empty($this->js_upload_progress)) {
            echo $this->js_upload_progress . '(file);';
        }
        ?>
		});

		uploader.bind('Error', function(up, err) {
			wpfbPlUploadError(err.file, err.code, err.message, up);
			up.refresh();
		});

		uploader.bind('FileUploaded', function(up, file, response) {
			// on success serverData should be numeric, fix bug in html4 runtime returning the serverData wrapped in a <pre> tag
			var serverData = response.response.replace(/^<pre>(.+)<\/pre>$/, '$1');
			
			if ( serverData.match('media-upload-error') || serverData.match('error-div') ) {
				wpfbPlFileError(file, serverData);
				return;
			}
			
			serverData = jQuery.parseJSON(serverData);
			
			<?php 
        echo $this->js_upload_success;
        ?>
(file, serverData);
		});

		uploader.bind('UploadComplete', function(up, files) {
			//uploadComplete();
		}); 
		
		
	
	
	
	
	


	


function wpfbPlFileUploading(up, file) {
	var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);

	if ( max > hundredmb && file.size > hundredmb ) {
		setTimeout(function(){
			var done;

			if ( file.status < 3 && file.loaded == 0 ) { // not uploading
				wpfbPlFileError(file, pluploadL10n.big_upload_failed.replace('%1$s', '<a class="uploader-html" href="#">').replace('%2$s', '</a>'));
				up.stop(); // stops the whole queue
				up.removeFile(file);
				up.start(); // restart the queue
			}
		}, 10000); // wait for 10 sec. for the file to start uploading
	}
}

/*
function uploadProgress(up, file) {
	var item = jQuery('#media-item-' + file.id);

	jQuery('.bar', item).width( (200 * file.loaded) / file.size );
	jQuery('.percent', item).html( file.percent + '%' );
}*/


function wpfbPlUploadSizeError( up, file, over100mb ) {
	var message;

	if ( over100mb )
		message = pluploadL10n.big_upload_queued.replace('%s', file.name) + ' ' + pluploadL10n.big_upload_failed.replace('%1$s', '<a class="uploader-html" href="#">').replace('%2$s', '</a>');
	else
		message = pluploadL10n.file_exceeds_size_limit.replace('%s', file.name);

	<?php 
        echo $this->js_file_error;
        ?>
 (message,file);

	up.removeFile(file);
}

function wpfbPlUploadError(fileObj, errorCode, message, uploader) {
	var hundredmb = 100 * 1024 * 1024, max;

	switch (errorCode) {
		case plupload.FAILED:
			wpfbPlFileError(fileObj, pluploadL10n.upload_failed);
			break;
		case plupload.FILE_EXTENSION_ERROR:
			wpfbPlFileError(fileObj, pluploadL10n.invalid_filetype);
			break;
		case plupload.FILE_SIZE_ERROR:
			wpfbPlUploadSizeError(uploader, fileObj);
			break;
		case plupload.IMAGE_FORMAT_ERROR:
			wpfbPlFileError(fileObj, pluploadL10n.not_an_image);
			break;
		case plupload.IMAGE_MEMORY_ERROR:
			wpfbPlFileError(fileObj, pluploadL10n.image_memory_exceeded);
			break;
		case plupload.IMAGE_DIMENSIONS_ERROR:
			wpfbPlFileError(fileObj, pluploadL10n.image_dimensions_exceeded);
			break;
		case plupload.GENERIC_ERROR:
			wpfbPlQueueError(pluploadL10n.upload_failed);
			break;
		case plupload.IO_ERROR:
			max = parseInt(uploader.settings.max_file_size, 10);

			if ( max > hundredmb && fileObj.size > hundredmb )
				wpfbPlFileError(fileObj, pluploadL10n.big_upload_failed.replace('%1$s', '<a class="uploader-html" href="#">').replace('%2$s', '</a>'));
			else
				wpfbPlQueueError(pluploadL10n.io_error);
			break;
		case plupload.HTTP_ERROR:
			wpfbPlQueueError(pluploadL10n.http_error);
			break;
		case plupload.INIT_ERROR:
			//jQuery('.media-upload-form').addClass('html-uploader');
			// TODO: on init failure
			break;
		case plupload.SECURITY_ERROR:
			wpfbPlQueueError(pluploadL10n.security_error);
			break;
/*		case plupload.UPLOAD_ERROR.UPLOAD_STOPPED:
		case plupload.UPLOAD_ERROR.FILE_CANCELLED:
			jQuery('#media-item-' + fileObj.id).remove();
			break;*/
		default:
			wpfbPlFileError(fileObj, pluploadL10n.default_error);
	}
}






function wpfbPlFileError(fileObj, message) {
	var item = jQuery('#' + fileObj.dom_id);
	jQuery('.error', item).show().html(message);
	<?php 
        if (!empty($this->js_file_error)) {
            ?>
 <?php 
            echo $this->js_file_error;
            ?>
 (message,fileObj); <?php 
        }
        ?>
}

// generic error message
function wpfbPlQueueError(message) {
	<?php 
        if (!empty($error_el_id)) {
            ?>
			jQuery('#<?php 
            echo $error_el_id;
            ?>
').show().html( '<div class="error"><p>' + message + '</p></div>' ); 
	<?php 
        } else {
            ?>
			alert(message);
	<?php 
        }
        ?>
}
	});
	init_<?php 
        echo $jss;
        ?>
();
</script>
<?php 
    }