Archive for the ‘code’ Category.

YATE testing

How can you test your YATE installation?

By trying to place a call from the YATE machine to one of your lines.

  • set up and activate music on hold (moh), I attached mine to madplay. Thus I get moh/madplay as an available data source (another would be tone/ring)
  • start YATE if it is not already running.
  • telnet localhost 5038 to login to YATE (rmanager has to be activated!)
  • callgen set called=yourlinenumber
  • callgen set source=moh/madplay
  • callgen single

The device attached to the line should get a call with Caller ID “YATE”, which will be routed to moh/madplay, and automatically disconnected after a minute.

You need to setup your call only once, and can continue testing with callgen single as often as you need to.

Here’s more information in the original documentation.

Please note: you can’t call outgoing numbers (as set up in your regex routing table) this way.

Also, you may need to enable the callgen and the rmanager modules in your yate.conf, if they had been disabled.

Compiling with Closure

Closure is a JavaScript optimizing compiler (targetting optimized JavaScript) by Google. For a very good introduction to closure see this blog article.

Illegal boolean value –js problem
I am trying to compile the following:

java -jar compiler.jar –compilation_level=ADVANCED_OPTIMIZATIONS –third_party –js=jquery.js –js=snippet-one.js –js=jquery-ui.js –js=jquery.debug.js –js=snippet-two.js –js=jajax.js –js=jstorage.js –js=jcompress.js –js=jquery.windowframe.js –js=jquery.treeview.min.js –js=jquery.bgiframe.js –js=jquery.dimensions.js –js=jquery.tooltip.min.js –js=jquery.json-2.2.min.js –js=js_debug_toolbar.js –js=CFInstall.min.js –externs=snippet-three.js –js=visualisation.js –externs=snippet-four.js –js_output_file=__output.js

Which results in this error:

Illegal boolean value: –js

I merged the js files by hand into one big file and tried this:

java -jar compiler.jar –compilation_level=ADVANCED_OPTIMIZATIONS –third_party –js=jquery_one.js –externs=externs.js –js_output_file=output.js

Which still results in the same error:

Illegal boolean value: –js

The solution to this problem: you need to specify the –third_party tag with true, like this:

java -jar compiler.jar –compilation_level=ADVANCED_OPTIMIZATIONS –third_party=true –js jquery_one.js –externs externs.js –js_output_file output.js

Compiling JQuery with advanced optimizations does not work

Yes, it does not work! See this website for details.

We need to switch back one optimisation level for the script to work again …:

java -jar compiler.jar –compilation_level=SIMPLE_OPTIMIZATIONS –third_party=true –js=jquery.js –js=snippet-one.js –js=jquery-ui.js –js=jquery.debug.js –js=snippet-two.js –js=jajax.js –js=jstorage.js –js=jcompress.js –js=jquery.windowframe_patched.js –js=jquery.treeview.min.js –js=jquery.bgiframe.js –js=jquery.dimensions.js –js=jquery.tooltip.min.js –js=jquery.json-2.2.min.js –js=js_debug_toolbar.js –js=CFInstall.min.js –externs=snippet-three.js –js=visualisation.js –externs=snippet-four.js –js_output_file=__output2.js

WebApps & Compression

http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

Actually I’ve already got a post about this and other techniques (in German).

Pre-Compressing files

If your files get really big, and never change, it’s time to add a new technique to your toolbelt: the pre-compression!

Use 7-zip to GZIP your files in ultimate mode, drop them on your server. Add some .htaccess and PHP magic, like so:

<?PHP
header(‘Content-Encoding: gzip’);
$req = $_SERVER['REQUEST_URI'];
$req_a = explode(‘/’,$req);
readfile($req_a[2] . ‘.gz’);
?>

(assuming your files will be reachable by /xyz/file and are stored with .gz as extension)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /104/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php [L]
</IfModule>

Modify your RewriteBase accordingly!

This will work wonders for huge files with repetetive content – no more processing overhead server-side, all files delivered faster, happy customers … don’t forget to write about your ideas and experiences with this!

Concrete 5 site is suddenly down

The symptoms:

Your site is suddenly down. If in production mode, a blank & empty page is displayed.

The solution:

After checking that the MySQL daemon still works, Apache is running, PHP is working and the configuration has not been changed (a test.txt file is served correctly), you might want to look into your PHP error log.

Here’s how you add PHP error logging to your .htaccess, if you do not have it already:

# php error logs..
php_flag display_errors off
php_flag log_errors on
php_value track_errors on
php_value error_log /path/to/php.error.log

Be sure to chown the file to www-data:www-data or whatever your PHP process is running under.

In my case, the culprit was a very strange “duplicate entry” error:

[09-Jun-2010 20:18:49] PHP Fatal error: Uncaught exception ‘ADODB_Exception’ with message ‘mysql error: [1062: Duplicate entry '300969' for key 1] in EXECUTE(“insert into PageStatistics (cID, uID, date) values (‘1′, 0, NOW())”)
‘ in /…/concrete5.4.0.5/concrete/libraries/3rdparty/adodb/adodb-exceptions.inc.php:78
Stack trace:
#0 /…/updates/concrete5.4.0.5/concrete/libraries/3rdparty/adodb/adodb.inc.php(1037): adodb_throw(‘mysql’, ‘EXECUTE’, 1062, ‘Duplicate entry…’, ‘insert into Pag…’, false, Object(ADODB_mysql))
#1 /…/concrete5.4.0.5/concrete/libraries/3rdparty/adodb/adodb.inc.php(993): ADOConnection->_Execute(‘insert into Pag…’)
#2 /…/updates/concrete5.4.0.5/concrete/libraries/3rdparty/adodb/adodb.inc.php(761): ADOConnection->Execute(‘insert into Pag…’, Array)
#3 [internal function]: ADOConnection->Query(‘insert into Pag…’, Array)
#4 /…/updates/concrete5.4.0.5/conc in /…/updates/concrete5.4.0.5/concrete/libraries/3rdparty/adodb/adodb-exceptions.inc.php on line 78

After checking the appropriate table (used for logging visits to your C5 page), I could not understand the error – there was no entry for key 300969, the last entry was 300968.

Here’s a quick way to turn off page statistics, which will fix this error and bring your site back on: Put this line o’code in your config/site.php

define(‘STATISTICS_TRACK_PAGE_VIEWS’, false);

In PHPMyAdmin there’s the option to manually increase the auto_increment value. I increased it by one to 300970 and the site was working again, with statistics (comment the line you just inserted.)

There’s a couple of pages out there, currently having this problem (searching with Google helps). I’m offering a low-cost watchdog service for Concrete5 sitesbe back up again before your visitors notice!

Internet Explorer (aka IE) and CSS

An order problem?

Internet Explorer seems to be picky about the order chained CSS class selectors appear in:

.q_null {background-color:#f5f5f5;}
.q_true {background-color:#81F7BE;}
.q_false {background-color:#F78181;}

.q_null.icon {background: url(icons/pencil.png) no-repeat center;}
.icon.q_false {background: url(icons/error.png) no-repeat center;}
.icon.q_true {background: url(icons/accept.png) no-repeat center;}

ie-layouter

As you can see, it layouts .q_null.icon as intended (one icon, table row has a background color), whereas the other order .icon.q_false is rendered incorrectly.

No – there’s something else in the works

ie-layouter-2

This is the result of the “corrected” code:

.q_null {background-color:#f5f5f5;}
.q_true {background-color:#81F7BE;}
.q_false {background-color:#F78181;}

.q_null.icon {background: url(icons/pencil.png) no-repeat center;}
.q_false.icon {background: url(icons/error.png) no-repeat center;}
.q_true.icon {background: url(icons/accept.png) no-repeat center;}

Does it ignore chained classes in CSS completely?

A little research shows: only Internet Explorer 6 ignores chained classes in CSS. Unfortunately it is still used by about 10 % of the online population. Thus, there’s no other choice but to rewrite the code to execute with “unchained” single classes in CSS.

jQuery AJAX & Internet Explorer

Internet Explorer getJSON trouble

This piece of code initially did not work for me on IE:

$.getJSON(“../inc/exercise_ajax.php?” + $(this).serialize(), function(json)

FireFox worked without problems.

The reason is that my JSON code was not well-formed. It had a comma (‘,’) too much.

Here’s the code which I use in PHP to create my JSON (braces omitted):

foreach($answers as $question => $answer){
$outstr .= ‘”q’.$question.’”: ‘;
if (isset($_GET[$question])){
if ($_GET[$question] == $answer) $outstr .= ‘true’;
else $outstr .= ‘false’;
} else $outstr .= ‘null’;
$outstr .= ‘,’;
}
echo chop($outstr,’,');

You have to chop off the trailing comma – if you don’t, IE will choke on it and your callback function won’t be executed.

Internet Explorer & AJAX caching

Yes, Internet Explorer caches your requests. You’ve got to empty the browser cache before testing the fix I mentioned. Also, you should append a unique parameter to suppress caching, i.e. the current timestamp. Example:

var now = new Date();
// submit with AJAX
$.getJSON(“../inc/exercise_ajax.php?ts=” + now.getTime() + ‘&’ + $(this).serialize(), function(json)

Working with the JQuery Form Validator

Q: Do you need the “<fieldset>” tags for the validator to work?
A: No you can omit them.

Bug in Concrete 5

If a page name contains “/” (the slash), the Concrete5 edit bar does not appear on the page. (At least in Opera 10)

Solution: go to the Dashboard, edit the page name (hint: remove the slash) from the Sitemap there and visit the page again.

Concrete5 does not update correctly?

Starting with the newest version of Concrete, 5.4, updates have been integrated into the web interface.

For me, this update process suddenly did not work anymore correctly:
After running the upgrade script, it would still show that we were using the old version of the code and offer to upgrade again – as if nothing had happened inbetween.

The solution to this problem lies in your config/site.php – look at the very end of it, it will contain a statement similar to this one:

<?php define(‘DIRNAME_APP_UPDATED’, ‘concrete5.4.0.5′);?>

My config/site.php contained two statements – one having the previous version, one the newest version of the update.

Try removing them both and running the upgrade once again. It will work this time – no upgrade will be offered again.

Does the AdoDB C extension speed up Concrete?

My experiments with a sufficiently complex page (www.vitanit.com) have shown: no. There even may be a slight time penalty.

To enable it, you’ll have to download it, compile it, and add the following to your php.ini:

extension=adodb.so

How do you know that it’s installed? phpinfo() will show something like:

ADOdbInfo Extension requires ADOdb classes
Download http://php.weblogs.com/adodb
API Version 5.04

It might be useful for the IdeaDay Import Wizard – which relies heavily on the database.