webgui developers workshop

Post on 24-May-2015

2.138 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Learn how to program the basics in the WebGUI Content Management system.

TRANSCRIPT

WEBGUI DEV 101WebGUI Developer Workshop

INSTALL WEBGUI

USB Drive

Copy the WebGUI Workshop folder to your hard disk

Pass the USB Drive off to someone else

(You’re going to need ~6GB of free space.)

Install

Install VMWare Player (or Fusion if on Mac)

Decompress the Zip File

Open VMWare

Browse to the folder where you extracted WebGUI

Open WebGUI

(If you already have VMWare Player 2 or higher you can ignore this.)

Test The Image

In the VMWare window log in to the command line

It should tell you what IP address to visit

Open your web browser and go to that IP address

File Share

You can access the VM’s filesystem from your computer

Windows: \\192.168.47.131\data

Mac/Linux: cifs://192.168.47.131/data

Username: webgui

Password: 123qwe

(The IP may bedifferent on your

install.)

CORPORATE PERL

Fred Rogers Foundation

OUR USERSAnd 10000+ more...

0

750,000

1,500,000

2,250,000

3,000,000

WebGUI®

MS Sharepoint®Oracle Portals®

Licensing Implementation Hardware

Figures based upon an actual client intranet project that was built in both Oracle Portals® and WebGUI®, and estimated for MS Sharepoint®.

0

20

40

60

80

Site Online Base Apps Full Suite

WebGUI® Oracle Portals®

Physical Cost (Dollars) Time Cost (Months)

WEBGUI DEMO

THE API

Sprawling API

WebGUI’s API is huge, can’t cover it all today.

Your brain will hurt without it anyway.

View the full API at:http://www.plainblack.com/downloads/builds/7.7.20-stable/api/ - or -perldoc /data/WebGUI/lib/WebGUI/User.pm

We’ll cover some basics now, and the rest as we go.

Application FrameworkApplication FrameworkApplication FrameworkApplication Framework

Plugin PointsPlugin PointsPlugin PointsPlugin Points

Template Processors Shipping Methods Payment Methods Product Types

Taxes Form Controls Cache Utility Scripts

Translations Content Packages Workflow Activities Authentication Handlers

Macros Assets URL Handlers Content Handlers

Core APICore APICore APICore API

File Storage Image Processing Search Sessions

Database Access HTTP Interaction Mail LDAP Access

Users Groups Privileges Other Utilities

DatabaseDatabaseDatabaseDatabase

WRITING MACROS

WebGUI::Session

$session is the circulatory and nervous system of WebGUI

Here’s how you create or reopen one:my $session = WebGUI::Session->open($rootPath, $config);

Here’s how you close one:$session->close;

Here’s how you destroy one:$session->var->end;$session->close;

Macros Are Easy

Used to put programmer power into an easy package content publishers can handle.

Macros reside in /data/WebGUI/lib/WebGUI/Macro

Single subroutine API

Gets a single argument, $session

Start by copying the _macro.skeleton file.

Hello Worldpackage WebGUI::Macro::HelloWorld;

use strict;

sub process {my ($session) = @_;return ‘Hello World!’;

}

1;

YOU DO IT

Hello Worldpackage WebGUI::Macro::HelloWorld;

use strict;

sub process {my ($session) = @_;return ‘Hello World!’;

}

1;

How do we know it works?

In your workshop folder find macroRunner.pl

Copy into /data/WebGUI/sbin

Type: perl macroRunner.pl \--config=www.example.com.conf \--macro=HelloWorld

And you should get:Hello World!

Install It

Edit /data/WebGUI/etc/www.example.com.conf

Find the ‘macros’ section

Add the following to your config file:

“HelloWorld” : “HelloWorld”,

Use It

wreservice.pl --restart modperl

Adding the following to your content:^HelloWorld;

Should produce:Hello World!

$session | Current User

A reference to the current user:my $user = $session->user;

ISA WebGUI::User object.

Get a param:my $username = $user->username;

Set a param:$user->username($username);

Username Macro

Create a macro called ‘Username’

Output the current user’s username.

WRITE IT!

Hint: $session->user

Hint 2: $session->user->username

Usernamepackage WebGUI::Macro::Username;

use strict;

sub process {my ($session) = @_;return $session->user->username;

}

1;

Does it work?

Test itmacroRunner.pl

Use it^Username;

Macros Can Have Params

^Sum(1,2,3,4,5);

Should produce: 15

Parameters are passed in to process() after $session

WRITE IT!

Hint: my ($session, @args) = @_;

Hint 2: $total += $_ foreach @args;

Sumpackage WebGUI::Macro::Sum;

use strict;

sub process {my ($session, @args) = @_;my $total = 0;$total += $_ foreach @args;return $total;

}

1;

Does it work?

Test itmacroRunner.pl

Use it^Sum(1,2,3,4,5);

WRITING CONTENT HANDLERS

Content Handlers Are Powerful

As easy to write as a macro, but way more powerful.

Can write a full web app with just a content handler.

Used mainly for writing simple round trip services.

Receives a single parameter of $session.

Hello Worldpackage WebGUI::Content::HelloWorld;

use strict;

sub handler {my ($session) = @_;return ‘Hello World!’;

}

1;

YOU DO IT

Hello Worldpackage WebGUI::Content::HelloWorld;

use strict;

sub handler {my ($session) = @_;return ‘Hello World!’;

}

1;

Install It

Edit /data/WebGUI/etc/www.example.com.conf

Find the ‘contentHandlers’ section

Add the following to your config file:

“WebGUI::Content::HelloWorld”,

Order is important. If something returns content before your content handler, then your content handler will never be called.

Use It

Visiting http://localhost:8081/

Should produce:Hello World!

$session | Forms

A reference to the form processormy $form = $session->form

Fetch a form parametermy $value = $form->get(“foo”);

Validate it against a specific field typemy $value = $form->get(“foo”,”integer”);

Conditionality

Content handlers should be conditional

Based on some setting

A specific URL

A parameter in the URL

A time of day

Anything else you choose

Conditional Hello World

Modify HelloWorld so that it only displays if a form parameter called ‘op’ has a value of ‘helloworld’.

WRITE IT!

Hint: my $value = $session->form->get(‘op’);

Hello Worldpackage WebGUI::Content::HelloWorld;

use strict;

sub handler {my ($session) = @_;if ($session->form->get(‘op’) eq ‘helloworld’) {

return ‘Hello World!’;}return undef;

}

1;

SumTask:

Triggered by form variable called ‘op=Sum’

User enters comma separated list of numbers in form variable called ‘values’

Sum them

Display the result

Test: http://localhost:8081/?op=Sum;values=1,2,3,4,5

WRITE IT!

Sumpackage WebGUI::Content::Sum;use strict;

sub handler {my ($session) = @_;if ($session->form->get(‘op’) eq ‘Sum’) {

my @values = split(‘,’, $session->form->get(‘values’));my $total = 0;$total += $_ foreach @values;return $total

}return undef;

}1;

WebGUI::HTMLForm

Draw forms quickly and easily.

Simple OO API

Dozens of form controls already in existence

Making A Formuse WebGUI::HTMLForm;my $f = WebGUI::HTMLForm->new($session);$f->hidden( name=>”ip”, value=>$ip );$f->text( name=>”username”, label=>”Username”);$f->integer( name=>”guess”, label=>”Pick a number”);$f->date( name=>”birthday”, label=>”Birth Date”);$f->submit;return $f->print;

Sum with Form

Task:

Now add a form to make it easier for users to use

WRITE IT!

Hint: my $f = WebGUI::HTMLForm->new($session);

Sumuse WebGUI::HTMLForm;

my $f = WebGUI::HTMLForm->new($session);$f->hidden( name=>’op’, value=>’Sum’ );$f->text( name=>’values’, defaultValue=>$session->form->get(‘values’), label => ‘Values to Sum’, subtext => ‘Separated by commas’);$f->submit;

return $total . “<br />” . $f->print;

$session | Styles

You can easily wrap output in a style to make it prettier.

You get the style reference from $session.my $style = $session->style;

Then you just wrap your output in the style using the userStyle() method.return $style->userStyle($output);

Sum with Style

Add a style wrapper to Sum

WRITE IT!

Sum

return $session->style->userStyle($total . “<br />” . $f->print);

OTHER PLUGINS

So Far

Macros

Content Handlers

But there are 17 plugin types for WebGUI currently

URL Handler

Like a content handler, but has direct access to the Apache request cycle

Asset

The main content application object.

Features version control, metadata, direct URLs, and lineage based relationships

Packages

Bundle asset configurations as a importable package.

Sku

A special type of asset that plugs into WebGUI shop as a sellable item.

Auth

Customize the authentication / login process.

i18n / Help

i18n allows you to internationalize any other plugins

Help allows you to document your plugins using the i18n system.

Shipping , Payment, and Tax Drivers

Tie in to shippers like UPS, Fedex, USPS, DHL, etc.

Tie in to payment gateways like PayPal, Google Checkout, Authorize.net, etc.

Tie in to various tax mechanisms set up by regional governments.

Template Engine

Tie your own template parsers to WebGUI.

Workflow Activities

Extend the workflow engine to run your asynchronous tasks

Utility Scripts

Run maintenance and administrative tasks from the command line.

Form Controls

Add to the more than two dozen form controls with input validation already in the system.

Cache

Add new ways of speeding up WebGUI by caching complex items.

QUESTIONS?

APPENDIX

Database

A reference to your WebGUI database:my $db = $session->db;

ISA WebGUI::SQL object.

Read:my $sth = $db->read($sql, \@params);

Write:$db->write($sql, \@params);

Database CRUD

Create:my $id = $db->setRow($table, $keyname, \%properties);

Read:my $row = $db->getRow($table, $keyname, $id);

Update:$db->setRow($table, $keyname, \%properties);

Delete:$db->deleteRow($table, $keyname, $id);

Database Helpers

Get a rowmy @array = $db->quickArray($sql, \@params);my %hash = $db->quickHash($sql, \@params);

Get a columnmy @array = $db->buildArray($sql, \@params);my %hash = $db->buildHash($sql, \@params);

Get a single column from a single rowmy $scalar = $db->quickScalar($sql, \@params);

Log

A reference to the log filemy $log = $session->log;

Write to the log$log->error($message);$log->warn($message);$log->info($message);$log->debug($message);

HTTP

Interact with HTTPmy $http = $session->http;

Set a redirect$http->setRedirect($url);

Send header$http->sendHeader;

HTTP Continued

Set headers$http->setCacheControl($seconds);$http->setCookie($name, $value);$http->setMimeType(‘text/xml’);$http->setFilename($filename, $mimetype);$http->setStatus(404,$notFoundMessage);

Get Cookiesmy $hashRef = $http->getCookies;

Output

Output back to browsermy $output = $session->output;

Print some content$output->print($content);

Don’t process macros as printing:$output->print($content,1);

Set the output handle$output->setHandle($someFileHandle);

top related