Commit c83fad68 by Aleksandar Hristov

ParsedownExtra (Markdown Extra in PHP);

FAQ page for admins;
1 parent 3afad25c
......@@ -45,7 +45,7 @@ else
$page_to_edit = $_GET['page_to_edit'];
$id = $db->querySingle("SELECT id FROM pages WHERE title = '$page_to_edit'");
$title = $_GET['new_page_title'];
$text = $_GET['new_page_text'];
$text = $db->escapeString($_GET['new_page_text']);
$query=$db->exec("UPDATE pages SET title = '$title', text = '$text' WHERE id = '$id'");
......@@ -84,7 +84,7 @@ else
$page_id = $db->querySingle("SELECT id FROM pages WHERE title = '$page_to_edit'");
$id = $db->querySingle("SELECT id FROM sections WHERE page_id = '$page_id' AND title = '$section_to_edit'");
$title = $_GET['new_section_title'];
$text = $_GET['new_section_text'];
$text = $db->escapeString($_GET['new_section_text']);
$query=$db->exec("UPDATE sections SET title = '$title', text = '$text' WHERE id = '$id'");
......
<?php
/**
* Created by PhpStorm.
* User: aleksandarhristov
* Date: 11.02.15
* Time: 10:39
*/
//include the smarty class and the global functions
require "libs/Smarty.class.php";
require "global_functions.php";
//initialize smarty
$smarty = new Smarty;
//get current page to determine the action about to be performed; needed to set the active id to the <li> in the sidebar menu
$current_page=$_SERVER['PHP_SELF'];
//assign a value to the current page variable in the admin sidebar wrapper template using the current_page() function from global_functions.php
$smarty->assign("current_page",current_page());
$smarty->display("tpl/faq.tpl");
?>
\ No newline at end of file
......@@ -6,6 +6,9 @@
* Time: 09:54
*/
include "Parsedown.php";
include "ParsedownExtra.php";
//function that returns all the pages in the database in an array
function get_pages()
{
......@@ -72,10 +75,12 @@ function current_page()
{
$current_page = "edit";
}
else
else if(strpos($current_page, "remove") !== false)
{
$current_page = "remove";
}
else
$current_page = "faq";
return $current_page;
}
......@@ -129,4 +134,51 @@ function return_page_id($page_title)
return $page_id;
}
function main_page($return_this, $current_page)
{
global $db;
$parsedown = new ParsedownExtra();
$query = $db->query("SELECT * FROM pages WHERE id = '$current_page'");
while($row = $query->fetchArray())
{
$page_id = $row[0];
$page_title = $row[1];
$page_text = $parsedown->text($row[2]);
$sections = $db->query("SELECT * FROM sections WHERE page_id = '$page_id'");
$i = 0;
while($row1 = $sections->fetchArray())
{
$section_id[$i] = $row1[0];
$section_title[$i] = $row1[2];
$section_text[$i] = $parsedown->text($row1[3]);
$i++;
}
}
switch($return_this)
{
case "page_id":
return $page_id;
break;
case "page_title":
return $page_title;
break;
case "page_text":
return $page_text;
break;
case "section_id":
return $section_id;
break;
case "section_title":
return $section_title;
break;
case "section_text":
return $section_text;
break;
default:
echo "Error!";
}
}
\ No newline at end of file
......@@ -13,6 +13,8 @@ require "global_functions.php";
//initialize smarty
$smarty = new Smarty;
//connect to the database
$db = new SQLite3('wiki.db');
......@@ -30,36 +32,13 @@ else
$current_page=$current_page[1];
}
$query=$db->query("SELECT * FROM pages WHERE id = '$current_page'");
while ($row=$query->fetchArray())
{
$page_id=$row[0];
$page_title=$row[1];
$page_text=$row[2];
$sections=$db->query("SELECT * FROM sections WHERE page_id = '$page_id'");
$i=0;
while ($row1=$sections->fetchArray())
{
$section_id[$i] = $row1[0];
$section_title[$i] = $row1[2];
$section_text[$i] = $row1[3];
$i++;
}
}
$smarty->assign("current_page", $current_page);
$smarty->assign("page_id", $page_id);
$smarty->assign("page_title", $page_title);
$smarty->assign("page_text", $page_text);
$smarty->assign("section_id", $section_id);
$smarty->assign("section_title", $section_title);
$smarty->assign("section_text", $section_text);
$smarty->assign("page_id", main_page("page_id", $current_page));
$smarty->assign("page_title", main_page("page_title", $current_page));
$smarty->assign("page_text", main_page("page_text", $current_page));
$smarty->assign("section_id", main_page("section_id", $current_page));
$smarty->assign("section_title", main_page("section_title", $current_page));
$smarty->assign("section_text", main_page("section_text", $current_page));
$smarty->assign("pages", get_pages());
$smarty->assign("pages_id", get_pages_id());
......
......@@ -6,6 +6,13 @@ class MyDB extends SQLite3
{
$this->open('wiki.db');
}
public function escape($data) {
if(is_array($data))
return array_map("sqlite_escape_string", $data);
return sqlite_escape_string($data);
}
}
......@@ -19,10 +26,10 @@ class MyDB extends SQLite3
$query = $db->exec('CREATE TABLE admin (username varchar(255), password VARCHAR (255))');
if(!$query) echo $db->lastErrorMsg();
$query = $db->exec('CREATE TABLE pages (id INTEGER PRIMARY KEY AUTOINCREMENT, title varchar(250) NULL, text STRING NULL)');
$query = $db->exec('CREATE TABLE pages (id INTEGER PRIMARY KEY AUTOINCREMENT, title varchar(250) NULL, text TEXT NULL)');
if(!$query) echo $db->lastErrorMsg();
$query = $db->exec('CREATE TABLE sections (id INTEGER PRIMARY KEY AUTOINCREMENT, page_id INTEGER NULL, title VARCHAR (250) NULL, text STRING NULL )');
$query = $db->exec('CREATE TABLE sections (id INTEGER PRIMARY KEY AUTOINCREMENT, page_id INTEGER NULL, title VARCHAR (250) NULL, text TEXT NULL )');
if(!$query) echo $db->lastErrorMsg();
?>
\ No newline at end of file
......@@ -291,9 +291,6 @@ html
}
@media(min-width:1025px) {
#wrapper {
padding-left: 250px;
......@@ -366,6 +363,7 @@ html
}
}
@media(max-width:1260px)
{
#datetime-number
......
//Main JS file; here is the JS needed for all the pages/subpages
$("table").addClass('table table-bordered table-striped');
......
(function($)
{
$.fn.simpleClock = function()
{
function getTime()
{
var date = new Date(),
hour = date.getHours();
return {
day: $L.days[calculateDay(date.getDay())],
date: date.getDate(),
month: $L.months[date.getMonth()],
hour: appendZero(hour),
minute: appendZero(date.getMinutes()),
second: appendZero(date.getSeconds())
};
}
// tage umrechen, da in der Languages der wochentag mit Montag beginnt und nicht mit Sonntag wie in JS benötigt
function calculateDay(weekday)
{
if(weekday == 0){
return 6;
}
return weekday - 1;
}
// appendZero - If the number is less than 10, add a leading zero.
function appendZero(num)
{
if (num < 10) {
return "0" + num;
}
return num;
}
// refreshTime - Build the clock.
function refreshTime()
{
var now = getTime();
//$('#date-container').html(now.day + ' ' + now.date + '. ' + now.month);
$('#date-container-day').html(now.day);
$('#date-container-date').html(now.date);
$('#date-container-month').html(now.month);
$('#time-container').html("<span class='time-hour'>" + now.hour + "</span>" + ":<span class='time-minute'>" + now.minute + "</span>");
}
// Tick tock - Run the clock.
refreshTime();
setInterval(refreshTime, 1000);
};
})(jQuery);
\ No newline at end of file
......@@ -28,6 +28,14 @@
{/if}
<a href="remove.php">Remove<i class="fa fa-chevron-right fa pull-right chevron-margin" id="valign-icon"></i></a>
</li>
{if $current_page eq 'faq'}
<li id="active">
{else}
<li>
{/if}
<a href="faq.php">FAQ<i class="fa fa-chevron-right fa pull-right chevron-margin" id="valign-icon"></i></a>
</li>
</ul>
</div>
<!-- /#sidebar-wrapper -->
\ No newline at end of file
......@@ -48,15 +48,6 @@
<label class="col-sm-4 control-label">New page text:</label>
<div class="col-sm-8">
<textarea class="form-control muted" name="new_page_text" id="textarea1" placeholder="Page Text"></textarea>
<div style="color:#66a3c7 !important;" class="text-center">
<i class="fa fa-bold fa editor-icon" id="bold" title="Bold"></i>
<i class="fa fa-italic fa editor-icon" id="italic" title="Italic"></i>
<i class="fa fa-underline fa editor-icon" id="underline" title="Underline"></i>
<i class="fa fa-strikethrough fa editor-icon" id="strikethrough" title="Strikethrough"></i>
<i class="fa fa-text-height fa editor-icon" id="small" title="Small"></i>
<i class="fa fa-bookmark fa editor-icon" id="mark" title="Mark"></i>
<i class="fa fa-code fa editor-icon" id="code" title="Code"></i>
</div>
</div>
</div>
</div>
......@@ -82,15 +73,6 @@
<label class="col-sm-4 control-label">New section text:</label>
<div class="col-sm-8">
<textarea class="form-control muted" name="new_section_text" id="textarea2" placeholder="Section Text"></textarea>
<div style="color:#66a3c7 !important;" class="text-center">
<i class="fa fa-bold fa editor-icon" id="bold" title="Bold"></i>
<i class="fa fa-italic fa editor-icon" id="italic" title="Italic"></i>
<i class="fa fa-underline fa editor-icon" id="underline" title="Underline"></i>
<i class="fa fa-strikethrough fa editor-icon" id="strikethrough" title="Strikethrough"></i>
<i class="fa fa-text-height fa editor-icon" id="small" title="Small"></i>
<i class="fa fa-bookmark fa editor-icon" id="mark" title="Mark"></i>
<i class="fa fa-code fa editor-icon" id="code" title="Code"></i>
</div>
</div>
</div>
</div>
......@@ -110,31 +92,6 @@
</div>
<!-- /#wrapper -->
<script>
$(function () {
$('.editor-icon').on('click', function () {
if (this.id=='bold'){ var txt = "<strong></strong>";}
else if (this.id=='italic'){ var txt = "<em></em>";}
else if (this.id=='underline'){ var txt = "<u></u>";}
else if (this.id=='strikethrough'){ var txt = "<s></s>";}
else if (this.id=='small'){ var txt = "<small></small>";}
else if (this.id=='mark'){ var txt = "<mark></mark>";}
else if (this.id=='code'){ var txt = "<pre></pre>";}
var e = document.getElementById("select_option");
var chosen_option = e.options[e.selectedIndex].value;
if (chosen_option=="page")
var box = $("#textarea1");
else if (chosen_option=="section")
var box = $("#textarea2")
box.val(box.val() + txt);
});
});
</script>
{include file="tpl/footer.tpl"}
{include file="tpl/header.tpl"}
<div id="wrapper">
{include file="tpl/admin_sidebar_wrapper.tpl"}
{include file="tpl/menu_tray.tpl"}
<div id="container2">
<h1 id="container2-header">Slimspots Wiki - FAQ</h1>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">FAQ</div>
<div class="panel-body">
<h5>1. Creating a new page/section</h5>
<p>To create a new page/section you have to click on Create in the sidebar menu. The process itself is self-explanatory:</p>
<ul>
<li>Choose what element you want to create (page or section);</li>
<li>Choose the new element's title;</li>
<li>Click the "Submit" button.</li>
</ul>
Once you're done creating the new page/section, you can edit it and give it a new title if needed, text etc.
<h5>2. Editing a page/section</h5>
<p>To edit an already existing page/section you have to click on Edit in the sidebar menu. Once the page is loaded you have to follow these steps:</p>
<ul>
<li>Choose what element you want to edit (page or section);</li>
<li>Choose the specific element you want to edit (the search field is your friend!);</li>
<li>Give it a new title if needed;</li>
<li>Type the new text using Markdown Extra (cheat sheet shown below);</li>
<li>Click the "Submit" button.</li>
</ul>
<h5>3. Removing a page/section</h5>
<p>To remove a specific page/section you have to click on Remove in the sidebar menu. The process is fairly easy:</p>
<ul>
<li>Choose what element you want to remove (page or section);</li>
<li>Choose the specific element you want to remove (the search field is your friend!);</li>
<li>Click the "Submit" button.</li>
</ul>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
{include file="tpl/footer.tpl"}
\ No newline at end of file
......@@ -3,7 +3,7 @@
<!-- Update time JavaScript -->
<script src="static/js/main.js"></script>
<script src="static/js/updatetime.js"></script>
<script src="static/js/simple-clock.js"></script>
<script src="static/js/new_fields.js"></script>
<script type="text/javascript" src="static/select2/select2.js"></script>
......
......@@ -6,16 +6,21 @@
</div>
<div id="page-content-wrapper">
<script type="text/javascript">
$L.months = ["Jan", "Feb", "Mrz", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"];
$L.days = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"];
</script>
<div class="pull-right">
<!-- In this table we display the date and time (desktop devices only) -->
<table id="datetime">
<tr>
<td id="date-container">
<span id="day"></span><br><span id="datetime-number">&nbsp;<span id="datum">&nbsp;</span>&nbsp;</span><span id="month">&nbsp;</span>&nbsp;
</td>
<td id="time-container">
<span id="hour">&nbsp;</span>&nbsp;:&nbsp;<span id="minute">&nbsp;</span>
</td>
</tr>
<tbody>
<tr>
<td id="date-container"><span id="date-container-day"></span><br><span id="date-container-date"></span>.&nbsp;<span id="date-container-month"></span></td>
<td id="time-container"></td>
</tr>
</tbody>
</table>
</div>
\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!