// TODO: Document } else { $link = 'https://pinterest.com/pin/create/button/' . '?url=' . $panel_context['post_data']['permalink'] . '&media=' . urlencode( $pinterest_image ) . '&description=' . urlencode( $pinterest_description ); $anchor = ''; } // If the user has not uploaded any Pinterest images. } elseif ( SWP_AMP::is_amp() ) { $link = 'https://pinterest.com/pin/create/button/' . '?url=' . $panel_context['post_data']['permalink']; $anchor = ''; } else { $link = 'https://pinterest.com/pin/create/button/?url=' . urlencode( $panel_context['post_data']['permalink'] ); $anchor = ''; } // * Begin parent class method. $post_data = $panel_context['post_data']; $share_counts = $panel_context['shares']; $options = $panel_context['options']; // Build the button. $icon = ''; $icon .= ''; $icon .= ''; $icon .= '' . $this->cta . ''; $icon .= ''; $icon .= ''; if ( true === $this->are_shares_shown( $panel_context ) ) : $icon .= '' . SWP_Utility::kilomega( $share_counts[ $this->key ] ) . ''; else : $icon = '' . $icon . ''; endif; // Build the wrapper. $html = '
'; $html .= $anchor; // Put the button inside. $html .= $icon; $html .= ''; $html .= '
'; // Store these buttons so that we don't have to generate them for each set $this->html = $html; if ( $output ) : echo wp_kses_post( $html ); endif; return $html; } public function generate_share_link( $post_data ) { return 0; } /** * Trims the text of a pinterest description down to the 500 character max. * * @since 3.5.0 | 21 FEB 2019 | Created. * @param string $pinterest_description The target Pinterest description. * @return string The same pinterest description, capped at 500 characters. */ public static function trim_pinterest_description( $pinterest_description, $via = '' ) { if ( strlen( $pinterest_description ) > 500 ) { /** * The provided description is too long before we have added * anything. We need to trim it before appending the @via. */ $read_more = '... ' . $via; $cutoff = 500 - strlen( $read_more ); $pinterest_description = substr( $pinterest_description, 0, $cutoff ); $pinterest_description .= $read_more; } else { /** * The description length + via length would be too long, so * trim a little bit of description so via will fit. */ if ( strlen( $pinterest_description ) + strlen( $via ) > 500 ) { $cutoff = 500 - strlen( $via ); $pinterest_description = substr( $pinterest_description, 0, $cutoff ); } $pinterest_description .= $via; } return $pinterest_description; } /** * Fetches the user's @via for Pinterest, if it exists. * * @since 3.5.1 | 26 FEB 2019 | Created. * @param void * @return string The '@via $username', or an empty string. */ public static function get_via() { $pinterest_username = ''; $via = SWP_Utility::get_option( 'pinterest_id' ); if ( ! empty( $via ) ) { $pinterest_username = ' via @' . str_replace( '@', '', $via ); } return $pinterest_username; } }