載入中 |
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
ob_start("ob_gzhandler");
else ob_start();
include 'CSP.php';
header("X-Frame-Options: DENY");
header('X-XSS-Protection:1; mode=block');
header('Strict-Transport-Security: max-age=31536000;');
header_remove('X-Powered-By');
$this_page = "/download.php";
$home_str = "/home".$this_page;
if(substr($_SERVER['REQUEST_URI'],0,strlen($this_page)) == $this_page || substr($_SERVER['REQUEST_URI'],0,strlen($home_str)) == $home_str){
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
include "404.php";
}
ini_set('session.cookie_httponly', 1);
ini_set('session.cookie_secure', 1);
ini_set('session.cookie_domain', 'yangfamily.tw');
ini_set('session.cookie_samesite', 'Strict');
ini_set('session.gc_maxlifetime', 60*60*24*3650);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 1);
session_save_path('sessions');
session_start();
include 'csrf/csrf.class.php';
$csrf = new csrf();
// Generate Token Id and Valid
$token_id = $csrf->get_token_id();
$token_value = $csrf->get_token($token_id);
// Generate Random Form Names
$form_names = $csrf->form_names(array('contact_name', 'contact_email','contact_tel','contact_gender','contact_content'), false);
include "../mysql_db_connection.php";
include "chat_online_update_parameter.php";
include "site_url.php";
$link = new mysqli($MYSQL_SERVER_SITE,$MYSQL_DB_USER,$MYSQL_DB_PASS,$MYSQL_DB_NAME);
$link->set_charset('utf8mb4');
$link->query('SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci');
function path_info($path,$r)
{
$dirname = '';
$basename = '';
$extension = '';
$filename = '';
$pos = strrpos($path, '/');
if($pos !== false) {
$dirname = substr($path, 0, $pos);
$basename = substr($path, $pos + 1);
} else {
$basename = $path;
}
$ext = strrchr($basename, '.');
if($ext !== false) {
$extension = substr($ext, 1);
}
$filename = $basename;
$pos = strrpos($basename, '.');
if($pos !== false) {
$filename = substr($basename, 0, $pos);
}
switch($r){
case PATHINFO_DIRNAME:
return $dirname;
break;
case PATHINFO_BASENAME:
return $basename;
break;
case PATHINFO_EXTENSION:
return $extension;
break;
case PATHINFO_FILENAME:
return $filename;
break;
default:
return "";
}
}
$str = "select introduction from yangfamily_yang where pattern='slideshow'";
$list = $link->query($str);
list($introduction) = $list->fetch_row();
$list->close();
$name0 = array();
$name = array();
$str = "select id,title from yangfamily_yang where pattern='members_yang' order by id asc";
$list = $link->query($str);
while(list($id,$title) = $list->fetch_row()){
$name0[$id] = $title;
$name[$id] = htmlspecialchars($title);
}
$list->close();
$str = "select title from yangfamily_yang where pattern='grayscale'";
$list = $link->query($str);
list($grayscale) = $list->fetch_row();
$list->close();
$read_num = 20;
$d_s = array(
"public",
"dad",
"mom",
"tetsuhiko",
"candy",
"maggie");
$d_array = array(
"undefined" => "檔案下載",
"public" => "共用檔案庫",
"dad" => $name0[0]."的檔案庫",
"mom" => $name0[1]."的檔案庫",
"tetsuhiko" => $name0[2]."的檔案庫",
"candy" => $name0[3]."的檔案庫",
"maggie" => $name0[4]."的檔案庫");
$id_array = array(
"undefined" => "5",
"public" => "51",
"dad" => "52",
"mom" => "53",
"tetsuhiko" => "54",
"candy" => "55",
"maggie" => "56");
$new_to_old = array(
"undefined" => "undefined",
"public" => "public",
"dad" => "dad",
"mom" => "mom",
"tetsuhiko" => "redwhale",
"candy" => "s1",
"maggie" => "s2");
$old_to_new = array(
"undefined" => "undefined",
"public" => "public",
"dad" => "dad",
"mom" => "mom",
"redwhale" => "tetsuhiko",
"s1" => "candy",
"s2" => "maggie");
if(isset($_GET['d']) && !empty($_GET['d']) && in_array($_GET['d'],array_keys($d_array))){
$d = $_GET['d'];
}else{
$d = "undefined";
}
$main_q = "";
$main_q_len = 0;
$keyword_value = "";
$q = "";
$t = "";
function pregQuote($string){ //類似PHP函數的preg_quote,只是它不跳脫「減號 (-)」這個字元
$pattern = '/([.\\\\+*?\\[\\^\\]$(){}=!<>|:\\/])/';
$replacement = '\\\\$1';
return preg_replace($pattern, $replacement, $string);
}
function insert_keyword_into_db($t){
global $link;
$q = trim($t);
// Get IP Address
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
}else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}
include "../array-lang_full_name.php";
$ip_to_long = ip2long($ip);
$str = "select country from ip_to_country2 where start<='$ip_to_long' and end>='$ip_to_long'";
$list = $link->query($str);
list($country) = $list->fetch_row();
$list->close();
if(empty($country)) $country = "Unknown";
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
$lang = strtolower(strtok(strip_tags($_SERVER['HTTP_ACCEPT_LANGUAGE']), ','));
else
$lang = "Unknown";
if(isset($lang_full_name[$lang]))
$lang_name = $lang_full_name[$lang];
else
$lang_name = "Unknown";
if(isset($_SERVER['HTTP_USER_AGENT']))
$browser = $_SERVER['HTTP_USER_AGENT'];
else
$browser = "Unknown";
$time = time();
$hidden = (preg_match("/([\s,+ ]+)/u",$q) || strlen($q) <= 0 || substr($q,0,1) === "-")?'T':'F';
$ip = $link->real_escape_string($ip);
$country = $link->real_escape_string($country);
$browser = $link->real_escape_string($browser);
$lang_name = $link->real_escape_string($lang_name);
$str = "insert into yangfamily_keyword (hidden,time,content,ip,country,browser,pc_language) values ('$hidden','$time','$q','$ip','$country','$browser','$lang_name')";
$link->query($str);
if($hidden == "T" && strlen($q) > 0){
$result = array();
$keywords = preg_split("/([\s,+ ]+)/u",$q);
$keywords_tmp = count($keywords);
for($i = 0; $i < $keywords_tmp; $i++){
$keyword = trim($keywords[$i]);
if(substr($keyword,0,1) === "-" && strlen($keyword) > 1){
array_push($result,substr($keyword,1));
}else if(strlen($keyword) > 0){
array_push($result,$keyword);
}
}
$str = "insert into yangfamily_keyword (hidden,time,content,ip,country,browser,pc_language) values ";
$result_tmp = count($result);
for($i = 0; $i < $result_tmp; $i++){
if($i > 0)
$str.=",";
$str.="('F','$time','".$result[$i]."','$ip','$country','$browser','$lang_name')";
}
$link->query($str);
}
}
function string_to_utf8($charset, $text, $htmlspecialchars){ //$charset設成'UTF-8'
$encoding_list = array('BIG-5', 'UCS-4', 'UCS-4BE', 'UCS-4LE', 'UCS-2', 'UCS-2BE', 'UCS-2LE', 'UTF-32', 'UTF-32BE', 'UTF-32LE', 'UTF-16', 'UTF-16BE', 'UTF-16LE', 'UTF-7', 'UTF7-IMAP', 'UTF-8', 'ASCII', 'EUC-JP', 'SJIS', 'eucJP-win', 'SJIS-win', 'ISO-2022-JP', 'ISO-2022-JP-MS', 'CP932', 'CP51932', 'MacJapanese', 'SJIS-DOCOMO', 'SJIS-KDDI', 'SJIS-SOFTBANK', 'UTF-8-DOCOMO', 'UTF-8-Mobile#KDDI-A', 'UTF-8-KDDI', 'UTF-8-SOFTBANK', 'ISO-2022-JP-KDDI', 'JIS', 'JIS-ms', 'CP50220', 'CP50220raw', 'CP50221', 'CP50222', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'byte2be', 'byte2le', 'byte4be', 'byte4le', 'BASE64', 'HTML-ENTITIES', '7bit', '8bit', 'EUC-CN', 'CP936', 'GB18030', 'HZ', 'EUC-TW', 'CP950', 'EUC-KR', 'CP949', 'ISO-2022-KR', 'CP1251', 'CP1252', 'IBM866', 'KOI8-R');
if(mb_check_encoding ($text, $charset))
$string = ($htmlspecialchars)?htmlspecialchars(iconv($charset, "utf-8", $text)):iconv($charset, "utf-8", $text);
else
$string = ($htmlspecialchars)?htmlspecialchars(mb_convert_encoding($text, "utf-8", $encoding_list)):mb_convert_encoding($text, "utf-8", $encoding_list);
return $string;
}
if(isset($_GET['q']) && strlen(trim($_GET['q'])) > 0 && !isset($_GET['feed'])){
$main_q = string_to_utf8('UTF-8', trim(str_replace(array('"',"'","_","%","\\"),"",$_GET['q'])), 0);
$keyword_value = htmlspecialchars($main_q);
$q = $link->real_escape_string(pregQuote($main_q, '/'));
$t = $link->real_escape_string($main_q);
insert_keyword_into_db($t);
$main_q_len = strlen($main_q) > 0;
}
$keyword = array();
$nKeyword = array();
$keywords = preg_split("/([\s, ]+)/u",$q);
$keywords_tmp = count($keywords);
function Vbv($col,$n,$g){
global $nKeyword,$keyword;
$result_array = array();
if(!$n){
for($i = 0; $i < $g; $i++){
if(substr($nKeyword[$i],0,2) == "[^")
array_push($result_array,$col." NOT REGEXP '".$nKeyword[$i]."'");
else
array_push($result_array,$col." NOT LIKE '%".$nKeyword[$i]."%'");
}
return implode(" and ",$result_array);
}else{
for($i = 0; $i < $g; $i++){
if(substr($keyword[$i],0,2) == "[^")
array_push($result_array,$col." REGEXP '".$keyword[$i]."'");
else
array_push($result_array,$col." LIKE '%".$keyword[$i]."%'");
}
return implode(" and ",$result_array);
}
}
$slk1 = "";
for($h = 0; $h < 2; $h++){
for($i = 0; $i < $keywords_tmp; $i++){
$ttr = explode("+",$keywords[$i]);
$ttr_tmp = count($ttr);
for($j = 0; $j < $ttr_tmp; $j++){
$tr = trim($ttr[$j]);
if(substr($tr,0,1) === "-" && strlen($tr) > 1){
$kw = substr($tr,1);
if($h == 0){
if(!ctype_alnum($kw))
array_push($nKeyword,$kw);
}else if(ctype_alpha($kw))
array_push($nKeyword,"[^a-zA-Z]".$kw."[^a-zA-Z]|^".$kw."$|^".$kw."[^a-zA-Z]|[^a-zA-Z]".$kw."$");
else if(ctype_digit($kw))
array_push($nKeyword,"[^0-9]".$kw."[^0-9]|^".$kw."$|^".$kw."[^0-9]|[^0-9]".$kw."$");
else if(ctype_alnum($kw))
array_push($nKeyword,"[^a-zA-Z0-9]".$kw."[^a-zA-Z0-9]|^".$kw."$|^".$kw."[^a-zA-Z0-9]|[^a-zA-Z0-9]".$kw."$");
}else if(strlen($tr) > 0){
if($h == 0)
array_push($keyword,$tr);
else if(ctype_alpha($tr))
array_push($keyword,"[^a-zA-Z]".$tr."[^a-zA-Z]|^".$tr."$|^".$tr."[^a-zA-Z]|[^a-zA-Z]".$tr."$");
else if(ctype_digit($tr))
array_push($keyword,"[^0-9]".$tr."[^0-9]|^".$tr."$|^".$tr."[^0-9]|[^0-9]".$tr."$");
else if(ctype_alnum($tr))
array_push($keyword,"[^a-zA-Z0-9]".$tr."[^a-zA-Z0-9]|^".$tr."$|^".$tr."[^a-zA-Z0-9]|[^a-zA-Z0-9]".$tr."$");
}
}
}
$nKeyword_count = count($nKeyword);
$keyword_count = count($keyword);
if($nKeyword_count > 0 || $keyword_count > 0)
$slk1 .= " and ";
$slk1 .= Vbv("search",0,$nKeyword_count);
if($nKeyword_count > 0 && $keyword_count > 0)
$slk1 .= " and ";
$slk1 .= Vbv("search",1,$keyword_count);
$keyword = array();
$nKeyword = array();
}
$page_data = "";
$page = 1;
if($main_q_len){
$page_data = "q=".rawurlencode($main_q);
}
if(isset($_POST['page']) && ctype_digit($_POST['page']) && $_POST['page'] > 0){
$page_data = (($page_data == "")?"":$page_data."&")."page=".intval($_POST['page']);
$page = intval($_POST['page']);
}elseif(isset($_GET['page']) && ctype_digit($_GET['page']) && $_GET['page'] > 0){
$page_data = (($page_data == "")?"":$page_data."&")."page=".intval($_GET['page']);
$page = intval($_GET['page']);
}
if(isset($_POST['id']) && ctype_digit($_POST['id']) && $_POST['id'] > 0){
$page_data = (($page_data == "")?"":$page_data."&")."folder=".intval($_POST['id']);
$folder = intval($_POST['id']);
}elseif(isset($_GET['id']) && ctype_digit($_GET['id']) && $_GET['id'] > 0){
$page_data = (($page_data == "")?"":$page_data."&")."folder=".intval($_GET['id']);
$folder = intval($_GET['id']);
}else{
$folder = 0;
}
$o0 = "";
if($d == "undefined")
$category_query = "";
elseif($d == "public")
$category_query = " and introduction='public'";
else
$category_query = " and category='".$new_to_old[$d]."'";
if($folder > 0){
$str = "select keywords from yangfamily_articles where id='$folder' and hidden='F' and head='F'".$category_query." and pattern='file_folder'";
$list = $link->query($str);
$c = $list->num_rows;
if($c <= 0){
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
include "404.php";
}
list($keywords2) = $list->fetch_row();
$list->close();
if(!$main_q_len && !isset($_GET['feed'])){
// Get IP Address
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
}else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}
include "../array-lang_full_name.php";
/*$str = "select count(*) from yangfamily_click where pattern='file_click'";
$list = $link->query($str);
list($c) = $list->fetch_row();
$c++;*/
$ip_to_long = ip2long($ip);
$str = "select country from ip_to_country2 where start<='$ip_to_long' and end>='$ip_to_long'";
$list = $link->query($str);
list($country) = $list->fetch_row();
$list->close();
if(empty($country)) $country = "Unknown";
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
$lang = strtolower(strtok(strip_tags($_SERVER['HTTP_ACCEPT_LANGUAGE']), ','));
else
$lang = "Unknown";
if(isset($lang_full_name[$lang]))
$lang_name = $lang_full_name[$lang];
else
$lang_name = "Unknown";
if(isset($_SERVER['HTTP_USER_AGENT']))
$browser = $_SERVER['HTTP_USER_AGENT'];
else
$browser = "Unknown";
$time = time();
//$str = "insert into yangfamily_click (id,to_time,category,time,title,pattern,ip,country,browser,pc_language,author) values ('$c','$folder','','$time','','file_click','$ip','$country','$browser','$lang_name','111')";
$ip = $link->real_escape_string($ip);
$country = $link->real_escape_string($country);
$browser = $link->real_escape_string($browser);
$lang_name = $link->real_escape_string($lang_name);
$str = "insert into yangfamily_click (to_time,category,time,title,pattern,ip,country,browser,pc_language,author) values ('$folder','','$time','','file_click','$ip','$country','$browser','$lang_name','111')";
$link->query($str);
$str = "update yangfamily_count set count=count+1 where to_time='$folder' and category='file'";
$link->query($str);
$str = "insert into yangfamily_count (to_time,category,count) select '$folder','file','1' where not exists (select * from yangfamily_count where to_time='$folder' and category='file')";
$link->query($str);
}
}
//$kkj = "CONCAT(title,' ',content,' ',thumbnail,' ',explode_and_replace(keywords,'|',' '))";
$start_num = $read_num*($page-1);
function to_folder_query(){
global $category_query,$folder,$link;
$layer = 0;
$has_folder_array = array();
$has_folder_array[$layer] = array($folder);
do {
$has_folder_array[$layer+1] = array();
$has_folder_array_tmp = count($has_folder_array[$layer]);
for($j = 0; $j < $has_folder_array_tmp; $j++){
$str = "select id from yangfamily_articles where to_time='".$has_folder_array[$layer][$j]."' and hidden='F' and head='F'".$category_query." and (pattern='file_folder')";
$list = $link->query($str);
while(list($folder_id) = $list->fetch_row()){
array_push($has_folder_array[$layer+1],$folder_id);
}
$list->close();
}
$layer++;
}while(count($has_folder_array[$layer]) > 0);
$result_array = array();
$has_folder_array_tmp = count($has_folder_array);
for($i = 0; $i < $has_folder_array_tmp; $i++){
$has_folder_array_i_tmp = count($has_folder_array[$i]);
for($j = 0; $j < $has_folder_array_i_tmp; $j++){
array_push($result_array,"to_time='".$has_folder_array[$i][$j]."'");
}
}
return "(".implode(" or ",$result_array).")";
}
$str = "select id,category,time,title,introduction,pattern,location,thumbnail,author from yangfamily_articles where ".(($main_q_len)?to_folder_query():"to_time='$folder'")." and hidden='F' and head='F'".$category_query." and (pattern='add_file' or pattern='file_folder')".$slk1." order by case when pattern = 'file_folder' then 1 else 2 end, time desc, serial desc";
$list = $link->query($str);
$numResults = $list->num_rows;
$counter = 0;
$i = 0;
$g = 0;
$data = array();
while(list($id,$category,$time,$title,$isPublic,$pattern,$filesize,$filename,$author) = $list->fetch_row()){
if(isset($_GET['feed']) || $g >= $start_num && $i < $read_num){
$o0 .= $yangfamily_site.'/img/icon/'.(($pattern == "file_folder")?"folder":strtolower(path_info($filename, PATHINFO_EXTENSION))).'.png|';
$data[$i] = array();
$data[$i]["id"] = $id;
$data[$i]["category"] = (array_key_exists($category,$old_to_new))?$old_to_new[$category]:$category;
$data[$i]["time"] = $time;
$data[$i]["title"] = $title;
$data[$i]["isPublic"] = $isPublic;
$data[$i]["pattern"] = $pattern;
$data[$i]["filesize"] = $filesize;
$data[$i]["filename"] = $filename;
$data[$i]["author"] = $author;
$i++;
}else if($i >= $read_num){
break;
}
$g++;
}
$list->close();
$numResults2 = $i;
$page_title = "";
if($folder > 0){
$to_folder_array = array();
$to_folder = $folder;
$to_folder_title_array = array();
do {
array_push($to_folder_array,$to_folder);
$str = "select to_time,title from yangfamily_articles where id='$to_folder' and hidden='F' and head='F' and (pattern='file_folder')";
$list = $link->query($str);
list($to_folder,$to_folder_title)=$list->fetch_row();
$list->close();
array_push($to_folder_title_array,$to_folder_title);
}while($to_folder > 0);
$page_title .= htmlspecialchars($to_folder_title_array[0]);
}else{
$keywords2 = "楊家人,家庭,網站,部落格,家庭成員,檔案,下載,資料夾,家人";
$page_title .= htmlspecialchars($d_array[$d]);
}
$page_title .= " - 楊家人";
$link_url = '/download'.(($d == "undefined")?"":"/".$d).(($folder > 0)?"/".$folder:"");
$this_page_location_href = '["'.$link_url.'","'.$link_url.'/search"]';
$link_url = $yangfamily_site.$link_url;
$feed_link_url = $link_url."/feed";
if(isset($_GET['feed'])){
header("Content-Type: text/xml; charset=utf-8");
$rssfeed = '';
$rssfeed .= '
':'').'發佈時間:'.date("Y-m-d H:i:s",$data[$i]["time"]).'
發佈人:'.$name[$data[$i]["author"]].'
'.(($data[$i]["pattern"] == "add_file")?'檔案大小:'.$filesize.'
':'').(($category_str)?'分類:'.$category_str:'')).'
載入中 |