-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new shortcode can now allow turn on 'links' and 'caption'
- Loading branch information
Showing
3 changed files
with
304 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters