2010/1/5 ideamenDave <[email protected]>:
> On Dec 23 2009, 6:54 pm, "Michael C. Harris" <[email protected]> 
> wrote:
> Hello again, and superThanks for the info, I believe you're getting at
> the crux of what it is that I just don't get about PHP/Habari, and now
> I'm as lost as ever :P

Ooops, sorry :)

>> Depending on the format of your time, you might be able to use a database
>> function to force the sorting to be correct[1]. For example, as is done on 
>> [2],
>> you can use ABS to force a string into a number.
>
> I like this idea and have yet to try it, but it will surely be nicer
> on the workload then having to re-save all of the show posts on the
> official site (there are quite a few on the official site, and we've
> got a 3 week tour coming up that I have yet to add to the calendar -
> perhaps we'll be playing in a town near you!).
>
>> The first if statement bothers me a bit though. You have a custom content 
>> type,
>> right ? And Date, Venue etc are fields that you've added to the publish page
>> for that content type ? That's what I'd do.
>
> Yep.  Basically just added a few fields to a pre-existing content type
> plugin:

[snip code that looks fine]

> But I just can't wrap my head around the important bit:
>> Then I'd create a rewrite rule for the url you want, and in the action
>> function just run that query. Then when someone visits the URL for your
>> rewrite rule, only those posts will be displayed.
>
> I have no frame in my head to grasp the concept of "the url you want",
> and I believe I've got some studying to do to make this make sense.  I
> also have been looking at documentation on the rewrite rules from the
> sidelines and not touching them with a 10 foot pole for fear of
> puncturing them and getting PHP goo all over myself.  I simply don't
> understand what a rewrite rule is.

Habari's rewrite rules map requests to URLs, such as
http://www.iloveideamen.com/user/login, to code in Habari (or a plugin) to deal
with the request.

(As an aside, these shouldn't be confused with the web server's rewrite rules,
which basically funnel everything that isn't an existing file or directory to
Habari's index.php.)

The first function I posted, filter_rewrite_rules(), takes the existing rewrite
rules and adds a new one called 'display_shows'. This says if the requested URL
matches the regular expression pattern in parse_regex, send execution off to
the UserThemeHandler with the action 'display_shows'.

The second function, filter_theme_act_display_shows(), filters requests made to
that action. Commented this time to explain what's going on.

public function filter_theme_act_display_shows( $handled, $theme )
{
  // Try to use the show.multiple.php template, and if that's not available,
  // use multiple.php
  $paramarray['fallback']= array(
    '{$type}.multiple',
    'multiple',
  );

  // Retrieve future shows.
  $shows = Posts::get(array(
    'content_type' => Post::type('ideamen_show'),
    'status' => Post::status('published'),
    'after' => strtotime('yesterday'),
    'has:info' => 'eventtimestamp',
    'orderby' => 'info_eventtimestamp_value ASC',
    'nolimit' => TRUE
  ));

  // Add the shows to the theme. Access this in your template with $shows.
  $theme->shows = $shows;

  $theme->act_display( $paramarray );
  return TRUE;

}

> Long story short, I don't know where to put the code you posted.
> I combed through it to make sure there weren't any semantic errors (I
> wouldn't know if it was syntactically correct) and dropped it into my plugin
> file.

Sorry I didn't make that clear. Yes, it belongs in your plugin file.

> I then replaced the previously working snippet of code in the home.php
> file with:
>        <?php
>        if ( $request->display_entries_by_tag && $tag == 'shows' &&
>        !$request->display_home ) {
>                foreach ( $shows as $post ) {
>                        $theme->content($post);
>                }
>        }
>        ?>

Make a copy of home.php and call it shows.multiple.php. Then you can remove the
if statement. The page can be accessed at http://www.iloveideamen.com/shows
instead of the tag page. Now you don't have to tag shows as shows, just
making a new post of type show is enough.

Note, I still haven't tested any of this. So there might still be errors in it.
Likewise, someone else may have a better way of doing it.

> Deactivated and reactivated the plugin (I'm pretty sure that's
> recommended when making changes).
> Didn't work.  I forgot to copy the error message, but I believe it was
> the same as my next attempt.  Ripped it out of the plugin file and
> plopped it into the theme.php file.  Getting:
> --Notice: Undefined variable: shows in user/themes/ideaTheme/home.php
> line 13
> --Warning: Invalid argument supplied for foreach() in user/themes/
> ideaTheme/home.php line 13

Yep, that's because the $shows variable has only been added to the theme for
requests to http://www.iloveideamen.com/shows.

> I then opened the rewriterules.php file and stared at it blankly for a
> while :)
> That was as far as I took it.  I'm betting that your code is fine, and
> my problem is that I just don't know how to use it properly.  One of
> my main hurdles in this area is that I'm still using the tag to get to
> the shows 'page'.  My link to Shows in the menu reads:
> <a href="<?php Site::out_url( 'habari' ); ?>/tag/shows"> <?php _e
> ('Upcoming Shows'); ?></a>
>
> I think what I should be using is a link that will take you to a page
> that displays only posts of the ideamen_shows content type, but I have
> no idea how to create such a link.  This must be related to the "when
> someone visits the URL for your rewrite rule" statement that is
> throwing me for a loop.

You can construct a URL for any rewrite rule in the system with url::get() to
retrieve and url::out() to echo. So you could do this to construct the URL to
the rewrite rule created in your plugin:

<a href="<?php url::out('display_shows'); ?>"> <?php 'Upcoming Shows'; ?></a>

You don't need the _e() call, because that's only used if you're running a
translated site.

-- 
Michael C. Harris, School of CS&IT, RMIT University
http://twofishcreative.com/michael/blog
IRC: michaeltwofish #habari

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/habari-users

Reply via email to