View Full Version : Idiot Admin PHP
ajhalls
03-03-2014, 05:42 PM
Ok, so I really hate the way the templates are handled with plugins / products and everything. I want to have a simple setup that I can use to add new pages to my site but it constantly seems so complicated.
Can't there be an easy way of just having a php page that says:
<?
include("./globals.php");
include("./header.php");
include("./navbar.php");
// Wow you can put anything you want here
include("./footer.php");
?>
I have spent hours trying to include a php file using the directions of creating a plugin attached to global_start, new template, new php file, and can't get it to actually pull in the include when I do {vb:raw phpfileinclude} in the template. Everything else works, the plugin is active, but the method above seems so much simpler.
As a site administrator, I can't stand how hard it is to do version control in development. So much of what makes the site tick is in the database and tracking incremental changes so I /or my staff can find what was changed when and what might have broken things is pretty hard.
If vB would implement something like above, I might actually be able to find php developers who don't have to deal with such a large learning curve, do subversion checkin / checkout and so much more. I have one great vBulletin developer that has been with me for years, but finding another has been miserable, and trying to learn it myself is even worse which is making me want to switch platforms.
Lynne
03-03-2014, 05:51 PM
<a href="https://vborg.vbsupport.ru/showthread.php?t=228112" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=228112</a>
ajhalls
03-03-2014, 06:41 PM
Thanks Lynne, I tried using that page to create the pages I wanted so I could do standard include(); I got the header to display, but couldn't get the header and navbar to work when I did:
<?
include("./header.php");
include("./navbar.php");
?>
I created some templates called idiotadmin-header and idiotadmin-navbar and left the appropriate code in each.
I tried this for header.php
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'test');
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('idiotadmin-header',
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
include('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'idiotadmin-header';
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('idiotadmin-header');
$templater->register_page_templates();
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());
?>
and this for navbar.php
<?php
define('THIS_SCRIPT', 'idiotadmin-navbar');
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('idiotadmin-navbar',
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
include('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
$navbits = construct_navbits(array('' => 'idiotadmin-navbar'));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'idiotadmin-navbar';
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('idiotadmin-navbar');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());
?>
I tried changing the $templater to $templater2, tried removing the global.php from the second file, and making lots of other edits to prevent overlap. Both files work fine by themselves, but put them together and it fails.
Zachery
03-03-2014, 07:11 PM
You're going about this in the wrong way. The template lynne gives you, gives you the ability to build vBulletin pages. The vbulletin way, you're coming at this kind of sideways, in a way we wouldn't normally do this
You really want something closer to this
<?php
define('THIS_SCRIPT', 'idiotadmin-pagex');
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array(
'header',
'headinclude',
'navbar',
'mypage',
'footer'
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
include('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
$navbits = construct_navbits(array('' => 'navbar'));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'MyPage';
// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$templater = vB_Template::create('mypage');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());
What this does is,
Defines what the page is (this_script)
Requires the needed phrases (we didn't do that here, since we're not using any)
Registers the templates that will be used on the page, these global templates at the top tell the software it needs these templates, so the software will get them all, instead of having to query for each template.
Requires the needed files.
Set's up the navbar
Set's up the page title
betwee the navbar stuff, and the page output stuff, you can do a lot of things. But if you just want a custom page, this is it
And then finally renders the templates.
Next, you'd add a new template in the software, based on my example it'd be mypage, AdminCP > Styles & Templates >STyle Manager > Add New Template
I've added the templates, and my custom html, stuff in it, and saved. Now it actually is a real page.
I did this pretty hastily, so I think I didn't get the navibts part right, but that is something I think with some trial and effort, and help from others, you should be able to nail down.
ajhalls
03-03-2014, 07:49 PM
Thank you so much for your help. I "learned" PHP about 15 years ago and am trying to get better but it seems so complicated when I am trying to figure out which problems are from php and which are vbulletin related. I have been running my vbulletin site for about 8 years and it has been heavily modified by Tigga (from vbadvanced) for the last 4 years. As much as I love everything he does, occasionally though I want to do something myself and get stuck over and over till I give up and outsource it AGAIN and AGAIN.
What am I supposed to do when I want to run PHP code? For example I want to create a page that has this code in the content area:
<?php
ini_set("display_errors",1);
require_once '../../../jq-config.php';
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// include the jqGrid Class
require_once ABSPATH."php/jqTreeGrid.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqTreeGrid instance
$tree = new jqTreeGrid($conn);
$tree->SelectCommand = "SELECT * FROM nested_category";
// set the table and primary key
$tree->table = 'nested_category';
$tree->setPrimaryKeyId('category_id');
// set tree model and table configuration
$tree->setTreeModel('nested');
$tree->setTableConfig(array('id'=>'category_id', 'left'=>'lft', 'right'=>'rgt'));
// autoloading nodes
$tree->autoLoadNodes = false;
// show any error (if any ) from server
$tree->showError = true;
$tree->setColModel();
$tree->setUrl('treegrid.php');
$tree->dataType = 'json';
// Some nice setting
$tree->setColProperty('name',array("label"=>"Name", "width"=>170));
$tree->setColProperty('price',array("label"=>"Price", "width"=>90, "align"=>"right"));
$tree->setColProperty('qty_onhand',array("label"=>"Qty", "width"=>90, "align"=>"right"));
$tree->setColProperty('color',array("label"=>"Color", "width"=>100));
// hide the not needed fields
$tree->setColProperty('category_id',array("hidden"=>true,"index"=>"accounts.account_id", "width"=>50));
$tree->setColProperty('lft',array("hidden"=>true));
$tree->setColProperty('rgt',array("hidden"=>true));
$tree->setColProperty('level',array("hidden"=>true));
$tree->setColProperty('uiicon',array("hidden"=>true));
$tree->navigator = true;
// Enable only deleting
$tree->setNavOptions('navigator', array("excel"=>true,"add"=>true,"edit"=>true,"del"=>true,"view"=>true, "search"=>true));
// and finaly set the expand column and height to auto
$tree->setGridOptions(array(
"ExpandColumn"=>"name",
"height"=>"auto",
"sortname"=>"account_id"
));
$tree->renderTree('#tree', '#pager', true,null, null, true, true);
?>
As I understand it I could have that page you did, but then I still need to deal with the plugin system and have everything written in the plugin and then do {vb:raw pluginname} instead of just doing this:
<?
include("./globals.php");
include("./header.php");
include("./navbar.php");
// Above code goes here
include("./footer.php");
?>
It just seems like a really complicated way to produce pages with a lot of going back and forth. It is making more sense why I have pages with 3000-4000 lines of code written by my programmer with tons of [if ($_POST['do'] == xxx] statements just to avoid dealing with vbulletin.
Zachery
03-03-2014, 08:42 PM
The entire snipet of code I gave you, is an ENTIRE page, in php.
Look at forum.php or showthread.php .You don't require a header.php opr navbar.php.
It is its own page, and does its own things.
Step 1: create mypage.php file on server with my code as above.
Step 2: Create a template called mypage in the style manager
Step 3, pull up domain.com/mypage.php on your site/server
ajhalls
03-03-2014, 09:39 PM
Ok so, I might be close. Looking at a page on my site I came up with the minimal code needed is this:
<?php
define('THIS_SCRIPT', 'Simple Page');
$specialtemplates = array();
$phrasegroups = array();
$globaltemplates = array('shell_blank');
require_once('./global.php');
// ################## content ###################
$html = "Type anything you want here";
// ################## build ####################
$navbits[] = 'Simple Page';
$navbits = construct_navbits($navbits);
$navbar = render_navbar_template($navbits);
$templater = vB_Template::create('shell_blank');
$templater->register_page_templates();
$templater->register('html', $html);
$templater->register('navbar', $navbar);
print_output($templater->render());
?>
And that works great for a basic HTML setup, but when I tried including a jquery grid I don't know a way to have it just execute the main render command and assign it to the $html variable so it is put in the right spot. The output of all the other code looks like this: http://workshopwarrior.com/grid/suppliers.php which is supposed to be in the template.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<link rel="stylesheet" type="text/css" media="screen" href="./themes/redmond/jquery-ui-custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="./themes/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="./themes/ui.multiselect.css" />
<style type="text">
html, body {
margin: 0; /* Remove body margin/padding */
padding: 0;
overflow: hidden; /* Remove scroll bars on browser window */
font-size: 75%;
}
</style>
<script src="./js/jquery.js" type="text/javascript"></script>
<script src="./js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script src="./js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="./js/jquery-ui-custom.min.js" type="text/javascript"></script>
<?php
define('THIS_SCRIPT', 'Supplier Grid');
$specialtemplates = array();
$phrasegroups = array();
$globaltemplates = array('shell_blank');
require_once('./global.php');
// ########################## content ##############################
ini_set("display_errors",1);
require_once '/var/www/workshopwarrior.com/grid/config.php';
// include the driver class
require_once "/var/www/workshopwarrior.com/grid/php/jqGridPdo.php";
// include the jqGrid Class
require_once "/var/www/workshopwarrior.com/grid/php/jqTreeGrid.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqTreeGrid instance
$tree = new jqTreeGrid($conn);
$tree->SelectCommand = "SELECT * FROM suppliers";
// set the table and primary key
$tree->table = 'suppliers';
$tree->setPrimaryKeyId('id');
// set tree model and table configuration
$tree->setTreeModel('adjacency');
$tree->setTableConfig(array('id'=>'id', 'parent'=>'parent_id'));
// autoloading is disabled
$tree->autoLoadNodes = false;
// collapse all nodes (default)
$tree->expandAll = true;
// show any error (if any ) from server
$tree->showError = true;
$tree->setColModel();
$tree->setUrl('treegrid.php');
$tree->dataType = 'json';
// Some nice setting
$tree->setColProperty('name',array("label"=>"<b>Name</b>", "width"=>470));
$tree->setColProperty('street',array("label"=>"Street Address", "width"=>270));
$tree->setColProperty('city',array("label"=>"City", "width"=>150, "align"=>"center"));
$tree->setColProperty('state',array("label"=>"State", "width"=>60, "align"=>"center"));
$tree->setColProperty('zip',array("label"=>"Zip", "width"=>70, "align"=>"center"));
$tree->setColProperty('phone',array("label"=>"Phone Number", "width"=>170, "align"=>"center"));
$tree->setColProperty('url',array("label"=>"Website", "width"=>370, "align"=>"center", "formatter"=>"link"));
// hide the not needed fields
$tree->setColProperty('id',array("hidden"=>true));
$tree->setColProperty('parent_id',array("hidden"=>true));
$tree->setColProperty('description',array("hidden"=>true));
$tree->setColProperty('category',array("hidden"=>true));
$tree->setColProperty('product',array("hidden"=>true));
// and finaly set the expand column and height to auto
$tree->setGridOptions(array(
"ExpandColumn"=>"name",
"height"=>'auto',
"width"=>1100,
"sortname"=>"id",
"sortable"=>true,
// allow automatic scrolling of the rows
"scrollrows"=>true
));
// enable key navigation
$tree->callGridMethod('#tree', 'bindKeys');
$tree->navigator = true;
$tree->setNavOptions('navigator', array("add"=>true,"edit"=>true, "del"=>true, "search"=>true, "excel"=>true));
$tree->renderTree('#tree', '#pager', true,null, null, true, true);
if($tree->oper == 'edit') {
$data = $_POST;
// $data is the posted data
// do what you want with it
$post_data = json_encode($data, JSON_FORCE_OBJECT);
$json_data = "[";
$json_data .= $post_data;
$json_data .= "]";
file_put_contents("json.txt", $json_data);
}
// build
$navbits[] = 'Supplier Grid';
$navbits = construct_navbits($navbits);
$navbar = render_navbar_template($navbits);
$templater = vB_Template::create('shell_blank');
$templater->register_page_templates();
$templater->register('html', $html);
$templater->register('navbar', $navbar);
print_output($templater->render());
?>
RichieBoy67
03-03-2014, 11:35 PM
Can't get much simpler then this.
https://vborg.vbsupport.ru/showthread.php?p=1961076
ajhalls
03-04-2014, 04:14 PM
Thank you so much RichieBoy, that is an awesome mod which I will definitely make use of. While fidgeting with everything, I finally found something that works:
<?php
define('THIS_SCRIPT', 'Supplier Grid');
$specialtemplates = array();
$phrasegroups = array();
$globaltemplates = array('shell_blank');
require_once('./global.php');
// ########################## content ##############################
ob_start();
include("/var/www/workshopwarrior.com/grid/suppliers.php");
$html = ob_get_contents();
ob_clean();
// build
$navbits[] = 'Supplier Grid';
$navbits = construct_navbits($navbits);
$navbar = render_navbar_template($navbits);
$templater = vB_Template::create('shell_blank');
$templater->register_page_templates();
$templater->register('html', $html);
$templater->register('navbar', $navbar);
print_output($templater->render());
?>
It was always dumping the included PHP file at the top of the page till I used the ob_start and ob_clean code.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.