So, wenns geht, sollte man das erstmal testen.
1. In contenido/includes eine Datei namens include.recipients_import.php anlegen und mit folgendem Code füllen:
Code: Alles auswählen
<?php
/*****************************************
* File : $RCSfile: include.recipients_import.php,v $
* Project : Contenido
* Descr : Frontend user editor
* Modified : $Date: 2005/12/11 18:48:25 $
*
* © four for business AG, www.4fb.de, generated by HerrB
*
* $Id: include.recipients_import.php,v 1.3 2005/12/11 18:48:25 bbehrens Exp $
******************************************/
cInclude("classes", "widgets/class.widgets.page.php");
cInclude("classes", "class.ui.php");
cInclude("classes", "class.htmlelements.php");
cInclude("classes", "class.newsletter.recipients.php");
$oPage = new cPage;
$oRecipients = new RecipientCollection;
if (is_array($cfg['plugins']['recipients'])) {
foreach ($cfg['plugins']['recipients'] as $plugin) {
plugin_include("recipients", $plugin."/".$plugin.".php");
}
}
$aFields = array();
$aFieldDetails = array();
$aFields["name"] = strtolower(i18n("Name"));
$aFieldDetails["name"]["mandatory"] = false;
$aFieldDetails["name"]["type"] = "string";
$aFieldDetails["name"]["plugin"] = false;
$aFieldDetails["name"]["col"] = -1;
$aFields["email"] = strtolower(i18n("Mail"));
$aFieldDetails["email"]["mandatory"] = true;
$aFieldDetails["email"]["type"] = "string";
$aFieldDetails["email"]["plugin"] = false;
$aFieldDetails["email"]["col"] = -1;
$aFields["deactivated"] = strtolower(i18n("Deactivated"));
$aFieldDetails["active"]["mandatory"] = false;
$aFieldDetails["active"]["type"] = "boolean";
$aFieldDetails["active"]["plugin"] = false;
$aFieldDetails["active"]["col"] = -1;
$aFields["confirmed"] = strtolower(i18n("Confirmed"));
$aFieldDetails["confirmed"]["mandatory"]= false;
$aFieldDetails["confirmed"]["type"] = "boolean";
$aFieldDetails["confirmed"]["plugin"] = false;
$aFieldDetails["confirmed"]["col"] = -1;
$aFields["confirmeddate"] = strtolower(i18n("Confirmed Date"));
$aFieldDetails["confirmeddate"]["mandatory"]= false;
$aFieldDetails["confirmeddate"]["type"] = "string";
$aFieldDetails["confirmeddate"]["plugin"] = false;
$aFieldDetails["confirmeddate"]["col"] = -1;
/* Check out if there are any plugins */
if (is_array($cfg['plugins']['recipients'])) {
foreach ($cfg['plugins']['recipients'] as $sPlugin) {
if (function_exists("recipients_".$sPlugin."_wantedVariables") && function_exists("recipients_".$sPlugin."_store")) {
$aPluginTitles = call_user_func("recipients_".$sPlugin."_canonicalVariables");
$aPluginFields = call_user_func("recipients_".$sPlugin."_wantedVariables");
foreach ($aPluginFields as $sField) {
if ($_REQUEST["ckb".$sField]) {
$aFields[$sField] = strtolower(str_replace(" ","", $aPluginTitles[$sField]));
$aFieldDetails[$sField]["mandatory"]= true;
$aFieldDetails[$sField]["type"] = "string";
$aFieldDetails[$sField]["plugin"] = $sPlugin;
$aFieldDetails[$sField]["col"] = -1;
}
}
}
}
}
if ($action == "recipients_import_exec" && $perm->have_perm_area_action("recipients", "recipients_create")) {
$_REQUEST["txtData"] = trim(stripslashes($_REQUEST["txtData"]));
if ($_REQUEST["txtData"]) {
//echo "<pre>".nl2br(stripslashes($_REQUEST["txtData"]))."</pre>";
$aLines = explode("\n", stripslashes($_REQUEST["txtData"]));
$iAdded = 0;
$iDublettes = 0;
$iInvalid = 0;
$iRow = 0;
$iCol = 0;
$bStop = false;
$sMessage = "";
$aMessage = array();
$aInvalidLines = array();
foreach($aLines as $sLine) {
$iRow++;
$aParts = explode(chr(9), trim($sLine));
if ($iRow == 1) {
$aInvalidLines[] = $sLine;
foreach ($aParts as $sHeader) {
$sKey = array_search(strtolower(htmlentities(trim($sHeader))), $aFields);
if ($sKey === false) {
$aMessage[] = sprintf(mi18n("Given column header '%s' unknown, column ignored"), $sHeader);
} else {
$aFieldDetails[$sKey]["col"] = $iCol;
$iCol++;
}
}
foreach ($aFieldDetails as $sKey => $aDetails) {
if ($aDetails["mandatory"] && $aDetails["col"] == -1) {
$aMessage[] = sprintf(mi18n("Mandatory column '%s' wasn't found, import stopped"), $aDetails[$sKey]);
$bStop = true;
}
}
if ($bStop) {
exit;
} else {
$_REQUEST["txtData"] = "";
}
} else {
$sEMail = trim($aParts[$aFieldDetails["email"]["col"]]);
if ($aFieldDetails["name"]["col"] > -1) {
$sName = trim($aParts[$aFieldDetails["name"]["col"]]);
if ($sName == "") {
$sName = $sEMail;
}
} else {
$sName = $sEMail;
}
if ($sEMail == "") {
$aMessage[] = sprintf(mi18n("Item with empty mail address found, item ignored (name: %s, row: %s)"), $sName, $iRow);
$aInvalidLines[] = $sLine;
$iInvalid++;
} else if (!isValidMail($sEMail)) {
$aMessage[] = sprintf(mi18n("Mail address '%s' is invalid, item ignored (row: %s)"), $sEMail, $iRow);
$aInvalidLines[] = $sLine;
$iInvalid++;
} else if ($oRecipients->emailExists($sEMail)) {
$aMessage[] = sprintf(mi18n("Recipient with mail address '%s' already exists, item skipped (row: %s)"), $sEMail, $iRow);
$aInvalidLines[] = $sLine;
$iDublettes++;
} else {
unset ($sLine);
if ($oRecipient = $oRecipients->create($sEMail, $sName)) {
$iAdded++;
unset($aPluginValue);
$aPluginValue = array();
foreach ($aFieldDetails as $sKey => $aDetails) {
if ($aDetails["col"] > -1) {
if ($aDetails["plugin"] == false) {
if ($aDetails["type"] == "boolean") {
$sValue = strtolower(trim($aParts[$aDetails["col"]]));
if ($sValue == "yes" || $sValue == i18n("yes") || $sValue == "true" || (is_numeric($sValue) && $sValue > 0)) {
$oRecipient->set($sKey, 1);
} else {
$oRecipient->set($sKey, 0);
}
} else {
$sValue = trim($aParts[$aDetails["col"]]);
$oRecipient->set($sKey, $sValue);
}
} else {
// type may be mentioned here, also, but as plugins currently can't
// specify the type, just treat everything as string
// There may be plugins which store more than one value per plugin_store-
// function. As the plugin_store parameter is an array of values, collect
// all values in an array for later storing... unfortunately, that means,
// that we have to go through the fields array second time per item *sigh*
$aPluginValue[$aDetails["plugin"]][$sKey] = trim($aParts[$aDetails["col"]]);
}
}
}
// Store all base data
$oRecipient->store();
// Store plugin data (to store plugin data, only, where the column has been found in the data
// should be faster than going through all plugins and store mostly empty arrays)
$sCurrentPlugin = "";
foreach ($aFieldDetails as $sKey => $aDetails) {
if ($aDetails["col"] > -1 && $aDetails["plugin"] && $aDetails["plugin"] !== $sCurrentPlugin) {
$sCurrentPlugin = $aDetails["plugin"];
call_user_func("recipients_".$sCurrentPlugin."_store", $aPluginValue[$sCurrentPlugin]);
}
}
}
}
}
}
if (count($aInvalidLines) > 1) {
$_REQUEST["txtData"] = implode("\n", $aInvalidLines);
}
if (count($aMessage) > 0) {
$sMessage = $notification->returnNotification("warning", implode("<br />", $aMessage))."<br />";
}
$sMessage .= $notification->returnNotification("info", sprintf(i18n("%d recipients added, %d recipients skipped (email already exists) and %d invalid recipients/e-mail adresses ignored. Invalid recipients are shown (if any)."), $iAdded, $iDublettes, $iInvalid));
if ($iAdded > 0) {
$oPage->setReload();
}
}
}
$oForm = new UI_Table_Form("properties");
$oForm->setVar("frame", $frame);
$oForm->setVar("area", $area);
$oForm->setVar("action", "recipients_import_exec");
$oForm->addHeader(i18n("Import recipients"));
$oAreaData = new cHTMLTextarea("txtData", $_REQUEST["txtData"], 80, 20);
$sInfo = sprintf(i18n("Insert recipients using this format: <data><tab><data>... - each recipient in a new line.".
"<br />The first line must contain the column names; this specifies the column order, ".
"<br />e.g. name mail -> first column contains the name, the second the mail address.".
"<br /><br />Example:<br />name mail<br />Smith jon.smith@domain.tld".
"<br /><br />The following column names will be recognized:<br />%s"), implode("<br />", $aFields));
$oForm->add(i18n("Recipients"), $oAreaData->render()."<br />".$sInfo);
unset ($sInfo);
$oPage->setContent($sMessage.$oForm->render(true));
$oPage->render();
?>
2. In contenido/includes/include.recipients_menu.php vor diese Zeile:
Code: Alles auswählen
/* Create a link to purge subscribed but not confirmed recipients */
diesen Code einfügen:
Code: Alles auswählen
/* Create a link to import recipients */
$oLink = new cHTMLLink;
$oLink->setMultiLink("recipients", "", "recipients_import", "recipients_import");
$oLink->setContent('<img style="padding-right: 4px;" src="'.$cfg["path"]["images"] . 'users_add.gif" align="middle">'.i18n("Import recipients").'</a>');
$sContent .= $oLink->render().'<br />'.chr(10);
Nun wird es haklig:
3. In con_area eine neue Zeile anlegen:
idarea: Aktuell höchster Wert + 1 (vorher ermitteln, vermutlich 90) - Wert merken!
parent_id: recipients
name: recipients_import
relevant: 1
online: 1
menuless: 0
4. In con_actions zwei neue Zeilen anlegen:
idaction: Aktuell höchster Wert + 1 (vorher ermitteln, vermutlich 434)
idarea: Wert von oben
alt_name: bleibt leer
name: recipients_import
code: bleibt leer
location: bleibt leer
relevant: 0
idaction: Aktuell höchster Wert + 1 (vorher ermitteln, vermutlich 435)
idarea: Wert von oben
alt_name: bleibt leer
name: recipients_import_exec
code: bleibt leer
location: bleibt leer
relevant: 0
5. In con_files eine neue Zeile anlegen:
idfile: Aktuell höchster Wert + 1 (vorher ermitteln, vermutlich ca. 200), Wert merken!
idarea: Wert von oben
filename: include.recipients_import.php
filetype: main
6. In con_frame_files eine neue Zeile anlegen:
idframefile: Aktuell höchster Wert + 1 (vorher ermitteln, vermutlich ca. 211)
idarea: Wert von oben
idframe: 4
idfile: Wert von eben
Bitte testen!!! Der Code ist "noch warm" und nicht wirklich mit Plugins getestet.
Den benötigten "Tab" bekommt man, wenn man die ganzen Daten (mit Kopfzeile mit den Spaltenbezeichnungen) in Excel einträgt, kopiert und von dort in das Feld einfügt. Werde da wohl ein ein Trennzeichen-Wähler bei Gelegenheit einbauen... (Workaorund: chr(9) durch das gewünschte Zeichen ersetzen, z.B. ";")
Beim Einfügen aus Excel wird immer eine Leerzeile mitkopiert, daher nach dem Einfügen einmal Backspace drücken.
Viel Erfolg.
Gruß
HerrB