Activate your free membership today | Log-in

Thursday, March 6th, 2008

To ExtPHP, or to PHP-Ext?

Category: JavaScript, PHP, Ext

I got emails on the same day from two developers letting me know about ExtJS wrappers for PHP.

PHP-Ext

First, Sergei Walter Guerra told me about PHP-Ext "an open source widget library written for PHP 4 and 5 to empower the UI Layer."

The API looks like this:

PHP:
  1.  
  2. echo Ext::onReady(
  3.         Javascript::stm(ExtQuickTips::init()),
  4.         Javascript::assign("data",Javascript::valueToJavascript($myData)),
  5.         //Javascript::valueToJavascript($myData),
  6.         $store->getJavascript(false, "ds"),
  7.         $italicRenderer,
  8.         $changeRenderer,
  9.         $pctChangeRenderer,
  10.         $colModel->getJavascript(false, "colModel"),
  11.         $gridForm->getJavascript(false, "gridForm")
  12. );
  13.  
  14. $gridForm = new ExtFormPanel("company-form");
  15. $gridForm->Frame = true;
  16. $gridForm->LabelAlign = EXT_FORM_LABEL_ALIGN_LEFT;
  17. $gridForm->Title = "Company Data";
  18. $gridForm->BodyStyle = "padding: 5px;";
  19. $gridForm->Width = 750;
  20. $gridForm->Layout = EXT_CONTAINER_LAYOUTS_COLUMN;
  21.  

ExtPHP

Then Chris Ravenscroft came to me to announce ExtPHP:

"It is something that I had to think about in my day job, because my team is migrating to PHP for web development and I believe that we simply do not have enough time for them to learn JavaScript's intricacies, I needed to be the one person who would have to wrestle JavaScript when problems happened. I therefore needed a way to insulate them from the gory details, which is why I created ExtPHP."

The API looks like this:

PHP:
  1.  
  2. $cfg = new Ext_Viewport_Config();
  3. $viewport = new Ext_Viewport(
  4.         $cfg->
  5.                 layout('border')->
  6.                 items(array($actionpanel, $tabpanel->name()))
  7. );
  8. $viewport->jsrender();
  9.  
  10. $tabpanel->add(
  11.         array('title'=>'New Tab', 'iconCls'=>'tabs', 'autoLoad'=>
  12.                 array('url'=>'extphptest.php?content1'),
  13.                 'closable'=>true
  14.         )
  15. );
  16.  
  17. new JsReady(JsWriter::get());
  18.  

Maybe you guys can join forces? :)

Posted by Dion Almaer at 8:54 am
7 Comments

++---
2.9 rating from 94 votes

Thursday, February 28th, 2008

Every keystroke is a prisoner - a neat commenting trick

Category: JavaScript, PHP, Tip

My favourite kind of tutorial or trick are the ones that are very easy to do but make a lot of sense - you know the ones that make you slap your forehead and say "why didn't I do that before?".

Dirk Ginader blogged about a commenting trick (in German) that is one of these. He rightly claims that when you develop, you will comment and uncomment a lot as you optimise and test your code. This means either inserting lines with comment and deleting those lines, adding and deleting the /* */ by hand or using a shortcut of your editor of choice (I loved Homesite for ctrl+shift+m). In any case, it means highlighting several lines to comment in or out.

If you however use the following syntax then you only need to delete one slash to comment and uncomment a section:

JAVASCRIPT:
  1.  
  2. foo();
  3. /*
  4. bar();
  5. baz.foo = 200;
  6. return{
  7.   dolly:clone()
  8. }
  9. // */
  10.  

The trick is the // before the closing */. With this you can just add another slash before the opening one and uncomment the block this way.

JAVASCRIPT:
  1.  
  2. foo();
  3. //*
  4. bar();
  5. baz.foo = 200;
  6. return{
  7.   dolly:clone()
  8. }
  9. // */
  10.  

This works in many languages, alas not in CSS as there is no single line comment.

Update: in CSS you can just delete and add and remove an asterisk:

CSS:
  1. .test{
  2.     border:1px solid red;
  3.     /*/
  4.     background-color:blue;
  5.     /**/
  6.     margin:1em;
  7. }
  8.  
CSS:
  1. .test{
  2.     border:1px solid red;
  3.     /**/
  4.     background-color:blue;
  5.     /**/
  6.     margin:1em;
  7. }
  8.  

Posted by Chris Heilmann at 3:57 am
15 Comments

+++--
3.9 rating from 37 votes

Monday, January 14th, 2008

HTML Purifier 3.0

Category: Library, PHP, Security

HTML Purifier 3.0 has been released.

What is HTML Purifier?

HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications.

What's new in 3.0?

Release 3.0.0 is the first release of 2008 and also HTML Purifier's first
PHP 5 only release.
The 2.1 series will still
be supported for bug and security fixes,
but will not get new features. This release a number of
improvements in CSS handling, including the filter
HTMLPurifier_Filter_ExtractStyleBlocks which integrates
HTML Purifier with
CSSTidy for cleaning style sheets
(see the source code file for more information on usage), contains
experimental support for
proprietary CSS properties with %CSS.Proprietary, case-insensitive
CSS properties, and more lenient hexadecimal color codes. Also, all code
has been upgraded to full PHP 5 and is
E_STRICT clean for all versions of PHP 5 (including the
5.0 series, which previously had parse-time errors).

You can run a live demo to see it at work.

Posted by Dion Almaer at 6:08 am
3 Comments

+++--
3.6 rating from 18 votes

Thursday, January 10th, 2008

Simplicity: PHP Ajax Framework using Ext

Category: PHP, Framework

John Le Drew has been working on a PHP framework for a few years, and has now packaged it as Simplicity:

The Simplicity PHP Application Framework is an advanced, scalable and extensible PHP application framework to aid developers in creating high traffic, high availability Web 2.0 online applications. Integrating a solid MVC framework with some of the best Open Source projects around Simplicity aims to assist developers with any amount of experience in taking their applications to a new level.

You can get to the code on the launchpad for the framework.

One important piece is the Ajax admin console, developed in Ext that allows a developer will be able to configure all aspects of their application via the Ajax interface, this includes database modeling and the creation of stub controllers, and even the addition of predefined actions to speed up development.

Simplicity

Posted by Dion Almaer at 11:59 am
5 Comments

++++-
4 rating from 29 votes

Friday, July 20th, 2007

Google Gears for Offline Data Entry

Category: Prototype, PHP, Articles, Gears

Jack Herrington has written his second article in his series on Gears.

The article goes into detail on creating a form based data entry application that works offline. This means that entries are batched up, so when the user goes online they can be sync'd up. The forms are sent using Prototype and Ajax.Updater.

Jack iterates on the data model, going from a simple blog, to separate content.

Conclusion

For years now, web applications have been stuck at the 90 percent solution mark. Web applications are incredibly easy to develop, but fail utterly when the customer isn't connected to the Web. On the day Google Gears was released, I knew that this status quo had instantly changed. Just as the addition of Ajax functionality to the browser was the one small step that added rich interactivity, this small step of Gears solves one of the few remaining problems of web development. What a powerful tool indeed!

Posted by Dion Almaer at 12:01 am
8 Comments

+++--
3.8 rating from 27 votes

Friday, July 13th, 2007

J4P5: JavaScript interpreter written in PHP 5

Category: JavaScript, PHP

I haven't seen many languages implemented in PHP. J4P5 "is a JavaScript interpreter written in PHP 5, that allows to run untrusted scripts in a sandbox on your server. It aims to implement most of Ecma-262 3d edition."

J4P5 uses a modified version of the CFG parser of the MetaPHP project, and is licensed under the GPL

This project is new. The current version already exposes most of the features commonly associated with JavaScript, such as objects, prototypes, closures.

Notable caveats of this version (aka "the TODO list"):

  • No support for unicode strings
  • No support for regular expressions
  • Semi-colons at the end of statements are not optional
  • Most of the pre-defined objects/methods have not been tested
  • The speed is definitely slower than PHP. It's getting better though.

Posted by Dion Almaer at 2:23 am
12 Comments

++++-
4 rating from 42 votes

Monday, June 18th, 2007

plainTemplate & phpQuery

Category: PHP, jQuery

plainTemplate is a new library that aims to separate out an HTML template from design and coding, thanks to selectors.

The designer works by simply using HTML in any way they wish, and then the programmer:

  • Write selectors based on HTML structure
  • Pass those selectors and Controller data to plainTemplate
  • plainTemplate parses template, removing designer's example data
  • If there is a need, you can manually write template proccessing rules with phpQuery - a jQuery port to PHP
  • Everything caches to pure, human-readable PHP file, similar to that one written with no template engine
  • From one HTML file You can build several templates
  • Once the Designer updates the file, the cached template updates itself transparently

phpQuery is a port of jQuery that let's you do things like this:

PHP:
  1.  
  2. _('body div.myClass.myClass2 ul> li:first')
  3.         ->parent()
  4.                 ->prepend('<li>my new first LI</li>')
  5.                 ->parents('.myClass')
  6.                         ->remove()
  7.                         ->end()
  8.                 ->appendTo('body');
  9.  

Download plainTemplate

Posted by Dion Almaer at 7:35 am
13 Comments

+++--
3.1 rating from 37 votes

Wednesday, May 9th, 2007

XAJAX PHP Live Datagrid

Category: JavaScript, PHP, Examples

Timothy Lorens has created a XAJAX PHP Live Datagrid that is as simple to setup as:

HTML:
  1.  
  2. <div id=“dataGrid” align=“center”></div>
  3. <script type=“text/javascript”>
  4.   xajax_showDataGrid();
  5. </script>
  6.  

xajax_showDataGrid is a callback where you get to implement methods such as passing back how many rows there are, and the rows to show.

Xajax Data Grid

Posted by Dion Almaer at 6:49 am
16 Comments

+++--
3.6 rating from 121 votes

Thursday, March 15th, 2007

jQPie: jQuery PHP interface extension

Category: Library, PHP, jQuery

jQPie is a lightweight PHP interface to jQuery that supports XML, HTML and JSON handlers.

What can jQPie do?

  • Easily request and process data from php using $.getJSON Example
  • Inject php generated html into elements using $.(element).load Example
  • Call php functions directly from your web pages using $.jqpie Example
  • Call jQuery from php in respond to $.jqpie calls Example
  • Advanced autocomplete using jqpie_complete ExampleAuto

jQPie

Posted by Dion Almaer at 5:55 am
9 Comments

+++--
3.4 rating from 62 votes

Wednesday, March 14th, 2007

Sun Web Developer Pack

Category: Java, Library, PHP, jMaki

The Sun Web Developer Pack isn't a sexy name, and having 'Sun' start it out often doesn't help a technology.... but there is some good technology here.

The Sun Web Developer Pack helps you to leverage emerging web technologies and techniques to create interactive and dynamic web applications for the enterprise. This toolkit is a collection of technologies for Ajax, Scripting and REST-based services development supported by a NetBeans plugin that simplifies the design and development of Rich Internet Applications.

If you look past the marketing-speak you see that Sun has packaged technology such as Project jMaki and Project Phobos.

jMaki is a lightweight, client/server framework for creating JavaScript-centric Web 2.0 applications. You can use jMaki when developing with PHP, Portlets, Facelets, Java, and JavaScript.

Do you see that? Since when did Sun create something that lets you develop with PHP :)

Phobos is a lightweight, scripting-friendly web application environment that runs on the Java platform.

Phobos allows you to write with JavaScript on the server side, which can be very powerful indeed.

There are a vast number of demos available including interesting mashups.

Sun Web Developer Pack

Posted by Dion Almaer at 10:14 am
8 Comments

+++--
3.4 rating from 35 votes

Wednesday, February 28th, 2007

Symfony Unobtrusive JavaScript Plug-In

Category: PHP, jQuery

François Zaninotto has been talking about a new Unobtrusive JavaScript Plug-In for symfony.

Simple Example

PHP:
  1.  
  2. <div id="foobar">
  3.   I'm here !
  4. </div>
  5. <?php UJS("$('#foobar').css('display', 'none')") ?>
  6.  

How it is generated

PHP:
  1.  
  2. <?php UJS_write('<a href="#" onclick="$(\'#foobar\').toggle();return false;">click me') ?>
  3. <div id="foobar">
  4.   I'm here !
  5. </div>
  6. <?php UJS_change_style('#foobar', 'display:none') ?>
  7.  

this becomes...

HTML:
  1.  
  2. <span style="display: none" class="UJS_placeholder" id="UJS_0"></span>
  3. <div id="foobar">
  4.   I'm here !
  5. </div>
  6. ...
  7. //  <![CDATA[
  8. $().ready(function(){
  9.     $('#UJS_0').after('<a href="#" onclick="$(\'#foobar\').toggle();return false;">click me');
  10.     $('#UJS_0').remove();
  11.     $('#foobar').css('display', 'none');
  12.  })
  13. //  ]]>
  14. </script>
  15.  

Posted by Dion Almaer at 11:15 am
12 Comments

+++--
3.5 rating from 30 votes

Thursday, February 22nd, 2007

PQuery - PHP and jQuery

Category: Library, PHP, jQuery

PQuery is to jQuery as Rails helpers is to Prototype and Script.aculo.us:

PQuery is a set of helper classes for JQuery JavaScript library.This library allows you to easily integrate AJAX , Effects and other JQuery functionality into your PHP scripts.IT has a small foot print and is compatible with PHP4 and PHP5.

PHP:
  1.  
  2. <?=$pquery->form_remote_tag(array('url'=>'index.php?task=ajax','update'=>'#idtoupdate'));?>
  3. Field : <input type="text" name="field" /><br />
  4. <input type="submit" />
  5.  
  6.  

Posted by Dion Almaer at 6:23 am
27 Comments

+++--
3.5 rating from 90 votes

Wednesday, January 24th, 2007

PHP for Microsoft Ajax Library

Category: .NET, PHP

Steve Marx has created a PHP library for the Microsoft Ajax 1.0 release that uses the JavaScript piece in PHP land.

The Microsoft AJAX Library is a pure-JavaScript library that's used by ASP.NET AJAX but is also available as a separate download. Because it's pure JavaScript, it's not tied to ASP.NET on the backend. PHP for MS AJAX is code to help you make use of the Micr