user = $current_user->user_login; $this->_loggedIn = $this->_get_google_login($this->user); } } /* Private Methods */ private function _get_google_login($username) { if(isset($_COOKIE['grd_cookie'])) { $data = stripslashes($_COOKIE['grd_cookie']); $data = json_decode($data, true); if($data['uLogin'] == $username) { $this->_gUser = $data['user']; $this->_gPass = $data['pass']; return true; } else { return false; } } else { return false; } } private function _load_reader($user, $password) { include_once(GRD_BASE_INC_URL . '/greader.class.php'); $this->reader = new JDMReader($user, $password); $this->_readerLoaded = $this->reader->loaded; } private function _googleLoginForm() { $form = '
'; $form .= '

Log in with your Google credentials:

'; $form .= '
'; $form .= '

'; $form .= '

'; $form .= '


'; $form .= '
'; $form .= '
'; return $form; } /* Public Methods */ // Hook the widget into WordPress - first function to fire!!! public function load() { if(!$this->_loggedIn) { add_action('admin_head', array(&$this,'login_javascript')); add_action('wp_ajax_grd_login', array(&$this,'grd_login_callback')); } add_action('admin_head', array(&$this, 'admin_style')); add_action('wp_dashboard_setup', array(&$this, 'call_widget')); } // Add the actual widget to the dashboard public function call_widget() { wp_add_dashboard_widget('google_reader', 'Google Reader', array(&$this, 'widget')); } // Render the widget public function widget() { global $current_user; get_currentuserinfo(); if($this->_loggedIn) { $this->_load_reader($this->_gUser, $this->_gPass); echo '
'; echo $this->reader->listUnread('5'); echo '
'; } else { echo '
'; echo $this->_googleLoginForm(); echo '
'; } } /* Google Reader Login Functions */ public function login_javascript() { ?> _gUser = $_POST['gUser']; $this->_gPass = $_POST['gPass']; $this->_load_reader($this->_gUser, $this->_gPass); if($this->_readerLoaded) { $cookieData = array( 'uLogin' => $current_user->user_login, 'user' => $this->_gUser, 'pass' => $this->_gPass); setcookie('grd_cookie', json_encode($cookieData), time() + 24*7*3600, '/'); $data = '
'; $data .= $this->reader->listUnread('5'); $data .= '
'; } else { $data = '

Bad Login

'; $data .= $this->_googleLoginForm(); } echo $data; die(); } // Add styling for the Google login form public function admin_style() { ?>