CMS_Types verfügbar machen wie CMS_VALUE

Ideen für neue Funktionen in CONTENIDO?
Antworten
OliverL
Beiträge: 870
Registriert: Do 28. Jun 2007, 09:28
Kontaktdaten:

CMS_Types verfügbar machen wie CMS_VALUE

Beitrag von OliverL » Fr 29. Jan 2010, 23:52

Hallo Leute,

dies ist eins meiner kleineren Ideen um z.B. CMS-TYPES in einer schleife zu erstellen.

Es ist so das sollte ein "CMS_VALUE[1]" in einem Modul ergänzt wir dieser Platzhalter durch "xyz" ersetzt wird.
Sollte der Fall eintretten das "CMS_VALUE[$i]" in einem Modul eingesetzt wird dieser Platzhalter durch "$C1CMS_VALUE[$i]" ersetzt wird (C1 = Container mit ID 1).

Das könnte man auch für alle CMS_TYPES wie CMS_LINK oder CMS_IMG machen. Einmal alle für den Artikel verfügbaren Content-Elemente in einer Variable Cachen und dann die TYPES mit nicht numerischer ID durch eine Funktion ersetzen. Funktion für die TYPES die nicht im Cach sind. Die Funktion würde den Cache prüfen und wenn kein eintrag besteht diesen erstellen.

d.h. aus "CML_LINK[$i]" würde "".myFunction('CMS_LINK', "$i").""

Diese Funktion ist schon (fast) fertig und ist hier im Forum entwickelt worden und im Wiki ergänzt worden.
http://www.contenido-wiki.org/wiki/inde ... atzhaltern


Warum ich das nicht schaffe.
Die liebe Zeit ist schult (immer wieder gerne genommen :) ).
Wie einige mit bekommen hab bin ich jetzt schon seid letztem Sommer sehr passiv im Forum.
Jedoch bearbeite ich gerade eine ganze Area und wenn die Zeit gekommen ist wird jeder verstehen warum ich all die mir gegebene Zeit in diese Area stecke.
Ein :wink: an Oldperl der diese arbeit sicher bestätigt (OHNE EINE INFO AUSZUPLAUDERN).

mfg OliverL

BagHira
Beiträge: 486
Registriert: Do 23. Feb 2006, 19:42
Wohnort: Tirschenreuth / Oberpfalz / Bayern
Kontaktdaten:

Re: CMS_Types verfügbar machen wie CMS_VALUE

Beitrag von BagHira » Di 2. Feb 2010, 09:17

Och Mensch Oli,

nu komm, raus mit der Sprache :roll:
Gruß Holger

Träumer haben vielleicht keinen Plan, aber Realisten haben keine Vision.

Handgewickelte Glasperlen Facebook Google+

xmurrix
Beiträge: 3147
Registriert: Do 21. Okt 2004, 11:08
Wohnort: Augsburg
Kontaktdaten:

Re: CMS_Types verfügbar machen wie CMS_VALUE

Beitrag von xmurrix » Do 4. Feb 2010, 15:12

Hallo,

das ist eine sehr gute Idee, und macht auf jeden Fall sinn.

Eine Frage hätte ich dazu. Wenn man im Modulcode mit

Code: Alles auswählen

echo myFunction('CMS_LINK', "$i");
arbeitet, werden dann bei jedem Aufruf von myFunction() Abfragen an die DB abgesetzt?

Falls ja, wäre es nicht besser, wenn das schon beim Generieren des Codes geschiehtm, und nicht jedes Mal bei der Ausgabe der Seite?

Wie wäre es, wenn man für solche Fälle einen neuen Modultag einführt, mit dem man solche Schleifen definieren kann?

Beispiel:

Code: Alles auswählen

<con:cmsTypeLoop start="1" end="5" step="1">
echo "CMS_LINK[$pos]";
</con:cmsTypeLoop>
Beim Generieren des Codes der Seite, könnte man daraus folgenden Modulcode machen:

Code: Alles auswählen

echo "CMS_LINK[1]";
echo "CMS_LINK[2]";
echo "CMS_LINK[3]";
echo "CMS_LINK[4]";
echo "CMS_LINK[5]";

Beim Generieren des Codes der Seite, werden CMS-Typen in der functions.con2.php geparst.

Code: Alles auswählen

		$tmp = preg_match_all("/(".$db->f("type")."\[+\d+\])/i", $code, $match);
Dies könnte man erweitern, um das Parsen solcher Taglibs und den Modulcode beim Genereieren des Codes der Seite schon entsprechend Modifizieren.

Die Idee ist natürlich reine Theorie, ob das so einfach geht, kann ich nicht sagen.

Denke aber, dass wir mit einem soliden, gut durchdachten Parsen der Modulcodes in Zukunft viel flexibler sein können. Eines der mögliche Wege, wären solche Taglibs, die auch für das Parsen vom Layout verwendet werden könnten.

Was meinst du dazu?
Sollte das eine Option sein, kann man sich ja überlegen, was alles damit machbar wäre...

Grüße
xmurrix
CONTENIDO Downloads: CONTENIDO 4.10.1
CONTENIDO Links: Dokumentationsportal, FAQ, API-Dokumentation
CONTENIDO @ Github: CONTENIDO 4.10 - Mit einem Entwicklungszweig (develop-branch), das viele Verbesserungen/Optimierungen erhalten hat und auf Stabilität und Kompatibilität mit PHP 8.0 bis 8.2 getrimmt wurde.

OliverL
Beiträge: 870
Registriert: Do 28. Jun 2007, 09:28
Kontaktdaten:

Re: CMS_Types verfügbar machen wie CMS_VALUE

Beitrag von OliverL » Do 4. Feb 2010, 16:02

Hi xmurrix,

du scheinst ja grad super aktiv an Contenido zuarbeite. Dass finde ich super.

bzgl.

Code: Alles auswählen

<con:cmsTypeLoop start="1" end="5" step="1">
würde ich sagen das eine eigene Codesprache noch nicht in die Modulen gehört.

Meine Idee des Ablaufs war/ist:
  • Alle Einträge aus der con_content für diesen Artikel mit einem SQL-Select laden
  • Alle Übereinstimmungen mit con_type werden geholt
  • Beide Ergebnisse werden in ein Array geschrieben
  • CMS-Types wie "HMLT[1]" werden natürlich weiterhin ersetzt
  • Undefinierte Types "HMLT[$i]" werden durch die Funktion ersetzt
  • Eval() für den gesamten Code
Wird jetzt die Funktion aufgerufen ...
  • wird überprüft ob ein entsprechender Eintrag aus dem "con_content"-Array vorhanden ist wenn nicht wird ein Select abgesetzt (dieser Select kommt aber nur wenn man im BE ist um editieren zukönnen da wenn im FE kein eintrag im Array ist auch kein Inhalt da ist
  • das gleiche bei con_type, auch wieder nur ein Select im BE und auch nur solange der Type noch nicht in verwendung war
So hat man für diese Methode 2 SQL-Selects (_content & _typ) egal ob eindeutige ID oder Variable.
Und im BE max. 21 selects für einen jungfreulichen Beitrag bei der Verwendung von allen CMS-Types im Template
1 für content
20 für types

[EDIT] wenn man direkt alle Types in das Array schreibt hat man nur 2 Selects. Das sind glaube ich bei der jetzigen Methode schon wesentlich mehr.
Wer keine dynamischen Types benutzt für den bleibt alles gleich. (Bis auf die eventuelle performance verbesserung bei der Cachegenerierung durch 2 Selects).



mfg Oliver

OliverL
Beiträge: 870
Registriert: Do 28. Jun 2007, 09:28
Kontaktdaten:

Re: CMS_Types verfügbar machen wie CMS_VALUE

Beitrag von OliverL » Mo 3. Mai 2010, 09:27

hab mir das mal gestern von 22-24 angeguckt:

[quote=xmurrix]Beim Generieren des Codes der Seite, werden CMS-Typen in der functions.con2.php geparst.

Code: Alles auswählen

$tmp = preg_match_all("/(".$db->f("type")."\[[color=#FF0000]+[/color]\d+\])/i", $code, $match);
[/quote](Wofür auch immer das +)

Da hab ich erstmal angesetzt:

Code: Alles auswählen

$tmp = preg_match_all("/(".$db->f("type").")\[(\d+)\]/i", $code, $match);

Code: Alles auswählen

array (
    [0] => array (     [0] = "CMS_HTML[1]", [1] = "CMS_TEXT[5]"    )
    [1] => array (     [0] = CMS_HTML, [1] = CMS_TEXT    )
    [2] => array (     [0] = 1, [1] = 5    )
)
0 = Summe von allem, 1 = CMS-Typ, 2 = ID

mit der klammer um das \d+ nimmt man sich direkt die ID und muss nicht das "array_walk(..., 'extractNumber')" ausführen. Hier reicht es von $match[0] auf $match[2] umzustellen.

Des weiteren habe ich für das hollen des Contents die Funktion conGetContentFromCmsType( $sType, $iId, $iIdArtLang=false ) und eine globale Var. $cCMS_Types erstellt.

Heute abend mach ich das noch fertig.
Fertig ist:
  • Alle Einträge aus der con_content für diesen Artikel mit einem SQL-Select laden
  • Alle Übereinstimmungen mit con_type werden geholt
Auf eine Einarbeitung von <con:cmsTypeLoop ...> oder so verzichte ich hier, da ich finde das Contenido sehr einfach zubedienen ist (der großte Vorteil zu anderen) und eigene Befehle das dann doch erschwären. Anstelle des Con:Loop kann man genauso gut ein php-for machen

mfg Oli

OliverL
Beiträge: 870
Registriert: Do 28. Jun 2007, 09:28
Kontaktdaten:

Re: CMS_Types verfügbar machen wie CMS_VALUE

Beitrag von OliverL » Mo 3. Mai 2010, 11:45

So!

hab gerade ein bisschen Mittagspause und hab das ganze mal fertig gemacht.

Neuer Codeblock für conGenerateCode():

Code: Alles auswählen

siehe unten
und die Dazugehörige Funktion conGetContentFromCmsType() :
(Einfach am ende der Datei functions.con2.php anhängen)

Code: Alles auswählen

siehe unten

Ein vollständiger Test steht noch aus!

mfg OliverL

Vollständige Datei functions.con2.php:

Code: Alles auswählen

    <?php
    /**
    * Project:
    * Contenido Content Management System
    *
    * Description:
    * Contenido Content Functions
    *
    * Requirements:
    * @con_php_req 5.0
    * @con_notice Please add only stuff which is relevant for the frontend
    *             AND the backend. This file should NOT contain any backend editing
    *             functions to improve frontend performance:
    *
    *
    * @package    Contenido Backend includes
    * @version    1.3.5
    * @author     Timo A. Hummel
    * @copyright  four for business AG <www.4fb.de>
    * @license    http://www.contenido.org/license/LIZENZ.txt
    * @link       http://www.4fb.de
    * @link       http://www.contenido.org
    * @since      file available since contenido release <= 4.6
    *
    * {@internal
    *   created 2003-12-15
    *   modified 2008-06-25, Timo Trautmann, user meta tags and system meta tags were merged, not replaced
    *   modified 2008-06-25, Frederic Schneider, add security fix
    *   modified 2008-08-29, Murat Purc, add new chain execution
    *   modified 2009-03-27, Andreas Lindner, Add title tag generation via chain   
    *
    *   $Id: functions.con2.php 1018 2009-04-21 12:29:03Z andreas.lindner $:
    * }}
    *
    */

    if(!defined('CON_FRAMEWORK')) {
       die('Illegal call');
    }

    /**
    * Generates the code for one
    * article
    *
    * @param int $idcat Id of category
    * @param int $idart Id of article
    * @param int $lang Id of language
    * @param int $client Id of client
    * @param int $layout Layout-ID of alternate Layout (if false, use associated layout)
    *
    * @author Jan Lengowski <jan.lengowski@4fb.de>
    * @copyright four for business AG <www.4fb.de>
    */
    function conGenerateCode($idcat, $idart, $lang, $client, $layout = false)
    {
       global $frontend_debug, $_cecRegistry;

       $debug = 0;

       if ($debug)
          echo "conGenerateCode($idcat, $idart, $lang, $client, $layout);<br>";

       global $db, $db2, $sess, $cfg, $code, $cfgClient, $client, $lang, $encoding;

       if (!is_object($db2))
          $db2 = new DB_Contenido;

       /* extract IDCATART */
       $sql = "SELECT
                           idcatart
                       FROM
                           ".$cfg["tab"]["cat_art"]."
                       WHERE
                           idcat = '".Contenido_Security::toInteger($idcat)."' AND
                           idart = '".Contenido_Security::toInteger($idart)."'";

       $db->query($sql);
       $db->next_record();

       $idcatart = $db->f("idcatart");

       /* If neither the
          article or the category is
          configured, no code will be
          created and an error occurs. */
       $sql = "SELECT
                a.idtplcfg AS idtplcfg
             FROM
                ".$cfg["tab"]["art_lang"]." AS a,
                ".$cfg["tab"]["art"]." AS b
             WHERE
                a.idart     = '".Contenido_Security::toInteger($idart)."' AND
                a.idlang    = '".Contenido_Security::escapeDB($lang, $db)."' AND
                b.idart     = a.idart AND
                b.idclient  = '".Contenido_Security::escapeDB($client, $db)."'";

       $db->query($sql);
       $db->next_record();

       if ($db->f("idtplcfg") != 0)
       {

          /* Article is configured */
          $idtplcfg = $db->f("idtplcfg");

          if ($debug)
             echo "configuration for article found: $idtplcfg<br><br>";

          $a_c = array ();

          $sql2 = "SELECT
                                  *
                               FROM
                                  ".$cfg["tab"]["container_conf"]."
                               WHERE
                                  idtplcfg = '".Contenido_Security::toInteger($idtplcfg)."'
                               ORDER BY
                                  number ASC";

          $db2->query($sql2);

          while ($db2->next_record())
          {
             $a_c[$db2->f("number")] = $db2->f("container");

          }

       } else
       {

          /* Check whether category is
           configured. */
          $sql = "SELECT
                                  a.idtplcfg AS idtplcfg
                              FROM
                                  ".$cfg["tab"]["cat_lang"]." AS a,
                                  ".$cfg["tab"]["cat"]." AS b
                              WHERE
                                  a.idcat     = '".Contenido_Security::toInteger($idcat)."' AND
                                  a.idlang    = '".Contenido_Security::escapeDB($lang, $db)."' AND
                                  b.idcat     = a.idcat AND
                                  b.idclient  = '".Contenido_Security::escapeDB($client, $db)."'";

          $db->query($sql);
          $db->next_record();

          if ($db->f("idtplcfg") != 0)
          {

             /* Category is configured,
                extract varstring */
             $idtplcfg = $db->f("idtplcfg");

             if ($debug)
                echo "configuration for category found: $idtplcfg<br><br>";

             $a_c = array ();

             $sql2 = "SELECT
                                         *
                                      FROM
                                         ".$cfg["tab"]["container_conf"]."
                                      WHERE
                                         idtplcfg = '".Contenido_Security::toInteger($idtplcfg)."'
                                      ORDER BY
                                         number ASC";

             $db2->query($sql2);

             while ($db2->next_record())
             {
                $a_c[$db2->f("number")] = $db2->f("container");

             }

          } else
          {

             /* Article nor Category
                is configured. Creation of
                Code is not possible. Write
                Errormsg to DB. */

             if ($debug)
                echo "Neither CAT or ART are configured!<br><br>";

             $code = '<html><body>No code was created for this art in this category.</body><html>';

             $sql = "SELECT * FROM ".$cfg["tab"]["code"]." WHERE idcatart='".Contenido_Security::toInteger($idcatart)."' AND idlang='".Contenido_Security::escapeDB($lang, $db)."'";

             $db->query($sql);

             if ($db->next_record())
             {
                $sql = "UPDATE ".$cfg["tab"]["code"]." SET code='".Contenido_Security::escapeDB($code, $db)."', idlang='".Contenido_Security::escapeDB($lang, $db)."', idclient='".Contenido_Security::escapeDB($client, $db)."'
                            WHERE idcatart='".Contenido_Security::toInteger($idcatart)."' AND idlang='".Contenido_Security::escapeDB($lang, $db)."'";
                $db->query($sql);
             } else
             {
                $sql = "INSERT INTO ".$cfg["tab"]["code"]." (idcode, idcatart, code, idlang, idclient) VALUES ('".Contenido_Security::toInteger($db->nextid($cfg["tab"]["code"]))."', '".Contenido_Security::toInteger($idcatart)."',
                            '".Contenido_Security::escapeDB($code, $db)."', '".Contenido_Security::escapeDB($lang, $db)."', '".Contenido_Security::escapeDB($client, $db)."')";
                $db->query($sql);
             }

             return "0601";

          }

       }

       /* Get IDLAY and IDMOD array */
       $sql = "SELECT
                           a.idlay AS idlay,
                           a.idtpl AS idtpl
                       FROM
                           ".$cfg["tab"]["tpl"]." AS a,
                           ".$cfg["tab"]["tpl_conf"]." AS b
                       WHERE
                           b.idtplcfg  = '".Contenido_Security::toInteger($idtplcfg)."' AND
                           b.idtpl     = a.idtpl";

       $db->query($sql);
       $db->next_record();

       $idlay = $db->f("idlay");

       if ($layout != false)
       {
          $idlay = $layout;
       }

       $idtpl = $db->f("idtpl");

       if ($debug)
          echo "Usging Layout: $idlay and Template: $idtpl for generation of code.<br><br>";

       /* List of used modules */
       $sql = "SELECT
                           number,
                           idmod
                       FROM
                           ".$cfg["tab"]["container"]."
                       WHERE
                           idtpl = '".Contenido_Security::toInteger($idtpl)."'
                       ORDER BY
                           number ASC";

       $db->query($sql);

       while ($db->next_record())
       {
          $a_d[$db->f("number")] = $db->f("idmod");
       }

       /* Get code from Layout */
       $sql = "SELECT * FROM ".$cfg["tab"]["lay"]." WHERE idlay = '".Contenido_Security::toInteger($idlay)."'";

       $db->query($sql);
       $db->next_record();

       $code = $db->f("code");
       $code = AddSlashes($code);

       /* Create code for all containers */
       if ($idlay)
       {
          cInclude("includes", "functions.tpl.php");
          tplPreparseLayout($idlay);
          $tmp_returnstring = tplBrowseLayoutForContainers($idlay);
          $a_container = explode("&", $tmp_returnstring);

          foreach ($a_container as $key => $value)
          {

             $sql = "SELECT * FROM ".$cfg["tab"]["mod"]." WHERE idmod='".$a_d[$value]."'";

             $db->query($sql);
             $db->next_record();

             if (is_numeric($a_d[$value]))
             {
                $thisModule = '<?php $cCurrentModule = '. ((int) $a_d[$value]).'; ?>';
                $thisContainer = '<?php $cCurrentContainer = '. ((int) $value).'; ?>';
             }

             $output = $thisModule.$thisContainer.$db->f("output");
             $output = AddSlashes($output)."\n";

             $template = $db->f("template");

             $a_c[$value] = preg_replace("/(&\$)/", "", $a_c[$value]);

             $tmp1 = preg_split("/&/", $a_c[$value]);

             $varstring = array ();

             foreach ($tmp1 as $key1 => $value1)
             {

                $tmp2 = explode("=", $value1);
                foreach ($tmp2 as $key2 => $value2)
                {
                   $varstring["$tmp2[0]"] = $tmp2[1];
                }
             }

             $CiCMS_Var = '$C'.$value.'CMS_VALUE';
             $CiCMS_VALUE = '';

             foreach ($varstring as $key3 => $value3)
             {
                $tmp = urldecode($value3);
                $tmp = str_replace("\'", "'", $tmp);
                $CiCMS_VALUE .= $CiCMS_Var.'['.$key3.']="'.$tmp.'"; ';
                $output = str_replace("\$CMS_VALUE[$key3]", $tmp, $output);
                $output = str_replace("CMS_VALUE[$key3]", $tmp, $output);
             }

             $output = str_replace("CMS_VALUE", $CiCMS_Var, $output);
             $output = str_replace("\$".$CiCMS_Var, $CiCMS_Var, $output);

             $output = eregi_replace("(CMS_VALUE\[)([0-9]*)(\])", "", $output);

             if ($frontend_debug["container_display"] == true)
             {
                $fedebug .= "Container: CMS_CONTAINER[$value]".'\\\\n';
             }
             if ($frontend_debug["module_display"] == true)
             {
                $fedebug .= "Modul: ".$db->f("name").'\\\\n';
             }
             if ($frontend_debug["module_timing_summary"] == true || $frontend_debug["module_timing"] == true)
             {
                $fedebug .= 'Eval-Time: $modtime'.$value.'\\\\n';
                $output = '<?php $modstart'.$value.' = getmicrotime(); ?'.'>'.$output.'<?php $modend'.$value.' = getmicrotime()+0.001; $modtime'.$value.' = $modend'.$value.' - $modstart'.$value.'; ?'.'>';
             }

             if ($fedebug != "")
             {
                $output = addslashes('<?php echo \'<img onclick="javascript:showmod'.$value.'();" src="'.$cfg['path']['contenido_fullhtml'].'images/but_preview.gif">\'; ?'.'>'."<br>").$output;
                $output = $output.addslashes('<?php echo \'<script language="javascript">function showmod'.$value.' () { window.alert(\\\'\'. "'.addslashes($fedebug).'".\'\\\');} </script>\'; ?'.'>');
             }

             if ($frontend_debug["module_timing_summary"] == true)
             {
                $output .= addslashes(' <?php $cModuleTimes["'.$value.'"] = $modtime'.$value.'; ?>');
                $output .= addslashes(' <?php $cModuleNames["'.$value.'"] = "'.addslashes($db->f("name")).'"; ?>');
             }
             /* Replace new containers */
             $code = preg_replace("/<container( +)id=\\\\\"$value\\\\\"(.*)>(.*)<\/container>/Uis", "CMS_CONTAINER[$value]", $code);

             $code = preg_replace("/<container( +)id=\\\\\"$value\\\\\"(.*)\/>/i", "CMS_CONTAINER[$value]", $code);

             $code = str_ireplace("CMS_CONTAINER[$value]", "<?php $CiCMS_VALUE ?>\r\n".$output, $code);

             $fedebug = "";

          }
       }

       /* Find out what kind of CMS_... Vars are in use */
       $sql = "SELECT
                           *
                       FROM
                           ".$cfg["tab"]["content"]." AS A,
                           ".$cfg["tab"]["art_lang"]." AS B,
                           ".$cfg["tab"]["type"]." AS C
                       WHERE
                           A.idtype    = C.idtype AND
                           A.idartlang = B.idartlang AND
                           B.idart     = '".Contenido_Security::toInteger($idart)."' AND
                           B.idlang    = '".Contenido_Security::escapeDB($lang, $db)."'";

       $db->query($sql);

       while ($db->next_record())
       {
          $a_content[$db->f("type")][$db->f("typeid")] = $db->f("value");
       }

       $sql = "SELECT idartlang, pagetitle FROM ".$cfg["tab"]["art_lang"]." WHERE idart='".Contenido_Security::toInteger($idart)."' AND idlang='".Contenido_Security::escapeDB($lang, $db)."'";

       $db->query($sql);
       $db->next_record();

       $idartlang = $db->f("idartlang");
       
       $pagetitle = stripslashes($db->f("pagetitle"));

       if ($pagetitle == '') {
          $pagetitle = CEC_Hook::execute("Contenido.Content.CreateTitletag");
          if (is_array($pagetitle)) {
             $pagetitle = '';
          }
       }

       /* replace all CMS_TAGS[] */
       global $cCMS_Types;
       $temp = conGetContentFromCmsType( '', 0 );
          
       $match = array ();
       $tmp = preg_match_all("/(".implode( "|", array_keys( $cCMS_Types['source'] )).")\[([^\]]*)\]/i", $code, $match);
       
       foreach( $match[1] as $iKey => $sCmsType )
       {
          $a_[$sCmsType][] = $match[2][$iKey];
       }

       $search = array ();
       $replacements = array ();
       
       foreach ($match[1] as $iKey => $sType)
       {
          $iId = $match[2][$iKey];
          
          $sCmsTypeName = $sType."[".$iId."]";
          
          $search[$sCmsTypeName] = $sCmsTypeName;
          
          $tempId = (int)$iId;
          
          if( $tempId && $tempId == $iId )
          {
             $replacements[$sCmsTypeName] = conGetContentFromCmsType( $sType, $iId );
          }
          else
          {
             $replacements[$sCmsTypeName] = '\".conGetContentFromCmsType(\"'.$sType.'\", '.$iId.', true ).\"';
          }
       }
	   
       $code = str_ireplace($search, $replacements, $code);
       

       if (is_array($keycode))
       {
          saveKeywordsForArt($keycode, $idart, "auto", $lang);
       }

       /* add/replace title */
       if ($pagetitle != "")
       {
          $code = preg_replace("/<title>.*?<\/title>/is", "{TITLE}", $code);

          if (strstr($code, "{TITLE}"))
          {
             $code = str_ireplace("{TITLE}", addslashes("<title>$pagetitle</title>"), $code);
          } else
          {
             $code = str_ireplace_once("</head>", addslashes("<title>".$pagetitle."</title>\n</head>"), $code);
          }
       } else
       {
          $code = str_replace('<title></title>', '', $code);
       }

       $availableTags = conGetAvailableMetaTagTypes();

       $metatags = array ();
       foreach ($availableTags as $key => $value)
       {
          $metavalue = conGetMetaValue($idartlang, $key);

          if (strlen($metavalue) > 0)
          {
             //$metatags[$value["name"]] = array(array("attribute" => $value["fieldname"], "value" => $metavalue), ...);
             $metatags[] = array ($value["fieldname"] => $value["name"], 'content' => $metavalue);
          }
       }

       /* contenido */
       $metatags[] = array ('name' => 'generator', 'content' => 'CMS Contenido '.$cfg['version']);
       if (getEffectiveSetting('generator', 'xhtml', "false") == "true")
       {
          $metatags[] = array ('http-equiv' => 'Content-Type', 'content' => 'application/xhtml+xml; charset='.$encoding[$lang]);
       } else {
          $metatags[] = array ('http-equiv' => 'Content-Type', 'content' => 'text/html; charset='.$encoding[$lang]);
       }   

       $_cecIterator = $_cecRegistry->getIterator("Contenido.Content.CreateMetatags");

       if ($_cecIterator->count() > 0)
       {
          $tmpMetatags = array ();
          while ($chainEntry = $_cecIterator->next())
          {
             $tmpMetatags = $chainEntry->execute($metatags);

             //added 2008-06-25 Timo Trautmann -- system metatags were merged to user meta tags and user meta tags were not longer replaced by system meta tags
             if (is_array($tmpMetatags))
             {
                //check for all system meta tags if there is already a user meta tag
                foreach ($tmpMetatags as $aAutValue) {
                   $bExists = false;
       
                   //get name of meta tag for search
                   $sSearch = '';
                   if (array_key_exists('name', $aAutValue)) {
                      $sSearch = $aAutValue['name'];
                   } else if (array_key_exists('http-equiv', $aAutValue)) {
                      $sSearch = $aAutValue['http-equiv'];
                   }
       
                   //check if meta tag is already in list of user meta tags
                   if (strlen($sSearch) > 0) {
                      foreach ($metatags as $aValue) {
                         if (array_key_exists('name', $aValue)) {
                            if ($sSearch == $aValue['name']) {
                               $bExists = true;
                               break;
                            }
                         } else if (array_key_exists('http-equiv', $aAutValue)) {
                            if ($sSearch == $aValue['http-equiv']) {
                               $bExists = true;
                               break;
                            }
                         }
                      }
                   }
       
                   //add system meta tag if there is no user meta tag
                   if ($bExists == false && strlen($aAutValue['content']) > 0) {
                      array_push($metatags, $aAutValue);
                   }
                }
             }
          }
       }

       $sMetatags = '';
       
       cInclude("classes", "class.htmlelements.php");
       
       foreach ($metatags as $value)
       {
          // build up metatag string
          $oMetaTagGen = new cHTML;
          $oMetaTagGen->_tag = 'meta';
          $oMetaTagGen->updateAttributes($value);

          /* HTML does not allow ID for meta tags */
          $oMetaTagGen->removeAttribute("id");
           
            /*Check if metatag already exists*/
            if (preg_match('/(<meta(?:\s+)name(?:\s*)=(?:\s*)(?:\\\\"|\\\\\')(?:\s*)'.$value["name"].'(?:\s*)(?:\\\\"|\\\\\')(?:[^>]+)>\r?\n?)/i', $code, $aTmetatagfound)) {
                $code = str_replace($aTmetatagfound[1], $oMetaTagGen->render()."\n", $code);
            } else {
                $sMetatags .= $oMetaTagGen->render()."\n";
            }
       }

       /* Add meta tags */
       $code = str_ireplace_once("</head>", $sMetatags."</head>", $code);

       /* write code into the database */
       $date = date("Y-m-d H:i:s");

       if ($layout == false)
       {
          $sql = "SELECT * FROM ".$cfg["tab"]["code"]." WHERE idcatart = '".Contenido_Security::toInteger($idcatart)."' AND idlang = '".Contenido_Security::escapeDB($lang, $db)."'";

          $db->query($sql);

          if ($db->next_record())
          {
             if ($debug)
                echo "UPDATED code for lang:$lang, client:$client, idcatart:$idcatart";
             $sql = "UPDATE ".$cfg["tab"]["code"]." SET code='".Contenido_Security::escapeDB($code, $db, false)."', idlang='".Contenido_Security::escapeDB($lang, $db)."', idclient='".Contenido_Security::escapeDB($client, $db)."'
                   WHERE idcatart='".Contenido_Security::toInteger($idcatart)."' AND idlang='".Contenido_Security::escapeDB($lang, $db)."'";
             $db->query($sql);
          } else
          {
             if ($debug)
                echo "INSERTED code for lang:$lang, client:$client, idcatart:$idcatart";
             $sql = "INSERT INTO ".$cfg["tab"]["code"]." (idcode, idcatart, code, idlang, idclient) VALUES ('".Contenido_Security::toInteger($db->nextid($cfg["tab"]["code"]))."', '".Contenido_Security::toInteger($idcatart)."',
                   '".Contenido_Security::escapeDB($code, $db, false)."', '".Contenido_Security::escapeDB($lang, $db)."', '".Contenido_Security::escapeDB($client, $db)."')";
             $db->query($sql);
          }

          $sql = "UPDATE ".$cfg["tab"]["cat_art"]." SET createcode = '0' WHERE idcatart='".Contenido_Security::toInteger($idcatart)."'";
          $db->query($sql);
       }

        // execute CEC hook
        $code = CEC_Hook::execute('Contenido.Content.conGenerateCode', $code);
       
       return $code;
    }

    /**
    * Returns the idartlang for a given article and language
    *
    * @param $idart ID of the article
    * @param $idlang ID of the language
    * @return mixed idartlang of the article or false if nothing was found
    *
    * @author Timo A. Hummel <Timo.Hummel@4fb.de>
    * @copyright four for business AG 2003
    */
    function getArtLang($idart, $idlang)
    {
       global $cfg;

       $db = new DB_Contenido;
       $sql = "SELECT idartlang FROM ".$cfg["tab"]["art_lang"]." WHERE "."idart = '".Contenido_Security::toInteger($idart)."' AND idlang = '".Contenido_Security::toInteger($idlang)."'";

       $db->query($sql);
       if ($db->next_record())
       {
          return $db->f("idartlang");
       } else
       {
          return false;
       }
    }

    /**
    * Returns all available meta tag types
    *
    * @param none
    *
    * @author Timo A. Hummel <Timo.Hummel@4fb.de>
    * @copyright four for business AG 2003
    */
    function conGetAvailableMetaTagTypes()
    {
       global $cfg;

       $db = new DB_Contenido;

       $sql = "SELECT idmetatype, metatype, fieldtype, maxlength, fieldname
             FROM ".$cfg["tab"]["meta_type"];

       $db->query($sql);

       $metatag = array ();

       while ($db->next_record())
       {
          $newentry["name"] = $db->f("metatype");
          $newentry["fieldtype"] = $db->f("fieldtype");
          $newentry["maxlength"] = $db->f("maxlength");
          $newentry["fieldname"] = $db->f("fieldname");
          $metatag[$db->f("idmetatype")] = $newentry;
       }

       return $metatag;

    }

    /**
    * Get the meta tag value for a specific article
    *
    * @param $idartlang ID of the article
    * @param $idmetatype Metatype-ID
    *
    * @author Timo A. Hummel <Timo.Hummel@4fb.de>
    * @copyright four for business AG 2003
    */
    function conGetMetaValue($idartlang, $idmetatype)
    {
       global $cfg;

       if ($idartlang == 0)
       {
          return;
       }

       $db = new DB_Contenido;

       $sql = "SELECT metavalue
             FROM ".$cfg["tab"]["meta_tag"]." WHERE idartlang = '".Contenido_Security::toInteger($idartlang)."'
             AND idmetatype = '".Contenido_Security::toInteger($idmetatype)."'";

       $db->query($sql);

       if ($db->next_record())
       {
          return stripslashes($db->f("metavalue"));
       } else
       {
          return "";
       }

    }

    /**
    * Set the meta tag value for a specific article
    *
    * @param $idartlang ID of the article
    * @param $idmetatype Metatype-ID
    * @param $value Value of the meta tag
    *
    * @author Timo A. Hummel <Timo.Hummel@4fb.de>
    * @copyright four for business AG 2003
    */
    function conSetMetaValue($idartlang, $idmetatype, $value)
    {
       global $cfg;

       $db = new DB_Contenido;
       $sql = "DELETE FROM ".$cfg["tab"]["meta_tag"]."
             WHERE idartlang = '".Contenido_Security::toInteger($idartlang)."'
             AND idmetatype = '".Contenido_Security::toInteger($idmetatype)."'";

       $db->query($sql);

       $nextid = $db->nextid($cfg["tab"]["meta_tag"]);

       $sql = "INSERT INTO ".$cfg["tab"]["meta_tag"]." SET idartlang = '".Contenido_Security::toInteger($idartlang)."',
             idmetatype = '".Contenido_Security::toInteger($idmetatype)."',
             idmetatag = '".Contenido_Security::toInteger($nextid)."',
             metavalue = '".Contenido_Security::escapeDB($value, $db)."'";

       $db->query($sql);

    }

    /**
    * (re)generate keywords for all articles of a given client (with specified language)
    * @param $client Client
    * @param $lang Language of a client
    * @return void
    *
    * @author Willi Man
    * Created   :   12.05.2004
    * Modified  :   13.05.2004
    * @copyright four for business AG 2003
    */
    function conGenerateKeywords($client, $lang)
    {
       global $cfg;
       $db_art = new DB_Contenido;

       $options = array ("img", "link", "linktarget", "swf"); // cms types to be excluded from indexing

       $sql = "SELECT
                    a.idart, b.idartlang
                 FROM
                    ".$cfg["tab"]["art"]." AS a,
                    ".$cfg["tab"]["art_lang"]." AS b
                 WHERE
                    a.idart    = b.idart AND
                    a.idclient = ".Contenido_Security::escapeDB($client, $db)." AND
                    b.idlang = ".Contenido_Security::escapeDB($lang, $db);

       $db_art->query($sql);

       $articles = array ();
       while ($db_art->next_record())
       {
          $articles[$db_art->f("idart")] = $db_art->f("idartlang");
       }

       if (count($articles) > 0)
       {
          cInclude('classes', 'class.search.php');

          foreach ($articles as $artid => $article_lang)
          {
             $article_content = array ();
             $article_content = conGetContentFromArticle($article_lang);

             if (count($article_content) > 0)
             {
                $art_index = new Index($db_art);
                $art_index->lang = $lang;
                $art_index->start($artid, $article_content, 'auto', $options);
             }

          }
       }

    }

    /**
    * get content from article
    * @param $article_lang ArticleLanguageId of an article (idartlang)
    * @return array Array with content of an article indexed by content-types
    *
    * @author Willi Man
    * Created   :   12.05.2004
    * Modified  :   13.05.2004
    * @copyright four for business AG 2003
    */
    function conGetContentFromArticle($article_lang)
    {

       global $cfg;
       $db_con = new DB_Contenido;

       $sql = "SELECT
                   *
                FROM
                   ".$cfg["tab"]["content"]." AS A,
                   ".$cfg["tab"]["art_lang"]." AS B,
                   ".$cfg["tab"]["type"]." AS C
                WHERE
                   A.idtype    = C.idtype AND
                   A.idartlang = B.idartlang AND
                   A.idartlang     = '".Contenido_Security::escapeDB($article_lang, $db_con)."' ";

       $db_con->query($sql);

       while ($db_con->next_record())
       {
          $a_content[$db_con->f("type")][$db_con->f("typeid")] = urldecode($db_con->f("value"));
       }

       return $a_content;

    }



    /**
    * get content from article-cms-type
    * @param $sType CMS-Type of Content (DB:_type:type)
    * @param $iId Id of CMS-Type (DB:_content:typeid)
    * @return string String of the CMS-Type
    *
    * @author Oliver Lohkemper
    * Created   :   03.05.2010
    * Modified  :   -
    * @copyright four for business AG 2010
    */
    function conGetContentFromCmsType( $sType, $iId, $bFromCache=false )
    {
       global $cfg, $db, $idcat, $idart, $idartlang, $lang, $edit, $cCMS_Types, $keycode, $a_content, $sess;

       // globals for Cms-Types-Code
       global $val, $a_content;
	          
       if (!is_object($db))
          $db = new DB_Contenido;
		  
		if( is_array($keycode) )
			$keycode = array();
       
       /*
        * Cache Cms-Type-Code and Content by Article
        */
       if( !is_array($cCMS_Types) )
       {
          $cCMS_Types = array( 'source'=>array(), 'content'=>array(), 'return'=>array() );
          
          $db->query("SELECT type, code FROM ".$cfg["tab"]["type"]);
          
          while ($db->next_record())
          {
             $cCMS_Types['source'][ $db->f("type") ] = $db->f("code");
          }
          
          $cCMS_Types['content'] = conGetContentFromArticle($idartlang);
       }
	   
       $a_content = $cCMS_Types['content'];
		  
       /*
        * Cache Cms-Type-Code result
        */
		if( !array_key_exists($sType, $cCMS_Types['return'])
			|| !array_key_exists($iId, $cCMS_Types['return'][$sType]) )
		{
			$val = $iId;
		  
			eval ($cCMS_Types["source"][$sType]);
          	
			$keycode[$sType][$iId] = $tmp.'--'.($cache?1:2);
			$cCMS_Types['return'][$sType][$iId] = $tmp;
		}
	   
		
		/*
		 * If Code from con_cache return stripslashes-String
		 */
		if( $bFromCache )
		{
			eval ('$temp = "'.stripslashes($cCMS_Types['return'][$sType][$iId]).'";');
			return $temp;
		}
		else
			return $cCMS_Types['return'][$sType][$iId];
	}
    ?>
Zuletzt geändert von OliverL am Di 18. Mai 2010, 16:21, insgesamt 4-mal geändert.
Grund: Korrektur

OliverL
Beiträge: 870
Registriert: Do 28. Jun 2007, 09:28
Kontaktdaten:

Re: CMS_Types verfügbar machen wie CMS_VALUE

Beitrag von OliverL » Di 18. Mai 2010, 13:12

Hab da noch mal drüber geguckt und muste die erste Version als nicht-funktionsfähig abstämpeln.
Hab den Code oben korrigiert.

Für den edit-Bereich muss auch noch follgende Datei geändert werden:

Vollständige Datei include.con_editcontent.php:

Code: Alles auswählen

<?php
/**
 * Project: 
 * Contenido Content Management System
 * 
 * Description: 
 * Include for editing the content in an article
 * 
 * Requirements: 
 * @con_php_req 5.0
 * 
 *
 * @package    Contenido Backend includes
 * @version    1.0.1
 * @author     Jan Lengowski
 * @copyright  four for business AG <www.4fb.de>
 * @license    http://www.contenido.org/license/LIZENZ.txt
 * @link       http://www.4fb.de
 * @link       http://www.contenido.org
 * @since      file available since contenido release <= 4.6
 * 
 * {@internal 
 *   created 2003
 *   modified 2008-06-16, Holger Librenz, Hotfix: check for illegal calls added
 *   modified 2008-06-27, Frederic Schneider, add security fix
 *
 *   $Id: include.con_editcontent.php 1004 2009-04-09 12:08:15Z timo.trautmann $:
 * }}
 * 
 */

if(!defined('CON_FRAMEWORK')) {
	die('Illegal call');
}

if (isset($_REQUEST['cfg']) || isset($_REQUEST['contenido_path'])) {
    die ('Illegal call!');
}

/* Compatibility: Include new functions.con2.php */
cInclude("includes", "functions.con2.php");

$edit 		= "true";

$db2 		= new DB_Contenido;
$scripts	= "";

if ( isset($idcat) )
{
	if( $action == 20 || $action == 10 )
	{
		if( $data != "" )
		{
			$data = explode("||", substr($data, 0, -2));

			foreach($data as $value)
			{
				$value = explode("|", $value);

				if ( $value[3] == "%$%EMPTY%$%" ) {
					$value[3] = "";
				} else {
					$value[3] = str_replace("%$%SEPERATOR%$%", "|", $value[3]);
				}

				conSaveContentEntry($value[0], "CMS_".$value[1], $value[2], $value[3]);
			}

			conMakeArticleIndex ($idartlang, $idart);

			// restore orginal values
			$data 	= $_REQUEST['data'];
			$value	= $_REQUEST['value'];
		}
		
		conGenerateCodeForArtInAllCategories ($idart);
	}

	if ( $action == 10 )
	{
		header("Location: ".$cfg["path"]["contenido_fullhtml"].$cfg["path"]["includes"]."include.backendedit.php?type=$type&typenr=$typenr&client=$client&lang=$lang&idcat=$idcat&idart=$idart&idartlang=$idartlang&contenido=$contenido&lang=$lang");
	} else {

		$markSubItem = markSubMenuItem(3, true);

    //Include tiny class
    include ($cfg["path"]["contenido"] . 'external/wysiwyg/tinymce3/editorclass.php');
    $oEditor = new cTinyMCEEditor ('', '');
    $oEditor->setToolbar('inline_edit');
    
    //Get configuration for popup und inline tiny
    $sConfigInlineEdit = $oEditor->getConfigInlineEdit(); 
    $sConfigFullscreen = $oEditor->getConfigFullscreen();        
    
    //Include tiny mce and con_tiny script for insight_editing    
    $scripts .= "\n".'<script src="'.$cfg["path"]["contenido_fullhtml"].'scripts/jquery/jquery.js" type="text/javascript"></script>';
    $scripts .= "\n".'<script src="'.$cfg["path"]["contenido_fullhtml"].'scripts/con_tiny.js" type="text/javascript"></script>';
    $scripts .= "\n<!-- tinyMCE -->\n".'<script language="javascript" type="text/javascript" src="'.$cfg["path"]["contenido_fullhtml"].'external/wysiwyg/tinymce3/jscripts/tiny_mce/tiny_mce.js"></script>';
    
    //Script template for insight editing
	$scripts .= <<<EOD
<style type="text/css">
	.defaultSkin table.mceLayout {position: absolute; z-index: 10000;}
	.defaultSkin #mce_fullscreen_tbl {z-index: 20000;}
	.defaultSkin .mcePlaceHolder {position: absolute; z-index: 10000;}
</style>
	
	
<script language="javascript">

tinymce.create('tinymce.plugins.ClosePlugin', {
	createControl: function(n, cm) {
		switch (n) {
			case 'close':
				var c = cm.createMenuButton('close', {
					title : '{CLOSE}',
					image : '{CON_PATH}images/back.gif',
					icons : false,
					onclick : function(ed) {
			           closeTiny();
			        }
				});

				// Return the new menu button instance
				return c;
				
			case 'save':
				var c = cm.createMenuButton('save', {
					title : '{SAVE}',
					image : '{CON_PATH}images/save.gif',
					icons : false,
					onclick : function(ed) {
			           setcontent(iIdartlang, '0');
			        }
				});

				// Return the new menu button instance
				return c;
		}

		return null;
	}
});

// Register plugin with a short name
tinymce.PluginManager.add('close', tinymce.plugins.ClosePlugin);

var active_id = null;  //id of div on which tiny is active
var active_object = null;  //onject of div on which tiny is active
var aEditdata = new Object();  //global array which stores edited content
var aEditdataOrig = new Object();  //global array which stored original content (Importent for decision if content has changed)
var bCheckLeave = true;  //globak var which defines if user is asked to store changes

//Global vars for contenido popup filebrowser
var fb_fieldname;
var fb_handle;
var fb_intervalhandle;
var fb_win;

//Configuration of tiny, when tiny is opened set event which stores original 
//content to global var aEditdataOrig
var tinymceConfigs = {
    {TINY_OPTIONS},
    fullscreen_settings : {
        {TINY_FULLSCREEN}
    },
    'setup' : function(ed) {
      ed.onSetContent.add(function(ed, o) {
            updateContent(ed.getContent());
      })}
};
tinyMCE.settings = tinymceConfigs;

//add tiny to elements which contains classname contentEditable
//tiny toggles on click 
$(document).ready( function(){
   $('div[contenteditable=true]').each( function(){
	  $(this).attr('contentEditable', 'false'); //remove coneditable tags in order to disable special firefox behaviour
      $(this).bind( "click", function(){
         {USE_TINY}
      });
   });
});

//activate save confirmation on page leave
if (document.all) {
	window.onunload = leave_check;
} else {
	window.onbeforeunload = leave_check;
}

var file_url = "{FILE}"; //Global var which contains url to contenido image browser
var image_url = "{IMAGE}"; //Global var which contains url to contenido file browser
var flash_url = "{FLASH}"; //Global var which contains url to contenido flash browser
var media_url = "{MEDIA}"; //Global var which contains url to contenido media browser
var frontend_path = "{FRONTEND}";

var iIdartlang = '{IDARTLANG}'; //Idartlang which is currently edited
var sQuestion = '{QUESTION}'; //Translation of save confirmation

</script>

EOD;

        //Replace vars in Script
        $oScriptTpl = new Template();
        
        //Set urls to file browsers
        $oScriptTpl->set('s', 'IMAGE', $cfg["path"]["contenido_fullhtml"] .'frameset.php?area=upl&contenido='.$sess->id.'&appendparameters=imagebrowser');
        $oScriptTpl->set('s', 'FILE', $cfg["path"]["contenido_fullhtml"] .'frameset.php?area=upl&contenido='.$sess->id.'&appendparameters=filebrowser');
        $oScriptTpl->set('s', 'FLASH', $cfg["path"]["contenido_fullhtml"] .'frameset.php?area=upl&contenido='.$sess->id.'&appendparameters=imagebrowser');
        $oScriptTpl->set('s', 'MEDIA', $cfg["path"]["contenido_fullhtml"] .'frameset.php?area=upl&contenido='.$sess->id.'&appendparameters=imagebrowser');
        $oScriptTpl->set('s', 'FRONTEND', $cfgClient[$client]["path"]["htmlpath"]);
		
        //Add tiny options and fill function leave_check()
        $oScriptTpl->set('s', 'TINY_OPTIONS', $sConfigInlineEdit);
        $oScriptTpl->set('s', 'TINY_FULLSCREEN', $sConfigFullscreen);
        $oScriptTpl->set('s', 'IDARTLANG', $idartlang);
		$oScriptTpl->set('s', 'CON_PATH', $cfg["path"]["contenido_fullhtml"]);
		$oScriptTpl->set('s', 'CLOSE', i18n('Close editor'));
		$oScriptTpl->set('s', 'SAVE', i18n('Close editor and save changes'));
        $oScriptTpl->set('s', 'QUESTION', i18n('Do you want to save changes?'));
		
		if (getEffectiveSetting('system', 'insight_editing_activated', 'true') == 'false') {
			$oScriptTpl->set('s', 'USE_TINY', '');
		} else {
			$oScriptTpl->set('s', 'USE_TINY', 'swapTiny(this);');
		}
        
        $scripts = $oScriptTpl->generate($scripts, 1);
        
        $contentform  = "<form name=\"editcontent\" method=\"post\" action=\"".$sess->url($cfg['path']['contenido_fullhtml']."external/backendedit/front_content.php?area=con_editcontent&idart=$idart&idcat=$idcat&lang=$lang&action=20&client=$client")."\">\n";
        $contentform .= "<input type=\"hidden\" name=\"changeview\" value=\"edit\">\n";
        $contentform .= "<input type=\"hidden\" name=\"data\" value=\"\">\n";
        $contentform .= "</form>";

        #
        # extract IDCATART
        #
        $sql = "SELECT
                    idcatart
                FROM
                    ".$cfg["tab"]["cat_art"]."
                WHERE
                    idcat = '".$idcat."' AND
                    idart = '".$idart."'";

        $db->query($sql);
        $db->next_record();

        $idcatart = $db->f("idcatart");

        #
        # Article is not configured,
        # if not check if the category
        # is configured. It neither the
        # article or the category is
        # configured, no code will be
        # created and an error occurs.
        #

        $sql = "SELECT
                    a.idtplcfg AS idtplcfg
                FROM
                    ".$cfg["tab"]["art_lang"]." AS a,
                    ".$cfg["tab"]["art"]." AS b
                WHERE
                    a.idart     = '".Contenido_Security::toInteger($idart)."' AND
                    a.idlang    = '".Contenido_Security::toInteger($lang)."' AND
                    b.idart     = a.idart AND
                    b.idclient  = '".Contenido_Security::toInteger($client)."'";

        $db->query($sql);
        $db->next_record();

        if ( $db->f("idtplcfg") != 0 ) {

            #
            # Article is configured
            #
            $idtplcfg = $db->f("idtplcfg");

            $a_c = array();

            $sql2 = "SELECT
                        *
                     FROM
                        ".$cfg["tab"]["container_conf"]."
                     WHERE
                        idtplcfg = '".Contenido_Security::toInteger($idtplcfg)."'
                     ORDER BY
                        number ASC";

            $db2->query($sql2);

            while ( $db2->next_record() ) {
                $a_c[$db2->f("number")] = $db2->f("container");

            }

        } else {

            #
            # Check whether category is
            # configured.
            #
            $sql = "SELECT
                        a.idtplcfg AS idtplcfg
                    FROM
                        ".$cfg["tab"]["cat_lang"]." AS a,
                        ".$cfg["tab"]["cat"]." AS b
                    WHERE
                        a.idcat     = '".Contenido_Security::toInteger($idcat)."' AND
                        a.idlang    = '".Contenido_Security::toInteger($lang)."' AND
                        b.idcat     = a.idcat AND
                        b.idclient  = '".Contenido_Security::toInteger($client)."'";

            $db->query($sql);
            $db->next_record();

            if ( $db->f("idtplcfg") != 0 ) {

                #
                # Category is configured,
                # extract varstring
                #
                $idtplcfg = $db->f("idtplcfg");

                $a_c = array();

                $sql2 = "SELECT
                            *
                         FROM
                            ".$cfg["tab"]["container_conf"]."
                         WHERE
                            idtplcfg = '".Contenido_Security::toInteger($idtplcfg)."'
                         ORDER BY
                            number ASC";

                $db2->query($sql2);

                while ( $db2->next_record() ) {
                    $a_c[$db2->f("number")] = $db2->f("container");

                }

            } else {

                #
                # Article nor Category
                # is configured. Creation of
                # Code is not possible. Write
                # Errormsg to DB.
                #
				if ( $_REQUEST['cfg'] ) { exit; }
                include_once ($cfg["path"]["contenido"].$cfg["path"]["classes"]."class.notification.php");
                include_once ($cfg["path"]["contenido"].$cfg["path"]["classes"]."class.table.php");

                if ( !is_object($notification) ) {
                    $notification = new Contenido_Notification;
                }

                $sql = "SELECT title FROM ".$cfg["tab"]["art_lang"]." WHERE idartlang = '".Contenido_Security::toInteger($idartlang)."'";
                $db->query($sql);
                $db->next_record();
                $art_name = $db->f("title");

                $cat_name = "";
                conCreateLocationString($idcat, "&nbsp;/&nbsp;", $cat_name);

                $sql = "SELECT name FROM ".$cfg["tab"]["lang"]." WHERE idlang = '".Contenido_Security::toInteger($lang)."'";
                $db->query($sql);
                $db->next_record();
                $lang_name = $db->f("name");

                $sql = "SELECT name FROM ".$cfg["tab"]["clients"]." WHERE idclient = '".Contenido_Security::toInteger($client)."'";
                $db->query($sql);
                $db->next_record();
                $client_name = $db->f("name");

                $noti_html = '<table cellspacing="0" cellpadding="2" border="0">

                                <tr class="text_medium">
                                    <td colspan="2">
                                        <b>'.i18n("No template assigned to the category<br>and/or the article").'</b><br><br>
                                        '.i18n("The code for the following article<br>couldnt be generated:").'
                                        <br><br>
                                    </td>
                                </tr>

                                <tr class="text_medium">
                                    <td >'.i18n("Article").':</td>
                                    <td><b>'.$art_name.'</b></td>
                                </tr>

                                <tr class="text_medium">
                                    <td >'.i18n("Category").':</td>
                                    <td><b>'.$cat_name.'</b></td>
                                </tr>

                                <tr class="text_medium">
                                    <td>'.i18n("Language").':</td>
                                    <td><b>'.$lang_name.'</b></td>
                                </tr>

                                <tr class="text_medium">
                                    <td>'.i18n("Client").':</td>
                                    <td><b>'.$client_name.'</b></td>
                                </tr>

                                <tr>
                                    <td colspan="2">&nbsp;</td>
                                </tr>

                              </table>';

                $code = '
                        <html>
                            <head>
                                <title>Error</title>
                                <link rel="stylesheet" type="text/css" href="'.$cfg["path"]["contenido_fullhtml"].$cfg["path"]["styles"].'contenido.css"></link>
                            </head>
                            <body style="margin: 10px">'.$notification->returnNotification("error", $noti_html).'</body>
                        </html>';

                $sql = "SELECT * FROM ".$cfg["tab"]["code"]." WHERE idcatart='".Contenido_Security::toInteger($idcatart)."' AND idlang='".Contenido_Security::toInteger($lang)."'";
                $db->query($sql);

                if ($db->next_record()) {
                    $sql = "UPDATE ".$cfg["tab"]["code"]." SET code='".Contenido_Security::escapeDB($code, $db)."', idlang='".Contenido_Security::toInteger($lang)."', idclient='".Contenido_Security::toInteger($client)."'
                            WHERE idcatart='".Contenido_Security::toInteger($idcatart)."' AND idlang='".Contenido_Security::toInteger($lang)."'";
                    $db->query($sql);
                } else {
                    $sql = "INSERT INTO ".$cfg["tab"]["code"]." (idcode, idcatart, code, idlang, idclient) VALUES ('".Contenido_Security::toInteger($db->nextid($cfg["tab"]["code"]))."', '".Contenido_Security::toInteger($idcatart)."',
                            '".Contenido_Security::escapeDB($code, $db)."', '".Contenido_Security::toInteger($lang)."', '".Contenido_Security::toInteger($client)."')";
                    $db->query($sql);
                }

                echo $code;

            }

        }

        #
        # Get IDLAY and IDMOD array
        #
        $sql = "SELECT
                    a.idlay AS idlay,
                    a.idtpl AS idtpl
                FROM
                    ".$cfg["tab"]["tpl"]." AS a,
                    ".$cfg["tab"]["tpl_conf"]." AS b
                WHERE
                    b.idtplcfg  = '".Contenido_Security::toInteger($idtplcfg)."' AND
                    b.idtpl     = a.idtpl";

        $db->query($sql);
        $db->next_record();

        $idlay = $db->f("idlay");
        $idtpl = $db->f("idtpl");

        #
        # List of used modules
        #
        $sql = "SELECT
                    number,
                    idmod
                FROM
                    ".$cfg["tab"]["container"]."
                WHERE
                    idtpl = '".Contenido_Security::toInteger($idtpl)."'
                ORDER BY
                    number ASC";

        $db->query($sql);

        while ( $db->next_record() ) {
            $a_d[$db->f("number")] = $db->f("idmod");
        }

        #
        # Get code from Layout
        #
        $sql = "SELECT * FROM ".$cfg["tab"]["lay"]." WHERE idlay = '".Contenido_Security::toInteger($idlay)."'";

        $db->query($sql);
        $db->next_record();

        $code = $db->f("code");
        $code = AddSlashes($code);

        #
        # Create code for all containers
        #
        if ($idlay) {
				tplPreparseLayout($idlay);
                $tmp_returnstring = tplBrowseLayoutForContainers($idlay);

                $a_container = explode("&", $tmp_returnstring);

                foreach ($a_container as $key=>$value) {

					$CiCMS_VALUE = "";

                    $sql = "SELECT * FROM ".$cfg["tab"]["mod"]." WHERE idmod='".Contenido_Security::toInteger($a_d[$value])."'";

                    $db->query($sql);
                    $db->next_record();

					if (is_numeric($a_d[$value]))
					{
						$thisModule = '<?php $cCurrentModule = '.((int)$a_d[$value]).'; ?>';
						$thisContainer = '<?php $cCurrentContainer = '.((int)$value).'; ?>';
					}

                    $output = $thisModule . $thisContainer . $db->f("output");
                    $output = AddSlashes($output);

                    $template = $db->f("template");

					if (array_key_exists($value, $a_c))
					{
						$a_c[$value] = preg_replace("/(&\$)/","", $a_c[$value]);
	                    $tmp1 = preg_split("/&/", $a_c[$value]);
					} else {
						$tmp1 = array();
					}

                    $varstring = array();

                    foreach ($tmp1 as $key1=>$value1) {
                            $tmp2 = explode("=", $value1);
                            foreach ($tmp2 as $key2 => $value2) {
                                    $varstring["$tmp2[0]"] = $tmp2[1];
                            }
                    }

                   	$CiCMS_Var = '$C'.$value.'CMS_VALUE';
                    $CiCMS_VALUE = '';

                    foreach ($varstring as $key3=>$value3){
                      $tmp = urldecode($value3);
                      $tmp = str_replace("\'", "'", $tmp);
                      $CiCMS_VALUE .= $CiCMS_Var.'['.$key3.']="'.$tmp.'"; ';
                      $output = str_replace("\$CMS_VALUE[$key3]", $tmp, $output);
                      $output = str_replace("CMS_VALUE[$key3]", $tmp, $output);
                    }

                    $output = str_replace("CMS_VALUE", $CiCMS_Var, $output);
                    $output = str_replace("\$".$CiCMS_Var, $CiCMS_Var, $output);

                    $output = eregi_replace("(CMS_VALUE\[)([0-9]*)(\])", "", $output);

                    /* Long syntax with closing tag */
                    $code = preg_replace("/<container( +)id=\\\\\"$value\\\\\"(.*)>(.*)<\/container>/Uis", "CMS_CONTAINER[$value]", $code);

                    /* Short syntax */
                    $code = preg_replace("/<container( +)id=\\\\\"$value\\\\\"(.*)\/>/i", "CMS_CONTAINER[$value]", $code);

                    $code = str_ireplace("CMS_CONTAINER[$value]", "<?php $CiCMS_VALUE ?>\r\n".$output, $code);



                }
        }

        #
        # Find out what kind of CMS_... Vars are in use
        #
        
        /*
        $sql = "SELECT
                    *
                FROM
                    ".$cfg["tab"]["content"]." AS A,
                    ".$cfg["tab"]["art_lang"]." AS B,
                    ".$cfg["tab"]["type"]." AS C
                WHERE
                    A.idtype    = C.idtype AND
                    A.idartlang = B.idartlang AND
                    B.idart     = '".Contenido_Security::toInteger($idart)."' AND
                    B.idlang    = '".Contenido_Security::toInteger($lang)."'";

        $db->query($sql);

        while ( $db->next_record() ) {
            $a_content[$db->f("type")][$db->f("typeid")] = $db->f("value");
        }

        $sql = "SELECT idartlang FROM ".$cfg["tab"]["art_lang"]." WHERE idart='".Contenido_Security::toInteger($idart)."' AND idlang='".Contenido_Security::toInteger($lang)."'";

        $db->query($sql);
        $db->next_record();

        $idartlang = $db->f("idartlang");
		*/
		
       global $cCMS_Types, $a_content, $edit;
       $temp = conGetContentFromCmsType( '', 0 );
          
       $match = array ();
       $tmp = preg_match_all("/(".implode( "|", array_keys( $cCMS_Types['source'] )).")\[([^\]]*)\]/i", $code, $match);
       
       foreach( $match[1] as $iKey => $sCmsType )
       {
          $a_[$sCmsType][] = $match[2][$iKey];
       }

       $search = array ();
       $replacements = array ();
       
       foreach ($match[1] as $iKey => $sType)
       {
          $iId = $match[2][$iKey];
          
          $sCmsTypeName = $sType."[".$iId."]";
          
          $search[$sCmsTypeName] = $sCmsTypeName;
          
          $tempId = (int)$iId;
          
          if( $tempId && $tempId == $iId )
          {
             $replacements[$sCmsTypeName] = conGetContentFromCmsType( $sType, $iId );
          }
          else
          {
             $replacements[$sCmsTypeName] = '\".conGetContentFromCmsType(\"'.$sType.'\", '.$iId.', true ).\"';
          }
       }
	    
       # print_r( $cCMS_Types['return'] );
       # print_r( $a_content );
       
       $code = str_ireplace($search, $replacements, $code);
       




        #
        # Replace all CMS_TAGS[]
        #
        $sql = "SELECT idtype, type, code FROM ".$cfg["tab"]["type"];

        $db->query($sql);

        while ( $db->next_record() )
        {

            $tmp = preg_match_all("/(".$db->f("type")."\[+\d+\])/i", $code, $match);
            $a_[strtolower($db->f("type"))] = $match[0];
            $success = array_walk($a_[strtolower($db->f("type"))], 'extractNumber');

    		$search = array();
    		$replacements = array();


            foreach ($a_[strtolower($db->f("type"))] as $val)
            {
                eval ($db->f("code"));

                $search[$val] = $db->f("type") ."[$val]";
                $replacements[$val] = addslashes($tmp);
            }

            $code  = str_ireplace($search, $replacements, $code);
		}
        

		unset($tmp);

        /* output the code */
        $code = stripslashes($code);
        $code = str_ireplace_once("</head>", "$markSubItem $scripts\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$encoding[$lang]\"></head>", $code);
        $code = str_ireplace_once_reverse("</body>", "$contentform</body>", $code);

		if ($cfg["debug"]["codeoutput"])
      	{
			echo "<textarea>".htmlspecialchars($code)."</textarea>";
      	}

        $code = str_ireplace_once("<head>", "<head>\n".'<base href="'.$cfgClient[$client]["path"]["htmlpath"].'">', $code);

        chdir($cfgClient[$client]["path"]["frontend"]);
      	eval("?>\n".$code."\n<?php\n");



    }
}
page_close();

?>

Antworten