コード例 #1
0
function adinj_get_random_ad_paragraph($content, $original_paragraph_positions, $opname, $default, &$debug)
{
    $ops = adinj_options();
    $debug_on = adinj_debug_on();
    $mode = $ops['random_ads_' . $opname . '_mode'];
    $paracount = count($original_paragraph_positions);
    $rawlength = strlen($content);
    $paragraph = -1;
    if ($mode == 'anywhere') {
        $paragraph = $default;
    } else {
        if ($mode == 'at' || $mode == 'after') {
            $position = $ops['random_ads_' . $opname . '_at'];
            $unit = $ops['random_ads_' . $opname . '_unit'];
            $direction = $ops['random_ads_' . $opname . '_direction'];
            if ($unit == 'character') {
                $adjust = $direction == 'fromend' ? 0 : 1;
                $paragraph = adinj_get_paragraph_from_position($content, $position, $original_paragraph_positions, $adjust, $direction);
                if ($opname == 'end' && $direction == 'fromstart' && $paragraph == -1) {
                    $paragraph = $paracount;
                }
            } else {
                // paragraph is same as value in UI
                $paragraph = $position;
                if ($direction == 'fromend') {
                    $paragraph = $paracount - $paragraph;
                }
            }
        } else {
            if ($mode == 'middleback') {
                $pos = round($rawlength / 2, 0);
                $paragraph = adinj_get_paragraph_from_position($content, $pos, $original_paragraph_positions, 0);
            } else {
                if ($mode == 'middleforward') {
                    $pos = round($rawlength / 2, 0);
                    $paragraph = adinj_get_paragraph_from_position($content, $pos, $original_paragraph_positions, 1);
                } else {
                    if ($mode == 'middleparaback') {
                        $val = $paracount % 2 == 0 ? 0 : 0.5;
                        $paragraph = intval(round(($paracount - $val) / 2, 0));
                        // todo test with 0 and 1 paragraphs
                    } else {
                        if ($mode == 'middleparaforward') {
                            $paragraph = intval(round($paracount / 2, 0));
                        } else {
                            if ($mode == 'twothirds') {
                                $pos = round($rawlength * 0.66, 0);
                                $paragraph = adinj_get_paragraph_from_position($content, $pos, $original_paragraph_positions, 1);
                            }
                        }
                    }
                }
            }
        }
    }
    if ($paragraph == -1) {
        if ($debug_on) {
            $debug .= "\nParagraph not found - mode:{$randomaftermode} op:{$opname}";
        }
    }
    return $paragraph;
}
コード例 #2
0
function adinj_get_random_ad_start_end_paragraph($content, $original_paragraph_positions, &$start, &$end, &$debug)
{
    $ops = adinj_options();
    $debug_on = adinj_debug_on();
    $paracount = count($original_paragraph_positions);
    if ($paracount == 0) {
        $start = -1;
        $end = -1;
        return;
    }
    // initialise to 'anywhere' max range
    $start = 1;
    $end = $paracount;
    // todo docs: should include these tags on same line as paragraph or can affect paragraph count
    $tagposition = stripos($content, '<!--adstart-->');
    if ($tagposition === false) {
        $tagposition = stripos($content, '<!--adsensestart-->');
    }
    if ($tagposition === false) {
        $start = adinj_get_random_ad_paragraph($content, $original_paragraph_positions, 'start', $start, $debug);
    } else {
        $start = adinj_get_paragraph_from_position($content, $tagposition, $original_paragraph_positions, 1);
        if ($debug_on) {
            $debug .= "\nFound hardcoded start tag. Starting ads at paragraph {$start}";
        }
    }
    $tagposition = stripos($content, '<!--adend-->');
    if ($tagposition === false) {
        $tagposition = stripos($content, '<!--adsenseend-->');
    }
    if ($tagposition === false) {
        $end = adinj_get_random_ad_paragraph($content, $original_paragraph_positions, 'end', $end, $debug);
    } else {
        $end = adinj_get_paragraph_from_position($content, $tagposition, $original_paragraph_positions, 0);
        if ($debug_on) {
            $debug .= "\nFound hardcoded end tag. Ending ads at paragraph {$end}";
        }
    }
}