Created
October 11, 2010 15:45
-
-
Save dkobia/620739 to your computer and use it in GitHub Desktop.
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 defined('SYSPATH') or die('No direct script access.'); | |
/** | |
* Clickatell HTTP GET Controller | |
* Acts as the HTTP callback for Clickatell | |
* | |
* PHP version 5 | |
* LICENSE: This source file is subject to LGPL license | |
* that is available through the world-wide-web at the following URI: | |
* http://www.gnu.org/copyleft/lesser.html | |
* @author Ushahidi Team <[email protected]> | |
* @package Ushahidi - http://source.ushahididev.com | |
* @module Clickatell Controller | |
* @copyright Ushahidi - http://www.ushahidi.com | |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL) | |
*/ | |
class Clickatell_Controller extends Controller | |
{ | |
function index() | |
{ | |
if (isset($_GET['key'])) { | |
$frontlinesms_key = $_GET['key']; | |
} | |
if (isset($_GET['from'])) { | |
$message_from = $_GET['from']; | |
// Remove non-numeric characters from string | |
$message_from = preg_replace("#[^0-9]#", "", $message_from); | |
} | |
if (isset($_GET['text'])) { | |
$message_description = $_GET['text']; | |
} | |
//Filters to allow modification of the values from the SMS gateway | |
Event::run('ushahidi_filter.message_from',$message_from); | |
Event::run('ushahidi_filter.message_description', | |
$message_description); | |
Event::run('ushahidi_filter.message_key',$frontlinesms_key); | |
if (!empty($frontlinesms_key) | |
&& !empty($message_from) | |
&& !empty($message_description)) | |
{ | |
// Is this a valid FrontlineSMS Key? | |
$keycheck = ORM::factory('settings', 1) | |
->where('frontlinesms_key', $frontlinesms_key) | |
->find(); | |
if ($keycheck->loaded == TRUE) | |
{ | |
$services = new Service_Model(); | |
$service = $services->where('service_name', 'SMS')->find(); | |
if (!$service) | |
return; | |
$reporter = ORM::factory('reporter') | |
->where('service_id', $service->id) | |
->where('service_account', $message_from) | |
->find(); | |
if (!$reporter->loaded == TRUE) | |
{ | |
// get default reporter level (Untrusted) | |
$level = ORM::factory('level') | |
->where('level_weight', 0) | |
->find(); | |
$reporter->service_id = $service->id; | |
$reporter->level_id = $level->id; | |
$reporter->service_userid = null; | |
$reporter->service_account = $message_from; | |
$reporter->reporter_first = null; | |
$reporter->reporter_last = null; | |
$reporter->reporter_email = null; | |
$reporter->reporter_phone = null; | |
$reporter->reporter_ip = null; | |
$reporter->reporter_date = date('Y-m-d'); | |
$reporter->save(); | |
} | |
// Save Message | |
$message = new Message_Model(); | |
$message->parent_id = 0; | |
$message->incident_id = 0; | |
$message->user_id = 0; | |
$message->reporter_id = $reporter->id; | |
$message->message_from = $message_from; | |
$message->message_to = null; | |
$message->message = $message_description; | |
$message->message_type = 1; // Inbox | |
$message->message_date = date("Y-m-d H:i:s",time()); | |
$message->service_messageid = null; | |
$message->save(); | |
// Notify Admin Of New Email Message | |
$send = notifications::notify_admins( | |
"[".Kohana::config('settings.site_name')."] ". | |
Kohana::lang('notifications.admin_new_sms.subject'), | |
Kohana::lang('notifications.admin_new_sms.message') | |
); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment