Skip to content

Commit

Permalink
add json header, install guide , update keyvalue table schema
Browse files Browse the repository at this point in the history
  • Loading branch information
easychen committed Feb 4, 2013
1 parent 3d261e9 commit 6c115c9
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 56 deletions.
14 changes: 11 additions & 3 deletions _lp/core/lib/db.function.php
Expand Up @@ -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
Expand All @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions _lp/lp.init.php
Expand Up @@ -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 ) );
Expand Down
1 change: 1 addition & 0 deletions config/app.config.sample.php
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions controller/api.class.php
Expand Up @@ -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 ) );
}

}

/*
Expand All @@ -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 ) );
}
}
}
?>
50 changes: 29 additions & 21 deletions controller/app.class.php
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions controller/buddy.class.php
Expand Up @@ -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')));
Expand Down
2 changes: 0 additions & 2 deletions controller/dashboard.class.php
Expand Up @@ -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' );

Expand Down
15 changes: 13 additions & 2 deletions controller/install.class.php
Expand Up @@ -7,12 +7,23 @@ class installController extends appController
function __construct()
{
parent::__construct();
if( !is_installed() ) db_init();
}

function index()
{
return info_page('API Server 已初始化完成,<a href="?c=guest">请使用管理账号登入</a>');
if( is_installed() )
return info_page('API Server 已初始化完成,<a href="?c=guest">请使用管理账号登入</a>');
elseif( intval(v('do')) == 1 )
{
db_init();
}
else
{
$data['title'] = $data['top_title'] = 'TeamToy安装页面';
return render( $data , 'web' , 'fullwidth' );
}


}


Expand Down
2 changes: 1 addition & 1 deletion controller/pluglist.class.php
Expand Up @@ -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 ) )
{
Expand Down
4 changes: 1 addition & 3 deletions index.php
Expand Up @@ -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 );
/**** lp framework init finished ***/
30 changes: 17 additions & 13 deletions lib/app.function.php
Expand Up @@ -29,6 +29,7 @@ function is_online( $uid )

function is_installed()
{
if( !db()) return false;
return mysql_query("SHOW COLUMNS FROM `user`",db());
}

Expand Down Expand Up @@ -301,25 +302,27 @@ 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()
{
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' );
Expand All @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion misc/install.sql
Expand Up @@ -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;
Expand Down
21 changes: 16 additions & 5 deletions static/css/style.css
Expand Up @@ -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;
Expand All @@ -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)
{

Expand Down
5 changes: 5 additions & 0 deletions static/script/app.js
@@ -1,3 +1,8 @@
$.ajaxSetup
({
dataType: "text"
});

/*
send form data via ajax and return the data to callback function
*/
Expand Down
2 changes: 1 addition & 1 deletion version.txt
@@ -1 +1 @@
1147
1190
6 changes: 4 additions & 2 deletions view/layout/rest/default.tpl.html
Expand Up @@ -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 );
}
?>
3 changes: 3 additions & 0 deletions view/layout/web/header.tpl.html
Expand Up @@ -35,7 +35,10 @@
<ul class="dropdown-menu">
<li><a href="http://teamtoy.net" target="_blank">TeamToy V<?=local_version()?></a></li>
<?php if( is_admin() ): ?>
<?php if( is_writable(AROOT) ): ?>
<li><a href="javascript:check_version();void(0);" target="_blank">版本升级</a></li>
<?php else: ?>
<?php endif; ?>
<?php do_action( 'UI_USERMENU_ADMIN_LAST' ); ?>
<?php endif; ?>
<li class="divider"></li>
Expand Down

0 comments on commit 6c115c9

Please sign in to comment.