Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > Programming Articles
[tip] Use PAPI if you're just starting out with phpinclude
filburt1
Join Date: Feb 2002
Posts: 6,144

 

Maryland, US
Show Printable Version Email this Page Subscription
filburt1 filburt1 is offline 12-18-2002, 10:00 PM

Note: this is not meant to be a plug for my mod.

PAPI (pronounced "pappy") is a mod I released: http://www.vbulletintemplates.com/mo...&threadid=2361 . Escentially it is a phpinclude swiss army knife although the name means phpinclude API. It is a set of wrapper functions designed to drastically simplify coding mods for use in the phpinclude template.

Going back a step: the phpinclude template is a template that is special in the sense that it can contain raw PHP code. It is the only template that can; the others can only contain PHP variables.

Standard vB pages are constructed in this order:
1. Execute the .php file
2. Execute the contents of phpinclude
3. Compile the final HTML to display

Therefore phpinclude can only access variables that are within a global scope and only gets executed when a template is generated.

Remember though that phpinclude is executed in any page, so you have to start accounting for that. Also you have to use vB's database reference methods to access the MySQL database. This is where PAPI starts to become useful.

Say you want to run code that only executes on forumhome (index.php). Normally you'd put this in phpinclude:
PHP Code:
if (strpos($_SERVER['PHP_SELF'], "index.php") != false
To those new to PHP, that tests whether the current page's path and filename contains the string "index.php".

With PAPI, this is simplified to:
PHP Code:
if (thisis("index")) 
or
PHP Code:
if (thisis("index.php")) 
PAPI offers a plethora of functions, but some general ones to note: actionis() returns true depending on the value of the "action" variable (i.e., index.php?action=something; actionis("something") would return true. mysqlqueryhandle (1.0.3 and later) returns the result from a MySQL query (i.e., returns $DB_site->query(query).

These may seem trivial, but it goes so far to implement mysqlmultiplequeries which can execute several queries in succession with one line of code. So
PHP Code:
$DB_site->query("DELETE FROM session");
$DB_site->query("DELETE FROM word");
$DB_site->query("INSERT INTO word (wordid) VALUES (1)"); 
can be simplified to:
PHP Code:
mysqlmultiplequeries("DELETE FROM session; DELETE FROM word; INSERT INTO word (wordid) VALUES (1)"); 
Also, starting with PAPI 1.0.3, an internal query counter is maintained, so every time a query is executed via PAPI's wrapper functions a counter is incremented; putting $papiquerycount in your footer will display how many queries PAPI's wrapper functions have executed.

There are far more features than this, however, so check out PAPI's thread for a near-full list, or at least the features from 1.0.0. Enjoy.
Reply With Quote
  #2  
Old 12-19-2002, 09:48 PM
Cypher720's Avatar
Cypher720 Cypher720 is offline
 
Join Date: Aug 2002
Posts: 705
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks again for making this! due to my lack of time...i havent tried it yet - sorry
Reply With Quote
  #3  
Old 12-19-2002, 11:23 PM
Tony G's Avatar
Tony G Tony G is offline
 
Join Date: Nov 2001
Location: Melbourne, Australia
Posts: 8,357
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've taken your advice, although I wanted to learn the hard way so PAPI would be easier.

Stay tuned for somewhat of a PAPI mod by me.
Reply With Quote
  #4  
Old 12-19-2002, 11:29 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just be sure to use PAPI's wrappers for the MySQL stuff wherever possible because the soon-to-be-uploaded 1.0.3 includes an internal counter.
Reply With Quote
  #5  
Old 12-19-2002, 11:35 PM
Tony G's Avatar
Tony G Tony G is offline
 
Join Date: Nov 2001
Location: Melbourne, Australia
Posts: 8,357
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'll wait for that version then.
Reply With Quote
Reply

Thread Tools

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:36 PM.


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.04458 seconds
  • Memory Usage 2,236KB
  • Queries Executed 18 (?)
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
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (4)postbit
  • (5)postbit_onlinestatus
  • (5)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_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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete