Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-23-2009, 08:05 PM
Pessimist's Avatar
Pessimist Pessimist is offline
 
Join Date: Aug 2006
Location: Europa
Posts: 28
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Strtange issue with cron und charset

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(''$nextitem1);

?>

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?
Attached Images
File Type: gif wrong_charset.gif (3.3 KB, 0 views)
Reply With Quote
  #2  
Old 01-24-2009, 02:44 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you check the values in $stylevar? My guess is that $stylevar is not available when running the task normally.
Reply With Quote
  #3  
Old 01-24-2009, 12:28 PM
Pessimist's Avatar
Pessimist Pessimist is offline
 
Join Date: Aug 2006
Location: Europa
Posts: 28
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dismounted
Sorry, I'm not programmer.

How I can check up it, what it is necessary to make?
Reply With Quote
  #4  
Old 01-24-2009, 04:47 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think what he's saying is you may need to make $stylevar a global so it is available for you to use:

PHP Code:
global $stylevar
(Your eye avatar freaks me out! )
Reply With Quote
  #5  
Old 01-25-2009, 08:23 AM
Pessimist's Avatar
Pessimist Pessimist is offline
 
Join Date: Aug 2006
Location: Europa
Posts: 28
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have replaced
PHP Code:
    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']);
    } 
with
PHP Code:
    if(@function_exists('mb_convert_encoding')) {
      
$lastx_thread['title'] = mb_convert_encoding($lastx_thread['title'], 'UTF-8''cp1251');
      
$lastx_thread['lastposter'] = mb_convert_encoding($lastx_thread['lastposter'], 'UTF-8''cp1251');
    }
    else {
      
$lastx_thread['title'] = iconv('cp1251''UTF-8'$lastx_thread['title']);
      
$lastx_thread['lastposter'] = iconv('cp1251''UTF-8'$lastx_thread['lastposter']);
    } 
And now works for me

Quote:
(Your eye avatar freaks me out! )
It is really my eye, little bit edited (color) in the Photoshop
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:32 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.13067 seconds
  • Memory Usage 2,272KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (1)postbit_attachment
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete