function __construct($host, $port, $timeout = 0)
 {
     $this->sw = swoole_server_create($host, $port, self::$sw_mode, SWOOLE_SOCK_TCP);
     $this->host = $host;
     $this->port = $port;
     \Swoole\Error::$stop = false;
     \Swoole_js::$return = true;
     $this->swooleSetting = array('timeout' => 2.5, 'backlog' => 128, 'log_file' => '/tmp/swoole.log');
 }
Exemple #2
0
 function category()
 {
     if (empty($_GET['cid'])) {
         return "Access Deny";
     }
     //Error::dbd();
     $this->common();
     $tplname = strtolower($this->app) . '_list.html';
     $cate_id = (int) $_GET['cid'];
     $cate = getCategory($cate_id);
     if (empty($cate)) {
         Swoole_js::js_back('不存在的分类!', '/index.php');
         exit;
     }
     if (!empty($cate['uptime']) and Swoole\Tool::httpExpire($cate['uptime']) === false) {
         exit;
     }
     if ($cate['fid'] == 0) {
         $this->swoole->tpl->assign("fid", $cate_id);
         $this->swoole->tpl->assign("ccate", $cate);
         if ($cate['tplname']) {
             $tplname = $cate['tplname'];
         }
         $gets['fid'] = $cate_id;
     } else {
         if ($cate['tplname']) {
             $tplname = $cate['tplname'];
         }
         $this->swoole->tpl->assign("cate", $cate);
         $ccate = $this->swoole->db->query("select * from st_catelog where id={$cate['fid']} limit 1")->fetch();
         $this->swoole->tpl->assign("ccate", $ccate);
         $gets['cid'] = $cate_id;
     }
     $pager = null;
     $gets['order'] = 'addtime desc';
     $gets['page'] = empty($_GET['page']) ? 1 : (int) $_GET['page'];
     $gets['pagesize'] = empty($this->_model->pagesize) ? $this->swoole->config['cms']['pagesize'] : $this->_model->pagesize;
     $gets['select'] = "id,title,addtime";
     $list = $this->_model->gets($gets, $pager);
     if ($this->swoole->config['cms']['html_static']) {
         $pager->page_tpl = WEBROOT . "/{$this->app}/list_{$cate_id}_%s.html";
     }
     $pager = array('total' => $pager->total, 'render' => $pager->render());
     $this->swoole->tpl->assign('pager', $pager);
     $this->swoole->tpl->assign("list", $list);
     $this->swoole->tpl->assign('cid', $cate_id);
     $this->swoole->tpl->display($tplname);
 }
function manage_create_model()
{
    if ($_POST) {
        $name = trim($_POST['name']);
        $table = trim($_POST['table']);
        if (empty($name) or empty($table)) {
            return false;
        }
        if (is_file(WEBPATH . '/apps/models/' . $name . '.model.php')) {
            Swoole_js::js_back('已存在此模型');
            return false;
        } else {
            create_modelclass($name, $table);
            Swoole_js::js_back('创建成功');
            return true;
        }
    }
    $title = "Swoole创建模型";
    echo <<<HTMLS
    <head>
    <title>{$title}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
HTMLS;
    echo file_get_contents(LIBPATH . '/data/media/swoole.css');
    echo <<<HTMLS
</style>
</head>
<body>
\t<div id="content">
\t  <h1>{$title}</h1>
\t  <p>{$GLOBALS['menu']}</p>
\t  <form id="form1" name="form1" method="post" action="">
\t\t<table border="1" cellpadding="0" cellspacing="0" width="450">
HTMLS;
    echo '<tr><td>模型名称</td><td>' . Form::input('name') . '</td></tr>';
    echo '<tr><td>数据库表名</td><td>' . Form::input('table') . '</td></tr>';
    echo '<tr><td colspan=2><input type="submit" name="button" id="button" value="确认并创建" /></td></tr>';
    //结束
    echo '</table></form></div></body></html>';
}
Exemple #4
0
 function admin_reply()
 {
     if (empty($_GET['id'])) {
         die('No ID!');
     }
     if (empty($_POST['reply'])) {
         $gb = $this->swoole->model->Guestbook->get($_GET['id'])->get();
         $this->swoole->tpl->assign('gb', $gb);
         $this->swoole->tpl->display('admin_reply.html');
     } else {
         $this->swoole->model->Guestbook->set($_GET['id'], $_POST);
         Swoole_js::js_back('添加成功');
     }
 }
Exemple #5
0
 function reply()
 {
     session();
     if (!$_SESSION['isLogin']) {
         return Swoole_js::echojs("if(confirm('您还没有登录,是否调整到登录页面(请首先复制您的回答内容)?')) window.parent.location.href='/page/login/?'");
     }
     $this->swoole->autoload('user');
     if (!empty($_POST['reply'])) {
         $answer['content'] = $_POST['reply'];
         $answer['uid'] = $this->swoole->user->getUid();
         $user = createModel('UserInfo')->get($answer['uid']);
         $answer['aid'] = (int) $_POST['aid'];
         $ask = createModel('AskSubject')->get($answer['aid']);
         //答案数量加1
         $ask->qcount += 1;
         //如果是未答状态,则设置为已答
         if ($ask->mstatus == 0) {
             $ask->mstatus = 1;
         }
         $ask->save();
         //为用户增加积分,回答即加5分
         $user->gold += 5;
         $user->save();
         Api::sendmail($ask['uid'], $answer['uid'], "【系统】" . $user['nickname'] . "回答了你的提问.({$ask['title']})", $answer['content']);
         createModel('AskReply')->put($answer);
         return Swoole_js::alert('发布成功') . Swoole_js::echojs('window.parent.location.href = window.parent.location.href;');
     }
 }
Exemple #6
0
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
</head>

<body>
<?php 
if (isset($_FILES['media'])) {
    $file = file_upload('media');
    if ($file == '') {
        Swoole_js::js_back('错误的类型!');
        exit;
    }
    ?>
<script language="javascript">
window.parent.upfile_success("<?php 
    echo $file;
    ?>
");
</script>
<?php 
}
?>

<form name="form1" enctype="multipart/form-data" method="post" action="">
  <hr width="100%" size="1" color="#CCCCCC" />
 function handle_catelog_center($config)
 {
     if (!isset($config['model']) or !isset($config['name'])) {
         die('参数错误!');
     }
     $_model = createModel($config['model']);
     $this->swoole->tpl->assign('act_name', $config['name']);
     if (empty($config['tpl.add'])) {
         $config['tpl.add'] = LIBPATH . '/data/tpl/admin_catelog_center_add.html';
     }
     if (empty($config['tpl.list'])) {
         $config['tpl.list'] = LIBPATH . '/data/tpl/admin_catelog_center_list.html';
     }
     if (isset($config['limit']) and $config['limit'] === true) {
         $this->swoole->tpl->assign('limit', true);
     } else {
         $this->swoole->tpl->assign('limit', false);
     }
     if (isset($_GET['add'])) {
         if (!empty($_POST['name'])) {
             $data['name'] = trim($_POST['name']);
             $data['pagename'] = trim($_POST['pagename']);
             $data['fid'] = intval($_POST['fid']);
             $data['intro'] = trim($_POST['intro']);
             $data['keywords'] = trim($_POST['keywords']);
             #增加
             if (empty($_POST['id'])) {
                 $_model->put($data);
                 Swoole_js::js_back('增加成功!');
             } else {
                 $_model->set((int) $_POST['id'], $data);
                 Swoole_js::js_back('修改成功!');
             }
         } else {
             if (!empty($_GET['id'])) {
                 $data = $_model->get((int) $_GET['id'])->get();
                 $this->swoole->tpl->assign('data', $data);
             }
             $this->swoole->tpl->display($config['tpl.add']);
         }
     } else {
         if (!empty($_GET['del'])) {
             $del_id = intval($_GET['del']);
             $_model->del($del_id);
             Swoole_js::js_back('删除成功!');
         }
         //Error::dbd();
         $get['fid'] = empty($_GET['fid']) ? 0 : (int) $_GET['fid'];
         $get['page'] = empty($_GET['page']) ? 1 : (int) $_GET['page'];
         $get['pagesize'] = 15;
         $pager = null;
         $list = $_model->gets($get, $pager);
         $this->swoole->tpl->assign('list', $list);
         $this->swoole->tpl->assign('pager', array('total' => $pager->total, 'render' => $pager->render()));
         $this->swoole->tpl->display($config['tpl.list']);
     }
 }
Exemple #8
0
 /**
  * JS验证
  * @param $form_name
  * @return unknown_type
  */
 static function js($form_name, $each = false)
 {
     $js = "window.onload = function(){\n validator(\"{$form_name}\");\n";
     if ($each) {
         $js .= "validator_each(\"{$form_name}\");\n";
     }
     $js .= "};\n";
     return Swoole_js::echojs($js, true);
 }
Exemple #9
0
<?php

require '../config.php';
$php->tpl->template_dir = WEBPATH . '/admin/templates';
session();
//$php->db->debug = true;
$table = 'st_admin';
Auth::$session_prefix = 'admin_';
Auth::$login_url = '/admin/login.php?';
$auth = new Auth($php->db, $table);
$refer = isset($_GET['refer']) ? $_GET['refer'] : WEBROOT . '/admin/index.php';
if ($auth->isLogin()) {
    header('location:' . $refer);
}
if (isset($_POST['username']) and $_POST['username'] != '') {
    $password = Auth::mkpasswd($_POST['username'], $_POST['password']);
    if ($auth->login($_POST['username'], $password, isset($_POST['auto']) ? 1 : 0)) {
        $admin_id = $_SESSION['admin_user_id'];
        $_SESSION['admin_user'] = $php->db->query("select * from {$table} where id={$admin_id}")->fetch();
        header('location:' . $refer);
    } else {
        Swoole_js::js_back('用户名或密码错误!');
        exit;
    }
} else {
    $php->tpl->display('admin_login.html');
}
if (isset($_GET['logout'])) {
    $auth->logout();
}