Skip to content

Commit

Permalink
Upload and findById options were added, test class for extracting bro…
Browse files Browse the repository at this point in the history
…wser name and version and the test HTML and CSV output data was greatly improved.

Modified   lib/document.php
* findById: Added an options hash so that parameters like the watermark and preview can be provided.
* upload: Added an options hash for parameters like "download_document" and "download_pdf".

Modified   lib/event.php
* findAll: Removed the deprecated "m=find" parameter.

Added      test/browser_info.php
* New class that parses out the browser type from a User-Agent property.

Modified   test/index.html
* Added options to the "upload" command for "secure", "download_pdf" and "download_document".
* Added options to the "load" command for "included_pages" and the watermark label.

Modified   test/test.php
* domain: New function that returns the domain of the service URL so that it can be applied to the Javascript class.
* load_command, upload_command: Added parameter options as per the new interfaces.
* event_load_csv: Improved the order of extracted data, added a short user agent and the duration value.
* event_load_html: Improved the order of extracted data and added a short user agent.
  • Loading branch information
bmatzelle committed Oct 18, 2009
1 parent 537a809 commit 932680b
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 33 deletions.
23 changes: 12 additions & 11 deletions lib/document.php
Expand Up @@ -116,12 +116,15 @@ public static function downloadUrl($webId, $fileExtension)
/*
Finds a document by the ID. It throws a <Vuzit_ClientException> on failure.
*/
public static function findById($webId)
public static function findById($webId, $options = null)
{
$method = "show";
$params = array();

$post_params = self::postParameters($method, $params, $webId);
if($options == null) {
$options = array();
}

$post_params = self::postParameters($method, $options, $webId);

$ch = self::curlRequest();
$url = self::parametersToUrl('documents', $post_params, $webId);
Expand Down Expand Up @@ -172,21 +175,19 @@ public static function findById($webId)
/*
Uploads a file to Vuzit. It throws a <Vuzit_ClientException> on failure.
*/
public static function upload($file, $secure = true, $fileType = null)
public static function upload($file, $options = null)
{
$method = "create";
if($options == null) {
$options = array();
}

if(!file_exists($file)) {
throw new Vuzit_ClientException("Cannot find file at path: $file");
}
$options['upload'] = "@".$file;

if($fileType != null) {
$params['file_type'] = $fileType;
}
$params['secure'] = ($secure) ? '1' : '0';
$params['upload'] = "@".$file;

$post_params = self::postParameters($method, $params);
$post_params = self::postParameters($method, $options);

$ch = self::curlRequest();
$url = Vuzit_Service::getServiceUrl() . "/documents.xml";
Expand Down
2 changes: 0 additions & 2 deletions lib/event.php
Expand Up @@ -90,8 +90,6 @@ public function getPage() {
public static function findAll($webId, $options = null)
{
$method = "show";
// This will be removed soon
$options["m"] = 'find';

if(!$webId) {
throw new Vuzit_ClientException("No webId parameter specified");
Expand Down
52 changes: 52 additions & 0 deletions test/browser_info.php
@@ -0,0 +1,52 @@
<?php

/*
Loads up browser information.
*/
class BrowserInfo
{
private $name = null;
private $agent = null;
private $version = null;

/*
Returns the name of the browser.
*/
public function getName()
{
return $this->name;
}

/*
Returns the version of the browser.
*/
public function getVersion()
{
return $this->version;
}

/*
Constructor. Loads a user agent or grabs the local version.
*/
public function __construct($userAgent = null)
{
$browsers = array("firefox", "msie", "opera", "chrome", "safari",
"mozilla", "seamonkey", "konqueror", "netscape",
"gecko", "navigator", "mosaic", "lynx", "amaya",
"omniweb", "avant", "camino", "flock", "aol");

$this->agent = strtolower($userAgent);

foreach($browsers as $browser)
{
if (preg_match("#($browser)[/ ]?([0-9.]*)#", $this->agent, $match))
{
$this->name = $match[1];
$this->version = $match[2];
break;
}
}
$this->AllowsHeaderRedirect = !($this->name == "msie" && $this->version < 7);
}
}
?>
7 changes: 5 additions & 2 deletions test/index.html
Expand Up @@ -34,14 +34,17 @@ <h1>Tests</h1>
Upload parameters:
<ul>
<li>path - Path to the file to upload (REQUIRED)</li>
<li>download_pdf - Set to "1" for true or "0" for false</li>
<li>download_document - Set to "1" for true or "0" for false</li>
<li>s - secure, Set to "1" for true or "0" for false</li>
<li>p - download_pdf, Set to "1" for true or "0" for false</li>
<li>d - download_document, Set to "1" for true or "0" for false</li>
</ul>
</li>
<li>
Load parameters:
<ul>
<li>id - Document web ID (REQUIRED)</li>
<li>p - Preview range</li>
<li>w - Watermark label</li>
</ul>
</li>
<li>
Expand Down
70 changes: 52 additions & 18 deletions test/test.php
@@ -1,9 +1,17 @@
<?php
require_once '../lib/vuzit.php';
require_once 'geo_location.php';
require_once 'browser_info.php';

// GENERAL FUNCTIONS

// Returns the domain for use with the Javascript API global variables.
function domain()
{
$url = Vuzit_Service::getServiceUrl();
return substr($url, 7, strlen($url) - 7);
}

// Returns the parameter from the _GET array or null if it isn't present.
function get($key)
{
Expand Down Expand Up @@ -46,13 +54,17 @@ function header_load($doc = null)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Vuzit <?php echo get("c") ?> Command Example</title>
<link href="http://vuzit.com/stylesheets/Vuzit-2.8.css" rel="Stylesheet" type="text/css" />
<script src="http://vuzit.com/javascripts/Vuzit-2.8.js" type="text/javascript"></script>

<link href="<?php echo Vuzit_Service::getServiceUrl(); ?>/stylesheets/Vuzit-2.8.css"
rel="Stylesheet" type="text/css" />
<script src="<?php echo Vuzit_Service::getServiceUrl(); ?>/javascripts/Vuzit-2.8.js"
type="text/javascript"></script>
<script type="text/javascript">
// Called when the page is loaded.
function initialize() {
vuzit.Base.apiKeySet("<?php echo Vuzit_Service::getPublicKey(); ?>");
vuzit.Base.webServerSet({ host: '<?php echo domain(); ?>', port: '80' });
vuzit.Base.imageServerSet({ host: '<?php echo domain(); ?>', port: '80' });

var options = {signature: '<?php echo rawurlencode($sig); ?>',
timestamp: '<?php echo $timestamp ?>'}
var viewer = vuzit.Viewer.fromId("<?php echo $id; ?>", options);
Expand Down Expand Up @@ -82,7 +94,12 @@ function footer_load()
// Runs the load command
function load_command()
{
$doc = Vuzit_Document::findById(get("id"));
$options = array();
if(get("p") != null) {
$options["included_pages"] = get("p");
}

$doc = Vuzit_Document::findById(get("id"), $options);
header_load($doc);
$pdf_url = Vuzit_Document::downloadUrl($doc->getId(), "pdf");

Expand Down Expand Up @@ -127,7 +144,15 @@ function delete_command()
// Runs the upload command
function upload_command()
{
$doc = Vuzit_Document::upload(get("path"));
$options = array();
if(get("p") != null) {
$options["download_pdf"] = get("p");
}
if(get("d") != null) {
$options["download_document"] = get("d");
}

$doc = Vuzit_Document::upload(get("path"), $options);
header_load($doc);
?>
<h3>
Expand Down Expand Up @@ -174,19 +199,21 @@ function event_load_csv($list, $fileName = "events.csv")
{
$csv = '';

$csv .= csv_line(array("web_id", "event", "page", "requested_at", "value",
"remote_host", "referer", "user_agent", "zoom"));
$csv .= csv_line(array("web_id", "requested_at", "duration", "event",
"page", "value", "remote_host", "referer",
"user_agent"));
foreach($list as $event)
{
$browser = new BrowserInfo($event->getUserAgent());
$fields = array($event->getWebId(),
date("m/d/y H:i", $event->getRequestedAt()),
$event->getDuration(),
$event->getEvent(),
$event->getPage(),
date("m/d/y H:i", $event->getRequestedAt()),
$event->getValue(),
$event->getRemoteHost(),
$event->getReferer(),
$event->getUserAgent(),
$event->getZoom()
$browser->getName() . " " . $browser->getVersion()
);
$csv .= csv_line($fields);
}
Expand Down Expand Up @@ -214,16 +241,23 @@ function event_load_html($list)
$item = $list[$i];
$event--;
$host = $item->getRemoteHost();
$browser = new BrowserInfo($item->getUserAgent());
?>
<li>
[<?php echo $item->getEvent(); ?>] on page <?php echo $item->getPage(); ?>
for <?php echo $item->getDuration(); ?> seconds
at <?php echo date("Y-d-m H:i:s", $item->getRequestedAt()); ?>
(value: <?php echo $item->getValue(); ?>) -
<a href="<?php echo $item->getReferer(); ?>">Referring page</a> -
Remote host:
<a href="location.php?ip=<?php echo $host; ?>"><?php echo $host; ?></a>
- User Agent: <?php echo substr($item->getUserAgent(), 0, 5); ?>...
<?php
echo "[" . date("Y-d-m H:i:s", $item->getRequestedAt());

if($item->getEvent() == "page_view") {
echo " (" . $item->getDuration() . " s)";
}
echo "] ";
echo '"' . $item->getEvent() . '"';
echo " on page ". $item->getPage();
echo " (value: " . $item->getValue() . ")";
echo ' - <a href="' . $item->getReferer() . '">URL</a> - ';
echo ' Remote host: <a href="location.php?ip=' . $host . '">' . $host . "</a> - ";
echo $browser->getName() . " " . $browser->getVersion();
?>
</li>
<?php
}
Expand Down

0 comments on commit 932680b

Please sign in to comment.