Skip to content

Commit

Permalink
Dev: extended getUrlReferrer in LSHttpRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jan 22, 2016
1 parent f074042 commit c4b1d4c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions application/controllers/admin/statistics.php
Expand Up @@ -734,6 +734,8 @@ protected function _renderWrappedTemplate($sAction = 'export', $aViewUrls = arra
//App()->getClientScript()->registerScriptFile( App()->getAssetManager()->publish( $switch) );
App()->getClientScript()->registerScriptFile( $switch );

$aData['menu']['closeurl'] = Yii::app()->request->getUrlReferrer(Yii::app()->createUrl("/admin/survey/sa/view/surveyid/".$aData['surveyid']));


$aData['display'] = array();
$aData['display']['menu_bars'] = false;
Expand Down
36 changes: 34 additions & 2 deletions application/core/LSHttpRequest.php
Expand Up @@ -34,9 +34,39 @@
class LSHttpRequest extends CHttpRequest {
public $noCsrfValidationRoutes = array();

/**
* Return the referal url,
* it's used for the close buttons.
* So it checks if the referrer url is the same than the current url to avoid looping.
* If it the case, a paramater can be set to tell what referrer to return.
* If the referrer is an external url, Yii return by default the current url.
*
* @param $ifNull string, the url to return if referrer url is the same than current url.
*/
public function getUrlReferrer($ifNull=null)
{

$referrer = parent::getUrlReferrer();
$baseReferrer = str_replace(Yii::app()->getBaseUrl(true), "", $referrer);
$baseRequestUri = str_replace(Yii::app()->getBaseUrl(), "", Yii::app()->request->requestUri);

// If they are the same, the script calling the method will choose what to do.
$referrer = ($baseReferrer != $baseRequestUri)?$referrer:null;

if(isset($ifNull))
{
if(is_null($referrer))
{
$referrer = $ifNull;
}
}

return $referrer;
}

protected function normalizeRequest(){
parent::normalizeRequest();

if(!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] != 'POST') return;

$route = Yii::app()->getUrlManager()->parseUrl($this);
Expand All @@ -52,4 +82,6 @@ protected function normalizeRequest(){
}
}

}


}
2 changes: 1 addition & 1 deletion application/views/admin/responses/browsemenubar_view.php
Expand Up @@ -261,7 +261,7 @@
<?php endif;?>

<?php if(isset($menu) && $menu['close']): ?>
<a class="btn btn-danger" href="<?php echo $this->createUrl("admin/responses/sa/index/surveyid/$surveyid"); ?>" role="button">
<a class="btn btn-danger" href="<?php echo $menu['closeurl']; ?>" role="button">
<span class="glyphicon glyphicon-close"></span>
<?php eT("Close");?>
</a>
Expand Down

0 comments on commit c4b1d4c

Please sign in to comment.