diff --git a/imdb/imdb.class.php b/imdb/imdb.class.php index bde50413..0a0fbfa1 100644 --- a/imdb/imdb.class.php +++ b/imdb/imdb.class.php @@ -209,6 +209,9 @@ $responseBody = $response->getBody(); } if( $this->page[$wt] ){ //storecache if ($this->storecache) { + if (!is_dir($this->cachedir)) { + $mkdirResult = mkdir($this->cachedir, 0777, true); + } $fp = fopen ("$this->cachedir/$this->imdbID.$wt", "w"); fputs ($fp, $this->page[$wt]); fclose ($fp); diff --git a/imdb/imdb_config.php b/imdb/imdb_config.php index 58d17eb7..e6acdf67 100644 --- a/imdb/imdb_config.php +++ b/imdb/imdb_config.php @@ -47,7 +47,7 @@ class imdb_config { $this->imdbsite = "www.imdb.com"; // cachedir should be writable by the webserver. This doesn't need to be // under documentroot. - $this->cachedir = './imdb/cache'; + $this->cachedir = ROOT_PATH . 'imdb/cache'; //whether to use a cached page to retrieve the information if available. $this->usecache = true; //whether to store the pages retrieved for later use. @@ -58,10 +58,10 @@ class imdb_config { $this->imageext = '.jpg'; // images are stored here after calling photo_localurl() // this needs to be under documentroot to be able to display them on your pages. - $this->photodir = './imdb/images/'; + $this->photodir = ROOT_PATH . 'imdb/pic_imdb/'; // this is the URL to the images, i.e. start at your servers DOCUMENT_ROOT // when specifying absolute path - $this->photoroot = './imdb/images/'; + $this->photoroot = '/pic_imdb/'; // TWEAKING OPTIONS: // limit the result set to X movies (0 to disable, comment out to use default of 20) $this->maxresults = 5000; diff --git a/include/bittorrent_announce.php b/include/bittorrent_announce.php index 3f73bf4c..c66dabbe 100644 --- a/include/bittorrent_announce.php +++ b/include/bittorrent_announce.php @@ -3,7 +3,6 @@ define('NEXUS_START', microtime(true)); # IMPORTANT: Do not edit below unless you know what you are doing! define('IN_TRACKER', true); $rootpath= dirname(__DIR__) . '/'; - require $rootpath . 'include/functions_announce.php'; require $rootpath . 'include/globalfunctions.php'; require $rootpath . 'include/core.php'; diff --git a/include/config.php b/include/config.php index 07506bf3..ed52663b 100644 --- a/include/config.php +++ b/include/config.php @@ -69,9 +69,7 @@ if (basename($_SERVER['SCRIPT_FILENAME']) == 'announce.php') { } $settings = get_setting(); foreach ($settings as $name => $value) { - $prefix = strtoupper(strstr($name, '.', true)); - $pureName = substr($name, strpos($name, '.') + 1); - $GLOBALS[$prefix][$pureName] = $value; + $GLOBALS[strtoupper($name)] = $value; } $SITENAME = $BASIC['SITENAME']; diff --git a/include/core.php b/include/core.php index 3a395354..b85c05b5 100644 --- a/include/core.php +++ b/include/core.php @@ -1,7 +1,14 @@ setUsername('your username') - ->setPassword('your password') + $transport = (new Swift_SmtpTransport($setting['smtpaddress'], $setting['smtpport'])) + ->setUsername($setting['accountname']) + ->setPassword($setting['accountpassword']) ; // Create the Mailer using your created Transport $mailer = new Swift_Mailer($transport); // Create a message - $message = (new Swift_Message('Wonderful Subject')) - ->setFrom(['john@doe.com' => 'John Doe']) - ->setTo(['receiver@domain.org', 'other@domain.org' => 'A name']) - ->setBody('Here is the message itself') + $message = (new Swift_Message($subject)) + ->setFrom($fromemail, $fromname) + ->setTo([$to]) + ->setBody($body) ; // Send the message - $result = $mailer->send($message); - + try { + $result = $mailer->send($message); + if ($result == 0) { + stderr($lang_functions['std_error'], $lang_functions['text_unable_to_send_mail']); + } + } catch (\Exception $e) { + do_log("send email fail: " . $e->getMessage() . ", trace: " . $e->getTraceAsString()); + stderr($lang_functions['std_error'], $lang_functions['text_unable_to_send_mail']); + } } if ($showmsg) { diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 16c7f01f..55ae0fcd 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -147,14 +147,16 @@ function dd($vars) exit(0); } -function do_log($log) +function do_log($log, $level = 'info') { global $TWEAK; if (!empty($TWEAK['logging'])) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $content = sprintf( - "[%s] %s:%s %s%s%s %s%s", + "[%s] [%s] [%s] %s:%s %s%s%s %s%s", date('Y-m-d H:i:s'), + $level, + REQUEST_ID, $backtrace[0]['file'] ?? '', $backtrace[0]['line'] ?? '', $backtrace[1]['class'] ?? '', @@ -206,11 +208,10 @@ function __($name = null, $prefix = null) function config($key, $default = null) { - global $rootpath; static $configs; if (is_null($configs)) { //get all configuration from config file - $files = glob($rootpath . 'config/*.php'); + $files = glob(ROOT_PATH . 'config/*.php'); foreach ($files as $file) { $basename = basename($file); if ($basename == 'allconfig.php') { @@ -233,7 +234,7 @@ function config($key, $default = null) * @param null $name * @return array|mixed|string */ -function get_setting($name = null, $prefix = null) +function get_setting($name = null) { static $settings; if (is_null($settings)) { @@ -246,36 +247,20 @@ function get_setting($name = null, $prefix = null) if (is_array($arr)) { $value = $arr; } - $settings[$row['name']] = $value; - } - - } - if (!is_null($name)) { - if (!is_null($prefix)) { - $name = "$prefix.$name"; - } - return $settings[$name] ?? null; - } - if (is_null($prefix)) { - return $settings; - } - $filtered = []; - foreach ($settings as $name => $value) { - if (preg_match("/^$prefix/", $name)) { - $nameWithoutPrefix = substr($name, strpos($name, '.') + 1); - $filtered[$nameWithoutPrefix] = $value; + arr_set($settings, $row['name'], $value); } } - return $filtered; - + if (is_null($name)) { + return $settings; + } + return arr_get($settings, $name); } function env($key, $default = null) { - global $rootpath; static $env; if (is_null($env)) { - $envFile = $rootpath . '.env'; + $envFile = ROOT_PATH . '.env'; if (!file_exists($envFile)) { throw new \RuntimeException(".env file is not exists in the root path."); } @@ -325,6 +310,18 @@ function normalize_env($value) } } +/** + * Get an item from an array using "dot" notation. + * + * referance to Laravel + * + * @author xiaomlove<1939737565@qq.com> + * @date 2021/1/14 + * @param $array + * @param $key + * @param null $default + * @return mixed|null + */ function arr_get($array, $key, $default = null) { if (strpos($key, '.') === false) { @@ -340,23 +337,44 @@ function arr_get($array, $key, $default = null) return $array; } +/** + * From Laravel + * + * Set an array item to a given value using "dot" notation. + * + * If no key is given to the method, the entire array will be replaced. + * + * @param array $array + * @param string|null $key + * @param mixed $value + * @return array + */ function arr_set(&$array, $key, $value) { - $parts = explode('.', $key); - $last = null; - while (true) { - $segment = array_pop($parts); - if (empty($segment)) { - return $array; - } - if (is_null($last)) { - $array[$segment] = $value; - } else { - $array[$segment] = $array; - unset($array[$last]); - } - $last = $segment; - + if (is_null($key)) { + return $array = $value; } + + $keys = explode('.', $key); + + foreach ($keys as $i => $key) { + if (count($keys) === 1) { + break; + } + + unset($keys[$i]); + + // If the key doesn't exist at this depth, we will just create an empty array + // to hold the next value, allowing us to create the arrays to hold final + // values at the correct depth. Then we'll keep digging into the array. + if (! isset($array[$key]) || ! is_array($array[$key])) { + $array[$key] = []; + } + + $array = &$array[$key]; + } + + $array[array_shift($keys)] = $value; + return $array; } diff --git a/public/index.php b/public/index.php index 8c5cf914..a73a3ca3 100644 --- a/public/index.php +++ b/public/index.php @@ -300,13 +300,18 @@ if ($CURUSER && $showpolls_main == "yes") $os = array(); // Count votes - while (($arr2 = mysql_fetch_row($res) !== null) && isset($arr2[0]) && isset($vs[$arr2[0]])) - $vs[$arr2[0]] ++; + while ($arr2 = mysql_fetch_row($res)) { + if (!isset($vs[$arr2[0]])) { + $vs[$arr2[0]] = 0; + } + $vs[$arr2[0]] ++; + } + reset($o); for ($i = 0; $i < count($o); ++$i){ - if (isset($vs[$i]) && isset($o[$i]) && $o[$i]) - $os[$i] = array($vs[$i], $o[$i], $i); + if ($o[$i]) + $os[$i] = array($vs[$i] ?? 0, $o[$i], $i);//field 1: options vote count, field 2: option name, field 3: option index } function srt($a,$b) diff --git a/public/log.php b/public/log.php index c2168ca4..aa6e0d42 100644 --- a/public/log.php +++ b/public/log.php @@ -222,8 +222,8 @@ else { break; case "funbox": stdhead($lang_log['head_funbox']); - $query = mysql_real_escape_string(trim($_GET["query"])); - $search = $_GET["search"]; + $query = mysql_real_escape_string(trim($_GET["query"] ?? '')); + $search = $_GET["search"] ?? ''; if($query){ switch ($search){ case "title": $wherea=" WHERE title LIKE '%$query%' AND status != 'banned'"; break; @@ -237,7 +237,7 @@ else { $addparam = ""; } logmenu("funbox"); - $opt = array (title => $lang_log['text_title'], body => $lang_log['text_body'], both => $lang_log['text_both']); + $opt = array ('title' => $lang_log['text_title'], 'body' => $lang_log['text_body'], 'both' => $lang_log['text_both']); searchtable($lang_log['text_search_funbox'], 'funbox', $opt); $res = sql_query("SELECT COUNT(*) FROM fun ".$wherea); $row = mysql_fetch_array($res); @@ -324,7 +324,7 @@ else { int_check($pollid,true); - $sure = $_GET["sure"]; + $sure = $_GET["sure"] ?? ''; if (!$sure) stderr($lang_log['std_delete_poll'],$lang_log['std_delete_poll_confirmation'] . "".$lang_log['std_here_if_sure'],false); @@ -394,13 +394,20 @@ else { $os = array(); // votes and options: array(array(123, "Option 1"), array(45, "Option 2")) // Count votes - while ($pollanswer = mysql_fetch_row($pollanswers)) - $vs[$pollanswer[0]] += 1; + while ($pollanswer = mysql_fetch_row($pollanswers)) { + if (isset($pollanswer[0])) { + if (!isset($vs[$pollanswer[0]])) { + $vs[$pollanswer[0]] = 0; + } + $vs[$pollanswer[0]] += 1; + } + } + reset($o); for ($i = 0; $i < count($o); ++$i) - if (isset($o[$i]) && isset($vs[$i])) - $os[$i] = array($vs[$i], $o[$i]); + if ($o[$i]) + $os[$i] = array($vs[$i] ?? 0, $o[$i]); print("