Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Redactor Settings in Profilen anpassen (#170)
Browse files Browse the repository at this point in the history
* Redactor settings in Profile anpassen

* Datentyp der Settings bestimmen

* i18n fuer Settings hinzufuegen

* Spanische Uebersetzung fuer Settings ergaenzt

* Typo fix

* Package-Version anpassen

* Settings beim Duplizieren uebernehmen
  • Loading branch information
rbergm authored Oct 16, 2020
1 parent a6f47dd commit cc4dc83
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 6 deletions.
5 changes: 3 additions & 2 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
->ensureColumn(new rex_sql_column('linkify', 'tinyint(1)'))
->ensureColumn(new rex_sql_column('imagetag', 'text'))
->ensureColumn(new rex_sql_column('redactor_plugins', 'text'))
->ensureColumn(new rex_sql_column('redactor_settings', 'text'))
->ensure();

rex_sql::factory()->setQuery('INSERT IGNORE INTO '.rex::getTable('redactor2_profiles').' (`id`, `name`, `description`, `minheight`, `maxheight`, `characterlimit`, `urltype`, `externalurltarget`, `shortcuts`, `linkify`, `imagetag`, `redactor_plugins`) VALUES
(1, "full", "Standard Redactor-Konfiguration", "300", "800", "0", "relative", "blank", "0", "1", "", "anchorlink,alignment,blockquote,bold,cleaner,clips[Snippetname1=Snippettext1|Snippetname2=Snippettext2],deleted,emaillink,externallink,fontcolor[Weiss=#ffffff|Schwarz=#000000],fontfamily[Arial|Times],fontsize[12px|15pt|120%],format[Absatz Klein=p.small|Absatz Mittel=p.middle|Absatz Gross=p.big],fullscreen,groupheading[1|2|3|4|5|6],grouplink[email|external|internal|media|telephone],grouplist[unorderedlist|orderedlist|indent|outdent],heading1,heading2,heading3,heading4,heading5,heading6,horizontalrule,internallink,italic,media,medialink,orderedlist,paragraph,properties,redo,source,styles[code=Code|kbd=Shortcut|mark=Markiert|samp=Sample|var=Variable],sub,sup,table,telephonelink,textdirection,underline,undo,unorderedlist");');
rex_sql::factory()->setQuery('INSERT IGNORE INTO '.rex::getTable('redactor2_profiles').' (`id`, `name`, `description`, `minheight`, `maxheight`, `characterlimit`, `urltype`, `externalurltarget`, `shortcuts`, `linkify`, `imagetag`, `redactor_plugins`, `redactor_settings`) VALUES
(1, "full", "Standard Redactor-Konfiguration", "300", "800", "0", "relative", "blank", "0", "1", "", "anchorlink,alignment,blockquote,bold,cleaner,clips[Snippetname1=Snippettext1|Snippetname2=Snippettext2],deleted,emaillink,externallink,fontcolor[Weiss=#ffffff|Schwarz=#000000],fontfamily[Arial|Times],fontsize[12px|15pt|120%],format[Absatz Klein=p.small|Absatz Mittel=p.middle|Absatz Gross=p.big],fullscreen,groupheading[1|2|3|4|5|6],grouplink[email|external|internal|media|telephone],grouplist[unorderedlist|orderedlist|indent|outdent],heading1,heading2,heading3,heading4,heading5,heading6,horizontalrule,internallink,italic,media,medialink,orderedlist,paragraph,properties,redo,source,styles[code=Code|kbd=Shortcut|mark=Markiert|samp=Sample|var=Variable],sub,sup,table,telephonelink,textdirection,underline,undo,unorderedlist", "");');
2 changes: 2 additions & 0 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ redactor2_profiles_label_linkify_option_false = Nein
redactor2_profiles_label_imagetag = HTML-Tag um Bilder<br><i>z.B. p oder figure</i>
redactor2_profiles_label_redactorplugins = Plugins
redactor2_profiles_label_redactorcustomplugins_help = Bitte eigene Plugins über das ProjektAddon einbinden. Eigene Javascripte entsprechend über den Extension Point `PACKAGES_INCLUDED` und Level `rex_extension::LATE` einbinden
redactor2_profiles_label_redactorsettings = Settings
redactor2_profiles_label_redactorsettings_help = Format: <code>key: val</code> Unterschiedliche Settings durch Zeilenumbruch trennen.

redactor2_profiles_plugins_anchorlink_description = Fügt einen Anker-Link ein
redactor2_profiles_plugins_alignment_description = Setzt die Ausrichtung des markierten Texts
Expand Down
3 changes: 2 additions & 1 deletion lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ redactor2_profiles_label_linkify_option_false = No
redactor2_profiles_label_imagetag = HTML-Tag around images<br><i>e.g. p or figure</i>
redactor2_profiles_label_redactorplugins = Plugins
redactor2_profiles_label_redactorcustomplugins_help = Include your plugins via your projectaddon. Please include your Javascript with the Extension Point `PACKAGES_INCLUDED` and level `rex_extension::LATE`

redactor2_profiles_label_redactorsettings = Settings
redactor2_profiles_label_redactorsettings_help = Format: <code>key: val</code> Use one line per setting.

redactor2_profiles_plugins_anchorlink_description = Inserts an anchor link
redactor2_profiles_plugins_alignment_description = Changes the alignment of the highlighted text
Expand Down
2 changes: 2 additions & 0 deletions lang/es_es.lang
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ redactor2_profiles_label_linkify_option_false = No
redactor2_profiles_label_imagetag = Etiqueta HTML para imágenes <br> <i> z. p o figura </ i>
redactor2_profiles_label_redactorplugins = Plugins
redactor2_profiles_label_redactorcustomplugins_help = Incluya sus complementos a través de su proyecto. Incluya su Javascript con el Punto de Extensión `PACKAGES_INCLUDED` y el nivel `rex_extension::LATE`
redactor2_profiles_label_redactorsettings = Settings
redactor2_profiles_label_redactorsettings_help = Formato: <code>key: val</code> Usa una linea por configuración.

redactor2_profiles_plugins_anchorlink_description = Inserta un enlace de anclaje
redactor2_profiles_plugins_alignment_description = Establece la alineación del texto seleccionado
Expand Down
40 changes: 39 additions & 1 deletion lib/class.redactor2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class redactor2
{
public static function insertProfile($name, $description = '', $minheight = '300', $maxheight = '800', $urltype = 'relative', $characterlimit = 0, $toolbarfixed = 0, $shortcuts = 0, $linkify = 1, $redactorPlugins = '')
public static function insertProfile($name, $description = '', $minheight = '300', $maxheight = '800', $urltype = 'relative', $characterlimit = 0, $toolbarfixed = 0, $shortcuts = 0, $linkify = 1, $redactorPlugins = '', $redactor_settings = '')
{
$sql = rex_sql::factory();
$sql->setTable(rex::getTablePrefix().'redactor2_profiles');
Expand All @@ -17,6 +17,7 @@ public static function insertProfile($name, $description = '', $minheight = '300
$sql->setValue('shortcuts', $shortcuts);
$sql->setValue('linkify', $linkify);
$sql->setValue('redactor_plugins', $redactorPlugins);
$sql->setValue('redactor_settings', $redactor_settings);

try {
$sql->insert();
Expand Down Expand Up @@ -104,6 +105,43 @@ public static function createJavascriptFile()
}
}

if (trim($profile['redactor_settings']) != '') {
$settings = explode("\n", $profile['redactor_settings']);
foreach ($settings as $setting) {
$matches = null;
if (preg_match('/(.*):\W?(.*)/', $setting, $matches)) {
$settingKey = trim($matches[1]);
$settingVal = trim($matches[2]);

// determine the dtype of the setting
if ($settingVal == 'true') { // bool
$settingVal = true;
} elseif ($settingVal == 'false') { // bool
$settingVal = false;
} elseif (ctype_digit($settingVal)) { // int
$settingVal = intval($settingVal);
} elseif (is_numeric($settingVal)) { // float
$settingVal = floatval($settingVal);
} elseif (preg_match('/\[(.*)\]/', $settingVal, $matches)) { // array
$settingVal = explode(',', $matches[1]);
foreach ($settingVal as $i => $val) {
$val = trim($val);

// drop surrounding braces
if (preg_match('/["\'](.*)["\']/', $val, $matches)) {
$val = $matches[1];
}
$settingVal[$i] = $val;
}
} else {
// just assume string and leave the val as it is
}

$profiles[$name][$settingKey] = $settingVal;
}
}
}

$profiles[$name]['buttons'] = [];
$profiles[$name]['plugins'] = $redactorPlugins;

Expand Down
2 changes: 1 addition & 1 deletion package.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package: redactor2
version: '4.0.3'
version: '4.1.0'
author: Friends Of REDAXO
supportpage: github.com/FriendsOfREDAXO/redactor2

Expand Down
15 changes: 14 additions & 1 deletion pages/profiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$sql = rex_sql::factory();

try {
$sql->setQuery('INSERT INTO '.rex::getTablePrefix() . 'redactor2_profiles (name, description, urltype, externalurltarget, minheight, maxheight, characterlimit, toolbarfixed, shortcuts, linkify, imagetag, redactor_plugins) SELECT name, description, urltype, externalurltarget, minheight, maxheight, characterlimit, toolbarfixed, shortcuts, linkify, imagetag, redactor_plugins FROM '.rex::getTablePrefix() . 'redactor2_profiles WHERE id = ?', [$profile_id]);
$sql->setQuery('INSERT INTO '.rex::getTablePrefix() . 'redactor2_profiles (name, description, urltype, externalurltarget, minheight, maxheight, characterlimit, toolbarfixed, shortcuts, linkify, imagetag, redactor_plugins, redactor_settings) SELECT name, description, urltype, externalurltarget, minheight, maxheight, characterlimit, toolbarfixed, shortcuts, linkify, imagetag, redactor_plugins, redactor_settings FROM '.rex::getTablePrefix() . 'redactor2_profiles WHERE id = ?', [$profile_id]);
$success = $this->i18n('profiles_message_copy_success');
} catch (rex_sql_exception $e) {
$error = $sql->getError();
Expand Down Expand Up @@ -284,6 +284,19 @@
</dl>
');

$field = $form->addTextAreaField('redactor_settings');
$field->setLabel($this->i18n('profiles_label_redactorsettings'));
$field = $form->addRawField('
<dl class="rex-form-group form-group">
<dt>
&nbsp;
</dt>
<dd>
<p>'.$this->i18n('profiles_label_redactorsettings_help').'</p>
</dd>
</dl>
');

if ($func == 'edit') {
$form->addParam('id', $id);
}
Expand Down

0 comments on commit cc4dc83

Please sign in to comment.