📄 functions.php
字号:
<?php
define("PROCESS_FILE", "/var/run/spnew.pid");
define("PROGRAM_DIR", "/data/sp/program");
define("PROGRAM_CONFIG", "/config");
define("CHANNEL_DIR", "/data/sp/playlist");
define("SP_ID", "/var/run/spnew.pid");
//得到channel文件名列表
function getChannelList(){
$channelList = array();
if ($handle = opendir(CHANNEL_DIR)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && strstr($file, ".swap")!=false ) {
$channelList[]=$file;
}
}
closedir($handle);
}
return $channelList;
}
//得到channel列表 md5对应文件行数组 的hashtable形式
function getChannelTable($sort = true){
$channelList = array();
if ($handle = opendir(CHANNEL_DIR)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filename = CHANNEL_DIR . "/" . $file;
$array_tmp = file($filename);
$filemtime = filemtime($filename);
//$channelList[$file]=$array_tmp;
$channelList[$filemtime] = array($file,$array_tmp);
}
}
closedir($handle);
}
if($sort) krsort($channelList, SORT_NUMERIC);
foreach($channelList as $array_tmp) {
$_channelList[$array_tmp[0]] = $array_tmp[1];
}
unset($channelList);
return $_channelList;
}
//得到program目录名列表
function getPromd5list($sort = true){
$pronamelist = array();
if ($handle = opendir(PROGRAM_DIR)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filemtime = filemtime(PROGRAM_DIR.'/'.$file.'/config');
$pronamelist[$filemtime]=$file;
}
}
closedir($handle);
}
if($sort) krsort($pronamelist, SORT_NUMERIC);
return $pronamelist;
}
//得到program列表 md5对应name 的hashtable形式
function getProgramTable($sort = true){
$programlist = array();
$pronamelist = getPromd5list($sort);
foreach ($pronamelist as $promd5) {
$profilename = PROGRAM_DIR . "/" . $promd5 . PROGRAM_CONFIG;
$config = array();
$array_tmp = file($profilename);
foreach($array_tmp as $v){
if ((substr(trim($v),0,1)!=';') && (substr_count($v,'=')>=1)){
//Line mustn't start with a ';' and must contain at least one '=' symbol.
$pos = strpos($v, '=');
$config[trim(substr($v,0,$pos))] = trim(substr($v, $pos+1));
}
}
unset($array_tmp);
$programlist[$promd5]=$config["ChannelName"];
}
if($sort) {
array_flip($programlist);
ksort($programlist);
array_flip($programlist);
}
return $programlist;
}
//得到program information列表 md5对应array 的hashtable形式
function getProgramInfoTable(){
$programlist = array();
$pronamelist = getPromd5list();
foreach ($pronamelist as $promd5) {
$profilename = PROGRAM_DIR . "/" . $promd5 . PROGRAM_CONFIG;
$config = array();
$array_tmp = file($profilename);
foreach($array_tmp as $v){
if ((substr(trim($v),0,1)!=';') && (substr_count($v,'=')>=1)){
//Line mustn't start with a ';' and must contain at least one '=' symbol.
$pos = strpos($v, '=');
$config[trim(substr($v,0,$pos))] = trim(substr($v, $pos+1));
}
}
unset($array_tmp);
$programlist[$promd5]=$config;
}
return $programlist;
}
function infoSp(){
$spid = file(SP_ID);
$command = "/usr/bin/sudo -u root kill -HUP ".$spid[0];
exec($command);
}
function shelldel($dir){
$command = "rm -rf ".$dir;
echo $command;
echo exec($command);
}
//@header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
//@header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
//@header('Cache-Control: no-store, no-cache, must-revalidate');
//@header('Cache-Control: post-check=0, pre-check=0', false);
//@header('Pragma: no-cache');
function cache_programlist() {
$file = time();
$gramTable = getProgramTable(true);
file_put_contents('/tmp/'.$file.'.prolist', serialize($gramTable));
return $file;
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -