Guten Tag,
ich möchte mit einer PHP Datei den Inhalt aller Artikel einer Kategorie auslesen. Diese Seite kann nicht innerhalb eines Moduls included werden. Ich muss also entweder die richtigen Bibiotheken von Contenido importieren oder direkt einfach über die Mysql-Tabellen den Inhalt auslesen.
Wie ich alle ArtikelID's einer Kategorie aus der Datenbank auslese habe ich schon gesehen, aber mir fehlt noch die Verbindung von den Aritkelids zu den Inhalten in der content Tabelle?
Würde mich über Hilfe freuen,
MfG bb
Artikelinhalt von außerhalb einlesen
Re: Artikelinhalt von außerhalb einlesen
Wenn du die ganzen Artikel haben willst, dann ist es ziemlich straight forward, im Grunde brauchst du nur die IDs anhand derer du den Code aus der con_code holst, Ausgabepufferung einschaltest, den Code evaluierst und dann den Puffer ausliest.
Kategorie, Sprache und Mandant sind in diesem Beispiel im Abschnitt "Config" hartverdrahtet.
Code: Alles auswählen
<?php
if (!defined("CON_FRAMEWORK")) {
define("CON_FRAMEWORK", true);
}
$contenido_path = '';
// include the config file of the frontend to init the Client and Language Id
include_once ("config.php");
// include security class and check request variables
include_once ($contenido_path . 'classes/class.security.php');
Contenido_Security::checkRequests();
// Contenido startup process
include_once ($contenido_path."includes/startup.php");
cInclude("includes", "functions.con.php");
cInclude("includes", "functions.con2.php");
cInclude("includes", "functions.api.php");
cInclude("includes", "functions.pathresolver.php");
/* ***************************************************** **
* Config *
* ***************************************************** */
$client = 1;
$lang = 1;
$idcat = 43;
/* ****************** END OF CONFIG ******************** */
$articles = array();
if (!is_object($db))
$db = new DB_Contenido;
if (!is_object($db2))
$db2 = new DB_Contenido;
page_open(array (
'sess' => 'Contenido_Frontend_Session',
'auth' => 'Contenido_Frontend_Challenge_Crypt_Auth',
'perm' => 'Contenido_Perm'
));
rereadClients();
$sql = "SELECT cca.idcatart, cal.idart " .
"FROM " . $cfg["tab"]["cat_art"] . " AS cca, " .
" " . $cfg["tab"]["cat_lang"] . " AS ccl, " .
" " . $cfg["tab"]["art_lang"] . " AS cal " .
"WHERE cca.idcat = '" . $idcat . "' " .
" AND ccl.idcat = cca.idcat " .
" AND ccl.idlang = cal.idlang " .
" AND ccl.visible = 1 " .
" AND cal.idart = cca.idart " .
" AND cal.idlang = " . Contenido_Security::toInteger($lang) . " " .
" AND cal.online = 1";
$db2->query($sql);
$arts = array();
while( $db2->next_record() ) {
$arts[] = array(
"idart" => $db2->f("idart"),
"idcatart" => $db2->f("idcatart")
);
}
foreach( $arts AS $v ) {
$idart = $v["idart"];
$idcatart = $v["idcatart"];
$sql = "SELECT code FROM " .
$cfg["tab"]["code"] .
" WHERE idcatart = '" . Contenido_Security::toInteger($idcatart)."'" .
" AND idlang = '".Contenido_Security::toInteger($lang)."'";
$db2->query($sql);
if( ! $db2->next_record() ) {
// We have to generate the code first, then try again fetching it
conGenerateCode($idcat, $idart, $lang, $client);
}
$db2->query($sql);
if( $db2->next_record() ) {
$code = $db2->f("code");
ob_start();
eval( "?>" . stripslashes($code) . "<" . "?php" );
$sCode = ob_get_contents();
ob_end_clean();
$articles[$idart] = substr($sCode, 2, strlen($sCode)-7);
}
}
header( 'Content-Type: text/plain' );
print_r($articles);
?>
Re: Artikelinhalt von außerhalb einlesen
Leider funktioniert der Code nicht so richtig. Ich habe die Config angepasst und es wird auch ein Array mit den IDs der Artikels gefüllt. Aber dieses ist dann leer:
Ich habe in der Kategorie bislang nur 3 Artikel.
Am liebsten wäre es mir, wenn ich CMS_HTML[0] und CMS_HTML[1] aus den jeweiligen Artikeln einzeln auslesen könnte...
Gruß bb
Code: Alles auswählen
Array
(
[120] =>
[121] =>
[122] =>
)
Am liebsten wäre es mir, wenn ich CMS_HTML[0] und CMS_HTML[1] aus den jeweiligen Artikeln einzeln auslesen könnte...
Gruß bb
Re: Artikelinhalt von außerhalb einlesen
Ich habe jetzt gefunden wonach ich gesucht habe.
Mit der MySql-Abfrage bekomme ich alle Felder der Artikel aus der Kategorie 67 - ich hatte vorher bloß noch nicht gesehen, wie die einzelnen Tabelle miteinander verknüpft sind...
Danke für eure Hilfe!
Code: Alles auswählen
SELECT value
FROM con_content AS a, con_art_lang AS b, con_cat_art AS c
WHERE c.idcat=67
AND b.idart=c.idart
AND a.idartlang=b.idartlang
AND a.typeid=0
Danke für eure Hilfe!
Re: Artikelinhalt von außerhalb einlesen
Wundert mich jetzt, dass es mit meinem Script nicht funktioniert hat. Ich hab trotzdem noch mal 'drübergestreichelt', so dass es jetzt gänzlich ohne handgeschriebenes SQL auskommt, die notwendigen Klassen sind ja im Contenido ohnehin schon drin (und deren Verwendung sollte auch etwaige Änderungen in der Datenbankstruktur beim Update überleben).
Die getContent-Methode der Article-Klasse macht dabei aber auch nix anderes als Dein Query.
Code: Alles auswählen
<?php
if (!defined("CON_FRAMEWORK")) {
define("CON_FRAMEWORK", true);
}
$contenido_path = '';
// include the config file of the frontend to init the Client and Language Id
include_once ("config.php");
// include security class and check request variables
include_once ($contenido_path . 'classes/class.security.php');
Contenido_Security::checkRequests();
// Contenido startup process
include_once ($contenido_path."includes/startup.php");
cInclude("includes", "functions.con.php");
cInclude("includes", "functions.con2.php");
cInclude("includes", "functions.api.php");
cInclude("includes", "functions.pathresolver.php");
cInclude("classes", "Contenido_Category/Contenido_Category_Articles.class.php");
/* ***************************************************** **
* Config *
* ***************************************************** */
$client = 1;
$lang = 1;
$idcat = 43;
/* ****************** END OF CONFIG ******************** */
if (!is_object($db))
$db = new DB_Contenido;
page_open(array (
'sess' => 'Contenido_Frontend_Session',
'auth' => 'Contenido_Frontend_Challenge_Crypt_Auth',
'perm' => 'Contenido_Perm'
));
rereadClients();
$oCatArts = new Contenido_Category_Articles( $db, $cfg, $client, $lang );
$cArticles = $oCatArts->getOnlineArticlesInCategory( $idcat );
$articles = array();
foreach( $cArticles AS $oArticle ) {
$articles[$oArticle->getField('idart')] = $oArticle->getContent('CMS_HTML');
}
header( 'Content-Type: text/plain' );
print_r($articles);
?>