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
I was pretty sure that I ought to get the sorting done at a level
higher then the home.php file, but I'm missing some basic
understanding of how it all works together.

> 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:

        public function action_form_publish($form, $post, $context)
        {
          // only edit the form if it's an ideamen_show
                if ($form->content_type->value == Post::type('ideamen_show')) {

          // add eventdate text field
      $form->insert('tags', 'text', 'eventdate', 'null:null', _t
('Event Date'), 'admincontrol_textArea');
      $form->eventdate->value = $post->info->eventdate;
      $form->eventdate->template = 'admincontrol_text';

      // add venue text field
      $form->insert('tags', 'text', 'venue', 'null:null', _t('Venue'),
'admincontrol_textArea');
      $form->venue->value = $post->info->venue;
      $form->venue->template = 'admincontrol_text';

      // add adress text field
      $form->insert('tags', 'text', 'address', 'null:null', _t('Venue
Address'), 'admincontrol_textArea');
      $form->address->value = $post->info->address;
      $form->address->template = 'admincontrol_text';

      // add with text field
      $form->insert('tags', 'text', 'with', 'null:null', _t('With'),
'admincontrol_textArea');
      $form->with->value = $post->info->with;
      $form->with->template = 'admincontrol_text';

                }
        }

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.

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.  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);
                }
        }
        ?>
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

Where line 13 is the
foreach ( $shows as $post ) {

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.

Thanks again for the help, and I hope that solving this will help
others understand how this stuff works!
--D.G. Solar


On Dec 23 2009, 6:54 pm, "Michael C. Harris"
<[email protected]> wrote:
> 2009/12/22 ideamenDave <[email protected]>:
>
>
>
> > ... It works!
>
> Fantastic!
>
>
>
> > Here's the final snippet that does the trick in the home.php file:
> > <?php
> > if ( $request->display_entries_by_tag && $tag == 'shows' &&
> > !$request->display_home ) {
> >   $theme->display ( 'showtop' );
> >   $eventposts = Posts::get(array(
> >   'content_type' => Post::type('ideamen_show'),
> >   'status' => Post::status('published'),
> >   'has:info' => 'eventtimestamp',
> >   'orderby' => 'info_eventtimestamp_value ASC',
> >   'nolimit' => TRUE
> >   ));
> >   foreach ( $eventposts as $post ) {
> >     if ( $post->info->eventtimestamp > strtotime('yesterday') ) {
> >       include( 'ideamen_show.php' );
> >     }
> >   }
> > }
> > ?>
>
> > Note that there is a new field 'eventtimestamp'.  I had to add another
> > field into the content type plugin to convert the event date string
> > into a timestamp for proper sorting (it got them mixed up sorting by
> > the string value).
>
> 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 tried the "$theme->content($post);" method instead of the include,
> > and it filled the page with only the latest post.  I likely
> > implemented it wrong.  The include does the trick though.
>
> $theme->content($post); will only work inside the loop. But yeah, it's 
> probably
> not something to worry about right now if it's working.
>
> > Also note the "if ( $post->info->eventtimestamp > strtotime
> > ('yesterday') )" that gets it to display only events that happened
> > after yesterday.  I'm all giddy now.
>
> That really should be done in the query, so you can eliminate that. This 
> should
> do the trick, properly integrated with the query above.
>
> Posts::get(array('after' => strtotime('yesterday'));
>
> I've now added that to the wiki page. (Anyone else who knows this stuff should
> feel free to fill in some of the other sections!)
>
> 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. 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.
>
> Untested, and others may have better ways:
>
> public function filter_rewrite_rules( $rules )
> {
>   $rules[] = new RewriteRule(array(
>     'name' => 'display_shows',
>     'parse_regex' => '%^shows(?:/page/(?P<page>\d+))?/?$%',
>     'build_str' => 'shows(/page/{$page})',
>     'handler' => 'UserThemeHandler',
>     'action' => 'display_shows',
>     'priority' => 2,
>     'rule_class' => RewriteRule::RULE_PLUGIN,
>     'is_active' => 1,
>     'description' => 'Display shows' )
>   );
>   return $rules;
>
> }
>
> /**
>  * @todo Can't remember if paging will be handled automatically
>  */
> public function filter_theme_act_display_shows( $handled, $theme )
> {
>   $paramarray['fallback']= array(
>     '{$type}.multiple',
>     'multiple',
>   );
>
>   $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
>   ));
>
>   $theme->shows = $shows;
>
>   $theme->act_display( $paramarray );
>   return TRUE;
>
> }
> > Now I suppose I'll have to update my live version to 0.7 and go for
> > the gold.  My next project is figuring out how to display custom
> > headers for each user on posts (could be as simple as loading a
> > different style class based on $post->author->username, but my efforts
> > in that direction didn't quite work).
>
> We'll come back to that later :)
>
> > p.s. Are we getting a shiny new official 0.7 release for Christmas
> > this year?
>
> Sadly, no.
>
> [1] See here for MySQL functions. Numeric or date functions may help you.
> [2]http://wiki.habariproject.org/en/Dev:Retrieving_Posts#Ordering_by_pos...
>
> --
> Michael C. Harris, School of CS&IT, RMIT 
> Universityhttp://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