Пример #1
0
 /**
  * 根据关注openid从微信端更新用户资料
  * @param $openid 关注者openid
  * @return bool
  */
 public function updateUserByOpenid($openid)
 {
     $openid = strval($openid);
     if (!$openid) {
         return false;
     }
     $user = $this->getRow(array('openid' => $openid));
     $weixin = InitPHP::getLibrarys('weixin');
     //始终从微信获取资料
     $accessToken = InitPHP::getMongoDao('weixinAccessToken', 'mongo/bi');
     $access_token = $accessToken->getAccessToken();
     $wxuser = [];
     if ($access_token) {
         //获取到关注用户的信息
         $wxuser = $weixin->getUserinfoByAccessToken($access_token, $openid);
         if (!$wxuser || !is_array($wxuser)) {
             $wxuser = [];
         }
     }
     $now = time();
     $tmpuser = ['openid' => $openid, 'update_time' => $now];
     $tmpuser = array_merge($wxuser, $tmpuser);
     if (!$user || !is_array($user)) {
         //未关注用户,重新生成用户记录
         $tmpuser['create_time'] = $now;
         return $this->add($tmpuser);
     }
     //已关注用户只需要更新用户资料即可
     return $this->mupdate($tmpuser, ['openid' => $openid]);
 }
Пример #2
0
 /**
  * 重写MYSQL中的QUERY,对SQL语句进行监控
  * @param string $sql
  */
 public function query($sql, $is_set_default = true)
 {
     $this->get_link_id($sql);
     //link_id获取
     $InitPHP_conf = InitPHP::getConfig();
     if ($InitPHP_conf['is_debug'] == true) {
         $start = microtime();
     }
     $query = $this->db->query($sql);
     if ($InitPHP_conf['is_debug'] == true) {
         $end = microtime();
     }
     //sql query debug
     if ($InitPHP_conf['is_debug'] == true) {
         $k = count($InitPHP_conf['sqlcontrolarr']);
         $InitPHP_conf['sqlcontrolarr'][$k]['sql'] = $sql;
         $costTime = substr($end - $start, 0, 7);
         $InitPHP_conf['sqlcontrolarr'][$k]['queryTime'] = $costTime;
         $InitPHP_conf['sqlcontrolarr'][$k]['affectedRows'] = $this->affected_rows();
         InitPHP::setConfig('sqlcontrolarr', $InitPHP_conf['sqlcontrolarr']);
     }
     if ($this->db->error()) {
         InitPHP::initError($this->db->error());
     }
     if ($is_set_default) {
         $this->set_default_link_id();
     }
     //设置默认的link_id
     return $query;
 }
Пример #3
0
 private function _uploadImage($field_name)
 {
     $upload = $this->getLibrary('upload');
     $folder = server_upload_path();
     $upload_path = server_upload_abs_path($folder);
     //添加文件夹
     if (!file_exists($upload_path)) {
         mkdir($upload_path, DIR_WRITE_MODE, true);
     }
     //$allowed_types = '*';
     //$config['max_size'] = '2048';
     $file_name = time() . rand(1000, 9999);
     // 		$this->upload->initialize($config);
     $upload = $upload->upload($field_name, $file_name, $upload_path, array('allowFileType' => '*'));
     if (is_int($upload)) {
         $this->controller->json_return(array('msg' => '', 'state' => 'FAILURE', 'imageid' => 0));
     }
     $abs_path = file_abs_path($folder, $upload['newName']);
     $hash = md5(file_get_contents($abs_path));
     $relative_path = $folder . $upload['newName'];
     $sizeAry = getimagesize($abs_path);
     list($width, $height, $type) = $sizeAry;
     $imageModel = InitPHP::getMysqlDao('image');
     //判断图片是否存在
     $exists = $imageModel->checkHash($hash);
     if (!empty($exists)) {
         //如果存在
         $this->controller->json_return(array('url' => upload_url($exists['path']), 'state' => 'SUCCESS', 'imageid' => $exists['id']));
     }
     $image = array('path' => $relative_path, 'size' => $upload['size'], 'width' => $width, 'height' => $height, 'type' => $type, 'hash' => $hash, 'create_time' => time());
     $image_id = $imageModel->insert($image);
     $this->controller->json_return(array('url' => upload_url($relative_path), 'state' => 'SUCCESS', 'imageid' => $image_id));
 }
Пример #4
0
 /**
  * 运行nosql
  * $this->getNosql()
  */
 public function run_nosql()
 {
     if ($this->nosql == NULL) {
         $this->nosql = InitPHP::loadclass('NosqlInit');
     }
     return $this->nosql;
 }
Пример #5
0
 /**
  *	Error机制 私有函数,error输出
  * 	@param  string   $error_type     错误类型
  *  @return object
  */
 private function display($error_type)
 {
     $InitPHP_conf = InitPHP::getConfig();
     if ($error_type == 'text') {
         $error = implode("\r\t", $this->error_data);
         exit($error);
     } elseif ($error_type == 'json') {
         exit(json_encode($this->error_data));
     } elseif ($error_type == 'xml') {
         $xml = '<?xml version="1.0" encoding="utf-8"?>';
         $xml .= '<return>';
         foreach ($this->error_data as $v) {
             $xml .= '<error>' . $v . '</error>';
         }
         $xml .= '</return>';
         exit($xml);
     } elseif ($error_type == 'array') {
         exit(var_export($this->error_data));
     } elseif ($error_type == 'html') {
         $error = $this->error_data;
         //$template = InitPHP::getAppPath($InitPHP_conf['error']['template']);
         $template = $InitPHP_conf['error']['template'];
         if ($template) {
             if (!file_exists($template)) {
                 InitPHP::initError('error template is not exist');
             }
             @(include $template);
         } else {
             InitPHP::initError('please set error template in initphp.conf.php');
         }
         //扩展HTML错误输出
         exit;
     }
 }
Пример #6
0
 public function __construct()
 {
     parent::__construct();
     //可以在构造函数中初始化
     //如果追求性能的话,可以在具体使用到的Action中调用
     $this->userService = InitPHP::getService("user");
 }
Пример #7
0
/**
 * 获取当前路径 带参数
 */
function current_url_query($query_string = FALSE, $remove = '')
{
    $config = InitPHP::getConfig();
    $current_url = trim($config['url'], '/');
    // BEGIN MODIFICATION
    if ($query_string === TRUE) {
        $gets = $_GET;
        if (!empty($remove)) {
            $newGets = array();
            foreach ($gets as $key => $value) {
                if ($key == $remove) {
                    continue;
                }
                $newGets[$key] = $value;
            }
            $gets = $newGets;
        }
        // Use your preferred method of fetching the query string
        if (!empty($gets)) {
            $current_url .= '?' . http_build_query($gets);
        }
    }
    // END MODIFICATION
    return $current_url;
}
Пример #8
0
 /**
  * 获取Nosql对象
  * @param string $type
  */
 public function init($type = 'MONGO', $server = 'default')
 {
     $InitPHP_conf = InitPHP::getConfig();
     //需要设置文件缓存目录
     $type = strtoupper($type);
     $type = in_array($type, $this->nosql_type) ? $type : 'MONGO';
     switch ($type) {
         case 'MONGO':
             $instance_name = 'mongo_' . $server;
             if (isset(nosqlInit::$instance[$instance_name])) {
                 return nosqlInit::$instance[$instance_name];
             }
             $mongo = $this->load_nosql('mongo.Init.php', 'mongoInit', $server);
             $mongo->init($InitPHP_conf['mongo'][$server]);
             nosqlInit::$instance[$instance_name] = $mongo;
             return $mongo;
             break;
         case 'REDIS':
             $instance_name = 'redis_' . $server;
             if (isset(nosqlInit::$instance[$instance_name])) {
                 return nosqlInit::$instance[$instance_name];
             }
             $redis = $this->load_nosql('redis.Init.php', 'redisInit', $server);
             $redis->init($InitPHP_conf['redis'][$server]);
             nosqlInit::$instance[$instance_name] = $redis;
             return $redis;
             break;
     }
 }
Пример #9
0
 /**
  * 运行nosql
  * $this->getNosql()
  */
 public function run_nosql()
 {
     if ($this->nosql == NULL) {
         require INITPHP_PATH . "/core/dao/nosql/nosql.init.php";
         $this->nosql = InitPHP::loadclass('nosqlInit');
     }
     return $this->nosql;
 }
Пример #10
0
 /**
  * 获取错误登录记录数
  * @param string $ip
  * @param int    $time
  */
 public function getCount($ip, $time)
 {
     $dtime = InitPHP::getTime() - $time;
     $where = $this->dao->db->build_where(array('ip' => $ip));
     $sql = sprintf("SELECT COUNT(id) as count FROM %s %s AND update_time > %s", $this->table_name, $where, $this->dao->db->build_escape($dtime));
     $result = $this->dao->db->get_one_sql($sql);
     return $result['count'];
 }
Пример #11
0
 /**
  * 运行search
  */
 public function run_search()
 {
     if ($this->search == NULL) {
         require INITPHP_PATH . "/core/dao/search/search.init.php";
         $this->search = InitPHP::loadclass('searchInit');
     }
     return $this->search;
 }
Пример #12
0
 /**
  * 添加用户
  * @author pwstrick
  */
 public function add()
 {
     InitPHP::getHelper('view/user');
     $breadcrumbs = array(array(base_url('user/lists'), '用户列表'), array(base_url('user/add'), '用户添加修改'));
     $form = add_view();
     $attrs = array('id' => 'add_view', 'data-uploadify' => 'cover', 'data-ueditor' => 'txtContent', 'data-hiddeniframe' => 'selectCategory');
     $form = $this->form_token_view($form, $attrs);
     $this->view->assign('form', $form);
     $this->mainFormTemplate('用户添加', $breadcrumbs);
 }
Пример #13
0
 /**
  * 从微信刷新jsapi_ticket
  * @param $access_token
  */
 public function refreshJsapiTicket($access_token)
 {
     $weixin = InitPHP::getLibrarys('weixin');
     //记录不存在,需要取微信拉取
     $ticket = $weixin->getJsapiTicket($access_token);
     if (!$ticket || !is_array($ticket)) {
         return null;
     }
     $ires = $this->add(['jsapi_ticket' => strval($ticket['ticket']), 'create_time' => time(), 'expires_in' => intval($ticket['expires_in'])]);
     return $ires ? $ticket['ticket'] : null;
 }
Пример #14
0
 /**
  * 从微信刷新access_token
  *
  * @return null
  */
 public function refreshAccessToken()
 {
     //为空说明没有记录,需要生成一条记录
     $weixin = InitPHP::getLibrarys('weixin');
     $res = $weixin->refreshAccessToken();
     if ($res && is_array($res)) {
         $ires = $this->add(array('access_token' => $res['access_token'], 'create_time' => time(), 'expires_in' => $res['expires_in']));
         return $ires ? $res['access_token'] : null;
     }
     return null;
 }
Пример #15
0
 /**
  * 后置拦截器,在所有操作进行完毕之后进行拦截
  */
 public function postHandle()
 {
     $config = InitPHP::getConfig();
     if ($config['is_xhprof']) {
         $xhprof_data = xhprof_disable();
         // save raw data for this profiler run using default
         // implementation of iXHProfRuns.
         $xhprof_runs = new XHProfRuns_Default();
         // save the run under a namespace "xhprof_foo"
         $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");
     }
 }
Пример #16
0
 /**
  * MYSQL连接器
  * @param  string $host sql服务器
  * @param  string $user 数据库用户名
  * @param  string $password 数据库登录密码
  * @param  string $database 数据库
  * @param  string $charset 编码
  * @param  string $pconnect 是否持久链接
  * @return obj
  */
 public function connect($host, $user, $password, $database, $charset = 'utf8', $pconnect = 0)
 {
     $link_id = $pconnect == 0 ? mysql_connect($host, $user, $password, true) : mysql_pconnect($host, $user, $password);
     if (!$link_id) {
         InitPHP::initError('mysql connect error!');
     }
     mysql_query('SET NAMES ' . $charset, $link_id);
     if (!mysql_select_db($database, $link_id)) {
         InitPHP::initError('database is not exist!');
     }
     return $link_id;
 }
Пример #17
0
 /**
  * 数据库语句监控器-结束点
  * 使用方法:$this->getUtil('sqlcontrol')->end();
  * @return string   
  */
 public function end()
 {
     $InitPHP_conf = InitPHP::getConfig();
     if (isset($InitPHP_conf['sqlcontrolarr']) && is_array($InitPHP_conf['sqlcontrolarr'])) {
         $i = 1;
         echo '<div style=" border:1px #000000 dotted; width:100%; background-color:#EEEEFF">';
         foreach ($InitPHP_conf['sqlcontrolarr'] as $k => $v) {
             echo '<div style=" height:20px; text-align:left; font-size:14px; margin-left:10px;margin-top:5px;"><span>' . $i . '.&nbsp;&nbsp;&nbsp;&nbsp;</span>' . $v . '</div>';
             $i++;
         }
         echo '</div>';
     }
 }
Пример #18
0
 /**
  * ajax登录
  * @author pwstrick
  */
 public function ajaxlogin()
 {
     $account = $this->p('name');
     $pwd = $this->p('pwd');
     $pwd = md5($pwd . constHelper::PWD_KEY);
     $userModel = InitPHP::getMysqlDao('user', 'mysql/sys');
     $account = $userModel->login($account, $pwd);
     if (empty($account)) {
         $this->ajaxFailureOutput('用户名或密码不正确');
         return;
     }
     //保存到session中
     $session = $this->getUtil('session');
     $session->set(constHelper::ADMIN_SESSION, $account);
     $this->ajaxSuccessOutput('登录成功');
 }
Пример #19
0
 /**
  * MYSQL连接器
  * @param  string $host sql服务器
  * @param  string $user 数据库用户名
  * @param  string $password 数据库登录密码
  * @param  string $database 数据库
  * @param  string $charset 编码
  * @param  string $pconnect 是否持久链接
  * @return obj
  */
 public function connect($host, $user, $password, $database, $charset = 'utf8', $pconnect = 0)
 {
     $port = 3306;
     //设置默认值
     if (strpos($host, ":")) {
         $arr = explode(":", $host);
         $host = $arr[0];
         $port = $arr[1];
     }
     $link_id = $pconnect == 0 ? mysqli_connect($host, $user, $password, $database, $port) : mysqli_pconnect($host, $user, $password, $database, $port);
     if (!$link_id) {
         InitPHP::initError("mysqli connect error");
     }
     mysqli_query($link_id, 'SET NAMES ' . $charset);
     return $link_id;
 }
Пример #20
0
 /**
  * 具体解析
  * @param unknown_type $isPre
  */
 private function parse($isPre = true)
 {
     $InitPHP_conf = InitPHP::getConfig();
     $interceptor = $InitPHP_conf['interceptor'];
     $filePath = $interceptor['path'];
     //文件路径
     $return = true;
     if (is_array($interceptor['rule']) && count($interceptor['rule']) > 0) {
         foreach ($interceptor['rule'] as $k => $v) {
             $file = ltrim($filePath, "/") . "/" . $v['file'] . $interceptor['postfix'] . '.php';
             $class = $v['file'] . $interceptor['postfix'];
             //处理正则匹配
             $regular = $v['regular'];
             if ($regular['m'] != "" && $regular['m'] != '*') {
                 if (!preg_match($regular['m'], $this->m)) {
                     continue;
                 }
             }
             if ($regular['c'] != "" && $regular['c'] != '*') {
                 if (!preg_match($regular['c'], $this->c)) {
                     continue;
                 }
             }
             if ($regular['a'] != "" && $regular['a'] != '*') {
                 if (!preg_match($regular['a'], $this->a)) {
                     continue;
                 }
             }
             if (file_exists(InitPHP::getAppPath($file))) {
                 InitPHP::import($file);
                 $obj = InitPHP::loadclass($class);
                 if ($isPre == true) {
                     $ret = $obj->preHandle();
                     if ($ret == false) {
                         $return = false;
                         break;
                     }
                 } else {
                     $obj->postHandle();
                 }
             }
         }
     }
     return $return;
 }
Пример #21
0
 /**
  * 获取search对象
  * @param string $type
  */
 public function init($type = 'SPHINX', $server = 'default')
 {
     $InitPHP_conf = InitPHP::getConfig();
     //需要设置文件缓存目录
     $type = strtoupper($type);
     $type = in_array($type, $this->search_type) ? $type : 'SPHINX';
     switch ($type) {
         case 'SPHINX':
             $instance_name = 'sphinx_' . $server;
             if (isset(searchInit::$instance[$instance_name])) {
                 return searchInit::$instance[$instance_name];
             }
             $search = $this->load_search('sphinx.init.php', 'sphinxInit', $server);
             $search->setServer($InitPHP_conf['sphinx'][$server]['server'], $InitPHP_conf['sphinx'][$server]['port']);
             searchInit::$instance[$instance_name] = $search;
             return $search;
             break;
     }
 }
Пример #22
0
 /**
  * demo
  */
 public function unittest()
 {
     InitPHP::getUtils('unittesting')->run('user');
 }
Пример #23
0
 /**
  * 广告DAO
  * @return AdDao
  */
 private function _getAdDao()
 {
     return InitPHP::getDao('Ad', 'ad');
 }
Пример #24
0
 /**
  * 模板-显示视图
  * 1. 在Controller中需要显示模板,就必须调用该函数
  * 2. 模板解析可以设置 $InitPHP_conf['isviewfilter'] 值,对变量进行过滤
  * Controller中使用方法:$this->view->display();
  * @return array
  */
 public function display($template = '')
 {
     if ($template != '') {
         $this->set_tpl($template);
     }
     $InitPHP_conf = InitPHP::getConfig();
     if (is_array($this->view)) {
         if ($InitPHP_conf['isviewfilter']) {
             $this->out_put($this->view);
         }
         foreach ($this->view as $key => $val) {
             ${$key} = $val;
         }
     }
     $this->template_arr = $this->parse_template_arr($this->template_arr);
     //模板设置
     foreach ($this->template_arr as $file_name) {
         if (in_array($file_name, $this->remove_tpl_arr)) {
             continue;
         }
         $complie_file_name = $this->template_run($file_name);
         //模板编译
         if (!file_exists($complie_file_name)) {
             InitPHP::initError($complie_file_name . ' is not exist!');
         }
         include_once $complie_file_name;
     }
 }
Пример #25
0
">[编辑]</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:del('确定要删除该单页?', '<?php 
    echo $singleSingleDel;
    ?>
', 'id=<?php 
    echo $value['id'];
    ?>
&init_token=<?php 
    echo $init_token;
    ?>
');">[删除]</a></td>
    </tr>
    <?php 
}
?>
    <?php 
if ($singleCount == 0) {
    ?>
    <tr>
      <td colspan="6">暂时没有任何数据!</td>
    </tr>
    <?php 
}
?>
  </table>
  <div class="page">
    <?php 
echo InitPHP::output($page, 'decode');
?>
  </div>
</div>
Пример #26
0
<?php

require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'defined.php';
define('APP_NAME', 'admin');
define('APP_PATH', ROOT_PATH . '/app/' . APP_NAME);
require_once APP_PATH . '/conf/comm.conf.php';
//APP配置
InitPHP::init();
Пример #27
0
 /**
  * 按月分表-分库方法
  * 1. 当数据表数据量过大的时候,可以根据按月分表的方法来进行分表
  * 2. 按月分库会根据当前的时间来决定是几月份的数据
  * 3. 按月分库$defaultId,可以自定义填入月份,例如:get_mon_table('test', 2),则返回 test_02
  * Dao中使用方法:$this->Dao->Db->month_identify($tbl, $defaultId = '')
  * @param string $tbl
  * @param string $defaultId
  */
 public function month_identify($tbl, $defaultId = '')
 {
     if (empty($defaultId)) {
         $mon = sprintf('%02d', date('m', InitPHP::getTime()));
         return $tbl . '_' . $mon;
     } else {
         return $tbl . '_' . sprintf('%02d', $defaultId);
     }
 }
Пример #28
0
 /**
  * 写日志-获取文件日志名称
  * @return string
  */
 private function get_file_log_name()
 {
     $config = InitPHP::getConfig();
     return $config['log_dir'] . $this->_errorLogFileName();
 }
Пример #29
0
 /**
  * 初始化 
  */
 public function __construct()
 {
     parent::__construct();
     $InitPHP_conf = InitPHP::getConfig();
     $this->controller = $this->load('controller', 'c');
     //导入Controller
     $this->view = $this->load('view', 'v');
     //导入View
     $this->view->set_template_config($InitPHP_conf['template']);
     //设置模板
     $this->view->assign('init_token', $this->controller->get_token());
     //全局输出init_token标记
     //注册全局变量,这样在Service和Dao中通过$this->common也能调用Controller中的类
     $this->register_global('common', $this->controller);
 }
Пример #30
0
 /**
  * @return AdminLogService
  */
 protected function _getAdminLogService()
 {
     return InitPHP::getService('AdminLog', 'admin');
 }