We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Inserting OpenAds into copy

Development and Programming

Chris Williams's avatar
Chris Williams
102 posts
17 years ago
Chris Williams's avatar Chris Williams

This is more of a how to php question that is currently stumping me.

I’ve got the Invocation code here:

<?php
  define('MAX_PATH', '/pathto/openads');
  if (@include_once(MAX_PATH . '/www/delivery/alocal.php')) {
    if (!isset($phpAds_context)) {
      $phpAds_context = array();
    }
    $phpAds_raw = view_local('', 1, 0, 0, '', '', '0', $phpAds_context);
    echo $phpAds_raw['html'];
  }
?>

and I’ve got a plugin I’ve written for my site that can insert html after the third paragraph:

class Formatstory {
    var $return_data;
    function Formatstorybeta($str = '')
    {    
        global $TMPL;
        if ($str == '')
        {
            $str = $TMPL->tagdata;
        }
        $str = preg_replace('/', $str, 1);
        $save = explode('', $str);
        $count = 1;
        foreach ($save as $a){
            if ($count == 3){
                (clever block ad here)
            }
            $rtn .= $a . '';
            $count = $count + 1;
        }
        $this->return_data = $rtn;
    }
}

How do I get the code for the ad into this string that I’m building? Thoughts?

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

Chris,

Is there a reason you don’t want to split your entries into two seperate custom fields?

Seems like it would be easier to simply do:

{custom_field_1}
AD CODE HERE
{custom_field_2}

If thats not a solution you can’t pass a multi line piece of code to a plugin using a parameter. So you have to have the invocation code either already in your plugin or else between the plugin tags in the template.

If you put it between the plugin tags in the template you could use a tag pair within the plugin tags:

{ad_bloc}INVOCATION CODE HERE{/ad_bloc}

And have your plugin remove it from the template and then replace it in the correct spot after paragraph 3 like you already have worked out.

Jamie

       
Chris Williams's avatar
Chris Williams
102 posts
17 years ago
Chris Williams's avatar Chris Williams

I wouldn’t want to do that, because I would have to edit all my previous entries to fit that format.

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

Well if working with lots of existing entries then you are left with the two choices I gave you. Both should work depending on your needs. If the invocation code will be changing regularly using tag pairs will be your best bet I would imagine.

Jamie

       
Chris Williams's avatar
Chris Williams
102 posts
17 years ago
Chris Williams's avatar Chris Williams

I’ve got a bit of a solution already (its been a while since I started this thread) using a plug-in and this bit of code:

$save = explode('', $str);

That way, I can take a given iteration and insert by desired code and return it.

I’m not a PHP developer by any means, so while I think I have it working correctly on the EE side, OpenAds is now wonky when I call it. and any other ad on the same page.

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

Glad you have something worked out.

OpenAds is an adventure. I have a client that uses it and we constantly run into issues. Its really too bad nothing else in its price range comes close as I’ve found it incredibly frustrating.

Jamie

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.