96 lines
5.4 KiB
PHP
96 lines
5.4 KiB
PHP
<?php
|
|
ini_set("display_errors", "off");
|
|
ini_set("log_errors", "on");
|
|
ini_set('error_log', dirname(__FILE__) . '/log.log');
|
|
|
|
$config = include 'config.php';
|
|
|
|
// launch by bookmarklet
|
|
if (isset($_GET['v'])) {
|
|
header("Content-type: text/javascript");
|
|
$email = isset($_GET['m']) ? $_GET['m'] : '';
|
|
$url = isset($_GET['u']) ? $_GET['u'] : '';
|
|
$title = isset($_GET['t']) ? $_GET['t'] : '';
|
|
$version = isset($_GET['v']) ? $_GET['v'] : '';
|
|
$xpath = isset($_GET['q']) ? $_GET['q'] : '';
|
|
$filtered_email = filter_var($email, FILTER_VALIDATE_EMAIL);
|
|
$filtered_version = filter_var($version, FILTER_VALIDATE_INT);
|
|
$filtered_url = filter_var($url, FILTER_VALIDATE_URL);
|
|
if ($filtered_email !== false && $filtered_version !== false && $filtered_url !== false) {
|
|
$content = '';
|
|
$f = $xpath != '' ? @DomDocument::loadHTMLFile($url) : false;
|
|
if ($f) {
|
|
$xp = new DomXPath($f);
|
|
$content = $xp->query($xpath) != false ? $f->saveXML($xp->query($xpath)->item(0)) : '';
|
|
}
|
|
|
|
$body = "\n" . $title;
|
|
$body .= "\nLink => " . $url;
|
|
$body .= "\n" . $content;
|
|
$body .= "\nThanks for using our service.";
|
|
$body .= "\n\nShikiryu";
|
|
$body .= "\n\nAny complain or advise? http://shikiryu.com/contact/";
|
|
include 'phpmailer.php';
|
|
try {
|
|
$mail = new PHPMailer(true);
|
|
$mail->setFrom($config['from_email'], $config['from_name']);
|
|
$mail->Subject = 'A new article to read : ' . $title;
|
|
$mail->addAddress($email);
|
|
if (!empty($config['bcc'])) {
|
|
$mail->addBCC($config['bcc']);
|
|
}
|
|
if ($xpath == '')
|
|
$mail->Body = $body;
|
|
else
|
|
$mail->Body = '<hr/>' . nl2br($body) . '<hr/>';
|
|
if ($mail->send()) {
|
|
echo 'alert("Email Sent.");';
|
|
} else {
|
|
echo ':(';
|
|
}
|
|
} catch (phpmailerException $et) {
|
|
echo 'alert("Error from sendmail :(");';
|
|
exit;
|
|
} catch (Exception $ep) {
|
|
echo 'alert("Email from SMTP :(");';
|
|
exit;
|
|
}
|
|
|
|
} else {
|
|
if ($filtered_email === false) {
|
|
echo 'alert("Invalid Email");';
|
|
}
|
|
if ($filtered_version === false) {
|
|
echo 'alert("Invalid Version");';
|
|
}
|
|
if ($filtered_url === false) {
|
|
echo 'alert("Invalid URL");';
|
|
}
|
|
}
|
|
} else if (isset($_POST['email'])) {
|
|
$filtered_email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
|
|
if ($filtered_email !== false) {
|
|
if ($_POST['html'] == 'on') { // bookmarklet pour l'envoi en HTML
|
|
$include = '<a href="javascript:void((function(){if(typeof(jQuery)!=\'function\'){var%20n=document.createElement(\'script\');n.setAttribute(\'src\',\'//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js\');document.getElementsByTagName(\'head\')[0].appendChild(n);}function%20v(){if(typeof(jQuery)==\'function\'){clearInterval(i);c();}}var%20i=window.setInterval(v,100);function%20c(){q=\'\';function%20gx(el){el=el.get(0);xp=\'\';for(;el&&el.nodeType==1;el=el.parentNode){id=jQuery(el.parentNode).children(el.tagName).index(el)+1;id>1?(id=\'[\'+id+\']\'):(id=\'\');xp=\'/\'+el.tagName.toLowerCase()+id+xp;}return%20xp;}jQuery(\'*\').bind(\'mouseenter\',function(){jQuery(\'*\').removeClass(\'shikihover\');jQuery(\'*\').css(\'border\',\'\');jQuery(this).css(\'border\',\'3px%20solid%20yellow\');jQuery(this).addClass(\'shikihover\');});jQuery(\'.shikihover\').live(\'click\',function(){jQuery(\'*\').unbind(\'mouseenter\').removeClass(\'shikihover\');jQuery(this).css(\'border\',\'\');var%20q=\'&q=\'+gx(jQuery(this)),d=document,t=d.title,f=\'//' . $_SERVER['HTTP_HOST'] . substr($_SERVER[PHP_SELF], 0, -9) . '\',m=\'' . $_POST['email'] . '\',l=d.location,e=encodeURIComponent,p=\'?v=1&u=\'+e(l.href)+\'&t=\'+e(t)+\'&m=\'+e(m),u=f+p+q;newScript=d.createElement(\'script\');newScript.type=\'text/javascript\';newScript.src=u;d.body.appendChild(newScript);});}})())">Bookmark by email</a>';
|
|
} else { // bookmarklet pour l'envoi normal
|
|
$include = "<a href='javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,t=d.title,f=\"//" . $_SERVER['HTTP_HOST'] . substr($_SERVER[PHP_SELF], 0, -9) . "\",m=\"" . $_POST['email'] . "\",l=d.location,e=encodeURIComponent,p=\"?v=1&u=\"+e(l.href)%20+\"&t=\"+e(t)%20+\"&m=\"+e(m),u=f+p;var%20newScript%20=%20document.createElement(\"script\");newScript.type=\"text/javascript\";newScript.src=u;document.body.appendChild(newScript);void(0)'>Bookmark by email</a>";
|
|
}
|
|
|
|
//ADDING STATS
|
|
include "XMLSQL.php";
|
|
$stats = new XMLSQL('emails.xml');
|
|
$stats->insert(array('ip' => getenv('REMOTE_ADDR'), 'date' => date('d/m/Y'), 'email' => $_POST['email']))->into('emails')->query();
|
|
|
|
} else {
|
|
$include = '<p class="error">Invalid email. Please <a href="javascript:history.go(-1);">go back</a></p>';
|
|
}
|
|
include 'template.php';
|
|
|
|
} else {
|
|
$include = '<form name="bookmarkletGenerator" action="" method="POST">
|
|
<input type="email" name="email" id="email" value="" placeholder="email@example.com" /><input type="checkbox" id="html" value="on" name="html" /><label for="html">html?</label>
|
|
<input type="submit" value="Generate!" id="submit"/></form>';
|
|
include 'template.php';
|
|
|
|
}
|