diff --git a/_lp/core/lib/db.function.php b/_lp/core/lib/db.function.php index 6ed809c..addb05c 100644 --- a/_lp/core/lib/db.function.php +++ b/_lp/core/lib/db.function.php @@ -23,7 +23,9 @@ function db( $host = null , $port = null , $user = null , $password = null , $db if( !$GLOBALS['LP_'.$db_key] = mysql_connect( $host.':'.$port , $user , $password , true ) ) { // - echo 'can\'t connect to database'; + //echo 'can\'t connect to database'; + $GLOBALS['LP_DB_CONNECT_ERROR'] = true; + $GLOBALS['LP_DB_CONNECT_ERROR_INFO'] = 'can\'t connect to database'; return false; } else @@ -32,13 +34,19 @@ function db( $host = null , $port = null , $user = null , $password = null , $db { if( !mysql_select_db( $db_name , $GLOBALS['LP_'.$db_key] ) ) { - echo 'can\'t select database ' . $db_name ; + //echo 'can\'t select database ' . $db_name ; + $GLOBALS['LP_DB_CONNECT_ERROR'] = true; + $GLOBALS['LP_DB_CONNECT_ERROR_INFO'] = 'can\'t select database ' . $db_name ; return false; } } } - mysql_query( "SET NAMES 'UTF8'" , $GLOBALS['LP_'.$db_key] ); + if(@mysql_query( "SET NAMES 'UTF8'" , $GLOBALS['LP_'.$db_key] )) + { + $GLOBALS['LP_DB_CONNECT_ERROR'] = false; + $GLOBALS['LP_DB_CONNECT_ERROR_INFO'] = '' ; + } } return $GLOBALS['LP_'.$db_key]; diff --git a/_lp/lp.init.php b/_lp/lp.init.php index 5c40b9a..44b3550 100644 --- a/_lp/lp.init.php +++ b/_lp/lp.init.php @@ -48,6 +48,8 @@ $o = new $class_name; if( !method_exists( $o , $a ) && !in_array( $c , $magic_controllers ) ) die('Can\'t find method - ' . $a . ' '); +if( strlen(c('timezone')) > 1 && function_exists('date_default_timezone_set') ) +@date_default_timezone_set( c('timezone') ); if(strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE && @ini_get("zlib.output_compression")) ob_start("ob_gzhandler"); call_user_func( array( $o , $a ) ); diff --git a/config/app.config.sample.php b/config/app.config.sample.php index 335b9fe..81f134e 100644 --- a/config/app.config.sample.php +++ b/config/app.config.sample.php @@ -12,6 +12,7 @@ $GLOBALS['config']['teamtoy_url'] = 'http://tt2net.sinaapp.com'; $GLOBALS['config']['at_short_name'] = true ; $GLOBALS['config']['can_modify_password'] = true ; +$GLOBALS['config']['timezone'] = 'Asia/Chongqing' ; // session time // you need change session lifetime in php.ini to0 diff --git a/controller/api.class.php b/controller/api.class.php index 0a25252..d6cfa66 100644 --- a/controller/api.class.php +++ b/controller/api.class.php @@ -2589,7 +2589,11 @@ public function send_error( $number , $msg ) if( g('API_EMBED_MODE') == 1 ) return json_encode( $obj ); else - die( json_encode( $obj ) ); + { + header('Content-type: application/json'); + die( json_encode( $obj ) ); + } + } /* @@ -2607,7 +2611,10 @@ public function send_result( $data ) if( g('API_EMBED_MODE') == 1 ) return json_encode( $obj ); else - die( json_encode( $obj ) ); + { + header('Content-type: application/json'); + die( json_encode( $obj ) ); + } } } ?> \ No newline at end of file diff --git a/controller/app.class.php b/controller/app.class.php index 40b4238..437b994 100644 --- a/controller/app.class.php +++ b/controller/app.class.php @@ -9,33 +9,41 @@ class appController extends coreController { function __construct() { - // 载入插件 - $plugins = c('plugins'); - if( mysql_query("SHOW COLUMNS FROM `plugin`",db()) ) - if($pinfos = get_data("SELECT * FROM `plugin`")) + // 安装时不启用插件 + if(g('c')!= 'install') { - foreach( $pinfos as $pinfo ) + // 载入插件 + $plugins = c('plugins'); + + if( mysql_query("SHOW COLUMNS FROM `plugin`",db()) ) + if($pinfos = get_data("SELECT * FROM `plugin`")) { - if( intval($pinfo['on']) == 0 ) - $plugins = array_remove( $pinfo['folder_name'] , $plugins ); - elseif( !in_array( $pinfo['folder_name'] , $plugins ) ) - $plugins[] = $pinfo['folder_name']; + foreach( $pinfos as $pinfo ) + { + if( intval($pinfo['on']) == 0 ) + $plugins = array_remove( $pinfo['folder_name'] , $plugins ); + elseif( !in_array( $pinfo['folder_name'] , $plugins ) ) + $plugins[] = $pinfo['folder_name']; + } } - } - - if( is_array($plugins) ) $plugins = array_unique( $plugins ); - if( isset($plugins) && is_array( $plugins ) ) - { - - foreach( $plugins as $plugin ) + + if( is_array($plugins) ) $plugins = array_unique( $plugins ); + if( isset($plugins) && is_array( $plugins ) ) { - $plugin_file = c('plugin_path') . DS . basename($plugin) . DS . 'app.php'; - if( file_exists( $plugin_file ) ) - require_once( $plugin_file ); + + foreach( $plugins as $plugin ) + { + $plugin_file = c('plugin_path') . DS . basename($plugin) . DS . 'app.php'; + if( file_exists( $plugin_file ) ) + require_once( $plugin_file ); + } } - } - $GLOBALS['config']['plugins'] = $plugins; + $GLOBALS['config']['plugins'] = $plugins; + } + + + // update config for this time diff --git a/controller/buddy.class.php b/controller/buddy.class.php index 32c6ee8..d76f1f3 100644 --- a/controller/buddy.class.php +++ b/controller/buddy.class.php @@ -38,6 +38,8 @@ function add() //ajax_echo( print_r( $_REQUEST , 1 ) ); $name = z(t(v('name'))); + // remove spaces in name + $name = str_replace( ' ' , '' , $name ); if( strlen($name) < 1 ) return render( array( 'code' => 100002 , 'message' => 'bad args' ) , 'rest' ); $email = z(t(v('email'))); diff --git a/controller/dashboard.class.php b/controller/dashboard.class.php index f344c6f..4cd8292 100644 --- a/controller/dashboard.class.php +++ b/controller/dashboard.class.php @@ -304,8 +304,6 @@ function password() function update_password() { - return render( array( 'code' => 100002 , 'message' => 'demo cannot modify password' ) , 'rest' ); - $opassword = z(t(v('oldpassword'))); if( strlen($opassword) < 1 ) return render( array( 'code' => 100002 , 'message' => 'bad args,old password required' ) , 'rest' ); diff --git a/controller/install.class.php b/controller/install.class.php index 54e4599..6d55937 100644 --- a/controller/install.class.php +++ b/controller/install.class.php @@ -7,12 +7,23 @@ class installController extends appController function __construct() { parent::__construct(); - if( !is_installed() ) db_init(); } function index() { - return info_page('API Server 已初始化完成,请使用管理账号登入'); + if( is_installed() ) + return info_page('API Server 已初始化完成,请使用管理账号登入'); + elseif( intval(v('do')) == 1 ) + { + db_init(); + } + else + { + $data['title'] = $data['top_title'] = 'TeamToy安装页面'; + return render( $data , 'web' , 'fullwidth' ); + } + + } diff --git a/controller/pluglist.class.php b/controller/pluglist.class.php index 23e48ad..bc81805 100644 --- a/controller/pluglist.class.php +++ b/controller/pluglist.class.php @@ -59,7 +59,7 @@ function uploaded() $zip = new dUnzip2( $tmp_name ); $zip->debug = false; $zip->unzipAll( $plug_path ); - chmod( $plug_path , 0755 ); + @chmod( $plug_path , 0755 ); $info_file = $plug_path . DS . 'app.php'; if( file_exists( $info_file ) ) { diff --git a/index.php b/index.php index 1c6d2c7..a9afba1 100644 --- a/index.php +++ b/index.php @@ -7,6 +7,4 @@ //ini_set('include_path', dirname( __FILE__ ) . DS .'_lp' ); include_once( '_lp'.DS .'lp.init.php' ); -/**** lp framework init finished ***/ -ini_set( 'display_errors', true ); -error_reporting( 1024 ); \ No newline at end of file +/**** lp framework init finished ***/ \ No newline at end of file diff --git a/lib/app.function.php b/lib/app.function.php index ff3fc96..fe77185 100644 --- a/lib/app.function.php +++ b/lib/app.function.php @@ -29,6 +29,7 @@ function is_online( $uid ) function is_installed() { + if( !db()) return false; return mysql_query("SHOW COLUMNS FROM `user`",db()); } @@ -301,17 +302,19 @@ function get_device() function login( $email , $password ) { - if($content = file_get_contents( c('api_server') . '?c=api&a=user_get_token&email=' . u($email) . '&password=' .u($password) )) - { - $data = json_decode( $content , 1 ); - if( ($data['err_code'] == 0) && is_array( $data['data'] ) ) - return $data['data']; - else - return false; - } - return null; - - + $params = array(); + $params['email'] = $email; + $params['password'] = $password; + + if($content = send_request( 'user_get_token' , $params )) + { + $data = json_decode( $content , 1 ); + if( ($data['err_code'] == 0) && is_array( $data['data'] ) ) + return $data['data']; + else + return false; + } + return null; } function token() @@ -319,7 +322,7 @@ function token() return $_SESSION['token']; } -function send_request( $action , $param , $token ) +function send_request( $action , $param , $token = null ) { require_once( AROOT . 'controller' . DS . 'api.class.php' ); require_once( AROOT . 'model' . DS . 'api.function.php' ); @@ -329,7 +332,8 @@ function send_request( $action , $param , $token ) $bake_request = $_REQUEST; $_REQUEST['c'] = 'api'; $_REQUEST['a'] = $action; - $_REQUEST['token'] = $token; + if( $token !== null ) + $_REQUEST['token'] = $token; if( (is_array( $param )) && (count($param) > 0) ) foreach( $param as $key => $value ) diff --git a/misc/install.sql b/misc/install.sql index 1d464ee..2eff13e 100644 --- a/misc/install.sql +++ b/misc/install.sql @@ -95,7 +95,7 @@ CREATE TABLE IF NOT EXISTS `feed` ( -- CREATE TABLE IF NOT EXISTS `keyvalue` ( - `key` varchar(16) NOT NULL, + `key` varchar(64) NOT NULL, `value` varchar(255) DEFAULT NULL, UNIQUE KEY `key` (`key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/static/css/style.css b/static/css/style.css index 64b6703..c2c0e33 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1571,30 +1571,30 @@ div.upgrade a.btn padding-left:2px; } -.table-plugin +.table-plugin,.table-install { background-color: white; color:#333; margin-top:20px; } -.table-plugin a +.table-plugin a,.table-install a { color:gray; } -.table-plugin thead +.table-plugin thead,.table-install thead { color:white; background-color: #273342; } -.table-plugin td,.table-plugin th +.table-plugin td,.table-plugin th,.table-install td,.table-install th { padding:15px; } -.table-plugin th +.table-plugin th , .table-install th { padding-top:8px; padding-bottom:8px; @@ -1605,6 +1605,17 @@ div.upgrade a.btn text-align:center; } +.table-install tbody tr +{ + color:gray; +} + +.table-install tr.bad +{ + color:red; +} + + @media (max-width: 480px) { diff --git a/static/script/app.js b/static/script/app.js index 61cf3e5..7d58ae2 100644 --- a/static/script/app.js +++ b/static/script/app.js @@ -1,3 +1,8 @@ +$.ajaxSetup +({ + dataType: "text" +}); + /* send form data via ajax and return the data to callback function */ diff --git a/version.txt b/version.txt index 8966a60..0b2a2c0 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1147 +1190 diff --git a/view/layout/rest/default.tpl.html b/view/layout/rest/default.tpl.html index d373025..774ddfc 100644 --- a/view/layout/rest/default.tpl.html +++ b/view/layout/rest/default.tpl.html @@ -4,13 +4,15 @@ $array = array(); $array['err_code'] = 0; $array['data'] = $data; - ajax_echo( json_encode( $array )); + header('Content-type: application/json'); + echo json_encode( $array ); } else { $array = array(); $array['err_code'] = intval($code); $array['message'] = $message; - ajax_echo( json_encode( $array )); + header('Content-type: application/json'); + echo json_encode( $array ); } ?> diff --git a/view/layout/web/header.tpl.html b/view/layout/web/header.tpl.html index f5fe94c..f362a46 100644 --- a/view/layout/web/header.tpl.html +++ b/view/layout/web/header.tpl.html @@ -35,7 +35,10 @@