Example #1
0
 /**
  * 设置缓存
  * 
  * @param string $key
  * @param string $value
  * @return boolean
  */
 public function set($key, $value)
 {
     if (!$key) {
         return false;
     }
     $cache_file = $this->parse_cache_file($key);
     // 分析缓存文件
     $value = !is_array($value) ? serialize($value) : serialize($value);
     // 分析缓存内容
     // 分析缓存目录
     if (!is_dir($this->cache_dir)) {
         dr_mkdirs($this->cache_dir, 0777);
     } else {
         if (!is_writeable($this->cache_dir)) {
             @chmod($this->cache_dir, 0777);
         }
     }
     return @file_put_contents($cache_file, $value, LOCK_EX) ? true : false;
 }
Example #2
0
 /**
  * 创建栏目的html文件
  */
 protected function _create_category_file($catid, $page = 0)
 {
     if (!MODULE_HTML || !$catid) {
         return NULL;
     }
     $mod = $this->get_cache('module-' . SITE_ID . '-' . $this->dir);
     $cat = $mod['category'][$catid];
     // 当此栏目是外链时,不生成!
     if ($cat['setting']['linkurl']) {
         return NULL;
     }
     $url = $page > 1 ? dr_category_url($mod, $cat, $page) : $cat['url'];
     if (!$url) {
         return NULL;
     }
     $file = str_replace($mod['url'], '', $url);
     $_GET['page'] = $page;
     if (strpos($file, 'index.php?c=category') !== FALSE) {
         return NULL;
     }
     ob_start();
     $this->_category($catid, NULL, $page);
     $dir = dirname($file);
     $file = basename($file);
     $html = ob_get_clean();
     if (SITE_ID > 1) {
         $dir = trim('html/' . SITE_ID . '/' . trim($dir, '.'), '/');
     }
     if ($dir != '.' && !file_exists(APPPATH . $dir)) {
         dr_mkdirs(APPPATH . $dir, TRUE);
     }
     // 判断是否为目录形式
     if (strpos($file, '.html') === FALSE && strpos($file, '.htm') === FALSE && strpos($file, '.shtml') === FALSE) {
         dr_mkdirs(APPPATH . $dir . '/' . $file, TRUE);
     }
     // 如果是目录就生成一个index.html
     if (is_dir(APPPATH . $dir . '/' . $file)) {
         $dir .= '/' . $file;
         $file = 'index.html';
     }
     if (!file_put_contents(APPPATH . $dir . '/' . $file, $html, LOCK_EX)) {
         return NULL;
     }
     // 保存文件记录
     $this->content_model->set_html(3, 0, 0, $catid, $catid, array(APPPATH . $dir . '/' . $file));
     // 生成栏目的第一页
     if ($page <= 1) {
         $purl = dr_category_url($mod, $cat, '{page}');
         $pfile = basename(str_replace(array($mod['url'], '{page}'), array('', 1), $purl));
         // 判断是否为目录形式
         if (strpos($pfile, '.html') === FALSE && strpos($pfile, '.htm') === FALSE && strpos($pfile, '.shtml') === FALSE) {
             dr_mkdirs(APPPATH . $dir . '/' . $pfile, TRUE);
         }
         // 如果是目录就生成一个index.html
         if (is_dir(APPPATH . $dir . '/' . $pfile)) {
             $dir .= '/' . $pfile;
             $pfile = 'index.html';
         }
         file_put_contents(APPPATH . $dir . '/' . $pfile, $html, LOCK_EX);
         $this->content_model->set_html(3, 0, 0, $catid, $catid, array(APPPATH . $dir . '/' . $pfile));
     }
     return TRUE;
 }
 /**
  * 模块缓存
  *
  * @param	string	$dirname	模块名称
  * @param	intval	$update		是否更新数量
  * @return	NULL
  */
 public function cache($dirname, $update = 1)
 {
     if (!is_dir(FCPATH . $dirname . '/')) {
         return NULL;
     }
     $data = $this->db->where('disabled', 0)->where('dirname', $dirname)->order_by('displayorder ASC,id ASC')->get('module')->row_array();
     if (!$data) {
         return NULL;
     }
     $config = (require FCPATH . $dirname . '/config/module.php');
     // 配置信息
     $site_domain = (require FCPATH . 'config/domain.php');
     // 加载站点域名配置文件
     $data['site'] = dr_string2array($data['site']);
     $data['setting'] = dr_string2array($data['setting']);
     // 模块表单数据
     $form = array();
     $temp = $this->db->where('disabled', 0)->order_by('id ASC')->get('module_form')->result_array();
     if ($temp) {
         foreach ($temp as $t) {
             $t['field'] = array();
             // 模块表单的自定义字段
             $field = $this->db->where('disabled', 0)->where('relatedid', $t['id'])->where('relatedname', 'mform-' . $data['dirname'])->order_by('displayorder ASC, id ASC')->get('field')->result_array();
             if ($field) {
                 foreach ($field as $f) {
                     $t['field'][$f['fieldname']] = $this->get_field_value($f);
                 }
             }
             $t['setting'] = dr_string2array($t['setting']);
             $t['permission'] = dr_string2array($t['permission']);
             $form[$t['module']][$t['table']] = $t;
         }
     }
     // 按站点生成缓存
     foreach ($this->SITE as $siteid => $t) {
         $cache = $data;
         $this->cache->delete('module-' . $siteid . '-' . $dirname);
         $this->ci->clear_cache('module-' . $siteid . '-' . $dirname);
         if (isset($data['site'][$siteid]['use']) && $data['site'][$siteid]['use']) {
             // 模块域名
             $domain = $data['site'][$siteid]['domain'];
             if ($domain) {
                 $site_domain[$domain] = $siteid;
             }
             // 将站点保存至域名配置文件
             $cache['url'] = $domain ? 'http://' . $domain . '/' : $this->SITE[$siteid]['SITE_URL'] . $dirname . '/';
             // 模块的URL地址
             $cache['html'] = $data['site'][$siteid]['html'];
             $cache['theme'] = $data['site'][$siteid]['theme'];
             $cache['domain'] = $data['site'][$siteid]['domain'];
             $cache['template'] = $data['site'][$siteid]['template'];
             // 非主站开启静态生成时,创建新的入口文件
             if ($cache['html'] && $siteid > 1) {
                 $path = FCPATH . $cache['dirname'] . '/html/' . $siteid;
                 if (!file_exists($path)) {
                     dr_mkdirs($path, TRUE);
                 }
                 copy(FCPATH . $cache['dirname'] . '/html.php', $path . '/index.php');
             }
             // 系统模块格式
             if (!isset($config['mydb']) || !$config['mydb']) {
                 // 模块的自定义字段
                 $field = $this->db->where('disabled', 0)->where('relatedid', $data['id'])->where('relatedname', 'module')->order_by('displayorder ASC, id ASC')->get('field')->result_array();
                 if ($field) {
                     foreach ($field as $f) {
                         $cache['field'][$f['fieldname']] = $this->get_field_value($f);
                     }
                 } else {
                     $cache['field'] = array();
                 }
                 // 模块扩展的自定义字段
                 if ($data['extend']) {
                     $field = $this->db->where('disabled', 0)->where('relatedid', $data['id'])->where('relatedname', 'extend')->order_by('displayorder ASC, id ASC')->get('field')->result_array();
                     $cache['extend'] = array();
                     if ($field) {
                         foreach ($field as $f) {
                             $cache['extend'][$f['fieldname']] = $this->get_field_value($f);
                         }
                     }
                 } else {
                     $cache['extend'] = 0;
                 }
                 // 模块表单归类
                 $cache['form'] = isset($form[$dirname]) ? $form[$dirname] : array();
                 // 模块表创建统计字段
                 if ($cache['form']) {
                     foreach ($cache['form'] as $fm) {
                         $this->system_model->create_form_total_field($siteid, $dirname, $fm['table'], 1);
                     }
                 }
                 // 模块的栏目分类
                 $category = $this->site[$siteid]->order_by('displayorder ASC, id ASC')->get($siteid . '_' . $dirname . '_category')->result_array();
                 if ($category) {
                     $CAT = $CAT_DIR = $level = array();
                     foreach ($category as $c) {
                         if ($update == 1) {
                             if (!$c['child']) {
                                 $c['total'] = $this->site[$siteid]->where('status', 9)->where('catid', $c['id'])->count_all_results($siteid . '_' . $dirname . '_index');
                             } else {
                                 $c['total'] = 0;
                             }
                         } else {
                             $c['total'] = $this->ci->get_cache('module-' . SITE_ID . '-' . APP_DIR, 'category', $c['id'], 'total');
                         }
                         $pid = explode(',', $c['pids']);
                         $level[] = substr_count($c['pids'], ',');
                         $c['topid'] = isset($pid[1]) ? $pid[1] : $c['id'];
                         $c['catids'] = explode(',', $c['childids']);
                         $c['setting'] = dr_string2array($c['setting']);
                         $c['permission'] = $c['child'] ? '' : dr_string2array($c['permission']);
                         $c['url'] = isset($c['setting']['linkurl']) && $c['setting']['linkurl'] ? $c['setting']['linkurl'] : dr_category_url($cache, $c);
                         // 删除过期的部分
                         unset($c['setting']['urlmode']);
                         unset($c['setting']['url']);
                         $CAT[$c['id']] = $c;
                         $CAT_DIR[$c['dirname']] = $c['id'];
                     }
                     // 更新父栏目数量
                     if ($update == 1) {
                         foreach ($category as $c) {
                             if ($c['child']) {
                                 $arr = explode(',', $c['childids']);
                                 $CAT[$c['id']]['total'] = 0;
                                 foreach ($arr as $i) {
                                     $CAT[$c['id']]['total'] += $CAT[$i]['total'];
                                 }
                             }
                         }
                     }
                     // 栏目自定义字段,把父级栏目的字段合并至当前栏目
                     $field = $this->db->where('disabled', 0)->where('relatedname', $dirname . '-' . $siteid)->order_by('displayorder ASC, id ASC')->get('field')->result_array();
                     if ($field) {
                         foreach ($field as $f) {
                             if (isset($CAT[$f['relatedid']]['childids']) && $CAT[$f['relatedid']]['childids']) {
                                 // 将该字段同时归类至其子栏目
                                 $child = explode(',', $CAT[$f['relatedid']]['childids']);
                                 foreach ($child as $catid) {
                                     if ($CAT[$catid]) {
                                         $CAT[$catid]['field'][$f['fieldname']] = $this->get_field_value($f);
                                     }
                                 }
                             }
                         }
                     }
                     $cache['category'] = $CAT;
                     $cache['category_dir'] = $CAT_DIR;
                     $cache['category_field'] = $field ? 1 : 0;
                     $cache['category_level'] = $level ? max($level) : 0;
                 } else {
                     $cache['category'] = array();
                     $cache['category_dir'] = array();
                     $cache['category_field'] = $cache['category_level'] = 0;
                 }
                 $cache['is_system'] = 1;
             } else {
                 $cache['is_system'] = 0;
             }
             // 模块名称
             $name = $this->db->select('name')->where('pid', 0)->where('mark', 'module-' . $dirname)->limit(1)->get('admin_menu')->row_array();
             $cache['name'] = $name['name'] ? $name['name'] : $config['name'];
             $this->dcache->set('module-' . $siteid . '-' . $dirname, $cache);
         }
     }
     $this->load->library('dconfig');
     $this->dconfig->file(FCPATH . 'config/domain.php')->note('站点域名文件')->space(32)->to_require_one($site_domain);
 }
Example #4
0
 /**
  * 下载远程文件
  *
  * @param	intval	$uid	uid	用户id
  * @param	string	$url	文件url
  * @return	array
  */
 public function catcher($uid, $url)
 {
     if (!$uid || !$url) {
         return NULL;
     }
     // 站点信息
     $siteinfo = $this->ci->get_cache('siteinfo', SITE_ID);
     // 域名验证
     $domain = (require FCPATH . 'config/domain.php');
     foreach ($siteinfo['remote'] as $t) {
         $domain[$t['SITE_ATTACH_URL']] = TRUE;
     }
     $domain['baidu.com'] = TRUE;
     $domain['google.com'] = TRUE;
     foreach ($domain as $uri => $t) {
         if (stripos($url, $uri) !== FALSE) {
             return NULL;
         }
     }
     $path = FCPATH . 'member/uploadfile/' . date('Ym', SYS_TIME) . '/';
     if (!is_dir($path)) {
         dr_mkdirs($path);
     }
     $filename = substr(md5(time()), 0, 7) . rand(100, 999);
     $data = dr_catcher_data($url);
     if (!$data) {
         return NULL;
     }
     $fileext = strtolower(trim(substr(strrchr($url, '.'), 1, 10)));
     //扩展名
     if (file_put_contents($path . $filename . '.' . $fileext, $data)) {
         $info = array('file_ext' => '.' . $fileext, 'full_path' => $path . $filename . '.' . $fileext, 'file_size' => filesize($path . $filename . '.' . $fileext) / 1024, 'client_name' => $url);
         return $this->upload($uid, $info, NULL);
     }
     return NULL;
 }
/**
 * 递归创建目录
 *
 * @param	string	$dir	目录名称
 * @return	bool|void
 */
function dr_mkdirs($dir)
{
    if (!$dir) {
        return FALSE;
    }
    if (!is_dir($dir)) {
        dr_mkdirs(dirname($dir));
        if (!file_exists($dir)) {
            mkdir($dir, 0777);
        }
    }
}
Example #6
0
 /**
  * 初始化网站全局变量
  */
 private function _init_variable()
 {
     define('IS_AJAX', $this->input->is_ajax_request());
     define('IS_POST', $_SERVER['REQUEST_METHOD'] == 'POST' && count($_POST) ? TRUE : FALSE);
     define('SYS_TIME', $_SERVER['REQUEST_TIME'] ? $_SERVER['REQUEST_TIME'] : time());
     define('SITE_PATH', '/');
     $this->load->library('session');
     $host = strtolower($_SERVER['HTTP_HOST']);
     // 当前网站的域名
     $domain = (require FCPATH . 'config/domain.php');
     // 加载站点域名配置文件
     $sitecfg = directory_map(FCPATH . 'config/site/');
     // 加载全部站点的配置文件
     foreach ($sitecfg as $file) {
         $id = (int) basename($file);
         if (is_file(FCPATH . 'config/site/' . $file)) {
             $this->SITE[$id] = (require FCPATH . 'config/site/' . $file);
             $this->SITE[$id]['SITE_ID'] = (int) $id;
             $this->SITE[$id]['SITE_URL'] = 'http://' . ($this->SITE[$id]['SITE_DOMAIN'] ? $this->SITE[$id]['SITE_DOMAIN'] : $host) . SITE_PATH;
         }
     }
     unset($sitecfg);
     // 分析站点信息
     $siteid = NULL;
     if (IS_ADMIN && $this->session->userdata('siteid')) {
         $siteid = (int) $this->session->userdata('siteid');
     }
     if ($siteid && isset($this->SITE[$siteid]) && isset($domain[$host])) {
         // 通过session来获取siteid
         define('SITE_ID', $siteid);
     } elseif (isset($domain[$host]) && isset($this->SITE[$domain[$host]])) {
         // 通过域名来获取siteid
         $siteid = (int) $domain[$host];
         $orthers = @explode(',', $this->SITE[$siteid]['SITE_DOMAINS']);
         if ($orthers && $host != $this->SITE[$siteid]['SITE_DOMAIN'] && in_array($host, $orthers)) {
             // 判断当前域名为“其他域名”
             $uri = isset($_SERVER['HTTP_X_REWRITE_URL']) && trim($_SERVER['REQUEST_URI'], '/') == SELF ? trim($_SERVER['HTTP_X_REWRITE_URL'], '/') : ($_SERVER['REQUEST_URI'] ? trim($_SERVER['REQUEST_URI'], '/') : '');
             redirect('http://' . $this->SITE[$siteid]['SITE_DOMAIN'] . '/' . $uri, '301');
             exit;
         } elseif (isset($this->SITE[$siteid]['SITE_MOBILE']) && $this->SITE[$siteid]['SITE_MOBILE'] && APP_DIR != 'weixin') {
             // 当前网站存在移动端域名时
             if ($host == $this->SITE[$siteid]['SITE_MOBILE']) {
                 // 当此域名是移动端域名时重新赋值给主站URL
                 $this->SITE[$siteid]['SITE_PC'] = $this->SITE[$siteid]['SITE_URL'];
                 $this->SITE[$siteid]['SITE_URL'] = 'http://' . $host . '/';
                 $this->SITE[$siteid]['SITE_MOBILE'] = TRUE;
             } elseif ($this->agent->is_mobile() && $this->SITE[$siteid]['SITE_MOBILE_OPEN'] && $this->SITE[$siteid]['SITE_MOBILE']) {
                 // 当网站开启强制定向时
                 redirect('http://' . $this->SITE[$siteid]['SITE_MOBILE'], '301');
                 exit;
             }
         } elseif ($this->agent->is_mobile() && $this->SITE[$siteid]['SITE_MOBILE_OPEN']) {
             // 识别移动端
             $this->SITE[$siteid]['SITE_PC'] = $this->SITE[$siteid]['SITE_URL'] = $this->SITE[$siteid]['SITE_URL'];
             $this->SITE[$siteid]['SITE_MOBILE'] = TRUE;
         }
         define('SITE_ID', $siteid);
     } else {
         // 识别移动端
         if ($this->agent->is_mobile() && $this->SITE[1]['SITE_MOBILE_OPEN']) {
             $this->SITE[1]['SITE_PC'] = $this->SITE[1]['SITE_URL'] = $this->SITE[1]['SITE_URL'];
             $this->SITE[1]['SITE_MOBILE'] = TRUE;
         }
         // 默认站点id
         define('SITE_ID', 1);
     }
     // 全局化站点变量
     $config1 = (require FCPATH . 'config/system.php');
     // 加载网站系统配置文件
     $config2 = (require FCPATH . 'config/version.php');
     // 加载系统版本更新文件
     $config3 = array_merge($config1, $config2);
     // 合并配置数组
     if ($this->SITE[SITE_ID]) {
         $config3 = array_merge($config3, $this->SITE[SITE_ID]);
     }
     // 将配置文件数组转换为常量
     foreach ($config3 as $var => $value) {
         define($var, $value);
     }
     unset($config3, $config2, $config1);
     // 判断网站是否关闭
     $site_close = defined('SITE_CLOSE') && SITE_CLOSE && !IS_ADMIN;
     // 判断手机端与PC端模板
     $this->mobile = SITE_MOBILE === TRUE ? TRUE : FALSE;
     // 网站在非关闭状态时加载首页缓存
     if (!$site_close) {
         // 首页静态文件过期检查
         if (!$this->mobile && SITE_HOME_INDEX && !IS_ADMIN && !IS_MEMBER && APP_DIR == '' && basename(APPPATH) == 'dayrui' && $this->router->class == 'home' && $this->router->method == 'index') {
             $file = FCPATH . 'cache/index/home-' . SITE_ID . '.html';
             if (!is_file($file) || is_file($file) && filemtime($file) + SITE_HOME_INDEX < SYS_TIME) {
                 @unlink($file);
             } else {
                 echo file_get_contents($file);
                 exit;
             }
         }
         // 模块静态文件过期检查
         if (!$this->mobile && SITE_MODULE_INDEX && !IS_ADMIN && !IS_MEMBER && APP_DIR && $this->router->class == 'home' && $this->router->method == 'index') {
             $file = FCPATH . 'cache/index/' . APP_DIR . '-' . SITE_ID . '.html';
             if (!is_file($file) || is_file($file) && filemtime($file) + SITE_MODULE_INDEX < SYS_TIME) {
                 @unlink($file);
             } else {
                 echo file_get_contents($file);
                 exit;
             }
         }
     }
     // 显示错误提示
     if (SYS_DEBUG) {
         error_reporting(E_ALL ^ E_NOTICE);
     }
     $this->config->set_item('language', SITE_LANGUAGE);
     // 网站语言
     date_default_timezone_set('Etc/GMT' . (SITE_TIMEZONE > 0 ? '-' : '+') . abs(SITE_TIMEZONE));
     // 设置时区
     $this->lang->load('member');
     $this->load->model('member_model');
     // 加载会员模型
     $MEMBER = $this->get_cache('member');
     if ($MEMBER['setting']['ucenter'] && is_file(FCPATH . 'member/ucenter/config.inc.php')) {
         include FCPATH . 'member/ucenter/config.inc.php';
         include FCPATH . 'member/ucenter/uc_client/client.php';
     }
     define('MEMBER_OPEN_SPACE', $MEMBER['setting']['space']['open']);
     require ENVIRONMENT . '/database.php';
     foreach ($this->SITE as $sid => $t) {
         $this->site[$sid] = isset($db[$sid]) ? $this->load->database((string) $sid, TRUE) : $this->db;
         // 站点数据库对象
     }
     // 当前登录会员信息
     $this->uid = (int) $this->member_model->member_uid();
     $this->member = $this->member_model->get_member($this->uid);
     // 会员不存在时,uid设置为0
     if (!$this->member) {
         $this->uid = 0;
     }
     // 管理员登陆才显示数据库错误提示
     if ($this->member['adminid'] || IS_ADMIN) {
         $this->db->db_debug = $this->site[SITE_ID]->db_debug = TRUE;
     } else {
         $this->db->db_debug = $this->site[SITE_ID]->db_debug = FALSE;
     }
     // 当前会员组的权限信息
     $this->markrule = $this->member ? $this->member['mark'] : 0;
     $this->member_rule = isset($MEMBER['setting']['permission'][$this->markrule]) ? $MEMBER['setting']['permission'][$this->markrule] : NULL;
     // 当前会员权限规则
     // 当前会员的模块栏目权限规则
     $MOD = $this->get_module(SITE_ID);
     if ($MOD && APP_DIR && $MOD[APP_DIR]['category']) {
         foreach ($MOD[APP_DIR]['category'] as $c) {
             $this->module_rule[$c['id']] = $c['permission'][$this->markrule];
         }
     }
     // 会员域名
     $url = SITE_URL . 'member/';
     if (!$this->mobile && isset($MEMBER['setting']['domain'][SITE_ID]) && $MEMBER['setting']['domain'][SITE_ID]) {
         // 当非移动端时且存在当前站点的会员域名就采用指定的域名
         $url = 'http://' . $MEMBER['setting']['domain'][SITE_ID] . '/';
     }
     define('MEMBER_URL', $url);
     // 会员目录
     $url = '/member/';
     if (!IS_ADMIN) {
         if (IS_MEMBER && isset($MEMBER['setting']['domain'][SITE_ID]) && $MEMBER['setting']['domain'][SITE_ID] && $_SERVER['HTTP_HOST'] == $MEMBER['setting']['domain'][SITE_ID]) {
             // 当是会员中心时且存在当前站点的会员域名就采用绝对根目录
             $url = '/';
         } elseif (APP_DIR && isset($MOD[APP_DIR]['site'][SITE_ID]['domain']) && $MOD[APP_DIR]['site'][SITE_ID]['domain']) {
             // 如果当前是模块且模块绑定了域名那么就采用绝对URL
             $url = MEMBER_URL;
         } elseif (APP_DIR == '' && isset($MEMBER['setting']['space']['domain']) && $MEMBER['setting']['space']['domain']) {
             // 表示空间搜索页绑定域名的情况下
             $url = MEMBER_URL;
         }
     }
     define('MEMBER_PATH', $url);
     // 非移动端时做域名301跳转
     if (!$this->mobile && !defined('DR_UEDITOR') && strpos($_SERVER['REQUEST_URI'], 'm=html') === FALSE) {
         // 会员中心的自定义域名301跳转
         if (IS_MEMBER && $this->router->class != 'api' && $this->router->class != 'home' && isset($MEMBER['setting']['domain'][SITE_ID]) && $MEMBER['setting']['domain'][SITE_ID] && $_SERVER['HTTP_HOST'] != $MEMBER['setting']['domain'][SITE_ID] && strpos($_SERVER['REQUEST_URI'], 'm=html') === FALSE) {
             redirect(MEMBER_URL . trim(str_replace('/member/', '/', $_SERVER['REQUEST_URI']), '/'), '301');
             exit;
         }
         // 模块的自定义域名301跳转
         if (APP_DIR && (!IS_ADMIN && !IS_MEMBER) && isset($MOD[APP_DIR]['site'][SITE_ID]['domain']) && $MOD[APP_DIR]['site'][SITE_ID]['domain'] && $_SERVER['HTTP_HOST'] != $MOD[APP_DIR]['site'][SITE_ID]['domain']) {
             redirect('http://' . $MOD[APP_DIR]['site'][SITE_ID]['domain'] . '/' . trim(str_replace('/' . APP_DIR . '/', '/', $_SERVER['REQUEST_URI']), '/'), '301');
             exit;
         }
     }
     // 会员风格和模板目录
     $theme = $MEMBER['group'][$this->member ? $this->member['groupid'] : 1]['theme'];
     $template = $MEMBER['group'][$this->member ? $this->member['groupid'] : 1]['template'];
     // 风格和模板常量
     define('MEMBER_THEME', $theme ? $theme : 'default');
     define('MEMBER_TEMPLATE', $template ? $template : 'default');
     define('MEMBER_THEME_PATH', MEMBER_URL . 'statics/' . MEMBER_THEME . '/');
     define('MEMBER_MOBILE_PATH', MEMBER_URL . 'mobiles/' . MEMBER_THEME . '/');
     define('HOME_THEME_PATH', SITE_URL . 'dayrui/statics/' . SITE_THEME . '/');
     define('HOME_MOBILE_PATH', SITE_URL . 'dayrui/mobiles/' . SITE_THEME . '/');
     $this->load->library('template');
     $this->load->model('cron_model');
     $this->load->model('system_model');
     // 当网站处于关闭状态时,非管理员无法访问
     if ($site_close && !$this->member['adminid']) {
         $this->msg(SITE_CLOSE_MSG);
     }
     unset($url, $theme, $template, $site_close);
     if (IS_MEMBER) {
         // 会员部分
         $this->load->helper(array('system', 'url'));
         $uri = str_replace('/member/', '/', $this->duri->uri(NULL, TRUE));
         $menu = $this->get_cache('member-menu');
         $this->pagesize = $MEMBER['setting']['pagesize'];
         if ($menu['data']) {
             foreach ($menu['data'] as $i => $t) {
                 if ($t['mark']) {
                     list($a, $dir) = explode('-', $t['mark']);
                     if (!isset($MOD[$dir]) || $MOD[$dir]['setting']['member'][$this->markrule]) {
                         unset($menu['data'][$i]);
                         continue;
                     }
                     // 第一个分组菜单
                     $one = @reset($menu['data'][$i]['left']);
                     $pid = $one['id'];
                     // 判断发布权限
                     if (!$this->_module_post_catid($MOD[$dir])) {
                         if ($one['link']) {
                             foreach ($one['link'] as $o) {
                                 // 过滤无发布权相关的菜单
                                 if (in_array($o['uri'], array($dir . '/home/index', $dir . '/home/flag', $dir . '/back/index', $dir . '/verify/index', $dir . '/everify/index', $dir . '/eback/index'))) {
                                     unset($menu['data'][$i]['left'][$pid]['link'][$o['id']]);
                                 }
                             }
                         }
                     }
                     // 为模块增加表单菜单
                     if ($MOD[$dir]['form'] && $pid) {
                         foreach ($MOD[$dir]['form'] as $f) {
                             $furi = APP_DIR . '/form_' . $f['table'] . '/index';
                             $link = array('id' => $t['id'] . '-' . $f['id'], 'tid' => $i, 'pid' => $pid, 'uri' => $furi, 'name' => dr_lang('m-097', $f['name']));
                             $menu['data'][$i]['left'][$pid]['link'][] = $menu['uri'][$furi] = $link;
                         }
                     }
                 }
                 if ($menu['data'][$i]['left']) {
                     $left = @reset($menu['data'][$i]['left']);
                     if ($left['link']) {
                         $link = @reset($left['link']);
                         if ($link) {
                             $menu['data'][$i]['uri'] = $link['uri'];
                             $menu['data'][$i]['url'] = $link['url'];
                         } else {
                             unset($menu['data'][$i]);
                         }
                     } else {
                         unset($menu['data'][$i]);
                     }
                 } else {
                     unset($menu['data'][$i]);
                 }
             }
         }
         // 当前会员组不允许使用空间时,删除空间菜单
         if ((!MEMBER_OPEN_SPACE || !$this->member['allowspace']) && isset($menu['data'][3])) {
             unset($menu['data'][3]);
         } elseif (!$this->member['spacedomain'] && isset($menu['data'][3]['left']) && $menu['data'][3]['left']) {
             // 当前用户的会员组不允许绑定域名时删除空间域名菜单
             foreach ($menu['data'][3]['left'] as $i => $t) {
                 if (isset($t['link']) && $t['link']) {
                     foreach ($t['link'] as $k => $c) {
                         if ($c['uri'] == 'space/domain') {
                             unset($menu['data'][3]['left'][$i]['link'][$k]);
                             break;
                         }
                     }
                 }
             }
         }
         // 增加内容扩展菜单
         if (strpos($uri, APP_DIR . '/extend/') !== FALSE || preg_match('/^' . APP_DIR . '\\/form_[0-9]+_[0-9]+\\/listc/Ui', $uri)) {
             $cur = $menu['uri'][APP_DIR . '/home/index'];
         } else {
             $cur = isset($menu['uri'][$uri]) ? $menu['uri'][$uri] : $menu['uri'][str_replace(strrchr($uri, '/'), '/index', $uri)];
         }
         // 当当前顶级菜单是应用菜单时统计通知及消息数量
         if ($menu['data'][$cur['tid']]['left']) {
             $find = 0;
             foreach ($menu['data'][$cur['tid']]['left'] as $lid => $left) {
                 if ($left['link']) {
                     foreach ($left['link'] as $mid => $link) {
                         if (strpos($link['uri'], 'pm/index') !== FALSE) {
                             // 统计未读短消息
                             $total = $this->db->where('uid', (int) $this->uid)->where('isnew', 1)->count_all_results('pm_members');
                             $menu['data'][$cur['tid']]['left'][$lid]['link'][$mid]['name'] .= ' (' . $total . ')';
                             $find++;
                         } elseif (strpos($link['uri'], 'notice/index') !== FALSE) {
                             // 统计未读系统提醒
                             $total = $this->db->where('uid', (int) $this->uid)->where('type', 1)->where('isnew', 1)->count_all_results('member_notice_' . (int) $this->member['tableid']);
                             $menu['data'][$cur['tid']]['left'][$lid]['link'][$mid]['name'] .= ' (' . $total . ')';
                             $find++;
                         } elseif (strpos($link['uri'], 'notice/member') !== FALSE) {
                             // 统计未读会员提醒
                             $total = $this->db->where('uid', (int) $this->uid)->where('type', 2)->where('isnew', 1)->count_all_results('member_notice_' . (int) $this->member['tableid']);
                             $menu['data'][$cur['tid']]['left'][$lid]['link'][$mid]['name'] .= ' (' . $total . ')';
                             $find++;
                         } elseif (strpos($link['uri'], 'notice/module') !== FALSE) {
                             // 统计未读模块提醒
                             $total = $this->db->where('uid', (int) $this->uid)->where('type', 3)->where('isnew', 1)->count_all_results('member_notice_' . (int) $this->member['tableid']);
                             $menu['data'][$cur['tid']]['left'][$lid]['link'][$mid]['name'] .= ' (' . $total . ')';
                             $find++;
                         } elseif (strpos($link['uri'], 'notice/app') !== FALSE) {
                             // 统计未读应用提醒
                             $total = $this->db->where('uid', (int) $this->uid)->where('type', 4)->where('isnew', 1)->count_all_results('member_notice_' . (int) $this->member['tableid']);
                             $menu['data'][$cur['tid']]['left'][$lid]['link'][$mid]['name'] .= ' (' . $total . ')';
                             $find++;
                         }
                         if ($find >= 5) {
                             break;
                         }
                     }
                     if ($find >= 5) {
                         break;
                     }
                 }
             }
         }
         $this->template->assign(array('uid' => $this->uid, 'menu' => $menu['data'], 'menu_id' => $cur['id'], 'menu_pid' => $cur['pid'], 'menu_tid' => $cur['tid'], 'meta_name' => $cur['name'], 'regverify' => $MEMBER['setting']['regverify'], 'member_rule' => $this->member_rule));
         // 登录判断
         if (!in_array($this->router->class, array('register', 'login', 'api'))) {
             // 不验证标识
             $verify = TRUE;
             // 支付回调页面不验证
             if (defined('DR_PAY_ID') && DR_PAY_ID) {
                 $verify = FALSE;
             }
             // 会员中心不验证
             if (!APP_DIR && $this->router->class == 'home' && $this->router->method == 'index') {
                 $verify = FALSE;
             }
             // 游客发布权限不验证
             $uri = $this->router->class . '-' . $this->router->method;
             if (APP_DIR && in_array($uri, array('home-add', 'home-field')) && !$this->member) {
                 $verify = FALSE;
             }
             // 待审核会员组
             if ($this->member['groupid'] == 1 && ($this->router->class != 'home' || $this->router->method != 'index')) {
                 $this->member_msg(lang('m-085'));
             }
             $url = MEMBER_URL . SELF . '?c=login&m=index&backurl=' . urlencode(dr_now_url());
             // 没有登录时
             if ($verify && !$this->uid) {
                 $this->member_msg(lang('m-039') . $this->member_model->logout(), $url);
             }
             // 会员不存在时
             if ($verify && !$this->member) {
                 $this->member_msg(lang('m-040') . $this->member_model->logout(), $url);
             }
             if ($this->uid) {
                 $this->member_model->init_member();
                 // 会员验证
                 if (APP_DIR || $uri != 'home-index' && $uri != 'pm-webchat') {
                     if ($MEMBER['setting']['complete'] && !isset($this->member['complete']) && $this->router->class != 'account') {
                         // 是否强制完善资料
                         $this->member_msg(lang('m-154'), dr_url('account/index'), 2, 2);
                     } elseif ($MEMBER['setting']['avatar'] && !$this->member['avatar'] && $this->router->class != 'account') {
                         // 是否强制上传头像
                         $this->member_msg(lang('m-153'), dr_url('account/avatar'), 2, 2);
                     } elseif ($MEMBER['setting']['mobile'] && !$this->member['ismobile'] && $this->router->class != 'account') {
                         // 是否强制手机认证
                         $this->member_msg(lang('m-094'), dr_url('account/index'), 2, 2);
                     }
                 }
             }
         }
     } elseif (IS_ADMIN) {
         // 后台部分
         $this->lang->load('admin');
         $this->lang->load('member');
         $this->lang->load('template');
         $this->load->helper(array('system', 'url'));
         $this->load->model('auth_model');
         $uri = $this->duri->uri();
         $this->admin = $this->is_admin_login();
         if (!$this->is_auth($uri)) {
             if (IS_AJAX) {
                 exit('<img src=' . SITE_URL . 'member/statics/js/skins/icons/error.png>' . dr_lang('049', $uri));
             } else {
                 $this->admin_msg(dr_lang('049', $uri));
             }
         }
         // 后台钩子
         $this->hooks->call_hook('finecms-admin', $uri);
         $this->template->assign('admin', $this->admin);
         // 后台日志
         if (SYS_LOG) {
             $uri = $this->duri->uri();
             // 当前uri
             $data = $this->duri->uri2ci($uri);
             $data['uri'] = $uri;
             $data['url'] = $this->duri->uri2url($uri);
             $data['admin'] = $this->admin['username'];
             $data['time'] = SYS_TIME;
             $data['ip'] = $this->input->ip_address();
             $path = FCPATH . 'cache/optionlog/' . date('Ym', SYS_TIME) . '/';
             $file = $path . date('d', SYS_TIME) . '.log';
             if (!is_dir($path)) {
                 dr_mkdirs($path);
             }
             $log = is_file($file) ? @explode(PHP_EOL, file_get_contents($file)) : array();
             if (IS_POST && !in_array($uri, array('admin/system/index', 'admin/home/index')) && $data['class'] != 'api' && $data['class'] != 'login') {
                 if ($log) {
                     $end = dr_string2array(end($log));
                     if ($end && $end['uri'] == $data['uri'] && $data['admin'] == $end['admin'] && $data['time'] - $end['time'] < 10) {
                         // 10s内的重复操作不记录
                         unset($data);
                     }
                 }
                 // 记录日志
                 if ($data) {
                     file_put_contents($file, PHP_EOL . dr_array2string($data), FILE_APPEND);
                 }
             }
             unset($data, $uri, $path, $file, $log, $end);
         }
         // 后台性能分析
         if (SYS_DEBUG && !IS_AJAX && $this->router->class != 'api') {
             $this->output->enable_profiler(TRUE);
         }
     }
     // 销毁变量
     unset($MOD, $MEMBER);
 }
Example #7
0
 /**
  * Ueditor上传(图片)
  * 向浏览器返回数据json数据
  * {
  *   'url'      :'a.jpg',   //保存后的文件路径
  *   'title'    :'hello',   //文件描述,对图片来说在前端会添加到title属性上
  *   'original' :'b.jpg',   //原始文件名
  *   'state'    :'SUCCESS'  //上传状态,成功时返回SUCCESS,其他任何值将原样返回至图片上传框中
  * }
  * @return void
  */
 public function ueupload()
 {
     if (!$this->uid) {
         exit("{'url':'','title':'','original':'','state':'" . lang('m-039') . "'}");
     }
     // 是否允许上传附件
     if (!$this->member['adminid'] && !$this->member_rule['is_upload']) {
         exit("{'url':'','title':'','original':'','state':'" . lang('m-143') . "'}");
     }
     if (!$this->member['adminid'] && $this->member_rule['attachsize']) {
         // 附件总大小判断
         $data = $this->db->select_sum('filesize')->where('uid', $this->uid)->get('attachment')->row_array();
         $filesize = (int) $data['filesize'];
         if ($filesize > $this->member_rule['attachsize'] * 1024 * 1024) {
             exit("{'url':'','title':'','original':'','state':'" . dr_lang('m-147', $this->member_rule['attachsize'] . 'MB', dr_format_file_size($filesize)) . "'}");
         }
     }
     $path = FCPATH . 'member/uploadfile/' . date('Ym', SYS_TIME) . '/';
     if (!is_dir($path)) {
         dr_mkdirs($path);
     }
     $type = $this->input->get('type');
     $_ext = $type == 'img' ? 'gif|jpg|png' : 'gz|7z|tar|ppt|pptx|xls|xlsx|rar|doc|docx|zip|pdf|txt|swf|mkv|avi|rm|rmvb|mpeg|mpg|ogg|mov|wmv|mp4|webm';
     $this->load->library('upload', array('max_size' => '999999', 'overwrite' => FALSE, 'file_name' => substr(md5(time()), 0, 10), 'upload_path' => $path, 'allowed_types' => $_ext));
     if ($this->upload->do_upload('upfile')) {
         $info = $this->upload->data();
         $this->load->model('attachment_model');
         $result = $this->attachment_model->upload($this->uid, $info);
         if (!is_array($result)) {
             exit('0,' . $result);
         }
         list($id, $file, $_ext) = $result;
         $url = $type == 'file' ? dr_down_file($id) : dr_file($file);
         $title = htmlspecialchars($this->input->post('pictitle', TRUE), ENT_QUOTES);
         exit("{'id':'" . $id . "','fileType':'." . $_ext . "', 'url':'" . $url . "','title':'" . $title . "','original':'" . str_replace('|', '_', $info['client_name']) . "','state':'SUCCESS'}");
     } else {
         exit("{'url':'','title':'','original':'','state':'" . $this->upload->display_errors('', '') . "'}");
     }
 }
 /**
  * 后台日志
  */
 public function system_log($action)
 {
     // 是否开启日志
     if (!SYS_LOG || !IS_ADMIN) {
         return NULL;
     }
     $data = array('ip' => $this->input->ip_address(), 'uid' => $this->admin['uid'], 'time' => SYS_TIME, 'action' => $action, 'username' => $this->admin['username']);
     $path = FCPATH . 'cache/optionlog/' . date('Ym', SYS_TIME) . '/';
     $file = $path . date('d', SYS_TIME) . '.log';
     if (!is_dir($path)) {
         dr_mkdirs($path);
     }
     file_put_contents($file, PHP_EOL . dr_array2string($data), FILE_APPEND);
 }
Example #9
0
    echo json_encode(array('state' => lang('m-143')));
    exit;
}
// 附件总大小判断
if (!$this->member['adminid'] && $this->member_rule['attachsize']) {
    $data = $this->db->select_sum('filesize')->where('uid', $this->uid)->get('attachment')->row_array();
    $filesize = (int) $data['filesize'];
    if ($filesize > $this->member_rule['attachsize'] * 1024 * 1024) {
        echo json_encode(array('state' => dr_lang('m-147', $this->member_rule['attachsize'] . 'MB', dr_format_file_size($filesize))));
        exit;
    }
}
// 上传目录
define('DR_UE_PATH', 'member/uploadfile/ueditor/' . date('Ym', SYS_TIME) . '/');
if (!is_dir(FCPATH . DR_UE_PATH)) {
    dr_mkdirs(FCPATH . DR_UE_PATH);
}
$CONFIG = json_decode(preg_replace("/\\/\\*[\\s\\S]+?\\*\\//", "", file_get_contents("config.json")), true);
$action = $_GET['action'];
switch ($action) {
    case 'config':
        $result = json_encode($CONFIG);
        break;
        /* 上传图片 */
    /* 上传图片 */
    case 'uploadimage':
        /* 上传涂鸦 */
    /* 上传涂鸦 */
    case 'uploadscrawl':
        /* 上传视频 */
    /* 上传视频 */
 /**
  * 远程图片下载
  *
  * @param	array	$data
  * @return  Bool|String
  */
 public function _execute_down_file($data)
 {
     $data = dr_string2array($data);
     if (!$data) {
         return '执行值不存在';
     }
     $path = SYS_UPLOAD_PATH . '/' . date('Ym', SYS_TIME) . '/';
     if (!is_dir($path)) {
         dr_mkdirs($path);
     }
     $file = dr_catcher_data($data['url']);
     if (!$file) {
         return '获取远程数据失败';
     }
     $fileext = strtolower(trim(substr(strrchr($data['url'], '.'), 1, 10)));
     //扩展名
     $filename = substr(md5(time()), 0, 7) . rand(100, 999);
     if (@file_put_contents($path . $filename . '.' . $fileext, $file)) {
         $info = array('file_ext' => '.' . $fileext, 'full_path' => $path . $filename . '.' . $fileext, 'file_size' => filesize($path . $filename . '.' . $fileext) / 1024, 'client_name' => $data['url']);
         $this->load->model('attachment_model');
         $result = $this->attachment_model->upload($data['uid'], $info, $data['id']);
         if (is_array($result)) {
             list($table, $tid, $eid) = explode('-', $result['related']);
             $this->ci->load->model('system_model');
             $tableinfo = $this->ci->system_model->cache();
             // 表结构缓存
             $this->ci->clear_cache('attachment-' . $data['id']);
             // 数据源判断
             if (strpos($table, $this->db->dbprefix($result['siteid'])) === 0) {
                 $db = isset($this->site[$result['siteid']]) ? $this->site[$result['siteid']] : $this->db;
             } else {
                 $db = $this->db;
             }
             $url = dr_get_file($data['id']);
             // 完整地址忽略水印
             $field = $data['field']['fieldname'];
             // 字段名称
             if ($data['field']['relatedname'] == 'module') {
                 // 模块表部分
                 if (strpos($table, '_draft') || strpos($table, '_verify')) {
                     // 草稿和审核表
                     $row = $db->where('id', $tid)->get($table)->row_array();
                     $content = dr_string2array($row['content']);
                     if (isset($content[$field]) && $content[$field]) {
                         $content[$field] = str_replace($data['url'] . '?s=finecms', $url, $content[$field]);
                         $db->where('id', $tid)->update($table, array('content' => dr_array2string($content)));
                     }
                     return TRUE;
                 } else {
                     // 模块表
                     if (!$data['field']['ismain']) {
                         // 附表
                         $index = $db->where('id', $tid)->get($table . '_index')->row_array();
                         $table = $table . '_data_' . intval($index['tableid']);
                     }
                 }
             } elseif ($data['field']['relatedname'] == 'extend') {
                 // 模块扩展表部分
                 if (strpos($table, '_draft') || strpos($table, '_verify')) {
                     // 草稿和审核表
                     $row = $db->where('id', $tid)->get($table)->row_array();
                     $content = dr_string2array($row['content']);
                     if (isset($content[$field]) && $content[$field]) {
                         $content[$field] = str_replace($data['url'] . '?s=finecms', $url, $content[$field]);
                         $db->where('id', $tid)->update($table, array('content' => dr_array2string($content)));
                     }
                     return TRUE;
                 } else {
                     // 内容表
                     if (!$data['field']['ismain']) {
                         // 附表
                         $index = $db->where('id', $tid)->get($table . '_extend_index')->row_array();
                         $table = $table . '_extend_data_' . intval($index['tableid']);
                     }
                 }
             } else {
                 list($dir, $catid) = explode('-', $data['field']['relatedname']);
                 if (is_dir(FCPATH . $dir)) {
                     // 栏目附加字段
                     if (!$data['field']['ismain']) {
                         // 附表
                         $index = $db->where('id', $tid)->get($table . '_index')->row_array();
                         $table = $table . '_category_data_' . intval($index['tableid']);
                     } else {
                         // 主表
                         $table = $table . '_category_data';
                     }
                 }
             }
             // 表结构不存在
             if (!isset($tableinfo[$table]['field'])) {
                 @unlink($info['full_path']);
                 return '表结构不存在:' . $table;
             }
             // 替换操作
             if (isset($tableinfo[$table]['field'][$field])) {
                 $db->query('UPDATE `' . $table . '` SET `' . $field . '` = replace (`' . $field . '`, "' . $data['url'] . '?s=finecms", "' . $url . '")');
             } else {
                 @unlink($info['full_path']);
                 return '表' . $table . '没有字段:' . $field;
             }
             return TRUE;
         } else {
             return $result;
         }
     } else {
         return '文件移动失败,目录无权限(' . $path . ')';
     }
 }
Example #11
0
 /**
  * 生成require N维数组文件
  *
  * @param	array	data
  * @return	int
  */
 public function to_require($data)
 {
     $body = $this->header . $this->note . 'return ';
     $body .= str_replace(array('  ', ' 
 '), array('    ', ' '), var_export($data, TRUE));
     $body .= ';';
     if (!is_dir(dirname($this->file))) {
         dr_mkdirs(dirname($this->file));
     }
     return file_put_contents($this->file, $body);
 }
    echo json_encode(array('state' => lang('m-143')));
    exit;
}
// 附件总大小判断
if (!$this->member['adminid'] && $this->member_rule['attachsize']) {
    $data = $this->db->select_sum('filesize')->where('uid', $this->uid)->get('attachment')->row_array();
    $filesize = (int) $data['filesize'];
    if ($filesize > $this->member_rule['attachsize'] * 1024 * 1024) {
        echo json_encode(array('state' => dr_lang('m-147', $this->member_rule['attachsize'] . 'MB', dr_format_file_size($filesize))));
        exit;
    }
}
// 上传目录
define('DR_UE_PATH', SYS_UPLOAD_PATH . '/ueditor/' . date('Ym', SYS_TIME) . '/');
if (!is_dir(SYS_UPLOAD_PATH)) {
    dr_mkdirs(SYS_UPLOAD_PATH);
}
$CONFIG = json_decode(preg_replace("/\\/\\*[\\s\\S]+?\\*\\//", "", file_get_contents("config.json")), true);
$action = $_GET['action'];
switch ($action) {
    case 'config':
        $result = json_encode($CONFIG);
        break;
        /* 上传图片 */
    /* 上传图片 */
    case 'uploadimage':
        /* 上传涂鸦 */
    /* 上传涂鸦 */
    case 'uploadscrawl':
        /* 上传视频 */
    /* 上传视频 */