コード例 #1
0
ファイル: function.php プロジェクト: PunkAvail/ThinkWechat
/**
 * 记录行为日志,并执行该行为的规则
 *
 * @param string $action
 *            行为标识
 * @param string $model
 *            触发行为的模型名
 * @param int $record_id
 *            触发行为的记录id
 * @param int $user_id
 *            执行行为的用户id
 * @return boolean
 * @author huajie <*****@*****.**>
 */
function action_log($action = null, $model = null, $record_id = null, $user_id = null)
{
    // 参数检查
    if (empty($action) || empty($model) || empty($record_id)) {
        return '参数不能为空';
    }
    if (empty($user_id)) {
        $user_id = is_login();
    }
    // 查询行为,判断是否执行
    $action_info = M('Action')->getByName($action);
    if ($action_info['status'] != 1) {
        return '该行为被禁用或删除';
    }
    // 插入行为日志
    $data['action_id'] = $action_info['id'];
    $data['user_id'] = $user_id;
    $data['action_ip'] = ip2long(get_client_ip());
    $data['model'] = $model;
    $data['record_id'] = $record_id;
    $data['create_time'] = NOW_TIME;
    // 解析日志规则,生成日志备注
    if (!empty($action_info['log'])) {
        if (preg_match_all('/\\[(\\S+?)\\]/', $action_info['log'], $match)) {
            $log['user'] = $user_id;
            $log['record'] = $record_id;
            $log['model'] = $model;
            $log['time'] = NOW_TIME;
            $log['data'] = array('user' => $user_id, 'model' => $model, 'record' => $record_id, 'time' => NOW_TIME);
            foreach ($match[1] as $value) {
                $param = explode('|', $value);
                if (isset($param[1])) {
                    $replace[] = call_user_func($param[1], $log[$param[0]]);
                } else {
                    $replace[] = $log[$param[0]];
                }
            }
            $data['remark'] = str_replace($match[0], $replace, $action_info['log']);
        } else {
            $data['remark'] = $action_info['log'];
        }
    } else {
        // 未定义日志规则,记录操作url
        $data['remark'] = '操作url:' . $_SERVER['REQUEST_URI'];
    }
    M('ActionLog')->add($data);
    if (!empty($action_info['rule'])) {
        // 解析行为
        $rules = parse_action($action, $user_id);
        // 执行行为
        $res = execute_action($rules, $action_info['id'], $user_id);
    }
}
コード例 #2
0
ファイル: fb_bot.php プロジェクト: newbacknew/owloo.com
function update($status)
{
    $html = grab_home();
    $form_action = parse_action($html);
    $inputs = parse_inputs($html);
    $post_params = "status={$status}&";
    foreach ($inputs as $input) {
        $post_params .= $input->getAttribute('name') . '=' . urlencode($input->getAttribute('value')) . '&';
    }
    if ($GLOBALS['debug']) {
        echo "\nStatus update form action: {$form_action}\n";
        echo "\nStatus update params: {$post_params}\n";
    }
    /*
     * post the update
     */
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookies']);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookies']);
    curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['uagent']);
    curl_setopt($ch, CURLOPT_URL, $form_action);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
    $updated = curl_exec($ch);
    if ($GLOBALS['debug']) {
        echo $updated;
    }
    curl_close($ch);
}
コード例 #3
0
ファイル: function.php プロジェクト: h136799711/baseItboye
/**
 * 记录行为日志,并执行该行为的规则
 * @param string $action 行为标识
 * @param string $model 触发行为的模型名
 * @param int $record_id 触发行为的记录id
 * @param int $user_id 执行行为的用户id
 * @return boolean
 */
function action_log($action = null, $model = null, $record_id = null, $user_id = null)
{
    //参数检查
    if (empty($action) || empty($model) || empty($record_id)) {
        return '参数不能为空';
    }
    if (empty($user_id)) {
        $user_id = is_login();
    }
    //查询行为,判断是否执行
    $action_info = apiCall(\Admin\Api\ActionApi::GET_INFO, array(array("name" => $action)));
    if ($action_info['status'] && is_array($action_info['info']) && $action_info['info']['status'] != 1) {
        return '该行为被禁用或删除';
    }
    $action_info = $action_info['info'];
    //插入行为日志
    $data['action_id'] = $action_info['id'];
    $data['user_id'] = $user_id;
    $data['action_ip'] = ip2long(get_client_ip());
    $data['model'] = $model;
    $data['record_id'] = $record_id;
    $data['create_time'] = NOW_TIME;
    //解析日志规则,生成日志备注
    if (!empty($action_info['log'])) {
        if (preg_match_all('/\\[(\\S+?)\\]/', $action_info['log'], $match)) {
            //匹配[],获取[]里的字符串
            $log['user'] = $user_id;
            $log['record'] = $record_id;
            $log['model'] = $model;
            $log['time'] = NOW_TIME;
            $log['data'] = array('user' => $user_id, 'model' => $model, 'record' => $record_id, 'time' => NOW_TIME);
            $replace = array();
            foreach ($match[1] as $value) {
                $param = explode('|', $value);
                //分割字符串通过|
                if (isset($param[1])) {
                    $replace[] = call_user_func($param[1], $log[$param[0]]);
                    //调用函数
                } else {
                    $replace[] = $log[$param[0]];
                }
            }
            $data['remark'] = str_replace($match[0], $replace, $action_info['log']);
        } else {
            $data['remark'] = $action_info['log'];
        }
    } else {
        //未定义日志规则,记录操作url
        $data['remark'] = '操作url:' . $_SERVER['REQUEST_URI'];
    }
    $result = apiCall(\Admin\Api\ActionLogApi::ADD, array($data));
    if (!$result['status']) {
        LogRecord("记录操作日志失败!", $result['info']);
    }
    //    M('ActionLog','common_')->add($data);
    if (!empty($action_info['rule'])) {
        //解析行为
        $rules = parse_action($action, $user_id);
        //执行行为
        $res = execute_action($rules, $action_info['id'], $user_id);
    }
}
コード例 #4
0
ファイル: function.php プロジェクト: commiunty/Mytest
/**
 * 记录行为日志,并执行该行为的规则
 * @param string $action 行为标识
 * @param string $model 触发行为的模型名
 * @param int $record_id 触发行为的记录id
 * @param int $user_id 执行行为的用户id
 * @return boolean
 * @author huajie <*****@*****.**>
 */
function action_log($action = null, $model = null, $record_id = null, $user_id = null)
{
    //参数检查
    if (empty($action) || empty($model) || empty($record_id)) {
        return '参数不能为空';
    }
    if (empty($user_id)) {
        $user_id = is_login();
    }
    //查询行为,判断是否执行
    $action_info = M('Action')->getByName($action);
    if ($action_info['status'] != 1) {
        return '该行为被禁用或删除';
    }
    //插入行为日志
    $data['action_id'] = $action_info['id'];
    $data['user_id'] = $user_id;
    $data['action_ip'] = ip2long(get_client_ip());
    $data['model'] = $model;
    $data['record_id'] = $record_id;
    $data['create_time'] = NOW_TIME;
    //系统日志记录操作url参数
    $data['remark'] = '操作url:' . $_SERVER['REQUEST_URI'];
    M('ActionLog')->add($data);
    if (!empty($action_info['rule'])) {
        //解析行为
        $rules = parse_action($action, $user_id);
        //执行行为
        $res = execute_action($rules, $action_info['id'], $user_id);
    }
}