• php

    Posted on April 7th, 2010

    Written by Jose (Jossi) Fresco Benaim

    Tags

    Mobile Content Switch Plugin for Joomla

    The Mobile Content Switch Plugin is a free Joomla Plugin that will enable you to hide or show content depending if the user is visiting your site from an iPad, iPhone, iPod Touch, or not.

    Great to display an embedded Flash video  for non-Apple mobile devices, and a QuickTime movie for Apple mobile devices, or other such uses.

    (Thanks to Peter van Westen from www.nonumber.nl for the help with regex)

    Usage:

    • {ipad}Display content to visitors ON an iPad.{/ipad}
    • {noipad}Display content to visitors NOT on an iPad{/noipad}
    • {iphone}Display content to visitors ON an iPhone or iPod touch.{/iphone}
    • {noiphone}Display content to visitors NOT on an iPhone or iPod touch.{/noiphone}
    • {applemobile}Display content to visitors in EITHER an iPad, an iPod, or an iPhone{/applemobile}
    • {noapplemobile}Display content to visitors in NEITHER an iPad, an iPod, or an iPhone{/noapplemobile}
    • {android}Display content to visitors on an Android device{/android}
    • {blackberry}Display content to visitors on an BlackBerry{/blackberry}
    • {palm}Display content to visitors on an PalmOS device{/palm}
    • {sonyericsson}Display content to visitors on an SonyEricsson (Nokia) device{/sonyericsson}
    • {symbian}Display content to visitors on an SymbianOS device{/symbian}

    joomla_commpow_sm

    Important Notes: (updated June 6, 2010)

    • Set in  Global Configuration > Systems > Cache = no for the plugin to work, otherwise what you will see is the cached version of the article, which may have been generated by a device other than the one you are viewing the article on.
    • If you have caching enabled, and your content is in a module, make sure to set the module not to be cached (advanced parameters > caching)
    • If you use the plugin  in a module, make sure that the module is capable of running plugins (such as mod_placehere)

    Changelog

    Version 2.1 – August 11, 2011

    • Support for Joomla 1.6 (Thanks to Louis Carlos)
    • Added {mobile}{/mobile} {nomobile}{/nomobile} parameters (Thanks to @Mano)

    Version 1.7 – January 29, 2011

    • Added support for Android, Palm, Blackbery, Symbian, Palm, and Sony Ericsson

    Version 1.6 – June 16, 2010

    • Resolved an issue with iPhone compatibility
    • To upgrade, unzip the plugin and copy the mobilecontentswitch.php and mobilecontentswitch.xml files to /plugins/content

    Download the Mobile Content Switch Plugin for Joomla 1.5

    Download the Mobile Content Switch Plugin for Joomla 1.6

    Found the plugin useful?


    All proceeds will be donated to Words of Peace Global

    This entry was posted on Wednesday, April 7th, 2010 at 6:06 pm and is filed under php. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 68 Comments

    Take a look at some of the responses we've had to this article.

    1. Frank G
      Posted on April 9th

      Cool, thanks!

    2. Posted on April 15th

      Great idea. I just ran a test and noapplemobile works, as does iphone specivid.

      But when I try to use applemobile as a catchall for iphone and ipad it goes wrong and shows the noapplemobile content.

      I am only testing on iphone as I don’t have an ipad.

    3. Posted on April 28th

      Great idea, what would be ideal (for me anyway) would be a way with the plugin to hide module positions. If I didn’t want the right or left menu areas to display, I could just select them in the plugin. It would pull all of the module positions from the template itself since many of the newer templates add new positions.

    4. jossi fresco
      Posted on April 30th

      You can do this by tweaking your template’s index.php.

      For example:

      countModules(‘mymodule’) && strstr($_SERVER['HTTP_USER_AGENT'],’iPad’);) : ?>

    5. Posted on May 12th

      Hi Jossi

      Can you give us more examples on how to tweak the index.php — such as for both ipod and ipad. Or would iPad handle all possibilities

      Thanks,

      Rowby

    6. Posted on May 12th

      For example, could you give us a complete rewrite of the following example that I have in my template to handle the iPad and Ipod

      countModules(‘banner’)) : ?>

      Thanks!

    7. Posted on May 12th

      Hmmmmm the comment system stripped out most of my code example.

      Perhaps you can add very specific examples in your useage section of this page tos howhow to handle modules.

      Thanks!

    8. Posted on May 18th

      Just the same as Don, works great with iphone tag but not with applemobile…
      Could it be fixed ?

    9. Posted on May 19th

      Hi, just the same as Don, works perfect with the iphone tag but not with the applemobile one ?
      SHould I use {ipad}{iphone}{/iphone]{/ipad} ?

    10. Rod
      Posted on May 31st

      Having the same issues as Don.

      I have an iPhone and an iPad…

      using {applemobile} doesn’t show the content on an iphone…

      any help would be appreciated

    11. Andrea
      Posted on June 10th

      Hi, the plugin is very helpful but it seems doesn’t work perfectly.
      By using the code

      {applemobile}testapple{/applemobile}
      {noapplemobile}testnoapple{/noapplemobile}

      the results are:

      on laptop “testnoapple” (correct!)
      on iPhone “testnoapple” (incorrect!)

      I need your help to solve the problem…
      Thank you very much in advance.
      Andrea

    12. jossi fresco
      Posted on June 11th

      @Andrea, Rod and Jerome

      Please note that you have to set in Global Configuration > Systems > Cache = no

      for the plugin to work, otherwise what you will see is the cached version of the article, which may have been generated by a device other than the one you are viewing the article on.

      If you have the content on a module,, make sure that the module is capable of running plugins (such as mod_placehere)

      If you have caching enabled, and your content is in a module, make sure to set the module not to be cached (advanced parameters > caching)

    13. Andrea
      Posted on June 14th

      Dear Jossi, thank you very much for your answer.
      I have just checked the system configuration, and the cache is already set on “no”.
      In my case I would like to use the plugin directly in an article: here’s the test code:

      {applemobile}applemobile{/applemobile}
      {noapplemobile}noapplemobile{/noapplemobile}

      and you can test by yourself here:

      http://www.milestonesrl.tv/index.php?option=com_content&view=article&id=97&Itemid=233

      If I open the page by PC, it works fine (noapplemobile label appears).
      If I open the page by iPhone, there is an error (noapplemobile label appears too).
      If I open the page by iPad, it works fine (applemobile label appears).

      So the problem seems to be with iPhone only.
      This plugin is very important for me and I need your support: I’m ready to donate a good amount if you can help me. My e-mail is webmaster@milestonesrl.com
      Thank you in advance.
      Andrea

    14. jossi fresco
      Posted on June 15th

      Hi Andrea, I am making some adjustments and will upload a new version today.

      Thank you for your feedback!

    15. jossi fresco
      Posted on June 16th

      New version 1.6 available, resolving the iPhone compatibility issue reported.
      Enjoy!

    16. chris w
      Posted on June 29th

      Hi, great plugin!

      Quick question, I have an older Joomla 1.0 site…do you know if I can use the plugin on 1.0?

      Thanks!

    17. jossi fresco
      Posted on June 29th

      @ Chris w

      You can certainly give it a try.

    18. Hasan
      Posted on August 24th

      How can I install it on Joomla 1.0?
      Your help will highly be appreciated.

    19. Posted on September 11th

      hi, im new to all this can you please tell me how to instal and run it on my video website.
      thank you

    20. jossi fresco
      Posted on September 25th

      @Hasan
      This plugin was designed for Joomla 1.5.

    21. jossi fresco
      Posted on September 25th

      @Jorge
      To learn about installing plugins, see the WIki http://docs.joomla.org/How_do_you_install_an_extension%3F

    22. Posted on November 25th

      Problem: I cannot get the link to work to download the product.

      Thank you.

    23. jossi fresco
      Posted on November 25th

      This is now corrected. Enjoy.

    24. Jonathan frewin
      Posted on December 20th

      This looks great but not being a coder I have a dumb question, sorry – where do you put the code to make this work? Does it go in the Header of the mobile and non mobile templates?

      Is there a tutorial?

      Is there an example page where I can use Firebug to see the code?

      Thanks

    25. jossi fresco
      Posted on December 20th

      @Jonathan

      You put the code anywhere in any of your articles.

      For example:
      Hello,
      Welcome to our Website
      {ipad}I see that you are using an iPad.{/ipad}
      {iphone}I see you are using and iPhone or an iPod touch.{/iphone}
      {applemobile}We have specific material suited for your mobile devices, so enjoy!{/applemobile}

      That content will not show for visitors that come to your site using a desktop browser (or any other browser that is not an iPhone or Ipad)

    26. Jonathan frewin
      Posted on January 5th

      Jossi

      Brilliant thank you, works perfectly.

      Happy New Year

    27. Posted on January 14th

      I’m having issues executing the video code within our tags. Is there a standard for embedding video within your tags? Is there a particular editor that work / does not work with your plugin?

      Here is my code:
      {noapplemobile} {/noapplemobile}

      any suggestions i’d appreciate.

      -jake

    28. jossi fresco
      Posted on January 14th

      @Jake:
      If you have problems with your editor removing the tags, simply set your editor to “No Editor”.

    29. Posted on January 27th

      I would love to use this, can you extend it to deal with Android and Blackberry as well, and not just Apple devices?

      Thanks!

    30. jossi fresco
      Posted on January 27th

      I am sending you via email a version that you can test.
      {android}Display content to visitors on an Android device{/android}
      {blackberry}Display content to visitors on an BlackBerry{/blackberry}
      {palm}Display content to visitors on an PalmOS device{/palm}
      {sonyericsson}Display content to visitors on an SonyEricsson (Nokia) device{/sonyericsson}
      {symbian}Display content to visitors on an SymbianOS device{/symbian}

    31. jossi fresco
      Posted on January 30th

      @jake: Just place the embed code within the tags. If it is not working for you, give me some more details on the problem.

    32. will
      Posted on February 16th

      Does this provide the ability to display a .jpg instead of a .swf for mobile devices?

    33. jossi fresco
      Posted on February 16th

      @will
      yes, of course. Just wrap the embed tag for flash or the img tag with

    34. Niall
      Posted on February 22nd

      Hi,

      Cant seem to get this working in a “Custom Html” module… I have it working on Article pages fine. When i try to insert the Tags into a module they dissplay as text on the forntend of the site. Im using 1.5.. any ideas?

    35. anne
      Posted on March 9th

      hi jossi,

      i already installed the plug-in and put the code in article but it’s still not running.

    36. Posted on March 14th

      Can you add {noandroid} tag in this GREAT plugin ? It is much appreciated ..

      Thanks

    37. jossi fresco
      Posted on March 14th

      @Niall: Modules have to be able to execute plugins for this to work. For example, the custom HTML module has a parameter “execute plugins”.

      Check that the plugin you are using has that capability, otherwise it will not work.

    38. jossi fresco
      Posted on March 14th

      @Chris.
      Yeas, I will do that… Please email me at jossif{at}emandtee.com so that I can send you the plugin to test

    39. jossi fresco
      Posted on March 14th

      @anne: Make sure to enable the plugin in Extensions > Plugin Manager

    40. Marge
      Posted on April 1st

      Hi Jossi,

      Very nice plugin, works wonderfully, and so easy to use !
      Do you still plan to add a {noandroid} tag, as you told Chris ? This would be useful. I can test it on my android device if needed.

      Thanks

    41. Posted on April 29th

      Great idea, easy to use plugin. Thank you.

      I have needed a little suplement, maybe you find it useful.
      I have added mobile and nomobile tag into the mobilecontentswitch.php.

      $mobile = $ipad || $iphone || $android || $blackberry || $symbian || $palm || $sonyericsson;

      if ($mobile) {

      //{mobile} tags regex
      $row->text = preg_replace( “#\{nomobile\}(.*?)\{/nomobile\}#s”, ”, $row->text ); // removes {nomobile} tags + content for nomobile content
      $row->text = preg_replace( “#\{mobile\}(.*?)\{/mobile\}#s”, ‘\1′, $row->text ); // removes just the {mobile} tags from content

      } elseif (!$mobile) {
      //{mobile} tags regex
      $row->text = preg_replace( “#\{mobile\}(.*?)\{/mobile\}#s”, ”, $row->text ); // removes {mobile} tags + content for ipad content
      $row->text = preg_replace( “#\{nomobile\}(.*?)\{/nomobile\}#s”, ‘\1′, $row->text ); // removes just the {nomobile} tags from content
      }

    42. jossi fresco
      Posted on April 29th

      @ webmano.hu
      Thank you. I shall add this to next release. Glad you found it useful.

    43. jossi fresco
      Posted on May 8th

      @Marge, Will have this ready later today for you to test

    44. Posted on May 11th

      Great!!! Thanks for the news,I need this plugin to develop my new website!!!thanks mate!cheers

    45. Posted on July 8th

      Will this work with Joomla 1.6.4?

    46. jossi fresco
      Posted on July 22nd

      I have not tested it on 1.6

    47. Ciul
      Posted on July 24th

      Hi @Jossi.

      I changed some lines to make it work for Joomla 1.6 and also added the {mobile}{/mobile} {nomobile}{/nomobile} code by @Mano.

      I don’t know how to upload it to Joomla extensions directory but I’d like you to update yours instead, which would be better.

      Want me to send you the zip file in an email?
      Regards,
      Ciul

    48. jossi fresco
      Posted on July 25th

      Thanks, Ciul.
      You can email me at jossif [at] emandtee.com with the new version. Please also provide info on contributors, so that I can add credits.

    49. Posted on August 2nd

      I’m desperate looking for such a plugin for Joomla 1.7.0.
      Is it compatible ?

    50. Posted on August 6th

      Jossi

      Fantastic plugin for Joomla 1.5, I won’t upgrade to 1.7 until there’s a version of your mobile content switch!

      Regards
      Jonathan

    51. Morten
      Posted on August 7th

      I cant see the changes for mobile/nomobile in the version (2.0) I downloaded. Is that correct or am I missing something?

    52. jossi fresco
      Posted on August 8th

      I will be uploading a new version compatible with Joomla 1.6 and 1.7 in a day or two

    53. jossi fresco
      Posted on August 11th

      New version uploaded. Thank you Luis Carlos!

    54. jossi fresco
      Posted on August 11th

      New version uploaded!

    55. jossi fresco
      Posted on August 11th

      Yes, it is now.

    56. Posted on August 16th

      It is not working for my iPad. It hangs a Flash movie up on the preloader. I’m using it inside a Custom HTML module.

    57. jossi fresco
      Posted on August 16th

      @Paul: what tags did you use?

      Also, please read note:

      Set in Global Configuration > Systems > Cache = no for the plugin to work, otherwise what you will see is the cached version of the article, which may have been generated by a device other than the one you are viewing the article on.

      If you have caching enabled, and your content is in a module, make sure to set the module not to be cached (advanced parameters > caching)

      If you use the plugin in a module, make sure that the module is capable of running plugins (such as mod_placehere)

    58. Posted on August 17th

      Hi Jossi,

      I have just installed the plugin. Set the cache system to no. Edit a new content article with:
      a video code with flash and the tag noapplemobile
      a video mp4 with the tag applemobile
      The plugin is active.
      From a PC I can see only the video with flash which is correct. From a ipad 1 and a iPhone3 I can only see the logo Adobe Flash.
      I tried with the tag iPad : same thing.
      No cache, no module, plugin active, tag at the beginning and at the end with a /, Joomla 1.53, new article (no cache problem) but still not working.
      What is your diagnosis ?

    59. jossi fresco
      Posted on August 17th

      Are you using the version for Joomla 1.5 or 1.6?

      Can you try on a test page the following?
      {applemobile}I am viewing this in an Apple iOS device{/applemobile}
      {ipad}I am viewing this in an iPad{/ipad}
      {iphone}I am viewing this in an iPhone{/ipad}
      {noapplemobile}I am viewing this in an device that is not an Apple iOS device{/noapplemobile}

    60. Posted on August 22nd

      I took my time to make the tests : it is working fine when the cache is off.
      And i can set it on after a time (15mn).

    61. Posted on August 31st

      I am trying to install the Mobile Content Switch Plugin but the error “Error! Could not find an XML setup file in the package.” appear. What is the problem? Please help.

      I am using Joomla 1.5.7

      Thank you in advance.

    62. jossi fresco
      Posted on August 31st

      @Sam – Maybe something wrong with the zip file? I suggest you unzip the package and zip again, Then try to install it again.

    63. Posted on October 10th

      Great plugin !
      But is there a way to transform it into a system plugin instead of a content plugin ?
      Because as it’s a content plugin it isn’t executed in rss feeds for example or in components, so if you use joomlatags for example you’ll see {noapplemobile}{/noapplemobile}{applemobile}{/applemobile} :
      http://www.360images.fr/chateau.html

      thanx !

    64. Liber
      Posted on October 26th

      Excellent plugin!!!

      But I would like it to have a {noblackberry} option, as my site is on Joomla 1.5.23 and I can’t use {nomobile}

      Thanks.

    65. jossi fresco
      Posted on October 26th

      @Liber:
      Open mobilecontentswitch.php and replace lines 65 to 73 with this:

      if ($blackberry) {

      $row->text = preg_replace( "#\{blackberry\}(.*?)\{/blackberry\}#s", '\1', $row->text ); // removes just the {blackberry} tags from content for blackberry devices
      $row->text = preg_replace( "#\{noblackberry\}(.*?)\{/noblackberry\}#s", '', $row->text ); // removes {noblackberry} tags + content for no blackberry content

      } elseif (!$blackberry) {

      $row->text = preg_replace( "#\{blackberry\}(.*?)\{/blackberry\}#s", '', $row->text ); // removes {blackberry} tags + content for non blackberry devices
      $row->text = preg_replace( "#\{noblackberry\}(.*?)\{/noblackberry\}#s", '\1', $row->text ); // removes just the {noblackberry} tags from content

      }

    66. Posted on December 28th

      This plugin is fantastic. It should be in the core of joomla since it serves up a very needed feature: a way to show different content specifically made for mobile devices while the desktop content remains untouched. Thank you for writing this I hope you’ll continue to update it for future versions of joomla its really needed

    67. John Galt
      Posted on January 3rd

      We have used this in our Joomla Real Estate Websites and it works Great ! Thanks for the post and sharing and spreading the power of Joomla.

      Custom IDX Solutions

    68. Posted on January 4th

      This plugin is so simple but awesome! Just works out of the box and solves many troubles! Great! Thank you for your work!

  • Post a Comment

    Let us know what you thought.

  • Name:

    Email (required):

    Website:

    Message: