array( 'name' => esc_html__( 'Follow Us', 'mega' ), 'description' => esc_html__( 'Follow Us block', 'mega' )),
'before' => '
',
'after' => '
',
'universal' => true,
'class_base'=> 'ys-follow'
);
$this->bookmarks = array(
'facebook' => array( 'name' => esc_html__( 'Facebook', 'mega' ), 'link' => 'http://www.facebook.com/%s' ),
'twitter' => array( 'name' => esc_html__( 'Twitter', 'mega' ), 'link' => 'http://twitter.com/%s' ),
'plus' => array( 'name' => esc_html__( 'Google Plus', 'mega' ), 'link' => 'http://plus.google.com/%s' ),
'youtube' => array( 'name' => esc_html__( 'YouTube', 'mega' ), 'link' => 'https://www.youtube.com/channel/%s' ),
'linkedin' => array( 'name' => esc_html__( 'Linkedin', 'mega' ), 'link' => 'http://www.linkedin.com/pub/%s' ),
'feedburner' => array( 'name' => esc_html__( 'Feedburner', 'mega' ), 'link' => 'http://feeds.feedburner.com/%s' ),
'wordpress' => array( 'name' => esc_html__( 'WordPress', 'mega' ), 'link' => 'http://%s.wordpress.com/' ),
'dribbble' => array( 'name' => esc_html__( 'Dribbble', 'mega' ), 'link' => 'http://dribbble.com/%s' ),
'flickr' => array( 'name' => esc_html__( 'Flickr', 'mega' ), 'link' => 'http://www.flickr.com/photos/%s' ),
'digg' => array( 'name' => esc_html__( 'Digg', 'mega' ), 'link' => 'http://digg.com/%s' ),
'spotify' => array( 'name' => esc_html__( 'Spotify', 'mega' ), 'link' => 'http://community.spotify.com/t5/user/viewprofilepage/user-id/%s' ),
'tumblr' => array( 'name' => esc_html__( 'Tumblr', 'mega' ), 'link' => 'http://%s.tumblr.com/' ),
'rss' => array( 'name' => esc_html__( 'RSS', 'mega' ), 'link' => '%s' )
);
parent::__construct( __CLASS__, $args );
}
public function settings( $form )
{
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Title', 'mega' ), 'value' => esc_html__( 'Follow Us', 'mega' ), 'name' => 'title' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Facebook', 'mega' ), 'value' => ' ', 'name' => 'facebook' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Twitter', 'mega' ), 'value' => ' ', 'name' => 'twitter' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Google Plus', 'mega' ), 'value' => ' ', 'name' => 'plus' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'YouTube', 'mega' ), 'value' => ' ', 'name' => 'youtube' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'LinkedIn', 'mega' ), 'value' => '', 'name' => 'linkedin' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'FeedBurner', 'mega' ), 'value' => '', 'name' => 'feedburner' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Digg', 'mega' ), 'value' => '', 'name' => 'digg' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Dribbble', 'mega' ), 'pro' => 1, 'value' => '', 'name' => 'dribbble' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Flickr', 'mega' ), 'pro' => 1, 'value' => '', 'name' => 'flickr' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'WordPress', 'mega' ), 'value' => '', 'name' => 'wordpress' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Spotify', 'mega' ), 'value' => '', 'name' => 'spotify' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Tumblr', 'mega' ), 'value' => '', 'name' => 'tumblr' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'RSS URL', 'mega' ), 'value' => get_bloginfo( 'rss2_url' ), 'name' => 'rss' ));
}
public function block()
{
extract( $this->mega['settings'] );
echo '';
foreach ( $this->bookmarks as $key => $args )
{
if ( !empty( $$key ))
printf(
'- %3$s
',
$key,
$$key === ' ' ? ' ' : ' href="' . esc_url( sprintf( $args['link'], $$key )) . '" ',
$args['name']
);
}
echo '
';
}
}
class Mega_Block_Follow_Counter extends Mega_Walker
{
public $bookmarks;
public function __construct()
{
$args = array(
'profile' => array( 'name' => esc_html__( 'Follow Us Counter', 'mega' ), 'description' => esc_html__( 'Follow Us Counter block', 'mega' )),
'before' => '',
'after' => '
',
'universal' => true,
'pro' => true,
'class_base'=> 'ys-follow-counter'
);
$this->bookmarks = array(
'facebook' => array(
'name' => esc_html__( 'Facebook', 'mega' ),
'link' => 'http://www.facebook.com/%s',
'api' => array(
'type' => 'json',//only json?
'data' => 'https://graph.facebook.com/%1$s?access_token=%2$s|%3$s',
'key' => 'likes'
)
),
/* 'twitter' => array(
'name' => esc_html__( 'Twitter', 'mega' ),
'link' => 'http://twitter.com/%s',
'api' => array(
'type' => 'json',
'data' => 'http://api.twitter.com/1/users/show.json?skip_status=1&screen_name=%s',
'key' => 'followers_count'
)
),*/
'dribbble' => array(
'name' => esc_html__( 'Dribbble', 'mega' ),
'link' => 'http://dribbble.com/%s',
'api' => array(
'type' => 'json',
'data' => 'http://api.dribbble.com/%s',
'key' => 'followers_count'
)
)
);
parent::__construct( __CLASS__, $args );
add_filter( 'mega_block_follow_counter_args', array( &$this, 'mega_block_follow_counter_args' ));
}
public function mega_block_follow_counter_args( $args )
{
$args['enqueue']['css'] = array( 'id' => 'Mega_Block_Follow', 'path' => '/theme/assets/css/class.Mega_Block_Follow.css' );
return $args;
}
public function settings( $form )
{
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Title', 'mega' ), 'value' => esc_html__( 'Follow Us', 'mega' ), 'name' => 'title' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Facebook', 'mega' ), 'value' => '.', 'name' => 'facebook' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Facebook App ID', 'mega' ), 'value' => '', 'name' => 'facebook_app' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Facebook App Secret', 'mega' ), 'value' => '', 'name' => 'facebook_app_secret' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Facebook Meta', 'mega' ), 'pro' => 1, 'desc' => wp_kses( __( 'Use the following snippets of code to output the necessary information:
Number - [number]
', 'mega' ), array( 'br' => true, 'strong' => true )), 'value' => esc_html__( '[number] Fans', 'mega' ), 'name' => 'facebook_meta' ));
//$this->addChild( 'Mega_Block_Form_Text', array( 'label' => esc_html__( 'Twitter', 'mega' ), 'value' => '.', 'name' => 'twitter' )),
//$this->addChild( 'Mega_Block_Form_Text', array( 'label' => esc_html__( 'Twitter Meta', 'mega' ), 'pro' => 1, 'value' => esc_html__( '%s Followers', 'mega' ), 'name' => 'twitter_meta' )),
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Dribbble', 'mega' ), 'value' => '.', 'name' => 'dribbble' ));
$form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Dribbble Meta', 'mega' ), 'pro' => 1, 'desc' => wp_kses( __( 'Use the following snippets of code to output the necessary information:
Number - [number]
', 'mega' ), array( 'br' => true, 'strong' => true )), 'value' => esc_html__( '[number] Followers', 'mega' ), 'name' => 'dribbble_meta' ));
}
public function block()
{
extract( $this->mega['settings'] );
echo '';
foreach ( $this->bookmarks as $key => $args )
{
if ( !empty( $$key ) && ( $counter = $this->getCounter( $key, $args['api'], $$key )))
printf(
'- %3$s
',
$key,
esc_url( sprintf( $args['link'], $$key )),
mega_parse_message( array( 'number' => '' . number_format( $counter ) . '' ), ${$key . '_meta'} ),
mega_parse_message( array( 'number' => number_format( $counter )), ${$key . '_meta'} )
);
}
echo '
';
}
public function getCounter( $id, $args, $user )
{
if ( $counter = get_transient( $id . '_counter' ))
return $counter;
if ( !$user || empty( $user ))
return false;
if ( isset( $this->mega['settings'][$id . '_app'] ) && isset( $this->mega['settings'][$id . '_app_secret'] ))
$new = sprintf( $args['data'], $user, $this->mega['settings'][$id . '_app'], $this->mega['settings'][$id . '_app_secret'] );
else
$new = sprintf( $args['data'], $user );
$data = json_decode( wp_remote_retrieve_body( wp_remote_get( $new )));
if ( isset( $data->$args['key'] ))
$data1 = $data->$args['key'];
if ( !isset( $data1 ) || empty( $data1 ))
return false;
set_transient( $id . '_counter', $data1, 3600 );
return $data1;
}
}