GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#197)
by ostashev
05:37
created

FController::getCanonicalUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
/**
3
 * @author Sergey Glagolev <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2014 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 * @package frontend.components
8
 *
9
 * @mixin CommonBehavior
10
 * @mixin SeoBehavior
11
 * @mixin TextBlockBehavior
12
 * @mixin FControllerBehavior
13
 *
14
 * @property Counter[] $counters
15
 * @property array $copyrights
16
 * @property array $contacts
17
 * @property array|string $settings
18
 *
19
 * @property FBasket|FCollectionElement[] $basket
20
 * @property FFavorite|FCollectionElement[] $favorite
21
 * @property FForm $fastOrderForm
22
 * @property FForm $callbackForm
23
 * @property FForm $loginPopupForm
24
 */
25
class FController extends CController
26
{
27
  public $breadcrumbs = array();
28
29
  /**
30
   * @var array $activeUrl
31
   */
32
  public $activeUrl = array();
33
34
  /**
35
   * @var bool
36
   */
37
  protected $rememberThisPage;
38
39
  public function behaviors()
40
  {
41
    return array(
42
      'seo' => array('class' => 'SeoBehavior'),
43
      'controller' => array('class' => 'FControllerBehavior'),
44
      'textBlock' => array('class' => 'TextBlockBehavior'),
45
      'common' => array('class' => 'CommonBehavior'),
46
    );
47
  }
48
49
  public function actions()
50
  {
51
    return array(
52
      'captcha' => array(
53
        'class' => 'FCaptchaAction',
54
      ),
55
    );
56
  }
57
58
  public function init()
59
  {
60
    Yii::app()->setHomeUrl($this->createAbsoluteUrl('index/index'));
61
  }
62
63
  public function renderOverride($view, $data = null, $return = false, $processOutput = false)
64
  {
65
    if( !empty($this->action) && file_exists($this->viewPath.'/'.$this->action->id.'/'.$view.'.php') )
66
    {
67
      $this->renderPartial($this->action->id.'/'.$view, $data, $return, $processOutput);
68
    }
69
    else if( file_exists($this->viewPath.'/'.$view.'.php') )
70
    {
71
      $this->renderPartial($view, $data, $return, $processOutput);
72
    }
73
    else
74
    {
75
      $this->renderPartial('//'.$view, $data, $return, $processOutput);
76
    }
77
  }
78
79
  /**
80
   * @param string $modelClass
81
   * @param int $id
82
   *
83
   * @return CActiveRecord
84
   * @throws CHttpException
85
   */
86
  public function loadModel($modelClass, $id)
87
  {
88
    $model = $modelClass::model()->findByPk($id);
89
90
    if( $model === null )
91
      throw new CHttpException(404, "The requested page of {$modelClass} does not exist.");
92
93
    return $model;
94
  }
95
96
  /**
97
   * @param string $view
98
   * @param null $data
99
   * @param bool $return
100
   *
101
   * @return string|null
102
   * @throws CException
103
   */
104
  public function render($view, $data = null, $return = false)
105
  {
106
    $this->onBeforeRender(new CEvent($this, array('data' => $data, 'view' => $view)));
107
108
    if( $this->beforeRender($view) )
109
    {
110
      $output = $this->renderPartial($view, $data, true);
111
112
      if( ($layoutFile = $this->getLayoutFile($this->layout)) !== false )
113
      {
114
        $this->onBeforeRenderLayout(new CEvent($this, array('content' => $output)));
115
        $output = $this->renderFile($layoutFile, array('content' => $output), true);
116
      }
117
118
      $this->afterRender($view, $output);
119
      $output = $this->processOutput($output);
120
121
      if( $return )
122
        return $output;
123
      else
124
        echo $output;
125
    }
126
127
    return null;
128
  }
129
130
  public function onBeforeRender(CEvent $event)
131
  {
132
    $this->raiseEvent('onBeforeRender', $event);
133
  }
134
135
  public function onBeforeRenderLayout(CEvent $event)
136
  {
137
    $this->raiseEvent('onBeforeRenderLayout', $event);
138
  }
139
140
  /**
141
   * http://help.yandex.ru/webmaster/?id=1111858#canonical
142
   *
143
   * @return string
144
   */
145
  public function getCanonicalUrl()
146
  {
147
    $params = array();
148
    if (Yii::app()->urlManager->rule) {
149
      $params = array_intersect_key($this->actionParams, array_flip(Yii::app()->urlManager->rule->canonicalParams));
150
    }
151
    return $this->createAbsoluteUrl($this->route, $params);
152
  }
153
154
  /**
155
   * @param bool $cutDefaultParams
156
   *
157
   * @return string
158
   */
159
  public function getCurrentUrl($cutDefaultParams = true)
160
  {
161
    return $this->createUrl($this->getCurrentRoute(), $this->getActionParams($cutDefaultParams));
162
  }
163
164
  /**
165
   * @param bool $cutDefaultParams
166
   *
167
   * @return string
168
   */
169
  public function getCurrentAbsoluteUrl($cutDefaultParams = true)
170
  {
171
    return $this->createAbsoluteUrl($this->getCurrentRoute(), $this->getActionParams($cutDefaultParams));
172
  }
173
174
  /**
175
   * @return string
176
   */
177
  public function getCurrentRoute()
178
  {
179
    $route = $this->id.'/'.$this->action->id;
180
181
    if( $module = $this->getModule() )
182
      $route = '/'.$module->id.'/'.$route;
183
184
    return $route;
185
  }
186
187
  /**
188
   * @param bool $cutDefaultParams
189
   *
190
   * @return string
191
   */
192
  public function getActionUrl($cutDefaultParams = true)
193
  {
194
    return preg_replace('/\?.*/', '', $this->getCurrentUrl($cutDefaultParams));
195
  }
196
197
  /**
198
   * @param bool $cutDefaultParams
199
   *
200
   * @return array
201
   */
202
  public function getActionParams($cutDefaultParams = false)
203
  {
204
    $params = $_GET;
205
206
    if( $cutDefaultParams )
207
    {
208
      $rule = Arr::get(Yii::app()->urlManager->rules, Yii::app()->urlManager->ruleIndex);
209
      foreach(Arr::get($rule, 'defaultParams', array()) as $key => $value)
210
        unset($params[$key]);
211
    }
212
213
    return $params;
214
  }
215
216
  /**
217
   * @param string $route
218
   * @param array $params
219
   * @param string $ampersand
220
   *
221
   * @return string
222
   */
223
  public function createUrl($route, $params = array(), $ampersand = '&')
224
  {
225
    // Исправляем относительные роуты в модуле на абсолютные
226
    if( !empty($route) && $route[0] !== '/' && ($module = $this->getModule()) !== null )
227
      $route = '/'.$route;
228
229
    return parent::createUrl($route, $params, $ampersand);
230
  }
231
232
  /**
233
   * @param CAction $action
234
   *
235
   * @return void
236
   */
237
  protected function afterAction($action)
238
  {
239
    if( Yii::app()->urlManager->shouldRememberReturnUrl() )
240
    {
241
      Yii::app()->user->setReturnUrl($this->getCurrentUrl());
242
    }
243
244
    parent::afterAction($action);
245
  }
246
}