Skip to content

Commit

Permalink
api control panel
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Apr 4, 2009
1 parent 1aeecf6 commit a3e5121
Show file tree
Hide file tree
Showing 42 changed files with 996 additions and 321 deletions.
6 changes: 5 additions & 1 deletion app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ env:
site_subtitle:
site_description:

theme: prologue-theme
theme: p2

email_from: root@localhost
email_name: Notifier
Expand Down Expand Up @@ -75,8 +75,12 @@ env:
- themepack1
- all_in_one_seo_pack
- notifixious
- apps
- password

installed:
- apps
- password

boot: omb

Expand Down
4 changes: 3 additions & 1 deletion app/identica/models/Dent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Dent extends Model {

function Dent() {

$this->set_param('table','dents');

// data dictionary
$this->auto_field( 'id' );
$this->char_field( 'tw_id' );
Expand All @@ -17,7 +19,7 @@ function Dent() {
$this->set_primary_key( 'id' );

// permissions for this resource
$this->let_read( 'all:always' );
$this->let_read( 'all:everyone' );

}

Expand Down
12 changes: 5 additions & 7 deletions app/omb/controllers/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function post( &$vars ) {
extract( $vars );
$Category->insert_from_post( $request );
header( 'Status: 201 Created' );
redirect_to( 'categories' );
redirect_to( $request->url_for('admin').'#ui-tabs-9' );
}

function delete( &$vars ) {
Expand All @@ -42,7 +42,7 @@ function delete( &$vars ) {
$result = $db->delete_record($rec);

header( 'Status: 200 OK' );
redirect_to( 'categories' );
redirect_to( $request->url_for('admin').'#ui-tabs-9' );
}

function index( &$vars ) {
Expand Down Expand Up @@ -114,19 +114,17 @@ function _remove( &$vars ) {


function _new( &$vars ) {

// bring controller vars into scope
extract( $vars );

if ( $request->error )
$Category = session_restore( $db->models['categories'] );
else
$Category = $Category->find( $request->id );



return vars(
array(

// return vars to the _new partial
&$Category,
),
Expand Down
63 changes: 50 additions & 13 deletions app/omb/controllers/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function put( &$vars ) {
$g = $Group->find($request->id);

if ($g && count($subscribers) > 0)
$result = $db->get_result( "DELETE FROM memberships WHERE group_id = ".$g->id );
$result = $db->get_result( "DELETE FROM ".$db->prefix."memberships WHERE group_id = ".$g->id );

foreach ( $subscribers as $addr ) {
$p = false;
Expand Down Expand Up @@ -57,20 +57,22 @@ function put( &$vars ) {

header( 'Status: 200 OK' );
redirect_to( 'groups' );

}



function do_invite_email($addr,$token, &$group) {

global $request;
$link = $request->url_for(array('resource'=>'posts','id'=>86,'ident'=>$token));

$subject = 'You are invited to join a private group on '.$request->base;
$link = $request->url_for(array('ident'=>$token));

$subject = 'You were added to a group on '.$request->base;

$email = "You are invited to join a private group on ".$request->base.", just follow the link to claim your invite.\n\n";
$email = "Hi, you have been invited to join the ".$group->name." group on ".$request->base.".\n\n";

$email .= "Redeem invite by clicking --> $link \n\n";
$email .= "Click here to check it out --> $link \n\n";


$html = false;
Expand Down Expand Up @@ -140,7 +142,7 @@ function delete( &$vars ) {
if ($e) {
$g = $Group->find($e->record_id);
if ($g)
$result = $db->get_result( "DELETE FROM memberships WHERE group_id = ".$g->id );
$result = $db->get_result( "DELETE FROM ".$db->prefix."memberships WHERE group_id = ".$g->id );
}
$Group->delete_from_post( $request );
header( 'Status: 200 OK' );
Expand All @@ -149,13 +151,15 @@ function delete( &$vars ) {

function index( &$vars ) {
extract( $vars );
$theme = '';
$theme = environment('theme');
$blocks = environment('blocks');
$atomfeed = $request->feed_url();
return vars(
array(
&$blocks,
&$profile,
&$atomfeed,
&$collection,
&$atomfeed,
&$theme
),
get_defined_vars()
Expand All @@ -164,6 +168,7 @@ function index( &$vars ) {




function _index( &$vars ) {

extract( $vars );
Expand Down Expand Up @@ -194,10 +199,13 @@ function _entry( &$vars ) {
$Membership = $Member->FirstChild( "memberships" );

$Entry = $Member->FirstChild( "entries" );





return vars(
array(

// return vars to the _entry partial
&$Member,
&$Membership,
Expand Down Expand Up @@ -253,19 +261,48 @@ function _edit( &$vars ) {
$Member = $Group->find( $request->id );

$Entry = $Member->FirstChild( "entries" );


if (empty($Entry->etag)) {
$Member->set_etag();
$Member = $Group->find( $request->id );
$Entry = $Member->FirstChild( "entries" );
}

$subscribers = "";
$arr = resource_group_members($Member->id);
$avatars = array();
foreach ( $arr as $member_ident ) {
$subscribers .= htmlentities($member_ident->email_value)."\n";
$avatars[$member_ident->id] = $member_ident->avatar;
}


// custom controller adds $group_perms named variable

$group_perms = array();

foreach ( $db->models as $model ) {
foreach( $model->access_list as $permission=>$values ) {
foreach($values as $fieldname=>$listofgroups) {
if (in_array($Member->name,$listofgroups)) {
if (!(is_array($group_perms[$model->table])))
$group_perms[$model->table] = array();
if (empty($model->table))
admin_alert( "table name not set for object ".get_class($model) );
$group_perms[$model->table][$permission] = $values;
break;
}
}
}
}

return vars(
array(

// return vars to the _edit partial
&$avatars,
&$Member,
&$Entry,
&$group_perms, // << I added this one to the standard list
&$subscribers

),
Expand Down
90 changes: 60 additions & 30 deletions app/omb/controllers/identities.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,38 +127,49 @@ function post( &$vars ) {
function put( &$vars ) {
extract( $vars );

$nick = strtolower($request->params['identity']['nickname']);

$request->set_param( array( 'identity', 'nickname' ), $nick );

if ($profile->nickname == $nick) {
// nickname did not change
if (isset($request->params['identity']['nickname'])) {
$nick = strtolower($request->params['identity']['nickname']);

$request->set_param( array( 'identity', 'nickname' ), $nick );

if ($profile->nickname == $nick) {
// nickname did not change
} else {
global $prefix;
// if post_notice is set it's a remote user and can share a nickname with a local user
$sql = "SELECT nickname FROM ".$prefix."identities WHERE nickname LIKE '".$db->escape_string($nick)."' AND (post_notice = '' OR post_notice IS NULL)";
$result = $db->get_result( $sql );
if ($db->num_rows($result) > 0)
trigger_error( 'Sorry, that nickname is already being used.', E_USER_ERROR );
}

} else {
// if post_notice is set it's a remote user and can share a nickname with a local user
$sql = "SELECT nickname FROM identities WHERE nickname LIKE '".$db->escape_string($nick)."' AND (post_notice = '' OR post_notice IS NULL)";
$result = $db->get_result( $sql );
if ($db->num_rows($result) > 0)
trigger_error( 'Sorry, that nickname is already being used.', E_USER_ERROR );

}

if (isset($request->params['identity']['url'])) {
if (strpos($request->params['identity']['url'], 'http') === false)
$request->params['identity']['url'] = 'http://'.$request->params['identity']['url'];
}

if (strpos($request->params['identity']['url'], 'http') === false)
$request->params['identity']['url'] = 'http://'.$request->params['identity']['url'];
if (isset($request->params['identity']['password']))
$request->params['identity']['password'] = md5($request->params['identity']['password']);

$resource->update_from_post( $request );

$rec = $Identity->find($request->id);

$sql = "SELECT photo FROM identities WHERE id = ".$db->escape_string($request->id);
$result = $db->get_result($sql);

if ($blobval = $db->result_value($result,0,"photo"))
$rec->set_value( 'avatar', $request->url_for(array('resource'=>"_".$rec->id)) . ".jpg" );
else
$rec->set_value( 'avatar', '' );

$rec->set_value( 'profile', $request->url_for(array('resource'=>"_".$rec->id)));
$rec->set_value( 'profile_url', $request->url_for(array('resource'=>"".$rec->nickname)));
$rec->save_changes();
if (is_upload('identities','photo')) {
$sql = "SELECT photo FROM ".$prefix."identities WHERE id = ".$db->escape_string($request->id);
$result = $db->get_result($sql);
if ($blobval = $db->result_value($result,0,"photo"))
$rec->set_value( 'avatar', $request->url_for(array('resource'=>"_".$rec->id)) . ".jpg" );
else
$rec->set_value( 'avatar', '' );
$rec->set_value( 'profile', $request->url_for(array('resource'=>"_".$rec->id)));
$rec->set_value( 'profile_url', $request->url_for(array('resource'=>"".$rec->nickname)));
$rec->save_changes();
}

broadcast_omb_profile_update();

Expand Down Expand Up @@ -259,6 +270,22 @@ function _new( &$vars ) {
);
}

function _pass( &$vars ) {
extract( $vars );
$Member = $collection->MoveFirst();
$Entry = $Member->FirstChild( 'entries' );
$identity_tz_options = array(
'PST',
'MST',
'CST',
'EST'
);
return vars(
array( &$Member, &$Entry, &$profile, &$identity_tz_options ),
get_defined_vars()
);
}


function _edit( &$vars ) {
extract( $vars );
Expand All @@ -282,6 +309,9 @@ function _admin( &$vars ) {
trigger_before( 'admin_menu', $current_user, $current_user );
$menuitems = array();
$apps_list = array();
global $env;
if (is_array($env['apps']))
$apps_list = $env['apps'];
$i = $Identity->find(get_profile_id());
while ($s = $i->NextChild('settings')){
$s = $Setting->find($s->id);
Expand All @@ -292,17 +322,17 @@ function _admin( &$vars ) {
'resource'=>'identities',
'id'=>get_profile_id(),
'action'=>'edit'
)).'/partial'] = 'Profile';
)).'/partial'] = 'Settings';
$menuitems[$request->url_for(array(
'resource'=>'identities',
'id'=>get_profile_id(),
'action'=>'subs'
)).'/partial'] = 'Friends';
$menuitems[$request->url_for(array(
'resource'=>'identities',
'id'=>get_profile_id(),
'action'=>'apps'
)).'/partial'] = 'Apps';
//$menuitems[$request->url_for(array(
// 'resource'=>'identities',
// 'id'=>get_profile_id(),
// 'action'=>'apps'
// )).'/partial'] = 'Apps';
foreach ($submenu as $arr) {
if (in_array($arr[0][0],$apps_list))
$menuitems[$arr[0][4]] = $arr[0][3];
Expand Down
2 changes: 1 addition & 1 deletion app/omb/models/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Aggregate() {

// permissions

$this->let_read( 'all:always' );
$this->let_read( 'all:everyone' );

$this->let_access( 'all:administrators' );

Expand Down
2 changes: 1 addition & 1 deletion app/omb/models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Category() {

// permissions

$this->let_read( 'all:always' );
$this->let_read( 'all:everyone' );

$this->let_access( 'all:administrators' );

Expand Down
2 changes: 1 addition & 1 deletion app/omb/models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function Event() {

// permissions

$this->let_read( 'all:always' );
$this->let_read( 'all:everyone' );
$this->let_access( 'all:administrators' );

$this->set_hidden();
Expand Down
2 changes: 1 addition & 1 deletion app/omb/models/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function Identity() {
$this->let_read( 'all:edit' );
$this->let_read( 'all:apps' );
$this->let_read( 'all:subs' );

$this->let_read( 'all:pass' );

// groups

Expand Down
2 changes: 1 addition & 1 deletion app/omb/models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Page() {

// permissions

$this->let_read( 'all:always' );
$this->let_read( 'all:everyone' );

$this->let_access( 'all:administrators' );

Expand Down

0 comments on commit a3e5121

Please sign in to comment.