Jan 12
Digg
Stumbleupon
Technorati
Delicious

Phoogle usage with Symfony

If you have ever needed a way to include Google Maps functionality into your project you should know what is Phoogle. There is also GoogleMap plugin for Symfony but I was not able to make it adding a point to a map based on lang an long values.
So it’s good to know that there is Phoogle php class which is going it simplify the life for developer:

http://www.systemsevendesigns.com/phoogle

Here is what they wrote about theirselves:

Phoogle Maps (pronounced like Foogle Maps) is a PHP class that integrates itself with the Google Maps API and with the Google Geocoding API to make an easy to use interface to display Google Maps on your site. With about 5 lines of PHP code you can display a customized Google Map on your website. Please note that you will need a free Google Maps API Key to use Phoogle Maps

And that’s the truth. If you need to have a quick way to display a point on world map - IMHO the easiest way is to use Phoogle.

Anyway, now.. does not matter if you’ll use pure Google Map API or Phoogle wrapper.. in both cases you may get into a small trouble with integrating it into symfony: how to add google map javascript code into header of only specific pages of your project.

Here is a trick for this (I found it on symfony forum, btw):

So you have to have this code in your layout.php template:

&lt?php if (has_slot(’gmapheader’)): ?>
&lt?php include_slot(’gmapheader’) ?>
&lt?php endif; ?>

Now dont forget to put phoogle class files into your lib/ folder.
And next step - for the pages where you want to show Google Map insert the following code into templates:

$map = new PhoogleMap();
$map->setAPIKey(YOUR_GOOGLEMAP_KEY_HERE);
$map->setWidth(700);
$map->setHeight(400);
$map->addGeoPoint($lat, $lon, ‘It is here!’);

slot(’gmapheader’);
$map->printGoogleJS();
end_slot();

echo $map->showMap();

This little trick works not only for Phoogle of course. You may use slot functionality as your additional weapon for inclusion of different javascript blocks or design elements.


Author: admin
Jan 08
Digg
Stumbleupon
Technorati
Delicious

How to hide symfony project in subfolder

As for me, this is gonna be quite popular task - do not use symfony project in root of web folder but keep it under kinda “forum” or “users” folder. This way you may use in root of web folder (public_html or web or wherever you have called it) another type of software (e.g. Joomla). So for instance when you go to domain.com you see Joomla pages and when you go to domain.com/forum you will get access to symfony-driven project.

This is not something complecated but requires some tuning. So first of all you’ll need to change a line in your .htaccess file in root: RewriteRule ^(.*)$ /forum/index.php [QSA,L]
This way your .htaccess (which is located directly in public_html) has to look like this one:

Options +FollowSymLinks +ExecCGI


RewriteEngine On

# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /

# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]

# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f

# no, so we redirect to our front web controller
RewriteRule ^(.*)$ /forum/index.php [QSA,L]

# big crash from our front web controller
ErrorDocument 500 “Application error. symfony application failed to start properly”

And now of course you’ll need to move you symfony project into forum directory and change a bit your index.php, frontend_dev.php, backend.php, etc controller files so they contain correct path to symfony root:

define(’SF_ROOT_DIR’, realpath(dirname(__FILE__).’/../../’));

and you may also want to have fixed trailing slash problem on some hostings so use the following line for it (index.php is of course for index.php file and the other ones has to contain correspondent filename):

$_SERVER[’SCRIPT_NAME’]=’/forum/index.php’;

That’s it. In your forum directory you’ll have to keep standard .htaccess:

Options +FollowSymLinks +ExecCGI


RewriteEngine On

# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /

# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]

# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f

# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]

# big crash from our front web controller
ErrorDocument 500 “Application error. symfony application failed to start properly”

Of course this is not that necessary to hide your project into a folder if you can have a workaround with routing features of symfony. But sometimes technique which I’ve just described can be very-very helpfull.

See ya!


Author: admin
Dec 22
Digg
Stumbleupon
Technorati
Delicious

Merry Christmas and Best Wishes for the New Year

As 2007 draws to an end and we thought it would be a good idea to close it off with an end of year message. Next week we’ll all be off visiting loved ones, relaxing, overindulging.

There were a few important things happened this year. Symfony framework was kept improving a lot and it became so popular that we’ve launched our site dedicated to this great framework :-)

2007 was an amazing year for us here at SymfonyLab.

We wanted to send out a special thanks to some of our most active commentors. Thanks guys, you’ve helped us a lot bringing important and interesting questions.

Enjoy your Christmas holidays! We look forward to keep posting for you in the new year - it should be a very exciting one!


Author: admin
Dec 13
Digg
Stumbleupon
Technorati
Delicious

Review of WilliamAnderson.ca

Ok, so this idea came to me on the stage when we’ve been launching SymfonyLab.com. I was going to review here existing symfony-based sites and I want finally to start doing that. I’m not a hacker and I’m not going to crack those resources. I’m also not security expert and the only reason why I’m doing that - it’s some kind of fun for me and it’s of course some warning for the resource owners and also it’s probably a ring for sites developers. Actually, what I want to finally reach - to help site owners to protect their sites a bit. Maybe when they will find their sites here - they will urgently protect/fix them or at least kick some developers asses :-)

Today lets take a look into the first site I’ve took out of symfony’s sites list: williamanderson.ca

So as it seems to me - the most popular problem of symfony sites - developers forget to delete _dev.php files from production server. And as a result we may figure out some interesting information about this site. I dont think this information is really critical but this can be helpfull for the hackers. So what we may figure out from here:

http://www.williamanderson.ca/frontend_dev.php

Not too much but first thing is that here is not turned off eaccelerator (in dev mode cache is also disabled but this can be only per dev mode so we cant be 100% assured). Maybe that’s the reason why this site is loading so slowly?
The other thing I’ve noticed that computer name where this site is hosted is called:

COMPUTERNAME: NATALIE

Hey guys, that’s my wife’s name. What a good shot! Well, what else.. NUMBER_OF_PROCESSORS: 2, php: 5.1.2
os: Windows NT NATALIE 5.2 build 3790. Interesting?

Developer uses quite simple set of modules and based on configuration variables and dump of SQL requests it’s generally possible to obtain good vision of project architecture, e.g. here is set of custom classes

myTools: E:\www\wa\lib\myTools.class.php
photoTools: E:\www\wa\lib\photoTools.class.php
Content: E:\www\wa\lib\model\Content.php
ContentPeer: E:\www\wa\lib\model\ContentPeer.php
ContentMapBuilder: >
E:\www\wa\lib\model\map\ContentMapBuilder.php
PhotoMapBuilder: >
E:\www\wa\lib\model\map\PhotoMapBuilder.php
BaseContent: E:\www\wa\lib\model\om\BaseContent.php
BaseContentPeer: >
E:\www\wa\lib\model\om\BaseContentPeer.php
BasePhoto: E:\www\wa\lib\model\om\BasePhoto.php
BasePhotoPeer: E:\www\wa\lib\model\om\BasePhotoPeer.php
Photo: E:\www\wa\lib\model\Photo.php
PhotoPeer: E:\www\wa\lib\model\PhotoPeer.php

so there are only 2 tables photo and content. I think there is no users table so the most probably password is hardcoded (and maybe not even crypted!). Here are samples of SQL requests, so I was right about that :

SELECT wa_content.ID, wa_content.TYPE, wa_content.BODY, wa_content.CREATED_AT, wa_content.UPDATED_AT FROM wa_content WHERE wa_content.ID=2

SELECT wa_photo.ID, wa_photo.NAME, wa_photo.DESCRIPTION, wa_photo.SORT_ORDER, wa_photo.PHOTO, wa_photo.THUMBNAIL, wa_photo.FEATURED, wa_photo.VIEWABLE, wa_photo.CREATED_AT, wa_photo.UPDATED_AT FROM wa_photo WHERE wa_photo.FEATURED=1 LIMIT 1

I wish I can see full info in “log and debug messages” but only stars are there :-(

+340 Creole connect(): DSN: array ( ‘database’ => ‘****’, ‘hostspec’ => ‘****’, ‘password’ => ‘****’, ‘phptype’ => ‘****’, ‘port’ => ‘****’, ‘username’ => ‘****’, ), FLAGS: 0

The other thing that was not complicated to figure out - admin access, I think most of developers use either standard “backend” way to determine admin access or like in case of this site - self-written authorization, and here it is:

http://www.williamanderson.ca/admin.php

Of course, I dont want to provide here information which way it’s possible to login into admin area but believe me this is not a big deal with only password field and no IP blocking. So dear William Anderson please contact your developer and ask him to secure your backend. At least that’s what I’d do ASAP if I were on your place.

Of course this is too simple site for good investigation. Also I think such kind of sites can be launched based on WP engine. I dont see the reason to waste time/money on re-inventing the wheel when this can be done in 2 hours with using of existing free open-source software. Using NextGen or another kind of gallery plugin it’s really simple and much more secure I believe.

As for the actual content of this site - Mr. William Anderson my hat off. I really love the photos you made.

Good night!


Author: admin
Dec 08
Digg
Stumbleupon
Technorati
Delicious

SymfonyLab Jobs

Today we launch new symfony-related service which is called ‘SymfonyLab Jobs’:

Jobs.SymfonyLab.com

It uses job-a-matic service (and that’s why it provides access to huge list of available vacancies) and allows to post a job as well as look for the new vacancies.

You may use this service absolutely for free if you are looking for the vacancy and if you are interested in developers you may try out ‘post a job’ service for free with this coupon code:

XMAS2007

It allows $5 discount which actually means that you can post a job here for free until 1st of January (after that date we will charge $5 per 30 days for each job posted on our site).

We offer an ability to post a job here because of about 200+ experience symfony developers are visiting this site each day. This can be a good option to post here a job and I bet some of them would be interested in your proposal.

We hope you’ll find this service usefull and feel free to contact us if you have any questions and proposals.

And the last note is why we are doing it. We plan to use money earned from this job advertisement for site improvement and development of more free symfony plugins.

Sincerely,
SymfonyLab.com Team


Author: admin
Dec 07
Digg
Stumbleupon
Technorati
Delicious

Would I use Motilee?

Would I use Motilee? Well, maybe.. I’ll use it for sure in order to learn something new from its code. I bet it must be excellent sample of coding practices. Well, maybe not excellent but it’s always good to compare code written by the other experienced symfony developers with our own code. At least I was able to learn a few important tricks from sfSimpleCMS, sfSimpleBlog, sfSimpleForum. But along with sfSimpleCMS, sfSimpleBlog, sfSimpleForum I dont think I’ll be able to use Motilee for my projects.
There is no reason to use it as major forum platform because of there are formed leaders in this area. I dont think it will be able to fight somehow with phpBB, vBulletin, Vanilla, etc. Also there is no easy way to integrate it into own projects as it’s kinda stand-alone software (e.g. sfSimpleForum can be integrated but it’s quite overcomplicated as for me. The same I feel about sfSimpleCMS, sfSimpleBlog - yes they are fine and great but because of its complexicity it’s always more hard to customize them than simply write them from scratch).

So I’d like to bring here a thought.. maybe all of these sfSimple plugins should have simpler analogues. Just very simple bricks for bigger projects. Like sfPropelActAs plugins. I use them very often as they are really simple and can be integrated into everything I want and can be customized easily. So I give my vote for sfVerySimpleCMS and sfVerySimpleForum, etc. They must have an easy way to be integrated into layout of existing projects. Moreover I’m quite sure a lot of symfony developers already have such plugins but they are not sharing them maybe because of they think these plugins are too simple. Am I right?

As a sample I’d recommend the other plugin I cotributed somehow - sfSupportPlugin. This is what I called a brick for the bigger projects. I’m sure I’ll be able to use this helpdesk anywhere I need. There is no css or ajax but that’s not important for the brick. This can be customized later. It’s very-very important to have such plugins especially on prototyping stage - when you can go and in 1-2 hours get together all required plugins and have system ready for initial using.

So again in order to be undertood correctly - of course Motilee (oh and of course I forgot about Askeet) and sfSimpleCMS, sfSimpleBlog, sfSimpleForum plugins are great but there must be also sfSimplerAlernative :-)

What ya think?


Author: admin
Nov 28
Digg
Stumbleupon
Technorati
Delicious

sfAdvancedConstPlugin

I found out that I hate to keep in mind ID of pending status value in statuses table or the other values like that. And actually I had a plugin to resolve this problem which is called sfConstPlugin but as it turned out it’s hard to manage it sometimes especially if you want to provide for the user a way to manage these values EASILY from backend. So here is the answer - new sfAdvancedConstPlugin plugin is ready for publishing but I have not had a chance yet to put it on symfony-project’s pear. Am going to do that on next weekend. So `sfAdvancedConstPlugin` is a symfony plugin that provides app wide constants functionality. It automatically generates constant values based on sfRefTable values and make them accessible in every app module. Values in sfRefTable are simple id/name references tables you have in your system. So effectively you add through sfAdvancedConstAdmin table names like user_status, entity_type, log_type, etc. Then plugin works the following way - system goes through the tables defined in sfRefTable and generate for each id / name pair from this table constants on the fly (via handler mechanism). And now you may use these constants in your code as USER_STATUS_PENDING, LOG_TYPE_ERROR, etc. Of course in order to get access to these constants dont forget to add a line:

include_once (sfConfigCache::getInstance()->checkConfig(’config/db_advanced_const.yml’));

to index.php or backend.php or another controller/script where you want to have a way to use these values.

This plugin is different from sfConst plugin which required to keep all the constants directly in sfConst table and did not require additional ref tables. Effectively, both plugins are usefull to be used. sfConst is good to go if you want to keep all the constanst centralized.

So for now you may download and try it out from here:

sfadvancedconstplugin.zip

I hope someone will find it usefull, at least it saves a lot for time me now and I dont have to keep in mind all those ID values.


Author: admin
Nov 22
Digg
Stumbleupon
Technorati
Delicious

The power of rsync

I’ve never really faced the problem of differences between development and production versions before. The reason is development version always was stored on my local PC and production one was stored on the server. Or I always tried to kept it in my mind (the differences between versions) and sometimes I felt really crazy about that. I had to go and copy files over and remember which ones I copied an which not. I never had a time to try rsync and now I know for sure it was a mistake. I figured out about the ability of symfony to synchronize versions and it helped me to breath out :-)

So it can be used in the different ways, e.g. you may synchronize development version and production. But there can be another implementation - you may have the same codebase which you are improving from time to time and you want these changes to be quickly deployed on another hosts where is installed the same codebase. So in other words you may want to have an ability to quickly upgrade your software. And lets focus exactly on this case.

So first of all you’ll have to go to config/properties.ini and modify it by adding a list of hosts where your codebase (which must be upgraded) is installed, e.g.

[name1]
host=hostname1.com
port=22
user=username1
dir=/home/username1

[name2]
host=hostname2.com
port=22
user=username2
dir=/home/username2

That’s it. Now you have to run the following commands from the place where is installed your main codebase (e.g. improved one):

symfony sync name1 go
symfony sync name2 go

and it will ask you about host access password and it will copy your current codebase to name1 and name2 locations.
You have to read symfony manual to figure out the details but I hope this small writing helps you to start using sync.


Author: admin
Nov 17
Digg
Stumbleupon
Technorati
Delicious

Dynamic access to classes in Symfony

It’s about something about how to simply your life. E.g. sometimes you may want to store table names in your DB. The reasons why you may want it are different. E.g. I want to generate constants for reference tables and in order to do that I use the following approach:

$tables = sfDatabaseTablePeer::doSelect(new Criteria());
if ($tables) foreach($tables as $t) {
$object_name = sfInflector::camelize($t->getName().’Peer’);
$object = new $object_name;
$values = $object->doSelect(new Criteria());
}

So as you may see I create object dynamically. Thanks God that’s what PHP allows to do and the only thing we need is to make sure we generate correct class name. I must say somehow I’ve been trying to generate dynamically access to class peer attributes, e.g. ClassPeer::{$NAME} - and I was not able to make it working. I’ve made a few attempts and no luck.

So if someone has ever done that please, please let me know! :-P


Author: admin
Nov 10
Digg
Stumbleupon
Technorati
Delicious

sfEmailTemplatePlugin 0.0.1 is released

Hi,

So first beta of sfEmailTemplatePlugin is finally released. Thanks a lot for all the guys who commented an initial post about this plugin (Eric, Gerald, COil and James). I must say this is really helpfull to read these warm words and it inspires me to work better.

This first beta does not include tag support for email template so far but it covers all the other declared functionality. Read Wiki page for futher details sfEmailTemplatePlugin.

Unfortunately, I wont be able to work on tags functionality in the nearest time so if someone will have a chance - everything is in his hands. There is already defined sf_tag_template table where email template tags must be stored.


Author: admin