_id)); if (is_wp_error($inserted)) { $last_folder++; $data = array('message' => $row->path . __(' already exists','maxgalleria-media-library'), 'last_folder' => $last_folder, 'percentage' => $percentage ); add_action('wpmf_create_folder', array($this, 'create_wpmf_folder'), 10, 4); echo json_encode($data); die(); } else { $updateted = wp_update_term($inserted['term_id'], WPMF_TAXO, array('term_group' => $id_author)); $term_info = get_term($updateted['term_id'], WPMF_TAXO); do_action('wpmf_create_folder', $inserted['term_id'], $row->text, $parent_id, array('trigger' => 'media_library_action')); //error_log("id " . $row->id . " term id " . $inserted['term_id']); $data = array('new_id' => $inserted['term_id']); $where = array('id' => $row->id); $wpdb->update($table, $data, $where); $table = $wpdb->prefix . MAXGALLERIA_MEDIA_LIBRARY_FOLDER_TABLE; $data = array('term_id' => $inserted['term_id']); $where = array('post_id' => $row->id); $wpdb->update($table, $data, $where); } } else { $table = $wpdb->prefix . MAXGALLERIA_MEDIA_LIBRARY_FOLDER_TABLE; $data = array('term_id' => 0); $where = array('post_id' => $row->id); $wpdb->update($table, $data, $where); } $last_folder++; $data = array('message' => $row->path, 'last_folder' => $last_folder, 'percentage' => $percentage ); } else { $data = array('message' => __('Folders added.','maxgalleria-media-library'), 'last_folder' => null, 'percentage' => 100 ); } add_action('wpmf_create_folder', array($this, 'create_wpmf_folder'), 10, 4); echo json_encode($data); die(); } public function mlfp_import_next_file() { global $wpdb; if ( !wp_verify_nonce( $_POST['nonce'], MAXGALLERIA_MEDIA_LIBRARY_NONCE)) { exit(__('missing nonce!','maxgalleria-media-library')); } if ((isset($_POST['last_file'])) && (strlen(trim($_POST['last_file'])) > 0)) $last_file = intval(trim(stripslashes(strip_tags($_POST['last_file'])))); else $last_file = 0; if ((isset($_POST['file_count'])) && (strlen(trim($_POST['file_count'])) > 0)) $file_count = intval(trim(stripslashes(strip_tags($_POST['file_count'])))); else $file_count = 0; if ((isset($_POST['id_author'])) && (strlen(trim($_POST['id_author'])) > 0)) $id_author = intval(trim(stripslashes(strip_tags($_POST['id_author'])))); else $id_author = 0; $percentage = (($last_file+1) / $file_count) * 100; $folder_table = $wpdb->prefix . MAXGALLERIA_MEDIA_LIBRARY_FOLDER_TABLE; $sql = "SELECT {$wpdb->prefix}posts.ID, {$wpdb->prefix}posts.post_title, pm.meta_value as attached_file, $folder_table.folder_id as parent_id FROM {$wpdb->prefix}posts LEFT JOIN {$wpdb->prefix}postmeta AS pm ON pm.post_id = {$wpdb->prefix}posts.ID LEFT JOIN $folder_table ON({$wpdb->prefix}posts.ID = $folder_table.post_id) WHERE post_type = 'attachment' AND pm.meta_key = '_wp_attached_file' group by ID ORDER by parent_id limit $last_file, 1"; //error_log($sql); $row = $wpdb->get_row($sql); if($row) { $folder_id = $this->mlfp_get_term_id($row->parent_id); $folder = array($folder_id); $results = wp_set_post_terms($row->ID, $folder, WPMF_TAXO ); if(!is_wp_error($results) && isset($results[0])) { //$this->get_wpmf_term_id($name, $row->parent_id); $data = array('term_id' => $results[0]); $where = array('post_id' => $row->ID); $wpdb->update($folder_table, $data, $where); } $last_file++; $data = array('message' => $row->attached_file, 'last_file' => $last_file, 'percentage' => $percentage ); } else { $table = $wpdb->prefix . MAXGALLERIA_MEDIA_LIBRARY_IMPORT_FOLDERS_TABLE; $sql = "TRUNCATE TABLE " . $table; $wpdb->query($sql); $data = array('message' => __('Files added.','maxgalleria-media-library'), 'last_file' => null, 'percentage' => 100 ); } echo json_encode($data); die(); } public function create_wpmf_folder($termID, $folder_name, $folder_parent, $trigger) { $parent_id = $this->get_mlfp_parent2($folder_parent); $this->create_new_mlfp_folder($parent_id, $folder_name, false, $termID); } public function delete_wpmf_folder($termID) { global $wpdb; $delete_id = $this->get_mlfp_parent2($termID->term_id); if(!empty($delete_id)) { $parent_folder = $this->get_parent($delete_id); $formatted_query = "select post_title, post_type, pm.meta_value as attached_file from {$wpdb->prefix}posts LEFT JOIN {$wpdb->prefix}postmeta AS pm ON (pm.post_id = {$wpdb->prefix}posts.ID) where ID = %d AND pm.meta_key = '_wp_attached_file'"; $sql = $wpdb->prepare($formatted_query, $delete_id); //error_log($sql); $row = $wpdb->get_row($sql); if($row) { $baseurl = $this->upload_dir['baseurl']; $baseurl = rtrim($baseurl, '/') . '/'; $image_location = $baseurl . ltrim($row->attached_file, '/'); $folder_path = $this->get_absolute_path($image_location); $del_post = array('post_id' => $delete_id); $this->mlfp_delete_single_folder($delete_id, $folder_path, $del_post, $parent_folder, $row, false); } } } public function mlfp_get_term_id($folder_parent) { global $wpdb; $table = $wpdb->prefix . MAXGALLERIA_MEDIA_LIBRARY_FOLDER_TABLE; $sql = "select term_id from $table where post_id = $folder_parent"; $term_id = $wpdb->get_var($sql); return $term_id; } public function get_mlfp_parent($folder_parent) { global $wpdb; $table = $wpdb->prefix . MAXGALLERIA_MEDIA_LIBRARY_IMPORT_FOLDERS_TABLE; $sql = "select parent from $table where new_id = $folder_parent"; $parent_id = $wpdb->get_var($sql); return $parent_id; } public function get_mlfp_parent2($folder_parent) { global $wpdb; $table = $wpdb->prefix . MAXGALLERIA_MEDIA_LIBRARY_FOLDER_TABLE; $sql = "select post_id from $table where term_id = $folder_parent"; //error_log($sql); $parent_id = $wpdb->get_var($sql); return $parent_id; } public function mlfp_remove_lookup_table($delete_id) { global $wpdb; $table = $wpdb->prefix . MAXGALLERIA_MEDIA_LIBRARY_IMPORT_FOLDERS_TABLE; $where = array( 'id' => $delete_id ); $wpdb->delete( $table, $where ); } public function get_wpmf_term_id($name, $parent) { global $wpdb; $sql = "select tt.term_id from {$wpdb->prefix}term_taxonomy as tt left join {$wpdb->prefix}terms as t ON (t.term_id = tt.term_id) where tt.taxonomy = '" . WPMF_TAXO . "' and tt.parent = $parent and t.name = '$name'"; //error_log($sql); $term_id = $wpdb->get_var($sql); return $term_id; } public function mlfp_wpmf_folder_count() { global $wpdb; if ( !wp_verify_nonce( $_POST['nonce'], MAXGALLERIA_MEDIA_LIBRARY_NONCE)) { exit(__('missing nonce!','maxgalleria-media-library')); } $sql = "SELECT count(*) FROM {$wpdb->prefix}terms AS t INNER JOIN {$wpdb->prefix}term_taxonomy AS tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy IN ('" . WPMF_TAXO . "') "; //error_log($sql); $wpmf_folder_count = $wpdb->get_var($sql); echo $wpmf_folder_count; die(); } public function mlfp_lookup_folder_id_from_term($parent_term_id) { global $wpdb; $table = $wpdb->prefix . MAXGALLERIA_MEDIA_LIBRARY_FOLDER_TABLE; $sql = "select post_id from $table where term_id = $parent_term_id"; //error_log($sql); $folder_id = $wpdb->get_var($sql); return $folder_id; } public function mlfp_import_next_wpmf_folder() { global $wpdb; if ( !wp_verify_nonce( $_POST['nonce'], MAXGALLERIA_MEDIA_LIBRARY_NONCE)) { exit(__('missing nonce!','maxgalleria-media-library')); } if ((isset($_POST['last_folder'])) && (strlen(trim($_POST['last_folder'])) > 0)) $last_folder = intval(trim(stripslashes(strip_tags($_POST['last_folder'])))); else $last_folder = 0; if ((isset($_POST['folder_count'])) && (strlen(trim($_POST['folder_count'])) > 0)) $folder_count = intval(trim(stripslashes(strip_tags($_POST['folder_count'])))); else $folder_count = 0; $percentage = (($last_folder+1) / $folder_count) * 100; $sql = "SELECT t.term_id, t.name, t.slug, tt.parent FROM {$wpdb->prefix}terms AS t INNER JOIN {$wpdb->prefix}term_taxonomy AS tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy IN ('" . WPMF_TAXO . "') ORDER BY t.term_id ASC LIMIT $last_folder, 1"; //error_log($sql); $row = $wpdb->get_row($sql); if($row) { if( $row->slug != 'wp-media-folder-root') { $relative_path = $this->get_wpmf_parent($row->parent, $row->name); $folder_exists = $this->mlfp_export->epim_folder_exist($relative_path); if(!$folder_exists) { if($row->parent == 0) $parent_folder_id = get_option(MAXGALLERIA_MEDIA_LIBRARY_UPLOAD_FOLDER_ID ); else $parent_folder_id = $this->mlfp_lookup_folder_id_from_term($row->parent); $this->create_new_mlfp_folder($parent_folder_id, $row->name, false, $row->term_id); $message = $relative_path; } else { $message = $relative_path . __(' already exists','maxgalleria-media-library'); } } else { $message = ""; } $last_folder++; $data = array('message' => $message, 'last_folder' => $last_folder, 'percentage' => $percentage ); } else { $data = array('message' => __('Folders added.','maxgalleria-media-library'), 'last_folder' => null, 'percentage' => 100 ); } echo json_encode($data); die(); } public function get_wpmf_parent($parent_id, $name) { if($parent_id == 0) return $name; $path_array = array($name); $row = $this->get_wpmf_folder_name($parent_id); array_unshift($path_array, $row->name); while($row->parent != 0) { $row = $this->get_wpmf_folder_name($row->parent); array_unshift($path_array, $row->name); } $relative_path = implode('/', $path_array); return $relative_path; } public function get_wpmf_folder_name($term_id) { global $wpdb; $sql = "SELECT t.name, tt.parent FROM {$wpdb->prefix}terms AS t INNER JOIN {$wpdb->prefix}term_taxonomy AS tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy IN ('wpmf-category') and t.term_id = $term_id"; $row = $wpdb->get_row($sql); return $row; } } $maxgalleria_media_library_pro = new MaxGalleriaMediaLibPro(); function mlpp_display_files( $atts ) { global $wpdb, $maxgalleria_media_library_pro; extract(shortcode_atts(array( 'folder_id' => '', ), $atts)); $upload_dir = wp_upload_dir(); $output = ""; $folder_table = $wpdb->prefix . "mgmlp_folders"; $sql = "select ID, post_title, $folder_table.folder_id, pm.meta_value as attached_file from {$wpdb->prefix}posts LEFT JOIN $folder_table ON({$wpdb->prefix}posts.ID = $folder_table.post_id) LEFT JOIN {$wpdb->prefix}postmeta AS pm ON (pm.post_id = {$wpdb->prefix}posts.ID) where post_type = 'attachment' and folder_id = '$folder_id' AND pm.meta_key = '_wp_attached_file' order by post_title"; //error_log($sql); $output .= "" . PHP_EOL; $output .= ' ' . PHP_EOL; $rows = $wpdb->get_results($sql); if($rows) { foreach($rows as $row) { $thumbnail = wp_get_attachment_thumb_url($row->ID); //error_log($thumbnail); if($thumbnail == false) { //$thumbnail = MAXGALLERIA_MEDIA_LIBRARY_PLUGIN_URL . "/images/file.jpg"; $ext = pathinfo($row->attached_file, PATHINFO_EXTENSION); $thumbnail = $maxgalleria_media_library_pro->get_file_thumbnail($ext); } $file_ulr = $upload_dir['baseurl'] . "/" . $row->attached_file; $output .= " $row->post_title $row->post_title " . PHP_EOL; } } $output .= ' ' . PHP_EOL; //error_log($output); return $output; } add_shortcode('mlpp-display-files', 'mlpp_display_files'); ?>