| 1 |
<?php |
| 2 |
|
| 3 |
function htinstagram_shortcode( $atts ) { |
| 4 |
extract(shortcode_atts( array( |
| 5 |
'id' => 'htinstragram_shortcode_one' |
| 6 |
,'limit' => 8 |
| 7 |
,'cash_time' => MINUTE_IN_SECONDS |
| 8 |
,'delete_cache' => 'no' |
| 9 |
,'column' => 4 |
| 10 |
,'space' => 5 |
| 11 |
,'showcaption' => 'no' |
| 12 |
,'caption_pos' => 'top' |
| 13 |
,'showfollowbtn'=> 'yes' |
| 14 |
,'followbtnpos' => 'bottom' |
| 15 |
,'target' => '_self' |
| 16 |
|
| 17 |
,'slider_on' => 'no' |
| 18 |
,'slarrows' => 'no' |
| 19 |
,'slprevicon' => 'fa fa-angle-left' |
| 20 |
,'slnexticon' => 'fa fa-angle-right' |
| 21 |
,'sldots' => 'no' |
| 22 |
,'slautolay' => 'yes' |
| 23 |
,'slautoplay_speed' => 3000 |
| 24 |
,'slanimation_speed' => 300 |
| 25 |
,'slcentermode' => 'no' |
| 26 |
,'slcenterpadding' => 0 |
| 27 |
,'slitems' => 4 |
| 28 |
,'slrows' => 2 |
| 29 |
,'slscroll_columns' => 1 |
| 30 |
,'sltablet_width' => 750 |
| 31 |
,'sltablet_display_columns' => 1 |
| 32 |
,'sltablet_scroll_columns' => 1 |
| 33 |
,'slmobile_width' => 480 |
| 34 |
,'slmobile_display_columns' => 1 |
| 35 |
,'slmobile_scroll_columns' => 1 |
| 36 |
|
| 37 |
,'captionbg' => '' |
| 38 |
,'caption_color' => '' |
| 39 |
,'caption_font_size' => '' |
| 40 |
,'follow_background' => '' |
| 41 |
,'follow_buttoncolor' => '' |
| 42 |
,'follow_button_f_s' => '' |
| 43 |
,'follow_icon_color' => '' |
| 44 |
,'follow_icon_background' => '' |
| 45 |
|
| 46 |
), $atts ) ); |
| 47 |
|
| 48 |
// Sanitize and validate all inputs |
| 49 |
$id = sanitize_text_field( $id ); |
| 50 |
$limit = absint( $limit ); |
| 51 |
$cash_time = absint( $cash_time ); |
| 52 |
$delete_cache = in_array( $delete_cache, array( 'yes', 'no' ) ) ? $delete_cache : 'no'; |
| 53 |
$column = absint( $column ); |
| 54 |
$space = absint( $space ); |
| 55 |
$showcaption = in_array( $showcaption, array( 'yes', 'no' ) ) ? $showcaption : 'no'; |
| 56 |
$caption_pos = in_array( $caption_pos, array( 'top', 'bottom', 'middle' ) ) ? $caption_pos : 'top'; |
| 57 |
$showfollowbtn = in_array( $showfollowbtn, array( 'yes', 'no' ) ) ? $showfollowbtn : 'yes'; |
| 58 |
$followbtnpos = in_array( $followbtnpos, array( 'top', 'bottom', 'middle' ) ) ? $followbtnpos : 'bottom'; |
| 59 |
$target = in_array( $target, array( '_self', '_blank' ) ) ? $target : '_self'; |
| 60 |
|
| 61 |
// Sanitize slider options |
| 62 |
$slider_on = in_array( $slider_on, array( 'yes', 'no' ) ) ? $slider_on : 'no'; |
| 63 |
$slarrows = in_array( $slarrows, array( 'yes', 'no' ) ) ? $slarrows : 'no'; |
| 64 |
$slprevicon = sanitize_html_class( $slprevicon ); |
| 65 |
$slnexticon = sanitize_html_class( $slnexticon ); |
| 66 |
$sldots = in_array( $sldots, array( 'yes', 'no' ) ) ? $sldots : 'no'; |
| 67 |
$slautolay = in_array( $slautolay, array( 'yes', 'no' ) ) ? $slautolay : 'yes'; |
| 68 |
$slautoplay_speed = absint( $slautoplay_speed ); |
| 69 |
$slanimation_speed = absint( $slanimation_speed ); |
| 70 |
$slcentermode = in_array( $slcentermode, array( 'yes', 'no' ) ) ? $slcentermode : 'no'; |
| 71 |
$slcenterpadding = absint( $slcenterpadding ); |
| 72 |
$slitems = absint( $slitems ); |
| 73 |
$slrows = absint( $slrows ); |
| 74 |
$slscroll_columns = absint( $slscroll_columns ); |
| 75 |
$sltablet_width = absint( $sltablet_width ); |
| 76 |
$sltablet_display_columns = absint( $sltablet_display_columns ); |
| 77 |
$sltablet_scroll_columns = absint( $sltablet_scroll_columns ); |
| 78 |
$slmobile_width = absint( $slmobile_width ); |
| 79 |
$slmobile_display_columns = absint( $slmobile_display_columns ); |
| 80 |
$slmobile_scroll_columns = absint( $slmobile_scroll_columns ); |
| 81 |
|
| 82 |
// Sanitize CSS-related parameters to prevent XSS |
| 83 |
$captionbg = sanitize_hex_color( $captionbg ); |
| 84 |
$caption_color = sanitize_hex_color( $caption_color ); |
| 85 |
$caption_font_size = absint( $caption_font_size ); |
| 86 |
$follow_background = sanitize_hex_color( $follow_background ); |
| 87 |
$follow_buttoncolor = sanitize_hex_color( $follow_buttoncolor ); |
| 88 |
$follow_button_f_s = absint( $follow_button_f_s ); |
| 89 |
$follow_icon_color = sanitize_hex_color( $follow_icon_color ); |
| 90 |
$follow_icon_background = sanitize_hex_color( $follow_icon_background ); |
| 91 |
|
| 92 |
$settings = array( |
| 93 |
'limit' => $limit, |
| 94 |
'cash_time_duration' => $cash_time, |
| 95 |
'delete_cache' => $delete_cache, |
| 96 |
); |
| 97 |
|
| 98 |
$instaitem = HTinstagram_feed::instance()->htinstagram_items_feed( $settings, $id ); |
| 99 |
$username = !empty( $instaitem[0]['username'] ) ? $instaitem[0]['username'] : ''; |
| 100 |
$profile_link = !empty( $instaitem[0]['username'] ) ? 'https://www.instagram.com/'.$instaitem[0]['username'] : '#'; |
| 101 |
|
| 102 |
$unique_class = uniqid('instragram_style_'); |
| 103 |
$instaclass = array( $unique_class, 'htinsta-instragram', 'htinsta-column-'.$column, 'htinsta-comment-'.$caption_pos ); |
| 104 |
|
| 105 |
$ulclass = array(); |
| 106 |
$ulclass['class'] = 'htinstagram-list'; |
| 107 |
if( $slider_on == 'yes' ){ |
| 108 |
|
| 109 |
$ulclass['class'] = 'htinstagram-carousel'; |
| 110 |
|
| 111 |
$slider_settings = [ |
| 112 |
'arrows' => ( 'yes' === $slarrows ), |
| 113 |
'arrow_prev_txt' => '<i class="'.$slprevicon.'"></i>', |
| 114 |
'arrow_next_txt' => '<i class="'.$slnexticon.'"></i>', |
| 115 |
'dots' => ( 'yes' === $sldots ), |
| 116 |
'autoplay' => ( 'yes' === $slautolay ), |
| 117 |
'autoplay_speed' => absint( $slautoplay_speed ), |
| 118 |
'animation_speed' => absint( $slanimation_speed ), |
| 119 |
'center_mode' => ( 'yes' === $slcentermode ), |
| 120 |
'center_padding' => absint( $slcenterpadding ), |
| 121 |
]; |
| 122 |
|
| 123 |
$slider_responsive_settings = [ |
| 124 |
'rows' => $slrows, |
| 125 |
'display_columns' => $slitems, |
| 126 |
'scroll_columns' => $slscroll_columns, |
| 127 |
'tablet_width' => $sltablet_width, |
| 128 |
'tablet_display_columns' => $sltablet_display_columns, |
| 129 |
'tablet_scroll_columns' => $sltablet_scroll_columns, |
| 130 |
'mobile_width' => $slmobile_width, |
| 131 |
'mobile_display_columns' => $slmobile_display_columns, |
| 132 |
'mobile_scroll_columns' => $slmobile_scroll_columns, |
| 133 |
]; |
| 134 |
|
| 135 |
$slider_settings = array_merge( $slider_settings, $slider_responsive_settings ); |
| 136 |
} |
| 137 |
|
| 138 |
// Register CSS and JS |
| 139 |
if( $slider_on == 'yes' ){ |
| 140 |
wp_enqueue_style('slick'); |
| 141 |
wp_enqueue_script('ht-active'); |
| 142 |
} |
| 143 |
|
| 144 |
ob_start(); |
| 145 |
$output = ''; |
| 146 |
// custom style |
| 147 |
$output .= '<style>'; |
| 148 |
|
| 149 |
if( !empty( $captionbg ) ){ |
| 150 |
$output .= ".$unique_class .instagram-like-comment{ background-color: " . esc_attr( $captionbg ) . "; }"; |
| 151 |
} |
| 152 |
|
| 153 |
if( !empty( $caption_color ) ){ |
| 154 |
$output .= ".$unique_class .instagram-like-comment p{ color: " . esc_attr( $caption_color ) . "; }"; |
| 155 |
} |
| 156 |
|
| 157 |
if( !empty( $caption_font_size ) ){ |
| 158 |
$output .= ".$unique_class .instagram-like-comment p{ font-size: " . esc_attr( $caption_font_size ) . "px; }"; |
| 159 |
} |
| 160 |
|
| 161 |
if( !empty( $follow_background ) ){ |
| 162 |
$output .= ".$unique_class a.instagram_follow_btn{ background-color: " . esc_attr( $follow_background ) . "; }"; |
| 163 |
} |
| 164 |
|
| 165 |
if( !empty($follow_buttoncolor) ){ |
| 166 |
$output .= ".$unique_class a.instagram_follow_btn{ color: " . esc_attr( $follow_buttoncolor ) . "; }"; |
| 167 |
} |
| 168 |
|
| 169 |
if( !empty( $follow_button_f_s )){ |
| 170 |
$output .= ".$unique_class a.instagram_follow_btn{ font-size: " . esc_attr( $follow_button_f_s ) . "px; }"; |
| 171 |
} |
| 172 |
|
| 173 |
if( !empty( $follow_icon_color ) ){ |
| 174 |
$output .= ".$unique_class a.instagram_follow_btn i{ color: " . esc_attr( $follow_icon_color ) . "; }"; |
| 175 |
} |
| 176 |
|
| 177 |
if( !empty( $follow_icon_background ) ){ |
| 178 |
$output .= ".$unique_class a.instagram_follow_btn i{ background-color: " . esc_attr( $follow_icon_background ) . "; }"; |
| 179 |
} |
| 180 |
|
| 181 |
$output .= '</style>'; |
| 182 |
|
| 183 |
?> |
| 184 |
<div class="<?php echo esc_attr(implode(' ', $instaclass )); ?>" > |
| 185 |
<?php if ( isset( $instaitem ) && !empty($instaitem)) :?> |
| 186 |
|
| 187 |
<?php if( $showfollowbtn == 'yes' && $followbtnpos == 'top' ): ?> |
| 188 |
<a class="instagram_follow_btn <?php echo esc_attr( $followbtnpos );?>" href="<?php echo esc_url( $profile_link ); ?>" target="_blank"> |
| 189 |
<i class="fa fa-instagram"></i> |
| 190 |
<span><?php echo esc_html__( 'Follow @ '.$username, 'ht-instagram' );?></span> |
| 191 |
</a> |
| 192 |
<?php endif;?> |
| 193 |
|
| 194 |
<ul class="<?php echo esc_attr( $ulclass['class'] ); ?>" style="<?php if( $slider_on != 'yes' ){ echo 'margin: 0 -'.esc_attr($space).'px'; } ?>" data-settings='<?php if( $slider_on == 'yes' ){ echo wp_json_encode( $slider_settings ); }else{echo 'no-opt'; } ?>'> |
| 195 |
<?php |
| 196 |
$countitem = 0; |
| 197 |
foreach ( $instaitem as $item ): |
| 198 |
$countitem++; |
| 199 |
$items_link = $item['link']; |
| 200 |
?> |
| 201 |
<li style="<?php echo 'padding: 0 '.esc_attr($space).'px; margin-bottom: '.( esc_attr($space)*2 ).'px;';?>"> |
| 202 |
<div class="htinstagram_single_item"> |
| 203 |
<a href="<?php echo esc_url( $items_link ); ?>" target="<?php echo esc_attr( $target );?>" > |
| 204 |
<img src="<?php echo esc_url( $item['src'] ); ?>" alt="<?php echo esc_html__( $item['username'], 'ht-instagram');?>"> |
| 205 |
</a> |
| 206 |
|
| 207 |
<?php if( $showcaption == 'yes' && !empty( $item['caption'] ) ) : ?> |
| 208 |
<div class="instagram-clip"> |
| 209 |
<div class="htinstagram-content"> |
| 210 |
<div class="instagram-like-comment"> |
| 211 |
<p><?php echo esc_html( $item['caption'] ); ?></p> |
| 212 |
</div> |
| 213 |
</div> |
| 214 |
</div> |
| 215 |
<?php endif;?> |
| 216 |
|
| 217 |
</div> |
| 218 |
</li> |
| 219 |
<?php if( $countitem == $limit ){ break; } endforeach;?> |
| 220 |
</ul> |
| 221 |
<?php if( $showfollowbtn == 'yes' && ( $followbtnpos == 'bottom' || $followbtnpos == 'middle' ) ): ?> |
| 222 |
<a class="instagram_follow_btn <?php echo esc_attr( $followbtnpos );?>" href="<?php echo esc_url( '' ); ?>" target="_blank"> |
| 223 |
<i class="fa fa-instagram"></i> |
| 224 |
<span><?php echo esc_html__( 'Follow @ '.$username, 'ht-instagram' );?></span> |
| 225 |
</a> |
| 226 |
<?php endif; else:?> |
| 227 |
<p class="htinsta-error"> |
| 228 |
<?php |
| 229 |
esc_html_e( 'Instagram Feed Not found Please enter valid Access Token.','ht-instagram' ); |
| 230 |
echo wp_kses_post( '(<a href="'.esc_url( admin_url().'admin.php?page=htinstagram' ).'" target="_blank">Enter Access Token</a>)', 'ht-instagram' ); |
| 231 |
?> |
| 232 |
</p> |
| 233 |
<?php endif; ?> |
| 234 |
</div> |
| 235 |
<?php |
| 236 |
|
| 237 |
$output .= ob_get_clean(); |
| 238 |
|
| 239 |
return $output; |
| 240 |
} |
| 241 |
add_shortcode( 'htinstagram', 'htinstagram_shortcode' ); |
| 242 |
|
| 243 |
?> |