|
|
@@ -93,18 +93,9 @@
|
|
|
<listitem>
|
|
|
<para>
|
|
|
<link
|
|
|
- linkend="zend.http.user-agent-features-wurfl">Zend_Http_UserAgent_Features_Adapter_Wurfl</link>
|
|
|
- consumes the <ulink url="http://wurfl.sourceforge.net/">WURFL</ulink> (Wireless
|
|
|
- Universal Resource File) PHP API. This database is considered one of the most
|
|
|
- comprehensive mobile device capabilities databases available.
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
-
|
|
|
- <listitem>
|
|
|
- <para>
|
|
|
- <link
|
|
|
linkend="zend.http.user-agent-features-tera-wurfl">Zend_Http_UserAgent_Features_Adapter_TeraWurfl</link>
|
|
|
- consumes the TeraWurfl API, which is built on top of <acronym>WURFL</acronym>,
|
|
|
+ consumes the TeraWurfl API, which is built on top of <ulink
|
|
|
+ url="http://wurfl.sourceforge.net/"><acronym>WURFL</acronym></ulink>,
|
|
|
and aimed at providing a highly available, highly performant lookup mechanism.
|
|
|
</para>
|
|
|
</listitem>
|
|
|
@@ -124,105 +115,56 @@
|
|
|
<title>Quick Start</title>
|
|
|
|
|
|
<para>
|
|
|
- First, you will need to download the following:
|
|
|
+ First, you will need to download the <filename>php_browscap.ini</filename> if you do not
|
|
|
+ already have it installed on your system:
|
|
|
</para>
|
|
|
|
|
|
<itemizedlist>
|
|
|
<listitem>
|
|
|
<para>
|
|
|
- The <acronym>WURFL</acronym> <ulink
|
|
|
- url="http://sourceforge.net/projects/wurfl/files/WURFL%20PHP/1.1/wurfl-php-1.1.tar.gz/download">PHP
|
|
|
- API</ulink>. This archive contains the most recent
|
|
|
- <filename>wurfl-latest.xml</filename> file and patches which constitute the
|
|
|
- actual <acronym>WURFL</acronym> database.
|
|
|
+ <ulink url="http://browsers.garykeith.com/stream.asp?PHP_BrowsCapINI">php_browscap.ini</ulink>
|
|
|
</para>
|
|
|
</listitem>
|
|
|
</itemizedlist>
|
|
|
|
|
|
<para>
|
|
|
- We suggest that you inflate this archive in your "library" directory. Inflating the
|
|
|
- archive will create a <filename>wurfl-php-1.1</filename> directory.
|
|
|
+ We suggest that you put the file in the same directory as your
|
|
|
+ <filename>php.ini</filename>.
|
|
|
</para>
|
|
|
|
|
|
- <programlisting language="text"><![CDATA[
|
|
|
-library
|
|
|
-|-- wurfl-php-1.1
|
|
|
-| |-- COPYING
|
|
|
-| |-- docs
|
|
|
-| |-- examples
|
|
|
-| |-- README
|
|
|
-| |-- tests
|
|
|
-| `-- WURFL
|
|
|
-]]></programlisting>
|
|
|
-
|
|
|
<para>
|
|
|
- Next, create a data and cache directory for the <acronym>WURFL</acronym> database and
|
|
|
- related cache files; this should be done from your project root (the directory
|
|
|
- containing the <filename>application</filename> and <filename>library</filename>
|
|
|
- directories). When you do so, make sure the directory is at least writable by the web
|
|
|
- server user; the following makes it writable for all users.
|
|
|
+ Next, notify PHP of the browscap file via the <varname>browscap</varname> setting.
|
|
|
+ Because this setting is of type <constant>PHP_INI_SYSTEM</constant>, this must be done
|
|
|
+ either in your <filename>php.ini</filename> or web server configuration; it cannot be
|
|
|
+ done in <filename>htaccess</filename> or via <function>ini_set()</function>. We
|
|
|
+ recommend adding it to your <filename>php.ini</filename>.
|
|
|
</para>
|
|
|
|
|
|
- <programlisting language="sh"><![CDATA[
|
|
|
-mkdir -p data/wurfl/cache
|
|
|
-chmod -R o+rwX data/wurfl/cache
|
|
|
-]]></programlisting>
|
|
|
-
|
|
|
- <para>
|
|
|
- Now, copy the <acronym>WURFL</acronym> data from the inflated archive into your data
|
|
|
- directory.
|
|
|
- </para>
|
|
|
-
|
|
|
- <programlisting language="sh"><![CDATA[
|
|
|
-cp library/wurfl-php-1.1/tests/resources/wurfl-latest.zip data/wurfl/
|
|
|
-cp library/wurfl-php-1.1/tests/resources/web_browsers_patch.xml data/wurfl/
|
|
|
+ <programlisting language="ini"><![CDATA[
|
|
|
+browscap = /path/to/php_browscap.ini
|
|
|
]]></programlisting>
|
|
|
|
|
|
<para>
|
|
|
- Create a <acronym>WURFL</acronym> configuration file named
|
|
|
- <filename>application/configs/wurfl-config.php</filename>, with the following contents:
|
|
|
+ If you put <varname>php_browscap.ini</varname> in the same directory as your
|
|
|
+ <filename>php.ini</filename>, this can be reduced to simply:
|
|
|
</para>
|
|
|
|
|
|
- <programlisting language="php"><![CDATA[
|
|
|
-$resourcesDir = dirname(__FILE__) . '/../../data/wurfl/';
|
|
|
-
|
|
|
-$wurfl['main-file'] = $resourcesDir . 'wurfl-latest.zip';
|
|
|
-$wurfl['patches'] = array($resourcesDir . 'web_browsers_patch.xml');
|
|
|
-
|
|
|
-$persistence['provider'] = 'file';
|
|
|
-$persistence['dir'] = $resourcesDir . 'cache/';
|
|
|
-
|
|
|
-$cache['provider'] = null;
|
|
|
-
|
|
|
-$configuration['wurfl'] = $wurfl;
|
|
|
-$configuration['persistence'] = $persistence;
|
|
|
-$configuration['cache'] = $cache;
|
|
|
+ <programlisting language="ini"><![CDATA[
|
|
|
+browscap = php_browscap.ini
|
|
|
]]></programlisting>
|
|
|
|
|
|
<para>
|
|
|
- Finally, edit your <filename>application.ini</filename> to add the following lines to your
|
|
|
+ Now, edit your <filename>application.ini</filename> to add the following lines to your
|
|
|
<varname>[production]</varname> section:
|
|
|
</para>
|
|
|
|
|
|
<programlisting language="ini"><![CDATA[
|
|
|
-resources.useragent.wurflapi.wurfl_api_version = "1.1"
|
|
|
-resources.useragent.wurflapi.wurfl_lib_dir = APPLICATION_PATH "/../library/wurfl-php-1.1/WURFL/"
|
|
|
-resources.useragent.wurflapi.wurfl_config_file = APPLICATION_PATH "/configs/wurfl-config.php"
|
|
|
+resources.useragent.mobile.features.classname = "Zend_Http_UserAgent_Device_Features_Browscap"
|
|
|
]]></programlisting>
|
|
|
|
|
|
- <note>
|
|
|
- <para>
|
|
|
- The trailing directory separator on the <constant>wurfl_lib_dir</constant> setting
|
|
|
- is important. The <acronym>WURFL</acronym> API does no normalization, and expects
|
|
|
- it to be there.
|
|
|
- </para>
|
|
|
- </note>
|
|
|
-
|
|
|
<para>
|
|
|
- At this point, everything is setup. The first request (from a mobile device) will populate the
|
|
|
- <acronym>WURFL</acronym> cache by parsing the <filename>resources/wurfl.xml</filename>
|
|
|
- file, and as such may take up to a minute. After that, lookups will be quite fast, and
|
|
|
- each request will contain detailed information on the user agent.
|
|
|
+ At this point, everything is setup. Each request will contain detailed information on
|
|
|
+ the user agent.
|
|
|
</para>
|
|
|
|
|
|
<para>
|
|
|
@@ -261,23 +203,25 @@ $userAgent = $this->userAgent();
|
|
|
capabilities.
|
|
|
</para>
|
|
|
|
|
|
+
|
|
|
<programlisting language="php"><![CDATA[
|
|
|
-$width = $userAgent->getDevice()->getPhysicalScreenWidth();
|
|
|
+$device = $userAgent->getDevice();
|
|
|
+
|
|
|
+$cssSupport = $device->getFeature('cssversion');
|
|
|
+$jsSupport = $device->getFeature('javascript');
|
|
|
+
|
|
|
switch (true) {
|
|
|
- case ($width <= 128):
|
|
|
- $layout->setLayout('layout-poor');
|
|
|
- break;
|
|
|
- case ($width <= 176):
|
|
|
- $layout->setLayout('layout-medium');
|
|
|
+ case ($jsSupport && $cssSupport >= 3):
|
|
|
+ $layout->setLayout('layout-html5');
|
|
|
break;
|
|
|
- case ($width <= 240):
|
|
|
- $layout->setLayout('layout-high');
|
|
|
+ case ($jsSupport && $cssSupport < 3):
|
|
|
+ $layout->setLayout('layout-xhtml');
|
|
|
break;
|
|
|
- case ($width <= 320):
|
|
|
- $layout->setLayout('layout-ultra');
|
|
|
+ case (!$jsSupport && $cssSupport < 3):
|
|
|
+ $layout->setLayout('layout-html-transitional');
|
|
|
break;
|
|
|
default:
|
|
|
- // use default
|
|
|
+ $layout->setLayout('layout-web-1');
|
|
|
break;
|
|
|
}
|
|
|
]]></programlisting>
|
|
|
@@ -285,7 +229,8 @@ switch (true) {
|
|
|
<para>
|
|
|
Finally, each device will often have a large number of capabilities not immediately
|
|
|
represented in the device interface. You can query these using the
|
|
|
- <methodname>hasFeature()</methodname> and <methodname>getFeature()</methodname> methods.
|
|
|
+ <methodname>hasFeature()</methodname> and <methodname>getFeature()</methodname> methods,
|
|
|
+ or simply grab all of them with <methodname>getAllFeatures()</methodname>.
|
|
|
</para>
|
|
|
|
|
|
<programlisting language="php"><![CDATA[
|
|
|
@@ -303,23 +248,9 @@ if ($userAgent->hasFeature('mp3') && $userAgent->getFeature('mp3')) {
|
|
|
|
|
|
<para>
|
|
|
The following options may be passed to the constructor or within your application
|
|
|
- configuration. A "." indicates another layer of depth in the configuration array; as
|
|
|
- an example, assigning "wurflapi.wurfl_config_array.wurfl.main-file" as part of a PHP
|
|
|
- configuration would require the following definition:
|
|
|
+ configuration. A "." indicates another layer of depth in the configuration array.
|
|
|
</para>
|
|
|
|
|
|
- <programlisting language="php"><![CDATA[
|
|
|
-$config = array(
|
|
|
- 'wurflapi' => array(
|
|
|
- 'wurfl_config_array' => array(
|
|
|
- 'wurfl' => array(
|
|
|
- 'main-file' => 'path/to/some/file',
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
-);
|
|
|
-]]></programlisting>
|
|
|
-
|
|
|
<para>
|
|
|
Each features adapter has its own options available as well, which may be mixed in
|
|
|
with the general UserAgent options.
|
|
|
@@ -491,97 +422,6 @@ resources.useragent.bot.device.prefix = "Mobile_Device"
|
|
|
</para>
|
|
|
</listitem>
|
|
|
</varlistentry>
|
|
|
-
|
|
|
- <varlistentry>
|
|
|
- <term>wurflapi.wurfl_api_version</term>
|
|
|
-
|
|
|
- <listitem>
|
|
|
- <para>
|
|
|
- If using the <acronym>WURFL</acronym> API, use this key to specify which
|
|
|
- version you are using; typically, this will be either "1.0" or "1.1".
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
- </varlistentry>
|
|
|
-
|
|
|
- <varlistentry>
|
|
|
- <term>wurflapi.wurfl_lib_dir</term>
|
|
|
-
|
|
|
- <listitem>
|
|
|
- <para>
|
|
|
- If using the <acronym>WURFL</acronym> API, use this key to specify in which
|
|
|
- directory the library exists.
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
- </varlistentry>
|
|
|
-
|
|
|
- <varlistentry>
|
|
|
- <term>wurflapi.wurfl_config_file</term>
|
|
|
-
|
|
|
- <listitem>
|
|
|
- <para>
|
|
|
- If using the <acronym>WURFL</acronym> API, use this key to specify the
|
|
|
- location of the configuration file you will use; typically, this will be
|
|
|
- <filename>resources/wurfl-config.php</filename> within the
|
|
|
- <varname>wurfl_lib_dir</varname>.
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
- </varlistentry>
|
|
|
-
|
|
|
- <varlistentry>
|
|
|
- <term>wurflapi.wurfl_config_array.wurfl.main-file</term>
|
|
|
-
|
|
|
- <listitem>
|
|
|
- <para>
|
|
|
- If using version 1.1 of the <acronym>WURFL</acronym> API, you can omit using
|
|
|
- a <varname>wurfl_config_file</varname>, and instead provide an associative
|
|
|
- array of configuration values. This particular value indicates the location
|
|
|
- of the <filename>wurfl.xml</filename> file containing the actual
|
|
|
- <acronym>WURFL</acronym> database.
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
- </varlistentry>
|
|
|
-
|
|
|
- <varlistentry>
|
|
|
- <term>wurflapi.wurfl_config_array.wurfl.patches[]</term>
|
|
|
-
|
|
|
- <listitem>
|
|
|
- <para>
|
|
|
- If using version 1.1 of the <acronym>WURFL</acronym> API, you can omit using
|
|
|
- a <varname>wurfl_config_file</varname>, and instead provide an associative
|
|
|
- array of configuration values. This particular value is an array of file
|
|
|
- locations containing patchfiles for the <varname>wurfl.main-file</varname>
|
|
|
- (which are used to ammend and extend the primary database file).
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
- </varlistentry>
|
|
|
-
|
|
|
- <varlistentry>
|
|
|
- <term>wurflapi.wurfl_config_array.persistence.provider</term>
|
|
|
-
|
|
|
- <listitem>
|
|
|
- <para>
|
|
|
- If using version 1.1 of the <acronym>WURFL</acronym> API, you can omit using
|
|
|
- a <varname>wurfl_config_file</varname>, and instead provide an associative
|
|
|
- array of configuration values. This particular value indicates the type of
|
|
|
- persistence provider used when caching discovered capabilities. See the
|
|
|
- <acronym>WURFL</acronym> documentation for potential values; "file" is a
|
|
|
- known good value.
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
- </varlistentry>
|
|
|
-
|
|
|
- <varlistentry>
|
|
|
- <term>wurflapi.wurfl_config_array.persistence.dir</term>
|
|
|
-
|
|
|
- <listitem>
|
|
|
- <para>
|
|
|
- If using version 1.1 of the <acronym>WURFL</acronym> API, you can omit using
|
|
|
- a <varname>wurfl_config_file</varname>, and instead provide an associative
|
|
|
- array of configuration values. This particular value indicates the location
|
|
|
- where the persistence provider will cache discovered capabilities.
|
|
|
- </para>
|
|
|
- </listitem>
|
|
|
- </varlistentry>
|
|
|
</variablelist>
|
|
|
</sect2>
|
|
|
|