From f0de7af14312368a11014befa428ff91bbebff76 Mon Sep 17 00:00:00 2001 From: Kamil Kaminski Date: Sun, 14 Dec 2014 04:39:17 -0600 Subject: fracturedcms, a flat file cms, fork of wondercms - minor code refactoring - fix improper navigation/footer link generation when current page is ?login or ?logout - include local jquery --- lib/fraktured.php | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 lib/fraktured.php (limited to 'lib') diff --git a/lib/fraktured.php b/lib/fraktured.php new file mode 100644 index 0000000..40a8af5 --- /dev/null +++ b/lib/fraktured.php @@ -0,0 +1,127 @@ +"; +} + +function get_slug($p) +{ + $p = strip_tags($p); + preg_match_all('/([a-z0-9A-Z-_]+)/', $p, $matches); + $matches = array_map('strtolower', $matches[0]); + $slug = implode('-', $matches); + return $slug; +} + +function is_loggedin() +{ + global $c; + return $c['loggedin']; +} + +function edit_tags() +{ + global $hook; + if (!is_loggedin() && !isset($_REQUEST['login'])) + return; + foreach ($hook['admin-head'] as $o) { + echo "\t" . $o . "\n"; + } +} + +function content($id, $content) +{ + global $d; + echo (is_loggedin()) ? "" . $content . "" : $content; +} + +function menu($stags, $etags) +{ + global $c, $hostname; + $mlist = explode('
', $c['menu']); + for ($i = 0; $i < count($mlist); $i++) { + $page = get_slug($mlist[$i]); + if (!$page) + continue; + echo $stags . " href='" . strchr($hostname, '?', TRUE) . $page . "'>" . str_replace('-', ' ', $page) . " " . $etags . " \n"; + } +} + +function login_form() +{ + global $c, $msg; + $msg = ''; + if (isset($_POST['sub'])) login(); + $c['content'] = "
+ Password + $msg +

Change password +

Type your old password above and your new one below.
+ New Password + + +
+
"; +} + +function login() +{ + global $c, $msg; + if (md5($_POST['password']) <> $c['password']) { + $msg = "Wrong Password"; + return; + } + if ($_POST['new']) { + save_password($_POST['new']); + $msg = 'Password changed'; + return; + } + $_SESSION['l'] = $c['password']; + header('Location: ./'); + exit; +} + +function save_password($p) +{ + $file = @fopen('files/password', 'w'); + if (!$file) { + echo "Error opening password. Set correct permissions (644) to the password file."; + exit; + } + fwrite($file, md5($p)); + fclose($file); + return md5($p); +} + +function settings() +{ + global $c, $d; + echo "
+

↕ Settings ↕

+
+
Theme 
+
Navigation (hint: add your page below and click here to refresh)
" . $c['menu'] . "
"; + foreach (array('title', 'description', 'keywords', 'copyright') as $key) { + echo "
" . $c[$key] . "
"; + } + echo "
"; +} -- cgit v1.2.3