public function doSwitch() { global $_W, $_GPC; $m = array_merge($_W['modules']['userapi'], $_W['account']['modules'][$_W['modules']['userapi']['mid']]); $cfg = $m['config']; if ($_W['ispost']) { $rids = explode(',', $_GPC['rids']); if (is_array($rids)) { $cfg = array(); foreach ($rids as $rid) { $cfg[intval($rid)] = true; } $this->saveSettings($cfg); } exit; } require model('rule'); $rs = rule_search("weid = 0 AND module = 'userapi' AND `status`=1"); $ds = array(); foreach ($rs as $row) { $reply = pdo_fetch('SELECT * FROM ' . tablename($this->tablename) . ' WHERE `rid`=:rid', array(':rid' => $row['id'])); $r = array(); $r['title'] = $row['name']; $r['rid'] = $row['id']; $r['description'] = $reply['description']; $r['switch'] = $cfg[$r['rid']] ? ' checked="checked"' : ''; $ds[] = $r; } include $this->template('switch'); }
public function doManage() { global $_GPC, $_W; include model('rule'); $pindex = max(1, intval($_GPC['page'])); $psize = 20; $sql = "weid = :weid AND `module` = :module"; $params = array(); $params[':weid'] = $_W['weid']; $params[':module'] = 'bigwheel'; if (isset($_GPC['keywords'])) { $sql .= ' AND `name` LIKE :keywords'; $params[':keywords'] = "%{$_GPC['keywords']}%"; } $list = rule_search($sql, $params, $pindex, $psize, $total); $pager = pagination($total, $pindex, $psize); if (!empty($list)) { foreach ($list as &$item) { $condition = "`rid`={$item['id']}"; $item['keywords'] = rule_keywords_search($condition); $bigwheel = pdo_fetch("SELECT fansnum, viewnum,starttime,endtime,isshow FROM " . tablename('bigwheel_reply') . " WHERE rid = :rid ", array(':rid' => $item['id'])); $item['fansnum'] = $bigwheel['fansnum']; $item['viewnum'] = $bigwheel['viewnum']; $item['starttime'] = date('Y-m-d H:i', $bigwheel['starttime']); $endtime = $bigwheel['endtime'] + 86399; $item['endtime'] = date('Y-m-d H:i', $endtime); $nowtime = time(); if ($bigwheel['starttime'] > $nowtime) { $item['status'] = '<span class="label label-red">未开始</span>'; $item['show'] = 1; } elseif ($endtime < $nowtime) { $item['status'] = '<span class="label label-blue">已结束</span>'; $item['show'] = 0; } else { if ($bigwheel['isshow'] == 1) { $item['status'] = '<span class="label label-green">已开始</span>'; $item['show'] = 2; } else { $item['status'] = '<span class="label ">已暂停</span>'; $item['show'] = 1; } } $item['isshow'] = $bigwheel['isshow']; } } include $this->template('manage'); }
public function doWebPlaylist() { //这个操作被定义用来呈现 管理中心导航菜单 global $_GPC, $_W; include model('rule'); $pindex = max(1, intval($_GPC['page'])); $psize = 20; $module = 'fighting'; $list = rule_search("weid = '{$_W['weid']}' AND module = '{$module}'", $params, $pindex, $psize, $total); $pager = pagination($total, $pindex, $psize); if (!empty($list)) { foreach ($list as &$item) { $condition = "`rid`={$item['id']}"; $item['keywords'] = rule_keywords_search($condition); $fighting = pdo_fetch("SELECT title,qutype,fansnum, viewnum,starttime,endtime,isshow FROM " . tablename('fighting_reply') . " WHERE rid = :rid ", array(':rid' => $item['id'])); $item['title'] = $fighting['title']; $item['qutype'] = $fighting['qutype']; $item['fansnum'] = $fighting['fansnum']; $item['viewnum'] = $fighting['viewnum']; $item['starttime'] = date('Y/m/d H:i', $fighting['starttime']); $item['endtime'] = date('Y/m/d H:i', $fighting['endtime']); $nowtime = time(); if ($fighting['starttime'] > $nowtime) { $item['status'] = '<span class="label label-red">未开始</span>'; $item['show'] = 1; } elseif ($fighting['endtime'] < $nowtime) { $item['status'] = '<span class="label label-blue">已结束</span>'; $item['show'] = 0; } else { if ($fighting['isshow'] == 1) { $item['status'] = '<span class="label label-satgreen">已开始</span>'; $item['show'] = 2; } else { $item['status'] = '<span class="label ">已暂停</span>'; $item['show'] = 1; } } } } include $this->template('plays'); }
} include model('rule'); if(!empty($_GPC['rule'])) { $rid = intval($_GPC['rule']); $rule = rule_single($rid); if(!isset($_GPC['page']) && !isset($_GPC['keyword'])) { $isSingle = true; } } $pindex = max(1, intval($_GPC['page'])); $psize = 10; $total = 0; $list = rule_search("weid = '{$_W['weid']}' " . (!empty($_GPC['keyword']) ? " AND `name` LIKE '%{$_GPC['keyword']}%'" : ''), $pindex, $psize, $total); if (!empty($list)) { foreach($list as &$item) { $condition = "`rid`={$item['id']}"; $item['keywords'] = rule_keywords_search($condition); } } $pager = pagination($total, $pindex, $psize, create_url('menu/search'), array('ajaxcallback'=>'ajaxpager')); $wechat = $_W['account']; $temp = iunserializer($wechat['default']); if (is_array($temp)) { $wechat['default'] = $temp; $wechat['defaultrid'] = $temp['id']; } $temp = iunserializer($wechat['welcome']);
if ($do == 'display') { require model('rule'); $pindex = max(1, intval($_GPC['page'])); $psize = 20; $types = array('', '等价', '包含', '正则表达式匹配'); $condition = 'weid = 0 AND module = \'userapi\''; $params = array(); if (isset($_GPC['status'])) { $condition .= " AND status = :status"; $params[':status'] = intval($_GPC['status']); } if (isset($_GPC['keyword'])) { $condition .= ' AND `name` LIKE :keyword'; $params[':keyword'] = "%{$_GPC['keyword']}%"; } $ds = rule_search($condition, $params, $pindex, $psize, $total); $pager = pagination($total, $pindex, $psize); if (!empty($ds)) { foreach ($ds as &$item) { $reply = pdo_fetch('SELECT * FROM ' . tablename('userapi_reply') . ' WHERE `rid`=:rid', array(':rid' => $item['id'])); $item['description'] = $reply['description']; } } $import = false; $apis = implode('\',\'', array_keys($predefines)); $apis = "'{$apis}'"; $sql = 'SELECT DISTINCT `apiurl` FROM ' . tablename('userapi_reply') . ' AS `e` LEFT JOIN ' . tablename('rule') . " AS `r` ON (`e`.`rid`=`r`.`id`) WHERE `r`.`weid`='0' AND `apiurl` IN ({$apis})"; $apiurls = pdo_fetchall($sql); if (count($apiurls) != count($predefines)) { $import = true; }
public function doWebManage() { global $_W, $_GPC; $foo = !empty($_GPC['foo']) ? $_GPC['foo'] : 'display'; if ($foo == 'display') { require model('rule'); $pindex = max(1, intval($_GPC['page'])); $psize = 20; $types = array('', '等价', '包含', '正则表达式匹配'); $condition = 'weid = 0 AND module = \'userapi\''; $params = array(); if (isset($_GPC['status'])) { $condition .= " AND status = :status"; $params[':status'] = intval($_GPC['status']); } if (isset($_GPC['keyword'])) { $condition .= ' AND `name` LIKE :keyword'; $params[':keyword'] = "%{$_GPC['keyword']}%"; } $ds = rule_search($condition, $params, $pindex, $psize, $total); $pager = pagination($total, $pindex, $psize); if (!empty($ds)) { foreach ($ds as &$item) { $reply = pdo_fetch('SELECT * FROM ' . tablename($this->tablename) . ' WHERE `rid`=:rid', array(':rid' => $item['id'])); $item['description'] = $reply['description']; } } $import = false; $apis = implode('\',\'', array_keys($this->predefines)); $apis = "'{$apis}'"; $sql = 'SELECT DISTINCT `apiurl` FROM ' . tablename($this->tablename) . ' AS `e` LEFT JOIN ' . tablename('rule') . " AS `r` ON (`e`.`rid`=`r`.`id`) WHERE `r`.`weid`='0' AND `apiurl` IN ({$apis})"; $apiurls = pdo_fetchall($sql); if (count($apiurls) != count($this->predefines)) { $import = true; } include $this->template('display'); } if ($foo == 'import') { $apis = implode('\',\'', array_keys($this->predefines)); $apis = "'{$apis}'"; $sql = 'SELECT DISTINCT `apiurl` FROM ' . tablename($this->tablename) . ' AS `e` LEFT JOIN ' . tablename('rule') . " AS `r` ON (`e`.`rid`=`r`.`id`) WHERE `r`.`weid`='0' AND `apiurl` IN ({$apis})"; $apiurls = pdo_fetchall($sql); $as = array(); foreach ($apiurls as $url) { $as[] = $url['apiurl']; } foreach ($this->predefines as $key => $v) { if (!in_array($key, $as)) { $rule = array('weid' => 0, 'cid' => 0, 'name' => $v['title'], 'module' => 'userapi', 'displayorder' => 255, 'status' => 1); pdo_insert('rule', $rule); $rid = pdo_insertid(); if (!empty($rid)) { foreach ($v['keywords'] as $row) { $data = array('content' => $row[1], 'type' => $row[0], 'rid' => $rid, 'weid' => 0, 'module' => 'userapi', 'status' => $rule['status'], 'displayorder' => $rule['displayorder']); pdo_insert('rule_keyword', $data); } $reply = array('rid' => $rid, 'description' => $v['description'], 'apiurl' => $key, 'token' => '', 'default_text' => '', 'cachetime' => 0); pdo_insert($this->tablename, $reply); } } } message('成功导入.', referer()); } if ($foo == 'delete') { $rid = intval($_GPC['rid']); $sql = 'DELETE FROM ' . tablename('rule') . " WHERE `weid`=0 AND `module`='userapi' AND `id`={$rid}"; pdo_query($sql); $sql = 'DELETE FROM ' . tablename('rule_keyword') . " WHERE `weid`=0 AND `module`='userapi' AND `rid`={$rid}"; pdo_query($sql); $sql = 'DELETE FROM ' . tablename($this->tablename) . " WHERE `rid`={$rid}"; pdo_query($sql); message('成功删除.', referer()); } if ($foo == 'post') { $rid = intval($_GPC['id']); require model('rule'); if (checksubmit()) { if (empty($_GPC['name'])) { message('抱歉,规则名称为必填项,请选回修改!'); } if ($_GPC['type'] && empty($_GPC['apiurl']) || empty($_GPC['type']) && empty($_GPC['apilocal'])) { message('请填写接口地址!'); } if ($_GPC['type'] && empty($_GPC['token'])) { message('请填写Token值!'); } $rule = array('weid' => 0, 'cid' => 0, 'name' => $_GPC['service'], 'module' => 'userapi', 'displayorder' => 255, 'status' => intval($_GPC['status'])); if ($rid) { pdo_update('rule', $rule, array('id' => $rid)); } else { pdo_insert('rule', $rule); $rid = pdo_insertid(); } if (empty($rid)) { message('增加服务失败, 请稍后重试. '); } $sql = 'DELETE FROM ' . tablename('rule_keyword') . ' WHERE `rid`=:rid AND `weid`=0'; $pars = array(); $pars[':rid'] = $rid; pdo_query($sql, $pars); $rows = array(); $rowtpl = array('rid' => $rid, 'weid' => 0, 'module' => $rule['module'], 'status' => $rule['status'], 'displayorder' => $rule['displayorder']); if (!empty($_GPC['keyword-name'])) { foreach ($_GPC['keyword-name'] as $id => $row) { if (empty($row) && strlen($row) == 0 && intval($_GPC['keyword-type'][$id]) != 4) { continue; } $rowtpl['content'] = $row; $rowtpl['type'] = intval($_GPC['keyword-type'][$id]); if ($rowtpl['type'] == 4) { $rowtpl['content'] = ''; } $rows[md5($rowtpl['type'] . $rowtpl['content'])] = $rowtpl; } } if (!empty($_GPC['keyword-name-new'])) { foreach ($_GPC['keyword-name-new'] as $id => $row) { if (empty($row) && strlen($row) == 0 && intval($_GPC['keyword-type-new'][$id]) != 4) { continue; } $rowtpl['content'] = $row; $rowtpl['type'] = intval($_GPC['keyword-type-new'][$id]); if ($rowtpl['type'] == 4) { $rowtpl['content'] = ''; } $rows[md5($rowtpl['type'] . $rowtpl['content'])] = $rowtpl; } } if (!empty($_GPC['keywords'])) { $kwds = explode(',', trim($_GPC['keywords'])); foreach ($kwds as $kwd) { $kwd = trim($kwd); if (empty($kwd)) { continue; } $rowtpl['content'] = $kwd; $rowtpl['type'] = 1; $rows[md5($rowtpl['type'] . $rowtpl['content'])] = $rowtpl; } } foreach ($rows as $krow) { $result = pdo_insert('rule_keyword', $krow); } $reply = array('rid' => $rid, 'description' => htmlspecialchars_decode($_GPC['description']), 'apiurl' => empty($_GPC['type']) ? $_GPC['apilocal'] : $_GPC['apiurl'], 'token' => $_GPC['wetoken'], 'default_text' => $_GPC['default-text'], 'cachetime' => intval($_GPC['cachetime'])); if ($_GPC['id']) { if (pdo_update($this->tablename, $reply, array('rid' => $rid)) !== false) { message('编辑服务成功. ', 'refresh'); } else { message('编辑服务失败, 请稍后重试. '); } } else { if (pdo_insert($this->tablename, $reply)) { message('增加服务成功. ', 'refresh'); } else { message('增加服务失败, 请稍后重试. '); } } } $rid = intval($_GPC['id']); if (!empty($rid)) { $rule = rule_single($rid); $rule['kwd-adv'] = false; $rule['keywords'] = array(); foreach ($rule['keyword'] as $kwd) { if ($kwd['type'] != '1') { $rule['kwd-adv'] = true; } else { $rule['keywords'][] = $kwd['content']; } } $rule['keywords'] = implode(',', $rule['keywords']); $row = pdo_fetch("SELECT * FROM " . tablename($this->tablename) . " WHERE rid = :rid ORDER BY `id` DESC", array(':rid' => $rid)); if (!strexists($row['apiurl'], 'http://') && !strexists($row['apiurl'], 'https://')) { $row['apilocal'] = $row['apiurl']; $row['apiurl'] = ''; } } else { $row = array('cachetime' => 0); } $types = array(2 => array('name' => '包含关键字', 'description' => '用户进行交谈时,对话中包含上述关键字就执行这条规则。'), 3 => array('name' => '正则表达式匹配', 'description' => "用户进行交谈时,对话内容符合述关键字中定义的模式才会执行这条规则。<br/><strong>注意:如果你不明白正则表达式的工作方式,请不要使用正则匹配</strong> <br/><strong>注意:正则匹配使用MySQL的匹配引擎,请使用MySQL的正则语法</strong> <br /><br /><strong>示例: </strong><br/><b>^微赞</b>匹配以“微赞”开头的语句<br /><b>微赞\$</b>匹配以“微赞”结尾的语句<br /><b>^微赞\$</b>匹配等同“微赞”的语句<br /><b>微赞</b>匹配包含“微赞”的语句<br /><b>[0-9\\.\\-]</b>匹配所有的数字,句号和减号<br /><b>^[a-zA-Z_]\$</b>所有的字母和下划线<br /><b>^[[:alpha:]]{3}\$</b>所有的3个字母的单词<br /><b>^a{4}\$</b>aaaa<br /><b>^a{2,4}\$</b>aa,aaa或aaaa<br /><b>^a{2,}\$</b>匹配多于两个a的字符串"), 4 => array('name' => '直接接管', 'description' => "如果没有比这条回复优先级更高的回复被触发,那么直接使用这条回复。<br/><strong>注意:如果你不明白这个机制的工作方式,请不要使用直接接管</strong>")); $path = IA_ROOT . '/source/modules/userapi/api'; if (is_dir($path)) { $apis = array(); if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $apis[] = $file; } } } } include $this->template('post'); } }
public function doWebList() { //这个操作被定义用来呈现 管理中心导航菜单 global $_GPC, $_W; include model('rule'); $pindex = max(1, intval($_GPC['page'])); $psize = 20; $sql = "weid = :weid AND `module` = :module"; $params = array(); $params[':weid'] = $_W['weid']; $params[':module'] = 'photowall'; if (isset($_GPC['keywords'])) { $sql .= ' AND `name` LIKE :keywords'; $params[':keywords'] = "%{$_GPC['keywords']}%"; } $list = rule_search($sql, $params, $pindex, $psize, $total); $pager = pagination($total, $pindex, $psize); if (!empty($list)) { foreach ($list as &$item) { $condition = "`rid`={$item['id']}"; $item['keywords'] = rule_keywords_search($condition); $photowall = pdo_fetch("SELECT sendtimes,daysendtimes,starttime,endtime,isshow,isdes,status FROM " . tablename('photowall_reply') . " WHERE rid = :rid ", array(':rid' => $item['id'])); $item['starttime'] = date('Y-m-d H:i', $photowall['starttime']); $endtime = $photowall['endtime'] + 86399; $item['endtime'] = date('Y-m-d H:i', $endtime); $nowtime = time(); if ($photowall['starttime'] > $nowtime || $photowall['status'] == '0') { $item['statuss'] = '<span class="label label-red">未开始</span>'; $item['show'] = 1; } elseif ($endtime < $nowtime || $photowall['status'] == '3') { $item['statuss'] = '<span class="label label-blue">已结束</span>'; $item['show'] = 0; } elseif ($photowall['status'] == '2') { $item['statuss'] = '<span class="label ">已暂停</span>'; } elseif ($photowall['status'] == '1') { $item['statuss'] = '<span class="label label-green">已开始</span>'; } else { $item['statuss'] = '<span class="label label-green">状态未知</span>'; } $item['sendtimes'] = $photowall['sendtimes']; $item['daysendtimes'] = $photowall['daysendtimes']; $item['isshow'] = $photowall['isshow']; $item['isdes'] = $photowall['isdes']; $item['status'] = $photowall['status']; } } include $this->template('manage'); }
} if (!empty($_GPC['cate_2'])) { $cid = intval($_GPC['cate_2']); $condition = " AND cid = '{$cid}'"; } elseif (!empty($_GPC['cate_1'])) { $cid = intval($_GPC['cate_1']); $cids = array(); if (!empty($children[$cid])) { $cids = array_keys($children[$cid]); } $cids[] = $cid; $condition = " AND cid IN (".implode(',', $cids).")"; } $modules = cache_load('modules'); $list = rule_search("weid = '{$_W['weid']}' $condition ". ($module == 'all' ? '' : " AND module = '$module'") . (!empty($_GPC['keyword']) ? " AND name LIKE '%{$_GPC['keyword']}%'" : ''), $pindex, $psize, $total); $pager = pagination($total, $pindex, $psize); if (!empty($list)) { foreach($list as &$item) { $condition = "`rid`={$item['id']}"; $item['keywords'] = rule_keywords_search($condition); $cate = $category[$item['cid']]; if (!empty($cate['parentid'])) { $item['cate'][0] = $category[$cate['parentid']]; $item['cate'][1] = $cate; } else { $item['cate'][0] = $cate; } $item['menus'] = ''; if (!empty($modules[$item['module']]['menus'])) {
exit; } if (isset($_GET["tabs"])) { tabs(); exit; } if (isset($_GET["items"])) { items(); exit; } if (isset($_GET["tab-gpid"])) { rule_page(); exit; } if (isset($_GET["table-gpid-search"])) { rule_search(); exit; } if (isset($_GET["ruleid"])) { ruleid_popup(); exit; } if (isset($_POST["SaveRule"])) { ruleid_save(); exit; } if (isset($_POST["enable_id"])) { ruleid_enable(); exit; } if (isset($_POST["delete-id"])) {
public function doManage() { global $_GPC, $_W; include model('rule'); $pindex = max(1, intval($_GPC['page'])); $psize = 20; $sql = "weid = :weid AND `module` = :module"; $params = array(); $params[':weid'] = $_W['weid']; $params[':module'] = 'vote'; if (isset($_GPC['keywords'])) { $sql .= ' AND `name` LIKE :keywords'; $params[':keywords'] = "%{$_GPC['keywords']}%"; } $list = rule_search($sql, $params, $pindex, $psize, $total); $pager = pagination($total, $pindex, $psize); if (!empty($list)) { foreach ($list as &$item) { $condition = "`rid`={$item['id']}"; $item['keywords'] = rule_keywords_search($condition); $vote = pdo_fetch("SELECT title,votenum,votetimes,votelimit,votetotal,viewnum,starttime,endtime,status FROM " . tablename('vote_reply') . " WHERE rid = :rid ", array(':rid' => $item['id'])); $item['title'] = $vote['title']; $item['votenum'] = $vote['votenum']; $item['votetimes'] = $vote['votetimes']; $item['viewnum'] = $vote['viewnum']; $item['starttime'] = date('Y-m-d H:i', $vote['starttime']); $endtime = $vote['endtime'] + 86399; $item['endtime'] = date('Y-m-d H:i', $endtime); $limits = ""; if ($vote['votelimit'] == 1) { $limits = "允许投票 " . $vote['votetotal'] . " 人"; } else { $limits = "投票期限: " . date('Y-m-d H:i', $vote['starttime']) . " 至 " . date('Y-m-d H:i', $endtime); } $item['limits'] = $limits; $nowtime = time(); if ($item['votelimit'] == 1) { if ($item['votetotal'] > 0 && $item['votenum'] >= $item['votetotal']) { $item['status'] = '<span class="label label-blue">已结束</span>'; $item['show'] = 0; } else { $item['status'] = '<span class="label label-satgreen">已开始</span>'; $item['show'] = 2; } } else { if ($vote['starttime'] > $nowtime) { $item['status'] = '<span class="label label-red">未开始</span>'; $item['show'] = 1; } elseif ($vote['endtime'] + 86399 < $nowtime) { $item['status'] = '<span class="label label-blue">已结束</span>'; $item['show'] = 0; } else { if ($vote['status'] == 1) { $item['status'] = '<span class="label label-satgreen">已开始</span>'; $item['show'] = 2; } else { $item['status'] = '<span class="label ">已暂停</span>'; $item['show'] = 1; } } } } } include $this->template('manage'); }