Drupal Case Study

January 8th, 2010

Salut,

La PHP Geek Meet 6 Cluj am prezentat inca putin din functionalitatile Drupal. Un studiu de caz pentru un director web, functionalitati de import / export, enhanced SEO & more.
Este vorba despre http://www.drug-rehabs-new-york.com/

Vreti sa mai vedeti prezentari de Drupal la PHP GeekMeet Cluj?

September 22nd, 2009

Salut,

Public si rezultatele chestionarului de Drupal la PHP GeekMeet Cluj-Napoca. Initial as fi vrut sa las chestionarul sa se desfasoare pe o perioada mai lunga dar am convenit ca raportat la prezenta normala la un PHP GeekMeet Cluj, un numar de 20 de respondenti pot fi considerati esantion reprezentativ.

Aici sunt si rezultatele:

De cate ori ai participat la PHP GeekMeet ?
Nu am fost niciodata 8 38%
E prima data 4 19%
Vin des 7 33%
Am fost la toate intalnirile 2 10%
Folosesti Drupal?
Folosesc deja 4 19%
Nu, dar poate am sa incerc 9 43%
Nu si nici nu voi folosi 8 38%
Te intereseaza si alte prezentari de Drupal?
Da 13 62%
Nu 8 38%

Prezentarea la GeekMeet – Drupal Basics

September 21st, 2009

Recent, am avut o prezentare la PHP GeekMeet Cluj Napoca, referitoare la Drupal.

Elemente de baza, avantajele si dezavantajele utilizarii Drupal ca unealta de lucru.

Prezentarea o gasiti aici:

seoLink in Flex

September 15th, 2009

Hello,

In the past days I worked on the so-called seoLink project for Flex. It’s a more deep aproach of Google Friendly Flex applications (discussed here: http://blog.ag-prime.com/2009/06/permanent-links-in-flex-and-track-them-with-google-analytics/).

Well the main idea is to create a common XML file that stores actual content. Then this XML file is parsed by the Flex application and by an PHP file too.

Using .htaccess I redirect all incoming requests to index.php?p=<request>

So, inside the .php file, I dispach this path parameter and load the equivalent information from XML file.

The resulting html will have the SWF loader for Flex (with flashvars = p=<request>) and alternate content selected from XML. So both alternate text and actual Flex content will be according to the <request> set to the browser.

You can view full source just by right click and view source here: http://seolink.ag-prime.com/

I’ll soon come with updates.

Later update: Lynx view

[15.09.2009 21:20] Yes, we are getting there. The first results in google just arived: http://www.google.com/search?q=site:seolink.ag-prime.com

Also, how it look on Google Analytics. It tracks pageviews, landing pages…

Simple but efficient way to protect your customers from phishing attacks

August 26th, 2009

Phishing attacks are becoming more and more popular this days.

Phishing (via wikipedia):
“In the field of computer security, phishing is the criminally fraudulent process of attempting to acquire sensitive information such as usernames, passwords and credit card details by masquerading as a trustworthy entity in an electronic communication. ” (read more)

The messages received from an attacker is very similar to the companies messages and many customers end up in providing sensitive information to attackers.

I recently signed-up on a website, and upon registering it asked me a “Phishing protect key“, so every time I receive a communication from their business I will have a header similar to:

Anti-Phishing Key: “<custom text I entered on registering form>
This information was inserted by you on your registration form. This “key” lets you verify that <Business> is the sender of this email and fight against the risk of phishing.

I think it’s a very simple and great idea to protect your customer from phishing attacks.

Making Drupal’s l() function language aware

July 21st, 2009

Hi, I recently found a very problematic situation. Wanted to ‘travel’ through some language aware links and Drupal l() function does not process with the language switcher.

I found a very particular solution (only to be used with Path prefix language negotiation ).

I used it inside my template.php file, and used it as THEMENAME_l($text, $path, $options)

So the code for custom l() is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function THEMENAME_l($text, $path, $options = array()) {
  global $language;
 
  // Merge in defaults.
  $options += array(
      'attributes' => array(),
      'html' => FALSE,
    );
 
  // Append active class.
  if (($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) &&
      (empty($options['language']) || $options['language']->language == $language->language)) {
    if (isset($options['attributes']['class'])) {
      $options['attributes']['class'] .= ' active';
    }
    else {
      $options['attributes']['class'] = 'active';
    }
  }
 
  // Remove all HTML and PHP tags from a tooltip. For best performance, we act only
  // if a quick strpos() pre-check gave a suspicion (because strip_tags() is expensive).
  if (isset($options['attributes']['title']) && strpos($options['attributes']['title'], '<') !== FALSE) {
    $options['attributes']['title'] = strip_tags($options['attributes']['title']);
  }
 
  // a small url tweak
    $url = check_url(url($path, $options));
    $url = base_path().(!empty($options['language'])?$options['language']->language:'').'/'.str_replace(base_path(),'',$url);
  // -------------------
 
  return '<a href="'. $url .'"'. drupal_attributes($options['attributes']) .'>'. ($options['html'] ? $text : check_plain($text)) .'</a>';
}

Permanent links in Flex and track them with Google Analytics

June 30th, 2009

The purpose of this tutorial is to recreate the browsing experience similar to HTML, so you can save / share links and track clicks through sections of your site.

I first created a very simple application, having 3 sections: Home, Events and Contact:

The directory structure

The application is organized in Views using ViewStack

CODE:

<mx:ViewStack id=”views” horizontalCenter=”0″ verticalCenter=”0″>

<views:home id=”home” label=”Home” showEffect=”{fadeIn}” hideEffect=”{fadeOut}” />

<views:events id=”events” label=”Events” showEffect=”{fadeIn}” hideEffect=”{fadeOut}” />

<views:contact id=”contact” label=”Contact” showEffect=”{fadeIn}” hideEffect=”{fadeOut}” />

</mx:ViewStack>

Every  view being placed in com/views/* , and all are components having the same structure:

CODE:

<mx:Canvas xmlns:mx=”http://www.adobe.com/2006/mxml” width=”400″ height=”300″>

<mx:VBox>

<mx:Label text=”Home page” />

<mx:TextArea htmlText=”Lorem ipsum”

editable=”false” borderThickness=”0″ condenseWhite=”true” backgroundAlpha=”0″ focusRoundedCorners=”0″ focusThickness=”0″

verticalScrollPolicy=”auto” horizontalScrollPolicy=”off”/>

</mx:VBox>

</mx:Canvas>

For menu display I used the very intuitive LinkBar that extracts labels from views inside ViewStack (great!)

CODE:

<mx:LinkBar dataProvider=”views” top=”10″ horizontalCenter=”0″/>

And that’s it for our simple application setup.

Preview what we have so far:

Ok it all works ok now, but we want, to send somebody directly to our events page. Simple! For that we will have to use the BrowserManager so we can add trailing variables to our page link. They will be pairs variable=value after a # character.

The steps are very simple, when we first load our application we check the variables, if any, at the end of our url and load the specified view. And during our application is running we update the url every time we change views, and update views every time we spot a url change (so we can also handle the browser’s back button).

Note! This makes use of the history.js script, make sure it’s included in your index.template.html file.

CODE:

<mx:Script>

<![CDATA[

// browser

import mx.events.BrowserChangeEvent;

import mx.managers.IBrowserManager;

import mx.managers.BrowserManager;

import mx.utils.URLUtil;

private var bm:IBrowserManager

protected function init() : void {

//get an instance of the browser manager

bm = BrowserManager.getInstance();

//initialize the browser manager

bm.init();

//set initial values based on url parameters

updateContent();

//add event listeners to handle back/forward browser buttons

bm.addEventListener( BrowserChangeEvent.BROWSER_URL_CHANGE,onURLChange );

}

private function updateContent():void

{

//convert url parameters to an actionscript object

var o:Object = URLUtil.stringToObject(bm.fragment);

//set the selected view

var p : String = (o.p != null)?o.p:"home";

Application.application.views.selectedChild = getViewsChildById(p);

}

private function onURLChange( event : BrowserChangeEvent ):void

{

//call update values based on change url

updateContent();

}

public function updateURL():void

{

//update URL fragment

var page : String = Application.application.views.selectedChild.toString().split(".").pop().toString();

bm.setFragment( "p=" + page );

}

private static function getViewsChildById(str : String):Object {

for each (var child : Object in Application.application.views.getChildren()) {

if (child.id == str) {

return child;

}

}

return null;

}

]]>

</mx:Script>

We store a browser manager instance into out IBrowserManager variable. Upon applicationComplete event we launch init(), initializing the browser manager, updating to selected view, and hooking a BROWSER_URL_CHANGE event to update views every time a url is change or browser’s Back, Forward button is pressed.

The pairs stored at the end of the url can be extracted from BrowserManager’s .fragment value. For example, I used the variable p to store the view name. So, for example the events view will have a link like http://localhost/…/permaLink.html#p=events

Since the value from fragment  is a string, I also created a helper function that extracts the view child by specifying it’s name getViewsChildById(str:String) that returns the object representing that view.

Next step is to put a handler on ViewStack change event , change=”updateURL()” so we will update the browser’s url every time a view is changed inside our application.

The updateUrl() simply reads the current ViewStack selectedChild and updates BrowserManager’s fragment variable.

CODE:

var page : String = Application.application.views.selectedChild.toString().split(“.”).pop().toString();

bm.setFragment( “p=” + page );

That’s it. Simple, right? Now when we click on events our url will like this:

Preview (note the p=value pair at the ending of your url)

Now our next task is to track this clicks with Google Analytics. Practically our Flex application behaves now like a Ajax application. So we just have to include our Google Analytics code in the <head> tag of our output html.

You can do this by modifying the html-template/index.template.html file.

CODE:

<head>

<script type=”text/javascript”>

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);

document.write(unescape(“%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

</script>

<script type=”text/javascript”>

try {

var pageTracker = _gat._getTracker(“put your tracker ID here”);

pageTracker._trackPageview();

} catch(err) {}

</script>

</head>

And when we update the url’s we should tell Google Analytics that we changed that page. For this purpose we have the function pageTracker._trackPageview(pageName).

So we will simply add a call to this Javascript function, using the Flex’s ExternalInterface.call , in the updateUrl function:

CODE:

ExternalInterface.call(‘pageTracker._trackPageview’,‘#’+bm.fragment);

So now we can share permanent links to views of our applications, we can track landing / exit pages, all trafic statistics with Google Analytics.

Thank you.

You can view the application in action here.

You can download sources here: permalink

Drupal Captcha (invisible captcha challenge)

June 30th, 2009

This is a verry simple captcha challenge. It’s based on the algorithm of Scott Allen (http://www.hybrid6.com/webgeek/plugins/wp-spamfree), a captcha free plugin for WordPress.

The user has to do no other input, just it’s browser should support javascript and cookies. (~95% of internet users have this). So might stop annoying 95% of your users and advice the other 5% to install javascript or to allow cookies support for their browser.

The process is very simple. This module requires CAPTCHA Module (http://drupal.org/project/captcha).

After installing both modules, you simply goto configuration page of CAPTCHA Module admin/user/captcha and chose default challenge type to: Invisible CAPTCHA (from module invisible_captcha).

And that’s it. More information on CAPTCHA module here.

Later edit: Updated to comply with user permisions.

Download module

Google indexes external loaded data in SWF files

June 25th, 2009

Hello, recently, Google announced support for dinamicly generated SWF content (aka. Flash and / or Flex).

So, from now onw, every SWF file in your website will be indexed, and appear on Google’s search results.

Read more about tracking your Flex website and friendly url’s here.

Read more about Google indexing content from external resources in Flash / Flex here.

Note! There will be still a issue with this, by now they can only index sites scripted with AS1 and AS2, so not your Flex application.

Cross browser XHTML Valid Flash embed

June 17th, 2009

Hey,

I recently had to write a cross-browser and XHTML Valid code, that embeds Flash content. Well, this is a very discused issue, and found a very simple solution to it :) via (http://robertnyman.com/2007/02/01/how-to-write-valid-htmlxhtml-code-to-include-flash/)

<object type="application/x-shockwave-flash"
	id="name" width="100%" height="40"
	data="http://www.example.com/path/to/flash/name.swf">
		<param name="movie" value="http://www.example.com/path/to/flash/name.swf" />
		<param name="quality" value="high" />
		<param name="wmode" value="transparent" />
		<param name="allowScriptAccess" value="sameDomain" />
</object>