| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License and the CiviCRM Licensing Exception along | |
| 21 | | with this program; if not, contact CiviCRM LLC | |
| 22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 25 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * This class generates form components for Miscellaneous. |
| 36 | */ |
| 37 | class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting { |
| 38 | |
| 39 | protected $_settings = array( |
| 40 | 'max_attachments' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 41 | 'contact_undelete' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 42 | 'versionAlert' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 43 | 'securityUpdateAlert' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 44 | 'versionCheck' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 45 | 'versionCheckIgnoreDate' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 46 | 'empoweredBy' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 47 | 'logging' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 48 | 'maxFileSize' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 49 | 'doNotAttachPDFReceipt' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 50 | 'secondDegRelPermissions' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 51 | 'checksumTimeout' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, |
| 52 | ); |
| 53 | |
| 54 | public $_uploadMaxSize; |
| 55 | |
| 56 | /** |
| 57 | * Basic setup. |
| 58 | */ |
| 59 | public function preProcess() { |
| 60 | $config = CRM_Core_Config::singleton(); |
| 61 | $this->_uploadMaxSize = (int) ini_get('upload_max_filesize'); |
| 62 | // check for post max size |
| 63 | CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Build the form object. |
| 68 | */ |
| 69 | public function buildQuickForm() { |
| 70 | CRM_Utils_System::setTitle(ts('Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.)')); |
| 71 | |
| 72 | $this->assign('validTriggerPermission', CRM_Core_DAO::checkTriggerViewPermission(FALSE)); |
| 73 | |
| 74 | $this->addElement( |
| 75 | 'text', |
| 76 | 'wkhtmltopdfPath', ts('Path to wkhtmltopdf executable'), |
| 77 | array('size' => 64, 'maxlength' => 256) |
| 78 | ); |
| 79 | |
| 80 | $this->addElement( |
| 81 | 'text', 'recaptchaPublicKey', ts('Public Key'), |
| 82 | array('size' => 64, 'maxlength' => 64) |
| 83 | ); |
| 84 | $this->addElement( |
| 85 | 'text', 'recaptchaPrivateKey', ts('Private Key'), |
| 86 | array('size' => 64, 'maxlength' => 64) |
| 87 | ); |
| 88 | |
| 89 | $this->addElement( |
| 90 | 'text', 'dashboardCacheTimeout', ts('Dashboard cache timeout'), |
| 91 | array('size' => 3, 'maxlength' => 5) |
| 92 | ); |
| 93 | |
| 94 | $this->addElement( |
| 95 | 'text', 'recaptchaOptions', ts('Recaptcha Options'), |
| 96 | array('size' => 64, 'maxlength' => 64) |
| 97 | ); |
| 98 | |
| 99 | $this->addFormRule(array('CRM_Admin_Form_Setting_Miscellaneous', 'formRule'), $this); |
| 100 | |
| 101 | parent::buildQuickForm(); |
| 102 | $this->addRule('checksumTimeout', ts('Value should be a positive number'), 'positiveInteger'); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Global form rule. |
| 107 | * |
| 108 | * @param array $fields |
| 109 | * The input form values. |
| 110 | * @param array $files |
| 111 | * The uploaded files if any. |
| 112 | * @param array $options |
| 113 | * Additional user data. |
| 114 | * |
| 115 | * @return bool|array |
| 116 | * true if no errors, else array of errors |
| 117 | */ |
| 118 | public static function formRule($fields, $files, $options) { |
| 119 | $errors = array(); |
| 120 | |
| 121 | // validate max file size |
| 122 | if ($fields['maxFileSize'] > $options->_uploadMaxSize) { |
| 123 | $errors['maxFileSize'] = ts("Maximum file size cannot exceed Upload max size ('upload_max_filesize') as defined in PHP.ini."); |
| 124 | } |
| 125 | |
| 126 | if (!empty($fields['wkhtmltopdfPath'])) { |
| 127 | // check and ensure that thi leads to the wkhtmltopdf binary |
| 128 | // and it is a valid executable binary |
| 129 | // Only check the first space separated piece to allow for a value |
| 130 | // such as /usr/bin/xvfb-run -- wkhtmltopdf (CRM-13292) |
| 131 | $pieces = explode(' ', $fields['wkhtmltopdfPath']); |
| 132 | $path = $pieces[0]; |
| 133 | if ( |
| 134 | !file_exists($path) || |
| 135 | !is_executable($path) |
| 136 | ) { |
| 137 | $errors['wkhtmltopdfPath'] = ts('The wkhtmltodfPath does not exist or is not valid'); |
| 138 | } |
| 139 | } |
| 140 | return $errors; |
| 141 | } |
| 142 | |
| 143 | } |