27.06.2017, 13:49
Witaj problem jest taki
Parse error: syntax error, unexpected ':', expecting '{' in /home/p507136/public_html/fabryka-skilla.pl/inc/plugins/dvz_stream/core.php on line 5
czy ktoś mógby naprawić to
Parse error: syntax error, unexpected ':', expecting '{' in /home/p507136/public_html/fabryka-skilla.pl/inc/plugins/dvz_stream/core.php on line 5
czy ktoś mógby naprawić to
<?php
namespace dvzStream;
function defaultFormatHandler(StreamEvent $streamEvent): string
{
global $mybb;
$event = [];
$user = $streamEvent->getUser();
$event['id'] = $streamEvent->getId();
$event['stream_name'] = \htmlspecialchars_uni($streamEvent->getStream()->getName());
$event['title'] = $streamEvent->getStream()->getEventTitle();
$event['date'] = \my_date($mybb->settings['dateformat'], $streamEvent->getDate(), null, true) . ', ' . \my_date($mybb->settings['timeformat'], $streamEvent->getDate(), null, true);
$event['user_associated'] = $user ? 1 : 0;
$event['user'] = $user
? \build_profile_link(\format_name($user['username'], $user['usergroup'], $user['displaygroup']), $user['id'])
: null;
$event['user_avatar_url'] = \format_avatar($user['avatar'])['image'];
$event['location'] = $streamEvent->getLocation()
? $streamEvent->getLocation() . ($streamEvent->getItem() ? ' → ' : null)
: null;
$event['item'] = $streamEvent->getItem()
? $streamEvent->getItem()
: null;
if ($event['user_avatar_url']) {
eval('$event[\'user_avatar\'] = "' . tpl('event_user_avatar') . '";');
} else {
$event['user_avatar'] = null;
}
$eventDetails = null;
$eventAppendix = null;
foreach ($streamEvent->getStream()->getPostFormatHandlers() as $handler) {
$handler($streamEvent, $event, $eventDetails, $eventAppendix);
}
$templateName = $streamEvent->getStream()->getCustomTemplateName() ?? 'event';
eval('$html = "' . tpl($templateName) . '";');
return $html;
}
function getFormattedEvents(array $streamEvents)
{
$html = null;
foreach ($streamEvents as $streamEvent) {
foreach ($streamEvent->getStream()->getProcessHandlers() as $handler) {
$handler($streamEvent);
}
if ($handler = $streamEvent->getStream()->getCustomFormatHandler()) {
$html .= $handler();
} else {
$html .= defaultFormatHandler($streamEvent);
}
foreach ($streamEvent->getStream()->getPostProcessHandlers() as $handler) {
$handler($streamEvent);
}
}
return $html;
}
function javascript(string $location, array $streamPointers)
{
global $mybb;
$html = null;
if ($streamPointers) {
$limit = (int)getSettingValue('limit_' . $location);
$attributes = [
'interval' => canUpdate() ? (float)getSettingValue('interval_' . $location) : 0,
'limit' => (int)$limit,
'items' => (int)$limit,
'lazyMode' => in_array(getSettingValue('lazyload'), ['off', 'start', 'always']) ? getSettingValue('lazyload') : 'off',
];
$attributesString = null;
foreach ($attributes as $name => $value) {
$attributesString .= ' data-' . $name . '="' . $value . '"';
}
$streamPointersEncoded = json_encode(
array_combine(
array_map('\htmlspecialchars_uni', array_keys($streamPointers)),
array_values($streamPointers))
);
$html .= '<script src="' . $mybb->asset_url . '/jscripts/dvz_stream.js" async defer' . $attributesString . '></script>' . PHP_EOL;
$html .= '<script type="application/json" id="dvz_stream_streamPointers">' . $streamPointersEncoded . '</script>';
}
return $html;
}
// stream handling
function addStream(Stream $stream)
{
global $dvzStreamStreams;
$dvzStreamStreams[ $stream->getName() ] = $stream;
}
function loadActiveStreams()
{
$streamNames = getActiveStreamNames();
foreach ($streamNames as $streamName) {
include_once MYBB_ROOT . 'inc/plugins/dvz_stream/streams/' . pathinfo($streamName, PATHINFO_FILENAME) . '.php';
}
}
function getStreamEventsWithPointers(array $streamEventIdPointers = null, int $limit = null): array
{
global $mybb, $dvzStreamStreams;
$streamEvents = [];
loadActiveStreams();
// get all streams
if ($streamEventIdPointers === null) {
$streamEventIdPointers = array_fill_keys(array_keys($dvzStreamStreams), 0);
}
foreach ($streamEventIdPointers as $streamName => $lastEventId) {
if (isset($dvzStreamStreams[$streamName])) {
$localStreamEvents = fetchStreamEvents($streamName, $limit, $lastEventId);
if ($localStreamEvents) {
$streamEventIdPointers[$streamName] = $localStreamEvents[0]->getId();
}
$streamEvents = array_merge($streamEvents, $localStreamEvents);
}
}
// sort descending
usort($streamEvents, function ($a, $b) {
return $b->getDate() - $a->getDate();
});
// limit items
$streamEvents = array_slice($streamEvents, 0, $limit);
return [
'streamEventIdPointers' => $streamEventIdPointers ?? [],
'streamEvents' => $streamEvents,
];
}
function fetchStreamEvents(string $streamName, int $limit, int $lastEventId = null): array
{
global $dvzStreamStreams;
$streamEvents = $dvzStreamStreams[$streamName]->getFetchHandler()($limit, $lastEventId);
return $streamEvents;
}
function getActiveStreamNames(): array
{
return getCsvSettingValues('active_streams');
}
// permissions
function canView(): bool
{
$array = getCsvSettingValues('groups_view');
return (isset($array[0]) && $array[0] == -1) || \is_member($array);
}
function canUpdate(): bool
{
$array = getCsvSettingValues('groups_update');
return (isset($array[0]) && $array[0] == -1) || \is_member($array);
}
function getInaccessibleForumIds(): array
{
global $mybb, $cache;
$ids = [];
$forums = $cache->read('forums');
$forumPermissions = $cache->read('forumpermissions');
foreach ($forums as $fid => $forumData) {
$localForumPermissions = $forumPermissions[ $fid ];
$permissions = [
'canview' => false,
'canviewthreads' => false,
'canonlyviewownthreads' => null, // any "false" supersedes "true"
];
$groups = array_merge([$mybb->user['usergroup']], explode(',', $mybb->user['additionalgroups']));
foreach ($groups as $gid) {
if (isset($localForumPermissions[ $gid ])) {
// get forum-specific group permissions
$groupPermissions = $localForumPermissions[ $gid ];
} else {
// default to global group permissions
$groupPermissions = $cache->read('usergroups')[ $gid ];
}
if ($groupPermissions['canview']) {
$permissions['canview'] = true;
}
if ($groupPermissions['canviewthreads']) {
$permissions['canviewthreads'] = true;
}
if ($groupPermissions['canonlyviewownthreads']) {
if ($permissions['canonlyviewownthreads'] == null) {
$permissions['canonlyviewownthreads'] = true;
}
} else {
$permissions['canonlyviewownthreads'] = false;
}
}
if (!$permissions['canview'] || !$permissions['canviewthreads']) {
$ids[] = $fid;
}
if ($permissions['canonlyviewownthreads']) {
$ids[] = $fid;
}
}
return $ids;
}
// common
function getSettingValue(string $name): string
{
global $mybb;
return $mybb->settings['dvz_stream_' . $name] ?? null;
}
function getCsvSettingValues(string $name): array
{
global $mybb;
return array_filter(explode(',', getSettingValue($name)));
}
function loadTemplates(array $templates, string $prefix = null)
{
global $templatelist;
if (!empty($templatelist)) {
$templatelist .= ',';
}
if ($prefix) {
$templates = preg_filter('/^/', $prefix, $templates);
}
$templatelist .= implode(',', $templates);
}
function tpl(string $name)
{
global $templates;
if (DEVELOPMENT_MODE) {
return str_replace(
"\\'",
"'",
addslashes(
file_get_contents(MYBB_ROOT . 'inc/plugins/dvz_stream/templates/' . $name . '.tpl')
)
);
} else {
return $templates->get('dvzstream_' . $name);
}
}