Example #1
0
 function order()
 {
     if (empty($_GET['id'])) {
         return "错误:父页面id为空";
     }
     $parent_id = intval($_GET['id']);
     $model = createModel('WikiTree');
     if (!empty($_POST['order'])) {
         $order = explode(',', $_POST['order']);
         $n = count($order);
         if ($n < 2) {
             return $this->message(501, '错误的请求');
         }
         foreach ($order as $k => $id) {
             $model->set($id, array('orderid' => $n - $k));
         }
         return $this->message(0, '排序操作成功');
     } else {
         $node = $model->get($parent_id);
         if ($node['order_by_time']) {
             return Swoole\JS::js_back("已启用自动时间排序,无法使用手工排序功能。");
         }
         $gets['pid'] = $parent_id;
         $gets['order'] = App\Content::$order;
         $childs = $model->gets($gets);
         $this->tpl->assign('childs', $childs);
         $this->tpl->display("wiki/order.html");
     }
 }
Example #2
0
 function category()
 {
     if (empty($_GET['cid']) and empty($_GET['user'])) {
         error(409);
     }
     $_blog = createModel('UserLogs');
     $_cate = createModel('UserLogCat');
     $gets1 = array();
     if (isset($_GET['cid'])) {
         $cid = (int) $_GET['cid'];
         $cate = $_cate->get($cid)->get();
         $uid = $cate['uid'];
         $gets1['c_id'] = $cid;
     } else {
         $uid = (int) $_GET['user'];
         $cate = array();
     }
     $this->userinfo($uid);
     $gets1['uid'] = $uid;
     $gets1['dir'] = 0;
     $gets1['select'] = 'title,id,substring(content,1,1000) as des,addtime,reply_count,look_count';
     $gets1['page'] = empty($_GET['page']) ? 1 : (int) $_GET['page'];
     $gets1['pagesize'] = 10;
     $blogs = $_blog->gets($gets1, $pager);
     foreach ($blogs as &$m) {
         $m['addtime'] = date('n月j日 H:i', strtotime($m['addtime']));
         $m['des'] = mb_substr(strip_tags($m['des']), 0, 120);
     }
     $this->swoole->tpl->assign('cate', $cate);
     $this->swoole->tpl->assign('blogs', $blogs);
     $pager->span_open = array();
     $pager = array('total' => $pager->total, 'render' => $pager->render());
     $this->swoole->tpl->assign('pager', $pager);
     return $this->swoole->tpl->fetch('blog_category.html');
 }
Example #3
0
 function getInfo($uid)
 {
     $cache_key = 'user_info_' . $uid;
     $user = $this->swoole->cache->get($cache_key);
     if (empty($user)) {
         $forms = (require WEBPATH . '/dict/forms.php');
         $user = $this->get($uid)->get();
         if (!empty($user['sex'])) {
             $user['sex'] = $forms['sex'][$user['sex']];
         }
         if (!empty($user['education'])) {
             $user['education'] = $forms['education'][$user['education']];
         }
         $user['php_level'] = $forms['level'][$user['php_level']];
         $_skill = createModel('UserSkill')->getMap(array());
         if (!empty($user['skill'])) {
             $_s = explode(',', $user['skill']);
             foreach ($_s as $s) {
                 $skill[] = $_skill[$s];
             }
             $user['skill'] = $skill;
         }
         if (substr($user['avatar'], 4) != 'http') {
             $user['avatar'] = str_replace('/static/', $this->swoole->config['site']['static'], $user['avatar']);
         }
         $this->swoole->cache->set($cache_key, $user, $this->cache_life);
     }
     return $user;
 }
Example #4
0
 function index()
 {
     //session();
     $data = createModel('UserInfo')->get(12)->get();
     $this->swoole->tpl->assign('data', $data);
     $html = $this->swoole->tpl->fetch('test.html');
     $time = $this->showTime();
     return $html . $time;
 }
Example #5
0
 static function sendmail($to, $from, $title, $msg)
 {
     $model = createModel('UserMail');
     $put['title'] = $title;
     $put['content'] = $msg;
     $put['fid'] = $from;
     $put['tid'] = $to;
     return $model->put($put);
 }
Example #6
0
 function getByAid($app, $aid, &$pager = null)
 {
     $gets['leftjoin'] = array(createModel('UserInfo')->table, createModel('UserInfo')->table . '.id=' . $this->table . '.uid');
     $gets['select'] = 'content,uid,uname,avatar,addtime';
     $gets['aid'] = $aid;
     $gets['app'] = $app;
     $gets['order'] = 'addtime desc';
     $gets['limit'] = 50;
     return $this->gets($gets);
 }
Example #7
0
 protected function getProjectInfo()
 {
     $this->project = createModel('WikiProject')->get($this->project_id);
     if (empty($this->project)) {
         echo "您访问的项目不存在";
         exit;
     }
     $this->swoole->tpl->assign("project_id", $this->project_id);
     $this->swoole->tpl->assign("project", $this->project);
 }
Example #8
0
 static function newPage($content)
 {
     $_cont = createModel('WikiContent');
     $in2['title'] = $content['title'];
     if (strlen($content['content']) > 0 and $content['content'][0] == '`') {
         $content['content'] = ' ' . $content['content'];
     }
     $in2['content'] = $content['content'];
     $in2['id'] = $content['id'];
     $_cont->put($in2);
 }
Example #9
0
function smarty_function_model($params, &$smarty)
{
    if (!isset($params['_from'])) {
        echo 'No model name!';
        return false;
    }
    if (!isset($params['_name'])) {
        echo 'No record variable name!';
        return false;
    }
    $smarty->_tpl_vars[$params['_name']] = createModel($params['_from'])->gets($model, $pager);
    if (isset($params['page'])) {
        $smarty->assign("pager", array('total' => $pager->total, 'render' => $pager->render()));
    }
}
Example #10
0
 function detail()
 {
     if (empty($_GET['id'])) {
         return "Access Deny";
     }
     $this->common();
     $aid = (int) $_GET['id'];
     //模板名称
     $tplname = strtolower($this->app) . '_detail.html';
     //获取详细内容
     $det = $this->_model->get($aid)->get();
     if (empty($det)) {
         $this->http->status(404);
         return "Page Not Found";
     }
     if (!empty($det['uptime']) and Swoole\Tool::httpExpire($det['uptime']) === false) {
         return "";
     }
     //阅读次数增加
     $this->_model->set($aid, array('click_num' => '`click_num`+1'));
     //关键词
     if (!empty($_GET['q'])) {
         $det['content'] = preg_replace("/({$_GET['q']})/i", "<font color=red>\\1</font>", $det['content']);
     }
     //获取小分类信息
     $cate = getCategory($det['cid']);
     $this->swoole->tpl->assign("cate", $cate);
     $ccate = getCategory($det['fid']);
     $this->swoole->tpl->assign("ccate", $ccate);
     $comments = createModel('UserComment')->getByAid($this->app, $det['id']);
     //是否使用特殊模板
     if ($ccate['tpl_detail']) {
         $tplname = $ccate['tpl_detail'];
     }
     if ($cate['tpl_detail']) {
         $tplname = $cate['tpl_detail'];
     }
     $this->swoole->tpl->assign('comments', $comments);
     $this->swoole->tpl->assign('det', $det);
     $this->swoole->tpl->display($tplname);
 }
Example #11
0
 function onEditPDB()
 {
     $req = $_REQUEST;
     //if($req['cmd'] == 'Cancel')
     if ($req['cmd'] == 'Go back') {
         pageGoto("editpdb_setup1.php");
         return;
     }
     // Otherwise, moving forward:
     $oldID = $req['modelID'];
     $oldModel = $_SESSION['models'][$oldID];
     $inpath = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $oldModel['pdb'];
     $newModel = createModel($oldID . "_edit");
     $newID = $newModel['id'];
     $outpath = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $newModel['pdb'];
     $s = "";
     if (is_array($req['removechain']) && count($req['removechain']) > 0) {
         removeChains($inpath, $outpath, $req['removechain']);
         $s .= "<p>You created {$newModel['pdb']} by removing chain(s) " . implode(', ', $req['removechain']) . " from {$oldModel['pdb']}.\n";
         mpLog("editpdb:Removed chains from a PDB file");
     } else {
         copy($inpath, $outpath);
     }
     $resolu = $req['resolution'] + 0;
     $oldRes = $oldModel['stats']['resolution'] + 0;
     if ($resolu && ($oldRes == 0 || $oldRes != $resolu)) {
         $remark2 = sprintf("REMARK   2                                                                      \nREMARK   2 RESOLUTION. %.2f ANGSTROMS.                                          \n", $resolu);
         replacePdbRemark($outpath, $remark2, 2);
         $s .= "<p>You manually set the resolution for {$newModel['pdb']}.\n";
         mpLog("editpdb:Changed/set resolution for a PDB file");
     }
     if ($req['removeHs']) {
         $newModel = createModel($oldID . "_trimmed");
         $newID = $newModel['id'];
         $outpath = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $newModel['pdb'];
         reduceTrim($inpath, $outpath);
         $s .= "<p>You created {$newModel['pdb']} by removing hydrogens from {$oldModel['pdb']}.\n";
         mpLog("editpdb:Removed hydrogens from a PDB file");
     }
     $newModel['stats'] = pdbstat($outpath);
     $newModel['history'] = "Edited {$oldModel['pdb']}";
     $newModel['isUserSupplied'] = $oldModel['isUserSupplied'];
     $_SESSION['models'][$newID] = $newModel;
     $_SESSION['lastUsedModelID'] = $newID;
     // this is now the current model
     $details = describePdbStats($newModel['stats'], true);
     $s .= "<ul>\n";
     foreach ($details as $detail) {
         $s .= "<li>{$detail}</li>\n";
     }
     $s .= "</ul>\n";
     $entrynum = addLabbookEntry("Created PDB file {$newModel['pdb']}", $s, "{$oldID}|{$newID}", "auto", "scissors.png");
     pageGoto("generic_done.php", array('labbookEntry' => $entrynum));
 }
Example #12
0
function cms_list(&$params, &$smarty)
{
    if (empty($params['cid'])) {
        exit('分类不能为空');
    }
    $cid = (int) $params['cid'];
    if (empty($params['name'])) {
        $params['name'] = 'list' . $cid;
    }
    $cate = getCategory($cid);
    $model = createModel($cate['app']);
    if ($cate['fid'] == 0) {
        $gets['fid'] = $cid;
    } else {
        $gets['cid'] = $cid;
    }
    if (empty($params['select'])) {
        $params['select'] = 'id,title,addtime';
    }
    if (empty($params['num'])) {
        $params['num'] = 10;
    }
    //查询的条数
    $gets['limit'] = (int) $params['num'];
    //查询的字段
    $gets['select'] = $params['select'];
    if (!empty($params['order'])) {
        $gets['order'] = $params['order'];
    }
    if (!empty($params['dig'])) {
        $gets['tagid'] = (int) $params['dig'];
    }
    if (!empty($params['titlelen'])) {
        $gets['select'] = str_replace('title', "substring( title, 1, {$gets['titlelen']} ) AS title,title as title_full", $gets['select']);
    }
    $smarty->_tpl_vars[$params['name']] = $model->gets($gets);
}
Example #13
0
function createView($name)
{
    $view = 'Hello World!';
    mkdir(VIEWS_DIR . $name);
    $handle = fopen(VIEWS_DIR . $name . DIRECTORY_SEPARATOR . 'v_index.php', 'w+');
    fwrite($handle, $view);
    fclose($handle);
}
if ($argc > 1) {
    //Define controller, model, and view directory
    define('CONTROLLERS_DIR', realpath(__DIR__ . '/app/controllers') . DIRECTORY_SEPARATOR);
    define('MODELS_DIR', realpath(__DIR__ . '/app/models') . DIRECTORY_SEPARATOR);
    define('VIEWS_DIR', realpath(__DIR__ . '/app/views') . DIRECTORY_SEPARATOR);
    //User command
    if ($argv[1] == 'controller') {
        createController($argv[2]);
        createView($argv[2]);
        fwrite(STDOUT, 'Controller c_' . $argv[2] . ' and View ' . $argv[2] . '/v_index.php created successfully');
    } else {
        if ($argv[1] == 'model') {
            createModel($argv[2], $argv[3], $argv[4]);
            fwrite(STDOUT, 'Model m_' . $argv[2] . ' created successfully');
        } else {
            fwrite(STDOUT, "Wrong command\n");
            fwrite(STDOUT, "Here the list of command:\n" . "1. controller <name>\n" . "2. model <table-name> <field-list> <primary-key>\n");
        }
    }
} else {
    //Write if user didn't specify arguments
    fwrite(STDOUT, "Please specify the arguments. You can use:\n" . "1. controller <name>\n" . "2. model <table-name> <field-list> <primary-key>\n");
}
Example #14
0
 function admin_attachment()
 {
     $this->_check_cms();
     import_func('file');
     import_func('js');
     $model = createModel('Attachment');
     $entity = createModel($this->app);
     if (empty($_GET['aid'])) {
         $res = $entity->getStatus();
         $id = $res['Auto_increment'];
     } else {
         $id = (int) $_GET['aid'];
     }
     if (isset($_GET['del'])) {
         $model->del((int) $_GET['del']);
     }
     if (isset($_FILES['media'])) {
         if (empty($_POST['title'])) {
             $_POST['title'] = $_FILES['media']['name'];
         }
         $_POST['url'] = file_upload('media');
         if (!empty($_POST['url'])) {
             $_POST['filetype'] = file_gettype($_FILES['media']['type']);
             $_POST['filesize'] = $_FILES['media']['size'];
             $_POST['user_id'] = $this->uid;
             $_POST['app'] = $this->app;
             $model->put($_POST);
         }
     }
     $list = $model->gets(array('aid' => $id, 'app' => $this->app));
     include "templates/admin_attachment.html";
 }
Example #15
0
if ($reduce_blength == 'ecloud') {
    $newModel['history'] = "Derived from {$model['pdb']} by Reduce -build";
} elseif ($reduce_blength == 'nuclear') {
    $newModel['history'] = "Derived from {$model['pdb']} by Reduce -build -nuclear";
}
$newModel['isUserSupplied'] = $model['isUserSupplied'];
$newModel['isReduced'] = true;
$newModel['isBuilt'] = true;
$_SESSION['models'][$newModel['id']] = $newModel;
$_SESSION['bgjob']['modelID'] = $newModel['id'];
$_SESSION['lastUsedModelID'] = $newModel['id'];
// this is now the current model
if ($did_flip && $_SESSION['bgjob']['nqh_regularize']) {
    setProgress($tasks, 'regularize');
    $flipInpath = $outpath;
    $minModel = createModel($modelID . "FH_reg");
    $outname2 = $minModel['pdb'];
    $outpath2 = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS;
    $outpath2 .= '/' . $outname2;
    $temp = $_SESSION['dataDir'] . '/tmp';
    if (file_exists($flipInpath)) {
        regularizeNQH($flipInpath, $outpath2, $temp);
    }
    unset($_SESSION['models'][$_SESSION['lastUsedModelID']]);
    if (!file_exists($outpath2)) {
        # We are deleting the reduced file because we'd rather not have users
        # play with the unregularized, nqh-flipped pdb.
        unlink($flipInpath);
        $_SESSION['lastUsedModelID'] = $prereduceid;
        unset($_SESSION['bgjob']['processID']);
        $_SESSION['bgjob']['endTime'] = time();
Example #16
0
 private function fulltext($q, $page)
 {
     $cl = new SphinxClient();
     $cl->SetServer('localhost', 9312);
     $cl->SetArrayResult(true);
     $cl->SetLimits(($page - 1) * $this->pagesize, $this->pagesize);
     $res = $cl->Query($q, "news");
     $model = createModel('News');
     foreach ($res['matches'] as $m) {
         $ids[] = $m['id'];
     }
     if (empty($ids)) {
         $res['list'] = array();
     } else {
         $gets['in'] = array('id', implode(',', $ids));
         $gets['limit'] = $this->pagesize;
         $gets['order'] = '';
         $gets['select'] = "id,title,addtime";
         $list = $model->gets($gets);
         $res['list'] = $list;
     }
     return $res;
 }
Example #17
0
 function onConvertToBiolUnit()
 {
     if ($_SESSION['lastUsedModelID']) {
         $oldID = $_SESSION['lastUsedModelID'];
         $model = $_SESSION['ensembles'][$oldID];
         if (!$model) {
             return;
         }
         $modelDir = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS;
         $infile = "{$modelDir}/{$model['pdb']}";
         $tmpfile = convertModelsToChains($infile);
         $newModel = createModel("{$oldID}-biolunit");
         $newID = $newModel['id'];
         $newModel['stats'] = pdbstat($tmpfile);
         $newModel['history'] = 'Converted from ensemble to biological unit';
         $newModel['isUserSupplied'] = $model['isUserSupplied'];
         if (!file_exists($modelDir)) {
             mkdir($modelDir, 0777);
         }
         copy($tmpfile, "{$modelDir}/{$newModel['pdb']}");
         unlink($tmpfile);
         $_SESSION['models'][$newID] = $newModel;
         $_SESSION['lastUsedModelID'] = $newID;
     }
 }
Example #18
0
/**
* Calling this function creates N new models with hydrogens and then
* reassembles them into one new ensemble with H.
*
* Returns the ID of the newly minted ensemble.
*
* $ensID        the ensemble ID for the ensemble to reduce
* $reduceFunc   the function to run on ensemble members: one of
*   'reduceBuild', 'reduceNoBuild', or 'reduceTrim'
*/
function reduceEnsemble($ensID, $reduceFunc = 'reduceNoBuild')
{
    $ens = $_SESSION['ensembles'][$ensID];
    $idList = array();
    $pdbList = array();
    $reduce_blength = $_SESSION['reduce_blength'];
    foreach ($ens['models'] as $modelNum => $modelID) {
        $oldModel = $_SESSION['models'][$modelID];
        $newModel = createModel($modelID . "H");
        $outname = $newModel['pdb'];
        $outpath = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS;
        if (!file_exists($outpath)) {
            mkdir($outpath, 0777);
        }
        // shouldn't ever happen, but might...
        $outpath .= '/' . $outname;
        $inpath = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $oldModel['pdb'];
        // FUNKY: calls the function whose name is stored in the variable $reduceFunc
        $reduceFunc($inpath, $outpath, $reduce_blength);
        $newModel['stats'] = pdbstat($outpath);
        $newModel['parent'] = $modelID;
        $newModel['history'] = "Derived from {$oldModel['pdb']} by {$reduceFunc}";
        $newModel['isUserSupplied'] = $oldModel['isUserSupplied'];
        $newModel['isReduced'] = $reduceFunc != 'reduceTrim';
        $newModel['isBuilt'] = $reduceFunc == 'reduceBuild';
        $_SESSION['models'][$newModel['id']] = $newModel;
        $idList[$modelNum] = $newModel['id'];
        $pdbList[$modelNum] = $outpath;
    }
    $ensemble = createEnsemble($ensID . "H");
    $ensemble['models'] = $idList;
    $ensemble['history'] = "Ensemble of " . count($idList) . " models derived from {$ens['pdb']} by {$reduceFunc}";
    //$newModel['isReduced']  = ($reduceFunc != 'reduceTrim');
    //$newModel['isBuilt']    = ($reduceFunc == 'reduceBuild');
    $ensemble['isReduced'] = $reduceFunc != 'reduceTrim';
    $ensemble['isBuilt'] = $reduceFunc == 'reduceBuild';
    $ensemble['isUserSupplied'] = $ens['isUserSupplied'];
    $joinedModel = joinPdbModels($pdbList);
    copy($joinedModel, $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $ensemble['pdb']);
    unlink($joinedModel);
    // Create the ensemble entry
    $id = $ensemble['id'];
    $_SESSION['ensembles'][$id] = $ensemble;
    return $id;
}
Example #19
0
 static function getUser($uid)
 {
     $_user = createModel('UserInfo');
     return $_user->getInfo($uid);
 }
Example #20
0
/**
 * 创建模型的别名函数
 * @param $model_name
 * @return unknown_type
 */
function M($model_name)
{
    return createModel($model_name);
}
Example #21
0
// don't want to bail after 30 sec!
// 6. Record this PHP script's PID in case it needs to be killed.
$_SESSION['bgjob']['processID'] = posix_getpid();
mpSaveSession();
#{{{ a_function_definition - sumary_statement_goes_here
############################################################################
/**
* Documentation for this function.
*/
//function someFunctionName() {}
#}}}########################################################################
# MAIN - the beginning of execution for this page
############################################################################
$oldID = $_SESSION['bgjob']['modelID'];
$oldModel = $_SESSION['models'][$oldID];
$newModel = createModel($oldID . "S");
$newModel['stats'] = $oldModel['stats'];
$newModel['parent'] = $oldID;
$newModel['history'] = "Derived from {$oldModel['pdb']} by SSwing";
$newModel['isUserSupplied'] = $oldModel['isUserSupplied'];
$newModel['isReduced'] = $oldModel['isReduced'];
$newModel['isBuilt'] = $oldModel['isBuilt'];
$_SESSION['models'][$newModel['id']] = $newModel;
$pdbin = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $oldModel['pdb'];
$pdbout = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $newModel['pdb'];
$map = $_SESSION['dataDir'] . '/' . MP_DIR_EDMAPS . '/' . $_SESSION['bgjob']['edmap'];
$cnit = $_SESSION['bgjob']['cnit'];
// Set up progress message
foreach ($cnit as $res) {
    $tasks[$res] = "Process {$res} with SSWING";
}
Example #22
0
 function reply()
 {
     $this->session->start();
     if (!$_SESSION['isLogin']) {
         return Swoole\JS::echojs("if(confirm('您还没有登录,是否调整到登录页面(请首先复制您的回答内容)?')) window.parent.location.href='/page/login/?'");
     }
     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();
         App\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;');
     }
 }
Example #23
0
############################################################################
$modelID = $_SESSION['bgjob']['modelID'];
$model = $_SESSION['models'][$modelID];
$pdb = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $model['pdb'];
$reduce_blength = $_SESSION['bgjob']['reduce_blength'];
$_SESSION['reduce_blength'] = $reduce_blength;
// Set up progress message
if ($reduce_blength == 'ecloud') {
    $tasks['reduce'] = "Add H with <code>reduce -nobuild9999</code>";
} elseif ($reduce_blength == 'nuclear') {
    $tasks['reduce'] = "Add H with <code>reduce -nobuild9999 -nuclear</code>";
}
$tasks['notebook'] = "Add entry to lab notebook";
setProgress($tasks, 'reduce');
// updates the progress display if running as a background job
$newModel = createModel($modelID . "H");
$outname = $newModel['pdb'];
$outpath = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS;
if (!file_exists($outpath)) {
    mkdir($outpath, 0777);
}
// shouldn't ever happen, but might...
$outpath .= '/' . $outname;
reduceNoBuild($pdb, $outpath, $reduce_blength);
$newModel['stats'] = pdbstat($outpath);
$newModel['parent'] = $modelID;
if ($reduce_blength == 'ecloud') {
    $newModel['history'] = "Derived from {$model['pdb']} by Reduce -nobuild9999";
}
if ($reduce_blength == 'nuclear') {
    $newModel['history'] = "Derived from {$model['pdb']} by Reduce -nobuild9999 -nuclear";
 function handle_attachment($config)
 {
     if (!isset($config['entity']) or !isset($config['attach']) or !isset($config['entity_id'])) {
         die('参数错误!');
     }
     $_mm = createModel($config['entity']);
     $_ma = createModel($config['attach']);
     $this->swoole->tpl->assign('config', $config);
     if ($_POST) {
         $_ma->put($_POST);
     }
     if (isset($_GET['del'])) {
         $dels['id'] = (int) $_GET['del'];
         $dels['aid'] = $config['entity_id'];
         $dels['limit'] = 1;
         $_ma->dels($dels);
     }
     $get['aid'] = $config['entity_id'];
     $get['pagesize'] = 16;
     $get['page'] = empty($get['page']) ? 1 : (int) $get['page'];
     $list = $_ma->gets($get, $pager);
     $this->swoole->tpl->assign('list', $list);
     $this->swoole->tpl->assign('pager', array('total' => $pager->total, 'render' => $pager->render()));
     if (empty($config['tpl.list'])) {
         $config['tpl.list'] = LIBPATH . '/data/tpl/admin_attachment.html';
     }
     $this->swoole->tpl->display($config['tpl.list']);
 }
         } else {
             $pred_model['valid'] = false;
         }
         $pred_model['uuid'] = $uuid;
         $stats->counting('habhub.predictor.php.got_by_uuid');
     }
     echo json_encode($pred_model);
     break;
 case "submitForm":
     $pred_model = array();
     $json_return = array();
     $json_return['valid'] = "false";
     // Make sure we have a submitted form
     if (isset($_POST['submit'])) {
         // First, make a model from the form data
         if (!($pred_model = createModel($_POST))) {
             $json_return['error'] = "Server couldn't make a model from the form \n                data";
             echo json_encode($json_return);
             $stats->counting('habhub.predictor.php.form_error');
             break;
         }
         // If that worked, make sure the model is valid
         $verify_dump = verifyModel($pred_model, $software_available);
         if (!$verify_dump['valid']) {
             $json_return['error'] = $verify_dump['msg'];
             echo json_encode($json_return);
             $stats->counting('habhub.predictor.php.invalid_model');
             break;
         }
         // If we have a valid model, try and make a UUID
         if (!($pred_model['uuid'] = makesha1hash($pred_model))) {
Example #26
0
 function getActiveUsers($num = 10)
 {
     $_uids = array();
     $_mblog = createModel('MicroBlog');
     $_user = createModel('UserInfo');
     $table = $_mblog->table;
     $uids = $this->swoole->db->query("select uid from {$table} order by id desc limit 500")->fetchall();
     foreach ($uids as $u) {
         $_uids[$u['uid']] = 1;
     }
     $gets['select'] = 'id,nickname,avatar';
     $gets['in'] = array('id', implode(',', array_keys($_uids)));
     $_users = $_user->getMap($gets);
     $new = array();
     foreach ($_uids as $uid => $u) {
         $new[] = $_users[$uid];
     }
     return $new;
 }
Example #27
0
 function ask_vote()
 {
     global $php;
     Swoole::$php->session->start();
     if (!$_SESSION['isLogin']) {
         return 'nologin';
     }
     $reid = (int) $_POST['reid'];
     $reply = createModel('AskReply')->get($reid);
     $reply->vote += 1;
     $reply->save();
     $put['uid'] = $_SESSION['user_id'];
     $put['aid'] = $reply['aid'];
     $put['reply_id'] = $reid;
     $php->db->insert($put, 'ask_vote');
     return 'ok';
 }
Example #28
0
function main()
{
    $arguments = getopt("f:wvche:t:", array("vv", "rpc::", "service", "model", "mapper"));
    $file = isset($arguments['f']) ? $arguments['f'] : false;
    if (!$file) {
        echo "ERROR Option file -f \n";
        return;
    }
    $help = isset($arguments['h']) ? true : false;
    $Sservice = isset($arguments['service']) ? true : false;
    $Smodel = isset($arguments['model']) ? true : false;
    $Smapper = isset($arguments['mapper']) ? true : false;
    $Sall = $Sservice + $Smodel + $Smapper;
    $Sall = $Sall == 3 || $Sall == 0 ? true : false;
    $write = isset($arguments['w']) ? true : false;
    $clean = isset($arguments['c']) ? true : false;
    $exclus = isset($arguments['e']) ? $arguments['e'] : array();
    $Otable = isset($arguments['t']) ? $arguments['t'] : array();
    if (!is_array($exclus) || is_array($exclus) && count($exclus) == 1) {
        $exclus = array($exclus);
    }
    if (!is_array($Otable) || is_array($Otable) && count($Otable) == 1) {
        $Otable = array($Otable);
    }
    $verbose = isset($arguments['v']) ? true : false;
    $vverbose = isset($arguments['vv']) ? true : false;
    $rpc = isset($arguments['rpc']) ? is_bool($arguments['rpc']) ? true : $arguments['rpc'] : false;
    if ($help) {
        echo "-w                  : write\n";
        echo "-e [NameTable]      : exclus table\n";
        echo "-t [NameTable]      : filtre la table\n";
        echo "--service           : génerer service\n";
        echo "--mapper            : génerer mapper\n";
        echo "--model             : génerer model\n";
        echo "-v                  : verbose\n";
        echo "--vv                : verbose++\n";
        echo "-f                  : file *.mwb (file mysql workbench)\n";
        echo "--rpc[=NameTable]   : ATTENTION! si NameTable n'est pas present tous les JsonRpc des tables seront créés, sinon seule la table JSON-RPC NameTable sera créé \n";
        return 0;
    }
    $pathDal = "../module/Application/src/Application/";
    $pathJsonRpcServer = "../module/JsonRpcServer/src/JsonRpcServer/";
    $pathConf = "../module/Dal/Module.php";
    $pathConfRpc = "../module/JsonRpcServer/config/module.config.php";
    $result = parseMwb($file, $vverbose);
    $handle = opendir($pathDal . '/Model');
    $TableExistante = array();
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != ".." && strpos($entry, 'Abstract') !== 0 && strpos($entry, '.php') !== false && $entry != "ModelInterface.php") {
            $TableExistante[] = substr(toNoCamelCase(substr($entry, 0, -4)), 1);
        }
    }
    foreach ($result as $nameTable => $body) {
        if (!empty($Otable) && in_array($nameTable, $Otable) || empty($Otable)) {
            $columCamel = array();
            foreach ($body['column'] as $colum => $opt) {
                $columCamel[$opt['name']] = toCamelCase($opt['name']);
            }
            if (in_array($nameTable, $TableExistante)) {
                $val = array_search($nameTable, $TableExistante);
                if ($val !== false) {
                    unset($TableExistante[$val]);
                }
            }
            if (!in_array($nameTable, $exclus) && $nameTable != "" && $body['type'] == "table") {
                if ($Sall || $Smodel) {
                    createModel($nameTable, $columCamel, $pathDal, $write, $verbose);
                }
                if ($Sall || $Smapper) {
                    createMapper($nameTable, $pathDal, $write, $verbose);
                }
                if ($Sall || $Sservice) {
                    createService($nameTable, $pathDal, $write, $verbose);
                }
            }
            if ($rpc && !is_string($rpc) || $rpc === $nameTable) {
                createServiceRpc($nameTable, $pathJsonRpcServer, $pathConfRpc, $write, $verbose);
            }
        }
    }
    foreach ($TableExistante as $nameTable) {
        if ($Otable && $Otable == $nameTable || !$Otable) {
            removeModel($nameTable, $pathDal, $write, $verbose);
        }
    }
}
Example #29
0
$memberConfig = createModel(1, 'test2', 1);
$t->is($memberConfig->getValue(), 1);
$memberConfig = createModel(1, 'test3', '1989-01-08');
$t->is($memberConfig->getValue(), '1989-01-08');
//------------------------------------------------------------
$t->diag('MemberConfig::getFormType()');
$t->is($pcAddressConfig->getFormType(), 'input');
$t->is($passwordConfig->getFormType(), 'password');
$memberConfig = createModel(1, 'test4', 1);
$t->is($pcAddressConfig->getFormType(), 'input');
//------------------------------------------------------------
$t->diag('MemberConfig::saveToken()');
$memberConfig = createModel(1, 'test5', 1);
$memberConfig->savePre();
$result1 = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId('test5_pre', 1, true);
$result1->saveToken();
$result2 = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId('test5_token', 1, true);
$t->isa_ok($result2, 'MemberConfig');
$memberConfig = createModel(1, 'test6', 1);
$memberConfig->saveToken();
$result3 = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId('test6_token', 1, true);
$t->isa_ok($result3, 'MemberConfig');
//------------------------------------------------------------
$t->diag('MemberConfig::generateRoleId()');
$t->is($pcAddressConfig->generateRoleId($member1), 'self');
$t->is($pcAddressConfig->generateRoleId($member2), 'everyone');
//------------------------------------------------------------
$t->diag('MemberConfig::getNameValueHash()');
$memberConfig = createModel(1, 'test7', 'test7');
$memberConfig->save();
$t->is($memberConfig->getNameValueHash(), '767f31fc467e7879989b52aa54d8f60d', 'The "member_config.name_value_hash" is calculated by the given "test7,test7" string');