<?php
/**
* WiseLoop PHP Web Media Grabber Sample<br/>
* Title: C-Type<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', '');
$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', '');
$content_types = wlExtArray::searchArraysByKey($arrays, 'content_types', '');
//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 : ''; ?>"/>
<small class="text-info">include http:// also</small>
</div>
<div class="well well-sm">
<h4>Content-Type Grabber Filters</h4>
<div class="container row">
<label class="checkbox col-sm-2">
Content-Types
</label>
</div>
<select class="form-control" name="content_types[]" multiple>
<?php echo options(wlWmgContentTypeGrabber::getContentTypes(), $content_types); ?>
</select>
<small class="text-info">Ctrl+Click to select multiple values</small>
</div>
<?php require_once 'widget-grabbing-parameters.php'; ?>
<div>
<input type="submit" value="Grab Resources" class="btn btn-primary"/>
</div>
</form>
</div>
<?php
//the magic starts here ...
//creating the content-type grabber object by giving some necessary parameters:
//$url: url,
//$content_types: the content-types to grab
$contentTypeMediaGrabber = new wlWmgContentTypeGrabber($url, $content_types);
//set download switch: if the grabbed media will be downloaded to localhost
$contentTypeMediaGrabber->setDoDownload($download);
//limit filter: setting the media limit count to be grabbed
if ($limit_active) {
$contentTypeMediaGrabber->setLimit($limit);
}
//the processor will grab only the media founded inside the contents of the tag specified here
if ($tagslice_active) {
$contentTypeMediaGrabber->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
$contentTypeMediaGrabber->addFilter($sizeFilter);
}
//grabbing
if ($url) {
$contentTypeMediaGrabber->grab();
//displaying the grabbed media
echo '<h3>Grabbed media (' . $contentTypeMediaGrabber->countValidMedia() . ' items found)</h3>';
echo '<pre>' . print_r($contentTypeMediaGrabber->getValidMediaTable(true), true) . '</pre>';
//displaying founded invalid media or unsuccessful grabbing tries (due to various server rejections, or broken links)
if ($contentTypeMediaGrabber->hasInvalidMedia()) {
echo '<h3>Invalid media (' . $contentTypeMediaGrabber->countInvalidMedia() . ' items found)</h3>';
echo '<pre>' . print_r($contentTypeMediaGrabber->getInvalidMediaTable(true), true) . '</pre>';
}
}
?>