SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/LaunchChecks.php

  1. <?php
  2. /**
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  *
  13.  * This class was originally from Kohana 2.3.4
  14.  * Copyright 2007-2008 Kohana Team
  15.  */
  16. namespace Sprout\Helpers;
  17.  
  18. use Kohana;
  19.  
  20.  
  21. class LaunchChecks
  22. {
  23. protected static $results;
  24. protected static $skin;
  25.  
  26.  
  27. public static function runTests()
  28. {
  29. self::$results = [];
  30.  
  31. // Get list of unique subsite codes actually in use, to avoid noise
  32. $q = "SELECT code FROM ~subsites WHERE active = 1 GROUP BY code";
  33. $codes = Pdb::query($q, [], 'col');
  34.  
  35. $methods = get_class_methods(__CLASS__);
  36. foreach ($methods as $m) {
  37. self::$skin = '';
  38.  
  39. if (strpos($m, 'testSkin') === 0) {
  40. foreach ($codes as self::$skin) {
  41. call_user_func([__CLASS__, $m], self::$skin);
  42. }
  43.  
  44. } else if (strpos($m, 'test') === 0) {
  45. call_user_func([__CLASS__, $m]);
  46. }
  47. }
  48.  
  49. return self::$results;
  50. }
  51.  
  52.  
  53. protected static function addResult($check, $result, $message)
  54. {
  55. self::$results[] = [
  56. 'check' => $check,
  57. 'skin' => self::$skin,
  58. 'result' => $result,
  59. 'message' => $message,
  60. ];
  61. }
  62.  
  63.  
  64. /**
  65.   * Check that the "CLI domain" has been set
  66.   */
  67. public static function testCliDomain()
  68. {
  69. $cli_domain = Kohana::config('config.cli_domain');
  70.  
  71. if (empty($cli_domain)) {
  72. self::addResult('CLI domain', 'error', 'Not set');
  73. return;
  74. }
  75.  
  76. // This would only be a false-positive for IANA...
  77. if ($cli_domain === 'www.example.com' or $cli_domain === 'devel.example.com') {
  78. self::addResult('CLI domain', 'error', 'Default value "' . $cli_domain . '"');
  79. return;
  80. }
  81.  
  82. if (strpos($cli_domain, 'www.') !== 0) {
  83. self::addResult('CLI domain', 'warning', 'Does not begin with www.');
  84. return;
  85. }
  86.  
  87. self::addResult('CLI domain', 'okay', $cli_domain);
  88. }
  89.  
  90.  
  91. public static function testEmail()
  92. {
  93. $cli_domain = Kohana::config('config.cli_domain');
  94. $email = Kohana::config('sprout.site_email');
  95.  
  96. $cli_domain = preg_replace('/^www\./i', '', $cli_domain);
  97. $email_domain = preg_replace('/^.*@/', '', $email);
  98.  
  99. if ($cli_domain != $email_domain) {
  100. self::addResult('Site email', 'error', 'Address "' . $email . '" does not match CLI domain');
  101. } else {
  102. self::addResult('Site email', 'okay', $email);
  103. }
  104. }
  105.  
  106.  
  107. /**
  108.   * Check that each skin has a site title set
  109.   */
  110. public static function testSkinSiteTitle($skin_code)
  111. {
  112. $subsite_config = Subsites::loadConfig($skin_code);
  113.  
  114. if (empty($subsite_config['site_title'])) {
  115. self::addResult('Site title', 'error', 'Not set');
  116. return;
  117. }
  118.  
  119. if ($subsite_config['site_title'] === 'Sprout3 test') {
  120. self::addResult('Site title', 'error', 'Default');
  121. return;
  122. }
  123.  
  124. self::addResult('Site title', 'okay', $subsite_config['site_title']);
  125. }
  126.  
  127.  
  128. /**
  129.   * Check that each skin has Google Analytics configured
  130.   */
  131. public static function testSkinAnalytics($skin_code)
  132. {
  133. $subsite_config = Subsites::loadConfig($skin_code);
  134. if (empty($subsite_config['google_analytics_id'])) {
  135. self::addResult('Google Analytics', 'error', 'Not set');
  136. } else {
  137. self::addResult('Google Analytics', 'okay', $subsite_config['google_analytics_id']);
  138. }
  139. }
  140.  
  141.  
  142. /**
  143.   * Check that each skin has Google Analytics configured
  144.   */
  145. public static function testSkinTemplatesExist($skin_code)
  146. {
  147. $templates = array('home', 'inner', 'wide');
  148. foreach ($templates as $tmpl) {
  149. $exists = file_exists(DOCROOT . "skin/{$skin_code}/{$tmpl}.php");
  150. self::addResult("Template {$tmpl}.php exists", ($exists ? 'okay' : 'error'), '');
  151. }
  152. }
  153.  
  154. }
  155.