Archive for May, 2009

method setTemplate() in a sfComponent (symfony 1.2) Comments Off

source : blog.doubleu3.com

Oops, there’s no setTemplate() for components!

Why is this a problem? Because, without it, there’d have to be a seperate template file for each section’s action in the component. I just want to use the one template, and use the $section variable to determine what section to highlight.

The fix

The fix is to add a setTemplate() method to the sfComponents class.
It isn’t that complicated, but requires modification to a couple of files.

Add the following lines (2 methods, and one property definition) to
symfony/actions/sfComponent.class.php

/**
* Holds the sfView instance which performs the rendering.
*/
private $componentView;

/**
* @author Jared Armstrong
* Set the "View" object for this component, so that the component
* actions can modify the template for the view.
*
* @param sfView $componentView
*/
public function setComponentView($componentView) {
$this->componentView = $componentView;
}

/**
* @author Jared Armstrong
* Sets the template to use when rendering this component.
* @param string $template Name of the template to render
* (excluding _ and .php extension - automatically added since this is a component)
*/
public function setTemplate($template) {
$this->logMessage('Modifying template for component to \''.$template.'\'', 'debug');
if (isset($this->componentView) && $this->componentView instanceof sfView)
$this->componentView->setTemplate('_'.$template.'.php');
else
throw new sfException("Unable to set template for this component.
Component did not provide a sfView instance to modify.");
}

This provides the setTemplate() functionality like that of sfAction.

Now, we need to modify the code that creates the component instance and renders it, because we need to pass it the sfView instance to modify the output template which gets used.

In symfony/helpers/PartialHelper.php

function get_component($moduleName, $componentName, $vars = array()) {
...
$allVars = _call_component($moduleName, $componentName, $vars);
...
}

to

function get_component($moduleName, $componentName, $vars = array()) {
...
$allVars = _call_component($moduleName, $componentName, $vars, $view);
...
}

This passes the view instance to the method executing the component.

Now also

function _call_component($moduleName, $componentName, $vars) {
to

function _call_component($moduleName, $componentName, $vars, $componentView = null) {

and

function _call_component($moduleName, $componentName, $vars, $componentView = null) {
...
// create an instance of the action
$componentInstance = $controller->getComponent($moduleName, $componentName);
...
}

to

function _call_component($moduleName, $componentName, $vars, $componentView = null) {
...
// create an instance of the action
$componentInstance = $controller->getComponent($moduleName, $componentName);
$componentInstance->setComponentView($componentView);
...
}

Done!
Now your sfComponents should be able to successfully use the setTemplate method like that of your sfActions.

Possible better alternatives
Using the sfConfig, my guess is you can modify the class used to render ‘partials’, and when it runs the getTemplate() method, check to see if a variable has been set in the varholder that tells of a different template to use. However, the above method provides more transparency from actions to components.

Thank you Jared for this tip, wrote here to have a backup ;-)

Tags: devloppement, symfony, tips

Twitter act as an email-discover for spam-bot ? Comments Off

it seems that with this little php-code :
$file = file_get_contents("http://search.twitter.com/search?q=gmail.com+OR+hotmail.com++OR+%22email+me%22");
$file = strip_tags($file);

preg_match_all(
"([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b)siU",
$file,
$matches);

print_r($matches);

Anyone can grab emails displayed on twitter recently … It just wanted to test this and it works :
image-6
People really have to learn what is internet and what is a bot … do never leave your email on a public page !

via http://twitter.com/_kemar/status/1804577430

Tags: bot, email, spam, twitter, Web

#Hadopi : du grand n’importe quoi Comments Off

Nos chers et très avisés députés ont pondu des choses pour le moins original ces derniers temps (lemonde.fr)
Avec Hadopi, installez un cheval de troye sur votre ordinateur pour prouver que vous n’êtes pas coupable (Adieu la présomption d’innocence ?) et le mieux dans tout ça :

Rien n’est prévu pour des systèmes d’exploitation libres. Il faudra donc pour un utilisateur sous Linux soit changer de système d’exploitation (Microsoft uniquement à priori), soit décider de se passer du fameux mouchard, à ses risques et périls… Rien n’est pour l’instant prévu non plus pour les utilisateurs de Mac OS.

En gros : soit vous retournez chez papi Bill Gates avec son Os de merde (qui au passage se verra doter d’un logiciel que rien ne promets d’être leger, un peu comme les antivirus nécessaire sur micro$oft), soit vous vous collez une incapacité a prouver que vous êtes innocent au moindre doute sur les activités de votre connexion internet.
Mais au fait : si je télécharge en bit-torrent la dernière version d’Ubuntu, on risque de me couper ma ligne ? Et si c’est mon serveur @hébergeur qui télécharge en P2P ils vont couper la connection de l’hébergeur ? (Oops)
Désolé messieurs les députés mais votre absence de logique me donnerait bien envie d’aller voir ailleurs (qu’en France) si l’herbe n’est pas plus verte …

Tags: coup de gueule, Général, Hadopi, Web

Design Comments Off

because brown was boring, i just change this blog’s theme.
Hope you’ll like it !

Tags: Général, mood, perso

Grep + Awk Comments Off

another tips for unix file management :

how to use grep an awk combined ? here is a simple example : i want to delete those boring ._* files created by macosx that i scp to my server

make a test :
find myDirectory/ "\._*" | grep "\._" | awk '{print "rm "$1}' > tmp_file

if cat tmp_file looks good, then execute the code !
find myDirectory/ "\._*" | grep "\._" | awk '{print "rm "$1}' | sh

there is probably better but i just know this tips :)

Tags: sysadmin, tips, ubuntu

Spotify invitations 15

I received today 9 Spotify invitations.
Spotify is something like a Deezer+iTunes software.
Tell me if you want one

Spotify free version caption

Spotify free version caption

UPDATE : no more invites, i keep the two last ones for family ;-)

Tags: spotify

Osx 10.5.7 released ! Comments Off

Everything is in the title : Osx 10.5.7 has been released yesterday ! (details are here : http://support.apple.com/kb/HT3397
Upgrading now !

Tags: Apple, Macosx

How to add a post-commit mailing on SVN Comments Off

Here is a short mémo on how setting up an automatic emailing when a user commits files on a svn repository
Assuming you use a Ubuntu/Debian-based OS.

  1. First step : make sure you have a functionnal SVN-repository on the machine
  2. 2nd step : we’ll need libsvn-notify-perl package :sudo apt-get install libsvn-notify-perl
  3. You may now have the svnnotify binary in /usr/bin/ or something like this. try whereis svnnotify if you don’t know where it is
  4. go to you repository’s directory:cd /home/myname/svn/project1/
  5. create a file named post-commit in ./hooks/ and make it executable by www-datatouch ./hooks/post-commit && chown www-data:www-data ./hooks/post-commit && sudo chmod u+x ./hooks/post-commit
  6. Now edit post-commit file and write the following :#!/bin/sh
    REPOS="$1"
    REV="$2"
    /usr/bin/svnnotify -r "$REV" -C -d -H Alternative \
    --alt HTML::ColorDiff -p "$REPOS" -t "to@domain.tld" \
    --from 'from @ domain.tld ' \

    just replace to@domain.tld and from@domain.tld by your correct email adresses (advising that to@domain.tld may be a mailing-list that mail all the people that work on the project)
  7. Additionnaly, you can add this : --reply-to `cat "/home/myname/etc/svn-authors/myproject/$AUTHOR"`\ assuming that you have files that contains the email of each svn-user in the /home/myname/etc/svn-authors/myproject/ directory
    E.G : in the etc/svn-authors/myproject/ directory you can
    echo -n 'firstName.lastName@domain.tld' > userPseudo foreach of yours svn-users

Good luck !

Tags: devloppement, svn, sysadmin, tips, tool, ubuntu

Rsync mémo Comments Off

A good way to Rsync files from ( excluding ‘._*’ files on my mac, you may need to exclude .svn files) :
rsync -avh --progress --exclude='._*' SRC_DIRECTORY DST_DIRECTORY

-v : verbose
-h : human readable
–progress : progress …
-a :

-a, –archive archive mode; same as -rlptgoD (no -H)

Moreover the -n option may be useful to preview the rsync results.
More options in the man-page ;-)

Tags: bonne pratiques, rsync, sysadmin, tips