The Code Cave

May 23, 2006

WP-Contract-Form 0.3 released

Filed under: WordPress — Brian @ 4:28 pm

The 0.2 had some debugging left in it and a verification didn’t work. Thus version 0.3. It can be downloaded in the same place:
http://www.thecodecave.com/downloads/plugins/wp-contract-form.zip

Changes
————————–

0.3 REQUIRED RELEASE
Removed debugging messages
When Website was blank, Email was highlighted.
When Agree was blank, an error message was not displayed.
0.2 REQUIRED RELEASE
Fixed the MD5. It now uses website instead of email too. Then the same email contact can be used for multiple websites.
Removed the CSS styles that were incompatible with my theme (and probably others). They are renamed and can be put back in easily.
Added carraige returns to the email where needed.
Made the whole thing WC3 compliant
0.1 Initial version
Automatically sends the email to the destination AND the user, reversing the From and To.
Required the website to be filled in.
Added a terms field that is customizable.
Added a customizable “I agree” line
Added a checkbox and verified it is filled out in the end.
I did not bother creating a legit POT file for language localization
Generated a unique ID for the contract.

May 22, 2006

WP-Contract-Form 0.2 released

Filed under: PHP — Brian @ 1:12 pm

The original version had some issues that have now been corrected. It can be downloaded here:
http://www.thecodecave.com/downloads/plugins/wp-contract-form.zip

Change Log:

0.2 REQUIRED RELEASE
Fixed the MD5. It now uses website instead of email too. Then the same email contact can be used for multiple websites.
Removed the CSS styles that were incompatible with my theme (and probably others). They are renamed and can be put back in easily.
Added carraige returns to the email where needed.
Made the whole thing WC3 compliant

0.1 Initial version
Automatically sends the email to the destination AND the user, reversing the From and To.
Required the website to be filled in.
Added a terms field that is customizable.
Added a customizable “I agree” line
Added a checkbox and verified it is filled out in the end.
I did not bother creating a legit POT file for language localization
Generated a unique ID for the contract.

How to install custom PEAR modules on 1and1.com and other shared servers

Filed under: PHP — Brian @ 9:57 am

1and1.com, as I said before, is a great host. Their support may not be able to tell you how to do everything you want to do, but for the most part, they give you full access. If they offer a Free server for three years deal again, snatch it up. You’ll save loads of money and may be offered an upgrade to a professional server for half price as I was.

A couple weeks ago, I told Michael (who paired with Angela has done some neat stuff - I’m gonna have to free up an hour to just browse through their site and listen to the Taiwanese Education Ministry stuff they have there and at http://metroministries.org/ ) that I would post a walk through of installing custom modules for PHP PEAR. PEAR is “custom framework for PHP Components”. In otherwords, PEAR is a HUGE common library of PHP code that will give you access to a wealth of resources you don’t have in the standard installs of PHP. If you want to do something easy or complex, there’s a good chance that there is a pear module that will help you out. Whether it is simply getting the date of a certain holiday, caching a news feed, rotating 3d objects for your visitors, streaming data to them or any of a large number of other tasks, chances are, there is a PEAR module that can give you a head start on your project. Here, take a look: http://pear.php.net/packages.php

Obviously, not all of those modules are installed under the default 1and1 PEAR account and there might be one there that you want but is not available by default. This article tells you how to get one of those modules installed. Fortunately, it’s not that complicated. Really the trick to installing custom PEAR modules at 1 and 1 is as simple as knowing how they are classifed in the PEAR documentation. See 1and1 has PEAR installed, but it is locked down so that you can’t break anything for all of the people that share your webserver. PEAR has planned for this and allows you to install a custom configuration for your particular webserver. This PEAR configuration will be the default for ALL of the server’s you host and will not affect anyone elses. PEAR calls that a “SHARED HOST” and once you have that term, you can follow the documentation here: http://pear.php.net/manual/en/installation.shared.php.

To customize all of that for 1and1, you have to put it in their directory structure. The 1and1 directory structure has two seperat number. First a two (or now maybe three) digit number which indicates the server or server farm you belong to (that’s a guess, but I think it makes sense). The second indicates your contract ID. This is not to be confused with your user ID which is the number that is shared by all of your email addresses and ftp logins. So, the directory structure looks something like this:
/kunden/homepages/10/d55555555/htdocs/ where 10 is the number I am guessing is the server farm and d55555555 is your contract ID. If you keep this in mind when reading through the document, you’ll be able to figure most of it out.

I don’t have time for the full blow by blow walk through with screenshots that I usually do, but hopefully, a quick run through will be all you need and then you can ask any questions you might have in the comments.

So your first task is to get putty.

That’s this PuTTY:

Not this putty:

Just download it from here: http://www.chiark.greenend.org.uk/~sgtatham/putty/ and install.

Setup an account to log into your site. It is straight forward, if you have difficulties. Please take a break and read the help docs on it and decided if you really want to take on custom pear modules without further reading and studying. Perhaps there is an easier way to do what you want to do.

Once you have putty installed (BTW does anyone have XWindows working through PuTTY for 1and1.com yet? I’ve wanted to try it but haven’t had the time yet…) login using your user number and main password (u35555555 or something like that not your contract ID)

Once you are logged you’ll be at a prompt that looks like this:
u35555555:~ >

Now ask pear what it’s current configuration is:
u35555555:~ > pear config-show

You’ll see that everything (Bin_dir, doc_dir and etc) is using common directory. That’s probably something like this: /usr/local/bin/php

What you need to do is create a custom config file into which you can install all of the modules you use but are not provided by default. In this case, we will be installing the HTTP_Request extension so that we can do some custom page grabbing and XSF attacks (JUST KIDDING!!!).

So, the first thing to do is create the config file in your root directory:
u35555555:~ > pear config-create /homepages/10/d55555555/htdocs/ .pearrc

Now tell the common pear module to create a copy of its directory structure for you to use…
u35555555:~ > pear install -o PEAR

Would you like to see what we’ve done?
Just type:
u35555555:~ > cat .pearrc
You’ll get something that looks like this:
#PEAR_Config 0.9
a:7:{s:7:”php_dir”;s:39:”/homepages/10/d55555555/htdocs/pear/php”;s:8:”data_dir”;s:40:”
/homepages/10/d55555555/htdocs/pear/data”;s:7:”ext_dir”;s:39:”/homepages/10/d5555555
5/htdocs/pear/ext”;s:7:”doc_dir”;s:40:”/homepages/10/d55555555/htdocs/pear/docs”;s:8:”t
est_dir”;s:41:”/homepages/10/d55555555/htdocs/pear/tests”;s:9:”cache_dir”;s:41:”/homepa
ges/10/d55555555/htdocs/pear/cache”;s:7:”bin_dir”;s:35:”/homepages/10/d55555555/htdoc
s/pear”;}

And that’s pretty much it! You’re installed. You can, if you want, see if a specific module is installed with a command like:
u35555555:~ > pear list-files HTTP
or
u35555555:~ > pear search HTTP_Request

You can try to install things:
u35555555:~ > pear install HTTP_Request

But you may find that other modules are required. So you must install them too
u35555555:~ > pear install Net_URL

However, the EASIEST thing to do is to have PEAR install all fo the modules you need automatically with the –alldependency swithc
u35555555:~ > pear install HTTP_Request –alldeps

That’s it! Your all installed.

Here is one final helpful command: config-show. If you (and I) did everything right, you should get something like the following:

u35555555:~ > pear config-show
Configuration (channel pear.php.net):
=====================================
Auto-discover new Channels auto_discover
Default Channel default_channel pear.php.net
HTTP Proxy Server Address http_proxy
PEAR server [DEPRECATED] master_server pear.php.net
Default Channel Mirror preferred_mirror pear.php.net
Remote Configuration File remote_config
PEAR executables directory bin_dir /homepages/10/d55555555/htdocs/pear
PEAR documentation directory doc_dir /homepages/10/d55555555/htdocs/pear/docs
PHP extension directory ext_dir /homepages/10/d55555555/htdocs/pear/ext
PEAR directory php_dir /homepages/10/d55555555/htdocs/pear/php
PEAR Installer cache directory cache_dir /homepages/10/d55555555/htdocs/pear/cache
PEAR data directory data_dir /homepages/10/d55555555/htdocs/pear/data
PHP CLI/CGI binary php_bin /usr/local/bin/php
PEAR test directory test_dir /homepages/10/d55555555/htdocs/pear/tests
Cache TimeToLive cache_ttl 3600
Preferred Package State preferred_state stable
Unix file mask umask 22
Debug Log Level verbose 1
PEAR password (for password
maintainers)
Signature Handling Program sig_bin /usr/bin/gpg
Signature Key Directory sig_keydir /usr/local/etc/pearkeys
Signature Key Id sig_keyid
Package Signature Type sig_type gpg
PEAR username (for username
maintainers)
User Configuration File Filename /kunden/homepages/10/d55555555/htdocs/.pearrc
System Configuration File Filename /usr/local/etc/pear.conf



(Please let me know if this post works for you or if there are mistakes I need to corred. This was all recovered from the bash log, so I could have miss read a step along the way - Thanks! Brian.)



May 20, 2006

WP-Post Contract Form

Filed under: WordPress — Brian @ 1:22 am

Updated to version 0.2 - Please download again.

Well, I’ve written my second WordPress Plugin. Well - Not really. This was more of a hack…

See Ryan Duff has a plugin that allows a person to dynamically insert contact forms into any post or page. And Podz needed a version of it that he was customized for a free WordPress installation project that’s being created. He’s got a prototype running but he wanted a unique key to be generated for each user.

You can see the request on the WP Hackers archive.

The download of my plug in is here: here.

Things I’ve changed:

0.2 REQUIRED UPDATE
Fixed the MD5. The website was not being included in the hash…
It now uses $wpcontract_website instead of email too. Then the same email contact can be used for multiple websites.
Removed the CSS styles that were incompatible with my theme (and probably others). The are renamed and can be put back in easily.
Added carraige returns to the email where needed.
Made the whole thing WC3 compliant:
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.thecodecave.com%2F%3Fp%3D133&charset=%28detect+automatically%29&doctype=Inline
0.1 Initial version
Automatically sends the email to the destination AND the user, reversing the From and To.
Required the website to be filled in.
Added a terms field that is customizable.
Added a customizable “I agree” line
Added a checkbox and verified it is filled out in the end.
I did not bother creating a legit POT file for language localization
Generated a unique ID for the contract.

Here’s a live demo of the result. I’ve since begun to wonder if the CSS alignment is specific to my blog as other blogs did not seem to have the alignment issues with the original plug in that I did. Well that’s easily fixed in anycase.

May 17, 2006

Safely using the Preview Pane in Outlook.

Filed under: Tips, Techniques and Technologies — Brian @ 2:04 pm

You CAN have the preview pane active in Microsoft Outlook without auto invoking all of the HTML spam you get.

To do this, just make a folder in your inbox that has the preview pane turned off. Then when HTML mail arrives, move it into that folder. You can also turn onthe auto-preview line that shows the first three text line for the email. This really helps cut down the spam that include refences to websites. That kind of email usually has your email address embedded in it (in code) so that the spammer can just tell when it has reached a live destination. Use this method for a few months and your name will drop off many of the spam lists.

To move only the HTML based email over to the ‘Suspect’ folder, create a rule that looks like this (leave a comment if you want more details than what is shown here):

Apply this rule after the message arrives
through the YOURACCOUNT@HERE.COM account
  and with ‘multipart/alternative’ or ‘multipart/related’ in the message header
move it to the SOME FOLDER WITH PREVIEW PANE TURNED OFF HERE folder
  and stop processing more rules

If only the courts hadn’t elected George W. Bush…

Filed under: My Kind of Joke — Brian @ 8:59 am

Things would have been sooo much better…


The office of the President

(Clicking READ THE COMPLETE ARTICLE (if shown) will invoke a streaming video with sound…)
(more…)

May 12, 2006

Resizing JPEGS in Delphi to create Thumbnails for posting to the web

Filed under: Delphi — Brian @ 6:45 am

I thought I might post this example… It works really well with the Light box java script plugin for WordPress… It is a single file (DPR) Delphi console app that can be used in a batch file to resize jpegs to any percentage of the original size.

I use it with ZTree by tagging all of the JPegs I wish to resize and then hitting CTRL B. Ctrl B will create a batch file out of all of the tagged files with the command line that I enter. So the command line I use is “ResizeJPeg %4.%5″ and 10 seconds later, I have a large set of images and thumbnails I can post to the web.

BTW I use net drive to make drive X: be a my FTP directory. NetDrive is WONDERFUL!!! I dare say it is ALMOST as useful as ZTree…. Almost….

For those who have no care to be interested in compiling Delphi Source code, here is the EXE: ResizeJPEG.exe

DELPHI:
  1. // ****************************************************************************
  2. //  ResizeJPEG.DPR                                                 01/Jul/2004
  3. //  Written by Brian Layman (AKA Capt. Queeg)
  4. //  Visit him at http://www.TheCodeCave.com
  5. //
  6. //  This routine was written to help resize jpegs for posting to the web
  7. //
  8. //
  9. //  Warning: This routine opens your images and replaces files without
  10. //    warnings.  It is not ever supposed to edit your original image, but
  11. //    if something unexpected happens, you could lose some important images.
  12. //    Understand every line of this example before you run it.  Or better yet,
  13. //    do not run this example at all. You should stop right now and erase the
  14. //    files. For if it causes blue smoke to be emitted from your network card,
  15. //    if it erases all users from your computer, or if it makes your sister
  16. //    break up with her lawyer boyfriend and start dating a caver, it is
  17. //    not my fault.  (Actually that last one might be an improvement, but
  18. //    it is still not my fault.) But the fact of the manner is, anything
  19. //    could happen when you mess with the registry and this example IS,
  20. //    in all seriousness, dangerous.
  21. //
  22. //  Usage: ResizeJPEG.exe JPGNAME.JPG  <– Resizes the image to 10% of original
  23. //         ResizeJPEG.exe JPEGNAME 50  <– Resizes the image to 50% of original
  24. //
  25. //  License - If this helps you - Great! Use it, modify it share it.
  26. //
  27. //  Donations - If this project really helps you out, feel free to make a $5
  28. //    (US) token donation via Paypal to Brian@TheCodeCave.com or just leave a
  29. //    comment on my blog and include your country of origin.
  30. //
  31. //  History:
  32. //    01/Jul/2004 - BL - Created
  33. //
  34. // ****************************************************************************
  35. program ResizeJPEG;
  36.  
  37. uses
  38.   ExceptionLog,
  39.   Forms, Classes, JPEG, Graphics, SysUtils;
  40.  
  41. {$R *.RES}
  42.  
  43. {******************************************************************************
  44.   DoResize
  45.   This routine receives two JPEGs and the percentage (as a whole number) of
  46.   the original size.  It only does aspect ratio resizing.
  47.   The creation and freeing of the JPEGs must be done outside this routine.
  48.   srcJPEG must contain an image.  destJPEG’s contents will be overwritten.
  49.   Passing a zero or negative percentage will
  50. ******************************************************************************}
  51. procedure DoResize(srcJPEG, destJPEG: TJPEGImage; const Pct: Integer; BMPName: String = );
  52. var
  53.   Bitmap: TBitmap;
  54. begin // DoResize
  55.  
  56.   if (not(Assigned(srcJPEG) and Assigned(destJPEG)))
  57.   then raise Exception.Create(‘There has been a programming error.  ‘ +
  58.                               ‘The JPEG parameters passed to DoResize have not ‘ +
  59.                               ‘been initialized.’);
  60.  
  61.   // Error out if we don’t have a valid source image
  62.   if (srcJPEG.Empty)
  63.   then raise Exception.Create(‘The parameters passed cannot produce a valid image.  ‘ +
  64.                               ‘The source image is blank.’);
  65.  
  66.   // Error out if we don’t have a valid source image
  67.   if (Pct <= 0)
  68.   then raise Exception.Create(‘The parameters passed cannot produce a valid image.  ‘ +
  69.                               ‘The percentage (’ + IntToStr(Pct) + ‘%) is invalid.’);
  70.  
  71.   Bitmap := TBitmap.Create;
  72.   try
  73.     Bitmap.Width := Trunc(srcJPEG.Width * (PCT/100));
  74.     Bitmap.Height := Trunc(srcJPEG.Height * (PCT/100));
  75.     Bitmap.Canvas.StretchDraw(Bitmap.Canvas.ClipRect, srcJPEG);
  76.     destJPEG.Assign(Bitmap);
  77.     if (BMPName <> )
  78.     then Bitmap.SaveToFile(BMPName);
  79.   finally
  80.     Bitmap.Free;
  81.   end;
  82. end// DoResize
  83.  
  84. var
  85.   JPEGOrig, JPEGTemp: TJPEGImage;
  86.   ImgName, imgExt: String;
  87.   Percentage: Integer;
  88.   CreateBMP: Boolean;
  89. begin
  90.   Application.Initialize;
  91.   // Retreive first parameter and strip off any path info.
  92.   // That’s the file name.  This now includes the extension.
  93.   ImgName := LowerCase(ExtractFileName(ParamStr(1)));
  94.  
  95.   // Determine the extension
  96.   ImgExt := ExtractFileExt(ImgName);
  97.  
  98.   // If there is an extension, remove it from the file name.
  99.   // If there is no extension, assume ‘.jpg’ for now.
  100.   if (ImgExt <> )
  101.   then ImgName := copy(ImgName, 1, Length(ImgName) - Length(ImgExt))
  102.   else ImgExt := ‘.jpg’;
  103.  
  104.   // The third parameter is for the percentage of change.
  105.   // If not provided, it defaults to 10%
  106.   Percentage := StrToIntDef(ParamStr(2), 10);
  107.  
  108.   CreateBMP := Boolean(StrToIntDef(ParamStr(3), 0));
  109.  
  110.   // This if statement both verifies that the file is there and that it now has
  111.   // a .jpg or .jpeg extension.  If these conditions are not met, the program
  112.   // exits without an error.
  113.   if (FileExists(ImgName + ImgExt) and ((ImgExt = ‘.jpg’) or (ImgExt = ‘.jpeg’)))
  114.   then begin
  115.     // Create the object for manipulating the new image
  116.     JPEGTemp := TJPEGImage.Create;
  117.     try
  118.       // Create the object for storing the original image
  119.       JPEGOrig := TJPEGImage.Create;
  120.       try
  121.         // Load the original
  122.         JPEGOrig.LoadFromFile(ImgName + ImgExt);
  123.  
  124.         // Call the subroutine for resizing the original and putting it in the
  125.         // temporary object.
  126.         if (CreateBMP)
  127.         then DoResize( JPEGOrig, JPEGTemp, Percentage, ImgName + ‘_s.bmp’)
  128.         else DoResize( JPEGOrig, JPEGTemp, Percentage);
  129.  
  130.         // Save the new image with a "_s" tacked onto the file name.
  131.         JPEGTemp.SaveToFile(ImgName + ‘_s’ + ImgExt);
  132.       finally // try around JPEGOrig usage
  133.         // Free the original object
  134.         JPEGOrig.Free;
  135.       end// try around JPEGOrig usage
  136.     finally // try around JPEGTemp usage
  137.       // Free the new/temp object
  138.       JPEGTemp.Free;
  139.     end; // try around JPEGTemp usage
  140.   end; // if fileexists
  141. end.

May 11, 2006

Mountain Bike

Filed under: My Journal — Brian @ 9:36 am

Monday nights are my nights off. I can go wherever I want. Unfortunately that often doesn’t amount to much. But this week it actually meant getting outside and having some fun.

I finally got to go ride the West Branch State Park Mountain Bike Trail. It was a blast even if I am not quite up to that skill level yet.

All winter long it is maintained by CAMBA - the Cleveland Area Mountain Bike Association.
Cleveland Area Mountain Bike Association

They put in bridges and other challenges along the trail. I even met two of the officers that night, Brian Lennon, president, and Mike Ryba, Treasurer. Unfortunately I can’t remember the names of the other people they were riding with, not even the one from Puerto Rico, but they were all really nice people. All winter long their members maintain the trails.

I tried out the camera on my new phone and got some quarter decent shots (they definately weren’t half decent) while it was still light. However, the exposure time must be really high when it gets dim. You can see that as the envening goes on, the shots get blurier. When taking pictures in twilight with the phone, I will have to stabalize it. Holding it by hand just isn’t sufficient (plus chances are mid-workout I wasn’t all that stable anyway…)

The trail followed along the resevoir and was beautiful with the sun setting... Some bridges offered alternate easy routes.  My helmet had not made this trip, so I was conservative on this one... A stone bump trail to make life interesting... too blurry to make out though...

The CAMBA web site has a great map of the park, but it’s a 2.5mb 1 page PDF. I mananged to convert it to a 45K JPEG that hasn’t lost much detail. This is a little handier to keep on PDAs and what not…
The blue dotted trail is the one I followed...

I even got myself a couple of badges… This all was mostly from one very tall root near the beginning of the trail. It was an up hill section that I’d started in the wrong gear and the root required about a foot worth of travel to get up and over it, though the root itself was probably just under 6 inches high. Anyway, I decided to push it and try it anyway. The result was I was slumped against the tree with only my front wheel making it over. The scrape was from sliding backwards down the bark as I got my footing…(Kneeing actually I guess)

I'm proud of this one! This one is just annoying...

I’m proud of the skinned knee… I probably haven’t skinned my knee falling from a bicycle in 20 years… Boy that makes me sound old…. Anyway, it meant I was pushing limits again, which is what living is all about and when you stop doing that, that’s in large part why people grow old… I had a few more bumps and bruises. For instance my right arm is scraped simply because there wasn’t enough room for me to get through between the trees that were there… All part of the fun and I’m smilin’ as I type…

May 9, 2006

Cycle Man

Filed under: My Journal — Brian @ 3:33 pm

I had a wonderfully fun weekend. I was pit crew for my friend Tom Moyer. He came up to race and the Nelson Ledges racetrack. It’s a nice track but VERY bumpy. We had to do some structural reenforcement of his tachometer and fairing, but it went really well. He reported that turn 7 was interesting because of the washboard right before it. He said he hit that washboard at speed and thought he’d be dead when the corner came. But then it smoothed out.

My jobs were to help get the bike fueled with premix - measure the tire temp before and after the races to make sure the tires were heating up enough to be sticky during those corners and not so much that he’s flinging chunks of rubber all over the track.

Other than the cold weather combined with the sunburn, it was a very good day. BTW, Tom’s the yellow Yamaha RZ350 #262. It’s a two stroke and a blast to ride… (Yes, I speak from experience :) )

Here’s a couple videos:
Movie 1
Movie 2

Learn more: Tom races in the Mid-Atlantic Roadracing Club

Images:











And Tom certainly had some admirers at our house afterwards. He’s the apple of Caleb’s eye at the moment…



“CycleMan!”


« Older Posts

Powered by WordPress