28 Aug, 2009
The ShareThis widget is pretty handy for getting your site viral but it sometimes doesn’t always fit into your design. ShareThis has the option to use your own image to open the widget window. To save you time trying to learn all of the ShareThis API, I will just show you what I did.
First you need to go to the ShareThis Website to get the button code. Go through the steps and put that code in the head section of your html.
Now the code I used to change it to use my image for the button:
var object = SHARETHIS.addEntry({
title:'sharethis',
summary: 'Sharing My Website'},
{button:false});
document.write('<span><a href="void(0);"><img src="/new/images/share.png" style="margin-top: 17px;margin-left:-20px" /></a></span>')
var element = document.getElementById("share");
object.attachButton(element);
Copy and paste that inside a javascript tag and just change the url of the img to yours in the document.write line.
19 Aug, 2009
Recently I was getting an error on one of our sites. It was a simple form that has an upload field that uploads a file and emails it.
I was getting this error however:
Could Not Access: /var/…… (my path to the upload)
I immediately figured it was a permission problem of the upload file. That was all fine though. After a lot of code staring and some reading up on the $_FILES array I noticed where the issue was in my phpmailer code.
if(isset($_FILES['filename'])){
$mail->addattachment($target_path);
}
The thing I learned is that even when a file is not picked to upload, the $_FILES array is still set albeit empty.
Once I changed my code to:
if(isset($_FILES['filename']) && $_FILES['filename'] != ''){
$mail->addattachment($target_path);
}
All is good now! Hope this helps others save time!
That’s all good and dandy unless a file was not selected to upload.
13 Aug, 2009
Lost passwords are the bane of my existence. Luckily, lots of places offer password recovery options. A Joomla 1.0.0 site for a long time client of mine wasn’t one of those sites. Given that the password is hashed, there’s no real way to recover it, but you can reset it; so, here’s how I reset my password:
- Try to guess password several times, no luck
- Look up username:
USE `joomla`;
SELECT `id`, `username` FROM `tbl_users`;
- Try a few more times to guess the password, using the correct username (admin by default, not the case for me)
- Look up the hashed password:
USE `joomla`;
SELECT `id`, `username`, `password` FROM `tbl_users`;
- Look up what type of hash Joomla uses. It looked like MD5 and it was.
- Generate a new password:
USE `joomla`;
UPDATE `tbl_users` SET `password` = MD5('new_password_here') WHERE `id` = 'selected_id_here';
- You may now log in with your new_password_here
11 Aug, 2009
Today a client wanted all form data to be saved to a spreadsheet. I knew it’s possible to do it to excel but I came across an easier solution. Google spreadsheets, I realized, is very easy in this regard. So easy I even integrated it along side wordpress. There are a couple of requirements however. First you need to pick up a version of the Zend PHP framework with Gdata in it’s library. You can stop there but I found a helper class that makes it that much easy.
Once you have both of those you have a bit of configuration to do.
set_include_path(get_include_path() . PATH_SEPARATOR . "$_SERVER[DOCUMENT_ROOT]/wp-content/plugins/zend/library");
include("$_SERVER[DOCUMENT_ROOT]/wp-content/plugins/zend/demos/Zend/Gdata/Google_Spreadsheet.php");
The first line is including the Zend Library and the second is loading the helper class. Once those two lines are added to you script you can begin connection.
$u = "your email";
$p = "your password";
$spreadsheet = new Google_Spreadsheet($u,$p);
Just like that you are connected. So for my client, who wanted to add a new row to the spreadsheet for everytime a registration form was finished, I named the columns in the spreadsheet the exact name as the input tags in the form. Then ran the following code.
$ss_array = array();
foreach($_POST as $key=>$value)
{
$ss_array[$key] = $value;
}
$spreadsheet->addRow($ss_array);
unset($ss_array);
Pretty cool! If you look into the helper class and even into the more advanced Zend files you will see there is a bunch of ways to manipulate. You can get rows from a spreadsheet even with search criteria. If you mastered the functions you could even use it as a poor man’s, err.. homeless man’s database if you wanted to. Even if you are using a database, this is a nice option to have next to it so a client could more easily see data. More clients will understand spreadsheets than anything sql.
10 Aug, 2009
Recently I needed to create a duplicate of PGSQL database. Being a MySQL guy, I didn’t know off hand how to do it, but here is an easy way:
pg_dump original_db > original_db.sql
createdb new_db
psql -d new_db < original_db.sql
From a bird’s eye view, you are creating a dump of the original database and outputting it to a file. From there, make sure the new database is created and use your dump file as input for that database. It wouldn’t be too hard to make this into a one-liner, but I like to see intermediate steps to make sure things are going well.
8 Aug, 2009
I just signed a client up for a dreamhost account for email. They have a large number of mailboxes and we are thinking this will be a good solution.
I decided to check for promo codes online before doing it. Success! The first code I found offered $97 off!  Better yet, I tried it and it worked!!! So far so good with dreamhost, though the account hasn’t been approved yet.
4 Aug, 2009
Here is a new plugin for getting a query string variable into a wordpress post or page.
Where ever you want your “get” variable to appear just type .
So if your url is http://www.yoursite.com/apageorpost?thevariable=success, get the “success” by typing [get thevariable] where you want it in your content.
Simple as that!
You can pick the plugin up right Here