About this topic

  • Posted by Savage702 7 months ago. There are 17 posts. The latest reply is from scottk1216.
  1. Postie is working perfectly... exactly what I wanted compared to all these other Google Reader integrations/iterations.

    What I'd like to do though is remove some extra stuff added when I send an article form Reader, it adds a blue box at the bottom of each post reading:

    Things you can do from here:
    - Subscribe to <site name>
    - Get started using google reader blah blah blah

    When you send the article, you don't actually see any of this, so using :start :end etc doesn't help. I need a way to filter this out.

    Any ideas?

  2. Ok, so I think I'm going to have to use the filterpostie.php, although I'm not sure where/how to extract or remove from the post.

    At the bottom of each post, there is the following HTML... there should be an easy way to remove that, no? Of course, the links change depending on the article... but essentially this is it.

    <div style="padding: 4px; background-color: #c3d9ff;">
    <h3 style="margin:0px 3px;font-family:sans-serif">Things you can do from here:</h3>
    <ul style="font-family:sans-serif">
    	<li><a href="http://www.google.com/reader/view/feed%2Fhttp%3A%2F%2Ffeeds.gawker.com%2Flifehacker%2Ffull?source=email">Subscribe to Lifehacker</a> using <strong>Google Reader</strong></li>
    	<li><a href="http://www.google.com/reader/?source=email">Get started using Google Reader</a> to easily keep up with <strong>all your favorite sites</strong></li>
    </ul>
    </div>
    <div style="margin: 0px 1px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"></div>
    <div style="margin: 0px 2px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"></div>
  3. this should do the trick

    <?php
    function strip_reader($post) {
      $text = $post->post_content;
      $text = preg_replace('/<div style="padding: 4px; background-color: #c3d9ff;">.*?<\/div>/s', '', $text);
      $text = preg_replace('/<div style="margin: 0px [12]px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"><\/div>/', '', $text);
      return $text;
    }
    add_filter('postie_post', 'strip_reader');
    ?>
  4. Oh wow... Ok, I'll give that a shot Monday morning. That kinda makes sense to me, I think... I can't wait to try it. Thank you, will let you know.

    Mark

  5. Ok, so I put that code in the postieFilter, activated it, and tested... it errored out. After pulling the email, it displays the email like normal, then underneath it shows the following:

    the subject is My Subject Here, right after calling GetSubject
    
    Post Author:
    Date:
    
    Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/wp-content/plugins/postie/postie-functions.php on line 1974
    Ping Status:
    Comment Status:
    Subject:
    Postname:
    Post Id:
    Posted content:

    It seems to be hanging up somehow in the report from Postie-functions.php. Here is the line it keeps referencing:

    foreach($details["post_category"] as $category) {

    I have tried removing both $text = preg_replace lines of the filter one at a time to see if the issue would persist, it did with either one still there, or even with both removed.

  6. Sorry about that. Let's try again:

    function strip_reader($post) {
      $text = $post->post_content;
      $text = preg_replace('/<div style="padding: 4px; background-color: #c3d9ff;">.*?<\/div>/s', '', $text);
      $text = preg_replace('/<div style="margin: 0px [12]px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"><\/div>/', '', $text);
    $post->post_content = $text;
    return($post);
    }
  7. Ok, the errors have stopped now... it processes the email and everything, but it doesn't appear to be removing/doing anything.

    I have checked to make sure the filter is active, and it is. I even made some changes to see if it would just change some text, but I couldn't get it to.

    Is this processing the html that's from the email, or the final html that's in the post? Doesn't postie &/or wordpress re-process some html?

  8. Ok, this appears to be all the Reader stuff that appears raw, in the email:

    <div style="margin: 0px 2px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"> </div>
    <div style="margin: 0px 1px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"> </div>
    <div style="padding: 4px; background-color: #c3d9ff;"><h3 style="margin:0px 3px;font-family:sans-serif">Sent to you by MyUsername via Google Reader:</h3></div>
    <div style="margin: 0px 1px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"> </div>
    <div style="margin: 0px 2px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"> </div>
    
    <div style="margin: 0px 2px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"> </div>
    <div style="margin: 0px 1px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"> </div>
    <div style="padding: 4px; background-color: #c3d9ff;"><h3 style="margin:0px 3px;font-family:sans-serif">Things you can do from here:</h3>
    <ul style="font-family:sans-serif"><li><a href="http://www.google.com/reader/view/feed%2Fhttp%3A%2F%2Fwww.geekologie.com%2Fatom.xml?source=email">Subscribe to Geekologie - Gadgets, Gizmos, and Awesome</a> using <b>Google Reader</b></li>
    <li><a href="http://www.google.com/reader/?source=email">Get started using Google Reader</a> to easily keep up with <b>all your favorite sites</b></li></ul></div>
    <div style="margin: 0px 1px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"> </div>
    <div style="margin: 0px 2px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"> </div>

    Now a lot of that is repeating the same old same old... I thought your line here would remove 8 lines of that:

    $text = preg_replace('/<div style="margin: 0px [12]px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"><\/div>/', '', $text);

    Although I'm seeing "None Breaking Spaces" in there now where they weren't before (or maybe I was looking at it wrong). I tried adding that, or just a space, and no luck.

    I tried your other line on it's own too (well, not "on it's own" but the only replace function), and it didn't remove/change anything either:

    $text = preg_replace('/<div style="padding: 4px; background-color: #c3d9ff;">.*?<\/div>/s', '', $text);

    Thanks so much for all your help.

  9. You might have to fool around a bit more with the regular expressions to get the desired effect. To test that the filter is working at all, try this:

    function strip_reader($post) {
      $post->post_content = 'foo';
      return($post);
    }
  10. What was that supposed to do? If I'm reading it right, it was supposed to replace the entire emailed article with simply "foo"? If that's the case, it didn't do anything. The email went through and posted as normal.

    filterPostie.php is active in plugins, and it saved fine.

    Is there something I might be missing in Postie Options that would effect the filter?

  11. do you have the line

    add_filter('postie_post', 'strip_reader');

    in filterPostie.php?

    If so, maybe try reactivating?

  12. Wow, so how about this. People that don't know what they're doing (me) should know when to leave well enough alone. :-p

    I wasn't closing out the script properly, and it wasn't erroring when I edited the script. I didn't have
    ?>
    at the end. :-( (I am pretty embarrassed about that!!)

    Ok, so I've started from scratch, and the last fixed script and the test script are both erroring out on the same line:

    From your last update:
    $post->post_content = $text;

    From the test script:
    $post->post_content = 'foo';

    The error message received when I run the script is:
    Warning: Attempt to assign property of non-object in /home/mysite/public_html/wp-content/plugins/postie/filterPostie.php on line 41

  13. I'm not sure if I'm getting ahead of myself here... but I looked up the error I was getting, and found this:

    http://bugs.php.net/bug.php?id=44660

    The server I'm hosted on is using PHP version 5.2.8

  14. Sorry for leading you astray. $post is actually an array, not an object. One more time:

    function strip_reader($post) {
      $text = $post['post_content'];
      $text = preg_replace('/<div style="padding: 4px; background-color: #c3d9ff;">.*?<\/div>/s', '', $text);
      $text = preg_replace('/<div style="margin: 0px [12]px; padding-top: 1px;    background-color: #c3d9ff; font-size: 1px !important;    line-height: 0px !important;"><\/div>/', '', $text);
    $post['post_content'] = $text;
    return($post);
    }
  15. Hey, thanks! That did it... although it didn't like the [12]px, I just broke that down to two separate lines and it works.

    Do you have a good site/reference with examples for regex stuff? Trying to search for suggestions/help is getting difficult. I'm finding articles from some sites that have all the bookmark/email/del-ic-ous/Digg This/etc etc stuff at the bottom, that seems to break the page formatting/template.

    Thing is they're so complex, I can't seem to find an easy way to kinda get *.* like you did with the other stuff.

    <hr><p><small> <a href="http://www.inhabitat.com/2010/01/04/burj-dubai-opens/">Permalink</a> |
    Add to <a href="http://del.icio.us/post?url=http://www.inhabitat.com/2010/01/04/burj-dubai-opens/&title=Tallest%20Building%20in%20the%20World,%20The%20Burj%20Dubai,%20Opens">del.icio.us</a> | <a href="http://digg.com/submit?url=http://www.inhabitat.com/2010/01/04/burj-dubai-opens/&title=Tallest%20Building%20in%20the%20World,%20The%20Burj%20Dubai,%20Opens">digg</a>  Post tags: <a href="http://www.inhabitat.com/tag/burj-dubai/" rel="tag">burj dubai</a>, <a href="http://www.inhabitat.com/tag/dubai/" rel="tag">dubai</a>, <a href="http://www.inhabitat.com/tag/skyscraper/" rel="tag">skyscraper</a>, <a href="http://www.inhabitat.com/tag/worlds-tallest-building/" rel="tag">world's tallest building</a> </small></p> <div>
    <a href="http://feeds.feedburner.com/~ff/Inhabitat?a=dgashmrJkwY:_wTWnKSRVuw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Inhabitat?d=yIl2AUoC8zA" border="0"></a> <a href="http://feeds.feedburner.com/~ff/Inhabitat?a=dgashmrJkwY:_wTWnKSRVuw:DLYy-l-dIDg"><img src="http://feeds.feedburner.com/~ff/Inhabitat?d=DLYy-l-dIDg" border="0"></a></div>

    In the example above for instance, for some reason "SMALL" doesn't seem to close out in the article. So it messes up the formatting of all articles after it, and adjusts some DIV tags because apparently there ends up being one too many for some reason. Very odd.

  16. In the example above, <small> does close, but it is over 2 lines. By default, . does not match a new line. You want to use the s flag to treat the whole string as a single line.

    <?php
    $text='<hr><p><small> <a href="http://www.inhabitat.com/2010/01/04/burj-dubai-opens/">Permalink</a> |
    Add to <a href="http://del.icio.us/post?url=http://www.inhabitat.com/2010/01/04/burj-dubai-opens/&title=Tallest%20Building%20in%20the%20World,%20The%20Burj%20Dubai,%20Opens">del.icio.us</a> | <a href="http://digg.com/submit?url=http://www.inhabitat.com/2010/01/04/burj-dubai-opens/&title=Tallest%20Building%20in%20the%20World,%20The%20Burj%20Dubai,%20Opens">digg</a>  Post tags: <a href="http://www.inhabitat.com/tag/burj-dubai/" rel="tag">burj dubai</a>, <a href="http://www.inhabitat.com/tag/dubai/" rel="tag">dubai</a>, <a href="http://www.inhabitat.com/tag/skyscraper/" rel="tag">skyscraper</a>, <a href="http://www.inhabitat.com/tag/worlds-tallest-building/" rel="tag">world\'s tallest building</a> </small></p> <div>
    <a href="http://feeds.feedburner.com/~ff/Inhabitat?a=dgashmrJkwY:_wTWnKSRVuw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Inhabitat?d=yIl2AUoC8zA" border="0"></a> <a href="http://feeds.feedburner.com/~ff/Inhabitat?a=dgashmrJkwY:_wTWnKSRVuw:DLYy-l-dIDg"><img src="http://feeds.feedburner.com/~ff/Inhabitat?d=DLYy-l-dIDg" border="0"></a></div>';
    $new = preg_replace('/<small>.*<\/small>/s', 'foo', $text);
    echo "newtext = $new\n";
    ?>

    As far as regex tutorials, I would recommend one of the Perl books by OReilly. Both php and python use perl-compatible regular expressions.

  17. I'm attempting to accomplish the same thing but this code doesn't seem to be working for me. Is it still working for you if not is something else? Any help would be appreciated.

RSS feed for this topic

Have you read the FAQ?
Have you tried the latest development version (at the bottom)?

Reply

You must log in to post.