コード例 #1
0
ファイル: functions.php プロジェクト: h3len/Project
function log2file($user, $level, $message, $input, $output = array())
{
    if (!LOG_LEVEL) {
        return;
    }
    if (LOG_FOR_USER != 'ALL' && $user['user_name'] != LOG_FOR_USER) {
        return;
    }
    $level = strtoupper($level);
    $log_level = array('ERROR' => 1, 'DEBUG' => 2, 'ALL' => 3);
    if ($log_level[$level] > LOG_LEVEL) {
        return;
    }
    $log_path = CUR_CONF_PATH . 'data/log/' . date('Y') . '/' . date('m') . '/';
    if (!is_dir($log_path)) {
        hg_mkdir($log_path);
    }
    $input = json_encode($input);
    $output = json_encode($output);
    $time = date('Y-m-d H:i');
    $user = @json_encode($user);
    $log_message_tpl = <<<LC
Level   : {$level}
Message : {$message}
Input   : {$input}
Ouput   : {$output}
Date\t: {$time}
User\t: {$user}


LC;
    hg_file_write($log_path . 'log-' . date('Y-m-d') . '.php', $log_message_tpl, 'a+');
}
コード例 #2
0
ファイル: alive.php プロジェクト: h3len/Project
    /**
     * 生成缓存文件
     * Enter description here ...
     */
    private function get_server_config()
    {
        $alive_filename = $this->settings['alive_filename'] ? $this->settings['alive_filename'] : 'alive';
        $filename = $alive_filename . '.php';
        if (is_file(CACHE_DIR . $filename)) {
            include CACHE_DIR . $filename;
        } else {
            $this->db = hg_ConnectDB();
            $sql = "SELECT id, host, output_dir, input_port, type FROM " . DB_PREFIX . "server_config ";
            $sql .= " WHERE status = 1 ORDER BY id DESC ";
            $q = $this->db->query($sql);
            $return = array();
            while ($row = $this->db->fetch_array($q)) {
                $row['host'] = $row['host'] . ':' . $row['input_port'];
                $return[] = $row;
            }
            $content = '<?php
				if (!IS_READ)
				{		
					exit();
				}
				$return = ' . var_export($return, 1) . ';
			?>';
            hg_file_write(CACHE_DIR . $filename, $content);
        }
        return $return;
    }
コード例 #3
0
ファイル: db.class.php プロジェクト: h3len/Project
function hg_debug_tofile($str, $is_arr = 0, $dir = '', $op_type = 'a+', $tofile = false)
{
    if ($is_arr) {
        $str = var_export($str, true);
    }
    if ($op_type == "a" || $op_type == "a+") {
        $str .= "<br />";
    }
    $tmp_info = debug_backtrace();
    $debug_tree = "";
    $max = count($tmp_info);
    $i = 1;
    foreach ($tmp_info as $debug_info) {
        $space = str_repeat('&nbsp;&nbsp;', $max - $i);
        $debug_tree = "<br />" . $space . $debug_info['file'] . " on line " . $debug_info['line'] . ":" . $debug_tree;
        $i++;
    }
    $str = "<br />" . '[' . date('Y-m-d H:i:s') . ']' . $debug_tree . $str;
    if ($tofile) {
        $filename = $dir ? $dir : LOG_DIR . "log.txt";
        hg_file_write($filename, $str, $op_type);
    } else {
        echo $str;
    }
}
コード例 #4
0
ファイル: debug.php プロジェクト: h3len/Project
function hg_debug_tofile($str = '', $is_arr = 0, $dir = '', $filename = 'log.txt', $op_type = 'a+', $tofile = true)
{
    if ($is_arr) {
        $str = var_export($str, true);
    }
    if ($op_type == "a" || $op_type == "a+") {
        if ($tofile) {
            $entersplit = "\r\n";
        } else {
            $entersplit = "<br />";
        }
    }
    $tmp_info = debug_backtrace();
    $str .= $entersplit;
    $debug_tree = "";
    $max = count($tmp_info);
    $i = 1;
    foreach ($tmp_info as $debug_info) {
        $space = str_repeat('&nbsp;&nbsp;', $max - $i);
        $debug_tree = $entersplit . $space . $debug_info['file'] . " on line " . $debug_info['line'] . ":" . $debug_tree;
        $i++;
    }
    $str = $entersplit . '[' . date('Y-m-d H:i:s') . ']' . $debug_tree . $str;
    if ($tofile) {
        $filename = $filename ? $filename : "log.txt";
        $filenamedir = explode('/', $filename);
        unset($filenamedir[count($filenamedir) - 1]);
        hg_mkdir(LOG_DIR . $dir . implode('/', $filenamedir));
        hg_file_write(LOG_DIR . $dir . $filename, $str, $op_type);
    } else {
        echo $str;
    }
}
コード例 #5
0
ファイル: cache.class.php プロジェクト: h3len/Project
 function buildCache($filename, $content)
 {
     if ($this->menableCache) {
         $this->deleteCache($filename);
         $filename = $this->mcacheDir . md5($filename) . $this->msuffix;
         return hg_file_write($filename, $content);
     } else {
         return false;
         //缓存被禁用
     }
 }
コード例 #6
0
ファイル: cache.class.php プロジェクト: h3len/Project
 function recache($cache_name, $cache_dir = CACHE_DIR)
 {
     if (empty($cache_name)) {
         return false;
     }
     $material_type = $this->get_material_type();
     hg_mkdir($cache_dir);
     $cache_file = $cache_dir . $cache_name;
     hg_file_write($cache_file, serialize($material_type));
     return $material_type;
 }
コード例 #7
0
ファイル: configuare.php プロジェクト: h3len/Project
    function settings_process()
    {
        $basic_settings = $this->input['param']['cloudvideo_basic_set'];
        if (!is_array($basic_settings)) {
            $basic_settings = array();
        }
        $content = '<?php
return $basic_settings = ' . var_export($basic_settings, 1) . ';
?>';
        hg_file_write(DATA_DIR . 'settings.php', $content);
    }
コード例 #8
0
ファイル: template.class.php プロジェクト: h3len/Project
 /**
  * 解析模板,生成模板缓存
  * @param $FileName
  * @return String
  */
 public function ParseTemplate($FileName = '')
 {
     $file = $this->mTemplateDir . $FileName;
     if (!is_file($file)) {
         return false;
     }
     $content = file_get_contents($file);
     $content = $this->ParseNestTemplate($content);
     $cache_file = $this->mTemplateCacheDir . md5($FileName . realpath($this->mTemplateDir)) . '.php';
     hg_file_write($cache_file, $content);
     return $cache_file;
 }
コード例 #9
0
ファイル: functions.class.php プロジェクト: h3len/Project
 function update_cache($v = array(), $cache_dir = CACHE_DIR)
 {
     if (is_string($v) && !empty($v)) {
         $v['name'] = $v;
     }
     if ($v['name']) {
         if (empty($v['value'])) {
             $v['value'] = $this->cache[$v['name']];
         } else {
             $this->cache[$v['name']] = $v['value'];
         }
         $cache_file = $cache_dir . $this->convert_cache_name($v['name'], true) . '.php';
         if ($v['value'] === false) {
             $v['value'] = 0;
         }
         if (!defined('CACHE_INCLUDE')) {
             $content = '<' . '?php exit; ?' . '>' . serialize($v['value']);
         } else {
             $content = '<' . "?php\n\$gCache['{$v['name']}'] = " . var_export($v['value'], true) . ";\n?" . '>';
         }
         hg_file_write($cache_file, $content);
     }
 }
コード例 #10
0
ファイル: update.php プロジェクト: h3len/Project
$rename = @rename($mp4, $source_file);
if (!$rename) {
    error_output('005', '视频权限限制,无法编辑视频');
}
$mediainfo = new mediainfo($source_file);
$source_file_data = $mediainfo->getMeidaInfo();
$source = array();
foreach ($svodid as $k => $vid) {
    $video_dir = hg_num2dir($vid);
    $targerdir = TARGET_DIR . $video_dir . $vid . '.ssm/';
    if ($vid == $vodid) {
        $sourcef = $source_file;
        $data = $source_file_data;
    } else {
        $sourcef = $targerdir . $vid . '.mp4';
        if (!is_file($sourcef)) {
            error_output('006', '指定片段视频不存在');
        }
        $mediainfo->setFile($sourcef);
        $data = $mediainfo->getMeidaInfo();
    }
    $source[] = array('source' => $sourcef, 'start' => intval($start[$k]), 'duration' => intval($duration[$k]), 'mediainfo' => $data);
}
$curl = new curl($gVodApi['host'], $gVodApi['dir'], $gVodApi['token']);
$curl->initPostData();
$conf = $curl->request('vod_config.php');
$gTransApi['filename'] = 'getVideoInfo.php';
$trans_info = array('sourceFile' => $source, 'id' => $video_id, 'vodid' => $vodid, 'targetDir' => $targerdir, 'config' => $conf[0], 'callback' => $gTransApi);
hg_file_write(UPLOAD_DIR . FILE_QUEUE . $vodid, json_encode($trans_info));
$data = array('id' => $video_id, 'vodid' => $vodid, 'trans_info' => $trans_info);
output($data);
コード例 #11
0
ファイル: functions.php プロジェクト: h3len/Project
function hg_update_role_prms($role_ids = '')
{
    $complex = array();
    global $gDB;
    //获取节点和发布栏目的权限
    $sql = 'SELECT * FROM ' . DB_PREFIX . 'role_prms  WHERE admin_role_id IN(' . $role_ids . ')';
    $query = $gDB->query($sql);
    while ($row = $gDB->fetch_array($query)) {
        $temp = array();
        $temp['action'] = trim($row['func_prms']) ? explode(',', $row['func_prms']) : array();
        $temp['nodes'] = strlen($row['node_prms']) ? explode(',', $row['node_prms']) : array();
        $temp['setting'] = $row['setting_prms'];
        $temp['is_complete'] = $row['is_complete'];
        $complex[$row['admin_role_id']]['app_prms'][$row['app_uniqueid']] = $temp;
    }
    //栏目节点
    $sql = 'SELECT publish_prms,extend_prms,id,site_prms FROM ' . DB_PREFIX . 'admin_role WHERE id IN(' . $role_ids . ')';
    $query = $gDB->query($sql);
    while ($publish_prms = $gDB->fetch_array($query)) {
        $complex[$publish_prms['id']]['site_prms'] = $publish_prms['site_prms'] ? explode(',', $publish_prms['site_prms']) : array();
        $complex[$publish_prms['id']]['publish_prms'] = $publish_prms['publish_prms'] ? explode(',', $publish_prms['publish_prms']) : array();
        $complex[$publish_prms['id']]['default_setting'] = $publish_prms['extend_prms'] ? unserialize($publish_prms['extend_prms']) : array();
    }
    if ($complex) {
        foreach ($complex as $role_id => $prms) {
            if (!write_role_prms_to_redis($role_id, json_encode($prms))) {
                $cache_dir = get_prms_cache_dir();
                if (!is_dir($cache_dir)) {
                    hg_mkdir($cache_dir);
                }
                $role_prms_file = get_prms_cache_dir($role_id);
                //$prms = hg_merger_show_node($prms);
                $content = '<?php
/*
权限测试注意事项
1、授权和测试在同一服务器上 因为读取是缓存文件
2、确定自己应用的主模块的标识符号
3、辅助模块 即除了主模块以外的 都是通过settings这个选项判定是否具有增删改查的权限
4、app_prms 存储的是应用标志 主要用于主模块的操作和节点控制
5、site_prms 全站栏目授权
6、publish_prms 控制发布权限 有栏目即即有发布操作权限
7、default_setting 控制其他选项 同之前版本
*/
return ' . var_export($prms, 1) . ';?>';
                hg_file_write($role_prms_file, $content);
            }
        }
    }
    return $complex;
}
コード例 #12
0
ファイル: catalog.core.php プロジェクト: h3len/Project
    public function cache()
    {
        $sql = 'SELECT sort.id as catalog_sort_id,sort.catalog_sort,
		sort.catalog_sort_name,field.id,field.catalog_field,field.remark,
		field.catalog_default,field.selected,field.bak,field.batch,field.required,
		field.zh_name,style.formhtml AS style,style.type FROM ' . DB_PREFIX . 'field AS field 
		LEFT JOIN ' . DB_PREFIX . 'style AS style ON field.form_style=style.id 
		LEFT JOIN ' . DB_PREFIX . 'field_sort AS sort ON sort.id=field.catalog_sort_id WHERE 1  AND field.switch = 1';
        $sql .= " ORDER BY sort.order_id DESC,field.order_id DESC";
        $q = $this->db->query($sql);
        while ($data = $this->db->fetch_array($q)) {
            $data['catalog_field'] = catalog_prefix($data['catalog_field']);
            $default = $data['catalog_default'] = $data['catalog_default'] ? explode(',', $data['catalog_default']) : NULL;
            $data['selected'] = maybe_unserialize($data['selected']);
            if (is_string($data['selected']) && !empty($data['selected'])) {
                $data['selected'] = $this->content_change($data['type'], $data['selected']);
            }
            $datas[$data['catalog_sort']]['catalog_sort_id'] = $data['catalog_sort_id'];
            $datas[$data['catalog_sort']]['catalog_sort_name'] = $data['catalog_sort_name'];
            $datas[$data['catalog_sort']]['catalog_sort'] = $data['catalog_sort'];
            if ($data['type'] == 'text' || $data['type'] == 'textarea') {
                $data['style'] = str_replace(REPLACE_NAME, $data['catalog_field'], $data['style']);
            } elseif ($data['type'] == 'radio') {
                $style = str_replace(REPLACE_NAME, $data['catalog_field'], $data['style']);
                unset($data['style']);
                foreach ($default as $defaults) {
                    $data['style'] .= str_replace(REPLACE_DATA, $defaults, $style);
                }
            } elseif ($data['type'] == 'checkbox') {
                $style = str_replace(REPLACE_NAME, $data['catalog_field'] . '[]', $data['style']);
                unset($data['style']);
                foreach ($default as $defaults) {
                    $data['style'] .= str_replace(REPLACE_DATA, $defaults, $style);
                }
            } elseif ($data['type'] == 'option') {
                $style = $data['style'];
                unset($data['style']);
                foreach ($default as $defaults) {
                    $data['style'] .= str_replace(REPLACE_DATA, $defaults, $style);
                }
                $data['style'] = '<select name=' . $data['catalog_field'] . '><option value>请选择' . $data['zh_name'] . '</option>' . $data['style'] . '</select>';
            } elseif ($data['type'] == 'img') {
                if ($data['batch']) {
                    $data['style'] = str_replace(REPLACE_NAME, $data['catalog_field'] . '[]', $data['style']);
                } else {
                    $data['style'] = str_replace(REPLACE_NAME, $data['catalog_field'], $data['style']);
                }
            } else {
                continue;
            }
            $html = array('catalog_id' => $data['id'], 'zh_name' => $data['zh_name'], 'catalog_field' => $data['catalog_field'], 'remark' => $data['remark'], 'catalog_default' => $data['catalog_default'], 'selected' => $data['selected'], 'bak' => $data['bak'], 'batch' => $data['batch'], 'required' => $data['required'], 'type' => $data['type'], 'style' => $data['style']);
            $datas[$data['catalog_sort']]['html'][$data['catalog_field']] = $html;
            $datas[$data['catalog_sort']]['html'][$data['catalog_field']]['data'] = NULL;
        }
        $text = '<?php $cache=' . var_export($datas, true) . ';?>';
        hg_file_write(CACHE_SORT, $text);
    }
コード例 #13
0
ファイル: template.php プロジェクト: RoyZeng/custom
 private function _changeCss($dir, $root = false)
 {
     if (!$root) {
         $root = $dir;
     }
     if (is_dir($dir) && ($dh = opendir($dir))) {
         while (false !== ($file = readdir($dh))) {
             if ($file != '.' && $file != '..') {
                 if (is_dir($dir . $file . '/')) {
                     $this->_changeCss($dir . $file . '/', $root);
                 } else {
                     if (preg_match('/.css$/', $file)) {
                         $content = file_get_contents($dir . $file);
                         $content = preg_replace("/{\\\$[a-zA-Z0-9_\\[\\]\\-\\'\\>]+}/", RESOURCE_URL, $content);
                         hg_file_write($dir . $file, $content);
                     }
                 }
             }
         }
         closedir($dh);
     }
 }
コード例 #14
0
ファイル: javascript.php プロジェクト: h3len/Project
 function show()
 {
     $hg_ad_js = ADV_DATA_DIR . 'script/hg_ad.js';
     if (!file_exists($hg_ad_js) || $this->input['forcejs']) {
         if (!is_dir(ADV_DATA_DIR . 'script/')) {
             hg_mkdir(ADV_DATA_DIR . 'script/');
         }
         $adjs = file_get_contents('./core/ad.js');
         hg_file_write($hg_ad_js, str_replace('{$addomain}', AD_DOMAIN, $adjs));
     }
     $para = array();
     $para['offset'] = $this->input['offset'] ? intval($this->input['offset']) : 0;
     $para['count'] = $this->input['count'] ? intval($this->input['count']) : 100;
     $para['where'] = urldecode($this->get_condition());
     $para['arcinfo'] = json_decode(urldecode($this->input['vinfo']), true);
     $para['colid'] = hg_filter_ids($this->input['colid']);
     $para['colid'] = $para['colid'] == -1 ? 0 : $para['colid'];
     $dostatistic = true;
     if ($this->input['preview']) {
         $dostatistic = false;
     }
     $ad = new adv();
     $ads = $ad->getAdDatas($para, $dostatistic);
     if ($ads) {
         $outputjs = '';
         foreach ($ads as $k => $r) {
             $_ad = $r;
             if (!is_array($r[0])) {
                 //不存在广告位多个广告
                 $_ad = array(0 => $r);
                 unset($r);
             }
             $_ad_tpl = '';
             foreach ($_ad as $r) {
                 if ($r['mtype'] != 'javascript') {
                     $is_js = 0;
                 } else {
                     $is_js = 1;
                 }
                 $r['param'] = array_merge((array) $r['param']['pos'], (array) $r['param']['ani']);
                 $r['param']['title'] = $r['title'];
                 $r['param']['content'] = build_ad_tpl($r['url'], $r['mtype'], $r['param']);
                 foreach ($r as $k => $v) {
                     if (is_array($v)) {
                         foreach ($v as $kk => $vv) {
                             ${$kk} = $vv;
                         }
                     } else {
                         ${$k} = $v;
                     }
                 }
                 if (!$tpl) {
                     $tpl = '{$content}';
                 }
                 $ad_tpl = stripslashes(preg_replace("/{(\\\$[a-zA-Z0-9_\\[\\]\\-\\'\"\$\\>\\.]+)}/ies", '${1}', $tpl));
                 $ad_tpl = preg_replace("/[\n]+/is", '', $ad_tpl);
                 //通过API进行统计
                 if ($link) {
                     if ($r['mtype'] != 'javascript') {
                         $_ad_tpl .= '<a href="' . AD_DOMAIN . 'click.php?a=doclick&url=' . urlencode($link) . '&pubid=' . $pubid . '" target="_blank">' . $ad_tpl . '</a>';
                     }
                 } else {
                     $_ad_tpl .= $ad_tpl;
                 }
                 if (!$ad_js_para) {
                     $ad_js_para = stripslashes(preg_replace("/{\\\$([a-zA-Z0-9_\\[\\]\\-\\'\"\$\\>\\.]+)}/ies", '${1} . ":\\"" . $${1} . "\\""', str_replace("\r\n", '', $js_para)));
                 }
             }
             $outputjs .= 'hg_AD_AddHtml({para:{' . $ad_js_para . '}, html:"' . addslashes($_ad_tpl) . '",box:"ad_' . $id . '",loadjs:"' . $include_js . '",loadurl:"' . ADV_DATA_URL . 'script/",isjs:' . $is_js . '});';
         }
         header('Content-Type:application/x-javascript');
         echo $outputjs;
     }
 }
コード例 #15
0
ファイル: logindb_update.php プロジェクト: h3len/Project
 public function unset_logindb_cache()
 {
     $id = $this->input['id'];
     if (!$id) {
         $this->errorOutput("无效的数据库服务器");
     }
     if ($id) {
         //禁用的数据库
         $sql = 'UPDATE ' . DB_PREFIX . 'login_server SET status = 0 WHERE id IN(' . $id . ')';
         $this->db->query($sql);
     }
     $sql = 'SELECT host,port,user,pass,`database`,`charset`,`pconnect` FROM ' . DB_PREFIX . 'login_server WHERE status=1 ORDER BY id DESC';
     //$this->errorOutput($sql);
     $query = $this->db->query($sql);
     $cache = array();
     while ($row = $this->db->fetch_array($query)) {
         $cache[] = $row;
     }
     hg_file_write(CACHE_DIR . 'loginserv.php', "<?php\n \$servers = " . var_export($cache, 1) . "\n?>");
     $this->addItem(explode(',', $id));
     $this->output();
 }
コード例 #16
0
ファイル: lottery_update.php プロジェクト: h3len/Project
 /**
  * 云表单使用需要选择模板
  */
 public function generate()
 {
     $id = $this->input['id'];
     if (!$id) {
         $this->errorOutput(NOID);
     }
     $lottery = $this->mode->detail($id);
     if (!$lottery) {
         $this->errorOutput(NO_DATA);
     }
     if (!defined('LOTTERY_DOMAIN') || !LOTTERY_DOMAIN) {
         $this->errorOutput(ERROR_URL);
     }
     $dir = $this->template->get_template($lottery['type']);
     //文件路径加密
     include_once CUR_CONF_PATH . 'lib/XDeode.php';
     $this->script = new XDeode();
     $dir_file = $this->script->encode($lottery['user_id']);
     $filename = $this->script->encode($lottery['id']);
     $lottery['winlist_url'] = $this->settings['winlist_url'];
     $lottery['prize'] = json_encode($lottery['prize']);
     $lottery['assist_url'] = LOTTERY_DOMAIN . $dir['sign'] . '/' . $dir['theme'] . '/' . $dir['id'];
     $lottery['url'] = LOTTERY_DOMAIN . 'lottery.php';
     //生成内容静态页
     $content = $this->template->generation($lottery, $dir['template_file']);
     if (!$content) {
         $this->errorOutput('生成模板失败');
     }
     $html_dir = DATA_DIR . $dir_file . '/';
     if (!is_dir($html_dir)) {
         hg_mkdir($html_dir);
     }
     hg_file_write($html_dir . '/' . $filename . '.html', $content, 'wb+');
     //生成辅助文件
     if (!$this->template->create_file(array('lottery.php'))) {
         $this->errorOutput('生成辅助文件失败');
     }
     //生成js/css/images辅助文件
     if (!$this->template->generate_assist($dir['style_dir'], $dir['sign'], $dir['theme'], $dir['id'])) {
         $this->errorOutput('生成辅助文件失败');
     }
     if (file_exists($html_dir . '/' . $filename . '.html')) {
         $ret['state'] = 1;
         $ret['url'] = LOTTERY_DOMAIN . $dir_file . '/' . $filename . '.html';
     } else {
         $ret['state'] = 0;
     }
     $this->addItem($ret);
     $this->output();
 }
コード例 #17
0
ファイル: node.class.php プロジェクト: h3len/Project
    private function compile_show($nodeapi, $application, $mod_uniqueid = '')
    {
        $api = $this->cal_api($application, $nodeapi);
        $program = '<?php
			$this->curlNode = new curl(\'' . $api['host'] . '\', \'' . $api['dir'] . '\', \'' . $api['token'] . '\');
		';
        $nodeapi['return_var'] = $nodeapi['return_var'] ? $nodeapi['return_var'] : $nodeapi['template'];
        $nodeapi['primary_key'] = $nodeapi['primary_key'] ? $nodeapi['primary_key'] : '_id';
        $program .= '
			$fid = $this->input[\'fid\'];
			$offset = $this->input[\'offset\'];
			$count = $this->input[\'count\'];
			$this->curlNode->setReturnFormat(\'' . $nodeapi['return_type'] . '\');
			$this->curlNode->initPostData();
			$this->curlNode->addRequestData(\'a\', \'' . $nodeapi['func_name'] . '\');
			if (!empty($offset))
			{
				$this->curlNode->addRequestData(\'offset\', $offset);
			}
			if (!empty($count))
			{
				$this->curlNode->addRequestData(\'count\', $count);
			}
			$this->curlNode->addRequestData(\'fid\', $fid);
			$this->curlNode->addRequestData(\'trigger_action\', \'show\');
			$this->curlNode->addRequestData(\'trigger_mod_uniqueid\', \'' . $mod_uniqueid . '\');
			$hg_data = $this->curlNode->request(\'' . $nodeapi['file_name'] . $nodeapi['file_type'] . '\');
			$s = \'hg_' . $nodeapi['return_var'] . '_selected\';
			if ($$s)
			{
				if (!is_array($$s))
				{
					$$s = array($$s);
				}
				$hg_selected_node = implode(\',\', $$s);
				$this->curlNode->initPostData();
				$this->curlNode->addRequestData(\'a\', \'' . $nodeapi['func_name'] . '\');
				$this->curlNode->addRequestData(\'' . $nodeapi['primary_key'] . '\', $hg_selected_node);
				$hg_selected_data = $this->curlNode->request(\'' . $nodeapi['file_name'] . $nodeapi['file_type'] . '\');
				$this->tpl->addVar(\'hg_' . $nodeapi['return_var'] . '_selected\', $hg_selected_data);
			}
			$hg_node_template = \'' . $nodeapi['template'] . '\';
			$extlink = \'&amp;infrm=1\';
			$hg_attr[\'nodeapi\'] = \'fetch_node.php?nid=' . $nodeapi['id'] . '&amp;node_en=' . $nodeapi['node_uniqueid'] . '&amp;mid=\' . $this->input[\'mid\'] . $extlink;
			';
        $program .= '
			$this->tpl->addVar(\'hg_' . $nodeapi['return_var'] . '\', $hg_data);
			$this->tpl->addVar(\'hg_' . $nodeapi['return_var'] . '_attr\', $hg_attr);
			$this->tpl->addVar(\'hg_data\', $hg_data);
			$this->tpl->addVar(\'hg_attr\', $hg_attr);
			';
        if (hg_mkdir($this->mNodedir)) {
            hg_file_write($this->mNodedir . $nodeapi['id'] . '.php', $program);
        } else {
            exit($this->mNodedir . '目录不可写');
        }
        return $this->mNodedir . $nodeapi['id'] . '.php';
    }
コード例 #18
0
ファイル: magic.class.php プロジェクト: h3len/Project
 /**
  * 处理单元、生成单元的html
  * 
  * @param array $info 单元详细信息
  * @param boolean $force 是否强制生成单元缓存
  * @param array $arData 数据、有此参数时用该数据生成单元hmtl 用于单元预览
  * @param array 处理过后的单元详细信息
  */
 public function cellProcess($info, $force = false, $arData = array())
 {
     if (!$info['cell_mode']) {
         //return array();
     }
     /**********专题栏目链接处理***************************/
     if (strpos($info['more_href'], 'COLURL') !== false) {
         $intColumnId = intval(str_replace('COLURL', '', $info['more_href']));
         if (!class_exists('special')) {
             include ROOT_PATH . 'lib/class/special.class.php';
         }
         $objSpecial = new special();
         $info['more_href'] = $objSpecial->get_special_col_url($intColumnId);
     }
     /**********专题栏目链接处理***************************/
     $mode_info = common::get_mode_info(intval($info['cell_mode']), $info['id'], intval($info['css_id']), intval($info['js_id']), $info['param_asso']);
     $blBuiltCell = $this->blBuiltCell && $this->blBuiltCell !== 'false' ? 1 : 0;
     if ($info['cell_type'] == 3 && $blBuiltCell) {
         $html = $info['static_html'];
     } else {
         $content = $mode_info['mode_info']['content'];
         $content = str_replace('&nbsp;', ' ', $content);
         $ret_data = array();
         if (!$info['data_source']) {
             $map = common::get_mode_map($mode_info);
             if ($blBuiltCell) {
                 $ret_data = !empty($arData) ? $arData : $mode_info['mode_info']['default_param'];
             }
             $ret_data = $info['using_block'] ? common::getBlockData($info['block_id']) : $ret_data;
         } else {
             $data_source = common::get_datasource_info($info['data_source'], $info['param_asso']);
             if ($info['using_block'] && $blBuiltCell) {
                 $ret_data = !empty($arData) ? $arData : common::getBlockData($info['block_id']);
             } else {
                 $map = common::get_cell_map($mode_info, $data_source, $info['param_asso']);
                 if ($blBuiltCell) {
                     $ret_data = common::get_content_by_datasource($info['data_source'], $map['data_input_variable']);
                     if (isset($ret_data['total'])) {
                         $intTotal = $ret_data['total'];
                         $ret_data = $ret_data['data'];
                     }
                     if (!$info['layout_id']) {
                         //替换已经编辑过的单元数据
                         if (!class_exists('cell')) {
                             include CUR_CONF_PATH . 'lib/cell.class.php';
                         }
                         $objCell = new cell();
                         $arCellData = $objCell->getCellData($info['id']);
                         if (is_array($ret_data) && count($ret_data) > 0) {
                             foreach ($ret_data as $k => $v) {
                                 !empty($arCellData[$v['id']]) && ($arCellData[$v['id']]['id'] = $arCellData[$v['id']]['content_id']);
                                 $ret_data[$k] = !empty($arCellData[$v['id']]) ? $arCellData[$v['id']] : $v;
                                 if (!empty($arData)) {
                                     if ($v['id'] == $arData['content_id']) {
                                         //arData 预览提交的数据
                                         $arData['id'] = $arData['content_id'];
                                         $ret_data[$k] = $arData;
                                     }
                                 }
                             }
                         }
                     }
                     if (isset($intTotal)) {
                         $ret_data = array('total' => $intTotal, 'data' => $ret_data);
                     }
                 }
             }
         }
         $cache_file = $info['layout_id'] ? $info['id'] . '_' . $info['layout_id'] . '.php' : $info['id'] . '.php';
         $cache_filepath = MODE_CACHE_DIR . substr(md5($cache_file), 0, 2) . '/';
         include_once CUR_CONF_PATH . 'lib/parse.class.php';
         $parse = new Parse();
         $parse->parse_template(stripcslashes($content), $info['id'], $mode_info['mode_info'], $map['relation_map'], $map['mode_variable_map'], $map['variable_function_relation']);
         if ($blBuiltCell) {
             if (MAGIC_DEBUG) {
                 $path = CUR_CONF_PATH . 'cache/log/data/';
                 hg_mkdir($path);
                 hg_file_write($path . $info['id'] . '.txt', var_export($map['data_input_variable'], 1) . var_export($ret_data, 1));
             }
             $html = $parse->built_cell_html($ret_data, $cache_file, $mode_info['mode_info'], $this->arNeedPageInfo, $this->arPageSiteInfo, $this->arPageColumnInfo, $this->arPageClientInfo, $this->arPageSpecialInfo, $this->arPageSpecialColumnInfo, $map['data_input_variable'], $force, $cache_filepath);
             if ($info['is_header']) {
                 $find = array('{$header_text}', '{$more_href}', '{$more_text}');
                 $replace = array($info['header_text'], $info['is_more'] ? $info['more_href'] : '#', $info['is_more'] ? '更多>>' : '');
                 $header = str_replace($find, $replace, $this->settings['header_dom']['cell']);
                 $html = $header . $html;
             }
             // if (empty($ret_data)) {
             // $html = '<span>暂无数据</span>' . $html;
             // }
         } else {
             $parse->built_mode_cache($cache_file, $cache_filepath);
         }
     }
     $ret = array();
     $ret = array_merge($info, $mode_info);
     $ret['mode_detail'] = $ret['mode_info'];
     //生成时用
     unset($ret['mode_info']);
     !$ret['using_block'] && $ret['data_source'] && ($ret['can_edit'] = 1);
     //有数据源且不是区块单元时单元数据可编辑
     $ret['rended_html'] = $html;
     $ret['input_param'] = $data_source['input_param'];
     $ret['site_id'] = $this->intSiteId;
     $ret['page_id'] = $this->intPageId;
     $ret['page_data_id'] = $this->intPageDataId;
     $ret['content_type'] = $this->intContentType;
     if ($blBuiltCell) {
         $strNsPre = $ret['layout_id'] ? 'layout_cell' : 'cell';
         $ret['css'] = str_replace('<MATEURL>', ICON_URL, preg_replace('/<NS([0-9a-zA-Z]*)>/', '.' . $strNsPre . '_' . $ret['id'] . '_\\1', $ret['css']));
         $ret['js'] = str_replace('<MATEURL>', ICON_URL, preg_replace('/<NS([0-9a-zA-Z]*)>/', '.' . $strNsPre . '_' . $ret['id'] . '_\\1', $ret['js']));
         $ret['rended_html'] = str_replace('<MATEURL>', ICON_URL, preg_replace('/<NS([0-9a-zA-Z]*)>/', $strNsPre . '_' . $ret['id'] . '_\\1', $ret['rended_html']));
         $ret['css'] = preg_replace('/<NNS([0-9a-zA-Z]*)>/', $strNsPre . '_' . $ret['id'] . '_\\1', $ret['css']);
         $ret['js'] = preg_replace('/<NNS([0-9a-zA-Z]*)>/', $strNsPre . '_' . $ret['id'] . '_\\1', $ret['js']);
         $ret['rended_html'] = preg_replace('/<NNS([0-9a-zA-Z]*)>/', $strNsPre . '_' . $ret['id'] . '_\\1', $ret['rended_html']);
         if ($this->input['data'] == 1 || $this->input['return_data'] == 1) {
             if (is_array($ret_data) && count($ret_data) > 0) {
                 foreach ($ret_data as $k => $v) {
                     $ret['data'][] = array('id' => $v['id'], 'title' => $v['title'], 'brief' => $v['brief'], 'indexpic' => $v['indexpic'], 'content_url' => $v['content_url']);
                 }
             }
         }
     }
     return $ret;
 }
コード例 #19
0
ファイル: functions.php プロジェクト: h3len/Project
function hg_cache_outputxml($filepath = '', $filename = '', $content = '')
{
    if (!CACHE_TIME) {
        return;
    }
    if (!$filename || !$filepath) {
        return false;
    }
    if (hg_mkdir($filepath)) {
        hg_file_write($filepath . $filename . '.xml', $content);
    }
}
コード例 #20
0
ファイル: VideoUpdate.php プロジェクト: h3len/Project
 public function uploadVideo()
 {
     $params['cate_id'] = $this->input['cate_id'];
     if ($params['cate_id'] && ($categoryVideoNumMax = $this->settings['categoryVideoNumMax'])) {
         $sql = 'select count(*) as total from ' . DB_PREFIX . 'video where 1 and cate_id = ' . $params['cate_id'] . ' and user_id = ' . $this->user['user_id'];
         $total = $this->db->query_first($sql);
         if ($total['total'] > $categoryVideoNumMax) {
             $this->errorOutput('此专辑内视频已达上限');
         }
     }
     $re = $this->upload();
     if (!is_array($re[0])) {
         $this->errorOutput(NO_VIDEO_UPLOAD);
     }
     //视频video_id
     $params['id'] = $re[0]['id'];
     $params['title'] = $re[0]['title'];
     //视频img
     $params['img']['host'] = $re[0]['img']['host'];
     $params['img']['dir'] = $re[0]['img']['dir'];
     $params['img']['filepath'] = $re[0]['img']['filepath'];
     $params['img']['filename'] = $re[0]['img']['filename'];
     $text = '<?php return ' . var_export($params, true) . ';?>';
     $filePath = CACHE_DIR . 'uploadVideo_' . $params['id'] . '.php';
     hg_file_write($filePath, $text);
     $cache_file = CUR_CONF_PATH . $filePath;
     if (!file_exists($cache_file)) {
         $this->errorOutPut(CACHE_ERROR);
     }
     $this->addItem($params);
     $this->output();
 }
コード例 #21
0
ファイル: sys.php プロジェクト: h3len/Project
    /**
     * 取频道、频道流、信号
     * 返回 三者合并后的信息
     * 缓存一份数据到 cache 目录
     * Enter description here ...
     */
    public function get_old_live_info()
    {
        $timenow = $this->input['timenow'] ? intval($this->input['timenow']) : TIMENOW;
        //频道信息
        $sql = "SELECT * FROM " . DB_PREFIX . "channel ";
        $sql .= " WHERE 1 ORDER BY id ASC ";
        $q = $this->db->query($sql);
        $channel = $channel_id = $stream_id = array();
        while ($row = $this->db->fetch_array($q)) {
            $row['stream_info_all'] = @unserialize($row['stream_info_all']);
            $row['logo_info'] = @unserialize($row['logo_info']);
            $row['logo_mobile_info'] = @unserialize($row['logo_mobile_info']);
            $row['column_id'] = @unserialize($row['column_id']);
            $row['column_url'] = @unserialize($row['column_url']);
            $channel_id[] = $row['id'];
            $stream_id[] = $row['stream_id'];
            $channel[] = $row;
        }
        //频道流
        if (!empty($channel_id)) {
            $sql = "SELECT * FROM " . DB_PREFIX . "channel_stream ";
            $sql .= " WHERE channel_id IN (" . implode(',', $channel_id) . ") ORDER BY id ASC ";
            $q = $this->db->query($sql);
            $channel_stream = array();
            while ($row = $this->db->fetch_array($q)) {
                $channel_stream[$row['channel_id']][] = $row;
            }
        }
        //信号
        if (!empty($stream_id)) {
            $sql = "SELECT * FROM " . DB_PREFIX . "stream ";
            $sql .= " WHERE id IN (" . implode(',', $stream_id) . ") ORDER BY id ASC ";
            $q = $this->db->query($sql);
            $stream = array();
            while ($row = $this->db->fetch_array($q)) {
                $row['uri'] = @unserialize($row['uri']);
                $row['other_info'] = @unserialize($row['other_info']);
                $stream[$row['id']] = $row;
            }
        }
        //频道流合并信号
        $channel_stream_info = array();
        if (!empty($channel_stream)) {
            foreach ($channel_stream as $k => $v) {
                foreach ($v as $kk => $vv) {
                    $v[$kk]['input_id'] = 0;
                    $v[$kk]['url'] = '';
                    $v[$kk]['bitrate'] = '';
                    foreach ($stream[$vv['stream_id']]['other_info']['input'] as $kkk => $vvv) {
                        if ($vv['stream_name'] == $vvv['name']) {
                            $v[$kk]['url'] = $vvv['uri'];
                            $v[$kk]['bitrate'] = $vvv['bitrate'];
                            $v[$kk]['input_id'] = $vvv['id'];
                        }
                    }
                }
                $channel_stream_info[$k] = $v;
            }
        }
        //取直播配置
        $config = $this->get_server_config();
        $server_config = array();
        if (!empty($config)) {
            foreach ($config as $k => $v) {
                $tmp = array('protocol' => 'http://', 'host' => $v['core_in_host'] ? $v['core_in_host'] : $v['host'], 'input_port' => $v['core_in_port'] ? $v['core_in_port'] : $v['input_port'], 'output_port' => $v['core_out_port'] ? $v['core_out_port'] : $v['output_port'], 'input_dir' => $v['input_dir'], 'output_dir' => $v['output_dir']);
                $server_config[$v['id']] = $tmp;
            }
        }
        //频道合并频道流
        $return = array();
        if (!empty($channel)) {
            foreach ($channel as $k => $v) {
                $v['channel_stream'] = $channel_stream_info[$v['id']];
                $v['server_config'] = $server_config[$v['server_id']];
                $v['is_push'] = $stream[$v['stream_id']]['wait_relay'];
                $return[] = $v;
            }
        }
        //缓存数据到cache目录
        if ($this->input['is_cache']) {
            $dir = CACHE_DIR . 'sys';
            $filename = $timenow . '_live.php';
            if (!is_dir($dir)) {
                hg_mkdir($dir);
            }
            $content = '<?php
				if (!IS_READ)
				{		
					exit();
				}
				$channel = ' . var_export($channel, 1) . ';
				$channel_stream = ' . var_export($channel_stream, 1) . ';
				$stream = ' . var_export($stream, 1) . ';
				$return = ' . var_export($return, 1) . ';
			?>';
            hg_file_write($dir . '/' . $filename, $content);
        }
        //缓存数据到cache目录
        $this->addItem($return);
        $this->output();
    }
コード例 #22
0
ファイル: app_template.php プロジェクト: h3len/Project
 /**
  * 生成文件
  *
  * @access private
  * @param  $url | $dir
  *
  * @return array
  */
 private function generate($url, $dir)
 {
     $content = file_get_contents($url);
     $filename = $dir . '/' . time() . '.zip';
     if (!hg_file_write($filename, $content)) {
         return false;
     }
     //解压缩文件并删除压缩包文件
 }
コード例 #23
0
ファイル: pm25.php プロジェクト: h3len/Project
 /**
  * 获取一个城市所有监测点的PM2.5数据
  * city:城市名称,必选参数
  * avg:是否返回一个城市所有监测点数据均值的标识,可选参数,默认是true,不需要均值时传这个参数并设置为false
  * stations:是否只返回一个城市均值的标识,可选参数,默认是yes,不需要监测点信息时传这个参数并设置为no
  */
 function pm25data()
 {
     $cache_lock = CACHE_DIR . 'PM2.5.lock';
     if (!file_exists($cache_lock) || TIMENOW - fileatime($cache_lock) > CACHE_TIME) {
         $this->mUpdateCache = 1;
     }
     if (!($pmdata = $this->pm25core->get_pm25_data()) || $this->mUpdateCache) {
         $parameters = array('city' => $this->mCity, 'avg' => 'true', 'stations' => 'yes');
         $this->setUrl($this->settings['pm25api']['pm25data']);
         $this->setRequestParameters($parameters);
         $data = $this->request();
         $avg = end($data);
         unset($data[array_search($avg, $data)]);
         $this->pm25core->update_pm25_data($avg, $data, $avg['time_point']);
         foreach ($data as $val) {
             $_data[$val['station_code']] = $val;
         }
         $pmdata = array();
         $pmdata['avg'] = $avg;
         $pmdata['stations'] = $_data;
         hg_file_write($cache_lock, $avg['time_point']);
     }
     foreach ($pmdata as $key => $val) {
         $this->addItem_withkey($key, $val);
     }
     $this->output();
 }
コード例 #24
0
ファイル: create.php プロジェクト: h3len/Project
    $vod['aspect'] = $data['Video']['Display aspect ratio'];
    $vod['frame_rate'] = $data['Video']['Frame rate'];
    $vod['img_src'] = THUMB_URL . $video_dir . $last_id . '.ssm/preview.jpg';
    include_once ROOT_DIR . 'lib/curl.class.php';
    $curl = new curl($gVodApi['host'], $gVodApi['dir'] . 'admin/', $gVodApi['token']);
    $curl->initPostData();
    $curl->setSubmitType('post');
    foreach ($vod as $k => $v) {
        $curl->addRequestData($k, $v);
    }
    $curl->addRequestData('a', 'create');
    $ret = $curl->request('vod_update.php');
    if (is_array($ret)) {
        $vodid = intval($ret[0]['id']);
        file_put_contents('../tmp/t.txt', $vodid);
    }
}
$curl = new curl($gVodApi['host'], $gVodApi['dir'], $gVodApi['token']);
$curl->initPostData();
$conf = $curl->request('vod_config.php');
$gTransApi['filename'] = 'getVideoInfo.php';
$trans_info = array('sourceFile' => array(array('source' => UPLOAD_DIR . $filepath, 'mediainfo' => $data)), 'id' => $vodid, 'force_codec' => intval($_INPUT['force_codec']), 'vodid' => $last_id, 'video_id' => $last_id, 'targetDir' => $targerdir, 'config' => $conf[0], 'callback' => $gTransApi);
hg_file_write(UPLOAD_DIR . FILE_QUEUE . $last_id, json_encode($trans_info));
hg_file_write($targerdir . 'source_media_info', json_encode($data));
$video_list_file = 'video_' . date('Ymd') . '.list';
file_put_contents(UPLOAD_DIR . $video_list_file, $last_id . ';', FILE_APPEND);
$filesize = $_FILES['videofile']['size'];
$data = array('id' => $vodid ? $vodid : $last_id, 'vodid' => $last_id, 'type' => $filetype, 'size' => $filesize, 'vod_leixing' => $_INPUT['vod_leixing'] ? $_INPUT['vod_leixing'] : 1, 'vod_sort_id' => $_INPUT['vod_sort_id'], 'filepath' => $_INPUT['vod_sort_id'], 'image' => THUMB_URL . $video_dir . $last_id . '.ssm/preview.jpg', 'server' => defined('SERVER_NAME') ? SERVER_NAME : 'codec1');
$data = $data + $_INPUT;
//视频上传成功,返回视频id
output($data);
コード例 #25
0
ファイル: template.php プロジェクト: h3len/Project
 /**
  * 获取模板信息
  *
  */
 private function fetchTemplates($template_name)
 {
     $this->initRequestData();
     $this->addRequestData('softvar', $this->mSoftVar);
     $this->addRequestData('group', $this->mTemplateGroup);
     $this->addRequestData('template', $template_name);
     $ret = $this->post(TEMPLATE_API, $this->mRequestData);
     if (hg_mkdir(TEMPLATE_DIR . $this->mSoftVar . '/')) {
         hg_file_write(TEMPLATE_DIR . $this->mSoftVar . '/' . $template_name . '.php', $ret);
     } else {
         exit(TEMPLATE_DIR . $this->mSoftVar . '/目录创建失败,请检查目录权限.');
     }
 }
コード例 #26
0
ファイル: index.php プロジェクト: h3len/Project
    $app = @array_pop($serv['app']);
    $app = $app['app'];
    include 'tpl/head.tpl.php';
    include 'tpl/complete.tpl.php';
    include 'tpl/foot.tpl.php';
}
if ($action == 'rebuild') {
    $i = 0;
    foreach ($servers as $id => $v) {
        $i++;
        $v['id'] = $i;
        $servers[$i] = $v;
    }
    $servers = json_encode($servers);
    hg_file_write('db/server.' . $customer, $servers);
    hg_file_write('db/autoid', $i);
    header('Location:./index.php');
}
if ($action == 'test') {
}
$gDomains = array();
$IMGAPIDOMAIN = $VODDOMAIN = '';
function hg_app_parse_domain($typ, $data)
{
    if (!$data) {
        return;
    }
    global $gDomains;
    $ip = $data['ip'];
    $info = $data[$typ];
    unset($data[$typ]);
コード例 #27
0
ファイル: download.php プロジェクト: h3len/Project
    public function banword()
    {
        $file_dir = CACHE_DIR;
        $file_name = 'example.txt';
        $file_path = $file_dir . $file_name;
        $str = '贪官={BANNED}
賽馬會={BANNED}
谱尼测试科技={BANNED}
谁能赢得这辆女性车你说了算={BANNED}
证件集团=无聊之事不足信
证件文凭=无聊之事不足信
论文发表={BANNED}
论文代写={BANNED}
论坛自动发贴机={BANNED}
论坛群发软件={BANNED}
论坛发贴工具={BANNED}
讨伐中宣部={BANNED}
言論自由={BANNED}
解码器=decode器
解决台湾={BANNED}
见证一个假农民形成的可悲历程={BANNED}
西藏独立={BANNED}
裸聊合法={BANNED}
裸体=**
装饰图纸类=**';
        hg_file_write($file_path, $str);
        if (!file_exists($file_path)) {
            echo '文件不存在';
            exit;
        }
        $download_file = TIMENOW . '.txt';
        header("Content-type: application/octet-stream");
        header("Accept-Ranges: bytes");
        header("Accept-Length: " . filesize($file_path));
        header("Content-Disposition: attachment; filename=" . $download_file);
        readfile($file_path);
        @unlink($file_path);
    }
コード例 #28
0
ファイル: mkpublish.php プロジェクト: h3len/Project
 public function file_in()
 {
     $filepath = $this->input['filepath'];
     $filename = $this->input['filename'];
     $content = $this->input['content'];
     if (!$filepath && !$filename) {
         $this->errorOutput('NO PARAM');
     }
     if (!hg_mkdir($filepath)) {
         $this->errorOutput('目录创建失败');
     }
     if (!hg_file_write($filepath . $filename, $content)) {
         $this->errorOutput('文件写入失败');
     }
     $ret = array('msg' => 'sucess');
     $this->addItem($ret);
     $this->output();
 }
コード例 #29
0
ファイル: check_transcoding.php プロジェクト: h3len/Project
if (!in_array($_INPUT['auth'], $gToken)) {
    error_output('009', '通信令牌错误');
}
$content = @file_get_contents(TRANSCODE_STAT);
$info = json_decode($content, true);
if ($info['files']) {
    $script = explode('/', TRANSCODE_SCRIPT);
    $cmd = PSCMD . $script[count($script) - 1];
    exec($cmd, $out, $t);
    $pid = intval($out[0]);
    if (!$pid) {
        include ROOT_DIR . 'lib/mediainfo.class.php';
        $mediainfo = new mediainfo();
        foreach ($info['files'] as $filepath) {
            if (!is_file(UPLOAD_DIR . $filepath)) {
                continue;
            }
            $mediainfo->setFile(UPLOAD_DIR . $filepath);
            $data = $mediainfo->getMeidaInfo();
            if (!$data) {
                continue;
            }
            $id = explode('/', $filepath);
            $id = $id[count($id) - 1];
            $id = explode('.', $id);
            $id = $id[0];
            hg_file_write(UPLOAD_DIR . FILE_QUEUE . $id, $filepath);
        }
    }
}
output(array('sucess' => 1));
コード例 #30
0
ファイル: pm25.api.php プロジェクト: h3len/Project
 /**
  * 获取一个城市所有监测点的PM2.5数据
  * city:城市名称,必选参数
  * avg:是否返回一个城市所有监测点数据均值的标识,可选参数,默认是true,不需要均值时传这个参数并设置为false
  * stations:是否只返回一个城市均值的标识,可选参数,默认是yes,不需要监测点信息时传这个参数并设置为no
  */
 function pm25data()
 {
     $cache_lock = CACHE_DIR . 'PM2.5.lock';
     if (!file_exists($cache_lock) || TIMENOW - fileatime($cache_lock) > CACHE_TIME) {
         $this->mUpdateCache = 1;
     }
     if (!($pmdata = $this->pm25core->get_pm25_data()) || $this->mUpdateCache) {
         $parameters = array('city' => $this->mCity, 'avg' => 'true', 'stations' => 'yes');
         $this->setUrl($this->settings['pm25api']['pm25data']);
         $this->setRequestParameters($parameters);
         $data = $this->request();
         if ($data === false) {
             //请求接口出错
             return $pmdata ? $pmdata : $this->pm25core->get_pm25_data();
         }
         $avg = end($data);
         unset($data[array_search($avg, $data)]);
         $avg['time_point'] = $this->format_time($avg['time_point']);
         $avg['update_time'] = date('Y/m/d H:i', $avg['time_point']);
         $this->pm25core->update_pm25_data($avg, $data, $avg['time_point']);
         foreach ($data as $val) {
             $val['time_point'] = $this->format_time($val['time_point']);
             $val['update_time'] = date('Y/m/d H:i', $val['time_point']);
             $_data[$val['station_code']] = $val;
         }
         $pmdata = array();
         $pmdata['avg'] = $avg;
         $pmdata['stations'] = $_data;
         hg_file_write($cache_lock, $avg['time_point']);
     }
     return $pmdata;
 }