VJ’s Warez

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 Microsoft AJAX Library from PHP applications. With this first Alpha release, it simply supports exposing PHP classes as AJAX-enabled web services, just as in ASP.NET applications. In fact, the generated proxies are identical to what you get from ASP.NET, meaning you can have full interoperability.

Hello World

The service on the backend so to speak:

  1. <?php
  2. require_once ‘../../dist/MSAjaxService.php’;
  3. class HelloService extends MSAjaxService
  4. {
  5. function SayHello($name)
  6. {
  7. return “Hello, “ . $name . “!”;
  8. }
  9. }
  10. $h = new HelloService();
  11. $h->ProcessRequest();

And the front end that will talk to it:

  1. <title>Hello, World!</title>
  2. <script type=“text/javascript” src=“../../MicrosoftAjaxLibrary/MicrosoftAjax.js”></script>
  3. <script type=“text/javascript” src=“HelloService.php/js”></script>
  4. </head>
  5. Name: <input id=“name” type=“text” />
  6. <input type=“button” value=“Say Hello” onclick=“button_click(); return false;” />
  7. <br />
  8. Response from server: <span id=“response”></span>
  9. </body>
  10. <script type=“text/javascript”>
  11. function button_click() {
  12. HelloService.SayHello($get(‘name’).value, function (result) {
  13. $get(‘response’).innerHTML = result;
  14. });
  15. }
  16. </script>
  17. </html>

Sam Ruby has that way about him that sees things very clearly. He just took a peak at jQuery for the first time and was able to really put into words what I think jQuery enthusiasts like about the library:

The notable thing about this is that despite all of the asynchronous events taking place, the code is sequential (nested, but sequential), and that the JSON results of the AJAX call is immediately available to the function that is invoked when the selection changes.

This is based on the following code that he wrote:

  1. $(“#archive”).click(function() {
  2. $.getJSON(‘unscanned.cgi’, {}, function(unscanned) {
  3. // replace realname input field with a selection list
  4. var select = $(‘<select name=”realname” id=”realname”/>’)[0];
  5. for (var i=0; i<unscanned .length; i++) {
  6. select.options[i] = new Option(unscanned[i][1], i);
  7. }
  8. $(‘#realname’).before(select).remove();
  9. $(“#archive”).attr(“disabled”,“disabled”);
  10. // process selection
  11. $(‘#realname’).focus().change(function() {
  12. var icla = unscanned[$(“#realname option:selected”).val()];
  13. $(“#realname”).before(‘<input type=”text” ‘ +
  14. ‘id=”realname” name=”realname”/>’).remove();
  15. $(“#realname”).val(icla[1]);
  16. $(“#pubname”).val(icla[2]);
  17. $(“#email”).val(icla[3]);
  18. $(“#replaces”).val(icla[0] + ‘:’ + icla[3]);
  19. $(“#filename”).val().focus();
  20. $(“#archive”).removeAttr(“disabled”);
  21. });
  22. });
  23. return false;
  24. });

Those that love jQuery, love the API.

John himself had an example in the comments:

  1. $(‘:radio[name=is_user]’)
  2. .change(function(){ $(‘.depends-isuser’)[ this.value == 1 ? ‘show’ : ‘hide’ ](); })
  3. .change();

jQuery 1.3 beta 1 has been released with John and the team asking for testing help.

This is a big release as a lot has been changed:

  • Sizzle has been integrated
  • No more browser testing: For example, no more if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { which is replaced with if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
  • Live event delegration: Reglib’s claim to fame was how event delegation was “live” meaning that if you added elements later on, they would also fall into the same delegations. With $("#foo > div").live("click", someFn); you get the same in jQuery
  • $(this).closest("div");: Returns this or closest ancestor that matches selector
  • .offset() rewrite – significantly faster, uses no browser sniffing.
  • .hide()/.show() rewrite – 50% – 200% faster.
  • .append/prepend/before/after rewrite – 10-15x faster.
Tags:

I like getting data from the web and I love JSON – as it is easy to use. The issue is that not many things on the web come as JSON from the get-go. Hence we need converters. You can use cURL and beautiful soup or roll your own hell of regular expressions. Alternatively you can use Yahoo Pipes to build your converter. Pipes is the bomb but a lot of people complained that there is no version control and that you need to use the very graphical interface to get to your data (which was the point of Pipes but let’s not go there).

AlasRejoice for there is a solution now available and it is called YQL. YQL is a SQL-style language to get information from all kind of web services, and – using oAuth – even Yahoo’s social graph. There is a test console available for you to get to grips with all the information it gives you access to (which is a lot!):

The YQL console

Here comes the kicker though: for all the open services that don’t need authentication you can use these YQL statements as a REST API with JSON output and an optional callback function for JSON-P by adding it to http://query.yahooapis.com/v1/public/yql?. For example to get the latest three headlines from Ajaxian’s RSS feed as JSON and wrap it in a function called leechajaxian do the following: Read the rest of this entry »

Today we are fortunate to have a guest post by Patrick Lightbody, most recently of BrowserMob fame (and previously Selenium work, OpenQA, WebWork, and more). Let’s listen in to him talk to us about load testing, and let him know your thoughts in the comments below:

I’ve been developing and testing complex web apps for a long time. I was the co-creator of WebWork (now Struts 2.0) and an early champion of DWR, writing one of the first AJAX form validation frameworks for Java web apps. But over the years, I noticed that as our web technologies and techniques got more sophisticated, our testing techniques were not keeping up.

That was why I founded OpenQA and helped grow Selenium to the popular testing tool that it is today. Selenium helps with functional testing of complex AJAX apps, but there isn’t an equivalent for load testing, which is why I started BrowserMob, a new type of load testing service. Read the rest of this entry »

At a New Years Eve party, a friend help up a drink and toasted to his company deciding to discontinue direct support of IE 6 in 2009, and letting users know that the site may work better with IE 7 or another latest browser.

Then, Asa Dotzer puts up a chart of the IE 6 numbers:

Read the rest of this entry »

So, another “PHP sucks” post, this time from Jeff Atwood. He actually ends up even kind of praising PHP, surprised by its success. I have a couple of thoughts on that topic too.

First, people really need to stop reading something on PHP written somewhere in 2005 (probably about experiences that happened in 2001) and apply it to PHP as it is now, without even checking around for current trends. It’s as if people would dig up books from middle ages saying that there are only seven metals in existence or debating about phlogiston, and would use it speaking about the modern chemistry. Come on! Read the rest of this entry »

My blog grew substantially during 2008. I gained thousands more RSS subscribers, my MooTools skills took a giant leap, and I even branched out in jQuery a little bit. That said, I feel like the blog just beginning. I’ve outlined some goals for 2009 — any feedback or requests would be appreciated.

1. New Redesign

I’m not happy with the current “design”. It’s too plain and even though I’m not a designer, I think I could do a lot better. I have a new redesign that’s about 25% done that I really love so far and hope to get out by February 1st. I will be giving peeks via Twitter very soon.

2. Walk the Walk

I write a lot of useful MooTools scripts. The problem is that I don’t actually use many of them on my site. My goal is to avoid overdoing my the MooTools “flash bang” effects but tastefully add enhancements here and there. I think people will like the new effects a lot. Read the rest of this entry »

Tags:

A new year usually brings hope of better things. It also bring expectations and wonder. Here are my (unfounded) web predictions for 2009.

1. A Javascript Framework Will Fall

I believe that a javascript framework will fall in 2009. I really wouldn’t be shocked to see one go. I don’t want to share which I think will fall, but the popularity of jQuery, coupled with the lack of progress being made on a few of them, makes me feel as though at least one will die off.


2. Firefox’s Usage Will Grow Tremendously…

I believe more businesses will steer their employees toward using Mozilla Firefox and thus increase Firefox’s usage. Internet Explorer’s sluggish performance coupled with Firefox’s feature set will make IE a secondary browser for many businesses.


3. …But IE Will Continue Its Reign

Too many users simply take what they’re given and this will not change. Internet Explorer 6 and 7, and on a lower usage level 8, will continue to dominate the browser market share.


4. MooTools’ Popularity Will Grow

MooTools will release a plugin forge which will quickly become a treasure chest that will attract many web developers.


5. Developers Find Out: Knowing One Framework Isn’t Good Enough

While being an expert with on javascript framework is great, developers will realize that knowing one framework isn’t good enough. Porting plugins from a different framework to the developer’s preferred framework will become tiresome and the process of reinventing the wheel will be the motivation pick up another framework.


Have any predictions of your own? Am I crazy? Share!

One of my customers has an insane amount of PDF and Microsoft Word DOC files on their website. It’s core to their online services so it’s not as though they’re garbage files up on the server. My customer wanted their website’s search engine (Sphider) to read these PDF files and DOC files so that their clients could get at the documents they needed without going through a bunch of summary pages to get them. I was successful in the task, so let me show you how to read PDF and DOC files using PHP.

Reading PDF Files

To read PDF files, you will need to install the XPDF package, which includes “pdftotext.” Once you have XPDF/pdftotext installed, you run the following PHP statement to get the PDF text:

$content = shell_exec(/usr/local/bin/pdftotext.$filename.‘ -‘); //dash at the end to output it

    Reading DOC Files

    Like the PDF example above, you’ll need to download another package. This package is called Antiword. Here’s the code to grab the Word DOC content:

    $result = shell_exec(/usr/local/bin/antiword .$filename);

      The above code does NOT read DOCX files and does not (and purposely so) preserve formatting. There are other libraries that will preserve formatting but in our case, we just want to get at the text.

      Tags:

      VJ’s Warez