vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Proiblems with Templater after datamager thread post (https://vborg.vbsupport.ru/showthread.php?t=315511)

ETS|LuucEarth 11-20-2014 03:02 AM

Proiblems with Templater after datamager thread post
 
Im creating a custom Post-Registration Application system for our use.

On submit all the info is stored in custom profile fields, A post is made with the information in our application review forum.

However Im having a problem with the Template in this system.

If I render the template before the post the post doesnt happen.
If I render the template after the post, the render doesnt happen. IE Blank white page
PHP Code:

    $threaddm = new vB_DataManager_Thread_FirstPost($vbulletinERRTYPE_STANDARD);
    
$threaddm->set_info('forum',$foruminfo);
    
$threaddm->set_info('user'$vbulletin->userinfo);
    
$threaddm->set('forumid'$forumid);
    
$threaddm->set('userid'197);
    
$threaddm->set('title'$threadtitle);
    
$threaddm->set('pagetext'$formoutput); 
    
$threaddm->set('open'TRUE);
    
$threaddm->set('allowsmilie'TRUE);
    
$threaddm->set('visible'TRUE);
    
$threaddm->pre_save();
    
$threadid $threaddm->save();
    unset(
$threaddm);
    
build_thread_counters($threadid);
    
build_forum_counters($forumid); 

PHP Code:

        $navbits construct_navbits($navbits);
        
$navbar render_navbar_template($navbits);
        
$templater vB_Template::create('ets_tester_application_submit');
        
$templater->register_page_templates();
        
$templater->register('navbar'$navbar);
        foreach(
$userdata as $key=>$value){
        
$templater->register($key,$value);
        }
        
print_output($templater->render()); 

Anyone have any ideas on this?

kh99 11-20-2014 08:20 AM

Well, the reason you don't see the post if you render first is because print_output() exits the script, so it doesn't return. Maybe the reason you get a blank page if you render last is because something before it is causing an error, but I don't see offhand what's wrong. If error messages are turned off, maybe you're not seeing the error message?

Edit: if you're seeing the post when you post first, then maybe that means the problem is with one of the build counter functions. Maybe you need to inlcude includes/functions_databuild.php?

ozzy47 11-20-2014 10:16 AM

This is what I use in my mods to make the post, build the thread counters, and if chosen, update the posters post count..

PHP Code:

if ($vbulletin->options['ozzmodz_welcome_thread_active'] AND $vbulletin->options['ozzmodz_welcome_thread_auto_post_email_verify'] == 0)
{
                
        
// Some Declarations
        
global $vbphrase;

        
$postmessage = array(
            
'pagetext1' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_one'],
            
'pagetext2' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_two'],
            
'pagetext3' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_three'],
            
'pagetext4' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_four'],
            
'pagetext5' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_five'],
            
'pagetext6' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_six'],
            
'pagetext7' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_seven'],
            
'pagetext8' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_eight'],
            
'pagetext9' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_nine'],
            
'pagetext10' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_post_ten']
        ); 
        
$rand_text array_rand($postmessage);

        
$title = array(
            
'title1' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_one'],
            
'title2' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_two'],
            
'title3' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_three'],
            
'title4' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_four'],
            
'title5' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_five'],
            
'title6' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_six'],
            
'title7' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_seven'],
            
'title8' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_eight'],
            
'title9' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_nine'],
            
'title10' => $vbulletin->options['ozzmodz_welcome_thread_auto_post_title_ten']
        ); 
        
$rand_title array_rand($title);                                        

        
// Needed Classes
        
require_once(DIR .'/includes/class_dm.php');
        require_once(
DIR .'/includes/class_dm_threadpost.php');
        require_once(
DIR '/includes/functions_databuild.php');
        
$threaddm datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
            
        
$userdata $vbulletin->db->query_first("
            SELECT u.username,u.userid
            FROM " 
TABLE_PREFIX "useractivation AS ua
            LEFT JOIN " 
TABLE_PREFIX "user AS u USING (userid) 
            WHERE ua.activationid = '" 
$vbulletin->db->escape_string($vbulletin->GPC['i']) . "'       
        "
);
        
        
$useridnumber $vbulletin->db->query_first("
            SELECT userid
            FROM " 
TABLE_PREFIX "useractivation
            WHERE activationid = '" 
$vbulletin->db->escape_string($vbulletin->GPC['i']) . "'
            
        "
);           

        
// Some Variables
        //Registered Name
        
$username htmlspecialchars_uni($userdata['username']);
        
//Registered Userid for DBTECH's AUT Mod
        
$mentionuserid $useridnumber['userid'];
        
//Post Icons
        
$posticons_get explode(","$vbulletin->options['ozzmodz_welcome_thread_auto_post_post_icon']);
        
$posticons $posticons_get[array_rand($posticons_get)];
        
//Forum ID To Post To
        
$forumid $vbulletin->options['ozzmodz_welcome_thread_auto_post_forumid'];
        
//Posters ID
        
$postuserid $vbulletin->options['ozzmodz_welcome_thread_auto_post_userid'];
        
//Posters ID?
        
$userid $vbulletin->options['ozzmodz_welcome_thread_auto_post_userid'];
        
//Posters Username
        
$usernames $db->query_first("
            SELECT username 
            FROM " 
TABLE_PREFIX "user 
            WHERE userid = " 
intval($userid));
        
$username2 $usernames['username'] ? $usernames['username'] : 'Guest';
        
//Site Title
        
$bbtitle $vbulletin->options['bbtitle'];
        
//Site URL
        
$url $vbulletin->options['bburl'];
                
$userid2 $useridnumber['userid'];

$vboptions $vbulletin->options;
$bbuserinfo $vbulletin->userinfo;

        
//Post Content
        
$pagetext str_replace(array('$username''$url''$bbtitle''$mentionuserid'), array($username$url$bbtitle$mentionuserid), $postmessage);    
        
//Post Title
        
$title str_replace(array('$username''$url''$bbtitle'), array($username$url$bbtitle), $title);
        
//Allow Smiles (No Option)
        
$allowsmilie '1';
        
//Show Signature (No Option)
        
$showsignature '1';
        
//Moderated (No Option)
        
$visible '1';
        
//Open To Replies
        
$open $vbulletin->options['ozzmodz_welcome_thread_auto_post_close_thread'];
        
//Sticky Thread
        
$sticky $vbulletin->options['ozzmodz_welcome_thread_auto_post_sticky'];
        
//Thread ID To Post To
        
$threadid $vbulletin->options['ozzmodz_welcome_thread_auto_post_thread'];
        
//Thread Counters To Build
        
$threadids $vbulletin->options['ozzmodz_welcome_thread_auto_post_thread'];
        
$ipaddress '000.000.000';

        if (
$vbulletin->options['ozzmodz_welcome_thread_auto_post_how'] AND $userdata['username'] !='')
        {
            
$threaddm datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
            
// Write Into Post Table
            
$threaddm->do_set('forumid'$forumid);
            
$threaddm->do_set('postuserid'$postuserid);
                        
$threaddm->do_set('ipaddress'$ipaddress);
            
$threaddm->do_set('userid'$userid);
            
$threaddm->do_set('title'$title[$rand_title]);
            
$threaddm->do_set('pagetext'$pagetext[$rand_text]);
            
$threaddm->do_set('username'$username2);
            
$threaddm->do_set('open'$open);
            
$threaddm->do_set('sticky'$sticky);
            
$threaddm->do_set('iconid'$posticons);
            
$threaddm->do_set('allowsmilie'$allowsmilie);
            
$threaddm->do_set('showsignature'$showsignature);
            
$threaddm->do_set('visible'$visible);
            
$threaddm->pre_save();
            
            if(
count($threaddm->errors) < 1)
            {
                
$threadid $threaddm->save();
                unset(
$threaddm);
                
build_thread_counters($threaddm);
            }
    
             
build_forum_counters($forumid);
        }
        else
        {
            
$threaddm datamanager_init('Post'$vbulletinERRTYPE_ARRAY'threadpost');
            
// Post As A Reply To A Post
            //$threaddm->do_set('forumid', $forumid);
            
$threaddm->do_set('threadid'$threadid);
                        
$threaddm->do_set('ipaddress'$ipaddress);
            
$threaddm->do_set('parentid'$parentid);
            
$threaddm->do_set('userid'$userid);
            
$threaddm->do_set('title'$title[$rand_title]);
            
$threaddm->do_set('pagetext'$pagetext[$rand_text]);
            
$threaddm->do_set('username'$username2);
            
//$threaddm->do_set('open', $open);
            
$threaddm->do_set('iconid'$posticons);
            
$threaddm->do_set('allowsmilie'$allowsmilie);
            
$threaddm->do_set('showsignature'$showsignature);
            
$threaddm->do_set('visible'$visible);
            
$threaddm->pre_save();
            
            if(
count($threaddm->errors) < 1)
            {
                
$threadid $threaddm->save();
                unset(
$threaddm);
                
build_thread_counters($threadids);
                
            
build_forum_counters($forumid);    
            }
        }         

        
// Update Post Count For Poster
        
if ($vbulletin->options['ozzmodz_welcome_thread_auto_post_count_posts'])
        {
            
$posts $vbulletin->db->query_first("
                SELECT posts
                 FROM " 
TABLE_PREFIX "user
                  WHERE userid = "
.$vbulletin->options['ozzmodz_welcome_thread_auto_post_userid']."
               "
);
    
             
$newpostcount $posts['posts'] + 1;
    
             
$vbulletin->db->free_result($posts);
    
             
$vbulletin->db->query_write("
                 UPDATE " 
TABLE_PREFIX "user
                 SET posts = "
.$newpostcount."
                  WHERE userid = "
.$vbulletin->options['ozzmodz_welcome_thread_auto_post_userid']."
               "
);
        }



ETS|LuucEarth 11-20-2014 06:55 PM

I found the issue. One of my fellow coders was using $userdata[] in their code globally on a userdata_postsave plugin. This was throwing a fatal error Call to a member function fetch_field() on a non-object I changed my $userdata to $usrdata and the problem went away completely.

However I did notice one other thing in the logs.

I get 10 or so of these

14:49:26 PHP Warning: Illegal offset type in isset or empty in /var/www/dev.elitetestingservices.com/public_html/vb/phrase.php on line 339 error
14:49:26 PHP Warning: Illegal offset type in /var/www/dev.elitetestingservices.com/public_html/vb/phrase.php on line 334

Im calling phrases in part of my code, maybe you can tell me what Ive done wrong

PHP Code:

       $titles=new vB_Phrase ('cprofilefield',$key.'_title');
       
$title=vB_Phrase::fetchPhrase($titles,null); 

The code works and pulls the data properly but I would love to get rid of the warinings

kh99 11-20-2014 07:13 PM

I'm not familiar with the vB_Phrase class, but looking at the code, it seems that that warning is happening because you're passing null as the second parameter to fetchPhrase(). You say it works so I guess it's OK to do that, but I don't know what that's supposed to do or what you could do instead.

ETS|LuucEarth 11-20-2014 07:16 PM

its a parameters for passing {option} type of things to the phrase. However these phrases do not use them. I could try something else in there I guess I added null to get rid of the Missing 2nd argument warnings

kh99 11-20-2014 07:20 PM

Well, now that I think about it a little more, I really was making a guess. It may not be the null. But I suppose it's easy enough to try.

kh99 11-20-2014 07:34 PM

Oh, yeah, I was being an idiot. I'm pretty sure the problem is really that the first argument should be a string but you're passing the vB_Phrase object. It looks llike the parameters should be the phrase group and the phrasekey, which I believe is the phrase name.

ETS|LuucEarth 11-20-2014 08:07 PM

I believe you are correct after I look at the documentation again.

static fetchPhrase (line 333)
Fetches a rendered phrase.

If the phrase is not in the local phrase cache, then the phrasekey cache is loaded and purged.

return: - The translated phrase
access: public
static string fetchPhrase (string $phrasegroup, string $phrasekey, [array $parameters = array()])
string $phrasegroup:
The phrase group where the phrase is located
string $phrasekey:
The phrasekey of the phrase
array $parameters: mixed - Array of parameters to parse into the phrase


That will teach me to code until 4am lol


***EDIT***

PHP Code:

$title=vB_Phrase::fetchPhrase('cprofilefield',$key."_title"NULL); 

That solved the warning Thanks kh99 and Ozzy47 for all the help Product nearly done now!


All times are GMT. The time now is 07:28 PM.

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.01287 seconds
  • Memory Usage 1,882KB
  • 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
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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