Exemplo n.º 1
0
function wppa_get_share_html($id, $key = '', $js = true)
{
    global $wppa_locale;
    $do_it = false;
    if (!wppa('is_slideonly') || $key == 'lightbox') {
        if (wppa_switch('share_on') && !wppa_in_widget()) {
            $do_it = true;
        }
        if (wppa_switch('share_on_widget') && wppa_in_widget()) {
            $do_it = true;
        }
        if (wppa_switch('share_on_lightbox')) {
            $do_it = true;
        }
    }
    if (!$do_it) {
        return '';
    }
    // The share url
    if (wppa_in_widget()) {
        if (wppa_opt('widget_sm_linktype') == 'home') {
            $share_url = home_url();
        } else {
            $share_url = get_permalink(wppa_get_the_landing_page('wppa_widget_sm_linkpage', __('Social media landing page', 'wp-photo-album-plus')));
            $alb = wppa_get_photo_item($id, 'album');
            $oc = wppa_opt('widget_sm_linkpage_oc');
            $share_url .= '?wppa-album=' . $alb . '&wppa-photo=' . $id . '&wppa-cover=0&wppa-occur=' . $oc;
            if (wppa_switch('share_single_image')) {
                $share_url .= '&wppa-single=1';
            }
        }
    } else {
        $share_url = wppa_get_image_page_url_by_id($id, wppa_switch('share_single_image'));
        $share_url = str_replace('&', '&', $share_url);
    }
    // The share title
    $photo_name = wppa_get_photo_name($id);
    // The share description
    $photo_desc = wppa_html(wppa_get_photo_desc($id));
    $photo_desc = strip_shortcodes(wppa_strip_tags($photo_desc, 'all'));
    // The default description
    $site = str_replace('&', __('and', 'wp-photo-album-plus'), get_bloginfo('name'));
    $see_on_site = sprintf(__('See this image on %s', 'wp-photo-album-plus'), $site);
    // The share image. Must be the fullsize image for facebook.
    // If you take the thumbnail, facebook takes a different image at random.
    $share_img = wppa_get_photo_url($id);
    // The icon size
    if (wppa_in_widget() && $key != 'lightbox' || $key == 'thumb') {
        $s = '16';
    } else {
        $s = wppa_opt('share_size');
    }
    // qr code
    if (wppa_switch('share_qr') && $key != 'thumb') {
        $src = 'http://api.qrserver.com/v1/create-qr-code/' . '?data=' . urlencode($share_url) . '&size=80x80' . '&color=' . trim(wppa_opt('qr_color'), '#') . '&bgcolor=' . trim(wppa_opt('qr_bgcolor'), '#');
        $qr = '<div style="float:left; padding:2px;" >' . '<img' . ' src="' . $src . '"' . ' title="' . esc_attr($share_url) . '"' . ' alt="' . __('QR code', 'wp-photo-album-plus') . '"' . ' />' . '</div>';
    } else {
        $qr = '';
    }
    // twitter share button
    if (wppa_switch('share_twitter')) {
        $tweet = urlencode($see_on_site) . ': ';
        $tweet_len = strlen($tweet) + '1';
        $tweet .= urlencode($share_url);
        // find first '/' after 'http( s )://' rest doesnt count for twitter chars
        $url_len = strpos($share_url, '/', 8) + 1;
        $tweet_len += $url_len > 1 ? $url_len : strlen($share_url);
        $rest_len = 140 - $tweet_len;
        if (wppa_switch('show_full_name')) {
            if ($rest_len > strlen($photo_name)) {
                $tweet .= ' ' . urlencode($photo_name);
                $rest_len -= strlen($photo_name);
                $rest_len -= '2';
            } else {
                $tweet .= ' ' . urlencode(substr($photo_name, 0, $rest_len)) . '...';
                $rest_len -= strlen(substr($photo_name, 0, $rest_len));
                $rest_len -= '5';
            }
        }
        if ($photo_desc) {
            if ($rest_len > strlen($photo_desc)) {
                $tweet .= ': ' . urlencode($photo_desc);
            } elseif ($rest_len > 8) {
                $tweet .= ': ' . urlencode(substr($photo_desc, 0, $rest_len)) . '...';
            }
        }
        $tw = '<div style="float:left; padding:0 2px;" >' . '<a' . ' title="' . sprintf(__('Tweet %s on Twitter', 'wp-photo-album-plus'), esc_attr($photo_name)) . '"' . ' href="https://twitter.com/intent/tweet?text=' . $tweet . '"' . ' target="_blank"' . ' >' . '<img' . ' src="' . wppa_get_imgdir() . 'twitter.png"' . ' style="height:' . $s . 'px;vertical-align:top;"' . ' alt="' . esc_attr(__('Share on Twitter', 'wp-photo-album-plus')) . '"' . ' />' . '</a>' . '</div>';
    } else {
        $tw = '';
    }
    // Google
    if (wppa_switch('share_google')) {
        $go = '<div style="float:left; padding:0 2px;" >' . '<a' . ' title="' . sprintf(__('Share %s on Google+', 'wp-photo-album-plus'), esc_attr($photo_name)) . '"' . ' href="https://plus.google.com/share?url=' . urlencode($share_url) . '"' . ' onclick="javascript:window.open( this.href, \\"\\", \\"menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600\\" );return false;"' . ' target="_blank"' . ' >' . '<img' . ' src="' . wppa_get_imgdir() . 'google.png"' . ' style="height:' . $s . 'px;vertical-align:top;"' . ' alt="' . esc_attr(__('Share on Google+', 'wp-photo-album-plus')) . '"' . ' />' . '</a>' . '</div>';
    } else {
        $go = '';
    }
    // Pinterest
    $desc = urlencode($see_on_site) . ': ' . urlencode($photo_desc);
    if (strlen($desc) > 500) {
        $desc = substr($desc, 0, 495) . '...';
    }
    if (wppa_switch('share_pinterest')) {
        $pi = '<div style="float:left; padding:0 2px;" >' . '<a' . ' title="' . sprintf(__('Share %s on Pinterest', 'wp-photo-album-plus'), esc_attr($photo_name)) . '"' . ' href="http://pinterest.com/pin/create/button/?url=' . urlencode($share_url) . '&media=' . urlencode(str_replace('/thumbs/', '/', $share_img)) . '&description=' . $desc . '"' . ' target="_blank"' . ' >' . '<img' . ' src="' . wppa_get_imgdir() . 'pinterest.png" style="height:' . $s . 'px;vertical-align:top;"' . ' alt="' . esc_attr(__('Share on Pinterest', 'wp-photo-album-plus')) . '"' . ' />' . '</a>' . '</div>';
    } else {
        $pi = '';
    }
    // LinkedIn
    if (wppa_switch('share_linkedin') && $key != 'thumb' && $key != 'lightbox') {
        $li = '<script' . ' type="text/javascript"' . ' src="//platform.linkedin.com/in.js"' . ' >' . 'lang: ' . $wppa_locale . '</script>' . '<script' . ' type="IN/Share"' . ' data-url="' . urlencode($share_url) . '"' . ' data-counter="top"' . ' >' . '</script>';
        if ($js) {
            $li = str_replace('<', '[', $li);
        }
    } else {
        $li = '';
    }
    // Facebook
    $fb = '';
    $need_fb_init = false;
    $small = 'thumb' == $key;
    if ('lightbox' == $key) {
        if (wppa_switch('facebook_like') && wppa_switch('share_facebook')) {
            $lbs = 'max-width:62px; max-height:96px; overflow:show;';
        } else {
            $lbs = 'max-width:62px; max-height:64px; overflow:show;';
        }
    } else {
        $lbs = '';
    }
    // Share
    if (wppa_switch('share_facebook') && !wppa_switch('facebook_like')) {
        if ($small) {
            $fb .= '<div' . ' class="fb-share-button"' . ' style="float:left;"' . ' data-href="' . $share_url . '"' . ' data-type="icon"' . ' >' . '</div>';
        } else {
            $disp = wppa_opt('fb_display');
            if ('standard' == $disp) {
                $disp = 'button';
            }
            $fb .= '<div' . ' class="fb-share-button"' . ' style="float:left; ' . $lbs . '"' . ' data-width="200"' . ' data-href="' . $share_url . '"' . ' data-type="' . $disp . '"' . ' >' . '</div>';
        }
        $need_fb_init = true;
    }
    // Like
    if (wppa_switch('facebook_like') && !wppa_switch('share_facebook')) {
        if ($small) {
            $fb .= '<div' . ' class="fb-like"' . ' style="float:left;"' . ' data-href="' . $share_url . '"' . ' data-layout="button"' . ' >' . '</div>';
        } else {
            $fb .= '<div' . ' class="fb-like"' . ' style="float:left; ' . $lbs . '"' . ' data-width="200"' . ' data-href="' . $share_url . '"' . ' data-layout="' . wppa_opt('fb_display') . '"' . ' >' . '</div>';
        }
        $need_fb_init = true;
    }
    // Like and share
    if (wppa_switch('facebook_like') && wppa_switch('share_facebook')) {
        if ($small) {
            $fb .= '<div' . ' class="fb-like"' . ' style="float:left;"' . ' data-href="' . $share_url . '"' . ' data-layout="button"' . ' data-action="like"' . ' data-show-faces="false"' . ' data-share="true"' . ' >' . '</div>';
        } else {
            $fb .= '<div' . ' class="fb-like"' . ' style="float:left; ' . $lbs . '"' . ' data-width="200"' . ' data-href="' . $share_url . '"' . ' data-layout="' . wppa_opt('fb_display') . '"' . ' data-action="like"' . ' data-show-faces="false"' . ' data-share="true"' . ' >' . '</div>';
        }
        $need_fb_init = true;
    }
    // Comments
    if (wppa_switch('facebook_comments') && !wppa_in_widget() && $key != 'thumb' && $key != 'lightbox') {
        $width = wppa('auto_colwidth') ? '100%' : wppa_get_container_width(true);
        if (wppa_switch('facebook_comments')) {
            $fb .= '<div style="color:blue;clear:both" >' . __('Comment on Facebook:', 'wp-photo-album-plus') . '</div>';
            $fb .= '<div class="fb-comments" data-href="' . $share_url . '" data-width=' . $width . '></div>';
            $need_fb_init = true;
        }
    }
    // Need init?
    if ($need_fb_init) {
        if ($js && $key != 'thumb') {
            $fb .= '[script>wppaFbInit();[/script>';
        } else {
            $fb .= '<script>wppaFbInit();</script>';
        }
    }
    return $qr . $tw . $go . $pi . $li . $fb . '<div style="clear:both"></div>';
}
function wppa_get_slide_info($index, $id, $callbackid = '')
{
    global $wpdb;
    static $user;
    // Make sure $thumb contains our image data
    $thumb = wppa_cache_thumb($id);
    if (!$user) {
        $user = wppa_get_user();
    }
    $photo = wppa_get_get('photo');
    $ratingphoto = wppa_get_get('rating-id');
    if (!$callbackid) {
        $callbackid = $id;
    }
    // Process a comment if given for this photo
    $comment_request = wppa_get_post('commentbtn') && $id == $photo;
    $comment_allowed = !wppa_switch('comment_login') || is_user_logged_in();
    if (wppa_switch('show_comments') && $comment_request && $comment_allowed) {
        wppa_do_comment($id);
    }
    // Find rating
    if (wppa_switch('rating_on') && !wppa('is_slideonly') && !wppa('is_filmonly')) {
        // Find my ( avg ) rating
        $rats = $wpdb->get_results($wpdb->prepare("SELECT `value` FROM `" . WPPA_RATING . "` " . "WHERE `photo` = %s AND `user` = %s AND `status` = 'publish'", $id, $user), ARRAY_A);
        wppa_dbg_q('Q33v');
        if ($rats) {
            $n = 0;
            $accu = 0;
            foreach ($rats as $rat) {
                $accu += $rat['value'];
                $n++;
            }
            $myrat = $accu / $n;
            $i = wppa_opt('rating_prec');
            $j = $i + '1';
            $myrat = sprintf('%' . $j . '.' . $i . 'f', $myrat);
        } else {
            $myrat = '0';
        }
        // Find the avg rating
        $avgrat = wppa_get_rating_by_id($id, 'nolabel');
        if (!$avgrat) {
            $avgrat = '0';
        }
        $avgrat .= '|' . wppa_get_rating_count_by_id($id);
        // Find the dislike count
        $discount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_RATING . "` WHERE `photo` = %s AND `value` = -1 AND `status` = %s", $id, 'publish'));
    } else {
        // Rating off
        $myrat = '0';
        $avgrat = '0';
        $discount = '0';
    }
    // Find comments
    $comment = wppa_switch('show_comments') && !wppa('is_filmonly') && !wppa('is_slideonly') ? wppa_comment_html($id, $comment_allowed) : '';
    // Get the callback url.
    if (wppa_switch('rating_on')) {
        $url = wppa_get_slide_callback_url($callbackid);
        $url = str_replace('&amp;', '&', $url);
        // js use
    } else {
        $url = '';
    }
    // Find link url, link title and link target
    if (wppa_in_widget() == 'ss') {
        $link = wppa_get_imglnk_a('sswidget', $id);
    } else {
        $link = wppa_get_imglnk_a('slideshow', $id);
    }
    $linkurl = $link['url'];
    $linktitle = $link['title'];
    $linktarget = $link['target'];
    // Find full image style and size
    if (wppa('is_filmonly')) {
        $style_a['style'] = '';
        $style_a['width'] = '';
        $style_a['height'] = '';
    } else {
        $style_a = wppa_get_fullimgstyle_a($id);
    }
    // Find image url
    if (wppa_switch('fotomoto_on') && !wppa_is_stereo($id)) {
        $photourl = wppa_get_hires_url($id);
    } elseif (wppa_use_thumb_file($id, $style_a['width'], $style_a['height']) && !wppa_is_stereo($id)) {
        $photourl = wppa_get_thumb_url($id, '', $style_a['width'], $style_a['height']);
    } else {
        $photourl = wppa_get_photo_url($id, '', $style_a['width'], $style_a['height']);
    }
    if (wppa_has_audio($id)) {
        $photourl = wppa_fix_poster_ext($photourl, $id);
    }
    // Find iptc data
    $iptc = wppa_switch('show_iptc') && !wppa('is_slideonly') && !wppa('is_filmonly') ? wppa_iptc_html($id) : '';
    // Find EXIF data
    $exif = wppa_switch('show_exif') && !wppa('is_slideonly') && !wppa('is_filmonly') ? wppa_exif_html($id) : '';
    // Lightbox subtitle
    $doit = false;
    if (wppa_opt('slideshow_linktype') == 'lightbox' || wppa_opt('slideshow_linktype') == 'lightboxsingle') {
        $doit = true;
    }
    // For fullsize
    if (wppa_switch('filmstrip') && wppa_opt('film_linktype') == 'lightbox') {
        // For filmstrip?
        if (!wppa('is_slideonly')) {
            $doit = true;
        }
        // Film below fullsize
        if (wppa('film_on')) {
            $doit = true;
        }
        // Film explicitly on ( slideonlyf )
    }
    if ($doit) {
        $lbtitle = wppa_get_lbtitle('slide', $id);
    } else {
        $lbtitle = '';
    }
    // Name
    if (wppa('is_filmonly')) {
        $name = '';
        $fullname = '';
    } else {
        $name = esc_js(wppa_get_photo_name($id));
        if (!$name) {
            $name = '&nbsp;';
        }
        $fullname = wppa_get_photo_name($id, wppa_switch('show_full_owner'), true, true, wppa_switch('wppa_show_full_name'));
        if (!$fullname) {
            $fullname = '&nbsp;';
        }
    }
    // Shareurl
    if (wppa('is_filmonly') || wppa('is_slideonly')) {
        $shareurl = '';
    } else {
        $shareurl = wppa_get_image_page_url_by_id($id, false, wppa('start_album'));
        $shareurl = wppa_convert_to_pretty($shareurl);
        $shareurl = str_replace('&amp;', '&', $shareurl);
    }
    // Make photo desc, filtered
    $desc = '';
    if ((!wppa('is_slideonly') || wppa('desc_on')) && !wppa('is_filmonly')) {
        $desc .= wppa_get_photo_desc($id, wppa_switch('allow_foreign_shortcodes'), 'do_geo');
        // Foreign shortcodes is handled here
        // Run wpautop on description?
        if (wppa_switch('run_wpautop_on_desc')) {
            $desc = wpautop($desc);
        }
        // And format
        $desc = wppa_html(esc_js(stripslashes($desc)));
        // Remove extra space created by other filters like wpautop
        if (wppa_switch('allow_foreign_shortcodes') && wppa_switch('clean_pbr')) {
            $desc = str_replace(array("<p>", "</p>", "<br>", "<br/>", "<br />"), " ", $desc);
        }
        if (!$desc) {
            $desc = '&nbsp;';
        }
    }
    // Edit photo link
    $editlink = '';
    $dellink = '';
    if (!wppa('is_filmonly') && !wppa('is_slideonly')) {
        if (!wppa_is_user_blacklisted()) {
            if (wppa_user_is('administrator') || current_user_can('wppa_moderate') || wppa_get_user() == wppa_get_photo_owner($id) && wppa_switch('upload_edit')) {
                $editlink = '
					<div style="float:right; margin-right:6px;" >' . '<a' . ' style="color:green;"' . ' onclick="_wppaStop( ' . wppa('mocc') . ' );wppaEditPhoto( ' . wppa('mocc') . ', ' . $thumb['id'] . ' ); return false;"' . ' >' . __('Edit', 'wp-photo-album-plus') . '</a>' . '</div>';
                $dellink = '
					<div style="float:right; margin-right:6px;" >' . '<a' . ' style="color:red;"' . ' onclick="' . '_wppaStop( ' . wppa('mocc') . ' );' . esc_attr('if ( confirm( "' . __('Are you sure you want to remove this photo?', 'wp-photo-album-plus') . '" ) ) ' . 'wppaAjaxRemovePhoto( ' . wppa('mocc') . ', ' . $thumb['id'] . ', true ); return false;') . '"' . '>' . __('Delete', 'wp-photo-album-plus') . '</a>' . '</div>';
            }
        }
    }
    if ($editlink || $dellink) {
        $desc = $editlink . $dellink . '<div style="clear:both"></div>' . $desc;
    }
    if (in_array($thumb['status'], array('pending', 'scheduled'))) {
        $desc .= wppa_html(esc_js(wppa_moderate_links('slide', $id)));
    }
    // Share HTML
    $sharehtml = wppa('is_filmonly') || wppa('is_slideonly') ? '' : wppa_get_share_html($id);
    // Og Description
    $ogdsc = wppa_switch('facebook_comments') && !wppa_in_widget() ? strip_shortcodes(wppa_strip_tags(wppa_html(wppa_get_photo_desc($id)), 'all')) : '';
    $ogdsc = esc_js($ogdsc);
    // Hires url
    $hiresurl = esc_js(wppa_fix_poster_ext(wppa_get_hires_url($id), $id));
    // Video html
    $videohtml = wppa_get_video_body($id);
    // Audio html
    $audiohtml = wppa_get_audio_body($id);
    // Produce final result
    $result = "'" . wppa('mocc') . "','";
    $result .= $index . "','";
    $result .= $photourl . "','";
    $result .= $style_a['style'] . "','";
    $result .= ($videohtml ? wppa_get_videox($id) : $style_a['width']) . "','";
    $result .= ($videohtml ? wppa_get_videoy($id) : $style_a['height']) . "','";
    $result .= $fullname . "','";
    $result .= $name . "','";
    $result .= $desc . "','";
    $result .= $id . "','";
    $result .= $avgrat . "','";
    $result .= $discount . "','";
    $result .= $myrat . "','";
    $result .= $url . "','";
    $result .= $linkurl . "','" . $linktitle . "','" . $linktarget . "','";
    $result .= wppa('in_widget_timeout') . "','";
    $result .= $comment . "','";
    $result .= $iptc . "','";
    $result .= $exif . "','";
    $result .= $lbtitle . "','";
    $result .= $shareurl . "','";
    // Used for history.pushstate()
    $result .= $sharehtml . "','";
    // The content of the SM ( share ) box
    $result .= $ogdsc . "','";
    $result .= $hiresurl . "','";
    $result .= $videohtml . "','";
    $result .= $audiohtml . "'";
    // This is an ingenious line of code that is going to prevent us from very much trouble.
    // Created by OpaJaap on Jan 15 2012, 14:36 local time. Thanx.
    // Make sure there are no linebreaks in the result that would screw up Javascript.
    return str_replace(array("\r\n", "\n", "\r"), " ", $result);
    //	return $result;
}
function wppa_get_album_title_attr_a($albumid, $linktype, $linkpage, $has_content, $coverphoto, $photocount)
{
    $album = wppa_cache_album($albumid);
    // Init
    $href_title = '';
    $onclick_title = '';
    $title_title = '';
    // Dispatch on linktype when page is not current
    if ($linkpage > 0) {
        switch ($linktype) {
            case 'content':
            case 'thumbs':
            case 'albums':
                if ($has_content) {
                    $href_title = wppa_get_album_url($albumid, $linkpage, $linktype);
                } else {
                    $href_title = get_page_link($album['cover_linkpage']);
                }
                break;
            case 'slide':
                if ($has_content) {
                    $href_title = wppa_get_slideshow_url($albumid, $linkpage);
                } else {
                    $href_title = get_page_link($album['cover_linkpage']);
                }
                break;
            case 'page':
                $href_title = get_page_link($album['cover_linkpage']);
                break;
            case 'none':
                break;
            default:
        }
        $href_title = wppa_convert_to_pretty($href_title);
        $title_title = __('Link to', 'wp-photo-album-plus');
        $title_title .= ' ' . __(get_the_title($album['cover_linkpage']));
    } elseif ($has_content) {
        switch ($linktype) {
            case 'content':
            case 'thumbs':
            case 'albums':
                $href_title = wppa_convert_to_pretty(wppa_get_album_url($albumid, $linkpage, $linktype));
                if (wppa_switch('allow_ajax')) {
                    $onclick_title = "wppaDoAjaxRender( " . wppa('mocc') . ", '" . wppa_get_album_url_ajax($albumid, $linkpage, $linktype) . "', '" . $href_title . "' )";
                    $href_title = "#";
                }
                break;
            case 'slide':
                $href_title = wppa_convert_to_pretty(wppa_get_slideshow_url($albumid, $linkpage));
                if (wppa_switch('allow_ajax')) {
                    $onclick_title = "wppaDoAjaxRender( " . wppa('mocc') . ", '" . wppa_get_slideshow_url_ajax($albumid, $linkpage, $linktype) . "', '" . $href_title . "' )";
                    $href_title = "#";
                }
                break;
            case 'none':
                break;
            default:
        }
        $title_title = __('View the album', 'wp-photo-album-plus') . ' ' . esc_attr(__(stripslashes($album['name'])));
    } else {
        // No content on current page/post
        if ($photocount > '0') {
            // coverphotos only
            if ($coverphoto) {
                $href_title = wppa_convert_to_pretty(wppa_get_image_page_url_by_id($coverphoto));
            } else {
                $href_title = '#';
            }
            if (wppa_switch('allow_ajax')) {
                if ($coverphoto) {
                    $onclick_title = "wppaDoAjaxRender( " . wppa('mocc') . ", '" . wppa_get_image_url_ajax_by_id($coverphoto) . "', '" . $href_title . "' )";
                } else {
                    $onclick_title = '';
                }
                $href_title = "#";
            }
            $title_title = _n('View the cover photo', 'View the cover photos', $photocount, 'wp-photo-album-plus');
        }
    }
    $title_attr['href'] = $href_title;
    $title_attr['onclick'] = $onclick_title;
    $title_attr['title'] = $title_title;
    return $title_attr;
}