1 edb Feb 13, 2009 10:37
3 edb 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 yabba 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 edb 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 yabba Feb 13, 2009 18:13
Oy, I do the one liners round here :|
¥
7 edb 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 yabba 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 edb 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 yabba 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 edb Feb 13, 2009 18:48
oh never mind. I get it now. it's morning is my excuse
12 edb 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:
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 )
¥