TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,947
  • Latest: sgm09
Stats
  • Total Posts: 195,756
  • Total Topics: 21,279
  • Online today: 314
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 311
  • Total: 312
  • @rjen

[PHP] TP Support Helper Page

Started by Senkusha, March 21, 2025, 04:13:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Senkusha

I developed this special article page when filling out my Support Ticket, and thought it might be helpful, especially if your forum is like mine, with many Packages.  This script began as just a easy compiler for that list, but I expanded it to include as much as I could automate.

Edit:  I found I didn't resolve all the errors before publishing this.  Fixed now, no errors found.

Issues:
  • Language doesn't populate, and I'm not entirely sure why, even after I've forced the variable.  Maybe a second set of (more experienced) eyes can see the problem?    But, I'm still unsure where to collect the Default Language in SMF.
  • I also looked to see if there was a reliable way to get the browser and version, and from what I can find, there isn't any reliable way that can be guaranteed.
  • The Theme that you're using isn't correctly being identified.  It does determine the forum default, but for example, in my case, I've got a different Theme selected, yet it's not reporting it.  Maybe the id_theme in the members table isn't the place to locate that information anymore?

There are a few variables that can be customized:
  • firstUserID is typically the (read: assumed) Administrator, the member that installed the forum.  Default is 1, feel free to change it if needed.
  • errCnt is the number of errors from the log to count backwards from (meaning the top listed error is going to be the most recent one.  By default only the last 24 hours are retrieved, and the default value of entries is 5.
  • defaultLanguage is the language of the forum.  Default is English, but feel free to change this if needed.  Hopefully, I can figure out why and where the Default Language is set and just use that in the future.
  • browser is the name of the browser (and version) that you're using.  Feel free to go to Help in your browser and copy/paste that information.  I routinely use two browsers, so I have both of them listed.

global $smcFunc, $db_prefix, $scripturl, $boardurl, $modSettings, $settings;

// Initialize all the internal variables!
$firstUserID = 1;    // Usually the first account is the Administrator account, right?
$errCnt = 5;            // Five is a nice round number-- we don't want to overwhelm the Devs!
$defaultLanguage = 'English';
$browser = 'FireFox (136.0.1 (64-bit)), Chrome (134.0.6998.90 (Official Build) (64-bit))';
$minTime = mktime(date("H"),date("m"),date("s"),date("m"),date("d")-1,date("Y"));  // When was 24 hours ago, exactly?

// Verify the board URL?
if (isset($boardurl))
  $boardURL = $boardurl;

// Get some SMF settings.
$query = $smcFunc['db_query']('','
  SELECT variable, value
  FROM {db_prefix}settings
  WHERE variable = {string:smfv} OR variable = {string:smftd}',
  array('smfv' => 'smfVersion',
          'smftd' => 'theme_default')
);
while ($result = $smcFunc['db_fetch_assoc']($query))
{
  switch ($result['variable'])
  {
    case 'smfVersion' :
    {
      $SMFversion = $result['value'];
      break;
    }
    case 'theme_default' :
    {
      $SMFdefaultTheme = $result['value'];
      break;
    }
  }
}
$smcFunc['db_free_result']($query);

// Let's get some Admin info, just in case we need it.
$query = $smcFunc['db_query']('','
    SELECT lngFile, id_theme FROM {db_prefix}members
    WHERE id_member = {int:adminID}',
    array('adminID' => $firstUserID)
  );
  $result = $smcFunc['db_fetch_assoc']($query);
  $adminLanguage = $result['lngFile'];
  $adminTheme = $result['id_theme'];

// Figure out the default language.
$query = $smcFunc['db_query']('','
  SELECT value FROM {db_prefix}settings
  WHERE variable = {string:lang}',
  array('lang' => 'language')
);
while ($result = $smcFunc['db_fetch_assoc']($query))
  $defaultLanguage = $result['value'];
$smcFunc['db_free_result']($query);

if (!isset($defaultLanguage) || $defaultLanguage == '')
{
  // Looks like the default language hasn't been specified!!  Look in the Administrator User account?
  $defaultLanguage = $adminLanguage; 
}

if (!isset($defaultLanguage) || $defaultLanguage == '')
{
  // Looks like even the Admin didn't select a default language.  Last resort is the Almighty Settings file??
  if (isset($settings['language']))
    $defaultLanguage = $settings['language'];
}
else
  $defaultLanguage = 'Unknown';

// Alrighty!  Let's gather a list of all the Themes installed, shall we?
$counter = 0;
$themeList = '';
$query = $smcFunc['db_query']('','
  SELECT id_theme, value
  FROM {db_prefix}themes
  WHERE variable = {string:nameField} AND id_member= {int:masterThemeID}
  ORDER BY value',
  array (
    'nameField' => 'name',
    'masterThemeID' => '0'
  )
);
while ($result = $smcFunc['db_fetch_assoc']($query))
{
  if ($counter > 0)
    $themeList .= ', ';

  if ($adminTheme == $result['id_theme'] || $adminTheme == $SMFdefaultTheme)
    $themeList .= '[b][i]' . $result['value'] . '[/i][/b]';
  else if ($adminTheme == 0 && $result['id_theme'] == $SMFdefaultTheme)
    $themeList .= '[b][i]' . $result['value'] . '[/i][/b]';
  else
    $themeList .= $result['value'] . ' (' . $result['id_theme'] . ')';

  $counter ++;
}

// Can we get the browser being used?

// Get all INSTALLED packages.
$counter = 0;
$packages = '';
$query = $smcFunc['db_query']('','
  SELECT name, version,  install_state
  FROM {db_prefix}log_packages
  WHERE install_state = {int:inPack}
  ORDER BY name',
  array('inPack' => 1)
);
while ($result = $smcFunc['db_fetch_assoc']($query))
{
  if ($counter > 0)
    $packages .= ', ';
  if ($result['name'] == 'TinyPortal')
    $TPversion = $result['version'];

  $packages .= $result['name'] . ' (' . $result['version'] . ')';
  $counter ++;
}
$smcFunc['db_free_result']($query);

// Finally, let's get a look at that log file...
$counter = 0;
$errorLogEntries = '';
$query = $smcFunc['db_query']('','
  SELECT log_time, url, message, error_type, file, line, backtrace
  FROM {db_prefix}log_errors
  WHERE log_time >= {int:timeRange}
  ORDER BY log_time DESC
  LIMIT {int:errorCount}', array (
    'timeRange' => $minTime,
    'errorCount' => $errCnt
  )
);
while ($result = $smcFunc['db_fetch_assoc']($query))
{
  // Let's make this output look presentable before taking it out on that date!
  $errorLogEntries .= $errCnt - $counter . '.  [b]' . $result['error_type'] . '[/b]<br />
Error:  ' . $result['message'] . '<br />
URL:  [url="' . $scripturl . $result['url'] . '"]' . $scripturl . $result['url'] . '[/url]<br />
File:  ' . $result['file'] . ' (Line:  ' . $result['line'] . ')<br />
<br />';

$counter ++;
}
$smcFunc['db_free_result']($query);

// But, what if there weren't any errors logged??
if ($errorLogEntries == '')
  $errorLogEntries = 'No errors were logged.';

// Finally!  The output!! :)
echo '
[b]Link to my forum: [/b] [url="' . $boardURL . '"]' . $boardURL . '[/url]<br />
[b]SMF version: [/b] ' . $SMFversion . '<br />
[b]TP version: [/b] ' . $TPversion . '<br />
[b]Default Forum Language: [/b] ' . $defaultLanguage . '<br />
[b]Theme name and version: [/b] ' . $themeList , '<br />
[b]Browser Name and Version: [/b] ' . $browser . '<br />
[b]Mods installed: [/b] ' . $packages . '<br />
[b]Related Error messages: [/b] <br />' . $errorLogEntries . '<br />
<br />';

Here is an example.  The errors listed below are only because I didn't want to clear out my log while testing.  As of right now, you have to manually Select All and Copy, however, I'm hoping that I can find a way to just click on a link/button and have the output automatically copied to the Clipboard.  Maybe somebody already knows how to do that?

QuoteLink to my forum: https://forum.animerpgs.com
SMF version: 2.1.4
TP version: 3.0.1
Default Forum Language:
Theme name and version: Reseller_v2.0.4 (2), SMF Default Theme - Curve2
Browser Name and Version: FireFox (136.0.1 (64-bit)), Chrome (134.0.6998.90 (Official Build) (64-bit))
Mods installed: Activity Bar (2.0.1), Alternate User Posting (2.1.2), Anime Avatars (1.0), Awesome Post Ratings (2.0.4b), Badge Awards (2.6.2b), Battle (1.17.9.4), Battle Image Expansion 1 (1.2), Battle Image Expansion 2 (1.1), Battle Image Expansion 3 (1.1), Battle Image Expansion 4 (1.1), Board Sorting Method (1.0.1), Country Flags (3.0), Curve2 Color Changer (1.4.2), Custom Board Icons (2.0.0), Dice Roller BBcode (2.0), Downloads Pro Addon - Display Credits (1.0), Emoji Pro (2.1a), Message Bookmarks (0.9.5), More Spiders (1.3.1), Optimus (3.0 RC3), Similar Topics (1.3.1), Simple Referrals (1.4.7), SimpleDesk - Integrated Helpdesk for Simple Machines Forum (2.1.3), SMF Arcade (2.7.0.6), SMF Classifieds (5.1.10), SMF Gallery Pro (10.2.2a), SMF Post Prefix (4.3.4), SMF Store (5.0.1), Spoiler (0.3.2), ST Shop (4.1.13), Stop Forum Spam (1.5.6), TinyPortal (3.0.1), Topic Solved (1.1.3)
Related Error messages:
5. undefined_vars
Error: 2: Undefined variable $packages
URL: https://forum.animerpgs.com/index.php?page=6
File: /home/animerpgs/www/forum/Sources/TPSubs.php(1482) : eval()'d code (Line: 120)

4. undefined_vars
Error: 2: Undefined variable $themeList
URL: https://forum.animerpgs.com/index.php?page=6
File: /home/animerpgs/www/forum/Sources/TPSubs.php(1482) : eval()'d code (Line: 97)

3. general
Error: 2: Trying to access array offset on value of type null
URL: https://forum.animerpgs.com/index.php?page=6
File: /home/animerpgs/www/forum/Sources/TPSubs.php(1482) : eval()'d code (Line: 57)

2. undefined_vars
Error: 2: Undefined variable $packages
URL: https://forum.animerpgs.com/index.php?page=6
File: /home/animerpgs/www/forum/Sources/TPSubs.php(1482) : eval()'d code (Line: 120)

1. undefined_vars
Error: 2: Undefined variable $themeList
URL: https://forum.animerpgs.com/index.php?page=6
File: /home/animerpgs/www/forum/Sources/TPSubs.php(1482) : eval()'d code (Line: 97)
--Senkusha
Check out my Anime Role Playing website!

This website is proudly hosted on Crocweb Cloud Website Hosting.