function media_upload_gmedia() { global $gmCore, $gmDB; add_action('admin_enqueue_scripts', 'gmedia_add_media_popup_enqueue_scripts'); $action = $gmCore->_get('action'); if (did_action('media_upload_gmedia_galleries')) { wp_iframe('gmedia_add_media_galleries'); } elseif (did_action('media_upload_gmedia_terms')) { wp_iframe('gmedia_add_media_terms'); } elseif (did_action('media_upload_gmedia_library')) { if ('upload' == $action && current_user_can('gmedia_upload')) { wp_iframe('gmedia_add_media_upload'); } else { wp_iframe('gmedia_add_media_library'); } } // Generate TinyMCE HTML output if (isset($_POST['gmedia_library_insert'])) { $id = $gmCore->_post('ID', 0); if ($gmedia = $gmDB->get_gmedia($id)) { $meta = $gmDB->get_metadata('gmedia', $gmedia->ID, '_metadata', true); $size = $gmCore->_post('size', 'web'); $src = $gmCore->gm_get_media_image($gmedia, $size); $width = $meta[$size]['width']; $height = $meta[$size]['height']; $title = esc_attr($gmCore->_post('title', '')); $align = esc_attr($gmCore->_post('align', 'none')); $link = trim(esc_attr($gmCore->_post('link', ''))); $caption = trim($gmCore->_post('description', '')); $html = "<img src='{$src}' width='{$width}' height='{$height}' alt='{$title}' title='{$title}' id='gmedia-image-{$id}' class='gmedia-singlepic align{$align}' />"; if ($link) { $html = "<a href='{$link}'>{$html}</a>"; } if ($caption) { $html = image_add_caption($html, false, $caption, $title, $align, $src, $size, $title); } ?> <script type="text/javascript"> /* <![CDATA[ */ var win = window.dialogArguments || opener || parent || top; jQuery('#__gm-uploader', win.document).css('display', 'none'); /* ]]> */ </script> <?php // Return it to TinyMCE media_send_to_editor($html); } } if (isset($_POST['gmedia_gallery_insert'])) { $sc = $gmCore->_post('shortcode'); ?> <script type="text/javascript"> /* <![CDATA[ */ var win = window.dialogArguments || opener || parent || top; jQuery('#__gm-uploader', win.document).css('display', 'none'); /* ]]> */ </script> <?php // Return it to TinyMCE media_send_to_editor($sc); } if (isset($_POST['gmedia_term_insert'])) { $module_preset = $gmCore->_post('module_preset'); $module = ''; $preset = ''; if (!empty($module_preset)) { if ($gmCore->is_digit($module_preset)) { $module_preset = $gmDB->get_term((int) $module_preset); $module = ' module=' . $module_preset->status; $preset = ' preset=' . $module_preset->term_id; } else { $module = ' module=' . $module_preset; } } $tax = $gmCore->_post('taxonomy'); $term_id = $gmCore->_post('term_id'); if ($tax && $term_id) { $tax = str_replace('gmedia_', '', $tax); $sc = "[gm {$tax}={$term_id}{$module}{$preset}]"; ?> <script type="text/javascript"> /* <![CDATA[ */ var win = window.dialogArguments || opener || parent || top; jQuery('#__gm-uploader', win.document).css('display', 'none'); /* ]]> */ </script> <?php // Return it to TinyMCE media_send_to_editor($sc); } } }
/** * Display shortcode * @since 1.4 * @param array $atts * @param string $content * @uses array $_wp_additional_image_sizes * @uses array $all_sizes * @uses int $blog_id * @uses object $post * @uses object $wpdb * @uses do_shortcode() * @uses get_attachment_link() * @uses get_blog_prefix() * @uses get_option() * @uses get_user_by() * @uses get_query_var() * @uses get_the_author_meta() * @uses get_user_meta() * @uses get_wp_user_avatar_src() * @uses get_wp_user_avatar() * @uses image_add_caption() * @uses is_author() * @uses shortcode_atts() * @return string */ public function wpua_shortcode($atts, $content = null) { global $all_sizes, $blog_id, $post, $wpdb; // Set shortcode attributes extract(shortcode_atts(array('user' => "", 'size' => '96', 'align' => "", 'link' => "", 'target' => ""), $atts)); // Find user by ID, login, slug, or e-mail address if (!empty($user)) { $user = is_numeric($user) ? get_user_by('id', $user) : get_user_by('login', $user); $user = empty($user) ? get_user_by('slug', $user) : $user; $user = empty($user) ? get_user_by('email', $user) : $user; } else { // Find author's name if id_or_email is empty $author_name = get_query_var('author_name'); if (is_author()) { // On author page, get user by page slug $user = get_user_by('slug', $author_name); } else { // On post, get user by author meta $user_id = get_the_author_meta('ID'); $user = get_user_by('id', $user_id); } } // Numeric sizes leave as-is $get_size = $size; // Check for custom image sizes if there are captions if (!empty($content)) { if (in_array($size, $all_sizes)) { if (in_array($size, array('original', 'large', 'medium', 'thumbnail'))) { $get_size = $size == 'original' ? get_option('large_size_w') : get_option($size . '_size_w'); } else { $get_size = $_wp_additional_image_sizes[$size]['width']; } } } // Get user ID $id_or_email = !empty($user) ? $user->ID : '*****@*****.**'; // Check if link is set if (!empty($link)) { // CSS class is same as link type, except for URL $link_class = $link; if ($link == 'file') { // Get image src $link = get_wp_user_avatar_src($id_or_email, 'original'); } elseif ($link == 'attachment') { // Get attachment URL $link = get_attachment_link(get_the_author_meta($wpdb->get_blog_prefix($blog_id) . 'user_avatar', $id_or_email)); } else { // URL $link_class = 'custom'; } // Open in new window $target_link = !empty($target) ? ' target="' . $target . '"' : ""; // Wrap the avatar inside the link $html = '<a href="' . $link . '" class="wp-user-avatar-link wp-user-avatar-' . $link_class . '"' . $target_link . '>' . get_wp_user_avatar($id_or_email, $get_size, $align) . '</a>'; } else { $html = get_wp_user_avatar($id_or_email, $get_size, $align); } // Check if caption is set if (!empty($content)) { // Get attachment ID $wpua = get_user_meta($id_or_email, $wpdb->get_blog_prefix($blog_id) . 'user_avatar', true); // Clean up caption $content = trim($content); $content = preg_replace('/\\r|\\n/', "", $content); $content = preg_replace('/<\\/p><p>/', "", $content, 1); $content = preg_replace('/<\\/p><p>$/', "", $content); $content = str_replace('</p><p>', "<br /><br />", $content); $avatar = do_shortcode(image_add_caption($html, $wpua, $content, $title = "", $align, $link, $get_size, $alt = "")); } else { $avatar = $html; } return $avatar; }