New module for testing - XajaxInterface - background JS calls to PHP

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
100rk

New module for testing - XajaxInterface - background JS calls to PHP

Post by 100rk »

xajax http://xajax.sourceforge.net/ is an open source PHP class library for easily creating powerful PHP-driven, web-based AJAX Applications. Using xajax, you can asynchronously call PHP functions and update the content of your webpage without reloading the page.

There are some similar projects, like Sajax, JPSpan etc, but xajax is as simple as possible. I just finished module, which completely encapsulated my needs for testing xajax on CMSMS : http://100rk.org/files/XajaxInterface.zip.

Do You want to see THIS demo http://xajax.sourceforge.net/thewall.php on Your page? Just install my module and paste code into Your page/template

Code: Select all

{cms_module module="XajaxInterface"}
.

OR (I HOPE): do You want to use this module for Your purposes? GREAT!!!! Just adopt it, make proper English comments and post it on wiki - ANYBODY WHO LIKES IT.

Small tutorial how to use it in Your modules is in GetHelp() function - but all English texts are waiting for somebody who really speaks English.

I am waiting for Your comments/ideas - otherwise I will delete this file from my web in during next 14 days.
Last edited by 100rk on Fri Jun 10, 2005 10:15 am, edited 1 time in total.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by Ted »

I would love to look into this for the 2.0 admin interface.  Some things (like content editing) would be WONDERFUL if they didn't have to reload all the time, like for preview.  AJAX is an up and coming technology that's really changing web applications and I would love to be on the forefront of it if it'll help make CMSMS a better application.
100rk

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by 100rk »

Yes, there is a lot of utilizations - preview, autosave, realtime checks of form fields (unique page_alias etc) or whatever.

I am just playing with one enhanced database filter - which will show count of accepted records just in time user changed form fields and before he clicks to button 'DISPLAY'. I do not like iframes and I am pretty stupid man (or: I hate so-called language named JavaScript) and it is very complex webpage with a lot of informations and it is pretty old too, so a lot of hands was changing its code... You know what I mean, I am sure. There is tens of reasons why I don't want to reload whole page just because client wants this integer in form. By the way - he is right - I also hate filters, which returns 'no records' :-)

OK, I will sit down and write some simple example how to utilize module XajaxInterface right now.

TASK: I want to write a plugin, which will:
  • track down all words, which user types in some textareas in public interface - include wrong typed and later corrected one's, exclude last word in text
  • inform user how many unique words was used in this textarea in during last check
  • for debug purposes I want to be able to display all of unique words, collected in during actual session
WHAT OUTPUT OF INDEX I WANT: text files in directory /tmp/cache with names like session_id().'.wordindex.txt' and content: all words which user typed in protected textareas
WHAT I NEED: CMSMS, module XajaxInterface, textarea with own HTML id on public page (hand-coded, from other module, or from other plugin...)
WHAT I HAVE TO DO: write short php file (plugin), copy it into plugins directory and declare it in page with watched textarea

IN DETAIL:
  • every XXX seconds send content of textarea with id YYY to server
  • split this text by spaces, cut off last word (it can be unfinished) - I don't care about person which types text from the middle, so I know there will be a lot of words in index
  • if it is necessary, update index of unique words in text file of this session
  • change innerHTML parameter of some DIV - put here count of unique words in this textarea
  • if we are running debug mode, display all unique words for this session (not only for this textarea)
HOW I WANT TO USE THIS PLUGIN:
There will be only one required parameter:

Code: Select all

{wordindex textarea_id='userRequest'}
manage textarea with id 'userRequest', default 3 seconds interval

Other examples of use:

Code: Select all

{wordindex textarea_id='userRequest' interval='2000'}
manage textarea with id 'userRequest', 2 seconds interval (2000 miliseconds)

Code: Select all

{wordindex textarea_id='userRequest' debug='1'}
manage textarea with id 'userRequest', default 3 seconds interval and display all unique words from watched textareas (for my session, of course)

So people, try to check this topic later - I am going to rewrite module XajaxInterface (I need more options for registration callback functions for my purposes) and then I will put all stuff here.
Last edited by 100rk on Thu Jun 23, 2005 3:38 am, edited 1 time in total.
100rk

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by 100rk »

It is done. :-)

Changes in module XajaxInterface: added method unregisterFunction() - module is here: http://100rk.org/files/XajaxInterface.zip

Plugin I was talking about is here: http://100rk.org/files/function.wordindex.php - just visit this link (this file will highlight itself in browser), copy&paste it's content to file named 'function.wordindex.php' and put this file to Your /plugins directory. Do not worry about length of this file - it is full of comments (for curious and impatient developers).

NOTE: this plugin is also for testing purposes only, because:
  • it do not care about last word in text (it count it for display count of unique words, but not index it)
  • it do not care about right parsing of text, so there are some issues with non-iso characters
For quick explanation what can be done with module XajaxInterface (take look into file xajax.inc.php, class 'xajaxResponse'):

Code: Select all

$objResponse->addAlert(); // method for display alert box
$objResponse->addAssign(); // method for assign content to html part with id
$objResponse->addAppend(); // method for append content to html part with id
$objResponse->addPrepend(); // method for prepend content to html part with id
$objResponse->addReplace(); // method for replacing any part of content of html part with id
$objResponse->addClear(); // method for clearing content of html part with id
$objResponse->addScript(); // method for run some JavaScript in page
ENJOY and write here some comments, please! Mozilla, Firefox and Konqueror seems works fine, but I am not able check this in other browsers - any help is appreciated. Thanks. I am going to recompense myself with some jolly smoke :-D
Last edited by 100rk on Sat Jun 18, 2005 10:33 pm, edited 1 time in total.
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by nils73 »

If I am not mistaken, then this is what we were talking about in this threa where I suggested something like autosave for creating pages (not for changing them). Haven't had the time to test them and work out how the plugin must be used but I will do it as soon as I am back from LinuxTag 2005 where I will be busy this week.

Regards,
Nils
100rk

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by 100rk »

nils73 wrote: If I am not mistaken, then this is what we were talking about
Yes, You're right :-) Nice trip!

For those who are interested: 06/24/2005 - xajax version 0.1 beta2 - see original pages here: http://xajax.sourceforge.net
Last edited by 100rk on Sat Jun 25, 2005 8:10 pm, edited 1 time in total.
roman
Forum Members
Forum Members
Posts: 77
Joined: Thu May 12, 2005 9:38 am
Location: slovakia

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by roman »

100rk

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by 100rk »

roman wrote: TIny MCE example: http://www.xlab6.com/spell.php
It is very nice - especially spelling suggestions. Also another example from this site 'make sense' for me - On-the-fly dictionary: http://www.xlab6.com/dictionary.php.

;-)
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by Ted »

What would be really neat would be some kind of way to have the cms_module parameters show up contextually...  or even some way to have it popup help if you hover over a parameter name.  This is way out of my league, though.  :)
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by nils73 »

I like the help popup idea ...
100rk

XajaxInterface - background JS calls to PHP

Post by 100rk »

For those who are interested: new version of xajax: 07/11/2005 - xajax version 0.1 beta4 - see original pages here: http://xajax.sourceforge.net

What's new? (for example)
  • You can now pass single and multidimensional arrays and associative arrays as parameters to your javascript stub functions, and then use them in your PHP functions. Additionally, if you pass in a javascript object as a parameter, the php function will receive an associative array representing the properties of the object
  • Added the new addRemove() command method to the xajaxResponse class. addRemove() will add an XML command to your response to remove the specified HTML element from your application
  • Added the new addCreate() command method to the xajaxResponse class. addCreate() will add an XML command to your response to create a new HTML element as a child to an existing element in your application
  • Fixed some serious bugs in the UTF-8 encoding that prevented non-latin unicode characters from being transmitted correctly though xajax. Now xajax should work correctly with unicode Russian, Greek, Arabic, Hebrew, and many other unicode character sets
So, some interesting features:
  • xajax provides easy asynchronous Form processing. By using the xajax.getFormValues() javascript method, you can easily submit an array representing the values in a form as a parameter to a xajax asynchronous function:
    xajax_processForm(xajax.getFormValues('formId');
    It even works with complex input names like "checkbox[][]" and "name[first]" to produce multidimensional and associative arrays, just as if you had submitted the form and used the PHP $_GET array
  • xajax automatically compares the data returned from the PHP functions to the data that is already in the attribute of the element you have marked for change. The attribute is only updated with the new data if it will actually change what is already in the attribute. This eliminates the flicker often observed in applications that update content at a regular time interval with data which may or may not differ from extant content.
  • Each function registered to be accessible through xajax can have a different request type. All functions default to use POST unless GET is explicitly set. This is to encourage careful consideration of when to use GET requests
  • xajax can be used with the Smarty templating system by creating a variable in smarty that contains the xajax javascript:
    $smarty->assign('xajax_javascript', $xajax->getJavascript());
    Then you can use
    {$xajax_javascript}
    in your header template to use xajax on your site.
100rk

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by 100rk »

I found another very nice aplication, which uses AJAX technology - mp3 streaming server based on PHP. It works fine on my FreeBSD, so I like AJAX technology more every day ;-)

http://www.mp3act.net/ or demo http://demo.mp3act.net/
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by Ted »

It's actually very cool.  However, I almost feel it's a little TOO overdone with the AJAX thing.  It's one of those things that has to be used in moderation.  At least in my humble opinion...
100rk

Re: New module for testing - XajaxInterface - background JS calls to PHP

Post by 100rk »

wishy wrote: it's a little TOO overdone with the AJAX thing
I agree with that - better way is stay compactible with browsers && people without JavaScript support. This can be done easy (xajax way):

Code: Select all

<a href="index.php?action=list" onclick="xajax_list();return false;">List</a>
In this example: index.php will not be visited by user with JavaScript support, but programmer have to implement 'old style' ;-) handling of requests and rendering of content.

Off-topic: same thing is 'onchange' event, which is frequently used in webpages. Solution for all people (with or without JavaScript) is simple: implement submit button with id 'myFormSubmit'and call JavaScript

Code: Select all

<__script__ type="text/javascript"><!-- document.getElementById('myFormSubmit').style.display = 'none'; // --></__script>
Submit button will not be displayed in case Your JavaScript is active.

Back to mp3act: I think it was plan of authors - take absolutely advantage of AJAX possibilities. And also: IMHO purpose of this product is for intranet use as 'fake' native client, because there are still serious problems with implementation of JavaScript XMLHttpRequest object in some browsers.

Anyway - mp3act is one of first public complex PHP AJAX applications I've ever seen - if You know any other, let me know, please. And it is functional, with simple user interface and very fast response. I really like it, because GUI of mp3 streaming server which I am using for long time (http://www.jinzora.org) is too complicated labyrinth for users with minimal computer skills. YES, there are stil those people. :-)
wishy wrote: that has to be used in moderation
You're totally right, wishy - this is my opinion also.

By the way: mp3act uses library http://www.modernmethod.com/sajax/, which is more usable (for javaScript programmers) then http://xajax.sourceforge.net/. But I prefer xajax, because it offers best simple way for changes in content and style definitions of HTML elements.

And last notice: producer of mp3act also works on CMS system: http://visiblebits.com/portfolio/buildingblocks/ ;-)
Last edited by 100rk on Fri Aug 05, 2005 11:46 am, edited 1 time in total.
User avatar
sjg
Power Poster
Power Poster
Posts: 310
Joined: Thu Jan 27, 2005 5:11 pm
Location: Los Angeles, CA

Xajaxinterface

Post by sjg »

Sorry, I'm kinda slow on the uptake, but I just started playing with this module :)

I'm excited by the possibilities. I'd like to roll this functionality into a lot of places!

Just for reference, I needed to make two changes for it to work under PHP 5.0.5:

Change line 28 of Xajaxinterface.module.php from

Code: Select all

if (count($_SESSION['xajax_includes'])) {
to

Code: Select all

if (isset($_SESSION['xajax_includes'])) {
and line 211 from

Code: Select all

if (empty(count(($_SESSION['xajax_additionals'][$filename]))) {
to

Code: Select all

if (! isset($_SESSION['xajax_additionals'][$filename])) {
Anyway, thanks for the module! Can you upload this to the Wiki? If I use it as a dependency, I'd like for it to be easily available.
Many modules available from the http://dev.cmsmadesimple.org
The CMS Made Simple Developer Cookbook is now available from Packt Publishers!
Locked

Return to “Modules/Add-Ons”