Thursday, September 29, 2011

Drupal adsense in content

This tip will show you how to insert your ads in the middle of your content with Drupal 6. Drupal 6 has many modules with lots of functions to do things, but if you can get to do things without installing a new module is much better!
So, if you want to insert adsense or any other javascript based ads in the middle of you content, in between your paragraphs, you can do it with a little bit of php.

1. Open your active theme folder, usually in /sites/all/themes/my_active_theme

2. Open the file page.tlp.php please do a backup of this file first

3. Search the line:   <?php print $content ?> and insert this code right before

<?php
// Show ads when user is not logged in
if(!user_is_logged_in())
{
// Show ads in the middle of content
$adsBlock='<script type="text/javascript">PLACE YOUR JAVASCRIPT CODE HERE</script>';
$arr = explode ("</p>", $content); // center content ads insert ads after first paragraph
$arr[1] = $adsBlock . $arr[1];
$content = implode("</p>", $arr);
}  
?>
This will show ads in the middle of your content right after the first paragraph, if you want to show your ads after the secod paragraph change this line
$arr[1] = $adsBlock . $arr[1];
to
$arr[2] = $adsBlock . $arr[2];


This code insert your ads after the first or second paragraph so it will appear in the middle of your article.
The ads will show once even if it is on the teaser view, it will only appear in the first post, so you won't have too many ads appearing.
And finally to make it work, clear the site cache to see changes. Now your ads appear in the middle of  content
All this is simply done without installing another Drupal module you only have to copy the code and adapt it a little bit to your needs.
In fact Drupal adsense module does not inject the ads in the middle of content but before or after the content, so here you've got a very easy way to do it, it works like a charm!

Tuesday, September 27, 2011

Configure Xampp on Windows

As you already know Xampp is a prepared environment to develop web applications with Apache, PHP and MySQL.
The good thing is that you don't have to spend time to install and configure these separately.
Once you've installed it  you may have to configure Xampp on windows to adapt it to your needs though, so here you can see some tips and tricks to tune up your Xampp installation on Windows

Launch PHP on the command line

Add C:\xampp\php\ to your environment variable windows PATH
Append your XAMPP PHP directory at the back of what is already there ;C:\xampp\php\


Increase PHP memory limit

Edit php.ini in c:/xampp/php/php.ini

change memory_limit to whatever you want:

memory_limit=256M


Add your web sites

Go to the Httdocs folder create a folder named old, cut and paste all loose files (not directories)
Then copy or create your own website folders:

/httdocs/website_1
/httdocs/website_2
/httdocs/website_3

You will access to them like this:

http://localhost/website_1


Xampp on windows: use MySQL on the command line

cd c:\xampp\mysql\bin

Set the root password:
mysqladmin.exe -u root password yourpassword


Connect to mysql:

mysql.exe --user=root --password=yourpassword

Load SQL file:

source c:/db/my_database.sql;

If all this fails reset root password to empty by executing: c:/xampp/mysql/resetroot.bat


Add a Virtual Host configuration

c:\xampp\apache\conf\httpd.conf

For a personalized configuration:

Add or edit files in:
c:\xampp\apache\conf\extra

So there, you can configure Xampp to work on windows and then deploy your pages and make it work on a Linux machine!

Sunday, September 25, 2011

Ubuntu 10: window buttons to the right

One more thing with Ubuntu 10: windows buttons are on the left instead of the right trying to imitate the Apple style.
I prefer the buttons to the right for a simple reason: the window title is the first thing you see to the left and the whole window top space is so much better optimized. I really hope they revert this: hey people from Canonical do not micmick Apple stuff, please, keep on thinking about users as before!

 I had to do some search to find how to change this one and here is the trick:

> Press ALT+F2 button to launch the Run application window
> Type gconf-editor





Navigate to Apps -> Metacity -> General
Double click on button_layout, values are: close,minimize,maximize:
Change values to menu:close,minimize,maximize
Well, I did mine to menu:minimize,maximize,close

To get the close control all to the right
That makes it easy if use both Windows and Linux regurlaly

Back to Ubuntu 10

Last night a virus killed my Windows XP, katusha a form or worm attacked my laptop. 
I decided to get back to Ubuntu as fighting against viruses, reformating my laptop every six month and reinstalling the OS and all the software can be annoying!

And now wich Ubuntu version to choose? I prefer a LTS (Long Term Support) version of course. The 10.04 LTS version "The Lucid Lynx" is supported till April 2013. For all the other new versions a 6 months update is due.
I've tried Ubuntu 11.04 but it slowed down my laptop too much so I went back to Ubuntu 10.

But there are so many thing I still love about Windows (omg!, ha!) I really love the Arial font type as it is my favourite for internet browsing. Times New Roman and Courier New are still the best! In fact Courier New is my favourite for programming.

So, to install the Microsoft font package in Ubuntu just type:

sudo apt-get install msttcorefonts

Anwser yes to all the license questions.

I've opened Firefox and the font type was the old "Sans", where is Arial in Firefox browser?
Open Firefox and go to:
Edit > Preferences > Content and choose Arial as the default font.

And in your system go to:

System > Preferences > Appearance and select Arial for the groups you want

The second thing I need is support for the spanish language, so to install the spanish language support just type:

sudo apt-get install language-support-es

That's pretty much all about it, the next step is configuring my programming environement.