Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
February 13, 2012, 03:22:19 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Interested in joining the WebsiteBaker team?
For more Information read
here
or on our
new website
.
149700
Posts in
21103
Topics by
7538
Members
Latest Member:
ionline
WebsiteBaker Community Forum
English
Modules
(Moderator:
Argos
)
Introducing wblib (Library Module)
Pages: [
1
]
Go Down
Author
Topic: Introducing wblib (Library Module) (Read 2235 times)
WebBird
Guest
Introducing wblib (Library Module)
«
on:
November 13, 2009, 11:21:26 AM »
After playing around with lots of modules (including PEAR), I found myself searching again and again for "better solutions". (From my point of view, of course.)
So, I started working on my very own bundle of useful classes I am going to use for all my future projects. Two of them, wbFormBuilder and wbTemplate, were already introduced to the community.
This bundle is still growing, as I'm using it every day, so I'd like to introduce it here. Maybe someone finds it useful.
Download:
http://www.websitebakers.com/pages/libs/wblib.php?lang=EN
wbTemplate
http://www.websitebaker2.org/forum/index.php/topic,15260.0.html
I liked the way x_FastTemplate2 works, but there are some features I missed. I found it hard to extend the code of the x_FastTemplate2 module, so I took what I liked and packed it into my own code.
wbTemplate can handle
Loops
if-else-Statements
Includes of other files into a template
Template comments (completely removed when rendering the template)
For more details, see
http://www.websitebaker2.org/forum/index.php/topic,15260.0.html
wbValidate
This is a complete validator class that helps you validating user input. At the moment, it can validate
different kinds of string (alphanumeric (0-9a-zA-Z), alphanum extended (same as alphanum plus underscore), or any string that doesn't have control characters (ASCII 0 - 31) - spaces allowed)
integer numbers
eMail addresses
URIs
Password complexity (6 or more letters, digits, underscores and hyphens. The input must contain at least one upper case letter, one lower case letter and one digit)
CSS style (experimental!)
wbFormBuilder
This is a complete Form Builder class that lets you create forms and validate the user input (using wbValidate, of course).
See
http://www.websitebaker2.org/forum/index.php/topic,15206.0.html
for details.
wbI18n
(Internationalizatio
n)
I don't like the way how I18n is done in WB, using often meaningless array keys. This way, you always have to translate these keys into at least one language (English), doing the work twice. Also, making a translation, you have to take care that each and every key is factored.
wbI18n allows you to use the English message as an array key, so you don't need an English translation. If the visitor uses another language, but no translation is given, the English message is shown - not a meaningless key, or, worse, nothing.
Example:
Code:
// in your code
echo $lang->translate( 'This is the message to translate' );
// ...instead of...
// echo $MOD_WHATEVER['TRANSLATE_ME'];
// in your language module
$LANG = array(
'This is the message to translate' => 'Dies ist die Mitteilung, die übersetzt werden soll',
);
wbListBuilder
This is brand-new.
I added this class to wblib v0.10, when I found that, what I did for EasyMenu, would be very helpful for other modules, also. (FolderGallery, for example.)
wbListBuilder can create an unordered nested list from any array that has at least two attributes: One that contains a unique ID, and another one that contains the unique ID of the parent element.
Say you have an array of WB pages, directly from the database. An array element looks like this:
Code:
<?php
$pages
= array (
0
=>
array (
'page_id'
=>
'24'
,
'parent'
=>
'25'
,
'level'
=>
'1'
,
'link'
=>
'/topnav-de/kontakt'
,
'menu_title'
=>
'Kontakt'
,
'page_trail'
=>
'25,24'
,
'visibility'
=>
'public'
,
),
...
more elements
...
);
?>
In this example, 'page_id' is the unique item ID, 'parent' is the unique ID of the parent item. You can create a complete nested list from this array of pages like this:
Code:
<?php
$list
= new
wbListBuilder
();
$list
->
set
(
array(
'__title_key'
=>
'menu_title'
,
'__id_key'
=>
'page_id'
,
'__level_key'
=>
'level'
,
)
);
echo
$list
->
buildList
(
$list
->
buildRecursion
(
$pages
) );
?>
(Where $pages is the pages array as mentioned above.)
That's it!
Docs
In progress.
http://www.webbird.de/wblib/en
«
Last Edit: January 28, 2010, 06:35:55 PM by WebBird
»
Logged
mahalleday
Offline
Posts: 188
Re: Introducing wblib (Library Module)
«
Reply #1 on:
November 14, 2009, 01:49:05 AM »
This sounds great. It would liek to try and utilize this is future releases of the ad baker module. I'll have a read thru what dicumatation there is and see what I can make of it. Things liek this are exactly waht WB needs more common classes and functions that all developers can use, this will make WB modules more consistant and standardized. Good work.
Logged
AdBaker2 Project Site:
http://code.google.com/p/adbaker/
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #2 on:
November 14, 2009, 01:34:24 PM »
Thank you.
By the way, there's also a database class, but at the moment, it is built upon the WB database class. This will change in future, so I did not mention it.
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #3 on:
November 14, 2009, 01:58:39 PM »
Quote from: Clara on November 14, 2009, 01:46:15 PM
- will your database class make use of PHP 5 MySQLi and prepared statements and/or any sort of PDOs
I am going to use MySQLi (for MySQL), but I will also add drivers for PostgreSQL and SQLite. The database class is going to be kind of Database Abstraction Layer.
Quote from: Clara on November 14, 2009, 01:46:15 PM
- is your filter class based on
PHP 5.2 filters
and if not what are the main differences or benefits coming along with your class
No. I created my own class to fit my needs. (Played with PEAR::Validate, but did not really like it.) My class is completely based on PCRE. Decide yourself if this is what you want.
Again, I built this class to fit
my
needs.
It doesn't seem that the PHP 5 filters are meant to be extendible by the user. My filters are. I am going to add a method to let you add your own filters on runtime.
Also, wbValidate has a method to validate CSS.
More to come.
Edit: As of SPL: I worked with the Autoloader, but performance dropped noticeable, so I removed it.
«
Last Edit: November 14, 2009, 02:10:44 PM by WebBird
»
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #4 on:
November 17, 2009, 06:09:19 PM »
I started a doc page here:
http://www.webbird.de/wblib/de
(German language for now)
It's still incomplete! Take a look at [Klassen] -> [Template Engine] for a first glance.
Logged
Luisehahne
Board Member
Development Team
Offline
Posts: 2952
Re: Introducing wblib (Library Module)
«
Reply #5 on:
November 17, 2009, 08:31:08 PM »
Yes, a examples page will be very helpfull.
Dietmar
Logged
We are human beings - and nobody is perfect at all.
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #6 on:
November 18, 2009, 10:41:23 AM »
I will link to modules using wblib later. Should be good enough for examples.
Edit: I have added an example for the FormBuilder class.
http://www.webing.de/webbird/wblib/de/index.php?n=Klassen.WbFormBuilderEx
«
Last Edit: November 18, 2009, 05:19:20 PM by WebBird
»
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #7 on:
December 02, 2009, 05:23:25 PM »
I've just released wblib v0.12
Template Engine can now handle conditionals as part of loops *)
Improved handling of checkboxes and radio buttons in FormBuilder
*)
Known issue:
Don't wrap a {{ :loop }} into an {{ :if }}. This won't work!
«
Last Edit: December 03, 2009, 02:44:44 PM by WebBird
»
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #8 on:
December 03, 2009, 02:43:49 PM »
wblib is now hosted at
http://github.com/webbird/wblib/
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #9 on:
December 07, 2009, 01:03:23 PM »
wblib v0.13 is available now.
wbFormBuilder
* "required" and "readonly" flags for fields can now be altered at runtime.
-> setRequired(<name>)
-> unsetRequired(<name>)
-> setReadonly(<name>)
-> unsetReadonly(<name>)
* Added "top" anchor to form.
* New field type "infotext" for pure text as part of the form.
wbI18n
Fix to avoid break when "message" committed to
translate()
is not a string.
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #10 on:
December 14, 2009, 05:47:09 PM »
I decided to build the
wbDatabase
class upon
PDO
,
not
mysqli. There are some issues with mysqli which make it hard to create an abstraction layer upon it. (The way variables are bound, for example.)
As
wbDatabase
is built upon PDO, I will focus on statement abstraction instead of DB abstraction.
Example:
Code:
<?php
$this
->
db
=
wbDatabase
::
singleton
(
array(
'user'
=>
DB_USERNAME
,
'pass'
=>
DB_PASSWORD
,
'dbname'
=>
DB_NAME
,
'prefix'
=>
TABLE_PREFIX
,
)
);
$result
=
$this
->
db
->
search
(
array(
'tables'
=> array(
'sections'
,
'pages'
),
'fields'
=> array(
'module'
,
'page_title'
),
'where'
=>
't1.page_id == ? and section_id == ?'
,
'params'
=> array(
1
,
1
)
)
);
Statement created (and executed using the params given in the 'params' attribute):
Code:
SELECT module, page_title FROM wb_sections as t1, wb_pages as t2 WHERE t1.page_id = ? AND section_id = ?
Specific joins will be supported later.
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #11 on:
December 29, 2009, 05:41:04 PM »
I've just released v0.14.
This version includes some first steps with wbDatabase.
* New: KLogger library (
http://codefury.net/projects/klogger/
) for logging/debugging. Please note that I made some changes in that library to fit my needs.
* New template markup
{{ :lang This is a string to be translated }}
for easier language handling
* Fix: Better handling of nested
{{ :if }}/{{ :loop }}
* Some more fixes/additions I don't remember in detail
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #12 on:
January 28, 2010, 06:30:18 PM »
http://www.webbird.de/wblib/en
This is the first time the docs are more up-to-date than the module download.
But I am going to release an update next week.
Logged
doc
Guest
Re: Introducing wblib (Library Module)
«
Reply #13 on:
January 28, 2010, 07:32:22 PM »
Hi,
looking forward. Hope your lib is as easy to use as the documentation reads
Doc
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #14 on:
January 29, 2010, 10:55:26 AM »
Well, I'm not very happy with the FormBuilder yet - it works very nice, but it's a bit complicated to use. I am going to improve it, so this is the reason the docs are missing for this class at the moment.
My personal favorites are the Template Engine and the ListBuilder. In fact I LOVE the ListBuilder.
If it's allowed to say that about my own work.
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #15 on:
February 02, 2010, 12:01:08 PM »
I'm quite happy with the way the new recoded FormBuilder is going. I take the opportunity to equalize the method names of the different libs, which also gave me the chance to move some of them out of the specific lib and into the "mother of all libs" wbBase.
Here's a new usage example:
Code:
// include the class
include_once 'wblib/class.wbFormBuilder.php';
// create FormBuilder instance
// If you have a file named 'inc.forms.php' in your current
// workdir, it will be loaded automatically
$form = new wbFormBuilder();
// print the form
echo $form->getForm();
As I put some "magic" into the lib, this can be enough to create a full featured form.
The "magic" is to create a file "inc.forms.php" in the current workdir (=the directory the executed script is located) and define the form elements there. (Element type, required or not, allowed values etc.) This is done using a simple array:
Code:
$FORMS = array(
'settings' =>
array(
array(
'type' => 'hidden',
'name' => 'page_id',
'allow' => 'number',
'value' => '1',
),
array(
'type' => 'hidden',
'name' => 'section_id',
'allow' => 'number',
'value' => '1',
),
array(
'type' => 'text',
'name' => 'addons_per_page',
'label' => 'Show X addons per page',
'allow' => 'integer',
'required' => true,
'missing' => 'Please enter a valid number!',
'invalid' => 'Please enter a valid number!',
),
array(
'type' => 'text',
'name' => 'date_format',
'label' => 'Date format',
'allow' => 'string',
'required' => true,
'missing' => 'Please enter a valid strftime() format!',
'invalid' => 'Please enter a valid strftime() format!',
),
),
),
);
The key "settings" in the example is a form name, so you can define several forms in only one config file and use them passing the name to getForm:
Code:
echo $form->getForm( 'settings' );
If no submit button is defined in your form, wbFormBuilder creates one automatically. You can also set the name of that button, so wbFormBuilder can recognize that the form is sent and check the form data for you automatically. It will show any errors in the form without any additional coding.
More to come soon.
Logged
WebBird
Guest
Re: Introducing wblib (Library Module)
«
Reply #16 on:
February 02, 2010, 06:19:23 PM »
Just uploaded v0.30 to AMASP.
http://www.websitebakers.com/pages/libs/wblib.php
Please note that the FormBuilder is still incomplete. (Recode in progress.) There may also be some "new bugs" that result from some bigger changes I made.
Module is no longer available. You may send me a PM if you wish to test it.
«
Last Edit: March 16, 2010, 12:08:07 PM by WebBird
»
Logged
mahalleday
Offline
Posts: 188
Re: Introducing wblib (Library Module)
«
Reply #17 on:
March 16, 2010, 02:06:35 AM »
The download link appears to be broken it redirects to the asamp login page.
Logged
AdBaker2 Project Site:
http://code.google.com/p/adbaker/
erpe
Offline
Posts: 2077
Re: Introducing wblib (Library Module)
«
Reply #18 on:
March 16, 2010, 08:57:24 AM »
Module has been removed from AMASP on demand of webbird.
Module should not be available anymore.
rgds
erpe
Logged
stories about
be part of the Tutorials-Project
visit the jQuery-Showroom
Waldschwein
Guest
Re: Introducing wblib (Library Module)
«
Reply #19 on:
March 16, 2010, 12:16:41 PM »
Hello!
Ok, after closing this thread was a wish, I will do it...
Yours Michael
Logged
Pages: [
1
]
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
-----------------------------
English
-----------------------------
=> Help & Support
-----------------------------
General
-----------------------------
=> WebsiteBaker Website Showcase
-----------------------------
English
-----------------------------
=> Modules
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
-----------------------------
General
-----------------------------
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
-----------------------------
General
-----------------------------
=> Security Announcements
-----------------------------
Deutsch (German)
-----------------------------
=> Hilfe/Support
-----------------------------
General
-----------------------------
=> Documentation
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
=> Module & Snippets
-----------------------------
English
-----------------------------
=> Archive (posts up to 2007)
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Deutsch (German)
-----------------------------
=> jQuery
=> Tutorials
=> Templates & Design
-----------------------------
English
-----------------------------
=> jQuery
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
===> Suggestions
-----------------------------
Deutsch (German)
-----------------------------
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
===> Vorschläge
-----------------------------
English
-----------------------------
===> Software bugs
-----------------------------
Deutsch (German)
-----------------------------
===> Softwarefehler
=====> Module / Extensions
-----------------------------
English
-----------------------------
=====> Modules / Extensions
-----------------------------
Deutsch (German)
-----------------------------
===> Erfahrungs und Testberichte
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...