function bp_links_auto_embed_panel_content($embed_service = null) { if (!$embed_service instanceof BP_Links_Embed_Service) { return; } // no selected image index by default $image_idx = null; $image_selected_idx = null; $image_selection_count = 0; $image_selection_diplay = null; // multiple images to select from? if ($embed_service instanceof BP_Links_Embed_Has_Selectable_Image && count($embed_service->image_selection()) >= 1) { // body of javascript array $js_array = array(); // user selected image index $image_idx = isset($_POST['link-url-embed-thidx']) ? $_POST['link-url-embed-thidx'] : $embed_service->image_get_selected(); // selected image index from data storage $image_selected_idx = $embed_service->image_get_selected(); // count of images in selection $image_selection_count = count($embed_service->image_selection()); foreach ($embed_service->image_selection() as $idx => $url) { if (is_int($idx)) { $js_array[] = sprintf('[%d,"%s"]', $idx, $url); } else { $js_array[] = sprintf('["%s","%s"]', $idx, $url); } } // js syntax strings $image_js_img = join(",", $js_array); $image_js_img_idx = is_null($image_idx) ? 'null' : $image_idx; // render js element ?> <script type="text/javascript"> jQuery(document).ready( function() { jQuery("div#link-url-embed-thpick").data("images", [ <?php echo $image_js_img; ?> ] ); jQuery("div#link-url-embed-thpick").data("images_idx", <?php echo $image_js_img_idx; ?> ); return; }); </script><?php } else { // don't display the thumb picker $image_selection_diplay = ' style="display: none;"'; } // determine output thumb url $service_thumb_url = $embed_service->image_thumb_url(); if (!empty($service_thumb_url) && bp_links_is_url_valid($service_thumb_url)) { $thumb_url = $service_thumb_url; } else { // service or owner chose not to have a thumb $thumb_url = bp_links_default_avatar_uri(); } // checkiness vars $checked_edit = !empty($_POST['link-url-embed-edit-text']) ? ' checked="checked"' : null; $checked_thumb = is_null($image_idx) ? ' checked="checked"' : null; // render the html ?> <label style="clear: right;"> <?php _e('Rich Media Detected:', 'buddypress-links'); ?> <?php echo esc_html($embed_service->service_name()); ?> </label> <div id="link-url-embed-content"> <div id="link-url-embed-avatar"> <img src="<?php echo esc_url($thumb_url); ?> " class="avatar-current" alt="<?php echo esc_attr($embed_service->title()); ?> "> <div id="link-url-embed-thpick"<?php echo $image_selection_diplay; ?> > <a href="#thprev" id="thprev"><</a> <span id="thcurrent"><?php echo $image_idx + 1; ?> </span>/<span id="thcount"><?php echo $image_selection_count; ?> </span> <?php _e('Thumbs', 'buddypress-links'); ?> <a href="#thnext" id="thnext">></a> <div id="thnone"> <input type="checkbox" name="link-url-embed-thskip" id="link-url-embed-thskip" value="1"<?php echo $checked_thumb; ?> > <?php _e('No Thumbnail', 'buddypress-links'); ?> </div> </div> </div> <a href="<?php echo esc_url($embed_service->url()); ?> " target="_blank"><?php echo esc_html($embed_service->title()); ?> </a> <p><?php echo esc_html($embed_service->description()); ?> </p> <div id="link-url-embed-options"> <label for="link-url-embed-edit-text"> <input type="checkbox" name="link-url-embed-edit-text" id="link-url-embed-edit-text" value="1"<?php echo $checked_edit; ?> > <?php _e('Edit Name and Description', 'buddypress-links'); ?> </label> <input type="hidden" name="link-url-embed-data" id="link-url-embed-data" value="<?php echo $embed_service->export_data(); ?> "> <input type="hidden" name="link-url-embed-thidx" id="link-url-embed-thidx" value="<?php echo esc_attr($image_selected_idx); ?> "> </div> </div><?php }
function bp_get_links_auto_embed_panel_content($embed_service = null) { if (!$embed_service instanceof BP_Links_Embed_Service) { return null; } // no js html or selected image index by default $js_html = null; $image_idx = null; $image_selected_idx = null; $image_selection_count = 0; $image_selection_diplay = null; // multiple images to select from? if ($embed_service instanceof BP_Links_Embed_Has_Selectable_Image && count($embed_service->image_selection()) >= 1) { // body of javascript array $js_array = array(); // user selected image index $image_idx = isset($_POST['link-url-embed-thidx']) ? $_POST['link-url-embed-thidx'] : $embed_service->image_get_selected(); // selected image index from data storage $image_selected_idx = $embed_service->image_get_selected(); // count of images in selection $image_selection_count = count($embed_service->image_selection()); foreach ($embed_service->image_selection() as $idx => $url) { if (is_int($idx)) { $js_array[] = sprintf('[%d,"%s"]', $idx, $url); } else { $js_array[] = sprintf('["%s","%s"]', $idx, $url); } } $js_html = sprintf('<script type="text/javascript"> jQuery(document).ready( function() { jQuery("div#link-url-embed-thpick").data("images", [ %1$s ] ); jQuery("div#link-url-embed-thpick").data("images_idx", %2$s ); return; }); </script>%3$s', join(",", $js_array), is_null($image_idx) ? 'null' : $image_idx, PHP_EOL); } else { // don't display the thumb picker $image_selection_diplay = ' style="display: none;"'; } // determine output thumb url $service_thumb_url = $embed_service->image_thumb_url(); if (!empty($service_thumb_url) && bp_links_is_url_valid($service_thumb_url)) { $thumb_url = $service_thumb_url; } else { // service or owner chose not to have a thumb $thumb_url = bp_links_default_avatar_uri(); } return $js_html . sprintf('<label style="clear: right;"> %1$s %3$s </label> <div id="link-url-embed-content"> <div id="link-url-embed-avatar"> <img src="%4$s" class="avatar-current" alt="%5$s"> <div id="link-url-embed-thpick"%12$s> <a href="#thprev" id="thprev"><</a> <span id="thcurrent">%13$d</span>/<span id="thcount">%14$d</span> %15$s <a href="#thnext" id="thnext">></a> <div id="thnone"> <input type="checkbox" name="link-url-embed-thskip" id="link-url-embed-thskip" value="1"%16$s /> %17$s </div> </div> </div> <a href="%7$s" target="_blank">%6$s</a> <p>%8$s</p> <div id="link-url-embed-options"> <label for="link-url-embed-edit-text"><input type="checkbox" name="link-url-embed-edit-text" id="link-url-embed-edit-text" value="1"%9$s /> %2$s</label> <input type="hidden" name="link-url-embed-data" id="link-url-embed-data" value="%10$s" /> <input type="hidden" name="link-url-embed-thidx" id="link-url-embed-thidx" value="%11$s" /> </div> </div>', __('Rich Media Detected:', 'buddypress-links'), __('Edit Name and Description', 'buddypress-links'), esc_html($embed_service->service_name()), esc_url($thumb_url), esc_attr($embed_service->title()), esc_html($embed_service->title()), esc_url($embed_service->url()), esc_html($embed_service->description()), !empty($_POST['link-url-embed-edit-text']) ? ' checked="checked"' : null, $embed_service->export_data(), $image_selected_idx, $image_selection_diplay, $image_idx + 1, $image_selection_count, __('Thumbs', 'buddypress-links'), is_null($image_idx) ? ' checked="checked"' : null, __('No Thumbnail', 'buddypress-links')); }
function bp_links_fetch_avatar($args = '', $link = false) { $defaults = array('item_id' => false, 'type' => 'full', 'width' => false, 'height' => false, 'class' => 'avatar', 'css_id' => false, 'alt' => __('Link Avatar', 'buddypress-links')); $params = wp_parse_args($args, $defaults); // hard code these options to prevent tampering // DO NOT try to use a gravatar, ever! $params['object'] = 'link'; $params['avatar_dir'] = 'link-avatars'; $params['no_grav'] = true; // try to grab avatar file $avatar = bp_core_fetch_avatar($params); if (!empty($avatar)) { // found an avatar file, return html for it return $avatar; } else { extract($params, EXTR_SKIP); $avatar_url = null; // check if we can use thumb from embedded content if ($link instanceof BP_Links_Link && $link->embed_status_enabled()) { $image_thumb_url = $link->embed()->image_thumb_url(); if (!empty($image_thumb_url)) { // check for additional avatar class if ($link->embed()->avatar_class()) { $class .= ' ' . $link->embed()->avatar_class(); } // when avatar type is 'full', check for avatar size limits and special class if ('full' == $type) { // get large thumb url from service object $avatar_url = $link->embed()->image_large_thumb_url(); // check for custom width and height if ($link->embed()->avatar_max_width() && $link->embed()->avatar_max_height()) { $width = $link->embed()->avatar_max_width(); $height = $link->embed()->avatar_max_height(); } } else { // get standard thumb url from service object $avatar_url = $link->embed()->image_thumb_url(); } } } // have an avatar file yet? if (empty($avatar_url)) { // no avatar file found, use the default image $avatar_url = bp_links_default_avatar_uri(); // default width/height if (empty($width)) { $width = 'thumb' == $type ? BP_AVATAR_THUMB_WIDTH : BP_AVATAR_FULL_WIDTH; } if (empty($height)) { $height = 'thumb' == $type ? BP_AVATAR_THUMB_HEIGHT : BP_AVATAR_FULL_HEIGHT; } } if (!$css_id) { $css_id = $object . '-' . $item_id . '-avatar'; } if ($width) { $attr_width = " width='{$width}'"; } if ($height) { $attr_height = " height='{$height}'"; } return apply_filters('bp_links_fetch_avatar_not_found', sprintf('<img src="%s" alt="%s" id="%s" class="%s"%s%s />', $avatar_url, $alt, $css_id, $class, $attr_width, $attr_height), $args); } }