V
volk15
Гость
-- page_header.tpl найти
HTML:
<table cellspacing="0" cellpadding="0" width="100%">
...
</table>
HTML:
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="50%">
<!-- IF SHOW_LATEST_NEWS -->
<h3>{L_LATEST_NEWS}</h3>
<table cellpadding="0">
<!-- BEGIN news -->
<tr>
<td><div class="news_date">{news.NEWS_TIME}</div></td>
<td width="100%">
<div class="news_title<!-- IF news.NEWS_IS_NEW --> new<!-- ENDIF -->"><a href="{news.NEWS_TOPIC_ID}">{news.NEWS_TITLE}</a></div>
</td>
</tr>
<!-- END news -->
</table>
<!-- ENDIF -->
</td>
<!-- IF SHOW_NETWORK_NEWS -->
<td width="50%">
<script type="text/javascript">
function news() {
var url = prompt("Поделиться интересной новостью с сайтов:\n gameland.ru", "http://");
if (!url) return false;
ajax.news(url);
return false;
}
ajax.news = function(url) {
$('#load').html('<img src="images/pic_loading.gif" align="right" title="Ваша новость оформляется" width="18px;" height="18px;" return false; />');
ajax.exec({
action : 'news',
url : url,
});
};
ajax.callback.news = function(data) {
$('#load').hide();
};
</script>
<h3><span onclick="news(); return false;" style="cursor: pointer;" class="menu-root" title="Оформить новость">{L_NETWORK_NEWS}<span id="load"></span></h3>
<table cellpadding="0">
<!-- BEGIN net -->
<tr>
<td><div class="news_date">{net.NEWS_TIME}</div></td>
<td width="100%">
<div class="news_title<!-- IF net.NEWS_IS_NEW --> new<!-- ENDIF -->"><a href="{TOPIC_URL}{net.NEWS_TOPIC_ID}">{net.NEWS_TITLE}</a></div>
</td>
</tr>
<!-- END net -->
</table>
</td>
<!-- ENDIF -->
</tr>
</table>
-- ajax.php
найти
Код:
break;
-- вставить
Код:
case 'news':
require(INC_DIR .'news.php');
require(INC_DIR .'bbcode.php');
require(INC_DIR .'functions_post.php');
break;
-- найти
Код:
'change_tor_status' => array('user'),
-- вставить
Код:
'news' => array('user'),
-- найти
Код:
function index_data()
{
require(AJAX_DIR .'index_data.php');
}
-- вставить
Код:
function news()
{
require(AJAX_DIR .'news.php');
}
создать ajax/news.php
содержимое:
PHP:
<?php
if (!defined('IN_AJAX')) die(basename(__FILE__));
global $lang, $bb_cfg, $userdata;
$url = (string) $this->request['url'];
preg_match("/^(http:\/\/)?([^\/]+)/i", $url, $matches);
$host = $matches[2];
preg_match("/[^\.\/]+/", $host, $m);
if (!function_exists($m[0])) $this->ajax_die('Кривая ссылка');
$html = $m[0] ($url); // text
$this->responce['url'] = $html;
создать includes/news.php
PHP:
<?php
if (!defined('BB_ROOT')) die(basename(__FILE__));
function gameland($url)
{
global $bb_cfg, $userdata;
$news = file_get_contents($url);
$news = iconv('windows-1251', 'utf-8', $news);
preg_match_all('#<h1>([\s\S]*?)</h1>#si', $news, $s);
$pos = strpos($news, '<div class="post">');
$news = substr($news, $pos);
$news = $news;
$pos = strpos($news, '<div class="blocks_content_pad">');
$news = substr($news, 0, $pos);
$news = preg_replace('/<a.*?>.*?last="1" src="(.*?)"><\/a>/', '[align=center][img]http://gameland.ru$1[/img][/align]', $news);
$news = preg_replace('/<strong>(.*?)<\/strong>/', '[b]$1[/b]', $news);
$news = preg_replace('/<p>(.*?)<\/p>/', "$1\n", $news);
$news = preg_replace('/<em .*?>(.*?)<\/em>/', '[i]$1[/i]', $news);
$news = preg_replace('/<a.*?href="\/(.*?)".*?>(.*?)<\/a>/', '[url=http://gameland.ru/$1]$2[/url]', $news);
$news = preg_replace('/<a.*?href="(.*?)".*?>(.*?)<\/a>/', '[url=$1]$2[/url]', $news);
$news = preg_replace('/<img.*?src="(.*?)".*?>/', '[img]http://gameland.ru/$1[/img]', $news);
$news = strip_tags(html_entity_decode('[size=14]'.$news.'[/size]'));
$message = DB()->escape($news);
$subject = DB()->escape($s[1][0]);
$fid = 2; // id форума
$topic = topic($message, $subject, $fid);
return $topic;
}
function topic($message, $subject, $fid)
{
global $bb_cfg, $userdata, $datastore;
$uid = $userdata['user_id'];
$username = $userdata['username'];
DB()->query("INSERT ".BB_TOPICS." (forum_id, topic_title, topic_poster, topic_time) VALUES ($fid, '$subject', $uid, ".TIMENOW.")");
$tid = DB()->sql_nextid();
DB()->query("INSERT ".BB_POSTS." (topic_id, forum_id, poster_id, post_time, poster_ip) VALUES ($tid, $fid, $uid, '".TIMENOW."', '".$userdata['user_last_ip']."')");
$pid = DB()->sql_nextid();
DB()->query("UPDATE " . BB_TOPICS . " SET topic_first_post_id = $pid, topic_last_post_id = $pid, topic_last_post_time = ".TIMENOW." WHERE topic_id = $tid");
DB()->query("INSERT ". BB_POSTS_TEXT ." (post_id, post_text) VALUES ($pid, '$message')");
DB()->query("UPDATE " . BB_USERS . " SET user_posts = user_posts +1 WHERE user_id = $pid");
DB()->query("UPDATE " . BB_FORUMS . " SET forum_last_post_id = $pid, forum_posts = forum_posts +1, forum_topics = forum_topics + 1 WHERE forum_id = $fid");
update_post_html(array(
'post_id' => $pid,
'post_text' => $message,
));
if($bb_cfg['show_latest_news'])
{
$news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id']));
if(isset($news_forums[$fid]) && $bb_cfg['show_latest_news'])
{
$datastore->enqueue('latest_news');
$datastore->update('latest_news');
}
}
if($bb_cfg['show_network_news'])
{
$net_forums = array_flip(explode(',', $bb_cfg['network_news_forum_id']));
if(isset($net_forums[$fid]) && $bb_cfg['show_network_news'])
{
$datastore->enqueue('network_news');
$datastore->update('network_news');
}
}
return $pid;
}
Обновлено: 12.10.2012