<?php /** * Embeds a twitter Follow button into the current page. Used by * the WYSIWYG editor's dynamic objects menu. */ if (! isset (self::$called['social/twitter/init'])) { echo $this->run ('social/twitter/init'); } if (! isset ($data['twitter_id'])) { $id = Appconf::user ('Twitter', 'twitter_id'); $data['twitter_id'] = (! empty ($id)) ? $id : $appconf['Twitter']['id']; } echo $tpl->render ('social/twitter/follow', $data);
$_POST['expires'] = $now; $_POST['signed_up'] = $now; $_POST['updated'] = $now; $_POST['userdata'] = json_encode(array()); unset($_POST['verify_pass']); unset($_POST['_states']); unset($_POST['_countries']); $u = new User($_POST); $u->put(); Versions::add($u); if (!$u->error) { $this->add_notification(__('Member added.')); $this->hook('user/add', $_POST); $this->redirect('/user/admin'); } $page->title = __('An Error Occurred'); echo __('Error Message') . ': ' . $u->error; } else { $u = new User(); $u->type = Appconf::user('User', 'default_role'); $u->types = User::allowed_roles(); $u->failed = $f->failed; $u = $f->merge_values($u); $u->_states = user\Data::states(); $u->_countries = user\Data::countries(); $page->title = __('Add Member'); $page->add_script('/js/json2.js'); $page->add_script('/js/jstorage.js'); $page->add_script('/js/jquery.autosave.js'); echo $tpl->render('user/add', $u); }
* New user form for registering social login users. */ if (!$appconf['Custom Handlers']['user/signup']) { echo $this->error(404, __('Not found'), __('The page you requested could not be found.')); return; } // Check for a custom handler override $res = $this->override('user/login/newuser'); if ($res) { echo $res; return; } $f = new Form('post', 'user/login/newuser'); if ($f->submit()) { $date = gmdate('Y-m-d H:i:s'); $u = new User(array('name' => $_POST['name'], 'email' => $_POST['email'], 'password' => User::encrypt_pass($_POST['password']), 'expires' => $date, 'type' => Appconf::user('User', 'default_role'), 'signed_up' => $date, 'updated' => $date, 'userdata' => json_encode(array()), 'about' => '')); $u->put(); Versions::add($u); if (!$u->error) { $oid = new User_OpenID(array('token' => $_POST['token'], 'user_id' => $u->id)); $oid->put(); $_POST['username'] = $_POST['email']; User::require_login(); $this->redirect($_POST['redirect']); } // TODO: already have an account @error_log('Error creating profile: ' . $u->error); $page->title = 'An Error Occurred'; echo '<p>Please try again later.</p>'; echo '<p><a href="/">' . __('Back') . '</a></p>'; } else {
/** * Log out and optionally redirect to the specified URL. */ public static function logout($redirect_to = FALSE, $path = '/', $domain = false, $secure = false, $httponly = true) { if (self::$user === FALSE) { self::require_login(); } if (Appconf::user('User', 'multi_login')) { user\Session::clear($_SESSION['session_id']); user\Session::clear_expired(); } elseif (!empty(self::$user->session_id)) { self::$user->expires = gmdate('Y-m-d H:i:s', time() - 100000); self::$user->put(); } $_SESSION['session_id'] = NULL; $name = conf('General', 'session_name'); if (isset($_COOKIE[$name])) { $domain = $domain ? $domain : conf('General', 'session_domain'); if ($domain === 'full') { $domain = $_SERVER['HTTP_HOST']; } elseif ($domain === 'top') { $parts = explode('.', $_SERVER['HTTP_HOST']); $tld = array_pop($parts); $domain = '.' . array_pop($parts) . '.' . $tld; } setcookie($name, $_COOKIE[$name], time() - 100000, $path, $domain, $secure, $httponly); } if ($redirect_to) { global $controller; $controller->redirect($redirect_to); } }
} $data['num_of_tweets'] = isset ($data['num_of_tweets']) ? $data['num_of_tweets'] : 5; $data['show_dates'] = isset ($data['show_dates']) ? $data['show_dates'] : 'no'; $cache_key = 'social:twitter:' . $data['twitter_id'] . ':' . $data['num_of_tweets']; $res = $cache->get ($cache_key); if ($res) { return $res; } $twauth = new tmhOAuth (array ( 'consumer_key' => Appconf::user ('Twitter', 'consumer_key'), 'consumer_secret' => Appconf::user ('Twitter', 'consumer_secret'), 'user_token' => Appconf::user ('Twitter', 'access_token'), 'user_secret' => Appconf::user ('Twitter', 'access_token_secret') )); $code = $twauth->request ( 'GET', 'https://api.twitter.com/1.1/statuses/user_timeline.json', array ( 'screen_name' => $data['twitter_id'], 'count' => $data['num_of_tweets'] ) ); $res = json_decode ($twauth->response['response']); if ($code !== 200) { error_log (sprintf (
$u->address2 = $_POST['address2']; $u->city = $_POST['city']; $u->state = $_POST['state']; $u->country = $_POST['country']; $u->zip = $_POST['zip']; $u->title = $_POST['title']; $u->company = $_POST['company']; $u->website = $_POST['website']; if (isset($_FILES['photo']) && is_uploaded_file($_FILES['photo']['tmp_name'])) { $tmp_file = 'cache/.' . basename($_FILES['photo']['name']); $old_file = $u->photo; if (move_uploaded_file($_FILES['photo']['tmp_name'], $tmp_file)) { if (preg_match('/\\.jpe?g$/i', $tmp_file)) { Image::reorient($tmp_file); } $u->photo = Image::resize($tmp_file, Appconf::user('User', 'photo_width'), Appconf::user('User', 'photo_height')); if (strpos($u->photo, '#') !== false) { error_log('Error processing photo: ' . $u->photo); $u->photo = $old_file; } elseif (!empty($old_file) && $old_file !== $u->photo && file_exists($old_file)) { unlink($old_file); } unlink($tmp_file); } } $u->put(); Versions::add($u); if (!$u->error) { $page->title = __('Profile Updated'); echo '<p><a href="/user">' . __('Continue') . '</a></p>'; return;
<?php /** * Default log out handler. You can specify a `redirect` value * to send them to after logging out. */ // Check for a custom handler override $res = $this->override('user/logout'); if ($res) { echo $res; return; } if (!isset($_GET['redirect'])) { $_GET['redirect'] = Appconf::user('User', 'logout_redirect'); } if (!Validator::validate($_GET['redirect'], 'header')) { $_GET['redirect'] = '/'; } $redir = parse_url($_GET['redirect']); if ($redir === false || $_GET['redirect'] !== $redir['path'] && $_GET['redirect'] !== $redir['path'] . '?' . $redir['query']) { $_GET['redirect'] = '/'; } Lock::clear(); echo User::logout($_GET['redirect']);
<?php /** * Adds a new user for the user chooser's new user form. */ $this->require_acl('admin', 'user'); $page->layout = false; header('Content-Type: application/json'); $f = new Form('post', 'user/add'); $f->verify_csrf = false; if (!$f->submit()) { echo json_encode(array('success' => false, 'error' => __('Form validation failed. Please review and try again.'))); return; } if (!User::require_acl('user/edit_roles')) { $_POST['type'] = Appconf::user('User', 'default_role'); } $_POST['password'] = User::encrypt_pass($_POST['password']); $now = gmdate('Y-m-d H:i:s'); $_POST['expires'] = $now; $_POST['signed_up'] = $now; $_POST['updated'] = $now; $_POST['userdata'] = json_encode(array()); unset($_POST['verify_pass']); $u = new User($_POST); $u->put(); Versions::add($u); if (!$u->error) { $this->add_notification(__('Member added.')); $this->hook('user/add', $_POST); echo json_encode(array('success' => true, 'data' => array('id' => $u->id, 'name' => $u->name, 'email' => $u->email)));
} if (!$this->internal) { $page->title = __('Members'); } elseif (isset($data['redirect'])) { $_POST['redirect'] = $data['redirect']; } if (isset($_GET['redirect'])) { $_POST['redirect'] = $_GET['redirect']; } if (!isset($_POST['redirect'])) { $_POST['redirect'] = $_SERVER['REQUEST_URI']; if ($_POST['redirect'] == '/user/login') { $_POST['redirect'] = '/user'; } } if (!Validator::validate($_POST['redirect'], 'header')) { $_POST['redirect'] = '/user'; } $redir = parse_url($_POST['redirect']); if ($redir === false || $_POST['redirect'] !== $redir['path'] && $_POST['redirect'] !== $redir['path'] . '?' . $redir['query']) { $_POST['redirect'] = '/user'; } if (!User::require_login()) { if (!$this->internal && !empty($_POST['username'])) { echo '<p>' . __('Incorrect email or password, please try again.') . '</p>'; } $_POST['signup_handler'] = Appconf::user('Custom Handlers', 'user/signup'); echo $tpl->render('user/login', $_POST); } elseif (!$this->internal) { $this->redirect($_POST['redirect']); }
* * - `twitter_id` - The Twitter ID to show a feed of (default = Twitter ID setting). * - `num_of_tweets` - Number of tweets to show (default = 5) * - `show_dates` - Whether to show the tweet dates (default = no) * * Also available in the dynamic objects menu as "Twitter: Feed". * * > Note: Requires you to register a Twitter app, then enter your * > Twitter app credentials on the Accounts > Settings screen. */ if (!isset($data['twitter_id'])) { $id = Appconf::user('Twitter', 'twitter_id'); $data['twitter_id'] = !empty($id) ? $id : $appconf['Twitter']['id']; } $data['num_of_tweets'] = isset($data['num_of_tweets']) ? $data['num_of_tweets'] : 5; $data['show_dates'] = isset($data['show_dates']) ? $data['show_dates'] : 'no'; $cache_key = 'social:twitter:' . $data['twitter_id'] . ':' . $data['num_of_tweets']; $res = $cache->get($cache_key); if ($res) { return $res; } $twauth = new tmhOAuth(array('consumer_key' => Appconf::user('Twitter', 'consumer_key'), 'consumer_secret' => Appconf::user('Twitter', 'consumer_secret'), 'user_token' => Appconf::user('Twitter', 'access_token'), 'user_secret' => Appconf::user('Twitter', 'access_token_secret'))); $code = $twauth->request('GET', 'https://api.twitter.com/1.1/statuses/user_timeline.json', array('screen_name' => $data['twitter_id'], 'count' => $data['num_of_tweets'])); $res = json_decode($twauth->response['response']); if ($code !== 200) { error_log(sprintf('Error requesting tweets: [%d] %s', $res->errors[0]->code, $res->errors[0]->message)); } $data['tweets'] = $res; $out = $tpl->render('social/twitter/feed', $data); $cache->set($cache_key, $out, 0, 1800); echo $out;