Skip to content

Commit

Permalink
more files
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Oct 20, 2008
1 parent 8544857 commit c75ec83
Show file tree
Hide file tree
Showing 8 changed files with 1,878 additions and 0 deletions.
74 changes: 74 additions & 0 deletions app/controllers/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php





function put( &$vars ) {
extract( $vars );
if (!(get_profile_id()))
trigger_error( 'Sorry, the setting could not be saved', E_USER_ERROR );
$resource->update_from_post( $request );
header_status( '201 Created' );
redirect_to( $request->resource );
}


function post( &$vars ) {
extract( $vars );
if (!(get_profile_id()))
trigger_error( 'Sorry, the setting could not be saved', E_USER_ERROR );
$request->set_param( array( 'setting', 'profile_id' ), get_profile_id() );


if ($request->params['setting']['name'] == 'app') {

$do_install = false;

$app = trim($request->params['setting']['value']);

$sources = environment('remote_sources');
$remote_list = array();

foreach($sources as $name=>$url) {
$p = get_profile();
$url = "http://".$url."&p=".urlencode($p->profile_url)."&a=".urlencode($app);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec( $curl );
if ($result) {
if (trim($result) == 'install')
$do_install = true;
continue;
}
curl_close( $curl );
}

if (!$do_install)
trigger_error( 'Sorry, you are not authorized to install '.$app, E_USER_ERROR );

}
$resource->insert_from_post( $request );
header_status( '201 Created' );
redirect_to( $request->resource );
}



function delete( &$vars ) {
extract( $vars );
$s = $collection->MoveFirst();
if (!$s || $s->profile_id != get_profile_id())
trigger_error( 'Sorry, the setting could not be deleted', E_USER_ERROR );
$resource->delete_from_post( $request );
header_status( '200 OK' );
redirect_to( $request->resource );
}





?>
120 changes: 120 additions & 0 deletions app/plugins/sms_notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

global $request;

function mobile_event( &$vars ) {

$response = "Welcome to ".environment('site_title');

$header = array(
"Status: 200 OK",
"Date: ".gmdate(DATE_RFC822),
"Content-Type: text/plain",
"Content-Length: " . strval(strlen($response))
);

foreach ($header as $str)
header($str);

echo substr($response,0,100);

exit;

}

function mobile_settings( &$vars ) {
render( 'action', 'mobile' );
}

function _mobile( &$vars ) {

extract( $vars );
$foo = "";
return vars(
array(&$foo),
get_defined_vars()
);

}



after_filter( 'broadcast_sms_notice', 'insert_from_post' );

function broadcast_sms_notice( &$model, &$rec ) {

$smsurl = environment('zeepUrl');

if (empty($smsurl))
return;

if (!(isset($rec->title)))
return;

global $request, $db;

$i = get_profile();

$notice_content = substr($rec->title,0,100);

$sent_to = array();

$Subscription = $db->model('Subscription');

$Subscription->has_one( 'subscriber:identity' );

$where = array(
'subscriptions.subscribed'=>$i->id,
);

$Subscription->set_param( 'find_by', $where );

$Subscription->find();

while ($sub = $Subscription->MoveNext()) {

$sid = $sub->FirstChild('identities');

if (!in_array($sid->id,$sent_to) && $sub->sms) {

$sent_to[] = $sid->id;

$apiurl = environment('zeepUrl');

$secret = environment('zeepSecretKey');

$apikey = environment('zeepAccessKey');

$http_date = gmdate( DATE_RFC822 );

$parameters = "user_id=".$sid->id."&body=".urlencode($notice_content);

$canonical_string = $apikey . $http_date . $parameters;

$b64_mac = base64_encode(hash_hmac("sha1", $canonical_string, $secret, TRUE));

$authentication = "Zeep $apikey:$b64_mac";

$header = array(
"Authorization: ".$authentication,
"Date: ".$http_date,
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: " . strval(strlen($parameters))
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters );
$response = curl_exec($ch);
curl_close($ch);

}
}
}

?>

0 comments on commit c75ec83

Please sign in to comment.