Recent Topics

1 Aug 02, 2007 10:39    

I've made a some code you can stick into your plugin, so when the "Show Support?" setting is check we add a credit link to the plugin.

Insert this into your plugin


	# =============================================================================
	# LINK LOVE / SHOW SUPPORT FUNCTIONALITY
	
	var $link_love__added_link = false;
	function link_love__settings ( & $settings, & $params )
	{
		$settings['link_love'] = array(
			'label' => $this->T_('Show Support?'),
			'type'	=> 'checkbox',
			'defaultvalue' => '0',
			'note'	=> $this->T_('Adds an additional credit link for this plugin').'.',
		);
	}
	
	function link_love__add_link ( )
	{	// Call this somewhere in a skin event
		if ( $this->link_love__added_link || !$this->Settings->get('link_love') )
			return true;
		
		global $credit_links;
		$credit_links[] = array($this->get_help_url(), $this->name);
		$this->link_love__added_link = true;
		
		return true;
	}

And at the end of your GetDefaultSettings


		// EXTRA FUNCTIONALITY
		$this->link_love__settings($r, $params);
		
		
		// Return settings
		return $r;
	}

It is unchecked by default, no one likes intrusive shit, so leave it as unchecked.

3 Mar 14, 2008 01:59

Okay finally got this working, only differently. I added the setting directly to GetDefaultSettings() because I generally don't bother with $r = foo and return $r, but whatever: add a setting to GetDefaultSettings:

'link_love' => array(
	'label' => $this->T_('Show Support?'),
	'type' => 'checkbox',
	'defaultvalue' => '0',
	'note' => T_('Adds a credit link for this plugin to your page footer.'),
	),

I then discovered by process of educated guess work and a wee bit of elimination that SkinBeginHtmlHead is a nice function to use to tweak the credits array with, like so:

/* add a link-back, if allowed, to the credits_array */
function SkinBeginHtmlHead() {
	if ( $this->Settings->get('link_love') ) {
		global $credit_links;
		$credit_links = array_merge( $credit_links, array( array( $this->get_help_url(), $this->name ) ) );
		return true;
		}
	}


Obviously if you are actually using the SkinBeginHtmlHead function then you wouldn't return out of it unless you've already done the bits you need to do, but yeah y'all can probably figure that part out... And clearly this depends on the blog owner still having credits_array in their skin, which is why it's even easier to dream of some link-love if your plugin is a widget maker.

In a widget maker you use a similar setting in your GetDefaultSettings function:

'link_love' => array(
	'label' => $this->T_('Show Support?'),
	'type' => 'checkbox',
	'defaultvalue' => '0',
	'note' => T_('Adds a credit link for this plugin under the widget.'),
	),


Then you add a little P tag to the bottom of your SkinTag function, like this:

if( $this->Settings->get('link_love') ) {
	echo $params['notes_start'];
	echo '<p><a href="'.$this->help_url.'">'.$this->name.' '.T_('widget by').' '.$this->author.'</a></p>';
	echo $params['notes_end']."\n";
	}

4 Mar 14, 2008 02:12

Very nice EdB,

If I didn't give you rep star points yesterday you'd have gotten them today. ;)

You can even use the BBcode in your Avatar to make the text smaller if you've got nothing to say.

5 Mar 14, 2008 02:49

Oh snap! I didn't notice the points thing. So now you got 'em back ;)

Yeah I like the idea of a nice simple way to ask for a bit of link-love, so I've had this thread in my watched list for a while. The widget maker version is pretty easy, but acrolink doesn't make a widget so ... Bob's your uncle!

6 Mar 16, 2008 22:14

EdB,

I have a fatal error with your widget thing. This more or less works:

		// EdB's Linklove support
		if( $params[ 'link_love' ] ) 
		{
			echo $params[ 'notes_start' ];
			echo '<p><a href="'.$this->help_url.'">'.$this->name.' '.T_( 'widget by' ).' '.$this->author.'</a></p>';
			echo $params[ 'notes_end' ]."\n";
		}


although I am still investigating.

I hope ¥åßßå can shed his light on this and explain a little, since I want to use the settings (not the params) also in another thing (lottery) and I don't know how and where to initialize, which seems the problem with EdB's code also.

7 Mar 17, 2008 00:36

Okay cool. I think it worked in the plugin I put it in because that particular setting doesn't go to the widget if the admin enables widget-level settings, but I'll test it and see and probably do an upgrade release. Not a show stopper though so not much pressure on getting it done yah?

8 Mar 17, 2008 00:39

EdB wrote:

Not a show stopper though so not much pressure on getting it done yah?

You call a fatal Error "not a show stopper"?

9 Mar 17, 2008 00:51

Yup. Because *I* am not seeing a fatal error, or an error of any kind in *my* implementation of that code. See the randomyoutubes plugin for the only place I've used that bit so far, and you won't see an error - or at least I don't under any combination of plugin or widget (if enabled) settings.

The only conditions under which a setting needs to be accessed as a param is if the setting is moved to widget-level control. Given that in the randomyoutubes plugin I am not offering the chance for each instance to decide on the value of the link-love setting(s), I've no need to concern myself with grabbing the info via Settings->get or param.

10 Mar 17, 2008 01:29

Fixed now.

I had them under widget params since the widget has no settings. With either code you can now choose where to do the control.

Tx

11 Mar 18, 2008 00:38

Good good good. I knew there would be a solution to the widget-settings version, but with 2.4.1 credits_link is toast so now that part of this "idea" is nullified.


Form is loading...