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

Commit

Permalink
Build out new comments component.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchisari authored and The Appleseed Project committed Dec 31, 2010
1 parent e4bb29b commit 9ff5361
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 8 deletions.
164 changes: 164 additions & 0 deletions components/comments/controllers/comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php
/**
* @version $Id$
* @package Appleseed.Components
* @subpackage Comments
* @copyright Copyright (C) 2004 - 2010 Michael Chisari. All rights reserved.
* @link http://opensource.appleseedproject.org
* @license GNU General Public License version 2.0 (See LICENSE.txt)
*/

// Restrict direct access
defined( 'APPLESEED' ) or die( 'Direct Access Denied' );

/** Comments Component Controller
*
* Comments Component Controller Class
*
* @package Appleseed.Components
* @subpackage Comments
*/
class cCommentsCommentsController extends cController {

/**
* Constructor
*
* @access public
*/
public function __construct ( ) {
parent::__construct( );
}

function Display ( $pView = null, $pData = array ( ) ) {

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

$Context = $pData['Context'];
$Context_FK = $pData['Id'];

if ( ( !$Context ) || ( !$Context_FK ) ) {
// Display error loading comments
$this->View = $this->GetView ( 'error' );
$this->View->Display ( );

return ( true );
}

$this->View = $this->GetView ( );

$this->Model = $this->GetModel ( );

$this->Comments = $this->Model->Load ( $Context, $Context_FK );

$ol = $this->View->Find ( '.comments', 0);

$row = $this->View->Copy ( '.comments' )->Find ( 'ol', 0 );

$rowOriginal = $row->outertext;

$ol->innertext = '';

foreach ( $this->Comments as $c => $comment ) {
if ( $comment['Parent_ID'] ) continue;

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

$this->_PrepComment ( $row, $comment );

if ( $Children = $this->_GetChildren ( $comment['Entry_PK'] ) ) {
$row->Find ( '.nesting', 0 )->innertext = $this->_BuildChildren ( $comment['Entry_PK'], $Children, $rowOriginal );
}

$ol->innertext .= $row->outertext;
unset ( $row );
}

$this->View->Display();

return ( true );
}

private function _GetChildren ( $pParent ) {

$children = array ( );

foreach ( $this->Comments as $c => $comment ) {
if ( $comment['Parent_ID'] == $pParent ) {
$children[] = $comment;
}
}

if ( count ( $children ) == 0 ) return ( false );

return ( $children );
}

private function _BuildChildren ( $pParent, $pChildren, $pOriginal ) {

$return = '';

foreach ( $pChildren as $c => $child ) {
if ( $child['Parent_ID'] != $pParent ) continue;

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

$row->Find ( 'ol', 0 )->class = 'comments nested';

$this->_PrepComment ( $row, $child );

if ( $Children = $this->_GetChildren ( $child['Entry_PK'] ) ) {
$row->Find ( '.nesting', 0 )->innertext .= $this->_BuildChildren ( $child['Entry_PK'], $Children, $pOriginal );
}

$return .= $row->outertext;

unset ( $row );

}

return ( $return );
}

private function _PrepComment ( $pRow, $pItem ) {

if ( $pItem['Status'] != 1 ) {
$this->_PrepDeletedComment ( $pRow, $pItem );
return ( true );
}

list ( $username, $domain ) = explode ( '@', $pItem['Owner'] );
$data = array ( 'username' => $username, 'domain' => $domain, 'width' => 32, 'height' => 32 );
$pRow->Find ( '.comment-icon', 0 )->src = $this->GetSys ( 'Event' )->Trigger ( 'On', 'User', 'Icon', $data );

$pRow->Find ( '.comment-body', 0 )->innertext = $this->GetSys ( 'Render' )->Format ( $pItem['Body'] );
$pRow->Find ( '.stamp', 0 )->innertext = $this->GetSys ( 'Date' )->Format ( $pItem['Created'] );

$pRow->Find ( '.comment-user-link', 0 )->rel = $pItem['Owner'];
$pRow->Find ( '.comment-user-link', 0 )->innertext = $pItem['Owner'];

$data = array ( 'account' => $pItem['Owner'], 'source' => ASD_DOMAIN );
$OwnerLink = $this->GetSys ( 'Event' )->Trigger ( 'Create', 'User', 'Link', $data );
$pRow->Find ( '.comment-user-link', 0 )->href = $OwnerLink;
$pRow->Find ( '.comment-icon-link', 0 )->href = $OwnerLink;

if ( ( $this->_Current->Account == $this->_Focus->Account ) or ( $this->_Current->Account == $pItem['Owner'] ) ) {
$pRow->Find ( '.delete', 0 )->href = "";
} else {
$pRow->Find ( '.delete-area', 0 )->outertext = "";
}

return ( true );
}

private function _PrepDeletedComment ( $pRow, $pItem ) {
$pRow->Find ( '.comment-body', 0 )->innertext = __ ( 'Deleted Comment' );
$pRow->Find ( '.comments', 0 )->class .= ' deleted ';
$pRow->Find ( '.delete-area', 0 )->outertext = '';
$pRow->Find ( '.reply-area', 0 )->outertext = '';
$pRow->Find ( '.stamp', 0 )->outertext = '';
}

}
2 changes: 2 additions & 0 deletions components/comments/languages/en-US/comments.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

DELETED_COMMENT="This comment has been deleted"
50 changes: 50 additions & 0 deletions components/comments/models/comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* @version $Id$
* @package Appleseed.Components
* @subpackage Comments
* @copyright Copyright (C) 2004 - 2010 Michael Chisari. All rights reserved.
* @link http://opensource.appleseedproject.org
* @license GNU General Public License version 2.0 (See LICENSE.txt)
*/

// Restrict direct access
defined( 'APPLESEED' ) or die( 'Direct Access Denied' );

/** Comments Component Model
*
* Comments Component Model Class
*
* @package Appleseed.Components
* @subpackage Comments
*/
class cCommentsModel extends cModel {

protected $_Tablename = "CommentEntries";

/**
* Constructor
*
* @access public
*/
public function __construct ( $pTables = null ) {
parent::__construct( $pTables );
}

public function Load ( $pContext, $pId ) {

$this->Retrieve ( array ( 'Context' => $pContext, 'Context_FK' => $pId ) );

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

$result = array ();

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

return ( $items );

}

}
24 changes: 24 additions & 0 deletions components/comments/views/comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1>Read Comments</h1>
<ol class="comments outer">
<li>
<div class="comment">
<div class="comment-icon-area">
<a class="comment-icon-link" href="#"><img class="comment-icon" src="" alt="Commenter Icon" /></a>
</div>
<div class="comment-content">
<div class="comment-area">
<a class="comment-user-link" href="#"></a>
<span class="comment-body"></span>
</div>
<abbr class="stamp"></abbr>
<nav>
<ul>
<li class="delete-area"><button class="delete">Delete</button></li>
<li class="reply-area"><button class="reply">Reply</button></li>
</ul>
</nav>
</div>
</div>
</li>
<li class='nesting'></li>
</ol>
2 changes: 2 additions & 0 deletions components/comments/views/error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Read Comments</h1>
<p class='error'>Error Loading Comments</p>
3 changes: 3 additions & 0 deletions components/journal/controllers/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private function _Prep ( ) {
$this->View->Find ( '.edit', 0 )->outertext = "";
}

$commentsData = array ( 'Context' => 'Journal', 'Id' => $this->Model->Get ( 'Entry_PK' ) );
$this->View->Find ( '.comments', 0 )->innertext = $this->GetSys ( 'Components' )->Buffer ( 'comments', $commentsData );

$this->View->Find ( '.back', 0 )->href = '/profile/' . $this->_Focus->Username . '/journal/';

$this->_PrepMessage();
Expand Down
1 change: 1 addition & 0 deletions components/journal/views/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
<section class="comments"></section>
</section>

<section class="comments"></section>
1 change: 0 additions & 1 deletion components/newsfeed/controllers/newsfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ private function _PrepPost ( ) {
$Comment = $this->GetSys ( 'Render' )->Format ( $this->Model->Get ( 'Comment' ) );
$Comment = $this->GetSys ( 'Render' )->LiveLinks ( $Comment );


$row->Find ( '.comment', 0 )->innertext = str_replace ( "\n", "<br />", $Comment );
$row->Find ( '.actionowner-link', 0 )->rel = $ActionOwner;
$row->Find ( '.actionowner-link', 0 )->innertext = $ActionOwner;
Expand Down
21 changes: 14 additions & 7 deletions themes/default/style/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,29 @@
input.search-submit { -webkit-border-bottom-right-radius:4px; -webkit-border-top-right-radius:4px; -moz-border-radius-bottomright:4px; -moz-border-radius-topright:4px; -border-bottom-right-radius:4px; -border-top-right-radius:4px; }

/* Comments */
section.comments { clear:both; float:left; width:100%; }
ol.comments.outer { font-size:110%; }
ol.comments { float:left; clear:both; width:100%; list-style-type:none; margin:0; }
ol.comments li { clear: left; }
ol.comments li div.comment { float:left; clear:both; background:#c0d895; border-top:1px solid #80af1f; margin-bottom:1px; }
ol.outer li div.comment { border:none; }
ol.comments li div.comment-icon { float:left; display:inline; clear:none; width:32px; padding:5px 5px 0 5px; }
ol.comments li div.comment-icon a { background:none; padding:0; }
ol.comments li div.comment-icon img { width:32px; height:32px; padding:0; margin:0; }
ol.comments li div.comment-icon-area { float:left; display:inline; clear:none; width:32px; padding:5px 5px 0 5px; }
ol.comments li div.comment-icon-area a { background:none; padding:0; }
ol.comments li div.comment-icon-area img { width:32px; height:32px; padding:0; margin:0; }

ol.deleted li div.comment { padding-right:42px; color:#4a4a4a; font-style:italic; }
ol.deleted li div.comment-icon-area { display:none; }

ol.comments li div.comment-content { float:right; clear:none; display:inline; width:658px; margin:5px 0 0 0; padding:0; vertical-align:top; }

ol.comments li div.comment-content p { float:left; width:100%; margin:0 0 5px 0; padding:0; }
ol.comments li div.comment-content p { float:left; width:100%; margin:0 0 5px 0; padding:0; font-size:100%; }
ol.comments li div.comment-content a { background:none; padding:0; font-weight:bold; margin-right:5px; }
ol.comments li div.comment-content abbr { float:left; clear:none; font-size:80%; color:#8a8a8a; font-style:italic; border:none; cursor:auto; }
ol.comments li div.comment-content nav { font-size:80%; float:right; margin:0; padding:0; clear:none; }
ol.comments li div.comment-content abbr { float:left; clear:none; font-size:90%; color:#8a8a8a; font-style:italic; border:none; cursor:auto; }
ol.comments li div.comment-content nav { font-size:90%; float:right; margin:0; padding:0; clear:none; }
ol.comments li div.comment-content nav ul li { float:left; display:inline; border:none; width:auto; padding:0; margin-right:10px; clear:none; }
ol.comments li div.comment-content nav ul li a { font-weight:normal; }

ol.comments ol.nested { margin: 0px 0px 0px 20px; clear: left; }
ol.comments ol.nested { padding: 0px 0px 0px 19px; border-left:1px solid #d9e8cf; clear: left; }
ol.comments ol.nested ol.nested ol.nested ol.nested ol.nested ol.nested ol.nested ol.nested ol.nested ol.nested ol.nested { margin: 0px 0px 0px 0px; clear:left; }

ol.comments li ol.nested li div.comment-content { width:638px; }
Expand All @@ -127,6 +131,9 @@
ol.comments li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li div.comment-content { width:478px; }
ol.comments li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li ol.nested li div.comment-content { width:458px; }

ol.comments .comment-content .comment-area { margin-bottom:5px; }
ol.comments .comment-content .comment-body p { clear:none; float:none; width:auto; display:inline; margin:0; padding:0; }

/* Translation Debugging */
span.untranslated { margin:0; padding:0px 4px; color:#2a2afa; background-color:#cacafa;}
span.untranslatedp { margin:0 0 0 0; padding:0px 4px; color:#2a2afa; background-color:#facaca;}
Expand Down

0 comments on commit 9ff5361

Please sign in to comment.