Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
WebApplication.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  class WebApplication extends CWebApplication
38  {
43  public $label;
44 
49  protected $installed;
50 
54  protected $edition;
55 
60  protected $maintenanceMode;
61 
66  protected $sandboxMode = false;
67 
72  protected $resolveAlwaysAsAbsoluteUrl = false;
73 
79  protected $allClassesImported = false;
80 
84  public function run()
85  {
86  try
87  {
88  parent::run();
89  }
90  catch (ChecksumMismatchException $e)
91  {
92  echo Zurmo::t('Core', 'A checksum mismatch has occurred while retrieving a cached model. ' .
93  'This is most likely caused by setting debug=true. The cache must be cleared.'); // Not Coding Standard
94  echo '<br/>';
95  exit;
96  $url = Yii::app()->createUrl('zurmo/default/index/', array('clearCache' => true));
97  echo ZurmoHtml::link('Click here to clear the cache', $url);
98  Yii::app()->end(0, false);
99  }
100  }
101 
108  public function getLocale($localeID = null)
109  {
110  if ($localeID == null && $this->user->userModel != null && $this->user->userModel->id > 0 &&
111  $this->user->userModel->locale != null)
112  {
113  $localeID = $this->user->userModel->locale;
114  }
115  elseif ($localeID == null)
116  {
117  $localeID = $this->getLanguage();
118  }
119  return ZurmoLocale::getInstance($localeID);
120  }
121 
131  public function createController($route, $owner = null)
132  {
133  if ($owner === null)
134  {
135  $owner = $this;
136  }
137  if (($route = trim($route, '/')) === '')
138  {
139  $route = $owner->defaultController;
140  }
141  $caseSensitive = $this->getUrlManager()->caseSensitive;
142  $route .= '/';
143  while (($pos = strpos($route, '/')) !== false)
144  {
145  $id = substr($route, 0, $pos);
146  if (!preg_match('/^\w+$/', $id)) // Not Coding Standard
147  {
148  return null;
149  }
150  if (!$caseSensitive)
151  {
152  $id = strtolower($id);
153  }
154  $route = (string)substr($route, $pos + 1);
155  if (!isset($basePath))
156  {
157  if (isset($owner->controllerMap[$id]))
158  {
159  return array(
160  Yii::createComponent(
161  $owner->controllerMap[$id],
162  $id,
163  $this->resolveWhatToPassAsParameterForOwner($owner)),
164  $this->parseActionParams($route),
165  );
166  }
167 
168  if (($module = $owner->getModule($id)) !== null)
169  {
170  return $this->createController($route, $module);
171  }
172  $basePath = $owner->getControllerPath();
173  $controllerID = '';
174  }
175  else
176  {
177  $controllerID .= '/';
178  }
179  $baseClassName = ucfirst($id) . 'Controller';
180  //this assumes owner is the module, which i am not sure is always true...
181  if ($this->isOwnerTheController($owner))
182  {
183  $className = $baseClassName;
184  $customClassName = 'Custom' . $baseClassName;
185  }
186  else
187  {
188  $className = $owner::getPluralCamelCasedName() . $baseClassName;
189  $customClassName = $owner::getPluralCamelCasedName() . 'Custom' . $baseClassName;
190  }
191  $classFile = $basePath . DIRECTORY_SEPARATOR . $baseClassName . '.php';
192  $customClassFile = $basePath . DIRECTORY_SEPARATOR . 'Custom' . $baseClassName . '.php';
193  if (is_file($customClassFile))
194  {
195  if (!class_exists($customClassName, false))
196  {
197  require($customClassFile);
198  }
199  if (class_exists($customClassName, false) && is_subclass_of($customClassName, 'CController'))
200  {
201  $id[0] = strtolower($id[0]);
202  return array(
203  new $customClassName($controllerID . $id, $this->resolveWhatToPassAsParameterForOwner($owner)),
204  $this->parseActionParams($route),
205  );
206  }
207  return null;
208  }
209  elseif (is_file($classFile))
210  {
211  if (!class_exists($className, false))
212  {
213  require($classFile);
214  }
215  if (class_exists($className, false) && is_subclass_of($className, 'CController'))
216  {
217  $id[0] = strtolower($id[0]);
218  return array(
219  new $className($controllerID . $id, $this->resolveWhatToPassAsParameterForOwner($owner)),
220  $this->parseActionParams($route),
221  );
222  }
223  return null;
224  }
225  $controllerID .= $id;
226  $basePath .= DIRECTORY_SEPARATOR . $id;
227  }
228  }
229 
230  protected function resolveWhatToPassAsParameterForOwner($owner)
231  {
232  if ($owner === $this)
233  {
234  return null;
235  }
236  return $owner;
237  }
238 
239  protected function isOwnerTheController($owner)
240  {
241  if ($owner === $this)
242  {
243  return true;
244  }
245  return false;
246  }
247 
251  public function findModule($moduleID)
252  {
253  return self::findInModule(Yii::app(), $moduleID);
254  }
255 
260  public static function findModuleInApplication($moduleID)
261  {
262  return self::findInModule(Yii::app(), $moduleID);
263  }
264 
268  private static function findInModule($parentModule, $moduleId)
269  {
270  if ($parentModule->getModule($moduleId))
271  {
272  return $parentModule->getModule($moduleId);
273  }
274  else
275  {
276  $modules = $parentModule->getModules();
277  foreach ($modules as $module => $moduleConfiguration)
278  {
279  $module = self::findInModule($parentModule->getModule($module), $moduleId);
280  if ($module)
281  {
282  return $module;
283  }
284  }
285  }
286  return null;
287  }
288 
289  public function isApplicationInstalled()
290  {
291  return $this->installed;
292  }
293 
294  public function setApplicationInstalled($installed)
295  {
296  $this->installed = $installed;
297  return true;
298  }
299 
300  public function isApplicationInMaintenanceMode()
301  {
302  return $this->maintenanceMode;
303  }
304 
305  public function isApplicationInSandboxMode()
306  {
307  return $this->sandboxMode;
308  }
309 
310  public function getEdition()
311  {
312  return $this->edition;
313  }
314 
322  public function createUrl($route, $params = array(), $ampersand = '&')
323  {
324  if ($this->resolveAlwaysAsAbsoluteUrl)
325  {
326  $url = $this->getUrlManager()->createUrl($route, $params, $ampersand);
327  if (strpos($url, 'http') === 0)
328  {
329  return $url;
330  }
331  else
332  {
333  return $this->getRequest()->getHostInfo() . $url;
334  }
335  }
336  else
337  {
338  return $this->getUrlManager()->createUrl($route, $params, $ampersand);
339  }
340  }
341 
346  {
347  $this->resolveAlwaysAsAbsoluteUrl = true;
348  }
349 
350  public function setAllClassesAreImported()
351  {
352  $this->allClassesImported = true;
353  }
354 
355  public function areAllClassesImported()
356  {
357  return $this->allClassesImported;
358  }
359  }
360 ?>
findModule($moduleID)
static getInstance($id)
Definition: ZurmoLocale.php:63
getLocale($localeID=null)
createController($route, $owner=null)
createUrl($route, $params=array(), $ampersand= '&')
static findModuleInApplication($moduleID)
Generated on Thu Sep 24 2020 07:10:25
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.