Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
PageView.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 
45  class PageView extends View
46  {
50  public static $foundErrors = false;
51 
52  public static $xhtmlValidationErrors = array();
53 
54  private $containedView;
55 
60  public function __construct(View $containedView)
61  {
62  $this->containedView = $containedView;
63  }
64 
65  public function render()
66  {
67  if (SHOW_PERFORMANCE)
68  {
69  $startTime = microtime(true);
70  }
71  static::registerAllPagesScriptFiles();
72  $content = $this->renderXHtmlStart() .
73  $this->renderXHtmlHead() .
74  $this->renderXHtmlBodyStart() .
75  parent::render() .
76  $this->renderXHtmlBeforeBodyEnd() .
77  $this->renderXHtmlBodyEnd() .
78  $this->renderXHtmlEnd();
79  Yii::app()->getClientScript()->render($content);
80  if (YII_DEBUG)
81  {
82  if (defined('XHTML_VALIDATION') && XHTML_VALIDATION)
83  {
84  $this->validate($content);
85  if (!empty(self::$xhtmlValidationErrors))
86  {
87  foreach (self::$xhtmlValidationErrors as $error)
88  {
89  $content = $this->appendContentBeforeXHtmlBodyEndAndXHtmlEnd($content, $error);
90  }
91  }
92  }
93  }
94  if (YII_DEBUG && Yii::app()->isApplicationInstalled())
95  {
96  $dbInfoHtml = '<span style="background-color: lightgreen; color: green">Database: \'' . Yii::app()->db->connectionString . '\', username: \'' . Yii::app()->db->username . '\'.</span><br />';
97  $content = $this->appendContentBeforeXHtmlBodyEndAndXHtmlEnd($content, $dbInfoHtml);
98  }
99  return $content;
100  }
101 
107  public static function validate($content)
108  {
109  $wrapper = '<span style="background-color: yellow; color: #c00000;"><b>{text}</b></span><br />';
110  $valid = false;
111  try
112  {
113  $xhtmlValidationErrors = W3CValidatorServiceUtil::validate($content);
114 
115  if (count($xhtmlValidationErrors))
116  {
117  foreach ($xhtmlValidationErrors as $xhtmlValidationError)
118  {
119  self::$xhtmlValidationErrors[] = str_replace('{text}', $xhtmlValidationError, $wrapper);
120  }
121  }
122  else
123  {
124  $valid = true;
125  }
126 
127  if (!count(self::$xhtmlValidationErrors))
128  {
129  $valid = true;
130  }
131  }
132  catch (Exception $e)
133  {
134  self::$xhtmlValidationErrors[] = str_replace('{text}', 'Error accessing W3C validation service.', $wrapper);
135  self::$xhtmlValidationErrors[] = str_replace('{text}', $e->getMessage(), $wrapper);
136  }
137  return $valid;
138  }
139 
144  public static function schemeValidationErrorHandler($errno, $errstr, $errfile, $errline)
145  {
146  static $first = true;
147 
148  if ($first)
149  {
150  self::$xhtmlValidationErrors[] = '<span style="background-color: yellow; color: #c00000;"><b>THIS IS NOT A VALID XHTML FILE</b></span><br />';
151  $first = false;
152  }
153  self::$xhtmlValidationErrors[] = "<span style=\"background-color: yellow; color: #c00000;\">$errstr</span><br />";
154 
155  self::$foundErrors = true;
156  }
157 
158  protected function renderContent()
159  {
160  return $this->containedView->render();
161  }
162 
166  protected function renderXHtmlStart()
167  {
168  $themeUrl = Yii::app()->themeManager->baseUrl;
169  $theme = Yii::app()->theme->name;
170  $backgroundTexture = Yii::app()->themeManager->getActiveBackgroundTexture();
171  $classContent = null;
172  if ($backgroundTexture != null)
173  {
174  $classContent .= ' ' . $backgroundTexture;
175  }
176  if (!MINIFY_SCRIPTS && Yii::app()->isApplicationInstalled())
177  {
178  Yii::app()->clientScript->registerScriptFile(
179  Yii::app()->getAssetManager()->publish(
180  Yii::getPathOfAlias('application.core.views.assets')) . '/less-1.2.0.min.js');
181  }
182  Yii::app()->clientScript->registerScriptFile(
183  Yii::app()->getAssetManager()->publish(
184  Yii::getPathOfAlias('application.core.views.assets')) . '/ZurmoDialog.js');
185  Yii::app()->clientScript->registerScriptFile(
186  Yii::app()->getAssetManager()->publish(
187  Yii::getPathOfAlias('application.core.views.assets')) . '/interactions.js');
188  Yii::app()->clientScript->registerScriptFile(
189  Yii::app()->getAssetManager()->publish(
190  Yii::getPathOfAlias('application.core.views.assets')) . '/mobile-interactions.js');
191  Yii::app()->clientScript->registerScriptFile(
192  Yii::app()->getAssetManager()->publish(
193  Yii::getPathOfAlias('application.core.views.assets')) . '/jquery.truncateText.js');
194  return '<!DOCTYPE html>' .
195  '<!--[if IE 8]><html class="zurmo ie8' . $classContent . '" lang="en"><![endif]-->' .
196  '<!--[if gt IE 8]><!--><html class="zurmo' . $classContent . '" lang="en"><!--<![endif]-->';
197  }
198 
202  protected function renderXHtmlBeforeBodyEnd()
203  {
204  return Yii::app()->userInterface->renderXHtmlBeforeBodyEndContent();
205  }
206 
213  protected function renderXHtmlHead()
214  {
215  $title = Yii::app()->format->text(trim($this->getTitle()));
216  $subtitle = Yii::app()->format->text(trim($this->getSubtitle()));
217  if ($subtitle != '')
218  {
219  $title = "$title - $subtitle";
220  }
221  $defaultThemeName = 'default';
222  $defaultThemeBaseUrl = Yii::app()->themeManager->baseUrl . '/' . $defaultThemeName;
223  $themeName = Yii::app()->theme->name;
224  $themeBaseUrl = Yii::app()->themeManager->baseUrl . '/' . $themeName;
225  $cs = Yii::app()->getClientScript();
226  //$cs->registerMetaTag('UTF-8', null, 'charset'); // Not Coding Standard
227 
228  $specialCssContent = null;
229  $publishedAssetsPath = Yii::app()->assetManager->publish(
230  Yii::getPathOfAlias("application.core.views.assets.fonts"));
231  $specialCssContent .= "<style>" .
232  "@font-face" .
233  "{" .
234  "font-family: 'zurmo_gamification_symbly_rRg';" .
235  "src: url('{$publishedAssetsPath}/zurmogamificationsymblyregular-regular-webfont.eot');" .
236  "src: url('{$publishedAssetsPath}/zurmogamificationsymblyregular-regular-webfont.eot?#iefix') format('embedded-opentype'), " .
237  "url('{$publishedAssetsPath}/zurmogamificationsymblyregular-regular-webfont.woff') format('woff'), " .
238  "url('{$publishedAssetsPath}/zurmogamificationsymblyregular-regular-webfont.ttf') format('truetype'), " .
239  "url('{$publishedAssetsPath}/zurmogamificationsymblyregular-regular-webfont.svg#zurmo_gamification_symbly_rRg') format('svg');" .
240  "font-weight: normal;" .
241  "font-style: normal;" .
242  "unicode-range: U+00-FFFF;" . // Not Coding Standard
243  "}" .
244  "</style>";
245  if (!MINIFY_SCRIPTS && Yii::app()->isApplicationInstalled())
246  {
247  $specialCssContent .= '<link rel="stylesheet/less" type="text/css" id="default-theme" href="' .
248  $themeBaseUrl . '/less/default-theme.less"/>';
249  $specialCssContent .= '<!--[if lt IE 9]><link rel="stylesheet/less" type="text/css" href="' .
250  $themeBaseUrl . '/less/ie.less"/><![endif]-->';
251  }
252  else
253  {
254  Yii::app()->themeManager->registerThemeColorCss();
255  if (file_exists("themes/$themeName/css/commercial.css"))
256  {
257  $cs->registerCssFile($themeBaseUrl . '/css/commercial.css' .
258  ZurmoAssetManager::getCssAndJavascriptHashQueryString("themes/$themeName/css/commercial.css"));
259  }
260  if (file_exists("themes/$themeName/css/custom.css"))
261  {
262  $cs->registerCssFile($themeBaseUrl . '/css/custom.css' .
263  ZurmoAssetManager::getCssAndJavascriptHashQueryString("themes/$themeName/css/custom.css"));
264  }
265  }
266  if (MINIFY_SCRIPTS)
267  {
268  Yii::app()->minScript->generateScriptMap('css');
269  Yii::app()->minScript->generateScriptMap('css-color');
270  if (!YII_DEBUG && !defined('IS_TEST'))
271  {
272  Yii::app()->minScript->generateScriptMap('js');
273  }
274  }
275  if (Yii::app()->browser->getName() == 'msie' && Yii::app()->browser->getVersion() < 9)
276  {
277  $cs->registerCssFile($themeBaseUrl . '/css/ie.css' .
278  ZurmoAssetManager::getCssAndJavascriptHashQueryString("themes/$themeName/css/ie.css"), 'screen, projection');
279  }
280 
281  foreach ($this->getStyles() as $style)
282  {
283  if ($style != 'ie')
284  {
285  if (file_exists("themes/$themeName/css/$style.css"))
286  {
287  // Begin Not Coding Standard
288  $cs->registerCssFile($themeBaseUrl . '/css/' . $style. '.css' .
289  ZurmoAssetManager::getCssAndJavascriptHashQueryString("themes/$themeName/css/$style.css"));
290  // End Not Coding Standard
291  }
292  }
293  }
294 
295  if (file_exists("themes/$themeName/ico/favicon.ico"))
296  {
297  $cs->registerLinkTag('shortcut icon', null, $themeBaseUrl . '/ico/favicon.ico');
298  }
299  else
300  {
301  $cs->registerLinkTag('shortcut icon', null, $defaultThemeBaseUrl . '/ico/favicon.ico');
302  }
303  return '<head>' .
304  '<meta charset="utf-8">' .
305  '<meta http-equiv="X-UA-Compatible" content="IE=edge" />' . // Not Coding Standard
306  '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">' . // Not Coding Standard
307  '<meta name="apple-mobile-web-app-capable" content="yes" />' . // Not Coding Standard
308  '<link rel="apple-touch-icon" sizes="144x144" href="' . $defaultThemeBaseUrl . '/images/touch-icon-iphone4.png" />' . //also add 57px, 72px, 144px // Not Coding Standard
309  $specialCssContent .
310  '<title>' . $title . '</title>' .
311  '</head>';
312  }
313 
317  protected function getSubtitle()
318  {
319  return '';
320  }
321 
328  protected function getStyles()
329  {
330  return array();
331  }
332 
336  protected function renderXHtmlBodyStart()
337  {
338  $classContent = Yii::app()->themeManager->getActiveThemeColor();
339  if (Yii::app()->userInterface->isMobile())
340  {
341  $classContent .= ' mobile-app';
342  }
343  if (Yii::app()->isApplicationInSandboxMode())
344  {
345  $classContent .= ' sandbox-mode';
346  }
347  Yii::app()->userInterface->resolveCollapseClassForBody($classContent);
348  return '<body class="' . $classContent . '">';
349  }
350 
354  protected function renderXHtmlBodyEnd()
355  {
356  return '</body>';
357  }
358 
362  protected function renderXHtmlEnd()
363  {
364  return '</html>';
365  }
366 
367  public static function makeNonHtmlDuplicateCountAndQueryContent()
368  {
369  $content = null;
370  $duplicateData = Yii::app()->performance->getRedBeanQueryLogger()->getDuplicateQueriesData();
371  foreach ($duplicateData as $query => $count)
372  {
373  $content .= 'Count: ' . $count . '--Query: ' . $query . "\n";
374  }
375  return $content;
376  }
377 
382  public static function registerAllPagesScriptFiles()
383  {
384  Yii::app()->clientScript->registerCoreScript('jquery');
385  Yii::app()->clientScript->registerCoreScript('jquery-migrate');
386  Yii::app()->clientScript->registerCoreScript('jquery.ui');
387  }
388 
392  public static function getScriptFilesThatLoadOnAllPages()
393  {
394  //When debug is on, the application never minifies
395  $scriptData = array();
396  if (MINIFY_SCRIPTS && !YII_DEBUG)
397  {
398  foreach (Yii::app()->minScript->usingAjaxShouldNotIncludeJsPathAliasesAndFileNames as $data)
399  {
400  $scriptData[] = Yii::app()->getAssetManager()->getPublishedUrl(Yii::getPathOfAlias($data[0])) . $data[1];
401  }
402  }
403  return $scriptData;
404  }
405 
412  public function appendContentBeforeXHtmlBodyEndAndXHtmlEnd($content, $additionalContent)
413  {
414  $content = str_replace($this->renderXHtmlBodyEnd() . $this->renderXHtmlEnd() ,
415  $additionalContent . $this->renderXHtmlBodyEnd() . $this->renderXHtmlEnd(),
416  $content );
417  return $content;
418  }
419  }
420 ?>
renderXHtmlHead()
Definition: PageView.php:213
appendContentBeforeXHtmlBodyEndAndXHtmlEnd($content, $additionalContent)
Definition: PageView.php:412
Definition: View.php:43
Definition: A.php:37
renderXHtmlBeforeBodyEnd()
Definition: PageView.php:202
static validate($content)
Definition: PageView.php:107
__construct(View $containedView)
Definition: PageView.php:60
static $foundErrors
Definition: PageView.php:50
renderXHtmlBodyStart()
Definition: PageView.php:336
renderXHtmlBodyEnd()
Definition: PageView.php:354
renderXHtmlStart()
Definition: PageView.php:166
renderXHtmlEnd()
Definition: PageView.php:362
Generated on Thu Jul 9 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.