Successfully reported this slideshow.

WebGUI Developers Workshop

3,870 views

Published on

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

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

WebGUI Developers Workshop

  1. WEBGUI DEV 101 WebGUI Developer Workshop
  2. INSTALL WEBGUI
  3. 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.)
  4. Install Install VMWare Player (or Fusion if on Mac) (If you already have VMWare Player 2 or higher you can ignore this.) Decompress the Zip File Open VMWare Browse to the folder where you extracted WebGUI Open WebGUI
  5. 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
  6. File Share You can access the VM’s filesystem from your computer Windows: 192.168.47.131data (The IP may be different on your Mac/Linux: cifs://192.168.47.131/data install.) Username: webgui Password: 123qwe
  7. CORPORATE PERL
  8. OUR USERS And 10000+ more... Fred Rogers Foundation
  9. Figures based upon an actual client intranet project that was built in both Oracle Portals® and WebGUI®, and estimated for MS Sharepoint®. Licensing Implementation Hardware WebGUI® Oracle Portals® 3,000,000 80 2,250,000 60 1,500,000 40 750,000 20 Oracle Portals® 0 MS Sharepoint® 0 WebGUI® Site Online Base Apps Full Suite Physical Cost (Dollars) Time Cost (Months)
  10. WEBGUI DEMO
  11. THE API
  12. 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.
  13. Application Framework Plugin 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 API File Storage Image Processing Search Sessions Database Access HTTP Interaction Mail LDAP Access Users Groups Privileges Other Utilities Database
  14. WRITING MACROS
  15. 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;
  16. 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.
  17. Hello World package WebGUI::Macro::HelloWorld; use strict; sub process { my ($session) = @_; return ‘Hello World!’; } 1;
  18. YOU DO IT
  19. Hello World package WebGUI::Macro::HelloWorld; use strict; sub process { my ($session) = @_; return ‘Hello World!’; } 1;
  20. 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!
  21. Install It Edit /data/WebGUI/etc/www.example.com.conf Find the ‘macros’ section Add the following to your config file: “HelloWorld” : “HelloWorld”,
  22. Use It wreservice.pl --restart modperl Adding the following to your content: ^HelloWorld; Should produce: Hello World!
  23. $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);
  24. Username Macro Create a macro called ‘Username’ Output the current user’s username. WRITE IT! Hint: $session->user Hint 2: $session->user->username
  25. Username package WebGUI::Macro::Username; use strict; sub process { my ($session) = @_; return $session->user->username; } 1;
  26. Does it work? Test it macroRunner.pl Use it ^Username;
  27. 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;
  28. Sum package WebGUI::Macro::Sum; use strict; sub process { my ($session, @args) = @_; my $total = 0; $total += $_ foreach @args; return $total; } 1;
  29. Does it work? Test it macroRunner.pl Use it ^Sum(1,2,3,4,5);
  30. WRITING CONTENT HANDLERS
  31. 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.
  32. Hello World package WebGUI::Content::HelloWorld; use strict; sub handler { my ($session) = @_; return ‘Hello World!’; } 1;
  33. YOU DO IT
  34. Hello World package WebGUI::Content::HelloWorld; use strict; sub handler { my ($session) = @_; return ‘Hello World!’; } 1;
  35. 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.
  36. Use It Visiting http://localhost:8081/ Should produce: Hello World!
  37. $session | Forms A reference to the form processor my $form = $session->form Fetch a form parameter my $value = $form->get(“foo”); Validate it against a specific field type my $value = $form->get(“foo”,”integer”);
  38. 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
  39. 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’);
  40. Hello World package WebGUI::Content::HelloWorld; use strict; sub handler { my ($session) = @_; if ($session->form->get(‘op’) eq ‘helloworld’) { return ‘Hello World!’; } return undef; } 1;
  41. Sum Task: 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!
  42. Sum package 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;
  43. WebGUI::HTMLForm Draw forms quickly and easily. Simple OO API Dozens of form controls already in existence
  44. Making A Form use 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;
  45. 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);
  46. Sum use 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;
  47. $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);
  48. Sum with Style Add a style wrapper to Sum WRITE IT!
  49. Sum return $session->style->userStyle($total . “<br />” . $f->print);
  50. OTHER PLUGINS
  51. So Far Macros Content Handlers But there are 17 plugin types for WebGUI currently
  52. URL Handler Like a content handler, but has direct access to the Apache request cycle
  53. Asset The main content application object. Features version control, metadata, direct URLs, and lineage based relationships
  54. Packages Bundle asset configurations as a importable package.
  55. Sku A special type of asset that plugs into WebGUI shop as a sellable item.
  56. Auth Customize the authentication / login process.
  57. i18n / Help i18n allows you to internationalize any other plugins Help allows you to document your plugins using the i18n system.
  58. 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.
  59. Template Engine Tie your own template parsers to WebGUI.
  60. Workflow Activities Extend the workflow engine to run your asynchronous tasks
  61. Utility Scripts Run maintenance and administrative tasks from the command line.
  62. Form Controls Add to the more than two dozen form controls with input validation already in the system.
  63. Cache Add new ways of speeding up WebGUI by caching complex items.
  64. QUESTIONS?
  65. APPENDIX
  66. 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);
  67. 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);
  68. Database Helpers Get a row my @array = $db->quickArray($sql, @params); my %hash = $db->quickHash($sql, @params); Get a column my @array = $db->buildArray($sql, @params); my %hash = $db->buildHash($sql, @params); Get a single column from a single row my $scalar = $db->quickScalar($sql, @params);
  69. Log A reference to the log file my $log = $session->log; Write to the log $log->error($message); $log->warn($message); $log->info($message); $log->debug($message);
  70. HTTP Interact with HTTP my $http = $session->http; Set a redirect $http->setRedirect($url); Send header $http->sendHeader;
  71. HTTP Continued Set headers $http->setCacheControl($seconds); $http->setCookie($name, $value); $http->setMimeType(‘text/xml’); $http->setFilename($filename, $mimetype); $http->setStatus(404,$notFoundMessage); Get Cookies my $hashRef = $http->getCookies;
  72. Output Output back to browser my $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);

×