Пример #1
0
/**
 * 百度地图调用
 */
function baiduMap($modelid, $name, $value, $width = 600, $height = 400)
{
    if (empty($modelid) || empty($name) || empty($value)) {
        return false;
    }
    $cache = new cache_file();
    $models = array('model', 'membermodel', 'formmodel');
    foreach ($models as $name) {
        $m = $cache->get($name);
        if (isset($m[$modelid])) {
            $t = $m[$modelid];
            break;
        }
    }
    $set = string2array($t['setting']);
    $apikey = isset($set['apikey']) ? $set['apikey'] : '';
    list($lngX, $latY, $zoom) = explode('|', $value);
    $str = "<script type='text/javascript' src='http://api.map.baidu.com/api?v=1.2&key=" . $apikey . "'></script>";
    $str .= '<div id="mapObj" class="view" style="width: ' . $width . 'px; height:' . $height . 'px"></div>';
    $str .= '<script type="text/javascript">';
    $str .= '
	var mapObj=null;
	lngX = "' . $lngX . '";
	latY = "' . $latY . '";
	zoom = "' . $zoom . '";		
	var mapObj = new BMap.Map("mapObj");
	var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
	mapObj.addControl(ctrl_nav);
	mapObj.enableDragging();
	mapObj.enableScrollWheelZoom();
	mapObj.enableDoubleClickZoom();
	mapObj.enableKeyboard();//启用键盘上下左右键移动地图
	mapObj.centerAndZoom(new BMap.Point(lngX,latY),zoom);
	drawPoints();
	';
    $str .= '
	function drawPoints(){
		var myIcon = new BMap.Icon("' . ADMIN_THEME . 'images/mak.png", new BMap.Size(27, 45));
		var center = mapObj.getCenter();
		var point = new BMap.Point(lngX,latY);
		var marker = new BMap.Marker(point, {icon: myIcon});
		mapObj.addOverlay(marker);
	}';
    $str .= '</script>';
    return $str;
}
Пример #2
0
 /**
  * 解析标签list
  */
 protected function _listdata($param)
 {
     $_param = explode(' ', $param);
     $param = array();
     foreach ($_param as $p) {
         $mark = strpos($p, '=');
         if ($p && $mark !== false) {
             $var = substr($p, 0, $mark);
             $val = substr($p, $mark + 1);
             if (isset($var) && $var) {
                 $param[$var] = $val;
             }
         }
     }
     $system = $fields = $_fields = $not = $in = $or = $between = $like = array();
     $dbcache = isset($param['cache']) ? (int) $param['cache'] : 0;
     unset($param['cache']);
     if (is_array($param)) {
         foreach ($param as $key => $val) {
             //参数归类
             if (in_array($key, array('return', 'more', 'page', 'urlrule', 'num', 'join', 'on', 'order', 'table', 'pagesize', 'pagerule', 'action', 'tag', 'extend', 'site', 'form', 'fields'))) {
                 $system[$key] = $val;
             } else {
                 if (substr($key, 0, 3) == 'NOT') {
                     $key = substr($key, 3);
                     $not[] = $key;
                 } elseif (substr($key, 0, 2) == 'OR') {
                     $key = substr($key, 2);
                     $or[] = $key;
                 } elseif (substr($key, 0, 2) == 'IN') {
                     $key = substr($key, 2);
                     $in[] = $key;
                 } elseif (substr($key, 0, 2) == 'BW') {
                     $key = substr($key, 2);
                     $between[] = $key;
                 } elseif (substr($key, 0, 4) == 'LIKE') {
                     $key = substr($key, 4);
                     $like[] = $key;
                 }
                 $fields[$key] = $val;
                 $_fields[] = $key;
             }
         }
     }
     $where = '';
     //设置站点id
     $system['site'] = !isset($system['site']) || empty($system['site']) ? App::get_site_id() : $system['site'];
     //Action判断
     if (isset($system['action']) && $system['action'] == 'position') {
         //推荐位
         $data = position($system['site'], $fields['id'], isset($fields['catid']) ? $fields['catid'] : 0, isset($system['num']) ? $system['num'] : 0);
         if ($data) {
             $db = Controller::model('content');
             foreach ($data as $i => $t) {
                 if ($t['contentid']) {
                     $row = $db->db->where('id', $t['contentid'])->get('content_' . $system['site'])->row_array();
                     $data[$i] = $t + $row;
                 }
             }
         }
         if (isset($system['return']) && $system['return'] && $system['return'] != 't') {
             return array('return_' . $system['return'] => $data, 'total_' . $system['return'] => count($data));
         }
         return array('return' => $data, 'total' => count($data));
     } elseif (isset($system['action']) && $system['action'] == 'keywords') {
         //搜索关键字
         $search = Controller::model('search');
         $num = $system['num'] ? (int) $system['num'] : 5;
         if (isset($system['order']) && $system['order']) {
             $order = null;
             $orders = explode(',', $system['order']);
             foreach ($orders as $t) {
                 list($_field, $_order) = explode('_', $t);
                 if (in_array($_field, array('id', 'keywords', 'addtime', 'total'))) {
                     $_orderby = isset($_order) && strtoupper($_order) == 'ASC' ? 'ASC' : 'DESC';
                     $order .= '`' . $_field . '` ' . $_orderby . ',';
                 }
             }
             if (substr($order, -1) == ',') {
                 $order = substr($order, 0, -1);
             }
         } else {
             $order = '`total` DESC';
         }
         $data = $search->execute('select distinct keywords as title from ' . $search->prefix . 'search order by ' . $order . ' limit ' . $num, true, $dbcache);
         if (isset($system['return']) && $system['return'] && $system['return'] != 't') {
             return array('return_' . $system['return'] => $data, 'total_' . $system['return'] => count($data));
         }
         return array('return' => $data, 'total' => count($data));
     } elseif (isset($system['action']) && $system['action'] == 'sql') {
         //
     } elseif (isset($system['action']) && $system['action'] == 'relation') {
         if (isset($system['tag']) && $system['tag']) {
             //按关键字搜索
             if (isset($fields['id']) && $fields['id']) {
                 $where .= '`id`<>' . (int) $fields['id'];
             }
             $tags = @explode(',', $system['tag']);
             $kwhere = $k = NULL;
             foreach ($tags as $tag) {
                 if ($tag) {
                     if (empty($k)) {
                         $kwhere .= '`title` like "%' . $tag . '%"';
                     } else {
                         $kwhere .= ' OR `title` like "%' . $tag . '%"';
                     }
                     $k = 1;
                 }
             }
             if ($kwhere) {
                 $where .= ' AND (' . $kwhere . ')';
             }
             unset($k, $tags, $tag, $kwhere, $system['table'], $fields['id']);
         } else {
             //手动设置的相关文章
             $data = $this->relation($fields['id'], $system['num']);
             if (isset($system['return']) && $system['return'] && $system['return'] != 't') {
                 return array('return_' . $system['return'] => $data, 'total_' . $system['return'] => count($data));
             }
             return array('return' => $data, 'total' => count($data));
         }
     } elseif (isset($system['action']) && $system['action'] == 'field') {
         //字段信息
         $mods = get_model_data();
         $mod = $mods[$fields['modelid']];
         $data = array();
         if ($mod['fields']) {
             foreach ($mod['fields']['data'] as $t) {
                 if ($fields['name'] == $t['field']) {
                     //加载字段配置文件
                     App::auto_load('fields');
                     $data_fields = '';
                     $data_fields .= '<tr id="fine_' . $t['field'] . '">';
                     $data_fields .= '<th>' . (isset($t['not_null']) && $t['not_null'] ? '<font color="red">*</font> ' : '') . $t['name'] . ':</th>';
                     $data_fields .= '<td>';
                     $func = 'content_' . $t['formtype'];
                     //防止出错,把字段内容转换成数组格式
                     $content = array($fields['value']);
                     $content = var_export($content, true);
                     $field_config = var_export($t, true);
                     if (function_exists($func)) {
                         eval("\$data_fields .= " . $func . "(" . $t['field'] . ", " . $content . ", " . $field_config . ");");
                     }
                     $data_fields .= $t['tips'] ? '<div class="onShow">' . $t['tips'] . '</div>' : '';
                     $data_fields .= '<span id="ck_' . $t['field'] . '"></span>';
                     $data_fields .= '</td>';
                     $data_fields .= '</tr>';
                     $data[0]['form'] = $data_fields;
                     if ($t['setting']) {
                         $c = string2array($t['setting']);
                         if ($c['content']) {
                             $select = explode(PHP_EOL, $c['content']);
                             $vdata = array();
                             foreach ($select as $i => $c) {
                                 list($n, $v) = explode('|', $c);
                                 $vdata[trim($n)] = $v === null ? trim($n) : trim($v);
                             }
                             $data[0]['data'] = $vdata;
                         }
                     }
                 }
             }
         }
         if (isset($system['return']) && $system['return'] && $system['return'] != 't') {
             return array('return_' . $system['return'] => $data);
         }
         return array('return' => $data);
     }
     //主表判断
     if (isset($system['table']) && $system['table']) {
         $table = $system['table'];
     } elseif (isset($system['form']) && $system['form']) {
         $table = 'form_' . $system['site'] . '_' . $system['form'];
     } else {
         $table = 'content';
     }
     //加载Model实例
     if (strpos($table, '.') !== false) {
         list($plugin, $table) = explode('.', $table);
         $db = App::plugin_model($plugin, $table);
     } else {
         $db = Controller::model('content');
         if (strpos($table, 'content') === 0) {
             $table .= '_' . $system['site'];
         }
     }
     $table = $db->prefix . $table;
     $db->table_name = $table;
     $table_join = $table_data = $table_fields = $table_join_fields = $table_data_fields = $arrchilds = null;
     $_table_fields = $db->get_table_fields();
     $table_fields = array_intersect($_fields, $_table_fields);
     //status判断
     if (in_array('status', $_table_fields)) {
         $where .= ($where ? ' AND ' : ' ') . ' `' . $table . '`.`status`=1';
     }
     if (isset($fields['catid']) && $fields['catid']) {
         //栏目信息
         $cats = get_category_data($system['site']);
         $cat = $cats[$fields['catid']];
     }
     if (isset($system['join']) && $system['join'] && $system['on']) {
         //JOIN联合查询
         $table_join = $system['join'];
         //加载Model实例
         if (strpos($table_join, '.') !== false) {
             list($plugin, $table_join) = explode('.', $table_join);
             $db_join = App::plugin_model($plugin, $table_join);
         } else {
             $db_join = Controller::model($table_join);
         }
         $_table_join_fields = $db_join->get_table_fields();
         $table_join_fields = array_intersect($_fields, $_table_join_fields);
         foreach ($table_join_fields as $k => $c) {
             if (in_array($c, $table_fields)) {
                 unset($table_join_fields[$k]);
             }
         }
         $table_join = $db->prefix . $table_join;
     }
     if (isset($system['more']) && $system['more']) {
         //附表
         $model = null;
         if ($table == $db->prefix . 'content_' . $system['site']) {
             $models = get_model_data('content', $system['site']);
             if (isset($fields['catid']) && $fields['catid'] && isset($cat) && $cat) {
                 $model = $models[$cat['modelid']];
             } elseif (isset($fields['modelid']) && $fields['modelid']) {
                 $model = $models[$fields['modelid']];
             }
         } elseif ($table == $db->prefix . 'member' && isset($fields['modelid']) && $fields['modelid']) {
             $cache = new cache_file();
             $models = $cache->get('model_member');
             $model = $models[$fields['modelid']];
         }
         if ($model) {
             $table_data = $model['tablename'];
             $db_data = Controller::model($table_data);
             $_table_data_fields = $db_data->get_table_fields();
             $table_data_fields = array_intersect($_fields, $_table_data_fields);
             foreach ($table_data_fields as $k => $c) {
                 if (in_array($c, $table_fields)) {
                     unset($table_data_fields[$k]);
                 }
             }
             $table_data = $db->prefix . $table_data;
         }
     }
     //WHERE整合
     $fieldsAll = array($table => $table_fields, $table_join => $table_join_fields, $table_data => $table_data_fields);
     foreach ($fieldsAll as $_table => $t) {
         if (is_array($t)) {
             foreach ($t as $f) {
                 if ($fields[$f] == '') {
                     continue;
                 }
                 $and_or = in_array($f, $or) ? 'OR' : 'AND';
                 //栏目条件根据子栏目来做为条件
                 if ($f == 'catid' && isset($fields['catid']) && $fields['catid']) {
                     if (isset($cat) && $cat && $cat['child']) {
                         $arrchilds = $cat['arrchilds'];
                         $not_in = in_array($f, $not) ? 'NOT IN' : 'IN';
                         $where .= ' ' . $and_or . ' `' . $_table . '`.`catid` ' . $not_in . ' (' . $arrchilds . ')';
                     } elseif (strpos($fields['catid'], ',') !== false) {
                         $not_in = in_array($f, $not) ? 'NOT IN' : 'IN';
                         $where .= ' ' . $and_or . ' `' . $_table . '`.`catid` ' . $not_in . ' (' . $fields['catid'] . ')';
                     } else {
                         $not_in = in_array($f, $not) ? '<>' : '=';
                         $where .= ' ' . $and_or . ' `' . $_table . '`.`catid`' . $not_in . $fields['catid'];
                     }
                 } elseif ($f == 'thumb' && isset($fields['thumb']) && is_numeric($fields['thumb'])) {
                     $where .= $fields['thumb'] ? ' ' . $and_or . ' `' . $_table . '`.`thumb`<>""' : ' ' . $and_or . ' `' . $_table . '`.`thumb`=""';
                 } else {
                     $not_in = in_array($f, $in) ? 'IN' : '';
                     $not_in = in_array($f, $not) ? 'NOT IN' : $not_in;
                     if (in_array($f, $between)) {
                         if (strpos($fields[$f], '_') !== false) {
                             list($v1, $v2) = explode('_', $fields[$f]);
                             $v1 = is_numeric($v1) ? $v1 : '"' . addslashes($v1) . '"';
                             $v2 = is_numeric($v2) ? $v2 : '"' . addslashes($v2) . '"';
                             $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '` BETWEEN ' . $v1 . ' AND ' . $v2;
                         } elseif (strpos($fields[$f], ',') !== false) {
                             list($v1, $v2) = explode(',', $fields[$f]);
                             $v1 = is_numeric($v1) ? $v1 : '"' . addslashes($v1) . '"';
                             $v2 = is_numeric($v2) ? $v2 : '"' . addslashes($v2) . '"';
                             $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '` BETWEEN ' . $v1 . ' AND ' . $v2;
                         } else {
                             continue;
                         }
                     } elseif ($not_in) {
                         $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '` ' . $not_in . ' (' . $fields[$f] . ')';
                     } elseif (in_array($f, $like)) {
                         $value = addslashes($fields[$f]);
                         $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '` LIKE "' . $value . '"';
                     } else {
                         $value = is_numeric($fields[$f]) ? $fields[$f] : '"' . addslashes($fields[$f]) . '"';
                         $where .= ' ' . $and_or . ' `' . $_table . '`.`' . $f . '`=' . $value . '';
                     }
                 }
             }
         }
     }
     if ($where) {
         if (substr($where, 0, 4) == ' AND') {
             $where = ' WHERE' . substr($where, 4);
         } elseif (substr($where, 0, 3) == ' OR') {
             $where = ' WHERE' . substr($where, 3);
         } else {
             $where = ' WHERE' . $where;
         }
         //对WHERE延展
         if (isset($system['extend']) && substr($system['extend'], 0, 6) == 'WHERE.') {
             $where .= ' ' . str_replace('-', ' ', substr($system['extend'], 6));
             unset($system['extend']);
         }
     }
     //延展list
     $extend = '';
     if (isset($system['extend']) && $system['extend']) {
         $extend = ' ' . str_replace('-', ' ', $system['extend']);
     }
     //FROM整合
     $from = 'FROM ' . $table;
     if ($table_data) {
         $from .= ' LEFT JOIN ' . $table_data . ' ON `' . $table . '`.`' . $db->get_primary_key() . '`=`' . $table_data . '`.`' . $db_data->get_primary_key() . '`';
     }
     if ($table_join && $system['on']) {
         $_join_name = null;
         if (in_array($system['on'], $_table_fields)) {
             $_join_name = $table;
         } elseif (isset($_table_data_fields) && in_array($system['on'], $_table_data_fields)) {
             $_join_name = $table_data;
         }
         if ($_join_name) {
             $from .= ' LEFT JOIN ' . $table_join . ' ON `' . $table_join . '`.`' . $db_join->get_primary_key() . '`=`' . $_join_name . '`.`' . $system['on'] . '`';
         }
     }
     //ORDER排序
     $order = '';
     if (isset($system['order']) && $system['order']) {
         if (strtoupper($system['order']) == 'RAND()') {
             $order .= ' ORDER BY RAND()';
         } else {
             $orders = explode(',', $system['order']);
             foreach ($orders as $t) {
                 list($_field, $_order) = explode('_', $t);
                 $_name = null;
                 if (in_array($_field, $_table_fields)) {
                     $_name = $table;
                 } elseif (isset($_table_data_fields) && in_array($_field, $_table_data_fields)) {
                     $_name = $table_data;
                 } elseif (isset($_table_join_fields) && in_array($_field, $_table_join_fields)) {
                     $_name = $table_join;
                 }
                 $_orderby = isset($_order) && strtoupper($_order) == 'ASC' ? 'ASC' : 'DESC';
                 if ($_name) {
                     $order .= ' `' . $_name . '`.`' . $_field . '` ' . $_orderby . ',';
                 }
             }
             if (substr($order, -1) == ',') {
                 $order = ' ORDER BY' . substr($order, 0, -1);
             }
         }
     }
     //limit与分页
     $limit = '';
     if (isset($system['num']) && $system['num']) {
         $limit = ' LIMIT ' . $system['num'];
     } elseif (isset($system['page'])) {
         $pageurl = '';
         $system['page'] = (int) $system['page'] ? (int) $system['page'] : 1;
         if ($system['urlrule']) {
             $pageurl = str_replace(array('_page_', '[page]'), '{page}', $system['urlrule']);
             $pagesize = $system['pagesize'] ? $system['pagesize'] : (isset($cat['pagesize']) ? $cat['pagesize'] : 10);
         } elseif ($cat) {
             $pageurl = getCaturl($cat, '{page}');
             $pagesize = $system['pagesize'] ? $system['pagesize'] : $cat['pagesize'];
         } else {
             $pagesize = $system['pagesize'] ? $system['pagesize'] : 10;
             $pageurl = '{page}';
         }
         $sql = 'SELECT count(*) AS total ' . $from . ' ' . $where;
         $count = $db->execute($sql, false, $dbcache);
         $total = $count['total'];
         $pagelist = Controller::instance('pagelist');
         $pagelist->loadconfig($system['pagerule'] ? $system['pagerule'] : 'pagerule');
         $start_id = $pagesize * ($system['page'] - 1);
         $limit = ' LIMIT ' . $start_id . ',' . $pagesize;
         $pagelist = $pagelist->total($total)->url($pageurl)->num($pagesize)->page($system['page'])->output();
     }
     //查询字段筛选
     if (isset($system['fields']) && $system['fields']) {
         $fields_array = explode(',', $system['fields']);
         //字段参数转为数组
         $select_array = array();
         foreach ($fields_array as $t) {
             //遍历字段参数数组,筛选无用字段、字段附加表前缀
             if (in_array($t, $_table_fields)) {
                 //主表字段
                 $select_array[] = '`' . $table . '`.`' . $t . '`';
             } elseif (isset($_table_data_fields) && in_array($t, $_table_data_fields)) {
                 //附表字段
                 $select_array[] = '`' . $table_data . '`.`' . $t . '`';
             } elseif (isset($_table_join_fields) && in_array($t, $_table_join_fields)) {
                 //联合表字段
                 $select_array[] = '`' . $table_join . '`.`' . $t . '`';
             }
         }
         $select_field = empty($select_array) ? ' * ' : ' ' . implode(',', $select_array) . ' ';
         //组合成sql查询格式
         unset($select_array, $fields_array);
     } else {
         $select_field = ' * ';
     }
     //查询结果
     $sql = 'SELECT' . $select_field . $from . $where . $order . $limit . $extend;
     $data = $db->execute($sql, true, $dbcache);
     //释放变量
     unset($_param, $param, $par, $p, $fields, $_fields, $not, $in, $or, $between, $dbcache, $like);
     unset($table, $db, $table_join, $table_data, $table_fields, $table_join_fields, $table_data_fields, $arrchilds, $_table_fields);
     unset($fieldsAll, $_table_data_fields, $cache, $db_join, $cats, $cat, $models, $model, $db_data, $where, $order, $from);
     if (isset($system['return']) && $system['return'] && $system['return'] != 't') {
         return array('sql_' . $system['return'] => $sql, 'total_' . $system['return'] => isset($total) ? $total : count($data), 'return_' . $system['return'] => $data, 'pagelist_' . $system['return'] => $pagelist);
     }
     return array('pagelist' => $pagelist, 'return' => $data, 'sql' => $sql, 'total' => isset($total) ? $total : count($data));
 }
Пример #3
0
 public function indexAction()
 {
     $step = $this->post('step') ? $this->post('step') : 1;
     switch ($step) {
         case '1':
             //说明
             $this->view->assign('percent', '0%');
             $this->view->display('../install/' . $step);
             break;
         case '2':
             //环境
             $pass = true;
             $PHP_VERSION = PHP_VERSION;
             if (version_compare($PHP_VERSION, '5.2.0', '<')) {
                 $php_pass = $pass = false;
             } else {
                 $php_pass = true;
             }
             $mysqli = $PHP_MYSQL = '';
             if (extension_loaded('mysql')) {
                 $PHP_MYSQL = '支持';
                 $mysql_pass = true;
             } elseif (function_exists('mysqli_init')) {
                 $PHP_MYSQL = 'mysqli';
                 $mysqli = mysqli_init();
                 $mysql_pass = true;
             } else {
                 $PHP_MYSQL = '不支持';
                 $mysql_pass = $pass = false;
             }
             $PHP_GD = '';
             if (function_exists('imagejpeg')) {
                 $PHP_GD .= 'jpg';
             }
             if (function_exists('imagegif')) {
                 $PHP_GD .= ' gif';
             }
             if (function_exists('imagepng')) {
                 $PHP_GD .= ' png';
             }
             $gd_pass = $PHP_GD ? true : false;
             $is_json = false;
             $json = '["ok","t2","t3"]';
             if (function_exists('json_decode')) {
                 $json_data = json_decode($json);
                 if ($json_data) {
                     $is_json = true;
                 } else {
                     $pass = false;
                 }
             } else {
                 $json_data = null;
                 $pass = false;
             }
             $this->view->assign(array('php_pass' => $php_pass, 'PHP_MYSQL' => $PHP_MYSQL, 'mysql_pass' => $mysql_pass, 'PHP_GD' => $PHP_GD, 'gd_pass' => $gd_pass, 'pass' => $pass, 'percent' => '20%', 'urlopen' => fn_check_url(), 'is_json' => $is_json, 'json_data' => $json_data));
             $this->view->display('../install/' . $step);
             break;
         case '3':
             //属性
             $ISWIN = strpos(strtoupper(PHP_OS), 'WIN') === false ? false : true;
             $files = array('cache/', 'config/', 'models/', 'uploadfiles/');
             $FILES = array();
             $pass = true;
             foreach ($files as $k => $v) {
                 $FILES[$k]['name'] = $v;
                 if (is_writable(APP_ROOT . $v)) {
                     $FILES[$k]['write'] = true;
                 } else {
                     $FILES[$k]['write'] = $pass = false;
                 }
             }
             $this->view->assign(array('ISWIN' => $ISWIN, 'files' => $files, 'FILES' => $FILES, 'pass' => $pass, 'percent' => '40%'));
             $this->view->display('../install/' . $step);
             break;
         case '4':
             //数据库
             $this->view->assign('percent', '60%');
             $this->view->display('../install/' . $step);
             break;
         case '5':
             //安装进度
             $tdb_host = $this->post('db_host');
             $tdb_user = $this->post('db_user');
             $tdb_pass = $this->post('db_pass');
             $tdb_name = $this->post('db_name');
             $ttb_pre = $this->post('tb_pre');
             $import = $this->post('import');
             $username = $this->post('username');
             $password = $this->post('password');
             $email = $this->post('email');
             function dexit($msg)
             {
                 echo '<script>alert("' . $msg . '");window.history.back();</script>';
                 exit;
             }
             if (!preg_match('/^[a-z0-9]+$/i', $username) || strlen($username) < 4) {
                 dexit('请填写正确的超级管理员户名');
             }
             if (strlen($password) < 4) {
                 dexit('超级管理员密码最少4位');
             }
             if ($this->mysqli) {
                 if (!@mysqli_real_connect($this->mysqli, $tdb_host, $tdb_user, $tdb_pass)) {
                     dexit('无法连接到数据库服务器,请检查配置');
                 }
                 $tdb_name or dexit('请填写数据库名');
                 if (!@mysqli_select_db($this->mysqli, $tdb_name)) {
                     if (!@mysqli_query('CREATE DATABASE ' . $tdb_name)) {
                         dexit('指定的数据库不存在\\n\\n系统尝试创建失败,请通过其他方式建立数据库');
                     }
                     @mysqli_select_db($this->mysqli, $tdb_name);
                 }
                 @mysqli_query($this->mysqli, 'SET NAMES utf8');
             } else {
                 if (!@mysql_connect($tdb_host, $tdb_user, $tdb_pass)) {
                     dexit('无法连接到数据库服务器,请检查配置');
                 }
                 $tdb_name or dexit('请填写数据库名');
                 if (!@mysql_select_db($tdb_name)) {
                     if (!@mysql_query('CREATE DATABASE $tdb_name')) {
                         dexit('指定的数据库不存在\\n\\n系统尝试创建失败,请通过其他方式建立数据库');
                     }
                 }
                 @mysql_query('SET NAMES utf8');
             }
             //保存配置文件
             $content = "<?php" . PHP_EOL . "if (!defined('IN_FINECMS')) exit();" . PHP_EOL . PHP_EOL . "/**" . PHP_EOL . " * 数据库配置信息" . PHP_EOL . " */" . PHP_EOL . "return array(" . PHP_EOL . PHP_EOL;
             $content .= "\t'host'     => '" . $tdb_host . "', " . PHP_EOL;
             $content .= "\t'username' => '" . $tdb_user . "', " . PHP_EOL;
             $content .= "\t'password' => '" . $tdb_pass . "', " . PHP_EOL;
             $content .= "\t'dbname'   => '" . $tdb_name . "', " . PHP_EOL;
             $content .= "\t'prefix'   => '" . $ttb_pre . "', " . PHP_EOL;
             $content .= "\t'charset'  => 'utf8', " . PHP_EOL;
             $content .= "\t'port'     => '', " . PHP_EOL;
             $content .= PHP_EOL . ");";
             if (!file_put_contents(CONFIG_DIR . 'database.ini.php', $content)) {
                 dexit('数据库配置文件保存失败,请检查文件权限!');
             }
             //保存站点域名配置文件
             $site = "<?php" . PHP_EOL . "if (!defined('IN_FINECMS')) exit();" . PHP_EOL . PHP_EOL . "/**" . PHP_EOL . " * 数据库配置信息" . PHP_EOL . " */" . PHP_EOL . "return array(" . PHP_EOL . PHP_EOL;
             $site .= "\t'1'     => '" . strtolower($_SERVER['HTTP_HOST']) . "', " . PHP_EOL;
             $site .= PHP_EOL . ");";
             if (!file_put_contents(CONFIG_DIR . 'site.ini.php', $site)) {
                 dexit('站点配置文件保存失败,请检查文件权限!');
             }
             //导入表结构
             $salt = substr(md5(time()), 0, 10);
             $sql = file_get_contents(APP_ROOT . './cache/install/table.sql');
             $sql = str_replace(array('{username}', '{password}', '{salt}', '{pre}'), array($username, md5(md5($password) . $salt . md5($password)), $salt, $ttb_pre), $sql);
             $this->installsql($sql);
             //导入演示数据
             if ($import) {
                 $sql = file_get_contents(APP_ROOT . './cache/install/data.sql');
                 $sql = str_replace('{pre}', $ttb_pre, $sql);
                 $this->installsql($sql);
             }
             $this->view->assign(array('percent' => '80%', 'username' => $username, 'password' => $password, 'msgs' => array('保存系统配置..................', '数据库连接....................', '创建数据库....................', '创建数据表....................', '设置管理员....................', '安装系统模型..................', '更新模型缓存..................', '更新插件缓存..................', '更新会员模型..................')));
             $this->view->display('../install/' . $step);
             break;
         case '6':
             //安装成功
             $cache = new cache_file();
             $cache->set('install', 1);
             file_put_contents(APP_ROOT . './cache/install.lock', time());
             $this->view->assign(array('percent' => '100%', 'username' => $this->post('username'), 'password' => $this->post('password')));
             $this->view->display('../install/' . $step);
             break;
         case 'db_test':
             $tdb_host = $this->post('tdb_host');
             $tdb_user = $this->post('tdb_user');
             $tdb_pass = $this->post('tdb_pass');
             $tdb_name = $this->post('tdb_name');
             $ttb_pre = $this->post('ttb_pre');
             $ttb_test = $this->post('ttb_test');
             if ($this->mysqli) {
                 if (!@mysqli_real_connect($this->mysqli, $tdb_host, $tdb_user, $tdb_pass)) {
                     exit("<script>alert('无法连接到数据库服务器,请检查配置');</script>");
                 }
                 if (!@mysqli_select_db($this->mysqli, $tdb_name)) {
                     if (!@mysqli_query('CREATE DATABASE ' . $tdb_name)) {
                         exit("<script>alert('指定的数据库(" . $tdb_name . ")不存在,系统尝试创建失败,请通过其他方式建立数据库');</script>");
                     }
                     @mysqli_select_db($this->mysqli, $tdb_name);
                 }
                 @mysqli_query($this->mysqli, 'SET NAMES utf8');
             } else {
                 if (!mysql_connect($tdb_host, $tdb_user, $tdb_pass)) {
                     exit("<script>alert('无法连接到数据库服务器,请检查配置');</script>");
                 }
                 if (!mysql_select_db($tdb_name)) {
                     if (!mysql_query("CREATE DATABASE " . $tdb_name)) {
                         exit("<script>alert('指定的数据库(" . $tdb_name . ")不存在,系统尝试创建失败,请通过其他方式建立数据库');</script>");
                     }
                     mysql_select_db($tdb_name);
                 }
             }
             $tables = array();
             $query = mysql_list_tables($tdb_name);
             while ($r = mysql_fetch_row($query)) {
                 $tables[] = $r[0];
             }
             if (is_array($tables) && in_array($ttb_pre . 'user', $tables)) {
                 if ($ttb_test) {
                     exit('<script>alert("数据库设置正确,连接正常\\n\\n注意:系统检测到您已经安装过' . CMS_NAME . ',如果继续安装将会清空现有数据\\n\\n如果需要保留现有数据,请修改数据表前缀");</script>');
                 } else {
                     exit('<script>alert("警告:系统检测到您已经安装过' . CMS_NAME . ',如果继续安装将会清空现有数据\\n\\n如果需要保留现有数据,请修改数据表前缀");</script>');
                 }
             }
             if ($ttb_test) {
                 exit('<script>alert("数据库设置正确,连接正常");</script>');
             }
             break;
     }
 }
Пример #4
0
 /**
  * 积分处理
  */
 public function credits($userid, $action)
 {
     if (empty($userid)) {
         return false;
     }
     $member = $this->from('member')->where('id=' . $userid)->select(false);
     if (empty($member)) {
         return false;
     }
     $cache = new cache_file();
     $config = $cache->get('member');
     if (isset($config['postcredits']) && $config['postcredits'] && $action == 1) {
         //增加积分
         $credit = $member['credits'] + (int) $config['postcredits'];
     } elseif (isset($config['delcredits']) && $config['delcredits'] && $action == 0) {
         //删除积分
         $credit = $member['credits'] - (int) $config['delcredits'];
     }
     if (isset($credit) && $credit != '') {
         $this->query('update ' . $this->prefix . 'member set credits=' . (int) $credit . ' where id=' . $userid);
     }
 }
Пример #5
0
/**
 * Execute cron tasks
 */
function cron_run()
{
    global $DB, $CFG, $OUTPUT;
    if (CLI_MAINTENANCE) {
        echo "CLI maintenance mode active, cron execution suspended.\n";
        exit(1);
    }
    if (moodle_needs_upgrading()) {
        echo "Moodle upgrade pending, cron execution suspended.\n";
        exit(1);
    }
    require_once $CFG->libdir . '/adminlib.php';
    require_once $CFG->libdir . '/gradelib.php';
    if (!empty($CFG->showcronsql)) {
        $DB->set_debug(true);
    }
    if (!empty($CFG->showcrondebugging)) {
        $CFG->debug = DEBUG_DEVELOPER;
        $CFG->debugdisplay = true;
    }
    set_time_limit(0);
    $starttime = microtime();
    // Increase memory limit
    raise_memory_limit(MEMORY_EXTRA);
    // Emulate normal session - we use admin accoutn by default
    cron_setup_user();
    // Start output log
    $timenow = time();
    mtrace("Server Time: " . date('r', $timenow) . "\n\n");
    // Run cleanup core cron jobs, but not every time since they aren't too important.
    // These don't have a timer to reduce load, so we'll use a random number
    // to randomly choose the percentage of times we should run these jobs.
    srand((double) microtime() * 10000000);
    $random100 = rand(0, 100);
    if ($random100 < 20) {
        // Approximately 20% of the time.
        mtrace("Running clean-up tasks...");
        // Delete users who haven't confirmed within required period
        if (!empty($CFG->deleteunconfirmed)) {
            $cuttime = $timenow - $CFG->deleteunconfirmed * 3600;
            $rs = $DB->get_recordset_sql("SELECT *\n                                             FROM {user}\n                                            WHERE confirmed = 0 AND firstaccess > 0\n                                                  AND firstaccess < ?", array($cuttime));
            foreach ($rs as $user) {
                delete_user($user);
                // we MUST delete user properly first
                $DB->delete_records('user', array('id' => $user->id));
                // this is a bloody hack, but it might work
                mtrace(" Deleted unconfirmed user for " . fullname($user, true) . " ({$user->id})");
            }
            $rs->close();
        }
        // Delete users who haven't completed profile within required period
        if (!empty($CFG->deleteincompleteusers)) {
            $cuttime = $timenow - $CFG->deleteincompleteusers * 3600;
            $rs = $DB->get_recordset_sql("SELECT *\n                                             FROM {user}\n                                            WHERE confirmed = 1 AND lastaccess > 0\n                                                  AND lastaccess < ? AND deleted = 0\n                                                  AND (lastname = '' OR firstname = '' OR email = '')", array($cuttime));
            foreach ($rs as $user) {
                delete_user($user);
                mtrace(" Deleted not fully setup user {$user->username} ({$user->id})");
            }
            $rs->close();
        }
        // Delete old logs to save space (this might need a timer to slow it down...)
        if (!empty($CFG->loglifetime)) {
            // value in days
            $loglifetime = $timenow - $CFG->loglifetime * 3600 * 24;
            $DB->delete_records_select("log", "time < ?", array($loglifetime));
            mtrace(" Deleted old log records");
        }
        // Delete old backup_controllers and logs.
        $loglifetime = get_config('backup', 'loglifetime');
        if (!empty($loglifetime)) {
            // Value in days.
            $loglifetime = $timenow - $loglifetime * 3600 * 24;
            // Delete child records from backup_logs.
            $DB->execute("DELETE FROM {backup_logs}\n                           WHERE EXISTS (\n                               SELECT 'x'\n                                 FROM {backup_controllers} bc\n                                WHERE bc.backupid = {backup_logs}.backupid\n                                  AND bc.timecreated < ?)", array($loglifetime));
            // Delete records from backup_controllers.
            $DB->execute("DELETE FROM {backup_controllers}\n                          WHERE timecreated < ?", array($loglifetime));
            mtrace(" Deleted old backup records");
        }
        // Delete old cached texts
        if (!empty($CFG->cachetext)) {
            // Defined in config.php
            $cachelifetime = time() - $CFG->cachetext - 60;
            // Add an extra minute to allow for really heavy sites
            $DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime));
            mtrace(" Deleted old cache_text records");
        }
        if (!empty($CFG->usetags)) {
            require_once $CFG->dirroot . '/tag/lib.php';
            tag_cron();
            mtrace(' Executed tag cron');
        }
        // Context maintenance stuff
        context_helper::cleanup_instances();
        mtrace(' Cleaned up context instances');
        context_helper::build_all_paths(false);
        // If you suspect that the context paths are somehow corrupt
        // replace the line below with: context_helper::build_all_paths(true);
        mtrace(' Built context paths');
        // Remove expired cache flags
        gc_cache_flags();
        mtrace(' Cleaned cache flags');
        // Cleanup messaging
        if (!empty($CFG->messagingdeletereadnotificationsdelay)) {
            $notificationdeletetime = time() - $CFG->messagingdeletereadnotificationsdelay;
            $DB->delete_records_select('message_read', 'notification=1 AND timeread<:notificationdeletetime', array('notificationdeletetime' => $notificationdeletetime));
            mtrace(' Cleaned up read notifications');
        }
        mtrace("...finished clean-up tasks");
    }
    // End of occasional clean-up tasks
    // Send login failures notification - brute force protection in moodle is weak,
    // we should at least send notices early in each cron execution
    if (!empty($CFG->notifyloginfailures)) {
        notify_login_failures();
        mtrace(' Notified login failured');
    }
    // Make sure all context instances are properly created - they may be required in auth, enrol, etc.
    context_helper::create_instances();
    mtrace(' Created missing context instances');
    // Session gc
    session_gc();
    mtrace("Cleaned up stale user sessions");
    // Run the auth cron, if any before enrolments
    // because it might add users that will be needed in enrol plugins
    $auths = get_enabled_auth_plugins();
    mtrace("Running auth crons if required...");
    foreach ($auths as $auth) {
        $authplugin = get_auth_plugin($auth);
        if (method_exists($authplugin, 'cron')) {
            mtrace("Running cron for auth/{$auth}...");
            $authplugin->cron();
            if (!empty($authplugin->log)) {
                mtrace($authplugin->log);
            }
        }
        unset($authplugin);
    }
    // Generate new password emails for users - ppl expect these generated asap
    if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
        mtrace('Creating passwords for new users...');
        $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.firstname,\n                                                 u.lastname, u.username,\n                                                 p.id as prefid\n                                            FROM {user} u\n                                            JOIN {user_preferences} p ON u.id=p.userid\n                                           WHERE p.name='create_password' AND p.value='1' AND u.email !='' AND u.suspended = 0 AND u.auth != 'nologin'");
        // note: we can not send emails to suspended accounts
        foreach ($newusers as $newuser) {
            if (setnew_password_and_mail($newuser)) {
                unset_user_preference('create_password', $newuser);
                set_user_preference('auth_forcepasswordchange', 1, $newuser);
            } else {
                trigger_error("Could not create and mail new user password!");
            }
        }
        $newusers->close();
    }
    // It is very important to run enrol early
    // because other plugins depend on correct enrolment info.
    mtrace("Running enrol crons if required...");
    $enrols = enrol_get_plugins(true);
    foreach ($enrols as $ename => $enrol) {
        // do this for all plugins, disabled plugins might want to cleanup stuff such as roles
        if (!$enrol->is_cron_required()) {
            continue;
        }
        mtrace("Running cron for enrol_{$ename}...");
        $enrol->cron();
        $enrol->set_config('lastcron', time());
    }
    // Run all cron jobs for each module
    mtrace("Starting activity modules");
    get_mailer('buffer');
    if ($mods = $DB->get_records_select("modules", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
        foreach ($mods as $mod) {
            $libfile = "{$CFG->dirroot}/mod/{$mod->name}/lib.php";
            if (file_exists($libfile)) {
                include_once $libfile;
                $cron_function = $mod->name . "_cron";
                if (function_exists($cron_function)) {
                    mtrace("Processing module function {$cron_function} ...", '');
                    $pre_dbqueries = null;
                    $pre_dbqueries = $DB->perf_get_queries();
                    $pre_time = microtime(1);
                    if ($cron_function()) {
                        $DB->set_field("modules", "lastcron", $timenow, array("id" => $mod->id));
                    }
                    if (isset($pre_dbqueries)) {
                        mtrace("... used " . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries");
                        mtrace("... used " . (microtime(1) - $pre_time) . " seconds");
                    }
                    // Reset possible changes by modules to time_limit. MDL-11597
                    @set_time_limit(0);
                    mtrace("done.");
                }
            }
        }
    }
    get_mailer('close');
    mtrace("Finished activity modules");
    mtrace("Starting blocks");
    if ($blocks = $DB->get_records_select("block", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
        // We will need the base class.
        require_once $CFG->dirroot . '/blocks/moodleblock.class.php';
        foreach ($blocks as $block) {
            $blockfile = $CFG->dirroot . '/blocks/' . $block->name . '/block_' . $block->name . '.php';
            if (file_exists($blockfile)) {
                require_once $blockfile;
                $classname = 'block_' . $block->name;
                $blockobj = new $classname();
                if (method_exists($blockobj, 'cron')) {
                    mtrace("Processing cron function for " . $block->name . '....', '');
                    if ($blockobj->cron()) {
                        $DB->set_field('block', 'lastcron', $timenow, array('id' => $block->id));
                    }
                    // Reset possible changes by blocks to time_limit. MDL-11597
                    @set_time_limit(0);
                    mtrace('done.');
                }
            }
        }
    }
    mtrace('Finished blocks');
    mtrace('Starting admin reports');
    cron_execute_plugin_type('report');
    mtrace('Finished admin reports');
    mtrace('Starting main gradebook job...');
    grade_cron();
    mtrace('done.');
    mtrace('Starting processing the event queue...');
    events_cron();
    mtrace('done.');
    if ($CFG->enablecompletion) {
        // Completion cron
        mtrace('Starting the completion cron...');
        require_once $CFG->libdir . '/completion/cron.php';
        completion_cron();
        mtrace('done');
    }
    if ($CFG->enableportfolios) {
        // Portfolio cron
        mtrace('Starting the portfolio cron...');
        require_once $CFG->libdir . '/portfoliolib.php';
        portfolio_cron();
        mtrace('done');
    }
    //now do plagiarism checks
    require_once $CFG->libdir . '/plagiarismlib.php';
    plagiarism_cron();
    mtrace('Starting course reports');
    cron_execute_plugin_type('coursereport');
    mtrace('Finished course reports');
    // run gradebook import/export/report cron
    mtrace('Starting gradebook plugins');
    cron_execute_plugin_type('gradeimport');
    cron_execute_plugin_type('gradeexport');
    cron_execute_plugin_type('gradereport');
    mtrace('Finished gradebook plugins');
    // Run external blog cron if needed
    if ($CFG->useexternalblogs) {
        require_once $CFG->dirroot . '/blog/lib.php';
        mtrace("Fetching external blog entries...", '');
        $sql = "timefetched < ? OR timefetched = 0";
        $externalblogs = $DB->get_records_select('blog_external', $sql, array(time() - $CFG->externalblogcrontime));
        foreach ($externalblogs as $eb) {
            blog_sync_external_entries($eb);
        }
        mtrace('done.');
    }
    // Run blog associations cleanup
    if ($CFG->useblogassociations) {
        require_once $CFG->dirroot . '/blog/lib.php';
        // delete entries whose contextids no longer exists
        mtrace("Deleting blog associations linked to non-existent contexts...", '');
        $DB->delete_records_select('blog_association', 'contextid NOT IN (SELECT id FROM {context})');
        mtrace('done.');
    }
    //Run registration updated cron
    mtrace(get_string('siteupdatesstart', 'hub'));
    require_once $CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php';
    $registrationmanager = new registration_manager();
    $registrationmanager->cron();
    mtrace(get_string('siteupdatesend', 'hub'));
    // If enabled, fetch information about available updates and eventually notify site admins
    if (empty($CFG->disableupdatenotifications)) {
        require_once $CFG->libdir . '/pluginlib.php';
        $updateschecker = available_update_checker::instance();
        $updateschecker->cron();
    }
    //cleanup old session linked tokens
    //deletes the session linked tokens that are over a day old.
    mtrace("Deleting session linked tokens more than one day old...", '');
    $DB->delete_records_select('external_tokens', 'lastaccess < :onedayago AND tokentype = :tokentype', array('onedayago' => time() - DAYSECS, 'tokentype' => EXTERNAL_TOKEN_EMBEDDED));
    mtrace('done.');
    // all other plugins
    cron_execute_plugin_type('message', 'message plugins');
    cron_execute_plugin_type('filter', 'filters');
    cron_execute_plugin_type('editor', 'editors');
    cron_execute_plugin_type('format', 'course formats');
    cron_execute_plugin_type('profilefield', 'profile fields');
    cron_execute_plugin_type('webservice', 'webservices');
    cron_execute_plugin_type('repository', 'repository plugins');
    cron_execute_plugin_type('qbehaviour', 'question behaviours');
    cron_execute_plugin_type('qformat', 'question import/export formats');
    cron_execute_plugin_type('qtype', 'question types');
    cron_execute_plugin_type('plagiarism', 'plagiarism plugins');
    cron_execute_plugin_type('theme', 'themes');
    cron_execute_plugin_type('tool', 'admin tools');
    // and finally run any local cronjobs, if any
    if ($locals = get_plugin_list('local')) {
        mtrace('Processing customized cron scripts ...', '');
        // new cron functions in lib.php first
        cron_execute_plugin_type('local');
        // legacy cron files are executed directly
        foreach ($locals as $local => $localdir) {
            if (file_exists("{$localdir}/cron.php")) {
                include "{$localdir}/cron.php";
            }
        }
        mtrace('done.');
    }
    // Run automated backups if required - these may take a long time to execute
    require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
    require_once $CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php';
    backup_cron_automated_helper::run_automated_backup();
    // Run stats as at the end because they are known to take very long time on large sites
    if (!empty($CFG->enablestats) and empty($CFG->disablestatsprocessing)) {
        require_once $CFG->dirroot . '/lib/statslib.php';
        // check we're not before our runtime
        $timetocheck = stats_get_base_daily() + $CFG->statsruntimestarthour * 60 * 60 + $CFG->statsruntimestartminute * 60;
        if (time() > $timetocheck) {
            // process configured number of days as max (defaulting to 31)
            $maxdays = empty($CFG->statsruntimedays) ? 31 : abs($CFG->statsruntimedays);
            if (stats_cron_daily($maxdays)) {
                if (stats_cron_weekly()) {
                    if (stats_cron_monthly()) {
                        stats_clean_old();
                    }
                }
            }
            @set_time_limit(0);
        } else {
            mtrace('Next stats run after:' . userdate($timetocheck));
        }
    }
    // cleanup file trash - not very important
    $fs = get_file_storage();
    $fs->cron();
    mtrace("Clean up cached external files");
    // 1 week
    cache_file::cleanup(array(), 60 * 60 * 24 * 7);
    mtrace("Cron script completed correctly");
    $difftime = microtime_diff($starttime, microtime());
    mtrace("Execution took " . $difftime . " seconds");
}
Пример #6
0
    /**
     * Returns information about file in this repository by reference
     * {@link repository::get_file_reference()}
     * {@link repository::get_file()}
     *
     * Returns null if file not found or can not be accessed
     *
     * @param stdClass $reference file reference db record
     * @return null|stdClass containing attribute 'filepath'
     */
    public function get_file_by_reference($reference) {
        $ref = unserialize(base64_decode($reference->reference));
        $url = $this->appendtoken($ref->url);

        if (!$url) {
            // Occurs when the user isn't known..
            return null;
        }

        // We use this cache to get the correct file size.
        $cachedfilepath = cache_file::get($url, array('ttl' => 0));
        if ($cachedfilepath === false) {
            // Cache the file.
            $path = $this->get_file($url);
            $cachedfilepath = cache_file::create_from_file($url, $path['path']);
        }

        if ($cachedfilepath && is_readable($cachedfilepath)) {
            return (object)array('filepath' => $cachedfilepath);
        }
        return null;
    }
Пример #7
0
    public function cron() {
        $fs = get_file_storage();
        $files = $fs->get_external_files($this->id);
        foreach ($files as $file) {
            $reference = unserialize($file->get_reference());

            $cachedfile = cache_file::get($reference);
            if ($cachedfile === false) {
                // Re-fetch resource.
                $this->set_access_key($reference->access_key);
                $this->set_access_secret($reference->access_secret);
                $path = $this->get_file($reference->path);
                cache_file::create_from_file($reference, $path['path']);
            }
        }
    }
Пример #8
0
function get_content_value($content)
{
    if ($content != '' && preg_match('/^\\{M:(.+)\\}$/U', $content, $field)) {
        if (App::get_namespace_id() == 'admin') {
            return null;
        }
        if (!get_cookie('member_id')) {
            return null;
        }
        $member = Controller::model('member');
        $name = trim($field[1]);
        $data = $member->find(get_cookie('member_id'));
        if (isset($data[$name])) {
            return $data[$name];
        }
        $cache = new cache_file();
        $model = $cache->get('model_member');
        $_member = Controller::model($model[$data['modelid']]['tablename']);
        $_data = $_member->find(get_cookie('member_id'));
        if (isset($_data[$name])) {
            return $_data[$name];
        }
    } else {
        return $content;
    }
}