Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
CJ Webmaster Forums Forum Index -> PHP Scripts » CJ Send Page

   
Modified Send Page v2 pop-up
View previous topic :: View next topic  
Author Message
stk



Joined: 30 Apr 2005
Posts: 4

Posted: Sun May 01, 2005 3:05 pm    Post subject: Modified Send Page v2 pop-up

As I mentioned in this post, I wanted to modify the existing code to do some more things.

In an attempt to comply with PHPDUMMY's request, this is the starting point:
  • Send Page Version modified: CJ Send Page v2.0 (PopUp)
  • Tested in PHP Version: 4.3.10
  • HTML Pages: Un-validated, tables (as original).

Improvements/Changes:
  • Only 1 file needed, instead of 3 ('config' & 'style' moved into 'friend')
  • Added option to email webmaster each time Send Page is used ($notify_webmaster)
  • Error messages display inside form fields
  • CSS stylesheets moved to HTML <head> area
  • Minor HTML page formatting changes


Installation is pretty much identical to the regular install notes (which are very nice, btw). Succinctly: Insert the <script> in the <head> area, define a link (php, ssi or html), then edit & upload friend.php. (The regular install notes covers each step in sufficient detail).

Modified Code:

Code:
<?
//--- CONFIGURATION Variables Edit as necessary or desired ------------------------------------------------//

$auto_responder ="yes";
$notify_webmaster = "yes";
$url="http://www.yoursite.com";
$admin_mail="yourmail@wherever.com";
$title="Send Link to Friend";
$your_website = "Kimler's Adventure Page";
$thankyousubject="Copy of Forwarded Link";

//--- Customize the stylesheets to match your site design --------------------------------------------------//
      // (CSS is between the <style type="text/css"> and </style> tags near the bottom of the file)

//--- Form Titles - Edit if desired ------------------------------------------------------------------------//

$yourname="Your Name";
$yourmail="Your E-mail";
$recipientmail="Recipient's E-mail";
$yourmessage="Your Message (optional)";

//--- More things to fiddle with ---------------------------------------------------------------------------//

$submitbutton="Send to Friend!";
$suggest_exp="Please fill the form below to send this link to a friend...";   
$send_subject = "You might be interested in this...";
$thankyoumessage="For your records, here is a copy of your successfully forwarded link:\n$link \n\nthat you sent to: $friend_mail. \n\nThanks. \n\n-Scott";

//--- End of Config ----------------------------------------------------------------------------------------//
//include("config.php");

if(!isset($_GET['js']) || $_GET['js'] == ""){
   $link = $url.$_GET['id'];
   //$link = $_GET['id'];  // for b2evo permalink (url already in there)
}
else if($_GET['js'] == "on"){
   $link = $_GET['id'];
}

$link = str_replace(" ","+", $link); // get rid of spaces

if(!isset($_POST['action']) || $_POST['action'] == ""){
   if(!isset($link)){
      print "No Link Specified";
   }
   else{
      printpage("","","","","","","","");
   }
}
else if($_POST['action'] == "submit"){

   $send = true;

   function is_valid_email($sender_mail) {
      if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $sender_mail)) {
         return 0;
       }
      else{
         return 1;
       }
   }
   
   $sender_mail = $_POST['sender_mail'];
   $friend_mail = $_POST['friend_mail'];
   $sender_name = $_POST['sender_name'];
   $opt_msg = $_POST['opt_msg'];
   $link = $_POST['link'];
   $js = $_POST['js'];
   $id = $_POST['id'];

   $s_emailvalid = is_valid_email($sender_mail);  // check email
   $f_emailvalid = is_valid_email($friend_mail);  // check email

   $errs = "There are Problems";

   if ($sender_name == "" || $sender_name == "A Name is Required"){
      $errName= "A Name is Required";
      $send = false;
   }
   if ($sender_mail == "" || $s_emailvalid == 1){
      $errSmail= "Enter your valid email";
      $send = false;
   }
   if ($friend_mail == "" || $f_emailvalid == 1){
      $errFmail= "Enter a friends valid email";
      $send = false;
   }

   if($send){      
      $recipient = "$friend_mail";
      $message .= "$sender_name wanted to share the following link with you:\n$link\n\n";
      if($opt_msg != ""){
         $message .= "Along with the following:\n\n-------------------- \r\n".$opt_msg."\n-------------------- \r\n\n";
      }
      $message .= "Powered by: Send Page V2.0 - http://www.cj-design.com";
      $headers = "From: $sender_name <$sender_mail>\r\nReply-To: $sender_mail\r\n";
      mail ($recipient, $send_subject, $message, $headers);

      if($auto_responder == "yes"){
         $recipient2 = "$sender_name <$sender_mail>";
         $subject2 = "$thankyousubject";
         $message2 = "$thankyoumessage\n\n$your_website\n$admin_mail\n\n Note: This is an automated response, no need to reply\n";
         $message2 .= "Powered by: Send Page V2.0 - http://www.cj-design.com";
         $headers2 = "From: $your_website <$admin_mail>\r\nReply-To: $admin_mail\r\n";
         mail ($recipient2, $subject2, $message2, $headers2);
      }
      /* ------------------------------------------- *
       * Added by stk to send mail to webmaster
       * each time someone uses this tool.
       * 4/30/05 - stk http://randsco.com
       * ------------------------------------------- */
      
      if($notify_webmaster == "yes") {
        $ip = getenv("REMOTE_ADDR");
        $recipient1 = "$admin_mail";
         $subject1 = "Website Link Sent";
         $message1 .= "$sender_name ($sender_mail, $ip) sent $recipient the following link:\n$link\n";
                     if ($opt_msg != ""){
                       $message1 .= "Along with this message:\n\n$opt_msg";
                        } else {
                        $message1 .= "$sender_name didn't include an optional message.";
                        }
         $headers1 = "From: $sender_name <$sender_mail>\r\nReply-To: $admin_mail\r\n";
         mail ($recipient1, $subject1, $message1, $headers1);
      }
      /* ------ end stk's webmaster mail ---------- */
      
      printthanks($sender_name,$friend_mail,$link);
      exit;
   }
   else if(!$send){
       printpage($sender_name,$sender_mail,$friend_mail,$opt_msg,$errs,$errName,$errSmail,$errFmail);
   }
}
else{
   printpage("","","","","","","","");
}

function printpage($sender_name,$sender_mail,$friend_mail,$opt_msg,$errs,$errName,$errSmail,$errFmail){
global $sender_name,$sender_mail,$friend_mail,$opt_msg,$errs,$errName,$errSmail,$errFmail,
       $link,$id,$js,$errors,$title,$suggest_exp,$yourname,$yourmail,$recipientmail,$yourmessage,$submitbutton;
//include("config.php");

      ?>

<html>
<head>
<META NAME="Title" CONTENT="<? echo $title; ?>">
<META NAME="Author" CONTENT="James Crooke - CJ Web Design">
<title>Send <? echo $link; ?> to a friend!</title>
<style type="text/css">

/*---------------------------------------------------*/
/* CSS Page #1 of 2                                  */
/* edit below to customize 'Send a Link' Pop-Up Page */
/* stk http://randsco.com  1-May-2005                */
/*---------------------------------------------------*/

body {
  font-family:verdana,sans-serif;
   color:#000;
   font-size:10pt;
   scrollbar-base-color:#eee;
   scrollbar-arrow-color:#666 ;
   }
table {
  width:600px;
  margin:10px auto;
  border:1px solid #000;
   padding:10px;
   background:#f6f6f6;
   }
td {
  font-family:verdana,sans-serif;
   color:#000;
   font-size:10pt;
   }
input {
  border:1px solid #000;
  font-family:verdana,sans-serif;
   font-size:10pt;
   color:#000;
   background:#eee;
   padding:0 5px;
   }
textarea {
  font-family:verdana,sans-serif;
   font-size:10pt;
   color:#000;
  border:1px solid #000;
  background:#eee;
   padding:5px;
   }
span#errTitle {
  color:red;
   font-size:14pt;
   }
input.err {
  padding:0 5px;
   color:red;
   font-weight:bold;
   }
span#title {
  font-size:14pt;
   font-weight:bold;
   }
/*---------------------------*/
/* end style editing #1 of 2 */
/*---------------------------*/
</style>
</head>
<body>

<form method="post" action="friend.php">
  <input type="hidden" name="link" value="<? echo $link; ?>">
  <input type="hidden" name="id" value="<? echo $id; ?>">
  <input type="hidden" name="js" value="<? echo $js; ?>">
  <input type="hidden" name="action" value="submit">
  <table cellspacing="0" cellpadding="5">
    <tr>
      <td colspan="2" width="625"><span id="title"><? echo $title; ?></span>
         <span id="errTitle"><? if ($errs!="") { echo ' ('.$errs.')'; } ?></span></td>
    </tr>
    <tr>
      <td colspan="2" width="625"><? echo $suggest_exp; ?><br /><small><? echo $link; ?></small></td>
    </tr>
    <tr>
      <td width="232"><? echo $yourname; ?> </td>
         <? if ($errName=="") {
      echo '<td width="381"><input type="text" value="'.$sender_name.'" name="sender_name" size="40"></td>';
         } else {
         echo '<td width="381"><input class="err" type="text" value="'.$errName.'" name="sender_name" size="40"></td>';
         } ?>
    </tr>
    <tr>
      <td width="232"><? echo $yourmail; ?></td>
        <? if ($errSmail=="") {
      echo '<td width="381"><input type="text" value="'.$sender_mail.'" name="sender_mail" size="40"></td>';
         } else {
         echo '<td width="381"><input class="err" type="text" value="'.$errSmail.'" name="sender_mail" size="40"></td>';
         } ?>
      </tr>
    <tr>
      <td width="232"><? echo $recipientmail; ?></td>
         <? if ($errFmail=="") {
      echo '<td width="381"><input type="text" value="'.$friend_mail.'" name="friend_mail" size="40"></td>';
         } else {
         echo '<td width="381"><input class="err" type="text" value="'.$errFmail.'" name="friend_mail" size="40"></td>';
         } ?>
      </tr>
    <tr>
      <td width="232"><? echo $yourmessage; ?></td>
      <td width="381"><textarea name="opt_msg" type="text" cols="45" rows="8"><? echo $opt_msg; ?></textarea></td>
    </tr>
    <tr>
      <td width="232"> </td>
      <td width="381">
        <div>
          <input type="submit" name="submit" value="<? echo $submitbutton; ?>">
        </div>
      </td>
    </tr>
  </table>
</form>

</body>
</html>


<?


}

function printthanks($sender_name,$friend_mail,$link){
global $sender_name,$friend_mail,$link;
//include("config.php");
   ?>

<html>
<head>
<META NAME="Title" CONTENT="<? echo $title; ?>">
<META NAME="Author" CONTENT="James Crooke - CJ Web Design">
<title>Thanks for sending <? echo $link; ?> to a friend!</title>
<style type="text/css">

/*---------------------------------------------------*/
/* CSS Page #1 of 2                                  */
/* edit below to customize 'Send a Link' Pop-Up Page */
/* stk http://randsco.com  1-May-2005                */
/*---------------------------------------------------*/

body {
  font-family:verdana,sans-serif;
   color:#000;
   font-size:10pt;
   scrollbar-base-color:#eee;
   scrollbar-arrow-color:#666 ;
   }
div#thanks {
  margin:15px auto;
  width:600px;
   height:380px;
   border:1px solid black;
   background:#f6f6f6;
   }
div#thanks p {
  margin-top:40px;
  font-family:georgia,times,serif;
   font-size:16pt;
   font-weight:bold;
   color:#aaa;
   text-align:center;
   }
span#big {
  font-size:36pt;
   }
span#link {
  font-family:arial,sans-serif;
   font-size:8pt;
   font-weight:normal;
   color:#666;
   }
form {
  text-align:center;
   }
input {
  font-family:verdana,sans-serif;
   font-size:10pt;
   border:1px solid #000;
   background:#eee;
   }
/*---------------------------*/
/* end style editing #1 of 2 */
/*---------------------------*/
</style>
</head>
<body>
<div id="thanks">
<p><span id="big">** success **<br /><br /></span>
Thank you<br />
<? echo $sender_name; ?><br />
I'm glad you liked:<br />
<span id="link"><? echo $link; ?></span> <br />
enough to send it to a friend.</p>

<form>
<input type="button" value="Close Window" onClick="window.close()">
</form>


</body>
</html>

<?

}

?>


All you need to do is cut-'n-paste this code into a file named "friend.php" and then edit to customize it to your site.

You can see this modified code in action on our website. Our install is specific to b2evolution, so there are some link differences (which I've commented out, just after the config stuff at the top). I plan on writing up a b2evo-specific "how-to" post on our website, which I'll come back and link, when it's finished. I'll likely change the tables design to DIVs and validate each pop-up in XHTML-strict & change the design to customize it more for our site ... but the working guts are here & you should be able to take off from here.

Hope ppl find this of value. I make no warranty or claim, just thought others *might* like the one-file/webmaster thing. Your smileage may vary.

Thanks again for providing a GREAT starting point!

Cheers,
-stk

This is what the pop-up page looks like:


And the error messages if someone types nothing:


Last edited by stk on Thu Nov 24, 2005 7:53 pm; edited 3 times in total
Back to top
darkcarnival
CJ-Design.com Admin



Joined: 10 Jul 2003
Posts: 1267
Location: Michigan

Posted: Sun May 01, 2005 3:41 pm    Post subject:

hmm very good dude

i think ill sticky this.
_________________
List of Mods to James Scripts!
http://www.cj-design.com/forum/viewtopic.php?t=1798

Elite Bulletin Board v0.5 help test it for me:
http://www.elite-board.z42.us/
Back to top
PHPDUMMY
CJ-Design.com Moderator



Joined: 09 Mar 2005
Posts: 534
Location: South East Kentucky,U.S.A.

Posted: Mon May 02, 2005 1:58 am    Post subject:

Further Building Block Suggestions;

Pt.1

$errs = "There are Problems";

Add an option for
For advanced users which may want to supress errors generated which in some instances will give a malicious user unnecessarily needed , direct file path locations.......

Pt.2

/* ------------------------------------------- *
* Added by stk to send mail to webmaster
* each time someone uses this tool.
* 4/30/05 - stk http://randsco.com
* ------------------------------------------- */

if($notify_webmaster == "yes") {
$ip = getenv("REMOTE_ADDR");
$recipient1 = "$admin_mail";
$subject1 = "Website Link Sent";
$message1 .= "$sender_name ($sender_mail, $ip) sent $recipient the following link:\n$link\n";
if ($opt_msg != ""){
$message1 .= "Along with this message:\n\n$opt_msg";
} else {
$message1 .= "$sender_name didn't include an optional message.";
}
$headers1 = "From: $sender_name <$sender_mail>\r\nReply-To: $admin_mail\r\n";
mail ($recipient1, $subject1, $message1, $headers1);
}
/* ------ end stk's webmaster mail ---------- */

[A]

There is a flaw dealing with LocalHost {127.0.0.1} in the 'REMOTE_ADDR' . There is further information dealing with this as well as examples on how to correct it at the php web-site , it may be advised to further this portion of the code in an effort to deture malicious users trying to access the LocalHost of a web-site to try and gain entry.

[B]

Some countries are malicious in general and some web-masters may wish to block the Country IP Block from the use of this portion of the site. This would be an excellent Add-On feature . Again , there is more information on dealing with this as well as code samples at the php web-site.

{}

Very clean , I like the code.
_________________
Cheers,
Danny
C-J Search Engine All Tidied Up V4.0http://www.cj-design.com/forum/viewtopic.php?t=1820

C-J Search Engine MySQL !http://www.cj-design.com/forum/viewtopic.php?t=1555
Back to top
James
CJ-Design.com Admin



Joined: 08 Nov 2002
Posts: 798
Location: UK

Posted: Fri May 06, 2005 10:10 am    Post subject:

Good job mate, wish I had the time to improve my own scripts, lol.

BTW guys, I'm working on this: www.geekshirts.co.uk/directory - call that the uber alpha before christ version. Should be good once i find some time to finish it.

The whole idea behind it is to be search engine friendly (note the page URLs which actually use the apache rewrite engine, i.e those folders don't actually exist). It is also dynamic, so no building required - changes are instant. It has a customisable template with simple includes like [%category-list%] and [%search-box%].

All in all, should piss on existing directory scripts, even Dmoz.

Think i'll probably release a free version and a pro version for 5/10 or something with loads more features.

Still thinking about that one...
_________________
CJ Website Design Developer
Web Design - http://www.cj-design.com
Web Hosting - http://www.cj-hosting.com
Back to top
darkcarnival
CJ-Design.com Admin



Joined: 10 Jul 2003
Posts: 1267
Location: Michigan

Posted: Fri May 06, 2005 11:03 pm    Post subject:

looks good dude

cant wait to see it running fully
_________________
List of Mods to James Scripts!
http://www.cj-design.com/forum/viewtopic.php?t=1798

Elite Bulletin Board v0.5 help test it for me:
http://www.elite-board.z42.us/
Back to top
Display posts from previous:   
       CJ Webmaster Forums Forum Index -> PHP Scripts » CJ Send Page All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group
iCGstation v1.0 Template By Ray © 2003, 2004 iOptional, Mods by CJ Website Design