Message: {$e->getMessage()}
"; 29 | echo "Code: {$e->getCode()}
"; 30 | echo "Consider installing if you haven't already.
"; 31 | die(); 32 | } 33 | 34 | // Initialise the theme 35 | require_once("themes/" . Config::THEME . "/index.php"); 36 | 37 | // Kill the PHP script. Some free web hosts like to inject their tracking 38 | // scripts and this should hopefully prevent that. 39 | die(); 40 | -------------------------------------------------------------------------------- /install.php: -------------------------------------------------------------------------------- 1 | find_one() === null) { 37 | return false; 38 | } 39 | } catch (Exception $e) { 40 | return false; 41 | } 42 | 43 | return true; 44 | } 45 | 46 | function quote ($string) { 47 | return preg_replace('/[\']/', '\\\'', $string); 48 | } 49 | 50 | /** 51 | * Creates the user configuration file 52 | * 53 | * @param string $name 54 | * @param string $email 55 | * @param string $note 56 | * @param array $identities 57 | * @return bool Successful or not 58 | */ 59 | function create_user_config ($name, $email, $note, $identities) { 60 | if (empty($name) || empty($email)) return false; 61 | 62 | // Escape quote characters 63 | $name = quote($name); 64 | $email = quote($email); 65 | 66 | // Create the contents of the `user.config.php` file 67 | $contents = ' 0) { 86 | foreach ($identities as $identity) { 87 | $id_name = quote($identity['name']); 88 | $id_url = quote($identity['url']); 89 | 90 | $contents .= ' [ 91 | \'name\' => \'' . $id_name . '\', 92 | \'url\' => \'' . $id_url . '\', 93 | ], 94 | '; 95 | } 96 | } else { 97 | $contents .= ' // [ \'name\' => \'\', \'url\' => \'\' ], 98 | '; 99 | } 100 | 101 | // Close identities section 102 | $contents .= ' ]; 103 | '; 104 | 105 | // Add the final closing curly bracket 106 | $contents .= '}'; 107 | 108 | if (file_put_contents('includes/user.config.php', $contents) === false) { 109 | return false; 110 | } 111 | 112 | return true; 113 | } 114 | 115 | if (is_installed()) { 116 | unset($_SESSION['csrf_token']); 117 | header('Location: ' . ml_base_url()); 118 | return; 119 | } 120 | 121 | if (isset($_POST['submit'])) { 122 | $errors = []; 123 | $services = []; 124 | 125 | try { 126 | // Ensure both tokens were provided 127 | if (!ml_post_not_blank('token')) array_push($errors, 'CSRF Token required'); 128 | if (empty($_SESSION['csrf_token'])) array_push($errors, 'CSRF Token required'); 129 | 130 | // Make sure they're equal 131 | if (!hash_equals($_POST['token'], $_SESSION['csrf_token'])) array_push($errors, 'CSRF Token invalid'); 132 | 133 | // Validate POST variables first 134 | if (!ml_post_not_blank('name')) array_push($errors, 'Name required'); 135 | if (!ml_post_not_blank('email')) array_push($errors, 'Email required'); 136 | foreach ($_POST['sm_service_names'] as $index => $name) { 137 | $url = $_POST['sm_service_urls'][$index]; 138 | if (!empty($name) && empty($url)) { 139 | array_push($errors, "Service '$name' requires a URL"); 140 | } elseif (!empty($name) && !empty($url)) { 141 | array_push($services, [ 142 | 'name' => $name, 143 | 'url' => $url, 144 | ]); 145 | } 146 | } 147 | 148 | // Attempt to upload/resize profile picture 149 | if (isset($_FILES['photo'])) { 150 | $image = new ImageResizer( 151 | $_FILES['photo'], 152 | 'me', 153 | ImageType::JPG, 154 | ImageResizeMethod::SQUARE 155 | ); 156 | } 157 | 158 | if (count($errors) === 0) { 159 | $name = $_POST['name']; 160 | $email = $_POST['email']; 161 | $note = $_POST['note']; 162 | 163 | // Connect to DB 164 | $db = new DB(); 165 | 166 | // Create posts table 167 | $post = new Post($db); 168 | $post->create_table(); 169 | 170 | $person = new Person($db); 171 | $person->create_table(); 172 | 173 | $interaction = new Interaction($db); 174 | $interaction->create_table(); 175 | 176 | if (create_user_config($name, $email, $note, $services) === false) { 177 | throw new Exception ( 178 | 'Could not create `user.config.php`. ' + 179 | 'Check your file permissions, and that the file doesn\'t ' + 180 | 'already exist.' 181 | ); 182 | } 183 | 184 | session_destroy(); 185 | } 186 | } catch (\Throwable $e) { 187 | array_push($errors, $e->getMessage()); 188 | } 189 | } else { 190 | if (empty($_SESSION['csrf_token'])) { 191 | $_SESSION['csrf_token'] = ml_generate_token(); 192 | } 193 | } 194 | ?> 195 | 196 | 197 | 198 | 199 | 200 | 201 |350 | Installation successful! You can now create posts using a 351 | micropub editor/publisher. 352 |
353 | < Go Home 354 | 355 | 356 | 357 |358 | You are viewing this page because Microlight has not been 359 | completely set up. You will need to create an identity to begin 360 | using Microlight. 361 |
362 | 363 | 508 | 509 |