Welcome, Guest. Please login or register.
Did you miss your activation email?
February 13, 2012, 03:22:19 AM

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
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Introducing wblib (Library Module)  (Read 2235 times)
WebBird
Guest
« 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. rolleyes

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. wink

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. grin 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 (
  
=> 
  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! rolleyes


Docs

In progress. http://www.webbird.de/wblib/en
« Last Edit: January 28, 2010, 06:35:55 PM by WebBird » Logged
mahalleday

Offline Offline

Posts: 188



WWW
« 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
« Reply #2 on: November 14, 2009, 01:34:24 PM »

Thank you. grin

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. wink
Logged
WebBird
Guest
« Reply #3 on: November 14, 2009, 01:58:39 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.

- 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. Wink Again, I built this class to fit my needs. Wink

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
« 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 Offline

Posts: 2952



WWW
« 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
« Reply #6 on: November 18, 2009, 10:41:23 AM »

I will link to modules using wblib later. Should be good enough for examples. grin

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
« 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
« Reply #8 on: December 03, 2009, 02:43:49 PM »

wblib is now hosted at http://github.com/webbird/wblib/
Logged
WebBird
Guest
« 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
« 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)
            )
        );

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
« 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 grin
Logged
WebBird
Guest
« 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. wink But I am going to release an update next week.
Logged
doc
Guest
« 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 wink

Doc
Logged
WebBird
Guest
« 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. grin

My personal favorites are the Template Engine and the ListBuilder. In fact I LOVE the ListBuilder. grin If it's allowed to say that about my own work. rolleyes
Logged
WebBird
Guest
« 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. grin

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. grin 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. grin

More to come soon.
Logged
WebBird
Guest
« 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 Offline

Posts: 188



WWW
« 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 Offline

Posts: 2077


WWW
« 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

Waldschwein
Guest
« 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
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!