Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Jan 2001
Posts: 184
Member
Member
Offline
Joined: Jan 2001
Posts: 184
This is for UBB code hackers only.

If this has already been posted my apologies but here is (based on my success) a "how to" so UBB code hackers can create CP configuration screens. Please note I posted a separate topic about wordlets. This topic is only for config settings for you hack.

FYI: "xxxx" will refer to the name of your hack in the documentation below...

Step 1)

FILE: cp.cgi

FIND:
----------------------------------
# Control Panel Options
if ($ubb eq 'entry') { &cp_entry_page; exit; } # end entry
----------------------------------
ADD JUST BELOW:
----------------------------------
# HACK START
if (($ubb eq "vars_xxxx") && ($status eq 'Administrator')) {
&view_vars("xxxx"); exit;
} #end vars_login
if (($ubb eq "set_vars_xxxx") && ($status eq "Administrator")) {
&set_vars_xxxx; exit;
} #end set_vars_xxxx
# HACK END
---------------------------------

Step 2)

FILE: cp_lib.cgi

FIND:
-----------------------------------
# Set the page title
if ($_[0] eq 'display') { $CurrentTab = qq%$vars_wordlets_cp{display_settings}%; }
-----------------------------------
ADD JUST BELOW:
-----------------------------------
# HACK START
elsif ($_[0] eq 'xxxx') { $CurrentTab = "xxxx Settings"; }
# HACK END
--------------------------------

Step 3)

While still editing cp_lib.cgi, insert this at the very top of the file (you will create a new subroutine which takes care of saving the variables to vars_xxxx.cgi):

-------------------------------
#### START OF HACK #################################
# All variables are case sensitive - do not edit this portion #
sub set_vars_xxxx {
local(*FILE); $CurrentTab = "xxxx Settings";
&CPHeader; &CPFooter;
open (FILE, ">$vars_config{VariablesPath}/vars_xxxx.cgi") or die("Unable to open vars_xxxx.cgi file for writing.");
&lock;
print FILE qq!%vars_xxxx = (n!;
print FILE qq!variable1 => q~$in{variable1}~,n!;
print FILE qq!variable2 => q~$in{variable2}~,n!;
print FILE qq!variable3 => "$in{variable3}",n!;
print FILE qq!);n!; print FILE qq!1;n!; &unlock; close (FILE);
chmod(0777, "$vars_config{VariablesPath}/vars_xxxx.cgi");
&cp_confirm("xxxx Settings Updated");
exit;} #end set_vars_login
#### END OF HACK #################################
--------------------------------

Notes: Examine other vars_*.cgi files (not wordlets) and you'll see some of them have error checking routines, many other ways to store variables, etc. The above is a simplistic example using 3 variables. The first two could store text or numeric values and the last one could store a URL or server path which may include special characters like ~ (tilde) for example.

Step 4)

UBB TEMPLATE FILE: cp_common.pl

FIND:
--------------------------
document.writeln("");
--------------------------
ADD JUST BELOW:
--------------------------
document.writeln("");
---------------------------

Notes: The above puts the new command under the "Primary settings" pulldown menu. My login hack is huge and affects operation in a major way so I put mine there. You all are smart enough to know how to hack HTML inside cp_common.pl, but thought I'd show this just to cover the bases.

Step 5)

And finally, the creative and fun part. You will create a brand new template file called cp_vars_xxxx.pl. This will be the actual configuration screen the user sees.

Before you even start one, be sure to examine other templates (i.e. cp_vars_time.pl) to see how it's structured.

Essentially a template file consists of these basic elements which are basically sub-routines you can use to display text and options. UBB made is rediculously easy:

Here are examples with syntax which follow a sequence you'll most likely find in a typical template file (from top to bottom):

&FormStart("$vars_config{CGIURL}/cp.cgi", "$Hiddens");

&TBT; #Table Border Top in cp_common.pl

&HeaderRow("text here", "2", "#c9c9c9", "#000000", "left", "2");

&RegField ("config label", "variable1", "yes|", "width", "maxchars", "comments", "$vars_xxxx{variable1}");

&DoTextArea ("config label", "variable2", "yes|", "comments", "$vars_display{variable2}", "width", "height");

&RadioField ("config label", "variable3", "yes|", "comments", "$vars_login{variable3}", "data1|choice1%%data2|choice2...");

&TBB; #Table Border Bottom in cp_common.pl

&Submit("Update $CurrentTab");

# DANGER: Do not remove the following line!
1;

Okay, as you can see above you've got ways to display things, and ways to get user input. It's really just a matter of combining those elements. You can embedd HTML inside the comments or text portions of the commands. If this all looks crazy to you right now, I stress... look at a default template and it'll make sense. Remember, the above example demonstrate syntax only.

Here are two ACTUAL examples from my cp_vars_login.pl template:

--- snip ---
&RadioField ("Log Access Level Restrictions", "LogLevelRestrict", "yes", "Users who are restricted via access level...", "$vars_login{LogLevelRestrict}", "1|On%%0|Off");

&RegField ("Maximum Log Size", "MaxLogSize", "yes", "8", "8", "To maintain the size of your log please specify the MAXIMUM size in bytes only, i.e. "48000". Please note any positive value triggers log archiving if enabled. Please enter only numbers in this field. Set to "0" for an unlimited log, but that's not advisable, usually 48000 or 64000 works well for most setups...", "$vars_login{MaxLogSize}");
--- snip ---

Now does it make sense? First I've got a required radio button with two choices, then a required text input box so the user can key in their maximum log size. Both generate variables which end up in vars_login.cgi. In my login.cgi script I simply require that file to load in my variables.

Once again, study existing templates and also study sub-routines in ubb_lib.cgi. There are many other commands which store/validate and do other nice things to make your job easier. To the end user, it looks like your hack is actually built into to UBB (which it is!)

So to get you the big picture:

1) come up with a short name for xxxx
2) hack to update subroutines for view/set
3) hack to add your stuff to whatever dropdown menu in the CP you want
4) create a new template file cp_vars_xxxx.pl which handles user input
5) add a require line in your hack which allows data stored in vars_xxxx.cgi to be used
6) use $vars_xxxx{variable} in your hack for each variable

Notes: When creating your template, do not add in HTML outside of functions. You can set fonts/colors and insert HTML inside of functions. If you want to add a blank line for spacing, what you're really doing is creating a row inside the table using:

&HeaderRow(qq%
%, "2", "#FFFFFF", "#000000", "left", "1");

Just a simple
and set the background color (the #FFFFFF above) to the same color as the page background.

Well, I think I covered it all. Please someone lemme know if I missed anything. I have working CP config and wordlet hacks for my script and I tell ya... it's awesome.

Hope this helps someone out there.

-jim

laugh

updated again as more cool stuff found!

[ March 25, 2001: Message edited by: JimGoldbloom ]

Sponsored Links
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
This might work better as a short tutorial Jim... we have something coming up we'd like to get your permission to use it in when the time comes...


- Allen wavey
- What Drives You?
Joined: Jan 2001
Posts: 184
Member
Member
Offline
Joined: Jan 2001
Posts: 184
Quote
quote:
of course - and obviously if anyone has anything to add/delete/edit, go for it. it's meant to be shared!


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Posts: 70
Joined: January 2007
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)