From 1d2349ef4ba7ec58a54c7a021704a7a0f56eb79c Mon Sep 17 00:00:00 2001 From: Zachary Doll Date: Mon, 12 Jan 2015 09:15:38 -0600 Subject: [PATCH] Remove echo option from `RenderReactionRecord()` --- controllers/class.reactcontroller.php | 2 +- library/functions.render.php | 38 +++++++-------------------- settings/class.hooks.php | 4 +-- views/best/index.php | 2 +- views/profile/best.php | 2 +- views/profile/reactions.php | 2 +- 6 files changed, 15 insertions(+), 35 deletions(-) diff --git a/controllers/class.reactcontroller.php b/controllers/class.reactcontroller.php index 6e62b14..ec2785b 100644 --- a/controllers/class.reactcontroller.php +++ b/controllers/class.reactcontroller.php @@ -99,7 +99,7 @@ class ReactController extends Gdn_Controller { $this->ReactionModel->Set($ID, $Type, $ItemOwnerID, $UserID, $ActionID); $this->JsonTarget($Anchor . ' .ReactMenu', RenderReactionList($ID, $Type), 'ReplaceWith'); - $this->JsonTarget($Anchor . ' .ReactionRecord', RenderReactionRecord($ID, $Type, FALSE), 'ReplaceWith'); + $this->JsonTarget($Anchor . ' .ReactionRecord', RenderReactionRecord($ID, $Type), 'ReplaceWith'); // Don't render anything $this->Render('Blank', 'Utility', 'Dashboard'); diff --git a/library/functions.render.php b/library/functions.render.php index ff866e1..43c8c0a 100644 --- a/library/functions.render.php +++ b/library/functions.render.php @@ -14,7 +14,7 @@ if(!function_exists('RenderReactionList')) { * * @param int $ID * @param string $Type 'discussion', 'activity', or 'comment' - * @return string Rendered list of reactions + * @return string Rendered list of actions available */ function RenderReactionList($ID, $Type) { $Reactions = Yaga::ReactionModel()->GetList($ID, $Type); @@ -46,51 +46,31 @@ if(!function_exists('RenderReactionRecord')) { * * @param int $ID * @param string $Type 'discussion', 'activity', or 'comment' - * @param bool $Echo Should it be echoed? - * @return mixed String if $Echo is false, TRUE otherwise + * @return string Rendered list of existing reactions */ - function RenderReactionRecord($ID, $Type, $Echo = TRUE) { + function RenderReactionRecord($ID, $Type) { $Reactions = Yaga::ReactionModel()->GetRecord($ID, $Type); $Limit = C('Yaga.Reactions.RecordLimit'); $ReactionCount = count($Reactions); $RecordsString = ''; - $i = 0; - foreach($Reactions as $Reaction) { - $i++; - + + foreach($Reactions as $i => $Reaction) { // Limit the record if there are a lot of reactions if($i <= $Limit || $Limit <= 0) { $User = Gdn::UserModel()->GetID($Reaction->UserID); - $DateTitle = sprintf( - T('Yaga.Reactions.RecordFormat'), - $User->Name, - $Reaction->Name, - Gdn_Format::Date($Reaction->DateInserted, '%B %e, %Y') - ); + $DateTitle = sprintf(T('Yaga.Reactions.RecordFormat'), $User->Name, $Reaction->Name, Gdn_Format::Date($Reaction->DateInserted, '%B %e, %Y')); $String = UserPhoto($User, array('Size' => 'Small', 'title' => $DateTitle)); $String .= ''; - $Wrapttributes = array( - 'class' => 'UserReactionWrap', - 'data-userid' => $User->UserID, - 'title' => $DateTitle - ); + $Wrapttributes = array('class' => 'UserReactionWrap', 'data-userid' => $User->UserID, 'title' => $DateTitle); $RecordsString .= Wrap($String, 'span', $Wrapttributes); } - + // Display the 'and x more' message if there is a limit if($Limit > 0 && $i >= $ReactionCount && $ReactionCount > $Limit) { $RecordsString .= Plural($ReactionCount - $Limit, 'Yaga.Reactions.RecordLimit.Single', 'Yaga.Reactions.RecordLimit.Plural'); } } - $AllRecordsString = Wrap($RecordsString, 'div', array('class' => 'ReactionRecord')); - - if($Echo) { - echo $AllRecordsString; - return true; - } - else { - return $AllRecordsString; - } + return Wrap($RecordsString, 'div', array('class' => 'ReactionRecord')); } } diff --git a/settings/class.hooks.php b/settings/class.hooks.php index d001f12..c005586 100755 --- a/settings/class.hooks.php +++ b/settings/class.hooks.php @@ -360,7 +360,7 @@ class YagaHooks implements Gdn_IPlugin { } $Type = 'discussion'; $ID = $Sender->DiscussionID; - RenderReactionRecord($ID, $Type); + echo RenderReactionRecord($ID, $Type); } /** @@ -373,7 +373,7 @@ class YagaHooks implements Gdn_IPlugin { } $Type = 'comment'; $ID = $Sender->EventArguments['Comment']->CommentID; - RenderReactionRecord($ID, $Type); + echo RenderReactionRecord($ID, $Type); } /** diff --git a/views/best/index.php b/views/best/index.php index aef7210..e5ff417 100644 --- a/views/best/index.php +++ b/views/best/index.php @@ -58,7 +58,7 @@ foreach ($Contents as $Content) { CheckPermission('Yaga.Reactions.View')) { - RenderReactionRecord($ContentID, strtolower($ContentType)); + echo RenderReactionRecord($ContentID, strtolower($ContentType)); } ?> diff --git a/views/profile/best.php b/views/profile/best.php index 209b594..ff2570d 100644 --- a/views/profile/best.php +++ b/views/profile/best.php @@ -58,7 +58,7 @@ foreach ($Contents as $Content) { CheckPermission('Yaga.Reactions.View')) { - RenderReactionRecord($ContentID, strtolower($ContentType)); + echo RenderReactionRecord($ContentID, strtolower($ContentType)); } ?> diff --git a/views/profile/reactions.php b/views/profile/reactions.php index 209b594..ff2570d 100644 --- a/views/profile/reactions.php +++ b/views/profile/reactions.php @@ -58,7 +58,7 @@ foreach ($Contents as $Content) { CheckPermission('Yaga.Reactions.View')) { - RenderReactionRecord($ContentID, strtolower($ContentType)); + echo RenderReactionRecord($ContentID, strtolower($ContentType)); } ?>