3.0.1 behaviour change - is_album() ?

undagiga

Joined: 2010-11-26
Posts: 693
Posted: Thu, 2011-02-10 11:24

I've written a site-specific hack to the metadescription module. It involves putting this code in the metadescription_theme.php helper file:

	} elseif ($theme->item->is_album()) {
        $tagsItem = ORM::factory("tag")
        ->join("items_tags", "items_tags.tag_id", "tags.id")
        ->join("items", "items.id", "items_tags.item_id", "LEFT")
        ->where("items.parent_id", "=", $theme->item->id)
        ->order_by("tags.id", "ASC")
        ->find_all();

However this code causes problems in 3.0.1, Specifically it caused pages which are not album, photo or tag pages to return a white screen with very little html. I guess the code crashes when trying to output the meta tags.

This would suggest that in 3.0.1 these pages return TRUE to the question "$theme->item->is_album()" and the code then crashes because they can't have tags. At least that's my guess. Why is this?

I have rearranged the code so that it now works, but for future reference I'd like to understand this change in behaviour.

U-G

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Thu, 2011-02-10 16:48

You said you rearranged the code and now it works. Could you post the entire code block of your modification both before and after the change?
____________________________________________
Like Gallery? Like the support? Donate now!

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Thu, 2011-02-10 17:13

If the current page isn't an item (album, photo, video) then the is_album() function doesn't exist, causing the script to crash.

Out of curiosity, what were you trying to change in metadescription? Is it anything that I should incorporate back into the main module?

 
danneh3826
danneh3826's picture

Joined: 2007-08-18
Posts: 290
Posted: Thu, 2011-02-10 19:18

if (is_object($theme->item()) && $theme->item()->is_album()) {}

is_object() will return true if it's an item/album page, and false if it's anything else (reauth page, etc).

should stop it crashing.

Dan

danneh.org :: Gallery3

 
undagiga

Joined: 2010-11-26
Posts: 693
Posted: Fri, 2011-02-11 01:34

@rWatcher - I don't think this change is of general interest. I don't use tags for albums - I regard them as being the tags for all the images in the album, if any. This is how the "About this album" module works. This approach may not work for everyone, but it works for me. So the hack is to include the code from ATA which, if the item is an album, finds all the tags of all its images.

The version of metadescription_theme.php which was working is (my insertion is the first elseif block):

    if ($theme->tag()) {
      // If the current page belongs to a tag, look up
      //   the information for that tag.
      $tagsItem = ORM::factory("tag")
      ->where("id", "=", $theme->tag()->id)
      ->find_all();

	} elseif ($theme->item->is_album()) {
        $tagsItem = ORM::factory("tag")
        ->join("items_tags", "items_tags.tag_id", "tags.id")
        ->join("items", "items.id", "items_tags.item_id", "LEFT")
        ->where("items.parent_id", "=", $theme->item->id)
        ->order_by("tags.id", "ASC")
        ->find_all();

    } elseif ($theme->item()) {
      // If the current page belongs to an item (album, photo, etc.),
      //   look up any tags that have been applied to that item.
      $tagsItem = ORM::factory("tag")
        ->join("items_tags", "tags.id", "items_tags.tag_id")
        ->where("items_tags.item_id", "=", $theme->item->id)
        ->find_all();
		
    } else {
      // If the current page is neither an item nor tag, do nothing.
      return;
    }

but this crashed on pages other than image/album/tag pages. I rearranged the code so that in 3.0.1 the following works:

    if ($theme->tag()) {
      // If the current page belongs to a tag, look up
      //   the information for that tag.
      $tagsItem = ORM::factory("tag")
      ->where("id", "=", $theme->tag()->id)
      ->find_all();

    } elseif ($theme->item()) {
	
      if ($theme->item->is_album()) {
        $tagsItem = ORM::factory("tag")
        ->join("items_tags", "items_tags.tag_id", "tags.id")
        ->join("items", "items.id", "items_tags.item_id", "LEFT")
        ->where("items.parent_id", "=", $theme->item->id)
        ->order_by("tags.id", "ASC")
        ->find_all();
      
      } else {

        // If the current page belongs to an item (album, photo, etc.),
        //   look up any tags that have been applied to that item.
        $tagsItem = ORM::factory("tag")
          ->join("items_tags", "tags.id", "items_tags.tag_id")
          ->where("items_tags.item_id", "=", $theme->item->id)
          ->find_all();
      }
		
    } else {
      // If the current page is neither an item nor tag, do nothing.
      return;
    }

This is not a big deal. There are various ways to get this to work. My point simply is that I am still struggling to learn this php Kohana thing and I thought that I understood how $theme->item->is_album() worked. But then I discover that the first version didn't crash on 3.0 but does on 3.0.1 on "other" pages and I just wondered if something changed or whether my initial understanding was incorrect.

Still learning - that's all.

U-G