Code: Alles auswählen
// Check php version
$sVersion   = explode( '.', phpversion() );
$sVersion   = (((int)$sVersion[0] == 5 && (int)$sVersion[1] >= 2) || (int)$sVersion[0] > 5) ? 'php>=5.2' : 'php<5.2';
if ($sVersion == 'php>=5.2') {
    cInclude("frontend", "includes/class.datetimereplacelang.php");
}
elseif (!function_exists(formatDateToStrftime))
{
    function formatDateToStrftime($sDate)
    {
        $aDate      = array('d', 'm', 'y', 'H', 'i', 'F', 'j', 'Y', 'M', 'l', 'D');
        $aStrftime  = array('%d', '%m', '%y', '%H', '%M', '%B', '%e', '%Y', '%b', '%A', '%a');
                        
        return str_replace($aDate, $aStrftime, $sDate);
    }
}
else
{
    // do nothing
}
unset ($aData);
$aData = array();
// Base settings
unset ($aSettings);
$aSettings = array();
$aSettings["ArticleCount"]               = "CMS_VALUE[0]";
$aSettings["ArticlePerPage"]             = "CMS_VALUE[1]";
$aSettings["SortBy"]                     = "CMS_VALUE[2]";
$aSettings["SortDir"]                    = "CMS_VALUE[3]";
$aSettings["ShowStart"]                  = "CMS_VALUE[4]";
$aSettings["Category"]                   = "CMS_VALUE[5]";
$aSettings["HeadlineIdentifier"]         = "CMS_VALUE[7]";
$aSettings["HeadlineLength"]             = "CMS_VALUE[8]";
$aSettings["Elements"]                   = "CMS_VALUE[9]";
$aSettings["CatTypeSel"]                 = "CMS_VALUE[10]";
$aSettings["AddCats"]                    = "CMS_VALUE[11]";
$aSettings["DateType"]                   = "CMS_VALUE[13]";
$aSettings["Date"]                       = "CMS_VALUE[14]";
$aSettings["Template"]                   = "CMS_VALUE[15]";
$aSettings["PageBrowsingType01"]         = "CMS_VALUE[16]";
$aSettings["PageBrowsingType02"]         = "CMS_VALUE[17]";
$aSettings["PageBrowsingType03"]         = "CMS_VALUE[18]";
$aSettings["PageBrowsingType04"]         = "CMS_VALUE[19]";
$aSettings["PageBrowsingType05"]         = "CMS_VALUE[20]";
$aSettings["UseUTF8"]                    = "CMS_VALUE[21]";
$aSettings["UseSummary"]                 = "CMS_VALUE[22]";
$aSettings["ShowOnlyStart"]              = "CMS_VALUE[23]";
$aSettings["DateLanguage"]               = "CMS_VALUE[24]";
$aSettings["PageBrowsingType05MaxPages"] = "CMS_VALUE[25]";
$aSettings["SummaryWidth"]               = "CMS_VALUE[26]";
$aSettings["UsePageTitle"]               = "CMS_VALUE[27]";
$aSettings["PageTitleWidth"]             = "CMS_VALUE[28]";
$aSettings["UseAuthor"]                  = "CMS_VALUE[29]";
$aSettings["AuthorLabeling"]             = "CMS_VALUE[30]";
$aSettings["ArtListHeadline"]            = "CMS_VALUE[31]";
$aSettings["ShowModul"]                  = "CMS_VALUE[100]";
$aSettings["CurrentPage"]                = $_REQUEST["page"];
if ($aSettings["ShowModul"] == 'on')
{
    // Checking base settings
    $aSettings["ArticleCount"]               = (!is_numeric($aSettings["ArticleCount"]) || $aSettings["ArticleCount"] < 0) ? 5 : $aSettings["ArticleCount"];
    $aSettings["ArticlePerPage"]             = (!is_numeric($aSettings["ArticlePerPage"]) || $aSettings["ArticlePerPage"] < 0) ? 0 : $aSettings["ArticlePerPage"]; // Deactivating page browsing
    $aSettings["CurrentPage"]                = ($aSettings["ArticlePerPage"] == 0 || !is_numeric($aSettings["CurrentPage"]) || !isset($aSettings["CurrentPage"])) ? 0 : $aSettings["CurrentPage"];
    $aSettings["CurrentPage"]                = (isset($aSettings["CurrentPage"]) && $aSettings["CurrentPage"] != 0) ? $aSettings["CurrentPage"] - 1 : $aSettings["CurrentPage"];
    $aSettings["Category"]                   = (!is_numeric($aSettings["Category"]) || $aSettings["Category"] <= 0) ? 0 : $aSettings["Category"];
    $aSettings["HeadlineIdentifier"]         = (strlen($aSettings["HeadlineIdentifier"]) > 50) ? '' : $aSettings["HeadlineIdentifier"];
    $aSettings["HeadlineLength"]             = (!is_numeric($aSettings["HeadlineLength"]) || $aSettings["HeadlineLength"] < 0) ? 0 : $aSettings["HeadlineLength"];
    $aSettings["Elements"]                   = (!is_numeric($aSettings["Elements"]) || $aSettings["Elements"] < 0) ? 0 : $aSettings["Elements"];
    $aSettings["CatTypeSel"]                 = ($aSettings["CatTypeSel"] == "" || ($aSettings["AddCats"] == "" && $aSettings["CatTypeSel"] == "selected")) ? "none" : $aSettings["CatTypeSel"];
    $aSettings["PageBrowsingType05MaxPages"] = (!is_numeric($aSettings["PageBrowsingType05MaxPages"]) || $aSettings["PageBrowsingType05MaxPages"] == '') ? 10 : $aSettings["PageBrowsingType05MaxPages"];
    $aSettings["PageBrowsingType05MaxPages"] = ($aSettings["PageBrowsingType05MaxPages"] <= 3) ? 3 : $aSettings["PageBrowsingType05MaxPages"];
    $aSettings["SummaryWidth"]               = (!is_numeric($aSettings["SummaryWidth"]) || $aSettings["SummaryWidth"] < 0) ? 0 : $aSettings["SummaryWidth"];
    $aSettings["PageTitleWidth"]             = (!is_numeric($aSettings["PageTitleWidth"]) || $aSettings["PageTitleWidth"] < 0) ? 0 : $aSettings["PageTitleWidth"];
    
    if ($aSettings["UseUTF8"] == "enabled")
    {
        if (!function_exists(html_entity_decode_utf8))
        {
            # Needed functions for UTF8 and PHP4 - Posted by "laurynas.butkus@gmail.com" at http://us2.php.net/manual/de/function.html-entity-decode.php
            ######
            # In PHP4 html_entity_decode() is not working well with UTF-8 spitting: "Warning: cannot yet handle MBCS in html_entity_decode()!".
            # This is working solution combining several workarounds:
            ######
            function html_entity_decode_utf8($string)
            {
                static $trans_tbl;
               
                // replace numeric entities
                $string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf(hexdec("\\1"))', $string);
                $string = preg_replace('~&#([0-9]+);~e', 'code2utf(\\1)', $string);
            
                // replace literal entities
                if (!isset($trans_tbl))
                {
                    $trans_tbl = array();
                   
                    foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key)
                        $trans_tbl[$key] = utf8_encode($val);
                }
               
                return strtr($string, $trans_tbl);
            }
        }
        
        if (!function_exists(code2utf))
        {
            // Returns the utf string corresponding to the unicode value (from php.net, courtesy - romans@void.lv)
            function code2utf($num)
            {
                if ($num < 128) return chr($num);
                if ($num < 2048) return chr(($num >> 6) + 192).chr(($num & 63) + 128);
                if ($num < 65536) return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
                if ($num < 2097152) return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
                return '';
            }
        }
    }
    
    // Detail settings
    if ($aSettings["Elements"] > 0)
    {
        for ($i = 0; $i < $aSettings["Elements"]; $i++)
        {
            $iElementType           = $iDataStart   + ($i * 10);
            $iElementIdentifier     = $iElementType + 1;
            $iElementWidth          = $iElementType + 2;
            $iElementHeight         = $iElementType + 3;
            $iElementDontStripTags  = $iElementType + 3;
    
            $aSettings["k".$i] = array();
            $aSettings["k".$i]["ElementType"]        = "CMS_VALUE[$iElementType]";        // Text, Image, ExtractedImage
            $aSettings["k".$i]["Identifier"]         = "CMS_VALUE[$iElementIdentifier]";
            $aSettings["k".$i]["ElementWidth"]       = "CMS_VALUE[$iElementWidth]";       // Textlength or ImageWidth
            $aSettings["k".$i]["ElementHeight"]      = "CMS_VALUE[$iElementHeight]";
            $aSettings["k".$i]["DontStripTags"]      = ("CMS_VALUE[$iElementDontStripTags]" == 'yes' && $aSettings["k".$i]["ElementWidth"] == 0);
    
            // Check detail settings
            if ($aSettings["k".$i]["ElementType"] == "")
            {
                $aSettings["k".$i]["ElementType"] == "Text";
            }
            if ($aSettings["k".$i]["ElementType"] == "Text")
            {
                $aSettings["ElementHeight"] = 0;
                if (!is_numeric($aSettings["k".$i]["ElementWidth"]) || $aSettings["k".$i]["ElementWidth"] < 0)
                {
                    $aSettings["k".$i]["ElementWidth"] = 50;
                }
            }
            elseif (!is_numeric($aSettings["k".$i]["ElementWidth"]) || $aSettings["k".$i]["ElementWidth"] <= 0 ||
                    !is_numeric($aSettings["k".$i]["ElementHeight"]) || $aSettings["k".$i]["ElementHeight"] <= 0)
            {
                $aSettings["k".$i]["ElementWidth"] = 0;
                $aSettings["k".$i]["ElementHeight"] = 0;
            }
            if (strlen($aSettings["Identifier"]) > 50)
            {
                $aSettings["Identifier"] = "";
            }
        } // end for
    }
    
    unset ($iDataStart);
    unset ($iElementType);
    unset ($iElementIdentifier);
    unset ($iElementWidth);
    unset ($iElementHeight);
    unset ($iElementDontStripTags);
    
    if ($aSettings["Category"] !== "0" && $aSettings["HeadlineIdentifier"] !== "")
    {
        if (!is_object($db2)) $db2 = new DB_Contenido;
    
        // Specifying search categories
        $sSelCats = "'".$aSettings["Category"]."'";
        // Adding categories "below" primary category
        switch ($aSettings["CatTypeSel"])
        {
            case "below":
                $lCatLevel = -1;
                $sql  = "SELECT a.idcat AS idcat, b.level AS level FROM ".$cfg["tab"]["cat"]." a, ".$cfg["tab"]["cat_tree"]." b ";
                $sql .= "WHERE a.idcat = b.idcat ORDER BY b.idtree";
    
                $db2->query($sql);
                while($db2->next_record())
                {
                    if ($db2->f("idcat") == $aSettings["Category"])
                        $lCatLevel = $db2->f("level");
                    elseif ($lCatLevel > -1 && $db2->f("level") > $lCatLevel)
                        $sSelCats .= ",'".$db2->f("idcat")."'";
                    elseif ($db2->f("level") <= $lCatLevel)
                        break;
                } // end while
                break;
            case "select":
                $aCats = explode(",", $aSettings["AddCats"]);
                foreach ($aCats as $value)
                    if (is_numeric($value))
                        $sSelCats .= ",'".$value."'";
                break;
            default:
        } // end switch
    
        $sql =  'SELECT
                    tblData.value AS headline,
                    artlang.pagetitle AS pagetitle,
                    artlang.summary AS summary,
                    artlang.idart AS idart,
                    artlang.idart AS idartlang,
                    artlang.lastmodified AS lastmodified,
                    artlang.modifiedby AS autor,
                    artlang.created AS created,
                    artlang.published AS published,
                    artlang.idartlang AS idartlang,
                    catlang.name AS category,
                    catlang.startidartlang AS startid,
                    catart.is_start AS isstart,
                    catart.idcat AS idcat,
                    catart.idcatart AS idcatart
                FROM
                    '.$cfg["tab"]["cat_art"].' AS catart,
                    '.$cfg["tab"]["art_lang"].' AS artlang,
                    '.$cfg["tab"]["cat_lang"].' AS catlang,
                    '.$cfg["tab"]["content"].' AS tblData
                WHERE
                    catart.idcat IN ('.$sSelCats.') AND
                    artlang.idlang = '.$lang.' AND
                    tblData.idartlang = artlang.idartlang AND
                    catlang.idlang = artlang.idlang AND
                    catlang.idcat = catart.idcat AND
                    artlang.idart = catart.idart ';
    
        if ($aSettings["ShowStart"] != "enabled")
            $sql .= ($cfg["is_start_compatible"] == true) ? 'AND catart.is_start = 0 ' : 'AND tblData.idartlang != catlang.startidartlang ';
        else
            if ($aSettings["ShowOnlyStart"] == "enabled")
                $sql .= ($cfg["is_start_compatible"] == true) ? 'AND catart.is_start = 1 ' : 'AND tblData.idartlang = catlang.startidartlang ';
        
        $sql .= 'AND artlang.online = 1 ';
        $sql .= 'AND '.$aSettings["HeadlineIdentifier"].' ';
    
        // Sort by
        $sql .= 'ORDER BY '.$aSettings["SortBy"].' '.$aSettings["SortDir"].' ';
    
        // LIMIT
        if ($aSettings["ArticleCount"] > 0) $sql .= 'LIMIT 0, '.$aSettings["ArticleCount"];
        if ($aSettings["ArticlePerPage"] > 0) $sql_pagination = $sql;
        
        // execute query
        $db2->query($sql);
        $lCount = $db2->num_rows();
    
        if ($lCount > 0)
        {
            if (!is_object($db3)) $db3 = new DB_Contenido;
            if (!is_object($db4)) $db4 = new DB_Contenido;
            if (!is_object($db5)) $db5 = new DB_Contenido;
            if ($aSettings["ArticlePerPage"] > 0)
            {
                $lStartCount = $aSettings["CurrentPage"] * $aSettings["ArticlePerPage"];
                $lEndCount   = ($aSettings["CurrentPage"] * $aSettings["ArticlePerPage"]) + $aSettings["ArticlePerPage"];
                
                if ($lEndCount > $lCount) $lEndCount = $lCount;
            }
            else
            {
                $lStartCount = 0;
                $lEndCount   = $lCount;
            }
    
            $lRow = 0;
            $i    = 0;
            while ($db2->next_record())
            {
                if ($aSettings["ShowStart"] == "enabled" ||
                   ($aSettings["ShowStart"] != "enabled" && $db2->f("idartlang") != $lStartIDArtLang))
                {
                    if ($lRow >= $lStartCount && $lRow < $lEndCount)
                    {
                        $aData[$i]                 = array();
                        $aData[$i]["Category"]     = urldecode($db2->f("category"));
                        
                        $sParams = ($db2->f("startid") == $db2->f("idartlang") || $db2->f("isstart")) ? 'idcat='.$db2->f("idcat") : 'idcat='.$db2->f("idcat")."&idart=".$db2->f("idart");
                        
                        $aData[$i]["Link"]         = $sess->url("front_content.php?".$sParams);
                        $aData[$i]["LastModified"] = $db2->f("lastmodified");
                        $aData[$i]["Autor"]        = $db2->f("autor");
                        $aData[$i]["Created"]      = $db2->f("created");
                        $aData[$i]["Published"]    = $db2->f("published");
 // Generate pagetitle
                        $sTmpValue = html_entity_decode(strip_tags(urldecode($db2->f('pagetitle'))));
                        if ($aSettings["PageTitleWidth"] > 0 && strlen($sTmpValue) > $aSettings["PageTitleWidth"] && $aSettings["UsePageTitle"] == 'enabled')
                        {
                            // Cutting text but preserving words and entities
                            $sTmpValue = capiStrTrimAfterWord($sTmpValue, $aSettings["PageTitleWidth"])."...";
                        }
                        elseif ($aSettings["UsePageTitle"] == 'enabled')
                        {
                            $sTmpValue = $sTmpValue;
                        }
                        else
                        {
                            $sTmpValue = '';
                        }
                        $aData[$i]["PageTitle"] = $sTmpValue;
                        // Generate headline
                        $sTmpValue = html_entity_decode(strip_tags(urldecode($db2->f('headline'))));
                        if ($aSettings["HeadlineLength"] > 0 && strlen($sTmpValue) > $aSettings["HeadlineLength"])
                        {
                            // Cutting text but preserving words and entities
                            $sTmpValue = htmlentities(capiStrTrimAfterWord($sTmpValue, $aSettings["HeadlineLength"])."...");
                        }
                        $aData[$i]["Headline"] = $sTmpValue;
                        // Generate Summary
                        $sTmpValue = html_entity_decode(strip_tags(urldecode($db2->f('summary'))));
                        if ($aSettings["SummaryWidth"] > 0 && strlen($sTmpValue) > $aSettings["SummaryWidth"] && $aSettings["UseSummary"] == 'enabled')
                        {
                            // Cutting text but preserving words and entities
                            $sTmpValue = capiStrTrimAfterWord($sTmpValue, $aSettings["SummaryWidth"])."...";
                        }
                        elseif ($aSettings["UseSummary"] == 'enabled')
                        {
                            $sTmpValue = $sTmpValue;
                        }
                        else
                        {
                            $sTmpValue = '';
                        }
                        $aData[$i]["Summary"] = $sTmpValue;
                        // 
                        if ($aSettings["Elements"] > 0)
                        {
                            for ($k = 0; $k < $aSettings["Elements"]; $k++)
                            {
                                $aData[$i]["i".$k]               = array();
                                $aData[$i]["i".$k]["Value"]      = "";
                                $aData[$i]["i".$k]["ServerPath"] = "";
                                $aData[$i]["i".$k]["WebPath"]    = "";
                                $aData[$i]["i".$k]["Width"]      = 0;
                                $aData[$i]["i".$k]["Height"]     = 0;
                            } // end for
    
                            $sql =  "SELECT tblData.value AS value, tblData.idtype AS idtype, tblData.typeid AS typeid FROM ";
                            $sql .= $cfg["tab"]["cat_art"]." AS tblCatArt, ";
                            $sql .= $cfg["tab"]["art_lang"]." AS tblArtLang, ";
                            $sql .= $cfg["tab"]["content"]." AS tblData ";
                            $sql .= "WHERE tblData.idartlang = tblArtLang.idartlang AND ";
                            $sql .= "tblArtLang.idlang = '".$lang."' AND ";
                            $sql .= "tblArtLang.idart = tblCatArt.idart AND ";
                            $sql .= "tblCatArt.idcatart = '".$db2->f("idcatart")."' AND (";
                            
                            $sql_items = "";
                            for ($k = 0; $k < $aSettings["Elements"]; $k++)
                            {
                                if ($aSettings["k".$k]["Identifier"] != "" && $aSettings["k".$k]["Identifier"] != "none")
                                {
                                    if ($sql_items != "")
                                    {
                                        $sql_items .= " OR (".$aSettings["k".$k]["Identifier"].")";
                                    }
                                    else
                                    {
                                        $sql_items = "(".$aSettings["k".$k]["Identifier"].")";
                                    }
                                }
                            } // end for
                            $sql .= $sql_items.")";
    
                            if ($bDebug)
                            {
                                echo "<pre>".$sql."</pre>", chr(10);
                            }
    
                            // execute query
                            $db3->query($sql);
    
                            while ($db3->next_record())
                            {
                                $sTypeIdentifier = "tblData.idtype = '".$db3->f('idtype')."' AND tblData.typeid = '".$db3->f('typeid')."'";
    
                                # Note: The TypeIdentifier for one item may be the same as for another item.
                                #       Therefore, we are storing the content everywhere as needed
                                for ($k = 0; $k < $aSettings["Elements"]; $k++)
                                {
                                    if ($sTypeIdentifier == $aSettings["k".$k]["Identifier"])
                                    {
                                        switch (TRUE)
                                        {
                                            case ($aSettings["k".$k]["ElementType"] == "Image" || $aSettings["k".$k]["ElementType"] == "ExtractedImage"):
                                                
                                                $sql = "";
                                                
                                                if ($aSettings["k".$k]["ElementType"] == "Image")
                                                {
                                                    $sql =  "SELECT
                                                                dirname,
                                                                filename
                                                            FROM
                                                                ".$cfg["tab"]["upl"]."
                                                            WHERE
                                                                idupl = '".$db3->f('value')."'";
                                                }
                                                else
                                                {
                                                    $sTmpValue = urldecode($db3->f('value'));
       
                                                    $regEx = "/<img[^>]*?>.*?/i";
                                                    $match = array ();
                                                    preg_match($regEx, $sTmpValue, $match);
    
                                                    $regEx = "/(src)(=)(['\"]?)([^\"']*)(['\"]?)/i";
                                                    $img = array ();
                                                    preg_match($regEx, $match[0], $img);
                                                    $img_src = preg_split("/\//", $img[0]);
    
                                                    $img_name = $img_src[count($img_src) - 1];
                                                    $img_name = preg_replace("/\"/", "", $img_name);
    
                                                    #Don't know what is happening here, exactly...
                                                    # $img_split = preg_split("/\./", $img_name);
                                                    # $img_type = $img_split[count($img_split) - 1];
                                                    # $img_split2 = preg_split("/_/", $img_split[0]);
    
                                                    $name = strtolower($img_name);
    
                                                    #Don't know what is happening here, exactly...
                                                    #if (count($img_split2) > 1) {
                                                    #   $img_x = $img_split2[count($img_split2) - 1];
                                                    #   $img_y = $img_split2[count($img_split2) - 2];
    
                                                    #   if (is_numeric($img_x) AND is_numeric($img_y)) {
                                                    #      $suffix = "_".$img_x."_".$img_y.".".$img_type;
                                                    #      $name = preg_replace("/$suffix/", "", $img_name);
                                                    #      $name = $name.".[a-zA-Z]{3}";
                                                    #   }
                                                    #}
    
                                                    if (strlen($name) > 0)
                                                    {
                                                        $sql =  "SELECT
                                                                    dirname,
                                                                    filename
                                                                FROM
                                                                    ".$cfg["tab"]["upl"]."
                                                                WHERE
                                                                    LOWER(filename) = '$name'";
                                                    }
                                                }
    
                                                if ($bDebug) echo "<pre>".$sql."</pre>";
    
                                                // execute query
                                                if ($sql != "")
                                                {
                                                    $db4->query($sql);
    
                                                    if ($db4->next_record())
                                                    {
                                                        $aData[$i]["i".$k]["ServerPath"]   = $cfgClient[$client]["upl"]["path"].$db4->f('dirname').$db4->f('filename');
                                                        $aData[$i]["i".$k]["WebPath"]      = $cfgClient[$client]["upl"]["htmlpath"].$db4->f('dirname').$db4->f('filename');
    
                                                        list (
                                                            $width,
                                                            $height,
                                                            $type,
                                                            $attr
                                                        ) = getimagesize($aData[$i]["i".$k]["ServerPath"]);
                                                        $aData[$i]["i".$k]["Width"]        = $width;
                                                        $aData[$i]["i".$k]["Height"]       = $height;
                                                    }
                                                }
                                                break;
                                            default:
                                                if ($aSettings["UseUTF8"] != "enabled")
                                                {
                                                    $sTmpValue = ($aSettings["k".$k]["DontStripTags"]) ? urldecode($db3->f('value')) : strip_tags(urldecode($db3->f('value')));
                                                }
                                                else
                                                {
                                                    $sTmpValue = ($aSettings["k".$k]["DontStripTags"]) ? html_entity_decode_utf8(urldecode($db3->f('value'))) : html_entity_decode_utf8(strip_tags(urldecode($db3->f('value')), '<h1>, <p>, <img>, <strong>, <b>, <a>, <font>'));
                                                }
                                                
                                                if ($aSettings["k".$k]["ElementWidth"] > 0 && strlen($sTmpValue) > $aSettings["k".$k]["ElementWidth"])
                                                {
                                                    // Cutting text but preserving words and entities
                                                    $sTmpValue = capiStrTrimAfterWord($sTmpValue, $aSettings["k".$k]["ElementWidth"])."...";
                                                }
                                                $aData[$i]["i".$k]["Value"] = $sTmpValue;
                                        } // end switch
                                    } // end if ($sTypeIdentifier == $aSettings["k".$k]["Identifier"])
                                } // end for
                            } // end while
                        }
                        $i++;
                    }
                    elseif ($lRow == $lEndCount)
                    {
                        break;
                    }
                    $lRow++;
                }
            } // end while
    
            // Clearing memory
            unset ($db2);
            unset ($db3);
            unset ($db4);
            unset ($sql);
            unset ($lStartIDArtLang);
            unset ($lStartCount);
            unset ($lEndCount);
        
            # Output data
            # Every output manipulation should be done here...
            #
            # Base information:
            # $aSettings["Elements"]:                  Number of expected, additional elements from each article
            # $aSettings["ArticlePerPage"]:            Number of articles per page (0: show all)
            # $aSettings["k".$i]["ElementType"]:       Per Element: Type of Element: Text, Image or ExtractedImage
            # $aSettings["k".$i]["ElementWidth"]:      Per Element: Text length or image width (-> recycling ...)
            # $aSettings["k".$i]["ElementHeight"]:     Per Element: Image width
            # $aSettings["k".$i]["DontStripTags"]      Per Element: Strip tags or not
            #
            # Per article:
            # $aValue["Headline"]:                     Content of article element specified as containing the headline information
            # $aValue["Link"]:                         Relative link to get to the listed article
            # $aValue["LastModified"]:                 Last modified date of the article
            # $aValue["Created"]:                      Created date of the article
            # $aValue["Published"]:                    Published date of the article
            # $aValue["Category"]:                     Category name
            # $aValue["Autor"]:                        Autor name
            # $aValue["Pagetitle"]:                    Pagetitle
            # $aValue["Summary"]:                      Summary
            #
            # Per article additional element:
            # $aValue["i".$i]["Value"]:                Text (only for text elements, otherwise "")
            # $aValue["i".$i]["WebPath"]:              HTTP... path to image
            # $aValue["i".$i]["ServerPath"]:           /server/... path to image
            # $aValue["i".$i]["Width"]:                >Original< image width
            # $aValue["i".$i]["Height"]:               >Original< image height
        
            /* Init Template */
        
            if (!is_object($tpl)) $tpl = new Template;
            $tpl->reset();
            
            if ($aSettings["ArtListHeadline"] != '')
                $tpl->set('s', 'TITLE', $aSettings["ArtListHeadline"]);
            else
                $tpl->set('s', 'TITLE', '');
        
            foreach ($aData as $aValue)
            {
                if ($aSettings["Elements"] > 0)
                {
                    for ($i = 0; $i < $aSettings["Elements"]; $i++)
                    {
                        switch (TRUE)
                        {
                            case ($aSettings["k".$i]["ElementType"] == "Image" || $aSettings["k".$i]["ElementType"] == "ExtractedImage"):
                                $image  = $aValue["i".$i]["WebPath"];
                                $width  = $aValue["i".$i]["Width"];
                                $height = $aValue["i".$i]["Height"];
                                if ($aSettings["k".$i]["ElementWidth"] > 0 && $aSettings["k".$i]["ElementHeight"] > 0)
                                {
                                    // Check, if resize necessary
                                    if ( $aValue["i".$i]["ServerPath"] != "" && file_exists($aValue["i".$i]["ServerPath"]) &&
                                        ($aValue["i".$i]["Width"] > $aSettings["k".$i]["ElementWidth"] || $aValue["i".$i]["Height"] > $aSettings["k".$i]["ElementHeight"]))
                                    {
                                        // Scale image
                                        $image = capiImgScale($aValue["i".$i]["ServerPath"], $aSettings["k".$i]["ElementWidth"], $aSettings["k".$i]["ElementHeight"], false, false, 10, false);
            
                                        // Get dimensions of the image
                                        list (
                                            $width,
                                            $height,
                                            $type,
                                            $attr
                                        ) = getimagesize(str_replace($cfgClient[$client]["path"]["htmlpath"], $cfgClient[$client]["path"]["frontend"], $image));
                                    }
                                    else
                                    {
                                        $image  = $aValue["i".$i]["WebPath"];
                                        $width  = $aValue["i".$i]["Width"];
                                        $height = $aValue["i".$i]["Height"];
                                    }
                                }
                                
                                $artlist_image = ($image != "") ? '<img class="articlelistImage" src="'.$image.'" width="'.$width.'" height="'.$height.'" alt="'.mi18n("Article Thumb").'" />' : '';
                                $tpl->set('d', 'IMG_'.$i,  $artlist_image);
                                break;
                            default: // Everything else is treated as "Text"
                                $artlist_text = $aValue["i".$i]["Value"];
                                $tpl->set('d', 'TEXT_'.$i,  $artlist_text);
                        } // end switch
                    } // end for
                }
                // Generate date if enabled
                if($aSettings["Date"] != "-1")
                {
                    if ($sVersion == 'php>=5.2')
                    {
                        if ($aSettings["DateLanguage"] != 'en_UK')
                        {
                            $oDate = ($aSettings["DateType"] == "create") ? new DateTimeReplaceLang($aValue["Created"]) : new DateTimeReplaceLang($aValue["Published"]);
                            $artlist_lastmod = $oDate->format($aSettings["Date"], $aSettings["DateLanguage"]);
                        }
                        else
                        {
                            $oDate = ($aSettings["DateType"] == "create") ? new DateTime($aValue["Created"]) : new DateTime($aValue["Published"]);
                            $artlist_lastmod = $oDate->format($aSettings["Date"]);
                        }
                    }
                    else
                    {
                        setlocale(LC_TIME, $aSettings["DateLanguage"]);
                        $tmp_artlist_Date = ($aSettings["DateType"] == "create") ? strtotime($aValue["Created"]) : strtotime($aValue["Published"]);
                        $artlist_lastmod = strftime(formatDateToStrftime($aSettings["Date"]), $tmp_artlist_Date);
                    }
                }
                else
                {
                    $artlist_lastmod = "";
                }
                
                // Search author if enabled
                if($aSettings["UseAuthor"] == 'enabled')
                {
                    $sql =  'SELECT
                                realname AS name
                            FROM
                                '.$cfg["tab"]["phplib_auth_user_md5"].'
                            WHERE
                                username = "'.$aValue["Autor"].'"';
                    
                    // execute query
                    $db5->query($sql);
                    if ($bDebug) { echo "<pre>".$sql."</pre>", chr(10); }
                    $db5->next_record();
                    
                    $sAuthor = strip_tags(urldecode($db5->f('name')));
                }
                else
                {
                    $sAuthor = '';
                }
                
                $artlist_more = mi18n("More");
                
                // Generate template 
                $tpl->set('d', 'PAGELINK', $aValue["Link"]);
                $tpl->set('d', 'PAGETITLE', $aValue["PageTitle"]);
                $tpl->set('d', 'DATE', $artlist_lastmod);
                $tpl->set('d', 'HEADLINE', $aValue["Headline"]);
                $tpl->set('d', 'LABELING', $aSettings["AuthorLabeling"]);
                $tpl->set('d', 'AUTHOR', $sAuthor);
                $tpl->set('d', 'SUMMARY', $aValue["Summary"]);
                $tpl->set('d', 'MORE', $artlist_more);
        
                $tpl->next();
        
            } // end foreach
        }
    
        # Page browsing
        # Hint: Number of max available records: $lCount
        #       Number of pages: ceil($lCount / $aSettings["ArticlePerPage"])
        #       First page: page=1;
        #       Last page:  page=ceil($lCount / $aSettings["ArticlePerPage"]);
        if ($aSettings["ArticlePerPage"] > 0)
        {
            $iPages = ceil($lCount / $aSettings["ArticlePerPage"]);
            
            // Example: Back and Next
            $sPageBrowsingType01 = '';
            if ($aSettings["PageBrowsingType01"] == "enabled")
            {
                if ($iPages > 1 && ($_REQUEST['page'] + 1) > 1)
                {
                    $sPageBrowsingType01 .= '<div class="articlelistBack">';
                    $sPageBrowsingType01 .= '<a href="front_content.php?idcat='.$idcat.'&idart='.$idart.'&page='.($aSettings["CurrentPage"]).'">'.mi18n("Back").'</a>';
                    $sPageBrowsingType01 .= '</div>';
                }
                else
                {
                    $sPageBrowsingType01 .= '<div class="articlelistBack">';
                    $sPageBrowsingType01 .= mi18n("Back");
                    $sPageBrowsingType01 .= '</div>';
                }
                
                if ($iPages > 1 && ($_REQUEST['page'] + 1) < $iPages)
                {
                    $sPageBrowsingType01 .= '<div class="articlelistNext">';
                    $sPageBrowsingType01 .= '<a href="front_content.php?idcat='.$idcat.'&idart='.$idart.'&page='.($aSettings["CurrentPage"] + 2).'">'.mi18n("Next").'</a>';
                    $sPageBrowsingType01 .= '</div>';
                }
                else
                {
                    $sPageBrowsingType01 .= '<div class="articlelistNext">';
                    $sPageBrowsingType01 .= mi18n("Next");
                    $sPageBrowsingType01 .= '</div>';
                }
            }
    
            // Example: 1 2 3 4 5 6 7 ...
            $sPageBrowsingType02 = '';
            if ($aSettings["PageBrowsingType02"] == "enabled")
            {
                for ($i = 1; $i <= $iPages; $i++)
                {
                    if ($sPageBrowsingType02 != '')
                        $sPageBrowsingType02 .= ' ';
                    
                    $sPageBrowsingType02 .= (($aSettings["CurrentPage"] + 1) == $i) ? $i : '<a class="articlelistPageNumber" href="front_content.php?idcat='.$idcat.'&idart='.$idart.'&page='.$i.'">'.$i.'</a>';
                }
            }
    
            // Example: Seite 1 von 7
            $sPageBrowsingType03 = '';
            if ($aSettings["PageBrowsingType03"] == "enabled")
                $sPageBrowsingType03 .= mi18n("Page").' '.($aSettings["CurrentPage"] + 1).' '.mi18n("of").' '.$iPages; // I'm on the current page, no link
    
            // Example: Erste Seite 1 ... 3 4 5 ... 8 Letzte Seite
            $sPageBrowsingType04 = '';
            if ($aSettings["PageBrowsingType04"] == "enabled")
            {
                $sPageBrowsingType04 .= '<a class="articlelistBegin" href="front_content.php?idcat='.$idcat.'&idart='.$idart.'&page=1">'.mi18n("Begin").'</a>';
                for ($i = 1; $i <= $iPages; $i++)
                {
                    if ($i == 1 || $i == $iPages)
                    {
                        if ($sPageBrowsingType04 != '')
                            $sPageBrowsingType04 .= ' ';
                        
                        $sPageBrowsingType04 .= (($aSettings["CurrentPage"] + 1) == $i) ? $i : '<a class="articlelistPageNumber" href="front_content.php?idcat='.$idcat.'&idart='.$idart.'&page='.$i.'">'.$i.'</a>';
                    }
                    elseif (($aSettings["CurrentPage"] + 1) == $i)
                    {
                        $sPageBrowsingType04 .= ' '.$i; // I'm on the current page, no link
                    }
                    elseif (($aSettings["CurrentPage"] + 1) == ($i + 1))
                    {
                        // Front
                        $sPageBrowsingType04 .= ' <a class="articlelistPageNumber" href="front_content.php?idcat='.$idcat.'&idart='.$idart.'&page='.$i.'">'.$i.'</a>';
                    }
                    elseif (($aSettings["CurrentPage"] + 1) == ($i - 1))
                    {
                        // Back
                        $sPageBrowsingType04 .= ' <a class="articlelistPageNumber" href="front_content.php?idcat='.$idcat.'&idart='.$idart.'&page='.$i.'">'.$i.'</a>';
                    }
                    elseif (($aSettings["CurrentPage"] + 1) == ($i - 2) || ($aSettings["CurrentPage"] + 1) == ($i + 2))
                    {
                        $sPageBrowsingType04 .= ' ...';
                    }
                }
                $sPageBrowsingType04 .= ' <a class="articlelistEnd" href="front_content.php?idcat='.$idcat.'&idart='.$idart.'&page='.$lCount.'">'.mi18n("End").'</a>';
            }
            
            // Example: << < 1 ... 3 4 5 ... 8 > >>
            // First Page
            $sPageBrowsingType05 = '';
            if ($aSettings["PageBrowsingType05"] == "enabled")
            {
                if (!is_object($db)) $db = new DB_Contenido;
                
                $sql =  $sql_pagination;
    
                /*
                 * Create a PS_Pagination object
                 * 
                 * $conn = MySQL connection object
                 * $sql = SQl Query to paginate
                 * $aSettings["ArticlePerPage"] = Number of rows per page
                 * $aSettings["PageBrowsingType05MaxPages"] = Number of links
                 * "param1=valu1¶m2=value2" = You can append your own parameters to paginations links
                 */
                $pager = new PS_Pagination($db, $sql, $aSettings["ArticlePerPage"], $aSettings["PageBrowsingType05MaxPages"], "idart=".$idart);
                
                /*
                 * Enable debugging if you want o view query errors
                */
                $pager->setDebug(true);
                
                // Init pagination
                $pager->paginate();
                
                // Display the full navigation in one go
                $sDotsBefore = '';
                $sDotsAfter = '';
                
                if ($iPages > $aSettings["PageBrowsingType05MaxPages"] && ($aSettings["CurrentPage"] + 1) > $aSettings["PageBrowsingType05MaxPages"])
                    $sDotsBefore .= ' ...';
                
                if ($iPages > $aSettings["PageBrowsingType05MaxPages"] && ($aSettings["CurrentPage"] + 1) <= $aSettings["PageBrowsingType05MaxPages"])
                    $sDotsAfter .= '... ';
                
                $sPageBrowsingType05 .= $pager->renderFirst('«').$pager->renderPrev('‹').$sDotsBefore.$pager->renderNav('','').$sDotsAfter.$pager->renderNext('›').$pager->renderLast('»');
            }
        }
        $tpl->set('s', 'PAGEBROWSINGTYPE01', $sPageBrowsingType01);
        $tpl->set('s', 'PAGEBROWSINGTYPE02', $sPageBrowsingType02);
        $tpl->set('s', 'PAGEBROWSINGTYPE03', $sPageBrowsingType03);
        $tpl->set('s', 'PAGEBROWSINGTYPE04', $sPageBrowsingType04);
        $tpl->set('s', 'PAGEBROWSINGTYPE05', $sPageBrowsingType05);
        $tpl->generate($aSettings["Template"]);
    }
    // Clearing memory
    unset ($aData);
    unset ($aSettings);
    unset ($i);
    unset ($lCount);
    unset ($bDebug);
    unset ($db5);
}
else
{
    // do nothing
}
?>