2024.8.23
Loading...
Searching...
No Matches
ajax.latestversion.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Constructs the download link for a new version if available.
12 *
13 * This function compares the current application version with the latest available version.
14 * If the latest version is greater, it sets the display flag to true and constructs an HTML link
15 * for downloading the new version, appending it to the 'download' key in the result array.
16 *
17 * @param array $result Holds the display flag and download link HTML.
18 *
19 * @return void Modifies the $result array by reference.
20 * @global object $bearsamppLang Language management object, used for retrieving language-specific values.
21 * @global object $bearsamppCore Core application object, used for retrieving the current version.
22 * @global array $githubVersionData Holds the latest version data retrieved from GitHub.
23 */
25
26$result = array(
27 'display' => false,
28 'download' => '',
29);
30
31// Assuming getAppVersion() returns the current version number
33
34/**
35 * Retrieves the latest version data from GitHub.
36 *
37 * @return array|null Returns an array with version data or null if retrieval fails.
38 */
40Util::logDebug('GitHub Version Data: ' . print_r($githubVersionData, true));
41
42if (!empty($githubVersionData)) {
43 Util::logDebug('GitHub Version Data: ' . print_r($githubVersionData, true));
44} else {
45 Util::logError('No data available in $githubVersionData');
46}
47
48/**
49 * Checks if the version data retrieval failed.
50 *
51 * @return void Exits the function if version data is null.
52 */
53if ($githubVersionData === null) {
54 Util::logError('Failed to retrieve version data from GitHub URL: ' . APP_GITHUB_LATEST_URL);
55 return;
56}
57
58/**
59 * Extracts relevant version information from the retrieved data.
60 *
61 * @var string $githubLatestVersion The latest version number.
62 * @var string $githubLatestVersionUrl The URL to the latest version.
63 * @var string $githubVersionName The name of the latest version.
64 */
66$githubLatestVersionUrl = $githubVersionData['html_url']; // URL of the latest version
69
70/**
71 * Compares the current version with the latest version.
72 *
73 * If the latest version is greater, sets the display flag to true and constructs the download link.
74 *
75 * @param string $bearsamppCurrentVersion The current version of the application.
76 * @param string $githubLatestVersion The latest version of the application.
77 * @return void Modifies the $result array by reference.
78 */
80 $result['display'] = true;
81 $result['download'] .= '<a role="button" class="btn btn-success fullversionurl" href="' . $githubLatestVersionUrl . '" target="_blank"><i class="fa-solid fa-cloud-arrow-down"></i> ';
82 $result['download'] .= $bearsamppLang->getValue(Lang::DOWNLOAD) . ' <strong>' . APP_TITLE . ' ' . $githubVersionName . '</strong><br />';
83 $result['changelog'] = '';
84}
85
86/**
87 * Outputs the result array as a JSON string.
88 *
89 * @param array $result The result array containing the display flag and download link.
90 * @return void Outputs the JSON-encoded result.
91 */
92echo json_encode($result);
$bearsamppCurrentVersion
global $githubVersionData
$githubVersionName
$githubLatestVersionUrl
$githubLatestVersion
global $bearsamppLang
global $bearsamppCore
const DOWNLOAD
static logError($data, $file=null)
static getLatestVersion($url)
static logDebug($data, $file=null)
const APP_GITHUB_LATEST_URL
Definition root.php:18
const APP_TITLE
Definition root.php:12