Saturday, September 12, 2009

Starting another script

I have a PHP script that customers would use to start a process. The process was time-intensive, so I had it start another script in the background. It was important that the customer did not have to wait until the long process ended. After trying a few things, I found a forum that gave me my solution (sorry, can't find where it is anymore). This starts a PHP script in the background from within another PHP script:
shell_exec('php /public_html/accountname/longProcess.php > /dev/null 2>/dev/null &');

Simply replace the script name with our own and it should work (note: not sure if the whole path is required). What this does is force the standard output and error output to be discarded and the final ampersand causes it all to be run in the background.

Tuesday, September 8, 2009

TinyMCE Spell Checking

In my last post I talked about the HTML/Rich-Text editor called TinyMCE. I have used it on a few sites for content management. Well, today I've learned of a plug-in for TinyMCE that is very promising.

This plug-in is a spell and grammar checker called After the Deadline. It is free for personal use, and from some of my limited tests it appears to be very powerful. I read on TechCrunch that it was recently acquired by WordPress co-founder Matt Mullenweg and is already enabled for users on their platform.

Need a spell checker? Check it out: http://www.afterthedeadline.com/

Thursday, September 3, 2009

Text Area to HTML Editor

TinyMCE is my visual HTML editor of choice (a.k.a. What You See Is What You Get or WYSIWYG). I use it on a number of websites to allow customers to update content without needing to take a class on HTML and CSS. It has worked pretty good for me thus far and best of all, its free.

One particular feature that I've recently discovered has made me pretty happy. TinyMCE allows me to supply a list of URLs for TinyMCE to make available when a user wishes to insert a hyper link. This is a beautiful thing. Before the user had to copy and paste every URL they wanted to link to.

Just as cool is that I can also supply a list of images and videos that can easily be inserted (no copying and pasting these URLs either). So after uploading an image to the server, they can edit a webpage and TinyMCE already has this image's URL ready if it is to be used.

In order to do all this, at the end of my TinyMCE initialization script I added these three lines:

<script type="text/javascript">
tinyMCE.init({
...
external_link_list_url : "/tiny_mce/links.php",
external_image_list_url : "/tiny_mce/images.php",
media_external_list_url : "/tiny_mce/media.php"
});
</script>

Now, on the other side of these specified URLs I have a PHP script that rounds up every URL (or image or video) on the server and provides it in a JSON encoded list for TinyMCE. This way, when a user wants to insert a link (or image or video), TinyMCE already has a good list of links that the user can choose from.

Let's assume, for the PHP example script, that you have a 2D PHP array called $linkOptions that had every link the user might want to use. Here is a part of links.php, specified above:

<?PHP
header("Content-type: application/javascript");

echo "var tinyMCELinkList = new Array( \n\t";

$firstLink = true;
for ($j = 0; $j < sizeof($linkOptions); $j++) {
// Go through each link of the array
if ($firstLink) {
echo "\n\t"; // No comma for the 1st
$firstLink = false;
} else echo ",\n\t";

echo '['. htmlentities($linkOptions[$j][0]); // Link Name
echo '","'. htmlentities($linkOptions[$j][1]) .'"]'; // Link URL
}

echo "\n".');'; // All done

Then, you would need to do replicate something like this for each of the link lists specified. Hope you find this feature as useful as I. Good luck!

PS. TinyMCE is also the HTML editor used for WordPress.