/** * This is a tool for selecting photos (to possibly add) * @param $facebook * Optional. You can provide instance of the Facebook class. * @param $upload * Defaults to false. If true, shows an option to upload, as well. * @param $action_uri * Defaults to 'items/addPhoto'. The URI to submit the form to. * @param $filter_visible * Optional string. Set to 'everyone' to only display albums visible to everyone. * @param $on_success * Optional string. The url to redirect to after a photo is added or uploaded. */ function items_addPhoto_tool($params) { if (isset(Users::$facebook)) { $facebook = Users::$facebook; } else { $app = Pie_Config::expect('pie', 'app'); if (!isset(Users::$facebooks[$app])) { throw new Pie_Exception_MissingObject(array('name' => 'Users::$facebooks[' . $app . ']')); } $facebook = Users::$facebooks[$app]; } $defaults = array('facebook' => $facebook, 'upload' => false, 'action_uri' => 'items/addPhoto', 'on_success' => Pie_Request::url()); extract(array_merge($defaults, $params)); if (!$facebook instanceof Facebook) { throw new Pie_Exception_WrongType(array('field' => '$facebook', 'type' => 'Facebook')); } if (isset($_REQUEST['_pie']['onSuccess'])) { $on_success = $_REQUEST['_pie']['onSuccess']; } $sn = Pie_Session::name(); $sid = Pie_Session::id(); $photos = array(); if (isset($aid)) { $photos = Items::facebookPhotos($facebook, $aid); return Pie::view('items/tool/addPhotoList.php', compact('photos')); } $facebook->require_login(); $album_rows = Items::facebookAlbums($facebook); $albums = array(); foreach ($album_rows as $ar) { if (isset($filter_visible) and $ar['visible'] != $filter_visible) { continue; } $albums[$ar['aid']] = $ar['name']; } $albums = $albums; if (count($album_rows)) { $row = reset($album_rows); $photos = Items::facebookPhotos($facebook, $row['aid']); } $throbber_url = Pie_Html::themedUrl('plugins/items/img/anim/throbber.gif'); $url_json = json_encode(Pie_Uri::url($action_uri)); Pie_Response::addStylesheet('plugins/items/css/Items.css'); if (Pie_Request::accepts('text/fbml')) { Pie_Response::addScript('plugins/items/fbjs/Items.fb.js'); } else { Pie_Response::addScript('plugins/items/js/Items.js'); } if (is_bool($upload)) { $upload = uniqid('up.', false); } $addPhoto_url_json = json_encode(Pie_Uri::url('items/addPhoto')); Pie_Response::addScriptLine("\tPie.Items.urls['items/addPhoto'] = {$addPhoto_url_json};"); return Pie::view('items/tool/addPhoto.php', compact('action_uri', 'on_success', 'on_added', 'albums', 'photos', 'throbber_url', 'upload')); }
/** * Logs a user in using a login identifier and a pasword * @param string $identifier * Could be an email address, a mobile number, or a user id. * @param string $password * The password to hash, etc. */ static function login($identifier, $password) { $return = null; $return = Pie::event('users/login', compact('identifier', 'password'), 'before'); if (isset($return)) { return $return; } Pie_Session::start(); $session_id = Pie_Session::id(); // First, see if we've already logged in somehow if ($user = self::loggedInUser()) { // Get logged in user from session return $user; } $user = new Users_User(); $user->identifier = $identifier; if ($user->retrieve()) { // User exists in database. Now check the password. $password_hash = self::hashPassword($password, $user->password_hash); if ($password_hash != $user->password_hash) { // Passwords don't match! throw new Users_Exception_WrongPassword(compact('identifier')); } // Do we need to update it? if (!isset($user->session_key) or $user->session_key != $session_id) { Pie::event('users/loginUpdateUser', compact('user'), 'before'); $user->session_key = $session_id; $user->save(); // update session_key in user Pie::event('users/loginUpdateUser', compact('user'), 'after'); } } else { // No user in database. Will insert a new one! // These users might be shared across apps. $user->password_hash = self::hashPassword($password); $user->session_key = $session_id; Pie::event('users/loginInsertUser', compact('user'), 'before'); $user->save(); Pie::event('users/loginInsertUser', compact('user'), 'after'); $inserted_new_user = true; } // Now save this user in the session as the logged-in user self::setLoggedInUser($user); Pie::event('users/login', compact('identifier', 'password', 'inserted_new_user', 'user'), 'after'); }