C:\xampp\htdocs\landing\wp-content\plugins\penci-framework\inc\pinterest.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
if ( ! class_exists'Penci_Pinterest' ) ):

    class 
Penci_Pinterest {

        
// Pinterest url
        
var $pinterest_feed 'https://pinterest.com/%s/feed.rss';

        var 
$start_time;

        function 
__construct() {
            
$this->start_time microtimetrue );
        }

        
// Render the pinboard and output
        
function render_html$username$numbers$cache_time 1200$follow true ) {

            
$user_display_html $username;
            
$user_display explode"/"trim$username ) );
            if( 
is_array$user_display ) && isset( $user_display[0] ) ) {
                
$user_display_html $user_display[0];
            }

            
$pins $this->get_board_name_pins$username$cache_time );

            if( ! empty( 
$pins ) ) {
                echo 
'<div class="penci-images-pin-widget">';

                
$i 1;
                foreach ( 
$pins as $pin ) {

                    if ( 
$numbers $i ) {
                        continue;
                    }

                    
$image = isset( $pin['images']['orig']['url'] ) ? $pin['images']['orig']['url'] : '';
                    if ( ! 
$image ) {
                        continue;
                    }

                    
$pin_id = isset( $pin['id'] ) ? $pin['id'] : '';
                    
$url    'https://www.pinterest.com/pin/' $pin_id;

                    echo 
'<a href="' esc_url$url ) . '" target="_blank"><span class="penci-image-holder rectangle-fix-size penci-lazy" data-src="' esc_url$image ) . '"></span></a>';

                    
$i ++;
                }

                echo 
'</div>';
            }else{
                
$user_board =  $user_display_html '';
                
$user_display explode"/"trim$username ) );
                if( 
is_array$user_display ) ) {
                    
$user_display_html $user_display[0];
                    if( isset(
$user_display[1]) && $user_display[1] ){
                        
$user_board =  $user_display[1];
                    }
                }

                if( 
$user_display_html && $user_board ){
                    
$feedurl 'http://pinterest.com/'.$user_display_html.'/'.$user_board.'.rss';
                }
                else{
                    
$feedurl 'http://pinterest.com/'.$user_display_html.'/feed.rss';
                }

                
$cache_key 'penci_pinterest_feed_' strtolower$username ) . esc_attr$numbers );
                
$item_foreach_cache get_transient$cache_key );

                
$remove_item_foreach_cache = isset( $_GET['penci_cache_feed'] ) ? true false;

                
$item_foreach_pre = array();
                if ( ! 
$item_foreach_cache || $remove_item_foreach_cache ) {
                    
$rss fetch_feed($feedurl);
                    
$item_foreach = ! empty( $rss->get_items() ) ? $rss->get_items() : array();


                    
$i 1;
                    foreach ( 
$item_foreach as $item ) {
                        if ( 
$numbers $i ) {
                            continue;
                        }
                        
$imagedata $item->get_content();

                        
preg_match'/src="([^\"]*)"/i'$imagedata$matchessrc ) ;
                        
preg_match'/href="([^\"]*)"/i'$imagedata$matcheshref ) ;

                        
$item_foreach_pre[] = array(
                            
'image_url' => isset( $matchessrc[1] ) ? $matchessrc[1] : '',
                            
'url' => isset( $matcheshref[1] ) ? $matcheshref[1] : ''
                        
);

                        
$i++;
                    }
                    if( ! empty( 
$item_foreach_pre ) ){
                        
set_transient$cache_key,$item_foreach_pre,  $cache_time );
                    }
                }else {

                    
$item_foreach_pre $item_foreach_cache;
                }

                if( ! empty( 
$item_foreach_pre ) ){

                    echo 
'<div class="penci-images-pin-widget">';
                    
$i 1;
                    foreach (
$item_foreach_pre as $item ) {
                        if ( 
$numbers $i ) {
                            continue;
                        }

                        
$image_url = isset( $item['image_url'] ) ? $item['image_url'] : '';
                        
$url =isset( $item['url'] ) ? $item['url'] : '';

                        
$lazyhtml '<span class="penci-image-holder rectangle-fix-size penci-lazy" data-src="' esc_url$image_url ) . '"></span>';
                        if( 
get_theme_mod'penci_disable_lazyload_layout' ) ) {
                            
$lazyhtml '<span class="penci-image-holder rectangle-fix-size" style="background-image: url(' esc_url$image_url ) . ');"></span>';
                        }

                        echo 
'<a href="' esc_url$url ) . '" target="_blank">'$lazyhtml .'</a>';
                        
$i++;
                    }
                    echo 
'</div>';
                }else{
                    echo( 
"Render failed - no data is received, please check the input" );
                }
            }
            
?>

            <?php if ( $follow ): ?>
                <div class="pin_link">
                    <a href="https://www.pinterest.com/<?php echo sanitize_text_field$username ); ?>" target="_blank">@<?php echo sanitize_text_field$user_display_html ); ?></a>
                </div>
            <?php endif; ?>
            <?php
        
}

        
/**
         * Retrieve RSS feed for username, and parse the data needed.
         * Returns null if error, otherwise a has of pins.
         * Callback it on render_html functions
         *
         * @since 1.0
         */
        
function get_pins$username$numbers$cache_time 1200 ) {

            if ( ! 
is_numeric$cache_time ) && $cache_time ): $cache_time 1200; endif;
            
// Set caching.
            
add_filter'wp_feed_cache_transient_lifetime'create_function'$a''return ' $cache_time ';' ) );

            
// Get the RSS feed.
            
$url sprintf$this->pinterest_feed$username );
            
$rss fetch_feed$url );

            if ( 
is_wp_error$rss ) ) {
                return 
null;
            }

            
$maxitems  $rss->get_item_quantity$numbers );
            
$rss_items $rss->get_items0$maxitems );

            
$pins;
            if ( 
is_null$rss_items ) ) {
                
$pins null;
            } else {

                
// Build patterns to search/replace in the image urls
                
$search  = array( '_b.jpg' );
                
$replace = array( '_t.jpg' );

                
// Make url 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;
        }

        public function 
get_board_name_pins$username$cache_time 1200 ) {

            
$output = array();

            
$cache_key 'penci_pinterest_' strtolower$username );

            
$pinterest_cache get_transient$cache_key );

            if ( ! 
$pinterest_cache ) {

                
$params = array(
                    
'timeout'    => 60,
                    
'sslverify'  => false,
                    
'headers'    => array( 'Accept-language' => 'en' ),
                    
'user-agent' => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'
                
);

                
$response wp_remote_get'https://www.pinterest.com/' $username$params );

                if ( ! 
is_wp_error$response ) ) {
                    
$request_result wp_remote_retrieve_body$response );

                    
preg_match_all'/jsInit1\'>(.*)<\/script>/'$request_result$matches );

                    if ( ! empty( 
$matches[1] ) && count$matches[1] ) ) {
                        
$pinterest_json json_decode$matches[1][0], true );

                        if ( ! isset( 
$pinterest_json['resourceDataCache'][1]['data']['board_feed'] ) ) {
                            
$output['error'] = esc_html__'The pinterest data is not set, please check the ID''penci-framework' );
                        } elseif ( isset( 
$pinterest_json["resourceDataCache"][0]['data']['type'] ) && $pinterest_json["resourceDataCache"][0]['data']['type'] !== 'board' ) {
                            
$output['error'] = __'Invalid pinterest data for  <strong>' $username '</strong> please check the <em>user/board_id</em>''penci-framework' );
                        } else {
                            
$output = (array) $pinterest_json['resourceDataCache'][1]['data']['board_feed'];
                        }
                    }
                }
            } else {
                
$output $pinterest_cache;
            }

            return 
$output;
        }
    }

endif; 
/* End check if class exists */
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586