Permalink
Browse files

first version

  • Loading branch information...
kei horikita
kei horikita committed Jun 30, 2008
1 parent 3f4f54c commit 74375ad48aefcd9c430d82315e367f45ba77c18a
Showing with 1,027 additions and 0 deletions.
  1. +127 −0 GPS.php
  2. +129 −0 GPS/Docomo.php
  3. +118 −0 GPS/Exception.php
  4. +120 −0 GPS/Ezweb.php
  5. +93 −0 GPS/Provider.php
  6. +151 −0 GPS/Softbank.php
  7. +120 −0 GPS/Willcom.php
  8. +68 −0 package.xml
  9. +101 −0 package2.xml
View
127 GPS.php
@@ -0,0 +1,127 @@
+<?php
+/**
+ * +----------------------------------------------------------------------+
+ * | PEAR :: Net :: UserAgent :: Mobile :: GPS |
+ * +----------------------------------------------------------------------+
+ * | Copyright (c) 2008 Kei Horikita |
+ * +----------------------------------------------------------------------+
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | * Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | * Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in |
+ * | the documentation and/or other materials provided with the |
+ * | distribution. |
+ * | * The names of its contributors may be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
+ * | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
+ * | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
+ * | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
+ * | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
+ * | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
+ * | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
+ * | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
+ * | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
+ * | POSSIBILITY OF SUCH DAMAGE. |
+ * +----------------------------------------------------------------------+
+ *
+ * PHP versions 5
+ *
+ * @category Net
+ * @package Net_UserAgent_Mobile_GPS
+ * @author Kei Horikita <gps4mobile@gmail.com>
+ * @copyright 2008 Kei Horikita
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @version CVS: $Id$
+ * @link http://mgps.org
+ */
+
+require_once 'Net/UserAgent/Mobile/GPS/Exception.php';
+
+/**
+ * GPS class
+ *
+ * This class provides a method to judge the device type
+ * and create the object for provicder
+ *
+ * @category Net
+ * @package Net_UserAgent_Mobile_GPS
+ * @author Kei Horikita <gps4mobile@gmail.com>
+ * @copyright 2008 Kei Horikita
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @version Release: 0.0.1
+ * @link http://mgps.org
+ */
+abstract class Net_UserAgent_Mobile_GPS
+{
+ /**
+ * constructor to prevent instantiation.
+ */
+ private final function __construct()
+ {
+ }
+
+ /**
+ * To judge the divice type
+ *
+ * @param object &$agent Net_UserAgent_Mobile object
+ *
+ * @return device type
+ *
+ * @throws Net_UserAgent_Mobile_GPS_Exception
+ */
+ static public function factory( &$agent = null )
+ {
+ if ( $agent === null ) {
+ include_once 'Net/UserAgent/Mobile.php';
+ $agent = Net_UserAgent_Mobile::singleton();
+ }
+
+ switch ( true ) {
+ case $agent->isDoCoMo() :
+ $_class = 'Docomo';
+ break;
+ case $agent->isSoftBank() :
+ $_class = 'Softbank';
+ break;
+ case $agent->isEzweb() :
+ $_class = 'Ezweb';
+ break;
+ case $agent->isWillcom() :
+ $_class = 'Willcom';
+ break;
+ default :
+ throw new Net_UserAgent_Mobile_GPS_Exception('Cannot detect device.
+ Please try me with mobile device');
+ break;
+ }
+
+ $classfile = 'GPS/' . $_class . '.php';
+ if ( !@fclose(@fopen($classfile, 'r', true)) ) {
+ throw new Net_UserAgent_Mobile_GPS_Exception('No driver for ' . $_class);
+ }
+
+ include_once $classfile;
+ $classname = 'Net_UserAgent_Mobile_GPS_' . $_class;
+
+ if ( class_exists($classname) === false ) {
+ throw new Net_UserAgent_Mobile_GPS_Exception('The driver does not hvae '
+ . $classname);
+ }
+
+ return new $classname($agent);
+ }
+
+}
+
+?>
View
@@ -0,0 +1,129 @@
+<?php
+/**
+ * +----------------------------------------------------------------------+
+ * | PEAR :: Net :: UserAgent :: Mobile :: GPS |
+ * +----------------------------------------------------------------------+
+ * | Copyright (c) 2008 Kei Horikita |
+ * +----------------------------------------------------------------------+
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | * Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | * Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in |
+ * | the documentation and/or other materials provided with the |
+ * | distribution. |
+ * | * The names of its contributors may be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
+ * | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
+ * | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
+ * | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
+ * | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
+ * | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
+ * | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
+ * | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
+ * | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
+ * | POSSIBILITY OF SUCH DAMAGE. |
+ * +----------------------------------------------------------------------+
+ *
+ * PHP versions 5
+ *
+ * @category Net
+ * @package Net_GPS
+ * @author Kei Horikita <gps4mobile@gmail.com>
+ * @copyright 2008 Kei Horikita
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @version CVS: $Id$
+ * @link http://mgps.org
+ */
+
+require_once 'Net/UserAgent/Mobile/GPS.php';
+require_once 'Net/UserAgent/Mobile/GPS/Provider.php';
+
+/**
+ * Net_UserAgent_Mobile_GPS_Docomo class
+ *
+ * This class provides a method to create a link for GPS
+ * and to parse a response from GPS
+ *
+ * @category Net
+ * @package Net_UserAgent_Mobile_GPS
+ * @author Kei Horikita <gps4mobile@gmail.com>
+ * @copyright 2008 Kei Horikita
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @version Release: 0.0.1
+ * @link http://mgps.org
+ */
+class Net_UserAgent_Mobile_GPS_Docomo extends Net_UserAgent_Mobile_GPS_Provider
+{
+ /**
+ * Net_UserAgent_Mobile object
+ * @var Net_UserAgent_Mobile
+ */
+ private $_agent = null;
+
+ /**
+ * Constructor, sets the User Agent object's
+ *
+ * @param object $agent Net_UserAgent_Mobile object
+ */
+ public function __construct($agent = null)
+ {
+ if ( $agent === null ) {
+ include_once 'Net/UserAgent/Mobile.php';
+ $agent = Net_UserAgent_Mobile::singleton();
+ }
+
+ $this->_agent = $agent;
+ }
+
+ /**
+ * Get Link for GPS
+ *
+ * @param string $callback_url url to get GPS information and return
+ * @param string $str string for link <a href=''>string</a>
+ *
+ * @return array array with the following items: (string)url, (string)tag
+ */
+ public function getGPSLink($callback_url, $str = null)
+ {
+ $_url = '';
+ $_tag = '';
+
+ if ( $this->_agent->isFOMA() ) {
+ $_url = $callback_url;
+ $_tag = "<a href=\"${_url}\" lcs>${str}</a>";
+ }
+
+ return array('url' => $_url, 'tag' => $_tag);
+ }
+
+ /**
+ * Parse Response from GPS
+ *
+ * @return array array with the following items:
+ * (string)longitude, (string)latitude
+ */
+ public function getGPSResponse()
+ {
+ $_lat = '';
+ $_lon = '';
+
+ if ( $this->_agent->isFOMA() ) {
+ $_lat = $_GET['lat'];
+ $_lon = $_GET['lon'];
+ }
+
+ return array('lat' => $_lat, 'lon' => $_lon);
+ }
+}
+?>
View
@@ -0,0 +1,118 @@
+<?php
+/**
+ * +----------------------------------------------------------------------+
+ * | PEAR :: Net :: UserAgent :: Mobile :: GPS |
+ * +----------------------------------------------------------------------+
+ * | Copyright (c) 2008 Kei Horikita |
+ * +----------------------------------------------------------------------+
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | * Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | * Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in |
+ * | the documentation and/or other materials provided with the |
+ * | distribution. |
+ * | * The names of its contributors may be used to endorse or promote |
+ * | products derived from this software without specific prior written |
+ * | permission. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
+ * | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
+ * | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
+ * | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
+ * | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
+ * | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
+ * | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
+ * | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
+ * | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
+ * | POSSIBILITY OF SUCH DAMAGE. |
+ * +----------------------------------------------------------------------+
+ *
+ * PHP versions 5
+ *
+ * @category Net
+ * @package Net_UserAgent_Mobile_GPS
+ * @author Kei Horikita <gps4mobile@gmail.com>
+ * @copyright 2008 Kei Horikita
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @version CVS: $Id$
+ * @link http://mgps.org
+ */
+
+require_once 'PEAR/Exception.php';
+
+/**
+ * Net_GPS_Exception class
+ *
+ * This class provides a exception for Net_GPS
+ *
+ * @category Net
+ * @package Net_UserAgent_Mobile_GPS
+ * @author Kei Horikita <gps4mobile@gmail.com>
+ * @copyright 2008 Kei Horikita
+ * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
+ * @version Release: 0.0.1
+ * @link http://mgps.org
+ */
+class Net_UserAgent_Mobile_GPS_Exception extends PEAR_Exception
+{
+ /**
+ * stack error message
+ * @var array
+ */
+ protected $errors = array();
+
+ /**
+ * Add error message to the internal error stack
+ *
+ * @param string $error Error message
+ *
+ * @return void
+ */
+ public function addError($error)
+ {
+ $this->errors[] = $error;
+ }
+
+ /**
+ * Add multiple error messages to the internal error stack
+ *
+ * @param array $errors Array of error messages
+ *
+ * @return void
+ */
+ public function addErrors($errors)
+ {
+ $this->errors = array_merge($this->errors, $errors);
+ }
+
+ /**
+ * Determine if the exception contains error messages in the internal stack
+ *
+ * @return boolean True if the stack contains errors, false otherwise
+ */
+ public function hasErrors()
+ {
+ return (count($this->errors) > 0);
+ }
+
+ /**
+ * Get list of error messages from the internal error stack
+ *
+ * This method may be used to generate a list of error messages
+ * that have been returned from the Yahoo API.
+ *
+ * @return array List of error messages
+ */
+ public function getErrors()
+ {
+ return $this->errors;
+ }
+}
Oops, something went wrong.

0 comments on commit 74375ad

Please sign in to comment.