Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [ADDON] Send Article URL to Friends  (Read 4760 times)

Zucye

  • Sr. Member
  • ****
  • Karma: 5
  • Posts: 347
    • Simplemente una Mujer
[ADDON] Send Article URL to Friends
« on: August 09, 2006, 04:31:45 pm »

This script will send the referring page (dynamic URL) to up to 10 persons.

If you want to see how it works, visit:
http://www.peterbustamante.com/diario/   (Spanish site)
Your will find a golden Button at the bottom that will take you to the PHP page (Just so you can give yourself an Idea of how it looks)

Your need 4 files and a link to the sendurl.php.
 
#1 File - A simple html as follows, named template.html:
Code: [Select]
<HTML><HEAD><TITLE>$title</TITLE></HEAD>
<BODY><CENTER>
$data
</CENTER></BODY></HTML>
#2 File - A simple text named emailMessage.txt:
Code: [Select]
Hi,
I thought you might like to check this out!
$url
#3 File - A footer named optionalfooter.txt:
Code: [Select]
From your friends at ....  :)#4 File - The sendurl.php as follows:
Code: [Select]
<?php
/* By Mauricio Rousseau */
$thisprog "sendurl.php";
$template "template.html"// must be valid!
$people "10"// number of people user can recommend page to at a time
$fontface "Verdana"// font style
$fontsize "8"// size in points! (pt); NOT html sizes, a decent size is between 8-14
$fontcolor "#663300";
$maxlength "45"// maximum length of string displayed url will be before adding "..." before it
$messagefile "emailMessage.txt"// Text to be send inside the email
$mes_footer_file "optionalfooter.txt"// Text optional at the end of email
$subject "A page from YourSite"// change this to your default subject
$changesub "n"// allow users to change the "subject" of the email
$requirerefer "y"// y or n
$validservers "YourSite.com";  // Please change to your site
$uselog "n"// want to enable log recording so that you may view a log of recommendations? ***REQUIRES mySQL!***
// IF YOU WANTED TO ENABLE LOG RECORDING THEM THE FOLLOWING PARAMETERS ALSO MUST BE SET
$truepassword "pbl"// password you will use in url query string to access log data
// MYSQL REQUIRED PARAMETERS
$GLOBALS['sqlhost'] = 'localhost';
$GLOBALS['sqluser'] = 'username';
$GLOBALS['sqlpass'] = 'password';
$GLOBALS['sqldbnm'] = 'database_name';

// ZUE, NOTHING BELOW THIS LINE NEEDS TO BE MODIFIED
///////////////////////////////////////////////
$validemail "/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/";
$program 'Tu-Refugio.com'// do not change
$data .= "<FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\">\n<BLOCKQUOTE><BIG><B>" " </B></BIG> \$title<P>\n\n";
$footer get_footer();
if (
$_GET['action'] == 'log' && $_GET['password'] == $truepassword)
{
$title "Log";
mysql_connect ($GLOBALS['sqlhost'], $GLOBALS['sqluser'], $GLOBALS['sqlpass']);
mysql_select_db ($GLOBALS['sqldbnm']);
$data .= "attempting to read from mySQL database...<P>\n";
$query "SELECT * FROM `recommend_log` ORDER BY `time` DESC";
if ($result mysql_query($query))
{
$data .= "<CENTER><TABLE CELLSPACING=0 CELLPADDING=3 BORDER=1>";
$total mysql_num_rows($result);
while ($logrow mysql_fetch_array($result))
{
$logrow['message'] = str_replace("\n","<BR>",$logrow['message']);
$newtime date("g:ia d M. Y",$logrow['time']);
$data .= "<TR><TD><FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\"><B>From:</B><BR>" $logrow['name'] . "\n<BR>\n" $logrow['email'];
$data .= "\n<BR>\n" $logrow['ip'] . "<P>\n<B>To:</B>\n<BR>\n" $logrow['to'] . "<P>\n";
$data .= "<B>Time:</B>\n<BR>\n" $newtime "</FONT></TD><TD>";
$data .= "<FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\"><B>" $logrow['subject'] . "</B><P>" $logrow['message'] . "</TD>";
}
$data .= "</TABLE></CENTER><P>SUCCESSFULLY READ LOG DATA (<B>$total</B> records!)!<P>\n";
}
else
{
$createq "CREATE TABLE `recommend_log` (
`time` INT( 15 ) NOT NULL ,
`name` TEXT NOT NULL ,
`email` TEXT NOT NULL ,
`subject` TEXT NOT NULL ,
`message` MEDIUMTEXT NOT NULL ,
`to` TEXT NOT NULL ,
`ip` TEXT NOT NULL 
);"
;
if ($createres mysql_query($createq))
{
$data .= "FAILED TO READ DATA; SUCCESSFULLY CREATED NEW TABLE IN DATABASE!<P>\n";
}
else
{
$data .= "FAILED TO READ OR CREATE FROM mySQL DATABASE!<P>\n";
}
}
}

if (
$footer == '' || !ereg("www.Tu-Refugio.com",$footer) || !ereg("$program",$footer) || !ereg("Tu-Refugio.com",$footer))
{
header("Location: http://www.Tu-Refugio.com/footer.php");
exit;
}
if (
$_POST['process'] && $_POST['url'] && $_POST['name'] != '' && preg_match($validemail,$_POST['email']))
{
$title "<h1>Share Page / Article</h1>";
if ($requirerefer == 'y')
{
$validarray explode(",",$validservers);
foreach ($validarray as $valid)
{
if (ereg($valid,$_POST['url']))
{
$serverisvalid 'y';
}
}
}
if ($serverisvalid != 'y' && $requirerefer == 'y') {$data .= "THIS SERVER IS NOT PERMITTED TO BE RECOMMENDED!";}
elseif ($serverisvalid == 'y' || $serverisvalid == '')
{
$headers "MIME-Version: 1.0\r\n";
$headers .= "From: " $_POST['name'] . " <" $_POST['email'] . ">\r\n";
$headers .= "Reply-to: " $_POST['name'] . " <" $_POST['email'] . ">\r\n";
if (file_exists($mes_footer_file))
{
$fh fopen ($mes_footer_file,"r");
$eml_footer_data fread($fh,filesize($mes_footer_file));
fclose ($fh);
}
if ($_POST['subject'] != '')
{
$subjecttouse $_POST['subject'];
}
else
{
$subjecttouse $GLOBALS['subject'];
}
$emailedusers '0';
for ($i=1;$i <= $people;$i++)
{
if (preg_match($validemail,$_POST["email$i"]))
{
$emailedusers++;
stripslashes($_POST['message']);
if ($eml_footer_data != '')
{
$newmessage $_POST['message'] . "\n\n" $eml_footer_data;
}
else
{
$newmessage $_POST['message'];
}
mail ($_POST["email$i"],$subjecttouse,$newmessage,$headers);
if ($uselog == 'y') {$query log_to_db ($_POST["email$i"]);}
$data .= "Page was sent to <I>" $_POST["email$i"] . "</I> Successfully!\n<BR><BR>\n";
$data .= "Thank you for sending one of our pages!\n<BR><BR>\n";
$data .= "<input type=button value='Click Here!' onClick='history.go(-2)'>, to go back to the article you just sent.\n";
}
}
if ($emailedusers == '0') {$data .= "ˇYou need to include at least 1 email to send page!\n<BR>\n";}
}
$data .= "<P>";
}


elseif (
$_GET['action'] == '')
{
$title "<h1>Share Page / Article</h1>";
if ($_GET['url'] != '')
{
$url $_GET['url'];
$url str_replace("~!Q!~","?",$url);
$url str_replace("~!AMP!~","&",$url);
}
elseif ($_POST['url'] != '')
{
$url $_POST['url'];
}
elseif ($_SERVER['HTTP_REFERER'] != '')
{
$url $_SERVER['HTTP_REFERER'];
}
else
{
$url "http://" $_SERVER['SERVER_NAME'];
}
if ($length strlen($url) > $maxlength)
{
$start strlen($url) - $maxlength;
$end strlen($url);
$url2 "..." substr($url,$start,$end);
}
else
{
$url2 $url;
}
if ($_POST['message'] == '')
{
$fh fopen($messagefile,"r");
$message fread ($fh,filesize($messagefile));
fclose ($fh);
$message str_replace('$url',$url,$message);
}
else
{
$message $_POST['message'];
}
if ($_POST['name'] == '' || !preg_match($validemail,$_POST['email']))
{
$data .= "\n<I>Please include <B>your name & e-Mail</B>.  Otherwise you will be send back to this page</I>\n<P>\n";
}
$data .= "<FORM ACTION=$thisprog METHOD=POST>\n";
$data .= "<TABLE>\n";
$data .= "<INPUT TYPE=HIDDEN NAME=process VALUE=y><INPUT TYPE=HIDDEN NAME=url VALUE=\"" $url "\">\n";
$data .= "<TR><TD><FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\"><B>Your Name:</B></FONT></TD><TD><INPUT TYPE=TEXT NAME=name SIZE=30 VALUE=\"" $_POST['name'] . "\" STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;\"></TD></TR>\n";
$data .= "<TR><TD><FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\"><B>Your e-Mail</B></FONT></TD><TD><INPUT TYPE=TEXT NAME=email SIZE=30 VALUE=\"" $_POST['email'] . "\" STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;\"></TD></TR>\n";
$data .= "<TR><TD><FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\"><B>Page to Share:</B></FONT></TD><TD><FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\"><I>$url2</I></FONT></TD></TR>\n";
if ($changesub == 'y')
{
if ($_POST['subject'] != '')
{
$subval $_POST['subject'];
}
else
{
$subval $subject;
}
$data .= "<TR><TD><FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\"><B>subject:</B></FONT></TD><TD><INPUT TYPE=TEXT NAME=subject VALUE=\"$subval\" SIZE=30 STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;\"></TD></TR>\n";
}
$data .= "<TR><TD><FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\"><B>Message:</B></FONT></TD><TD><TEXTAREA ROWS=10 COLS=35 NAME=\"message\" STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;\">$message</TEXTAREA></TD></TR>\n";
for ($i=1;$i <= $people;$i++)
{
$data .= "<TR><TD><FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;COLOR:$fontcolor;\"><B>e-Mail $i:</B></FONT></TD><TD><INPUT TYPE=TEXT NAME=email$i SIZE=30 VALUE=\"" $_POST["email$i"] . "\" STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;\"></TD></TR>\n";
}
$data .= "</TABLE>\n<P>\n";
$data .= "<INPUT TYPE=SUBMIT VALUE=\"Click to Send Page\" STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize"pt;FONT-WEIGHT:bold;\">\n</FORM>\n";
}


$data .= "\n<FONT SIZE=1>$footer</FONT></BLOCKQUOTE>\n";
if (!
ereg($footer,$data))
{
header ("Location: http://www.Tu-Refugio.com/footer.php");
exit;
}
$data str_replace('$title',$title,$data);
printpage($title,$data,"");

function 
get_footer ()
{
$data "\n\n<P><FONT STYLE=\"FONT-FAMILY:" $GLOBALS['fontface'] . ";FONT-SIZE:" . ($GLOBALS['fontsize'] - 0) . "pt;COLOR:" $GLOBALS['fontcolor'] . ";\"><A HREF=\"http://www.Tu-Refugio.com\" STYLE=\"color:$GLOBALS[fontcolor]\" TARGET=\"_top\">" $GLOBALS['program'] . "</A> - Copyright 2006 - All rights reserved.</SMALL>";
return $data;
}
function 
log_to_db ($email)
{
$time time();
if ($_POST['subject'] != '')
{
$subjecttouse $_POST['subject'];
}
else
{
$subjecttouse $GLOBALS['subject'];
}
mysql_connect ($GLOBALS['sqlhost'], $GLOBALS['sqluser'], $GLOBALS['sqlpass']);
mysql_select_db ($GLOBALS['sqldbnm']);
$query "INSERT INTO `recommend_log` (`time`,`name`,`email`,`subject`,`message`,`to`,`ip`) VALUES ('$time', '" $_POST['name'];
$query .= "', '" $_POST['email'] . "', '" $subjecttouse "', '" $_POST['message'] . "', '$email', '";
$query .= $_SERVER['REMOTE_ADDR'] . "');";
if (mysql_query($query)) {return "SUCCESSFUL TO LOG";} else {return "FAILED TO LOG";}
}

function 
printpage ($title,$data,$meta)
{
$newtitle $GLOBALS['program'] . " -> " $title;
$fh fopen ($GLOBALS['template'],"r");
$template fread($fh,filesize($GLOBALS['template']));
fclose ($fh);
$newdata str_replace('$title',$newtitle,$template);
$newdata str_replace('$meta',$meta,$newdata);
$newdata str_replace('$data',$data,$newdata);
echo $newdata;
}
?>
Link to sendurl.php:
Code: [Select]
<A HREF=http://www.domain.com/sendurl.php>Send URL to Friends</A>Hope It can be of Help to someone.  Don't forget to change the variables in the sendurl.php

Note:  This script was coded for my site by a friend I don't know how to code php!
« Last Edit: November 08, 2007, 02:38:04 pm by Keyrocks »
Logged
We can always learn from our failures, not so much from obvious success - C. Robinson (W. Disney). :)

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[ADDON] Send Article URL to Friends
« Reply #1 on: August 09, 2006, 04:42:20 pm »

zucye, please introduce your friend and make a note somewhere in your code
/* created by .... */

personal note: your friend is our friend :)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Zucye

  • Sr. Member
  • ****
  • Karma: 5
  • Posts: 347
    • Simplemente una Mujer
[ADDON] Send Article URL to Friends
« Reply #2 on: August 09, 2006, 05:16:00 pm »

No problem!

Quote
/* By Mauricio Rousseau */
Done! ;)
Logged
We can always learn from our failures, not so much from obvious success - C. Robinson (W. Disney). :)

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
[ADDON] Send Article URL to Friends
« Reply #3 on: August 09, 2006, 11:06:37 pm »

another nice solution and a handy addon..you guys are working hard today..thanks a lot for sharing this..wicked! :D
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D