summaryrefslogtreecommitdiffstats
path: root/lib/fraktured.php
blob: 40a8af500061342f493f6875a1fd469d73aa2ec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php

function load_plugins()
{
  global $hook, $c;
  $cwd = getcwd();
  if (chdir("./plugins/")) {
    $dirs = glob('*', GLOB_ONLYDIR);
    if (is_array($dirs))
      foreach ($dirs as $dir) {
        require_once($cwd . '/plugins/' . $dir . '/index.php');
      }
  }
  chdir($cwd);
  $hook['admin-head'][] = "<script type='text/javascript' src='./js/editinplace.php?hook=" . $hook['admin-richText'] . "'></script>";
}

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()) ? "<span title='" . $d['default']['content'] . "' id='" . $id . "' class='editText richText'>" . $content . "</span>" : $content;
}

function menu($stags, $etags)
{
  global $c, $hostname;
  $mlist = explode('<br />', $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'] = "<form action='' method='POST'>
    Password <input type='password' name='password'>
    <input type='submit' name='login' value='Login'> $msg
    <br /><br /><b class='toggle'>Change password</b>
    <div class='hide'><br />Type your old password above and your new one below.<br />
    New Password <input type='password' name='new'>
    <input type='submit' name='login' value='Change'>
    <input type='hidden' name='sub' value='sub'>
    </div>
    </form>";
}

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 "<div class='settings'>
    <h3 class='toggle'>↕ Settings ↕</h3>
    <div class='hide'>
    <div class='change border'><b>Theme</b>&nbsp;<span id='theme_name'><select name='theme_name' onchange='fieldSave(\"theme_name\",this.value);'>";
  if (chdir("./themes/")) {
    $dirs = glob('*', GLOB_ONLYDIR);
    foreach ($dirs as $val) {
      $select = ($val == $c['theme_name']) ? ' selected' : '';
      echo '<option value="' . $val . '"' . $select . '>' . $val . "</option>\n";
    }
  }
  echo "</select></span></div>
    <div class='change border'><b>Navigation <small>(hint: add your page below and <a href='javascript:location.reload(true);'>click here to refresh</a>)</small></b><br /><span id='menu' title='Home' class='editText'>" . $c['menu'] . "</span></div>";
  foreach (array('title', 'description', 'keywords', 'copyright') as $key) {
    echo "<div class='change border'><span title='" . $d['default'][$key] . "' id='" . $key . "' class='editText'>" . $c[$key] . "</span></div>";
  }
  echo "</div></div>";
}