// If the form was submitted, take appropriate action.
if (!empty($_POST['revert'])) {
self::deleteConfigFile($this->preset);
+ self::setConfigDefault();
}
elseif (!empty($_POST['config'])) {
$this->save($_POST);
* @param array $params
*/
public function save($params) {
- $config = "/**\n"
- . " * CKEditor config file auto-generated by CiviCRM.\n"
- . " *\n"
- . " * Note: This file will be overwritten if settings are modified at:\n"
- . " * @link " . CRM_Utils_System::url(CRM_Utils_System::currentPath(), NULL, TRUE, NULL, FALSE) . "\n"
- . " */\n\n"
+ $config = self::fileHeader()
// Standardize line-endings
. preg_replace('~\R~u', "\n", $params['config']);
}
}
+ /**
+ * Create default config file if it doesn't exist
+ */
+ public static function setConfigDefault() {
+ if (!self::getConfigFile()) {
+ $config = self::fileHeader() . "CKEDITOR.editorConfig = function( config ) {\n\tconfig.allowedContent = true;\n};\n";
+ // Make sure directories exist
+ if (!is_dir(Civi::paths()->getPath('[civicrm.files]/persist'))) {
+ mkdir(Civi::paths()->getPath('[civicrm.files]/persist'));
+ }
+ $newFileName = Civi::paths()->getPath('[civicrm.files]/persist/crm-ckeditor-default.js');
+ file_put_contents($newFileName, $config);
+ }
+ }
+
+ /**
+ * @return string
+ */
+ public static function fileHeader() {
+ return "/**\n"
+ . " * CKEditor config file auto-generated by CiviCRM (" . date('Y-m-d H:i:s') . ").\n"
+ . " *\n"
+ . " * Note: This file will be overwritten if settings are modified at:\n"
+ . " * @link " . CRM_Utils_System::url('civicrm/admin/ckeditor', NULL, TRUE, NULL, FALSE) . "\n"
+ . " */\n";
+ }
+
}
$setting = "\n\tconfig.allowedContent = true;\n";
$config = substr_replace($config, $setting, $pos, 0);
unlink($fileName);
+ $newFileName = Civi::paths()->getPath('[civicrm.files]/persist/crm-ckeditor-default.js');
+ file_put_contents($newFileName, $config);
}
- // Create config file if it doesn't exist
- else {
- $config = "CKEDITOR.editorConfig = function( config ) {\n\tconfig.allowedContent = true;\n};\n";
- // Make sure directories exist
- if (!is_dir(Civi::paths()->getPath('[civicrm.files]'))) {
- mkdir(Civi::paths()->getPath('[civicrm.files]'));
- }
- if (!is_dir(Civi::paths()->getPath('[civicrm.files]/persist'))) {
- mkdir(Civi::paths()->getPath('[civicrm.files]/persist'));
- }
- }
- $newFileName = Civi::paths()->getPath('[civicrm.files]/persist/crm-ckeditor-default.js');
- file_put_contents($newFileName, $config);
return TRUE;
}