Shift
11 years ago
16 changed files with 821 additions and 0 deletions
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
-- phpMyAdmin SQL Dump |
||||
-- version 4.0.6 |
||||
-- http://www.phpmyadmin.net |
||||
-- |
||||
-- Хост: localhost |
||||
-- Время создания: Авг 07 2014 г., 04:43 |
||||
-- Версия сервера: 5.5.38-0ubuntu0.14.04.1 |
||||
-- Версия PHP: 5.5.9-1ubuntu4.3 |
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; |
||||
SET time_zone = "+00:00"; |
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; |
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; |
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; |
||||
/*!40101 SET NAMES utf8 */; |
||||
|
||||
-- |
||||
-- База данных: `twistercms` |
||||
-- |
||||
CREATE DATABASE IF NOT EXISTS `twistercms` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; |
||||
USE `twistercms`; |
||||
|
||||
-- -------------------------------------------------------- |
||||
|
||||
-- |
||||
-- Структура таблицы `rss` |
||||
-- |
||||
|
||||
CREATE TABLE IF NOT EXISTS `rss` ( |
||||
`id` int(11) NOT NULL AUTO_INCREMENT, |
||||
`name` text NOT NULL, |
||||
`url` text NOT NULL, |
||||
`active` tinyint(4) NOT NULL, |
||||
`lastupdate` text NOT NULL, |
||||
`updatetime` smallint(6) NOT NULL, |
||||
`account` text NOT NULL, |
||||
PRIMARY KEY (`id`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ; |
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; |
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT) |
||||
|
||||
Copyright (c) 2014 Denis Ryabov |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of |
||||
this software and associated documentation files (the "Software"), to deal in |
||||
the Software without restriction, including without limitation the rights to |
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
||||
the Software, and to permit persons to whom the Software is furnished to do so, |
||||
subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
twister-phpbot |
||||
============== |
||||
|
||||
Simple Twister bot written in PHP. It is used to post messages for twister's @habr_ru account. |
||||
|
||||
## Requirements |
||||
|
||||
- PHP 5.3+ |
||||
- `mbstring` extension |
||||
- `allow_url_fopen` enabled |
||||
- `exec` allowed |
||||
|
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
<?php |
||||
session_start(); |
||||
require('settings.php'); |
||||
if ($_SESSION['login'] ==='true') { |
||||
//header('Location: http://'.$domain.'/cms/admin.php'); |
||||
}else { |
||||
header('Location: http://'.$domain.'/cms/index.php'); |
||||
die (); |
||||
} |
||||
echo '<!DOCTYPE html> |
||||
<html lang="ru"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
<meta name="description" content=""> |
||||
<meta name="author" content=""> |
||||
<link rel="icon" href="../../favicon.ico"> |
||||
|
||||
<title>Twister-RSS</title> |
||||
|
||||
<!-- Bootstrap core CSS --> |
||||
<link href="bootstrap.min.css" rel="stylesheet"> |
||||
|
||||
</head> |
||||
|
||||
<body> |
||||
|
||||
<div class="container"> |
||||
<div class="header"> |
||||
<ul class="nav nav-pills pull-right"> |
||||
<li ><a href="admin.php">Admin</a></li> |
||||
<li class="active"><a class="active"href="#">About</a></li> |
||||
|
||||
</ul> |
||||
<h3 class="text-muted">Twister-RSS</h3> |
||||
</div>'; |
||||
|
||||
|
||||
echo '<hr><div class=""> |
||||
<h1>About</h1> |
||||
<h2>Twister-RSS v 0.1</h2> |
||||
<h3>Авторы данного софта: @denis, @shift</h3> |
||||
|
||||
'; |
||||
|
||||
|
||||
|
||||
|
||||
echo ' <div class="footer"> |
||||
<p>© Company 2014</p> |
||||
</div> |
||||
|
||||
</div> <!-- /container --> |
||||
|
||||
|
||||
|
||||
</body> |
||||
</html>'; |
||||
|
||||
|
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
<?php |
||||
session_start(); |
||||
echo '<!DOCTYPE html> |
||||
<html lang="ru"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
<meta name="description" content=""> |
||||
<meta name="author" content=""> |
||||
<link rel="icon" href="../../favicon.ico"> |
||||
|
||||
<title>Twister-RSS</title> |
||||
|
||||
<!-- Bootstrap core CSS --> |
||||
<link href="bootstrap.min.css" rel="stylesheet"> |
||||
|
||||
</head> |
||||
|
||||
<body> |
||||
|
||||
<div class="container"> |
||||
<div class="header"> |
||||
<ul class="nav nav-pills pull-right"> |
||||
<li class="active"><a href="#">Admin</a></li> |
||||
<li><a href="about.php">About</a></li> |
||||
</ul> |
||||
<h3 class="text-muted">Twister-RSS</h3> |
||||
</div>'; |
||||
|
||||
|
||||
echo '<hr><div class=""> |
||||
<h1>Ваши RSS подписки</h1> |
||||
|
||||
|
||||
'; |
||||
require('settings.php'); |
||||
$sql="SELECT * |
||||
FROM `rss`"; |
||||
|
||||
echo '<table class="table">'; |
||||
echo '<tr><td>Название RSS</td><td>URL</td><td>Включено</td><td>Последнее обновление</td><td>Частота обновления</td><td>Публиковать от имени</td><td></td><td></td><td></td></tr>'; |
||||
$result=mysql_query($sql) or die(mysql_error()); |
||||
while ($row = mysql_fetch_array($result)) { |
||||
if ($row['active'] == '1') { |
||||
$trclass="success"; |
||||
$activeTXT='Да'; |
||||
$activeTXT2='Отключить'; |
||||
$activeTXT3=0; |
||||
$activeTXTClass='btn btn-warning'; |
||||
} else { |
||||
$trclass="warning"; |
||||
$activeTXT='Нет'; |
||||
$activeTXT2='Включить'; |
||||
$activeTXT3=1; |
||||
$activeTXTClass='btn btn-success'; |
||||
} |
||||
echo '<tr class="'.$trclass.'">'; |
||||
echo '<td>'.$row['name'].'</td>'; |
||||
echo '<td>'.$row['url'].'</td>'; |
||||
echo '<td>'.$activeTXT.'</td>'; |
||||
echo '<td>'.$row['lastupdate'].'</td>'; |
||||
echo '<td>'.$row['updatetime'].'</td>'; |
||||
echo '<td>'.$row['account'].'</td>'; |
||||
echo '<td><a class="'.$activeTXTClass.'" href="edit.php?action=active&id='.$row['id'].'&active='.$activeTXT3.'">'.$activeTXT2.'</a></td>'; |
||||
//echo '<td><a class="btn btn-primary" href="edit.php?action=edit&id='.$row['id'].'">Изменить</a></td>'; |
||||
echo '<td><a class="btn btn-danger" href="edit.php?action=del&id='.$row['id'].'">Удалить</a></td>'; |
||||
echo '</tr>'; |
||||
unset($trclass); |
||||
} |
||||
echo '</table></div>'; |
||||
echo '<script> |
||||
function hideshow (){ |
||||
document.getElementById("hide2").style.display="none" |
||||
document.getElementById("hide").style.display="block" |
||||
} |
||||
</script>'; |
||||
echo '<hr> |
||||
<div class="well"> |
||||
<div align="center" id="hide2"><a class="btn btn-lg btn-primary" onclick="hideshow();">Добавить RSS поток</a></div> |
||||
<div id="hide" style="display:none"><form class="navbar-form" action="edit.php" method="post"><div class="form-group">'; |
||||
echo 'Название RSS: <input class="form-control" name="name" type="text" size="20"> |
||||
URL: <input class="form-control" name="url" type="text" size="20"> |
||||
Публиковать от имени: <input class="form-control" name="account" type="text" size="20"> |
||||
<!--(Не реализовано) Частота обновления: <input name="updatetime" type="text" size="20">--> |
||||
Включен ? <input class="form-control" name="active" type="checkbox" size="20"> '; |
||||
echo '<input style="margin-left:20px" class="btn btn-default" type="submit" value="Добавить"></div></div></form></div>'; |
||||
|
||||
|
||||
|
||||
echo ' <div class="footer"> |
||||
<p>© Company 2014</p> |
||||
</div> |
||||
|
||||
</div> <!-- /container --> |
||||
|
||||
|
||||
|
||||
</body> |
||||
</html>'; |
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
<?php |
||||
session_start(); |
||||
require('settings.php'); |
||||
if ($_SESSION['login'] ==='true') { |
||||
header('Location: http://'.$domain.'/cms/admin.php'); |
||||
}else { |
||||
header('Location: http://'.$domain.'/cms/index.php'); |
||||
die (); |
||||
} |
||||
|
||||
$active = $_POST['active']; |
||||
if (empty($active)) { |
||||
$active = $_GET['active']; |
||||
} |
||||
echo $active; |
||||
if ($active === "on") $active = 1; |
||||
echo $active; |
||||
$account = $_POST['account']; |
||||
|
||||
$action = $_POST['action']; |
||||
if (empty($action)) { |
||||
$action = $_GET['action']; |
||||
} |
||||
|
||||
|
||||
$id = $_POST['id']; |
||||
if (empty($id)) { |
||||
$id = $_GET['id']; |
||||
} |
||||
|
||||
$name = $_POST['name']; |
||||
$url = $_POST['url']; |
||||
$updatetime = $_POST['updatetime']; |
||||
|
||||
if (!empty($url)) { |
||||
if (empty($action)) { |
||||
// add |
||||
$sql = "INSERT INTO `rss` (`name`, `url`, `active`, `lastupdate`, `updatetime`, `account`) VALUES ('$name','$url','$active','$lastupdate','$updatetime', '$account')"; |
||||
$result=mysql_query($sql) or die(mysql_error()); |
||||
header('Location: http://'.$domain.'/cms/admin.php'); |
||||
} |
||||
}elseif ($action == 'edit') { |
||||
// edit |
||||
//$sql="UPDATE `rss` SET `name`='$name',`url`='$url',`active`='$active',`updatetime`='$updatetime' WHERE `id`='$id'"; |
||||
//$result=mysql_query($sql) or die(mysql_error()); |
||||
//header('Location: http://'.$domain.'/cms/admin.php'); |
||||
}elseif ($action == 'del') { |
||||
// del |
||||
$sql="DELETE FROM `rss` WHERE `id`='$id'"; |
||||
$result=mysql_query($sql) or die(mysql_error()); |
||||
header('Location: http://'.$domain.'/cms/admin.php'); |
||||
}elseif ($action == 'active') { |
||||
$sql="UPDATE `rss` SET `active`='$active' WHERE `id`='$id'"; |
||||
$result=mysql_query($sql) or die(mysql_error()); |
||||
header('Location: http://'.$domain.'/cms/admin.php'); |
||||
} |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
<?php |
||||
$rpcusername = $_POST['rpcusername']; |
||||
$rpcpassword1 = $_POST['rpcpassword1']; |
||||
session_start(); |
||||
require('settings.php'); |
||||
echo '<!DOCTYPE html> |
||||
<html lang="ru"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
<meta name="description" content=""> |
||||
<meta name="author" content=""> |
||||
<link rel="icon" href="../../favicon.ico"> |
||||
|
||||
<title>Twister-RSS</title> |
||||
|
||||
<!-- Bootstrap core CSS --> |
||||
<link href="bootstrap.min.css" rel="stylesheet"> |
||||
|
||||
</head> |
||||
|
||||
<body> |
||||
|
||||
<div class="container"> |
||||
<div class="header"> |
||||
<ul class="nav nav-pills pull-right"> |
||||
<li class="active"><a href="#">Admin</a></li> |
||||
<li><a href="about.php">About</a></li> |
||||
</ul> |
||||
<h3 class="text-muted">Twister-RSS</h3> |
||||
</div>'; |
||||
|
||||
|
||||
if ($_SESSION['login'] ==='true') { |
||||
header('Location: http://'.$domain.'/cms/admin.php'); |
||||
}else { |
||||
//header('Location: http://'.$domain.'/cms/index.php'); |
||||
//die (); |
||||
} |
||||
if (empty($rpcusername)){ |
||||
echo '<hr><div align="center" class="jumbotron"> |
||||
<h1>Login</h1> |
||||
<form class="navbar-form" action="index.php" method="post"><div class="form-group">'; |
||||
echo 'RPC username: <input class="form-control" name="rpcusername" type="text" size="20"><br> |
||||
RPC password: <input class="form-control" name="rpcpassword1" type="password" size="20"><br><br>'; |
||||
echo '<input style="margin-left:20px" class="btn btn-primary" type="submit" value="Войти"></div></div></form> |
||||
|
||||
'; |
||||
}else{ |
||||
if ($rpcusername == $rpcuser && $rpcpassword1 == $rpcpassword) { |
||||
$_SESSION['login']='true'; |
||||
header('Location: http://'.$domain.'/cms/admin.php'); |
||||
}else { |
||||
//echo $rpcpassword .' / '.$rpcpassword1 . ' / '.$rpcuser.' / '.$rpcusername; |
||||
die ('Bad username/password'); |
||||
} |
||||
|
||||
} |
||||
|
||||
echo ' <div class="footer"> |
||||
<p>© Company 2014</p> |
||||
</div> |
||||
|
||||
</div> <!-- /container --> |
||||
|
||||
|
||||
|
||||
</body> |
||||
</html>'; |
||||
|
||||
|
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
/* Space out content a bit */ |
||||
body { |
||||
padding-top: 20px; |
||||
padding-bottom: 20px; |
||||
} |
||||
|
||||
/* Everything but the jumbotron gets side spacing for mobile first views */ |
||||
.header, |
||||
.marketing, |
||||
.footer { |
||||
padding-right: 15px; |
||||
padding-left: 15px; |
||||
} |
||||
|
||||
/* Custom page header */ |
||||
.header { |
||||
border-bottom: 1px solid #e5e5e5; |
||||
} |
||||
/* Make the masthead heading the same height as the navigation */ |
||||
.header h3 { |
||||
padding-bottom: 19px; |
||||
margin-top: 0; |
||||
margin-bottom: 0; |
||||
line-height: 40px; |
||||
} |
||||
|
||||
/* Custom page footer */ |
||||
.footer { |
||||
padding-top: 19px; |
||||
color: #777; |
||||
border-top: 1px solid #e5e5e5; |
||||
} |
||||
|
||||
/* Customize container */ |
||||
@media (min-width: 768px) { |
||||
.container { |
||||
max-width: 730px; |
||||
} |
||||
} |
||||
.container-narrow > hr { |
||||
margin: 30px 0; |
||||
} |
||||
|
||||
/* Main marketing message and sign up button */ |
||||
.jumbotron { |
||||
text-align: center; |
||||
border-bottom: 1px solid #e5e5e5; |
||||
} |
||||
.jumbotron .btn { |
||||
padding: 14px 24px; |
||||
font-size: 21px; |
||||
} |
||||
|
||||
/* Supporting marketing content */ |
||||
.marketing { |
||||
margin: 40px 0; |
||||
} |
||||
.marketing p + h4 { |
||||
margin-top: 28px; |
||||
} |
||||
|
||||
/* Responsive: Portrait tablets and up */ |
||||
@media screen and (min-width: 768px) { |
||||
/* Remove the padding we set earlier */ |
||||
.header, |
||||
.marketing, |
||||
.footer { |
||||
padding-right: 0; |
||||
padding-left: 0; |
||||
} |
||||
/* Space out the masthead */ |
||||
.header { |
||||
margin-bottom: 30px; |
||||
} |
||||
/* Remove the bottom border on the jumbotron for visual effect */ |
||||
.jumbotron { |
||||
border-bottom: 0; |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
<?php |
||||
require('settings.php'); |
||||
$UID = $_GET['id']; |
||||
$sql="SELECT * |
||||
FROM `rss` |
||||
WHERE `id`='$UID'"; |
||||
$result=mysql_query($sql) or die(mysql_error()); |
||||
while ($row = mysql_fetch_array($result)) { |
||||
$account=$row['account']; |
||||
$url=$row['url']; |
||||
} |
||||
|
||||
mb_internal_encoding('UTF-8'); |
||||
setlocale(LC_CTYPE, 'en_US.UTF-8'); |
||||
|
||||
// Load RSS feed |
||||
require_once 'rssreader.php'; |
||||
$feed_uri = $url; |
||||
$rss = getRssFeed($feed_uri); |
||||
if (!$rss) die('Cannot read rss or it is up to date'); |
||||
|
||||
// Initialise TwisterPost |
||||
require_once 'twisterpost.php'; |
||||
$twister = new TwisterPost($account); |
||||
|
||||
// Initialise RSS database |
||||
require_once 'rssdb.php'; |
||||
$db = new RSSDb($account.'.dat'); |
||||
|
||||
foreach ($rss->channel->item as $item) { |
||||
$link = (string)$item->link; |
||||
$title = (string)$item->title; |
||||
// Note: habrahabr.ru does both special chars encoding and CDATA wrap |
||||
$title = htmlspecialchars_decode($title); |
||||
|
||||
// get post id from link |
||||
$id = (int)preg_replace('#[^\d]#', '', $link); |
||||
|
||||
if ($db->isPublished($id)) { |
||||
continue; |
||||
} |
||||
|
||||
// shorten URL [-6 chars do matter] |
||||
$link = str_replace('habrahabr.ru', 'habr.ru', $link); |
||||
$link = rtrim($link, '/'); |
||||
|
||||
$msg = $twister->prettyPrint($title, $link, isset($item->category) ? $item->category : null); |
||||
|
||||
if ($twister->postMessage($msg)) { |
||||
$db->setPublished($id); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
<?php |
||||
|
||||
class RSSDb |
||||
{ |
||||
protected $hDatabase = null; |
||||
protected $minId = 0; |
||||
protected $bits = array(0=>1, 2, 4, 8, 16, 32, 64, 128); |
||||
|
||||
public function __construct($dbFile, $minId = 0) |
||||
{ |
||||
fclose(fopen($dbFile, 'a')); // create file if not exists |
||||
$this->hDatabase = fopen($dbFile, 'r+'); |
||||
$this->minId = $minId; |
||||
} |
||||
|
||||
public function __destruct() |
||||
{ |
||||
fclose($this->hDatabase); |
||||
} |
||||
|
||||
public function isPublished($id) |
||||
{ |
||||
$id -= $this->minId; |
||||
if ($id < 0) return true; |
||||
$pos = intval($id/8); |
||||
fseek($this->hDatabase, $pos); |
||||
$status = ord(fgetc($this->hDatabase)); |
||||
return (bool)($status & $this->bits[$id % 8]); |
||||
} |
||||
|
||||
public function setPublished($id) |
||||
{ |
||||
$id -= $this->minId; |
||||
if ($id < 0) return; |
||||
$pos = intval($id/8); |
||||
fseek($this->hDatabase, $pos); |
||||
$status = ord(fgetc($this->hDatabase)); |
||||
fseek($this->hDatabase, $pos); |
||||
fwrite($this->hDatabase, chr($status | $this->bits[$id % 8])); |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
<?php |
||||
|
||||
function getRssFeed($feed_uri, $reload = false) |
||||
{ |
||||
$meta_file = md5($feed_uri) . '.json'; |
||||
$meta = @json_decode(@file_get_contents($meta_file), true); |
||||
|
||||
$ch = curl_init(); |
||||
curl_setopt($ch, CURLOPT_URL, $feed_uri); |
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); |
||||
curl_setopt($ch, CURLOPT_HEADER, true); |
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
||||
if (!$reload) { |
||||
if (isset($meta['etag'])) |
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('If-None-Match: ' . $meta['etag'])); |
||||
if (isset($meta['lastModified'])) |
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('If-Modified-Since: ' . $meta['lastModified'])); |
||||
} |
||||
|
||||
$response = curl_exec($ch); |
||||
$info = curl_getinfo($ch); |
||||
|
||||
$http_code = $info['http_code']; |
||||
if ($http_code !== 200) |
||||
return false; |
||||
|
||||
$headers = substr($response, 0, $info['header_size']); |
||||
$headers_arr = array(); |
||||
foreach (explode("\n", $headers) as $h) { |
||||
$h = explode(':', $h, 2); |
||||
if (!isset($h[1])) continue; |
||||
$key = $h[0]; |
||||
$value = trim($h[1]); |
||||
if (!isset($headers_arr[$key])) |
||||
$headers_arr[$key] = $value; |
||||
elseif (is_array($headers[$key])) |
||||
$headers_arr[$key][] = $value; |
||||
else |
||||
$headers_arr[$key] = array($headers_arr[$key], $value); |
||||
} |
||||
|
||||
$meta = array(); |
||||
if (isset($headers_arr['Etag'])) |
||||
$meta['etag'] = $headers_arr['Etag']; |
||||
if (isset($headers_arr['Last-Modified'])) |
||||
$meta['lastModified'] = $headers_arr['Last-Modified']; |
||||
file_put_contents($meta_file, json_encode($meta)); |
||||
|
||||
$body = substr($response, $info['header_size']); |
||||
|
||||
return @simplexml_load_string($body); |
||||
} |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
<?php |
||||
$sdd_db_host='localhost'; |
||||
// Имя базы данных с которой вы хотите работать, так как их может быть множество |
||||
$sdd_db_name=''; |
||||
// логин доступ к базе данных |
||||
$sdd_db_user=''; |
||||
// пароль доступа к базе данных |
||||
$sdd_db_pass=''; |
||||
// устанавливаем связь с сервером |
||||
@mysql_connect($sdd_db_host,$sdd_db_user,$sdd_db_pass); |
||||
// переключаемся на нужную нам базу данных |
||||
@mysql_select_db($sdd_db_name); |
||||
// делаем выборку из таблицы |
||||
mysql_query("SET NAMES utf8"); |
||||
$domain=""; |
||||
|
||||
$rpcuser = 'LOGIN'; |
||||
$rpcpassword = 'PASSWORD'; |
||||
$rpchost = '127.0.0.1'; |
||||
$rpcport = 28332; |
||||
?> |
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
<?php |
||||
public $rpcuser = 'LOGIN'; |
||||
public $rpcpassword = 'PASSWORD'; |
||||
public $rpchost = '127.0.0.1'; |
||||
public $rpcport = 28332; |
||||
?> |
@ -0,0 +1,168 @@
@@ -0,0 +1,168 @@
|
||||
<?php |
||||
//require("settings.php"); |
||||
class TwisterPost |
||||
{ |
||||
|
||||
// public $user = ''; |
||||
require("settings.php"); |
||||
//public $rpcuser = ''; |
||||
//public $rpcpassword = ''; |
||||
//public $rpchost = '127.0.0.1'; |
||||
//public $rpcport = 28332; |
||||
|
||||
public $lastError = null; |
||||
|
||||
protected $maxId = false; |
||||
|
||||
// see updateSeenHashtags in https://github.com/miguelfreitas/twister-core/blob/master/src/twister.cpp |
||||
protected $hashBreakChars = " \n\t.,:/?!"; |
||||
|
||||
public function __construct($user) |
||||
{ |
||||
$this->user = $user; |
||||
} |
||||
|
||||
public function runRpcCommand($method, $params = array()) |
||||
{ |
||||
$request = new stdClass; |
||||
$request->jsonrpc = '2.0'; |
||||
$request->id = uniqid('', true); |
||||
$request->method = $method; |
||||
$request->params = $params; |
||||
|
||||
if (defined('JSON_UNESCAPED_UNICODE')) { // PHP 5.4+: |
||||
$request_json = json_encode($request, JSON_UNESCAPED_UNICODE); |
||||
} else { // PHP 5.3: |
||||
$request_json = json_encode($request); |
||||
$request_json = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($matches){return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');}, $request_json); |
||||
} |
||||
|
||||
$ch = curl_init(); |
||||
$url = "http://{$this->rpchost}:{$this->rpcport}/"; |
||||
curl_setopt($ch, CURLOPT_URL, $url); |
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
||||
'Authorization: Basic ' . base64_encode($this->rpcuser . ':' . $this->rpcpassword), |
||||
'Content-Type: application/json; charset=utf-8' |
||||
)); |
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_json); |
||||
curl_setopt($ch, CURLOPT_HEADER, 0); |
||||
curl_setopt($ch, CURLOPT_POST, 1); |
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||||
|
||||
$response_json = curl_exec($ch); |
||||
|
||||
if (curl_errno($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200) { |
||||
curl_close($ch); |
||||
return false; |
||||
} |
||||
|
||||
curl_close( $ch ); |
||||
|
||||
$response = json_decode($response_json); |
||||
|
||||
if (!is_object( $response ) || |
||||
(isset( $response->error ) && !is_null($response->error)) || |
||||
!isset( $response->result ) || !isset( $response->id ) || $response->id !== $request->id) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
return $response->result; |
||||
} |
||||
|
||||
public function updateMaxId() |
||||
{ |
||||
$this->lastError = null; |
||||
$this->maxId = -1; |
||||
|
||||
$result = $this->runRpcCommand('getposts', array(1, array(array('username' => $this->user)))); |
||||
if ($result === false || (isset($result->code) && $result->code < 0)) { |
||||
$this->maxId = false; |
||||
$this->lastError = $result; |
||||
return false; |
||||
} |
||||
foreach($result as $item) { |
||||
if (isset($item->userpost->n) && $item->userpost->n === $this->user) { |
||||
$this->maxId = $item->userpost->k; |
||||
} |
||||
} |
||||
|
||||
$result = $this->runRpcCommand('dhtget', array($this->user, 'status', 's')); |
||||
if ($result === false || (isset($result->code) && $result->code < 0)) { |
||||
$this->maxId = false; |
||||
$this->lastError = $result; |
||||
return false; |
||||
} |
||||
foreach($result as $item) { |
||||
if (isset($item->sig_user) && isset($item->p) && $item->sig_user === $this->user) { |
||||
if (isset($item->p->seq)) { |
||||
$this->maxId = max($this->maxId, $item->p->seq); |
||||
} |
||||
if (isset($item->p->v) && isset($item->p->v->userpost) && isset($item->p->v->userpost->k)) { |
||||
$this->maxId = max($this->maxId, $item->p->v->userpost->k); |
||||
} |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
public function postMessage($text) |
||||
{ |
||||
$this->lastError = null; |
||||
|
||||
if ($this->maxId === false) { |
||||
if (!$this->updateMaxId()) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
$k = $this->maxId + 1; |
||||
$result = $this->runRpcCommand('newpostmsg', array($this->user, $k, $text)); |
||||
if (!isset($result->userpost) || !isset($result->userpost->k) || ($result->userpost->k != $k)) { |
||||
$this->maxId = false; |
||||
$this->lastError = $result; |
||||
return false; |
||||
} |
||||
$this->maxId = $k; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
public function prettyPrint($title, $url = '', $tags = null, $maxLen = 140) |
||||
{ |
||||
$title_len = mb_strlen($title); |
||||
$url_len = mb_strlen($url); |
||||
|
||||
if ($url_len === 0) { |
||||
if ($title_len > $maxLen) { |
||||
$text = rtrim(mb_substr($title, 0, $maxLen - 1), ' ') . '…'; |
||||
} else { |
||||
$text = $title; |
||||
} |
||||
} else if ($title_len + 1 + $url_len > $maxLen) { |
||||
$text = rtrim(mb_substr($title, 0, $maxLen - 2 - $url_len), ' ') . '… ' . $url; |
||||
} else { |
||||
$text = $title . ' ' . $url; |
||||
} |
||||
|
||||
if (isset($tags)) { |
||||
foreach ($tags as $tag) { |
||||
$tagText = (string)$tag; |
||||
$tagText = strtr($tagText, $this->hashBreakChars, str_repeat('_', strlen($this->hashBreakChars))); |
||||
$tagText = trim($tagText, '_'); |
||||
$tagText = preg_replace('#(?<=_)_+#', '', $tagText); |
||||
if (!empty($tagText)) { |
||||
$text .= ' #' . $tagText; |
||||
} |
||||
} |
||||
if(mb_strlen($text) > $maxLen) { |
||||
$text = mb_substr($text, 0, $maxLen + 1); |
||||
$pos = mb_strrpos($text, ' '); |
||||
$text = mb_substr($text, 0, $pos); |
||||
} |
||||
} |
||||
|
||||
return $text; |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
<?php |
||||
require("settings.php"); |
||||
$sql="SELECT * |
||||
FROM `rss` |
||||
WHERE `active`='1'"; |
||||
$result=mysql_query($sql) or die(mysql_error()); |
||||
while ($row = mysql_fetch_array($result)) { |
||||
$account=$row['account']; |
||||
$url=$row['url']; |
||||
$id=$row['id']; |
||||
|
||||
echo $account; |
||||
echo $url; |
||||
echo $id; |
||||
$actual_link = "http://".$domain."/cms/loader.php?id=".$id; |
||||
$a = file_get_contents($actual_link); |
||||
echo '<br>'; |
||||
echo($a); |
||||
//if ($a !== "Cannot read rss or it is up to date"){ |
||||
// $datetime=date("d / F / Y ").date('H:i:s'); |
||||
// $sql="UPDATE `rss` SET `lastupdate`='$datetime' WHERE `id`='$id'"; |
||||
// echo $sql; |
||||
// $result=mysql_query($sql) or die(mysql_error()); |
||||
//}else {echo "olo";} |
||||
echo '<br>'; |
||||
} |
||||
|
||||
// open |
||||
?> |
Loading…
Reference in new issue