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('&', '&', $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 = ' '; } $fullname = wppa_get_photo_name($id, wppa_switch('show_full_owner'), true, true, wppa_switch('wppa_show_full_name')); if (!$fullname) { $fullname = ' '; } } // 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('&', '&', $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 = ' '; } } // 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_add_to_cart($atts) { global $post; $thumb = wppa('current_photo'); extract(shortcode_atts(array('name' => wppa_get_photo_name($thumb['id']), 'price' => 0.01, 'qty_field' => '', 'b_title' => __('Buy now', 'wp-photo-album-plus'), 'options' => '', 'options_name' => '', 'qty_field' => '', 'fshipping' => '', 'weight' => ''), $atts)); $cart =& $_SESSION['wfcart']; // load the cart from the session $scabn_options = get_option('scabn_options'); $currency = apply_filters('scabn_display_currency_symbol', NULL); // Slideshow? if (wppa('is_slide')) { $action_url = wppa_get_slide_callback_url($thumb['id']); $item_url = $action_url . '&wppa-single=1'; $action_url = wppa_convert_to_pretty($action_url); $item_url = wppa_convert_to_pretty($item_url); } else { $action_url = wppa_get_thumb_callback_url(); if (!strpos($action_url, '&')) { $action_url = str_replace('&', '&', $action_url); } $item_url = wppa_get_slide_callback_url($thumb['id']) . '&wppa-single=1'; $action_url = wppa_convert_to_pretty($action_url); $item_url = wppa_convert_to_pretty($item_url); } $output = ' <div class="wppa-addtocart"> <form method="post" class="wppa-cartform ' . $name . '" action="' . $action_url . '"> ' . wp_nonce_field('add_to_cart', 'scabn-add', false, false) . ' <input type="hidden" value="add_item" name="action" /> <input type="hidden" class="item_url" value="' . $item_url . '" name="item_url" /> <input type="hidden" value="' . $cart->random() . '" name="randomid" /> <input type="hidden" value="' . $name . '" name="item_id" /> <input type="hidden" class="item_name" value="' . $name . '" name="item_name" /> <input type="hidden" class="item_price" value="' . $price . '" name="item_price" />'; if ($fshipping) { $output .= ' <input type="hidden" class="item_shipping" value="' . $fshipping . '" name="item_shipping" />'; } if ($weight) { $output .= ' <input type="hidden" class="item_weight" value="' . $weight . '" name="item_weight" />'; } if ($options) { if ($options_name) { $output .= $options_name . ': '; } $output .= ' <input type="hidden" value="' . $options_name . '" name="item_options_name" class="item_options_name" />'; $item_options = explode(',', $options); $output .= ' <select style="max-width:200px; margin:0" name="item_options" class="item_options" >'; foreach ($item_options as $option) { $info = explode(':', $option); if (count($info) == 1) { $output .= ' <option value="' . $info[0] . '">' . $info[0] . ' (' . $currency . number_format($price, 2) . ')</option>'; } else { $output .= ' <option value="' . $info[0] . ':' . $info[1] . '">' . $info[0] . ' (' . $currency . number_format($info[1], 2) . ')</option>'; } } $output .= ' </select>'; } else { $output .= sprintf(__('Unit Price: %s each', 'wp-photo-album-plus'), $currency . number_format($price, 2)) . ' '; } if ($qty_field) { $output .= __('Qty:', 'wp-photo-album-plus') . ' <input type="text" style="max-width:50px; margin:0;" class="item_qty" value="1" size="2" name="item_qty" />'; } else { $output .= '<input type="hidden" class="item_qty" value="1" size="2" name="item_qty" />'; } $output .= ' <input type="submit" id="' . $name . '" class="add" name="add" value="' . $b_title . '"/> </form> </div>'; return $output; }