public static function CreateForActualLink($link) { $ob = new self(); $ob->SetAuthorID(GetUserID()); $ob->SetActualLink($link); $random_link = SecretLink::GenerateRandomLink(); do { $old = SecretLink::FetchBy(['select_list' => 'id', 'eq_conds' => ['public_link' => $random_link]]); if (count($old) != 0) { $random_link = SecretLink::GenerateRandomLink(); } else { break; } } while (1); $ob->SetPublicLink($random_link); $res = SecretLink::InsertToDB($ob); if (Error::IsError($res)) { return $res; } return $ob; }
<?php require_once 'utility_lgmis_lib.php'; include_once $link_to_utility_authorization; if (isset($_GET['public_link'])) { SecretLink::ClearOldLinks(); $link = SecretLink::FetchBy(['select_list' => 'actual_link', 'eq_conds' => ['public_link' => $_GET['public_link']], 'is_unique' => true]); if (Error::IsError($link)) { echo 'Ссылка не найдена'; exit; } global $link_prefix; header('Location: ' . $link_prefix . $link->GetActualLink()); exit; } $file_path = $_SERVER['DOCUMENT_ROOT'] . $link_prefix; if (isset($_GET['file_path'])) { $file_path .= $_GET['file_path']; } else { if (isset($_POST['file_path'])) { $file_path .= $_POST['file_path']; } else { echo 'exit'; exit; } } if (file_exists($file_path)) { if (!is_dir($file_path)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . urldecode(basename($file_path)) . '"');
public static function FetchBy($kwargs) { extract($kwargs, EXTR_PREFIX_ALL, 't'); $select_list = '*'; $eq_conds = array(); $order_by = ''; $limit = ''; $offset = ''; $where_addition = ''; $is_assoc = false; $is_unique = false; $special = array(); if (isset($t_select_list)) { $select_list = $t_select_list; } if (isset($t_eq_conds)) { $eq_conds = $t_eq_conds; } if (isset($t_order_by)) { $order_by = $t_order_by; } if (isset($t_limit)) { $limit = $t_limit; } if (isset($t_offset)) { $offset = $t_offset; } if (isset($t_where_addition)) { $where_addition = $t_where_addition; } if (isset($t_is_assoc)) { $is_assoc = $t_is_assoc; } if (isset($t_is_unique)) { $is_unique = $t_is_unique; } if (isset($t_special)) { $special = $t_special; } global $db_connection; $where_clause = ''; $i = 0; $size = count($eq_conds); $need_where_word = $size !== 0 || StringNotEmpty($where_addition); foreach ($eq_conds as $key => $value) { $value_tmp = $db_connection->real_escape_string($value); if (is_string($value)) { $value_tmp = '"' . $value_tmp . '"'; } $where_clause .= ' (' . $key . ' = ' . $value_tmp . ') '; if ($i < $size - 1) { $where_clause .= 'OR'; } ++$i; } if ($need_where_word) { if (StringNotEmpty($where_clause) && StringNotEmpty($where_addition)) { $where_clause = '(' . $where_clause . ') AND '; $where_addition = '(' . $where_addition . ')'; } $where_clause = "WHERE " . $where_clause . ' ' . $where_addition; } if (StringNotEmpty($order_by)) { $where_clause .= ' ORDER BY ' . $order_by; } if (StringNotEmpty($limit)) { $where_clause .= ' LIMIT ' . $limit; } if (StringNotEmpty($offset)) { $where_clause .= ' OFFSET ' . $offset; } if (!StringNotEmpty($lang)) { $lang = GetLanguage(); } $from_table = self::$table; $res = $db_connection->query("SELECT " . $select_list . " FROM " . $from_table . " " . $where_clause); if (!$res) { return new Error($db_connection->error, Error::db_error); } $res = self::ArrayFromDBResult($res, $is_assoc); $res_count = count($res); if ($is_unique) { if ($res_count > 1) { return Error::ambiguously; } if ($res_count === 0) { return Error::not_found; } } for ($i = 0, $count = count($special); $i < $count; ++$i) { switch ($special[$i]) { case 'file_type': if ($is_assoc === false) { break; } global $valid_extensions; for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['name'])) { $type = fileExtension($res[$j]['name']); if (!in_array($type, $valid_extensions)) { $type = 'file'; } $res[$j]['file_type'] = $type; } } break; case 'link_to_download': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['path_to_file']) && isset($res[$j]['name']) && isset($res[$j]['is_directory'])) { $tmp = self::FetchFromAssoc(['path_to_file' => $res[$j]['path_to_file'], 'name' => $res[$j]['name'], 'is_directory' => $res[$j]['is_directory']]); $res[$j]['link_to_download'] = $tmp->GetLinkToFile(); } } break; case 'link_to_delete': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) { $tmp = self::FetchFromAssoc(['id' => $res[$j]['id'], 'owner_id' => $res[$j]['owner_id']]); $res[$j]['link_to_delete'] = $tmp->GetLinkToDelete(); } } break; case 'link_to_edit': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) { $tmp = self::FetchFromAssoc(['id' => $res[$j]['id'], 'owner_id' => $res[$j]['owner_id']]); $res[$j]['link_to_edit'] = $tmp->GetLinkToEdit(); } } break; case 'link_to_link_to_download': if ($is_assoc === false) { break; } for ($j = 0; $j < $res_count; ++$j) { if (isset($res[$j]['id']) && isset($res[$j]['owner_id'])) { $tmp = self::FetchFromAssoc(['path_to_file' => $res[$j]['path_to_file'], 'name' => $res[$j]['name'], 'id' => $res[$j]['id']]); $link = $tmp->CreateDownloadLink(); $res[$j]['link_to_link_to_download'] = SecretLink::WrapLinkToButton($link->GetPublicLink()); } } break; default: break; } } if (!$is_unique) { return $res; } else { return $res[0]; } }
$res['projects'] = $projects; $res['projects_name'] = Language::PublicMenu('projects'); $content = json_encode($res); break; default: break; } } else { if (isset($_REQUEST['download'])) { switch ($_REQUEST['download']) { case 'link': switch ($_REQUEST['type']) { case 'file': $file = MyFile::FetchBy(['select_list' => 'name, path_to_file', 'eq_conds' => ['id' => $_REQUEST['id']], 'is_unique' => true]); $url = $file->GetURLToFile(); $link = SecretLink::CreateForActualLink($url); if (Error::IsError($link)) { $content = json_encode(['error' => Error::ToString($link)]); break; } global $link_prefix; $content = json_encode(['link' => 'http://' . $_SERVER["HTTP_HOST"] . $link_prefix . 'download/' . $link->GetPublicLink()]); break; default: break; } break; case 'more': switch ($_REQUEST['type']) { case Article::$type: $need_authorization = false;