I went through a massive cleansing of this blog, deleting over 560 user accounts.
Rest assured, no actual accounts were deleted. Not that anyone registered is actually human…yep that’s right I’m essentially talking to myself.
I went through a massive cleansing of this blog, deleting over 560 user accounts.
Rest assured, no actual accounts were deleted. Not that anyone registered is actually human…yep that’s right I’m essentially talking to myself.
Yea so I was busy testing a form when I ran across this.. lol. Needless to say, my attempt to enter the right ‘phrase’ failed as well. NICE reCaptcha, NICE.
I accidentally Googled ‘recaptcha fail’ on image search and found more disturbing occurrences. Find out for yourself.
Recently I’ve been wanting a challenge. After watching the Social Network, the dramatized version of Mark Zuckerberg’s story, I was inspired by some of the short coding sessions that he likes to do as proven with the all-night Facebook Hackathons (which mostly do not have much to do with actual hacking. I won’t get into that).
I’ve definitely been met with a challenge. This is a cut and dry version of the Knights and Knaves puzzle by our friend Smullyan
The idea: Your algorithm must process a huge amount of data quickly and accurately decide who is lying and who is not. A nice little Turing test if you will.
For those who are theory-savvy think of one-pass in a file and that’s it. Your processing should be done in a ‘reasonable amount of time’ (reasonable to humans because that’s who would really care, right?).
I guess a hint in the right direction might be:
Finally.. try your algorithm with the 5 test cases they have. Just in case your algorithm is too slow to handle a large amount of data be sure to start out with the first test they provide in their example or else you might have to kill the process.
There’s a ton more puzzles to tackle and this is definitely a good break from the day to day tasks for any programmer.
Post your ideas and what languages you might be using, but please no algorithms/solutions. Email me at bran [dot] cham [at] gmail if you would like to discuss algorithms further!
Good luck and have fun!
eZ Publish is by nature, easy to understand in the administration panel, adding and editing content. However, once you look under the hood it’s like a complex maze of code, intricately designed, but still a maze. While the template code, based on Smarty I believe, is well documented there’s no single source to figure out how things work in PHP land. You just find out for yourself by looking through other extensions as well as the kernel code, ask other people or by just plain “elbow grease.” Well here’s some findings I came across fumbling around on a project as well as spare time.
Tutorial Skill requirements:
If you need to head over to eZ Systems’ site for more information on installing and configuring an extension
I came across two main ways to implement AJAX (jQuery) with eZPublish.
AJAX + Custom Module:
So obviously you need a module and a view (and thus an extension). By looking at the JavaScript you’ll see the module and view names I used. You can use whatever you want.
The JavaScript:
var data_sent = { message: "testing!"};
$.ajax({
url: "/mymodule/post",
type: 'POST',
data: ( data_sent),
dataType: 'json',
success: function( data ){
if( data.response == "ok" )
{
alert( data.message );
}
}
});The Module code:
In post.php I usually have something along the lines of this initial setup:
if ( $http->hasPostVariable( 'message'' ) && $http->postVariable( 'message' ) )
{
$response = array( 'response' => 'ok');
print( json_encode( $response ) );
eZExecution::cleanExit();
}That’s IT!
AJAX + eZJSCore + Custom Class:
This approach requires you have eZJSCore installed and working.
One of the first things you’ll notice with this approach by looking at the code is there’s a little more of it, but it looks cleaner in the JavaScript code.
To get eZJSCore setup add your custom class to ezjscore.ini (preferably in your extension’s settings directory):
[ezjscServer] FunctionList[]=ajaxFunc [ezjscServer_myajax] Class=MyAJAX File=extension/myextension/classes/myajax.php Functions[]=ajaxFunc
The JavaScript:
//You can keep going with the args
var dataSent = {arg1: "123", arg2: "456"};
$.ez( 'myajax::ajaxfunc', dataSent, function( ezp_data )
{
if ( ezp_data.error_text )
{
alert( ezp_data.error_text );
}
else
{
alert( ezp_data.content );
}
}Custom PHP Class setup:
class MyAJAX extends ezjscServerFunctions
{
public static function ajaxFunc( $args )
{
if ( isset( $args[0] ) && isset( $args[1] ) && isset( $args[2] ) && isset( $args[3] ) )
{
$var1 = htmlspecialchars( $args[0] );
$var2 = htmlspecialchars( $args[1] );
$var3 = htmlspecialchars( $args[2] );
$var4 = htmlspecialchars( $args[3] );
}
else if ( $http->hasPostVariable( 'arg1' ) && $http->hasPostVariable( 'arg2' ) && $http->hasPostVariable( 'arg3' ) && $http->hasPostVariable( 'arg4' ) )
{
$var1 = htmlspecialchars( $http->postVariable( 'arg1') );
$var2 = htmlspecialchars( $http->postVariable( 'arg2') );
$var3 = htmlspecialchars( $http->postVariable( 'arg3') );
$var4 = htmlspecialchars( $http->postVariable( 'arg4') );
}
else
{
return $error['args'];
}
return "ok";
}
}Use for debugging via HTTP:
http://dev.server.com/ezjscore/call/myajax::ajaxfunc::val1::val2::val3::val4
eZ Find definitely has its advantages and it would be a good idea to use eZ Find for large data sets. In my next post I will try to demystify the PHP implementation of an eZFind fetch.
Until then, get used to using the template code outlined in Ivo Lukac’s guide to using eZ Find. There you can also find the advantages and disadvantages of eZ Find.
The Background
In a recent project I needed to get a basic form working. It took some effort to get a custom registration form plugged in to eZ Publish but I’m still very new to the system so I can’t complain much. Once the custom registration extension was coded and the form was tested in its unstyled state, it was time to add the styling. I was handed static HTML from the designer (not me in this case) and needed to get the live version working quickly as the project was coming to an end. So I stayed on course religiously with the design specs given to me and used the jQTransform plugin for jQuery. It takes your forms and styles them. Very swanky and neat looking. However, some things to note about jQTransform:
This last item I found to be quite discouraging.
In hindsight it wasn’t very complicated at all. It was a 3 state form:
State 1:

State 2:

State 3:

Easy right? Just add jQuery show/hide!
WRONG
The plugin doesn’t do too bad with the regular text line inputs but the problem I ran into is the plugin changes the HTML on page load. Actually, it appends an entirely new set of elements to the HTML and hides the original <select> block. Not only that, but other classes were added/removed on the fly when a user clicks the drop-down menu. So essentially it’s doing some fancy dancy manipulation to get the fields to be styled like you want it. So instead of trying to actually style the <select> tags it’s replacing those with <ul>/<li> tags and keeping track of what’s selected to get around that issue of no styling support for the <select> tag.
The Fix
The reason I could not simply use my own show/hide code to control the simple behavior was that the plugin had hijacked control of the elements in question, namely the click handler for the <a> tags within <ul>/<li> tags. Instead of fighting for control of the <a> click handler I had to make the plugin give that control back to me. Thus by adding an ID to the HTML and a couple function calls I was back in control of my world.
Hacking jqTransform
Here’s a snippit of the jqTransform code starting around line 250, but more specifically within the Select section. I gave my custom code top priority in the handler as it looked for the custom ID’s I set up. Not that pretty, but it’ll do.
/***************************
Select
***************************/
$.fn.jqTransSelect = function(){
...
...
/* Now add the html for the select */
$wrapper.prepend('<div><span></span><a href="#"></a></div><ul></ul>');
var $ul = $('ul', $wrapper).css('width',$select.width()).hide();
/* Now we add the options */
$('option', this).each(function(i){...});
/* Add click handler to the a */
$ul.find('a').click(function(){
//Custom behavior
var thisID = $(this).attr('id');
if (thisID == "emp-fields"){showEmployeeFields();}
else if(thisID == "con-fields"){showContractorFields();}
...
...
});
My jQuery Code
I placed this code outside of the jqTransform code and in a separate JS file. The reason for the $(document).ready part WITHIN these functions is for insurance. In fact I saw some funky stuff happening when I first decided to leave it out.
function showEmployeeFields(){ $(document).ready(function(){ $("#emp").show(); $("#con1").hide(); $("#con2").hide(); }); } function showContractorFields(){ $(document).ready(function(){ $("#emp").hide(); $("#con1").show(); $("#con2").show(); }); }
The HTML
<div>
<label for="user_type">I Am A :</label>
<select tabindex="4" name="user_type">
<option id="selected_user_type">* Please Select</option>
<option id="emp-fields" value="Internal Staff">Employee</option>
<option id="con-fields" value="External Contractor">Vendor</option>
</select>
</div>
<!-- Additional fields for Contractors -->
<div id="con1"><input type="text" name="sponsor_name" size="20"value="* Sponsor's Name"/></div>
<div id="con2"><input type="text" name="sponsor_email_address" size="20" value="* Sponsor's E-mail"/></div>
<!-- Additional fields for Emplopyees -->
<div id="emp">
<select name="position">
<option value="196">Administrative Assistant</option>
<option value="194">Manager</option>
<option value="195">Senior Manager</option>
</select>
</div>
This could have been done differently but this is just a simple modification to let a user take back some control that’s lost when using a heavy plugin such as jqTransform.
My current work as a web developer has landed me in the middle of an Open Source CMS I never heard of (there are literally hundreds out there) called eZ Publish. I was placed on a project after 3 days or so of training on the system and was quickly on my way to creating a website backed by a solid CMS
Coding with eZ Publish
The most coding I have done so far in the system has been with CSS/HTML/JavaScript and their Template Code (based on Smarty). I have barely touched PHP so far in the two months I have used eZ Publish, but it is a great system for plugging in reusable PHP (extensions and modules). For example a fellow developer and I created a business locator using Google Maps (JavaScript) and the eZ CMS. We stored the businesses and their addresses as well as the latitude/longitude as one “object” and then the user could find the closest business to them. The other portion of PHP I had to use more recently was to create a custom user registration form.
I haven’t investigated the eZ Publish API Documentation for PHP yet but it is definitely on my list of things to do before I try to take the eZ Publish developer exam. It seems complete at a first glance and uses doxygen, a great sign.
I’ll admit, this system is not for the faint of heart but if you like learning new systems and like to get your hands dirty, this is the place. It is a highly customizable system for the developer but easy enough for a non-techie to make content contributions. As a developer there are lots of little things to remember when building a custom website backed by a CMS such as this. It will take months to learn and I recommend learning PHP while you’re at it.