smarty $view no longer available

Discussion corner for Developers of Serendipity.
User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

smarty $view no longer available

Post by Don Chambers » Thu Jun 12, 2008 7:52 pm

I just noticed that logic I use in a template to determine the value of $view was no longer working.... when I set {debug} in entries.tpl, $view isn't listed as one of the smarty variables. This is with the latest 1.3 branch.

Doesn't appear to be my template either - also tried it with carl_contest - same thing - no $view.

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers » Fri Jun 13, 2008 4:14 am

Found it.... the microformats plugin seems to be the problem. Its genpage?

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Fri Jun 13, 2008 10:19 am

Hi!

You mean when you disable microformats, $view gets in again?

I don't see anything in the 'genpage' hook of microformats that would even touch this variable. You are using the recent version in spartacus, not some other version?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers » Fri Jun 13, 2008 4:56 pm

Yes Garvin - when I deactivate the microformats plugin - which I had recently installed out of curiosity - $view is again available.

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Fri Jun 13, 2008 7:03 pm

Hi!

Hm, can you edit the plugin and insert a simple "return true;" just as the first line after the "case 'genpage':" case? This could show whether the genpage hook is responsible,or another one.

I'll be offline for the weekend, so I'll have to get backto you next week.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

mattsches
Regular
Posts: 440
Joined: Sat Nov 05, 2005 10:35 pm
Location: Wiesbaden, Germany
Contact:

Post by mattsches » Sun Jun 15, 2008 2:39 pm

Don, let me know it it's got anything to do with the microformats plugin. I have begun to rewrite the plugin a couple of months ago, but never found the motivation to finish it :?

Now, after I received a copy of Garvin's excellent S9y book, I am determined to delve into the depths of my plugin again :wink: Right now, however, I'm busy tweaking some options in my blog that I've just found out exist. S9y book FTW!!

- Mattsches

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers » Sun Jun 15, 2008 9:51 pm

garvinhicking wrote:Hi!

Hm, can you edit the plugin and insert a simple "return true;" just as the first line after the "case 'genpage':" case? This could show whether the genpage hook is responsible,or another one.

I'll be offline for the weekend, so I'll have to get backto you next week.

Regards,
Garvin


Garvin, at line 199 I added return true, and $view is again available.

Code: Select all

                case 'genpage':
                    return true;

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Mon Jun 16, 2008 10:11 am

Hi!

And if you move that return true after the line where serendipity_smarty_init() is called? Maybe that function call somehow resets the view...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers » Mon Jun 16, 2008 4:21 pm

That is correct Garvin. If located after the smarty_init(), there is no $view.

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Mon Jun 16, 2008 4:42 pm

Hi!

That is too strange, because the serendipity_smarty_init() call does not tamper with $serendipity['view'].

Is your template using a config.inc.php? That file will then be utilized, maybe that could be responsible. If you use it, please temporarily remove that config.inc.php file?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Don Chambers
Regular
Posts: 3633
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Post by Don Chambers » Mon Jun 16, 2008 6:05 pm

Before I even posted this thread, I switched my template to carl_contest.... the behavior is the same there.

User avatar
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert » Mon Jun 16, 2008 8:12 pm

Yup, the microformats plugin is causing it.

The problem starts in include/genpage.inc.php, line 221. First we call the genpage hook, then we call serendipity_smarty_init(). This is where $view gets set; it's among the variables passed to serendipity_smarty_init() to be assigned to Smarty.

Unfortunately, the microformats plugin calls serendipity_smarty_init() with no assignable variables. (Other plugins may do this, too; I don't mean to single out microformats.) When we return to genpage.inc.php after the genpage hook, we call serendipity_smarty_init() with the set of variables to be assigned (including $view), but serendipity_smarty_init() sees that it's already initialized once, and skips the variable assignments.

By Garvin's great foresight, we pass the list of variables to initialize with the genpage hook. So the right thing to do in a plugin is not to initialize Smarty and assign variables, but rather to add the necessary initializations to the $addData.

In short, I changed the microformats plugin (starting on line 199) from this:

Code: Select all

                case 'genpage':
                    include_once(dirname(__FILE__).'/smarty.inc.php');
                    if (!isset($serendipity['smarty'])) {
                        serendipity_smarty_init();
                    }
                    $serendipity['smarty']->assign('subnode', ($this->get_config('subnode') ? 1 : 0));
                    $serendipity['smarty']->assign('best', $this->get_config('best'));
                    $serendipity['smarty']->assign('step', $this->get_config('step'));
                    $serendipity['smarty']->assign('timezone', $this->get_config('timezone'));
                    $serendipity['smarty']->register_function('microformats_show', 'microformats_serendipity_show');
                    break;

To this:

Code: Select all

                case 'genpage':
                    $addData['subnode'] = ($this->get_config('subnode') ? 1 : 0);
                    $addData['best'] = $this->get_config('best');
                    $addData['step'] = $this->get_config('step');
                    $addData['timezone'] = $this->get_config('timezone');
                    $addData['microformats_show'] = 'microformats_serendipity_show';
                    break;


When the genpage hook is done, all that additional data should be added to the list of things that get assigned when Smarty is initialized. Tested only to verify that nothing blows up; commited; should be available withing 24 hours through SPARTACUS.

Morals of the story:
  1. Plugins shouldn't call serendipity_smarty_init().
  2. Garvin has already thought of everything.
Judebert
---
Website | Wishlist | PayPal

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Tue Jun 17, 2008 10:26 am

Hi!

Thanks for that patch! Now I see the problem.

With your patch however you removed the register_function() call to a microformat function. Was this no longer necessary? Does it work without it?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert » Tue Jun 17, 2008 5:14 pm

Oh, bloody H. I didn't even recognize that was a different call.

Nothing blows up, and my frontpage event list still looks OK, but I'll bet the microformats don't work very well now.

Hmmm, there's no way to pass functions to register on init. Maybe Garvin didn't think of everything.

Well, the easy thing to do is just add the function during the "frontend_header" hook. By then the "genpage" hook has already been called, and Smarty is already initialized (it has to be, because frontend_header is hooked from a template). Alternatively, I could just check at each hook, and add it for the first hook that doesn't have it.

In the future, it might be nice to have a 'Smarty initialization complete' hook.

Meanwhile, I'm updating the plugin to fix my error. I'm also adding a 'path' variable (copied from the lightbox plugin), so users don't have to edit their index.tpl and insert a '<link>' tag.

Is it plugins that you need to define strings in every language, or the main code? I can never remember.
Judebert
---
Website | Wishlist | PayPal

User avatar
garvinhicking
Core Developer
Posts: 30020
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking » Tue Jun 17, 2008 7:48 pm

Hi!

One can register smarty functions any time before the smarty output is called...so frontend_header sounds like a suitable register_function call to me?!

Is it plugins that you need to define strings in every language, or the main code? I can never remember.


New language constants are only required in each file of the main s9y release. They wouldn't hurt for plugins though, so you can simply try to remember "put it in everywhere", that has the least screw up factor ;-) ;-)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

Post Reply