Online html to pdf tool

html to pdf converter I just want to present a new tool for converting HTML to PDF – html-2-pdf.com. It’s basically an online converter which could transform any* web site to a PDF document. Generally it could be useful if you want to print a website, or for example if you want to save the content of the website for offline reading.

The site is really simple – just insert the address of the web page which you want to be converted and few seconds after that it is ready to be downloaded. The site is just an interface of the amazing wkhtmltopdf library.

I am open for suggestions about the functionality of the site.

* – for some reasons there are web sites which are not converted correctly. This is because of HTTP headers which these sites restricting.

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca

Careful with the links in the layout

When you building application most likely there are common links within the layout. They could be in a menu, or let’s say “edit profile” and ‘logout’ links which are visible everywhere. As you probably know if you use Html Helper the link could be either Cake-relative URL or array of URL parameters.

The problem may occur if you using the second option – the array.
Continue reading

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca

Problem with mysql_real_escape_string when Sanitize your data.

When building applications is always smart to check and clean the user input. This is a must when you building a website or public application.

I create always an instance of Sanitize class in my AppController and then using it in all of my controllers like this
Continue reading

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca

Detecting if the cookies are enabled with PHP

For my current project I need a detection if the cookies are enabled or not in the user’s browser.

The easiest way to do this is by using this code:

<?php
setcookie('test', 1, time()+3600);
if(!isset($_GET['cookies'])){
    header('Location:/info.php?cookies=true');
}
if(count($_COOKIE) > 0){
    echo "Cookies are yummy!";
} else {
    echo "You didn't bring any cookies here. We are hungry!";
}
?>

The CakePHP way is almost similar:

<?php
$this->Cookie->write('test', 1);
if(!isset($_GET['cookies'])){
    header('Location:/info.php?cookies=true');
}
if(count($_COOKIE) > 0){
    echo "Cookies are yummy!";
} else {
    echo "You didn't bring any cookies here. We are hungry!";
}
?>

Ok, it’s not rocket science, but it helps 🙂

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca

How to use aggregation SQL functions with CakePHP

Have you ever wondering how to find MAX, MIN or AVG of a database table column in CakePHP way? Well I haven’t since yesterday. The solution is quite simple and obvious.

Lets say you want to show the average views per post (in the example we have the views field in every post).
The SQL should be something like this:

SELECT AVG(views) FROM posts

Instead of using query() function you can use the CakePHP way:

$this->Post->find('first', array('fields'=>array('AVG(views) as avg_views')));

Hope this will help someone.

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca

linxspy.com – track your links

Today I want to present you a small service which I wrote for a week /including the design/. 🙂

I’ve wrote it, because few times I’ve exchanged some links with strangers and few weeks after this, my link was disappeared from their sites while their was on mine. It is a bit unfair isn’t it? I know that link exchange is not promoted from Google, but people still do it. Do you? 🙂

The service is called Linxspy.com and in general it is a simple interface, where you can define your links and partner’s websites. On a regular basis /at this moment every week/, the service will check the partner site and will look for your link. If everything is ok and link is there, no action will be taken, but if the link is missing, you will be notified by mail.

It should be very usefull for web masters which exchanging or buying links with unknown or not well known partners.

Basically if everything is cool with your partners, you should forget about Linxspy, because it will bother you only for troubles. 🙂

A little bit for implementation: As I said it was build for a week and as you probably guess it’s CakePHP app. On this project I’ve used Console Shell interface for triggering the weekly check.

Here you could find more information on about the service page

Here are some screenshots from Linxspy:

Hope it would be useful for you.

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca

CakePHP ajaxed pagination and sort

Here I will describe how I did an Ajaxed pagination for one of my projects using jQuery and Livequery Plugin. Currently I am working on a huge project which, hopefully, will feed me with some ideas for blog posts and this is one of them :). So:

1. Loading the javascript libs

Loading the jQuery and Livequery was done by Autoloader helper, but if you don’t use it just include jQuery and Livequery in your layout with following code

<?php
echo $javascript->link('jquery.min');
echo $javascript->link('plugins/jquery.livequery');
?>

Continue reading

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca

Passing variables to all Models from the Controller – strict MVC way

It’s really easy to find inspiration when you developing on CakePHP. For the current project I need to create global (for all models) behavior which stores creator and modifier as well as deleter and deleted (for soft-delete).

What are the requirements

1. For every table (or at least the most of them) there are fields 6 fields:

  • creator (int) – user who create the the record
  • created (datetime) – date when the record was created
  • modifier (int) – user who modified the the record
  • modified (datetime) – date when the record was modified
  • deleter (int) – user who delete the the record
  • deleted (datetime) – date when the record was modified

2. Some tables doesn’t have such fields (like aros, acos, settings etc), so it should update tables which has such fields.

I’ve seen Soft Deletable Behavior as well as recently added WhoDidIt behavior, but I don’t like the approach of using _SESSION. I’ve also decided to use datetime field to determine if the record is active (field deleted is NULL) or deleted (if the field is set with date).

So the result was – I’ve write my own behavior who serves this.
Continue reading

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca

Autoload your javascript and css in CakePHP

Have you ever wanted to have all your css or javascripts files loaded automatically once they are on place under /webroot/js and webroot/css folders? Well this is the solution.

What is all about

I’ve build a quick helper which will include all files under the js/ and css/ directories. So once the javascripts and css are there, they will be loaded automatically.

How to use it?

Using it is really easy. It’s like a normal helper:
1. add the file autoload.php under your /app/views/helpers
2. add it in the $helpers var in the controller
3. add the following snippet in your layout file. It should be under /app/views/layouts:

<?php echo $autoload->javascript();?>

This will include all files under /webroot/js

<?php echo $autoload->css();?>

This will include all files under /webroot/css

<?php echo $autoload->all();?>

This will include all files under /webroot/js and /webroot/css

Key features:

1. The helper includes all files recursively.
2. The helper includes also files under /root/vendors/js and /root/app/vendors/js too (same apply to css). Vendors are loaded first. (Thanks to suggestion from Juan Basso)
3. The order of the files in one directory is based on the name, so now you can control the order as well. (Thanks to suggestion from Juan Basso)
4. Files starting with . (dot) are not included, files under directories starting with . are not included as well, so you can exclude some files
5. if you want to load some files after other use directories. For example if you want to include plugins after the main lib (jQuery), place them in plugins directory like:
js/plugins/plugin_one.js
js/plugins/plugin_another.js
js/.hidden/plugin_third.js
js/jquery.js
the result will be:

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/plugins/plugin_one.js"></script>
<script type="text/javascript" src="js/plugins/plugin_another.js"></script>

(same apply to css as well)

Warning: I’ve noticed that this helper doesn’t work properly with scriptaculous, because the script tries to load the additional plugins and they fail, but for jQuery there is not a problem at all.

Finally here is the code of the helper:
Continue reading

Share it:
  • Facebook
  • Twitter
  • Digg
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Yahoo! Buzz
  • Add to favorites
  • Identi.ca