';
				$links = array();
				if (preg_match_all('/\[\[(.*)\]\]/', $content, $links, PREG_SET_ORDER))
				{
					foreach($links as $link)
					{
						$divcontent .=  '
';
					}
				}
				$links = array();
				if (preg_match_all('/https:(.*)\b/', $content, $links, PREG_SET_ORDER))
				{
					foreach($links as $link)
					{
						$divcontent .=  '
';
					}
				}
				$divcontent .= '
 ';
				return $divcontent;
			}
			$nextpage = 'home';
			if (isset($_GET['clip']) && $_GET['param'])
			{
			 	$content = $_GET['param'] . "\r\n" . file_get_contents($dir . '/todo');
				savenote('todo', $content);
				$_GET['param'] = '';
			}
			else if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['links']) || isset($_POST['stats']))
			{
				$title = $_POST['title'];
				$content = $_POST['content'];
				savenote($title, $content);
				$previoustitle = $_POST['previoustitle'];
				if ($title != $previoustitle)
				{
					rename($dir . '/' . $previoustitle, $dir . '/' . $previoustitle . '.del');
					removefromindex($previoustitle);
				}
				if (!isset($_POST['home']))
				{
					$nextpage = 'note';
				}
			}
			else if (isset($_POST['delete']))
			{
				$title = $_POST['title'];
				rename($dir . '/' . $title, $dir . '/' . $title . '.del');
				removefromindex($title);
			}
			else if (isset($_POST['preview']))
			{
				require 'libs/Parsedown.php';
				$title = $_POST['title'];
				$content = $_POST['content'];
				$pos = 0;
				if (str_starts_with($content, '---'))
				{
					$pos = strpos($content, '---', 3) + 3;
				}
				$Parsedown = new Parsedown();
				$Parsedown->setBreaksEnabled(true);
				echo $Parsedown->text('# ' . $title . "\r\n" . substr($content, $pos));
				$nextpage = '';
			}
			else if (isset($_GET['open']))
			{
				$nextpage = 'note';
				$title = $_GET['param'];
			}
			if ($nextpage == 'note')
			{
				$now = date("Y-m-d H.i.s", time());
				if (!$title)
				{
					$title = $now;
				}
				if (!file_exists($dir . '/' . $title))
				{
					$content = "---\r\ndate: " . substr($now, 0, 10) . "\r\ntags: \r\n---\r\n";
					savenote($title, $content);
				}
				else if (!$content)
				{
					$content = file_get_contents($dir . '/' . $title);
				}
				$lines = substr_count($content, "\r\n");
				$words = substr_count($content, " ") + $lines;
				$chars = strlen($content);
				$rows = max(20, $lines) * 2;
				require('note.php');
			}
			else if ($nextpage == 'home')
			{
				if (isset($_GET['param']))
				{
					$param = $_GET['param'];
				}
				require('home.php');
				echo '';
				if (!isset($_SESSION['index']) || isset($_GET['reindex']) || empty($_SESSION['index']))
				{
					$files = glob($dir . '/*');
					usort($files, function($a, $b)
					{
						return filemtime($b) - filemtime($a);
					});
					$_SESSION['index'] = $files;
				}
				foreach($_SESSION['index'] as $path)
				{
					$tags = '';
					$name = basename($path);
					if (!str_ends_with($name, '.del'))
					{
						if ($_GET['param'] && (isset($_GET['search']) || isset($_GET['tags'])))
						{
							$content = file_get_contents($path);
							if ((isset($_GET['search']) && !str_contains(strtolower($content), strtolower($param)) && !str_contains(strtolower($name), strtolower($param)))
								|| (isset($_GET['tags']) && !preg_match('/tags:.*' . $param . '/i', $content)))
							{
								continue;
							}
						}
						echo '
' . $name .'';
						if (isset($content) && isset($_GET['tags']))
						{
							$tags = array();
							$hastags = preg_match_all('/tags:(.*)/i', $content, $tags, PREG_SET_ORDER);
							if ($hastags)
							{
								$tagslist = explode(',', $tags[0][1]);
								echo '
 ';
								foreach ($tagslist as $tag)
								{
									$tag = trim($tag);
									echo('' . $tag . ' ');
								}
								echo '';
							}
						}
						else if (isset($_GET['search']) && str_contains(strtolower($content), strtolower($param)))
						{
							$pos = strpos(strtolower($content), strtolower($param));
							echo '
 ' . $param . substr($content, $pos + strlen($param), 42) . '';
						}
						echo'
 ';
					}
				}
				echo '
 ';
			}
		?>