Файл: style/themes/justweb/functions.php
Строк: 252
<?php
define('THEME_VERSION', mt_rand(1, 999999999999999));
define('LANGUAGE_DOMAIN', 'justweb');
require dirname(__FILE__) . '/includes/template-functions.php';
add_event('init_head_theme', 'justweb_styles_init');
function justweb_styles_init()
{
ds_theme_style_add('https://fonts.googleapis.com/css?family=Roboto', 'justweb-fonts', '', 'all');
ds_theme_style_add(get_theme_uri() . '/css/icons.css', 'justweb-icons', THEME_VERSION, 'all');
ds_theme_style_add(get_theme_uri() . '/icons/flaticon.css', 'justweb-flaticon', THEME_VERSION, 'all');
ds_theme_style_add(get_theme_uri() . '/css/audio-player.css', 'justweb-audio-player', THEME_VERSION, 'all');
ds_theme_style_add(get_theme_uri() . '/css/nprogress.css', 'justweb-nprogress', THEME_VERSION, 'all');
}
add_event('ds_theme_scripts_init', 'justweb_add_scripts');
function justweb_add_scripts() {
ds_theme_script_add(get_theme_uri() . '/js/nprogress.min.js', 'justweb-nprogress', THEME_VERSION);
ds_theme_script_add(get_theme_uri() . '/js/jquery.ajaxpage.js', 'justweb-ajaxpage', THEME_VERSION);
ds_theme_script_add(get_theme_uri() . '/js/main.js', 'justweb-main', THEME_VERSION);
}
add_event('ds_pre_redirect', 'ds_ajax_redirect');
function ds_ajax_redirect($url, $status)
{
if (is_ajax()) {
die('<div id="ajax-meta" style="display: none;" data-redirect="' . $url . '" data-title="" data-body=""></div>');
}
}
add_filter('ds_files_file_mask_list_item', 'justweb_files_list_mask_file', 10, 2);
function justweb_files_list_mask_file($mask, $file)
{
if (strpos($file['mimetype'], 'audio') !== false) {
$mask['%after_item%'] = '<div class="list-item-player">' . get_audio_player($file) . '</div>';
}
return $mask;
}
function justweb_users_online()
{
$counters = ds_get('justweb_counters', array());
if (!isset($counters['users_online'])) {
$counters['users_online'] = db::count("SELECT COUNT(*) FROM `user` WHERE `date_last` > " . ( time() - 600 ) . "");
ds_set('justweb_counters', $counters);
}
return $counters['users_online'];
}
add_filter('ds_events_counters_ajax', function($data) {
return get_user_counters();
});
add_filter('ds_events_playlist_ajax', function($data) {
$query = new DB_Files(array(
'p_str' => 30,
'file_type' => 'music',
'user_id' => get_user_id(),
));
$music = array();
if ($query->total) {
foreach($query->files AS $key => $file) {
$download_url = get_file_download_url($file);
$music[] = array(
'id' => $file['id'],
'title' => text($file['title']),
'url' => get_file_link($file),
'src' => $download_url,
'hash' => md5($download_url),
'uniquie' => md5($download_url . mt_rand(1, 9999999)),
'thumbnail' => get_file_thumbnail_url($file, 'thumbnail'),
);
}
}
return array(
'title' => 'Моя музыка',
'list' => $music,
);
});
add_filter('ds_events_mail_ajax', function($data) {
$user = get_user();
$ajax = array();
$contact_id = (int) $data['contact_id'];
$first_id = (int) $data['first_id'];
$last_id = (int) $data['last_id'];
$toread = (int) $data['toread'];
$previus = (int) $data['previus'];
if ($toread) {
update_mail_read($contact_id, $user['id']);
$toread = -1;
}
$unread = db::count("SELECT COUNT(id) FROM `mail` WHERE `user_id` = '" . $user['id'] . "' AND `contact_id` = '" . $contact_id . "' AND `read` = '0'");
$lastCount = db::count("SELECT COUNT(id) FROM `mail` WHERE `contact_id` = '" . $user['id'] . "' AND `user_id` = '" . $contact_id . "' AND `read` = '0' AND `id` > '" . $last_id . "'");
$messages = array();
if ($lastCount) {
$q = db::query("SELECT * FROM mail WHERE `contact_id` = '" . $user['id'] . "' AND `user_id` = '" . $contact_id . "' AND `read` = '0' AND `id` > '" . $last_id . "'");
while($post = $q->fetch_assoc()) {
$messages[] = justweb_template_message($post);
if ($post['id'] > $last_id) {
$last_id = $post['id'];
}
}
}
$json = array(
'toread' => $toread,
'unread' => $unread,
'first_id' => $first_id,
'last_id' => $last_id,
'messages' => $messages,
'prev' => array(),
);
if ($previus == 1) {
$q = db::query("SELECT * FROM mail WHERE (`contact_id` = '" . $user['id'] . "' AND `user_id` = '" . $contact_id . "' OR `contact_id` = '" . $contact_id . "' AND `user_id` = '" . $user['id'] . "') AND `id` < '" . $first_id . "' ORDER BY id DESC LIMIT 10");
while($post = $q->fetch_assoc()) {
array_push($json['prev'], justweb_template_message($post));
if ($post['id'] < $json['first_id']) {
$json['first_id'] = (int) $post['id'];
}
}
}
return $json;
});
add_filter('ds_events_comments_ajax', function($data) {
$array = array();
foreach($data AS $key => $elem) {
$attr = explode(':', base64_decode($elem['hash']));
$comment_table = use_filters('ds_comment_table', 'comments', $attr[0], $attr[1]);
$comments = new DB_Comments(array(
'db_table' => $comment_table,
'object' => $attr[0],
'object_id' => $attr[1],
'last' => $elem['last_id'],
));
if ($comments->is_posts()) {
foreach($comments->items() AS $post) {
$classes = array(
'ds-messages-item',
'comment comment-' . $post['id'],
);
$args = array(
'classes' => join(' ', $classes),
'image' => get_avatar($post['user_id']),
'title' => '<a href="' . get_user_url($post['user_id']) . '">' . get_user_nick($post['user_id']) . '</a>',
'time' => vremja($post['time']),
'content' => output_text($post['msg']),
'reply' => '?reply_to=' . $post['user_id'] . '&comment_id=' . $post['id'],
'actions' => array(),
);
$array[$key]['hash'] = $elem['hash'];
$array[$key]['container'] = '[data-comments="' . $elem['hash'] . '"]';
$array[$key]['count'] = get_comments_count($attr[0], $attr[1]);
if ($post['id'] > $elem['last_id']) {
$array[$key]['last_id'] = $post['id'];
}
$array[$key]['messages'][] = array(
'id' => $post['id'],
'append' => 'first',
'content' => get_comment_template($args),
);
}
}
}
if (empty($array)) {
return false;
}
return $array;
});
/**
* Сортируем сообщения в почте
* Т.к. новые сообщения внизу, то в обратном порядке
*/
add_filter('ds_mail_messages', 'justweb_sort_mail_messages');
function justweb_sort_mail_messages($array) {
krsort($array);
return $array;
}
function justweb_template_message($post)
{
global $user;
$classes = array(
'ds-messages-item',
$post['user_id'] == $user['id'] ? 'ds-msg-user' : 'ds-msg-ank',
$post['read'] == 0 ? 'no-read' : 'read',
'post-' . $post['id'],
);
$msg = '<div class="' . join(' ', $classes) . '">';
$msg .= '<div class="ds-messages-post">';
$msg .= '<div class="ds-message-photo">' . get_avatar($post['user_id']) . '</div>';
$msg .= '<div class="ds-message-content">';
$msg .= ' <a href="' . get_user_url($post['user_id']) . '">' . get_user_nick($post['user_id']) . '</a> (' . vremja($post['time']) . ')<br />';
$msg .= '<div class="ds-message-text">' . output_text($post['msg']) . '</div>';
$msg .= '</div>';
$msg .= '</div>';
$msg .= '</div>';
return $msg;
}
add_event('ds_mail_posted', 'justweb_mail_posted_json');
function justweb_mail_posted_json($post_id) {
global $user;
$post = get_mail_message($post_id);
$json = array(
'id' => $post_id,
'append' => 'last',
'container' => '.ds-messages',
'msg' => justweb_template_message($post),
);
justweb_output_json($json);
}
add_event('ds_comment_send', 'justweb_comment_posted_json', 10, 3);
function justweb_comment_posted_json($post_id, $object_type, $object_id)
{
$comment_table = use_filters('ds_comment_table', 'comments', $object_type, $object_id);
$post = db::fetch("SELECT * FROM `" . $comment_table . "` WHERE id = '" . $post_id . "' LIMIT 1");
$args = array(
'classes' => 'comment-' . $post['id'],
'image' => get_avatar($post['user_id']),
'title' => '<a href="' . get_user_url($post['user_id']) . '">' . get_user_nick($post['user_id']) . '</a>',
'time' => vremja($post['time']),
'content' => output_text($post['msg']),
);
$json = array(
'id' => $post_id,
'append' => 'first',
'hash' => get_comments_hash($object_type, $object_id),
'container' => '[data-comments="' . get_comments_hash($object_type, $object_id) . '"]',
'msg' => get_comment_template($args),
'count' => get_comments_count($object_type, $object_id),
);
justweb_output_json($json);
}
add_event('ds_mail_error', 'justweb_mail_error_json');
function justweb_mail_error_json() {
$json = array(
'errors' => get_errors(),
);
justweb_output_json($json);
}
function justweb_output_json($json) {
die(json_encode($json));
}
add_event('ds_messages_helper_before', 'justweb_messages_helper_before');
function justweb_messages_helper_before($ank) {
echo '<div class="mail_Pagination-helper"></div>';
}
add_event('ds_messages_helper_after', 'justweb_messages_helper_after');
function justweb_messages_helper_after($ank) {
echo '<div class="mail_Scroll-helper"></div>';
}
add_filter('filter_message_form_args', function($args) {
$args['strings']['send_title'] = '<span class="icon-comment-send"></span>';
return $args;
});
add_event('ds_comment_textarea_after', 'justweb_bbpanel_toggle', 10, 2);
function justweb_bbpanel_toggle($hash, $args) {
echo '<div class="textarea-panel"><span class="bb-panel-toggle" data-toggle="bbpanel"><i class="fa fa-font"></i></span> <span data-toggle="smiles" class="smile-panel-toggle"><i class="fa fa-smile-o"></i></span></div>';
}