|
About:
Tera-WURFL is a PHP class that can identify the
capabilities of mobile devices using the
standardized Wireless Universal Resource File
(WURFL). This implementation uses the same methods
as the stock PHP WURFL library, but significantly
improves performance by storing the WURFL data in
a MySQL database. You can also obtain a thumbnail
image of the device and include your own device
definitions in a patch file. It can figure out if
the client visiting your site is a mobile device
or a desktop Web browser. It can also identify a
wide variety of capabilities.
Author:
Steve Kamerman [contact developer]
Homepage:
http://www.tera-wurfl.com
Zip:
http://devel.teratechnologies.net/tera-wurfl/tera_wurfl-stable_v1.5.2.zip
Demo site:
http://devel.tera-tones.com:8000/ringtones/tera_wurfl/admin/
Trove categories:
[change]
Dependencies:
[change]
No dependencies filed
|
|
» Rating:
(not rated)
» Vitality: 0.00% (Rank 8801)
» Popularity: 0.31% (Rank 17333)

(click to enlarge graphs)
Record hits: 3,753
URL hits: 843
Subscribers: 7
|
|
Branches
Comments
[»]
PHP5 + MySQL5 Version
by Steve Kamerman - Oct 31st 2006 18:31:25
I've been playing around with MySQL 5's Stored Procedures a bit, and I
completely implemented the searching section of
$obj->getDeviceCapabilitesFromAgent method in 1 stored procedure.
This one is a mouthfull but could speed things up significantly!
CREATE PROCEDURE `findUserAgent`(IN minlen INT, IN ua VARCHAR(128), IN
preferroot TINYINT)
findua:BEGIN
DECLARE curlen INT;
DECLARE prematch VARCHAR(45) DEFAULT NULL;
DECLARE matches INT DEFAULT 0;
DECLARE maxmatch INT DEFAULT 0;
/* Look for an exact match first */
SELECT deviceID INTO prematch FROM tera_wurfl_hybrid WHERE user_agent=ua
LIMIT 1;
IF prematch IS NOT NULL
THEN
/* Found an exact match - done. */
SELECT "Matched Exactly" AS match_type;
SELECT * FROM tera_wurfl_hybrid WHERE deviceID=prematch;
LEAVE findua;
END IF;
/* See if there is ever going to be a match */
SELECT COUNT(user_agent) INTO maxmatch FROM tera_wurfl_hybrid WHERE
user_agent LIKE (CONCAT(LEFT(ua,minlen),'%'));
IF maxmatch = 0
THEN
/* No matches were found, even down to the smallest char length - we
don't need to continue */
SELECT "Will Never Match" AS match_type;
LEAVE findua;
END IF;
/* We've already tested the full length and the smallest length, so don't
test them again */
SELECT LEFT(ua, curlen - 1 ) INTO ua;
SET minlen = minlen + 1;
SELECT CHAR_LENGTH(ua) INTO curlen;
WHILE ( curlen > minlen AND matches = 0) DO
SELECT COUNT(user_agent) INTO matches FROM tera_wurfl_hybrid WHERE
user_agent LIKE CONCAT(ua,'%');
IF matches > 0 AND curlen > minlen
THEN
SELECT "Matched After Trimming" AS match_type;
IF preferroot = 1
THEN
/* We would prefer a device root if there are multiple matching user
agents */
SELECT * FROM tera_wurfl_hybrid WHERE user_agent LIKE CONCAT(ua,'%')
ORDER BY actual_device_root DESC LIMIT 1;
LEAVE findua;
ELSE
/* We could really through a 'ORDER BY RAND() ' in there if we wanted
to get creative */
SELECT * FROM tera_wurfl_hybrid WHERE user_agent LIKE CONCAT(ua,'%')
ORDER BY actual_device_root ASC LIMIT 1;
LEAVE findua;
END IF;
END IF;
SELECT LEFT(ua, curlen - 1 ) INTO ua;
SELECT CHAR_LENGTH(ua) INTO curlen;
END WHILE;
/*SELECT "done" AS `status`;*/
SELECT "Did Not Match" AS match_type;
END
I may branch off the main PHP4+MySQL4 version and make a new version using
this method since it's so fast.
This is auto formatted very poorly so if you want a copy of it in a
different form let me know.
[reply]
[top]
|