Skip to content

Commit

Permalink
PHP7 ready
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrant88 committed Dec 8, 2016
1 parent 857537a commit ad3e68c
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 141 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

Version 1.1.2 – 08.12.2016
--------------------------

* PHP7 ready

Version 1.1 – 13.07.2016
--------------------------
Expand Down
1 change: 1 addition & 0 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions lang/en_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion lib/cleverreach_api_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
11 changes: 6 additions & 5 deletions lib/yform/action/cr_recipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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 ) {
Expand Down
5 changes: 3 additions & 2 deletions package.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand Down
140 changes: 140 additions & 0 deletions pages/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

/** @var rex_addon $this */

//echo rex_view::title($this->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', '<p>' . rex_i18n::msg('lus_cleverreach_infotext') . '</p>', false);
echo $fragment->parse('core/page/section.php');





$content = '<fieldset>';
$formElements = [];

$n = [];
$n['label'] = '<label for="apikey">' . $this->i18n('lus_cleverreach_apikey') . '</label>';
$n['field'] = '<input type="text" id="apikey" name="config[apikey]" size="40" value="' .$this->getConfig("apikey"). '" />';
$formElements[] = $n;

$n = [];
$n['label'] = '<label for="groupid">' . $this->i18n('lus_cleverreach_groupid') . '</label>';
//$n['field'] = '<input type="text" id="groupid" name="config[groupid]" value="' .$this->getConfig('groupid'). '" />';
$n['field'] = implode('<br />',$htmlgroup);
$formElements[] = $n;

$n = [];
$n['label'] = '<label for="formid">' . $this->i18n('lus_cleverreach_formid') . '</label>';
//$n['field'] = '<input type="text" id="formid" name="config[formid]" value="' . $this->getConfig('formid'). '" />';
$n['field'] = implode("\n",$htmlform);
$formElements[] = $n;

$n = [];
$n['label'] = '<label for="source">' . $this->i18n('lus_cleverreach_source') . '</label>';
$n['field'] = '<input type="text" id="source" name="config[source]" size="40" value="' .$this->getConfig('source'). '" />';
$formElements[] = $n;

$fragment = new rex_fragment();
$fragment->setVar('elements', $formElements, false);
$content .= $fragment->parse('core/form/form.php').'</fieldset>';



$formElements = [];
$n = [];
$n['field'] = '<button class="btn btn-save rex-form-aligned" type="submit" name="config-submit" value="1" ' . rex::getAccesskey($this->i18n('lus_cleverreach_config_save'), 'save') . '>' . $this->i18n('lus_cleverreach_config_save') . '</button>';
$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 '
<form action="' . rex_url::currentBackendPage() . '" method="post">
' . $content . '
</form>';
13 changes: 13 additions & 0 deletions pages/help.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$file = rex_file::get(rex_path::addon('lus_cleverreach','README.md'));
$Parsedown = new Parsedown();
$content = '<div id="lus_cleverreach">'.$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');


138 changes: 5 additions & 133 deletions pages/index.php
Original file line number Diff line number Diff line change
@@ -1,138 +1,10 @@
<?php

/** @var rex_addon $this */

echo rex_view::title($this->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', '<p>' . rex_i18n::msg('lus_cleverreach_infotext') . '</p>', false);
echo $fragment->parse('core/page/section.php');


$content = '<fieldset>';

$formElements = [];

$n = [];
$n['label'] = '<label for="apikey">' . $this->i18n('lus_cleverreach_apikey') . '</label>';
$n['field'] = '<input type="text" id="apikey" name="config[apikey]" size="40" value="' .$this->getConfig("apikey"). '" />';
$formElements[] = $n;

$n = [];
$n['label'] = '<label for="groupid">' . $this->i18n('lus_cleverreach_groupid') . '</label>';
//$n['field'] = '<input type="text" id="groupid" name="config[groupid]" value="' .$this->getConfig('groupid'). '" />';
$n['field'] = implode('<br />',$htmlgroup);
$formElements[] = $n;

$n = [];
$n['label'] = '<label for="formid">' . $this->i18n('lus_cleverreach_formid') . '</label>';
//$n['field'] = '<input type="text" id="formid" name="config[formid]" value="' . $this->getConfig('formid'). '" />';
$n['field'] = implode("\n",$htmlform);
$formElements[] = $n;

$n = [];
$n['label'] = '<label for="source">' . $this->i18n('lus_cleverreach_source') . '</label>';
$n['field'] = '<input type="text" id="source" name="config[source]" size="40" value="' .$this->getConfig('source'). '" />';
$formElements[] = $n;


$fragment = new rex_fragment();
$fragment->setVar('elements', $formElements, false);
$content .= $fragment->parse('core/form/form.php');

$formElements = [];

$n = [];
$n['field'] = '<button class="btn btn-save rex-form-aligned" type="submit" name="config-submit" value="1" ' . rex::getAccesskey($this->i18n('lus_cleverreach_config_save'), 'save') . '>' . $this->i18n('lus_cleverreach_config_save') . '</button>';
$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 '
<form action="' . rex_url::currentBackendPage() . '" method="post">
' . $content . '
</form>';
rex_be_controller::includeCurrentPageSubPath();

0 comments on commit ad3e68c

Please sign in to comment.