Recent Topics

1 Feb 13, 2009 10:37    

So my silly little plugin has info associated with a post, stored in 4 tables the plugin created. Is there an easy way to tell the posts loop "you gotta think about this particular plugin"? What I'm doing right now is hard-coding a query to talk to the tables the plugin made because $this-> doesn't work - of course. So if I could tell it somehow "when I say $this I mean that particular plugin".

SkinTag will be much later down the road. Currently all I want to do is have a wee bit of text under the title that picks up the info the plugin stored. Since I'm using evopress I currently have the datestamp under the title. So now I want it to be like this:

My awesome hang gliding flight (title)
February 13th, 2009 (existing "small" bit)
From {{site_name}} for XX miles in YY hours, ZZ minutes (only the plugin knows this stuff)

To do it with brute force I have to hard code the query to the table that stores "Entry" info, then hard code a query to the "Sites" table, then hard code a query to the "Gliders" table. This last just to pick up an icon associated with the flight report. Seems to me this is rather dumb. Seems to me if I was even half smart I'd be able to tell my 'posts' and 'single' files to be aware of the plugin named 'xccontest', then simply use $this for that. Might still have to query the heck out of the database for each post displayed, but at least it wouldn't be hard coding the plugin ID eh?

2 Feb 13, 2009 11:15

Some ways :
1) create a container and add it as a widget
2) call it directly ( $Plugings->call_by_code() ... can't remember if that one barfs if the plugin isn't installed )
3) Add a custom event and use triggers ( $Plugins->trigger_event( 'foo', array( ) ) ... this one can be used by multiple plugins )

¥

3 Feb 13, 2009 12:25

Okay cool. Item 2 sounds good to me although I'll probably use "$Plugins" because "$Plugings" isn't likely to work. (I know - free typed is a sweet excuse ;) )

In my situation there is no chance that the plugin isn't installed, so yeah that sounds good. I'll be testing soon.

Thanks again ¥åßßå!

EDIT: oops. function call_by_code does call_method_if_active() which assumes a SkinTag. Not interested in a skintag though. Interested in, basically, the plugin's ID. I have and will use a skin tag, but the bits it'll make won't belong in each post's portion of the posts loop.

Ah well. I guess don't really mind hard coding it including the ID portion. It's not like anyone else will ever care about or want to use this thing, but it would have been nice to be able to 'turn on' the plugin without trying to display something designed for displaying. And hey if I get lucky I'll take bits from call_by_code and bend it to satisfy my desires :)

4 Feb 13, 2009 17:13

Add a custom event ( function GetExtraEvents() ) and then use triggers, they're very cool :D

¥

*edit*

Example : Profiles plugin skin call ( for one bit )

		$Plugins->trigger_event( 'UserTimezone', array(
						'block_start' => '',
						'block_end' => '',
						'display' => true,
						'localdatetime' => $Comment->get( 'date' ),
						) );

Code to add said trigger ( in plugin )

	/**
	 * Should these be reduced to a single funtion ?
	 *
	 * @return unknown
	 */
	function GetExtraEvents()
	{
		return array(
			'UserTimezone' => 'Displays or returns the timezone offset for the current visitor',
			'UserSignature' => 'Displays or returns the users signature',
			'UserAvatar' => 'Displays or returns the users avatar',
			'UserLocation' => 'Displays or returns the users location',
//			'DisplayProfile' => 'Displays the extra profile stuff', // deprecated, use SkinTag()
			'LinkUserProfile' => 'Links a user name to their profile .... only works with enabled skins ;)',
			'AMProfileTabAction' => 'AdminTabAction() when on our profile tab',
			'AMProfileTabPayload' => 'AdminTabPayload() when on our profile tab',
			 );
	}

Shit in the plugin that reacts to aforementioned trigger :

	/**
	 * Converts a date/times to users timezone
	 * and sets the date/time format to the users
	 * preferred date/time format based on user settings
	 *
	 * If no user then the default timezone/format is used
	 *
	 * @param mixed $params
	 * 	localdatetime - mysql date/time to convert
	 * 	display - display or return the formatted date/time
	 * 	block_start : html output before the date/time
	 * 	block_end : html output after the date/time
	 *
	 * @return mixed params
	 */
	function UserTimezone( & $params )
	{
		$params = array_merge( array(
			'block_start' => '<p class="userDateTime">',
			'block_end' => '</p>',
			'display' => true,
			'output_format' => '$date$ @ $time$',
			), $params );
		if( is_logged_in() )
		{	// we have a current user
			$params['timeformat'] = $this->UserSettings->get( 'timeformat' );
			$params['dateformat'] = $this->UserSettings->get( 'dateformat' );
			$params['userOffset'] = $this->UserSettings->get( 'timezone' );
		}
		else
		{	// we don't have a current user
			$params['timeformat'] = $this->Settings->get( 'default_timeformat' );
			$params['dateformat'] = $this->Settings->get( 'default_dateformat' );
			$params['userOffset'] = $this->Settings->get( 'default_timezone' );
		}
		//pre_dump( $params );
		$params['usertime'] = mysql2timestamp( $params['localdatetime'] ) + ( $params['userOffset'] * 60 );

		$params['user_datetime' ] = str_replace( array( '$date$', '$time$' ), array( date( $params['dateformat'], $params['usertime'] ), date( $params['timeformat'], $params[ 'usertime'] ) ), $params['output_format' ] );
		$params['result'] = $params['block_start'].$params['user_datetime'].$params['block_end']."\n";
		if( $params['display'] )
		{ // we want to display the date/time
			echo $params['result'];
		}
		return $params['result'];
	}

The world is your oyster .... hope you like seafood :D

5 Feb 13, 2009 18:10

Groovy. Effectively this means, if I may paraphrase, "put a hook in the posts loop then put the code in the plugin". Yay for smartness!

6 Feb 13, 2009 18:13

Oy, I do the one liners round here :|

¥

7 Feb 13, 2009 18:24

Hey uh that's kinda what I thought when you wrote a book. Only different ;)

The detail I'm going to have to work out is how it knows which post ID it is on, but I think trigger_event( $Item->ID ) will take care of that.

8 Feb 13, 2009 18:33

Touche .... or however the hell you spell "bugger, you just made me make another multi lined post :("

$Plugins->trigger_event( 'my_groovy_hook', array( 'Item' => $Item ) );

¥

9 Feb 13, 2009 18:44

See what happens when I free-type stuff? Doh!

Hey do you also put bits into ... gah the two files that seem to have every plugin hook in them? One is always like an empty function and the other is just a list with a comment that shows up when someone clicks the "don't click me" bit on the plugin's settings page? I've done that for each of my extra hooks but to be honest don't have a clue if I need to.

10 Feb 13, 2009 18:46

Nope, you can create hooks to your hearts content ;) ... the world awaits your unique hooks with bated ... urm, breath or summat ... until they read the health advisory that warned that your "humongous plugin to dwarf all plugins" was taking a smidge longer than the lung capacity of a healthy smurf :|

¥

11 Feb 13, 2009 18:48

oh never mind. I get it now. it's morning is my excuse

12 Feb 13, 2009 18:50

¥åßßå wrote:

... "humongous plugin to dwarf all plugins" ...

¥

Useless too. I mean, unless you want a plugin that is completely focused on a 6 month hang gliding contest and probably can't be beaten into anything but that without a total re-write :roll:


Form is loading...