simpub/shared.php

191 lines
7.0 KiB
PHP
Raw Normal View History

2017-01-27 20:29:27 +01:00
<?php
define('PAGE_NAME', '[Simpub CMS]'); // Title of the page
2017-05-28 17:58:44 +02:00
define("PAGE_URL", "notsyncing.net"); // Base URL of the page
2017-01-27 20:29:27 +01:00
define('PAGE_AUTHOR', 'Simpub CMS'); // Author of the page (used in footer)
define('HOME_PAGE', 'blog'); // Entry page (and link for logo)
define('CACHE_POSTS_TTL', 3600); // Time to cache the posts list (1h)
define('POSTS_BASE', "/b/"); // Root directory of the posts (relative)
define('YT_PREVIEW', "/b/pimg-yt/"); // Directory containing local copies of the youtube thumbnails
2017-01-27 20:29:27 +01:00
define('POSTS_ROOT', $_SERVER['DOCUMENT_ROOT'] . POSTS_BASE); // Root directory of the posts (absolute)
define('POSTS_PAGE_SIZE', 10); // Numbers of posts on a page
define('POSTS_DIR_SEP', "."); // Directory separator (/) in post names
define('POSTS_MAX_FILENAME', 30); // Maximum length of a post name (including suffix)
define('POSTS_TAG_SEARCH', 30); // Maximum length for the tag search argument
2017-05-27 11:45:08 +02:00
define('RSS_ENABLED', true); // Enable the RSS news feed
define('RSS_REFRESH_INTERVAL', 14400); // Advertised update interval for the RSS feed
define('RSS_SHOW_FULL', false); // Show extended section in RSS feed
2017-01-27 20:29:27 +01:00
2017-09-30 16:09:46 +02:00
define('RSS_DATE_FORMAT', 'D, d M Y H:i:s O');
2017-01-27 20:29:27 +01:00
$menuItems = array(
array("label" => "Page A", "link" => "?p=00-template", "highlight" => "related-subpages,00-template"),
array("label" => "Page B", "link" => "?p=404", "highlight" => "404"),
array("label" => "Repository", "link" => "https://git.notsyncing.net:8080", "highlight" => ""),
array("label" => "Contact", "link" => "?p=00-template", "highlight" => "")
);
$blogDirs = array("2017");
function opted_in($identifier) {
global $optin;
return (stripos($optin, $identifier) !== false);
}
function append_param($p) {
$url = $_SERVER['REQUEST_URI'];
if (stripos($url, "?") !== false)
$url .= "&";
else
$url .= "?";
$url .= $p;
return $url;
}
2017-01-27 20:29:27 +01:00
/*
* This function will include an image as figure.
* returns : Number of the figure for later referencing.
* $title : Image title, will be prefixed with Figure n.
* $path : If $path starts with http or / it will be
* treated as an absolute path and no downscaled preview will be rendered.
* Other paths will be prefixed with /b/img.
* $preview : When set to "", no preview will be generated. Otherwise the specified
* path will be used.
* $link : Link to follow when clicking the image. Default is the full resolution image.
*/
$counters['figure'] = 1;
function includeGraphics($title, $path, $preview="+", $style="", $link="+") {
global $blogentry;
global $counters;
$title = "Figure " . $counters['figure'] . ". $title";
// TODO: External image
if (substr($path, 0, 4) == "http" || $path[0] == "/") {
$preview="";
$spath=$path;
}
else {
$spath = POSTS_BASE . "img/" . $path;
$fpath = $_SERVER['DOCUMENT_ROOT'] . $spath;
}
if ($preview == "+") {
$previewPath = POSTS_BASE . "pimg/" . str_replace("/", "_", $path);
$fpreviewPath = $_SERVER['DOCUMENT_ROOT'] . $previewPath;
if (!file_exists($fpreviewPath)) {
preg_match("/^[A-Za-z_\.\-0-9\/]*$/", $fpath, $matches); // SANITIZED!
if (!$matches) {
echo "<p>SERVER ERROR: Image not valid!</p>";
return ;
}
$page=substr($page,0,12); // SECURITY: Max 12 chars
exec("gm convert '$fpath' -resize 640 '$fpreviewPath';");
}
}
elseif ($preview == "") {
$previewPath = $spath;
}
else {
$previewPath = $preview;
}
if ($link == "+")
$link = $spath;
echo '<figure>
<a href="' . $link . '">
<img style="' . $style . '" title="' . $title . '" style="margin: 0px;padding: 0px;" src="' . $previewPath . '">
</a>
<figcaption>' . $title . '</figcaption>
</figure>';
return $counters['figure']++;
}
/*
* This function will include a video.
* returns : Number of the video for later referencing.
* $url : URL of the video. Autodetects YouTube. Otherwise HTML5 video.
* $title : Display "Video n. $title" below the video.
* $width : Width of the player
*/
$counters['video'] = 1;
function includeVideo($url, $title="", $width=640) {
global $counters;
$vlink = "NULL";
preg_match("/.*youtube.com\/embed\/(.*)$/", $url, $matches);
if (!$matches)
preg_match("/.*youtube.com\/watch\?v=([^&]*).*$/", $url, $matches);
if ($matches) {
$youtube['embed'] = "https://www.youtube.com/embed/" . $matches[1];
$youtube['link'] = "https://www.youtube.com/watch?v=" . $matches[1];
$youtube['vid'] = $matches[1];
}
2017-01-27 20:29:27 +01:00
echo '<videoframe><div class="videoframe" style="width:' . $width . 'px;height:' . $width*9/16 . 'px">';
if (isset($youtube)) {
if (opted_in('y')) {
echo '<iframe width="100%" height="100%" src="' . $url . '" frameborder="0" allowfullscreen></iframe>';
} else {
echo "<div style='width:100%;height:100%;background-color:black;background-image: url(" . YT_PREVIEW . $youtube['vid'] . ".jpg);background-size:contain;'><table border=0 style='height:100%;width:100%;backdrop-filter:blur(3px);background-color:rgba(0,0,0,0.55);text-shadow:1px 1px black;'><tr><td style='text-align:center;'>Embedded content has been disabled to protect your privacy.<br><br><br><strong><form action='' method='post'><input type='hidden' name='optin-once' value='y' /><input type='submit' value='Click here to load the videos on this site once,'/></form></strong><br><br><strong><a href='/?p=privacy-controls'>or click here to allow them permanently,</a><br><br><a href=\"" . $youtube['link'] . "\">" . "or click here to watch the video on YouTube:<br>" . $youtube['link'] . "</a></strong><br><br><br>Please note that, by enabling this video, data is transferred <br>to YouTube LLC, and is subject to their privacy policy.</td></tr></table></div>";
}
} else {
// TODO: HTML5 video
echo "SERVER ERROR: Video format not supported.";
}
2017-01-27 20:29:27 +01:00
echo '</div></videoframe>';
if ($title != "") {
echo '<vidcaption>Video ' . $counters['video'] . ". $title</vidcaption>";
}
return $counters['video']++;
}
/*
* This function will add a reference
* returns : Number of the source for later referencing
* $url : URL of the source, if its a number it will not create a new entry.
*/
$meta['sources'] = array();
$counters['sources'] = 1;
function addSource($url, $text="") {
2017-01-27 20:29:27 +01:00
global $counters;
global $meta;
if ("$text" != "")
$text .= " ";
2017-01-27 20:29:27 +01:00
if (is_numeric($url)) {
echo "<a href=\"#src$url\">[" . $url . "]</a>";
return $url;
}
else {
// Check whether source already exists
$i = 1;
foreach ($meta['sources'] as $v) {
if ($v == $url) {
echo "<a href=\"$url\">" . $text . "[" . $i . "]</a>";
2017-01-27 20:29:27 +01:00
return $i;
}
$i++;
}
// If not found, then add
$meta['sources'][$counters['sources']] = $url;
echo "<a href=\"$url\">" . $text . "[" . $counters['sources'] . "]</a>";
2017-01-27 20:29:27 +01:00
return $counters['sources']++;
}
}
2017-05-27 11:45:08 +02:00
function getServerUrl() {
$temp = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
2017-05-28 17:58:44 +02:00
$temp .= PAGE_URL;
2017-05-27 11:45:08 +02:00
return $temp;
}
2017-01-27 20:29:27 +01:00
?>