Overview

Packages

  • Auth
  • Config
  • Controller
  • Date
  • Db
  • Feed
    • Abstract
    • Writers
  • File
    • Decorator
  • Form
    • Element
  • Image
  • Log
    • Writer
  • Net
    • Exception
  • None
  • PHP
  • PHPMailer
  • Session
  • Util
  • Validate
    • Validator
  • Zend
    • Registry

Classes

  • Util_Bench
  • Util_ErrorHandler
  • Util_Pagination
  • Util_String
  • Util_Token
  • Util_UserAgent

Exceptions

  • Util_ExceptionHandler
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Pry Framework
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file LICENSE.txt.
 10:  * 
 11:  * @version $Revision: 276 $
 12:  */
 13: 
 14: /**
 15:  * Classe d"identification de navigateur internet.
 16:  * <code>
 17:  * $ua = new UserAgent();
 18:  * if($ua->isMobile()){echo 'Navigateur mobile';}
 19:  * $ua->addMobile('Mon Mobile');
 20:  * $mesMobiles = array('mobile 1', 'mobile2');
 21:  * $ua->addMobile($mesMobiles);
 22:  * $ua->removeMobile('Nokia');
 23:  * </code>
 24:  * @category Pry
 25:  * @package Util
 26:  * @author          Olivier ROGER <oroger@prynel.com>
 27:  * @version         1.1.6
 28:  *
 29:  */
 30: class Util_UserAgent
 31: {
 32: 
 33:     /**
 34:      * User agent du navigateur
 35:      * @var string
 36:      * @access private
 37:      */
 38:     private $user_agent;
 39: 
 40:     /**
 41:      * Tableau des entête mobile
 42:      * @var array
 43:      * @access private
 44:      */
 45:     private $tabOfMobile;
 46: 
 47:     /**
 48:      * Tableau des mot clé pour smartphone
 49:      *
 50:      * @var array
 51:      * @access private
 52:      */
 53:     private $tabOfSmart;
 54: 
 55:     /**
 56:      * Tableau des navigateur de bureau
 57:      * @var array
 58:      * @access private
 59:      */
 60:     private $tabDesktopBrowser;
 61: 
 62:     /**
 63:      * Taille du tableau des entêtes
 64:      * @var int
 65:      * @access private
 66:      */
 67:     private $tabSize;
 68: 
 69:     /**
 70:      * Taille du tableau des navigateurs
 71:      * @var int
 72:      * @access private
 73:      */
 74:     private $tabSizeDesktopBrowser;
 75: 
 76:     /**
 77:      * Nav Mobile ou non
 78:      * @var boolean
 79:      * @access private
 80:      */
 81:     private $mobile;
 82: 
 83:     /**
 84:      * Navigateur sur smartphone ou non
 85:      *
 86:      * @var bool
 87:      * @access private
 88:      */
 89:     private $smartphone;
 90: 
 91:     /**
 92:      * Nav "desktop" ou non
 93:      * @var boolean
 94:      * @access private
 95:      */
 96:     private $desktop;
 97: 
 98:     /**
 99:      * Le bavigateur de bureau utilisé
100:      * @var string
101:      * @access private
102:      */
103:     private $usedDesktop;
104: 
105:     /**
106:      * Le navigateur mobile détecté
107:      * @var string
108:      */
109:     private $usedMobile;
110: 
111:     /**
112:      * Constructeur
113:      * @param string $UA HTTP_USER_AGENT du navigateur
114:      */
115:     public function __construct($UA)
116:     {
117:         $this->user_agent   = $UA;
118:         $this->tabOfMobile  = array("Android",
119:             "Blazer",
120:             "Palm",
121:             "Handspring",
122:             "Nokia",
123:             "Kyocera",
124:             "Samsung",
125:             "Motorola",
126:             "Smartphone",
127:             "Windows CE",
128:             "Blackberry",
129:             "WAP",
130:             "SonyEricsson",
131:             "Pda",
132:             "Cldc",
133:             "Midp",
134:             "Symbian",
135:             "Ericsson",
136:             "Portalmmm",
137:             "PANTECH",
138:             "Bcdm",
139:             "Bvirtual",
140:             "Klondike",
141:             "Pocketpc",
142:             "Vodafone",
143:             "AvantGo",
144:             "Minimo",
145:             "iPhone",
146:             "iPod",
147:             "iPad",
148:             "HP",
149:             "LGE",
150:             "mmp",
151:             "Xda",
152:             "PSP",
153:             "phone",
154:             "mobile");
155:         $this->tabSize = count($this->tabOfMobile);
156:         $this->tabDesktopBrowser = array(
157:             "Chrome",
158:             "Netscape",
159:             "Safari",
160:             "Firefox",
161:             "Konqueror",
162:             "Epiphany",
163:             "Lynx",
164:             "MSIE",
165:             "Opera");
166:         $this->tabOfSmart = array("wap", "smartphone", "phone", "mmp", "symbian", "midp");
167:         $this->tabSizeDesktopBrowser = count($this->tabDesktopBrowser);
168:         $this->mobile = false;
169:         $this->desktop = false;
170:         $this->smartphone = false;
171:         $this->usedDesktop = 'Inconnu';
172:     }
173: 
174:     /**
175:      * Détécte si le navigateur est un navigateur d'appareil mobile;
176:      * @access public
177:      * @return boolean
178:      */
179:     public function isMobile()
180:     {
181:         for ($i = 0; $i < $this->tabSize; $i++) {
182:             if (!strripos($this->user_agent, $this->tabOfMobile[$i]) === FALSE)
183:             {
184:                 $this->mobile = true;
185:                 $this->usedMobile = $this->tabOfMobile[$i];
186:                 break;
187:             }
188:         }
189:         if ($this->mobile == false)
190:         {
191:             $this->desktop = true;
192:             $this->quelDesktop();
193:         }
194:         return $this->mobile;
195:     }
196: 
197:     /**
198:      * Détecte si l'appareil est un Iphone//Ipod touch
199:      * return boolean
200:      */
201:     public function isIphone()
202:     {
203:         if ($this->isMobile())
204:         {
205:             if (strripos($this->user_agent, 'iPhone') || strripos($this->user_agent, 'iPod'))
206:                 return true;
207:         }
208:         return false;
209:     }
210: 
211:     /**
212:      * Détecte si l'appareil est un iPad
213:      * @return boolean
214:      */
215:     public function isIpad()
216:     {
217:         if ($this->isMobile())
218:         {
219:             if (strripos($this->user_agent, 'iPad'))
220:                 return true;
221:         }
222:         return false;
223:     }
224:     
225:     /**
226:      * Détecte si le device est un device android
227:      * @return boolean 
228:      */
229:     public function isAndroid()
230:     {
231:         if ($this->isMobile())
232:             if (strripos($this->user_agent, 'Android'))
233:                 return true;
234: 
235:         return false;
236:     }
237: 
238:     /**
239:      * Détecte si l'appareil mobile est un smartphone. Si non c'est un pda
240:      * 
241:      * @access public
242:      * @return bool
243:      */
244:     public function isSmartphone()
245:     {
246:         $tailleSmart = count($this->tabOfSmart);
247:         for ($i = 0; $i < $tailleSmart; $i++) {
248:             if (!strripos($this->user_agent, $this->tabOfSmart[$i]) === FALSE)
249:             {
250:                 $this->smartphone = true;
251:                 break;
252:             }
253:         }
254:         return $this->smartphone;
255:     }
256: 
257:     /**
258:      * Détecte si le navigateur est un navigateur de bureau;
259:      * @access public
260:      * @return boolean
261:      */
262:     public function isDesktop()
263:     {
264:         if ($this->isMobile() === FALSE)
265:         {
266:             $this->desktop = true;
267:             $this->quelDesktop();
268:         }
269:         else
270:             $this->desktop = false;
271: 
272:         return $this->desktop;
273:     }
274: 
275:     /**
276:      * Retourne le navigateur de bureau utilisé
277:      * @access public
278:      * @return string
279:      */
280:     public function showDesktop()
281:     {
282:         if ($this->isDesktop() === true)
283:         {
284:             $nav = $this->usedDesktop;
285:         }
286:         else
287:         {
288:             $nav = 'Navigateur mobile';
289:         }
290:         return $nav;
291:     }
292: 
293:     /**
294:      * Retourne le navigateur mobile utilisé
295:      * @since 1.1.4
296:      * @return string
297:      */
298:     public function showMobile()
299:     {
300:         if ($this->isMobile())
301:             $nav = $this->usedMobile;
302:         else
303:             $nav = 'Desktop';
304: 
305:         return $nav;
306:     }
307: 
308:     /**
309:      * Retourne le navigateur de bureau utilisé
310:      * @access private
311:      *
312:      */
313:     private function quelDesktop()
314:     {
315:         for ($i = 0; $i < $this->tabSizeDesktopBrowser; $i++) {
316:             if (!strripos($this->user_agent, $this->tabDesktopBrowser[$i]) === FALSE)
317:             {
318:                 $this->usedDesktop = $this->tabDesktopBrowser[$i];
319:                 break;
320:             }
321:         }
322:     }
323: 
324:     /**
325:      * Ajoute un ou plusieur mobile à la liste des chaines de détection
326:      * @access public
327:      * @param string/array $input Chaine ou tableau de chaine représentant un mobile potentiel.
328:      */
329:     public function addMobile($input)
330:     {
331:         if (is_array($input))
332:         {
333:             foreach ($input as $value) {
334:                 array_push($this->tabOfMobile, $value);
335:             }
336:         }
337:         else
338:         {
339:             array_push($this->tabOfMobile, $input);
340:         }
341:         $this->tabSize = count($this->tabOfMobile);
342:         return $this->tabOfMobile;
343:     }
344: 
345:     /**
346:      * Retire un mobile au tableau des chaines de détection
347:      * @access public
348:      * @param string $valeur Chaine ou tableau de chaine représentant un mobile potentiel.
349:      */
350:     public function removeMobile($valeur)
351:     {
352:         if (in_array($valeur, $this->tabOfMobile))
353:         {
354:             $key = array_search($valeur, $this->tabOfMobile);
355:             unset($this->tabOfMobile[$key]);
356:             $this->tabSize = count($this->tabOfMobile);
357:         }
358:     }
359: 
360:     /**
361:      * Retour le user agent
362:      * @since 1.1.4
363:      * @return string
364:      */
365:     public function get()
366:     {
367:         return $this->user_agent;
368:     }
369: 
370: }
371: 
372: ?>
Pry Framework API documentation generated by ApiGen 2.6.1