L
ler
Гость
Еще парочка странных вопросов.
Как записать запрос в кеш
Как указать время жизни кеша
Как вытащить из кэша
Как записать запрос в кеш
Как указать время жизни кеша
Как вытащить из кэша
Как записать запрос в кеш
CACHE('bb_cache')->set($cache_name, $cache_data, 180);
Как вытащить из кэша
CACHE('bb_cache')->get($cache_name);
if (!$data = CACHE('bb_cache')->get('cached_data'))
{
$data = ...
CACHE('bb_cache')->set('cached_data', $data, 180);
}
<?php
$forum_sql = '5'; // Из каких форумов брать
$per_page = '30'; // Раздач на страницу
define('IN_FORUM', true);
define('BB_SCRIPT', 'cccp');
define('BB_ROOT', './');
require(BB_ROOT ."common.php");
require(INC_DIR .'bbcode.php');
if ($bb_cfg['show_latest_news'])
{
$datastore->enqueue('latest_news');
}
// Start session management
$user->session_start();
$start = ( isset($_GET['start']) ) ? intval($_GET['start']) : 0;
$search = ( isset($_GET['search']) ) ? $_GET['search'] : '';
if (isset($_POST['mode']) || isset($_GET['mode']))
{
$mode = (isset($_POST['mode'])) ? $_POST['mode'] : $_GET['mode'];
}
$sql = "SELECT COUNT(t.topic_id) as topic_count
FROM " . BB_TOPICS . " AS t
WHERE t.forum_id IN ($forum_sql)";
if ( !($result = DB()->sql_query($sql)) )
{
bb_die ('Ошибка подключения');
}
$row = DB()->sql_fetchrow($result);
$topic_count = ( $row['topic_count'] ) ? $row['topic_count'] : 0;
DB()->sql_freeresult($result);
if ($topic_count)
{
if (!$row = CACHE('cccp')->get('cccp_tile_count'.$start.$mode.$search))
{
$sql = "SELECT t.*, pt.*, p.post_id, u.username, u.user_id, u.user_rank, tr.size, tr.attach_id
FROM " . BB_TOPICS . " AS t,
" . BB_USERS . " AS u,
" . BB_POSTS_HTML . " AS pt,
" . BB_POSTS . " AS p,
" . BB_BT_TORRENTS . " AS tr
WHERE t.forum_id IN ($forum_sql)
AND t.topic_poster = u.user_id
AND t.topic_first_post_id = pt.post_id
AND t.topic_first_post_id = p.post_id
AND t.topic_id= tr.topic_id
AND t.topic_status <> 2
ORDER BY t.topic_time DESC
LIMIT $start, $per_page";
CACHE('cccp')->set('cccp_tile_count'.$start.$mode.$search, $row, 3600);
}
if ( !($result = DB()->sql_query($sql)) )
{
bb_die ('Ошибка подключения');
}
$topics = DB()->sql_fetchrowset($result);
for ($i = 0; $i < count($topics); $i++)
{
preg_match_all('/<var class="postImg postImgAligned img-(.*?)" title="(.*?)"> <\/var>/', $topics[$i]['post_html'], $poster, PREG_SET_ORDER);
preg_match_all('/<var class="postImg" title="(.*?)"> <\/var>/', $topics[$i]['post_html'], $poster2, PREG_SET_ORDER);
$url = '';
if (@$poster[0][2])
{
$url = $poster[0][2];
}
elseif (@$poster2[0][1])
{
$url = $poster2[0][1];
}
$template->assign_block_vars('topics', array(
'TOPIC_TITLE' => wbr(str_short($topics[$i]['topic_title'], 35)),
'U_VIEW_TOPIC' => TOPIC_URL . $topics[$i]['topic_id'],
'SIZE' => humn_size($topics[$i]['size']),
'TOPIC_POSTER_ID' => $topics[$i]['user_id'],
'POSTER_IMG' => '<img border="1" src="'.$url.'" align="center" style="margin-bottom:8px;margin-center:8px;width:150px;height:200px;">',
'DOWNLOAD' => '<a href="dl.php?id='. $topics[$i]['attach_id'] .'"><img alt="" height="27" src="styles/images/icon_dn.gif" width="35"></a>',
));
}
$url = ($search) ? "cccp.php?mode=$mode&search=$search" : "cccp.php?mode=cccp";
$pagination = generate_pagination($url, $topic_count, $per_page, $start);
$template->assign_vars(array(
'PAGINATION' => $pagination,
'PAGE_NUMBER' => sprintf($lang['PAGE_OF'], ( floor( $start / $per_page ) + 1 ), ceil( $topic_count / $per_page )),
'U_PER_PAGE' => $url,
'PER_PAGE' => $per_page,
));
}
else
{
$template->assign_block_vars('no_topics', array());
}
$template->assign_vars(array(
'PORTAL' => true,
'PAGE_TITLE' => 'Наши фильмы 60fps',
'L_STATISTICS' => $lang['STATISTICS'],
'L_DESCRIPTION' => $lang['DESCRIPTION'],
));
print_page('portal.tpl');
?>
<?php
$forum_sql = '5'; // Из каких форумов брать
$per_page = '30'; // Раздач на страницу
define('IN_FORUM', true);
define('BB_SCRIPT', 'cccp');
define('BB_ROOT', './');
require(BB_ROOT ."common.php");
require(INC_DIR .'bbcode.php');
if ($bb_cfg['show_latest_news'])
{
$datastore->enqueue('latest_news');
}
// Start session management
$user->session_start();
$start = ( isset($_GET['start']) ) ? intval($_GET['start']) : 0;
$search = ( isset($_GET['search']) ) ? $_GET['search'] : '';
if (isset($_POST['mode']) || isset($_GET['mode']))
{
$mode = (isset($_POST['mode'])) ? $_POST['mode'] : $_GET['mode'];
}
$sql = "SELECT COUNT(t.topic_id) as topic_count
FROM " . BB_TOPICS . " AS t
WHERE t.forum_id IN ($forum_sql)";
if ( !($result = DB()->sql_query($sql)) )
{
bb_die ('Ошибка подключения');
}
$row = DB()->sql_fetchrow($result);
$topic_count = ( $row['topic_count'] ) ? $row['topic_count'] : 0;
DB()->sql_freeresult($result);
if ($topic_count)
{
if (!$topics = CACHE('cccp')->get('cccp_tile_count'.$start.$mode.$search))
{
$topics =DB()->fetch_rowset( "SELECT t.*, pt.*, p.post_id, u.username, u.user_id, u.user_rank, tr.size, tr.attach_id
FROM " . BB_TOPICS . " AS t,
" . BB_USERS . " AS u,
" . BB_POSTS_HTML . " AS pt,
" . BB_POSTS . " AS p,
" . BB_BT_TORRENTS . " AS tr
WHERE t.forum_id IN ($forum_sql)
AND t.topic_poster = u.user_id
AND t.topic_first_post_id = pt.post_id
AND t.topic_first_post_id = p.post_id
AND t.topic_id= tr.topic_id
AND t.topic_status <> 2
ORDER BY t.topic_time DESC
LIMIT $start, $per_page");
CACHE('cccp')->set('cccp_tile_count'.$start.$mode.$search, $topics, 3600);
}
for ($i = 0; $i < count($topics); $i++)
{
preg_match_all('/<var class="postImg postImgAligned img-(.*?)" title="(.*?)"> <\/var>/', $topics[$i]['post_html'], $poster, PREG_SET_ORDER);
preg_match_all('/<var class="postImg" title="(.*?)"> <\/var>/', $topics[$i]['post_html'], $poster2, PREG_SET_ORDER);
$url = '';
if (@$poster[0][2])
{
$url = $poster[0][2];
}
elseif (@$poster2[0][1])
{
$url = $poster2[0][1];
}
$template->assign_block_vars('topics', array(
'TOPIC_TITLE' => wbr(str_short($topics[$i]['topic_title'], 35)),
'U_VIEW_TOPIC' => TOPIC_URL . $topics[$i]['topic_id'],
'SIZE' => humn_size($topics[$i]['size']),
'TOPIC_POSTER_ID' => $topics[$i]['user_id'],
'POSTER_IMG' => '<img border="1" src="'.$url.'" align="center" style="margin-bottom:8px;margin-center:8px;width:150px;height:200px;">',
'DOWNLOAD' => '<a href="dl.php?id='. $topics[$i]['attach_id'] .'"><img alt="" height="27" src="styles/images/icon_dn.gif" width="35"></a>',
));
}
$url = ($search) ? "cccp.php?mode=$mode&search=$search" : "cccp.php?mode=cccp";
$pagination = generate_pagination($url, $topic_count, $per_page, $start);
$template->assign_vars(array(
'PAGINATION' => $pagination,
'PAGE_NUMBER' => sprintf($lang['PAGE_OF'], ( floor( $start / $per_page ) + 1 ), ceil( $topic_count / $per_page )),
'U_PER_PAGE' => $url,
'PER_PAGE' => $per_page,
));
}
else
{
$template->assign_block_vars('no_topics', array());
}
$template->assign_vars(array(
'PORTAL' => true,
'PAGE_TITLE' => 'Наши фильмы 60fps',
'L_STATISTICS' => $lang['STATISTICS'],
'L_DESCRIPTION' => $lang['DESCRIPTION'],
));
print_page('portal.tpl');
?>