Esempio n. 1
0
 function get_fb($code)
 {
     if (!$code) {
         not_found();
     }
     $url = "https://graph.facebook.com/oauth/access_token?" . 'client_id=' . FACEBOOK_APP_ID . '&redirect_uri=http://' . $_SERVER['HTTP_HOST'] . '/api/fb' . '&client_secret=' . FACEBOOK_APP_KEY . '&code=' . urlencode($code);
     // var_dump($_SERVER)
     // print $url;
     $ret = http_get($url);
     if (isset($ret['error']) || !isset($ret['access_token'])) {
         server_error($ret['error']['message']);
     }
     $at = $ret['access_token'];
     $sig = _gen_sig($at);
     $url = "https://graph.facebook.com/me?access_token=" . $at;
     $dat = http_get($url);
     if (!isset($dat['id'])) {
         return server_error('invalid record');
     }
     $user_id = email_exists($dat['email']);
     if (!is_file(get_stylesheet_directory() . '/sdk/cache/' . $dat['id'] . '.jpg')) {
         file_put_contents(get_stylesheet_directory() . '/sdk/cache/' . $dat['id'] . '.jpg', file_get_contents(get_bloginfo('template_directory') . '/sdk/timthumb.php?src=http://graph.facebook.com/' . $dat['id'] . '/picture?type=large&w=75&h=75'));
     }
     if ($user_id) {
         // Existing user.
         $user_data = get_userdata($user_id);
         $user_login = $user_data->user_login;
         // @TODO do a check against user meta to make sure its the same user
     } else {
         // New user.
         if (!isset($dat['username'])) {
             $dat['username'] = $dat['first_name'] . '_' . $dat['last_name'];
         }
         $userdata = array('user_login' => $dat['username'], 'user_email' => $dat['email'], 'first_name' => $dat['first_name'], 'last_name' => $dat['last_name'], 'user_url' => $dat['link'], 'user_pass' => wp_generate_password());
         $user_id = wp_insert_user($userdata);
         if (is_wp_error($user)) {
             return server_error('Something went wrong with creating your user.');
         }
         // switch off the wordpress bar, which is on by default
         update_user_meta($user_id, 'show_admin_bar_front', false);
         if (is_file(get_stylesheet_directory() . '/sdk/cache/' . $dat['id'] . '.jpg')) {
             update_user_meta($user_id, 'hg_profile_url', get_stylesheet_directory_uri() . '/sdk/cache/' . $dat['id'] . '.jpg');
         }
     }
     // log the user in..
     wp_set_auth_cookie($user_id, true);
     // store login details
     update_user_meta($user_id, 'hg_facebook', true);
     update_user_meta($user_id, 'hg_facebook_id', $dat['id']);
     update_user_meta($user_id, 'hg_facebook_acess_token', $at);
     update_user_meta($user_id, 'hg_facebook_sig', $sig);
     $json_user_info = json_encode(array('username' => $dat['username'], 'email' => $dat['email'], 'access_token' => $at, 'sig' => $sig));
     require_once 'templates/oauth_popup_close.php';
 }
Esempio n. 2
0
/**
 * Returns server error output
 *
 * @access private
 * @param int $errno
 * @param string $errstr
 * @param string $errfile
 * @param string $errline
 * @return string
 */
function error_server_error_output($errno, $errstr, $errfile, $errline)
{
    if (!function_exists('server_error')) {
        /**
         * Default server error output
         *
         * @param string $errno
         * @param string $errstr
         * @param string $errfile
         * @param string $errline
         * @return string
         */
        function server_error($errno, $errstr, $errfile = null, $errline = null)
        {
            $is_http_error = http_response_status_is_valid($errno);
            $args = compact('errno', 'errstr', 'errfile', 'errline', 'is_http_error');
            option('views_dir', option('limonade_views_dir'));
            $html = render('error.html.php', null, $args);
            option('views_dir', option('error_views_dir'));
            return html($html, error_layout(), $args);
        }
    }
    return server_error($errno, $errstr, $errfile, $errline);
}
 function put()
 {
     $x = file_get_contents("php://input");
     $y = json_decode($x, TRUE);
     $z = mysql_real_escape_string($y['google_drive_folder_id']);
     $sql = "UPDATE {$this->table} SET google_drive_folder_id = '{$z}'";
     $sql .= " WHERE case_id = " . mysql_real_escape_string($this->id);
     $result = mysql_query($sql) or server_error(mysql_error($result));
     $this->transmitJson();
     return;
 }
Esempio n. 4
0
// exécution du routage.
$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
switch ($routeInfo[0]) {
    case Dispatcher::NOT_FOUND:
        $body = not_found();
        break;
    case Dispatcher::METHOD_NOT_ALLOWED:
        $body = not_allowed($routeInfo[1]);
        break;
    case Dispatcher::FOUND:
        $handler = $routeInfo[1];
        $args = $routeInfo[2];
        try {
            $body = call_user_func_array($handler, $args);
        } catch (Exception $e) {
            $body = server_error($e);
        }
        break;
}
header("Content-Type: text/html; charset=utf-8");
header("Content-Length: " . strlen($body));
echo $body;
// les pages
function equipe($slug)
{
    global $twig, $base, $titre;
    $personne = R::findOne("personnes", "slug = ?", [$slug]);
    if (!$personne) {
        return not_found();
    }
    return $twig->render("equipe.html", compact("base", "titre", "personne"));
Esempio n. 5
0
/**
 * Returns server error output
 *
 * @access private
 * @param int $errno 
 * @param string $errstr 
 * @param string $errfile 
 * @param string $errline 
 * @return string
 */
function error_server_error_output($errno, $errstr, $errfile, $errline)
{
    if (!function_exists('server_error')) {
        /**
         * Default server error output
         *
         * @param string $errno 
         * @param string $errstr 
         * @param string $errfile 
         * @param string $errline 
         * @return string
         */
        function server_error($errno, $errstr, $errfile = null, $errline = null)
        {
            $is_http_error = http_response_status_is_valid($errno);
            $html = render_error($errno, $errstr, $errfile, $errline, $is_http_error);
            return error_html($html);
        }
    }
    return server_error($errno, $errstr, $errfile, $errline);
}