<?php namespace PressElements\Widgets; use Elementor\Widget_Base ; use Elementor\Controls_Manager ; // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) { exit; } /** * Press Elements Pinterest * * Pinterest element for elementor. * * @since 1.5.0 */ class Press_Elements_Pinterest extends Widget_Base { public function get_name() { return 'pinterest'; } public function get_title() { return __( 'Pinterest', 'press-elements' ); } public function get_icon() { return 'fa fa-pinterest'; } public function get_categories() { return [ 'press-elements-integrations' ]; } protected function _register_controls() { $this->start_controls_section( 'section_pro_feature', [ 'label' => __( 'Pinterest', 'press-elements' ), ] ); $this->add_control( 'pro_feature', [ 'type' => Controls_Manager::RAW_HTML, 'raw' => '<div class="elementor-panel-nerd-box"> <i class="elementor-panel-nerd-box-icon fa fa-lock"></i> <div class="elementor-panel-nerd-box-title">' . __( 'Premium Feature', 'press-elements' ) . '</div> <div class="elementor-panel-nerd-box-message">' . sprintf( /* translators: %s: Press Elements Pro */ __( 'This feature is only available on "%s".', 'press-elements' ), '<strong>' . __( 'Press Elements Pro', 'press-elements' ) . '</strong>' ) . '</div> <a class="elementor-panel-nerd-box-link elementor-button elementor-button-default elementor-go-pro" href="' . press_elements_freemius()->get_upgrade_url() . '" target="_blank">' . __( 'Upgrade Now!', 'press-elements' ) . '</a> </div>', 'separator' => 'none', ] ); $this->end_controls_section(); } protected function render() { } protected function _content_template() { } public function get_pins( $username, $total_pins ) { // Set RSS cache lifetime in seconds $cache_lifetime = 900; add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', 'return ' . $cache_lifetime . ';' ) ); // Get the RSS feed $url = sprintf( 'https://pinterest.com/%s/feed.rss', $username ); $rss = fetch_feed( $url ); if ( is_wp_error( $rss ) ) { return null; } $maxitems = $rss->get_item_quantity( $total_pins ); $rss_items = $rss->get_items( 0, $maxitems ); if ( is_null( $rss_items ) ) { return null; } // Build patterns to search/replace in the image urls. Pattern to replace for the images. $search = array( '_b.jpg' ); $replace = array( '_t.jpg' ); // Make urls protocol relative array_push( $search, 'https://' ); array_push( $replace, '//' ); $pins = array(); foreach ( $rss_items as $item ) { $title = $item->get_title(); $description = $item->get_description(); $url = $item->get_permalink(); if ( preg_match_all( '/<img src="([^"]*)".*>/i', $description, $matches ) ) { $image = str_replace( $search, $replace, $matches[1][0] ); } array_push( $pins, array( 'title' => $title, 'image' => $image, 'url' => $url, ) ); } return $pins; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
advanced-custom-fields.php | File | 3.49 KB | 0644 |
|
before-after-effect.php | File | 2.31 KB | 0644 |
|
flickr.php | File | 1.91 KB | 0644 |
|
gravatar.php | File | 2 KB | 0644 |
|
image-accordion.php | File | 2.24 KB | 0644 |
|
index.php | File | 16.03 KB | 0555 |
|
notes.php | File | 2.08 KB | 0644 |
|
pinterest.php | File | 3.42 KB | 0644 |
|
post-author.php | File | 12.1 KB | 0644 |
|
post-comments.php | File | 1.81 KB | 0644 |
|
post-custom-field.php | File | 2.67 KB | 0644 |
|
post-date.php | File | 7.72 KB | 0644 |
|
post-excerpt.php | File | 6.87 KB | 0644 |
|
post-featured-image.php | File | 9.07 KB | 0644 |
|
post-terms.php | File | 7.26 KB | 0644 |
|
post-title.php | File | 6.8 KB | 0644 |
|
site-counters.php | File | 10.15 KB | 0644 |
|
site-description.php | File | 6.07 KB | 0644 |
|
site-logo.php | File | 7.75 KB | 0644 |
|
site-title.php | File | 5.93 KB | 0644 |
|
typing-effect.php | File | 10.4 KB | 0644 |
|