<?php
/**
* WiseLoop PHP Web Media Grabber Sample<br/>
* Title: Flash<br/>Grabber
*/
require_once dirname(__FILE__) . "/../php-web-media-grabber/bin/wlWmg.php";
require_once dirname(__FILE__) . "/demo-utils.php";
$arrays = array($_POST, $_GET);
$url = wlExtArray::searchArraysByKey($arrays, 'url', null);
$download = wlExtArray::searchArraysByKey($arrays, 'download', '');
$size_active = wlExtArray::searchArraysByKey($arrays, 'size_active', '');
$size = intval(wlExtArray::searchArraysByKey($arrays, 'size', ''));
$size_operator = wlExtArray::searchArraysByKey($arrays, 'size_operator', '');
$limit_active = wlExtArray::searchArraysByKey($arrays, 'limit_active', '');
$limit = intval(wlExtArray::searchArraysByKey($arrays, 'limit', ''));
$tagslice_active = wlExtArray::searchArraysByKey($arrays, 'tagslice_active', '');
$tagslice = wlExtArray::searchArraysByKey($arrays, 'tagslice', '');
$ctype_active = wlExtArray::searchArraysByKey($arrays, 'ctype_active', '');
$flash_extensions_active = wlExtArray::searchArraysByKey($arrays, 'flash_extensions_active', '');
$flash_extensions = wlExtArray::searchArraysByKey($arrays, 'flash_extensions', '');
//testing if the url is coming from the approved sites (wiseloop or darkroomdesign)
//this test is meant to save bandwidth and disk space only on wiseloop.com demonstration page
//please remove this from your real production project
if ($download && isset($allowDownloadFrom)) {
$download = false;
foreach ($allowDownloadFrom as $approvedSite) {
if (stripos($url, $approvedSite)) {
$download = true;
break;
}
}
}
?>
<div class="row container">
<form action="" id="form" method="POST" enctype="multipart/form-data" class="form form-horizontal" role="form">
<div class="well well-sm">
<label class="control control-label" for="url">Full target URL path:</label>
<input class="form-control" type="text" name="url" id="url" placeholder="http://" value="<?php echo isset($url) ? $url : 'http://www.flashearth.com'; ?>"/>
<small class="text-info">include http:// also</small>
</div>
<div class="well well-sm">
<h4>Flash Grabber Filters</h4>
<div class="container row">
<div class="checkbox col-sm-2">
<label>
<input type="checkbox" id="flash_extensions_active" name="flash_extensions_active" <?php echo $flash_extensions_active ? 'checked' : ''; ?>/>
Flash Extensions
</label>
</div>
<div class="col-sm-10">
<small class="text-info">if nothing is selected or the filter is inactive (unchecked), all extensions will be searched</small>
</div>
</div>
<select class="form-control" name="flash_extensions[]" multiple>
<?php echo options(wlWmgFlashGrabber::getFlashFileExtensions(), $flash_extensions); ?>
</select>
<small class="text-info">Ctrl+Click to select multiple values</small>
<div class="container row">
<div class="checkbox col-sm-2">
<label>
<input type="checkbox" id="ctype_active" name="ctype_active" <?php echo $ctype_active ? 'checked' : ''; ?>/>
Check Content-Type header
</label>
</div>
<div class="col-sm-10">
<small class="text-info">
if checked, the grabber engine will check also the content-type of the grabbed media to make sure it is a flash app;
this checking will add some additional processing as headers for each possible media will be downloaded in order to perform flash validation.
If unchecked, the grabber engine will use only the provided file extensions and therefore the grabbing process will be faster but can bring non-flash files also
</small>
</div>
</div>
</div>
<?php require_once 'widget-grabbing-parameters.php'; ?>
<div>
<input type="submit" value="Grab Flash/Flex Files" class="btn btn-primary"/>
</div>
</form>
</div>
<?php
//the magic starts here ...
//creating the flash grabber object by giving some necessary parameters:
//$url: url
$flashMediaGrabber = new wlWmgFlashGrabber($url, $flash_extensions, $ctype_active);
//set download switch: if the flash files should be downloaded to localhost
$flashMediaGrabber->setDoDownload($download);
//limit filter: setting the media limit count to be grabbed
if ($limit_active) {
$flashMediaGrabber->setLimit($limit);
}
//the processor will grab only the media founded inside the contents of the tag specified here
if ($tagslice_active) {
$flashMediaGrabber->setGrabOnlyFromTagSlice($tagslice);
}
//the content-length (size) filter
if ($size_active) {
//filter creation
$sizeFilter = new wlWmgFilter(
$size,
wlWmgFilter::TYPE_CONTENT_LENGTH,
$size_operator
);
//adding filter to the grabber
$flashMediaGrabber->addFilter($sizeFilter);
}
//grabbing
if ($url) {
$flashMediaGrabber->grab();
//displaying the grabbed media
echo '<h3>Grabbed media (' . $flashMediaGrabber->countValidMedia() . ' items found)</h3>';
echo '<pre>' . print_r($flashMediaGrabber->getValidMediaTable(true), true) . '</pre>';
//displaying founded invalid media or unsuccessful grabbing tries (due to various server rejections, or broken links)
if ($flashMediaGrabber->hasInvalidMedia()) {
echo '<h3>Invalid media (' . $flashMediaGrabber->countInvalidMedia() . ' items found)</h3>';
echo '<pre>' . print_r($flashMediaGrabber->getInvalidMediaTable(true), true) . '</pre>';
}
}
?>