1

Topic: Page-aware 'Post' Link

In the process of tweaking my Ochiba installation I became keenly aware of a problem that might crop up by having every category listed in the Post New Image dialog—should I wish to set up categories that users may not wish to see, I would have to somehow affect the display of the categories in this dialog such that some were not visible by default.

As an alternative idea, I thought that it might be more practical to have a 'Post New Image' link on each category's page that was aware of said category and passed it to the dialog when it was clicked, thereby side-stepping the need to list every category. For example, the 'Tabletop Gaming' category's page would have a Post New Image link that would 'know' it was posting to the Tabletop Gaming category.

Would it be terribly difficult to accomplish this, and—if not—where should I start?

Thanks a bunch.

2

Re: Page-aware 'Post' Link

The posting form already does the detection of which category it was called from, actually. It looks at the referer (sic) field and then uses that to automatically select that category.

Given that, I think it would be fairly trivial to do what you describe. In includes/posting.php, at line 370 is a curly brace that closes an if{} block:

   368                if ($row["abbr"] == $referrer) {
   369                    $row["checked"] = 'checked="true"';
   370                }
   371                $tmpl->setCurrentBlock("category");
   372                $tmpl->setVariable(array(
   373                    "category_name"     => FEATURE_MULTIPLE_CATEGORY ? "categories[]" : "categories",
   374                    "category_type"     => FEATURE_MULTIPLE_CATEGORY ? "checkbox" : "radio",
   375                    "category_value"    => $row["abbr"],
   376                    "checked"           => $row["checked"],
   377                    "label"             => $row["category"],
   378                ));
   379                $tmpl->parseCurrentBlock();

Move this line to *after* what is line 379:

   368                if ($row["abbr"] == $referrer) {
   369                    $row["checked"] = 'checked="true"';
   370                    $tmpl->setCurrentBlock("category");
   371                    $tmpl->setVariable(array(
   372                        "category_name"     => FEATURE_MULTIPLE_CATEGORY ? "categories[]" : "categories",
   373                        "category_type"     => FEATURE_MULTIPLE_CATEGORY ? "checkbox" : "radio",
   374                        "category_value"    => $row["abbr"],
   375                        "checked"           => $row["checked"],
   376                        "label"             => $row["category"],
   377                    ));
   378                    $tmpl->parseCurrentBlock();
   379                }

This will make *only* the category the post form was called from appear, and be checked.

That's the basic change. It will fail if the posting form was called from a non-category page (ie, the home, admin, stats, etc pages), so you'll have to make other changes that depend on how you want to handle it. You can also make the category selection not appear at all (the above makes only the relevant one appear, and it is selected) by modifying templates/post.tmpl at line 47 from:

        <input type="{category_type}" name="{category_name}" value="{category_value}" {checked} /> {label}

to

        <input type="{category_type}" name="{category_name}" value="{category_value}" {checked} style="display:none"/>

Or something along those lines.

The other aspect of this is the "hidden" categories appearing in the default menu - you will have to change that to a static list that you manage yourself (ie if you add a new category, you have to add it to the menu manually). This is in templates/site.tmpl, you want to remove the line that says {CATEGORIES} and put in the HTML for your specific list of categories in its place.

I hope this is to your point and enough to get you going!

3

Re: Page-aware 'Post' Link

This is exactly what I was looking for.

Thank you!