From 08580c94393ccb17c8202269808c7ec979693432 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Thu, 3 Sep 2020 11:28:01 +0300 Subject: [PATCH 01/10] Add files via upload --- lib/common.class.php | 299 ++-------------------------------------- lib/general.class.php | 88 ------------ lib/messages.class.php | 194 ++++++++++++++++++++++++++ lib/syncfiles.class.php | 167 ++++++++++++++++++++++ 4 files changed, 375 insertions(+), 373 deletions(-) create mode 100644 lib/messages.class.php diff --git a/lib/common.class.php b/lib/common.class.php index 1079e9955..836a52423 100644 --- a/lib/common.class.php +++ b/lib/common.class.php @@ -42,197 +42,6 @@ function getSystemSerial($force_update = 0) { return $serial; } -function sayReplySafe($ph, $level = 0, $replyto = '') -{ - $data = array( - 'sayReply' => 1, - 'ph' => $ph, - 'level' => $level, - 'replyto' => $replyto, - ); - if (session_id()) { - $data[session_name()] = session_id(); - } - $url = BASE_URL . '/objects/?' . http_build_query($data); - if (is_array($params)) { - foreach ($params as $k => $v) { - $url .= '&' . $k . '=' . urlencode($v); - } - } - $result = getURLBackground($url, 0); - return $result; -} - -/** - * Summary of sayReply - * @param mixed $ph Phrase - * @param mixed $level Level (default 0) - * @param mixed $replyto Original request - * @return void - */ -function sayReply($ph, $level = 0, $replyto = '') -{ - $source = ''; - if ($replyto) { - $terminal_rec = SQLSelectOne("SELECT * FROM terminals WHERE LATEST_REQUEST LIKE '%" . DBSafe($replyto) . "%' ORDER BY LATEST_REQUEST_TIME DESC LIMIT 1"); - $orig_msg = SQLSelectOne("SELECT * FROM shouts WHERE SOURCE!='' AND MESSAGE LIKE '%" . DBSafe($replyto) . "%' AND ADDED>=(NOW() - INTERVAL 30 SECOND) ORDER BY ADDED DESC LIMIT 1"); - if ($orig_msg['ID']) { - $source = $orig_msg['SOURCE']; - } - } else { - $terminal_rec = SQLSelectOne("SELECT * FROM terminals WHERE LATEST_REQUEST_TIME>=(NOW() - INTERVAL 5 SECOND) ORDER BY LATEST_REQUEST_TIME DESC LIMIT 1"); - } - if (!$terminal_rec) { - $source = 'terminal_not_found'; - say($ph, $level); - } else { - $source = 'terminal' . $terminal_rec['ID']; - $said_status = sayTo($ph, $level, $terminal_rec['NAME']); - if (!$said_status) { - say($ph, $level); - } else { - //$rec = array(); - //$rec['MESSAGE'] = $ph; - //$rec['ADDED'] = date('Y-m-d H:i:s'); - //$rec['ROOM_ID'] = 0; - //$rec['MEMBER_ID'] = 0; - //if ($level > 0) $rec['IMPORTANCE'] = $level; - //$rec['ID'] = SQLInsert('shouts', $rec); - } - } - processSubscriptionsSafe('SAYREPLY', array('level' => $level, 'message' => $ph, 'replyto' => $replyto, 'source' => $source)); -} - - -function sayToSafe($ph, $level = 0, $destination = '') -{ - $data = array( - 'sayTo' => 1, - 'ph' => $ph, - 'level' => $level, - 'destination' => $destination, - ); - if (session_id()) { - $data[session_name()] = session_id(); - } - $url = BASE_URL . '/objects/?' . http_build_query($data); - if (is_array($params)) { - foreach ($params as $k => $v) { - $url .= '&' . $k . '=' . urlencode($v); - } - } - $result = getURLBackground($url, 0); - return $result; -} - -/** - * Summary of sayTo - * @param mixed $ph Phrase - * @param mixed $level Level (default 0) - * @param mixed $destination Destination terminal name - * @return void - */ -function sayTo($ph, $level = 0, $destination = '') -{ - if (!$destination) { - return 0; - } - // add message to chat - $rec = array(); - $rec['MESSAGE'] = $ph; - $rec['ADDED'] = date('Y-m-d H:i:s'); - $rec['ROOM_ID'] = 0; - $rec['MEMBER_ID'] = 0; - if ($level > 0) $rec['IMPORTANCE'] = $level; - $rec['ID'] = SQLInsert('shouts', $rec); - - $processed = processSubscriptionsSafe('SAYTO', array('level' => $level, 'message' => $ph, 'destination' => $destination)); - return 1; -} - -function saySafe($ph, $level = 0, $member_id = 0, $source = '') -{ - $data = array( - 'say' => 1, - 'ph' => $ph, - 'level' => $level, - 'member_id' => $member_id, - 'source' => $source, - ); - if (session_id()) { - $data[session_name()] = session_id(); - } - $url = BASE_URL . '/objects/?' . http_build_query($data); - if (is_array($params)) { - foreach ($params as $k => $v) { - $url .= '&' . $k . '=' . urlencode($v); - } - } - $result = getURLBackground($url, 0); - return $result; -} - -/** - * Summary of say - * @param mixed $ph Phrase - * @param mixed $level Level (default 0) - * @param mixed $member_id Member ID (default 0) - * @return void - */ -function say($ph, $level = 0, $member_id = 0, $source = '') -{ - - //dprint(date('Y-m-d H:i:s')." Say started",false); - - verbose_log("SAY (level: $level; member: $member; source: $source): " . $ph); - //DebMes("SAY (level: $level; member: $member; source: $source): ".$ph,'say'); - - $rec = array(); - $rec['MESSAGE'] = $ph; - $rec['ADDED'] = date('Y-m-d H:i:s'); - $rec['ROOM_ID'] = 0; - $rec['MEMBER_ID'] = $member_id; - $rec['SOURCE'] = $source; - - if ($level > 0) $rec['IMPORTANCE'] = $level; - $rec['ID'] = SQLInsert('shouts', $rec); - - if ($member_id) { - $processed = processSubscriptionsSafe('COMMAND', array('level' => $level, 'message' => $ph, 'member_id' => $member_id, 'source' => $source)); - return; - } - - if (defined('SETTINGS_HOOK_BEFORE_SAY') && SETTINGS_HOOK_BEFORE_SAY != '') { - eval(SETTINGS_HOOK_BEFORE_SAY); - } - - - if (!defined('SETTINGS_SPEAK_SIGNAL') || SETTINGS_SPEAK_SIGNAL == '1') { - if ($level >= (int)getGlobal('minMsgLevel') && !$member_id) { // && !$ignoreVoice - $passed = time() - (int)getGlobal('lastSayTime'); - if ($passed > 20) { - playSound('dingdong', 1, $level); - } - } - } - - setGlobal('lastSayTime', time()); - setGlobal('lastSayMessage', $ph); - - processSubscriptionsSafe('SAY', array('level' => $level, 'message' => $ph, 'member_id' => $member_id)); //, 'ignoreVoice'=>$ignoreVoice - - if (defined('SETTINGS_HOOK_AFTER_SAY') && SETTINGS_HOOK_AFTER_SAY != '') { - eval(SETTINGS_HOOK_AFTER_SAY); - } - //dprint(date('Y-m-d H:i:s')." Say OK",false); - -} - -function ask($prompt, $target = '') -{ - processSubscriptionsSafe('ASK', array('prompt' => $prompt, 'message' => $prompt, 'target' => $target, 'destination' => $target)); -} - /** * Summary of processCommand * @param mixed $command Command @@ -565,31 +374,6 @@ function recognizeTime($text, &$newText) return $result; } -/** - * Summary of getRandomLine - * @param mixed $filename File name - * @return mixed - */ -function getRandomLine($filename) -{ - if (file_exists(ROOT . 'cms/texts/' . $filename . '.txt')) { - $filename = ROOT . 'cms/texts/' . $filename . '.txt'; - } - - if (file_exists($filename)) { - $data = LoadFile($filename); - $data = str_replace("\r", '', $data); - $data = str_replace("\n\n", "\n", $data); - $lines = mb_split("\n", $data); - $total = count($lines); - $line = $lines[round(rand(0, $total - 1))]; - - if ($line != '') { - return $line; - } - } -} - /** * Summary of playSound * @param mixed $filename File name @@ -1290,16 +1074,6 @@ function hsvToHex($h, $s, $v) return sprintf("%02x%02x%02x", $rgb[0], $rgb[1], $rgb[2]); } -function remote_file_exists($url){ - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_NOBODY, true); - curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - if( $httpCode == 200 ){return true;} - return false; -} - function logAction($action_type,$details='') { global $session; $rec=array(); @@ -1322,64 +1096,19 @@ function logAction($action_type,$details='') { } -function get_media_info($file) -{ - if (!defined('PATH_TO_FFMPEG')) { - if (IsWindowsOS()) { - define("PATH_TO_FFMPEG", SERVER_ROOT . '/apps/ffmpeg/ffmpeg.exe'); - } else { - define("PATH_TO_FFMPEG", 'ffmpeg'); - } - } - $data = shell_exec(PATH_TO_FFMPEG . " -i " . $file . " 2>&1"); - //DebMes ($data); - if (preg_match("/: Invalid /", $data)) { - return false; - } - //get duration - preg_match("/Duration: (.{2}):(.{2}):(.{2})/", $data, $duration); - - if (!isset($duration[1])) { - return false; - } - $hours = $duration[1]; - $minutes = $duration[2]; - $seconds = $duration[3]+1; - $out['duration'] = $seconds + ($minutes * 60) + ($hours * 60 * 60); - // get all info about codec - preg_match("/Audio: (.+), (.\d+) Hz, (.\w+), (.+), (.\d+) kb/", $data, $format); - - if ($format) { - $out['Audio_format'] = $format[1]; - $out['Audio_sample_rate'] = $format[2]; - $out['Audio_type'] = $format[3]; - $out['Audio_codec'] = $format[4]; - $out['Audio_bitrate'] = $format[5]; - if ($out['Audio_type'] == 'mono' ) { - $out['Audio_chanel'] = 1; - } else { - $out['Audio_chanel'] = 2; - } - } - preg_match("/Video: (.+),\s(.\d+x.\d+) (.+), (.+), (.+), (.+), (.+), (.+) /", $data, $formatv); - if ($formatv) { - $out['Video_format'] = $formatv[1]; - $out['Video_size'] = $formatv[2]; - $out['Video_bitrate'] = str_ireplace("kb/s", "", $formatv[4]); - $out['Video_fps'] = $formatv[5]; - } - return $out; -} - -function get_remote_filesize($url) +/** + * Ping host + * @param mixed $host Host address + * @return bool + */ +function ping($host) { - $head = array_change_key_case(get_headers($url, 1)); - // content-length of download (in bytes), read from Content-Length: field - $clen = isset($head['content-length']) ? $head['content-length'] : 0; - - // cannot retrieve file size, return "-1" - if (!$clen) { - return '0'; - } - return $clen; // return size in bytes + if (IsWindowsOS()) + exec(sprintf('ping -n 1 %s', escapeshellarg($host)), $res, $rval); + elseif (substr(php_uname(), 0, 7) === "FreeBSD") + exec(sprintf('ping -c 1 -t 5 %s', escapeshellarg($host)), $res, $rval); + else + exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res, $rval); + + return $rval === 0 && preg_match('/ttl/is', join('', $res)); } diff --git a/lib/general.class.php b/lib/general.class.php index 2637df02c..1f26aed9d 100644 --- a/lib/general.class.php +++ b/lib/general.class.php @@ -153,55 +153,6 @@ function redirect($url, $owner = "", $no_sid = 0) } } -/** - * Summary of LoadFile - * - * @access public - * - * @param mixed $filename File name - * @return string - */ -function LoadFile($filename) -{ - // loading file - $f = fopen($filename, "r"); - $data = ""; - if ($f) { - $fsize = filesize($filename); - if ($fsize > 0) { - $data = fread($f, $fsize); - } - fclose($f); - } - return $data; -} - -/** - * Summary of SaveFile - * @access public - * - * @param mixed $filename File name - * @param mixed $data Content - * @return int - */ -function SaveFile($filename, $data) -{ - // saving file - $f = fopen("$filename", "w+"); - - if ($f) { - flock($f, 2); - fwrite($f, $data); - flock($f, 3); - fclose($f); - @chmod($filename, 0666); - - return 1; - } - - return 0; -} - /** * Summary of outHash * @param mixed $var Var @@ -675,28 +626,6 @@ function colorizeArray(&$ar, $every = 2) } } -/** - * Summary of clearCache - * @param mixed $verbose Verbode (default 0) - * @return void - */ -function clearCache($verbose = 0) -{ - if ($handle = opendir(ROOT . 'cms/cached')) { - while (false !== ($file = readdir($handle))) { - if (is_file(ROOT . 'cms/cached/' . $file)) { - @unlink(ROOT . 'cms/cached/' . $file); - - if ($verbose) { - echo "File : " . $file . " removed
\n"; - } - } - } - - closedir($handle); - } -} - /** * Summary of checkBadwords * @param mixed $s String @@ -744,23 +673,6 @@ function checkBadwords($s, $replace = 1) } } -/** - * Ping host - * @param mixed $host Host address - * @return bool - */ -function ping($host) -{ - if (IsWindowsOS()) - exec(sprintf('ping -n 1 %s', escapeshellarg($host)), $res, $rval); - elseif (substr(php_uname(), 0, 7) === "FreeBSD") - exec(sprintf('ping -c 1 -t 5 %s', escapeshellarg($host)), $res, $rval); - else - exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res, $rval); - - return $rval === 0 && preg_match('/ttl/is', join('', $res)); -} - /** * Transliterate string * @param mixed $string String diff --git a/lib/messages.class.php b/lib/messages.class.php new file mode 100644 index 000000000..470858c3c --- /dev/null +++ b/lib/messages.class.php @@ -0,0 +1,194 @@ + 1, + 'ph' => $ph, + 'level' => $level, + 'replyto' => $replyto, + ); + if (session_id()) { + $data[session_name()] = session_id(); + } + $url = BASE_URL . '/objects/?' . http_build_query($data); + if (is_array($params)) { + foreach ($params as $k => $v) { + $url .= '&' . $k . '=' . urlencode($v); + } + } + $result = getURLBackground($url, 0); + return $result; +} + +/** + * Summary of sayReply + * @param mixed $ph Phrase + * @param mixed $level Level (default 0) + * @param mixed $replyto Original request + * @return void + */ +function sayReply($ph, $level = 0, $replyto = '') +{ + $source = ''; + if ($replyto) { + $terminal_rec = SQLSelectOne("SELECT * FROM terminals WHERE LATEST_REQUEST LIKE '%" . DBSafe($replyto) . "%' ORDER BY LATEST_REQUEST_TIME DESC LIMIT 1"); + $orig_msg = SQLSelectOne("SELECT * FROM shouts WHERE SOURCE!='' AND MESSAGE LIKE '%" . DBSafe($replyto) . "%' AND ADDED>=(NOW() - INTERVAL 30 SECOND) ORDER BY ADDED DESC LIMIT 1"); + if ($orig_msg['ID']) { + $source = $orig_msg['SOURCE']; + } + } else { + $terminal_rec = SQLSelectOne("SELECT * FROM terminals WHERE LATEST_REQUEST_TIME>=(NOW() - INTERVAL 5 SECOND) ORDER BY LATEST_REQUEST_TIME DESC LIMIT 1"); + } + if (!$terminal_rec) { + $source = 'terminal_not_found'; + say($ph, $level); + } else { + $source = 'terminal' . $terminal_rec['ID']; + $said_status = sayTo($ph, $level, $terminal_rec['NAME']); + if (!$said_status) { + say($ph, $level); + } else { + //$rec = array(); + //$rec['MESSAGE'] = $ph; + //$rec['ADDED'] = date('Y-m-d H:i:s'); + //$rec['ROOM_ID'] = 0; + //$rec['MEMBER_ID'] = 0; + //if ($level > 0) $rec['IMPORTANCE'] = $level; + //$rec['ID'] = SQLInsert('shouts', $rec); + } + } + processSubscriptionsSafe('SAYREPLY', array('level' => $level, 'message' => $ph, 'replyto' => $replyto, 'source' => $source)); +} + + +function sayToSafe($ph, $level = 0, $destination = '') +{ + $data = array( + 'sayTo' => 1, + 'ph' => $ph, + 'level' => $level, + 'destination' => $destination, + ); + if (session_id()) { + $data[session_name()] = session_id(); + } + $url = BASE_URL . '/objects/?' . http_build_query($data); + if (is_array($params)) { + foreach ($params as $k => $v) { + $url .= '&' . $k . '=' . urlencode($v); + } + } + $result = getURLBackground($url, 0); + return $result; +} + +/** + * Summary of sayTo + * @param mixed $ph Phrase + * @param mixed $level Level (default 0) + * @param mixed $destination Destination terminal name + * @return void + */ +function sayTo($ph, $level = 0, $destination = '') +{ + if (!$destination) { + return 0; + } + // add message to chat + $rec = array(); + $rec['MESSAGE'] = $ph; + $rec['ADDED'] = date('Y-m-d H:i:s'); + $rec['ROOM_ID'] = 0; + $rec['MEMBER_ID'] = 0; + if ($level > 0) $rec['IMPORTANCE'] = $level; + $rec['ID'] = SQLInsert('shouts', $rec); + + $processed = processSubscriptionsSafe('SAYTO', array('level' => $level, 'message' => $ph, 'destination' => $destination)); + return 1; +} + +function saySafe($ph, $level = 0, $member_id = 0, $source = '') +{ + $data = array( + 'say' => 1, + 'ph' => $ph, + 'level' => $level, + 'member_id' => $member_id, + 'source' => $source, + ); + if (session_id()) { + $data[session_name()] = session_id(); + } + $url = BASE_URL . '/objects/?' . http_build_query($data); + if (is_array($params)) { + foreach ($params as $k => $v) { + $url .= '&' . $k . '=' . urlencode($v); + } + } + $result = getURLBackground($url, 0); + return $result; +} + +/** + * Summary of say + * @param mixed $ph Phrase + * @param mixed $level Level (default 0) + * @param mixed $member_id Member ID (default 0) + * @return void + */ +function say($ph, $level = 0, $member_id = 0, $source = '') +{ + + //dprint(date('Y-m-d H:i:s')." Say started",false); + + verbose_log("SAY (level: $level; member: $member; source: $source): " . $ph); + //DebMes("SAY (level: $level; member: $member; source: $source): ".$ph,'say'); + + $rec = array(); + $rec['MESSAGE'] = $ph; + $rec['ADDED'] = date('Y-m-d H:i:s'); + $rec['ROOM_ID'] = 0; + $rec['MEMBER_ID'] = $member_id; + $rec['SOURCE'] = $source; + + if ($level > 0) $rec['IMPORTANCE'] = $level; + $rec['ID'] = SQLInsert('shouts', $rec); + + if ($member_id) { + $processed = processSubscriptionsSafe('COMMAND', array('level' => $level, 'message' => $ph, 'member_id' => $member_id, 'source' => $source)); + return; + } + + if (defined('SETTINGS_HOOK_BEFORE_SAY') && SETTINGS_HOOK_BEFORE_SAY != '') { + eval(SETTINGS_HOOK_BEFORE_SAY); + } + + + if (!defined('SETTINGS_SPEAK_SIGNAL') || SETTINGS_SPEAK_SIGNAL == '1') { + if ($level >= (int)getGlobal('minMsgLevel') && !$member_id) { // && !$ignoreVoice + $passed = time() - (int)getGlobal('lastSayTime'); + if ($passed > 20) { + playSound('dingdong', 1, $level); + } + } + } + + setGlobal('lastSayTime', time()); + setGlobal('lastSayMessage', $ph); + + processSubscriptionsSafe('SAY', array('level' => $level, 'message' => $ph, 'member_id' => $member_id)); //, 'ignoreVoice'=>$ignoreVoice + + if (defined('SETTINGS_HOOK_AFTER_SAY') && SETTINGS_HOOK_AFTER_SAY != '') { + eval(SETTINGS_HOOK_AFTER_SAY); + } + //dprint(date('Y-m-d H:i:s')." Say OK",false); + +} + +function ask($prompt, $target = '') +{ + processSubscriptionsSafe('ASK', array('prompt' => $prompt, 'message' => $prompt, 'target' => $target, 'destination' => $target)); +} + + diff --git a/lib/syncfiles.class.php b/lib/syncfiles.class.php index 18d4c3e75..79e663ec4 100644 --- a/lib/syncfiles.class.php +++ b/lib/syncfiles.class.php @@ -819,3 +819,170 @@ function sort_files_by_date($a,$b) { } } +/** + * Summary of getRandomLine + * @param mixed $filename File name + * @return mixed + */ +function getRandomLine($filename) +{ + if (file_exists(ROOT . 'cms/texts/' . $filename . '.txt')) { + $filename = ROOT . 'cms/texts/' . $filename . '.txt'; + } + + if (file_exists($filename)) { + $data = LoadFile($filename); + $data = str_replace("\r", '', $data); + $data = str_replace("\n\n", "\n", $data); + $lines = mb_split("\n", $data); + $total = count($lines); + $line = $lines[round(rand(0, $total - 1))]; + + if ($line != '') { + return $line; + } + } +} + +function remote_file_exists($url){ + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if( $httpCode == 200 ){return true;} + return false; +} + +function get_media_info($file) +{ + if (!defined('PATH_TO_FFMPEG')) { + if (IsWindowsOS()) { + define("PATH_TO_FFMPEG", SERVER_ROOT . '/apps/ffmpeg/ffmpeg.exe'); + } else { + define("PATH_TO_FFMPEG", 'ffmpeg'); + } + } + $data = shell_exec(PATH_TO_FFMPEG . " -i " . $file . " 2>&1"); + + if (preg_match("/: Invalid /", $data)) { + return false; + } + //get duration + preg_match("/Duration: (.{2}):(.{2}):(.{2})/", $data, $duration); + + if (!isset($duration[1])) { + return false; + } + $hours = $duration[1]; + $minutes = $duration[2]; + $seconds = $duration[3]+1; + $out['duration'] = $seconds + ($minutes * 60) + ($hours * 60 * 60); + // get all info about codec + preg_match("/Audio: (.+), (.\d+) Hz, (.\w+), (.+), (.\d+) kb/", $data, $format); + + if ($format) { + $out['Audio_format'] = $format[1]; + $out['Audio_sample_rate'] = $format[2]; + $out['Audio_type'] = $format[3]; + $out['Audio_codec'] = $format[4]; + $out['Audio_bitrate'] = $format[5]; + if ($out['Audio_type'] == 'mono' ) { + $out['Audio_chanel'] = 1; + } else { + $out['Audio_chanel'] = 2; + } + } + preg_match("/Video: (.+),\s(.\d+x.\d+) (.+), (.+), (.+), (.+), (.+), (.+) /", $data, $formatv); + if ($formatv) { + $out['Video_format'] = $formatv[1]; + $out['Video_size'] = $formatv[2]; + $out['Video_bitrate'] = str_ireplace("kb/s", "", $formatv[4]); + $out['Video_fps'] = $formatv[5]; + } + return $out; +} + +function get_remote_filesize($url) +{ + $head = array_change_key_case(get_headers($url, 1)); + // content-length of download (in bytes), read from Content-Length: field + $clen = isset($head['content-length']) ? $head['content-length'] : 0; + + // cannot retrieve file size, return "-1" + if (!$clen) { + return '0'; + } + return $clen; // return size in bytes +} + +/** + * Summary of LoadFile + * + * @access public + * + * @param mixed $filename File name + * @return string + */ +function LoadFile($filename) +{ + // loading file + $f = fopen($filename, "r"); + $data = ""; + if ($f) { + $fsize = filesize($filename); + if ($fsize > 0) { + $data = fread($f, $fsize); + } + fclose($f); + } + return $data; +} + +/** + * Summary of SaveFile + * @access public + * + * @param mixed $filename File name + * @param mixed $data Content + * @return int + */ +function SaveFile($filename, $data) +{ + // saving file + $f = fopen("$filename", "w+"); + + if ($f) { + flock($f, 2); + fwrite($f, $data); + flock($f, 3); + fclose($f); + @chmod($filename, 0666); + + return 1; + } + + return 0; +} + +/** + * Summary of clearCache + * @param mixed $verbose Verbode (default 0) + * @return void + */ +function clearCache($verbose = 0) +{ + if ($handle = opendir(ROOT . 'cms/cached')) { + while (false !== ($file = readdir($handle))) { + if (is_file(ROOT . 'cms/cached/' . $file)) { + @unlink(ROOT . 'cms/cached/' . $file); + + if ($verbose) { + echo "File : " . $file . " removed
\n"; + } + } + } + + closedir($handle); + } +} \ No newline at end of file From 4bb09f1b786d816bde33ec7940531a1006caf039 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Thu, 3 Sep 2020 16:17:33 +0300 Subject: [PATCH 02/10] Delete sms.class.php --- lib/sms.class.php | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 lib/sms.class.php diff --git a/lib/sms.class.php b/lib/sms.class.php deleted file mode 100644 index 3e1d1effa..000000000 --- a/lib/sms.class.php +++ /dev/null @@ -1,16 +0,0 @@ - Date: Thu, 3 Sep 2020 16:22:28 +0300 Subject: [PATCH 03/10] Update terminals.class.php --- lib/terminals.class.php | 123 ---------------------------------------- 1 file changed, 123 deletions(-) diff --git a/lib/terminals.class.php b/lib/terminals.class.php index 1be3137ef..33213448a 100644 --- a/lib/terminals.class.php +++ b/lib/terminals.class.php @@ -359,126 +359,3 @@ function setTerminalMML($host = 'localhost', $mml=0) { SQLUpdate('terminals', $terminal); return true; } - -function postURLBackground($url, $query = array(), $cache = 0, $username = '', $password = '') -{ - //DebMes("URL: ".$url,'debug1'); - postURL($url, $query , $cache, $username, $password, true); -} - -/** - * Summary of postURL - * @param mixed $url Url - * @param mixed $query query - * @param mixed $cache Cache (default 0) - * @param mixed $username User name (default '') - * @param mixed $password Password (default '') - * @return mixed - */ -function postURL($url, $query = array(), $cache = 0, $username = '', $password = '', $background = false) -{ - startMeasure('postURL'); - // DebMes($url,'urls'); - $filename_part = preg_replace('/\W/is', '_', str_replace('http://', '', $url)); - if (strlen($filename_part) > 200) { - $filename_part = substr($filename_part, 0, 200) . md5($filename_part); - } - $cache_file = ROOT . 'cms/cached/urls/' . $filename_part . '.html'; - - if (!$cache || !is_file($cache_file) || ((time() - filemtime($cache_file)) > $cache)) { - try { - - //DebMes('Geturl started for '.$url. ' Source: ' .debug_backtrace()[1]['function'], 'geturl'); - startMeasure('curl_prepare'); - $ch = curl_init(); - @curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $query); - curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // connection timeout - curl_setopt($ch, CURLOPT_MAXREDIRS, 2); - @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 45); // operation timeout 45 seconds - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // bad style, I know... - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - - if ($background) { - curl_setopt($ch, CURLOPT_NOSIGNAL, 1); - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 300); - } - - if ($username != '' || $password != '') { - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); - } - - $url_parsed = parse_url($url); - $host = $url_parsed['host']; - - $use_proxy = false; - if (defined('USE_PROXY') && USE_PROXY != '') { - $use_proxy = true; - } - - if ($host == '127.0.0.1' || $host == 'localhost') { - $use_proxy = false; - } - - if ($use_proxy && defined('HOME_NETWORK') && HOME_NETWORK != '') { - $p = preg_quote(HOME_NETWORK); - $p = str_replace('\*', '\d+?', $p); - $p = str_replace(',', ' ', $p); - $p = str_replace(' ', ' ', $p); - $p = str_replace(' ', '|', $p); - if (preg_match('/' . $p . '/is', $host)) { - $use_proxy = false; - } - } - - if ($use_proxy) { - curl_setopt($ch, CURLOPT_PROXY, USE_PROXY); - if (defined('USE_PROXY_AUTH') && USE_PROXY_AUTH != '') { - curl_setopt($ch, CURLOPT_PROXYUSERPWD, USE_PROXY_AUTH); - } - } - - $tmpfname = ROOT . 'cms/cached/cookie.txt'; - curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname); - curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname); - - endMeasure('curl_prepare'); - startMeasure('curl_exec'); - $result = curl_exec($ch); - endMeasure('curl_exec'); - - - startMeasure('curl_post'); - if (!$background && curl_errno($ch)) { - $errorInfo = curl_error($ch); - $info = curl_getinfo($ch); - $backtrace = debug_backtrace(); - $callSource = $backtrace[1]['function']; - DebMes("GetURL to $url (source " . $callSource . ") finished with error: \n" . $errorInfo . "\n" . json_encode($info),'geturl_error'); - } - curl_close($ch); - endMeasure('curl_post'); - - - } catch (Exception $e) { - registerError('geturl', $url . ' ' . get_class($e) . ', ' . $e->getMessage()); - } - - if ($cache > 0) { - CreateDir(ROOT . 'cms/cached/urls'); - SaveFile($cache_file, $result); - } - } else { - $result = LoadFile($cache_file); - } - - - endMeasure('postURL'); - - return $result; -} From 438a8ebf730276ebed79d6245ca3414b72dff8d5 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Thu, 3 Sep 2020 16:23:28 +0300 Subject: [PATCH 04/10] Update common.class.php --- lib/common.class.php | 164 ++++++++++++++++++++++++++++++++----------- 1 file changed, 123 insertions(+), 41 deletions(-) diff --git a/lib/common.class.php b/lib/common.class.php index 836a52423..ff1bbc2d6 100644 --- a/lib/common.class.php +++ b/lib/common.class.php @@ -596,6 +596,129 @@ function getURL($url, $cache = 0, $username = '', $password = '', $background = return $result; } +function postURLBackground($url, $query = array(), $cache = 0, $username = '', $password = '') +{ + //DebMes("URL: ".$url,'debug1'); + postURL($url, $query , $cache, $username, $password, true); +} + +/** + * Summary of postURL + * @param mixed $url Url + * @param mixed $query query + * @param mixed $cache Cache (default 0) + * @param mixed $username User name (default '') + * @param mixed $password Password (default '') + * @return mixed + */ +function postURL($url, $query = array(), $cache = 0, $username = '', $password = '', $background = false) +{ + startMeasure('postURL'); + // DebMes($url,'urls'); + $filename_part = preg_replace('/\W/is', '_', str_replace('http://', '', $url)); + if (strlen($filename_part) > 200) { + $filename_part = substr($filename_part, 0, 200) . md5($filename_part); + } + $cache_file = ROOT . 'cms/cached/urls/' . $filename_part . '.html'; + + if (!$cache || !is_file($cache_file) || ((time() - filemtime($cache_file)) > $cache)) { + try { + + //DebMes('Geturl started for '.$url. ' Source: ' .debug_backtrace()[1]['function'], 'geturl'); + startMeasure('curl_prepare'); + $ch = curl_init(); + @curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $query); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // connection timeout + curl_setopt($ch, CURLOPT_MAXREDIRS, 2); + @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 45); // operation timeout 45 seconds + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // bad style, I know... + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); + + if ($background) { + curl_setopt($ch, CURLOPT_NOSIGNAL, 1); + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 300); + } + + if ($username != '' || $password != '') { + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); + } + + $url_parsed = parse_url($url); + $host = $url_parsed['host']; + + $use_proxy = false; + if (defined('USE_PROXY') && USE_PROXY != '') { + $use_proxy = true; + } + + if ($host == '127.0.0.1' || $host == 'localhost') { + $use_proxy = false; + } + + if ($use_proxy && defined('HOME_NETWORK') && HOME_NETWORK != '') { + $p = preg_quote(HOME_NETWORK); + $p = str_replace('\*', '\d+?', $p); + $p = str_replace(',', ' ', $p); + $p = str_replace(' ', ' ', $p); + $p = str_replace(' ', '|', $p); + if (preg_match('/' . $p . '/is', $host)) { + $use_proxy = false; + } + } + + if ($use_proxy) { + curl_setopt($ch, CURLOPT_PROXY, USE_PROXY); + if (defined('USE_PROXY_AUTH') && USE_PROXY_AUTH != '') { + curl_setopt($ch, CURLOPT_PROXYUSERPWD, USE_PROXY_AUTH); + } + } + + $tmpfname = ROOT . 'cms/cached/cookie.txt'; + curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname); + curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname); + + endMeasure('curl_prepare'); + startMeasure('curl_exec'); + $result = curl_exec($ch); + endMeasure('curl_exec'); + + + startMeasure('curl_post'); + if (!$background && curl_errno($ch)) { + $errorInfo = curl_error($ch); + $info = curl_getinfo($ch); + $backtrace = debug_backtrace(); + $callSource = $backtrace[1]['function']; + DebMes("GetURL to $url (source " . $callSource . ") finished with error: \n" . $errorInfo . "\n" . json_encode($info),'geturl_error'); + } + curl_close($ch); + endMeasure('curl_post'); + + + } catch (Exception $e) { + registerError('geturl', $url . ' ' . get_class($e) . ', ' . $e->getMessage()); + } + + if ($cache > 0) { + CreateDir(ROOT . 'cms/cached/urls'); + SaveFile($cache_file, $result); + } + } else { + $result = LoadFile($cache_file); + } + + + endMeasure('postURL'); + + return $result; +} + /** * Summary of safe_exec * @param mixed $command Command @@ -647,47 +770,6 @@ function execInBackground($cmd) } } -/** - * Summary of getFilesTree - * @param mixed $destination Destination - * @param mixed $sort Sort (default 'name') - * @return array - */ -function getFilesTree($destination, $sort = 'name') -{ - if (substr($destination, -1) == '/' || substr($destination, -1) == '\\') { - $destination = substr($destination, 0, strlen($destination) - 1); - } - - $res = array(); - - if (!is_dir($destination)) - return $res; - - if ($dir = @opendir($destination)) { - while (($file = readdir($dir)) !== false) { - if (is_dir($destination . "/" . $file) && ($file != '.') && ($file != '..')) { - $tmp = getFilesTree($destination . "/" . $file); - if (is_array($tmp)) { - foreach ($tmp as $elem) { - $res[] = $elem; - } - } - } elseif (is_file($destination . "/" . $file)) { - $res[] = ($destination . "/" . $file); - } - } - closedir($dir); - } - - if ($sort == 'name') { - sort($res, SORT_STRING); - } - - return $res; -} - - /** * Summary of isOnline * @param mixed $host Host From 4a43fcfac3a41a2e8acf7aad336fd1675a8b0421 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Thu, 3 Sep 2020 16:24:06 +0300 Subject: [PATCH 05/10] Update syncfiles.class.php --- lib/syncfiles.class.php | 88 +++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/lib/syncfiles.class.php b/lib/syncfiles.class.php index 79e663ec4..5179ff1af 100644 --- a/lib/syncfiles.class.php +++ b/lib/syncfiles.class.php @@ -3,52 +3,6 @@ * @version 0.1 (auto-set) */ - -/* -Установка переменных, которые можно использовать в коммандах - -SET PROJECTS_DIR=D:/jey/projects - -Игнорирование папок и файлов, которые включают указанное слово - -IGNORE project_files - -Синхронизация (добавление новых и измененных файлов) - -LOCAL_DIR/wiki => PROJECTS_DIR/jeywork/wiki -LOCAL_DIR/wiki <= PROJECTS_DIR/jeywork/wiki - -Перемещение всех файлов из одной папки в другую - -f:/video/daily <- /video_daily -/video_daily -> f:/video/daily - -Добавление только файлов, определенной давности (более ранние файлы игнорируются) - -/music/podcasts <+ D:/jey/handled/music/Podcasts 2 DAYS OLD - -Удаление файлов старше определенного "возраста" - -CLEAR D:/jey/handled/music/Podcasts 2 DAYS OLD - -Синхронизация с полным зеркалирование, т.е. на месте назначения будут удаляться файлы и папки, которых нет на источнике - -SOURCE/dir !> DESTINATION/dir -SOURCE/dir d:/jey/foto2/%Y/%m-%F (файлы из первой папки будут разбросаны по годам и месяцам во второй) -при этом если используется %, то в качестве времени берется время модификации файла, а если $, то текущее время - - */ - /** * Summary of preparePathTime * @param mixed $s String @@ -985,4 +939,44 @@ function clearCache($verbose = 0) closedir($handle); } -} \ No newline at end of file +} + +/** + * Summary of getFilesTree + * @param mixed $destination Destination + * @param mixed $sort Sort (default 'name') + * @return array + */ +function getFilesTree($destination, $sort = 'name') +{ + if (substr($destination, -1) == '/' || substr($destination, -1) == '\\') { + $destination = substr($destination, 0, strlen($destination) - 1); + } + + $res = array(); + + if (!is_dir($destination)) + return $res; + + if ($dir = @opendir($destination)) { + while (($file = readdir($dir)) !== false) { + if (is_dir($destination . "/" . $file) && ($file != '.') && ($file != '..')) { + $tmp = getFilesTree($destination . "/" . $file); + if (is_array($tmp)) { + foreach ($tmp as $elem) { + $res[] = $elem; + } + } + } elseif (is_file($destination . "/" . $file)) { + $res[] = ($destination . "/" . $file); + } + } + closedir($dir); + } + + if ($sort == 'name') { + sort($res, SORT_STRING); + } + + return $res; +} From ea160deae3d5019fb0669d54ac8b6af0fc861d8f Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Thu, 3 Sep 2020 16:28:03 +0300 Subject: [PATCH 06/10] Update terminals.class.php --- lib/terminals.class.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/lib/terminals.class.php b/lib/terminals.class.php index 33213448a..4032dabd1 100644 --- a/lib/terminals.class.php +++ b/lib/terminals.class.php @@ -222,29 +222,6 @@ function getPlayerStatus($host = 'localhost') } } -function getMediaDurationSeconds($file) -{ - if (!defined('PATH_TO_FFMPEG')) { - if (IsWindowsOS()) { - define("PATH_TO_FFMPEG", SERVER_ROOT . '/apps/ffmpeg/ffmpeg.exe'); - } else { - define("PATH_TO_FFMPEG", 'ffmpeg'); - } - } - $dur = shell_exec(PATH_TO_FFMPEG . " -i " . $file . " 2>&1"); - if (preg_match("/: Invalid /", $dur)) { - return false; - } - preg_match("/Duration: (.{2}):(.{2}):(.{2})/", $dur, $duration); - if (!isset($duration[1])) { - return false; - } - $hours = $duration[1]; - $minutes = $duration[2]; - $seconds = $duration[3]; - return $seconds + ($minutes * 60) + ($hours * 60 * 60); -} - /** * Summary of playMedia * @param mixed $path Path From d2ce506eb7bf43503907d1fe6e446f1820a4e22d Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Thu, 3 Sep 2020 16:28:43 +0300 Subject: [PATCH 07/10] Update syncfiles.class.php --- lib/syncfiles.class.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/syncfiles.class.php b/lib/syncfiles.class.php index 5179ff1af..f7ce0d094 100644 --- a/lib/syncfiles.class.php +++ b/lib/syncfiles.class.php @@ -808,6 +808,29 @@ function remote_file_exists($url){ return false; } +function getMediaDurationSeconds($file) +{ + if (!defined('PATH_TO_FFMPEG')) { + if (IsWindowsOS()) { + define("PATH_TO_FFMPEG", SERVER_ROOT . '/apps/ffmpeg/ffmpeg.exe'); + } else { + define("PATH_TO_FFMPEG", 'ffmpeg'); + } + } + $dur = shell_exec(PATH_TO_FFMPEG . " -i " . $file . " 2>&1"); + if (preg_match("/: Invalid /", $dur)) { + return false; + } + preg_match("/Duration: (.{2}):(.{2}):(.{2})/", $dur, $duration); + if (!isset($duration[1])) { + return false; + } + $hours = $duration[1]; + $minutes = $duration[2]; + $seconds = $duration[3]; + return $seconds + ($minutes * 60) + ($hours * 60 * 60); +} + function get_media_info($file) { if (!defined('PATH_TO_FFMPEG')) { From d9bfeae2623eaa5dec0d8ee9b012c7963e757b1e Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Thu, 3 Sep 2020 16:33:52 +0300 Subject: [PATCH 08/10] Delete smsgw.php --- lib/hardware/smsgw.php | 90 ------------------------------------------ 1 file changed, 90 deletions(-) delete mode 100644 lib/hardware/smsgw.php diff --git a/lib/hardware/smsgw.php b/lib/hardware/smsgw.php deleted file mode 100644 index d9a9771d7..000000000 --- a/lib/hardware/smsgw.php +++ /dev/null @@ -1,90 +0,0 @@ - \ No newline at end of file From bcbe6710885d22a9532e68f8b27b5198a01cdba3 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Fri, 4 Sep 2020 14:00:46 +0300 Subject: [PATCH 09/10] Update syncfiles.class.php --- lib/syncfiles.class.php | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/lib/syncfiles.class.php b/lib/syncfiles.class.php index f7ce0d094..ce4173cfe 100644 --- a/lib/syncfiles.class.php +++ b/lib/syncfiles.class.php @@ -1003,3 +1003,74 @@ function getFilesTree($destination, $sort = 'name') return $res; } + +function get_mime_type($filename) { + $idx = explode( '.', $filename ); + $count_explode = count($idx); + $idx = strtolower($idx[$count_explode-1]); + + $mimet = array( + 'txt' => 'text/plain', + 'htm' => 'text/html', + 'html' => 'text/html', + 'php' => 'text/html', + 'css' => 'text/css', + 'js' => 'application/javascript', + 'json' => 'application/json', + 'xml' => 'application/xml', + 'swf' => 'application/x-shockwave-flash', + 'flv' => 'video/x-flv', + + // images + 'png' => 'image/png', + 'jpe' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'gif' => 'image/gif', + 'bmp' => 'image/bmp', + 'ico' => 'image/vnd.microsoft.icon', + 'tiff' => 'image/tiff', + 'tif' => 'image/tiff', + 'svg' => 'image/svg+xml', + 'svgz' => 'image/svg+xml', + + // archives + 'zip' => 'application/zip', + 'rar' => 'application/x-rar-compressed', + 'exe' => 'application/x-msdownload', + 'msi' => 'application/x-msdownload', + 'cab' => 'application/vnd.ms-cab-compressed', + + // audio/video + 'mp3' => 'audio/mpeg', + 'qt' => 'video/quicktime', + 'mov' => 'video/quicktime', + + // adobe + 'pdf' => 'application/pdf', + 'psd' => 'image/vnd.adobe.photoshop', + 'ai' => 'application/postscript', + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + + // ms office + 'doc' => 'application/msword', + 'rtf' => 'application/rtf', + 'xls' => 'application/vnd.ms-excel', + 'ppt' => 'application/vnd.ms-powerpoint', + 'docx' => 'application/msword', + 'xlsx' => 'application/vnd.ms-excel', + 'pptx' => 'application/vnd.ms-powerpoint', + + + // open office + 'odt' => 'application/vnd.oasis.opendocument.text', + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', + ); + + if (isset( $mimet[$idx] )) { + return $mimet[$idx]; + } else { + return 'application/octet-stream'; + } +} From 9e852f57741185d4a5398b2bc19600833c9f88c9 Mon Sep 17 00:00:00 2001 From: tarasfrompir Date: Fri, 4 Sep 2020 14:01:16 +0300 Subject: [PATCH 10/10] Update stream_files.php --- modules/app_mediabrowser/stream_files.php | 73 +---------------------- 1 file changed, 1 insertion(+), 72 deletions(-) diff --git a/modules/app_mediabrowser/stream_files.php b/modules/app_mediabrowser/stream_files.php index b6935ead8..bc7664e3b 100644 --- a/modules/app_mediabrowser/stream_files.php +++ b/modules/app_mediabrowser/stream_files.php @@ -31,77 +31,6 @@ exit; } -function get_mime_type($filename) { - $idx = explode( '.', $filename ); - $count_explode = count($idx); - $idx = strtolower($idx[$count_explode-1]); - - $mimet = array( - 'txt' => 'text/plain', - 'htm' => 'text/html', - 'html' => 'text/html', - 'php' => 'text/html', - 'css' => 'text/css', - 'js' => 'application/javascript', - 'json' => 'application/json', - 'xml' => 'application/xml', - 'swf' => 'application/x-shockwave-flash', - 'flv' => 'video/x-flv', - - // images - 'png' => 'image/png', - 'jpe' => 'image/jpeg', - 'jpeg' => 'image/jpeg', - 'jpg' => 'image/jpeg', - 'gif' => 'image/gif', - 'bmp' => 'image/bmp', - 'ico' => 'image/vnd.microsoft.icon', - 'tiff' => 'image/tiff', - 'tif' => 'image/tiff', - 'svg' => 'image/svg+xml', - 'svgz' => 'image/svg+xml', - - // archives - 'zip' => 'application/zip', - 'rar' => 'application/x-rar-compressed', - 'exe' => 'application/x-msdownload', - 'msi' => 'application/x-msdownload', - 'cab' => 'application/vnd.ms-cab-compressed', - - // audio/video - 'mp3' => 'audio/mpeg', - 'qt' => 'video/quicktime', - 'mov' => 'video/quicktime', - - // adobe - 'pdf' => 'application/pdf', - 'psd' => 'image/vnd.adobe.photoshop', - 'ai' => 'application/postscript', - 'eps' => 'application/postscript', - 'ps' => 'application/postscript', - - // ms office - 'doc' => 'application/msword', - 'rtf' => 'application/rtf', - 'xls' => 'application/vnd.ms-excel', - 'ppt' => 'application/vnd.ms-powerpoint', - 'docx' => 'application/msword', - 'xlsx' => 'application/vnd.ms-excel', - 'pptx' => 'application/vnd.ms-powerpoint', - - - // open office - 'odt' => 'application/vnd.oasis.opendocument.text', - 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', - ); - - if (isset( $mimet[$idx] )) { - return $mimet[$idx]; - } else { - return 'application/octet-stream'; - } -} - function rangeDownload($file) { $fp = @fopen($file, 'rb'); @@ -196,4 +125,4 @@ function rangeDownload($file) { } fclose($fp); -} \ No newline at end of file +}