Created
January 15, 2012 22:28
-
-
Save axwax/1617749 to your computer and use it in GitHub Desktop.
FrontlineSMS to WordPress Posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: FrontlineSMS-Posts | |
* Plugin URI: https://gist.github.com/1617749 | |
* Description: Plugin to create WordPress post from Frontline SMS, based on a plugin by Kaka E. Prakasa ( https://github.com/pr4ka5a/wp-frontlinesms_posts/ ) | |
* Author: AxWax | |
* Version: 0.1 | |
* Author URI: http://axwax.de | |
*/ | |
// create unique key when installing plugin | |
function frontlinesms_posts_install() | |
{ | |
add_option( 'frontlinesms_posts_key', generateRandomString(8)); | |
} | |
register_activation_hook(__FILE__,'frontlinesms_posts_install'); | |
// settings page | |
function frontlinesms_posts_options() | |
{ | |
echo "Set up an <b>External Command</b> for your keyword, select <b>HTTP request and paste the following string into the Command field:<br/><b>http://" . $_SERVER['HTTP_HOST'] . "/index.php?s=\${sender_number}&m=\${message_content}&k=" . get_option('frontlinesms_posts_key') . " </b>"; | |
} | |
// create submenu of settings menu | |
function frontlinesms_posts_admin_menu() | |
{ | |
add_options_page('FrontlineSMS Posts','FrontlineSMS Posts','manage_options','FrontlineSMS-Posts','frontlinesms_posts_options'); | |
} | |
add_action('admin_menu', 'frontlinesms_posts_admin_menu'); | |
//Retrieve post from FrontlineSMS | |
function frontline_post($args) | |
{ | |
if (isset($_SERVER['QUERY_STRING'])) | |
{ | |
// set default values | |
$default = array ( | |
's' => '', | |
'm' => '', | |
'k' => '' | |
); | |
$dt = date("Y-m-d H:i:s"); | |
// parse query string | |
$args = wp_parse_args( $args, $default); | |
extract( $args, EXTR_SKIP); | |
if(!empty($s) AND !empty($m) AND !empty($k)) | |
{ | |
if($k == get_option('frontlinesms_posts_key')) | |
{ | |
// create post | |
$gmt_date=$dt; | |
$post = array( | |
'post_content' => $m, | |
'post_status' => 'draft', | |
'post_date_gmt' => $gmt_date, | |
'post_date' => get_date_from_gmt( $gmt_date ), | |
'post_author' => 1, | |
'post_title' => $m | |
); | |
$post_id = wp_insert_post( $post ); | |
} | |
} | |
} | |
} | |
frontline_post($_SERVER['QUERY_STRING']); | |
function generateRandomString($length) | |
{ | |
$result = ''; | |
$num = rand(0,26); | |
$result .= substr(md5(microtime()),$num,$length); | |
return $result; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment