diff --git a/README.md b/README.md
index 583dc03..3a2472b 100644
--- a/README.md
+++ b/README.md
@@ -12,4 +12,8 @@ Abhängige Extensions
* [MultiColumnWizard](https://contao.org/de/extension-list/view/MultiColumnWizard.html)
-redirect4ward ist auch im offiziellen [Extension-Repository](https://contao.org/de/extension-list/view/Redirect4ward.html) von Contao
\ No newline at end of file
+redirect4ward ist auch im offiziellen [Extension-Repository](https://contao.org/de/extension-list/view/Redirect4ward.html) von Contao
+
+Abhängige Extensions
+--------------------
+url;host;type;jumpToType;jumpTo;externalUrl;rgxp;priority;published
diff --git a/config/config.php b/config/config.php
index 3f21b6b..d702351 100644
--- a/config/config.php
+++ b/config/config.php
@@ -14,6 +14,7 @@
array_insert($GLOBALS['BE_MOD']['system'],2,array(
'redirect4ward' => array(
'tables' => array('tl_redirect4ward'),
+ 'redirectImport' => array('tl_redirect4ward','redirectImport'),
'icon' => 'system/modules/redirect4ward/html/icon.png'
)
));
diff --git a/dca/tl_redirect4ward.php b/dca/tl_redirect4ward.php
index c81b5ce..55a9a35 100644
--- a/dca/tl_redirect4ward.php
+++ b/dca/tl_redirect4ward.php
@@ -47,6 +47,13 @@
'href' => 'act=select',
'class' => 'header_edit_all',
'attributes' => 'onclick="Backend.getScrollOffset();"'
+ ),
+ 'redirectImport' => array
+ (
+ 'label' => &$GLOBALS['TL_LANG']['tl_redirect4ward']['redirectImport'],
+ 'href' => 'key=redirectImport',
+ 'class' => 'header_theme_import',
+ 'attributes' => 'onclick="Backend.getScrollOffset()"'
)
),
'operations' => array
@@ -228,7 +235,14 @@
'default' => '1',
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'w50')
- )
+ ),
+ 'source' => array
+ (
+ 'label' => &$GLOBALS['TL_LANG']['tl_redirect4ward']['source'],
+ 'exclude' => true,
+ 'inputType' => 'fileTree',
+ 'eval' => array('fieldType'=>'radio', 'files'=>true,'filesOnly' => true, 'mandatory'=>true, 'tl_class'=>'clr','extensions' => 'csv')
+ ),
)
);
@@ -427,6 +441,137 @@ public function pagePicker(DataContainer $dc)
{
return ' ' . $this->generateImage('pickpage.gif', $GLOBALS['TL_LANG']['MSC']['pagepicker'], 'style="vertical-align:top;cursor:pointer" onclick="Backend.pickPage(\'ctrl_' . $dc->inputName . '\')"');
}
+
+ /**
+ * import a specified csv file to the database
+ * @return string
+ */
+ public function redirectImport()
+ {
+
+ if ($this->Input->post('FORM_SUBMIT') == 'tl_redirect_import') {
+ $countRedirect = 0;
+ if (file_exists(TL_ROOT . '/' . $this->Input->post('source'))) {
+ $handle = fopen(TL_ROOT . '/' . $this->Input->post('source'), "r");
+ while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
+
+ if ($data[0] != 'url' && strlen($data[0])) {
+ if($this->checkExistingRedirect($data) == 0) {
+ if($data[3] == 'Intern') {
+ if($this->redirectImportPageCheck($data[4]) > 0) {
+ $this->addRedirectData($data);
+ $this->addInfoMessage(sprintf($GLOBALS['TL_LANG']['tl_redirect4ward']['import_success'], $data[0], $data[4]));
+ $countRedirect++;
+ } else {
+ $this->addErrorMessage(sprintf($GLOBALS['TL_LANG']['tl_redirect4ward']['import_error'], $data[0], $data[4]));
+ }
+ } else {
+ $this->addRedirectData($data);
+ $countRedirect++;
+ }
+ } else {
+ $this->addErrorMessage(sprintf($GLOBALS['TL_LANG']['tl_redirect4ward']['import_exist'], $data[0], $data[4]));
+ }
+ }
+ }
+
+ fclose($handle);
+ $this->addInfoMessage(sprintf($GLOBALS['TL_LANG']['tl_redirect4ward']['import_complete'], $countRedirect));
+
+ $this->redirect($this->addToUrl('key='));
+ }
+ }
+ $this->loadDataContainer("tl_redirect4ward");
+ $objTree = new FileTree($this->prepareForWidget($GLOBALS['TL_DCA']['tl_redirect4ward']['fields']['source'], 'source', null, 'source', 'tl_redirect4ward'));
+
+ // Return the form
+ return '
+
+
+
+
+' . $GLOBALS['TL_LANG']['tl_redirect4ward']['redirectImport'][0] . '
+' . $this->getMessages() . '
+';
+
+ }
+
+ /**
+ * check for an existing redirect in the database
+ * @param $arrData
+ * @return mixed
+ */
+ public function checkExistingRedirect($arrData) {
+ $arrData = array(
+ 'url' => $arrData[0],
+ 'host' => $arrData[1],
+ 'type' => $arrData[2],
+ 'jumpToType' => $arrData[3],
+ 'jumpTo' => $arrData[4],
+ 'externalUrl' => $arrData[5],
+ 'rgxp' => $arrData[6],
+ );
+
+ $arrQuery = array();
+ foreach($arrData as $field => $value) {
+ $arrQuery[] = sprintf('%s="%s"', $field, $value);
+ }
+
+ $objRedirect = $this->Database->query("SELECT id FROM tl_redirect4ward Where " . implode(' AND ', $arrQuery));
+
+ return $objRedirect->numRows;
+ }
+
+ /**
+ * add the new redirect to the database
+ * @param $arrData
+ */
+ public function addRedirectData($arrData) {
+ $arrSet = array(
+ 'tstamp' => time(),
+ 'url' => $arrData[0],
+ 'host' => $arrData[1],
+ 'type' => $arrData[2],
+ 'jumpToType' => $arrData[3],
+ 'jumpTo' => $arrData[4],
+ 'externalUrl' => $arrData[5],
+ 'rgxp' => $arrData[6],
+ 'priority' => $arrData[7],
+ 'published' => $arrData[8]
+ );
+
+ $this->Database->prepare("INSERT INTO tl_redirect4ward %s")->set($arrSet)->execute();
+ }
+
+ /**
+ * check whether the redirect page exist
+ * @param $intPage
+ * @return mixed
+ */
+ public function redirectImportPageCheck($intPage) {
+ $objPage = $this->Database->prepare("SELECT id FROM tl_page Where id = ?")->execute($intPage);
+
+ return $objPage->numRows;
+ }
}
?>
diff --git a/languages/de/tl_redirect4ward.php b/languages/de/tl_redirect4ward.php
index 0cdbb9f..c06f825 100644
--- a/languages/de/tl_redirect4ward.php
+++ b/languages/de/tl_redirect4ward.php
@@ -59,5 +59,14 @@
$GLOBALS['TL_LANG']['tl_redirect4ward']['expert_legend'] = 'Weitere Einstellungen';
$GLOBALS['TL_LANG']['tl_redirect4ward']['publish_legend'] = 'Veröffentlichung';
+/**
+ * Import
+ */
+$GLOBALS['TL_LANG']['tl_redirect4ward']['source'] = array('Import Datei','CSV-Datei mit den Redirect-Daten');
+$GLOBALS['TL_LANG']['tl_redirect4ward']['redirectImport'] = array('Weiterleitungen Importieren','');
+$GLOBALS['TL_LANG']['tl_redirect4ward']['import_error'] = 'Die interne Weiterleitung für die URL %s und der Seiten ID %s konnte nicht importiert werden.';
+$GLOBALS['TL_LANG']['tl_redirect4ward']['import_success'] = 'Die Weiterleitung für die URL %s und der Seiten ID %s wurde erfolgreich importiert.';
+$GLOBALS['TL_LANG']['tl_redirect4ward']['import_exist'] = 'Die Weiterleitung für die URL %s und der Seiten ID %s existiert bereits.';
+$GLOBALS['TL_LANG']['tl_redirect4ward']['import_complete'] = 'Es wurden insgesamt %s Weiterleitungen importiert.';
?>
\ No newline at end of file
diff --git a/languages/en/tl_redirect4ward.php b/languages/en/tl_redirect4ward.php
index 77e5c68..aa36a2c 100644
--- a/languages/en/tl_redirect4ward.php
+++ b/languages/en/tl_redirect4ward.php
@@ -58,4 +58,13 @@
$GLOBALS['TL_LANG']['tl_redirect4ward']['expert_legend'] = 'Config';
$GLOBALS['TL_LANG']['tl_redirect4ward']['publish_legend'] = 'Publish settings';
+/**
+ * Import
+ */
+$GLOBALS['TL_LANG']['tl_redirect4ward']['source'] = array('Import File','CSV-File holding the redirect data');
+$GLOBALS['TL_LANG']['tl_redirect4ward']['redirectImport'] = array('Import redirects','');
+$GLOBALS['TL_LANG']['tl_redirect4ward']['import_error'] = array('The internal redirect for the url %s and page id %s could not imported.');
+$GLOBALS['TL_LANG']['tl_redirect4ward']['import_success'] = array('The redirect for the url %s and page id %s was successfully imported.');
+$GLOBALS['TL_LANG']['tl_redirect4ward']['import_exist'] = array('The redirect for the url %s and page id %s already.');
+$GLOBALS['TL_LANG']['tl_redirect4ward']['import_complete'] = array('%s redirect were imported successfully.');
?>
\ No newline at end of file