2012-05-16 07:31:36 +02:00
|
|
|
<?php
|
|
|
|
|
2017-05-02 05:09:26 +02:00
|
|
|
require_once 'vendor/autoload.php';
|
|
|
|
|
2012-05-16 07:31:36 +02:00
|
|
|
set_time_limit(0);
|
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
define('BUILD_ID', 1000);
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
define('EOL', "<br />\r\n");
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
define('REGISTER_CLOSED', 0);
|
|
|
|
define('REGISTER_APPROVE', 1);
|
2017-05-02 04:50:24 +02:00
|
|
|
define('REGISTER_OPEN', 2);
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
define('DIRECTION_NONE', 0);
|
|
|
|
define('DIRECTION_IN', 1);
|
|
|
|
define('DIRECTION_OUT', 2);
|
|
|
|
define('DIRECTION_BOTH', 3);
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
define('NOTIFY_INTRO', 0x0001);
|
|
|
|
define('NOTIFY_CONFIRM', 0x0002);
|
2017-05-02 04:50:24 +02:00
|
|
|
define('NOTIFY_WALL', 0x0004);
|
2017-04-21 03:41:47 +02:00
|
|
|
define('NOTIFY_COMMENT', 0x0008);
|
2017-05-02 04:50:24 +02:00
|
|
|
define('NOTIFY_MAIL', 0x0010);
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
define('NAMESPACE_DFRN', 'http://purl.org/macgirvin/dfrn/1.0');
|
2012-05-16 07:31:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* log levels
|
|
|
|
*/
|
2017-05-02 04:50:24 +02:00
|
|
|
define('LOGGER_NORMAL', 0);
|
|
|
|
define('LOGGER_TRACE', 1);
|
|
|
|
define('LOGGER_DEBUG', 2);
|
|
|
|
define('LOGGER_DATA', 3);
|
|
|
|
define('LOGGER_ALL', 4);
|
2017-04-21 03:41:47 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('x')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function x($s, $k = null)
|
|
|
|
{
|
|
|
|
if ($k != null) {
|
|
|
|
if ((is_array($s)) && (array_key_exists($k, $s))) {
|
|
|
|
if ($s[$k]) {
|
|
|
|
return (int) 1;
|
|
|
|
}
|
|
|
|
return (int) 0;
|
2012-05-16 07:31:36 +02:00
|
|
|
}
|
2017-04-21 03:41:47 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (isset($s)) {
|
|
|
|
if ($s) {
|
|
|
|
return (int) 1;
|
|
|
|
}
|
|
|
|
return (int) 0;
|
|
|
|
}
|
|
|
|
return false;
|
2012-05-16 07:31:36 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('system_unavailable')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function system_unavailable()
|
|
|
|
{
|
|
|
|
include('system_unavailable.php');
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('logger')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function logger($msg, $level = 0)
|
|
|
|
{
|
|
|
|
$debugging = 1;
|
2017-05-02 04:50:24 +02:00
|
|
|
$loglevel = LOGGER_ALL;
|
|
|
|
$logfile = 'logfile.out';
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if ((!$debugging) || (!$logfile) || ($level > $loglevel)) {
|
2017-04-21 03:41:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
require_once('include/datetime.php');
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
@file_put_contents($logfile, datetime_convert() . ':' . ' ' . $msg . "\n", FILE_APPEND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('replace_macros')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function replace_macros($s, $r)
|
|
|
|
{
|
|
|
|
$search = array();
|
|
|
|
$replace = array();
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
if (is_array($r) && count($r)) {
|
|
|
|
foreach ($r as $k => $v) {
|
2017-05-02 04:50:24 +02:00
|
|
|
$search[] = $k;
|
2017-04-21 03:41:47 +02:00
|
|
|
$replace[] = $v;
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
}
|
2017-04-21 03:41:47 +02:00
|
|
|
return str_replace($search, $replace, $s);
|
2012-05-16 07:31:36 +02:00
|
|
|
}
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('load_translation_table')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function load_translation_table($lang)
|
|
|
|
{
|
|
|
|
global $a;
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('t')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function t($s)
|
|
|
|
{
|
|
|
|
global $a;
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
if ($a->strings[$s]) {
|
|
|
|
return $a->strings[$s];
|
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('fetch_url')) {
|
|
|
|
function fetch_url($url, $binary = false, $timeout = 20)
|
2017-04-21 03:41:47 +02:00
|
|
|
{
|
|
|
|
$ch = curl_init($url);
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!$ch) {
|
2017-04-21 03:41:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, max(intval($timeout), 1)); //Minimum of 1 second timeout.
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
curl_setopt($ch, CURLOPT_MAXREDIRS, 8);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
if ($binary) {
|
|
|
|
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
|
|
|
|
}
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
$s = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
return($s);
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('post_url')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function post_url($url, $params)
|
|
|
|
{
|
|
|
|
$ch = curl_init($url);
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!$ch) {
|
2017-04-21 03:41:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
curl_setopt($ch, CURLOPT_MAXREDIRS, 8);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
|
|
|
$s = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
return($s);
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('random_string')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function random_string()
|
|
|
|
{
|
|
|
|
return(hash('sha256', uniqid(rand(), true)));
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('notags')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function notags($string)
|
|
|
|
{
|
|
|
|
// protect against :<> with high-bit set
|
2017-05-02 04:50:24 +02:00
|
|
|
return(str_replace(array("<", ">", "\xBA", "\xBC", "\xBE"), array('[', ']', '', '', ''), $string));
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('escape_tags')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function escape_tags($string)
|
|
|
|
{
|
|
|
|
return(htmlspecialchars($string));
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('login')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function login($register = false)
|
|
|
|
{
|
|
|
|
$o = "";
|
|
|
|
$register_html = (($register) ? file_get_contents("view/register-link.tpl") : "");
|
2012-05-16 07:31:36 +02:00
|
|
|
|
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
if (x($_SESSION, 'authenticated')) {
|
|
|
|
$o = file_get_contents("view/logout.tpl");
|
|
|
|
} else {
|
|
|
|
$o = file_get_contents("view/login.tpl");
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
$o = replace_macros($o, array('$register_html' => $register_html));
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
|
|
|
return $o;
|
2012-05-16 07:31:36 +02:00
|
|
|
}
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('killme')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function killme()
|
|
|
|
{
|
|
|
|
session_write_close();
|
|
|
|
exit;
|
2012-05-16 07:31:36 +02:00
|
|
|
}
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('goaway')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function goaway($s)
|
|
|
|
{
|
|
|
|
header("Location: $s");
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('local_user')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function local_user()
|
|
|
|
{
|
|
|
|
if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'uid'))) {
|
|
|
|
return $_SESSION['uid'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('notice')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function notice($s)
|
|
|
|
{
|
|
|
|
if (!isset($_SESSION['sysmsg'])) {
|
|
|
|
$_SESSION['sysmsg'] = '';
|
|
|
|
}
|
|
|
|
$_SESSION['sysmsg'] .= $s;
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('hex2bin')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function hex2bin($s)
|
|
|
|
{
|
|
|
|
return(pack("H*", $s));
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('paginate')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function paginate(&$a)
|
|
|
|
{
|
|
|
|
$o = '';
|
|
|
|
$stripped = preg_replace("/&page=[0-9]*/", "", $a->query_string);
|
|
|
|
$stripped = str_replace('q=', '', $stripped);
|
|
|
|
$stripped = trim($stripped, '/');
|
|
|
|
$pagenum = $a->pager['page'];
|
2017-05-02 04:50:24 +02:00
|
|
|
$url = $a->get_baseurl() . '/' . $stripped;
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
if ($a->pager['total'] > $a->pager['itemspage']) {
|
|
|
|
$o .= '<div class="pager">';
|
|
|
|
if ($a->pager['page'] != 1) {
|
2017-05-02 04:50:24 +02:00
|
|
|
$o .= '<span class="pager_prev">' . "<a href=\"$url" . '&page=' . ($a->pager['page'] - 1) . '">' . t('prev') . '</a></span> ';
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
$o .= "<span class=\"pager_first\"><a href=\"$url" . "&page=1\">" . t('first') . "</a></span> ";
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
$numpages = $a->pager['total'] / $a->pager['itemspage'];
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
$numstart = 1;
|
|
|
|
$numstop = $numpages;
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
if ($numpages > 14) {
|
|
|
|
$numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
|
|
|
|
$numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
for ($i = $numstart; $i <= $numstop; $i++) {
|
|
|
|
if ($i == $a->pager['page']) {
|
2017-05-02 04:50:24 +02:00
|
|
|
$o .= '<span class="pager_current">' . (($i < 10) ? ' ' . $i : $i);
|
2017-04-21 03:41:47 +02:00
|
|
|
} else {
|
2017-05-02 04:50:24 +02:00
|
|
|
$o .= "<span class=\"pager_n\"><a href=\"$url" . "&page=$i\">" . (($i < 10) ? ' ' . $i : $i) . "</a>";
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
|
|
|
$o .= '</span> ';
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
if (($a->pager['total'] % $a->pager['itemspage']) != 0) {
|
|
|
|
if ($i == $a->pager['page']) {
|
2017-05-02 04:50:24 +02:00
|
|
|
$o .= '<span class="pager_current">' . (($i < 10) ? ' ' . $i : $i);
|
2017-04-21 03:41:47 +02:00
|
|
|
} else {
|
2017-05-02 04:50:24 +02:00
|
|
|
$o .= "<span class=\"pager_n\"><a href=\"$url" . "&page=$i\">" . (($i < 10) ? ' ' . $i : $i) . "</a>";
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
|
|
|
$o .= '</span> ';
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
$lastpage = (($numpages > intval($numpages)) ? intval($numpages) + 1 : $numpages);
|
|
|
|
$o .= "<span class=\"pager_last\"><a href=\"$url" . "&page=$lastpage\">" . t('last') . "</a></span> ";
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
if (($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0) {
|
2017-05-02 04:50:24 +02:00
|
|
|
$o .= '<span class="pager_next">' . "<a href=\"$url" . "&page=" . ($a->pager['page'] + 1) . '">' . t('next') . '</a></span>';
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
2017-05-02 04:50:24 +02:00
|
|
|
$o .= '</div>' . "\r\n";
|
2012-05-16 07:31:36 +02:00
|
|
|
}
|
2017-04-21 03:41:47 +02:00
|
|
|
return $o;
|
2012-05-16 07:31:36 +02:00
|
|
|
}
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
function get_my_url()
|
|
|
|
{
|
|
|
|
if (x($_SESSION, 'my_url')) {
|
2012-05-16 07:31:36 +02:00
|
|
|
return $_SESSION['my_url'];
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-21 03:41:47 +02:00
|
|
|
function zrl($s, $force = false)
|
|
|
|
{
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!strlen($s)) {
|
2012-05-16 07:31:36 +02:00
|
|
|
return $s;
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
2017-05-02 04:50:24 +02:00
|
|
|
if ((!strpos($s, '/profile/')) && (!$force)) {
|
2012-05-16 07:31:36 +02:00
|
|
|
return $s;
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
|
|
|
$achar = strpos($s, '?') ? '&' : '?';
|
2012-05-16 07:31:36 +02:00
|
|
|
$mine = get_my_url();
|
2017-04-21 03:41:47 +02:00
|
|
|
if ($mine and ! link_compare($mine, $s)) {
|
2012-05-16 07:31:36 +02:00
|
|
|
return $s . $achar . 'zrl=' . urlencode($mine);
|
2017-04-21 03:41:47 +02:00
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('link_compare')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function link_compare($a, $b)
|
|
|
|
{
|
|
|
|
if (strcasecmp(normalise_link($a), normalise_link($b)) === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 07:31:36 +02:00
|
|
|
|
2017-05-02 04:50:24 +02:00
|
|
|
if (!function_exists('normalise_link')) {
|
2017-04-21 03:41:47 +02:00
|
|
|
function normalise_link($url)
|
|
|
|
{
|
|
|
|
$ret = str_replace(array('https:', '//www.'), array('http:', '//'), $url);
|
|
|
|
return(rtrim($ret, '/'));
|
|
|
|
}
|
|
|
|
}
|