cvs: pear /HTML_Progress/examples/preload shockwaveflash.html shockwaveflash.php sw4p.html

From: Date: Sun, 27 Jun 2004 14:03:51 +0000
Subject: cvs: pear /HTML_Progress/examples/preload shockwaveflash.html shockwaveflash.php sw4p.html
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-21191@lists.php.net to get a copy of this message
farell Sun Jun 27 10:03:51 2004 EDT Added files: /pear/HTML_Progress/examples/preload shockwaveflash.html shockwaveflash.php sw4p.html Log: HTML_Progress examples reorganized by category http://cvs.php.net/co.php/pear/HTML_Progress/examples/preload/shockwaveflash.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/preload/shockwaveflash.html +++ pear/HTML_Progress/examples/preload/shockwaveflash.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="robots" content="index,nofollow" > <meta name="keywords" content"="HTML_Progress, HTTP_Request, preload, progress meter" /> <meta name="description" content"="HTML_Progress in action with HTTP_Request" /> <meta name="author" content="Laurent Laville" /> <title>PEAR::HTML::Progress example: Listener usage with HTTP_Request</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="../examples.css" /> </head> <body> <a name="top"> <p><a href="../index.html"><img src="../images/home.gif" alt="Examples TOC"/>examples</a></p> <h1><span class="chapter">Preload Shockwave Flash object </span></h1> <p align="right">$Date: 2004/06/27 14:03:50 $</p> <div class="toc">&nbsp;Table of contents </div> <ul> <li><a href="#intro">Introduction<a> <li><a href="#render">Render options<a> <li><a href="#source">PHP source syntax highlight<a> <li><a href="#run">Play demo<a> </ul> <a name="intro"> <h2><img src="../images/info.gif"/> Introduction</h2> <p>This example requires : <ul> <li>PEAR::HTTP_Request 1.2.2 or better (see source at line 14).</li> <li>PEAR::HTML_Progress 1.1 or better (see source at line 16).</li> </ul> </p> <p>Be aware that: <ul> <li>HTTP_Request has dependencies (Net_URL 1.0.12+, Net_Socket 1.0.2+) </li> </ul> </p> <hr/> <p><b>This example will display a basic progress bar while retrieving a large file.</b></p> <p>We have created a Request/Listener class HTTP_Request_DownloadListener on lines 18 to 104. In this Listener, a progress bar was integrated on lines 78 to 84. It's a basic progress bar with only one render option changed (animation speed).</p> <p>On lines 90 and 92 the progress bar is updated depending of the data size already received.</p> <p>Media file is identify by URL defined at line 106.</p> <p>When the shockwave flash object is fully loaded, page sw4p.html is shown on lines 115 to 117.</p> <p>[<a href="#top">Top</a>]</p> <a name="render"> <h2><img src="../images/config.gif"/>&nbsp;Render options </h2> Animation speed is set to 10 (see source at line 79). <p>[<a href="#top">Top</a>]</p> <a name="source"> <h2><img src="../images/source.gif"/>&nbsp;PHP source syntax highlight</h2> <a target="_blank" href="../highlighter.php?file=preload/shockwaveflash.php">Open</a> source listing in a new window. <p>[<a href="#top">Top</a>]</p> <a name="run"> <h2><img src="../images/run.gif"/>&nbsp;Play demo</h2> <p><a href="shockwaveflash.php">Run</a> the script.</p> <p>[<a href="#top">Top</a>]</p> </body> </html> http://cvs.php.net/co.php/pear/HTML_Progress/examples/preload/shockwaveflash.php?r=1.1&p=1 Index: pear/HTML_Progress/examples/preload/shockwaveflash.php +++ pear/HTML_Progress/examples/preload/shockwaveflash.php <?php @include '../include_path.php'; /** * An example of Listener usage with HTTP_Request and HTML_Progress. * * Credit: Alexey Borzov <avb@php.net> * for his download-progress.php pattern in HTTP_Request package * * @version $Id: shockwaveflash.php,v 1.1 2004/06/27 14:03:50 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress */ require_once 'HTTP/Request.php'; require_once 'HTTP/Request/Listener.php'; require_once 'HTML/Progress.php'; class HTTP_Request_DownloadListener extends HTTP_Request_Listener { /** * Handle for the target file * @var int */ var $_fp; /** * ProgressBar intance used to display the indicator * @var object */ var $_bar; /** * Name of the target file * @var string */ var $_target; /** * Number of bytes received so far * @var int */ var $_size = 0; function HTTP_Request_DownloadListener() { $this->HTTP_Request_Listener(); } /** * Opens the target file * @param string Target file name * @throws PEAR_Error */ function setTarget($target) { $this->_target = $target; $this->_fp = @fopen($target, 'wb'); if (!$this->_fp) { PEAR::raiseError("Cannot open '{$target}'"); } } function update(&$subject, $event, $data = null) { switch ($event) { case 'sentRequest': $this->_target = basename($subject->_url->path); break; case 'gotHeaders': if (isset($data['content-disposition']) && preg_match('/filename="([^"]+)"/', $data['content-disposition'], $matches)) { $this->setTarget(basename($matches[1])); } else { $this->setTarget($this->_target); } $this->_bar =& new HTML_Progress(); $this->_bar->setAnimSpeed(10); $inc = isset($data['content-length'])? round($data['content-length'] / 100) : 1; $this->_bar->setIncrement(intval($inc)); echo '<style type="text/css">'.$this->_bar->getStyle().'</style>'; echo '<script type="text/javascript">'.$this->_bar->getScript().'</script>'; echo $this->_bar->toHtml(); $this->_size = 0; break; case 'tick': $this->_size += strlen($data); $this->_bar->display(); $val = round($this->_size / $this->_bar->getIncrement()); $this->_bar->setValue(intval($val)); fwrite($this->_fp, $data); break; case 'gotBody': fclose($this->_fp); break; default: PEAR::raiseError("Unhandled event '{$event}'"); } // switch } } $url = 'http://pear.laurent-laville.org/HTML_Progress/examples/viewlet/sw4p.swf'; $req =& new HTTP_Request($url); $download =& new HTTP_Request_DownloadListener(); $req->attach($download); $req->sendRequest(false); $href = 'http://'.$_SERVER['SERVER_NAME']. dirname($_SERVER['PHP_SELF']) . '/sw4p.html'; $go = '<script type="text/javascript">window.location.href="'.$href.'";</script>'; echo $go; ?> http://cvs.php.net/co.php/pear/HTML_Progress/examples/preload/sw4p.html?r=1.1&p=1 Index: pear/HTML_Progress/examples/preload/sw4p.html +++ pear/HTML_Progress/examples/preload/sw4p.html <!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'> <html> <head> <title>Setup Wizard for PHP</title> <meta name="Keywords" content="viewlet, qarbon, leelou, help, frequently asked questions, faqs, demonstrations, training, viewlets, help files, software help, software demonstrations, online assistance, authoring tool"> <meta name="Description" content="A solution to help end-user to easily install their applications"> </head> <body bgcolor="#ffffff" leftmargin="0" rightmargin="0" topmargin="0"> <br /> <center> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="530" height="416"> <param name="movie" value="sw4p.swf"> <param name="quality" value="high"> <param name="bgcolor" value="#ffffff"> <embed src="sw4p.swf" quality="high" bgcolor="#ffffff" width="530" height="416" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> </object> </center> </body> </html>

« previous php.pear.cvs (#21191) next »