Automaticly Copy Zend/Symfony Library to Project

Zend Framework Batch file

@echo off
:MENU
ECHO Zend will be copied to "%CD%\library"
SET /P M=Type PRESS 1 to continue or any key to EXIT:
IF %M%==1 (	GOTO IMPORT ) ELSE ( GOTO :EOF )
:IMPORT
xcopy /E "ABSOLUTE_PATH_TO_Zend_Library" "%CD%\library"
GOTO :EOF

Symfony Framework Batch file

@echo off
:MENU
ECHO Symfony will be copied to "%CD%\lib\vendor"
SET /P M=Type PRESS 1 to continue or any key to EXIT:
IF %M%==1 (	GOTO IMPORT ) ELSE ( GOTO :EOF )
:IMPORT
xcopy /E "ABSOLUTE_PATH_TO_Symfony_Library" "%CD%\lib\vendor\"
GOTO :EOF

Read the rest of this entry »

Zend Framework : Create Modular Application [Part 2]

SQL Code

CREATE  DATABASE  `MyApp` ;

Then under `MyApp`

CREATE TABLE IF NOT EXISTS `guestbook` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`comment` text NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Using Zend_Tool configure Database

zf configure db-adapter "adapter=pdo_mysql&host=localhost&username=root&password=&dbname=MyApp"

Or add lines directly into application.ini

resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.dbname = "MyApp"

Create a table (Model) for ‘MyApp.guestbook’ database

zf create db-table Guestbook guestbook Guestbook
/* zf create db-table Model-Name The-Table-Name Module-Name */

To Be continued

Recaptcha basic php class

See Demo
@ PhpClasses.org

<?php
/*
 *	Easy Recaptcha : Basic class
 *	Abdelkader ELKALIDI | contact@updel.com
 *	More infos : https://www.google.com/recaptcha
 */
class Recaptcha{
	public 		$theme		=	'clean';
	public 		$lang		=	'en';
	public		$publicKey;
	public 		$privateKey;
	public 		$messages	=	array(
									'invalid-site-private-key'	=>	'We weren\'t able to verify the private key.',
									'invalid-request-cookie'	=>	'The challenge parameter of the verify script was incorrect.',
									'incorrect-captcha-sol'		=>	'The CAPTCHA solution was incorrect.',
									'recaptcha-not-reachable'	=>	'reCAPTCHA never returns this error code. A plugin should manually return this code in the unlikely event that it is unable to contact the reCAPTCHA verify server.',
								);
	protected 	$error;
	protected 	$recaptchaServer 		= 	'http://www.google.com/recaptcha/api';
	protected 	$recaptchaSslServer 	= 	'https://www.google.com/recaptcha/api';
	protected 	$recaptchaCheckServer 	= 	'http://www.google.com/recaptcha/api/verify';

	/*
	 *	Nothing
	 */
	function __construct(){
	}

	/*
	 *	Debugger
	 */
	public function getError() {
		return !empty($this->error)	? $this->messages[$this->error] : false;
	}

	/*
	 *	Get Recaptcha
	 */
	public function getCaptcha($ssl = 0){
		$server	=	($ssl)	?	$this->recaptchaSslServer	:	$this->recaptchaServer;
		$error	=	(!$this->getError()) ? null : "&amp;error=" . $this->getError();
		$html	=	'
		<script type= "text/javascript">
			var RecaptchaOptions = {theme: \''.$this->theme.'\', lang : \''.$this->lang.'\'	};
		</script>
		<script type="text/javascript" src="'.$server.'/challenge?k='.$this->publicKey.$error.'"></script><noscript><iframe src="'.$server.'/noscript?k='.$this->publicKey.$error.'" height="300" width="500" frameborder="0"></iframe><br /><textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea><input type="hidden" name="recaptcha_response_field" value="manual_challenge"/></noscript>';
		return	$html;
	}

	/*
	 *	Check Recaptcha
	 */
	public function checkCaptcha(){
        $data 	= 	$this->getBySocket(
								$this->recaptchaCheckServer,
								array (
									'privatekey'	=> 	$this->privateKey,
									'remoteip'		=> 	$_SERVER["REMOTE_ADDR"],
									'challenge'		=> 	$_POST['recaptcha_challenge_field'],
									'response'		=> 	$_POST['recaptcha_response_field'],
								)
							);

        $array 			= 	explode("\n", $data);
		$this->error 	= 	(trim($array[0]) == 'false') ? trim($array[1]) : null;
	}

	/*
	 *	Send Data using Sockets
	 */
	private function getBySocket($url, $data) {
		$data		=	$this->concatData($data);
		$post	 	= 	curl_init();
		curl_setopt($post, CURLOPT_URL, $url);
		curl_setopt($post, CURLOPT_USERAGENT, $data);
		curl_setopt($post, CURLOPT_POST, 1);
		curl_setopt($post, CURLOPT_POSTFIELDS,$data);
		curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
		$response = curl_exec($post);
		curl_close($post);
		return $response;
	}

	/*
	 *	Concat Data
	 */
	private function concatData($data) {
		if(is_array($data)){
			foreach ($data as $key => $value){
				$var[]	= $key."=".$value;
			}
			return implode("&",$var);
		}
		else{
			return $data;
		}
	}
}

Example :

<form method="post" action="">
<?php
    require 'recaptcha.class.php';

    $captcha    =    new Recaptcha;
    $captcha->publicKey        =    'your public API key';
    $captcha->privateKey    =    'your private API key';

    if(isset($_POST) AND !empty($_POST)){
        $captcha->checkCaptcha();
        $debug    =    $captcha->getError();
        if(!$debug){
            echo 'All right';
        }
        else{
            echo $debug;
        }
    }

    echo $captcha->getCaptcha();
?>
<input type="submit" value="Check captcha" />
</form>

Zend Framework : Modular Application [Part 1]

Project description : A simple guestbook module using Zend Framework 1.11 .

Project

Create new project using Zend_Tool :

zf create project MyApp
cd MyApp

Create module :

zf create module Guestbook

Create controller for Guestbook (1 = index action included):

zf create controller Index 1 Guestbook

Now go to /MyApp/application/configs/application.ini and comment/delete the line :

;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

Then add the lines

;Modular suport
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =

And add this lines to set Guestbook as default module

resources.frontController.params.prefixDefaultModule = "1"
resources.frontController.defaultModule = "Guestbook"

Create php file “Bootstrap.php” under folder /MyApp/application/modules/Guestbook and past the code

<?php
class Guestbook_Bootstrap extends Zend_Application_Module_Bootstrap{}

Now test your app

Read the rest of this entry »

Drag2Crop mootools plugin : Drag picture inside a box

UPDATE 09/06/2010 : Start drag at “Top” and “Left” values.

facebook_thumbnail

Drag2Crop : This small mootools plugin extends “Drag plgin” allow to drag picture inside a small box to get a thumbnail showing the good part of the picture, and after Drag complete return values [Top, Left, Width, Height] of picture relative to the box (Like facebook).

The MooTools 1.2 JavaScript

var Drag2Crop = new Class({
    Extends: Drag,
    Implements:[Options,Events],
    initialize: function(picture, options) {
        this.setOptions({
            relative    :    'relative',
            modifiers   :    { x: 'scrollLeft', y: 'scrollTop' },
            style       :    false,
            invert      :    true,
            top  		:    0,
            left		:    0,
            onComplete  :    this.complete.bind(this),
            debug       :    false
        }, options);
		this.top        =     this.options.top.toInt();
        this.left       =     this.options.left.toInt();
        this.picture    =     $(picture);
        this.relative   =     $(this.options.relative).setStyles({cursor:'move'}).scrollTo(-this.left, -this.top);
 this.parent(this.relative);
 this.__construct();
 },
 __construct	:    function(){
 if(Browser.Engine.trident) document.ondragstart = function (){return false;}; // IE fix
 },
 coordinates	: function(){
 this.getCoordinates	=	this.relative.getScroll();
 this.getSize		=	this.relative.getSize();
 this.width  		=   this.relative.getSize().x.toInt();
 this.height  		=   this.relative.getSize().y.toInt();
 this.left  			=   -this.getCoordinates.x.toInt();
 this.top    		=   -this.getCoordinates.y.toInt();
 },
 complete    :    function(){
 this.coordinates();
 this.fireEvent("done",[this.top,this.left,this.width,this.height]);
 }
});

The Usage

window.addEvent('load', function(){
	new Drag2Crop('pictureId', {
		relative 	: 	'relative',
		top			:	-30, // Start at top : -30
		left		:	-60, // Start at left : -60
        onStart		:    function(){
            this.picture.setStyles({opacity:0.5});
        },
        onDone      :    function(top,left){
            this.picture.setStyles({opacity:1});
			$('test').set('text', 'Top : ' + top + ' | Left : ' + left);
        }
    });
});

See Demo

GitHub Repository

Projet @ Mootools Forge

Events :

beforeStart : Executed before the Drag instance attaches the events. Receives the dragged element as an argument.

start : Executed when the user starts to drag (on mousedown). Receives the dragged element as an argument.

snap : Executed when the user has dragged past the snap option. Receives the dragged element as an argument.

drag : Executed on every step of the drag. Receives the dragged element and the event as arguments.

complete : Executed when the user completes the drag. Receives the dragged element and the event as arguments.

cancel : Executed when the user has cancelled the drag. Receives the dragged element as an argument.

top: (number) start drag at top value.

left: (number) start drag at left value.

done : Executed when the user completes the drag.Receives the values [Top, Left, Width, Height] of picture relative to the box

The thrilling potential of SixthSense technology

Smarty : {capture} to put code in your header page

If you are using Smarty to generate your templates, I strongly advice you to take advantage of the function: {capture}

This function is used to collect the output of the template between the tags {capture}{/capture} into a variable instead of displaying it.

Exemple  :

index.tpl

{capture name=header}
{literal}
<script type="text/javascript">
alert('Javascript in head');
</script>
{/literal}
{/capture}
<!-- Include Page Header using Smarty {include} -->
{include file="header.tpl"}
My index page content

header.tpl

<html>
<head>
<title>Page ttle</title>
{$smarty.capture.header}
</head>

Nb : “Javascript code” must be placed between {literal}{/literal}

SDK Iphone pour windows et linux

La moindre des choses qu’on puisse dire sur la politique d’Apple  concernant le développement des application destinées à Iphone et Ipod touch est “Meeeeeeeeeeerde”.

Apple tente de vendre un Mac pour tout curieux qui souhaite personnaliser son mobile à la pomme, puisque son kit de développement XCODE (Iphone SDK) n’est disponible que pour son OSX (à partir de leopard 1.5.2 si je ne me trompe pas).

En gros, les utilisateurs de Linux et Windows sont ignorés par Apple, ce qui laisse deviner que la croissance positive des ventes d’Iphone a peut être une grande influence sur la vente des Macs.

Alternative PC :

Depuis la sortie des Mac Intel, certains bricoleurs ont déjà hackés OSX pour le faire tourner sur PC, idem pour “Snow Leopard”, il ne reste plus qu’a trouvé un bon tutoriel.

Alternative Linux :

On parle beaucoup de iphone-dev Toolchain, disponible pour plusieurs plateformes et qui permet de coder en Objective-C comme pour XCODE.
Plus d’infos sur : http://code.google.com/p/iphone-dev/wiki/Building [EN].
NB : malheureusement pour les utilisateurs de Windows “iphone-dev Toolchain est indisponible.

Alternative Windows :

Winchain : Un nom familier pour les Linuxiens, en faites c’est peut être une reprise de l’iphone-dev toolchain et qui a été peut être abandonner, à voir les commentaires de la partie HowToUse j’en doute que ca marche encore pour l’iphone OS 3.X mais bon il faut l’essayer avant.

DragonFireSDK (Payant) : Il vient de sortir, On dit que c’est un SDK pour Windows, mais en vérité (après un test en Bêta) c’est une dizaines de fonctions dite API, donc rien à voir avec le vrai SDK d’Iphone, la programmation se passe dans Microsoft Visual C ++, et après compilation, DragonFireSDK émule le code dans une fenêtre sous forme d’Iphone, au final vous devez uploader votre application sur http://dragonfiresdk.com/buildserver.htm qui convertira votre code en Application Iphone dans un de leurs serveurs MAC, la définition de DragonFireSDK serai donc : Intermédiaire entre Windows et le SDK d’iphone sous Mac

Malgré les alternatives, vous n’êtes pas le bienvenue dans l’App Store, à moins que vous disposez d’un Mac et d’une Apple ID.
Y a t’il une solution pour faire fonctionner Android sur mon Ipod Touch ?

Plesk : How to pointing domain to a subdirectory

First create your “subdirectory_name” then run terminal and edit httpd.include (vi, pico …):

pico /var/www/vhosts/domain.com/conf/httpd.include

Change every “/var/www/vhosts/domain.com/httpdocs
To “/var/www/vhosts/domain.com/httpdocs/subdirectory_name

Restart apache :

service httpd restart

This trick can be used to configure another domain to be pointing in another domaine : exemple

Change every “/var/www/vhosts/domain2.com/httpdocs
To “/var/www/vhosts/domain1.com/httpdocs

Mise à jour Snow Leopard 10.6.2 : Menus barre disparu

Pressé d’installer la mise à jour 10.6.2 de Snow Leopard, je me retrouve sans la barre de menus

Capture d’écran 2009-11-17 à 01.30.21

Une situation merdique mais bon, il fallait juste patienter quelques jours pour que d’autres partagent leurs expériences.

1 – Si vous utilisez Istats regardez par ici : http://forums.appleinsider.com/showthread.php?t=102462

2 – Si non (comme dans mon cas) ce billet est votre sauveur : http://www.mymacosx.com/tricks-and-tips/10-6-2-caused-empty-menu-bar-spotlight-icon-disabled.html

Capture d’écran 2009-11-17 à 02.22.27

Page 1 of 3123»