aboutsummaryrefslogtreecommitdiff
path: root/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'functions.php')
-rw-r--r--functions.php419
1 files changed, 406 insertions, 13 deletions
diff --git a/functions.php b/functions.php
index 9f5ff49..31eeb94 100644
--- a/functions.php
+++ b/functions.php
@@ -24,7 +24,7 @@ function failure($reason, $httpcode, $ajax = true, $heading = NULL){
exit;
}
- // TODO: Put pretty HTML here, please
+ // TODO: Put pretty HTML here, please --deprecated?
# print full error page
if($heading != NULL)
@@ -111,8 +111,8 @@ if( isset($_GET["goto"]) && $_GET["goto"] != "" ) {
}
function print_logout(){
- global $cache;
- $cache = false;
+ global $c;
+ $c->bypassCache = true;
global $user;
if ( $user->isLoggedIn() ){
$user->logout();
@@ -348,8 +348,8 @@ function _add_entry(){
function print_404(){
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
- global $cache;
- $cache = false;
+ global $c;
+ $c->bypassCache=true;
?>
<!--h1 style="color:red;font-size:3.0em;">404 - Not Found</h1-->
<h1>Error 404 - Not Found</h1>
@@ -368,7 +368,7 @@ function print_404(){
</div>
<br>
<p>Wir haben die Seite <strong>'<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>'</strong> nicht gefunden!</p>
- <a href="javascript:history.go(-1)" title="Index">Geh eins zurück!</a>
+ <a href="javascript:history.go(-1)" title="Index"><span class="fa fa-hand-o-left"></span> Geh eins zurück!</a>
</div>
<?php
}
@@ -476,8 +476,8 @@ function print_register($option = false){
}
function print_account($option = false){
- global $cache;
- $cache = false;
+ global $c;
+ $c->bypassCache = true;
lredirect("account");
global $user;
?>
@@ -619,8 +619,8 @@ function print_recover($option = false){
}
function print_download(){
- global $cache;
- $cache = false;
+ global $c;
+ $c->bypassCache = true;
if ( ! isset($_GET["type"]) || $_GET["type"] == "plain" )
$type = "plain";
else
@@ -641,12 +641,388 @@ function print_download(){
<?php
}
+function show_gallery(){
+ if ( isset($_GET["gallery"]) && ! is_null($_GET["gallery"]) && $_GET["gallery"] != "" )
+ $_SESSION["gallery"] = $_GET["gallery"];
+ else
+ $_SESSION["gallery"] = 0;
+ lredirect("gallery;gallery=".$_SESSION["gallery"]);
+
+ global $c;
+ global $db;
+ $sql = $db->prepare("SELECT name, description, owner, time FROM " . DBPREFIX . "gallery WHERE id = %d ;", $_GET["gallery"]);
+ $res = $db->doQuery($sql);
+ require 'static/modal-new-gallery.html';
+ if ( $res->num_rows <= 0 ) {
+ // Start 404
+ $c->bypassCache=true;
+
+?>
+ <h1>Keine Galerie gefunden!</h1>
+ <hr width="50%">
+ <h4>Vielleicht wäre es angebracht eine neue Galerie zu erstellen?</h4>
+ <br>
+ <button class="btn btn-primary " data-toggle="modal" data-target="#modal-new-gallery" data-loading-text="Lade...">
+ <span class="fa fa-folder-open"></span> Erstelle eine Neue!
+ </button>
+ </div>
+
+<?php
+ // End 404
+ } else {
+ // Start non-404
+
+ global $moar;
+ $moar->addHeader( "<style>".file_get_contents('static/gallery.min.css')."</style>" );
+ $moar->addFooter('<script src="/js/gallery.min.js" defer></script>');
+
+ if ( isset($_GET["edit"]) ){
+ $moar->addFooter('<script>$("#modal-edit-gallery").modal("show");</script>');
+ }
+ if ( isset($_GET["new"]) ){
+ $moar->addFooter('<script>$("#modal-new-gallery").modal("show");</script>');
+ }
+
+ if ( $c->exists2( CACHEPREFIX . "gallery_headline_" . $_SESSION["gallery"] ) ){
+ echo $c->get2( CACHEPREFIX . "gallery_headline_" . $_SESSION["gallery"] );
+ } else {
+ ob_start();
+ $row = $res->fetch_array(MYSQLI_ASSOC);
+ $owner = $db->doQuery("SELECT name FROM " . DBPREFIX . "user WHERE id = " . $row["owner"] . ";");
+ $owner = $owner->fetch_array(MYSQLI_NUM);
+ $owner = $owner[0];
+
+ require 'static/modal-edit-gallery.php';
+ require 'static/modal-delete-gallery.php';
+
+?>
+ <ul class="list-inline">
+ <li><h1><span class="fa fa-camera-retro"></span> <?php echo htmlentities($row["name"]); ?> <span class="desc">|</span> </h1></li>
+ <li><h5 class="desc">erstellt von <?php echo htmlentities($owner . " am " . date("j.n.Y", $row["time"])); ?></h5></li>
+ </ul>
+ <h5><?php echo htmlentities($row["description"]); ?></h5>
+<?php
+ $c->set2( CACHEPREFIX . "gallery_headline_" . $_SESSION["gallery"], ob_get_contents() );
+ ob_end_flush();
+ }
+?>
+ </div>
+ </div>
+ <div class="row">
+ <!-- Tab Navigation! -->
+ <ul class="nav nav-tabs" role="tablist">
+<?php
+# determines active class for tab naviagation
+ if ( ! isset($_GET["mode"]) || $_GET["mode"] == "" )
+ $_GET["mode"] = "show";
+
+ $active = array('show' => 'Galerie', 'upload' => 'Hochladen');
+ foreach($active as $tab => $msg){
+ if ( $tab == "show" ) {
+ $span = '<span class="fa fa-picture-o"></span> ';
+ } elseif ( $tab == "upload") {
+ $span = '<span class="fa fa-upload"></span> ';
+ } else {
+ $span="";
+ }
+
+ if ( $tab == $_GET["mode"] )
+ echo '<li class="active"><a href="/?page=gallery&amp;gallery='.htmlentities($_GET["gallery"]).'&mode='.$tab.'" role="tab">'.$span.$msg.'</a></li>';
+ else
+ echo '<li><a href="/?page=gallery&amp;gallery='.htmlentities($_GET["gallery"]).'&mode='.$tab.'" role="tab">'.$span.$msg.'</a></li>';
+ }
+?>
+ <li><a href="#change" role="tab" onclick="$('#modal-edit-gallery').modal('show');"><span class="glyphicon glyphicon-cog"></span> Ändern</a></li>
+ <li><a href="#new" role="tab" onclick="$('#modal-new-gallery').modal('show')"><span class="fa fa-plus"></span> Neu</a></li>
+ <li><a href="#delete" role="tab" onclick="$('#modal-delete-gallery').modal('show')"><span class="glyphicon glyphicon-trash"></span> Löschen</a></li>
+ </ul>
+ <div class="tab-content">
+<?php
+ if ( $_GET["mode"] == "show" ){
+?>
+ <!-- Start Tab 'Gallery' -->
+ <div class="tab-pane active effect" id="galerie">
+
+<div id="blueimp-gallery" class="blueimp-gallery" data-use-bootstrap-modal="false">
+ <!-- The container for the modal slides -->
+ <div class="slides"></div>
+ <!-- Controls for the borderless lightbox -->
+ <h3 class="title"></h3>
+ <a class="prev">‹</a>
+ <a class="next">›</a>
+ <a class="close">×</a>
+ <a class="play-pause"></a>
+ <ol class="indicator"></ol>
+ <!-- The modal dialog, which will be used to wrap the lightbox content -->
+ <div class="modal fade">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" aria-hidden="true">&times;</button>
+ <h4 class="modal-title"></h4>
+ </div>
+ <div class="modal-body next"></div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default pull-left prev">
+ <i class="glyphicon glyphicon-chevron-left"></i>
+ Previous
+ </button>
+ <button type="button" class="btn btn-primary next">
+ Next
+ <i class="glyphicon glyphicon-chevron-right"></i>
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+<?php
+ if ( $c->exists( CACHEPREFIX . "gallery_imagelinks_" . $_SESSION["gallery"] ) ){
+ echo $c->get2( CACHEPREFIX . "gallery_imagelinks_" . $_SESSION["gallery"] );
+ } else {
+ ob_start();
+ $images = array_diff( scandir(IMAGE_PATH . $_SESSION["gallery"] . '/thumbnail' ), array('..', '.') );
+ if ( ! is_null($images) ){
+ echo '<div id="links">';
+ foreach($images as $image){
+ echo '<a href="'.IMAGE_URL.'?file='.$image.'&amp;download=1" title="'.$image.'" data-gallery>
+ <img src="'.IMAGE_URL.'?file='.$image.'&amp;thumb=1" alt="'.$image.'">
+ </a>';
+ }
+ echo "</div>";
+ } else {
+ echo "<h4>Keine Bilder in der aktuellen Gallerie vorhanden!</h4>";
+ }
+ $c->set2( CACHEPREFIX . "gallery_imagelinks_" . $_SESSION["gallery"], ob_get_contents() );
+ ob_end_flush();
+ }
+?>
+ <!-- End Tab 'Galerie' -->
+ </div>
+<?php
+ } elseif ( $_GET["mode"] == "upload" ){
+ $moar->addFooter('<script src="/js/upload.min.js" defer></script>');
+?>
+ <!-- Start Tab 'Upload' -->
+ <div class="tab-pane active effect" id="upload">
+ <!-- The file upload form used as target for the file upload widget -->
+ <form id="fileupload" action="/images/" method="POST" enctype="multipart/form-data">
+ <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
+ <div class="row fileupload-buttonbar">
+ <div class="col-lg-7">
+ <!-- The fileinput-button span is used to style the file input field as button -->
+ <span class="btn btn-success fileinput-button">
+ <i class="glyphicon glyphicon-plus"></i>
+ <span>Add files...</span>
+ <input type="file" name="files[]" multiple>
+ </span>
+ <button type="submit" class="btn btn-primary start">
+ <i class="glyphicon glyphicon-upload"></i>
+ <span>Start upload</span>
+ </button>
+ <button type="reset" class="btn btn-warning cancel">
+ <i class="glyphicon glyphicon-ban-circle"></i>
+ <span>Cancel upload</span>
+ </button>
+ <button type="button" class="btn btn-danger delete">
+ <i class="glyphicon glyphicon-trash"></i>
+ <span>Delete</span>
+ </button>
+ <input type="checkbox" class="toggle">
+ <!-- The global file processing state -->
+ <span class="fileupload-process"></span>
+ </div>
+ <!-- The global progress state -->
+ <div class="col-lg-5 fileupload-progress fade">
+ <!-- The global progress bar -->
+ <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
+ <div class="progress-bar progress-bar-success" style="width:0%;"></div>
+ </div>
+ <!-- The extended global progress state -->
+ <div class="progress-extended">&nbsp;</div>
+ </div>
+ </div>
+ <!-- The table listing the files available for upload/download -->
+ <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
+ </form>
+ <!-- The blueimp Gallery widget -->
+ <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-filter=":even">
+ <div class="slides"></div>
+ <h3 class="title"></h3>
+ <a class="prev">‹</a>
+ <a class="next">›</a>
+ <a class="close">×</a>
+ <a class="play-pause"></a>
+ <ol class="indicator"></ol>
+ </div>
+ <!-- End Tab 'Upload' -->
+ </div>
+<!-- The template to display files available for upload -->
+<script id="template-upload" type="text/x-tmpl">
+{% for (var i=0, file; file=o.files[i]; i++) { %}
+ <tr class="template-upload fade">
+ <td>
+ <span class="preview"></span>
+ </td>
+ <td>
+ <p class="name">{%=file.name%}</p>
+ <strong class="error text-danger"></strong>
+ </td>
+ <td>
+ <p class="size">Processing...</p>
+ <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
+ </td>
+ <td>
+ {% if (!i && !o.options.autoUpload) { %}
+ <button class="btn btn-primary start" disabled>
+ <i class="glyphicon glyphicon-upload"></i>
+ <span>Start</span>
+ </button>
+ {% } %}
+ {% if (!i) { %}
+ <button class="btn btn-warning cancel">
+ <i class="glyphicon glyphicon-ban-circle"></i>
+ <span>Cancel</span>
+ </button>
+ {% } %}
+ </td>
+ </tr>
+{% } %}
+</script>
+<!-- The template to display files available for download -->
+<script id="template-download" type="text/x-tmpl">
+{% for (var i=0, file; file=o.files[i]; i++) { %}
+ <tr class="template-download fade">
+ <td>
+ <span class="preview">
+ {% if (file.thumbnailUrl) { %}
+ <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
+ {% } %}
+ </span>
+ </td>
+ <td>
+ <p class="name">
+ {% if (file.url) { %}
+ <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
+ {% } else { %}
+ <span>{%=file.name%}</span>
+ {% } %}
+ </p>
+ {% if (file.error) { %}
+ <div><span class="label label-danger">Error</span> {%=file.error%}</div>
+ {% } %}
+ </td>
+ <td>
+ <span class="size">{%=o.formatFileSize(file.size)%}</span>
+ </td>
+ <td>
+ {% if (file.deleteUrl) { %}
+ <button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
+ <i class="glyphicon glyphicon-trash"></i>
+ <span>Delete</span>
+ </button>
+ <input type="checkbox" name="delete" value="1" class="toggle">
+ {% } else { %}
+ <button class="btn btn-warning cancel">
+ <i class="glyphicon glyphicon-ban-circle"></i>
+ <span>Cancel</span>
+ </button>
+ {% } %}
+ </td>
+ </tr>
+{% } %}
+</script>
+
+<?php
+ } else {
+ $c->bypassCache = true;
+ }
+?>
+ <!-- End Tab Content -->
+ </div>
+
+<?php
+// End non-404
+ }
+?>
+<?php
+}
+
+function list_gallery(){
+ lredirect("foto");
+ require 'static/modal-new-gallery.html';
+?>
+ <h1>Liste aller Galerien</h1>
+ <hr width="%0%">
+ <!-- End Text-Center-->
+ </div>
+</div>
+ <div class="row">
+<?php
+ global $c;
+ if ( $c->exists2( CACHEPREFIX . 'list_all_gallery' ) ){
+ echo $c->get2( CACHEPREFIX . 'list_all_gallery' );
+ } else {
+ global $db;
+ $res = $db->doQuery("SELECT * FROM " . DBPREFIX . "gallery;");
+ $numb = $db->affectedRows();
+
+ $class = array('fa fa-camera', 'fa fa-camera-retro', 'fa fa-picture-o');
+ ob_start();
+ while ( $row = $res->fetch_array(MYSQLI_ASSOC) ){
+
+ $res_n = $db->doQuery("SELECT name FROM " . DBPREFIX . "user WHERE id = " . $row["owner"] . ";");
+ $name = $res_n->fetch_array(MYSQLI_ASSOC);
+ $name = $name["name"];
+ $span = '<span class="'.$class[ mt_rand(0, count($class)-1 ) ].' fa-2x a-black"></span> ';
+
+?>
+ <ul class="list-unstyled effect">
+ <li>
+ <ul class="list-inline ">
+ <li>
+ <h2><a href="/?page=gallery&amp;gallery=<?php echo $row["id"]; ?>&amp;mode=show" class="a-restore"><?php echo $span . htmlentities($row["name"]);?></a></h2>
+ </li>
+ <li>
+ <h5 class="desc">Erstellt von <u><?php echo htmlentities($name); ?></u> am <?php echo date("j.n.Y", $row["time"]); ?>.</h5>
+ </li>
+ <li>
+ <a href="/?page=gallery&amp;gallery=<?php echo $row["id"]; ?>&amp;edit=1" class="desc"><span class="glyphicon glyphicon-link font-small"></span>edit</a>
+ </li>
+ </ul>
+ </li>
+ <li>
+ <h5 class="des"><?php echo htmlentities($row["description"]); ?></h5>
+ </li>
+ <li>
+ <hr width="20%">
+ </li>
+ </ul>
+<?php
+ }
+?>
+
+ <div class="text-center">
+<?php
+ echo "<h3>$numb Ergebnisse gefunden</h3>";
+?>
+ <hr width="50%">
+ <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#modal-new-gallery" data-loading-text="Lade...">
+ <span class="fa fa-folder-open"></span> Neue Galerie
+ </button>
+
+ </div>
+<?php
+ $c->set2( CACHEPREFIX . 'list_all_gallery', ob_get_contents() );
+ ob_end_flush();
+ }
+}
+
function flush_cache(){
lredirect("cache");
global $c;
- $c->flush();
- global $cache;
- $cache = false;
+ $c->flushAll();
+ $c->bypassCache = true;
?>
<h1>Cache flushed!</h1>
</div>
@@ -670,3 +1046,20 @@ function minify($buffer){
return $buffer;
}
+
+# remove recursive all directories and files
+function rrmdir($dir) {
+ if (is_dir($dir)) {
+ $objects = scandir($dir);
+ foreach ($objects as $object) {
+ if ($object != "." && $object != "..") {
+ if (filetype($dir."/".$object) == "dir")
+ rrmdir($dir."/".$object);
+ else
+ unlink($dir."/".$object);
+ }
+ }
+ reset($objects);
+ rmdir($dir);
+ }
+}