Hey all-
Just wrote this quick script which takes in a blog title, url, anchor text, and an article, breaks up the article into pieces, adds a link using the url and anchor text, and emails it to Blogger to be posted.
Feel free to use it or give me shit.
Just wrote this quick script which takes in a blog title, url, anchor text, and an article, breaks up the article into pieces, adds a link using the url and anchor text, and emails it to Blogger to be posted.
Feel free to use it or give me shit.
Code:
<?
// username and password to log into script
$conf[adminuser] = "blogrocker";
$conf[adminpass] = "ohmyshit";
// authenticate administrator
if ((![URL="http://www.php.net/isset"]isset[/URL]($_SERVER['PHP_AUTH_USER'])) || (![URL="http://www.php.net/isset"]isset[/URL]($_SERVER['PHP_AUTH_PW'])) || ($_SERVER['PHP_AUTH_USER'] != $conf[adminuser]) || ($_SERVER['PHP_AUTH_PW'] != $conf[adminpass])) {
[URL="http://www.php.net/header"]header[/URL]('WWW-Authenticate: Basic realm="BlogRocker"');
[URL="http://www.php.net/header"]header[/URL]("HTTP/1.1 401 Unauthorized");
[URL="http://www.php.net/print"]print[/URL] "This page requires authorization.";
[URL="http://www.php.net/exit"]exit[/URL]();
}
// blog post by e-mail addresses; add as many blogs and email addresses as you want
$blog = [URL="http://www.php.net/array"]array[/URL]();
$blog[0] = "myblog@myblog.com";
$blog[1] = "myblog@myblog.net";
$blog[2] = "myblog@myblog.org";
$a = $_GET['a'];
if ($a == "") {
$html = "
<form method='post' action='blogrocker.php?a=sendthatbitch'>"
."
<table>"
."
<tr>
<td>Post Title:
<input type='text' size='60' name='title'></td>
</tr>
"
."
<tr>
<td>URL:
<input type='text' size='60' name='url'></td>
</tr>
"
."
<tr>
<td>Anchor Text (comma delimited):
<input type='text' size='60' name='anchor'></td>
</tr>
"
."
<tr>
<td>Text:<textarea name='text' rows='20' cols='80'></textarea></td>
</tr>
"
."
<tr>
<td>
<input type='submit' value='Rock those blogs!'></td>
</tr>
"
."</table>
"
."</form>
";
}
if ($a == "sendthatbitch") {
$title = $_POST['title'];
$url = $_POST['url'];
$anchors = [URL="http://www.php.net/explode"]explode[/URL](',', $_POST['anchor']);
$text = [URL="http://www.php.net/strip_tags"]strip_tags[/URL]($_POST['text']);
$length = [URL="http://www.php.net/strlen"]strlen[/URL]($text);
// turn one article into a bunch of articles
$i = 0;
$j = 1;
$sub_art = [URL="http://www.php.net/array"]array[/URL]();
while ($i <= $length) {
$end = 500 * $j;
$sub_art[$j] = [URL="http://www.php.net/substr"]substr[/URL]($text, $i, $end);
$i = $i + 500;
$j++;
}
// use the url and anchor text to build links
$link = [URL="http://www.php.net/array"]array[/URL]();
$i = 0;
foreach($anchors as $anchor) {
$link[$i] = "<a href='" . $url . "' title='" . $anchor . "'>" . $anchor . "</a>";
$i++;
}
// Heavy lifting: pick a sub article, combine it with a link, and send it to the blogs
$html = "Blogs updated: ";
foreach($blog as $send) {
$subart_num = [URL="http://www.php.net/array_rand"]array_rand[/URL]($sub_art);
$link_num = [URL="http://www.php.net/array_rand"]array_rand[/URL]($link);
$post = $sub_art[$subart_num] . "... " . $link[$link_num];
[URL="http://www.php.net/mail"]mail[/URL]($send, $title, $post, "MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\nFrom: MFE <email@mcfarlanenterprises.com>\r\nX-Mailer: PHP/" . [URL="http://www.php.net/phpversion"]phpversion[/URL]());
$html = $html . "<br/>$send";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>BlogRocker</title>
<style type='text/css'>
body {
background: #e0e0e0;
}
td {
font-size: 10pt;
font-weight: bold;
}
</style>
</head>
<body>
<? [URL="http://www.php.net/echo"]echo[/URL] $html; ?>
</body>
</html>