PDA

View Full Version : Need Help with plugin that's not in forum root


EquinoxWorld
08-04-2011, 02:18 AM
Hello everyone, I am currently trying to utilize a part of a file as a plugin. I want to be able to sue this same file for several plugins to reduce number of files. The other issue is that this file is not in the forum root.

Here is the plugin:

Location Global Start
vb version 4.1.5

ob_start();
require_once('.intuitco/cotw/functions/cotw_func_contest_num.php?do=sotw');
$cotw_sotw_contests_number = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('COTW_SOTW',array('cotw_s otw_contests_number' => $cotw_sotw_contests_number));

As you can see the file is in httpdocs(forum root)/intuitco/cotw/functions/ . Also I am trying to use it as php?do=x , not sure if that is valid though when using it as a plugin. When I activate this plugin I get a internal server error, when disabled the page loads fine.

If anyone has any ideas or any additional info that might be useful please do let us know. Thank you for your time everyone.

kh99
08-04-2011, 02:34 AM
One thing I notice, you say the file is in intuitco/cotw/functions directory but you've got .intuitco in the file name (maybe you meant ./intuitco). But anyway, I don't think you can put ?do=sotw on the file name, but this might work:

require_once('http://www.domain.com/intuitco/cotw/functions/cotw_func_contest_num.php?do=sotw');


(of course you'd replace www.domain.com with your domain name).


Another alternative might be something like:

$savedo = $_GET['do'];
$_GET['do'] = 'sotw';
ob_start();
require_once('./intuitco/cotw/functions/cotw_func_contest_num.php');
$cotw_sotw_contests_number = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('COTW_SOTW',array('cotw_s otw_contests_number' => $cotw_sotw_contests_number));

$_GET['do'] = $savedo;


but I'm not sure, I've never tried that, and it probably depends on what the included script actually does.

EquinoxWorld
08-04-2011, 02:50 AM
One thing I notice, you say the file is in intuitco/cotw/functions directory but you've got .intuitco in the file name (maybe you meant ./intuitco). But anyway, I don't think you can put ?do=sotw on the file name, but this might work:

require_once('http://www.domain.com/intuitco/cotw/functions/cotw_func_contest_num.php?do=sotw');


(of course you'd replace www.domain.com with your domain name).


Another alternative might be something like:

$savedo = $_GET['do'];
$_GET['do'] = 'sotw';
ob_start();
require_once('./intuitco/cotw/functions/cotw_func_contest_num.php');
$cotw_sotw_contests_number = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('COTW_SOTW',array('cotw_s otw_contests_number' => $cotw_sotw_contests_number));

$_GET['do'] = $savedo;


but I'm not sure, I've never tried that, and it probably depends on what the included script actually does.

Well the second code you suggested did eliminate the error but the value does not show though. I beleive it has to do with the php?do= part. Here is the file I am using:

<?php
//===================================Contests Number==================================//
//Require This is required everywhere//
require_once('./global.php');
//This protection si also required//
define('CSRF_PROTECTION', true);
//================================First Contest:Signature Of The Week=======================================//
//==============================NOTHING IS CHANGED BEYOND THIS LINE!!!!!====================================//
//================================================== ================================================== ======//
if ($_REQUEST['do'] == 'sotw')

{
$result = $db->query_read("SELECT id FROM cotw_sotw_time_end ORDER BY id DESC LIMIT 1");
$row = mysql_fetch_row($result);
echo $row[0];
}
//================================================== ================================================== =====//
//===================================Second Contest:Avatar Of The Week=====================================//
//==============================NOTHING IS CHANGED BEYOND THIS LINE!!!!!====================================//
//================================================== ================================================== ======//
if ($_REQUEST['do'] == 'aotw')

{
$result = $db->query_read("SELECT id FROM cotw_aotw_time_end ORDER BY id DESC LIMIT 1");
$row = mysql_fetch_row($result);
echo $row[0];
}
//================================================== ================================================== ======//
//=================================END OF PRINTING CURRENT CONTEST NUMBER===================================//
//================================================== ================================================== ======//
?>

I could just use two seperate files but it seems a waste to have to use 2 files to do such a simple operation....Any ideas? :confused:

kh99
08-04-2011, 02:55 AM
I think that all boils down to a plugin with this code:

$row = $db->query_first("SELECT id FROM cotw_sotw_time_end ORDER BY id DESC LIMIT 1");
$cotw_sotw_contests_number = $row['id'];
vB_Template::preRegister('COTW_SOTW',array('cotw_s otw_contests_number' => $cotw_sotw_contests_number));


I suppose you could put that query in a file and include() it if the code is used in more than one place.

EquinoxWorld
08-04-2011, 02:59 AM
I think that all boils down to a plugin with this code:

$row = $db->query_first("SELECT id FROM cotw_sotw_time_end ORDER BY id DESC LIMIT 1");
$cotw_sotw_contests_number = $row['id'];
vB_Template::preRegister('COTW_SOTW',array('cotw_s otw_contests_number' => $cotw_sotw_contests_number));


I suppose you could put that query in a file and include() it if the code is used in more than one place.

Well that worked! No need for a file, even better! Thanks for the help kh99, as always very helpful. :) I didn;t even know you could run queries from there like that... Opens up more possibilities :up:

--------------- Added 1312430497 at 1312430497 ---------------

Can I do this in the same plguin?

$row = $db->query_first("SELECT id FROM cotw_sotw_time_end ORDER BY id DESC LIMIT 1");
$cotw_sotw_contests_number = $row['id'];
$row2 = $db->query_first("SELECT id FROM cotw_aotw_time_end ORDER BY id DESC LIMIT 1");
$cotw_aotw_contests_number = $row2['id'];
vB_Template::preRegister('COTW_SOTW',array('cotw_s otw_contests_number' => $cotw_sotw_contests_number));
vB_Template::preRegister('COTW_SOTW',array('cotw_a otw_contests_number' => $cotw_aotw_contests_number));