There are:
domen 1 - forum, vB 3.7.0,
cp1251
domen 2 - site, Wordpress,
utf-8
Task:
5 last new threads from forum (domen 1) at site (domen 2).
This file is in a folder
http://www._forumname_.ru/include/cron/ and it should generate once at hour file
cron_newthreads.html which included in WordPress:
PHP Code:
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db)) {
exit;
}
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
// ###### Start of settings ######
// directory of forum (without "/" at and)
// full domenname, if forum and site in others domens
$forumdir = "http://www._forumname_.ru";
// private forums (IDs)
$privateforumid = "70,95,99,108,109,124,129,142,153,154,155";
// limit to show
$showlimit = "5";
// only this forum to show (ID)
$and_fid = "";
// ###### End of settings ######
if(empty($and_fid) OR $and_fid == '0') {
$and_forumid = '';
}
else {
$and_forumid = " AND forumid = $and_fid ";
}
if(empty($privateforumid) OR $privateforumid == '0') {
$priv_forumid = '';
}
else {
$priv_forumid = " AND forumid NOT IN ($privateforumid) ";
}
if(empty($showlimit) OR $showlimit == '0') {
$showlimit = '5';
}
$result = $vbulletin->db->query_read("SELECT threadid,
lastposter,
dateline,
title,
postusername,
T.lastpost AS lastpostdate,
views,
postuserid,
replycount,
U.userid as userid
FROM ".TABLE_PREFIX."thread T
LEFT JOIN ".TABLE_PREFIX."user U ON (T.lastposter = U.username)
WHERE 1=1 $priv_forumid $and_forumid
ORDER BY dateline DESC
LIMIT $showlimit");
ob_start();
while ($lastx_thread = $vbulletin->db->fetch_array($result)) {
if($stylevar['charset'] != 'UTF-8') {
if(@function_exists('mb_convert_encoding')) {
$lastx_thread['title'] = mb_convert_encoding($lastx_thread['title'], 'UTF-8', $stylevar['charset']);
$lastx_thread['lastposter'] = mb_convert_encoding($lastx_thread['lastposter'], 'UTF-8', $stylevar['charset']);
}
else {
$lastx_thread['title'] = iconv($stylevar['charset'], 'UTF-8', $lastx_thread['title']);
$lastx_thread['lastposter'] = iconv($stylevar['charset'], 'UTF-8', $lastx_thread['lastposter']);
}
}
echo "<li>".date("d.m.y, H:i",$lastx_thread['dateline'])."<br /><a href='$forumdir/showthread.php?t=".$lastx_thread['threadid']."' target='_blank'>".$lastx_thread['title']."</a></li>
";
}
$html = ob_get_clean();
file_put_contents(DIR.'/cron_newthreads.html', $html);
log_cron_action('', $nextitem, 1);
?>
And all works perfectly if I press the button
Run now in admincp (Scheduled Task Manager). But if the scheduled task starts itself automatically, the generated file is created with the incorrect coding (see attach).
Why??? What is wrong?