Pagegangster logo

Share your stand alone publication

December 4, 2008

Today I wrote a small PHP script you can put on your webserver, point your stand alone package to it and have the share functionality re-enabled. This is a first draft, and you’re very welcome to suggest improvements, or send a altered version back to me at rb (at) pagegangster.com. You’re also very welcome to port it to other programming languages, we would love to put it in our product.

To get it you can download the script, or a complete example of the stand alone which contains the share script. I haven’t put a working example available on a webserver as it just works as when the publication is hosted on our server. The rest of this entry I use on explaining how to use the script and how to make improvements. I’ll assume you have your stand alone hosted on an environment that supports PHP.

So, open the share.php file in your favorite editor and take a look at the first section, looking something like this:

$subject = "[FROM_NAME] have sent you a publication";
 
$body = "Hi,
 
We sent you a publication you might want to take a look at:
 
    [LINK]
 
[FROM_NAME] has the following comment:
 
    [MESSAGE]
 
[FROM_NAME]";
 
/*
 * The url that will be sent out in the script, set this to the link you
 * want the user to see.
 *
 * Example: http://www.example.com/path/to/publication/
 */
$publication_url = "";
 
/* Name used in emails from field */
$from_name = "someone";
 
/* From email */
$from_email = "example@example.com";
 
/*
 * Set to true if you want to allow a custom from email, otherwise the
 * variables set above will be used as from.
 */
$allow_custom_from = true;

There are a few things to mention here. First, the mail is sent in plain text. This is partly done because doing custom mime handling is mind-numming boring and to limit the package dependencies. If you really need to send HTML emails you should have a look at something like Mail Mime from Pear. And now to the settings. Generally speaking, strings containing structures like “[NAME]” and “[LINK]” are placeholders and should not be directly manipulated. Don’t rewrite [LINK], simply put the value in the correct variable. Otherwise features will behave strangely or not at all:

  • $subject: Should not require the longest explaintion. Whatever you write here will result in the subject of the mail. [FROM_NAME] will be replaced by the senders name.
  • $body: The body part of the mail. [FROM_NAME] will behave like in the subject, [LINK] is the link to your publication. Remember to use this as the script will add information like the page the sharer want to tell the sharee about. [MESSAGE] contains the message to the user.
  • $publication_url is the base url of where you have put your publication
  • $allow_custom_from determines how the from header of the emails looks. If you set this variable to true, the senders name and email will be used to generate the header. Otherwise the variables below are used
  • $from_name: The name to insert in the from header. Only used if $allow_custom_from is set to false.
  • $from_email: The email to insert in the from header. Only used if $allow_custom_from is set to false.

That’s the basics. A little heads up if you purchased a stand alone package before this blog post. Your index.html will not contain the javascript it needs to open the publication at a specific page. Open the file and delete this line:

so.addVariable("firstPageToLoad", firstPage);

and insert this:

// Put this just below the //VARIABLES comment
var firstPage;
 
try {
	firstPage = parseInt(window.location.hash.substr(1));
} catch (e) {};
 
if (!firstPage) {
	firstPage = 1;
}
 
// Put this together with lines like it
so.addVariable("firstPageToLoad", firstPage);

This should get you up and running. Happy sharing.

No comments yet.

Give us your comment

Name (*):
Mail (will not be published) (*):
Homepage URL:
Comment (*)