ich habe mal eine Datenübernahme programmiert, die aus statischen Seiten, die mit Dreamweaver Templates erstellt worden sind, die Inhalte in einzelne Artikel importiert.
Dazu habe ich mich durch den Contenido Sourcecode gegraben und über Copy&Paste nachher mir einen Datei datenuebernahme.php im contenido/ Verzeichniss erstellt. Nach einem Login in contenido, habe ich diese Datei manuell aufgerufen (inkl. dem dann sichtbaren sess Parameter in der URL)
Dazu muss man aber wissen, in welchen CMS_xx[nr] Feldern was in dem jeweiligen Template in einer Kategorie gespiechert wird und wie die Werte für $client, $lang und $idcat sind.
Code: Alles auswählen
<?php
include_once ('./includes/startup.php');
cInclude ("includes", 'functions.general.php');
$cfg["debug"]["backend_exectime"]["fullstart"] = getmicrotime();
cInclude ("includes", 'functions.i18n.php');
cInclude ("includes", 'functions.api.php');
cInclude ("includes", 'functions.general.php');
cInclude ("includes", 'functions.forms.php');
cInclude ("classes", 'class.xml.php');
cInclude ("classes", 'class.navigation.php');
cInclude ("classes", 'class.template.php');
cInclude ("classes", 'class.backend.php');
cInclude ("classes", 'class.notification.php');
cInclude ("classes", 'class.area.php');
cInclude ("classes", 'class.action.php');
cInclude ("classes", 'class.layout.php');
cInclude ("classes", 'class.treeitem.php');
cInclude ("classes", 'class.user.php');
cInclude ("classes", 'class.group.php');
cInclude ("classes", 'class.cat.php');
cInclude ("classes", 'class.client.php');
cInclude ("classes", 'class.inuse.php');
cInclude ("classes", 'class.table.php');
page_open(array('sess' => 'Contenido_Session',
'auth' => 'Contenido_Challenge_Crypt_Auth',
'perm' => 'Contenido_Perm'));
i18nInit($cfg["path"]["contenido"].$cfg["path"]["locale"], $belang);
cInclude ("includes", 'cfg_language_de.inc.php');
if ($cfg["use_pseudocron"] == true)
{
/* Include cronjob-Emulator, but only for frame 1 */
if ($frame == 1)
{
$sess->freeze();
$oldpwd = getcwd();
chdir($cfg["path"]["contenido"].$cfg["path"]["cronjobs"]);
cInclude("includes", "pseudo-cron.inc.php");
chdir($oldpwd);
if ($bJobRunned == true)
{
/* Some cronjobs might overwrite important system variables.
* We are thaw'ing the session again to re-register these variables.
*/
$sess->thaw();
}
}
}
/* Remove all own marks, only for frame 1 and 4 */
if ($frame == 1 || $frame == 4)
{
$col = new InUseCollection;
$col->removeSessionMarks($sess->id);
}
/* If the override flag is set, override a specific InUseItem */
if (isset($overrideid) && isset($overridetype))
{
$col = new InUseCollection;
$col->removeItemMarks($overridetype, $overrideid);
}
# Create Contenido classes
$db = new DB_Contenido;
$notification = new Contenido_Notification;
$classarea = new Area();
$classlayout = new Layout();
$classclient = new Client();
$classuser = new User();
$currentuser = new User();
$currentuser->loadUserByUserID($auth->auth["uid"]);
# change Client
if (isset($changeclient) && is_numeric($changeclient) ) {
$client = $changeclient;
unset($lang);
}
# Sprache wechseln
if (isset($changelang) && is_numeric($changelang) ) {
unset($area_rights);
unset($item_rights);
$lang = $changelang;
}
if (!is_numeric($client) ||
(!$perm->have_perm_client("client[".$client."]") &&
!$perm->have_perm_client("admin[".$client."]")))
{
// use first client which is accessible
$sess->register("client");
$sql = "SELECT idclient FROM ".$cfg["tab"]["clients"]." ORDER BY idclient ASC";
$db->query($sql);
while ($db->next_record())
{
$mclient = $db->f("idclient");
if ($perm->have_perm_client("client[".$mclient."]") ||
$perm->have_perm_client("admin[".$mclient."]") )
{
unset($lang);
$client = $mclient;
break;
}
}
} else {
$sess->register("client");
}
if (!is_numeric($lang) || $lang == "") {
$sess->register("lang");
# search for the first language of this client
$sql = "SELECT * FROM ".$cfg["tab"]["lang"]." AS A, ".$cfg["tab"]["clients_lang"]." AS B WHERE A.idlang=B.idlang AND idclient='$client' ORDER BY A.idlang ASC";
$db->query($sql);
$db->next_record();
$lang = $db->f("idlang");
} else {
$sess->register("lang");
}
if (array_key_exists("use_encoding", $_GET))
{
$use_encoding = $_GET["use_encoding"];
}
if (array_key_exists("use_encoding", $_POST))
{
$use_encoding = $_POST["use_encoding"];
}
if (!isset($use_encoding))
{
$use_encoding = true;
}
if (is_string($use_encoding))
{
if ($use_encoding == "false")
{
$use_encoding = false;
} else {
$use_encoding = true;
}
}
if ($use_encoding != false)
{
$sql = "SELECT idlang, encoding FROM ".$cfg["tab"]["lang"];
$db->query($sql);
$aLanguageEncodings = array();
while ($db->next_record())
{
$aLanguageEncodings[$db->f("idlang")] = $db->f("encoding");
}
if (array_key_exists($lang, $aLanguageEncodings))
{
if (!in_array($aLanguageEncodings[$lang], $cfg['AvailableCharsets']))
{
header("Content-Type: text/html; charset=ISO-8859-1");
} else {
header("Content-Type: text/html; charset={$aLanguageEncodings[$lang]}");
}
} else {
header("Content-Type: text/html; charset=ISO-8859-1");
}
}
$perm->load_permissions();
# Create Contenido classes
$xml = new XML_doc;
$tpl = new Template;
$backend = new Contenido_Backend;
# Register session variables
$sess->register("sess_area");
if (isset($area)) {
$sess_area = $area;
} else {
$area = ( isset($sess_area) && $sess_area != "" ) ? $sess_area : 'login';
}
$sess->register("cfgClient");
$sess->register("errsite_idcat");
$sess->register("errsite_idart");
if ($cfgClient["set"] != "set")
{
rereadClients ();
}
# Initialize Contenido_Backend.
# Load all actions from the DB
# and check if permission is
# granted.
if ($cfg["debug"]["rendering"] == true)
{
if (function_exists("memory_get_usage"))
{
$oldmemusage = memory_get_usage();
}
}
# Select frameset
$backend->setFrame($frame);
# Select area
$backend->select($area);
$cfg["debug"]["backend_exectime"]["start"] = getmicrotime();
# Include all required 'include' files.
# Can be an array of files, if more than
# one file is required.
if (is_array($backend->getFile('inc'))) {
foreach ($backend->getFile('inc') as $filename) {
include_once($cfg['path']['contenido'].$filename);
}
}
# If $action is set -> User klicked some button/link
# get the appopriate code for this action and evaluate it.
if (isset($action) && $action != "")
{
if (!isset($idart))
{
$idart = 0;
}
$backend->log($idcat, $idart, $client, $lang, $action);
}
if (isset($action)) {
if ($backend->getCode($action) != '') {
if ($backend->debug == 1) {
echo '<pre style="font-family: verdana; font-size: 10px"><b>Executing:</b>'."\n";
echo $backend->getCode($action)."\n";
echo '</pre>';
}
eval($backend->getCode($action));
} else {
if ($backend->debug == 1) {
echo '<pre style="font-family: verdana; font-size: 10px"><b>Executing:</b>'."\n";
echo "no code available in action\n";
echo '</pre>';
}
}
}
include_once($cfg['path']['contenido'].$cfg['path']['includes'].'functions.con.php');
function GetSubDirs($rootDir, &$ar_result, $parentDirStr)
{
$dir_handle = "dir".str_replace("/", "_", $parentDirStr);
$$dir_handle = @opendir($rootDir);
if ($$dir_handle !== false)
{
while (false !== ($file = readdir($$dir_handle)))
{
if (($file != ".")
&& ($file != "..")
&& ($file != "CVS")
&& ($file != "classes")
&& ($file != "imgs")
&& ($file != str_replace(PROJEKT_ROOT, "", FILE_DEPOSIT_RELATIV))
&& ($file != "pear")
&& (strpos($file, ".") === FALSE))
{
array_push($ar_result, $parentDirStr."/".$file);
GetSubDirs($rootDir.$file."/", $ar_result, $parentDirStr."/".$file);
}
}
closedir($$dir_handle);
}
}
function GetFilesInDir($dir)
{
$dir_handle = opendir($dir);
$ar_files = array();
while (false !== ($file = readdir($dir_handle)))
{
if (($file != '.') && ($file != '..') && (!is_dir($file)))
{
array_push($ar_files, $file);
}
}
closedir($dir_handle);
sort($ar_files);
return $ar_files;
} // function GetFilesInDir($dir)
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
function DecodeStringHTML($string)
{
global $trans_tbl;
return strtr($string, $trans_tbl);
}
ini_set('max_execution_time', 300);
# Konstanten für das SWU Energielexikon
$import_client = 6;
$import_lang = 6;
$import_idcat = 507;
$import_idcatnew = array($import_idcat);
$import_idart = null;
$import_is_start = 0;
$import_idtpl = null;
$import_idartlang = null;
$import_summary = null;
$import_artspec = null;
$import_created = date('Y-m-d H:i:s');
$import_lastmodified = date('Y-m-d H:i:s');
$import_author = 'swu_admin';
$import_online = 1;
$import_datestart = '0000-00-00 00:00:00';
$import_dateend = '0000-00-00 00:00:00';
$import_artsort = 0;
# Pfad zum Energielexikon
$energielex_root = '__-Energielexikon';
$dirs2search = array();
GetSubDirs($energielex_root, $dirs2search, '');
# alle Ordner + Dateien im energielex_root einlesen
foreach ($dirs2search as $aSubDir)
{
$files2import = GetFilesInDir($energielex_root.$aSubDir);
foreach ($files2import as $aFile2Import)
{
echo "<h3>".$aFile2Import."</h3>\r\n";
# Datei einlesen
$fileContent = str_replace(" ", " ", str_replace("\r", " ", str_replace("\n", " ", file_get_contents($energielex_root.$aSubDir.'/'.$aFile2Import))));
...
$import_title = $Ueberschrift;
$CMS_HTML = '';
$CMS_HTML .= (strlen($Unterschrift) > 0 ? '<h2>'.$Unterschrift.'</h2>' : '');
$CMS_HTML .= (strlen($ColorText) > 0 ? '<h3>'.$ColorText.'</h3>' : '');
$CMS_HTML .= (strlen($Mengentext) > 0 ? $Mengentext : '');
# Artikel anlegen -BEGIN-
$import_idart = conEditFirstTime($import_idcat, $import_idcatnew, $import_idart, $import_is_start, $import_idtpl, $import_idartlang, $import_lang, $import_title, $import_summary, $import_artspec, $import_created, $import_lastmodified, $import_author, $import_online, $import_datestart, $import_dateend, $import_artsort);
# idcatart ermitteln
$sql = "SELECT idcatart FROM ".$cfg["tab"]["cat_art"]." WHERE idcat = '".$import_idcat."' AND idart = '".$import_idart."'";
$db->query($sql);
$db->next_record();
$import_idcatart = $db->f("idcatart");
# idartlang ermitteln
$sql = "SELECT idartlang FROM ".$cfg["tab"]["art_lang"]." WHERE idart = $import_idart AND idlang = $import_lang";
$db->query($sql);
$db->next_record();
$import_idartlang = $db->f("idartlang");
# nicht als startartikel setzen
conMakeStart($import_idcatart, 0);
# "Titel der Seite" füllen
$typenr = 3;
#$CMS_TEXT = 'la le lu';
consaveContentEntry($import_idartlang, "CMS_TEXT", $typenr, $import_title);
# "Inhalt" füllen
$typenr = 1;
#$CMS_HTML = '<h2>la </h2>le lu';
consaveContentEntry($import_idartlang, "CMS_HTML", $typenr, $CMS_HTML);
# Artikel anlegen -ENDE-
flush();
}
}
page_close();
?>