/** * Constructor * * @access public * @return void **/ public function __construct() { $this->_ci =& get_instance(); // -------------------------------------------------------------------------- // Fetch our config variables $this->_settings = array(); $this->_settings['consumer_key'] = app_setting('social_signin_fb_app_id'); $this->_settings['consumer_secret'] = app_setting('social_signin_fb_app_secret'); if ($this->_settings['consumer_secret']) { $this->_settings['consumer_secret'] = $this->_ci->encrypt->decode($this->_settings['consumer_secret'], APP_PRIVATE_KEY); } // Sanity check if (!$this->_settings['consumer_key'] || !$this->_settings['consumer_secret']) { if (ENVIRONMENT === 'production') { show_fatal_error('Twitter has not been configured correctly', 'The Twitter App ID and secret must be specified in Admin under Site Settings.'); } else { show_error('The Twitter App ID and secret must be specified in Admin under Site Settings.'); } } // -------------------------------------------------------------------------- // Fire up and initialize the SDK Codebird\Codebird::setConsumerKey($this->_settings['consumer_key'], $this->_settings['consumer_secret']); $this->_twitter = new Codebird\Codebird(); }
/** * Create widget frontend * * @param array $args * @param array $instance */ public function widget($args, $instance) { global $cb; $consumer_key = $instance['consumer_key']; $consumer_secret = $instance['consumer_secret']; $access_token = $instance['access_token']; $access_secret = $instance['access_secret']; Codebird\Codebird::setConsumerKey($consumer_key, $consumer_secret); $cb = Codebird\Codebird::getInstance(); $cb->setToken($access_token, $access_secret); $tweets = $this->get_tweets($args['widget_id'], $instance); if (!empty($tweets['tweets']) and empty($tweets['tweets']->errors)) { $title = apply_filters('widget_title', $instance['title']); // before and after widget arguments are defined by themes echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } $user = current($tweets['tweets']); $user = $user->user; ?> <div class="twitter-profile"> <img src="<?php echo $user->profile_image_url; ?> "> <h4><a class="heading-text-color" href="http://twitter.com/<?php echo $user->screen_name; ?> "><?php echo $user->screen_name; ?> </a></h4> <div class="description content"><?php echo $user->description; ?> </div> </div> <ul class="twitter-timeline"> <?php foreach ($tweets['tweets'] as $tweet) { if (is_object($tweet)) { $tweet_text = htmlentities($tweet->text, ENT_QUOTES); ?> <li> <span class="content"><?php echo $tweet_text; ?> </span> <div class="date"><?php echo human_time_diff(strtotime($tweet->created_at)); ?> ago </div> </li> <?php } } ?> </ul> <?php echo $args['after_widget']; } }