From 1a6bc9d435cfa059cbfea0cc67c0b22ccb4c17f0 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Tue, 15 Aug 2023 20:11:46 +1000 Subject: [PATCH] cleanup --- Code/Lib/DB_Upgrade.php | 40 ++++++++++++++++++++-------------------- Code/Module/Photos.php | 40 ++++++++++++++++++++-------------------- Code/Nomad/Receiver.php | 4 +--- boot.php | 5 +---- 4 files changed, 42 insertions(+), 47 deletions(-) diff --git a/Code/Lib/DB_Upgrade.php b/Code/Lib/DB_Upgrade.php index 1e35a323c..0dd25a85e 100644 --- a/Code/Lib/DB_Upgrade.php +++ b/Code/Lib/DB_Upgrade.php @@ -19,30 +19,30 @@ class DB_Upgrade $this->func_prefix = '_'; $build = get_config('system', 'db_version', 0); - if (!intval($build)) { + if (!(int)$build)) { $build = set_config('system', 'db_version', $db_revision); } - if ($build == $db_revision) { + if ((int)$build === (int)$db_revision) { // Nothing to be done. return; } else { - $stored = intval($build); - if (!$stored) { + $storedVersion = (int)$build; + if (!$storedVersion) { logger('Critical: check_config unable to determine database schema version'); return; } - $current = intval($db_revision); + $newVersion = (int)$db_revision; - if ($stored < $current) { + if ($storedVersion < $newVersion) { // The last update we performed was $stored. // Start at $stored + 1 and continue until we have completed $current - for ($x = $stored + 1; $x <= $current; $x++) { - $s = '_' . $x; - $cls = '\\Code\Update\\' . $s; - if (!class_exists($cls)) { + for ($currentUpdate = $storedVersion + 1; $currentUpdate <= $newVersion; $currentUpdate++) { + $configString = '_' . $currentUpdate; + $updateClass = '\\Code\Update\\' . $configString; + if (!class_exists($updateClass)) { return; } @@ -56,18 +56,18 @@ class DB_Upgrade Config::Load('database'); - if (get_config('database', $s)) { + if (get_config('database', $configString)) { break; } - set_config('database', $s, '1'); + set_config('database', $configString, '1'); - $c = new $cls(); + $update = new $updateClass(); - $retval = $c->run(); + $retval = $update->run(); if ($retval != UPDATE_SUCCESS) { - $source = t('Source code of failed update: ') . "\n\n" . @file_get_contents('Code/Update/' . $s . '.php'); + $source = t('Source code of failed update: ') . "\n\n" . @file_get_contents('Code/Update/' . $configString . '.php'); // Prevent sending hundreds of thousands of emails by creating @@ -80,7 +80,7 @@ class DB_Upgrade } @unlink($lockfile); //send the administrator an e-mail - file_put_contents($lockfile, $x); + file_put_contents($lockfile, $currentUpdate); $r = q( "select account_language from account where account_email = '%s' limit 1", @@ -96,8 +96,8 @@ class DB_Upgrade [ '$sitename' => App::$config['system']['sitename'], '$siteurl' => z_root(), - '$update' => $x, - '$error' => sprintf(t('Update %s failed. See error logs.'), $x), + '$update' => $currentUpdate, + '$error' => sprintf(t('Update %s failed. See error logs.'), $currentUpdate), '$baseurl' => z_root(), '$source' => $source ] @@ -106,10 +106,10 @@ class DB_Upgrade ); //try the logger - logger('CRITICAL: Update Failed: ' . $x); + logger('CRITICAL: Update Failed: ' . $currentUpdate); pop_lang(); } else { - set_config('database', $s, 'success'); + set_config('database', $configString, 'success'); } } } diff --git a/Code/Module/Photos.php b/Code/Module/Photos.php index 0b48241a5..19f9a4e9e 100644 --- a/Code/Module/Photos.php +++ b/Code/Module/Photos.php @@ -580,7 +580,7 @@ class Photos extends Controller if (!x(App::$data, 'channel')) { notice(t('No photos selected') . EOL); - return; + return ''; } $ph = photo_factory(''); @@ -633,7 +633,7 @@ class Photos extends Controller if (!$can_view) { notice(t('Access to this item is restricted.') . EOL); - return; + return ''; } $sql_item = item_permissions_sql($owner_uid, get_observer_hash()); @@ -642,12 +642,12 @@ class Photos extends Controller Navbar::set_selected('Photos'); - $o = ' + $output = ' '; - $o .= "\r\n"; $_is_owner = (local_channel() && (local_channel() == $owner_uid)); @@ -858,19 +858,19 @@ class Photos extends Controller if ($_REQUEST['aj']) { if ($photos) { - $o = replace_macros(Theme::get_template('photosajax.tpl'), array( + $output = replace_macros(Theme::get_template('photosajax.tpl'), array( '$photos' => $photos, '$album_id' => $datum )); } else { - $o = '
'; + $output = '
'; } - echo $o; + echo $output; killme(); } else { - $o .= ""; + $output .= ""; $tpl = Theme::get_template('photo_album.tpl'); - $o .= replace_macros($tpl, array( + $output .= replace_macros($tpl, array( '$photos' => $photos, '$album' => $album, '$album_id' => $datum, @@ -885,7 +885,7 @@ class Photos extends Controller '$usage' => $usage_message )); - return $o; + return $output; } } @@ -929,7 +929,7 @@ class Photos extends Controller } else { notice(t('Photo not available') . EOL); } - return; + return ''; } @@ -1307,7 +1307,7 @@ class Photos extends Controller $responses = get_responses($conv_responses, $response_verbs, '', $link_item); - $o .= replace_macros(Theme::get_template('photo_view.tpl'), [ + $output .= replace_macros(Theme::get_template('photo_view.tpl'), [ '$id' => $ph[0]['id'], '$album' => $album_e, '$tools_label' => t('Photo Tools'), @@ -1343,8 +1343,8 @@ class Photos extends Controller '$paginate' => $paginate, ]); - App::$data['photo_html'] = $o; - return $o; + App::$data['photo_html'] = $output; + return $output; } // Default - show recent photos @@ -1402,19 +1402,19 @@ class Photos extends Controller if ($_REQUEST['aj']) { if ($photos) { - $o = replace_macros(Theme::get_template('photosajax.tpl'), [ + $output = replace_macros(Theme::get_template('photosajax.tpl'), [ '$photos' => $photos, '$album_id' => bin2hex(t('Recent Photos')) ]); } else { - $o = '
'; + $output = '
'; } - echo $o; + echo $output; killme(); } else { - $o .= ""; + $output .= ""; - $o .= replace_macros(Theme::get_template('photos_recent.tpl'), [ + $output .= replace_macros(Theme::get_template('photos_recent.tpl'), [ '$title' => t('Recent Photos'), '$album_id' => bin2hex(t('Recent Photos')), '$file_view' => t('View files'), @@ -1426,7 +1426,7 @@ class Photos extends Controller '$usage' => $usage_message ]); - return $o; + return $output; } } } diff --git a/Code/Nomad/Receiver.php b/Code/Nomad/Receiver.php index 6c1c22cdb..81d110526 100644 --- a/Code/Nomad/Receiver.php +++ b/Code/Nomad/Receiver.php @@ -46,7 +46,7 @@ class Receiver } else { $this->rawdata = file_get_contents('php://input'); - // All access to the zot endpoint must use http signatures + // All access to the nomad endpoint must use http signatures if (!$this->Valid_Httpsig()) { logger('signature failed'); @@ -75,8 +75,6 @@ class Receiver logger('received_json: ' . json_encode($this->data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), LOGGER_DATA); - logger('received: ' . print_r($this->data, true), LOGGER_DATA); - if ($this->data && is_array($this->data)) { $this->encrypted = array_key_exists('encrypted', $this->data) && intval($this->data['encrypted']); diff --git a/boot.php b/boot.php index 15cf3ff94..7d466a6a8 100755 --- a/boot.php +++ b/boot.php @@ -89,8 +89,6 @@ function sys_boot() { * Try to open the database; */ - - if (! App::$install) { DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, App::$install); if (! DBA::$dba->connected) { @@ -795,8 +793,7 @@ function clean_urls() { function z_path() { $base = z_root(); if(! clean_urls()) - $base .= '/?q='; - + $base .= '/?req='; return $base; }