vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [vBulletin 4] Simple way of including an external PHP file (https://vborg.vbsupport.ru/showthread.php?t=242454)

webmaster74 12-10-2010 10:51 AM

Quote:

Originally Posted by webmaster74 (Post 2108292)
I created this plug-in and activated it.

ob_start();
include('/home/mydomain/public_html/php/includes/ineverypost.inc.php');
$includedineverypost = ob_get_contents();
ob_end_clean();


vB_Template::preRegister('postbit_display_complete ',array('includedineverypost' => $includedineverypost));

in vb 3.8.6, this was hooked to 'postbit_display_complete'

Now with VB4, there is no template for post_display_complete....

I tried "postbit" it did notwork. I tried other postbit related templates, this still did not work.

any help ??


any generous person wants to share his knowledge ?

--------------- Added 11 Dec 2010 at 03:23 ---------------

would any kind person help with this ?

BirdOPrey5 12-22-2010 01:32 AM

postbit_display_complete is a php code hook... not a template... the template is named postbit and it's the same in VB3 and VB4.

fluidswork 12-22-2010 01:15 PM

Nice idea i will give this a try ..........

aileron79 12-22-2010 02:24 PM

Hi everybody,
sorry in advance for me maybe talking rubbish, but I am completely new to developing plugin code for vbulletin. I am quite experienced in coding PHP, though. Boofo pointed me in the right direction (thanks for that), but, however, I am still facing the following problem:

I want to extend the list of online users (online.php) by another column. Information within that column is not extracted from the database but fetched from a third party. This has to be done for each user that shows up in the list of online users - but I have no idea which hook I may use.

At the moment, my plugin works pretty fine - but it is a bad mixture of source code hacking and template modifications. If any future upgrade replaces online.php, all my changes are gone. I added a very few lines of code in online.php (v4.1.0 PL2) starting from line 414, which basically adds another value to the $userinfo array which (as if this variable is registered) can be accessed from the whoisonlinebit template, where the output is generated from the additional value.

As mentioned before - so far, everything works fine but I truly hate source code modifications as they are gone after an update. Therefore, it would be great to know if there is another way of executing code (maybe in an external file) for each line in the result set. If I interpret the PHP source in online.php correctly, anything that should be executed for each user name should go inside the while loop on line 393. The instructions above explain how to use external files with hooks but I just can't figure out which hook to use in that case...

Is there a way to execute PHP code from templates without having a hook?

As I said, I am completely new to this stuff, please help...

BirdOPrey5 12-22-2010 03:38 PM

There's a hook at the very end of the while loop:
PHP Code:

        ($hook vBulletinHook::fetch_hook('online_user')) ? eval($hook) : false

So if you can use that hook, "online_user."

aileron79 12-22-2010 04:33 PM

Indeed, I have found that hook and I thought it would be what I was looking for, but obviously this hook only affects spiders/guests, according to the comment on line 449:

PHP Code:

while ($users $db->fetch_array($allusers))
{
    if (
$users['userid'])
    { 
// Reg'd Member
...
    }
    else
    { 
// Guest or Spider..
        
$spider '';
...

        
$guests["$count"]['count'] = $count 1;
        
$guests["$count"]['useragent'] = htmlspecialchars_uni($users['useragent']);
        
$count++;

        (
$hook vBulletinHook::fetch_hook('online_user')) ? eval($hook) : false;
    }


The hook is inside the else branch which obviously handles unregistered users, the code I have added is in the if branch... Did I misinterpret anything...?

BirdOPrey5 12-22-2010 04:49 PM

Probably not... although it's of no use when releasing a mod to others you can add your own hooks to the code anywhere you want- so if it's just for you adding a 1 line hook and keeping the bulk of the code in a plugin will make life easier than keeping all edits in the files.

aileron79 12-22-2010 08:48 PM

Thanks for replying to fast! Well, that of course would be possible and still, this is probably the best idea. I still could add instructions on how to create the custom hook in my install guide. However, I consider this hook a bug... I just can't believe it makes any sense in that position. But as mentioned before, I am quite new to this plugin system, probably I just do not understand enough...

But am I right that there is no way to achieve what I want without modifying the original vb source code?

BirdOPrey5 12-22-2010 11:20 PM

Quote:

Originally Posted by aileron79 (Post 2137787)
But am I right that there is no way to achieve what I want without modifying the original vb source code?

Best I can tell if you really need that location you would have to manually edit the source code but I'm far from an 'expert' on this topic myself.

However if you're fetching data from an external source could you not just "run the loop" a second time and collect the data needed per user id, and put the data in an array who's keys are the userid's themselves so it's say $mydata[1] for userid 1, $mydata[200] for user 200, etc... then call it in the template where needed (after pre-registering it of course.)

robert garrett 12-30-2010 12:43 PM

PHP Code:

ob_start();
  require_once(
'/home/echoca/public_html/news/journals1.php');
  
$php_journal ob_get_contents();
ob_end_clean();
vB_Template::preRegister('echo_journals',array('php_journal' => $php_journal)); 

tried also leaving custom_ out this is not working at all.

global bootstrap init start, is the hook I am using. I had some bugs in the code when I first included it, and it showed up as I worked the bugs out, and the code ran clean, it made it through the hook. Thats great. I clicked on the tab, that is linked to the template I added it to, and it just wont display Ideas anybody?

RG


All times are GMT. The time now is 03:11 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.01202 seconds
  • Memory Usage 1,755KB
  • 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
  • (3)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete