<?php
/**
* SeekQuarry/Yioop --
* Open Source Pure PHP Search Engine, Crawler, and Indexer
*
* Copyright (C) 2009 - 2026 Chris Pollett chris@pollett.org
*
* LICENSE:
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* END LICENSE
*
* @author Chris Pollett chris@pollett.org
* @license https://www.gnu.org/licenses/ GPL3
* @link https://www.seekquarry.com/
* @copyright 2009 - 2026
* @filesource
*/
namespace seekquarry\yioop\views\elements;
use seekquarry\yioop as B;
use seekquarry\yioop\configs as C;
/**
* ManagecrawlsElement draws the Manage Crawls page, where crawls are
* started, stopped, deleted and chosen for search. The crawl status on the
* page is drawn by CrawlstatusView, which the page's script asks for.
*
* @author Chris Pollett
*/
class ManagecrawlsElement extends Element
{
/**
* render draws the crawl controls and a place for the crawl status,
* with the script that fills it. The script asks for the status every
* 30 seconds with a request made in the background (an Ajax request)
* and stops asking after 20 minutes. It says which running crawls are
* open, so a refresh leaves them as they were. Without script, the
* status is shown in a frame instead.
*
* @param array $data the paging of the Crawls table and the token that
* shows a request came from this site, under the name CSRF_TOKEN
* gives
*/
public function render($data)
{
$admin_url = B\controllerUrl('admin', true);
$status_url = $admin_url .
C\p('CSRF_TOKEN') . "=" . $data[C\p('CSRF_TOKEN')] .
"&a=crawlStatus" .
'&num_show=' . $data['NUM_SHOW'] . "&start_row=".
$data['START_ROW'] . "&end_row=" . $data['END_ROW'];
if (!empty($_REQUEST['crawlform'])) {
$status_url .= "&crawlform=true";
}
?>
<div class="current-activity">
<?=$this->view->element('crawlcontrols')->render($data); ?>
<div id="crawlstatus" >
<script>
document.write('<h2 class="red"><?=
tl('managecrawls_element_awaiting_status') ?></h2>');
</script>
<noscript>
<iframe src="<?=str_replace("&", "&", $status_url .
"&noscript=true")?>" style="width:100%; height: 800px;">
</iframe>
</noscript>
</div>
<script>
var updateId;
function crawlStatusUpdate()
{
admin_form_object = elt('admin-form-row');
if (admin_form_object &&
admin_form_object.style.display == 'block') {
return;
}
let start_url = '<?=$status_url ?>';
start_url += "&crawl_toggle=";
let crawl_tag = elt('crawlstatus');
let i = 0;
let active_crawl;
let comma = "";
while (active_crawl = elt('active-crawl-' + i)) {
if (active_crawl.style.display != 'none') {
start_url += comma + "a" + i;
comma = ",";
}
i++;
}
getPage(crawl_tag, start_url);
}
function clearUpdate()
{
clearInterval(updateId );
let crawlTag = elt('crawlstatus');
crawlTag.innerHTML= "<h2 class='red'><?=
tl('managecrawls_element_up_longer_update')?></h2>";
}
function doUpdate()
{
let sec = 1000;
let minute = 60 * sec;
crawlStatusUpdate();
updateId = setInterval("crawlStatusUpdate()", 30*sec);
setTimeout("clearUpdate()", 20*minute + sec);
}
</script>
</div>
<?php
}
}