PDA

View Full Version : postbit_legacy template editing error


ninadbe
03-21-2011, 09:05 PM
I am editing postbit_legacy at "template" table. I want to displaye some images extracted from remote server after 1st post.
My code is as follows

if($post['postcount'] == 1)
{
$dbh=mysql_connect("remote_ip:port", "username", "password") or die
('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("db_name");

code for extracting and displaying image here
}


After editing postbit_legacy with above customized code, I am getting following error


Incorrect key file for table '/tmp/#sql_791b_0.MYI'; try to repair it


When remote server connection string code is removed, I am not getting any errors.

It seems like I am getting error because existing connection is active


Please help me with this problem.

Thanks

Lynne
03-21-2011, 10:56 PM
I'm not sure exactly what you are saying, but you said your were editing the template via the table? Do you mean you were editing it directly in the database? Please don't do that. You should be editing it via the admincp > style manager > find style > edit templates. Also, you cannot put php in templates. Templates are for html only. If you need the output from some php to show up in a template, then you need to create a plugin to run the php code and assign the output to a variable that you would then put into the template.

ninadbe
03-21-2011, 11:05 PM
Yes I were editing templates at database through phpmyadmin.

Is there any help topic regarding how to create plugin and implement output in template?

Lynne
03-21-2011, 11:16 PM
I would suggest download a mod that does that to see how it was done. I'm not sure if there is a help topic because I haven't actually looked for one, but you can take a look in the vB4 Articles forum for one.

ninadbe
03-23-2011, 04:45 PM
Can you please suggest me any plugin that uses remote database connection or use to extract data from other server?
We have vbulletin forum for our site, but our site is located on one server and forum located on another server in order to avoid load.
I want to extract data from main site (which is located on another server) and display it on forum.

I tried lot , searched everywhere. But I not found any specific plugin / mod.

I created custom plugin on my own but it giving errors like
"MySql client ran out of memory"
"Invalid key error"

Please any help would be appreciated.

Thanks

Lynne
03-23-2011, 05:10 PM
Connecting to the database is something you set up in the config.php file. If it is set up correctly there, then you just make a database call and the config.php file points to the correct database. (I have my database on a different server and it works just fine).

Those errors you posted - running out of memory and invalid key error, are server errors and you should talk to your host about them.

ninadbe
03-23-2011, 05:24 PM
I am connecting to the my main site database not vbulletin database.

My vbulleting forum and database are on same server , but main site and its databse are on another server.

I linked forum with main site via Menu Tab.

At config.php I think there is setting for vbulletin database.

Lynne
03-23-2011, 05:38 PM
Then I guess you will need to do this via the mysql_connect that you were talking about earlier. You cannot put it in a template though. You will need to put php in a plugin. I doubt there is any example here that actually shows to php to use for your specific situation of connecting to an external database. You will have to just use regular php/mysql for that.

ninadbe
03-23-2011, 05:58 PM
Yes thats what I have been trying since last, created plugin , hooked it at "SHOWTHREAD" , "postbit" template.

I also tried to include file with following code


ob_start();
require_once('prod_gallery_maker.php');
$creds = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('SHOWTHREAD',array('creds ' => $creds));



Above code gives error


following code do works 60%


ob_start();
$threadtitle = $threadinfo['title'];
require_once('http://sitename.com/prod_gallery_maker.php?t=<?$threadtitle;?>');
$creds = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('SHOWTHREAD',array('creds ' => $creds));



However if I tired above code it works fine. It showing product successfully. But problem is that, I want to show products related to forum title. Therefore why I passed parameters along with it as
require_once('http://sitename.com/prod_gallery_maker.php?t=<?$threadtitle;?>');
but its not working.


It is not passing parameter successfully.

--------------- Added 1300907348 at 1300907348 ---------------

session variables are not working.
Do you it would work with cookie variable? i.e store threadtitle with the help of cookie.

--------------- Added 1300913112 at 1300913112 ---------------

ob_start();
$threadtitle = $threadinfo['title'];
setcookie('threadtitle111',$threadtitle);
require_once('http://naturalparenting.com.au/prod_gallery.php');
$prods = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('postbit_legacy',array('p rods' => $prods));


Dont know why setcookie not working at vbulletin?

Lynne
03-23-2011, 09:01 PM
I do not understand all all what you are doing. If you are putting that code in a plugin, you need to tell us what hook location you are using. - there is no such thing as "hooked it at "SHOWTHREAD" , "postbit" template". You don't hook to a template.

ninadbe
03-23-2011, 09:19 PM
hook : global_start

at postbit_legacy => {vb:raw prods}


It is working, only facing problem with cookie.
I have changed setcookie('threadtitle111',$threadtitle); to vbsetcookie('threadtitle111',$threadtitle);
as setcookie is not working. vbsetcookie works.

It seems like cookies at vbulletin are encrypted.
So cannot fetch cookie at location.

Lynne
03-23-2011, 09:23 PM
I would not pick the global_start template. If you look that template up, you will see it is deprecated and you are supposed to use another one instead (I can't remember which one, but you are told when you look that one up).

ninadbe
03-23-2011, 10:34 PM
I hooked it at showthread_start. Also tried hooking with global_bootstrap_init_start.

Plugin is working with all hooks I have tried so far (global_start, global_bootstrap_init_start, showthread_start etc). As I explained before mine problem is with cookies.

I have set cookies with the help of foolowing code

vbsetcookie('threadtitle111',$threadtitle);


As I said before vbulletin is encrypting cookie. Therefore I cannot get cookie value at included location.
Is there anyway to decode cookies?