Example #1
0
function dlog($log, $type = 'log', $css = '')
{
    $log_file = AROOT . 'compiled' . DS . 'log.txt';
    if (is_array($log)) {
        $log = print_r($log, true);
    }
    if (is_writable($log_file)) {
        file_put_contents($log_file, $log . '@' . time() . PHP_EOL, FILE_APPEND);
    } elseif (on_sae()) {
        sae_debug($log);
    }
}
Example #2
0
 /**
  * 用户更新头像
  *
  * 使用标准Form表单上传,头像文件名为file,只接受jpg格式的文件
  *
  * @param string token , 必填
  * @return user array 
  * @author EasyChen
  */
 public function user_update_avatar()
 {
     if ($_FILES['file']['error'] != 0) {
         return self::send_error(OP_API_UPLOAD_ERROR, 'UPLOAD ERROR ' . $_FILES['file']['error']);
     }
     $tmp_image_name = SAE_TMP_PATH . md5(time() . rand(1, 99999)) . '.tmp.jpg';
     jpeg_up($_FILES['file']['tmp_name'], $tmp_image_name);
     include_once AROOT . 'lib/thumbnail.class.php';
     $file_thumb_name = 'avatar-' . uid() . '.jpg';
     $tmp_file = SAE_TMP_PATH . $file_thumb_name;
     include_once AROOT . 'lib/icon.class.php';
     $icon = new Icon();
     $icon->path = $tmp_image_name;
     $icon->size = 100;
     $icon->dest = $tmp_file;
     $icon->createIcon();
     if (on_sae()) {
         $s = new SaeStorage();
         if (!($thumb_url = $s->write('upload', $file_thumb_name, file_get_contents($tmp_file)))) {
             return self::send_error(OP_API_STORAGE_ERROR, 'SAVE ERROR ' . $s->errmsg());
         }
     } else {
         $local_storage = AROOT . 'static' . DS . 'upload' . DS . 'avatar' . DS;
         $local_storage_url = c('site_url') . DS . 'static' . DS . 'upload' . DS . 'avatar' . DS;
         $thumb_path = $local_storage . $file_thumb_name;
         $thumb_url = $local_storage_url . $file_thumb_name;
         if (!copy($tmp_file, $thumb_path)) {
             return self::send_error(OP_API_STORAGE_ERROR, 'SAVE ERROR ');
         }
     }
     $sql = "UPDATE `user` SET `avatar_small` = '" . s($thumb_url) . "' WHERE `id` = '" . intval(uid()) . "' LIMIT 1";
     run_sql($sql);
     if (mysql_errno() != 0) {
         return self::send_error(OP_API_DB_ERROR, __('API_MESSAGE_DATABASE_ERROR') . mysql_error());
     } else {
         return self::send_result(get_user_info_by_id(intval(uid())));
     }
 }
Example #3
0
<?php

$GLOBALS['lpconfig']['site_name'] = '';
$GLOBALS['lpconfig']['site_domain'] = '';
if (!on_sae()) {
    $GLOBALS['lpconfig']['mode'] = 'dev';
}
$GLOBALS['lpconfig']['buildeverytime'] = false;
Example #4
0
try {
    require_once FROOT . 'lib' . DS . 'functions.php';
    // 公用函数
    require_once FROOT . 'config' . DS . 'core.php';
    // 核心配置
    require_once AROOT . 'config' . DS . 'database.php';
    // 数据库配置
    require_once AROOT . 'config' . DS . 'app.php';
    // 应用配置
    require_once AROOT . 'lib' . DS . 'functions.php';
    // 公用函数
    if (is_devmode()) {
        ini_set('display_errors', true);
        error_reporting(E_ALL);
    }
    $force_build = !on_sae() && is_devmode() && c('buildeverytime');
    load_route_file($force_build);
} catch (PDOException $e) {
    $error = get_error('DATABASE');
    $error['message'] = $error['message'] . '- ' . $e->getMessage();
    send_json($error);
} catch (\Lazyphp\Core\RestException $e) {
    $class_array = explode('\\', get_class($e));
    $class = t(end($class_array));
    $prefix = strtoupper(rremove($class, 'Exception'));
    $error = get_error($prefix);
    $error['message'] = $error['message'] . '- ' . $e->getMessage();
    send_json($error);
} catch (\Exception $e) {
    // alway send json format
    $class_array = explode('\\', get_class($e));
Example #5
0
<?php

// 兼容SAE
if (on_sae()) {
    $GLOBALS['lpconfig']['database'] = array('adapter' => 'mysql', 'host' => SAE_MYSQL_HOST_M, 'name' => SAE_MYSQL_DB, 'user' => SAE_MYSQL_USER, 'password' => SAE_MYSQL_PASS, 'port' => SAE_MYSQL_PORT, 'charset' => 'utf8');
    $GLOBALS['lpconfig']['database']['dsn'] = $GLOBALS['lpconfig']['database']['adapter'] . ':host=' . $GLOBALS['lpconfig']['database']['host'] . ';port=' . $GLOBALS['lpconfig']['database']['port'] . ';dbname=' . $GLOBALS['lpconfig']['database']['name'] . ';port=' . $GLOBALS['lpconfig']['database']['port'] . ';charset=' . $GLOBALS['lpconfig']['database']['charset'];
} else {
    $GLOBALS['lpconfig']['database'] = array('adapter' => 'mysql', 'host' => 'localhost', 'name' => c('site_db'), 'user' => 'root', 'password' => 'root', 'port' => 8889, 'charset' => 'utf8');
    $GLOBALS['lpconfig']['database']['dsn'] = $GLOBALS['lpconfig']['database']['adapter'] . ':host=' . $GLOBALS['lpconfig']['database']['host'] . ';port=' . $GLOBALS['lpconfig']['database']['port'] . ';dbname=' . $GLOBALS['lpconfig']['database']['name'] . ';port=' . $GLOBALS['lpconfig']['database']['port'] . ';charset=' . $GLOBALS['lpconfig']['database']['charset'];
}
$GLOBALS['lpconfig']['database_dev'] = array('adapter' => 'mysql', 'host' => 'localhost', 'name' => c('site_db'), 'user' => 'root', 'password' => 'root', 'port' => 8889, 'charset' => 'utf8');
$GLOBALS['lpconfig']['database_dev']['dsn'] = $GLOBALS['lpconfig']['database_dev']['adapter'] . ':host=' . $GLOBALS['lpconfig']['database_dev']['host'] . ';port=' . $GLOBALS['lpconfig']['database_dev']['port'] . ';dbname=' . $GLOBALS['lpconfig']['database_dev']['name'] . ';port=' . $GLOBALS['lpconfig']['database_dev']['port'] . ';charset=' . $GLOBALS['lpconfig']['database_dev']['charset'];