From ad3e68ce7b088a57c956e7c8d0deaa70cb399f68 Mon Sep 17 00:00:00 2001 From: tyrant88 Date: Thu, 8 Dec 2016 11:09:20 +0100 Subject: [PATCH] PHP7 ready --- CHANGELOG.md | 4 + lang/de_de.lang | 1 + lang/en_en.lang | 1 + lib/cleverreach_api_helper.php | 2 +- lib/yform/action/cr_recipient.php | 11 +-- package.yml | 5 +- pages/config.php | 140 ++++++++++++++++++++++++++++++ pages/help.php | 13 +++ pages/index.php | 138 ++--------------------------- 9 files changed, 174 insertions(+), 141 deletions(-) create mode 100644 pages/config.php create mode 100644 pages/help.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9842681..5aeca7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +Version 1.1.2 – 08.12.2016 +-------------------------- + +* PHP7 ready Version 1.1 – 13.07.2016 -------------------------- diff --git a/lang/de_de.lang b/lang/de_de.lang index 09e9128..e1fe47b 100644 --- a/lang/de_de.lang +++ b/lang/de_de.lang @@ -2,6 +2,7 @@ lus_cleverreach_title = cleverreach lus_cleverreach_config = Einstellungen +lus_cleverreach_help = Hilfe lus_cleverreach_config_save = Einstellungen speichern lus_cleverreach_config_saved = Einstellungen wurden aktualisiert. lus_cleverreach_config_not_saved = Einstellungen konnte nicht gespeichert werden! diff --git a/lang/en_en.lang b/lang/en_en.lang index ddb2dd0..060a8ed 100644 --- a/lang/en_en.lang +++ b/lang/en_en.lang @@ -2,6 +2,7 @@ lus_cleverreach_title = cleverreach lus_cleverreach_config = Configuration +lus_cleverreach_help = Help lus_cleverreach_config_save = Save settings lus_cleverreach_config_saved = Settings were updated. lus_cleverreach_config_not_saved = Settings could not be saved! diff --git a/lib/cleverreach_api_helper.php b/lib/cleverreach_api_helper.php index ac5ed70..84b5b0d 100644 --- a/lib/cleverreach_api_helper.php +++ b/lib/cleverreach_api_helper.php @@ -52,7 +52,7 @@ public function getApi() return $this->api; } - public function CleverreachAPI($apikey = null) + public function __construct($apikey = null) { if (!empty($apikey)) { $this->setApikey(trim($apikey)); diff --git a/lib/yform/action/cr_recipient.php b/lib/yform/action/cr_recipient.php index ced8e94..0c5abc5 100644 --- a/lib/yform/action/cr_recipient.php +++ b/lib/yform/action/cr_recipient.php @@ -40,9 +40,10 @@ function execute() } } + $attributes = array(); if ($this->getElement(4) != '') { $fields = explode( ',',$this->getElement(4)); - $attributes = array(); + foreach ($this->params['value_pool']['sql'] as $key => $value) { if (in_array($key, $fields)) { $attributes[] = array('key'=>$key, 'value'=>$value); @@ -60,7 +61,7 @@ function execute() // define fromid $api->setFormid($formid); - $errormsg = $this->i18n('lus_cleverreach_api_failure'); + $errormsg = rex_i18n::translate('lus_cleverreach_api_failure'); if ($action == "1") { // add resipient @@ -69,18 +70,18 @@ function execute() // remove resipient $result = $api->removeRecipient($email); } else { - $errormsg = $this->i18n('lus_cleverreach_add_remove'); + $errormsg = rex_i18n::translate('lus_cleverreach_add_remove'); } if ($result->status === 'SUCCESS') { - //$errormsg = $this->i18n('lus_cleverreach_api_success'); + //$errormsg = rex_i18n::translate('lus_cleverreach_api_success'); } else { $error = true; if ($result->message != '') { $errormsg .= ': '. $result->message; } } } elseif (!empty($email) && !$error) { $error == true; - $errormsg = $this->i18n('lus_cleverreach_config_failure'); + $errormsg = rex_i18n::translate('lus_cleverreach_config_failure'); } if ( $error == true ) { diff --git a/package.yml b/package.yml index 5402ad3..aecb83f 100644 --- a/package.yml +++ b/package.yml @@ -1,7 +1,7 @@ # Alle hier gesetzten Werte können über $addon->getProperty($key) abgefragt werden package: lus_cleverreach # Pflichtfeld -version: '1.1' # Pflichtfeld +version: '1.1.2' # Pflichtfeld author: Laut und Schoen supportpage: https://github.com/tyrant88/lus_cleverreach @@ -11,7 +11,8 @@ page: perm: admin[] icon: rex-icon fa-envelope-o subpages: - main: { title: 'translate:lus_cleverreach_config' } + config: { title: 'translate:lus_cleverreach_config' } + help: { title: 'translate:lus_cleverreach_help' } requires: packages: diff --git a/pages/config.php b/pages/config.php new file mode 100644 index 0000000..7fe51ed --- /dev/null +++ b/pages/config.php @@ -0,0 +1,140 @@ +i18n('lus_cleverreach_title')); + +if (rex_post('config-submit', 'boolean')) { + $this->setConfig(rex_post('config', [ + ['apikey', 'string'], + ['groupid', 'string'], + ['formid', 'string'], + ['source', 'string'], + ])); + + echo rex_view::success($this->i18n('lus_cleverreach_config_saved')); +} +$apikey = $this->getConfig("apikey"); +$groupid = $this->getConfig("groupid"); +$formid = $this->getConfig("formid"); +$source = $this->getConfig("source"); + +$htmlgroup = array(); +$htmlform = array(); +$selectgroupid = new rex_select(); +$selectformid = new rex_select(); + +if ( empty($apikey) ) { + $htmlgroup[] = $this->i18n('lus_cleverreach_select_apikey'); +} else { + try { + $api = new CleverreachAPI($apikey); + $result = $api->getGroupList(); + $selectgroupid->setSize(1); + $selectgroupid->setName('config[groupid]'); + if ( !empty($groupid) ) { $selectgroupid->setSelected($groupid); } + + if ($result != false && $result->status == "SUCCESS") { + $selectgroupid->addOption($this->i18n('lus_cleverreach_select_groupid'),-1); + foreach ($result->data as $dataset) { + $selectgroupid->addOption( $dataset->name, $dataset->id); + } + $htmlgroup[] = $selectgroupid->get(); + } else { + $htmlgroup[] = $this->i18n('lus_cleverreach_groupid_failure'); + } + + } catch (Exception $e) { + $htmlgroup[] = $this->i18n('lus_cleverreach_api_failure'); + } + +} +if (empty($groupid)) { + $htmlform[] = $this->i18n('lus_cleverreach_select_groupid'); +} else { + if (!empty($apikey)) { + try { + $api = new CleverreachAPI($apikey); + $result = $api->getFormsList($groupid); + $selectformid->setSize(1); + $selectformid->setName('config[formid]'); + if ( !empty($formid) ) {$selectformid->setSelected($formid); } + + if ($result != false && $result->status == "SUCCESS") { + $selectformid->addOption($this->i18n('lus_cleverreach_select_formid'), -1); + foreach ($result->data as $dataset) { + $selectformid->addOption($dataset->name, $dataset->id); + } + $htmlform[] = $selectformid->get(); + } else { + $htmlform[] = $this->i18n('lus_cleverreach_formid_failure'); + } + + } catch (Exception $e) { + $htmlform[] = $this->i18n('lus_cleverreach_api_failure'); + } + } +} + +$fragment = new rex_fragment(); +$fragment->setVar('class', 'info', false); +$fragment->setVar('title', rex_i18n::msg('lus_cleverreach_info'), false); +$fragment->setVar('body', '

' . rex_i18n::msg('lus_cleverreach_infotext') . '

', false); +echo $fragment->parse('core/page/section.php'); + + + + + +$content = '
'; +$formElements = []; + +$n = []; +$n['label'] = ''; +$n['field'] = ''; +$formElements[] = $n; + +$n = []; +$n['label'] = ''; +//$n['field'] = ''; +$n['field'] = implode('
',$htmlgroup); +$formElements[] = $n; + +$n = []; +$n['label'] = ''; +//$n['field'] = ''; +$n['field'] = implode("\n",$htmlform); +$formElements[] = $n; + +$n = []; +$n['label'] = ''; +$n['field'] = ''; +$formElements[] = $n; + +$fragment = new rex_fragment(); +$fragment->setVar('elements', $formElements, false); +$content .= $fragment->parse('core/form/form.php').'
'; + + + +$formElements = []; +$n = []; +$n['field'] = ''; +$formElements[] = $n; +$fragment = new rex_fragment(); +$fragment->setVar('flush', true); +$fragment->setVar('elements', $formElements, false); +$buttons = $fragment->parse('core/form/submit.php'); + + +$fragment = new rex_fragment(); +$fragment->setVar('class', 'edit'); +$fragment->setVar('title', $this->i18n('lus_cleverreach_config')); +$fragment->setVar('body', $content, false); +$fragment->setVar('buttons', $buttons, false); +$content = $fragment->parse('core/page/section.php'); + +echo ' +
+ ' . $content . ' +
'; diff --git a/pages/help.php b/pages/help.php new file mode 100644 index 0000000..982e4e3 --- /dev/null +++ b/pages/help.php @@ -0,0 +1,13 @@ +'.$Parsedown->text($file); + +$fragment = new rex_fragment(); +$fragment->setVar('title', $this->i18n('title')); +$fragment->setVar('class', 'info', false); +$fragment->setVar('body', $content, false); +echo $fragment->parse('core/page/section.php'); + + diff --git a/pages/index.php b/pages/index.php index 9e83eb2..1e9c527 100644 --- a/pages/index.php +++ b/pages/index.php @@ -1,138 +1,10 @@ i18n('lus_cleverreach_title')); +/** + * @package redaxo5 + */ -if (rex_post('config-submit', 'boolean')) { - $this->setConfig(rex_post('config', [ - ['apikey', 'string'], - ['groupid', 'string'], - ['formid', 'string'], - ['source', 'string'], - ])); +echo rex_view::title(rex_i18n::msg('lus_cleverreach_title')); - echo rex_view::success($this->i18n('lus_cleverreach_config_saved')); -} -$apikey = $this->getConfig("apikey"); -$groupid = $this->getConfig("groupid"); -$formid = $this->getConfig("formid"); -$source = $this->getConfig("source"); - -$htmlgroup = array(); -$htmlform = array(); -$selectgroupid = new rex_select(); -$selectformid = new rex_select(); - -if ( empty($apikey) ) { - $htmlgroup[] = $this->i18n('lus_cleverreach_select_apikey'); -} else { - try { - $api = new CleverreachAPI($apikey); - $result = $api->getGroupList(); - $selectgroupid->setSize(1); - $selectgroupid->setName('config[groupid]'); - if ( !empty($groupid) ) { $selectgroupid->setSelected($groupid); } - - if ($result != false && $result->status == "SUCCESS") { - $selectgroupid->addOption($this->i18n('lus_cleverreach_select_groupid'),-1); - foreach ($result->data as $dataset) { - $selectgroupid->addOption( $dataset->name, $dataset->id); - } - $htmlgroup[] = $selectgroupid->get(); - } else { - $htmlgroup[] = $this->i18n('lus_cleverreach_groupid_failure'); - } - - } catch (Exception $e) { - $htmlgroup[] = $this->i18n('lus_cleverreach_api_failure'); - } - -} -if (empty($groupid)) { - $htmlform[] = $this->i18n('lus_cleverreach_select_groupid'); -} else { - if (!empty($apikey)) { - try { - $api = new CleverreachAPI($apikey); - $result = $api->getFormsList($groupid); - $selectformid->setSize(1); - $selectformid->setName('config[formid]'); - if ( !empty($formid) ) {$selectformid->setSelected($formid); } - - if ($result != false && $result->status == "SUCCESS") { - $selectformid->addOption($this->i18n('lus_cleverreach_select_formid'), -1); - foreach ($result->data as $dataset) { - $selectformid->addOption($dataset->name, $dataset->id); - } - $htmlform[] = $selectformid->get(); - } else { - $htmlform[] = $this->i18n('lus_cleverreach_formid_failure'); - } - - } catch (Exception $e) { - $htmlform[] = $this->i18n('lus_cleverreach_api_failure'); - } - } -} - -$fragment = new rex_fragment(); -$fragment->setVar('class', 'info', false); -$fragment->setVar('title', rex_i18n::msg('lus_cleverreach_info'), false); -$fragment->setVar('body', '

' . rex_i18n::msg('lus_cleverreach_infotext') . '

', false); -echo $fragment->parse('core/page/section.php'); - - -$content = '
'; - -$formElements = []; - -$n = []; -$n['label'] = ''; -$n['field'] = ''; -$formElements[] = $n; - -$n = []; -$n['label'] = ''; -//$n['field'] = ''; -$n['field'] = implode('
',$htmlgroup); -$formElements[] = $n; - -$n = []; -$n['label'] = ''; -//$n['field'] = ''; -$n['field'] = implode("\n",$htmlform); -$formElements[] = $n; - -$n = []; -$n['label'] = ''; -$n['field'] = ''; -$formElements[] = $n; - - -$fragment = new rex_fragment(); -$fragment->setVar('elements', $formElements, false); -$content .= $fragment->parse('core/form/form.php'); - -$formElements = []; - -$n = []; -$n['field'] = ''; -$formElements[] = $n; - -$fragment = new rex_fragment(); -$fragment->setVar('flush', true); -$fragment->setVar('elements', $formElements, false); -$buttons = $fragment->parse('core/form/submit.php'); - -$fragment = new rex_fragment(); -$fragment->setVar('class', 'edit'); -$fragment->setVar('title', $this->i18n('lus_cleverreach_config')); -$fragment->setVar('body', $content, false); -$fragment->setVar('buttons', $buttons, false); -$content = $fragment->parse('core/page/section.php'); - -echo ' -
- ' . $content . ' -
'; +rex_be_controller::includeCurrentPageSubPath();