ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

New plugins: Will Hunting (math), and Count Entries.

December 07, 2010 4:44pm

Subscribe [7]
  • #1 / Dec 07, 2010 4:44pm

    airways

    154 posts

    Thought I’d post a note that I’ve released two new, free, plugins.

    Will Hunting

    The first plugin is Will Hunting, continuing my play on names of characters from famous movies. This plugin provides a tag that is capable of evaluating relatively complex mathematical formula including stuff like round() and rand(). EE 1.x and 2.0 compatible.

    Example tags:

    12 * 12 = {exp:will_hunting solve="12 * 12"}

    Generating previous and next integers for custom pagination links from a page parameter (in this case retrieved using Super Globals):

    prev_page = {exp:will_hunting solve="{get:page} - 1"”}
    next_page = {exp:will_hunting solve="{get:page} + 1"}

    Count Entries

    Count Entries does what it says on the tin - provides a count of entries. Counts can be filtered by member ID(s) and by weblog name(s). EE 1.x only.

    Example tag, count entries in a weblog named “blog” for member ID 1 :

    {exp:count_entries member_id="1" weblog="blog"}
  • #2 / Dec 10, 2010 5:06pm

    sleven1868

    78 posts

    Can I use this to give me a count of entries that I have narrowed down by a conditional.
    See *** section of code.  I dont know how to get a count of a weblog results thats been narrowed down by a conditional clause. 
    Example:

    {exp:weblog:entries weblog="test" category="4"}
       {if no_results}
           ...no results
       {/if}
       {if x > 0}
            {if y==12}
           ....show entries that match criteria
    
            {if:else}
                ***if entry count from conditional = 0 then show no results text***
            {/if}
        {if:else}
             show entries
        {/if}
  • #3 / Dec 11, 2010 10:41pm

    Bransin

    157 posts

    I can see this coming in handy when splitting entries into multiple columns. I’ve always resorted to PHP parsed as input, but yet that even has it’s limitations and resorting to embed another include.

  • #4 / Dec 11, 2010 11:04pm

    airways

    154 posts

    Bransin,

    If you end up using the plugin, post an example if you can. It’d be great to see how people use it.

    sleven1868,

    I’ve started working on a way to access the variables managed by the core class this plugin uses. Hopefully once I figured out how to do that you can use it for this type of thing. Will probably be a few days at least but I’ll try my best. 😉

  • #5 / Dec 12, 2010 12:10am

    airways

    154 posts

    sleven1868 ,

    Well… I have something pretty close to working, but figuring out how to get conditionals to work correctly in this context is proving somewhat difficult. Here’s what it would look like if I can figure out how to get the conditionals to work correctly. Almost there.

    {exp:will_hunting cache="1"}
      {$count=0}
      start count = {$count}<br>
      {exp:weblog:entries parse="inward"}
          {if no_results}
            Real no results!
          {/if}

          {if x == 3}{!-- x is a custom field on the only weblog in my test instance, none of the entries have x set to 3 --}
            {entry_id} {title}<br>
            {$count=$count+1}
          {/if}
      {/exp:weblog:entries}
    {/exp:will_hunting}

    {exp:will_hunting cache="2"}
      count = {$count}<br>
      {if "{$count}” == “0”}
          Fake no entries!
      {/if}
    {/exp:will_hunting}

    Updated: By the way, it is super annoying to have to do that whole cache=“1”, cache=“2” thing on these tags.

    Because both usages have the same parameters, EE assumes we want the same value for the second usage (in this case both usages have zero parameters, although even if there were some but they didn’t change, the result would be the same). This might be a safe assumption for a lot of plugins and modules but I keep running into this as a frustration.

    Adding arbitrary parameters to the tag calls such as cache=”{entry_id}” if in a loop, or just random numbers like I’ve done here, is the only way to get this caching to stop as far as I can tell. If anyone has a better way I’d like to hear it! 😊

  • #6 / Dec 12, 2010 10:14pm

    narration

    773 posts

    Nice plugin to provide, airways. (had you confused with Good Will Hunting for a moment there 😉 ).

    Your notes on uniquing for cache makes one wonder what will happen inside an EE loop, such as multiple content within exp:entries.

    If it’s a problem, seems an EE-level solution might be auto-incrementing variables. They should probably have a settable initial value, and deliver that first.

    It seems such auto-incrementing variables might be deliverable by some form of add-on, but not in a position to dig into this. Inline PHP might be able to do it as well.

    Regards,
    Clive

  • #7 / Dec 12, 2010 11:15pm

    airways

    154 posts

    narration,

    Yeah the name is a reference to him being a math wizard. 😉

    Far as the caching goes, I’ve found that usually using something like entry_id=”{entry_id}” fixes the problem inside a exp:weblog:entries loop.

    It just occurred to me to try simply setting TMPL->tagparams[‘random’] = rand(); or something similar inside the tag code itself. That should be as good as passing it in the template… will have to try that.

  • #8 / Dec 12, 2010 11:26pm

    airways

    154 posts

    Yep looks like that fixed it:

    global $WILL_HUNTING_CACHE_BUSTER;
    if(!isset($WILL_HUNTING_CACHE_BUSTER))
    {
        $WILL_HUNTING_CACHE_BUSTER = 1;
    } else {
        $WILL_HUNTING_CACHE_BUSTER += 1;
    }
    $TMPL->tagparams['__cache_buster__'] = $WILL_HUNTING_CACHE_BUSTER;
  • #9 / Dec 13, 2010 12:29am

    narration

    773 posts

    Great job, you figured it.

    Knew I was getting too far from what it is to design code 😉

    I have always liked that movie—and there’s no mistaking it’s a tough one, on many levels. Very worth to see.

    Best, airways,
    Clive

  • #10 / Dec 13, 2010 12:17pm

    sleven1868

    78 posts

    Hey Airways,

    First, thanks for taking a look at this.  Can you explain the above code to me?  Here is how I’m reading it.  You are counting the entries inside the narrowing results using the will_hunting tag.  Then you are outputting some message if that count is zero.  That way, if there aren’t any results, nothing will dsiplay from your x==0 conditional but “Fake No Entries!” will display because that count is zero.  Is that right?

    Also, where are you putting the cache busting code? 

    global $WILL_HUNTING_CACHE_BUSTER;
    if(!isset($WILL_HUNTING_CACHE_BUSTER))
    {
        $WILL_HUNTING_CACHE_BUSTER = 1;
    } else {
        $WILL_HUNTING_CACHE_BUSTER += 1;
    }
    $TMPL->tagparams['__cache_buster__'] = $WILL_HUNTING_CACHE_BUSTER;
  • #11 / Dec 13, 2010 12:50pm

    airways

    154 posts

    Hey Airways,

    First, thanks for taking a look at this.  Can you explain the above code to me?  Here is how I’m reading it.  You are counting the entries inside the narrowing results using the will_hunting tag.  Then you are outputting some message if that count is zero.  That way, if there aren’t any results, nothing will dsiplay from your x==0 conditional but “Fake No Entries!” will display because that count is zero.  Is that right?

    Yep that’s exactly right - that is how it would / will / half works.

    The problem I’m running into now is that I have to actually trigger an early parsing of conditionals - otherwise all of the tags inside the results of weblog:entries are parsed and run. If I didn’t parse conditionals early, it would run everything even if there were contionals that should have tripped things out since normally those conditionals wouldn’t run until much later in the parsing process.

    I think the answer will be to be a bit more intelligent with how I’m doing that early conditionals parsing, but it’s taking me a little while to figure out the best way to do this - and I’m back at work today so it will be a couple more days at least before I have enough time to figure it out completely.

    Hey Airways,
    Also, where are you putting the cache busting code? 
    *snip*

    This is a bit of code that goes into the plugin tag code itself. It basically fakes an additional parameter named __cache_buster__ which is assigned an auto incrementing integer to prevent the tag cache from ever caching the results of calls to this tag. It’s a house keeping thing that means instead of doing this:

    {exp:will_hunting cache=“1”}
    ...
    {/exp:will_hunting}
    {exp:will_hunting cache=“2”}
    ...
    {/exp:will_hunting}

    you can just call it as many times as you want without any extra parameters and it will run every time:

    {exp:will_hunting}
    ...
    {/exp:will_hunting}
    {exp:will_hunting}
    ...
    {/exp:will_hunting}
  • #12 / Dec 13, 2010 12:52pm

    Sue Crocker

    26054 posts

    Hey, guys - gentle reminder - support should be handled via Devot-ee.com instead of here..

  • #13 / Dec 13, 2010 12:55pm

    sleven1868

    78 posts

    Thanks for the quick response.  I look forward to seeing your solution.  If I figure out an alternative method this week, I’ll post it here for you.

  • #14 / Dec 13, 2010 1:12pm

    sleven1868

    78 posts

    @Sue.  I opened a post last week but I have not received a repsonse from anyone.  http://ellislab.com/forums/viewthread/175523/  I only came to this thread to see if this plugin might solve my issue.  I don’t know if my original thread is in the wrong place, because it received no responses.  I have it in CodeShare.  Is that the right place for it to be?  There are many ways to solve problems in EE so I would like to see if I could get a response from EE tech support on this issue also. 

    @Airways.  Created thread on will_hunting @ devotee here http://devot-ee.com/add-ons/support/will-hunting/viewthread/293/

  • #15 / Jan 20, 2011 11:18pm

    PixelGrinch

    48 posts

    I had some time to test this on EE 1.7.0 it seems to work fine except for divisions!
    “10/5” returns 10 potentially ignoring everything starting with / ..

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases