Plugin Directory

Changeset 3700366


Ignore:
Timestamp:
09/17/2026 01:17:59 PM (2 months ago)
Author:
ravooka
Message:

Added programmatic option

Location:
ravooka/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ravooka/trunk/modules/ads/package.json

    r3506972 r3700366  
    11{
    22        "name": "ravooka",
    3         "version": "1.0.1",
     3        "version": "1.0.2",
    44        "description": "Unified Ads + PR Publishing plugin for WordPress.",
    55        "author": "Ravooka",
  • ravooka/trunk/modules/ads/ravooka-ads.php

    r3506972 r3700366  
    239239    // 🔹 Prepare blocks
    240240    $blocks = [
     241          // External Banner
     242        'external-banner' => '
     243            <div class="ravooka-external-banner" style="width:100%; padding-bottom:10px;">
     244                <ins
     245                    class="ravookaads"
     246                    data-ad-slot="external-banner">
     247                </ins>
     248            </div>
     249        ',
    241250        'press' => '<ins class="ravookaads" data-ad-client="' . esc_attr($pub_id) . '" data-ad-slot="10492067384"' . ($press_prod ? ' data-ad-prod="' . esc_attr($press_prod) . '"' : '') . '></ins>',
    242251        'carousel' => '<ins class="ravookaads" data-ad-client="' . esc_attr($pub_id) . '" data-ad-slot="54220348490"' . ($carousel_prod ? ' data-ad-prod="' . esc_attr($carousel_prod) . '"' : '') . '></ins>',
    … …  
    261270    $order_array = explode(',', $order_setting);
    262271
    263     // 🔹 Always keep Press-Unifier first
    264     $output = $blocks['press'];
    265 
    266     // 🔹 Append the other blocks according to the order
     272   
     273
     274    // 🔹 External Banner is ALWAYS first
     275    $output = $blocks['external-banner'];
     276
     277    // 🔹 Press-Unifier is ALWAYS second
     278    $output .= $blocks['press'];
     279
     280    // 🔹 Append Carousel / Leaderboard / Composite according to settings
    267281    foreach ($order_array as $key) {
     282
     283        // Prevent external banner and press from being duplicated
     284        if ($key === 'external-banner' || $key === 'press') {
     285            continue;
     286        }
     287
    268288        if (isset($blocks[$key])) {
    269289            $output .= $blocks[$key];
    … …  
    274294
    275295}, 20, 2);
     296
     297/**
     298 * 🔹 Fallback: No Featured Image
     299 *
     300 * If the post has no featured image, WordPress never calls
     301 * post_thumbnail_html(). Therefore inject ONLY the External Banner
     302 * at the beginning of the post content.
     303 */
     304add_filter('the_content', function ($content) {
     305
     306    if (
     307        is_admin() ||
     308        !is_singular('post') ||
     309        !in_the_loop() ||
     310        !is_main_query()
     311    ) {
     312        return $content;
     313    }
     314
     315    $post_id = get_queried_object_id();
     316
     317    // Only run when there is NO featured image.
     318    if (has_post_thumbnail($post_id)) {
     319        return $content;
     320    }
     321
     322    // Prevent duplicate injection.
     323    if (strpos($content, 'ravooka-external-banner') !== false) {
     324        return $content;
     325    }
     326
     327    $pub_id = ravooka_get_pub_id();
     328
     329    $external_banner = '
     330        <div class="ravooka-external-banner"
     331             style="width:100%; padding-bottom:10px;">
     332            <ins
     333                class="ravookaads"
     334                data-ad-client="' . esc_attr($pub_id) . '"
     335                data-ad-slot="external-banner">
     336            </ins>
     337        </div>
     338    ';
     339
     340    // Put External Banner at the beginning of the content.
     341    return $external_banner . $content;
     342
     343}, 19);
    276344
    277345/**
    … …  
    358426}, 10, 2);
    359427
     428
     429/**
     430 * 🔹 Insert VAST Ad After Second Paragraph
     431 */
     432
     433
     434add_filter('the_content', function ($content) {
     435
     436    // Only run on individual posts on the frontend
     437    if (
     438        is_admin() ||
     439        !is_singular('post') ||
     440        !in_the_loop() ||
     441        !is_main_query()
     442    ) {
     443        return $content;
     444    }
     445
     446    // Prevent duplicate injection
     447    if (strpos($content, 'ravooka-inarticle-video') !== false) {
     448        return $content;
     449    }
     450
     451    // Video ad block
     452        $ad = '
     453            <video
     454            id="ravooka-test-video"
     455            controls
     456            playsinline
     457            preload="none"
     458            data-ravooka-video="true"
     459            data-ad-slot="external-vast"
     460            data-content-src="https://asset.ravooka.ai/internal-ad/playlist.m3u8"
     461            ></video>';
     462
     463    // Find all paragraphs
     464    preg_match_all(
     465        '/<p\b[^>]*>.*?<\/p>/is',
     466        $content,
     467        $matches,
     468        PREG_OFFSET_CAPTURE
     469    );
     470
     471    $paragraph_count = count($matches[0]);
     472
     473    // No paragraphs → append VAST ad at the end
     474    if ($paragraph_count === 0) {
     475        return $content . $ad;
     476    }
     477
     478    /*
     479     * 2 or more paragraphs:
     480     * Insert after the second paragraph.
     481     *
     482     * 1 paragraph:
     483     * Insert after the first/last paragraph.
     484     */
     485    $target_index = ($paragraph_count >= 2)
     486        ? 1
     487        : 0;
     488
     489    $paragraph = $matches[0][$target_index][0];
     490    $position = $matches[0][$target_index][1] + strlen($paragraph);
     491
     492    // Insert VAST ad immediately after target paragraph
     493    $content = substr_replace(
     494        $content,
     495        $ad,
     496        $position,
     497        0
     498    );
     499
     500    return $content;
     501
     502}, 20);
     503
    360504/**
    361505 * 🔹 Enqueue Ravooka JS
    362506 */
    363507
     508
    364509add_action('wp_enqueue_scripts', function () {
    365510
    366511    $pub_id = ravooka_get_pub_id();
    367     $script_url = 'https://ads.ravooka.ai/ravooka.min.js?client=' . urlencode($pub_id);
     512
     513    // Change the script version every hour for automatic cache busting.
     514    // $version = gmdate('YmdH');
     515    $version = gmdate('Ymd');
     516
     517    $script_url =
     518        'https://ads.ravooka.ai/ravooka.min.js?client=' .
     519        urlencode($pub_id);
    368520
    369521    wp_register_script(
    … …  
    371523        $script_url,
    372524        [],
    373         '1.0.1',
     525        $version,
    374526        true
    375527    );
    … …  
    378530
    379531    /**
    380      * 🔹 BEFORE script (replaces wp_head inline script)
     532     * BEFORE script
    381533     */
    382534    wp_add_inline_script(
    … …  
    387539
    388540    /**
    389      * 🔹 AFTER script (replaces wp_footer inline script)
     541     * AFTER script
    390542     */
    391543    wp_add_inline_script(
  • ravooka/trunk/ravooka.php

    r3506972 r3700366  
    33 * Plugin Name:       Ravooka Platform
    44 * Description:       Unified Ads + PR Publishing plugin for WordPress.
    5  * Version:           1.0.1
     5 * Version:           1.0.2
    66 * Author:            Ravooka
    77 * Author URI:        https://www.ravooka.ai
  • ravooka/trunk/readme.txt

    r3506972 r3700366  
    44Tags: ads, advertising, monetization, blocks, gutenberg
    55Requires at least: 4.7
    6 Tested up to: 6.9
    7 Stable tag: 1.0.1
     6Tested up to: 7.1
     7Stable tag: 1.0.2
    88Requires PHP: 7.4
    99License: GPL-2.0-or-later
    … …  
    115115* Removed hidden file
    116116
     117= 1.0.2 =
     118* Added programmatic option
     119
    117120== Upgrade Notice ==
    118121
    … …  
    123126* Removed hidden file
    124127
     128= 1.0.2 =
     129* Added programmatic option and ready for 7.1
     130
    125131== Additional Notes ==
    126132
Note: See TracChangeset for help on using the changeset viewer.