workshop fix 1234
This commit is contained in:
parent
6be904e903
commit
3d7aa64db6
15 changed files with 509 additions and 484 deletions
|
|
@ -23,7 +23,6 @@
|
|||
* download_zip – download a .zip/.tar.gz and extract into the server path
|
||||
* download_file – download a single file into the server path
|
||||
* post_script – run only a post-install bash script (no download)
|
||||
* steam_workshop – install/update via Steam Workshop item IDs through agent
|
||||
* minecraft_jar – download a Minecraft server jar and update startup config
|
||||
* profile_copy – copy a profile directory tree into the server home
|
||||
*
|
||||
|
|
@ -41,7 +40,6 @@ function get_server_content_categories()
|
|||
{
|
||||
return array(
|
||||
'file_download' => 'Downloadable Mod',
|
||||
'workshop_item' => 'Steam Workshop Mods',
|
||||
'config_edit' => 'Configuration Package',
|
||||
'scripted_installer' => 'Scripted Installer',
|
||||
);
|
||||
|
|
@ -79,7 +77,6 @@ function scm_get_addon_type_from_install_method($install_method)
|
|||
$install_method = trim((string)$install_method);
|
||||
$map = array(
|
||||
'download_zip' => 'file_download',
|
||||
'steam_workshop' => 'workshop_item',
|
||||
'config_edit' => 'config_edit',
|
||||
'post_script' => 'scripted_installer',
|
||||
);
|
||||
|
|
@ -93,9 +90,6 @@ function scm_normalize_addon_type($addon_type, $install_method = '')
|
|||
if (isset($categories[$addon_type])) {
|
||||
return $addon_type;
|
||||
}
|
||||
if ($addon_type === 'workshop') {
|
||||
return 'workshop_item';
|
||||
}
|
||||
if ($addon_type === 'script') {
|
||||
return 'scripted_installer';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
// Central category map — load so we can iterate all types dynamically.
|
||||
require_once(dirname(__FILE__) . '/server_content_categories.php');
|
||||
require_once(dirname(__FILE__) . '/server_content_helpers.php');
|
||||
require_once("modules/config_games/server_config_parser.php");
|
||||
|
||||
function exec_ogp_module() {
|
||||
global $db;
|
||||
|
|
@ -46,10 +44,7 @@ function exec_ogp_module() {
|
|||
}
|
||||
if ($home_info)
|
||||
{
|
||||
scm_ensure_workshop_schema($db);
|
||||
$home_cfg_id = $home_info['home_cfg_id'];
|
||||
$server_xml = read_server_config(SERVER_CONFIG_LOCATION . "/" . $home_info['home_cfg_file']);
|
||||
$workshop_supported = ($server_xml !== false && scm_workshop_is_supported($server_xml));
|
||||
echo "<h2>Server Content: ".htmlentities($home_info['home_name'])."</h2>\n".
|
||||
"<table class='center' >\n".
|
||||
"<tr>\n";
|
||||
|
|
@ -69,32 +64,15 @@ function exec_ogp_module() {
|
|||
"NATURAL JOIN OGP_DB_PREFIXconfig_homes " .
|
||||
"WHERE addon_type='" . $db->realEscapeSingle($type_key) . "' " .
|
||||
"AND home_cfg_id=" . (int)$home_cfg_id . $query_groups
|
||||
);
|
||||
$items_qty = is_array($items) ? count((array)$items) : 0;
|
||||
if ($type_key === 'workshop_item' && $workshop_supported && $items_qty < 1) {
|
||||
$items = array(array('addon_id' => 0, 'name' => 'Steam Workshop', 'game_name' => isset($home_info['game_name']) ? $home_info['game_name'] : ''));
|
||||
$items_qty = 1;
|
||||
}
|
||||
if ($items && $items_qty >= 1)
|
||||
{
|
||||
if ($printed_any_cell)
|
||||
);
|
||||
$items_qty = is_array($items) ? count((array)$items) : 0;
|
||||
if ($items && $items_qty >= 1)
|
||||
{
|
||||
if ($printed_any_cell)
|
||||
echo "</td><td>\n";
|
||||
else
|
||||
echo "<td>\n";
|
||||
$printed_any_cell = true;
|
||||
// Workshop items route to the workshop_content page where users
|
||||
// enter their own Workshop IDs. All other types use the installer.
|
||||
if ($type_key === 'workshop_item') {
|
||||
$first_addon_id = isset($items[0]['addon_id']) ? (int)$items[0]['addon_id'] : 0;
|
||||
echo "<a href='?m=addonsmanager&p=workshop_content" .
|
||||
"&home_id=" . (int)$home_id .
|
||||
"&mod_id=" . (int)$mod_id .
|
||||
($first_addon_id > 0 ? "&addon_id=" . $first_addon_id : '') .
|
||||
"&ip=" . htmlspecialchars($ip) .
|
||||
"&port=" . htmlspecialchars($port) . "'>" .
|
||||
htmlspecialchars($type_label) . ($workshop_supported ? "" : " (" . $items_qty . ")") .
|
||||
"</a>\n";
|
||||
} else {
|
||||
else
|
||||
echo "<td>\n";
|
||||
$printed_any_cell = true;
|
||||
echo "<a href='?m=addonsmanager&p=addons" .
|
||||
"&home_id=" . (int)$home_id .
|
||||
"&mod_id=" . (int)$mod_id .
|
||||
|
|
@ -105,7 +83,6 @@ function exec_ogp_module() {
|
|||
"</a>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($printed_any_cell)
|
||||
echo "</td>\n";
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ function do_progress($kbytes,$totalsize)
|
|||
function show_back($home_id)
|
||||
{
|
||||
if( isset($_SESSION['fm_cwd_'.$home_id]) && preg_match("/^\/*$/",$_SESSION['fm_cwd_'.$home_id]) == 0 )
|
||||
return "<tr><td colspan='5' ><a href=\"?m=litefm&home_id=$home_id&back\" style='padding-left:5px;' > .. ".get_lang("level_up")."</a></td></tr>";
|
||||
return "<tr><td colspan='5' ><a class='btn btn-sm btn-success' href=\"?m=litefm&home_id=$home_id&back\"> .. ".get_lang("level_up")."</a></td></tr>";
|
||||
}
|
||||
|
||||
function litefm_check($home_id)
|
||||
|
|
@ -200,4 +200,4 @@ function litefm_check($home_id)
|
|||
|
||||
return TRUE;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -51,6 +51,128 @@ function create_drop_box_from_array_onchange($input_array,$listname,$current_val
|
|||
return $retval;
|
||||
}
|
||||
|
||||
function steam_workshop_h($value)
|
||||
{
|
||||
return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
function steam_workshop_request($url, $context, &$error = "")
|
||||
{
|
||||
$response = @file_get_contents($url, false, $context);
|
||||
if($response !== FALSE)
|
||||
return $response;
|
||||
|
||||
$http_response = isset($http_response_header) ? implode(" | ", $http_response_header) : "";
|
||||
$error = $http_response != "" ? $http_response : "request_failed";
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function steam_workshop_extract_ids($value)
|
||||
{
|
||||
$ids = array();
|
||||
$value = trim((string)$value);
|
||||
if($value === "")
|
||||
return $ids;
|
||||
|
||||
if(preg_match_all('/[?&]id=(\d+)/i', $value, $url_matches))
|
||||
{
|
||||
foreach($url_matches[1] as $url_id)
|
||||
$ids[] = $url_id;
|
||||
$value = preg_replace('/https?:\/\/\S+/i', ' ', $value);
|
||||
}
|
||||
|
||||
$tokens = preg_split('/[\s,;]+/', $value);
|
||||
foreach($tokens as $token)
|
||||
{
|
||||
$token = trim($token);
|
||||
if($token !== "" && ctype_digit($token))
|
||||
$ids[] = $token;
|
||||
}
|
||||
|
||||
$ids = array_values(array_unique($ids));
|
||||
return $ids;
|
||||
}
|
||||
|
||||
function steam_workshop_normalize_checkbox_ids($ids)
|
||||
{
|
||||
if(!is_array($ids))
|
||||
return array();
|
||||
|
||||
$normalized = array();
|
||||
foreach($ids as $id)
|
||||
{
|
||||
$id = trim((string)$id);
|
||||
if($id !== "" && ctype_digit($id))
|
||||
$normalized[] = $id;
|
||||
}
|
||||
return array_values(array_unique($normalized));
|
||||
}
|
||||
|
||||
function steam_workshop_collect_requested_ids($manual_ids, $xml_ids = array(), $search_ids = array())
|
||||
{
|
||||
$collected = array_merge(
|
||||
steam_workshop_extract_ids($manual_ids),
|
||||
steam_workshop_normalize_checkbox_ids($xml_ids),
|
||||
steam_workshop_normalize_checkbox_ids($search_ids)
|
||||
);
|
||||
return array_values(array_unique($collected));
|
||||
}
|
||||
|
||||
function steam_workshop_fetch_published_file_details($workshop_mod_ids)
|
||||
{
|
||||
$details = array();
|
||||
$workshop_mod_ids = steam_workshop_normalize_checkbox_ids($workshop_mod_ids);
|
||||
if(empty($workshop_mod_ids))
|
||||
return $details;
|
||||
|
||||
$request = array('itemcount' => count($workshop_mod_ids));
|
||||
foreach($workshop_mod_ids as $index => $workshop_mod_id)
|
||||
$request["publishedfileids[$index]"] = $workshop_mod_id;
|
||||
|
||||
$context = stream_context_create(array('http' => array(
|
||||
'method' => "POST",
|
||||
'header' => "Content-type: application/x-www-form-urlencoded\r\nUser-Agent: GSP-Panel-SteamWorkshop/1.0\r\n",
|
||||
'content' => http_build_query($request),
|
||||
'timeout' => 10,
|
||||
'ignore_errors' => true
|
||||
)));
|
||||
|
||||
$error = "";
|
||||
$json = steam_workshop_request('https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/', $context, $error);
|
||||
if($json === FALSE)
|
||||
$json = steam_workshop_request('http://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/', $context, $error);
|
||||
|
||||
if($json === FALSE)
|
||||
return $details;
|
||||
|
||||
$response_array = json_decode($json, true);
|
||||
if(!is_array($response_array) || !isset($response_array['response']['publishedfiledetails']))
|
||||
return $details;
|
||||
|
||||
foreach($response_array['response']['publishedfiledetails'] as $app_info)
|
||||
{
|
||||
if(!is_array($app_info) || empty($app_info['publishedfileid']))
|
||||
continue;
|
||||
|
||||
$publishedfileid = (string)$app_info['publishedfileid'];
|
||||
$details[$publishedfileid] = array(
|
||||
'publishedfileid' => $publishedfileid,
|
||||
'title' => isset($app_info['title']) ? $app_info['title'] : $publishedfileid,
|
||||
'description' => isset($app_info['description']) ? $app_info['description'] : '',
|
||||
'preview_url' => isset($app_info['preview_url']) ? $app_info['preview_url'] : '',
|
||||
'file_url' => isset($app_info['file_url']) ? $app_info['file_url'] : '',
|
||||
'filename' => isset($app_info['filename']) ? basename($app_info['filename']) : '',
|
||||
'file_size' => isset($app_info['file_size']) ? $app_info['file_size'] : '',
|
||||
'creator_app_id' => isset($app_info['creator_app_id']) ? (string)$app_info['creator_app_id'] : '',
|
||||
'consumer_app_id' => isset($app_info['consumer_app_id']) ? (string)$app_info['consumer_app_id'] : '',
|
||||
'time_updated' => isset($app_info['time_updated']) ? $app_info['time_updated'] : 0,
|
||||
'time_created' => isset($app_info['time_created']) ? $app_info['time_created'] : 0,
|
||||
);
|
||||
}
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
function get_mod_names_list($mods_list, $xml_mods)
|
||||
{
|
||||
$mod_names = "";
|
||||
|
|
@ -71,43 +193,231 @@ function get_mod_names_list($mods_list, $xml_mods)
|
|||
|
||||
function get_mod_info($workshop_mod_id)
|
||||
{
|
||||
$request = http_build_query(array('itemcount' => '1', 'publishedfileids[0]' => "$workshop_mod_id"));
|
||||
|
||||
$context = stream_context_create
|
||||
(array('http' => array
|
||||
(
|
||||
'method' => "POST",
|
||||
'header' => "Content-type: application/x-www-form-urlencoded",
|
||||
'content' => $request,
|
||||
'timeout' => 5
|
||||
)));
|
||||
|
||||
$json = @file_get_contents('http://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/', false, $context);
|
||||
$response_array = json_decode($json, true);
|
||||
$app_info = $response_array['response']['publishedfiledetails'][0];
|
||||
return array($app_info['title'], $app_info['description'], $app_info['preview_url'], $app_info['file_url'], basename($app_info['filename']), $app_info['file_size']);
|
||||
$details = steam_workshop_fetch_published_file_details(array($workshop_mod_id));
|
||||
if(!isset($details[$workshop_mod_id]))
|
||||
return array($workshop_mod_id, '', '', '', '', '');
|
||||
|
||||
$app_info = $details[$workshop_mod_id];
|
||||
return array(
|
||||
$app_info['title'],
|
||||
$app_info['description'],
|
||||
$app_info['preview_url'],
|
||||
$app_info['file_url'],
|
||||
$app_info['filename'],
|
||||
$app_info['file_size']
|
||||
);
|
||||
}
|
||||
|
||||
function belongs_to_workshop($workshop_mod_id, $workshop_id)
|
||||
{
|
||||
$request = http_build_query(array('itemcount' => '1', 'publishedfileids[0]' => "$workshop_mod_id"));
|
||||
|
||||
$context = stream_context_create
|
||||
(array('http' => array
|
||||
(
|
||||
'method' => "POST",
|
||||
'header' => "Content-type: application/x-www-form-urlencoded",
|
||||
'content' => $request,
|
||||
'timeout' => 5
|
||||
)));
|
||||
|
||||
$json = @file_get_contents('http://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/', false, $context);
|
||||
$response_array = json_decode($json, true);
|
||||
$app_info = $response_array['response']['publishedfiledetails'][0];
|
||||
if($app_info['creator_app_id'] == $workshop_id)
|
||||
return true;
|
||||
else
|
||||
$details = steam_workshop_fetch_published_file_details(array($workshop_mod_id));
|
||||
if(!isset($details[$workshop_mod_id]))
|
||||
return false;
|
||||
|
||||
$app_info = $details[$workshop_mod_id];
|
||||
return ($app_info['creator_app_id'] == $workshop_id || $app_info['consumer_app_id'] == $workshop_id);
|
||||
}
|
||||
|
||||
function steam_workshop_sync_xml_mods(&$xml, $xml_file, $workshop_id, $workshop_mod_ids, &$errors)
|
||||
{
|
||||
$errors = array();
|
||||
$workshop_mod_ids = steam_workshop_normalize_checkbox_ids($workshop_mod_ids);
|
||||
if(empty($workshop_mod_ids))
|
||||
return true;
|
||||
|
||||
$known_mods = array();
|
||||
if(isset($xml->mods) && isset($xml->mods->mod))
|
||||
{
|
||||
foreach($xml->mods->mod as $mod)
|
||||
$known_mods[(string)$mod['id']] = true;
|
||||
}
|
||||
|
||||
$missing_ids = array();
|
||||
foreach($workshop_mod_ids as $workshop_mod_id)
|
||||
{
|
||||
if(!isset($known_mods[$workshop_mod_id]))
|
||||
$missing_ids[] = $workshop_mod_id;
|
||||
}
|
||||
|
||||
if(empty($missing_ids))
|
||||
return true;
|
||||
|
||||
$details = steam_workshop_fetch_published_file_details($missing_ids);
|
||||
$dom = dom_import_simplexml($xml)->ownerDocument;
|
||||
$dom->formatOutput = true;
|
||||
$mods = $dom->getElementsByTagName('mods')->item(0);
|
||||
if(!$mods)
|
||||
{
|
||||
$mods = $dom->createElement('mods');
|
||||
$dom->documentElement->appendChild($mods);
|
||||
}
|
||||
|
||||
foreach($missing_ids as $workshop_mod_id)
|
||||
{
|
||||
if(!isset($details[$workshop_mod_id]))
|
||||
{
|
||||
$errors[] = get_lang_f('failed_to_fetch_workshop_item_details', $workshop_mod_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
$app_info = $details[$workshop_mod_id];
|
||||
if($app_info['creator_app_id'] != $workshop_id && $app_info['consumer_app_id'] != $workshop_id)
|
||||
{
|
||||
$errors[] = get_lang_f('mod_does_not_belong_to_workshop', $workshop_mod_id);
|
||||
continue;
|
||||
}
|
||||
|
||||
$mod = new SimpleXMLElement('<mod/>');
|
||||
$mod->addAttribute('id', $workshop_mod_id);
|
||||
$mod->addChild('name', $app_info['title']);
|
||||
$mod->addChild('description', base64_encode($app_info['description']));
|
||||
$mod->addChild('image_url', $app_info['preview_url']);
|
||||
$mod->addChild('download_url', $app_info['file_url']);
|
||||
$mod->addChild('filename', $app_info['filename']);
|
||||
$mod->addChild('file_size', $app_info['file_size']);
|
||||
$moddom = dom_import_simplexml($mod)->ownerDocument;
|
||||
$moddom->formatOutput = true;
|
||||
$fragment = $dom->createDocumentFragment();
|
||||
$fragment->appendXML($moddom->saveXML($moddom->documentElement)."\n");
|
||||
$mods->appendChild($fragment);
|
||||
}
|
||||
|
||||
file_put_contents($xml_file, $dom->saveXML());
|
||||
$xml = simplexml_load_file($xml_file);
|
||||
return count($errors) === 0;
|
||||
}
|
||||
|
||||
function steam_workshop_search_items($workshop_id, $query, &$error = "")
|
||||
{
|
||||
$error = "";
|
||||
$query = trim((string)$query);
|
||||
if($query === "")
|
||||
return array();
|
||||
|
||||
$direct_ids = steam_workshop_extract_ids($query);
|
||||
if(!empty($direct_ids))
|
||||
{
|
||||
$details = steam_workshop_fetch_published_file_details($direct_ids);
|
||||
$results = array();
|
||||
foreach($direct_ids as $workshop_mod_id)
|
||||
{
|
||||
if(!isset($details[$workshop_mod_id]))
|
||||
continue;
|
||||
|
||||
$app_info = $details[$workshop_mod_id];
|
||||
if($app_info['creator_app_id'] != $workshop_id && $app_info['consumer_app_id'] != $workshop_id)
|
||||
continue;
|
||||
|
||||
$results[] = array(
|
||||
'id' => $workshop_mod_id,
|
||||
'title' => $app_info['title'],
|
||||
'description' => $app_info['description'],
|
||||
'preview_url' => $app_info['preview_url'],
|
||||
'url' => 'https://steamcommunity.com/sharedfiles/filedetails/?id='.$workshop_mod_id,
|
||||
'author' => '',
|
||||
);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
$url = 'https://steamcommunity.com/workshop/browse/?appid='.rawurlencode($workshop_id).
|
||||
'&searchtext='.rawurlencode($query).
|
||||
'&browsesort=textsearch§ion=readytouseitems&actualsort=textsearch&p=1&days=-1';
|
||||
$context = stream_context_create(array('http' => array(
|
||||
'method' => "GET",
|
||||
'header' => "User-Agent: Mozilla/5.0 (compatible; GSP-Panel-SteamWorkshop/1.0)\r\n",
|
||||
'timeout' => 15,
|
||||
'ignore_errors' => true
|
||||
)));
|
||||
|
||||
$html = steam_workshop_request($url, $context, $error);
|
||||
if($html === FALSE)
|
||||
{
|
||||
$error = get_lang('unable_to_contact_steam_workshop');
|
||||
return array();
|
||||
}
|
||||
|
||||
libxml_use_internal_errors(true);
|
||||
$dom = new DOMDocument();
|
||||
if(!@$dom->loadHTML($html))
|
||||
{
|
||||
$error = get_lang('unable_to_parse_steam_workshop_response');
|
||||
return array();
|
||||
}
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
$anchors = $xpath->query('//a[contains(@href,"/sharedfiles/filedetails/?id=")]');
|
||||
$results = array();
|
||||
$seen_ids = array();
|
||||
foreach($anchors as $anchor)
|
||||
{
|
||||
$href = $anchor->getAttribute('href');
|
||||
if(!preg_match('/[?&]id=(\d+)/', $href, $matches))
|
||||
continue;
|
||||
|
||||
$workshop_mod_id = $matches[1];
|
||||
if(isset($seen_ids[$workshop_mod_id]))
|
||||
continue;
|
||||
|
||||
$title = trim($anchor->textContent);
|
||||
$image_nodes = $xpath->query('.//img', $anchor);
|
||||
$preview_url = '';
|
||||
if($image_nodes->length > 0)
|
||||
{
|
||||
$preview_url = $image_nodes->item(0)->getAttribute('src');
|
||||
if($title === '')
|
||||
$title = trim($image_nodes->item(0)->getAttribute('alt'));
|
||||
}
|
||||
|
||||
$card = $anchor;
|
||||
for($depth = 0; $depth < 4 && $card->parentNode instanceof DOMElement; $depth++)
|
||||
$card = $card->parentNode;
|
||||
|
||||
$author = '';
|
||||
if($card instanceof DOMElement)
|
||||
{
|
||||
$author_nodes = $xpath->query('.//a[contains(@href,"/myworkshopfiles/?appid=")]', $card);
|
||||
if($author_nodes->length > 0)
|
||||
$author = trim(preg_replace('/^By\s+/i', '', $author_nodes->item(0)->textContent));
|
||||
}
|
||||
|
||||
if($title === '')
|
||||
continue;
|
||||
|
||||
$seen_ids[$workshop_mod_id] = true;
|
||||
$results[$workshop_mod_id] = array(
|
||||
'id' => $workshop_mod_id,
|
||||
'title' => $title,
|
||||
'description' => '',
|
||||
'preview_url' => $preview_url,
|
||||
'url' => $href,
|
||||
'author' => $author,
|
||||
);
|
||||
|
||||
if(count($results) >= 12)
|
||||
break;
|
||||
}
|
||||
|
||||
if(empty($results))
|
||||
return array();
|
||||
|
||||
$details = steam_workshop_fetch_published_file_details(array_keys($results));
|
||||
foreach($results as $workshop_mod_id => $result)
|
||||
{
|
||||
if(!isset($details[$workshop_mod_id]))
|
||||
continue;
|
||||
$app_info = $details[$workshop_mod_id];
|
||||
if($app_info['creator_app_id'] != $workshop_id && $app_info['consumer_app_id'] != $workshop_id)
|
||||
{
|
||||
unset($results[$workshop_mod_id]);
|
||||
continue;
|
||||
}
|
||||
$results[$workshop_mod_id]['description'] = $app_info['description'];
|
||||
if($results[$workshop_mod_id]['preview_url'] === '' && $app_info['preview_url'] !== '')
|
||||
$results[$workshop_mod_id]['preview_url'] = $app_info['preview_url'];
|
||||
}
|
||||
|
||||
return array_values($results);
|
||||
}
|
||||
|
||||
function get_installed_mods($home_cfg, $remote, $xml)
|
||||
|
|
@ -216,4 +526,4 @@ function get_blacklist()
|
|||
"17585","739590","17555","232370","55280","17705","261140","222840","320850","317670","824360","381690",
|
||||
"41005","208050","105600","556450","402370");
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,14 @@ echo '<link rel="stylesheet" type="text/css" href="css/xbbcode/xbbcode.css">'."\
|
|||
'<script type="text/javascript" src="js/xbbcode/xbbcode.js"></script>'."\n".
|
||||
'<script type="text/javascript" src="js/modules/steam_workshop.js"></script>';
|
||||
|
||||
function steam_workshop_render_nav($home_key)
|
||||
{
|
||||
echo "<div class='mb-3'>".
|
||||
"<a class='btn btn-sm btn-danger mr-2' href='?m=steam_workshop&p=uninstall&home_id-mod_id-ip-port=".$home_key."'>".get_lang('uninstall_mods')."</a>".
|
||||
"<a class='btn btn-sm btn-primary' href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=".$home_key."'>".get_lang('back')."</a>".
|
||||
"</div>";
|
||||
}
|
||||
|
||||
function exec_ogp_module()
|
||||
{
|
||||
|
||||
|
|
@ -44,13 +52,8 @@ function exec_ogp_module()
|
|||
return;
|
||||
}
|
||||
|
||||
if(!isset($_POST['workshop_mod_id']) and !isset($_GET['show_log']) and !isset($_POST['manual_workshop_mod_id']))
|
||||
{
|
||||
echo "<ul>".
|
||||
"<li><a href='?m=steam_workshop&p=uninstall&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'>".get_lang('uninstall_mods')."</a></li>".
|
||||
"<li><a href='?m=gamemanager&p=game_monitor&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'>".get_lang('back')."</a></li>".
|
||||
"</ul>";
|
||||
}
|
||||
if(!isset($_GET['show_log']))
|
||||
steam_workshop_render_nav($_GET['home_id-mod_id-ip-port']);
|
||||
|
||||
$isAdmin = $db->isAdmin( $_SESSION['user_id'] );
|
||||
|
||||
|
|
@ -117,6 +120,13 @@ function exec_ogp_module()
|
|||
|
||||
if($xml !== false)
|
||||
{
|
||||
$workshop_id = (string)$xml->workshop_id;
|
||||
$search_query = isset($_GET['workshop_search']) ? trim((string)$_GET['workshop_search']) : '';
|
||||
$search_results = array();
|
||||
$search_error = '';
|
||||
if($search_query !== '')
|
||||
$search_results = steam_workshop_search_items($workshop_id, $search_query, $search_error);
|
||||
|
||||
$remote = new OGPRemoteLibrary($home_cfg['agent_ip'],$home_cfg['agent_port'],$home_cfg['encryption_key'], $home_cfg['timeout']);
|
||||
|
||||
if($remote->status_chk() !== 1)
|
||||
|
|
@ -152,72 +162,34 @@ function exec_ogp_module()
|
|||
{
|
||||
print_success( get_lang("update_completed") );
|
||||
echo "<pre>".$log_txt."</pre>\n";
|
||||
echo "<table class='center'><tr><td><a href='?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'><< ". get_lang("back") ."</a></td></tr></table>";
|
||||
echo "<table class='center'><tr><td><a class='btn btn-sm btn-primary' href='?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'><< ". get_lang("back") ."</a></td></tr></table>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($_POST['workshop_mod_id']) OR isset($_POST['manual_workshop_mod_id']))
|
||||
if(isset($_POST['install']) || isset($_POST['show_info']))
|
||||
{
|
||||
$failure = false;
|
||||
if(isset($_POST['manual_workshop_mod_id']) and $_POST['manual_workshop_mod_id'] != "" and preg_match('/^([0-9]+,?)+$/', $_POST['manual_workshop_mod_id']))
|
||||
$requested_ids = steam_workshop_collect_requested_ids(
|
||||
isset($_POST['manual_workshop_mod_id']) ? $_POST['manual_workshop_mod_id'] : '',
|
||||
isset($_POST['workshop_mod_id']) ? $_POST['workshop_mod_id'] : array(),
|
||||
isset($_POST['search_workshop_mod_id']) ? $_POST['search_workshop_mod_id'] : array()
|
||||
);
|
||||
if(empty($requested_ids))
|
||||
{
|
||||
$mods_list = $_POST['manual_workshop_mod_id'];
|
||||
$mod_id_array = explode(',', $mods_list);
|
||||
foreach($mod_id_array as $workshop_mod_id)
|
||||
{
|
||||
$exist = false;
|
||||
foreach($xml->mods->mod as $mod)
|
||||
{
|
||||
if($mod['id'] == $workshop_mod_id)
|
||||
{
|
||||
$exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(belongs_to_workshop($workshop_mod_id, $xml->workshop_id))
|
||||
{
|
||||
if(!$exist)
|
||||
{
|
||||
list($mod_title, $mod_description, $mod_image_url, $download_url, $filename, $file_size) = get_mod_info($workshop_mod_id);
|
||||
//add mods to the xml
|
||||
$mod = new SimpleXMLElement('<mod/>');
|
||||
$mod->addAttribute('id', $workshop_mod_id);
|
||||
$mod->addChild('name', $mod_title);
|
||||
$mod->addChild('description', base64_encode($mod_description));
|
||||
$mod->addChild('image_url', $mod_image_url);
|
||||
$mod->addChild('download_url', $download_url);
|
||||
$mod->addChild('filename', $filename);
|
||||
$mod->addChild('file_size', $file_size);
|
||||
$moddom = dom_import_simplexml($mod)->ownerDocument;
|
||||
$moddom->formatOutput = true;
|
||||
$mod_string = $moddom->saveXML($moddom->documentElement);
|
||||
|
||||
$dom = dom_import_simplexml($xml)->ownerDocument;
|
||||
$dom->formatOutput = true;
|
||||
|
||||
$mods = $dom->getElementsByTagName('mods')->item(0);
|
||||
|
||||
$f = $dom->createDocumentFragment();
|
||||
$f->appendXML($mod_string."\n");
|
||||
$mods->appendChild($f);
|
||||
|
||||
|
||||
file_put_contents($xml_file, $dom->saveXML());
|
||||
$xml = simplexml_load_file($xml_file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print_failure(get_lang_f('mod_does_not_belong_to_workshop', $workshop_mod_id));
|
||||
$failure = true;
|
||||
}
|
||||
}
|
||||
print_failure(get_lang('select_at_least_one_mod_or_enter_mod_id'));
|
||||
$failure = true;
|
||||
}
|
||||
elseif(isset($_POST['workshop_mod_id']))
|
||||
else
|
||||
{
|
||||
$mods_list = implode(',',$_POST['workshop_mod_id']);
|
||||
$sync_errors = array();
|
||||
if(!steam_workshop_sync_xml_mods($xml, $xml_file, $workshop_id, $requested_ids, $sync_errors))
|
||||
{
|
||||
foreach($sync_errors as $sync_error)
|
||||
print_failure($sync_error);
|
||||
$failure = true;
|
||||
}
|
||||
$mods_list = implode(',', $requested_ids);
|
||||
}
|
||||
|
||||
if(isset($_POST['install']) and !$failure and isset($mods_list) and preg_match('/^([0-9]+,?)+$/', $mods_list))
|
||||
|
|
@ -237,8 +209,6 @@ function exec_ogp_module()
|
|||
$post_install = $xml->post_install;
|
||||
$mod_names_list = get_mod_names_list($mods_list, $xml->mods->mod);
|
||||
$mods_full_path = clean_path($home_cfg['home_path'].'/'.$xml->mods_path);
|
||||
$workshop_id = $xml->workshop_id;
|
||||
|
||||
$url_list = "";
|
||||
$filename_list = "";
|
||||
if($download_method == "steamapi")
|
||||
|
|
@ -294,14 +264,64 @@ function exec_ogp_module()
|
|||
"<div class='bbcode_container' style='padding-left:245px;'>".htmlentities(base64_decode($mod->description))."</div></div><td><tr>";
|
||||
}
|
||||
}
|
||||
echo "</table><a href='?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'>".get_lang('back')."</a>";
|
||||
echo "</table><a class='btn btn-sm btn-primary mt-2' href='?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port']."'>".get_lang('back')."</a>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($workshop_id != "")
|
||||
{
|
||||
echo "<form action='' method='get' class='mb-3'>".
|
||||
"<input type='hidden' name='m' value='steam_workshop' />".
|
||||
"<input type='hidden' name='p' value='main' />".
|
||||
"<input type='hidden' name='home_id-mod_id-ip-port' value='".steam_workshop_h($_GET['home_id-mod_id-ip-port'])."' />".
|
||||
"<table class='center'>".
|
||||
"<tr><td><strong>".get_lang('workshop_search')."</strong></td><td>".
|
||||
"<input type='text' name='workshop_search' size='42' value='".steam_workshop_h($search_query)."' placeholder='".steam_workshop_h(get_lang('workshop_search_placeholder'))."' />".
|
||||
"</td><td><button type='submit' class='btn btn-sm btn-primary'>".get_lang('search')."</button></td></tr>".
|
||||
"<tr><td></td><td colspan='2'><small>".get_lang_f('workshop_search_info', steam_workshop_h($workshop_id))."</small></td></tr>".
|
||||
"</table>".
|
||||
"</form>";
|
||||
|
||||
if($search_query !== '')
|
||||
{
|
||||
if($search_error !== '')
|
||||
print_failure($search_error);
|
||||
elseif(empty($search_results))
|
||||
echo "<p>".get_lang('no_workshop_items_found')."</p>";
|
||||
}
|
||||
}
|
||||
|
||||
$ft = new FormTable();
|
||||
$ft->start_form("?m=steam_workshop&p=main&home_id-mod_id-ip-port=".$_GET['home_id-mod_id-ip-port'], "post", "onsubmit='return isValidForm(this)' data-form-error='".get_lang('select_at_least_one_mod_or_enter_mod_id')."'");
|
||||
$ft->start_table();
|
||||
if(!empty($search_results))
|
||||
{
|
||||
echo "<tr><td colspan='2'><div style='max-height:460px; overflow:auto; padding-right:6px;'>";
|
||||
foreach($search_results as $search_result)
|
||||
{
|
||||
$short_description = trim($search_result['description']);
|
||||
if(strlen($short_description) > 220)
|
||||
$short_description = substr($short_description, 0, 217).'...';
|
||||
|
||||
echo "<div style='display:flex; gap:12px; padding:10px 0; border-bottom:1px solid rgba(255,255,255,0.1); align-items:flex-start;'>".
|
||||
"<div><input type='checkbox' id='search_mod_".$search_result['id']."' name='search_workshop_mod_id[]' value='".steam_workshop_h($search_result['id'])."' /></div>".
|
||||
"<div style='min-width:96px;'>";
|
||||
if($search_result['preview_url'] !== '')
|
||||
echo "<label for='search_mod_".$search_result['id']."'><img src='".steam_workshop_h($search_result['preview_url'])."' alt='".steam_workshop_h($search_result['title'])."' style='width:96px; max-width:96px; height:auto; border-radius:4px;' /></label>";
|
||||
echo "</div><div style='flex:1; min-width:0; text-align:left;'>" .
|
||||
"<label for='search_mod_".$search_result['id']."' style='display:block; font-weight:bold;'>".steam_workshop_h($search_result['title'])."</label>".
|
||||
"<div><small>".get_lang('workshop_id').": ".steam_workshop_h($search_result['id'])."</small></div>";
|
||||
if($search_result['author'] !== '')
|
||||
echo "<div><small>Author: ".steam_workshop_h($search_result['author'])."</small></div>";
|
||||
if($short_description !== '')
|
||||
echo "<div style='margin-top:4px;'>".steam_workshop_h($short_description)."</div>";
|
||||
if($search_result['url'] !== '')
|
||||
echo "<div style='margin-top:6px;'><a target='_blank' rel='noopener' href='".steam_workshop_h($search_result['url'])."'>".get_lang('open_workshop_page')."</a></div>";
|
||||
echo "</div></div>";
|
||||
}
|
||||
echo "</div></td></tr>";
|
||||
}
|
||||
if(count($xml->mods->mod) > 0)
|
||||
{
|
||||
echo '<tr><td colspan=2><div id="uninstall_scrolling_checkbox">';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue