Plugin Directory

Changeset 3464464


Ignore:
Timestamp:
02/18/2026 03:33:30 PM (7 weeks ago)
Author:
werbeagenturcommotion
Message:

1.2

  • Compatibility for custom template overrides.
  • Better detection of line breaks in the vehicle description.
  • Fixes a bug if a data value does not exist.
Location:
ad-integration-for-mobile-de-api
Files:
155 added
5 edited

Legend:

Unmodified
Added
Removed
  • ad-integration-for-mobile-de-api/trunk/includes/admin/settings.php

    r3460286 r3464464  
    1919        function() {
    2020            ?>
    21             <input name="mobile_api_username" id="mobile_api_username" type="text" value="<?php echo esc_attr( get_option( 'mobile_api_username' ) ) ?>" class="regular-text">
     21            <input name="mobile_api_username" id="mobile_api_username" type="text" value="<?php echo esc_attr( get_option( 'mobile_api_username' ) ) ?>" placeholder="dlr_" class="regular-text">
    2222            <?php
    2323        },
  • ad-integration-for-mobile-de-api/trunk/includes/cron.php

    r3460286 r3464464  
    1616    $url = 'https://services.mobile.de/search-api/search?page.size=100&modificationTime.min='.$last_sync;
    1717    $json = mobile_api_request( $url );
    18     // echo '<pre>'; var_dump( $json ); echo '</pre>';
    1918
    2019    foreach ( $json->ads AS $ad ) :
     
    2221        $url = 'https://services.mobile.de/search-api/ad/'.$ad->mobileAdId;
    2322        $json = mobile_api_request( $url );
    24         // echo '<pre>'; var_dump( $json ); echo '</pre>';
    2523
    2624        // Check if vehicle already exists
  • ad-integration-for-mobile-de-api/trunk/includes/functions.php

    r3460286 r3464464  
    2626        )
    2727    );
    28     // echo '<pre>'; print_r( $response ); echo '</pre>';
    2928
    3029    if ( is_wp_error( $response ) )
     
    229228
    230229function mobile_api_description_to_html( $raw ) {
    231     // 1) Grundnormalisierung: Entities, newlines
     230
    232231    $text = html_entity_decode( (string) $raw, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
    233232    $text = str_replace( ["\r\n", "\r"], "\n", $text );
    234233
    235     // 2) Backslash-Markierungen vor Sternen/Headlines: \**  oder  \*  -> Newline + marker (macht aus "...\\* Punkt" => "... \n* Punkt" usw.)
    236     $text = preg_replace( '/\\\\+\\*\\*/', "\n**", $text ); // \\**  -> \n**
    237     $text = preg_replace( '/\\\\+\\*/', "\n*", $text );     // \*    -> \n*
    238 
    239     // 3) Single '*' (die nicht Teil von '**' sind) ebenfalls als Listenstarter normalisieren: ersetzt jedes einzelne '*' (nicht Teil eines '**') durch "\n*"
    240     $text = preg_replace( '/(?<!\*)\*(?!\*)/', "\n*", $text );
    241 
    242     // 4) Überschriften **...** -> Platzhalter (sicher vor weiterer Verarbeitung)
    243     $text = preg_replace( '/\*\*(.+?)\*\*/s', "\n%%H3%%$1\n", $text );
    244 
    245     // 5) Optional: entferne verbleibende Backslashes (die keine Sternchen markiert haben) (wir haben die für Sternchen-bezogenen Fälle bereits behandelt)
    246     $text = str_replace( '\\', '', $text );
    247 
    248     // 6) Mehrfache newlines zusammenfassen
    249     $text = preg_replace( "/\n+/", "\n", $text );
    250     $text = trim( $text, "\n" );
    251 
    252     $lines   = explode( "\n", $text );
    253     $html    = '';
     234    // -------------------------
     235    // 1) H3 zuerst sichern
     236    // -------------------------
     237    $text = preg_replace_callback(
     238        '/\*\*(.*?)\*\*/s',
     239        function( $m ) {
     240            return "\n%%H3%%" . trim( $m[1] ) . "\n";
     241        },
     242        $text
     243    );
     244
     245    // -------------------------
     246    // 2) Listenmarker normalisieren
     247    // -------------------------
     248    $text = preg_replace('/\\\\+-/', "\n- ", $text);
     249    $text = preg_replace('/\\\\+\\*/', "\n* ", $text);
     250    $text = preg_replace('/(?<=\S)\s-\s/', "\n- ", $text);
     251
     252    // -------------------------
     253    // 3) KRITISCHE LOGIK:
     254    // Wenn Backslashes nach Satzende kommen → Absatz
     255    // -------------------------
     256    $text = preg_replace('/([.!?])\\\\{2,}/', "$1\n", $text);
     257
     258    // -------------------------
     259    // 4) Restliche Mehrfach-Backslashes → <br>
     260    // -------------------------
     261    $text = preg_replace('/\\\\{2,}/', '%%BR%%', $text);
     262
     263    // Restliche Backslashes entfernen
     264    $text = str_replace('\\', '', $text);
     265
     266    // Aufräumen
     267    $text = preg_replace("/\n+/", "\n", $text);
     268    $text = trim($text);
     269
     270    $lines = explode("\n", $text);
     271
     272    $html = '';
    254273    $in_list = false;
    255     $started = false; // merken: noch kein Hauptblock ausgegeben?
    256274
    257275    foreach ( $lines as $line ) {
    258         $line = trim( $line );
    259         if ( $line === '' )
    260             continue;
    261 
    262         // H3 placeholder?
    263         if ( strpos( $line, '%%H3%%' ) === 0 ) {
    264             if ( $in_list ) {
    265                 $html   .= "</ul>\n";
     276
     277        $line = trim($line);
     278        if ($line === '') continue;
     279
     280        // -------- H3 --------
     281        if (strpos($line, '%%H3%%') === 0) {
     282
     283            if ($in_list) {
     284                $html .= "</ul>\n";
    266285                $in_list = false;
    267286            }
    268             $title = trim( substr( $line, 6 ) );
    269             $html .= '<h3>' . esc_html( $title ) . "</h3>\n";
    270             $started = true;
     287
     288            $title = trim(substr($line, 6));
     289            $title = str_replace('%%BR%%', '<br>', esc_html($title));
     290
     291            $html .= "<h3>{$title}</h3>\n";
    271292            continue;
    272293        }
    273294
    274         // First <p>
    275         if ( !$started ) {
    276             // If line begins with '*' remove it for <p>
    277             $candidate = $line;
    278             if ( isset( $candidate[0] ) && $candidate[0] === '*' )
    279                 $candidate = ltrim( $candidate, "* \t" );
    280 
    281             if ( $candidate !== '' ) {
    282                 $html .= '<p>' . esc_html( $candidate ) . "</p>\n";
    283                 $started = true;
     295        // -------- LISTE --------
     296        if (preg_match('/^[-*]\s*(.+)$/', $line, $m)) {
     297
     298            if (!$in_list) {
     299                $html .= "<ul>\n";
     300                $in_list = true;
    284301            }
     302
     303            $item = str_replace('%%BR%%', '<br>', esc_html(trim($m[1])));
     304            $html .= "<li>{$item}</li>\n";
    285305            continue;
    286306        }
    287307
    288         if ( isset( $line[0] ) && $line[0] === '*' ) {
    289             $items = array_filter( array_map( 'trim', explode( '*', $line ) ) );
    290             if ( ! empty( $items ) ) {
    291                 if ( ! $in_list ) {
    292                     $html   .= "<ul>\n";
    293                     $in_list = true;
    294                 }
    295                 foreach ( $items as $item ) {
    296                     if ( $item === '' ) continue;
    297                     $html .= '<li>'.esc_html( $item )."</li>\n";
    298                 }
    299                 continue;
    300             }
    301         }
    302 
    303         if ( $in_list ) {
    304             $html   .= "</ul>\n";
     308        // -------- NORMALER ABSATZ --------
     309        if ($in_list) {
     310            $html .= "</ul>\n";
    305311            $in_list = false;
    306312        }
    307313
    308         $html .= '<p>'.esc_html( $line )."</p>\n";
     314        $content = str_replace('%%BR%%', '<br>', esc_html($line));
     315        $html .= "<p>{$content}</p>\n";
    309316    }
    310317
    311     if ( $in_list )
     318    if ($in_list)
    312319        $html .= "</ul>\n";
    313320
     
    420427    );
    421428
    422     $return = array_key_exists( $data, $data_descriptions ) ? $data_descriptions[$data] : '';
    423 
    424     return $return;
     429    if ( array_key_exists( $data, $data_descriptions ) )
     430        return $data_descriptions[$data];
     431
     432    return $data;
    425433}
    426434
    427435function mobile_api_translate_data_value( $value ) {
    428     // Documentatation: https://services.mobile.de/docs/search-api.html
     436    // Documentation: https://services.mobile.de/docs/search-api.html
    429437
    430438    $data_values = array(
  • ad-integration-for-mobile-de-api/trunk/mobile-api.php

    r3460286 r3464464  
    1313 * Description: Plugin to integrate the Ad-Integration for mobile.de via the API and show your vehicles on your website.
    1414 * Network: true
    15  * Version: 1.0
     15 * Version: 1.2
    1616 * License: GPLv2 or later
    1717 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1818 * Requires at least: 6.7
    19  * Requires PHP: 7.0
     19 * Requires PHP: 8.0
    2020 * Author: ComMotion
    2121 * Author URI: https://commotion.online/
     
    167167    public function single_vehicle_template( $single ) {
    168168        if ( /* ( !function_exists( 'wp_is_block_theme' ) || !wp_is_block_theme() ) && */ is_singular( 'mobile-api-vehicle' ) ) {
     169            $theme_templates = array(
     170                'single-ad-integration-for-mobile-de-api-vehicle.php', // Default WP naming
     171                'ad-integration-for-mobile-de-api-single-vehicle.php', // Alternate WP naming
     172                'ad-integration-for-mobile-de-api/single-vehicle.php' // optional structural override
     173            );
     174            $theme_template = locate_template( $theme_templates );
     175            if ( !empty( $theme_template ) )
     176                return $theme_template;
     177
    169178            $plugin_template = plugin_dir_path( __FILE__ ).'templates/single-vehicle.php';
    170 
    171179            if ( file_exists( $plugin_template ) )
    172180                return $plugin_template;
  • ad-integration-for-mobile-de-api/trunk/readme.txt

    r3460286 r3464464  
    44Requires at least: 6.7
    55Tested up to: 6.9
    6 Requires PHP: 7.0
    7 Stable tag: 1.1
     6Requires PHP: 8.0
     7Stable tag: 1.2
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    137137== Changelog ==
    138138
     139= 1.2 =
     140* Compatibility for custom template overrides.
     141* Better detection of line breaks in the vehicle description.
     142* Fixes a bug if a data value does not exist.
     143
    139144= 1.1 =
    140145* Post image updates on change.
    141 *
    142146* Minor bugfixes and improvements.
    143147* Compatibility for latest WordPress version.
Note: See TracChangeset for help on using the changeset viewer.