Skip to content

Instantly share code, notes, and snippets.

@pafnuty
Last active August 30, 2021 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pafnuty/5655368 to your computer and use it in GitHub Desktop.
Save pafnuty/5655368 to your computer and use it in GitHub Desktop.
Быстрая подписка на новости DLE
// Подписка на комменты от dark5ider (минимизированный код)
function commSubs(a,b,c){return $.get(dle_root+"engine/ajax/subscribe.comm.php",{news_id:a,user_id:b,subunsub:c},function(a){$("#allow_subscribe").text(a.text),$("#allow_subscribe").attr("onclick",a.value),ShowLoading(a.loading),setTimeout("HideLoading('')",2e3)},"JSON"),!1}
<?php
/*
=====================================================
http://www.dark5ider.ru/
-----------------------------------------------------
Dmitry Dark5ider (2013) dark5ider.ru
=====================================================
Файл: subscribe.comm.php
-----------------------------------------------------
Назначение: Подписка на комменатрии на ajax
=====================================================
*/
/**
* Доп правки.
*
* @date 27.05.13 00:30
* @author Elkhan I.Isaev <elhan.isaev@gmail.com>
*/
define('DATALIFEENGINE', true);
define('ROOT_DIR', substr(dirname(__FILE__), 0, -12));
define('ENGINE_DIR', ROOT_DIR . '/engine');
include ENGINE_DIR . '/data/config.php';
if (empty($config['http_home_url'])) {
$config['http_home_url'] = explode("engine/ajax/subscribe.comm.php", $_SERVER['PHP_SELF']);
$config['http_home_url'] = reset($config['http_home_url']);
$config['http_home_url'] = "http://" . $_SERVER['HTTP_HOST'] . $config['http_home_url'];
} //empty($config['http_home_url'])
require_once ENGINE_DIR . '/classes/mysql.php';
require_once ENGINE_DIR . '/data/dbconfig.php';
require_once ENGINE_DIR . '/modules/functions.php';
require_once ENGINE_DIR . '/modules/sitelogin.php';
include_once ROOT_DIR . '/language/' . $config['langs'] . '/website.lng';
// GR CHECK
$user_group = get_vars("usergroup");
if (empty($user_group)) {
$user_group = array();
$db->query("SELECT * FROM " . USERPREFIX . "_usergroups ORDER BY id ASC");
while ($row = $db->get_row()) {
$user_group[$row['id']] = array();
foreach ($row as $key => $value) {
$user_group[$row['id']][$key] = stripslashes($value);
} //$row as $key => $value
} //$row = $db->get_row()
set_vars("usergroup", $user_group);
$db->free();
} //!empty($user_group)
// ICONVARRAY
function iconv_array($inCharset, $outCharset, $inArray)
{
if (empty($inArray) || !is_array($inArray))
return false;
$outArray = array();
foreach ($inArray as $key => $value) {
if (is_array($value))
$outArray[$key] = iconv_array($inCharset, $outCharset, $value);
else
$outArray[$key] = iconv($inCharset, $outCharset, $value);
} //$inArray as $key => $value
return $outArray;
}
/**
* Реализация
*/
$allow_subscribe = ($config['allow_subscribe'] && $user_group[$member_id['user_group']]['allow_subscribe']) ? TRUE : FALSE;
if (FALSE === $allow_subscribe) {
die("Not allow to subscribe");
} //FALSE === $allow_subscribe
if (empty($_GET['news_id'])) {
die('News ID is empty!');
} //empty($_GET['news_id'])
$news = $db->super_query("SELECT id FROM " . PREFIX . "_post WHERE id = " . ((int) $_GET['news_id']));
if (empty($news['id'])) {
die('This News IS NOT FOUND!');
} //empty($news['id'])
$subOpt = array(
((int) $_GET['news_id']),
((int) $member_id['user_id'])
);
$row = $db->super_query("SELECT hash FROM " . PREFIX . "_subscribe
WHERE
news_id = " . ((int) $_GET['news_id']) . "
AND
user_id = " . $member_id['user_id']);
if (!empty($row['hash'])) {
// Описка от новости
if (1 == $_GET['subunsub']) {
$db->query("DELETE FROM " . PREFIX . "_subscribe
WHERE
news_id = " . ((int) $_GET['news_id']) . "
AND
user_id = " . $member_id['user_id']);
$subOpt[] = 0;
$status = TRUE;
$text = $lang['c_subscribe'];
$loading = $lang['unsubscribe_ok'];
} //1 == $_GET['subunsub']
if (0 == $_GET['subunsub']) {
$loading = $lang['subscribe_err'];
$subOpt[] = 0;
} //0 == $_GET['subunsub']
} //!empty($row['hash'])
else {
if (1 == $_GET['subunsub']) {
$loading = $lang['unsubscribe_err'];
$subOpt[] = 1;
} //1 == $_GET['subunsub']
if (0 == $_GET['subunsub']) {
if (function_exists('openssl_random_pseudo_bytes')) {
$stronghash = md5(openssl_random_pseudo_bytes(15));
} //function_exists('openssl_random_pseudo_bytes')
else {
$stronghash = md5(uniqid(mt_rand(), TRUE));
}
$salt = str_shuffle($stronghash);
$s_hash = "";
for ($i = 0; $i < 10; $i++) {
$s_hash .= $salt{mt_rand(0, 31)};
} //$i = 0; $i < 10; $i++
$s_hash = md5($s_hash);
$db->query("INSERT INTO " . PREFIX . "_subscribe
(
user_id,
name,
email,
news_id,
hash
)
VALUES
(
'" . $member_id['user_id'] . "',
'" . $member_id['name'] . "',
'" . $member_id['email'] . "',
'" . ((int) $_GET['news_id']) . "',
'" . $s_hash . "'
)
");
$status = TRUE;
$text = $lang['c_unsubscribe'];
$subOpt[] = 1;
$loading = $lang['subscribe_ok'];
} //0 == $_GET['subunsub']
}
$buffer = array(
"loading" => $loading,
"value" => "commSubs('" . implode("','", $subOpt) . "'); return false;" . $sububsub,
"text" => $text,
"status" => (TRUE === $status ? 'ok' : 'err')
);
$buffer = json_encode(iconv_array($config['charset'], 'utf-8', $buffer));
@header("Content-type: text/html; charset=" . $config['charset']);
echo $buffer;
@dj-avtosh
Copy link

if (!empty($user_group)) {

заменить на

if (empty($user_group)) {

@dj-avtosh
Copy link

Все вхождения

$_GET['user_id']

замени на

$member_id['user_id']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment