Esempio n. 1
0
<?php
/**
 * [WeEngine System] Copyright (c) 2013 WE7.CC
 */
defined('IN_IA') or exit('Access Denied');

if(!$_W['isajax'] || !$_W['ispost']) {
	//exit('Access Denied');
}

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'));
Esempio n. 2
0
 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');
     }
 }
Esempio n. 3
0
            $settings['welcome'] = serialize(array('module' => $keyword['module'], 'id' => $keyword['rid']));
        }
        if (!empty($_GPC['defaultkeyword'])) {
            $keyword = pdo_fetch("SELECT rid, module FROM " . tablename('rule_keyword') . " WHERE content = :content AND weid = :weid", array(':weid' => $_W['weid'], ':content' => $_GPC['defaultkeyword']));
            $settings['default'] = serialize(array('module' => $keyword['module'], 'id' => $keyword['rid']));
        }
        pdo_update('wechats', $settings, array('weid' => $_W['weid']));
        message('系统回复更新成功!', create_url('rule/system'));
    } else {
        include model('rule');
        if (is_array($_W['account']['default'])) {
            $wechat['default'] = rule_single($_W['account']['default']['id']);
            $wechat['defaultrid'] = $_W['account']['default']['id'];
        }
        if (is_array($_W['account']['welcome'])) {
            $wechat['welcome'] = rule_single($_W['account']['welcome']['id']);
            $wechat['welcomerid'] = $_W['account']['welcome']['id'];
        }
        template('rule/system');
    }
} elseif ($do == 'message') {
    $mtypes = array();
    $mtypes['image'] = '图片消息';
    $mtypes['voice'] = '语音消息';
    $mtypes['video'] = '视频消息';
    $mtypes['location'] = '位置消息';
    $mtypes['link'] = '链接消息';
    $mtypes['subscribe'] = '粉丝开始关注';
    if (checksubmit()) {
        $s = array_elements(array_keys($mtypes), $_GPC);
        $ms = array();
Esempio n. 4
0
$entry = pdo_fetch($sql, array(':eid' => $eid));
if (empty($entry)) {
    message('非法访问.');
}
$modulename = '';
foreach ($_W['account']['modules'] as $m) {
    if ($m['name'] == $entry['module']) {
        $modulename = $m['name'];
        break;
    }
}
if (empty($modulename)) {
    message('您未启用、安装该模块或是您没有权限使用!', '', 'error');
}
$reply = pdo_fetch("SELECT * FROM " . tablename('cover_reply') . ' WHERE `module` = :module AND `do` = :do AND weid = :weid', array(':module' => $entry['module'], ':do' => $entry['do'], ':weid' => $_W['weid']));
$rule = rule_single($reply['rid']);
$rule['keywords'] = array();
if (is_array($rule['keyword'])) {
    foreach ($rule['keyword'] as $kwd) {
        $rule['keywords'][] = $kwd['content'];
    }
}
$rule['keywords'] = implode(',', $rule['keywords']);
if (empty($reply)) {
    $reply = array();
}
if (empty($reply['title'])) {
    $reply['title'] = $entry['title'];
}
if (checksubmit('submit')) {
    if (trim($_GPC['keywords']) == '') {