vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Strtange issue with cron und charset (https://vborg.vbsupport.ru/showthread.php?t=202857)

Pessimist 01-23-2009 08:05 PM

Strtange issue with cron und charset
 
1 Attachment(s)
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?

Dismounted 01-24-2009 02:44 AM

Did you check the values in $stylevar? My guess is that $stylevar is not available when running the task normally.

Pessimist 01-24-2009 12:28 PM

Dismounted
Sorry, I'm not programmer.

How I can check up it, what it is necessary to make?

Lynne 01-24-2009 04:47 PM

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! :D )

Pessimist 01-25-2009 08:23 AM

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! :D )
It is really my eye, little bit edited (color) in the Photoshop :)


All times are GMT. The time now is 01:03 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01085 seconds
  • Memory Usage 1,768KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete