'name',
'hide_empty' => false,
'parent' => $parnet
);
$categories = get_categories($args);
foreach ($categories as $category) {
if( !in_array( $category->name, $excludes ) ) {
$cats[] = array( 'id' => $category->term_id, 'name' => $category->name, 'parent' => $category->parent);
$cats = adv_cat_list( $category->term_id, $cats, $excludes );
}
}
return $cats;
}
function adv_admin_inline_js($hook) {
global $adv_file_upload_admin_page, $wpdb;
//get plugin's options
$destinations = get_option('adv_file_upload_destination');
$gallery = get_option('adv_file_upload_gallery');
$bws = get_option('adv_file_upload_bws');
$cat = get_option('adv_file_upload_cat');
$progress = get_option('adv_file_upload_progress');
$maxFileSize = '1073741824';
//set the default location
$upload_dir = wp_upload_dir();
$default_dir = str_replace ( ABSPATH, '', $upload_dir['path'] );
// get list wordpress galleries
if ($gallery) {
$query = "
SELECT $wpdb->posts.ID, $wpdb->posts.post_title, $wpdb->posts.post_name
FROM $wpdb->posts
WHERE $wpdb->posts.post_type IN ('post','page')
AND $wpdb->posts.post_status IN ('publish','private','protected')
AND $wpdb->posts.post_content LIKE '%[gallery%ids=%'
";
$galleries = $wpdb->get_results($query);
//option to create new gallery
$destinations[] = Array ('label' => 'Create New Gallery',
'dest' => $default_dir,
'lib' => true,
'type' => "Wordpress Gallery",
'id' => 'new');
//show existing Galleries
foreach( $galleries as $gallery ) {
$destinations[] = Array ('label' => $gallery->post_title,
'dest' => $default_dir,
'lib' => true,
'type' => "Wordpress Gallery",
'id' => $gallery->ID);
}
}
// get list BWS galleries
if ($bws) {
//get BWS galleries
$args = array(
'post_type' => 'gallery',
'post_status' => array('publish','private','protected'),
);
$query = new WP_Query( $args );
$gllr_options = get_option( 'gllr_options' );
if ( $query->have_posts() ) {
foreach ($query->posts as $post) {
$destinations[] = Array ('label' => $post->post_title,
'dest' => $default_dir,
'lib' => true,
'type' => "BWS Gallery",
'id' => $post->ID);
}
}
/* Restore original Post Data */
wp_reset_postdata();
}
// get list of Categories
if ($cat) {
$excludes = explode (',', get_option( 'adv_file_upload_exc_cat', 'Uncategorized' ));
$cats = adv_cat_list( 0, array(), $excludes );
}
if ($progress) {
//added Style sheet based on settings
echo "\n";
}
if ( $adv_file_upload_admin_page == $hook ) {
echo "\n";
}
//added javascript vairables
echo "";
}
function adv_file_upload_admin_menu() {
global $adv_file_upload_admin_page;
/* Register our plugin page */
if (!get_option('adv_file_upload_replace_default')) {
$adv_file_upload_admin_page = add_media_page(
__('Advanced uploader','adv-file-upload'), // The Page title
__('Advanced uploader','adv-file-upload'), // The Menu title
'upload_files', // The capability required for access to this item
'adv-file-upload', // the slug to use for the page in the URL
'adv_file_upload_manage_menu' // The function to call to render the page
);
}
add_action('admin_enqueue_scripts', 'adv_file_upload_admin_scripts');
}
function adv_file_upload_admin_scripts($hook) {
global $adv_file_upload_admin_page, $post;
if( !($adv_file_upload_admin_page == $hook ||
(($hook == 'media-new.php' || $hook == 'post-new.php' || $hook == 'post.php') &&
get_option('adv_file_upload_replace_default')))
|| $post->post_type == attachment )
return;
wp_enqueue_script( 'adv-file-upload' );
if (get_option('adv_file_upload_replace_default') || $adv_file_upload_admin_page == $hook) {
//check version number and include newer version plupload if wordpress version is older then 3.9
global $wp_version;
if( version_compare( $wp_version, 3.9 ) < 0 ) {
wp_deregister_script('plupload');
wp_deregister_script('plupload-html5');
wp_deregister_script('plupload-flash');
wp_deregister_script('plupload-silverlight');
wp_deregister_script('plupload-html4');
wp_register_script( 'plupload', null, array( 'plupload2' ), '1.0');
wp_register_script( 'plupload-html5', null, array( 'plupload2' ), '1.0');
wp_register_script( 'plupload-flash', null, array( 'plupload2' ), '1.0');
wp_register_script( 'plupload-silverlight', null, array( 'plupload2' ), '1.0');
wp_register_script( 'plupload-html4', null, array( 'plupload2' ), '1.0');
}
}
wp_enqueue_style( 'adv-file-upload-css' );
wp_enqueue_style( 'wp-jquery-ui-dialog' );
// js varaibles to page
adv_admin_inline_js($hook);
}
function adv_file_upload_set_loader() {
set_user_setting('adv_uploader', $_REQUEST['loader']);
exit();
}
function adv_file_upload_manage_menu() {
if ( !current_user_can( 'upload_files' ) ) {
wp_die( __( 'You do not have permission to upload files.' ) );
}
wp_enqueue_script('plupload-handlers');
echo "
";
screen_icon('upload');
echo "
Advanced uploader
";
echo "";
echo "\n";
}
function adv_upload_add_file ($name, $target_path, $parent_id, $sizes, $dest, $galleryType, $galleryID) {
$upload_dir = wp_upload_dir();
$wp_filetype = wp_check_filetype($name);
//set parent ID to add picture to BWS gallery
if ($galleryType == 'BWS Gallery')
$parent_id = $galleryID;
$attachment = array(
'guid' => $upload_dir ['url'] . '/' . $name,
'post_mime_type' => $wp_filetype['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', $name),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $target_path . $name, $parent_id);
// you must first include the image.php file
// for the function wp_generate_attachment_metadata() to work
require_once(ABSPATH . 'wp-admin/includes/image.php');
//get reduced size images imformation from file
if($sizes != null && count($sizes) > 0) {
if (pathinfo($name, PATHINFO_EXTENSION) != 'pdf') {
//get image dimentions
$size = getimagesize ($target_path . $name);
//Horizontal size of image attachment, in pixels.
$attach_data["width"] = $size[0];
//Vertical size of image attachment, in pixels.
$attach_data["height"] = $size[1];
//get additional picture meta data
$attach_data["image_meta"] = wp_read_image_metadata($target_path . $name);
}
//Path to image attachment, relative to the currently configured uploads directory.
//need to add logic to check if the upload dir is organised into year/month.
$attach_data["file"] = substr($upload_dir['subdir'],1) . '/' . urlencode($name);
$attach_data["sizes"] = $sizes;
} else {
$attach_data = wp_generate_attachment_metadata( $attach_id, $target_path . $name );
}
wp_update_attachment_metadata( $attach_id, $attach_data );
return $attach_id;
}
// ------------------------------------------------------------------
// fields and settings during admin_init
// ------------------------------------------------------------------
//
function adv_file_upload_settings_api_init() {
// Add the section to reading settings so we can add our
// fields to it
add_settings_section('adv_file_upload',
'Advanced uploader',
'adv_file_upload_setting_section',
'media');
// Add the field with the names and function to use for our new
// settings, put it in our new section
add_settings_field('adv_file_upload_destination',
'Destinations',
'adv_file_upload_setting_dest',
'media',
'adv_file_upload');
add_settings_field('adv_file_upload_progress',
'Colour of progress bar',
'adv_file_upload_setting_prog',
'media',
'adv_file_upload');
add_settings_field('adv_file_upload_gallery',
'Include Wordpress Galleries',
'adv_file_upload_setting_gallery',
'media',
'adv_file_upload');
add_settings_field('adv_file_upload_bws',
'Include BWS Galleries',
'adv_file_upload_setting_bws',
'media',
'adv_file_upload');
add_settings_field('adv_file_upload_cat',
'Include Categories',
'adv_file_upload_setting_cat',
'media',
'adv_file_upload');
add_settings_field('adv_file_upload_exc_cat',
'Categories to exclude',
'adv_file_upload_setting_exc_cat',
'media',
'adv_file_upload');
add_settings_field('adv_file_upload_replace_default',
'Replace Default Uploader',
'adv_file_upload_setting_replace_default',
'media',
'adv_file_upload');
// Register our setting so that $_POST handling is done for us and
// our callback function just has to echo the
register_setting('media','adv_file_upload_destination','adv_file_upload_validate_destination');
register_setting('media','adv_file_upload_progress','adv_file_upload_validate_progress');
register_setting('media','adv_file_upload_gallery');
register_setting('media','adv_file_upload_bws');
register_setting('media','adv_file_upload_cat');
register_setting('media','adv_file_upload_exc_cat');
register_setting('media','adv_file_upload_replace_default');
}
add_action('admin_init', 'adv_file_upload_settings_api_init');
// ------------------------------------------------------------------
// Settings link
// ------------------------------------------------------------------
//
// This function adds settings link to plugin page.
//
//Add the filter with your plugin information
add_filter( 'plugin_action_links_' . 'advanced-uploader/upload.php', 'adv_file_upload_setting_action_links' );
//The callback function to add the settings link
function adv_file_upload_setting_action_links( $links ) {
array_unshift( $links, 'Settings' );
return $links;
}
// ------------------------------------------------------------------
// Settings section callback function
// ------------------------------------------------------------------
//
// This function is needed for the new section.
//
function adv_file_upload_setting_section () {
wp_enqueue_script( 'adv-file-upload-settings' );
echo '
Settings for the Advanced uploader plugin
';
}
// ------------------------------------------------------------------
// Default Override Callback function
// ------------------------------------------------------------------
//
// creates a checkbox for overiding default
//
function adv_file_upload_setting_replace_default () {
$default = get_option('adv_file_upload_replace_default');
echo "";
}
// ------------------------------------------------------------------
// Wordpress Galleries Callback function
// ------------------------------------------------------------------
//
// creates a checkbox for Wordpress Galleries settings
//
function adv_file_upload_setting_gallery () {
$gallery = get_option('adv_file_upload_gallery');
echo "";
echo " Selecting this will include Wordpress Galleries as destinations ";
}
// ------------------------------------------------------------------
// BWS Galleries Callback function
// ------------------------------------------------------------------
//
// creates a checkbox for BWS Galleries settings
//
function adv_file_upload_setting_bws () {
$bws = get_option('adv_file_upload_bws');
echo "";
echo " Selecting this will include BWS Galleries as destinations ";
echo "Note: BWS Gallery needs to be active to use this feature";
}
// ------------------------------------------------------------------
// Category Callback functions
// ------------------------------------------------------------------
//
// creates a checkbox for Category settings
//
function adv_file_upload_setting_cat () {
$cat = get_option('adv_file_upload_cat');
echo "";
echo " Selecting this will include Categories as destinations ";
echo "Note: It is recommend to have Media Categories By Eddie Moya to be active to use this feature";
}
//
// creates a text box for Category exclusion settings
//
function adv_file_upload_setting_exc_cat () {
$cat = get_option('adv_file_upload_exc_cat','Uncategorized');
echo "";
echo "Note: Enter category names separated with a comma, parent categories will exclude child categories";
}
// ------------------------------------------------------------------
// Destiantions Callback function
// ------------------------------------------------------------------
//
// creates a boxes for destination settings
//
function adv_file_upload_setting_dest() {
$destinations = get_option('adv_file_upload_destination');
echo "