Site to Mobile Conversion
 

Site to Mobile Conversion

on

  • 2,144 views

A brief overview of some of the different options available for converting your desktop site into a mobile site quickly and with a small budget.

A brief overview of some of the different options available for converting your desktop site into a mobile site quickly and with a small budget.

Statistics

Views

Total Views
2,144
Views on SlideShare
2,129
Embed Views
15

Actions

Likes
1
Downloads
40
Comments
0

2 Embeds 15

http://www.mikestowe.com 14
https://www.mikestowe.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Site to Mobile Conversion Site to Mobile Conversion Presentation Transcript

  • Site2MobileConversionmichael stowe AUGUST 12, 2012
  • MIKESTOWE .com• 10+ years experience hacking PHP• Published Author, Speaker, and Consultant• Developed applications used by the medical field and law enforcement• Software Engineer at CaringBridge.org (half a million visitors every day)• Zend Certified PHP 5.3 Software Engineer@mikegstowe
  • SO YOU WANT TO GO MOBILEYou have a fantastic desktop version of your website thatabsolutely rocks! But your boss just bought an iPhone,and now your boss wants a “mobile” version of the site…tomorrow!Oh yeah, and just because your boss shelled out $$$ forthat fancy iPhone, don’t expect the same for this project.Budget is everything.
  • THE GOOD NEWSNo matter what your site looks like, as long as youfollowed at least SOME standards and conventions…we can make a mobile version of it!
  • THE BAD NEWSSome ways are a lot easier than others… and if youdidn’t follow at least some conventions, well… yourboss isn’t going to be very happy budget or timewise.
  • DESIGN HELPERSFor developing a mobile version of your site, youmay find the following libraries to be useful:• jQuery Mobile• jQTouch• Sencha Touch
  • RESPONSIVE DESIGNResponsive design can be a quick and fairly easy wayto make your site more friendly for mobile users. Byusing media queries you can setup rules for how theCSS is rendered by the browser.
  • RESPONSIVE DESIGN CSS <html> <head> <!-- Using Link HREF --> <link rel="stylesheet" media="screen and (max-width: 1024px)" rel="stylesheet" href="example.css"> <!-- Using CSS --> <style type="text/css"> /* Using Import */ @import url(example.css) screen and (max-width: 1024px) /** Not as Ideal **/ @media screen and (max-width: 320px) { /** ... **/ } </style> </head> </html>
  • Image © StudioPress.com | Article
  • RESPONSIVE DESIGNHowever, if you don’t utilize CSS to handle thetemplating of your site, or if you use things liketables or flash, you’re going to run into big problems.Also, size matters, big images and excess code canmake for unpleasant loading times and experiences.
  • RESPONSIVE DESIGNOh yeah, and this is a PHP Conference, so we’re notgoing to focus on this solution.However, (advertising alert), you can learn moreabout Responsive Design and Media Queries from myMobile Presentations available athttp://www.mikestowe.com/slides
  • RESPONSIVE DESIGN + SERVER SIDEResponsive Design + Server Side, or RESS utilizesResponsive Design for templating, but also relies onback-end modifications for mobile users.RESS can be a great solution, but requires access tothe back-end code of the application, and mayrequire you to go in and make tweaks/ hacks tomake certain pages mobile friendly.
  • A PHP SKIMMERSo let’s say you have a fairly large website, or even asmall website… but you don’t have access to thedatabase/ API layer, or worse- it’s a static site writtenin HTML!As long as you followed some uniform codestandards for your pages, you can utilize theDOMDocument class to grab the content.
  • A PHP SKIMMERWith the DOMDocument class we can use theloadHTML(), loadHTMLFile(),getElementsByTagName(), andgetElementById() methods to load a HTML fileand access it’s elements.
  • A PHP SKIMMER HTML <html> <head> <title>Sample Site</title> </head> <body> <header>Header Text</header> <div id="menu">Menu Items</div> <div id="content"> <p>Hello World</p> </div> <footer>Footer Text</footer> </body> </html>
  • A PHP SKIMMER – BY ID <?php<?php$content = ;$dom = new DOMDocument();$dom->loadHTMLFile(index.html);$elem = $dom->getElementById(content);$children = $elem->childNodes;foreach ($children as $child) { $tmp_doc = new DOMDocument(); $tmp_doc->appendChild($tmp_doc->importNode($child,true)); $content .= $tmp_doc->saveHTML();}// echos "<p>Hello World</p>"echo $content;
  • A PHP SKIMMER – BY TAG <?php<?php$content = ;$dom = new DOMDocument();$dom->loadHTMLFile(index.html);$elements = $this->DOM->getElementsByTagName(header);$elem = $elements[0]; // First Element$children = $elem->childNodes;foreach ($children as $child) { $tmp_doc = new DOMDocument(); $tmp_doc->appendChild($tmp_doc->importNode($child,true)); $content .= $tmp_doc->saveHTML();}// echos "Header Text"echo $content;
  • A PHP SKIMMERUnfortunately, DOMDocument doesn’t allow us tolocate elements by class name, nor does it formatthe content for mobile devices (ie resizing images).Fortunately, there is an pre-existing script based onDOMDocument and designed for mobileimplementation that does both (and also performsCaching) – DomRipper.Download DomRipper at github.com/mikestowe.com/DomRipper
  • A PHP SKIMMER – DOMRIPPER <?php <?php $dom = new DomRipper(); // echos "Header Text" echo $doc->fetch(index.html,header, tag); // echos "<p>Hello World</p>" echo $doc->fetch(index.html,content);Download DomRipper at github.com/mikestowe.com/DomRipper
  • SIMPLE TEMPLATINGOne of the easiest ways (especially for informationalsites or CSS driven sites) is to simply switch out theheader and footer.This is usually the FASTEST solution, as long as yourheader and footer files are used across the platformand you do not use a lot of fancy features (drag anddrop JavaScript is bad).
  • SIMPLE TEMPLATING <?php <?php // Header File $mobile = new MobileCheck(); if ($mobile->isMobile()) { require_once(mobile_header.php); } else { // Header contents moved to a new file require_once(desktop_header.php); }Download DomRipper at github.com/mikestowe.com/DomRipper
  • DATABASE/ API LAYEROf course, if we have a database driven site, and wehave access to the database/ API layer, this providesus with an even more efficient and flexible solution.
  • DATABASE/ API LAYER BASIC <?php <?php $api = new ApiLayer(/path/to/file); ?> <html> <!-- Mobile Header --> Name: <?php echo $api->user->name; ?><br /> Email: <?php echo $api->user->email; ?> <br /><br /> <strong>Sites:</strong><br /> <?php foreach ($api->user->sites as $site) { echo $site->siteName . <br />; } ?> <!-- Mobile Footer --> </html>Data can be pulled in through a simple JSON call and requires no work on themobile platform other than decoding
  • DATABASE/ API LAYER <?php <?php $api = new ApiLayer(); ?> <html> <!-- Mobile Header --> Name: <?php echo $api->user()->name; ?><br /> Email: <?php echo $api->user()->email; ?> <br /><br /> <strong>Sites:</strong><br /> <?php foreach ($api->user()->getSites() as $site) { echo $site->siteName . <br />; } ?> <!-- Mobile Footer --> </html>Initial data is called in, but the ApiLayer has the ability to continuing grabbinginformation from the host, and requires access to the necessary classes.
  • DATABASE/ API LAYERA properly designed API layer will provide yourmobile platform with all of the data necessary toperform the same functionality as your desktopversion.While setting up the API Layer initially takes moretime, it provides incredible flexibility and allows forincreased efficiency.
  • TRANSLATION ENGINEFor sites that offer multiple languages/ translations,having a centralized translation engine that allows formobile translations (which may differ from desktoptranslations) may be beneficial.If you already have a database with key, language,and translation columns, you may want to add acolumn for “platform.”
  • TRANSLATION ENGINE <?php<?phpfunction getMobileTranslation($key, $language){ $db = new Database(); $query = SELECT `translation` FROM translations WHERE key = ? AND language = ? AND platform = ?; $row = $db->fetch($query, $key, $language, mobile); if (!$row) { $row = $db->fetch($query, $key, $language, desktop); } return $row;}echo getMobileTranslation(welcomeText, en);
  • TRANSLATION ENGINEThe mobile translation engine can be setup either onthe mobile platform, or it can be setup on the hostAPI platform, allowing for any future changes to thetranslations system to be modified all at once.The translation engine would then be made availableto the mobile platform through the API Layer.
  • FRAMEWORKSMany popular frameworks allow not only for rapidapplication development, but also provide the abilityto modify the view layer.This allows your site to operate under the samecode, but with a separate interface for your users.
  • FRAMEWORKSBecause you are using the same code for youractions, but have the ability to set unique templates,views, pull in or remove scripts, etc; Frameworksallow for the greatest flexibility while beingtremendously efficient.
  • FRAMEWORKSTechniques:• Modify the Template (choose a mobile template)• Modify the View (change the file used for the view)• Modify the Context-Type (ie return JSON).
  • FRAMEWORK CONTROLLER VIEW <?php <?php class MyController extends MyControllerAbstract { public function myAction() { parent::handleMobile(); /** Controller Contents **/ } }Example for ZendFramework 1
  • FRAMEWORK ABSTRACT FOR VIEW <?php <?php abstract class myControllerAbstract extends ZendControllerAbstract { protected function handleMobile($altView = null, $altTemplate = null) { $mobile = new MobileHandler(); // new class we created if($mobile->isMobile()) { if ($altView) { $this->view->render($altView); } $template = $altTemplate ? $altTemplate : mobile.html; $this->_helper->_layout->setLayoutetLayout($template); } } }Example for ZendFramework 1
  • FRAMEWORK CONTEXT SWITCHER <?php <?php class MyController extends MyControllerAbstract { public function myAction() { $viewVariables = array(item1 => hello, item2 => world); if ($this -> params() -> fromQuery(context) == json) { $result = new JsonModel(); $result -> setTerminal(true); $result -> setVariables($viewVariables); return $result; } return $viewVariables; } }Example for ZendFramework 2
  • FRAMEWORKSSome of the more popular frameworks out thereinclude:• Zend Framework• CakePHP• CodeIgnighter• Symphony• Yii
  • OVERVIEW OF SOLUTIONS Platform User Tactic Efficiency Flexibility Tie-In FriendlyResponsive DesignRESSSkimmerSimple TemplateAPI LayerFramework Good So-So Poor
  • IN SUMMARYIn the end, the best solution is the one that fits yourcurrent infrastructure, your capabilities, yourtimeline, and your budget.While some solutions certainly provide greaterefficiency, flexibility, and the best user experience - ifit isn’t feasible something is usually better thannothing.
  • THANK YOU. @mikegstowevisit mikestowe.com/slides for more on Mobile and PHP