Skip to content

Commit

Permalink
feat: new shortcode can now allow turn on 'links' and 'caption'
Browse files Browse the repository at this point in the history
  • Loading branch information
devuri committed Dec 5, 2020
1 parent a7f22f7 commit c53be8a
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 15 deletions.
31 changes: 31 additions & 0 deletions src/InstagramFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace SimSocialFeed;

use SimSocialFeed\View\Display;

class InstagramFeed
{
/**
* Get the Display
*/
public static function get() {
return new Display();
}

/**
* Get the Feed items
*
* @param array $args .
*/
public static function view( $args ) {
return self::get()->igfeed( $args );
}

/**
* Get the Admin list of Feed items
*/
public static function admin_view() {
return self::get()->admin_view();
}
}
265 changes: 265 additions & 0 deletions src/View/Display.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
<?php

namespace SimSocialFeed\View;

class Display
{

/**
* List images
*
* @param string $limit .
* @param string $w .
* @param string $css .
*/
public function admin_view( $limit = 6, $w = '240', $css = '' ) {
echo '<div class="row" style="display: inline-flex; flex-wrap: wrap; ' . $css . '">'; // @codingStandardsIgnoreLine
if ( is_array( get_option( 'simsf_user_media' ) ) ) {
/**
* Get IG list
* limit the return values
*/
$i = 0;
foreach ( get_option( 'simsf_user_media' ) as $mkey => $media ) {
if ( isset( $media->caption ) ) {
$caption = $media->caption;
} else {
$caption = '';
}
if ( 'VIDEO' === $media->media_type ) continue;
echo '<div class="ig-image" style="margin:2px;"><a href="' . esc_url( $media->permalink ) . '" target="_blank"><img class="img-responsive" height="230" width="' . esc_attr( $w ) . '" src="' . esc_url( $media->media_url ) . '" alt="' . esc_attr( $caption ) . '"></a></div>';
if ( ++$i === $limit ) break;
}
}
echo '</div>';
}

/**
* The feed igfeed()
*
* Shortcode to display the instagram feed [igfeed].
*
* @param array $args .
*/
public function igfeed( $args = array() ) {

$defaults = array(
'limit' => 6,
'linked' => 'no',
'caption' => 'off',
);
$args = wp_parse_args( $args, $defaults );

// make sure limit is integer.
$args['limit'] = absint( $args['limit'] );

// caption and linked.
if ( 'yes' === $args['linked'] && 'on' === $args['caption'] ) {
return $this->view_linked_caption( $args['limit'] );
}

// without caption no link.
if ( 'on' === $args['caption'] ) {
return $this->view_with_caption( $args['limit'] );
}

// linked without caption.
if ( 'yes' === $args['linked'] ) {
return $this->view_linked( $args['limit'] );
}

return $this->view( $args['limit'] );

}

/**
* Display View
*
* Get the Images
*
* @param integer $limit .
*
* @return void
*/
public function view_linked_caption( $limit = 6 ) {
?>
<div class="igfeed-container">
<div class="igfeed">
<?php
if ( is_array( get_option( 'simsf_user_media' ) ) ) {

/**
* Get IG list
* limit the return values
*/
$i = 0;
foreach ( get_option( 'simsf_user_media' ) as $mkey => $media ) {

if ( isset( $media->caption ) ) {
$caption = $media->caption;
} else {
$caption = '';
}

if ( 'VIDEO' === $media->media_type ) continue;
?>
<div class="igfeed-item" tabindex="0">
<img style="min-height:200px;" src="<?php echo esc_url( $media->media_url ); ?>" alt="<?php echo esc_attr( $caption ); ?>">
<a href="<?php echo esc_url( $media->permalink ); ?>" target="_blank">
<div class="igfeed-item-info">
<p>
<?php echo esc_attr( $caption ); ?>
</p>
</div>
</a>
</div>
<?php
if ( ++$i === $limit ) break;
}
}
?>
</div>
</div>
<?php
}

/**
* Display View
*
* Get the Images
*
* @param integer $limit .
*
* @return void
*/
public function view_with_caption( $limit = 6 ) {
?>
<div class="igfeed-container">
<div class="igfeed">
<?php
if ( is_array( get_option( 'simsf_user_media' ) ) ) {

/**
* Get IG list
* limit the return values
*/
$i = 0;
foreach ( get_option( 'simsf_user_media' ) as $mkey => $media ) {

if ( isset( $media->caption ) ) {
$caption = $media->caption;
} else {
$caption = '';
}

if ( 'VIDEO' === $media->media_type ) continue;
?>
<div class="igfeed-item" tabindex="0">
<img style="min-height:200px;" src="<?php echo esc_url( $media->media_url ); ?>" alt="<?php echo esc_attr( $caption ); ?>">
<div class="igfeed-item-info">
<p>
<?php echo esc_attr( $caption ); ?>
</p>
</div>
</div>
<?php
if ( ++$i === $limit ) break;
}
}
?>
</div>
</div>
<?php
}

/**
* Display View
*
* Get the Images
*
* @param integer $limit .
*
* @return void
*/
public function view_linked( $limit = 6 ) {
?>
<div class="igfeed-container">
<div class="igfeed">
<?php
if ( is_array( get_option( 'simsf_user_media' ) ) ) {

/**
* Get IG list
* limit the return values
*/
$i = 0;
foreach ( get_option( 'simsf_user_media' ) as $mkey => $media ) {

if ( isset( $media->caption ) ) {
$caption = $media->caption;
} else {
$caption = '';
}

if ( 'VIDEO' === $media->media_type ) continue;
?>
<div class="igfeed-item" tabindex="0">
<a href="<?php echo esc_url( $media->permalink ); ?>" target="_blank">
<img style="min-height:200px;" src="<?php echo esc_url( $media->media_url ); ?>" alt="<?php echo esc_attr( $caption ); ?>">
</a>
</div>
<?php
if ( ++$i === $limit ) break;
}
}
?>
</div>
</div>
<?php
}

/**
* Display View
*
* Get the Images
*
* @param integer $limit .
*
* @return void
*/
public function view( $limit = 6 ) {
?>
<div class="igfeed-container">
<div class="igfeed">
<?php
if ( is_array( get_option( 'simsf_user_media' ) ) ) {

/**
* Get IG list
* limit the return values
*/
$i = 0;
foreach ( get_option( 'simsf_user_media' ) as $mkey => $media ) {

if ( isset( $media->caption ) ) {
$caption = $media->caption;
} else {
$caption = '';
}

if ( 'VIDEO' === $media->media_type ) continue;
?>
<div class="igfeed-item" tabindex="0">
<img style="min-height:200px;" src="<?php echo esc_url( $media->media_url ); ?>" alt="<?php echo esc_attr( $caption ); ?>">
</div>
<?php
if ( ++$i === $limit ) break;
}
}
?>
</div>
</div>
<?php
}

}
23 changes: 8 additions & 15 deletions src/shortcode.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use SimSocialFeed\InstagramSocialFeed;
use SimSocialFeed\InstagramFeed;

/**
* Shortcode to use [ig_socialfeed limit="6" linked="yes"]
* Shortcode to use [igfeed limit="6" linked="yes"]
*
* @param array $atts .
*
Expand All @@ -13,33 +13,26 @@ function simsf_igmedia_feed( $atts ) {

$a = shortcode_atts(
array(
'limit' => 6,
'linked' => 'no',
'limit' => 6,
'linked' => 'no',
'caption' => 'off',
),
$atts
);

// params .
$limit = absint( $a['limit'] );
$linked = strtolower( $a['linked'] );

/**
* Load the grid styles
*/
wp_enqueue_style( 'sim-social-feed-grid' );
wp_enqueue_style( 'igfeed-grid' );

ob_start();

if ( 'yes' === $linked ) {
InstagramSocialFeed::igfeedlinked( $limit );
} else {
InstagramSocialFeed::igfeed( $limit );
}
InstagramFeed::view( $a );

$output_sfd = ob_get_contents();

ob_end_clean();

return $output_sfd;
}
add_shortcode( 'ig_socialfeed', 'simsf_igmedia_feed' );
add_shortcode( 'igfeed', 'simsf_igmedia_feed' );

0 comments on commit c53be8a

Please sign in to comment.