Neuigkeiten
  • Die modified eCommerce Shopsoftware ist kostenlos, aber nicht umsonst.
    Spenden
  • Damit wir die modified eCommerce Shopsoftware auch zukünftig kostenlos anbieten können:
    Spenden
  • Thema: MODUL: Themenwelten

    Whiteflash

    • Fördermitglied
    • Beiträge: 186
    • Geschlecht:
    Re: MODUL: Themenwelten
    Antwort #135 am: 16. Oktober 2018, 07:06:23
    Hallo TnT34,

    super, dass du dir selbst helfen konntest - ich muss mich nämlich erst wieder ins Modul einarbeiten, das ist schon eine Weile her...  :nixweiss:
    Marktplatz - Eine große Auswahl an neuen und hilfreichen Modulen sowie modernen Templates für die modified eCommerce Shopsoftware

    Whiteflash

    • Fördermitglied
    • Beiträge: 186
    • Geschlecht:
    Re: MODUL: Themenwelten
    Antwort #136 am: 17. Oktober 2018, 17:11:10
    So, habe glaube fertig...  :-)

    Da die Integration nicht so schwierig war, da abgesehen vom Aufruf der enhancer-Funktion alles beim alten blieb, habe ich mir die Modifikationen nochmals vorgenommen und etwas verfeinert - Erläuterungen dazu weiter unten.

    Wer die von mir gemachten Änderungen nutzen will, kopiert am Besten einfach den kompletten nachfolgenden Code in die Datei templates/CURRENT_TEMPLATE/smarty/modifier.contentenhancer.php - alles allem dort befindlichen Code markieren, löschen und mit dem nachfolgenden Code ersetzen - dann sind alle Änderungen sicher drin (es sind nämlich doche einige geworden, und ich habe glaube ich vergessen auch einige zu markieren...)
    Code: PHP  [Auswählen]

    <?php

    function smarty_modifier_contentenhancer ($html) {
       
       
        // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying setting template
        if(preg_match_all('/(\[([\w\d ]*)template[^\]]+\])/', $html, $matches)){
            foreach($matches[1] AS $snippet){
                if(preg_match('/template\=\'([^\']+)\'/', $snippet, $template_matches)){
                    if (!empty($template_matches[1])) {
                        $template=$template_matches[1];
                        $template_usage=(!empty($matches[2][0])) ? $matches[2][0] : "all";
                        $html = str_replace($snippet, '', $html);
                        break;
                    }
                }
            }
        }
        // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying setting template


        if(preg_match_all('/(\[products [^\]]+\])/', $html, $matches)){
            foreach($matches[1] AS $snippet){
                $products_models = null;
                $categories_ids = null;
                $keywords = null;

                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models
                $restrictions=setRestrictions($snippet);
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models

                if(preg_match('/products_models\=\'([^\']+)\'/', $snippet, $model_matches)){
                    $t_models = explode(',', $model_matches[1]);
                    $products_models = array();
                    foreach($t_models AS $model){
                        $products_models[] = xtc_db_input(trim($model));
                    }
                }

                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models
                $restrictions=setRestrictions($snippet);
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models

                if(preg_match('/categories_ids\=\'([^\']+)\'/', $snippet, $categories_ids_matches)){
                    $t_categories_ids = explode(',', $categories_ids_matches[1]);
                    $categories_ids = array();
                    foreach($t_categories_ids AS $categories_id){
                        $categories_ids[] = (int)$categories_id;
                    }
                }

                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models
                $restrictions=setRestrictions($snippet);
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models

                if(preg_match('/keywords\=\'([^\']+)\'/', $snippet, $keyword_matches)){
                    $t_keywords = explode(',', $keyword_matches[1]);
                    $keywords = array();
                    foreach($t_keywords AS $keyword){
                        $keywords[] = xtc_db_input(trim($keyword));
                    }
                }

                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - parse Products (with selected template) for keyword with  $limit, $order_by, $exclusion (change function call)
                if (($template_usage == 'all') || ($template_usage == 'categories')) {
                    $html = str_replace($snippet, parseProducts($products_models, $categories_ids, $keywords, $restrictions, $template), $html);
                } else {
                    $html = str_replace($snippet, parseProducts($products_models, $categories_ids, $keywords, $restrictions), $html);
                }
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - parse Products (with selected template) for keyword with  $limit, $order_by, $exclusion (change function call)

            }
        }

        if(preg_match_all('/(\[categories [^\]]+\])/', $html, $matches)){
            foreach($matches[1] AS $snippet){

                if(preg_match('/categories_ids\=\'([^\']+)\'/', $snippet, $categories_ids_matches)){
                    $t_categories_ids = explode(',', $categories_ids_matches[1]);
                    $categories_ids = array();
                    foreach($t_categories_ids AS $categories_id){
                        $categories_ids[] = (int)$categories_id;
                    }
                }

                if(preg_match('/keywords\=\'([^\']+)\'/', $snippet, $keyword_matches)){
                    $t_keywords = explode(',', $keyword_matches[1]);
                    $keywords = array();
                    foreach($t_keywords AS $keyword){
                        $keywords[] = xtc_db_input(trim($keyword));
                    }
                }

                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - parse Categories (with selected template)
                $restrictions=setRestrictions($snippet);
                if (($template_usage == 'all') || ($template_usage == 'categories')) {
                    $html = str_replace($snippet, parseCategories($categories_ids, $keywords, $restrictions, $template), $html);
                } else {
                    $html = str_replace($snippet, parseCategories($categories_ids, $keywords, $restrictions), $html);
                }
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - parse Categories (with selected template)
            }
        }

        // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword with  $limit, $order_by, $exclusion (change function call)
        $html = parseSubstitutions($html);
        // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword with  $limit, $order_by, $exclusion (change function call)

        return $html;

    }


    function /* parseCategories($categories_ids = NULL) { */
        parseCategories($categories_ids = null, $keywords = null, $restrictions = null, $template = '/module/modules/content_enhancer/listing_cats.html'){ // Whiteflash: Modul Content-Enhancer - mod modifying sql_settings for keyword with $limit

        if ((is_array($categories_ids)) || (is_array($keywords))) {

            if (GROUP_CHECK == 'true') {
                    $group_check = "c.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 AND";
            }

            // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword
            $keywords_sequence = generateKeywordsequence($categories_ids, $keywords, 'cd', array('categories_name', 'categories_description'));

            $q = "SELECT
                            c.categories_id,
                            c.categories_image,  
                            cd.categories_name,
                            cd.categories_description
                    FROM categories AS c
                    LEFT JOIN categories_description as cd
                    ON c.categories_id = cd.categories_id
                    WHERE c.categories_id IN ('"
    .implode("', '", $categories_ids)."')
                    "
    .$keywords_sequence." -- Whiteflash 2018-10-23: add keywords_sequence
                    AND "
    .$group_check." c.categories_status = '1'
                    AND cd.language_id = '"
    .(int) $_SESSION['languages_id'] ."'
                    ORDER BY FIND_IN_SET(c.categories_id,'"
    .implode(",", $categories_ids)."')";

            // Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for restrictions
            $q = convertRestrictions($q, $restrictions);

            $categories_query = xtDBquery($q);

            while($categories = xtc_db_fetch_array($categories_query, true)) {
                $category_link =xtc_category_link($categories['categories_id'],$categories['categories_name']);
                $module_content[] = array ('CATEGORY_NAME'        => $categories['categories_name'],
                    'CATEGORY_IMAGE_TRUE'  => $categories['categories_image'],        
                    'CATEGORY_IMAGE'       => DIR_WS_IMAGES .'categories/' . $categories['categories_image'],
                    'CATEGORY_LINK'        => xtc_href_link(FILENAME_DEFAULT,  xtc_get_all_get_params(array(array('cat','page','filter_id','manufacturers_id'))) . $category_link),
                    'CATEGORY_DESCRIPTION' => $categories['categories_description'],
                    'CATEGORY_DESCRIPTION_INTRO' => shortenStringOnNextSpace($categories['categories_description'])
                 );


            }      
            //echo "<pre>";
            //var_dump($module_content);
            //echo "</pre>";
            $smarty = new Smarty;
            $smarty->assign('categories', $module_content);
            $smarty->assign('language', $_SESSION["language"]);

            // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - check template file and set ready for use
            $template_chck = str_replace('//', '/', DIR_FS_CATALOG) .'templates/'. CURRENT_TEMPLATE. $template;
            $used_template = (file_exists($template_chck)) ? CURRENT_TEMPLATE.$template : CURRENT_TEMPLATE.'/module/modules/content_enhancer/listing_cats.html';
            // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - check template file and set ready for use
            $html = $smarty->fetch($used_template);

            return $html;
        }
    }

    function /* parseProducts($products_models = null, $categories_ids = null, $keywords = null){ */
        parseProducts($products_models = null, $categories_ids = null, $keywords = null, $restrictions = null, $template = '/module/modules/content_enhancer/listing.html'){ // Whiteflash: Modul Content-Enhancer - mod modifying sql_settings for keyword with $limit
        if(is_array($products_models) || is_array($categories_ids) || is_array($keywords)){
            $group_check = '';
            $fsk_lock = '';

            if ($_SESSION['customers_status']['customers_fsk18_display'] == '0') {
                $fsk_lock = ' AND p.products_fsk18!=1';
            }

            if (GROUP_CHECK == 'true') {
                $group_check = " AND p.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";
            }

            $q = "SELECT * FROM
                            "
    .TABLE_PRODUCTS." p
                            JOIN "
    .TABLE_PRODUCTS_DESCRIPTION." pd ON (p.products_id = pd.products_id AND pd.language_id = ".(int)$_SESSION["languages_id"].")
                  WHERE
                        p.products_status = 1 "
    .$fsk_lock.$group_check;

            if(is_array($products_models)){
                $q .= " AND p.products_model IN ('".implode("', '", $products_models)."') ";
            }

            if(is_array($categories_ids)){
                $q .= " AND p.products_id IN (SELECT p2c.products_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." p2c WHERE p2c.categories_id IN (".implode(',', $categories_ids).")) ";
            }

            // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword
            $q .= generateKeywordsequence($categories_ids, $keywords, 'pd', array('products_keywords', 'products_name', 'products_description'), 'AND');

            // Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword
            $q = convertRestrictions($q, $restrictions);


            global $product;
            $module_content = array();
            $listing_query = xtDBquery($q);
            while ($listing = xtc_db_fetch_array($listing_query, true)) {

                 // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword
                if (is_array($restrictions['excludes'])) {
                    foreach ($restrictions['excludes'] as $column => $values) {
                        if ((!empty($listing[$column])) && (in_array($listing[$column], $values))) continue 2;
                    }
                }
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword

                $module_content[] =  $product->buildDataArray($listing);
            }

            $smarty = new Smarty;
            $smarty->assign('products', $module_content);
            $smarty->assign('language', $_SESSION["language"]);

            // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - check template file and set ready for use
            $template_chck = str_replace('//', '/', DIR_FS_CATALOG) .'templates/'. CURRENT_TEMPLATE. $template;
            $used_template = (file_exists($template_chck)) ? CURRENT_TEMPLATE.$template : CURRENT_TEMPLATE.'/module/modules/content_enhancer/listing.html';
            // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - check template file and set ready for use
            $html = $smarty->fetch($used_template);
            return $html;

        }

        return '';
    }

    /**
     *
     * @param type $input
     * @param type $target_length
     * @return string
     * @author Whiteflash, 2018-10-23
     */

    function shortenStringOnNextSpace($input, $target_length = 125) {


        $shorty = substr($input, 0, strpos($input, " ", $target_length));
        if ((!empty($shorty)) && (strlen($shorty) < strlen($input))) $shorty .= "...";

        return $shorty;
    }

    /**
     *
     * @param type $q
     * @param type $restrictions
     * @return string
     * @author Whiteflash, 2018-10-23
     */

    function convertRestrictions($q, $restrictions) {


        if (!empty($restrictions['order_by'][0])) $q .= " ORDER BY ".$restrictions['order_by'][0]." ".$restrictions['order_by'][1];
        if (!empty($restrictions['limit'])) $q .= " LIMIT ".$restrictions['limit'];
        if (!empty($restrictions['random'])) {
            if (($order_by_pos = strpos($q, 'ORDER BY')) !== false) $q = substr($q, 0, $order_by_pos);
            $q .= " ORDER BY RAND() ".((!empty($restrictions['random'])) ? ( (strtolower($restrictions['random']) == 'all') ? "" : "LIMIT ".$restrictions['random']."") : "")." ";
        }

        return $q;
    }

    /**
     *
     * @param array $categories_ids
     * @param array $keywords
     * @param string $table_shortcut
     * @param array $table_fields
     * @param string $concatenate, optional (null)
     * @return string keywordsequence
     * @author Whiteflash, 2018-10-23
     */

    function generateKeywordsequence($categories_ids, $keywords, $table_shortcut, $table_fields, $concatenate = null) {

        $keywords_sequence = (!empty($concatenate)) ? " ".$concatenate : "";
        if(is_array($keywords)) {
            $connector = (empty($categories_ids)) ? " " : " OR";
            $keywords_sequence .= $connector." (1!=1";
            foreach($keywords AS $keyword){
                for ($i=0;$i<count($table_fields);$i++) { $keywords_sequence .= " OR (".$table_shortcut.".".$table_fields[$i]." LIKE ('%".$keyword."%'))"; }
            }
            $keywords_sequence .= ")";
        }

        return $keywords_sequence;
    }

    /**
     *
     * @param type $html
     * @return type
     * @author Whiteflash, 2018-10-23
     */

    function parseSubstitutions($html) {

        if (strpos($html, 'substitutions') !== false) {

            if(preg_match_all('/(\[substitutions [^\]]+\])/', $html, $matches)){
                foreach($matches[1] AS $match){

                    $quantifier = '';
                    $regex = '{(.[^{]*?)}';
                    $regex = '(?<={)(.[^{]*?)(?=})';

                    $left_brace = strpos($match, '{');
                    $right_brace = strrpos($match, '}');

                    $captured_raw_jsonstring = substr($match, $left_brace, (($right_brace - $left_brace) + 1));
                    $captured_jsonstring = str_replace('\'', '"', strip_tags($captured_raw_jsonstring));

                    $arguments = json_decode($captured_jsonstring);

                    if ($arguments !== NULL) {                        
                        foreach ($arguments as $search => $argument) {
                            if (is_object($argument)) {
                                $substitution = $limit = null;
                                $validity_range = array();
                                foreach ($argument as $command => $c_argument) {
                                    if ($command == 'substitution') {
                                        $substitution = $c_argument;
                                    } elseif ($command == 'limit') {
                                        $limit = $c_argument;
                                    } elseif ($command == 'validity') {
                                        if (!is_object($c_argument)) {
                                            $validity_range = array($c_argument);
                                        } else {
                                            foreach ($c_argument as $cc_key => $cc_argument) { $validity_range[] = $cc_argument; }
                                        }
                                    } else {
                                        // unknown $command
                                    }
                                }

                                // check if substitution found
                                if ($substitution !== null) {
                                    foreach ($validity_range as $identifyer) {
                                        $elements = array();
                                        if (($identifyer == 'products_name') || ($identifyer == 'name')) {
                                            $tagname = 'div';
                                            $elements = findElements($html, $search, $tagname, array('class', 'nameWr'));
                                        } elseif ($identifyer == 'text') {
                                            $tagname = 'p';
                                            $elements = findElements($html, $search, $tagname, array());
                                        } else {
                                            continue;
                                        }

                                        if(!empty($elements)) {
                                            $count_replaces = 0;
                                            foreach ($elements as $element) {
                                                if (($limit !== null) && ($count_replaces >= $limit)) { continue; }
                                                $new_replace = str_replace($search, $substitution, $element['inner_html']);
                                                $html = str_replace($element['inner_html'], $new_replace, $html);
                                                $count_replaces++;
                                            }
                                        }
                                    }
                                }
                            } else {
                                $html = str_replace($search, $argument, $html);
                            }
                        }
                    }
                    // remove substitutions-instructions from output
                    if (strpos($html, '[substitutions')!==false)
                        $html = preg_replace('/(\[substitutions [^\]]+\])/', '', $html);
                }
            }
        }

        return $html;
    }

    /**
     *
     * @param string $string
     * @param string $search
     * @param string $tagname
     * @param array $identifying, optional
     * @return array | boolean false on error
     * @author Whiteflash, 2018-10-23
     */

    function findElements($string, $search, $tagname, $identifying = array()) {


        $elements = array();
        $security_chars = 10;

        while (($pos = (strpos($string, $tagname, $offset))) !== false) {

            $end_of_tag_pos = strpos($string, '>', $pos);
            $start_of_next_tag_pos = null;

            if (!empty($identifying)) {
                $identifyer_length = strlen($identifying[0]) + strlen($identifying[1]) + $security_chars;
                $controllstring = substr($string, $pos, $identifyer_length);
                if (strpos($controllstring, $identifying[1]) === false) {
                    $start_of_next_tag_pos = strpos($string, '</'.$tagname, $end_of_tag_pos);
                    $start_of_next_tag_pos_sec = strpos($string, '</ '.$tagname, $end_of_tag_pos);
                } else {
                    // nothing? - no, do nothing
                }
            } else {
                $start_of_next_tag_pos = strpos($string, '</'.$tagname, $end_of_tag_pos);
                $start_of_next_tag_pos_sec = strpos($string, '</ '.$tagname, $end_of_tag_pos);
            }

            // check for problems in setup of the html-tags
            if (($start_of_next_tag_pos_sec - $start_of_next_tag_pos) > 1) { return false; }

            // recompare start-pos of next tag
            if ($start_of_next_tag_pos_sec > $start_of_next_tag_pos) $start_of_next_tag_pos = $start_of_next_tag_pos_sec;

            if ($start_of_next_tag_pos !== null) {
                $inner_html = substr($string, ($end_of_tag_pos + 1), (($start_of_next_tag_pos - $end_of_tag_pos) - 1));
                if (strpos($inner_html, $search) !== false) {
                    $elements[] = array('inner_html'=>$inner_html, 'start'=>($end_of_tag_pos + 1), 'end'=>(($start_of_next_tag_pos - $end_of_tag_pos) - 1));
                }
            }
            // upcount offset
            $offset = $pos + 1;
        }

        return $elements;
    }

    /**
     * Function evaluates all restrictions from the given snippet-string.
     * @param string $snippet
     * @return array
     * @author Whiteflash, 2018-10-23
     */

    function setRestrictions($snippet) {

        // return already known restrictions
        if (key_exists($snippet, $_SESSION['snippets'])) return $_SESSION['snippets'][$snippet];

        $restrictions = array();

        if(preg_match('/limit\=\'([^\']+)\'/', $snippet, $modding_matches)) $restrictions['limit'] = intval($modding_matches[1]);
        if(preg_match('/order_by\=\'([^\']+)\'/', $snippet, $modding_matches)) $restrictions['order_by'] = (!empty($modding_matches[1]))?explode(':', $modding_matches[1]):null;
        if(preg_match('/random\=\'([^\']+)\'/', $snippet, $modding_matches)) $restrictions['random'] = intval($modding_matches[1]);
        // check order_by-statement
        if (!strstr($restrictions['order_by'][0], '.')) getColumsTable($restrictions['order_by'][0]);
        if (empty($restrictions['order_by'][1])) $restrictions['order_by'][1] = 'asc';

        if(preg_match('/excludes\=\'([^\']+)\'/', $snippet, $modding_matches)) $excludes = (!empty($modding_matches[1]))?explode(':', $modding_matches[1]):null;
        // check excludes-statement
        if (strstr($excludes[0], '.')) unsetColumsTable($excludes[0]);
        $excludes[1]=explode(',', $excludes[1]);
        array_walk($excludes[1], 'trim');
        $restrictions['exlcudes']=array($excludes[0] => $excludes[1]);

        // prepare (and save) restriction
        if (!is_array($_SESSION['snippets'])) $_SESSION['snippets'] = array();
        $_SESSION['snippets'][$snippet] = $restrictions;

        return $restrictions;
    }

    /**
     * Unsets all given table-prefixes of th given $input.
     * @param string $input
     * @author by Whiteflash, 2018-10-23
     */

    function unsetColumnsTable(&$input) {

        $input=preg_replace('#.*\.#', '', $input);
    }

    /**
     * Switches table-prefix for $input (column) or set it to null, if no match given.
     * @param string $input
     * @author Whiteflash, 2018-10-23
     */

    function getColumsTable(&$input) {


        switch ($input) {
            case "products_id": $input='p.'.$input; break;
            case "products_model": $input='p.'.$input; break;
            case "products_status": $input='p.'.$input; break;
            case "products_name": $input='pd.'.$input; break;
            case "products_keywords": $input='pd.'.$input; break;

            default: $input=null;
        }
    }
    ?>
     

    Zur Verwendung der Modifikationen:

    1) Template:
    Zitat
    [template='/module/modules/content_enhancer/flow_listing.html']
    Zitat
    [productstemplate='/module/modules/content_enhancer/flow_listing.html']
    Zitat
    [categoriestemplate='/module/modules/content_enhancer/flow_listing.html']
    Über den Tag template kann ein alternatives Template gewählt werden. Wird kein Tag gesetzt, dann bleibt es beim Standard-Template '/module/modules/content_enhancer/listing.html' für die Produkte und bei '/module/modules/content_enhancer/listing-cats.html' für die Kategorien. Wird dem Tag ein 'products' vorangestellt, gilt das gesetzte Template nur für die Produkte, wird ein 'categories' vorangestellt, analog nur für die Kategorien. Bei keinem gesetzten Präfix gilt das Template dann für beides (Vorsicht, das muss dann aber mit beidem umgehen können: Produkte und Kategorien!).

    2) Tags für Produkte:
    Zitat
    [products keywords='keyword1,keyword2' Limit o. random='8 o. all' order_by='products_id:desc' excludes='products_id:314,313']

    Bei allen 3 Tag-Arten (also keywords, categories_ids und products_models können frei und in loser Reihenfolge folgende Modifikatoren übergeben werden:
    1. limit: setzt in der SQL-Abfrage ein Limit (dann auf jeden Fall Anzahl angeben!) oder random: wählt zufällig die gesetzte Anzahl an Artikeln oder Kategorien oder zeigt alle (all) in zufälliger Reihenfolge an.

    2. order_by: setzt in der SQL-Abfrage ein Order By. Schema
    'Tabellenkürzel.Spaltenname:Sortierrichtung'

    3. excludes: sortiert alle Produkte mit der angegebenen products_id wieder aus dem Ergebnis-Array

    ... to be continued

    Whiteflash

    • Fördermitglied
    • Beiträge: 186
    • Geschlecht:
    Re: MODUL: Themenwelten
    Antwort #137 am: 17. Oktober 2018, 17:39:32
    … Fortsetzung vom letzen Post:

    4. substitutions:
    Zitat
    [substitutions {'Jacke':'Hose','Winterjacke':{'substitution':'warme Jacke','validity':'name'},'Herbstjacke':{'substitution':'normale Jacke','validity':{'0':'name','1':'description'}},'Produkt':{'substitution':'Artikel','validity':{'0':'text','1':'description'}}}]
    Wer mag, kann dadurch Textersetzungen vornehmen und somit ein bisschen Keyword-Stuffing betreiben  ;-)
    Der String muss als JSON-Objektliteral aufgebaut sein, so ergibt im Beispiel oben {'Jacke':'Hose'} die generelle Ersetzung von allen 'Jacke'-Strings durch 'Hose'. Im Beispiel ist eine zweite Ersetzung erwünscht, die wiederum ein (eingefügtes) JSON-Objekt darstellt - dadurch kann die Ersetzung gesteuert werden. So soll aus 'Winterjacke' der Begriff 'warme Jacke' werden (=Substitution), der Gültigkeitsbereich der Ersetzung 'validity' bezieht sich aber nur auf Produktnamen ('name').

    Die 'Herbstjacke' soll durch 'normale Jacke' ersetzt werden, und zwar im Bereich 'name' und 'description'. Es können hier also auch zwei oder mehr Bereiche gesetzt werden - damit das Script diese auch verarbeiten kann, brauchen diese Aufzählungen immer einen Bezeichner (z.B. '0', '1', etc - und den bitte immer in einfachen Anführungszeichen [single-quotes]).

    Ersetzungen können eingeschränkt werden auf: name (products_name) und text (der ggf. auf der Seite befindliche Freitext - dann muss der aber jeweils in einem p-Tag liegen, damit er auch vom Script geparsed werden kann...

    Ich hoffe, das ist brauchbar und der ein oder andere hat Verwendung dafür...

    LG Whiteflash

    TnT34

    • Neu im Forum
    • Beiträge: 38
    Re: MODUL: Themenwelten
    Antwort #138 am: 24. Oktober 2018, 22:09:20
    Mooin,

    suuper, herzliches Danke fürs Teilen!  :thx:

    Baue ich ASAP ein und berichte danach.

    Greetz, T

    pomm

    • Schreiberling
    • Beiträge: 258
    Re: MODUL: Themenwelten
    Antwort #139 am: 26. Oktober 2018, 18:31:06
    Hallo!

    Danke für das Modul, fkt. auf Anhieb super.

    Stelle damit die Kategorien auf der Startseite dar und habe einen Schönheitsfehler, da meine Kategorienamen zum Teil zu lang sind.
    [ Für Gäste sind keine Dateianhänge sichtbar ]

    Gibt es eine Möglichkeit den Umbruch zu beeinflußen, daß er nur bei ganzen Wörtern umbricht oder nach Rechtschreibregeln mit Bindestrich?

    Shop: V2.0.4.2 rev 11374
    Datenbank: MOD_2.0.4.2
    Template: tpl_modified_responsive

    Danke!
    LG Sigi

    noRiddle (revilonetz)

    • Experte
    • Beiträge: 13.838
    • Geschlecht:
    Re: MODUL: Themenwelten
    Antwort #140 am: 26. Oktober 2018, 22:35:30
    Schau mal ob für den Artikelnamen evtl. einer dieser Styles gesetzt ist:
    Code: CSS  [Auswählen]
    word-break: break-word;
    oder
    Code: CSS  [Auswählen]
    word-wrap: break-word;

    und wenn ja, setze es in beiden Fällen auf normal.

    Ansonsten: Link ?

    Gruß,
    noRiddle

    TnT34

    • Neu im Forum
    • Beiträge: 38
    Re: MODUL: Themenwelten
    Antwort #141 am: 27. Oktober 2018, 03:48:04
    Moin Whiteflash,

    hab deinen Mod nun nachgezogen.

    Soweit alles tiptop!

    Nur das exclude will bei mir einfach nicht.

    Hab ich so nen Tag:

    Code: PHP  [Auswählen]
    [products keywords='schlachmichtot' excludes='products_id:123']

    Dann wird mir der Artikel (hier Id 484) trotzdem immer angezeigt.
    Weil ich will natürlich den Artikel, in welchem ich das Listing vornehme, nicht nochmal als Empfehlung angezeigt haben.
    M.E. sollte das sowieso standardmäßig automagisch erfolgen, weil macht niemals Sinn.. ;-)

    Ich schau mal, ob ich selber herausfinde, woran das liegen kann.

    Thx & Greetz, T

    pomm

    • Schreiberling
    • Beiträge: 258
    Re: MODUL: Themenwelten
    Antwort #142 am: 27. Oktober 2018, 14:49:57
    Schau mal ob für den Artikelnamen evtl. einer dieser Styles gesetzt ist:
    Code: CSS  [Auswählen]
    word-break: break-word;
    oder
    Code: CSS  [Auswählen]
    word-wrap: break-word;

    und wenn ja, setze es in beiden Fällen auf normal.

    Ansonsten: Link ?

    Gruß,
    noRiddle

    Danke noRiddle für deine hellseherischen Fähigkeiten!
    Es war word-break:break-all drinnen.
    LG Sigi

    InfoCut

    • Neu im Forum
    • Beiträge: 24
    Re: MODUL: Themenwelten
    Antwort #143 am: 02. November 2018, 12:35:09
    Moin , Hallo,
    was mache ich falsch ? bekomme nichts angezeigt
    Eintrag in CAT/Sub_Cat/Cub_cat/

    [products categories_ids='107' order_by='products_id:desc']

    LOG
    [02-11-2018 12:20:17] E_USER_WARNING   : LoggingManager: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY p.products_id desc' at line 5<br/><br/>SELECT * FROM
                            products p
                            JOIN products_description pd ON (p.products_id = pd.products_id AND pd.language_id = 2)
                  WHERE
                        p.products_status = 1  AND p.products_id IN (SELECT p2c.products_id FROM products_to_categories p2c WHERE p2c.categories_id IN (107))  AND ORDER BY p.products_id desc in /inc/db_functions_mysqli.inc.php on Line: 161

    Whiteflash

    • Fördermitglied
    • Beiträge: 186
    • Geschlecht:
    Re: MODUL: Themenwelten
    Antwort #144 am: 10. November 2018, 09:27:51
    Hallo an alle,

     :paperbag:

    Ich habe nicht sauber gearbeitet! Die Funktionalität der 'excludes' habe ich gar nicht vollständig eingebaut, außerdem war ein Tippfehler ('elxcudes') im Script. Das kann dann nicht funktionieren. Und leider hatte ich aber die letzten 2 Wochen dermaßen zu tun, das ich nicht zur Überarbeitung kam... Sorry dafür!

    @InfoCut: nein, du machst nix falsch - der Query, der gebildet wird ist aber falsch. Ich hoffe, dass dies mit der überarbeiteten Version der 'templates\CURRENT_TEMPLATE/smarty/modifier.contentenhancer.php' nun nicht mehr passiert. Also bitte den Inhalt der Datei mit dem nachfolgenden PHP-Code ersetzen:
    Code: PHP  [Auswählen]

    <?php

    function smarty_modifier_contentenhancer ($html) {
       
       
        // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying setting template
        if(preg_match_all('/(\[([\w\d ]*)template[^\]]+\])/', $html, $matches)){
            foreach($matches[1] AS $snippet){
                if(preg_match('/template\=\'([^\']+)\'/', $snippet, $template_matches)){
                    if (!empty($template_matches[1])) {
                        $template=$template_matches[1];
                        $template_usage=(!empty($matches[2][0])) ? $matches[2][0] : "all";
                        $html = str_replace($snippet, '', $html);
                        break;
                    }
                }
            }
        }
        // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying setting template


        if(preg_match_all('/(\[products [^\]]+\])/', $html, $matches)){
            foreach($matches[1] AS $snippet){
                $products_models = null;
                $categories_ids = null;
                $keywords = null;

                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models
                $restrictions=setRestrictions($snippet);
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models

                if(preg_match('/products_models\=\'([^\']+)\'/', $snippet, $model_matches)){
                    $t_models = explode(',', $model_matches[1]);
                    $products_models = array();
                    foreach($t_models AS $model){
                        $raw_model = xtc_db_input(trim($model));
                        if (strlen($raw_model) < 10) { $raw_model = str_pad($raw_model, 10, "0", STR_PAD_LEFT); }
                        $products_models[] = xtc_db_input(sanitizeIdentifyerstrings($raw_model));
                    }
                }
               
                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models
                $restrictions=setRestrictions($snippet);
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models

                if(preg_match('/categories_ids\=\'([^\']+)\'/', $snippet, $categories_ids_matches)){
                    $t_categories_ids = explode(',', $categories_ids_matches[1]);
                    $categories_ids = array();
                    foreach($t_categories_ids AS $categories_id){
                        $categories_ids[] = (int)$categories_id;
                    }
                }

                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models
                $restrictions=setRestrictions($snippet);
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for product_models

                if(preg_match('/keywords\=\'([^\']+)\'/', $snippet, $keyword_matches)){
                    $t_keywords = explode(',', $keyword_matches[1]);
                    $keywords = array();
                    foreach($t_keywords AS $keyword){
                        $keywords[] = xtc_db_input(trim($keyword));
                    }
                }

                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - parse Products (with selected template) for keyword with  $limit, $order_by, $exclusion (change function call)
                if (($template_usage == 'all') || ($template_usage == 'categories')) {
                    $html = str_replace($snippet, parseProducts($products_models, $categories_ids, $keywords, $restrictions, $template), $html);
                } else {
                    $html = str_replace($snippet, parseProducts($products_models, $categories_ids, $keywords, $restrictions), $html);
                }
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - parse Products (with selected template) for keyword with  $limit, $order_by, $exclusion (change function call)

            }
        }

        if(preg_match_all('/(\[categories [^\]]+\])/', $html, $matches)){
            foreach($matches[1] AS $snippet){

                if(preg_match('/categories_ids\=\'([^\']+)\'/', $snippet, $categories_ids_matches)){
                    $t_categories_ids = explode(',', $categories_ids_matches[1]);
                    $categories_ids = array();
                    foreach($t_categories_ids AS $categories_id){
                        $categories_ids[] = (int)$categories_id;
                    }
                }

                if(preg_match('/keywords\=\'([^\']+)\'/', $snippet, $keyword_matches)){
                    $t_keywords = explode(',', $keyword_matches[1]);
                    $keywords = array();
                    foreach($t_keywords AS $keyword){
                        $keywords[] = xtc_db_input(trim($keyword));
                    }
                }

                // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - parse Categories (with selected template)
                $restrictions=setRestrictions($snippet);
                if (($template_usage == 'all') || ($template_usage == 'categories')) {
                    $html = str_replace($snippet, parseCategories($categories_ids, $keywords, $restrictions, $template), $html);
                } else {
                    $html = str_replace($snippet, parseCategories($categories_ids, $keywords, $restrictions), $html);
                }
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - parse Categories (with selected template)
            }
        }

        // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword with  $limit, $order_by, $exclusion (change function call)
        $html = parseSubstitutions($html);
        // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword with  $limit, $order_by, $exclusion (change function call)

        return $html;

    }


    function /* parseCategories($categories_ids = NULL) { */
        parseCategories($categories_ids = null, $keywords = null, $restrictions = null, $template = '/module/modules/content_enhancer/listing_cats.html'){ // Whiteflash: Modul Content-Enhancer - mod modifying sql_settings for keyword with $limit

        if ((is_array($categories_ids)) || (is_array($keywords))) {

            if (GROUP_CHECK == 'true') {
                    $group_check = "c.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 AND";
            }

            // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword
            $keywords_sequence = generateKeywordsequence($categories_ids, $keywords, 'cd', array('categories_name', 'categories_description'));

            $q = "SELECT
                            c.categories_id,
                            c.categories_image,  
                            cd.categories_name,
                            cd.categories_description
                    FROM categories AS c
                    LEFT JOIN categories_description as cd
                    ON c.categories_id = cd.categories_id
                    WHERE c.categories_id IN ('"
    .implode("', '", $categories_ids)."')
                    "
    .$keywords_sequence." -- Whiteflash 2018-10-23: add keywords_sequence
                    AND "
    .$group_check." c.categories_status = '1'
                    AND cd.language_id = '"
    .(int) $_SESSION['languages_id'] ."'
                    ORDER BY FIND_IN_SET(c.categories_id,'"
    .implode(",", $categories_ids)."')";

            // Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for restrictions
            $q = convertRestrictions($q, $restrictions);

            $categories_query = xtDBquery($q);

            while($categories = xtc_db_fetch_array($categories_query, true)) {
                $category_link =xtc_category_link($categories['categories_id'],$categories['categories_name']);
                $module_content[] = array ('CATEGORY_NAME'        => $categories['categories_name'],
                    'CATEGORY_IMAGE_TRUE'  => $categories['categories_image'],        
                    'CATEGORY_IMAGE'       => DIR_WS_IMAGES .'categories/' . $categories['categories_image'],
                    'CATEGORY_LINK'        => xtc_href_link(FILENAME_DEFAULT,  xtc_get_all_get_params(array(array('cat','page','filter_id','manufacturers_id'))) . $category_link),
                    'CATEGORY_DESCRIPTION' => $categories['categories_description'],
                    'CATEGORY_DESCRIPTION_INTRO' => shortenStringOnNextSpace($categories['categories_description'])
                 );


            }      
            //echo "<pre>";
            //var_dump($module_content);
            //echo "</pre>";
            $smarty = new Smarty;
            $smarty->assign('categories', $module_content);
            $smarty->assign('language', $_SESSION["language"]);

            // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - check template file and set ready for use
            $template_chck = str_replace('//', '/', DIR_FS_CATALOG) .'templates/'. CURRENT_TEMPLATE. $template;
            $used_template = (file_exists($template_chck)) ? CURRENT_TEMPLATE.$template : CURRENT_TEMPLATE.'/module/modules/content_enhancer/listing_cats.html';
            // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - check template file and set ready for use
            $html = $smarty->fetch($used_template);

            return $html;
        }
    }

    function /* parseProducts($products_models = null, $categories_ids = null, $keywords = null){ */
        parseProducts($products_models = null, $categories_ids = null, $keywords = null, $restrictions = null, $template = '/module/modules/content_enhancer/listing.html'){ // Whiteflash: Modul Content-Enhancer - mod modifying sql_settings for keyword with $limit
        if(is_array($products_models) || is_array($categories_ids) || is_array($keywords)){
            $group_check = '';
            $fsk_lock = '';

            if ($_SESSION['customers_status']['customers_fsk18_display'] == '0') {
                $fsk_lock = ' AND p.products_fsk18!=1';
            }

            if (GROUP_CHECK == 'true') {
                $group_check = " AND p.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";
            }

            $q = "SELECT * FROM
                            "
    .TABLE_PRODUCTS." p
                            JOIN "
    .TABLE_PRODUCTS_DESCRIPTION." pd ON (p.products_id = pd.products_id AND pd.language_id = ".(int)$_SESSION["languages_id"].")
                  WHERE
                        p.products_status = 1 "
    .$fsk_lock.$group_check;

            if(is_array($products_models)){
                $q .= " AND p.products_model IN ('".implode("', '", $products_models)."') ";
            }

            if(is_array($categories_ids)){
                $q .= " AND p.products_id IN (SELECT p2c.products_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." p2c WHERE p2c.categories_id IN (".implode(',', $categories_ids).")) ";
            }
           
            // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword
            $q .= generateKeywordsequence($categories_ids, $keywords, 'pd', array('products_keywords', 'products_name', 'products_description'), 'AND');
           
            // Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword
            $q = convertRestrictions($q, $restrictions);
           
            global $product;
            $module_content = array();
            $listing_query = xtDBquery($q);
            while ($listing = xtc_db_fetch_array($listing_query, true)) {

                 // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword
                if (is_array($restrictions['excludes'])) {
                    foreach ($restrictions['excludes'] as $column => $values) {
                        if ((!empty($listing[$column])) && (in_array($listing[$column], $values))) continue 2;
                    }
                }
                // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - mod modifying sql_settings for keyword

                $module_content[] =  $product->buildDataArray($listing);
            }

            $smarty = new Smarty;
            $smarty->assign('products', $module_content);
            $smarty->assign('language', $_SESSION["language"]);

            // BOF - Whiteflash 2018-10-23: Modul Content-Enhancer - check template file and set ready for use
            $template_chck = str_replace('//', '/', DIR_FS_CATALOG) .'templates/'. CURRENT_TEMPLATE. $template;
            $used_template = (file_exists($template_chck)) ? CURRENT_TEMPLATE.$template : CURRENT_TEMPLATE.'/module/modules/content_enhancer/listing.html';
            // EOF - Whiteflash 2018-10-23: Modul Content-Enhancer - check template file and set ready for use
            $html = $smarty->fetch($used_template);
            return $html;

        }

        return '';
    }

    /**
     *
     * @param type $input
     * @param type $target_length
     * @return string
     * @author Whiteflash, 2018-10-23
     */

    function shortenStringOnNextSpace($input, $target_length = 125) {


        $shorty = substr($input, 0, strpos($input, " ", $target_length));
        if ((!empty($shorty)) && (strlen($shorty) < strlen($input))) $shorty .= "...";

        return $shorty;
    }

    /**
     *
     * @param type $q
     * @param type $restrictions
     * @return string
     * @author Whiteflash, 2018-10-23
     */

    function convertRestrictions($q, $restrictions) {

       
        if (!empty($restrictions['excludes']['products_id'])) {
            $q .= " AND p.products_id NOT IN(";
            foreach ($restrictions['excludes']['products_id'] as $xcl_id) { $q .= $xcl_id.", "; }
            if (substr($q, -2) == ', ') { $q = substr($q, 0, -2); }
            $q .= ")";
        }
        if (!empty($restrictions['order_by'][0])) $q .= " ORDER BY ".$restrictions['order_by'][0]." ".$restrictions['order_by'][1];
        if (!empty($restrictions['limit'])) $q .= " LIMIT ".$restrictions['limit'];
        if (!empty($restrictions['random'])) {
            if (($order_by_pos = strpos($q, 'ORDER BY')) !== false) $q = substr($q, 0, $order_by_pos);
            $q .= " ORDER BY RAND() ".((!empty($restrictions['random'])) ? ( (strtolower($restrictions['random']) == 'all') ? "" : "LIMIT ".$restrictions['random']."") : "")." ";
        }

        return $q;
    }

    /**
     *
     * @param array $categories_ids
     * @param array $keywords
     * @param string $table_shortcut
     * @param array $table_fields
     * @param string $concatenate, optional (null)
     * @return string keywordsequence
     * @author Whiteflash, 2018-10-23
     */

    function generateKeywordsequence($categories_ids, $keywords, $table_shortcut, $table_fields, $concatenate = null) {

        $keywords_sequence = (!empty($concatenate)) ? " ".$concatenate : "";
        if(is_array($keywords)) {
            $connector = (empty($categories_ids)) ? " " : " OR";
            $keywords_sequence .= $connector." (1!=1";
            foreach($keywords AS $keyword){
                for ($i=0;$i<count($table_fields);$i++) { $keywords_sequence .= " OR (".$table_shortcut.".".$table_fields[$i]." LIKE ('%".$keyword."%'))"; }
            }
            $keywords_sequence .= ")";
        }
        if (strlen($keywords_sequence) < 5) { $keywords_sequence = ''; }
       
        return $keywords_sequence;
    }

    /**
     *
     * @param type $html
     * @return type
     * @author Whiteflash, 2018-10-23
     */

    function parseSubstitutions($html) {

        if (strpos($html, 'substitutions') !== false) {

            if(preg_match_all('/(\[substitutions [^\]]+\])/', $html, $matches)){
                foreach($matches[1] AS $match){

                    $quantifier = '';
                    $regex = '{(.[^{]*?)}';
                    $regex = '(?<={)(.[^{]*?)(?=})';

                    $left_brace = strpos($match, '{');
                    $right_brace = strrpos($match, '}');

                    $captured_raw_jsonstring = substr($match, $left_brace, (($right_brace - $left_brace) + 1));
                    $captured_jsonstring = str_replace('\'', '"', strip_tags($captured_raw_jsonstring));

                    $arguments = json_decode($captured_jsonstring);

                    if ($arguments !== NULL) {                        
                        foreach ($arguments as $search => $argument) {
                            if (is_object($argument)) {
                                $substitution = $limit = null;
                                $validity_range = array();
                                foreach ($argument as $command => $c_argument) {
                                    if ($command == 'substitution') {
                                        $substitution = $c_argument;
                                    } elseif ($command == 'limit') {
                                        $limit = $c_argument;
                                    } elseif ($command == 'validity') {
                                        if (!is_object($c_argument)) {
                                            $validity_range = array($c_argument);
                                        } else {
                                            foreach ($c_argument as $cc_key => $cc_argument) { $validity_range[] = $cc_argument; }
                                        }
                                    } else {
                                        // unknown $command
                                    }
                                }

                                // check if substitution found
                                if ($substitution !== null) {
                                    foreach ($validity_range as $identifyer) {
                                        $elements = array();
                                        if (($identifyer == 'products_name') || ($identifyer == 'name')) {
                                            $tagname = 'div';
                                            $elements = findElements($html, $search, $tagname, array('class', 'nameWr'));
                                        } elseif ($identifyer == 'text') {
                                            $tagname = 'p';
                                            $elements = findElements($html, $search, $tagname, array());
                                        } else {
                                            continue;
                                        }

                                        if(!empty($elements)) {
                                            $count_replaces = 0;
                                            foreach ($elements as $element) {
                                                if (($limit !== null) && ($count_replaces >= $limit)) { continue; }
                                                $new_replace = str_replace($search, $substitution, $element['inner_html']);
                                                $html = str_replace($element['inner_html'], $new_replace, $html);
                                                $count_replaces++;
                                            }
                                        }
                                    }
                                }
                            } else {
                                $html = str_replace($search, $argument, $html);
                            }
                        }
                    }
                    // remove substitutions-instructions from output
                    if (strpos($html, '[substitutions')!==false)
                        $html = preg_replace('/(\[substitutions [^\]]+\])/', '', $html);
                }
            }
        }

        return $html;
    }

    /**
     *
     * @param string $string
     * @param string $search
     * @param string $tagname
     * @param array $identifying, optional
     * @return array | boolean false on error
     * @author Whiteflash, 2018-10-23
     */

    function findElements($string, $search, $tagname, $identifying = array()) {


        $elements = array();
        $security_chars = 10;

        while (($pos = (strpos($string, $tagname, $offset))) !== false) {

            $end_of_tag_pos = strpos($string, '>', $pos);
            $start_of_next_tag_pos = null;

            if (!empty($identifying)) {
                $identifyer_length = strlen($identifying[0]) + strlen($identifying[1]) + $security_chars;
                $controllstring = substr($string, $pos, $identifyer_length);
                if (strpos($controllstring, $identifying[1]) === false) {
                    $start_of_next_tag_pos = strpos($string, '</'.$tagname, $end_of_tag_pos);
                    $start_of_next_tag_pos_sec = strpos($string, '</ '.$tagname, $end_of_tag_pos);
                } else {
                    // nothing? - no, do nothing
                }
            } else {
                $start_of_next_tag_pos = strpos($string, '</'.$tagname, $end_of_tag_pos);
                $start_of_next_tag_pos_sec = strpos($string, '</ '.$tagname, $end_of_tag_pos);
            }

            // check for problems in setup of the html-tags
            if (($start_of_next_tag_pos_sec - $start_of_next_tag_pos) > 1) { return false; }

            // recompare start-pos of next tag
            if ($start_of_next_tag_pos_sec > $start_of_next_tag_pos) $start_of_next_tag_pos = $start_of_next_tag_pos_sec;

            if ($start_of_next_tag_pos !== null) {
                $inner_html = substr($string, ($end_of_tag_pos + 1), (($start_of_next_tag_pos - $end_of_tag_pos) - 1));
                if (strpos($inner_html, $search) !== false) {
                    $elements[] = array('inner_html'=>$inner_html, 'start'=>($end_of_tag_pos + 1), 'end'=>(($start_of_next_tag_pos - $end_of_tag_pos) - 1));
                }
            }
            // upcount offset
            $offset = $pos + 1;
        }

        return $elements;
    }

    /**
     * Function evaluates all restrictions from the given snippet-string.
     * @param string $snippet
     * @return array
     * @author Whiteflash, 2018-10-23
     */

    function setRestrictions($snippet) {
       
        // return already known restrictions
        if (key_exists($snippet, $_SESSION['snippets'])) return $_SESSION['snippets'][$snippet];

        $restrictions = array();

        if(preg_match('/limit\=\'([^\']+)\'/', $snippet, $modding_matches)) $restrictions['limit'] = intval($modding_matches[1]);
        if(preg_match('/order_by\=\'([^\']+)\'/', $snippet, $modding_matches)) $restrictions['order_by'] = (!empty($modding_matches[1]))?explode(':', $modding_matches[1]):null;
        if(preg_match('/random\=\'([^\']+)\'/', $snippet, $modding_matches)) $restrictions['random'] = intval($modding_matches[1]);
        // check order_by-statement
        if (!strstr($restrictions['order_by'][0], '.')) getColumsTable($restrictions['order_by'][0]);
        if (empty($restrictions['order_by'][1])) $restrictions['order_by'][1] = 'asc';

        if(preg_match('/excludes\=\'([^\']+)\'/', $snippet, $modding_matches)) $excludes = (!empty($modding_matches[1]))?explode(':', $modding_matches[1]):null;
        // check excludes-statement
        if (strstr($excludes[0], '.')) unsetColumsTable($excludes[0]);
        $excludes[1]=explode(',', $excludes[1]);
        array_walk($excludes[1], 'trim');
        $restrictions['excludes']=array($excludes[0] => $excludes[1]);
       
        // prepare (and save) restriction
        if (!is_array($_SESSION['snippets'])) $_SESSION['snippets'] = array();
        $_SESSION['snippets'][$snippet] = $restrictions;

        return $restrictions;
    }

    /**
     * Unsets all given table-prefixes of th given $input.
     * @param string $input
     * @author by Whiteflash, 2018-10-23
     */

    function unsetColumnsTable(&$input) {

        $input=preg_replace('#.*\.#', '', $input);
    }

    /**
     * Switches table-prefix for $input (column) or set it to null, if no match given.
     * @param string $input
     * @author Whiteflash, 2018-10-23
     */

    function getColumsTable(&$input) {


        switch ($input) {
            case "products_id": $input='p.'.$input; break;
            case "products_model": $input='p.'.$input; break;
            case "products_status": $input='p.'.$input; break;
            case "products_name": $input='pd.'.$input; break;
            case "products_keywords": $input='pd.'.$input; break;

            default: $input=null;
        }
    }

    /**
     * Function replaces all non-digit characters from incomming string.
     * @param type $input
     * @return string
     */

    function sanitizeIdentifyerstrings($input) {
       
        return preg_replace('/[^\d]*/', '', $input);
    }
    ?>
     

    Code gerade noch einmal neu  gepostet - war immer noch der alte aus einer alten Sicherung  -  :doh:! Jetzt sollte es aber passen.

    Bitte weiter testen und verwenden - bei Fehler wieder ins Forum posten.

    LG Whiteflash

    TnT34

    • Neu im Forum
    • Beiträge: 38
    Re: MODUL: Themenwelten
    Antwort #145 am: 10. November 2018, 14:11:56
    Mooin,

    herzlichen Dank mal wieder!!

    Habe es eingebaut und alles ist gut bis jetzt, tut was es soll.

    Wenn du kurzfristig nichts mehr von mir hörst, habe ich keine Fehler mehr feststellen können.

    Schönes Wochenende gewünscht,

    T

    Timm

    • Fördermitglied
    • Beiträge: 6.192
    Re: MODUL: Themenwelten
    Antwort #146 am: 16. November 2018, 17:16:39
    Moin,

    könnte bitte jemand mal über meine Änderung schauen, ob die so richtig ist? Es geht um den Teil für die Kategoriebilder. Da ich viele auf der Startseite nutze, wurde das von Google bemängelt, dass diese geladen werden, obwohl sie nicht im sichtbaren Bereich sind.

    in /templates/tpl_modified_responsive/module/modules/content_enhancer/listing.html

    Code: XML  [Auswählen]
    {config_load file="$language/lang_$language.conf" section="index"}
    <div class="contentEnhancerClear"></div>
    <div class="subcats cf">
      {foreach item=category from=$categories }
      <div class="subcatlist">
        <div class="subcatlist_inner cf">
          <a href="{$category.CATEGORY_LINK}">
            {if $category.CATEGORY_IMAGE_TRUE != ''}<span class="subcat_image"><span class="subcat_image_inner cf"><img class="unveil" src="/templates/tpl_modified_responsive/css/images/loading.gif" data-src="{$category.CATEGORY_IMAGE}" alt="{$category.CATEGORY_NAME|onlytext}" /><noscript><img src="{$category.CATEGORY_IMAGE}" alt="{$category.CATEGORY_NAME|onlytext}" /></noscript></span></span>{/if}
            <span class="subcat_title"><h2 class="subcat_title_inner">{$category.CATEGORY_NAME}</h2></span>
          </a>
        </div>
      </div>
      {/foreach}
    </div>
    <div class="contentEnhancerClear"></div>

    Und was ich mich noch frage, warum

    Code: XML  [Auswählen]
    src="{$tpl_path}css/images/loading.gif"

    ein Fragezeichen statt des Loading.gif hervorruft. Ist die Variable {$tpl_path} in der Datei nicht aufrufbar? Musste den Pfad ausschreiben und dann kam das Loading.gif.

    Gruß Timm

    karsta.de

    • Experte
    • Beiträge: 3.092
    Re: MODUL: Themenwelten
    Antwort #147 am: 17. November 2018, 11:54:01
    Zitat
    Und was ich mich noch frage, warum ...

    Hallo Timm,

    du musst dafür das Script erweitern (Kommt 2x vor.).
    templates\CURRENT_TEMPLATE\smarty\modifier.contentenhancer.php
    Suche:
    Code: PHP  [Auswählen]
    $smarty->assign('language', $_SESSION["language"]);

    Danach einfügen:
    Code: PHP  [Auswählen]
    $smarty->assign('tpl_path', DIR_WS_BASE.'templates/'.CURRENT_TEMPLATE.'/');

    Dann kennt er auch den Templatepfad.

    BG kgd

    Timm

    • Fördermitglied
    • Beiträge: 6.192
    Re: MODUL: Themenwelten
    Antwort #148 am: 17. November 2018, 22:14:02
    Danke dir - hat natürlich funktioniert.

    Gruß Timm

    InfoCut

    • Neu im Forum
    • Beiträge: 24
    Re: MODUL: Themenwelten
    Antwort #149 am: 21. November 2018, 10:49:22
    Hier wohl noch ein kleiner fehler ?
    [21-11-2018 10:44:41] E_WARNING   : LoggingManager: strpos(): Offset not contained in string in File: /is/htdocs/wp1122303_ZDJUH3JT76/www/Folie2018/templates/bs24_camp/smarty/modifier.contentenhancer.php on Line: 253
    Marktplatz - Eine große Auswahl an neuen und hilfreichen Modulen sowie modernen Templates für die modified eCommerce Shopsoftware
    5 Antworten
    3504 Aufrufe
    12. September 2010, 21:03:02 von Haina
    106 Antworten
    52674 Aufrufe
    06. März 2021, 19:27:04 von awids