Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Building out privacy checks for page.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchisari authored and The Appleseed Project committed Oct 21, 2010
1 parent b11ed36 commit 91a9a7f
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 13 deletions.
2 changes: 1 addition & 1 deletion components/example/controllers/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function Display ( $pView = null, $pData = null ) {
*/

// This query fails because it has nothing to do with our database structure.
$this->Customers->Retrieve ( $criteria, "fifth DESC", array ( "start" => 1500, "step", 100 ) );
$this->Customers->Retrieve ( $criteria, "fifth DESC", array ( "start" => 1500, "step" => 100 ) );

/*
* @tutorial You can also retrieve saved session data.
Expand Down
1 change: 0 additions & 1 deletion components/friends/friends.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,5 @@ public function Friends ( $pData = null ) {
}

return ( $return );

}
}
53 changes: 44 additions & 9 deletions components/page/controllers/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
class cPagePageController extends cController {

var $Type = array();

/**
* Constructor
*
Expand All @@ -32,7 +34,7 @@ public function __construct ( ) {
public function Display ( $pView = null, $pData = array ( ) ) {

$this->View = $this->GetView ( $pView );
$this->Model = $this->GetModel ();
$this->References = $this->GetModel ( 'References' );

$this->_Focus = $this->Talk ( 'User', 'Focus' );
$this->_Current = $this->Talk ( 'User', 'Current' );
Expand All @@ -58,7 +60,7 @@ public function Display ( $pView = null, $pData = array ( ) ) {

private function _Prep ( ) {

$this->Model->RetrievePagePosts ( $this->_Focus->Id );
$this->References->RetrieveReferences ( $this->_Focus->Id );
$this->View->Find ( '[name=Context]', 0 )->value = $this->Get ( 'Context' );

$privacyData = array ( 'start' => $start, 'step' => $step, 'total' => $total, 'link' => $link );
Expand All @@ -76,22 +78,27 @@ private function _Prep ( ) {
$Editor = false;
if ( $this->_CheckEditor() ) $Editor = true;

while ( $this->Model->Fetch() ) {
while ( $this->References->Fetch() ) {
$Type = $this->References->Get ( 'Type' );
$Identifier = $this->References->Get ( 'Identifier' );

if (!$Item = $this->_ReferenceByType ( $Type, $Identifier ) ) continue;

$row = new cHTML ();
$row->Load ( $rowOriginal );

$row->Find ( '.stamp', 0 )->innertext = $this->GetSys ( 'Date' )->Format ( $this->Model->Get ( 'Stamp' ) );
$row->Find ( '.content', 0 )->innertext = $this->Model->Get ( 'Content' );
$row->Find ( '.owner-link', 0 )->rel = $this->Model->Get ( 'Owner' );
$row->Find ( '.owner-link', 0 )->innertext = $this->Model->Get ( 'Owner' );
$row->Find ( '.stamp', 0 )->innertext = $this->GetSys ( 'Date' )->Format ( $this->References->Get ( 'Stamp' ) );
$row->Find ( '.content', 0 )->innertext = $Item['Comment'];
$row->Find ( '.owner-link', 0 )->rel = $Item['Owner'];
$row->Find ( '.owner-link', 0 )->innertext = $Item['Owner'];
if ( !$Editor ) $row->Find ( '.delete', 0 )->innertext = '';

list ( $username, $domain ) = explode ( '@', $this->Model->Get ( 'Owner' ) );
list ( $username, $domain ) = explode ( '@', $Item['Owner'] );
$data = array ( 'username' => $username, 'domain' => $domain, 'width' => 64, 'height' => 64 );
$row->Find ( '.owner-icon', 0 )->src = $this->GetSys ( 'Event' )->Trigger ( 'On', 'User', 'Icon', $data );

$row->Find ( '[name=Context]', 0 )->value = $this->Get ( 'Context' );
$row->Find ( '[name=Identifier]', 0 )->value = $this->Model->Get ( 'Identifier' );
$row->Find ( '[name=Identifier]', 0 )->value = $Identifier;

$row->Find ( '.delete', 0 )->action = $this->GetSys ( "Router" )->Get ( "Base" );

Expand Down Expand Up @@ -160,4 +167,32 @@ public function Remove ( $pData = null ) {
exit;
}

private function _ReferenceByType ( $pType, $pIdentifier ) {
if ( !$this->Types ) $this->Types = $this->_ReferenceTypes ( );

$pType = strtolower ( $pType );

$pointer = $this->Types[$pType];
$data = array ( 'Identifier' => $pIdentifier, 'Account' => $this->_Current->Account );
$return = $this->GetSys ( 'Components' )->Talk ( $pointer->Component, $pointer->Function, $data );

return ( $return );
}

private function _ReferenceTypes ( ) {

$components = $this->GetSys ( 'Components' );
$componentList = $components->Get ( 'Config' )->Get ( 'Components' );

foreach ( $componentList as $c => $component ) {
if ( !$types = $components->Talk ( $component, 'RegisterPageType' ) ) continue;
if ( !is_array ( $types ) ) continue;
$this->Types = array_merge ( (array)$this->Types, $types );
}

$this->Types = array_change_key_case ( $this->Types, CASE_LOWER );

return ( $this->Types );
}

}
13 changes: 13 additions & 0 deletions components/page/models/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ public function RetrievePagePosts ( $pUserId ) {
return ( true );
}

public function RetrievePost ( $pUserId, $pIdentifier ) {

$criteria = array ('User_FK' => $pUserId, 'Identifier' => $pIdentifier );

$this->Retrieve ( $criteria );

if ( $this->Get ( "Total" ) == 0) return ( false );

$this->Fetch();

return ( $this->Get ( "Data" ) );
}

public function Post ( $pComment, $pPrivacy, $pUserId, $pOwner, $pCurrent = false ) {

$Identifier = $this->CreateUniqueIdentifier();
Expand Down
8 changes: 8 additions & 0 deletions components/page/models/references.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ public function Create ( $pType, $pIdentifier, $pUserId ) {
return ( true );
}

public function RetrieveReferences ( $pUserId, $pStart = 0, $pLimit = 100 ) {

$criteria = array ( 'User_FK' => $pUserId );
$this->Retrieve ( $criteria, 'Stamp DESC', array ( 'start' => $pStart, 'step' => $pLimit ) );

return ( true );
}

}
52 changes: 52 additions & 0 deletions components/page/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,56 @@ public function ClearStatus ( $pData = null ) {
return ( true );
}

public function RegisterPageType ( $pData = null ) {

$post = new stdClass();
$post->Component = $this->Get ( 'Component' );
$post->Function = 'GetPost';

$return = array ( 'Post' => $post );

return ( $return );
}

public function GetPost ( $pData = null ) {

$this->_Current = $this->Talk ( 'User', 'Current' );
$this->_Focus = $this->Talk ( 'User', 'Focus' );

$Identifier = $pData['Identifier'];
$Account = $pData['Account'];

// Check the privacy settings on this item.
$Privacy = $this->Talk ( 'Privacy', 'Check', array ( 'Type' => 'Post', 'Identifier' => $Identifier ) );

// Load the Post data
include_once ( ASD_PATH . 'components/page/models/page.php' );
$Model = new cPageModel();

$Post = $Model->RetrievePost ( $this->_Focus->Id, $Identifier );

$return['Owner'] = $Post['Owner'];
$return['Comment'] = $Post['Content'];

// If false, then assume the highest level of privacy.
if ( !$Privacy ) {
// If the person viewing is the owner, grant access.
if ( $this->_Current->Account == $Post['Owner'] ) {
return ( $return );
} else if ( $this->_Focus->Account == $this->_Current->Account ) {
return ( $return );
} else {
return ( false );
}
} else if ( $Privacy->Circles ) {
} else if ( $Privacy->Friends ) {
} else if ( $Privacy->Everybody ) {
return ( $return );
} else {
return ( false );
}

return ( $return );
}

}
34 changes: 34 additions & 0 deletions components/privacy/models/privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,38 @@ public function Store ( $pCircle, $pType, $pIdentifier, $pUserId, $pEverybody =
return ( true );
}

public function RetrieveItem ( $pUserId, $pType, $pIdentifier ) {

$criteria = array ( 'User_FK' => $pUserId, 'Type' => $pType, 'Identifier' => $pIdentifier );

$this->Retrieve ( $criteria );

if ( $this->Get ( 'Total' ) == 0 ) return ( false );

while ( $this->Fetch() ) {
$data[] = $this->Get ( "Data" );
}

$return = new stdClass();

if ( count ( $data ) > 1 ) {
// Return the circle data
$return->Circles = array();
$return->Friends = true;
$return->Everybody = false;
} else if ( $data[0]['Friends'] ) {
$return->Circles = array();
$return->Friends = true;
$return->Everybody = false;
} else if ( $data[0]['Everybody'] ) {
$return->Circles = array();
$return->Friends = false;
$return->Everybody = true;
} else {
return ( false );
}

return ( $return );
}

}
17 changes: 16 additions & 1 deletion components/privacy/privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Store ( $pData ) {
unset ( $Privacy['everybody'] );
unset ( $Privacy['friends'] );

include ( ASD_PATH . 'components/privacy/models/privacy.php' );
include_once ( ASD_PATH . 'components/privacy/models/privacy.php' );
$Model = new cPrivacyModel();

if ( count ( $Privacy ) > 0 ) {
Expand All @@ -70,4 +70,19 @@ function Store ( $pData ) {
return ( true );
}

public function Check ( $pData = null ) {

$Identifier = $pData['Identifier'];
$Type = $pData['Type'];
$Circles = $this->Talk ( 'Friends', 'Circles' );

$this->_Focus = $this->Talk ( 'User', 'Focus' );

include_once ( ASD_PATH . 'components/privacy/models/privacy.php' );
$Model = new cPrivacyModel();

if ( !$Privacy = $Model->RetrieveItem ( $this->_Focus->Id, $Type, $Identifier ) ) return ( false );

return ( $Privacy );
}
}
2 changes: 1 addition & 1 deletion foundations/default/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ routes[/articles/edit/(\d+)]="articles/queue.php?Article=$1"

[page]
routes[profile/(.*)/page]="profile/page.php?Username=$1"
routes[profile/(.*)/]="profile/page.php?Username=$1"
routes["profile/([^/]+)/"]="profile/page.php?Username=$1"

[photos]
;routes[profile/(.*)/photos]="photos/sets.php"
Expand Down

0 comments on commit 91a9a7f

Please sign in to comment.