Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-03-2014, 05:42 PM
ajhalls ajhalls is offline
 
Join Date: Nov 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Idiot Admin PHP

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:
Code:
<?
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.
Reply With Quote
  #2  
Old 03-03-2014, 05:51 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<a href="https://vborg.vbsupport.ru/showthread.php?t=228112" target="_blank">https://vborg.vbsupport.ru/showthread.php?t=228112</a>
Reply With Quote
  #3  
Old 03-03-2014, 06:41 PM
ajhalls ajhalls is offline
 
Join Date: Nov 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Code:
<?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
Code:
<?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.
Reply With Quote
  #4  
Old 03-03-2014, 07:11 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Code:
<?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.
Attached Images
File Type: jpg 2014-03-03_14h55_26.jpg (86.0 KB, 0 views)
File Type: jpg 2014-03-03_14h55_12.jpg (44.6 KB, 0 views)
Reply With Quote
Благодарность от:
TheLastSuperman
  #5  
Old 03-03-2014, 07:49 PM
ajhalls ajhalls is offline
 
Join Date: Nov 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
Code:
<?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.
Reply With Quote
  #6  
Old 03-03-2014, 08:42 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #7  
Old 03-03-2014, 09:39 PM
ajhalls ajhalls is offline
 
Join Date: Nov 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok so, I might be close. Looking at a page on my site I came up with the minimal code needed is this:
Code:
<?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.

Code:
<!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());

?>
Reply With Quote
  #8  
Old 03-03-2014, 11:35 PM
RichieBoy67's Avatar
RichieBoy67 RichieBoy67 is offline
 
Join Date: Apr 2004
Location: CT - Down in a hole..
Posts: 3,057
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can't get much simpler then this.

https://vborg.vbsupport.ru/showthread.php?p=1961076
Reply With Quote
  #9  
Old 03-04-2014, 04:14 PM
ajhalls ajhalls is offline
 
Join Date: Nov 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
Code:
<?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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:57 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04543 seconds
  • Memory Usage 2,302KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (2)postbit_attachment
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete