Templatekonfiguration vererben.

Gesperrt
tono
Beiträge: 574
Registriert: Mo 25. Apr 2005, 20:51
Wohnort: Frankfurt am Main
Kontaktdaten:

Templatekonfiguration vererben.

Beitrag von tono »

In Contenido muß jede Kategorie ein Template zugewiesen bekommen. Es gibt aber durchaus vorstellbare Szenarien in denen es praktisch wäre, wenn die Konfiguration der Mutterkategorie verwendet würde, wenn eine Kategorie nicht konfiguriert ist. Sozusagen vererbt eine Kategorie ihre Konfiguration nicht nur an ihre Artikel, sondern auch an ihre Unterkategorieen und so fort.

Um eine solche Funktionalität zu erzielen bedarf es tiefer Eingriffe ins System. Deshalb der Hinweis:
!!!Achtung!!! Lass die Finger von diesem Artikel, wenn Du nicht genau weißt was Du tust. Ein kleines Backup hat auch noch niemandem geschadet.

Diese Änderungen sind auch nicht vollständig. Ein Artikel benutzt zwar die gewünschte Konfiguration seine Mutter oder Großmutter oder Urgroßmutter-Kategorie, aber nur dann, wenn kein Code für den Artikel in con_code hinterlegt ist. Beim Ändern eines Layouts oder eines Templates wird der Code der abhänigen Artikel normalerweise aus der con_code gelöscht, so das die Artikel beim nächsten Aufruf aktualisiert werden, das funktioniert aber nicht für Enkel oder Urenkel-Artikel. Nach dem Ändern von Layout oder Template muss also die Tabelle con_code manuell gelöscht werden, damit auch diese Artikel aktualisiert werden.

Die nötigen Änderungen veröffentliche ich hier als patch. Dieser patch wurde mit diff gegen die Version 4.4.4 erstellt, und ist geeignet mit dem Unix-Programm patch über eine Version 4.4.4 installiert zu werden. Den Output von diff kann man mit dieser Anleitung auch lesen und manuell nachvollziehen.

Und jetzt gehts los:

Code: Alles auswählen

diff -r -b -B -C3 /contenido-4.4.4/contenido/classes/class.templateconfig.php /contenido/contenido/classes/class.templateconfig.php
*** /contenido-4.4.4/contenido/classes/class.templateconfig.php Wed Oct 29 15:33:16 2003
--- /contenido/contenido/classes/class.templateconfig.php   Sun May  1 21:19:47 2005
***************
*** 195,207 ****
         */
        function _getTplCfgByCatId ($idcat)
        {
!               $sql = "SELECT idtplcfg FROM ".$this->cfg['tab']['cat_lang']." WHERE idcat=$idcat AND idlang=".$this->lang;
                $this->db->query($sql);
!               if ($this->db->next_record())
                {
                        return $this->db->f("idtplcfg");
                }
                return false;
        }
  
        /**
--- 195,228 ----
         */
        function _getTplCfgByCatId ($idcat)
        {
!               $sql = "
!                       SELECT
!                               a.idtplcfg,
!                               b.parentid 
!                       FROM ".$this->cfg['tab']['cat_lang']." as a,
!                               ".$this->cfg['tab']['cat']." as b 
!                       WHERE 
!                               a.idcat=$idcat AND 
!                               a.idlang=".$this->lang." AND
!                               b.idcat=a.idcat;";
! 
                $this->db->query($sql);
!               $this->db->next_record();
!               if ($this->db->f("idtplcfg")!=0)
                {
                        return $this->db->f("idtplcfg");
                }
+               else
+               {
+                       if ($this->db->f("parentid")==0)
+                       {
                        return false;
+                       }
+                       else
+                       {
+                       return $this->_getTplCfgByCatId ($this->db->f("parentid"));
+                       }
+               }
        }
  
        /**
diff -r -b -B -C3 /contenido-4.4.4/contenido/includes/functions.con.php /contenido/contenido/includes/functions.con.php
*** /contenido-4.4.4/contenido/includes/functions.con.php       Mon Feb  2 14:19:22 2004
--- /contenido/contenido/includes/functions.con.php Mon May 16 20:22:38 2005
***************
*** 1069,1074 ****
--- 1069,1131 ----
  
  }
  
+ /**
+  * Checks recursive from subcategory to category
+  * for template configuration
+  *
+  * @param int $idcat Id of category
+  * @param int $lang Id of language
+  * @param int $client Id of client
+  *
+  * @return idtplcfg of given category or 0 if none was found
+  *
+  * @author Tobias Nothdurft <tono@online.de>
+  * @copyright s.a.
+  */
+ 
+ function getidtplcfgbyidcat($idcat, $lang, $client)
+ {
+     global $db;
+     global $cfg;
+     global $debug;
+     /* Check whether category is
+      configured. */
+     $sql = "SELECT
+                 a.idtplcfg AS idtplcfg,
+                 b.parentid AS parentid
+             FROM
+                 ".$cfg["tab"]["cat_lang"]." AS a,
+                 ".$cfg["tab"]["cat"]." AS b
+             WHERE
+                 a.idcat     = '".$idcat."' AND
+                 a.idlang    = '".$lang."' AND
+                 b.idcat     = a.idcat AND
+                 b.idclient  = '".$client."'";
+ 
+     $db->query($sql);
+     $db->next_record();
+     if ($debug==1) echo "idcat: ".$idcat;
+     if ($debug==1) echo "parentid: ".$db->f("parentid");
+     if ($debug==1) echo "idtplcfg: ".$db->f("idtplcfg");
+ 
+ 
+     if ( $db->f("idtplcfg") != 0 ) // Is this category configured?
+         {
+             return $db->f("idtplcfg");  // Yes, return idtplcfg
+         }
+     else
+         {
+         if ( $db->f("parentid") == 0 ) // No, Are we at the top node already?
+             {
+             return 0;                 // Yes, return 0
+             }
+         else
+             {
+             return getidtplcfgbyidcat($db->f("parentid"), $lang, $client);   //No, look at the Mothernode
+             }
+         }
+ }
+ 
  
  /**
   * Generates the code for one
***************
*** 1113,1118 ****
--- 1170,1176 ----
             article or the category is
             configured, no code will be
             created and an error occurs. */
+         /* Tono: dann schaun wir mal bei den Grosseltern */
          $sql = "SELECT
                      a.idtplcfg AS idtplcfg
                  FROM
***************
*** 1156,1180 ****
  
              /* 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     = '".$idcat."' AND
-                         a.idlang    = '".$lang."' AND
-                         b.idcat     = a.idcat AND
-                         b.idclient  = '".$client."'";
  
!             $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>";
  
--- 1214,1226 ----
  
              /* Check whether category is
               configured. */
  
!             $idtplcfg = getidtplcfgbyidcat($idcat, $lang, $client);
  
!             if ( $idtplcfg != 0 ) {
  
                  /* Category is configured,
                     extract varstring */
                  
                  if ($debug) echo "configuration for category found: $idtplcfg<br><br>";
  
diff -r -b -B -C3 /contenido-4.4.4/contenido/includes/include.con_editcontent.php /contenido/contenido/includes/include.con_editcontent.php
*** /contenido-4.4.4/contenido/includes/include.con_editcontent.php     Mon Feb  9 09:55:50 2004
--- /contenido/contenido/includes/include.con_editcontent.php       Sun May 22 21:38:59 2005
***************
*** 280,300 ****
              # 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     = '".$idcat."' AND
!                         a.idlang    = '".$lang."' AND
!                         b.idcat     = a.idcat AND
!                         b.idclient  = '".$client."'";
  
!             $db->query($sql);
!             $db->next_record();
  
!             if ( $db->f("idtplcfg") != 0 ) {
  
                  #
                  # Category is configured,
--- 280,290 ----
              # Check whether category is
              # configured.
              #
!             cInclude("includes", "functions.con.php");
  
!             $idtplcfg = getidtplcfgbyidcat($idcat, $lang, $client);
  
!             if ( $idtplcfg != 0 ) {
  
                  #
                  # Category is configured,
***************
*** 567,573 ****
          $code = stripslashes($code);
          $code = preg_replace("/<\/head>/i", "$markSubItem $scripts</head>", $code);
          $code = preg_replace("/<\/body>/i", "$contentform</body>", $code);
-       
                eval("?>\n".$code."\n<?php\n");
        
      }
--- 557,562 ----
Das wärs zu den Dateien, aber contenido hat auch noch Code in der Datenbank. Der kann ersetzt werden durch:

Code: Alles auswählen

UPDATE `con_actions` SET `idaction` = 54, `idarea` = 3, `alt_name` = '', `name` = 'con_newart', `code` = '/* Code for action\r\n   \'con_newart\' */\r\n\r\n$idtplcfg=getidtplcfgbyidcat($idcat, $lang, $client);\r\n\r\nif ( $idtplcfg != 0 ) {\r\n$newart = true;\r\n \r\n\r\n} else {\r\n\r\n    $noti_html = \'<table cellspacing="0" cellpadding="2" border="0">\r\n\r\n                    <tr class="text_medium">\r\n                        <td colspan="2">\r\n                            <b>Fehler bei der Erstellung des Artikels</b><br><br>\r\n                            Der Kategorie ist kein Template zugewiesen.\r\n                        </td>\r\n                    </tr>\r\n\r\n                    <tr>\r\n                        <td colspan="2">&nbsp;</td>\r\n                    </tr>\r\n\r\n                  </table>\';\r\n\r\n    $code = \'\r\n            <html>\r\n                <head>\r\n                    <title>Error</title>\r\n                    <link rel="stylesheet" type="text/css" href="\'.$cfg["path"]["contenido_fullhtml"].$cfg["path"]["styles"].\'contenido.css"></link>\r\n                </head>\r\n                <body style="margin: 10px">\'.$notification->returnNotification("error", $noti_html).\'</body>\r\n            </html>\';\r\n\r\n    echo $code;\r\n\r\n}', `location` = '', `relevant` = 1;
Das con in 'con_actions' müsst ihr dabei an euer Tabellenprefix anpassen, das con in 'con_newart' aber auf keinen Fall.
i-fekt
Beiträge: 1520
Registriert: Mo 3. Jan 2005, 02:15
Wohnort: Chemnitz
Kontaktdaten:

Beitrag von i-fekt »

Klingt interessant und nach Typo3. Wenn das optimiert ist und fehlerfrei läuft wäre das eine gute Neuerung für Contenido, die man standardmäßig einbauen könnte.
Gruss,
Michael

"Keep on riding this Bike!" (Jackson Mulham)
tono
Beiträge: 574
Registriert: Mo 25. Apr 2005, 20:51
Wohnort: Frankfurt am Main
Kontaktdaten:

Beitrag von tono »

Ja, das wäre nett, denn für jede neue Version diesen Aufwand... Und das ist ja erst die Hälfte. siehe auch hier: http://www.contenido.org/forum/viewtopic.php?t=7567
Gesperrt