Hier mal mein Code. Ist noch ziemlich chaotisch und unübersichtlich.
Code: Alles auswählen
<?php
//include("soap.php");
include('main.php');
//include('startup.php');
cInclude('classes', 'class.treeitem.php');
cInclude('classes', 'class.article.php');
cInclude('classes', 'class.cat.php');
cInclude('classes', 'class.template.php');
cInclude('includes', 'functions.con.php');
//cInclude('frontend', 'includes/functions.icdp.php'); //contains dirlist function print2log
cInclude('classes', 'contenido/class.articlelanguage.php');
function createArticle($elems, $opt, $title, $content) {
//parse "product" options
//that means: create new article(s) if desired
//conEditFirstTime (
//$idcat,$idcatnew,$idart,$is_start,$idtpl,
//$idartlang,$idlang,$title,$summary,$artspec,
//$created,$lastmodified,$author,$online,
//$datestart,$dateend,$artsort,$keyart = 0
//)
$new_art_id = 0;
$def = array ();
//always the same values
getsetNewarticleDefaults($def);
/*
* template ids, contenido-dev
* 73-default
* 162 -
* 167/168- ...
*
* nongeneric, dynamic defaults:
*/
$withsource = 1;
//$def["title"] = getArticleTitle($elems, $opt, $txt, $withsource);
$def["title"] = $title;
$def["summary"] = $def["title"] . ", imported " . date("r", time());
//$def["lang"] = $opt["lang"];
$def["lang"] = 1;
//$def["client"] = $opt["client"];
$def["client"] = 1;
//$def["idcat"] = $opt['selcat'];
$def["idcat"] = 2;
$def["idcatnew"] = array($def["idcat"]); //for unknown reasons, this param must be an array
//echo "<pre>def[] is now: " . print_r($def) . "</pre>";
$def["idtpl"] = null; //create empty article, template gets inherited from category
$new_art_id = conEditFirstTime($def["idcat"], $def["idcatnew"], $def["idart"], $def["is_start"], $def["idtpl"], $def["idartlang"], $def["lang"], $def["title"], $def["summary"], $def["artspec"], $def["created"], $def["lastmodified"], $def["author"], $def["online"], $def["keyart"], $def["datestart"], $def["dateend"]);
/*
echo "<pre>" .
sprintf("conEditFirstTime(def['idcat']='%s', def['idcatnew']='%s', def['idart']='%s'\n, def['is_start']='%s', def['idtpl']='%s', def['idartlang']='%s', def['lang']='%s'\n, def['title']='%s'\n, def['summary']='%s', def['artspec']='%s', def['created']='%s', def['lastmodified']='%s', def['author']='%s', def['online']='%s', def['keyart']='%s'\n, def['datestart']='%s', def['dateend']='%s')",
$def["idcat"], $def["idcatnew"], $def["idart"], $def["is_start"], $def["idtpl"], $def["idartlang"], $def["lang"], $def["title"], $def["summary"], $def["artspec"], $def["created"], $def["lastmodified"], $def["author"], $def["online"], $def["keyart"], $def["datestart"], $def["dateend"])
. "</pre>";
*/
echo("conSaveContentEntry");
$artlang = getArtLang($new_art_id,$def["lang"]);
echo("<br>");
echo($artlang);
conSaveContentEntry($artlang, "CMS_HTML", 1, $content);
return $new_art_id;
}
function getsetNewarticleDefaults(& $def) {
//the Contenido API function conEditFirstTime wants 18 Parameters
//some generic defaults to are set here, to keep the code of the main module more readable
//some specific defaults are set in the struc2htmltpl fct
global $client, $lang;
$def["client"] = $client;
$def["lang"] = $lang;
$def["idcat"] = null;
// using this function conEditFirstTime,
// article can be copied to several locations within a single call.
// therefore, idcatnew is an array
$def["idcatnew"] = array($def["idcat"]);
//$def["idart"] = null;
$def["is_start"] = 0;
$def["idtpl"] = null; //if null , article inherits template from category
$def["idartlang"] = null;
$def["title"] = "Imported from Filesystem on " . date('Y-m-d H:i:s');
$def["summary"] = null; //title
$def["artspec"] = null;
$def["created"] = date('Y-m-d H:i:s');
$def["lastmodified"] = date('Y-m-d H:i:s');
$def["author"] = 'knb_script';
$def["online"] = 0; //should be 1 on development, 0 on production system
$def["datestart"] = '0000-00-00 00:00:00';
$def["dateend"] = '0000-00-00 00:00:00';
$def["artsort"] = 0;
//echo "<pre>generic defaults in def[] are " . print_r($def) . "</pre>";
}
global $elems;
global $opt;
$soap_client = new SoapClient(
"http://soap.amazon.com/schemas2/AmazonWebServices.wsdl");
//var_dump($client->__getFunctions());
//var_dump($client->__getTypes());
$soap_params = array(
'keyword' => 'harry potter',
'page' => 1,
'mode' => 'books',
'tag' => 'preinheimerco-20',
'type' => 'lite',
'devtag' => ''
);
$soap_result = $soap_client->KeywordSearchRequest($soap_params);
foreach ($soap_result->Details AS $product)
{
/*
echo '<a href="' . $product->Url . '">' .
$product->ProductName . "</a><br>\n";
echo '<img src="' . $product->ImageUrlSmall .
'" border="0" alt="book cover"><br>' . "\n";
*/
echo(createArticle($elems, $opt, $product->Asin, $product->ProductName));
echo("<br>");
}
//echo(createArticle($elems, $opt, "Nummer", "text"));
//echo(strNewCategory (78, "neue Kategorie", $remakeTree=true));
$artikel = new Article();
?>
Zu Testzwecken nutze ich den Amazon-Webservice, um Produktdaten in Contenido zu importieren. Den devtag bekommt man, wenn man sich bei Amazon.com Webservices als Entwickler anmeldet.