/** * @param $action * @param $data * @param bool $filter * * @return array */ function gmedia_ios_app_processor($action, $data, $filter = true) { global $gmCore, $gmDB, $gmGallery, $user_ID, $gmapp_version; $out = array(); if (version_compare('3', $gmapp_version, '<=')) { $logic = 2; if (version_compare('3.1', $gmapp_version, '<')) { $logic = 3; } } else { $logic = 1; } $error = array(); $error_info = array(); $alert = array(); $alert_info = array(); $data = (array) $data; switch ($action) { case 'do_library': if (!isset($data['action'])) { return $out; } $filter = array(); switch ($data['action']) { case 'add_media': if (!current_user_can('gmedia_upload')) { $out['error'] = array('code' => 'nocapability', 'title' => __("You can't do this", 'grand-media'), 'message' => __('You have no permission to do this operation', 'grand-media')); return $out; } usleep(10); if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { $file_name = $_FILES['userfile']['name']; $file_tmp = $_FILES['userfile']['tmp_name']; } else { $error[] = __("Failed to move uploaded file.", 'grand-media'); break; } $fileinfo = $gmCore->fileinfo($file_name); if (false === $fileinfo) { break; } $gmedia = (array) $data['item']; if (!current_user_can('gmedia_terms')) { unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']); } else { if (empty($gmedia['albums'])) { $gmedia['terms']['gmedia_album'] = ''; } else { $alb = isset($gmedia['albums'][0]->term_id) ? $gmedia['albums'][0]->term_id : $gmedia['albums'][0]->name; $gmedia['terms']['gmedia_album'] = $alb; } if (empty($gmedia['categories'])) { $gmedia['terms']['gmedia_category'] = ''; } else { $categories = array(); foreach ($gmedia['categories'] as $category) { $categories[] = isset($category->term_id) ? $category->term_id : $category->name; } $gmedia['terms']['gmedia_category'] = implode(',', $categories); } if (empty($gmedia['tags'])) { $gmedia['terms']['gmedia_tag'] = ''; } else { $tags = array(); foreach ($gmedia['tags'] as $tag) { $tags[] = isset($tag->term_id) ? $tag->term_id : $tag->name; } $gmedia['terms']['gmedia_tag'] = implode(',', $tags); } unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']); } if (isset($gmedia['status']) && 'public' == $gmedia['status']) { $gmedia['status'] = 'publish'; } $return = $gmCore->gmedia_upload_handler($file_tmp, $fileinfo, 'multipart', $gmedia); if (isset($return['error'])) { $error[] = $return['error']['message']; } else { $alert[] = $return['success']['message']; } break; case 'update_media': if (!current_user_can('gmedia_edit_media')) { $error[] = __('You are not allowed to edit media', 'grand-media'); break; } $gmedia = (array) $data['item']; if (!empty($gmedia['ID'])) { $item = $gmDB->get_gmedia($gmedia['ID']); if (!$item || $user_ID != $item->author && !current_user_can('gmedia_edit_others_media')) { $error[] = __('You are not allowed to edit others media', 'grand-media'); break; } unset($gmedia['date'], $gmedia['mime_type'], $gmedia['gmuid'], $gmedia['modified']); //$gmedia['modified'] = current_time('mysql'); if (!current_user_can('gmedia_delete_others_media')) { $gmedia['author'] = $item->author; } if (isset($gmedia['status']) && 'public' == $gmedia['status']) { $gmedia['status'] = 'publish'; } if (!current_user_can('gmedia_terms')) { unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']); } else { if (empty($gmedia['albums'])) { $gmedia['terms']['gmedia_album'] = ''; } else { if (isset($gmedia['albums'][0]->term_id)) { $gmedia['terms']['gmedia_album'] = $gmedia['albums'][0]->term_id; } elseif (current_user_can('gmedia_album_manage')) { $gmedia['terms']['gmedia_album'] = $gmedia['albums'][0]->name; } } if (empty($gmedia['categories'])) { $gmedia['terms']['gmedia_category'] = ''; } else { $categories = array(); foreach ($gmedia['categories'] as $category) { if (isset($category->term_id)) { $categories[] = $category->term_id; } elseif (current_user_can('gmedia_category_manage')) { $categories[] = $category->name; } } $gmedia['terms']['gmedia_category'] = $categories; } if (empty($gmedia['tags'])) { $gmedia['terms']['gmedia_tag'] = ''; } else { $tags = array(); foreach ($gmedia['tags'] as $tag) { if (isset($tag->term_id)) { $tags[] = $tag->term_id; } elseif (current_user_can('gmedia_tag_manage')) { $tags[] = $tag->name; } } $gmedia['terms']['gmedia_tag'] = $tags; } unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']); } $gmDB->insert_gmedia($gmedia); } break; case 'assign_album': if (!current_user_can('gmedia_edit_media')) { $error[] = __('You are not allowed to edit media', 'grand-media'); break; } if (!current_user_can('gmedia_terms')) { $error[] = __('You are not allowed to manage albums', 'grand-media'); } $term = $data['assign_album'][0]; $count = count($data['selected']); if ('0' == $term) { foreach ($data['selected'] as $item) { $gmDB->delete_gmedia_term_relationships($item, 'gmedia_album'); } $alert[] = sprintf(__('%d item(s) updated with "No Album"', 'grand-media'), $count); } else { foreach ($data['selected'] as $item) { $gm_item = $gmDB->get_gmedia($item); if (!$gm_item || $user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media')) { continue; } $result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_album', $append = 0); if (is_wp_error($result)) { $error[] = $result->get_error_message(); $count--; } elseif (!$result) { $count--; } } if ($gmCore->is_digit($term)) { $alb_name = $gmDB->get_term_name($term); } else { $alb_name = $term; } $alert[] = sprintf(__('Album `%s` assigned to %d item(s)', 'grand-media'), esc_html($alb_name), $count); } break; case 'assign_category': if (!current_user_can('gmedia_edit_media')) { $error[] = __('You are not allowed to edit media', 'grand-media'); break; } if (!current_user_can('gmedia_terms')) { $error[] = __('You are not allowed to manage categories', 'grand-media'); break; } if (empty($data['assign_category'])) { $error[] = __('No categories provided', 'grand-media'); break; } $terms = $data['assign_category']; $count = count($data['selected']); if (1 === count($terms) && '0' == $terms[0]) { foreach ($data['selected'] as $item) { $gm_item = $gmDB->get_gmedia($item); if (!$gm_item || $user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media')) { continue; } $gmDB->delete_gmedia_term_relationships($item, 'gmedia_category'); } $alert[] = sprintf(__('%d item(s) updated with "Uncategorized"', 'grand-media'), $count); } else { foreach ($data['selected'] as $item) { $gm_item = $gmDB->get_gmedia($item); if (!$gm_item || $user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media')) { continue; } $result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_category', $append = 0); if (is_wp_error($result)) { $error[] = $result->get_error_message(); $count--; } elseif (!$result) { $count--; } } $alert[] = sprintf(__('%d category(ies) added to %d item(s)', 'grand-media'), count($terms), $count); } break; case 'unassign_category': if (!current_user_can('gmedia_edit_media')) { $error[] = __('You are not allowed to edit media', 'grand-media'); break; } if (empty($data['unassign_category'])) { $error[] = __('No categories provided', 'grand-media'); break; } $terms = array_map('intval', $data['unassign_category']); $count = count($data['selected']); foreach ($data['selected'] as $item) { $gm_item = $gmDB->get_gmedia($item); if (!$gm_item || $user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media')) { continue; } $result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_category', $append = -1); if (is_wp_error($result)) { $error[] = $result->get_error_message(); $count--; } elseif (!$result) { $count--; } } $alert[] = sprintf(__('%d category(ies) deleted from %d item(s)', 'grand-media'), count($terms), $count); break; case 'add_tags': if (!current_user_can('gmedia_edit_media')) { $error[] = __('You are not allowed to edit media', 'grand-media'); break; } if (!current_user_can('gmedia_terms')) { $error[] = __('You are not allowed manage tags', 'grand-media'); break; } if (empty($data['add_tags'])) { $error[] = __('No tags provided', 'grand-media'); break; } $terms = $data['add_tags']; $count = count($data['selected']); foreach ($data['selected'] as $item) { $gm_item = $gmDB->get_gmedia($item); if (!$gm_item || $user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media')) { continue; } $result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_tag', $append = 1); if (is_wp_error($result)) { $error[] = $result->get_error_message(); $count--; } elseif (!$result) { $count--; } } $alert[] = sprintf(__('%d tag(s) added to %d item(s)', 'grand-media'), count($terms), $count); break; case 'add_cover': if (!current_user_can('gmedia_edit_media')) { $error[] = __('You are not allowed to edit media', 'grand-media'); break; } $cover = (int) $data['add_cover']; $count = count($data['selected']); foreach ($data['selected'] as $item) { $gm_item = $gmDB->get_gmedia($item); if (!$gm_item || $user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media')) { $count--; continue; } if ('image' == substr($gm_item->mime_type, 0, 5)) { $count--; continue; } if ($cover) { $gmDB->update_metadata('gmedia', $gm_item->ID, '_cover', $cover); } else { $gmDB->delete_metadata('gmedia', $gm_item->ID, '_cover'); } } $alert[] = sprintf(__('%d item(s) updated', 'grand-media'), $count); break; case 'delete_tags': if (!current_user_can('gmedia_edit_media')) { $error[] = __('You are not allowed to edit media', 'grand-media'); break; } if (empty($data['delete_tags'])) { $error[] = __('No tags provided', 'grand-media'); break; } $terms = array_map('intval', $data['delete_tags']); $count = count($data['selected']); foreach ($data['selected'] as $item) { $gm_item = $gmDB->get_gmedia($item); if (!$gm_item || $user_ID != $gm_item->author && !current_user_can('gmedia_edit_others_media')) { continue; } $result = $gmDB->set_gmedia_terms($item, $terms, 'gmedia_tag', $append = -1); if (is_wp_error($result)) { $error[] = $result->get_error_message(); $count--; } elseif (!$result) { $count--; } } $alert[] = sprintf(__('%d tag(s) deleted from %d item(s)', 'grand-media'), count($terms), $count); break; case 'delete': if (!current_user_can('gmedia_delete_media')) { $error[] = __('You are not allowed to delete this post.'); break; } $count = count($data['selected']); foreach ($data['selected'] as $item) { $gm_item = $gmDB->get_gmedia($item); if ((int) $gm_item->author != $user_ID && !current_user_can('gmedia_delete_others_media')) { $error[] = "#{$item}: " . __('You are not allowed to delete media others media', 'grand-media'); continue; } if (!$gmDB->delete_gmedia((int) $item)) { $error[] = "#{$item}: " . __('Error in deleting...', 'grand-media'); $count--; } } if ($count) { $alert[] = sprintf(__('%d items deleted successfuly', 'grand-media'), $count); } break; } if (1 === $logic) { $filter = gmedia_ios_app_library_data(array('filter', 'gmedia_category', 'gmedia_album', 'gmedia_tag')); } $out = array_merge($out, $filter); break; case 'library': $ep = $gmGallery->options['endpoint']; if (get_option('permalink_structure')) { $share_link_base = home_url(urlencode($ep) . '/$2/$1'); } else { $share_link_base = add_query_arg(array("{$ep}" => '$1', 't' => '$2'), home_url('index.php')); } $filter = $filter ? gmedia_ios_app_library_data(array('filter')) : array(); $mime_type = $logic > 2 ? array('image', 'audio') : 'image'; $args = array('mime_type' => $mime_type, 'orderby' => 'ID', 'order' => 'DESC', 'per_page' => 100, 'page' => 1, 'tag__in' => null, 'category__in' => null, 'album__in' => null, 'gmedia__in' => null, 'author' => 0, 'status' => null); $terms_ids_query = array(); if (!empty($data['tag__in'])) { if (empty($data['category__in']) && empty($data['album__in'])) { $args['orderby'] = $gmGallery->options['in_tag_orderby']; $args['order'] = $gmGallery->options['in_tag_order']; } $terms_ids_query = array_merge($terms_ids_query, $data['tag__in']); } if (!empty($data['category__in'])) { $cat_ids = wp_parse_id_list($data['category__in']); if (1 === count($cat_ids)) { $cat_meta = $gmDB->get_metadata('gmedia_term', $cat_ids[0]); $args['orderby'] = !empty($cat_meta['_orderby'][0]) ? $cat_meta['_orderby'][0] : $gmGallery->options['in_category_orderby']; $args['order'] = !empty($cat_meta['_order'][0]) ? $cat_meta['_order'][0] : $gmGallery->options['in_category_order']; } $terms_ids_query = array_merge($terms_ids_query, $cat_ids); } if (!empty($data['album__in'])) { $alb_ids = wp_parse_id_list($data['album__in']); if (1 === count($alb_ids)) { $album_meta = $gmDB->get_metadata('gmedia_term', $alb_ids[0]); $args['orderby'] = !empty($album_meta['_orderby'][0]) ? $album_meta['_orderby'][0] : $gmGallery->options['in_album_orderby']; $args['order'] = !empty($album_meta['_order'][0]) ? $album_meta['_order'][0] : $gmGallery->options['in_album_order']; } $terms_ids_query = array_merge($terms_ids_query, $alb_ids); } $data = wp_parse_args($data, $args); $false_out = array_merge($filter, array('properties' => array('request' => isset($data['request']) ? $data['request'] : null), 'data' => array())); $terms_ids = array(); if (!empty($terms_ids_query)) { $terms_ids = $gmDB->get_terms(array('gmedia_album', 'gmedia_category', 'gmedia_tag'), array('include' => $terms_ids_query)); if (!empty($terms_ids) && !is_wp_error($terms_ids)) { foreach ($terms_ids as $i => $term) { gmedia_ios_app_term_data_extend($terms_ids[$i], $share_link_base); } $terms_ids = array_filter($terms_ids); if (empty($terms_ids)) { $out = $false_out; break; } } else { $terms_ids = array(); } } $req_terms = array(); if (!empty($terms_ids)) { foreach ($terms_ids as $term) { $taxterm = str_replace('gmedia_', '', $term->taxonomy); $req_terms["{$taxterm}__in"]["{$term->term_id}"] = $term; } } $is_admin = isset($data['admin']) ? intval($data['admin']) : 0; if (!is_user_logged_in()) { $logged_in = false; $data['status'] = array('publish'); if (!empty($req_terms['album__in'])) { $break = false; foreach ($req_terms['album__in'] as $alb) { if (!(isset($alb->status) && 'publish' == $alb->status)) { $break = true; } } if ($break) { $out = $false_out; break; } } } else { $logged_in = true; if ($is_admin && !current_user_can('gmedia_library')) { $out = $false_out; break; } if ($is_admin && !current_user_can('gmedia_show_others_media')) { $data['author'] = $user_ID; } } $_data = $data; $_data['per_page'] = -1; $_data['status'] = null; $_data['fields'] = 'ids'; $all_gmedias_ids = $gmDB->get_gmedias($_data); $gmedias = $gmDB->get_gmedias($data); $properties = array_merge($req_terms, array('request' => isset($data['request']) ? $data['request'] : null, 'total_pages' => $gmDB->pages, 'current_page' => $gmDB->openPage, 'items_count' => $gmDB->resultPerPage, 'total_count' => $gmDB->totalResult, 'count' => count($all_gmedias_ids))); foreach ($gmedias as $i => $item) { //if((!$logged_in && 'publish' != $item->status) || (!$is_admin && ('draft' == $item->status) && ((int)$user_ID != (int)$item->author))) { if ((!$is_admin || $is_admin && !current_user_can('gmedia_edit_others_media')) && ('draft' == $item->status && (int) $user_ID != (int) $item->author)) { unset($gmedias[$i]); $properties['total_count']--; $properties['items_count']--; continue; } $author_id = $item->author; $authordata = get_userdata($author_id); if ($authordata) { $display_name = $authordata->display_name; $first_name = $authordata->first_name; $last_name = $authordata->last_name; } else { $display_name = __('Deleted User', 'grand-media'); $first_name = ''; $last_name = ''; } $gmedias[$i]->user = array('id' => $author_id, 'displayname' => $display_name, 'firstname' => $first_name, 'last_name' => $last_name); $gmedias[$i]->date = strtotime($item->date); $meta = $gmDB->get_metadata('gmedia', $item->ID); //$_metadata = maybe_unserialize( $meta['_metadata'][0] ); $_metadata = $meta['_metadata'][0]; unset($meta['_metadata']); $type = explode('/', $item->mime_type); $item_url = $gmCore->upload['url'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $item->gmuid; $gmedias[$i]->url = $item_url; $terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_tag'); $tags = array(); if ($terms) { $terms = array_values((array) $terms); foreach ($terms as $term) { $tags[] = array('term_id' => $term->term_id, 'name' => $term->name); } } $gmedias[$i]->tags = $tags; $terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_album'); $albums = array(); if ($terms) { $terms = array_values((array) $terms); foreach ($terms as $term) { $albums[] = array('term_id' => $term->term_id, 'name' => $term->name, 'status' => 1 === $logic && 'publish' == $term->status ? 'public' : $term->status); } } $gmedias[$i]->albums = $albums; if ('image' == $type[0]) { $terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_category'); $categories = array(); if ($terms) { $terms = array_values((array) $terms); foreach ($terms as $term) { $categories[] = array('term_id' => $term->term_id, 'name' => $term->term_id, 'title' => $term->name); } } $gmedias[$i]->categories = $categories; $gmedias[$i]->meta = array('thumb' => $_metadata['thumb'], 'web' => $_metadata['web'], 'original' => $_metadata['original']); $gmedias[$i]->meta['thumb']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_thumb']}/{$item->gmuid}"; $gmedias[$i]->meta['web']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image']}/{$item->gmuid}"; if (is_file("{$gmCore->upload['path']}/{$gmGallery->options['folder']['image_original']}/{$item->gmuid}")) { $gmedias[$i]->meta['original']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_original']}/{$item->gmuid}"; } else { $gmedias[$i]->meta['original']['link'] = ''; } if (isset($_metadata['image_meta'])) { $gmedias[$i]->meta['data'] = $_metadata['image_meta']; } unset($meta['image_meta']); } else { $cover_gmedia = false; if (!empty($meta['_cover'][0])) { $cover_gmedia = $gmDB->get_gmedia($meta['_cover'][0]); if ($cover_gmedia) { $cover_metadata = $gmDB->get_metadata('gmedia', $cover_gmedia->ID, '_metadata', true); $gmedias[$i]->meta = array('thumb' => $cover_metadata['thumb'], 'web' => $cover_metadata['web'], 'original' => $cover_metadata['original']); $gmedias[$i]->meta['thumb']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_thumb']}/{$cover_gmedia->gmuid}"; $gmedias[$i]->meta['web']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image']}/{$cover_gmedia->gmuid}"; if (is_file("{$gmCore->upload['path']}/{$gmGallery->options['folder']['image_original']}/{$cover_gmedia->gmuid}")) { $gmedias[$i]->meta['original']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_original']}/{$cover_gmedia->gmuid}"; } else { $gmedias[$i]->meta['original']['link'] = ''; } } } unset($meta['_cover']); if (!$cover_gmedia) { $gmedias[$i]->meta = array('thumb' => array('link' => $gmCore->gm_get_media_image($item, 'thumb', false), 'width' => 300, 'height' => 300)); } if (!empty($_metadata)) { $gmedias[$i]->meta['data'] = $_metadata; } } $gmedias[$i]->meta['views'] = 0; $gmedias[$i]->meta['likes'] = 0; if (isset($meta['views'][0])) { $gmedias[$i]->meta['views'] = $meta['views'][0]; } unset($meta['views']); if (isset($meta['likes'][0])) { $gmedias[$i]->meta['likes'] = $meta['likes'][0]; } unset($meta['likes']); if (!empty($meta['_gps'][0])) { $gmedias[$i]->meta['data']['GPS'] = $meta['_gps'][0]; } unset($meta['_gps']); if (isset($meta['_rating'][0])) { $gmedias[$i]->meta['rating'] = maybe_unserialize($meta['_rating'][0]); } unset($meta['_rating']); if (!empty($data['meta']) && !empty($meta)) { foreach ($meta as $key => $val) { if ('_peaks' == $key) { $gmedias[$i]->meta[$key] = json_decode($val[0]); } else { $gmedias[$i]->meta[$key] = maybe_unserialize($val); } } } $item_name = $item->title ? $item->title : pathinfo($item->gmuid, PATHINFO_FILENAME); $gmedia_hashid = gmedia_hash_id_encode($item->ID, 'single'); $gmedias[$i]->sharelink = str_replace(array('$1', '$2'), array(urlencode($gmedia_hashid), 's'), $share_link_base); if (1 === $logic && 'publish' == $item->status) { $gmedias[$i]->status = 'public'; } } $out = array_merge($filter, array('properties' => $properties, 'data' => array_values($gmedias))); break; case 'delete_term': $taxonomy = $data['taxonomy']; if (!empty($data['items'])) { if (!current_user_can('gmedia_terms_delete')) { $error[] = __('You have no permission to do this operation', 'grand-media'); break; } $count = count($data['items']); foreach ($data['items'] as $item) { if (!current_user_can('gmedia_edit_others_media')) { if ('gmedia_album' == $taxonomy) { $term = $gmDB->get_term($item, $taxonomy); if ((int) $term->global != (int) $user_ID) { $error['delete_album'] = __('You are not allowed to edit others media', 'grand-media'); $count--; continue; } } else { $error[] = __('You are not allowed to edit others media', 'grand-media'); $count--; continue; } } $delete = $gmDB->delete_term($item); if (is_wp_error($delete)) { $error[] = $delete->get_error_message(); $count--; } } if ($count) { $alert[] = sprintf(__('%d items deleted successfuly', 'grand-media'), $count); } } $out = gmedia_ios_app_library_data(array('filter', $taxonomy)); break; case 'add_term': $taxonomy = $data['taxonomy']; $edit_term = isset($data['term_id']) ? (int) $data['term_id'] : 0; $term = $data; $term_id = 0; if ('gmedia_album' == $taxonomy) { if (!current_user_can('gmedia_album_manage')) { $out['error'] = array('code' => 'nocapability', 'title' => __("You can't do this", 'grand-media'), 'message' => __('You have no permission to do this operation', 'grand-media')); return $out; } $args = array(); do { $term['name'] = trim($term['name']); if (empty($term['name'])) { $error[] = __('Term Name is not specified', 'grand-media'); break; } if ($gmCore->is_digit($term['name'])) { $error[] = __("Term Name can't be only digits", 'grand-media'); break; } if (1 === $logic && isset($term['status']) && 'public' == $term['status']) { $term['status'] = 'publish'; } if ($edit_term && !$gmDB->term_exists($edit_term, $taxonomy)) { $error[] = __('A term with the id provided does not exists', 'grand-media'); $edit_term = false; } $term_author = isset($term['global']) ? $term['global'] : false; if ($term_id = $gmDB->term_exists($term['name'], $taxonomy, $term_author)) { if ($term_id != $edit_term) { $error[] = __('A term with the name provided already exists', 'grand-media'); $error_info['terms'][$term_id] = $term['name']; break; } } if ($edit_term) { $_term = $gmDB->get_term($edit_term, $taxonomy); if ((int) $_term->global != (int) $user_ID && !current_user_can('gmedia_edit_others_media')) { $error[] = __('You are not allowed to edit others media', 'grand-media'); break; } $term_id = $gmDB->update_term($edit_term, $term); } else { if (!current_user_can('gmedia_edit_others_media')) { $term['global'] = intval($user_ID); } $term_id = $gmDB->insert_term($term['name'], $taxonomy, $term); } if (is_wp_error($term_id)) { $error[] = $term_id->get_error_message(); $term_id = 0; break; } $alert_info['terms'][$term_id] = $term['name']; $term_meta = array(); if (isset($term['_orderby'])) { $term_meta['_orderby'] = $term['_orderby']; } elseif (isset($term['orderby'])) { $term_meta['_orderby'] = $term['orderby']; } if (isset($term['_order'])) { $term_meta['_order'] = $term['_order']; } elseif (isset($term['order'])) { $term_meta['_order'] = $term['order']; } if (isset($term['cover_id'])) { $term_meta['_cover'] = (int) $term['cover_id'] ? $term['cover_id'] : ''; } foreach ($term_meta as $key => $value) { $gmDB->update_metadata('gmedia_term', $term_id, $key, $value); } $alert[] = sprintf(__('Album `%s` successfuly saved', 'grand-media'), $term['name']); } while (0); if (1 < $logic && $edit_term && $term_id) { $lib_data = array('album__in' => array($term_id), 'admin' => 1); if (!empty($data['per_page'])) { $lib_data['per_page'] = $data['per_page']; } $out = gmedia_ios_app_processor('library', $lib_data); } else { $out = gmedia_ios_app_library_data(array('filter', $taxonomy), $args); } } elseif ('gmedia_category' == $taxonomy) { if (!current_user_can('gmedia_category_manage')) { $out['error'] = array('code' => 'nocapability', 'title' => __("You can't do this", 'grand-media'), 'message' => __('You have no permission to do this operation', 'grand-media')); return $out; } $args = array(); if ($edit_term) { if (!current_user_can('gmedia_edit_others_media')) { $error[] = __('You are not allowed to edit others media', 'grand-media'); break; } $term['name'] = trim($term['name']); $term['term_id'] = intval($term['term_id']); if ($term['name'] && !$gmCore->is_digit($term['name'])) { if ($term_id = $gmDB->term_exists($term['term_id'], $taxonomy)) { $db_term = $gmDB->get_term($term_id); if ($db_term->name == $term['name'] || $db_term->name != $term['name'] && !$gmDB->term_exists($term['name'], $taxonomy)) { $term_id = $gmDB->update_term($term['term_id'], $term); if (is_wp_error($term_id)) { $error[] = $term_id->get_error_message(); $term_id = 0; } else { $alert[] = sprintf(__("Category %d successfuly updated", 'grand-media'), $term_id); $alert_info['terms'][$term_id] = $term['name']; if (1 < $logic) { $args['include'][] = $term_id; } $term_meta = array(); if (isset($term['_orderby'])) { $term_meta['_orderby'] = $term['_orderby']; } elseif (isset($term['orderby'])) { $term_meta['_orderby'] = $term['orderby']; } if (isset($term['_order'])) { $term_meta['_order'] = $term['_order']; } elseif (isset($term['order'])) { $term_meta['_order'] = $term['order']; } foreach ($term_meta as $key => $value) { $gmDB->update_metadata('gmedia_term', $term_id, $key, $value); } } } else { $error[] = __('A term with the name provided already exists', 'grand-media'); $error_info['terms'][$term_id] = $term['name']; } } else { $error[] = __("A term with the id provided does not exists", 'grand-media'); } } else { $error[] = __("Term name can't be only digits or empty", 'grand-media'); } } else { $terms = array_filter(array_map('trim', explode(',', $term['name']))); $terms_added = 0; $terms_qty = count($terms); foreach ($terms as $term_name) { if ($gmCore->is_digit($term_name)) { continue; } if (!($term_id = $gmDB->term_exists($term_name, $taxonomy))) { $term_id = $gmDB->insert_term($term_name, $taxonomy); if (is_wp_error($term_id)) { $error[] = $term_id->get_error_message(); $term_id = 0; } else { $alert['category_add'] = sprintf(__('%d of %d categories successfuly added', 'grand-media'), ++$terms_added, $terms_qty); $alert_info['terms'][$term_id] = $term_name; } } else { $alert['category_add'] = __('Some of provided categories are already exists', 'grand-media'); $alert_info['terms'][$term_id] = $term_name; } } } if (1 < $logic && $edit_term && $term_id) { $lib_data = array('category__in' => array($term_id), 'admin' => 1); if (!empty($data['per_page'])) { $lib_data['per_page'] = $data['per_page']; } $out = gmedia_ios_app_processor('library', $lib_data); } else { $out = gmedia_ios_app_library_data(array('filter', $taxonomy), $args); } } elseif ('gmedia_tag' == $taxonomy) { if (!current_user_can('gmedia_tag_manage')) { $out['error'] = array('code' => 'nocapability', 'title' => __("You can't do this", 'grand-media'), 'message' => __('You have no permission to do this operation', 'grand-media')); return $out; } $args = array(); if ($edit_term) { if (!current_user_can('gmedia_edit_others_media')) { $error[] = __('You are not allowed to edit others media', 'grand-media'); break; } $term['name'] = trim($term['name']); $term['term_id'] = intval($term['term_id']); if ($term['name'] && !$gmCore->is_digit($term['name'])) { if ($term_id = $gmDB->term_exists($term['term_id'], $taxonomy)) { if (!$gmDB->term_exists($term['name'], $taxonomy)) { $term_id = $gmDB->update_term($term['term_id'], $term); if (is_wp_error($term_id)) { $error[] = $term_id->get_error_message(); $term_id = 0; } else { $alert[] = sprintf(__("Tag %d successfuly updated", 'grand-media'), $term_id); $alert_info['terms'][$term_id] = $term['name']; } } else { $error[] = __('A term with the name provided already exists', 'grand-media'); $error_info['terms'][$term_id] = $term['name']; } } else { $error[] = __("A term with the id provided does not exists", 'grand-media'); } } else { $error[] = __("Term name can't be only digits or empty", 'grand-media'); } } else { $terms = array_filter(array_map('trim', explode(',', $term['name']))); $terms_added = 0; $terms_qty = count($terms); foreach ($terms as $term_name) { if ($gmCore->is_digit($term_name)) { continue; } if (!($term_id = $gmDB->term_exists($term_name, $taxonomy))) { $term_id = $gmDB->insert_term($term_name, $taxonomy); if (is_wp_error($term_id)) { $error[] = $term_id->get_error_message(); $term_id = 0; } else { $alert['tag_add'] = sprintf(__('%d of %d tags successfuly added', 'grand-media'), ++$terms_added, $terms_qty); $alert_info['terms'][$term_id] = $term_name; } } else { $alert['tag_add'] = __('Some of provided tags are already exists', 'grand-media'); $alert_info['terms'][$term_id] = $term_name; } } } if (1 < $logic && $edit_term && $term_id) { $lib_data = array('tag__in' => array($term_id), 'admin' => 1); if (!empty($data['per_page'])) { $lib_data['per_page'] = $data['per_page']; } $out = gmedia_ios_app_processor('library', $lib_data); } else { $out = gmedia_ios_app_library_data(array('filter', $taxonomy), $args); } } break; default: break; } if (!empty($error)) { $out['error'] = array('code' => $action, 'title' => 'ERROR', 'message' => implode("\n", $error)); if (!empty($error_info)) { $out['error'] = array_merge($out['error'], $error_info); } } if (!empty($alert)) { $out['alert'] = array('title' => 'Success', 'message' => implode("\n", $alert)); if (!empty($alert_info)) { $out['alert'] = array_merge($out['alert'], $alert_info); } } return $out; }
/** * gmediaTerms() * * @return mixed content */ function gmediaTerms() { global $user_ID, $gmDB, $gmCore, $gmGallery, $gmProcessor; $url = add_query_arg(array('page' => $gmProcessor->page), admin_url('admin.php')); $endpoint = $gmGallery->options['endpoint']; $gm_screen_options = get_user_meta($user_ID, 'gm_screen_options', true); if (!is_array($gm_screen_options)) { $gm_screen_options = array(); } $gm_screen_options = array_merge($gmGallery->options['gm_screen_options'], $gm_screen_options); $orderby = !empty($gm_screen_options['orderby_gmedia_terms']) ? $gm_screen_options['orderby_gmedia_terms'] : 'name'; $order = !empty($gm_screen_options['sortorder_gmedia_terms']) ? $gm_screen_options['sortorder_gmedia_terms'] : 'ASC'; $per_page = !empty($gm_screen_options['per_page_gmedia_terms']) ? $gm_screen_options['per_page_gmedia_terms'] : 30; $taxonomy = $gmCore->_get('term', 'gmedia_album'); if ($gmCore->caps['gmedia_show_others_media']) { $author = 0; } else { $author = $user_ID; } $filter = 'selected' == $gmCore->_req('filter') ? $gmProcessor->selected_items : null; $search_string = $gmCore->_get('s', ''); if ('#' == substr($search_string, 0, 1)) { $filter = substr($search_string, 1); $search_string = ''; } $args = array('orderby' => $gmCore->_get('orderby', $orderby), 'order' => $gmCore->_get('order', $order), 'search' => $search_string, 'number' => $gmCore->_get('number', $per_page), 'hide_empty' => $gmCore->_get('hide_empty', 0), 'page' => $gmCore->_get('pager', 1), 'include' => $filter); $args['offset'] = ($args['page'] - 1) * $args['number']; $allow_edit = 0; switch ($taxonomy) { case 'gmedia_filter': $args['hide_empty'] = 0; $allow_edit = $gmCore->caps['gmedia_filter_manage']; $args['global'] = $gmCore->_get('author', $gmCore->caps['gmedia_edit_others_media'] ? '' : array(0, $user_ID)); if (!$gmCore->caps['gmedia_show_others_media']) { $args['global'] = wp_parse_id_list($args['global']); $args['global'] = array_intersect(array(0, $user_ID), $args['global']); if (empty($args['global'])) { $args['global'] = array(0, $user_ID); } } break; case 'gmedia_album': $allow_edit = $gmCore->caps['gmedia_album_manage']; $args['global'] = $gmCore->_get('author', $gmCore->caps['gmedia_edit_others_media'] ? '' : array(0, $user_ID)); if (!$gmCore->caps['gmedia_show_others_media']) { $args['global'] = wp_parse_id_list($args['global']); $args['global'] = array_intersect(array(0, $user_ID), $args['global']); if (empty($args['global'])) { $args['global'] = array(0, $user_ID); } } break; case 'gmedia_tag': $allow_edit = $gmCore->caps['gmedia_tag_manage']; if ('global' == $args['orderby']) { $args['orderby'] = 'id'; } break; case 'gmedia_category': $args = array(); break; } $gmediaTerms = $gmDB->get_terms($taxonomy, $args); ?> <div class="panel panel-default" id="gmedia-panel"> <div class="panel-heading clearfix"> <?php if ('gmedia_category' != $taxonomy) { ?> <form class="form-inline gmedia-search-form" role="search" method="get"> <div class="form-group"> <input type="hidden" name="page" value="<?php echo $gmProcessor->page; ?> "/> <input type="hidden" name="term" value="<?php echo $taxonomy; ?> "/> <input id="gmedia-search" class="form-control input-sm" type="text" name="s" placeholder="<?php _e('Search...', 'gmLang'); ?> " value="<?php echo $gmCore->_get('s', ''); ?> "/> </div> <button type="submit" class="btn btn-default input-sm"><span class="glyphicon glyphicon-search"></span> </button> </form> <?php echo $gmDB->query_pager(); ?> <?php } ?> <div class="btn-toolbar pull-left"> <?php if ('gmedia_category' != $taxonomy) { ?> <div class="btn-group gm-checkgroup" id="cb_global-btn"> <span class="btn btn-default active"><input class="doaction" id="cb_global" data-group="cb_term-object" type="checkbox"/></span> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'gmLang'); ?> </span> </button> <ul class="dropdown-menu" role="menu"> <li><a data-select="total" href="#"><?php _e('All', 'gmLang'); ?> </a></li> <li><a data-select="none" href="#"><?php _e('None', 'gmLang'); ?> </a></li> <li class="divider"></li> <li><a data-select="reverse" href="#" title="<?php _e('Reverse only visible items', 'gmLang'); ?> "><?php _e('Reverse', 'gmLang'); ?> </a> </li> </ul> </div> <?php } ?> <?php switch ($taxonomy) { case 'gmedia_album': $button_title = __('Show: Albums', 'gmLang'); break; case 'gmedia_filter': $button_title = __('Show: Filters', 'gmLang'); break; case 'gmedia_tag': $button_title = __('Show: Tags', 'gmLang'); break; case 'gmedia_category': $button_title = __('Show: Categories', 'gmLang'); break; default: $button_title = __('Show: Albums', 'gmLang'); break; } ?> <div class="btn-group" style="margin-right:20px;"> <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> <?php echo $button_title; ?> <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li<?php if ('gmedia_album' == $taxonomy) { echo ' class="active"'; } ?> ><a href="<?php echo add_query_arg(array('term' => 'gmedia_album'), $url); ?> "><?php _e('Albums', 'gmLang'); ?> </a></li> <li<?php if ('gmedia_tag' == $taxonomy) { echo ' class="active"'; } ?> ><a href="<?php echo add_query_arg(array('term' => 'gmedia_tag'), $url); ?> "><?php _e('Tags', 'gmLang'); ?> </a></li> <li<?php if ('gmedia_category' == $taxonomy) { echo ' class="active"'; } ?> ><a href="<?php echo add_query_arg(array('term' => 'gmedia_category'), $url); ?> "><?php _e('Categories', 'gmLang'); ?> </a></li> <li class="divider"></li> <li<?php if ('gmedia_filter' == $taxonomy) { echo ' class="active"'; } ?> ><a href="<?php echo add_query_arg(array('term' => 'gmedia_filter'), $url); ?> "><?php _e('Custom Filters', 'gmLang'); ?> </a></li> </ul> </div> <?php if ('gmedia_filter' == $taxonomy) { ?> <a class="btn btn-success pull-left" href="<?php echo add_query_arg(array('edit_filter' => '0'), $url); ?> "><?php _e('Create Filter', 'gmLang'); ?> </a> <?php } ?> <?php if ('gmedia_category' != $taxonomy && !empty($gmediaTerms)) { ?> <div class="btn-group"> <a class="btn btn-default" href="#"><?php _e('Action', 'gmLang'); ?> </a> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'gmLang'); ?> </span> </button> <?php $rel_selected_show = 'rel-selected-show'; $rel_selected_hide = 'rel-selected-hide'; ?> <ul class="dropdown-menu" role="menu"> <li class="dropdown-header <?php echo $rel_selected_hide; ?> "> <span><?php _e("Select items to see more actions", "gmLang"); ?> </span></li> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_terms_delete']) { echo ' disabled'; } ?> "> <a href="<?php echo wp_nonce_url($gmCore->get_admin_url(array('delete' => 'selected'), array('filter')), 'gmedia_delete'); ?> " class="gmedia-delete" data-confirm="<?php _e("You are about to permanently delete the selected items.\n\r'Cancel' to stop, 'OK' to delete.", "gmLang"); ?> "><?php _e('Delete Selected Items', 'gmLang'); ?> </a> </li> <?php do_action('gmedia_term_action_list'); ?> </ul> </div> <form class="btn-group" id="gm-selected-btn" name="gm-selected-form" action="<?php echo add_query_arg(array('term' => $taxonomy, 'filter' => 'selected'), $url); ?> " method="post"> <button type="submit" class="btn btn<?php echo 'selected' == $gmCore->_req('filter') ? '-success' : '-info'; ?> "><?php printf(__('%s selected', 'gmLang'), '<span id="gm-selected-qty">' . count($gmProcessor->selected_items) . '</span>'); ?> </button> <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"><span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'gmLang'); ?> </span></button> <input type="hidden" id="gm-selected" data-userid="<?php echo $user_ID; ?> " data-key="<?php echo $taxonomy; ?> " name="selected_items" value="<?php echo implode(',', $gmProcessor->selected_items); ?> "/> <ul class="dropdown-menu" role="menu"> <li><a id="gm-selected-show" href="#show"><?php _e('Show only selected items', 'gmLang'); ?> </a> </li> <li><a id="gm-selected-clear" href="#clear"><?php _e('Clear selected items', 'gmLang'); ?> </a> </li> </ul> </form> <?php } ?> </div> </div> <?php if ('gmedia_album' == $taxonomy) { ?> <?php if ($allow_edit) { ?> <form method="post" id="gmedia-edit-term" name="gmAddTerms" class="panel-body" action="<?php echo $url; ?> " style="padding-bottom:0; border-bottom:1px solid #ddd;"> <div class="row"> <div class="col-xs-6"> <div class="form-group"> <label><?php _e('Name', 'gmLang'); ?> </label> <input type="text" class="form-control input-sm" name="term[name]" placeholder="<?php _e('Album Name', 'gmLang'); ?> " required/> </div> <div class="form-group"> <label><?php _e('Description', 'gmLang'); ?> </label> <textarea class="form-control input-sm" style="height:75px;" rows="2" name="term[description]"></textarea> </div> </div> <div class="col-xs-6"> <div class="form-group row"> <div class="col-xs-6"> <label><?php _e('Order gmedia', 'gmLang'); ?> </label> <select name="term[orderby]" class="form-control input-sm"> <option value="custom"><?php _e('user defined', 'gmLang'); ?> </option> <option selected="selected" value="ID"><?php _e('by ID', 'gmLang'); ?> </option> <option value="title ID"><?php _e('by title', 'gmLang'); ?> </option> <option value="gmuid"><?php _e('by filename', 'gmLang'); ?> </option> <option value="date ID"><?php _e('by date', 'gmLang'); ?> </option> <option value="modified ID"><?php _e('by last modified date', 'gmLang'); ?> </option> <option value="rand"><?php _e('Random', 'gmLang'); ?> </option> </select> </div> <div class="col-xs-6"> <label><?php _e('Sort order', 'gmLang'); ?> </label> <select name="term[order]" class="form-control input-sm"> <option selected="selected" value="DESC"><?php _e('DESC', 'gmLang'); ?> </option> <option value="ASC"><?php _e('ASC', 'gmLang'); ?> </option> </select> </div> </div> <div class="row"> <div class="form-group col-xs-6"> <label><?php _e('Status', 'gmLang'); ?> </label> <select name="term[status]" class="form-control input-sm"> <option selected="selected" value="public"><?php _e('Public', 'gmLang'); ?> </option> <option value="private"><?php _e('Private', 'gmLang'); ?> </option> <option value="draft"><?php _e('Draft', 'gmLang'); ?> </option> </select> </div> <div class="col-xs-6"> <div class="form-group"> <label><?php _e('Author', 'gmLang'); ?> </label> <?php $user_ids = $gmCore->caps['gmedia_delete_others_media'] ? $gmCore->get_editable_user_ids() : array($user_ID); if ($user_ids && $gmCore->caps['gmedia_edit_others_media']) { if (!in_array($user_ID, $user_ids)) { array_push($user_ids, $user_ID); } wp_dropdown_users(array('include' => $user_ids, 'include_selected' => true, 'name' => 'term[global]', 'selected' => $user_ID, 'class' => 'form-control input-sm', 'multi' => true, 'show_option_all' => __('Shared', 'gmLang'))); } else { echo '<input type="hidden" name="term[global]" value="' . $user_ID . '"/>'; echo '<div>' . get_the_author_meta('display_name', $user_ID) . '</div>'; } ?> </div> <div class="form-group"> <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('GmediaTerms', 'term_save_wpnonce'); ?> <input type="hidden" name="term[taxonomy]" value="gmedia_album"/> <button style="display:block" type="submit" class="btn btn-primary btn-sm" name="gmedia_album_save"><?php _e('Add New Album', 'gmLang'); ?> </button> </div> </div> </div> </div> </div> </form> <?php } else { ?> <div class="alert alert-warning alert-dismissible" role="alert" style="margin-bottom:0"> <button type="button" class="close" data-dismiss="alert"> <span aria-hidden="true">×</span><span class="sr-only"><?php _e('Close', 'gmLang'); ?> </span> </button> <strong><?php _e('Info:', 'gmLang'); ?> </strong> <?php _e('You are not allowed to add new terms', 'gmLang'); ?> </div> <?php } ?> <form class="list-group" id="gm-list-table" style="margin-bottom:4px;"> <?php if (count($gmediaTerms)) { foreach ($gmediaTerms as $item) { $termItems = array(); $per_page = 7; if ($item->count) { $term_meta = $gmDB->get_metadata('gmedia_term', $item->term_id); $term_meta = array_map('reset', $term_meta); $term_meta = array_merge(array('orderby' => 'ID', 'order' => 'DESC'), $term_meta); /* $term_meta_default = array('orderby' => 'ID', 'order' => 'DESC'); $term_meta = array_intersect_key($term_meta, $term_meta_default) + $term_meta_default; */ $args = array('no_found_rows' => true, 'per_page' => $per_page, 'album__in' => array($item->term_id), 'author' => $author, 'orderby' => $term_meta['orderby'], 'order' => $term_meta['order']); $termItems = $gmDB->get_gmedias($args); } $is_selected = in_array($item->term_id, $gmProcessor->selected_items) ? true : false; $author_name = ''; $list_row_class = $row_class = ''; $allow_terms_delete = $gmCore->caps['gmedia_terms_delete']; if ($item->global) { if ($display_author_name = get_the_author_meta('display_name', $item->global)) { $author_name .= sprintf(__('by %s', 'gmLang'), $display_author_name); } else { $author_name .= '(' . __('deleted author', 'gmLang') . ')'; } if ($item->global == $user_ID) { $row_class .= ' current_user'; $allow_edit = $gmCore->caps['gmedia_album_manage']; $allow_delete = $allow_terms_delete; } else { $row_class .= ' other_user'; $allow_edit = $gmCore->caps['gmedia_edit_others_media']; $allow_delete = $allow_edit && $allow_terms_delete; } } else { $author_name .= '(' . __('no author', 'gmLang') . ')'; $row_class .= ' shared'; $allow_edit = $gmCore->caps['gmedia_edit_others_media']; $allow_delete = $allow_edit && $allow_terms_delete; } if ('public' != $item->status) { $author_name .= ' [' . $item->status . ']'; if ('private' == $item->status) { $list_row_class = ' list-group-item-info'; } elseif ('draft' == $item->status) { $list_row_class = ' list-group-item-warning'; } } ?> <div class="list-group-item term-list-item<?php echo $is_selected ? ' active-row' : ''; echo $list_row_class; ?> "> <div class="row cb_term-object<?php echo $row_class; ?> "> <div class="term_id">#<?php echo $item->term_id; ?> </div> <div class="col-xs-6 term-label"> <div class="checkbox"> <input name="doaction[]" type="checkbox"<?php echo $is_selected ? ' checked="checked"' : ''; ?> value="<?php echo $item->term_id; ?> "/> <?php if ($allow_edit) { ?> <a class="term_name" href="<?php echo add_query_arg(array('edit_album' => $item->term_id), $url); ?> "><?php echo esc_html($item->name); ?> </a> <?php } else { ?> <span class="term_name"><?php echo esc_html($item->name); ?> </span> <?php } ?> <span class="term_info_author"><?php echo $author_name; ?> </span> <div class="object-actions"> <?php $filter_icon = '<span class="badge">' . $item->count . '</span>'; if ($item->count) { echo '<a title="' . __('Filter in Gmedia Library', 'gmLang') . '" href="' . $gmCore->get_admin_url(array('page' => 'GrandMedia', 'alb' => $item->term_id), array(), true) . '">' . $filter_icon . '</a>'; } else { echo $filter_icon; } $gmedia_hashid = gmedia_hash_id_encode($item->term_id, 'album'); if (get_option('permalink_structure')) { $cloud_link = home_url(urlencode($endpoint) . '/a/' . $gmedia_hashid); } else { $cloud_link = add_query_arg(array("{$endpoint}" => $gmedia_hashid, 't' => 'a'), home_url('index.php')); } $share_icon = '<span class="glyphicon glyphicon-share"></span>'; if ('draft' !== $item->status) { echo '<a target="_blank" data-target="#shareModal" data-share="' . $item->term_id . '" class="share-modal" title="' . __('Share', 'gmLang') . '" href="' . $cloud_link . '">' . $share_icon . '</a>'; } else { echo "<span class='action-inactive'>{$share_icon}</span>"; } $edit_icon = '<span class="glyphicon glyphicon-edit"></span>'; if ($allow_edit) { echo '<a title="' . __('Edit', 'gmLang') . '" href="' . add_query_arg(array('edit_album' => $item->term_id), $url) . '">' . $edit_icon . '</a>'; } else { echo "<span class='action-inactive'>{$edit_icon}</span>"; } if ($allow_terms_delete) { $trash_icon = '<span class="glyphicon glyphicon-trash"></span>'; if ($allow_delete) { echo '<a class="trash-icon" title="' . __('Delete', 'gmLang') . '" href="' . wp_nonce_url(add_query_arg(array('term' => $taxonomy, 'delete' => $item->term_id), $url), 'gmedia_delete') . '" data-confirm="' . __("You are about to permanently delete the selected items.\n\r'Cancel' to stop, 'OK' to delete.", "gmLang") . '">' . $trash_icon . '</a>'; } else { echo "<span class='action-inactive'>{$trash_icon}</span>"; } } ?> </div> </div> </div> <div class="col-xs-6"> <div class="term-images"> <?php if (!empty($termItems)) { foreach ($termItems as $i) { ?> <img style="z-index:<?php echo $per_page--; ?> ;" src="<?php echo $gmCore->gm_get_media_image($i, 'thumb', false); ?> " alt="<?php echo $i->ID; ?> " title="<?php echo esc_attr($i->title); ?> "/> <?php } } if (count($termItems) < $item->count) { echo '...'; } ?> </div> </div> </div> <?php if (!empty($item->description)) { ?> <div class="term-description"><?php echo nl2br(esc_html($item->description)); ?> </div> <?php } ?> </div> <?php } } else { ?> <div class="list-group-item"> <div class="well well-lg text-center"> <h4><?php _e('No items to show.', 'gmLang'); ?> </h4> </div> </div> <?php } ?> <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('GmediaTerms'); ?> </form> <?php } elseif ('gmedia_filter' == $taxonomy) { ?> <form class="list-group" id="gm-list-table" style="margin-bottom:4px;"> <?php if (count($gmediaTerms)) { foreach ($gmediaTerms as $item) { $term_query = $gmDB->get_metadata('gmedia_term', $item->term_id, 'query', true); $is_selected = in_array($item->term_id, $gmProcessor->selected_items) ? true : false; $author_name = ''; $row_class = ''; $allow_terms_delete = $gmCore->caps['gmedia_terms_delete']; if ($item->global) { if ($display_author_name = get_the_author_meta('display_name', $item->global)) { $author_name .= sprintf(__('by %s', 'gmLang'), $display_author_name); } else { $author_name .= '(' . __('deleted author', 'gmLang') . ')'; } if ($item->global == $user_ID) { $row_class .= ' current_user'; $allow_edit = $gmCore->caps['gmedia_filter_manage']; $allow_delete = $allow_terms_delete; } else { $row_class .= ' other_user'; $allow_edit = $gmCore->caps['gmedia_edit_others_media']; $allow_delete = $allow_edit && $allow_terms_delete; } } else { $author_name .= '(' . __('no author', 'gmLang') . ')'; $row_class .= ' shared'; $allow_edit = $gmCore->caps['gmedia_edit_others_media']; $allow_delete = $allow_edit && $allow_terms_delete; } ?> <div class="list-group-item term-list-item<?php echo $is_selected ? ' active-row' : ''; ?> "> <div class="row cb_term-object<?php echo $row_class; ?> "> <div class="term_id">#<?php echo $item->term_id; ?> </div> <div class="col-xs-6 term-label"> <div class="checkbox"> <input name="doaction[]" type="checkbox"<?php echo $is_selected ? ' checked="checked"' : ''; ?> value="<?php echo $item->term_id; ?> "/> <?php if ($allow_edit) { ?> <a class="term_name" href="<?php echo add_query_arg(array('edit_filter' => $item->term_id), $url); ?> "><?php echo esc_html($item->name); ?> </a> <?php } else { ?> <span class="term_name"><?php echo esc_html($item->name); ?> </span> <?php } ?> <span class="term_info_author"><?php echo $author_name; ?> </span> <div class="object-actions"> <?php $filter_icon = '<span class="glyphicon glyphicon-filter"></span>'; echo '<a title="' . __('Filter in Gmedia Library', 'gmLang') . '" href="' . $gmCore->get_admin_url(array('page' => 'GrandMedia', 'custom_filter' => $item->term_id), array(), true) . '">' . $filter_icon . '</a>'; $gmedia_hashid = gmedia_hash_id_encode($item->term_id, 'filter'); if (get_option('permalink_structure')) { $cloud_link = home_url(urlencode($endpoint) . '/f/' . $gmedia_hashid); } else { $cloud_link = add_query_arg(array("{$endpoint}" => $gmedia_hashid, 't' => 'f'), home_url('index.php')); } $share_icon = '<span class="glyphicon glyphicon-share"></span>'; echo '<a target="_blank" data-target="#shareModal" data-share="' . $item->term_id . '" class="share-modal" title="' . __('Share', 'gmLang') . '" href="' . $cloud_link . '">' . $share_icon . '</a>'; $edit_icon = '<span class="glyphicon glyphicon-edit"></span>'; if ($allow_edit) { echo '<a title="' . __('Edit', 'gmLang') . '" href="' . add_query_arg(array('edit_filter' => $item->term_id), $url) . '">' . $edit_icon . '</a>'; } else { echo "<span class='action-inactive'>{$edit_icon}</span>"; } if ($allow_terms_delete) { $trash_icon = '<span class="glyphicon glyphicon-trash"></span>'; if ($allow_delete) { echo '<a class="trash-icon" title="' . __('Delete', 'gmLang') . '" href="' . wp_nonce_url(add_query_arg(array('term' => $taxonomy, 'delete' => $item->term_id), $url), 'gmedia_delete') . '" data-confirm="' . __("You are about to permanently delete the selected items.\n\r'Cancel' to stop, 'OK' to delete.", "gmLang") . '">' . $trash_icon . '</a>'; } else { echo "<span class='action-inactive'>{$trash_icon}</span>"; } } ?> </div> </div> </div> <div class="col-xs-6"> <p class="term-meta" style="margin:10px 0;"> <?php echo '<b>' . __('Query:') . "</b> " . str_replace(',"', ', "', json_encode($term_query)); ?> </p> </div> </div> <?php if (!empty($item->description)) { ?> <div class="term-description"><?php echo nl2br(esc_html($item->description)); ?> </div> <?php } ?> </div> <?php } } else { ?> <div class="list-group-item"> <div class="well well-lg text-center"> <h4><?php _e('No items to show.', 'gmLang'); ?> </h4> </div> </div> <?php } ?> <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('GmediaTerms'); ?> </form> <?php } elseif ('gmedia_tag' == $taxonomy) { ?> <?php if ($allow_edit) { ?> <form method="post" id="gmedia-edit-term" name="gmAddTerms" class="panel-body" action="<?php echo add_query_arg(array('term' => $taxonomy), $url); ?> " style="padding-bottom:0; border-bottom:1px solid #ddd;"> <div class="row"> <div class="form-group col-xs-9"> <label><?php _e('Tags', 'gmLang'); ?> <small class="text-muted">(<?php _e('you can type multiple tags separated by comma'); ?> ) </small> </label> <input type="text" class="form-control input-sm" name="term[name]" placeholder="<?php _e('Tag Names', 'gmLang'); ?> " required/> </div> <div class="col-xs-3" style="padding-top:24px;"> <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('GmediaTerms', 'term_save_wpnonce'); ?> <input type="hidden" name="term[taxonomy]" value="gmedia_tag"/> <button type="submit" class="btn btn-primary btn-sm" name="gmedia_tag_add"><?php _e('Add New Tags', 'gmLang'); ?> </button> </div> </div> </form> <?php } else { ?> <div class="alert alert-warning alert-dismissible" role="alert" style="margin-bottom:0"> <button type="button" class="close" data-dismiss="alert"> <span aria-hidden="true">×</span><span class="sr-only"><?php _e('Close', 'gmLang'); ?> </span> </button> <strong><?php _e('Info:', 'gmLang'); ?> </strong> <?php _e('You are not allowed to add new terms', 'gmLang'); ?> </div> <?php } ?> <form class="list-group" id="gm-list-table" style="margin-bottom:4px;"> <?php if (count($gmediaTerms)) { if ($gmCore->caps['gmedia_edit_others_media']) { $allow_edit = true; $allow_delete = $gmCore->caps['gmedia_terms_delete']; } else { $allow_edit = false; $allow_delete = false; } foreach ($gmediaTerms as $item) { $termItems = array(); $per_page = 5; if ($item->count) { $args = array('no_found_rows' => true, 'per_page' => $per_page, 'orderby' => $gmGallery->options['in_tag_orderby'], 'order' => $gmGallery->options['in_tag_order'], 'tag_id' => $item->term_id, 'author' => $author); $termItems = $gmDB->get_gmedias($args); } $is_selected = in_array($item->term_id, $gmProcessor->selected_items) ? true : false; ?> <div class="list-group-item term-list-item<?php echo $is_selected ? ' active-row' : ''; ?> "> <div class="row cb_term-object" id="tag_<?php echo $item->term_id; ?> "> <div class="term_id">#<?php echo $item->term_id; ?> </div> <div class="col-xs-6 term-label"> <div class="checkbox"> <input name="doaction[]" type="checkbox"<?php echo $is_selected ? ' checked="checked"' : ''; ?> value="<?php echo $item->term_id; ?> "/> <?php if ($allow_edit) { ?> <a class="edit_tag_link" href="#tag_<?php echo $item->term_id; ?> "><?php echo esc_html($item->name); ?> </a> <span class="edit_tag_form" style="display:none;"><input class="edit_tag_input" type="text" data-tag_id="<?php echo $item->term_id; ?> " name="gmedia_tag_name[<?php echo $item->term_id; ?> ]" value="<?php echo esc_attr($item->name); ?> " placeholder="<?php echo esc_attr($item->name); ?> "/><a href="#tag_<?php echo $item->term_id; ?> " class="edit_tag_save btn btn-link glyphicon glyphicon-pencil"></a></span> <?php } else { ?> <span><?php echo esc_html($item->name); ?> </span> <?php } ?> <div class="object-actions"> <?php $filter_icon = '<span class="badge">' . $item->count . '</span>'; if ($item->count) { echo '<a title="' . __('Filter in Gmedia Library', 'gmLang') . '" href="' . $gmCore->get_admin_url(array('page' => 'GrandMedia', 'tag__in' => $item->term_id), array(), true) . '">' . $filter_icon . '</a>'; } else { echo $filter_icon; } $gmedia_hashid = gmedia_hash_id_encode($item->term_id, 'tag'); if (get_option('permalink_structure')) { $cloud_link = home_url(urlencode($endpoint) . '/t/' . $gmedia_hashid); } else { $cloud_link = add_query_arg(array("{$endpoint}" => $gmedia_hashid, 't' => 't'), home_url('index.php')); } $share_icon = '<span class="glyphicon glyphicon-share"></span>'; echo '<a target="_blank" data-target="#shareModal" data-share="' . $item->term_id . '" class="share-modal" title="' . __('Share', 'gmLang') . '" href="' . $cloud_link . '">' . $share_icon . '</a>'; /* $edit_icon = '<span class="glyphicon glyphicon-edit"></span>'; if ( $allow_edit ){ echo '<a class="edit_tag_link" title="' . __('Edit', 'gmLang') . '" href="#tag_' . $item->term_id . '">'.$edit_icon.'</a>'; } */ if ($allow_delete) { $trash_icon = '<span class="glyphicon glyphicon-trash"></span>'; echo '<a title="' . __('Delete', 'gmLang') . '" href="' . wp_nonce_url(add_query_arg(array('term' => $taxonomy, 'delete' => $item->term_id), $url), 'gmedia_delete') . '">' . $trash_icon . '</a>'; } ?> </div> </div> </div> <div class="col-xs-6 term-images"> <?php if (!empty($termItems)) { foreach ($termItems as $i) { ?> <img style="z-index:<?php echo $per_page--; ?> ;" src="<?php echo $gmCore->gm_get_media_image($i, 'thumb', false); ?> " alt="<?php echo $i->ID; ?> " title="<?php echo esc_attr($i->title); ?> "/> <?php } } if (count($termItems) < $item->count) { echo '...'; } ?> </div> </div> </div> <?php } ?> <?php if ($allow_edit) { ?> <script type="text/javascript"> jQuery(function($){ $('#gm-list-table').data('edit', false); $('input.edit_tag_input').keypress(function(e){ var tagdiv = $('#tag_' + $(this).data('tag_id')); var charCode = e.charCode || e.keyCode || e.which; if(charCode == 13){ e.preventDefault(); edit_tag(tagdiv); } }).blur(function(e){ var tagdiv = $('#tag_' + $(this).data('tag_id')); edit_tag(tagdiv); }); $('.edit_tag_link').click(function(e){ e.preventDefault(); var id = $(this).attr('href'); $(this).hide(); $(id).find('.edit_tag_form').show().find('input').focus(); $('#gm-list-table').data('edit', true); }); $('.edit_tag_save').click(function(e){ e.preventDefault(); }); function edit_tag(tagdiv){ var inp = tagdiv.find('.edit_tag_form input'); var new_tag_name = $.trim(inp.val()); var old_tag_name = inp.attr('placeholder'); if((old_tag_name == new_tag_name) || ('' === new_tag_name) || $.isNumeric()){ inp.val(old_tag_name); tagdiv.find('.edit_tag_form').hide(); tagdiv.find('.edit_tag_link').show(); return; } var post_data = { action: 'gmedia_tag_edit', tag_id: inp.data('tag_id'), tag_name: new_tag_name, _wpnonce: $('#_wpnonce').val() }; $.post(ajaxurl, post_data, function(data, textStatus, jqXHR){ console.log(data); if(data.error){ //inp.val(inp.attr('placeholder')); $('#gmedia-panel').before(data.error); } else{ //new_tag_name = new_tag_name.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); inp.attr('placeholder', new_tag_name); tagdiv.find('.edit_tag_link').text(new_tag_name).show(); $('#gmedia-panel').before(data.msg); tagdiv.find('.edit_tag_form').hide(); } }); } }); </script> <?php } ?> <?php } else { ?> <div class="list-group-item"> <div class="well well-lg text-center"> <h4><?php _e('No items to show.', 'gmLang'); ?> </h4> </div> </div> <?php } ?> <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('GmediaTerms'); ?> </form> <?php } elseif ('gmedia_category' == $taxonomy) { ?> <div class="panel-body"></div> <div class="list-group" id="gm-list-table" style="margin-bottom:4px;"> <?php $gmediaCategories = $gmGallery->options['taxonomies']['gmedia_category']; foreach ($gmediaTerms as $item) { $cat[$item->name] = $item; } unset($gmediaTerms); foreach ($gmediaCategories as $name => $title) { $termItems = array(); $per_page = 10; if (isset($cat[$name])) { $count = $cat[$name]->count; $term_id = $cat[$name]->term_id; if ($count) { $args = array('no_found_rows' => true, 'per_page' => $per_page, 'orderby' => $gmGallery->options['in_category_orderby'], 'order' => $gmGallery->options['in_category_order'], 'category__in' => array($term_id), 'author' => $author); $termItems = $gmDB->get_gmedias($args); } } else { $count = 0; $term_id = '##'; } ?> <div class="list-group-item term-list-item"> <div class="row cb_term-object"> <div class="term_id">#<?php echo $term_id; ?> </div> <div class="col-xs-6" style="padding-top:10px; padding-bottom:10px;"> <?php echo esc_html($title); ?> <div class="object-actions"> <?php $filter_icon = '<span class="badge">' . $count . '</span>'; if ($count) { echo '<a title="' . __('Filter in Gmedia Library', 'gmLang') . '" href="' . $gmCore->get_admin_url(array('page' => 'GrandMedia', 'cat' => $term_id), array(), true) . '">' . $filter_icon . '</a>'; } else { echo $filter_icon; } $share_icon = '<span class="glyphicon glyphicon-share"></span>'; if (isset($cat[$name]->term_id)) { $gmedia_hashid = gmedia_hash_id_encode($term_id, 'tag'); if (get_option('permalink_structure')) { $cloud_link = home_url(urlencode($endpoint) . '/k/' . $gmedia_hashid); } else { $cloud_link = add_query_arg(array("{$endpoint}" => $gmedia_hashid, 't' => 'k'), home_url('index.php')); } echo '<a target="_blank" data-target="#shareModal" data-share="' . $term_id . '" class="share-modal" title="' . __('Share', 'gmLang') . '" href="' . $cloud_link . '">' . $share_icon . '</a>'; } else { echo "<span class='action-inactive'>{$share_icon}</span>"; } /* $edit_icon = '<span class="glyphicon glyphicon-edit"></span>'; echo '<a title="' . __('Edit', 'gmLang') . '" href="' . add_query_arg( array( 'edit_album' => $item->term_id ), $url ) . '">'.$edit_icon.'</a>'; */ ?> </div> </div> <div class="col-xs-6 term-images"> <?php if (!empty($termItems)) { foreach ($termItems as $i) { ?> <img style="z-index:<?php echo $per_page--; ?> ;" src="<?php echo $gmCore->gm_get_media_image($i, 'thumb', false); ?> " alt="<?php echo $i->ID; ?> " title="<?php echo esc_attr($i->title); ?> "/> <?php } } if (count($termItems) < $count) { echo '...'; } ?> </div> </div> </div> <?php } ?> </div> <?php } ?> </div> <div class="modal fade gmedia-modal" id="shareModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title"><?php _e('GmediaCloud Page'); ?> </h4> </div> <form class="modal-body" method="post" id="shareForm"> <div class="form-group"> <label><?php _e('Link to page', 'gmLang'); ?> </label> <input name="sharelink" type="text" class="form-control sharelink" readonly="readonly" value=""/> </div> <div class="form-group"> <label><?php _e('Send this link to', 'gmLang'); ?> </label> <input name="email" type="email" class="form-control sharetoemail" value="" placeholder="<?php _e('Email', 'gmLang'); ?> "/> <textarea name="message" cols="20" rows="3" class="form-control" placeholder="<?php _e('Message (optional)', 'gmLang'); ?> "></textarea> </div> <input type="hidden" name="action" value="gmedia_share_page"/> <?php wp_nonce_field('share_modal', '_sharenonce'); ?> </form> <div class="modal-footer"> <button type="button" class="btn btn-primary sharebutton" disabled="disabled"><?php _e('Send', 'gmLang'); ?> </button> <button type="button" class="btn btn-default" data-dismiss="modal"><?php _e('Close', 'gmLang'); ?> </button> </div> </div> </div> </div> <?php }
/** * gmediaLib() * * @return mixed content */ function gmediaLib() { global $user_ID, $gmDB, $gmCore, $gmGallery, $gmProcessor; $url = add_query_arg(array('page' => $gmProcessor->page, 'mode' => $gmProcessor->mode), admin_url('admin.php')); $endpoint = $gmGallery->options['endpoint']; $gm_screen_options = get_user_meta($user_ID, 'gm_screen_options', true); if (!is_array($gm_screen_options)) { $gm_screen_options = array(); } $gm_screen_options = array_merge($gmGallery->options['gm_screen_options'], $gm_screen_options); if ($gmCore->caps['gmedia_show_others_media']) { if ($author = $gmCore->_get('author')) { $author = wp_parse_id_list($author); } } else { $author = array($user_ID); } $gmedia__in = $gmCore->_get('gmedia__in', null); $search_string = $gmCore->_get('s', null); if ('#' == substr($search_string, 0, 1)) { $gmedia__in = substr($search_string, 1); $search_string = null; } $orderby = $gm_screen_options['orderby_gmedia']; $order = $gm_screen_options['sortorder_gmedia']; if ('selected' == $gmCore->_req('filter') && !empty($gmProcessor->selected_items)) { $gmedia__in = $gmProcessor->selected_items; $orderby = 'gmedia__in'; $order = 'ASC'; } $args = array('mime_type' => $gmCore->_get('mime_type', null), 'orderby' => $orderby, 'order' => $order, 'per_page' => $gm_screen_options['per_page_gmedia'], 'page' => $gmCore->_get('pager', 1), 'tag_id' => $gmCore->_get('tag_id', null), 'tag__in' => $gmCore->_get('tag__in', null), 'cat' => $gmCore->_get('cat', null), 'category__in' => $gmCore->_get('category__in', null), 'alb' => $gmCore->_get('alb', null), 'album__in' => $gmCore->_get('album__in', null), 'author__in' => $author, 'gmedia__in' => $gmedia__in, 's' => $search_string); $custom_filter = false; if ($filter_id = (int) $gmCore->_get('custom_filter', 0)) { if ($gmedia_filter = $gmDB->get_term($filter_id, 'gmedia_filter')) { if ($gmedia_filter->global == $user_ID || $gmCore->caps['gmedia_show_others_media']) { $_args = $gmDB->get_metadata('gmedia_term', $gmedia_filter->term_id, 'query', true); $args = array_merge($args, $_args); $custom_filter = $gmedia_filter->name; } else { echo $gmProcessor->alert('danger', __('You are not allowed to see others media', 'gmLang')); } } } $gmediaQuery = $gmDB->get_gmedias($args); $gm_qty = array('total' => '', 'image' => '', 'audio' => '', 'video' => '', 'text' => '', 'application' => '', 'other' => ''); $gmDbCount = $gmDB->count_gmedia(); foreach ($gmDbCount as $key => $value) { $gm_qty[$key] = '<span class="badge pull-right">' . (int) $value . '</span>'; } ?> <?php if (!empty($author)) { ?> <div class="custom-message alert alert-info" xmlns="http://www.w3.org/1999/html"> <strong><?php _e('Selected Authors:', 'gmLang'); ?> </strong> <?php $sep = ''; foreach ($author as $a) { echo $sep . '<a href="#libModal" data-modal="filter_authors" data-action="gmedia_get_modal" class="gmedia-modal">' . get_the_author_meta('display_name', $a) . '</a>'; $sep = ', '; } ?> </div> <?php } ?> <?php if ($custom_filter) { ?> <div class="custom-message alert alert-info" xmlns="http://www.w3.org/1999/html"> <strong><?php _e('Selected Filter:', 'gmLang'); ?> </strong> <a href="#libModal" data-modal="custom_filters" data-action="gmedia_get_modal" class="gmedia-modal"><?php echo $custom_filter; ?> </a> </div> <?php } ?> <div class="panel panel-default" id="gmedia-panel"> <div class="panel-heading clearfix"> <form class="form-inline gmedia-search-form" role="search"> <div class="form-group"> <?php foreach ($_GET as $key => $value) { if (in_array($key, array('page', 'mode', 'author', 'mime_type', 'tag_id', 'tag__in', 'cat', 'category__in', 'alb', 'album__in'))) { ?> <input type="hidden" name="<?php echo $key; ?> " value="<?php echo $value; ?> "/> <?php } } ?> <input id="gmedia-search" class="form-control input-sm" type="text" name="s" placeholder="<?php _e('Search...', 'gmLang'); ?> " value="<?php echo $gmCore->_get('s', ''); ?> "/> </div> <button type="submit" class="btn btn-default input-sm"><span class="glyphicon glyphicon-search"></span></button> </form> <?php echo $gmDB->query_pager(); ?> <div class="btn-toolbar pull-left"> <?php if (!$gmProcessor->mode) { ?> <div class="btn-group gm-checkgroup" id="cb_global-btn"> <span class="btn btn-default active"><input class="doaction" id="cb_global" data-group="cb_media-object" type="checkbox"/></span> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'gmLang'); ?> </span></button> <ul class="dropdown-menu" role="menu"> <li><a data-select="total" href="#"><?php _e('All', 'gmLang'); ?> </a></li> <li><a data-select="none" href="#"><?php _e('None', 'gmLang'); ?> </a></li> <li class="divider"></li> <li><a data-select="image" href="#"><?php _e('Images', 'gmLang'); ?> </a></li> <li><a data-select="audio" href="#"><?php _e('Audio', 'gmLang'); ?> </a></li> <li><a data-select="video" href="#"><?php _e('Video', 'gmLang'); ?> </a></li> <li class="divider"></li> <li><a data-select="reverse" href="#" title="<?php _e('Reverse only visible items', 'gmLang'); ?> "><?php _e('Reverse', 'gmLang'); ?> </a></li> </ul> </div> <?php } ?> <div class="btn-group"> <?php $curr_mime = explode(',', $gmCore->_get('mime_type', 'total')); ?> <?php if ($gmDB->filter) { ?> <a class="btn btn-warning" title="<?php _e('Reset Filter', 'gmLang'); ?> " rel="total" href="<?php echo $url; ?> "><?php _e('Filter', 'gmLang'); ?> </a> <?php } else { ?> <button type="button" class="btn btn-default"><?php _e('Filter', 'gmLang'); ?> </button> <?php } ?> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'gmLang'); ?> </span> </button> <ul class="dropdown-menu" role="menu"> <li role="presentation" class="dropdown-header"><?php _e('FILTER BY AUTHOR', 'gmLang'); ?> </li> <li class="gmedia_author"> <a href="#libModal" data-modal="filter_authors" data-action="gmedia_get_modal" class="gmedia-modal"><?php if (!empty($author)) { $sep = ''; foreach ($author as $a) { echo $sep . get_the_author_meta('display_name', $a); $sep = ', '; } } else { _e('Show all authors', 'gmLang'); } ?> </a></li> <li role="presentation" class="dropdown-header"><?php _e('TYPE', 'gmLang'); ?> </li> <li class="total<?php if (in_array('total', $curr_mime)) { echo ' active'; } ?> "><a rel="total" href="<?php echo $gmCore->get_admin_url(array(), array('mime_type', 'pager')); ?> "><?php echo $gm_qty['total']; _e('All', 'gmLang'); ?> </a></li> <li class="image<?php if (in_array('image', $curr_mime)) { echo ' active'; } if (!$gmDbCount['image']) { echo ' disabled'; } ?> "><a rel="image" href="<?php echo $gmCore->get_admin_url(array('mime_type' => 'image'), array('pager')); ?> "><?php echo $gm_qty['image']; _e('Images', 'gmLang'); ?> </a></li> <li class="audio<?php if (in_array('audio', $curr_mime)) { echo ' active'; } if (!$gmDbCount['audio']) { echo ' disabled'; } ?> "><a rel="audio" href="<?php echo $gmCore->get_admin_url(array('mime_type' => 'audio'), array('pager')); ?> "><?php echo $gm_qty['audio']; _e('Audio', 'gmLang'); ?> </a></li> <li class="video<?php if (in_array('video', $curr_mime)) { echo ' active'; } if (!$gmDbCount['video']) { echo ' disabled'; } ?> "><a rel="video" href="<?php echo $gmCore->get_admin_url(array('mime_type' => 'video'), array('pager')); ?> "><?php echo $gm_qty['video']; _e('Video', 'gmLang'); ?> </a></li> <li class="application<?php if (in_array('application', $curr_mime) || in_array('text', $curr_mime)) { echo ' active'; } if (!$gmDbCount['application']) { echo ' disabled'; } ?> "> <a rel="application" href="<?php echo $gmCore->get_admin_url(array('mime_type' => 'application,text'), array('pager')); ?> "><?php echo $gm_qty['other']; _e('Other', 'gmLang'); ?> </a></li> <li role="presentation" class="dropdown-header"><?php _e('COLLECTIONS', 'gmLang'); ?> </li> <li class="filter_categories<?php if (isset($gmDB->filter_tax['gmedia_category'])) { echo ' active'; } ?> "> <a href="#libModal" data-modal="filter_categories" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Categories', 'gmLang'); ?> </a> </li> <li class="filter_albums<?php if (isset($gmDB->filter_tax['gmedia_album'])) { echo ' active'; } ?> "><a href="#libModal" data-modal="filter_albums" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Albums', 'gmLang'); ?> </a></li> <li class="filter_tags<?php if (isset($gmDB->filter_tax['gmedia_tag'])) { echo ' active'; } ?> "><a href="#libModal" data-modal="filter_tags" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Tags', 'gmLang'); ?> </a></li> <li class="divider"></li> <li class="custom_filters"><a href="#libModal" data-modal="custom_filters" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Custom Filters', 'gmLang'); ?> </a></li> <?php do_action('gmedia_filter_list'); ?> </ul> </div> <div class="btn-group"> <?php if (!$gmProcessor->mode) { $args = array('mode' => 'edit'); $edit_mode_href = $gmCore->get_admin_url($args); $args2 = array('mode' => 'edit', 'filter' => 'selected', 'pager' => false, 's' => false); $edit_mode_data = 'data-href="' . $edit_mode_href . '" data-href_sel="' . $gmCore->get_admin_url($args2) . '"'; } else { $edit_mode_href = $gmCore->get_admin_url(array(), array('mode')); $edit_mode_data = ''; } ?> <?php if ($gmCore->caps['gmedia_edit_media']) { ?> <a class="btn btn-default edit-mode-link" title="<?php _e('Toggle Edit Mode', 'gmLang'); ?> " href="<?php echo $edit_mode_href; ?> " <?php echo $edit_mode_data; ?> ><?php _e('Action', 'gmLang'); ?> </a> <?php } else { ?> <button type="button" class="btn btn-default"><?php _e('Action', 'gmLang'); ?> </button> <?php } ?> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'gmLang'); ?> </span></button> <?php $rel_selected_show = 'rel-selected-show'; $rel_selected_hide = 'rel-selected-hide'; ?> <ul class="dropdown-menu" role="menu"> <?php if (!$gmProcessor->mode) { ?> <li class="<?php if (!$gmCore->caps['gmedia_edit_media']) { echo 'disabled'; } ?> "><a class="edit-mode-link" href="<?php echo $edit_mode_href; ?> " <?php echo $edit_mode_data; ?> ><?php _e('Enter Edit Mode', 'gmLang'); ?> </a> </li> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_edit_media']) { echo ' disabled'; } ?> "> <a href="#libModal" data-modal="batch_edit" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Batch Edit', 'gmLang'); ?> </a> </li> <li class="divider"></li> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_gallery_manage']) { echo ' disabled'; } ?> "> <a href="#libModal" data-modal="quick_gallery" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Quick Gallery from Selected', 'gmLang'); ?> </a> </li> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_terms']) { echo ' disabled'; } ?> "> <a href="#libModal" data-modal="assign_category" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Assign Category...', 'gmLang'); ?> </a> </li> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_terms']) { echo ' disabled'; } ?> "> <a href="#libModal" data-modal="assign_album" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Move to Album...', 'gmLang'); ?> </a> </li> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_terms']) { echo ' disabled'; } ?> "><a href="#libModal" data-modal="add_tags" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Add Tags...', 'gmLang'); ?> </a> </li> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_terms']) { echo ' disabled'; } ?> "> <a href="#libModal" data-modal="delete_tags" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Delete Tags...', 'gmLang'); ?> </a> </li> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_delete_media']) { echo ' disabled'; } ?> "> <a href="<?php echo wp_nonce_url($gmCore->get_admin_url(array('delete' => 'selected'), array('filter')), 'gmedia_delete'); ?> " class="gmedia-delete" data-confirm="<?php _e("You are about to permanently delete the selected items.\n\r'Cancel' to stop, 'OK' to delete.", "gmLang"); ?> "><?php _e('Delete Selected Items', 'gmLang'); ?> </a> </li> <li class="divider <?php echo $rel_selected_show; ?> "></li> <li class="<?php echo $rel_selected_show; if (!$gmCore->caps['gmedia_edit_media']) { echo ' disabled'; } ?> "> <a href="<?php echo wp_nonce_url($gmCore->get_admin_url(array('update_meta' => 'selected'), array()), 'gmedia_update_meta'); ?> " class="gmedia-update"><?php _e('Update Metadata in Database', 'gmLang'); ?> </a> </li> <li class="dropdown-header <?php echo $rel_selected_hide; ?> "><span><?php _e("Select items to see more actions", "gmLang"); ?> </span></li> <?php } else { ?> <li><a href="<?php echo $edit_mode_href; ?> "><?php _e('Exit Edit Mode', 'gmLang'); ?> </a></li> <?php } do_action('gmedia_action_list'); ?> </ul> </div> <?php $filter_selected = $gmCore->_req('filter'); $filter_selected_arg = $filter_selected ? false : 'selected'; ?> <form class="btn-group" id="gm-selected-btn" name="gm-selected-form" action="<?php echo add_query_arg(array('filter' => $filter_selected_arg), $url); ?> " method="post"> <button type="submit" class="btn btn<?php echo 'selected' == $filter_selected ? '-success' : '-info'; ?> "><?php printf(__('%s selected', 'gmLang'), '<span id="gm-selected-qty">' . count($gmProcessor->selected_items) . '</span>'); ?> </button> <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"><span class="caret"></span> <span class="sr-only"><?php _e('Toggle Dropdown', 'gmLang'); ?> </span></button> <input type="hidden" id="gm-selected" data-userid="<?php echo $user_ID; ?> " data-key="library" name="selected_items" value="<?php echo implode(',', $gmProcessor->selected_items); ?> "/> <ul class="dropdown-menu" role="menu"> <li><a id="gm-selected-show" href="#show"><?php if (!$filter_selected) { _e('Show only selected items', 'gmLang'); } else { _e('Show all gmedia items', 'gmLang'); } ?> </a></li> <li><a id="gm-selected-clear" href="#clear"><?php _e('Clear selected items', 'gmLang'); ?> </a></li> <li class="<?php if (!$gmCore->caps['gmedia_gallery_manage']) { echo 'disabled'; } ?> "> <a href="#libModal" data-modal="quick_gallery" data-action="gmedia_get_modal" class="gmedia-modal"><?php _e('Quick Gallery from Selected', 'gmLang'); ?> </a> </li> </ul> </form> </div> </div> <div class="panel-body"></div> <div class="list-group" id="gm-list-table"> <?php if (count($gmediaQuery)) { if ($gmProcessor->mode && $gmCore->caps['gmedia_show_others_media'] && !$gmCore->caps['gmedia_edit_others_media']) { ?> <div class="alert alert-warning alert-dismissible" role="alert" style="margin-bottom:0"> <button type="button" class="close" data-dismiss="alert"> <span aria-hidden="true">×</span><span class="sr-only"><?php _e('Close', 'gmLang'); ?> </span></button> <strong><?php _e('Info:', 'gmLang'); ?> </strong> <?php _e('You are not allowed to edit others media', 'gmLang'); ?> </div> <?php } foreach ($gmediaQuery as $item) { $meta = $gmDB->get_metadata('gmedia', $item->ID); $_metadata = $gmDB->get_metadata('gmedia', $item->ID, '_metadata', true); $type = explode('/', $item->mime_type); $item_url = $gmCore->upload['url'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $item->gmuid; $item_path = $gmCore->upload['path'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $item->gmuid; if (function_exists('exif_imagetype')) { $is_webimage = 'image' == $type[0] && in_array(exif_imagetype($item_path), array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)) ? true : false; } else { $is_webimage = 'image' == $type[0] && in_array($type[1], array('jpeg', 'png', 'gif')) ? true : false; } $modal_width = isset($_metadata['original']['width']) ? $_metadata['original']['width'] : (isset($_metadata['width']) ? $_metadata['width'] : '900'); $modal_height = isset($_metadata['original']['height']) ? $_metadata['original']['height'] : (isset($_metadata['height']) ? $_metadata['height'] : '300'); $modal_web_width = isset($_metadata['web']['width']) ? $_metadata['web']['width'] : (isset($_metadata['width']) ? $_metadata['width'] : '640'); $modal_web_height = isset($_metadata['web']['height']) ? $_metadata['web']['height'] : (isset($_metadata['height']) ? $_metadata['height'] : '200'); $tags = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_tag'); $albs = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_album'); $cats = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_category'); $list_row_class = ''; if ('public' != $item->status) { if ('private' == $item->status) { $list_row_class = ' list-group-item-info'; } elseif ('draft' == $item->status) { $list_row_class = ' list-group-item-warning'; } } ?> <?php if (!$gmProcessor->mode) { $is_selected = in_array($item->ID, $gmProcessor->selected_items) ? true : false; ?> <div class="list-group-item d-row clearfix<?php echo ($is_selected ? ' active-row' : '') . $list_row_class; ?> " id="list-item-<?php echo $item->ID; ?> " data-id="<?php echo $item->ID; ?> " data-type="<?php echo $type[0]; ?> "> <div class="gmedia_id">#<?php echo $item->ID; ?> </div> <label class="cb_media-object col-sm-4" style="max-width:350px;"> <input name="doaction[]" type="checkbox"<?php echo $is_selected ? ' checked="checked"' : ''; ?> data-type="<?php echo $type[0]; ?> " class="hidden" value="<?php echo $item->ID; ?> "/> <span data-target="<?php echo $item_url; ?> " class="thumbnail"> <?php if ('image' == $type[0]) { ?> <img class="gmedia-thumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb'); ?> " alt=""/> <?php } else { $typethumb = false; ?> <?php if (isset($meta['cover'][0]) && !empty($meta['cover'][0])) { $typethumb = true; ?> <img class="gmedia-thumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb'); ?> " alt=""/> <?php } elseif (isset($_metadata['image']['data']) && !empty($_metadata['image']['data'])) { $typethumb = true; ?> <img class="gmedia-thumb" src="<?php echo $_metadata['image']['data']; ?> " alt=""/> <?php } else { ?> <img class="gmedia-thumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb', false); ?> " alt=""/> <?php } ?> <?php if ($typethumb) { ?> <img class="gmedia-typethumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb', false); ?> " alt=""/> <?php } ?> <?php } ?> </span> </label> <div class="col-sm-8"> <div class="row" style="margin:0;"> <div class="col-lg-6"> <p class="media-title"><?php echo esc_html($item->title); ?> </p> <div class="in-library media-caption"><?php echo nl2br(esc_html($item->description)); ?> </div> <p class="media-meta"><span class="label label-default"><?php _e('Album', 'gmLang'); ?> :</span> <?php if ($albs) { $terms_album = array(); foreach ($albs as $c) { $terms_album[] = sprintf('<a class="album" href="%s">%s</a>', esc_url(add_query_arg(array('alb' => $c->term_id), $url)), esc_html($c->name)); } $terms_album = join(', ', $terms_album); } else { $terms_album = sprintf('<a class="album" href="%s">%s</a>', esc_url(add_query_arg(array('alb' => 0), $url)), '—'); } echo $terms_album; if ($is_webimage) { ?> <br/><span class="label label-default"><?php _e('Category', 'gmLang'); ?> :</span> <?php if ($cats) { $terms_category = array(); foreach ($cats as $c) { $terms_category[] = sprintf('<a class="category" href="%s">%s</a>', esc_url(add_query_arg(array('cat' => $c->term_id), $url)), esc_html($gmGallery->options['taxonomies']['gmedia_category'][$c->name])); } $terms_category = join(', ', $terms_category); } else { $terms_category = sprintf('<a class="category" href="%s">%s</a>', esc_url(add_query_arg(array('cat' => 0), $url)), __('Uncategorized', 'gmLang')); } echo $terms_category; } ?> <br/><span class="label label-default"><?php _e('Tags', 'gmLang'); ?> :</span> <?php if ($tags) { $terms_tag = array(); foreach ($tags as $c) { $terms_tag[] = sprintf('<a class="tag" href="%s">%s</a>', esc_url(add_query_arg(array('tag_id' => $c->term_id), $url)), esc_html($c->name)); } $terms_tag = join(', ', $terms_tag); } else { $terms_tag = '—'; } echo $terms_tag; ?> <br/><span class="label label-default"><?php _e('Views / Likes', 'gmLang'); ?> :</span> <?php echo (isset($meta['views'][0]) ? $meta['views'][0] : '0') . ' / ' . (isset($meta['likes'][0]) ? $meta['likes'][0] : '0'); ?> <?php if (isset($meta['rating'][0])) { $ratings = maybe_unserialize($meta['rating'][0]); ?> <br/><span class="label label-default"><?php _e('Rating', 'gmLang'); ?> :</span> <?php echo $ratings['value'] . ' / ' . $ratings['votes']; ?> <?php } ?> </p> </div> <div class="col-lg-6"> <div class="media-meta"> <span class="label label-default"><?php _e('Status', 'gmLang'); ?> :</span> <?php echo $item->status; ?> </div> <div class="media-meta"> <span class="label label-default"><?php _e('Type', 'gmLang'); ?> :</span> <?php echo $item->mime_type; ?> </div> <?php if ('image' == $type[0]) { ?> <div class="media-meta"> <span class="label label-default"><?php _e('Size', 'gmLang'); ?> :</span> <?php echo $_metadata['original']['width'] . ' × ' . $_metadata['original']['height']; ?> </div> <?php } ?> <div class="media-meta"><span class="label label-default"><?php _e('Filename', 'gmLang'); ?> :</span> <a href="<?php echo $item_url; ?> "><?php echo $item->gmuid; ?> </a></div> <div class="media-meta"> <span class="label label-default"><?php _e('Author', 'gmLang'); ?> :</span> <?php printf('<a class="gmedia-author" href="%s">%s</a>', esc_url(add_query_arg(array('author' => $item->author), $url)), get_user_option('display_name', $item->author)); ?> </div> <div class="media-meta"><span class="label label-default"><?php _e('Date', 'gmLang'); ?> :</span> <?php echo $item->date; echo ' <small class="modified" title="' . __('Last Modified Date', 'gmLang') . '">' . ($item->modified != $item->date ? $item->modified : '') . '</small>'; ?> </div> <div class="media-meta"><span class="label label-default"><?php _e('Link', 'gmLang'); ?> :</span> <?php if (!empty($item->link)) { ?> <a href="<?php echo $item->link; ?> "><?php echo $item->link; ?> </a> <?php } else { echo '—'; } ?> </div> <p class="media-meta" style="margin:5px 4px;"> <?php $media_action_links = array(); if ($gmCore->caps['gmedia_edit_media'] && (int) $item->author == get_current_user_id() || $gmCore->caps['gmedia_edit_others_media']) { $gmedia_hashid = gmedia_hash_id_encode($item->ID, 'single'); if (get_option('permalink_structure')) { $cloud_link = home_url(urlencode($endpoint) . '/s/' . $gmedia_hashid); } else { $cloud_link = add_query_arg(array("{$endpoint}" => $gmedia_hashid, 't' => 's'), home_url('index.php')); } $media_action_links[] = '<a target="_blank" data-target="#shareModal" data-share="' . $item->ID . '" class="share-modal" title="' . __('GmediaCloud Page', 'gmLang') . '" href="' . $cloud_link . '">' . __('Share', 'gmLang') . '</a>'; $media_action_links[] = '<a href="' . admin_url("admin.php?page=GrandMedia&mode=edit&gmedia__in={$item->ID}") . '">' . __('Edit Data', 'gmLang') . '</a>'; } if ('image' == $type[0]) { if ($gmCore->caps['gmedia_edit_media'] && (int) $item->author == get_current_user_id() || $gmCore->caps['gmedia_edit_others_media']) { $media_action_links[] = '<a href="' . admin_url("admin.php?page=GrandMedia&gmediablank=image_editor&id={$item->ID}") . '" data-target="#gmeditModal" class="gmedit-modal">' . __('Edit Image', 'gmLang') . '</a>'; } $media_action_links[] = '<a href="' . $gmCore->gm_get_media_image($item, 'original') . '" data-target="#previewModal" data-width="' . $modal_width . '" data-height="' . $modal_height . '" class="preview-modal" title="' . esc_attr($item->title) . '">' . __('View Original', 'gmLang') . '</a>'; } elseif (in_array($type[1], array('mp4', 'mp3', 'mpeg', 'webm', 'ogg', 'wave', 'wav'))) { $media_action_links[] = '<a href="' . $item_url . '" data-target="#previewModal" data-width="' . $modal_web_width . '" data-height="' . $modal_web_height . '" class="preview-modal" title="' . esc_attr($item->title) . '">' . __('Play', 'gmLang') . '</a>'; } $metainfo = $gmCore->metadata_text($item->ID); if ($metainfo) { $media_action_links[] = '<a href="#metaInfo" data-target="#previewModal" data-metainfo="' . $item->ID . '" class="preview-modal" title="' . __('Meta Info', 'gmLang') . '">' . __('Meta Info', 'gmLang') . '</a>'; } if ($gmCore->caps['gmedia_delete_media'] && (int) $item->author == get_current_user_id() || $gmCore->caps['gmedia_delete_others_media']) { $media_action_links[] = '<a class="text-danger" href="' . wp_nonce_url($gmCore->get_admin_url(array('delete' => $item->ID)), 'gmedia_delete') . '" data-confirm="' . sprintf(__("You are about to permanently delete %s file.\n\r'Cancel' to stop, 'OK' to delete.", "gmLang"), $item->gmuid) . '">' . __('Delete', 'gmLang') . '</a>'; if ($gmCore->_get('showmore')) { $media_action_links[] = '<a class="text-danger" href="' . wp_nonce_url($gmCore->get_admin_url(array('delete' => $item->ID, 'save_original_file' => 1)), 'gmedia_delete') . '" data-confirm="' . sprintf(__("You are about to delete record from DB for %s file.\n\r'Cancel' to stop, 'OK' to delete.", "gmLang"), $item->gmuid) . '">' . __('Delete DB record (leave file on the server)', 'gmLang') . '</a>'; } } echo implode(' | ', $media_action_links); ?> </p> <?php if ($metainfo) { ?> <div class="metainfo hidden" id="metainfo_<?php echo $item->ID; ?> "> <?php echo nl2br($metainfo); ?> </div> <?php } ?> </div> </div> </div> </div> <?php } elseif ($gmCore->caps['gmedia_edit_media']) { ?> <?php if ((int) $item->author != $user_ID && !$gmCore->caps['gmedia_edit_others_media']) { ?> <div class="list-group-item row d-row" id="list-item-<?php echo $item->ID; ?> " data-id="<?php echo $item->ID; ?> " data-type="<?php echo $type[0]; ?> "> <div class="gmedia_id">#<?php echo $item->ID; ?> </div> <div class="li_media-object col-sm-4" style="max-width:350px;"> <span data-target="<?php echo $item_url; ?> " class="thumbnail"> <?php if ('image' == $type[0]) { ?> <img class="gmedia-thumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb'); ?> " alt=""/> <?php } else { $typethumb = false; ?> <?php if (isset($meta['cover'][0]) && !empty($meta['cover'][0])) { $typethumb = true; ?> <img class="gmedia-thumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb'); ?> " alt=""/> <?php } elseif (isset($_metadata['image']['data']) && !empty($_metadata['image']['data'])) { $typethumb = true; ?> <img class="gmedia-thumb" src="<?php echo $_metadata['image']['data']; ?> " alt=""/> <?php } else { ?> <img class="gmedia-thumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb', false); ?> " alt=""/> <?php } ?> <?php if ($typethumb) { ?> <img class="gmedia-typethumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb', false); ?> " alt=""/> <?php } ?> <?php } ?> </span> </div> <div class="col-sm-8"> <div class="col-md-6"> <p class="media-title"><?php echo esc_html($item->title); ?> </p> <p class="media-caption"><?php echo esc_html($item->description); ?> </p> <p class="media-meta"><span class="label label-default"><?php _e('Album', 'gmLang'); ?> :</span> <?php if ($albs) { $terms_album = array(); foreach ($albs as $c) { $terms_album[] = sprintf('<span class="album">%s</span>', esc_html($c->name)); } $terms_album = join(', ', $terms_album); } else { $terms_album = '<span class="album">—</span>'; } echo $terms_album; if ($is_webimage) { ?> <br/><span class="label label-default"><?php _e('Category', 'gmLang'); ?> :</span> <?php if ($cats) { $terms_category = array(); foreach ($cats as $c) { $terms_category[] = sprintf('<span class="category">%s</span>', esc_html($gmGallery->options['taxonomies']['gmedia_category'][$c->name])); } $terms_category = join(', ', $terms_category); } else { $terms_category = sprintf('<span class="category">%s</span>', __('Uncategorized')); } echo $terms_category; } ?> <br/><span class="label label-default"><?php _e('Tags', 'gmLang'); ?> :</span> <?php if ($tags) { $terms_tag = array(); foreach ($tags as $c) { $terms_tag[] = sprintf('<span class="tag">%s</span>', esc_html($c->name)); } $terms_tag = join(', ', $terms_tag); } else { $terms_tag = '—'; } echo $terms_tag; ?> </p> </div> <div class="col-md-6"> <div class="media-meta"> <span class="label label-default"><?php _e('Status', 'gmLang'); ?> :</span> <?php echo $item->status; ?> </div> <div class="media-meta"> <span class="label label-default"><?php _e('Type', 'gmLang'); ?> :</span> <?php echo $item->mime_type; ?> </div> <?php if ('image' == $type[0]) { ?> <div class="media-meta"> <span class="label label-default"><?php _e('Size', 'gmLang'); ?> :</span> <?php echo $_metadata['original']['width'] . ' × ' . $_metadata['original']['height']; ?> </div> <?php } ?> <div class="media-meta"><span class="label label-default"><?php _e('Filename', 'gmLang'); ?> :</span> <a href="<?php echo $item_url; ?> "><?php echo $item->gmuid; ?> </a></div> <div class="media-meta"> <span class="label label-default"><?php _e('Author', 'gmLang'); ?> :</span> <?php printf('<span class="gmedia-author">%s</a>', get_user_option('display_name', $item->author)); ?> </div> <div class="media-meta"><span class="label label-default"><?php _e('Date', 'gmLang'); ?> :</span> <?php echo $item->date; echo ' <small class="modified" title="' . __('Last Modified Date', 'gmLang') . '">' . ($item->modified != $item->date ? $item->modified : '') . '</small>'; ?> </div> <div class="media-meta"><span class="label label-default"><?php _e('Link', 'gmLang'); ?> :</span> <?php if (!empty($item->link)) { ?> <a href="<?php echo $item->link; ?> "><?php echo $item->link; ?> </a> <?php } else { echo '—'; } ?> </div> <?php if ('image' == $type[0]) { ?> <p class="media-meta" style="margin:5px 4px;"> <a href="<?php echo $gmCore->gm_get_media_image($item, 'original'); ?> " data-target="#previewModal" data-width="<?php echo $modal_width; ?> " data-height="<?php echo $modal_height; ?> " class="preview-modal" title="<?php echo esc_attr($item->title); ?> "> <?php _e('View Original', 'gmLang'); ?> </a> </p> <?php } elseif (in_array($type[1], array('mp4', 'mp3', 'mpeg', 'webm', 'ogg', 'wave', 'wav'))) { ?> <p class="media-meta" style="margin:5px 4px;"> <a href="<?php echo $item_url; ?> " data-target="#previewModal" data-width="<?php echo $modal_web_width; ?> " data-height="<?php echo $modal_web_height; ?> " class="preview-modal" title="<?php echo esc_attr($item->title); ?> "> <?php _e('Play', 'gmLang'); ?> </a> </p> <?php } ?> </div> </div> </div> <?php continue; } ?> <form class="list-group-item row d-row edit-gmedia" id="list-item-<?php echo $item->ID; ?> " data-id="<?php echo $item->ID; ?> " data-type="<?php echo $type[0]; ?> " role="form"> <div class="col-sm-4" style="max-width:350px;"> <input name="ID" type="hidden" value="<?php echo $item->ID; ?> "/> <?php $media_action_links = array(); if ('image' == $type[0]) { ?> <a href="<?php echo $item_url; ?> " data-target="#previewModal" data-width="<?php echo $modal_web_width; ?> " data-height="<?php echo $modal_web_height; ?> " class="thumbnail preview-modal" title="<?php echo esc_attr($item->title); ?> "> <img class="gmedia-thumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb'); ?> " alt=""/> </a> <?php $media_action_links[] = '<a href="' . admin_url("admin.php?page=GrandMedia&gmediablank=image_editor&id={$item->ID}") . '" data-target="#gmeditModal" class="btn btn-link btn-sm gmedit-modal">' . __('Edit Image', 'gmLang') . '</a>'; $media_action_links[] = '<a href="' . $gmCore->gm_get_media_image($item, 'original') . '" data-target="#previewModal" data-width="' . $modal_width . '" data-height="' . $modal_height . '" class="btn btn-link btn-sm preview-modal" title="' . esc_attr($item->title) . '">' . __('View Original', 'gmLang') . '</a>'; } else { ?> <a href="<?php echo $item_url; ?> " data-target="#previewModal" data-width="<?php echo $modal_web_width; ?> " data-height="<?php echo $modal_web_height; ?> " class="thumbnail preview-modal" title="<?php echo esc_attr($item->title); ?> "> <?php $typethumb = false; if (isset($meta['cover'][0]) && !empty($meta['cover'][0])) { $typethumb = true; ?> <img class="gmedia-thumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb'); ?> " alt=""/> <?php } elseif (isset($_metadata['image']['data']) && !empty($_metadata['image']['data'])) { $typethumb = true; ?> <img class="gmedia-thumb" src="<?php echo $_metadata['image']['data']; ?> " alt=""/> <?php } else { ?> <img class="gmedia-thumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb', false); ?> " alt=""/> <?php } ?> <?php if ($typethumb) { ?> <img class="gmedia-typethumb" src="<?php echo $gmCore->gm_get_media_image($item, 'thumb', false); ?> " alt=""/> <?php } ?> </a> <?php if (in_array($type[1], array('mp4', 'mp3', 'mpeg', 'webm', 'ogg', 'wave', 'wav'))) { $media_action_links[] = '<a href="' . $item_url . '" data-target="#previewModal" data-width="' . $modal_width . '" data-height="' . $modal_height . '" class="btn btn-link btn-sm preview-modal" title="' . esc_attr($item->title) . '">' . __('Play', 'gmLang') . '</a>'; } } $metainfo = $gmCore->metadata_text($item->ID); if ($metainfo) { $media_action_links[] = '<a href="#metaInfo" data-target="#previewModal" data-metainfo="' . $item->ID . '" class="btn btn-link btn-sm preview-modal" title="' . __('Meta Info', 'gmLang') . '">' . __('Meta Info', 'gmLang') . '</a>'; } if ($gmCore->caps['gmedia_delete_media'] && (int) $item->author == get_current_user_id() || $gmCore->caps['gmedia_delete_others_media']) { $media_action_links[] = '<a class="btn btn-link btn-sm text-danger" href="' . wp_nonce_url($gmCore->get_admin_url(array('delete' => $item->ID)), 'gmedia_delete') . '" data-confirm="' . sprintf(__("You are about to permanently delete %s file.\n\r'Cancel' to stop, 'OK' to delete.", "gmLang"), $item->gmuid) . '">' . __('Delete', 'gmLang') . '</a>'; } echo '<p>' . implode(' | ', $media_action_links) . '</p>'; ?> <?php if ($metainfo) { ?> <div class="metainfo hidden" id="metainfo_<?php echo $item->ID; ?> "> <?php echo nl2br($metainfo); ?> </div> <?php } ?> </div> <div class="col-sm-8"> <div class="row"> <div class="form-group col-lg-6"> <label><?php _e('Title', 'gmLang'); ?> </label> <input name="title" type="text" class="form-control input-sm" placeholder="<?php _e('Title', 'gmLang'); ?> " value="<?php echo esc_attr($item->title); ?> "> </div> <div class="form-group col-lg-6"> <label><?php _e('Link URL', 'gmLang'); ?> </label> <input name="link" type="text" class="form-control input-sm" value="<?php echo $item->link; ?> "/> </div> </div> <div class="row"> <div class="form-group col-lg-6"> <label><?php _e('Description', 'gmLang'); ?> </label> <?php if ('false' == $gm_screen_options['library_edit_quicktags']) { echo "<textarea id='gm{$item->ID}_description' class='form-control input-sm' name='description' cols='20' rows='4' style='height:174px'>" . esc_html($item->description) . '</textarea>'; } else { wp_editor(esc_html($item->description), "gm{$item->ID}_description", array('editor_class' => 'form-control input-sm', 'editor_height' => 140, 'wpautop' => false, 'media_buttons' => false, 'textarea_name' => 'description', 'textarea_rows' => '4', 'tinymce' => false, 'quicktags' => array('buttons' => apply_filters('gmedia_editor_quicktags', 'strong,em,link,ul,li,close')))); } ?> </div> <div class="col-lg-6"> <?php if ('image' != $type[0]) { ?> <div class="form-group"> <label><?php _e('Custom Cover', 'gmLang'); ?> </label> <input name="meta[cover]" type="text" class="form-control input-sm gmedia-cover" value="<?php if (isset($meta['cover'][0])) { echo $meta['cover'][0]; } ?> " placeholder="<?php _e('Gmedia ID or Image URL', 'gmLang'); ?> "/> </div> <?php } ?> <?php if ($gmCore->caps['gmedia_terms']) { ?> <?php if ($is_webimage) { ?> <?php $cat_name = empty($cats) ? 0 : reset($cats)->name; $term_type = 'gmedia_category'; $gm_terms = $gmGallery->options['taxonomies'][$term_type]; $terms_category = ''; if (count($gm_terms)) { foreach ($gm_terms as $term_name => $term_title) { $selected_option = $cat_name === $term_name ? ' selected="selected"' : ''; $terms_category .= '<option' . $selected_option . ' value="' . $term_name . '">' . esc_html($term_title) . '</option>' . "\n"; } } ?> <div class="form-group"> <label><?php _e('Category', 'gmLang'); ?> </label> <select name="terms[gmedia_category]" class="gmedia_category form-control input-sm"> <option<?php echo $cat_name ? '' : ' selected="selected"'; ?> value=""><?php _e('Uncategorized', 'gmLang'); ?> </option> <?php echo $terms_category; ?> </select> </div> <?php } ?> <?php $alb_id = empty($albs) ? 0 : reset($albs)->term_id; $term_type = 'gmedia_album'; $args = array(); if (!$gmCore->caps['gmedia_edit_others_media']) { $args = array('global' => array(0, $user_ID), 'orderby' => 'global_desc_name'); } $gm_terms = $gmDB->get_terms($term_type, $args); $terms_album = ''; $album_status = 'none'; if (count($gm_terms)) { foreach ($gm_terms as $term) { $author_name = ''; if ($term->global) { if ($gmCore->caps['gmedia_edit_others_media']) { $author_name .= ' ' . sprintf(__('by %s', 'gmLang'), get_the_author_meta('display_name', $term->global)); } } else { $author_name .= ' (' . __('shared', 'gmLang') . ')'; } if ('public' != $term->status) { $author_name .= ' [' . $term->status . ']'; } $selected_option = ''; if ($alb_id == $term->term_id) { $selected_option = ' selected="selected"'; $album_status = $term->status; } $terms_album .= '<option' . $selected_option . ' value="' . $term->term_id . '">' . esc_html($term->name) . $author_name . '</option>' . "\n"; } } ?> <div class="form-group status-album bg-status-<?php echo $album_status; ?> "> <label><?php _e('Album ', 'gmLang'); ?> </label> <select name="terms[gmedia_album]" class="combobox_gmedia_album form-control input-sm" placeholder="<?php _e('Album Name...', 'gmLang'); ?> "> <option<?php echo $alb_id ? '' : ' selected="selected"'; ?> value=""></option> <?php echo $terms_album; ?> </select> </div> <?php if (!empty($tags)) { $terms_tag = array(); foreach ($tags as $c) { $terms_tag[] = esc_html($c->name); } $terms_tag = join(', ', $terms_tag); } else { $terms_tag = ''; } ?> <div class="form-group"> <label><?php _e('Tags ', 'gmLang'); ?> </label> <textarea name="terms[gmedia_tag]" class="gmedia_tags_input form-control input-sm" rows="1" cols="50"><?php echo $terms_tag; ?> </textarea> </div> <?php } ?> </div> </div> <div class="row"> <div class="col-lg-6"> <div class="form-group"> <label><?php _e('Filename', 'gmLang'); ?> </label> <input name="filename" type="text" class="form-control input-sm gmedia-filename" <?php if ((int) $item->author !== $user_ID) { echo 'readonly'; } ?> value="<?php echo pathinfo($item->gmuid, PATHINFO_FILENAME); ?> "/> </div> <div class="form-group"> <label><?php _e('Date', 'gmLang'); ?> </label> <div class="input-group date input-group-sm" data-date-format="YYYY-MM-DD HH:mm:ss"> <input name="date" type="text" readonly="readonly" class="form-control input-sm" value="<?php echo $item->date; ?> "/> <span class="input-group-btn"><button type="button" class="btn btn-primary"> <span class="glyphicon glyphicon-calendar"></span></button></span> </div> </div> <div class="form-group status-item bg-status-<?php echo $item->status; ?> "> <label><?php _e('Status', 'gmLang'); ?> </label> <select name="status" class="form-control input-sm"> <option <?php selected($item->status, 'public'); ?> value="public"><?php _e('Public', 'gmLang'); ?> </option> <option <?php selected($item->status, 'private'); ?> value="private"><?php _e('Private', 'gmLang'); ?> </option> <option <?php selected($item->status, 'draft'); ?> value="draft"><?php _e('Draft', 'gmLang'); ?> </option> </select> </div> </div> <div class="col-lg-6"> <div class="form-group"> <label><?php _e('Author', 'gmLang'); ?> </label> <?php $user_ids = $gmCore->caps['gmedia_delete_others_media'] ? $gmCore->get_editable_user_ids() : false; if ($user_ids) { if (!in_array($user_ID, $user_ids)) { array_push($user_ids, $user_ID); } wp_dropdown_users(array('include' => $user_ids, 'include_selected' => true, 'name' => 'author', 'selected' => $item->author, 'class' => 'form-control', 'multi' => true)); } else { echo '<input type="hidden" name="author" value="' . $item->author . '"/>'; echo '<div>' . get_the_author_meta('display_name', $item->author) . '</div>'; } ?> </div> <div class="media-meta"><span class="label label-default"><?php _e('ID', 'gmLang'); ?> :</span> <strong><?php echo $item->ID; ?> </strong></div> <div class="media-meta"><span class="label label-default"><?php _e('Type', 'gmLang'); ?> :</span> <?php echo $item->mime_type; ?> </div> <div class="media-meta"><span class="label label-default"><?php _e('File Size', 'gmLang'); ?> :</span> <?php echo $gmCore->filesize($item_path); ?> </div> <?php if ('image' == $type[0]) { $_metadata = unserialize($meta['_metadata'][0]); ?> <div class="media-meta"><span class="label label-default"><?php _e('Dimensions', 'gmLang'); ?> :</span> <span title="<?php echo $_metadata['web']['width'] . ' × ' . $_metadata['web']['height'] . ', ' . $_metadata['thumb']['width'] . ' × ' . $_metadata['thumb']['height']; ?> "><?php echo $_metadata['original']['width'] . ' × ' . $_metadata['original']['height']; ?> </span> </div> <?php } ?> <div class="media-meta"><span class="label label-default"><?php _e('Uploaded', 'gmLang'); ?> :</span><?php echo $item->date; ?> </div> <div class="media-meta"><span class="label label-default"><?php _e('Last Edited', 'gmLang'); ?> :</span> <span class="gm-last-edited modified"><?php echo $item->modified; ?> </span></div> </div> </div> <?php do_action('gmedia_edit_form'); ?> </div> </form> <?php } ?> <?php } ?> <script type="text/javascript"> jQuery(function($){ <?php if (!$gmProcessor->mode) { ?> $('#gm-selected').on('change', function(){ var val = $(this).val(); $('.edit-mode-link').each(function(){ if(val){ $(this).attr('href', $(this).data('href_sel')); } else{ $(this).attr('href', $(this).data('href')); } }); }).trigger('change'); <?php } else { ?> <?php if ($gmCore->caps['gmedia_terms']) { ?> $('.combobox_gmedia_album').selectize({ create: <?php echo $gmCore->caps['gmedia_album_manage'] ? 'true' : 'false'; ?> , persist: false }); <?php } ?> var gmedia_date_temp; $('.input-group.date').datetimepicker({useSeconds: true}).on('dp.show', function(){ gmedia_date_temp = $('input', this).val(); }).on('dp.hide', function(){ if(gmedia_date_temp != $('input', this).val()){ $('input', this).trigger('change'); } }); var inp_filename = $('input.gmedia-filename').not('[readonly]'); if(inp_filename.length){ inp_filename.alphanum({ allow: '-_', disallow: '', allowSpace: false, allowNumeric: true, allowUpper: true, allowLower: true, allowCaseless: true, allowLatin: true, allowOtherCharSets: false, forceUpper: false, forceLower: false, maxLength: NaN }); } <?php } ?> }); window.closeModal = function(id){ jQuery('#' + id).modal('hide'); }; </script> <?php } else { ?> <div class="list-group-item"> <div class="well well-lg text-center"> <h4><?php _e('No items to show.', 'gmLang'); ?> </h4> <?php if ($gmCore->caps['gmedia_upload']) { ?> <p> <a href="<?php echo admin_url('admin.php?page=GrandMedia_AddMedia'); ?> " class="btn btn-success"><span class="glyphicon glyphicon-plus"></span> <?php _e('Add Media', 'gmLang'); ?> </a></p> <?php } ?> </div> </div> <?php } ?> </div> <div class="panel-footer clearfix"> <?php echo $gmDB->query_pager(); ?> <a href="#top" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-arrow-up"></span> <?php _e('Back to top', 'gmLang'); ?> </a> </div> <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('GmediaGallery'); ?> </div> <div class="modal fade gmedia-modal" id="libModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"></div> </div> <?php if ($gmCore->caps['gmedia_edit_media']) { ?> <div class="modal fade gmedia-modal" id="gmeditModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"></div> </div> </div> <?php } ?> <div class="modal fade gmedia-modal" id="previewModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title"></h4> </div> <div class="modal-body"></div> </div> </div> </div> <div class="modal fade gmedia-modal" id="shareModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title"><?php _e('GmediaCloud Page'); ?> </h4> </div> <form class="modal-body" method="post" id="shareForm"> <div class="form-group"> <label><?php _e('Link to page', 'gmLang'); ?> </label> <input name="sharelink" type="text" class="form-control sharelink" readonly="readonly" value="" /> </div> <div class="form-group"> <label><?php _e('Send this link to', 'gmLang'); ?> </label> <input name="email" type="email" class="form-control sharetoemail" value="" placeholder="<?php _e('Email', 'gmLang'); ?> " /> <textarea name="message" cols="20" rows="3" class="form-control" placeholder="<?php _e('Message (optional)', 'gmLang'); ?> "></textarea> </div> <input type="hidden" name="action" value="gmedia_share_page" /> <?php wp_nonce_field('share_modal', '_sharenonce'); ?> </form> <div class="modal-footer"> <button type="button" class="btn btn-primary sharebutton" disabled="disabled"><?php _e('Send', 'gmLang'); ?> </button> <button type="button" class="btn btn-default" data-dismiss="modal"><?php _e('Close', 'gmLang'); ?> </button> </div> </div> </div> </div> <?php }
/** * Generate GmediaCloud page url * * @param $id * @param $type * @param bool $default * * @return string */ function gmcloudlink($id, $type, $default = false) { $options = get_option('gmediaOptions'); $endpoint = $options['endpoint']; $hashid = gmedia_hash_id_encode($id, $type); $t = array('gallery' => 'g', 'album' => 'a', 'tag' => 't', 'single' => 's', 'category' => 'k', 'author' => 'u'); if (!$default && get_option('permalink_structure')) { $cloud_link = home_url(urlencode($endpoint) . "/{$t[$type]}/{$hashid}"); } else { $cloud_link = add_query_arg(array("{$endpoint}" => $hashid, 't' => $t[$type]), home_url('index.php')); } return $cloud_link; }
/** * gmediaGalleryEdit() * * @return mixed content */ function gmediaGalleryEdit() { global $gmDB, $gmCore, $gmGallery, $gmProcessor, $user_ID; $alert = array(); $module_name = $gmCore->_get('gallery_module'); $gallery_id = $gmCore->_get('edit_gallery'); $author_new = false; if ($gmCore->caps['gmedia_edit_others_media']) { $author = (int) $gmCore->_get('author', $user_ID); } else { $author = $user_ID; } $url = add_query_arg(array('page' => $gmProcessor->page, 'edit_gallery' => $gallery_id), admin_url('admin.php')); $gallery = array('name' => '', 'description' => '', 'global' => $author, 'status' => 'public', 'edited' => '—', 'module' => '', 'query' => array(), 'settings' => array()); $taxonomy = 'gmedia_gallery'; if ($gallery_id) { $url = add_query_arg(array('page' => $gmProcessor->page, 'edit_gallery' => $gallery_id), admin_url('admin.php')); $gallery = $gmDB->get_term($gallery_id, $taxonomy, ARRAY_A); if (is_wp_error($gallery)) { $alert[] = $gallery->get_error_message(); } elseif (empty($gallery)) { $alert[] = sprintf(__('No gallery with ID #%s in database'), $gallery_id); } else { if ($gallery['global'] == $author || $gmCore->caps['gmedia_edit_others_media']) { $gallery_meta = $gmDB->get_metadata('gmedia_term', $gallery_id); $gallery_meta = array_map('reset', $gallery_meta); $gallery_meta = array_map('maybe_unserialize', $gallery_meta); $gallery = array_merge($gallery, $gallery_meta); if (isset($_GET['author']) && $gallery['global'] != $author) { unset($gallery['query']['gmedia_album']); $gallery['global'] = $author; $author_new = true; } if (!$module_name) { $module_name = $gallery['module']; } } else { $alert[] = __('You are not allowed to edit others media'); } } } elseif ($module_name) { $url = add_query_arg(array('page' => $gmProcessor->page, 'gallery_module' => $module_name), admin_url('admin.php')); $gallery['module'] = $module_name; } $gallery_post = $gmCore->_post('gallery'); if ($gallery_post) { $gallery = $gmCore->array_replace_recursive($gallery, $gallery_post); } if (!empty($alert)) { echo $gmProcessor->alert('danger', $alert); gmediaGalleries(); return; } $modules = array(); if ($plugin_modules = glob(GMEDIA_ABSPATH . 'module/*', GLOB_ONLYDIR | GLOB_NOSORT)) { foreach ($plugin_modules as $path) { $mfold = basename($path); $modules[$mfold] = array('place' => 'plugin', 'module_name' => $mfold, 'module_url' => "{$gmCore->gmedia_url}/module/{$mfold}", 'module_path' => $path); } } if ($upload_modules = glob($gmCore->upload['path'] . '/' . $gmGallery->options['folder']['module'] . '/*', GLOB_ONLYDIR | GLOB_NOSORT)) { foreach ($upload_modules as $path) { $mfold = basename($path); $modules[$mfold] = array('place' => 'upload', 'module_name' => $mfold, 'module_url' => "{$gmCore->upload['url']}/{$gmGallery->options['folder']['module']}/{$mfold}", 'module_path' => $path); } } $default_options = array(); $presets = false; $default_preset = array(); $load_preset = array(); /** * @var $place * @var $module_name * @var $module_url * @var $module_path */ if ($module_name) { $presets = $gmDB->get_terms('gmedia_module', array('global' => $user_ID, 'status' => $module_name)); foreach ($presets as $i => $preset) { if ('[' . $module_name . ']' == $preset->name) { $default_preset = maybe_unserialize($preset->description); $default_preset['term_id'] = $preset->term_id; $default_preset['name'] = $preset->name; unset($presets[$i]); } if ((int) $preset->term_id == (int) $gmCore->_get('preset', 0)) { $load_preset = maybe_unserialize($preset->description); $load_preset['term_id'] = $preset->term_id; $load_preset['name'] = $preset->name; } } if (isset($modules[$module_name])) { extract($modules[$module_name]); /** * @var $module_info * * @var $default_options * @var $options_tree */ if (file_exists($module_path . '/index.php') && file_exists($module_path . '/settings.php')) { include $module_path . '/index.php'; include $module_path . '/settings.php'; if (!empty($default_preset)) { $default_options = $gmCore->array_replace_recursive($default_options, $default_preset); } } else { $alert[] = sprintf(__('Module `%s` is broken. Choose another module from the list and save settings'), $module_name); } } else { $alert[] = sprintf(__('Can\'t get module with name `%s`. Choose module from the list and save settings'), $module_name); } } else { $alert[] = sprintf(__('Module is not selected for this gallery. Choose module from the list and save settings'), $module_name); } if (!empty($alert)) { echo $gmProcessor->alert('danger', $alert); } if (!empty($load_preset)) { $gallery['settings'][$module_name] = $gmCore->array_replace_recursive($gallery['settings'][$module_name], $load_preset); echo $gmProcessor->alert('info', sprintf(__('Preset `%s` loaded. To apply it for current gallery click Save button'), $load_preset['name'])); } if (isset($gallery['settings'][$module_name])) { $gallery_settings = $gmCore->array_replace_recursive($default_options, $gallery['settings'][$module_name]); } else { $gallery_settings = $default_options; } include_once GMEDIA_ABSPATH . '/inc/module.options.php'; ?> <form class="panel panel-default" id="gallerySettingsForm" method="post" action="<?php echo $url; ?> "> <div class="panel-heading clearfix"> <div class="btn-toolbar pull-left"> <div class="btn-group"> <a href="<?php echo add_query_arg(array('page' => 'GrandMedia_Galleries'), admin_url('admin.php')); ?> " class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> <?php _e('Manage Galleries', 'gmLang'); ?> </a> </div> <div class="btn-group" id="save_buttons"> <?php if ($gallery['module'] != $module_name) { ?> <a href="<?php echo $url; ?> " class="btn btn-default"><?php _e('Cancel preview module', 'gmLang'); ?> </a> <button type="submit" name="gmedia_gallery_save" class="btn btn-primary"><?php _e('Save with new module', 'gmLang'); ?> </button> <?php } else { ?> <?php $reset_settings = $gmCore->array_diff_keyval_recursive($default_options, $gallery_settings, true); if (!empty($reset_settings)) { ?> <button type="submit" name="gmedia_gallery_reset" class="btn btn-default" data-confirm="<?php _e('Confirm reset gallery options'); ?> "><?php _e('Reset to default', 'gmLang'); ?> </button> <?php } ?> <button type="submit" name="gmedia_gallery_save" class="btn btn-primary"><?php _e('Save', 'gmLang'); ?> </button> <?php } ?> </div> </div> <div class="btn-toolbar pull-right" id="module_preset"> <div class="btn-group"> <button type="button" class="btn btn-default" id="save_preset" data-toggle="popover"><?php _e('Module Presets', 'gmLang'); ?> </button> </div> <script type="text/html" id="_save_preset"> <div style="padding-top: 5px;"> <p style="white-space: nowrap"> <button type="submit" name="module_preset_save_default" class="ajax-submit btn btn-default btn-sm"><?php _e('Save as Default', 'gmLang'); ?> </button> <em><?php _e('or', 'gmLang'); ?> </em> <?php if (!empty($default_preset)) { ?> <button type="submit" name="module_preset_restore_original" class="ajax-submit btn btn-default btn-sm"><?php _e('Restore Original', 'gmLang'); ?> </button> <input type="hidden" name="preset_default" value="<?php echo $default_preset['term_id']; ?> " /> <?php } ?> </p> <div class="form-group clearfix" style="border-top: 1px solid #444444; padding-top: 5px;"> <label><?php _e('Save Preset as:', 'gmLang'); ?> </label> <div class="input-group input-group-sm"> <input type="text" class="form-control input-sm" name="module_preset_name" placeholder="<?php _e('Preset Name', 'gmLang'); ?> " value="" /> <span class="input-group-btn"><button type="submit" name="module_preset_save_as" class="ajax-submit btn btn-primary"><?php _e('Save', 'gmLang'); ?> </button></span> </div> </div> <?php if (!empty($presets)) { ?> <ul class="list-group presetlist"> <?php foreach ($presets as $preset) { $trim = '[' . $module_name . '] '; $count = 1; ?> <li class="list-group-item"> <span class="delpreset"><span class="label label-danger" data-id="<?php echo $preset->term_id; ?> ">×</span></span> <a href="<?php echo $gmCore->get_admin_url(array('preset' => $preset->term_id), array(), $url); ?> "><?php echo str_replace($trim, '', $preset->name, $count); ?> </a> </li> <?php } ?> </ul> <?php } ?> </div> </script> </div> </div> <div class="panel-body" id="gmedia-msg-panel"></div> <div class="panel-body" id="gmedia-edit-gallery" style="margin-bottom:4px; padding-top:0;"> <div class="row"> <div class="col-lg-6 tabable tabs-left"> <ul class="nav nav-tabs" id="galleryTabs" style="padding:10px 0;"> <?php if (isset($module_info)) { ?> <li class="text-center"> <strong><?php echo $module_info['title']; ?> </strong><a href="#chooseModuleModal" data-toggle="modal" style="padding:5px 0;"><img src="<?php echo $module_url . '/screenshot.png'; ?> " alt="<?php echo esc_attr($module_info['title']); ?> " width="100" style="height:auto;"/></a> </li> <?php } else { ?> <li class="text-center"><strong><?php echo $gallery['module']; ?> </strong> <p><?php _e('This module is broken or outdated. Please, go to Modules page and update/install module.', 'gmLang'); ?> </p> <a href="#chooseModuleModal" data-toggle="modal" style="padding:5px 0;"><img src="<?php echo $module_url . '/screenshot.png'; ?> " alt="<?php echo esc_attr($gallery['module']); ?> " width="100" style="height:auto;"/></a> </li> <?php } ?> <li class="active"><a href="#general_settings" data-toggle="tab"><?php _e('General Settings', 'gmLang'); ?> </a></li> <?php if (isset($options_tree)) { gmedia_gallery_options_nav($options_tree); } ?> </ul> <div id="gallery_options_block" class="tab-content" style="padding-top:20px;"> <fieldset id="general_settings" class="tab-pane active"> <p><?php echo '<b>' . __('Gallery module:') . '</b> ' . $gallery['module']; if ($gallery['module'] != $module_name) { echo '<br /><b>' . __('Preview module:') . '</b> ' . $module_name; echo '<br /><span class="text-muted">' . sprintf(__('Note: Module changed to %s, but not saved yet'), $module_name) . '</span>'; } ?> </p> <p><b><?php _e('Gallery author:', 'gmLang'); ?> </b> <?php if ($gmCore->caps['gmedia_delete_others_media']) { ?> <a href="#gallModal" data-modal="select_author" data-action="gmedia_get_modal" class="gmedia-modal" title="<?php _e('Click to choose author for gallery', 'gmLang'); ?> "><?php echo $gallery['global'] ? get_the_author_meta('display_name', $gallery['global']) : __('(no author / shared albums)'); ?> </a> <?php if ($author_new) { echo '<br /><span class="text-danger">' . __('Note: Author changed but not saved yet. You can see Albums list only of chosen author') . '</span>'; } ?> <?php } else { echo $gallery['global'] ? get_the_author_meta('display_name', $gallery['global']) : '—'; } ?> <input type="hidden" name="gallery[global]" value="<?php echo $gallery['global']; ?> "/></p> <?php if ($gallery_id) { ?> <p><b><?php _e('Shortcode:'); ?> </b> [gmedia id=<?php echo $gallery_id; ?> ]</p> <?php } ?> <input type="hidden" name="gallery[module]" value="<?php echo esc_attr($module_name); ?> "> <div class="form-group"> <label><?php _e('Gallery Name', 'gmLang'); ?> </label> <input type="text" class="form-control input-sm" name="gallery[name]" placeholder="<?php echo empty($gallery['name']) ? esc_attr(__('Gallery Name', 'gmLang')) : esc_attr($gallery['name']); ?> " value="<?php echo esc_attr($gallery['name']); ?> " required="required"/> </div> <div class="form-group"> <label><?php _e('Status', 'gmLang'); ?> </label> <select name="gallery[status]" class="form-control input-sm"> <option value="public"<?php selected($gallery['status'], 'public'); ?> ><?php _e('Public', 'gmLang'); ?> </option> <option value="private"<?php selected($gallery['status'], 'private'); ?> ><?php _e('Private', 'gmLang'); ?> </option> <option value="draft"<?php selected($gallery['status'], 'draft'); ?> ><?php _e('Draft', 'gmLang'); ?> </option> </select> </div> <div class="form-group"> <label><?php _e('Show supported files from', 'gmLang'); ?> </label> <select data-watch="change" id="gmedia_query" class="form-control input-sm" name="gallery[term]"> <?php reset($gallery['query']); $gallery['term'] = key($gallery['query']); ?> <?php if ($gmCore->caps['gmedia_terms']) { ?> <option value="gmedia_album"<?php selected($gallery['term'], 'gmedia_album'); ?> ><?php _e('Albums', 'gmLang'); ?> </option> <option value="gmedia_tag"<?php selected($gallery['term'], 'gmedia_tag'); ?> ><?php _e('Tags', 'gmLang'); ?> </option> <option value="gmedia_category"<?php selected($gallery['term'], 'gmedia_category'); ?> ><?php _e('Categories', 'gmLang'); ?> </option> <option value="gmedia_filter"<?php selected($gallery['term'], 'gmedia_filter'); ?> ><?php _e('Filter', 'gmLang'); ?> </option> <?php } ?> <option value="gmedia__in"<?php selected($gallery['term'], 'gmedia__in'); ?> ><?php _e('Selected Gmedia', 'gmLang'); ?> </option> </select> </div> <?php if ($gmCore->caps['gmedia_terms']) { ?> <div class="form-group" id="div_gmedia_category"> <?php $term_type = 'gmedia_category'; $gm_terms_all = $gmGallery->options['taxonomies'][$term_type]; $gm_terms = $gmDB->get_terms($term_type, array('fields' => 'names_count')); $terms_items = ''; if (count($gm_terms)) { foreach ($gm_terms as $id => $term) { $selected = isset($gallery['query'][$term_type]) && in_array($id, $gallery['query'][$term_type]) ? ' selected="selected"' : ''; $terms_items .= '<option value="' . $id . '"' . $selected . '>' . esc_html($gm_terms_all[$term['name']]) . ' (' . $term['count'] . ')</option>' . "\n"; } } $setvalue = isset($gallery['query'][$term_type]) ? 'data-setvalue="' . implode(',', $gallery['query'][$term_type]) . '"' : ''; ?> <label><?php _e('Choose Categories', 'gmLang'); ?> </label> <select data-gmedia_query="is:gmedia_category" <?php echo $setvalue; ?> id="gmedia_category" name="gallery[query][gmedia_category][]" class="gmedia-combobox form-control input-sm" multiple="multiple" placeholder="<?php echo esc_attr(__('Choose Categories...', 'gmLang')); ?> "> <option value=""><?php _e('Choose Categories...', 'gmLang'); ?> </option> <?php echo $terms_items; ?> </select> </div> <div class="form-group" id="div_gmedia_tag"> <?php $term_type = 'gmedia_tag'; $gm_terms = $gmDB->get_terms($term_type, array('fields' => 'names_count')); $terms_items = ''; if (count($gm_terms)) { foreach ($gm_terms as $id => $term) { $selected = isset($gallery['query'][$term_type]) && in_array($id, $gallery['query'][$term_type]) ? ' selected="selected"' : ''; $terms_items .= '<option value="' . $id . '"' . $selected . '>' . esc_html($term['name']) . ' (' . $term['count'] . ')</option>' . "\n"; } } $setvalue = isset($gallery['query'][$term_type]) ? 'data-setvalue="' . implode(',', $gallery['query'][$term_type]) . '"' : ''; ?> <label><?php _e('Choose Tags', 'gmLang'); ?> </label> <select data-gmedia_query="is:gmedia_tag" <?php echo $setvalue; ?> id="gmedia_tag" name="gallery[query][gmedia_tag][]" class="gmedia-combobox form-control input-sm" multiple="multiple" placeholder="<?php echo esc_attr(__('Choose Tags...', 'gmLang')); ?> "> <option value=""><?php echo __('Choose Tags...', 'gmLang'); ?> </option> <?php echo $terms_items; ?> </select> </div> <div class="form-group" id="div_gmedia_album"> <?php $term_type = 'gmedia_album'; $args = array(); /*if($gallery['global']){ if(user_can($gallery['global'], 'gmedia_edit_others_media')){ $args['global'] = ''; } else { $args['global'] = array( 0, $gallery['global'] ); } } else{ $args['global'] = 0; }*/ if ($gmCore->caps['gmedia_edit_others_media']) { $args['global'] = ''; } else { $args['global'] = array(0, $user_ID); } $gm_terms = $gmDB->get_terms($term_type, $args); $terms_items = ''; if (count($gm_terms)) { foreach ($gm_terms as $term) { $selected = isset($gallery['query'][$term_type]) && in_array($term->term_id, $gallery['query'][$term_type]) ? ' selected="selected"' : ''; $terms_items .= '<option value="' . $term->term_id . '"' . $selected . '>' . esc_html($term->name) . ('public' == $term->status ? '' : " [{$term->status}]") . ' (' . $term->count . ')</option>' . "\n"; } } $setvalue = isset($gallery['query'][$term_type]) ? 'data-setvalue="' . implode(',', $gallery['query'][$term_type]) . '"' : ''; ?> <label><?php _e('Choose Albums', 'gmLang'); ?> </label> <select data-gmedia_query="is:gmedia_album" <?php echo $setvalue; ?> id="gmedia_album" name="gallery[query][gmedia_album][]" class="gmedia-combobox form-control input-sm" multiple="multiple" placeholder="<?php echo esc_attr(__('Choose Albums...', 'gmLang')); ?> "> <option value=""><?php echo __('Choose Albums...', 'gmLang'); ?> </option> <?php echo $terms_items; ?> </select> <p class="help-block"><?php _e('You can choose Albums from the same author as Gallery author or Albums without author', 'gmLang'); ?> </p> </div> <div class="form-group" id="div_gmedia_filter"> <?php $term_type = 'gmedia_filter'; $args = array(); if ($gmCore->caps['gmedia_edit_others_media']) { $args['global'] = ''; } else { $args['global'] = array(0, $user_ID); } $gm_terms = $gmDB->get_terms($term_type, $args); $terms_items = ''; if (count($gm_terms)) { foreach ($gm_terms as $term) { $selected = isset($gallery['query'][$term_type]) && in_array($term->term_id, $gallery['query'][$term_type]) ? ' selected="selected"' : ''; $terms_items .= '<option value="' . $term->term_id . '"' . $selected . '>' . esc_html($term->name) . '</option>' . "\n"; } } $setvalue = isset($gallery['query'][$term_type]) ? 'data-setvalue="' . implode(',', $gallery['query'][$term_type]) . '"' : ''; ?> <label><?php _e('Choose Custom Filters', 'gmLang'); ?> </label> <select data-gmedia_query="is:gmedia_filter" <?php echo $setvalue; ?> id="gmedia_filter" name="gallery[query][gmedia_filter][]" class="gmedia-combobox form-control input-sm" multiple="multiple" placeholder="<?php echo esc_attr(__('Choose Filters...', 'gmLang')); ?> "> <option value=""><?php echo __('Choose Filters...', 'gmLang'); ?> </option> <?php echo $terms_items; ?> </select> <p class="help-block"><?php _e('Filter - is custom query with multiple parameters.', 'gmLang'); ?> <a target="_blank" href="<?php echo add_query_arg(array('page' => 'GrandMedia_Terms', 'edit_filter' => '0'), admin_url('admin.php')); ?> "><?php _e('Create Filter', 'gmLang'); ?> </a></p> </div> <?php } ?> <div class="form-group" id="div_gmedia__in"> <label><?php _e('Selected Gmedia IDs <small class="text-muted">separated by comma</small>', 'gmLang'); ?> </label> <?php $value = isset($gallery['query']['gmedia__in'][0]) ? implode(',', wp_parse_id_list($gallery['query']['gmedia__in'][0])) : ''; ?> <textarea data-gmedia_query="is:gmedia__in" id="gmedia__in" name="gallery[query][gmedia__in][]" rows="1" class="form-control input-sm" style="resize:vertical;" placeholder="<?php echo esc_attr(__('Gmedia IDs...', 'gmLang')); ?> "><?php echo $value; ?> </textarea> </div> <div class="form-group"> <label><?php _e('Description', 'gmLang'); ?> </label> <textarea class="form-control input-sm" rows="5" name="gallery[description]"><?php echo esc_html($gallery['description']); ?> </textarea> </div> </fieldset> <?php if (isset($options_tree)) { gmedia_gallery_options_fieldset($options_tree, $default_options, $gallery_settings); } ?> </div> </div> <div class="col-lg-6" style="padding-top:20px;"> <p><b><?php _e('Last edited:'); ?> </b> <?php echo $gallery['edited']; ?> </p> <?php if ($gallery_id) { $params = array(); $params['set_module'] = $gallery['module'] != $module_name ? $module_name : false; $params['iframe'] = 1; ?> <p><b><?php _e('Gallery ID:'); ?> </b> #<?php echo $gallery_id; ?> </p> <p><b><?php _e('GmediaCloud page URL for current gallery:'); ?> </b> <?php $endpoint = $gmGallery->options['endpoint']; $gmedia_hashid = gmedia_hash_id_encode($gallery_id, 'gallery'); $gallery_link_default = add_query_arg(array("{$endpoint}" => $gmedia_hashid, 't' => 'g'), home_url('index.php')); if (get_option('permalink_structure')) { $gallery_link = home_url(urlencode($endpoint) . '/g/' . $gmedia_hashid); } else { $gallery_link = $gallery_link_default; } ?> <br/><a target="_blank" href="<?php echo $gallery_link; ?> "><?php echo $gallery_link; ?> </a> </p> <div class="help-block"> <?php _e('update <a href="options-permalink.php">Permalink Settings</a> if above link not working', 'gmLang'); ?> <?php if (current_user_can('manage_options')) { echo '<br>' . __('More info about GmediaCloud Pages and GmediaCloud Settings can be found <a href="admin.php?page=GrandMedia_Settings#gmedia_settings_cloud">here</a>', 'gmLang'); } ?> </div> <div><b><?php _e('Gallery Preview:'); ?> </b></div> <div class="gallery_preview" style="overflow:hidden;"> <iframe id="gallery_preview" name="gallery_preview" src="<?php echo add_query_arg($params, $gallery_link_default); ?> "></iframe> </div> <?php } ?> </div> </div> <script type="text/javascript"> jQuery(function($){ <?php if (!empty($alert)) { ?> $('#chooseModuleModal').modal('show'); <?php } ?> var hash = window.location.hash; if(hash){ $('#galleryTabs a').eq(hash.replace('#tab-', '')).tab('show'); } $('#gallerySettingsForm').on('submit', function(){ $(this).attr('action', $(this).attr('action') + '#tab-' + $('#galleryTabs li.active').index()); }); <?php if ($gmCore->caps['gmedia_terms']) { ?> $('.gmedia-combobox').each(function(){ var select = $(this).selectize({ plugins: ['drag_drop'], create: false, hideSelected: true }); var val = $(this).data('setvalue'); if(val){ val = val.toString().split(','); select[0].selectize.setValue(val); } }); <?php } ?> var main = $('#gallery_options_block'); $('input', main).filter('[data-type="color"]').minicolors({ animationSpeed: 50, animationEasing: 'swing', change: null, changeDelay: 0, control: 'hue', //defaultValue: '', hide: null, hideSpeed: 100, inline: false, letterCase: 'lowercase', opacity: false, position: 'bottom left', show: null, showSpeed: 100, theme: 'bootstrap' }); $('[data-watch]', main).each(function(){ var el = $(this); gmedia_options_conditional_logic(el, 0); var event = el.attr('data-watch'); if(event){ el.on(event, function(){ if('change' == el.attr('data-watch')){ $(this).blur().focus(); } gmedia_options_conditional_logic($(this), 400); }); } }); function gmedia_options_conditional_logic(el, slide){ if(el.is(':input')){ var val = el.val(); var id = el.attr('id').toLowerCase(); if(el.is(':checkbox') && !el[0].checked){ val = '0'; } $('[data-' + id + ']', main).each(function(){ var key = $(this).attr('data-'+id); key = key.split(':'); //var hidden = $(this).data('hidden')? parseInt($(this).data('hidden')) : 0; var hidden = $(this).data('hidden')? $(this).data('hidden') : {}; var ch = true; switch(key[0]){ case '=': case 'is': if(val == key[1]){ delete hidden[id]; if(slide && $.isEmptyObject(hidden)){ $(this).prop('disabled', false).closest('.form-group').stop().slideDown(slide, function(){ $(this).css({display: 'block'}); }); if(key[2]){ key[2] = $(this).data('value'); } else{ ch = false; } } else{ ch = false; } $(this).data('hidden', hidden); } else{ if($.isEmptyObject(hidden)){ if(key[2]){ $(this).closest('.form-group').stop().slideUp(slide, function(){ $(this).css({display: 'none'}); }); } else{ $(this).prop('disabled', true).closest('.form-group').stop().slideUp(slide, function(){ $(this).css({display: 'none'}); }); } } else{ ch = false; } hidden[id] = 1; $(this).data('hidden', hidden); } break; case '!=': case 'not': if(val == key[1]){ if($.isEmptyObject(hidden)){ if(key[2]){ $(this).closest('.form-group').stop().slideUp(slide, function(){ $(this).css({display: 'none'}); }); } else{ $(this).prop('disabled', true).closest('.form-group').stop().slideUp(slide, function(){ $(this).css({display: 'none'}); }); } } else{ ch = false; } hidden[id] = 1; $(this).data('hidden', hidden); } else{ delete hidden[id]; if(slide && $.isEmptyObject(hidden)){ $(this).prop('disabled', false).closest('.form-group').stop().slideDown(slide, function(){ $(this).css({display: 'block'}); }); if(key[2] && slide){ key[2] = $(this).data('value'); } else{ ch = false; } } else{ ch = false; } $(this).data('hidden', hidden); } break; } if(key[2] && ch){ if($(this).is(':checkbox')){ if(+($(this).prop('checked')) != parseInt(key[2])){ $(this).data('value', ($(this).prop('checked')? '1' : '0')); $(this).prop('checked', ('0' != key[2])).trigger('change'); } } else{ if($(this).val() != key[2]){ $(this).data('value', $(this).val()); $(this).val(key[2]).trigger('change'); } } } }); } } }); </script> </div> <?php wp_nonce_field('GmediaGallery'); ?> </form> <!-- Modal --> <?php if ($gmCore->caps['gmedia_edit_others_media']) { ?> <div class="modal fade gmedia-modal" id="gallModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"></div> </div> <?php } ?> <div class="modal fade gmedia-modal" id="chooseModuleModal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title"><?php _e('Choose Module for Gallery'); ?> </h4> </div> <div class="modal-body linkblock"> <?php if (!empty($alert)) { echo $gmProcessor->alert('danger', $alert); } $current_module = $module_name; if (!empty($modules)) { foreach ($modules as $m) { /** * @var $module_name * @var $module_url * @var $module_path */ extract($m); if ($module_name == $current_module || !file_exists($module_path . '/index.php')) { continue; } $module_info = array(); include $module_path . '/index.php'; if (empty($module_info)) { continue; } $mclass = ' module-' . $module_info['type'] . ' module-' . $module_info['status']; ?> <div data-href="<?php echo add_query_arg(array('edit_gallery' => $gallery_id, 'gallery_module' => $module_name), $url); ?> " class="choose-module media<?php echo $mclass; ?> "> <a href="<?php echo add_query_arg(array('edit_gallery' => $gallery_id, 'gallery_module' => $module_name), $url); ?> " class="thumbnail pull-left"> <img class="media-object" src="<?php echo $module_url . '/screenshot.png'; ?> " alt="<?php echo esc_attr($module_info['title']); ?> " width="160" height="120"/> </a> <div class="media-body" style="margin-left:180px;"> <h4 class="media-heading"><?php echo $module_info['title']; ?> </h4> <p class="version"><?php echo __('Version', 'gmLang') . ': ' . $module_info['version']; ?> </p> <div class="description"><?php echo nl2br($module_info['description']); ?> </div> </div> </div> <?php } } else { _e('No installed modules', 'gmLang'); } ?> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"><?php _e('Cancel', 'gmLang'); ?> </button> </div> </div> </div> </div> <?php }
/** * @param $action * @param $data * * @param bool $filter * * @return array */ function gmedia_ios_app_processor($action, $data, $filter = true) { global $gmCore, $gmDB, $gmGallery, $user_ID; $out = array(); $error = array(); $alert = array(); $data = (array) $data; switch ($action) { case 'do_library': if (!isset($data['action'])) { return $out; } switch ($data['action']) { case 'add_media': if (!current_user_can('gmedia_upload')) { $out['error'] = array('code' => 'nocapability', 'title' => __("You can't do this", 'gmLang'), 'message' => __('You have no permission to do this operation', 'gmLang')); return $out; } usleep(10); if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { $file_name = $_FILES['userfile']['name']; $file_tmp = $_FILES['userfile']['tmp_name']; } else { $error[] = __("Failed to move uploaded file.", 'gmLang'); break; } $fileinfo = $gmCore->fileinfo($file_name); if (false === $fileinfo) { break; } $gmedia = (array) $data['item']; if (!current_user_can('gmedia_terms')) { unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']); } else { if (!empty($gmedia['categories'])) { $cat = $gmedia['categories'][0]->name; $gmedia['terms']['gmedia_category'] = $cat; } if (empty($gmedia['albums'])) { $gmedia['terms']['gmedia_album'] = ''; } else { $alb = isset($gmedia['albums'][0]->term_id) ? $gmedia['albums'][0]->term_id : $gmedia['albums'][0]->name; $gmedia['terms']['gmedia_album'] = $alb; } if (empty($gmedia['tags'])) { $gmedia['terms']['gmedia_tag'] = ''; } else { $tags = array(); foreach ($gmedia['tags'] as $tag) { $tags[] = isset($tag->term_id) ? $tag->term_id : $tag->name; } $gmedia['terms']['gmedia_tag'] = implode(',', $tags); } unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']); } /*if(isset($gmedia['terms'])){ $post_data = array('terms' => $gmedia['terms']); } else{ $post_data = array(); }*/ $return = $gmCore->gmedia_upload_handler($file_tmp, $fileinfo, 'multipart', $gmedia); if (isset($return['error'])) { $error[] = $return['error']['message']; } else { $alert[] = $return['success']['message']; } break; case 'update_media': $gmedia = (array) $data['item']; if (!empty($gmedia['ID'])) { $item = $gmDB->get_gmedia($gmedia['ID']); $gmedia['modified'] = current_time('mysql'); $gmedia['mime_type'] = $item->mime_type; $gmedia['gmuid'] = $item->gmuid; if (!current_user_can('gmedia_delete_others_media')) { $gmedia['author'] = $item->author; } if (!current_user_can('gmedia_terms')) { unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']); } else { if (!empty($gmedia['categories'])) { $cat = $gmedia['categories'][0]->name; $gmedia['terms']['gmedia_category'] = $cat; } if (empty($gmedia['albums'])) { $gmedia['terms']['gmedia_album'] = ''; } else { if (isset($gmedia['albums'][0]->term_id)) { $gmedia['terms']['gmedia_album'] = $gmedia['albums'][0]->term_id; } elseif (current_user_can('gmedia_album_manage')) { $gmedia['terms']['gmedia_album'] = $gmedia['albums'][0]->name; } } if (empty($gmedia['tags'])) { $gmedia['terms']['gmedia_tag'] = ''; } else { $tags = array(); foreach ($gmedia['tags'] as $tag) { if (isset($tag->term_id)) { $tags[] = $tag->term_id; } elseif (current_user_can('gmedia_tag_manage')) { $tags[] = $tag->name; } } $gmedia['terms']['gmedia_tag'] = implode(',', $tags); } unset($gmedia['categories'], $gmedia['albums'], $gmedia['tags']); } if ((int) $item->author == get_current_user_id()) { if (!current_user_can('gmedia_edit_media')) { $alert[] = __('You are not allowed to edit media', 'gmLang'); } } else { if (!current_user_can('gmedia_edit_others_media')) { $alert[] = __('You are not allowed to edit others media', 'gmLang'); } } if (empty($alert)) { $gmDB->insert_gmedia($gmedia); } else { if (current_user_can('gmedia_terms') && count($gmedia['terms'])) { foreach ($gmedia['terms'] as $tax => $terms) { $result = $gmDB->set_gmedia_terms($gmedia['ID'], $terms, $tax, $append = 0); if (is_wp_error($result)) { $error[] = $result->get_error_message(); } } } } } break; case 'assign_category': if (!current_user_can('gmedia_terms')) { $error[] = __('You are not allowed to manage categories', 'gmLang'); break; } $term = $data['assign_category'][0]; if (false === $term) { break; } $count = count($data['selected']); if ('0' == $term) { foreach ($data['selected'] as $item) { $gmDB->delete_gmedia_term_relationships($item, 'gmedia_category'); } $alert[] = sprintf(__('%d items updated with "Uncategorized"', 'gmLang'), $count); } else { foreach ($data['selected'] as $item) { $result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_category', $append = 0); if (is_wp_error($result)) { $error[] = $result->get_error_message(); $count--; } elseif (!$result) { $count--; } } if (isset($gmGallery->options['taxonomies']['gmedia_category'][$term])) { $cat_name = $gmGallery->options['taxonomies']['gmedia_category'][$term]; $alert[] = sprintf(__("Category `%s` assigned to %d images.", 'gmLang'), esc_html($cat_name), $count); } else { $error[] = sprintf(__("Category `%s` can't be assigned.", 'gmLang'), $term); } } break; case 'assign_album': if (!current_user_can('gmedia_terms')) { $error[] = __('You are not allowed to manage albums', 'gmLang'); } $term = $data['assign_album'][0]; $count = count($data['selected']); if ('0' == $term) { foreach ($data['selected'] as $item) { $gmDB->delete_gmedia_term_relationships($item, 'gmedia_album'); } $alert[] = sprintf(__('%d items updated with "No Album"', 'gmLang'), $count); } else { foreach ($data['selected'] as $item) { $result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_album', $append = 0); if (is_wp_error($result)) { $error[] = $result->get_error_message(); $count--; } elseif (!$result) { $count--; } } if ($gmCore->is_digit($term)) { $alb_name = $gmDB->get_alb_name($term); } else { $alb_name = $term; } $alert[] = sprintf(__('Album `%s` assigned to %d items', 'gmLang'), esc_html($alb_name), $count); } break; case 'add_tags': if (!current_user_can('gmedia_terms')) { $error[] = __('You are not allowed manage tags', 'gmLang'); break; } if (empty($data['add_tags'])) { $error[] = __('No tags provided', 'gmLang'); break; } $term = $data['add_tags']; $count = count($data['selected']); foreach ($data['selected'] as $item) { $result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_tag', $append = 1); if (is_wp_error($result)) { $error[] = $result->get_error_message(); $count--; } elseif (!$result) { $count--; } } $alert[] = sprintf(__('%d tags added to %d items', 'gmLang'), count($term), $count); break; case 'delete_tags': if (!current_user_can('gmedia_delete_others_media')) { $error[] = __('You are not allowed to delete others media', 'gmLang'); break; } if (empty($data['delete_tags'])) { $error[] = __('No tags provided', 'gmLang'); break; } $term = array_map('intval', $data['delete_tags']); $count = count($data['selected']); foreach ($data['selected'] as $item) { $result = $gmDB->set_gmedia_terms($item, $term, 'gmedia_tag', $append = -1); if (is_wp_error($result)) { $error[] = $result->get_error_message(); $count--; } elseif (!$result) { $count--; } } $alert[] = sprintf(__('%d tags deleted from %d items', 'gmLang'), count($term), $count); break; case 'delete': if (!current_user_can('gmedia_delete_media')) { $error[] = __('You are not allowed to delete this post.'); break; } $count = count($data['selected']); foreach ($data['selected'] as $item) { $gm_item = $gmDB->get_gmedia($item); if ((int) $gm_item->author != $user_ID && !current_user_can('gmedia_delete_others_media')) { $error[] = "#{$item}: " . __('You are not allowed to delete media others media', 'gmLang'); continue; } if (!$gmDB->delete_gmedia((int) $item)) { $error[] = "#{$item}: " . __('Error in deleting...', 'gmLang'); $count--; } } if ($count) { $alert[] = sprintf(__('%d items deleted successfuly', 'gmLang'), $count); } break; } $filter = gmedia_ios_app_library_data(array('filter', 'gmedia_category', 'gmedia_album', 'gmedia_tag')); $out = array_merge($out, $filter); break; case 'library': $ep = $gmGallery->options['endpoint']; if (get_option('permalink_structure')) { $share_link = home_url(urlencode($ep) . '/$2/$1'); } else { $share_link = add_query_arg(array("{$ep}" => '$1', 't' => '$2'), home_url('index.php')); } $filter = $filter ? gmedia_ios_app_library_data(array('filter')) : array(); $args = array('mime_type' => 'image/*', 'orderby' => 'ID', 'order' => 'DESC', 'per_page' => 100, 'page' => 1, 'tag__in' => null, 'category__in' => null, 'album__in' => null, 'author' => 0, 'status' => null); $data = wp_parse_args($data, $args); $false_out = array_merge($filter, array('properties' => array('request' => isset($data['request']) ? $data['request'] : null), 'data' => array())); $is_collection = !(empty($data['album__in']) && empty($data['tag__in']) && empty($data['category__in'])); $is_admin = isset($data['admin']) ? intval($data['admin']) : 0; if (!is_user_logged_in()) { $data['status'] = array('public'); if ($is_collection) { if (!empty($data['album__in'])) { $alb = $gmDB->get_term((int) $data['album__in'][0], 'gmedia_album'); if (!(isset($alb->status) && 'public' == $alb->status)) { $out = $false_out; break; } } } else { $out = $false_out; break; } } else { if ($is_admin && !current_user_can('gmedia_library')) { $out = $false_out; break; } if ($is_admin && !current_user_can('gmedia_show_others_media')) { $data['author'] = $user_ID; } } $gmedias = $gmDB->get_gmedias($data); foreach ($gmedias as $i => $item) { if (!$is_admin && 'draft' == $item->status && (int) $user_ID != (int) $item->author) { //if (!current_user_can('gmedia_edit_others_media')){ unset($gmedias[$i]); continue; //} } $author_id = $item->author; $authordata = get_userdata($author_id); if ($authordata) { $display_name = $authordata->display_name; $first_name = $authordata->first_name; $last_name = $authordata->last_name; } else { $display_name = __('Deleted User', 'gmLang'); $first_name = ''; $last_name = ''; } $gmedias[$i]->user = array('id' => $author_id, 'displayname' => $display_name, 'firstname' => $first_name, 'last_name' => $last_name); $meta = $gmDB->get_metadata('gmedia', $item->ID); $_metadata = maybe_unserialize($meta['_metadata'][0]); $type = explode('/', $item->mime_type); $item_url = $gmCore->upload['url'] . '/' . $gmGallery->options['folder'][$type[0]] . '/' . $item->gmuid; $gmedias[$i]->url = $item_url; $terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_tag'); $tags = array(); if ($terms) { $terms = array_values((array) $terms); foreach ($terms as $term) { $tags[] = array('term_id' => $term->term_id, 'name' => $term->name); } } $gmedias[$i]->tags = $tags; $terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_album'); $albums = array(); if ($terms) { $terms = array_values((array) $terms); foreach ($terms as $term) { $albums[] = array('term_id' => $term->term_id, 'name' => $term->name, 'status' => $term->status); } } $gmedias[$i]->albums = $albums; if ('image' == $type[0]) { $terms = $gmDB->get_the_gmedia_terms($item->ID, 'gmedia_category'); $categories = array(); if ($terms) { $terms = array_values((array) $terms); foreach ($terms as $term) { $categories[] = array('term_id' => $term->term_id, 'name' => $term->name); } } $gmedias[$i]->categories = $categories; $gmedias[$i]->meta = array('thumb' => $_metadata['thumb'], 'web' => $_metadata['web'], 'original' => $_metadata['original']); $gmedias[$i]->meta['thumb']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_thumb']}/{$item->gmuid}"; $gmedias[$i]->meta['web']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image']}/{$item->gmuid}"; $gmedias[$i]->meta['original']['link'] = "{$gmCore->upload['url']}/{$gmGallery->options['folder']['image_original']}/{$item->gmuid}"; $gmedias[$i]->meta['views'] = 0; $gmedias[$i]->meta['likes'] = 0; if (isset($meta['views'][0])) { $gmedias[$i]->meta['views'] = $meta['views'][0]; } if (isset($meta['likes'][0])) { $gmedias[$i]->meta['likes'] = $meta['likes'][0]; } if (isset($_metadata['image_info'])) { $gmedias[$i]->meta['data'] = $_metadata['image_info']; } } else { $gmedias[$i]->meta = array('thumb' => array('link' => $gmCore->gm_get_media_image($item, 'thumb'), 'width' => 300, 'height' => 300)); if (!empty($_metadata)) { $gmedias[$i]->meta['data'] = $_metadata; } } if (isset($meta['rating'][0])) { $gmedias[$i]->meta['rating'] = maybe_unserialize($meta['rating'][0]); } $item_name = $item->title ? $item->title : pathinfo($item->gmuid, PATHINFO_FILENAME); $gmedia_hashid = gmedia_hash_id_encode($item->ID, 'single'); $gmedias[$i]->sharelink = str_replace(array('$1', '$2'), array(urlencode($gmedia_hashid), 's'), $share_link); } $out = array_merge($filter, array('properties' => array('request' => isset($data['request']) ? $data['request'] : null, 'total_pages' => $gmDB->pages, 'current_page' => $gmDB->openPage, 'items_count' => $gmDB->gmediaCount), 'data' => array_values($gmedias))); break; case 'delete_term': $taxonomy = $data['taxonomy']; if (!empty($data['items'])) { if (!current_user_can('gmedia_terms_delete')) { $error[] = __('You have no permission to do this operation', 'gmLang'); break; } $count = count($data['items']); foreach ($data['items'] as $item) { if (!current_user_can('gmedia_edit_others_media')) { if ('gmedia_album' == $taxonomy) { $term = $gmDB->get_term($item, $taxonomy); if ((int) $term->global != (int) $user_ID) { $error['delete_album'] = __('You are not allowed to edit others media', 'gmLang'); $count--; continue; } } else { $error[] = __('You are not allowed to edit others media', 'gmLang'); $count--; continue; } } $delete = $gmDB->delete_term($item, $taxonomy); if (is_wp_error($delete)) { $error[] = $delete->get_error_message(); $count--; } } if ($count) { $alert[] = sprintf(__('%d items deleted successfuly', 'gmLang'), $count); } } $out = gmedia_ios_app_library_data(array('filter', $taxonomy)); break; case 'add_term': $taxonomy = $data['taxonomy']; $edit_term = isset($data['term_id']) ? (int) $data['term_id'] : 0; $term = $data; if ('gmedia_album' == $taxonomy) { if (!current_user_can('gmedia_album_manage')) { $out['error'] = array('code' => 'nocapability', 'title' => __("You can't do this", 'gmLang'), 'message' => __('You have no permission to do this operation', 'gmLang')); return $out; } do { $term['name'] = trim($term['name']); if (empty($term['name'])) { $error[] = __('Term Name is not specified', 'gmLang'); break; } if ($gmCore->is_digit($term['name'])) { $error[] = __("Term Name can't be only digits", 'gmLang'); break; } if ($edit_term && !$gmDB->term_exists($edit_term, $taxonomy)) { $error[] = __('A term with the id provided do not exists', 'gmLang'); $edit_term = false; } if ($term_id = $gmDB->term_exists($term['name'], $taxonomy)) { if ($term_id != $edit_term) { $error[] = __('A term with the name provided already exists', 'gmLang'); break; } } if ($edit_term) { $_term = $gmDB->get_term($edit_term, $taxonomy); if ((int) $_term->global != (int) $user_ID && !current_user_can('gmedia_edit_others_media')) { $error[] = __('You are not allowed to edit others media', 'gmLang'); break; } $term_id = $gmDB->update_term($edit_term, $taxonomy, $term); } else { if (!current_user_can('gmedia_edit_others_media')) { $term['global'] = intval($user_ID); } $term_id = $gmDB->insert_term($term['name'], $taxonomy, $term); } if (is_wp_error($term_id)) { $error[] = $term_id->get_error_message(); break; } $term_meta = array('orderby' => $term['orderby'], 'order' => $term['order']); foreach ($term_meta as $key => $value) { if ($edit_term) { $gmDB->update_metadata('gmedia_term', $term_id, $key, $value); } else { $gmDB->add_metadata('gmedia_term', $term_id, $key, $value); } } $alert[] = sprintf(__('Album `%s` successfuly saved', 'gmLang'), $term['name']); } while (0); $out = gmedia_ios_app_library_data(array('filter', $taxonomy)); } elseif ('gmedia_tag' == $taxonomy) { if (!current_user_can('gmedia_tag_manage')) { $out['error'] = array('code' => 'nocapability', 'title' => __("You can't do this", 'gmLang'), 'message' => __('You have no permission to do this operation', 'gmLang')); return $out; } if ($edit_term) { if (!current_user_can('gmedia_edit_others_media')) { $error[] = __('You are not allowed to edit others media', 'gmLang'); break; } $term['name'] = trim($term['name']); $term['term_id'] = intval($term['term_id']); if ($term['name'] && !$gmCore->is_digit($term['name'])) { if ($term_id = $gmDB->term_exists($term['term_id'], $taxonomy)) { if (!$gmDB->term_exists($term['name'], $taxonomy)) { $term_id = $gmDB->update_term($term['term_id'], $taxonomy, $term); if (is_wp_error($term_id)) { $error[] = $term_id->get_error_message(); } else { $alert[] = sprintf(__("Tag %d successfuly updated", 'gmLang'), $term_id); } } else { $error[] = __('A term with the name provided already exists', 'gmLang'); } } else { $error[] = __("A term with the id provided do not exists", 'gmLang'); } } else { $error[] = __("Term name can't be only digits or empty", 'gmLang'); } } else { $terms = array_filter(array_map('trim', explode(',', $term['name']))); $terms_added = 0; $terms_qty = count($terms); foreach ($terms as $term_name) { if ($gmCore->is_digit($term_name)) { continue; } if (!$gmDB->term_exists($term_name, $taxonomy)) { $term_id = $gmDB->insert_term($term_name, $taxonomy); if (is_wp_error($term_id)) { $error[] = $term_id->get_error_message(); } else { $alert['tag_add'] = sprintf(__('%d of %d tags successfuly added', 'gmLang'), ++$terms_added, $terms_qty); } } else { $alert['tag_add'] = __('Some of provided tags are already exists', 'gmLang'); } } } $out = gmedia_ios_app_library_data(array('filter', $taxonomy)); } break; default: break; } if (!empty($error)) { $out['error'] = array('code' => $action, 'title' => 'ERROR', 'message' => implode("\n", $error)); } if (!empty($alert)) { $out['alert'] = array('title' => 'Success', 'message' => implode("\n", $alert)); } return $out; }