Guest User

functions.inc.php

a guest
Dec 22nd, 2024
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | Source Code | 0 0
  1. <?php
  2.  
  3. use App\Core\Database;
  4.  
  5. /**
  6.  * Prepare reading of SQL dump file and executing SQL statements
  7.  *
  8.  * @param string $sqlDumpFile
  9.  * @param $db
  10.  * @return bool
  11.  */
  12. function dbImport(string $sqlDumpFile, $db)
  13. {
  14.     $query = "";
  15.  
  16.     // get  sql dump content
  17.     $sqlDump = file($sqlDumpFile);
  18.  
  19.     // add ";" at the end of file to catch last sql query
  20.     if (substr($sqlDump[count($sqlDump) - 1], -1) != ";") {
  21.         $sqlDump[count($sqlDump) - 1] .= ";";
  22.     }
  23.  
  24.     foreach ($sqlDump as $sqlLine) {
  25.         $tsl = trim(utf8_decode($sqlLine));
  26.         $tsl = trim($sqlLine);
  27.         if (($sqlLine != "") && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != "?") && (substr($tsl, 0, 1) != "#")) {
  28.             $query .= $sqlLine;
  29.             if (preg_match("/;\s*$/", $sqlLine)) {
  30.                 if (strlen(trim($query)) > 5) {
  31.                     if (!@$db->query($query)) {
  32.                         return false;
  33.                     }
  34.                 }
  35.                 $query = "";
  36.             }
  37.         }
  38.     }
  39.  
  40.     return true;
  41. }
  42.  
  43. /**
  44.  * Returns language key
  45.  *
  46.  * @param $key
  47.  * @return array|mixed|string|string[]
  48.  */
  49. function lang_key($key)
  50. {
  51.     global $arrLang;
  52.     $output = "";
  53.  
  54.     if (isset($arrLang[$key])) {
  55.         $output = $arrLang[$key];
  56.     } else {
  57.         $output = str_replace("_", " ", $key);
  58.     }
  59.  
  60.     return $output;
  61. }
  62.  
  63. function getInstallHost()
  64. {
  65.     return $_SERVER["SERVER_NAME"];
  66. }
  67.  
  68. function getInstallPath()
  69. {
  70.     $pageURL = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  71.  
  72.     // remove install folder
  73.     $pageUrlExp = explode("/install/", $pageURL);
  74.  
  75.     return $pageUrlExp[0];
  76. }
  77.  
  78. function genRandomString($length = 16)
  79. {
  80.     $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
  81.     $final_rand = '';
  82.     for ($i = 0; $i < $length; $i++) {
  83.         $final_rand .= $chars[rand(0, strlen($chars) - 1)];
  84.     }
  85.  
  86.     return $final_rand;
  87. }
  88.  
  89. function isExistingInstall()
  90. {
  91.     // function to check if we're already on an existing install
  92.     $existingInstall = false;
  93.     if (file_exists('../_config.inc.php')) {
  94.         include_once('../_config.inc.php');
  95.         if (strlen(_CONFIG_SITE_HOST_URL)) {
  96.             $existingInstall = true;
  97.         }
  98.     }
  99.  
  100.     return $existingInstall;
  101. }
  102.  
  103. function getScriptVersion()
  104. {
  105.     require_once(realpath(dirname(__FILE__).'/../app/core/Framework.class.php'));
  106.  
  107.     return App\Core\Framework::VERSION_NUMBER;
  108. }
  109.  
  110. function validateLicenseKey($licenseKey)
  111. {
  112.     return ["status"=>"SUCCESS"];
  113. }
Advertisement
Add Comment
Please, Sign In to add comment