Misc ajax functionality Index: * index_ajax.php * ezcore/call * ezcoreservercall.php * ezajaxcontent.php Note: take a look in performance41.txt for how to improve performance for (your ajax calls in) eZ Publish 4.1. index_ajax.php: A light ajax index.php for your ajax modules, checks access to siteaccess and module / view and gives response according to HTTP_ACCEPT header. Is approximately 20-80% faster then normal index.php loading, and you avoid getting a large and slow 404 response if something went wronge.. Supported responses: xml, json and text/xhtml Note: ActiveAccessExtenions setting is for performance reasons disabled, you can however re activate it by uncommenting "eZExtension::activateExtensions('access');" at line ~149. Install: 1. copy file from root of extension to root of eZ Publish installation. 2. Add this to your apache rewrite rules (for the views you need): RewriteRule ezcore/call/ /index_ajax.php [L] RewriteRule ezcore/run/ /index_ajax.php [L] Using on your own modules: 0. This example uses myextension and mymodule as extension and module name 1. Add Rewrite rule RewriteRule mymodule/myview/ /index_ajax.php [L] Alternative approach for using your own modules: 1. simply use ezcore/run to execute your own view so you don't need to add rewrite rules for each new ajax view 2. Recomended: Specify ezcore/run in the [SiteAccessSettings]AnonymousAccessList[] and [RoleSettings]PolicyOmitList[] To keep overhead of the ezcore/run/ call close to zero. 3. example url: /ezcore/run/content/view/full/2 ezcore/call: A simple to use (module) view where you register your own php classes or templates that should be callable to the world. Working examples on php class and template use can be found in ezcore.ini Use from javascript using the bundled ezcore js library: 1. First load the needed javascript using the ezscript template operator: {ezscript(array('ez_core.js', 'ezcore::server'))} 2a. when this is loaded you can call your server code like this: ez.server.call( 'ezcore::time', myCallBackFunction ); 2b. Alternatively you can call several server functions at once to save time (and requests to your server): ez.server.call( ['ezcore::time','ezcore::keyword'], myCallBackFunction ); 3. Create your call back function to handle the response from the server: function myCallBackFunction( content, errorCode, errorText ) { // errorCode is 0 if everything went ok alert( content + errorCode + errorText ); } How to use your own flavour of a javascript library: 1. Since all js libraryes are different, you'll need to implement the js -> ezcore/call glue your self. But it is really simple if you know your js. So look in classes/ezcoreservercallfunctions.php in the 'server' function for how it is done. You'll notice that the only reason why this is generated in php code is to know the url for the root of the current eZ Publish install, so you can implement this as a template instead if you want to or in pure javascript where you hardcode server root url or guess it or set it with {'/'|ezurl}. 2. Now simply follow the guid above for the ezcore library, but change the calls to your own functions. 1st step could be something like {ezscript(array('yui.js', 'yui::server'))} if your using yui. ezcoreservercall.php: The php code that does all the code for the ezcore/call, also used by the ezpacker.php code (ezcss and ezscript template operators) for custom code generators (used for i18n string generator in Online Editor 5.0 for tinyMCE translation integration). ezajaxcontent.php: Functions for encoding mixed data to json / xml / text, and functionality for simplifying node(s) to a hash so they can be encoded. Also function for figuring out what kind of content type the client accepts to be able to do auto encoding based on preferred content type. json encoding uses the php json extension included in php 5.2 and higher or fallback to a php version if not present. Template operators that uses this class: node_encode, xml_encode and json_encode