Skip to content

Commit

Permalink
Добалена работа по крону, через прокси и поддержка cp1251
Browse files Browse the repository at this point in the history
  • Loading branch information
Gokujo committed May 24, 2018
1 parent b552753 commit 0d14060
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 498 deletions.
6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/telegramposting.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

373 changes: 0 additions & 373 deletions .idea/workspace.xml

This file was deleted.

109 changes: 109 additions & 0 deletions engine/ajax/maharder/telegram/cronadd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
// ===============================
// Добавление новостей по крону
// ===============================
// Автор: Maxim Harder
// Сайт: https://maxim-harder.de
// Телеграм: http://t.me/MaHarder
// ===============================
// Ничего не менять
// ===============================
@error_reporting ( E_ALL ^ E_WARNING ^ E_NOTICE );
@ini_set ( 'display_errors', true );
@ini_set ( 'html_errors', false );
@ini_set ( 'error_reporting', E_ALL ^ E_WARNING ^ E_NOTICE );

define( 'DATALIFEENGINE', true );
define( 'ROOT_DIR', dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) );
define( 'ENGINE_DIR', ROOT_DIR . '/engine' );

include ENGINE_DIR . "/data/telegram.php";
include ENGINE_DIR . '/data/config.php';
date_default_timezone_set ( $config['date_adjust'] );

if( $config['http_home_url'] == "" ) {

$config['http_home_url'] = explode( "engine/ajax/maharder/telegram/cronadd.php", $_SERVER['PHP_SELF'] );
$config['http_home_url'] = reset( $config['http_home_url'] );
$config['http_home_url'] = "https://" . $_SERVER['HTTP_HOST'] . $config['http_home_url'];

}

require_once ENGINE_DIR . '/classes/mysql.php';
require_once ENGINE_DIR . '/data/dbconfig.php';

if($telebot['onof'] && $telebot['cron']) {
require_once (ENGINE_DIR . "/inc/maharder/telegram/functions.php");

if($telebot['cron_news'] > 0) $limit = "LIMIT " . $telebot['cron_news'];
else $limit = "";
$cron = $db->query("SELECT * FROM " . PREFIX . "_telegram_cron {$limit}" );
if(count($cron) <= 0) return;
else {
while ($row = $db->get_row($cron)) {
$news_id = intval($row['news_id']);
$news = $db->super_query("SELECT * FROM " . PREFIX . "_post LEFT JOIN " . PREFIX . "_post_extras ON " . PREFIX . "_post.id = " . PREFIX . "_post_extras.news_id WHERE id = '{$news_id}'");
$news_time = $row['time'];
if(!isset($telebot['cron_time'])) $telebot['cron_time'] = 0;
$cron_time = $telebot['cron_time'];
$cron_time = $cron_time * 60;
$news_time = $news_time+$cron_time;
$now_time = time();

$xfields = explode('||', $news['xfields']);
$xf = array();
foreach ($xfields as $key => $value) {
$sfields = explode('|', $value);
$xf[$sfields[0]] = $sfields[1];
}
if($now_time >= $news_time) {
if($row['type'] == "add")
$source = $telebot['cron_addnews'] ? $source : $telebot['addnews'];
elseif ($row['type'] == "edit")
$source = $telebot['cron_editnews'] ? $source : $telebot['editnews'];

if ($config['allow_alt_url']) {
if ($config['seo_type'] == 1 OR $config['seo_type'] == 2) {
if (intval($news['category']) and $config['seo_type'] == 2) {
$full_link = $config['http_home_url'] . get_url(intval($news['category'])) . "/" . $news_id . "-" . $news['alt_name'] . ".html";
} else {
$full_link = $config['http_home_url'] . $news_id . "-" . $news['alt_name'] . ".html";
}
} else {
$full_link = $config['http_home_url'] . date('Y/m/d/', strtotime($news['date'])) . $news['alt_name'] . ".html";
}
} else {
$full_link = $config['http_home_url'] . "index.php?newsid=" . $news_id;
}

$temes = htmlspecialchars_decode($source);
$temes = str_replace('%title%', $news['title'], $temes);
$temes = str_replace('%link%', $full_link, $temes);
$temes = str_replace('%descr%', "%short_descr%", $temes);
$temes = str_replace('%short_descr%', $news['short_story'], $temes);
$temes = str_replace('%full_descr%', $news['full_story'], $temes);
$temes = str_replace('%autor%', $news['autor'], $temes);
$temes = str_replace('[b]', '<b>', $temes);
$temes = str_replace('[/b]', '</b>', $temes);
$temes = str_replace('[i]', '<i>', $temes);
$temes = str_replace('[/i]', '</i>', $temes);
$temes = str_replace('[code]', '<code>', $temes);
$temes = str_replace('[/code]', '</code>', $temes);
if ($row['type'] == "add") $temes = str_replace('%editreason%', $news['reason'], $temes);
$temes = preg_replace("/\[url=(.*)\](.*)\[\/url\]/", "<a href=\"$1\">$2</a>", $temes);
$temes = preg_replace("/\[url\](.*)\[\/url\]/", "<a href=\"$1\">$1</a>", $temes);
preg_match_all("/%xf_(.*)%/", $temes, $tempFields);
foreach ($tempFields[1] as $id => $value) {
$temes = str_replace('%xf_' . $value . '%', $xf[$value], $temes);
}
$temes = str_replace('<br>', "\r\n", $temes);

$turl = "https://api.telegram.org/bot" . $telebot['token'] . "/sendMessage?chat_id=" . $telebot['chat'] . "&text=" . urlencode($temes) . "&parse_mode=HTML";
sendMessage($turl);
$cron_id = intval($row['cron_id']);
$db->query("DELETE FROM " . PREFIX . "_telegram_cron WHERE cron_id = {$cron_id}");
} else continue;
}
}

} else return;
76 changes: 42 additions & 34 deletions engine/inc/maharder/telegram/addnews.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
if(!$id) return;

@include (ENGINE_DIR . '/data/'.$codename.'.php');
require_once (ENGINE_DIR . '/inc/maharder/assets/functions.php');
require_once (ENGINE_DIR . '/inc/maharder/'.$codename.'/version.php');
require_once (ENGINE_DIR . '/inc/maharder/'.$codename.'/functions.php');

if($telebot['onof']) {

$xfields = explode('||', $filecontents);
$xf = array();
foreach ($xfields as $key => $value) {
Expand All @@ -32,47 +31,56 @@
$request = explode(':', $telebot['field']);
$field = explode('|', $request[1]);

if($request[0] == "xf") {
$post_tg = false;

if ($request[0] == "xf") {
if ($xf[$field[0]] != $field[1]) return;
else $post_tg = true;
} elseif ($request[0] == "post") {
$quest = $db->super_query("SELECT {$field[0]} FROM " . PREFIX . "_post WHERE id = '{$id}'");
if($quest[$field[0]] != $field[1]) return;
if ($quest[$field[0]] != $field[1]) return;
else $post_tg = true;
}

if ($config['allow_alt_url']) {
if ($config['seo_type'] == 1 OR $config['seo_type'] == 2) {
if (intval($category_list) and $config['seo_type'] == 2) {
$full_link = $config['http_home_url'] . get_url(intval($category_list)) . "/" . $id . "-" . $alt_name . ".html";
if($telebot['cron'] && $post_tg) $db->query("INSERT INTO " . PREFIX . "_telegram_cron (news_id, type, time) VALUES ('{$id}', 'add', '{$added_time}')");
else {

if ($config['allow_alt_url']) {
if ($config['seo_type'] == 1 OR $config['seo_type'] == 2) {
if (intval($category_list) and $config['seo_type'] == 2) {
$full_link = $config['http_home_url'] . get_url(intval($category_list)) . "/" . $id . "-" . $alt_name . ".html";
} else {
$full_link = $config['http_home_url'] . $id . "-" . $alt_name . ".html";
}
} else {
$full_link = $config['http_home_url'] . $id . "-" . $alt_name . ".html";
$full_link = $config['http_home_url'] . date('Y/m/d/', strtotime($thistime)) . $alt_name . ".html";
}
} else {
$full_link = $config['http_home_url'] . date('Y/m/d/', strtotime($thistime)) . $alt_name . ".html";
$full_link = $config['http_home_url'] . "index.php?newsid=" . $id;
}
} else {
$full_link = $config['http_home_url'] . "index.php?newsid=" . $id;
}

$temes = htmlspecialchars_decode($telebot['addnews']);
$temes = str_replace('%title%', $title, $temes);
$temes = str_replace('%link%', $full_link, $temes);
$temes = str_replace('%descr%', "%short_descr%", $temes);
$temes = str_replace('%short_descr%', $short_story, $temes);
$temes = str_replace('%full_descr%', $full_story, $temes);
$temes = str_replace('%autor%', $author, $temes);
$temes = str_replace('[b]', '<b>', $temes);
$temes = str_replace('[/b]', '</b>', $temes);
$temes = str_replace('[i]', '<i>', $temes);
$temes = str_replace('[/i]', '</i>', $temes);
$temes = str_replace('[code]', '<code>', $temes);
$temes = str_replace('[/code]', '</code>', $temes);
$temes = preg_replace("/\[url=(.*)\](.*)\[\/url\]/", "<a href=\"$1\">$2</a>", $temes);
$temes = preg_replace("/\[url\](.*)\[\/url\]/", "<a href=\"$1\">$1</a>", $temes);
preg_match_all("/%xf_(.*)%/", $temes, $tempFields);
foreach ($tempFields[1] as $id => $value) {
$temes = str_replace('%xf_' . $value . '%', $xf[$value], $temes);
$temes = htmlspecialchars_decode($telebot['addnews']);
$temes = str_replace('%title%', $title, $temes);
$temes = str_replace('%link%', $full_link, $temes);
$temes = str_replace('%descr%', "%short_descr%", $temes);
$temes = str_replace('%short_descr%', $short_story, $temes);
$temes = str_replace('%full_descr%', $full_story, $temes);
$temes = str_replace('%autor%', $author, $temes);
$temes = str_replace('[b]', '<b>', $temes);
$temes = str_replace('[/b]', '</b>', $temes);
$temes = str_replace('[i]', '<i>', $temes);
$temes = str_replace('[/i]', '</i>', $temes);
$temes = str_replace('[code]', '<code>', $temes);
$temes = str_replace('[/code]', '</code>', $temes);
$temes = preg_replace("/\[url=(.*)\](.*)\[\/url\]/", "<a href=\"$1\">$2</a>", $temes);
$temes = preg_replace("/\[url\](.*)\[\/url\]/", "<a href=\"$1\">$1</a>", $temes);
preg_match_all("/%xf_(.*)%/", $temes, $tempFields);
foreach ($tempFields[1] as $id => $value) {
$temes = str_replace('%xf_' . $value . '%', $xf[$value], $temes);
}
$temes = str_replace('<br>', "\r\n", $temes);
if($config['charset'] != "utf-8") $temes = mb_convert_encoding($temes, "utf-8", "windows-1251");
$turl = "https://api.telegram.org/bot" . $telebot['token'] . "/sendMessage?chat_id=" . $telebot['chat'] . "&text=" . urlencode($temes) . "&parse_mode=HTML";
sendMessage($turl);
}
$temes = str_replace('<br>', "\r\n", $temes);
$turl = "https://api.telegram.org/bot" . $telebot['token'] . "/sendMessage?chat_id=" . $telebot['chat'] . "&text=" . urlencode($temes) . "&parse_mode=HTML";
sendMessage ($turl);
}
Loading

0 comments on commit 0d14060

Please sign in to comment.