コード例 #1
0
ファイル: lib_form.php プロジェクト: 1upon0/ui
function check_captcha()
{
    if ($_SERVER["REMOTE_ADDR"] == '::1') {
        return true;
    }
    $resp = recaptcha_check_answer(\ui\config('recaptcha_private_key'), $_SERVER["REMOTE_ADDR"], isset($_POST["recaptcha_challenge_field"]) ? $_POST["recaptcha_challenge_field"] : '', isset($_POST["recaptcha_response_field"]) ? $_POST["recaptcha_response_field"] : '');
    return $resp->is_valid;
}
コード例 #2
0
ファイル: lib_apis.php プロジェクト: 1upon0/ui
function config($api, $key = false)
{
    $config = \ui\config($api);
    if ($key) {
        if (isset($config[$key])) {
            return $config[$key];
        } else {
            return NULL;
        }
    }
    return $config;
}
コード例 #3
0
ファイル: lib_lang.php プロジェクト: 1upon0/ui
 function load($locale = false)
 {
     global $_LANG_POT;
     if ($locale == false) {
         if (isset($_REQUEST['lang'])) {
             $locale = substr($_REQUEST['lang'], 0, 2);
         } elseif (isset($_SESSION['lang_code'])) {
             $locale = $_SESSION['lang_code'];
         } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
             $langs = array();
             // break up string into pieces (languages and q factors)
             preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\\s*(;\\s*q\\s*=\\s*(1|0\\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
             if (count($lang_parse[1])) {
                 // create a list like "en" => 0.8
                 $langs = array_combine($lang_parse[1], $lang_parse[4]);
                 // set default to 1 for any without q factor
                 foreach ($langs as $lang => &$val) {
                     if ($val === '') {
                         $val = 1;
                     }
                     $val = (double) $val;
                 }
                 // sort list based on value
                 arsort($langs, SORT_NUMERIC);
             }
             // Check them all, until we find a match
             foreach ($langs as $locale => $priority) {
                 // Turn en-gb into en
                 $locale = strtolower(substr($locale, 0, 2));
                 // Check its in the array. If so, break the loop, we have one!
                 if (file_exists(\ui\global_var('app_dir') . 'lang/' . $locale . '.php')) {
                     break;
                 }
             }
         }
     }
     $_LANG_POT = array();
     $locale = preg_replace('[^a-z]', '', strtolower($locale));
     if (!file_exists(\ui\global_var('app_dir') . 'lang/' . $locale . '.php')) {
         $locale = \ui\config('lang');
     } else {
         $_SESSION['lang_code'] = $locale;
     }
     include 'lang/' . $locale . '.php';
     $_LANG_POT['lang_code'] = $locale;
     if (\ui\config('lang_write')) {
         \ui\register_hook('exit', '\\ui\\lang\\write');
     }
 }
コード例 #4
0
ファイル: lib_aws.php プロジェクト: 1upon0/ui
function s3_url($file, $bucket, $expires = 0)
{
    $file = rawurlencode($file);
    $file = str_replace('%2F', '/', $file);
    $path = $bucket . '/' . $file;
    if ($expires === 0) {
        $expires = time() + 24 * 3600;
    }
    $str = utf8_encode("GET\n\n\n{$expires}\n//{$path}");
    $str = hash_hmac('sha1', $str, \ui\config('aws_secret'), true);
    $str = base64_encode($str);
    $str = urlencode($str);
    $url = "http://{$bucket}.s3.amazonaws.com/{$file}";
    $url .= '?AWSAccessKeyId=' . \ui\config('aws_id') . '&Expires=' . $expires . '&Signature=' . $str;
    return $url;
}
コード例 #5
0
ファイル: lib_data.php プロジェクト: 1upon0/ui
function update($specific = false)
{
    $all_data =& data();
    if (!$specific) {
        foreach ($all_data as $container => &$data) {
            file_put_contents(\ui\config('data_path') . $container . \ui\config('data_file_suffix'), serialize($data));
        }
    } else {
        if (isset($all_data[$specific])) {
            file_put_contents(\ui\config('data_path') . $specific . \ui\config('data_file_suffix'), serialize($all_data[$specific]));
            return true;
        } else {
            return false;
        }
    }
}
コード例 #6
0
ファイル: lib_func.php プロジェクト: 1upon0/ui
function thumbnail($src, $thumb)
{
    //thumbnailer
    $post_src = @imagecreatefromstring(file_get_contents($src));
    if (!$post_src) {
        $type = pathinfo($src, PATHINFO_EXTENSION);
        if ($type == 'jpeg' || $type == 'jpg') {
            $post_src = imagecreatefromjpeg($src);
        } elseif ($type == 'png') {
            $post_src = imagecreatefrompng($src);
        } elseif ($type == 'gif') {
            $post_src = imagecreatefromgif($src);
        } else {
            error_log("\\ui\func\thumbnail(): Image format not recognised. src:{$src}");
            return false;
        }
        if (!$post_src) {
            error_log("\\ui\func\thumbnail(): Image format not recognised. src:{$src}");
            return false;
        }
    }
    $srcx = imagesx($post_src);
    $srcy = imagesy($post_src);
    $tarx = \ui\config('thumb_width');
    $tary = \ui\config('thumb_height');
    if ($tarx == 0) {
        $tarx = $srcx / $srcy * $tary;
    }
    if ($tary == 0) {
        $tary = $srcy / $srcx * $tarx;
    }
    $factor = $srcx / $tarx;
    $dfactor = 1.5;
    while ($factor >= $dfactor) {
        //imagefilter($post_src,post_FILTER_SMOOTH,$dfactor/$factor);
        imagecopyresampled($post_src, $post_src, 0, 0, 0, 0, ceil($srcx / $dfactor), ceil($srcy / $dfactor), $srcx, $srcy);
        $srcx = ceil($srcx / $dfactor);
        $srcy = ceil($srcy / $dfactor);
        $factor = $srcx / $tarx;
    }
    $post_tar = imagecreatetruecolor($tarx, $tary);
    imagecopyresampled($post_tar, $post_src, 0, 0, 0, 0, $tarx, $tary, $srcx, $srcy);
    imagedestroy($post_src);
    imagejpeg($post_tar, $thumb, 70);
    imagedestroy($post_tar);
    return true;
}
コード例 #7
0
ファイル: lib_fb.php プロジェクト: 1upon0/ui
/**
 * Exchanges a short token for a long one
 * Note that if a short token has already been exchanged, it can't be exchanged again
 * and a long token (if passed) will also return an error.
 * @return array array({the long token},{expiry time, absolute}) on success, otherwise array(false,0)
 */
function exchange_token($token = false)
{
    if ($token === false) {
        $token = session('access_token');
    }
    $response = get('/oauth/access_token', array('client_id' => \ui\config('fb_id'), 'client_secret' => \ui\config('fb_secret'), 'grant_type' => 'fb_exchange_token', 'fb_exchange_token' => $token), false);
    $params = array();
    parse_str($response, $params);
    if (isset($params['access_token'])) {
        $token = $params['access_token'];
        $expires = 59 * 3600 * 24 + time();
        //default expiry is 60 days. subtracted 1 day for safe margin
        session('access_token', $token);
        session('expires', $expires);
        return array($token, $expires);
    } else {
        error_log('\\ui\\fb\\exchange_token failed!' . PHP_EOL . $response . PHP_EOL);
    }
    return array(false, 0);
}
コード例 #8
0
ファイル: lib_auth2.php プロジェクト: 1upon0/ui
function log_out()
{
    $timestamp = time() - 10;
    setcookie(IID . '_login2_key', 0, $timestamp, '/');
    setcookie(IID . '_login2_time', 0, $timestamp, '/');
    setcookie(IID . '_login2_user', 0, $timestamp, '/');
    if (!session_id()) {
        session_start();
    }
    if (isset($_SESSION[IID . '_login2_key'])) {
        unset($_SESSION[IID . '_login2_key']);
    }
    if (isset($_SESSION[IID . '_login2_time'])) {
        unset($_SESSION[IID . '_login2_time']);
    }
    if (isset($_SESSION[IID . '_login2_user'])) {
        unset($_SESSION[IID . '_login2_user']);
    }
    $guest = \ui\config('users');
    $guest = $guest['guest'];
    user(false, $guest);
}
コード例 #9
0
ファイル: lib_auth.php プロジェクト: 1upon0/ui
function log_in($email, $pass, $remember = true)
{
    $user =& user();
    \ui\db\select(\ui\config('auth_table'), array('*'), "WHERE email='" . \ui\db\escape($email) . "' LIMIT 1");
    $user = \ui\db\assoc();
    if (!$user) {
        $admin = \ui\config('auth_admin');
        if ($email === $admin['email']) {
            $user = $admin;
            $user['password'] = pass($admin['password'], substr(\ui\config('salt'), 0, 8));
        }
    }
    if (!$user) {
        return false;
    }
    if (!check($pass, $user['password'])) {
        $user = array();
        if (DEBUG) {
            error_log('FAILED LOGIN ATTEMPT FROM ' . $_SERVER['REMOTE_ADDR'] . ' ON ' . date('M d,Y h:i:s a P') . PHP_EOL);
        }
        return false;
    }
    if (!session_id()) {
        session_start();
    }
    session_regenerate_id();
    $timestamp = time();
    $_SESSION[IID . '_login_time'] = $timestamp;
    $_SESSION[IID . '_login_email'] = $user['email'];
    $_SESSION[IID . '_login_key'] = make_key($user['email'], $user['password'], $timestamp);
    if ($remember) {
        setcookie(IID . '_login_key', $_SESSION[IID . '_login_key'], $timestamp + 3600 * 24 * 30, '/');
        setcookie(IID . '_login_email', $_SESSION[IID . '_login_email'], $timestamp + 3600 * 24 * 30, '/');
        setcookie(IID . '_login_time', $timestamp, $timestamp + 3600 * 24 * 30, '/');
    }
    return true;
}
コード例 #10
0
ファイル: lib_cache.php プロジェクト: 1upon0/ui
function data_stop(&$var, $id)
{
    $fname = \ui\config('cache_path') . $id . \ui\config('cache_file_suffix');
    $fs = @fopen($fname, 'wb', FALSE);
    if ($fs !== FALSE) {
        flock($fs, LOCK_EX);
        //Lock the file for safety
        fwrite($fs, pack('N', time()));
        fwrite($fs, serialize($var));
        flock($fs, LOCK_UN);
        fclose($fs);
        return TRUE;
    }
    return FALSE;
}