Witam serdecznie mam pytanko jak zrobić wywołanie usera na Shoutbox typu [b]...[/.b] żeby był pogrubiony
DVZ Shoutbox(2.2.1)
DVZ Shoutbox(2.2.1)
<?php
/* by Tomasz 'Devilshakerz' Mlynski [devilshakerz.com]; Copyright (C) 2014-2015
released under Creative Commons BY-NC-SA 4.0 license: http://creativecommons.org/licenses/by-nc-sa/4.0/ */
$plugins->add_hook('global_start', ['dvz_shoutbox', 'global_start']); // cache shoutbox templates
$plugins->add_hook('global_end', ['dvz_shoutbox', 'global_end']); // catch archive page
$plugins->add_hook('xmlhttp', ['dvz_shoutbox', 'xmlhttp']); // xmlhttp.php listening
$plugins->add_hook('index_end', ['dvz_shoutbox', 'load_window']); // load Shoutbox window to {$dvz_shoutbox} variable
$plugins->add_hook('admin_user_users_merge_commit', ['dvz_shoutbox', 'user_merge']);
$plugins->add_hook('fetch_wol_activity_end', ['dvz_shoutbox', 'activity']); // catch activity
$plugins->add_hook('build_friendly_wol_location_end', ['dvz_shoutbox', 'activity_translate']); // translate activity
$plugins->add_hook('misc_clearcookies', ['dvz_shoutbox', 'clearcookies']);
function dvz_shoutbox_info()
{
return [
'name' => 'DVZ Shoutbox',
'description' => 'Lightweight AJAX chat.',
'website' => 'http://devilshakerz.com/',
'author' => 'Tomasz \'Devilshakerz\' Mlynski',
'authorsite' => 'http://devilshakerz.com/',
'version' => '2.2.1',
'codename' => 'dvz_shoutbox',
'compatibility' => '18*',
];
}
function dvz_shoutbox_install()
{
global $db;
// table
$db->write_query("
CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "dvz_shoutbox` (
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL,
`text` text NULL,
`date` int(11) NOT NULL,
`modified` int(11) NULL DEFAULT NULL,
`ipaddress` varbinary(16) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB " . $db->build_create_table_collation() . "
");
// example shout
$db->insert_query('dvz_shoutbox', [
'uid' => 1,
'text' => 'DVZ Shoutbox!',
'date' => TIME_NOW,
'ipaddress' => my_inet_pton('127.0.0.1'),
]);
// settings
$settingGroupId = $db->insert_query('settinggroups', [
'name' => 'dvz_shoutbox',
'title' => 'DVZ Shoutbox',
'description' => 'Settings for DVZ Shoutbox.',
]);
$settings = [
[
'name' => 'dvz_sb_num',
'title' => 'Shouts to display',
'description' => 'Number of shouts to be displayed in the Shoutbox window.',
'optionscode' => 'numeric',
'value' => '20',
],
[
'name' => 'dvz_sb_num_archive',
'title' => 'Shouts to display on archive',
'description' => 'Number of shouts to be displayed per page on Archive view.',
'optionscode' => 'numeric',
'value' => '20',
],
[
'name' => 'dvz_sb_reversed',
'title' => 'Reversed order',
'description' => 'Reverses the shouts display order in the Shoutbox window so that new ones appear on the bottom. You may also want to move the <b>{$panel}</b> variable below the window in the <i>dvz_shoutbox</i> template.',
'optionscode' => 'yesno',
'value' => '0',
],
[
'name' => 'dvz_sb_height',
'title' => 'Shoutbox height',
'description' => 'Height of the Shoutbox window in pixels.',
'optionscode' => 'numeric',
'value' => '160',
],
[
'name' => 'dvz_sb_dateformat',
'title' => 'Date format',
'description' => 'Format of the date displayed. This format uses the PHP\'s <a href="http://php.net/manual/en/function.date.php#refsect1-function.date-parameters">date() function syntax</a>.',
'optionscode' => 'text',
'value' => 'd M H:i',
],
[
'name' => 'dvz_sb_maxlength',
'title' => 'Maximum message length',
'description' => 'Set 0 to disable the limit.',
'optionscode' => 'numeric',
'value' => '0',
],
[
'name' => 'dvz_sb_mycode',
'title' => 'Parse MyCode',
'description' => '',
'optionscode' => 'yesno',
'value' => '1',
],
[
'name' => 'dvz_sb_smilies',
'title' => 'Parse smilies',
'description' => '',
'optionscode' => 'yesno',
'value' => '1',
],
[
'name' => 'dvz_sb_interval',
'title' => 'Refresh interval',
'description' => 'Number of seconds between Shoutbox updates (lower values provide better synchronization but cause higher server load). Set 0 to disable the auto-refreshing feature.',
'optionscode' => 'numeric',
'value' => '5',
],
[
'name' => 'dvz_sb_away',
'title' => 'Away mode',
'description' => 'Number of seconds after last user action (e.g. click) after which shoutbox will be minimized to prevent unnecessary usage of server resources. Set 0 to disable this feature.',
'optionscode' => 'numeric',
'value' => '600',
],
[
'name' => 'dvz_sb_antiflood',
'title' => 'Anti-flood interval',
'description' => 'Forces a minimum number of seconds to last between user\'s shouts (this does not apply to Shoutbox moderators).',
'optionscode' => 'numeric',
'value' => '5',
],
[
'name' => 'dvz_sb_sync',
'title' => 'Moderation synchronization',
'description' => 'Applies moderation actions without refreshing the Shoutbox window page.',
'optionscode' => 'onoff',
'value' => '1',
],
[
'name' => 'dvz_sb_lazyload',
'title' => 'Lazy load',
'description' => 'Start loading data only when the Shoutbox window is actually being displayed on the screen (the page is scrolled to the Shoutbox position).',
'optionscode' => 'select
off=Disabled
start=Check if on display to start
always=Always check if on display to refresh',
'value' => 'off',
],
[
'name' => 'dvz_sb_status',
'title' => 'Shoutbox default status',
'description' => 'Choose whether Shoutbox window should be expanded or collapsed by default.',
'optionscode' => 'onoff',
'value' => '1',
],
[
'name' => 'dvz_sb_minposts',
'title' => 'Minimum posts required to shout',
'description' => 'Set 0 to allow everyone.',
'optionscode' => 'numeric',
'value' => '0',
],
[
'name' => 'dvz_sb_groups_view',
'title' => 'Group permissions: View',
'description' => 'User groups that can view Shoutbox.',
'optionscode' => 'groupselect',
'value' => '-1',
],
[
'name' => 'dvz_sb_groups_refresh',
'title' => 'Group permissions: Auto-refresh',
'description' => 'User groups that shoutbox will be refreshing for.',
'optionscode' => 'groupselect',
'value' => '-1',
],
[
'name' => 'dvz_sb_groups_shout',
'title' => 'Group permissions: Shout',
'description' => 'User groups that can post shouts in Shoutbox (logged in users only).',
'optionscode' => 'groupselect',
'value' => '-1',
],
[
'name' => 'dvz_sb_groups_recall',
'title' => 'Group permissions: Scroll back to show past shouts',
'description' => 'User groups that shoutbox will load previous posts when scrolling back for.',
'optionscode' => 'groupselect',
'value' => '-1',
],
[
'name' => 'dvz_sb_groups_mod',
'title' => 'Group permissions: Moderation',
'description' => 'User groups that can moderate the Shoutbox (edit and delete shouts).',
'optionscode' => 'groupselect',
'value' => '',
],
[
'name' => 'dvz_sb_groups_mod_own',
'title' => 'Group permissions: Moderation of own shouts',
'description' => 'Users groups whose members can edit and delete their own shouts.',
'optionscode' => 'groupselect',
'value' => '',
],
[
'name' => 'dvz_sb_supermods',
'title' => 'Super moderators are Shoutbox moderators',
'description' => 'Automatically allow forum super moderators to moderate Shoutbox as well.',
'optionscode' => 'yesno',
'value' => '1',
],
[
'name' => 'dvz_sb_blocked_users',
'title' => 'Banned users',
'description' => 'Comma-separated list of user IDs that are banned from posting messages.',
'optionscode' => 'textarea',
'value' => '',
],
];
$i = 1;
foreach ($settings as &$row) {
$row['gid'] = $settingGroupId;
$row['title'] = $db->escape_string($row['title']);
$row['description'] = $db->escape_string($row['description']);
$row['disporder'] = $i++;
}
$db->insert_query_multiple('settings', $settings);
rebuild_settings();
// templates
$templates = [
'dvz_shoutbox_panel' => '<div class="panel">
<form>
<input type="text" class="text" placeholder="{$lang->dvz_sb_default}" maxlength="{$maxlength}" autocomplete="off" />
<input type="submit" style="display:none" />
</form>
</div>',
'dvz_shoutbox' => '<div id="shoutbox" class="front{$classes}">
<div class="head">
<strong>{$lang->dvz_sb_shoutbox}</strong>
<p class="right"><a href="{$mybb->settings[\'bburl\']}/index.php?action=shoutbox_archive">« {$lang->dvz_sb_archivelink}</a></p>
</div>
<div class="body">
{$panel}
<div class="window" style="height:{$mybb->settings[\'dvz_sb_height\']}px">
<div class="data">
{$html}
</div>
</div>
</div>
<script type="text/javascript" src="{$mybb->settings[\'bburl\']}/jscripts/dvz_shoutbox.js"></script>
{$javascript}
</div>',
'dvz_shoutbox_archive' => '<html>
<head>
<title>{$lang->dvz_sb_archive}</title>
{$headerinclude}
</head>
<body>
{$header}
<script type="text/javascript" src="{$mybb->settings[\'bburl\']}/jscripts/dvz_shoutbox.js"></script>
{$javascript}
{$modoptions}
{$multipage}
<br />
<div id="shoutbox">
<div class="head"><strong>{$lang->dvz_sb_archive}</strong></div>
<div class="data">
{$archive}
</div>
</div>
<br />
{$multipage}
{$footer}
</body>
</html>',
'dvz_shoutbox_archive_modoptions' => '<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr><td class="thead" colspan="2"><strong>{$lang->dvz_sb_mod}</strong></td></tr>
<tr><td class="tcat">{$lang->dvz_sb_mod_banlist}</td><td class="tcat">{$lang->dvz_sb_mod_clear}</td></tr>
<tr>
<td class="trow1">
<form action="" method="post">
<input type="text" class="textbox" style="width:80%" name="banlist" value="{$blocked_users}"></textarea>
<input type="hidden" name="postkey" value="{$mybb->post_code}" />
<input type="submit" class="button" value="{$lang->dvz_sb_mod_banlist_button}" />
</form>
</td>
<td class="trow1">
<form action="" method="post">
<select name="days">
<option value="2">2 {$lang->days}</option>
<option value="7">7 {$lang->days}</option>
<option value="30">30 {$lang->days}</option>
<option value="90">90 {$lang->days}</option>
<option value="all">* {$lang->dvz_sb_mod_clear_all} *</option>
</select>
<input type="hidden" name="postkey" value="{$mybb->post_code}" />
<input type="submit" class="button" value="{$lang->dvz_sb_mod_clear_button}" />
</form>
</td>
</tr>
</table>
<br />',
];
$data = [];
foreach ($templates as $name => $content) {
$data[] = [
'title' => $name,
'template' => $db->escape_string($content),
'sid' => -1,
'version' => 1,
'status' => '',
'dateline' => TIME_NOW,
];
}
$db->insert_query_multiple('templates', $data);
}
function dvz_shoutbox_uninstall()
{
global $db;
$settingGroupId = $db->fetch_field(
$db->simple_select('settinggroups', 'gid', "name='dvz_shoutbox'"),
'gid'
);
// delete settings
$db->delete_query('settinggroups', 'gid=' . $settingGroupId);
$db->delete_query('settings', 'gid=' . $settingGroupId);
rebuild_settings();
// delete templates
$db->delete_query('templates', "title IN('dvz_shoutbox', 'dvz_shoutbox_panel', 'dvz_shoutbox_archive', 'dvz_shoutbox_archive_modoptions')");
// delete data
$db->drop_table('dvz_shoutbox');
}
function dvz_shoutbox_is_installed()
{
global $mybb;
return $mybb->settings['dvz_sb_num'] !== null;
}
class dvz_shoutbox
{
// hooks
static function global_start()
{
global $mybb, $templatelist;
if (defined('THIS_SCRIPT') && THIS_SCRIPT == 'index.php' && self::access_view()) {
if (!empty($templatelist)) {
$templatelist .= ',';
}
if ($mybb->get_input('action') == 'shoutbox_archive') {
// archive templates
$templatelist .= 'dvz_shoutbox_archive,multipage,multipage_page,multipage_page_current,multipage_nextpage';
if (self::access_mod()) {
$templatelist .= ',dvz_shoutbox_archive_modoptions';
}
} else {
// index templates
$templatelist .= 'dvz_shoutbox,dvz_shoutbox_panel';
}
}
}
static function global_end()
{
global $mybb;
if ($mybb->get_input('action') == 'shoutbox_archive' && self::access_view()) {
return self::show_archive();
}
}
static function xmlhttp()
{
global $mybb, $db, $charset;
switch ($mybb->get_input('action')) {
case 'dvz_sb_get_updates':
$permissions = (
self::access_view() &&
self::access_refresh()
);
$handler = function () use ($mybb, $db) {
$syncConditions = $mybb->settings['dvz_sb_sync']
? "OR s.modified >= " . (time() - $mybb->settings['dvz_sb_interval']) . " AND s.id BETWEEN " . abs($mybb->get_input('first', MyBB::INPUT_INT)) . " AND " . abs($mybb->get_input('last', MyBB::INPUT_INT))
: null
;
$data = self::get_multiple("WHERE s.id > " . abs($mybb->get_input('last', MyBB::INPUT_INT)) . " AND s.text IS NOT NULL " . $syncConditions . " ORDER BY s.id DESC LIMIT " . abs((int)$mybb->settings['dvz_sb_num']));
$html = null; // JS-handled empty response
$sync = [];
$lastId = 0;
while ($row = $db->fetch_array($data)) {
if ($row['id'] <= $mybb->get_input('last', MyBB::INPUT_INT)) {
// sync update
$sync[ $row['id'] ] = $row['text'] === null
? null
: self::parse($row['text'], $row['username'])
;
} else {
// new shout
if ($lastId == 0) {
$lastId = $row['id'];
}
$shout = self::render_shout($row);
$html = $mybb->settings['dvz_sb_reversed']
? $shout . $html
: $html . $shout
;
}
}
if ($html != null || !empty($sync)) {
$response = [];
if ($html != null) {
$response['html'] = $html;
$response['last'] = $lastId;
}
if (!empty($sync)) {
$response['sync'] = $sync;
}
echo json_encode($response);
}
};
break;
case 'dvz_sb_recall':
$permissions = (
self::access_view() &&
self::access_refresh() &&
self::access_recall()
);
$handler = function () use ($mybb, $db) {
$data = self::get_multiple("WHERE s.id < " . abs($mybb->get_input('first', MyBB::INPUT_INT)) . " ORDER BY s.id DESC LIMIT " . abs((int)$mybb->settings['dvz_sb_num']));
$response = [];
$html = null; // JS-handled empty response
$firstId = 0;
while ($row = $db->fetch_array($data)) {
$firstId = $row['id'];
$shout = self::render_shout($row);
$html = $mybb->settings['dvz_sb_reversed']
? $shout . $html
: $html . $shout
;
}
if ($html != null) {
$response['html'] = $html;
}
if ($db->num_rows($data) < $mybb->settings['dvz_sb_num']) {
$response['end'] = 1;
}
if ($response) {
$response['first'] = $firstId;
}
echo json_encode($response);
};
break;
case 'dvz_sb_shout':
$permissions = (
self::access_shout() &&
verify_post_check($mybb->get_input('key'), true)
);
$handler = function () use ($mybb) {
// JS-handled error (Anti-flood)
if (!self::antiflood_pass() && !self::access_mod()) {
die('A');
}
self::shout([
'uid' => $mybb->user['uid'],
'text' => $mybb->get_input('text'),
'ipaddress' => my_inet_pton(get_ip()),
]);
};
break;
case 'dvz_sb_get':
$data = self::get($mybb->get_input('id', MyBB::INPUT_INT));
$permissions = (
(
self::access_mod() ||
(self::access_mod_own() && $data['uid'] == $mybb->user['uid'])
) &&
verify_post_check($mybb->get_input('key'), true)
);
$handler = function () use ($data) {
echo json_encode([
'text' => $data['text'],
]);
};
break;
case 'dvz_sb_update':
$permissions = (
self::can_mod($mybb->get_input('id', MyBB::INPUT_INT)) &&
verify_post_check($mybb->get_input('key'), true)
);
$handler = function () use ($mybb) {
self::update($mybb->get_input('id', MyBB::INPUT_INT), $mybb->get_input('text'));
echo self::parse($mybb->get_input('text'), self::get_username($mybb->get_input('id', MyBB::INPUT_INT)));
};
break;
case 'dvz_sb_delete':
$permissions = (
self::can_mod($mybb->get_input('id', MyBB::INPUT_INT)) &&
verify_post_check($mybb->get_input('key'), true)
);
$handler = function () use ($mybb) {
self::delete($mybb->get_input('id', MyBB::INPUT_INT));
};
break;
}
if (isset($permissions)) {
if ($permissions == false) {
echo 'P'; // JS-handled error (Permissions)
} else {
header('Content-type: text/plain; charset=' . $charset);
header('Cache-Control: no-store'); // force update on load
$handler();
}
}
}
static function load_window()
{
global $templates, $dvz_shoutbox, $lang, $mybb, $db, $theme;
$lang->load('dvz_shoutbox');
// MyBB template
$dvz_shoutbox = null;
// dvz_shoutbox template
$javascript = null;
$panel = null;
$classes = null;
if (self::access_view()) {
if (self::is_user()) {
// message: blocked
if (self::is_blocked()) {
$panel = '<div class="panel blocked"><p>' . $lang->dvz_sb_user_blocked . '</p></div>';
}
// message: minimum posts
else if (!self::access_minposts() && !self::access_mod()) {
$panel = '<div class="panel minposts"><p>' . str_replace('{MINPOSTS}', (int)$mybb->settings['dvz_sb_minposts'], $lang->dvz_sb_minposts) . '</p></div>';
}
// shout form
else if (self::access_shout()) {
$maxlength = $mybb->settings['dvz_sb_maxlength'] ? (int)$mybb->settings['dvz_sb_maxlength'] : null;
eval('$panel = "' . $templates->get('dvz_shoutbox_panel') . '";');
}
}
$js = null;
// configuration
$js .= 'dvz_shoutbox.interval = ' . (self::access_refresh() ? (float)$mybb->settings['dvz_sb_interval'] : 0) . ';' . PHP_EOL;
$js .= 'dvz_shoutbox.antiflood = ' . (self::access_mod() ? 0 : (float)$mybb->settings['dvz_sb_antiflood']) . ';' . PHP_EOL;
$js .= 'dvz_shoutbox.maxShouts = ' . (int)$mybb->settings['dvz_sb_num'] . ';' . PHP_EOL;
$js .= 'dvz_shoutbox.awayTime = ' . (float)$mybb->settings['dvz_sb_away'] . '*1000;' . PHP_EOL;
$js .= 'dvz_shoutbox.lang = [\'' . $lang->dvz_sb_delete_confirm . '\', \'' . str_replace('{ANTIFLOOD}', (float)$mybb->settings['dvz_sb_antiflood'], $lang->dvz_sb_antiflood) . '\', \''.$lang->dvz_sb_permissions.'\'];' . PHP_EOL;
// reversed order
if ($mybb->settings['dvz_sb_reversed']) {
$js .= 'dvz_shoutbox.reversed = true;' . PHP_EOL;
$js .= '$(\'#shoutbox .window\').scrollTop( $(\'#shoutbox .window\')[0].scrollHeight );' . PHP_EOL;
}
// lazyload
if ($mybb->settings['dvz_sb_lazyload']) {
$js .= 'dvz_shoutbox.lazyMode = \'' . (int)$mybb->settings['dvz_sb_lazyload'] . '\';' . PHP_EOL;
$js .= '$(window).bind(\'scroll resize\', dvz_shoutbox.checkVisibility);' . PHP_EOL;
}
// away mode
if ($mybb->settings['dvz_sb_away']) {
$js .= '$(window).on(\'mousemove click dblclick keydown scroll\', dvz_shoutbox.updateActivity);' . PHP_EOL;
}
// shoutbox status
$status = !isset($mybb->cookies['dvz_sb_status']) || $mybb->cookies['dvz_sb_status'] == 1;
$js .= 'dvz_shoutbox.status = ' . (int)$status . ';' . PHP_EOL;
if ($status == false) {
$classes .= ' collapsed';
}
$html = null;
$firstId = 0;
$lastId = 0;
if ($status == true) {
// preloaded shouts
$data = self::get_multiple("WHERE s.text IS NOT NULL ORDER BY s.id DESC LIMIT " . abs((int)$mybb->settings['dvz_sb_num']));
while ($row = $db->fetch_array($data)) {
$firstId = $row['id'];
if ($lastId == 0) {
$lastId = $row['id'];
}
$shout = self::render_shout($row);
$html = $mybb->settings['dvz_sb_reversed']
? $shout . $html
: $html . $shout
;
}
}
if (self::access_refresh()) {
$js .= 'setTimeout(\'dvz_shoutbox.loop()\', ' . (float)$mybb->settings['dvz_sb_interval'] . ' * 1000);' . PHP_EOL;
}
if (self::access_recall()) {
$js .= 'dvz_shoutbox.recalling = true;' . PHP_EOL;
}
$javascript = '
<script>
' . $js . '
dvz_shoutbox.firstId = ' . $firstId . ';
dvz_shoutbox.lastId = ' . $lastId . ';
dvz_shoutbox.appendControls();
dvz_shoutbox.updateActivity();
</script>';
eval('$dvz_shoutbox = "' . $templates->get('dvz_shoutbox') . '";');
}
}
static function show_archive()
{
global $db, $mybb, $templates, $lang, $theme, $footer, $headerinclude, $header, $charset;
$lang->load('dvz_shoutbox');
header('Content-type: text/html; charset=' . $charset);
add_breadcrumb($lang->dvz_sb_shoutbox, "index.php?action=shoutbox_archive");
// moderation panel
if (self::access_mod()) {
if ($mybb->get_input('banlist') && verify_post_check($mybb->get_input('postkey'))) {
self::banlist_update($mybb->get_input('banlist'));
}
if ($mybb->get_input('days') && verify_post_check($mybb->get_input('postkey'))) {
if ($mybb->get_input('days') == 'all') {
self::clear();
} else {
$allowed = [2, 7, 30, 90];
if (in_array($mybb->get_input('days'), $allowed)) {
self::clear($mybb->get_input('days'));
}
}
}
$blocked_users = htmlspecialchars_uni($mybb->settings['dvz_sb_blocked_users']);
eval('$modoptions = "' . $templates->get("dvz_shoutbox_archive_modoptions") . '";');
} else {
$modoptions = null;
}
// pagination
$items = self::count();
$page = abs($mybb->get_input('page', MyBB::INPUT_INT));
$perPage = abs((int)$mybb->settings['dvz_sb_num_archive']);
if ($perPage == 0) {
$pages = 0;
} else {
$pages = ceil($items / $perPage);
}
if (!$page || $page < 1 || $page > $pages) {
$page = 1;
}
$start = ($page - 1) * $perPage;
if ($items > $perPage) {
$multipage = multipage($items, $perPage, $page, 'index.php?action=shoutbox_archive');
}
$data = self::get_multiple("WHERE s.text IS NOT NULL ORDER by s.id DESC LIMIT $start,$perPage");
$archive = null;
while ($row = $db->fetch_array($data)) {
$archive .= self::render_shout($row, true);
}
$javascript = '
<script>
dvz_shoutbox.lang = [\'' . $lang->dvz_sb_delete_confirm . '\', \'' . str_replace('{ANTIFLOOD}', (float)$mybb->settings['dvz_sb_antiflood'], $lang->dvz_sb_antiflood) . '\', \'' . $lang->dvz_sb_permissions . '\'];
</script>';
eval('$content = "' . $templates->get("dvz_shoutbox_archive") . '";');
output_page($content);
exit;
}
static function user_merge()
{
global $db, $source_user, $destination_user;
return $db->update_query('dvz_shoutbox', ['uid' => $destination_user['uid']], 'uid=' . (int)$source_user['uid']);
}
static function activity(&$user_activity)
{
$location = parse_url($user_activity['location']);
$filename = basename($location['path']);
parse_str(html_entity_decode($location['query']), $parameters);
if ($filename == 'index.php' && $parameters['action'] == 'shoutbox_archive') {
$user_activity['activity'] = 'dvz_shoutbox_archive';
}
}
static function activity_translate(&$data)
{
global $lang;
$lang->load('dvz_shoutbox');
if ($data['user_activity']['activity'] == 'dvz_shoutbox_archive') {
$data['location_name'] = sprintf($lang->dvz_sb_activity, 'index.php?action=shoutbox_archive');
}
}
static function clearcookies()
{
global $remove_cookies;
$remove_cookies[] = 'dvz_sb_status';
}
// data manipulation
static function get($id)
{
global $db;
return $db->fetch_array( $db->simple_select('dvz_shoutbox', '*', 'id=' . (int)$id) );
}
static function get_multiple($clauses)
{
global $db;
return $db->query("
SELECT
s.*, u.username, u.usergroup, u.displaygroup, u.avatar
FROM
" . TABLE_PREFIX . "dvz_shoutbox s
LEFT JOIN " . TABLE_PREFIX . "users u ON u.uid = s.uid
" . $clauses . "
");
}
static function get_username($id)
{
global $db;
return $db->fetch_field(
$db->query("SELECT username FROM " . TABLE_PREFIX . "users u, " . TABLE_PREFIX . "dvz_shoutbox s WHERE u.uid=s.uid AND s.id=" . (int)$id),
'username'
);
}
static function user_last_shout_time($uid)
{
global $db;
return $db->fetch_field(
$db->simple_select('dvz_shoutbox', 'date', 'uid=' . (int)$uid, [
'order_by' => 'date',
'order_dir' => 'desc',
'limit' => 1,
]),
'date'
);
}
static function count()
{
global $db;
return $db->fetch_field(
$db->simple_select('dvz_shoutbox', 'COUNT(*) as n'),
'n'
);
}
static function shout($data)
{
global $mybb, $db;
if ($mybb->settings['dvz_sb_maxlength'] > 0) {
$data['text'] = mb_substr($data['text'], 0, $mybb->settings['dvz_sb_maxlength']);
}
foreach ($data as &$item) {
$item = $db->escape_string($item);
}
$data['date'] = TIME_NOW;
return $db->insert_query('dvz_shoutbox', $data);
}
static function update($id, $text)
{
global $db;
return $db->update_query('dvz_shoutbox', [
'text' => $db->escape_string($text),
'modified' => time(),
], 'id=' . (int)$id);
}
static function banlist_update($new)
{
global $db;
$db->update_query('settings', ['value' => $db->escape_string($new)], "name='dvz_sb_blocked_users'");
rebuild_settings();
}
static function delete($id)
{
global $mybb, $db;
if ($mybb->settings['dvz_sb_sync']) {
return $db->update_query('dvz_shoutbox', [
'text' => 'NULL',
'modified' => time(),
], 'id=' . (int)$id, false, true);
} else {
return $db->delete_query('dvz_shoutbox', 'id=' . (int)$id);
}
}
static function clear($days = false)
{
global $db;
if ($days) {
$where = 'date < ' . ( TIME_NOW - ((int)$days * 86400) );
} else {
$where = false;
}
return $db->delete_query('dvz_shoutbox', $where);
}
// permissions
static function is_user()
{
global $mybb;
return $mybb->user['uid'] != 0;
}
static function is_blocked()
{
global $mybb;
return in_array($mybb->user['uid'], self::settings_get_csv('blocked_users'));
}
static function access_view()
{
$array = self::settings_get_csv('groups_view');
return $array[0] == -1 || is_member($array);
}
static function access_refresh()
{
$array = self::settings_get_csv('groups_refresh');
return $array[0] == -1 || is_member($array);
}
static function access_shout()
{
$array = self::settings_get_csv('groups_shout');
return (
self::is_user() &&
!self::is_blocked() &&
(
self::access_mod() ||
(
self::access_view() &&
self::access_minposts() &&
$array[0] == -1 || is_member($array)
)
)
);
}
static function access_recall()
{
$array = self::settings_get_csv('groups_recall');
return $array[0] == -1 || is_member($array);
}
static function access_mod()
{
global $mybb;
$array = self::settings_get_csv('groups_mod');
return (
($array[0] == -1 || is_member($array)) ||
($mybb->settings['dvz_sb_supermods'] && $mybb->usergroup['issupermod'])
);
}
static function access_mod_own()
{
$array = self::settings_get_csv('groups_mod_own');
return $array[0] == -1 || is_member($array);
}
static function access_minposts()
{
global $mybb;
return $mybb->user['postnum'] >= $mybb->settings['dvz_sb_minposts'];
}
static function can_mod($shoutId)
{
global $mybb;
if (self::access_mod()) {
return true;
} else if (self::access_mod_own() && self::access_shout()) {
$data = self::get($shoutId);
if ($data['uid'] == $mybb->user['uid']) {
return true;
}
}
return false;
}
// core
static function render_shout($data, $static = false)
{
global $mybb;
$id = $data['id'];
$text = self::parse($data['text'], $data['username']);
$date = htmlspecialchars_uni(my_date($mybb->settings['dvz_sb_dateformat'], $data['date']));
$username = htmlspecialchars_uni($data['username']);
$user = build_profile_link(format_name($username, $data['usergroup'], $data['displaygroup']), (int)$data['uid']);
$avatar = '<img src="' . (empty($data['avatar']) ? htmlspecialchars_uni($mybb->settings['useravatar']) : htmlspecialchars_uni($data['avatar'])) . '" alt="avatar" />';
$notes = null;
$attributes = null;
$own = $data['uid'] == $mybb->user['uid'];
if ($static) {
if (self::access_mod()) {
$notes .= '<span class="ip">' . my_inet_ntop($data['ipaddress']) . '</span>';
}
if (
self::access_mod() ||
(self::access_mod_own() && $own)
) {
$notes .= '<a href="" class="mod edit">E</a><a href="" class="mod del">X</a>';
}
}
if (
self::access_mod() ||
(self::access_mod_own() && $own)
) {
$attributes .= ' data-mod';
}
if ($own) {
$attributes .= ' data-own';
}
return '
<div class="entry" data-id="' . $id . '" data-username="' . $username . '"' . $attributes . '>
<div class="avatar">' . $avatar . '</div>
<div class="user">' . $user . '</div>
<div class="text">' . $text . '</div>
<div class="info">' . $notes . '<span class="date">' . $date . '</span></div>
</div>';
}
static function parse($message, $me_username)
{
global $mybb;
require_once MYBB_ROOT . 'inc/class_parser.php';
$parser = new postParser;
$options = [
'allow_mycode' => $mybb->settings['dvz_sb_mycode'],
'allow_smilies' => $mybb->settings['dvz_sb_smilies'],
'allow_imgcode' => 0,
'filter_badwords' => 1,
'me_username' => $me_username,
];
return $parser->parse_message($message, $options);
}
static function antiflood_pass()
{
global $mybb;
return (
!$mybb->settings['dvz_sb_antiflood'] ||
( TIME_NOW - self::user_last_shout_time($mybb->user['uid']) ) > $mybb->settings['dvz_sb_antiflood']
);
}
static function settings_get_csv($name)
{
global $mybb;
return array_filter( explode(',', $mybb->settings['dvz_sb_' . $name]) );
}
}
(14.08.2016, 20:27)tadek22 napisał(a): chodzi o to żeby nie było @
/* DVZ Shoutbox by Tomasz 'Devilshakerz' Mlynski [devilshakerz.com]; Copyright (C) 2014-2015 */
var dvz_shoutbox = {
// defaults
interval: 5,
antiflood: 0,
maxShouts: 20,
awayTime: 600000,
lazyMode: false,
lazyMargin: 0,
callSign: 'b',
lang: [],
status: true,
reversed: false,
callbacks: {
'toggle': [],
'update': [],
'recall': [],
'entries': [],
'shout': [],
'edit': [],
'delete': [],
'call': [],
},
// runtime
recalling: false,
timeout: false,
holdTimeout: false,
frozen: false,
updating: false,
started: false,
lastSent: 0,
firstId: 0,
lastId: 0,
activity: 0,
loop: function (forced) {
if (forced == true) {
clearTimeout(dvz_shoutbox.timeout);
} else {
if (dvz_shoutbox.isAway()) {
dvz_shoutbox.toggle(false, false);
dvz_shoutbox.frozen = true;
return false;
}
if (!dvz_shoutbox.lazyLoad()) {
dvz_shoutbox.frozen = true;
return false;
}
if (dvz_shoutbox.status == false) {
dvz_shoutbox.frozen = true;
return false;
}
}
dvz_shoutbox.update(function(){
dvz_shoutbox.started = true;
// next request
if (dvz_shoutbox.interval) {
dvz_shoutbox.timeout = setTimeout('dvz_shoutbox.loop()', dvz_shoutbox.interval * 1000);
}
});
},
// actions
update: function (callback) {
if (dvz_shoutbox.updating) {
return false;
} else {
dvz_shoutbox.updating = true;
}
$.get(
'xmlhttp.php',
{ action: 'dvz_sb_get_updates', first: dvz_shoutbox.firstId, last: dvz_shoutbox.lastId },
function(data) {
if (dvz_shoutbox.handleErrors(data)) {
return false;
}
if (data) {
var data = $.parseJSON(data);
// new shouts
if (data.html) {
// insert new shouts
if (dvz_shoutbox.reversed) {
var scrollMax = $('#shoutbox .data').innerHeight() - $('#shoutbox .window').innerHeight(),
scroll = $('#shoutbox .window').scrollTop();
$('#shoutbox .data').append( $(data.html).fadeIn(function(){
// scroll to bottom again
if (!dvz_shoutbox.started || scroll >= scrollMax) {
$('#shoutbox .window').scrollTop( $('#shoutbox .window')[0].scrollHeight );
}
}) );
} else {
$('#shoutbox .data').prepend( $(data.html).hide().fadeIn() );
}
// remove old shouts to fit the limit
var old = $('#shoutbox .entry').length - dvz_shoutbox.maxShouts;
if (old > 0) {
$('#shoutbox .entry:nth'+(dvz_shoutbox.reversed ? '' : '-last')+'-child(-n+'+old+')').remove();
}
// mark new shouts
if (dvz_shoutbox.started) {
$('#shoutbox .entry').filter(function(){
return parseInt($(this).attr('data-id')) > dvz_shoutbox.lastId && $(this).not('[data-own]').length;
}).addClass('new');
setTimeout("$('#shoutbox .entry.new').removeClass('new')", 1000);
}
dvz_shoutbox.lastId = data.last;
dvz_shoutbox.appendControls();
}
// sync updates
if (data.sync) {
for (var i in data.sync) {
var entry = $('#shoutbox .entry[data-id='+i+']');
if (data.sync[i] === null) {
entry.fadeOut(function(){
$(this).remove();
});
} else {
entry.children('.text').html(data.sync[i]);
}
}
}
}
dvz_shoutbox.updating = false;
dvz_shoutbox.runCallbacks('update');
if (typeof(callback) == 'function') {
callback();
}
}
);
},
recall: function () {
$.get(
'xmlhttp.php',
{ action: 'dvz_sb_recall', first: dvz_shoutbox.firstId },
function(data) {
if (dvz_shoutbox.handleErrors(data)) {
return false;
}
if (data) {
var data = $.parseJSON(data);
// insert new shouts
if (dvz_shoutbox.reversed) {
$('#shoutbox .data').prepend( $(data.html) );
} else {
$('#shoutbox .data').append( $(data.html) );
}
// extend the limit
dvz_shoutbox.maxShouts = $('#shoutbox .entry').length;
dvz_shoutbox.firstId = data.first;
dvz_shoutbox.appendControls();
if (data.end) {
dvz_shoutbox.recalling = false;
}
}
dvz_shoutbox.runCallbacks('recall');
}
);
},
shout: function() {
var message = $('#shoutbox input.text').val();
if ($.trim(message) == '') {
return false;
}
if (!dvz_shoutbox.antifloodPass()) {
dvz_shoutbox.handleErrors('A');
return false;
}
dvz_shoutbox.toggleForm(false);
$.post(
'xmlhttp.php',
{ action: 'dvz_sb_shout', text: message, key: my_post_key },
function(data) {
if (!dvz_shoutbox.handleErrors(data)) {
dvz_shoutbox.lastSent = Math.floor((new Date).getTime() / 1000);
dvz_shoutbox.clearForm();
dvz_shoutbox.loop(true);
dvz_shoutbox.runCallbacks('shout', { message: message });
}
dvz_shoutbox.toggleForm(true);
}
);
},
edit: function (id) {
// text request
$.get(
'xmlhttp.php',
{ action: 'dvz_sb_get', id: id, key: my_post_key },
function(data){
if (dvz_shoutbox.handleErrors(data)) {
return false;
}
var data = $.parseJSON(data),
newText = prompt('Shout #'+id+':', data.text);
if (newText && newText != data.text) {
// update request
$.post(
'xmlhttp.php',
{ action: 'dvz_sb_update', text: newText, id: id, key: my_post_key },
function(data) {
if (!dvz_shoutbox.handleErrors(data)) {
$('#shoutbox .entry[data-id="'+id+'"] .text').html(data);
dvz_shoutbox.runCallbacks('edit', { id: id, text: data });
}
}
);
}
}
);
},
delete: function (id, noConfirm) {
if (noConfirm || confirm(dvz_shoutbox.lang[0])) {
$.post(
'xmlhttp.php',
{ action: 'dvz_sb_delete', id: id, key: my_post_key },
function(data) {
if (!dvz_shoutbox.handleErrors(data)) {
$('#shoutbox .entry[data-id="'+id+'"]').fadeOut(function(){ $(this).remove() });
dvz_shoutbox.runCallbacks('delete', { id: id });
}
}
);
}
},
// functionality
toggle: function (status, remember) {
if (status == true) {
dvz_shoutbox.status = true;
$('#shoutbox').removeClass('collapsed');
$('#shoutbox .body').fadeIn();
if (dvz_shoutbox.frozen || !dvz_shoutbox.started) {
dvz_shoutbox.frozen = false;
dvz_shoutbox.loop();
}
} else {
dvz_shoutbox.status = false;
$('#shoutbox .body').stop(1).fadeOut(function(){
if (dvz_shoutbox.status == false) $('#shoutbox').stop(1).addClass('collapsed');
});
}
if (remember !== false) {
document.cookie = cookiePrefix+'dvz_sb_status='+(+status)+'; path='+cookiePath+'; max-age=31536000';
}
dvz_shoutbox.runCallbacks('toggle', { status: status });
},
// core
antifloodPass: function() {
var time = Math.floor((new Date).getTime() / 1000);
return (time - dvz_shoutbox.lastSent) >= dvz_shoutbox.antiflood;
},
updateActivity: function () {
dvz_shoutbox.activity = (new Date).getTime();
},
isAway: function () {
if (!dvz_shoutbox.awayTime) return false;
return (new Date).getTime() - dvz_shoutbox.activity > dvz_shoutbox.awayTime;
},
onDisplay: function () {
var viewTop = $(document).scrollTop(),
viewBottom = viewTop + $(window).height(),
elementTop = $('#shoutbox').offset().top,
elementBottom = elementTop + $('#shoutbox').height();
return elementBottom >= (viewTop - dvz_shoutbox.lazyMargin) && elementTop <= (viewBottom + dvz_shoutbox.lazyMargin);
},
checkVisibility: function () {
if (dvz_shoutbox.frozen && dvz_shoutbox.onDisplay()) {
dvz_shoutbox.frozen = false;
dvz_shoutbox.loop();
}
},
lazyLoad: function () {
if (dvz_shoutbox.lazyMode && !dvz_shoutbox.onDisplay()) {
if (
dvz_shoutbox.lazyMode == 'start' && !dvz_shoutbox.started ||
dvz_shoutbox.lazyMode == 'always'
) {
return false;
}
}
return true;
},
handleErrors: function (response) {
if (response == 'A') {
alert(dvz_shoutbox.lang[1]);
return true;
} else
if (response == 'P') {
alert(dvz_shoutbox.lang[2]);
return true;
}
if (response == 'S') {
dvz_shoutbox.toggle(false);
return true;
}
return false;
},
runCallbacks: function (name, data) {
if (dvz_shoutbox.callbacks[name]) {
for (var i in dvz_shoutbox.callbacks[name]) {
dvz_shoutbox.callbacks[name][i](data);
}
}
},
// visual
call: function (username) {
var $input = $('#shoutbox input.text'),
words = $input.val().split(' '),
appendix = username;
// enclose in quotes if needed
if (username.match( /["'`\.:\-+=~@#$%^*!?()\[\]{}\s]+/g )) {
var quotes = ['"', "'", '`'];
for (var i in quotes) {
if (username.indexOf(quotes[i]) == -1) {
appendix = quotes[i] + username + quotes[i];
break;
}
}
}
// add a call sign
appendix = dvz_shoutbox.callSign + appendix;
// add a leading space if suitable
if ($input.val() != '' && $input.val().slice(-1) != ' ') {
appendix = ' ' + appendix;
}
// add a trailing space if suitable
for (var i in words) {
if (words[i] != '' && words[i].slice(0,1) != dvz_shoutbox.callSign) {
break;
}
if (i == words.length-1) {
appendix = appendix + ' ';
}
}
$('#shoutbox input.text').focus();
$('#shoutbox input.text').val($input.val() + appendix);
$('#shoutbox input.text').focus();
dvz_shoutbox.runCallbacks('call', { username: username });
},
toggleForm: function (status) {
if (status == false) {
$("#shoutbox input.text").attr('disabled', 'disabled');
} else {
$("#shoutbox input.text").removeAttr('disabled');
$("#shoutbox input.text").focus();
}
},
clearForm: function () {
$('#shoutbox input.text').val('');
},
appendControls: function () {
dvz_shoutbox.runCallbacks('entries');
$('#shoutbox .entry:not([parsed])').each(function(){
if (typeof $(this).attr('data-mod') !== 'undefined') {
$(this).children('.info').prepend('<a href="" class="mod edit">E</a><a href="" class="mod del">X</a>');
}
$(this).attr('parsed', '');
});
},
};
$(document).on('click', '#shoutbox .head', function() {
dvz_shoutbox.toggle(!dvz_shoutbox.status);
});
$(document).on('click', '#shoutbox .head a', function(e){
e.stopPropagation();
});
$(document).on('click', '#shoutbox .entry .avatar', function() {
dvz_shoutbox.call( $(this).parents('.entry').attr('data-username') );
return false;
});
$(document).on('click', '#shoutbox .entry .mod.edit', function() {
dvz_shoutbox.edit( $(this).parents('.entry').attr('data-id') );
return false;
});
$(document).on('mousedown', '#shoutbox .entry[data-mod] .text', function() {
dvz_shoutbox.holdTimeout = setTimeout($.proxy(function() {
dvz_shoutbox.edit( $(this).parents('.entry').attr('data-id') );
}, this), 500);
}).bind('mouseup mouseleave', function() {
clearTimeout(dvz_shoutbox.holdTimeout);
});
$(document).on('click', function(e) {
if (e.which == 2 && $(e.target).is('#shoutbox .entry .mod.del')) {
dvz_shoutbox.delete( $(e.target).parents('.entry').attr('data-id'), true );
e.preventDefault();
}
});
$(document).on('click', '#shoutbox .entry .mod.del', function() {
dvz_shoutbox.delete( $(this).parents('.entry').attr('data-id') );
return false;
});
$('#shoutbox .window').scroll(function() {
if (dvz_shoutbox.recalling && $('#shoutbox .entry').length == dvz_shoutbox.maxShouts) {
var scrollMax = $('#shoutbox .data').innerHeight() - $('#shoutbox .window').innerHeight(),
scroll = $('#shoutbox .window').scrollTop();
if (
!dvz_shoutbox.reversed && scroll >= scrollMax ||
dvz_shoutbox.reversed && scroll == 0
) {
dvz_shoutbox.recall();
}
}
});
$(document).on('submit', '#shoutbox .panel form', function() {
dvz_shoutbox.shout();
return false;
});
/* DVZ Shoutbox by Tomasz 'Devilshakerz' Mlynski [devilshakerz.com]; Copyright (C) 2014-2015 */
var dvz_shoutbox = {
// defaults
interval: 5,
antiflood: 0,
maxShouts: 20,
awayTime: 600000,
lazyMode: false,
lazyMargin: 0,
callSign: '@',
lang: [],
status: true,
reversed: false,
callbacks: {
'toggle': [],
'update': [],
'recall': [],
'entries': [],
'shout': [],
'edit': [],
'delete': [],
'call': [],
},
// runtime
recalling: false,
timeout: false,
holdTimeout: false,
frozen: false,
updating: false,
started: false,
lastSent: 0,
firstId: 0,
lastId: 0,
activity: 0,
loop: function (forced) {
if (forced == true) {
clearTimeout(dvz_shoutbox.timeout);
} else {
if (dvz_shoutbox.isAway()) {
dvz_shoutbox.toggle(false, false);
dvz_shoutbox.frozen = true;
return false;
}
if (!dvz_shoutbox.lazyLoad()) {
dvz_shoutbox.frozen = true;
return false;
}
if (dvz_shoutbox.status == false) {
dvz_shoutbox.frozen = true;
return false;
}
}
dvz_shoutbox.update(function(){
dvz_shoutbox.started = true;
// next request
if (dvz_shoutbox.interval) {
dvz_shoutbox.timeout = setTimeout('dvz_shoutbox.loop()', dvz_shoutbox.interval * 1000);
}
});
},
// actions
update: function (callback) {
if (dvz_shoutbox.updating) {
return false;
} else {
dvz_shoutbox.updating = true;
}
$.get(
'xmlhttp.php',
{ action: 'dvz_sb_get_updates', first: dvz_shoutbox.firstId, last: dvz_shoutbox.lastId },
function(data) {
if (dvz_shoutbox.handleErrors(data)) {
return false;
}
if (data) {
var data = $.parseJSON(data);
// new shouts
if (data.html) {
// insert new shouts
if (dvz_shoutbox.reversed) {
var scrollMax = $('#shoutbox .data').innerHeight() - $('#shoutbox .window').innerHeight(),
scroll = $('#shoutbox .window').scrollTop();
$('#shoutbox .data').append( $(data.html).fadeIn(function(){
// scroll to bottom again
if (!dvz_shoutbox.started || scroll >= scrollMax) {
$('#shoutbox .window').scrollTop( $('#shoutbox .window')[0].scrollHeight );
}
}) );
} else {
$('#shoutbox .data').prepend( $(data.html).hide().fadeIn() );
}
// remove old shouts to fit the limit
var old = $('#shoutbox .entry').length - dvz_shoutbox.maxShouts;
if (old > 0) {
$('#shoutbox .entry:nth'+(dvz_shoutbox.reversed ? '' : '-last')+'-child(-n+'+old+')').remove();
}
// mark new shouts
if (dvz_shoutbox.started) {
$('#shoutbox .entry').filter(function(){
return parseInt($(this).attr('data-id')) > dvz_shoutbox.lastId && $(this).not('[data-own]').length;
}).addClass('new');
setTimeout("$('#shoutbox .entry.new').removeClass('new')", 1000);
}
dvz_shoutbox.lastId = data.last;
dvz_shoutbox.appendControls();
}
// sync updates
if (data.sync) {
for (var i in data.sync) {
var entry = $('#shoutbox .entry[data-id='+i+']');
if (data.sync[i] === null) {
entry.fadeOut(function(){
$(this).remove();
});
} else {
entry.children('.text').html(data.sync[i]);
}
}
}
}
dvz_shoutbox.updating = false;
dvz_shoutbox.runCallbacks('update');
if (typeof(callback) == 'function') {
callback();
}
}
);
},
recall: function () {
$.get(
'xmlhttp.php',
{ action: 'dvz_sb_recall', first: dvz_shoutbox.firstId },
function(data) {
if (dvz_shoutbox.handleErrors(data)) {
return false;
}
if (data) {
var data = $.parseJSON(data);
// insert new shouts
if (dvz_shoutbox.reversed) {
$('#shoutbox .data').prepend( $(data.html) );
} else {
$('#shoutbox .data').append( $(data.html) );
}
// extend the limit
dvz_shoutbox.maxShouts = $('#shoutbox .entry').length;
dvz_shoutbox.firstId = data.first;
dvz_shoutbox.appendControls();
if (data.end) {
dvz_shoutbox.recalling = false;
}
}
dvz_shoutbox.runCallbacks('recall');
}
);
},
shout: function() {
var message = $('#shoutbox input.text').val();
if ($.trim(message) == '') {
return false;
}
if (!dvz_shoutbox.antifloodPass()) {
dvz_shoutbox.handleErrors('A');
return false;
}
dvz_shoutbox.toggleForm(false);
$.post(
'xmlhttp.php',
{ action: 'dvz_sb_shout', text: message, key: my_post_key },
function(data) {
if (!dvz_shoutbox.handleErrors(data)) {
dvz_shoutbox.lastSent = Math.floor((new Date).getTime() / 1000);
dvz_shoutbox.clearForm();
dvz_shoutbox.loop(true);
dvz_shoutbox.runCallbacks('shout', { message: message });
}
dvz_shoutbox.toggleForm(true);
}
);
},
edit: function (id) {
// text request
$.get(
'xmlhttp.php',
{ action: 'dvz_sb_get', id: id, key: my_post_key },
function(data){
if (dvz_shoutbox.handleErrors(data)) {
return false;
}
var data = $.parseJSON(data),
newText = prompt('Shout #'+id+':', data.text);
if (newText && newText != data.text) {
// update request
$.post(
'xmlhttp.php',
{ action: 'dvz_sb_update', text: newText, id: id, key: my_post_key },
function(data) {
if (!dvz_shoutbox.handleErrors(data)) {
$('#shoutbox .entry[data-id="'+id+'"] .text').html(data);
dvz_shoutbox.runCallbacks('edit', { id: id, text: data });
}
}
);
}
}
);
},
delete: function (id, noConfirm) {
if (noConfirm || confirm(dvz_shoutbox.lang[0])) {
$.post(
'xmlhttp.php',
{ action: 'dvz_sb_delete', id: id, key: my_post_key },
function(data) {
if (!dvz_shoutbox.handleErrors(data)) {
$('#shoutbox .entry[data-id="'+id+'"]').fadeOut(function(){ $(this).remove() });
dvz_shoutbox.runCallbacks('delete', { id: id });
}
}
);
}
},
// functionality
toggle: function (status, remember) {
if (status == true) {
dvz_shoutbox.status = true;
$('#shoutbox').removeClass('collapsed');
$('#shoutbox .body').fadeIn();
if (dvz_shoutbox.frozen || !dvz_shoutbox.started) {
dvz_shoutbox.frozen = false;
dvz_shoutbox.loop();
}
} else {
dvz_shoutbox.status = false;
$('#shoutbox .body').stop(1).fadeOut(function(){
if (dvz_shoutbox.status == false) $('#shoutbox').stop(1).addClass('collapsed');
});
}
if (remember !== false) {
document.cookie = cookiePrefix+'dvz_sb_status='+(+status)+'; path='+cookiePath+'; max-age=31536000';
}
dvz_shoutbox.runCallbacks('toggle', { status: status });
},
// core
antifloodPass: function() {
var time = Math.floor((new Date).getTime() / 1000);
return (time - dvz_shoutbox.lastSent) >= dvz_shoutbox.antiflood;
},
updateActivity: function () {
dvz_shoutbox.activity = (new Date).getTime();
},
isAway: function () {
if (!dvz_shoutbox.awayTime) return false;
return (new Date).getTime() - dvz_shoutbox.activity > dvz_shoutbox.awayTime;
},
onDisplay: function () {
var viewTop = $(document).scrollTop(),
viewBottom = viewTop + $(window).height(),
elementTop = $('#shoutbox').offset().top,
elementBottom = elementTop + $('#shoutbox').height();
return elementBottom >= (viewTop - dvz_shoutbox.lazyMargin) && elementTop <= (viewBottom + dvz_shoutbox.lazyMargin);
},
checkVisibility: function () {
if (dvz_shoutbox.frozen && dvz_shoutbox.onDisplay()) {
dvz_shoutbox.frozen = false;
dvz_shoutbox.loop();
}
},
lazyLoad: function () {
if (dvz_shoutbox.lazyMode && !dvz_shoutbox.onDisplay()) {
if (
dvz_shoutbox.lazyMode == 'start' && !dvz_shoutbox.started ||
dvz_shoutbox.lazyMode == 'always'
) {
return false;
}
}
return true;
},
handleErrors: function (response) {
if (response == 'A') {
alert(dvz_shoutbox.lang[1]);
return true;
} else
if (response == 'P') {
alert(dvz_shoutbox.lang[2]);
return true;
}
if (response == 'S') {
dvz_shoutbox.toggle(false);
return true;
}
return false;
},
runCallbacks: function (name, data) {
if (dvz_shoutbox.callbacks[name]) {
for (var i in dvz_shoutbox.callbacks[name]) {
dvz_shoutbox.callbacks[name][i](data);
}
}
},
// visual
call: function (username) {
var $input = $('#shoutbox input.text'),
words = $input.val().split(' '),
appendix = username;
// enclose in quotes if needed
if (username.match( /["'`\.:\-+=~@#$%^*!?()\[\]{}\s]+/g )) {
var quotes = ['"', "'", '`'];
for (var i in quotes) {
if (username.indexOf(quotes[i]) == -1) {
appendix = quotes[i] + username + quotes[i];
break;
}
}
}
// add a call sign
appendix = dvz_shoutbox.callSign + appendix;
// add a leading space if suitable
if ($input.val() != '' && $input.val().slice(-1) != ' ') {
appendix = ' ' + appendix;
}
// add a trailing space if suitable
for (var i in words) {
if (words[i] != '' && words[i].slice(0,1) != dvz_shoutbox.callSign) {
break;
}
if (i == words.length-1) {
appendix = appendix + ' ';
}
}
$('#shoutbox input.text').focus();
$('#shoutbox input.text').val($input.val() + appendix);
$('#shoutbox input.text').focus();
dvz_shoutbox.runCallbacks('call', { username: username });
},
toggleForm: function (status) {
if (status == false) {
$("#shoutbox input.text").attr('disabled', 'disabled');
} else {
$("#shoutbox input.text").removeAttr('disabled');
$("#shoutbox input.text").focus();
}
},
clearForm: function () {
$('#shoutbox input.text').val('');
},
appendControls: function () {
dvz_shoutbox.runCallbacks('entries');
$('#shoutbox .entry:not([parsed])').each(function(){
if (typeof $(this).attr('data-mod') !== 'undefined') {
$(this).children('.info').prepend('<a href="" class="mod edit">E</a><a href="" class="mod del">X</a>');
}
$(this).attr('parsed', '');
});
},
};
$(document).on('click', '#shoutbox .head', function() {
dvz_shoutbox.toggle(!dvz_shoutbox.status);
});
$(document).on('click', '#shoutbox .head a', function(e){
e.stopPropagation();
});
$(document).on('click', '#shoutbox .entry .avatar', function() {
dvz_shoutbox.call('[b]'+ $(this).parents('.entry').attr('data-username') +'[/b]');
return false;
});
$(document).on('click', '#shoutbox .entry .mod.edit', function() {
dvz_shoutbox.edit( $(this).parents('.entry').attr('data-id') );
return false;
});
$(document).on('mousedown', '#shoutbox .entry[data-mod] .text', function() {
dvz_shoutbox.holdTimeout = setTimeout($.proxy(function() {
dvz_shoutbox.edit( $(this).parents('.entry').attr('data-id') );
}, this), 500);
}).bind('mouseup mouseleave', function() {
clearTimeout(dvz_shoutbox.holdTimeout);
});
$(document).on('click', function(e) {
if (e.which == 2 && $(e.target).is('#shoutbox .entry .mod.del')) {
dvz_shoutbox.delete( $(e.target).parents('.entry').attr('data-id'), true );
e.preventDefault();
}
});
$(document).on('click', '#shoutbox .entry .mod.del', function() {
dvz_shoutbox.delete( $(this).parents('.entry').attr('data-id') );
return false;
});
$('#shoutbox .window').scroll(function() {
if (dvz_shoutbox.recalling && $('#shoutbox .entry').length == dvz_shoutbox.maxShouts) {
var scrollMax = $('#shoutbox .data').innerHeight() - $('#shoutbox .window').innerHeight(),
scroll = $('#shoutbox .window').scrollTop();
if (
!dvz_shoutbox.reversed && scroll >= scrollMax ||
dvz_shoutbox.reversed && scroll == 0
) {
dvz_shoutbox.recall();
}
}
});
$(document).on('click', '#shoutbox .entry .avatar', function() {
dvz_shoutbox.call('[b]'+ $(this).parents('.entry').attr('data-username')+'[/b]' );
return false;
});
$('#shoutbox input.text').val($input.val() + appendix);
3 gości