Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-07-22 11:36:09

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 335
Website

pro_mobile

Hi pretty txp people :)

Can I have an account in the plugin author support please? Just looking to publish a mobile browser if else tagaroo please!

(Should I upload the file+zip to my web server for preview?)


…………………
I <3 txp
…………………

Offline

#2 2011-07-22 11:44:11

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 335
Website

Re: pro_mobile

Here’s the plugin, only tested on the newest version of txp and android, was hoping to have some people download and test on their iphones etc..

pro_mobile

Last edited by hilaryaq (2013-06-28 15:42:00)


…………………
I <3 txp
…………………

Offline

#3 2011-07-22 11:49:25

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,303

Re: pro_mobile

Plugin prefix preserved ;)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2011-07-22 11:50:51

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 335
Website

Re: pro_mobile

FAME! Finally! Knew if I waited long enough :D :D thanks!


…………………
I <3 txp
…………………

Offline

#5 2011-07-22 12:06:08

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 335
Website

Re: pro_mobile

Still very stuck on how to actually publish the plugin to http://textpattern.org/plugins.. someone mentioned registration but there’s no register link anywhere, just a login, must be up to a moderator? You guys do so much work!!


…………………
I <3 txp
…………………

Offline

#6 2011-07-22 12:11:52

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: pro_mobile

Nice. Welcome abroad. Some things to note:

  • Textpattern uses GPLv2. Thus plugins (as they share memory, functions) should be released under the same license.
  • To avoid possible conflicts mobile_display() function should be prefixed too.
  • Instead of using $_SERVER, you could use serverSet function to ensure that the element exists before trying to use it.
  • You can return mobile_display()’s results to EvalElse(). The additional conditional isn’t needed.

There are other plugins that do the same thing too, tho. Like for example adi_mobile which also includes additional attributes for targeting specific clients. But good work nonetheless especially if your intention was to experiment.

Last edited by Gocom (2011-07-22 12:13:43)

Offline

#7 2011-07-22 12:17:21

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 335
Website

Re: pro_mobile

Thanks for that, I’ll tweak it up!

I saw adi_mobile, and just noticed it wasn’t built using an array, so my intention is to develop this further being able to pick values from the array and display custom messages for iphone, android etc, so that’s kind of why I did it, along with wanting to learn how plugins work.. I’ll put the licence info with the plugin, the cc licence on my web site is actually just for my text content if people want to re-blog stuff..


…………………
I <3 txp
…………………

Offline

#8 2011-07-22 13:09:07

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 335
Website

Re: pro_mobile

Adi actually does use an array, I just find the code hard to read it’s a good plugin, very indepth, I think it was just so much code I wanted to start from scratch, and build extra functionality for v2 in but in a neat way that I understood!


…………………
I <3 txp
…………………

Offline

#9 2011-07-23 15:44:07

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 335
Website

Re: pro_mobile

Hey guys, just edited my plugin to accept variables so:

<txp:pro_if_mobile curragent="opera mini"> You use opera mini </txp:pro_if_mobile>

As far as I can see from the documentation adi_mobile doesn’t have this functionality? Worth releasing?


…………………
I <3 txp
…………………

Offline

#10 2011-07-23 15:48:35

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 335
Website

Re: pro_mobile

Oh no, found it:

<txp:adi_if_mobile type="iphone,android"> <meta name="viewport" content="width=device-width" /> </txp:adi_if_mobile>

Ah well, nice to be able to use my own plugin anyway, great learning experience!!


…………………
I <3 txp
…………………

Offline

#11 2011-07-23 16:46:40

hilaryaq
Plugin Author
Registered: 2006-08-20
Posts: 335
Website

Re: pro_mobile

Uploaded the second version with new tag to pro_mobile_v0.2

Think it’s a bit easier to understand than adi, just for me anyway, but if it’s major functionality you want adi_mobile has it all!

Last edited by hilaryaq (2013-06-28 15:43:54)


…………………
I <3 txp
…………………

Offline

#12 2011-07-23 17:22:49

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: pro_mobile

Nice.

You could pretty easily compress that all into 10 lines of code and a single tag.

Basically, you could set the array of mobile user-agents as the default value of name, and then use that to detect the user client. That way when name isn’t defined, it detects all the mobile clients. If the name is defined, it detects what the user has defined.

Also, you could still use serverSet() and note that strpos() will return 0 when the matched needle is the first byte. Matching with out specifying the type likely doesn’t matter as the needle won’t be at the beginning of user agent header, but the user can use something that is with the name value. So you may want to use !== operator.

Making the changes, the whole plugin could become just this:

function pro_if_mobile($atts, $thing=NULL) {

	/*
		Set the mobile clients as the default value
	*/

	extract(lAtts(array(
		'name'  => 'iphone,ipod,aspen,nexus,dream,android,cupcake,blackberry9500,blackberry9530,opera mini,webos,incognito,webmate'
	),$atts));

	/*
		Get visitor's user-agent
	*/

	$user_agent = strtolower(serverSet('HTTP_USER_AGENT'));

	/*
		Split the list of values in $name into array
	*/

	$agents = explode(',', $name);

	foreach($agents as $agent) {

		/*
			Remove white-space
		*/

		$agent = trim($agent);

		/*
			Match the agent
		*/		

		if(strpos($user_agent, $agent) !== false)
			return parse(EvalElse($thing,  true));
	}

	return parse(EvalElse($thing, false));
}

I also added some indentation so that the code is easier to read. It’s untested, it may or may not work. I’m just throwing the code out there. Not expecting you to use it or anything.

Offline

Board footer

Powered by FluxBB