| Current Path : /var/www/html/components/com_jdownloads/tmpl/search/ |
| Current File : /var/www/html/components/com_jdownloads/tmpl/search/default_form.php |
<?php
/**
* @package Joomla.Administrator
* @subpackage com_search
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* @package jDownloads
* @version 4.0
* Some parts from the search component 3.x (and search content plugin) adapted and modified to can use it in jDownloads 4.x as an internal search function.
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\Database\DatabaseInterface;
use JDownloads\Component\JDownloads\Site\Helper\JDHelper;
use JDownloads\Component\JDownloads\Site\Helper\SearchHelper;
$db = Factory::getContainer()->get(DatabaseInterface::class);
$document = Factory::getApplication()->getDocument();
$jinput = Factory::getApplication()->getInput();
$app = Factory::getApplication();
$params = $app->getParams();
$user = Factory::getApplication()->getIdentity();
$upper_limit = SearchHelper::getSearchWordUpperLimit();
// get jD user limits and settings
$jd_user_settings = JDHelper::getUserRules();
$html = '';
$layout = '';
$searchphrase_markup = str_replace('<input', '<input class="form-check-input m-0 me-2 float-none"', $this->lists['searchphrase']);
$searchphrase_markup = str_replace('<label', '<label class="d-inline-flex align-items-center mb-0 me-4 lh-sm"', $searchphrase_markup);
$limit_box = '';
$search_error_html = '';
if ($this->pagination) {
$limit_box = str_replace('class="inputbox"', 'class="form-select form-select-sm w-auto d-inline-block"', $this->pagination->getLimitBox());
}
if ($this->error) {
$search_error_html = '<div class="alert alert-danger border mt-3 mb-0" role="alert">' . $this->escape($this->error) . '</div>';
}
// Get the needed layout data - type = 7 for a 'search form' layout
// Please note that he are stored only header data not the layout self - not the best solutions. So perhaps will we change it in later releases.
$layout = JDHelper::getLayout(7);
if ($layout){
$layout_text = $layout->template_text;
$header = $layout->template_header_text;
$subheader = $layout->template_subheader_text;
$footer = $layout->template_footer_text;
} else {
// We have not a valid layout data
echo '<big>No valid layout found!</big>';
}
// get current category menu ID when exist and all needed menu IDs for the header links
$menuItemids = JDHelper::getMenuItemids(0);
// get all other menu category IDs so we can use it when we needs it
$cat_link_itemids = JDHelper::getAllJDCategoryMenuIDs();
// "Home" menu link itemid
$root_itemid = $menuItemids['root'];
// Get CSS button settings
$menu_color = $params->get('css_menu_button_color');
$menu_size = $params->get('css_menu_button_size');
if ($params->get('css_buttons_with_font_symbols')){
$span_home_symbol = '<span class="icon-home-2 jd-menu-icon"> </span>';
$span_search_symbol = '<span class="icon-search jd-menu-icon"> </span>';
$span_upper_symbol = '<span class="icon-arrow-up-2 jd-menu-icon"> </span>';
$span_upload_symbol = '<span class="icon-new jd-menu-icon"> </span>';
} else {
$span_home_symbol = '';
$span_search_symbol = '';
$span_upper_symbol = '';
$span_upload_symbol = '';
}
// ==========================================
// HEADER SECTION
// ==========================================
if ($header != ''){
$menuItemids = JDHelper::getMenuItemids(0);
// component title - not more used. So we must replace the placeholder from layout with spaces!
$header = str_replace('{component_title}', '', $header);
// replace both Google adsense placeholder with script
$header = JDHelper::insertGoogleAdsenseCode($header);
// components description
if ($params->get('downloads_titletext') != '') {
$header_text = stripslashes(JDHelper::getOnlyLanguageSubstring($params->get('downloads_titletext')));
// replace both Google adsense placeholder with script
$header_text = JDHelper::insertGoogleAdsenseCode($header_text);
$header .= $header_text;
}
// check $Itemid exist
if (!isset($menuItemids['search'])) $menuItemids['search'] = $menuItemids['root'];
if (!isset($menuItemids['upload'])) $menuItemids['upload'] = $menuItemids['root'];
// build home link
$home_link = '<a href="'.Route::_('index.php?option=com_jdownloads&Itemid='.$menuItemids['root']).'" title="'.Text::_('COM_JDOWNLOADS_HOME_LINKTEXT_HINT').'">'.'<span class="jdbutton '.$menu_color.' '.$menu_size.'">'.$span_home_symbol.Text::_('COM_JDOWNLOADS_HOME_LINKTEXT').'</span>'.'</a>';
// build search link
$search_link = '<a href="'.Route::_('index.php?option=com_jdownloads&view=search&Itemid='.$menuItemids['search']).'" title="'.Text::_('COM_JDOWNLOADS_SEARCH_LINKTEXT_HINT').'">'.'<span class="jdbutton '.$menu_color.' '.$menu_size.'">'.$span_search_symbol.Text::_('COM_JDOWNLOADS_SEARCH_LINKTEXT').'</span>'.'</a>';
// build frontend upload link
$upload_link = '<a href="'.Route::_('index.php?option=com_jdownloads&view=form&layout=edit&Itemid='.$menuItemids['upload']).'" title="'.Text::_('COM_JDOWNLOADS_UPLOAD_LINKTEXT_HINT').'">'.'<span class="jdbutton '.$menu_color.' '.$menu_size.'">'.$span_upload_symbol.Text::_('COM_JDOWNLOADS_UPLOAD_LINKTEXT').'</span>'.'</a>';
// build level up link
$upper_link = Route::_('index.php?option=com_jdownloads&view=categories&Itemid='.$menuItemids['root']);
$header = str_replace('{home_link}', $home_link, $header);
$header = str_replace('{search_link}', $search_link, $header);
if ($jd_user_settings->uploads_view_upload_icon){
if ($this->view_upload_button){
$header = str_replace('{upload_link}', $upload_link, $header);
} else {
$header = str_replace('{upload_link}', '', $header);
}
} else {
$header = str_replace('{upload_link}', '', $header);
}
$header = str_replace('{upper_link}', '<a href="'.$upper_link.'" title="'.Text::_('COM_JDOWNLOADS_UPPER_LINKTEXT_HINT').'">'.'<span class="jdbutton '.$menu_color.' '.$menu_size.'">'.$span_upper_symbol.Text::_('COM_JDOWNLOADS_UPPER_LINKTEXT').'</span>'.'</a>', $header);
// create category listbox and viewed it when it is activated in configuration
if ($params->get('show_header_catlist')){
// get current selected cat id from listbox
$catlistid = 0;
$orderby_pri = '';
$data = JDHelper::buildCategorySelectBox($catlistid, $cat_link_itemids, $root_itemid, $params->get('view_empty_categories', 1), $orderby_pri );
// build special selectable URLs for category listbox
$root_url = Route::_('index.php?option=com_jdownloads&Itemid='.$root_itemid);
$allfiles_url = str_replace('Itemid[0]', 'Itemid', Route::_('index.php?option=com_jdownloads&view=downloads&Itemid='.$root_itemid));
$topfiles_url = str_replace('Itemid[0]', 'Itemid', Route::_('index.php?option=com_jdownloads&view=downloads&type=top&Itemid='.$root_itemid));
$newfiles_url = str_replace('Itemid[0]', 'Itemid', Route::_('index.php?option=com_jdownloads&view=downloads&type=new&Itemid='.$root_itemid));
$listbox = HTMLHelper::_('select.genericlist', $data['options'], 'cat_list', 'class="form-select" title="'.Text::_('COM_JDOWNLOADS_SELECT_A_VIEW').'" onchange="gocat(\''.$root_url.'\', \''.$allfiles_url.'\', \''.$topfiles_url.'\', \''.$newfiles_url.'\' ,\''.$data['url'].'\')"', 'value', 'text', $data['selected'] );
$header = str_replace('{category_listbox}', '<form name="go_cat" id="go_cat" method="post">'.$listbox.'</form>', $header);
} else {
$header = str_replace('{category_listbox}', '', $header);
}
$html .= $header;
}
// ==========================================
// SUB HEADER SECTION
// ==========================================
if ($subheader != ''){
// replace both Google adsense placeholder with script
$subheader = JDHelper::insertGoogleAdsenseCode($subheader);
$html .= $subheader;
}
// ==========================================
// MAIN SECTION
// ==========================================
if ($layout_text) {
// replace both Google adsense placeholder with script
$layout_text = JDHelper::insertGoogleAdsenseCode($layout_text);
}
$html .= $layout_text;
// remove empty html tags
if ($params->get('remove_empty_tags')){
$html = JDHelper::removeEmptyTags($html);
}
$action_uri = htmlspecialchars(Uri::getInstance()->toString());
echo $html;
?>
<form id="searchForm" action="<?php echo Route::_($action_uri);?>" method="post" accept-charset="utf-8" class="jd-search-form">
<div class="container my-4">
<div class="card border-0 shadow-sm">
<div class="card-body p-4">
<div class="row g-3 align-items-end">
<div class="col-12 col-lg-6">
<label for="search-searchword" class="form-label fw-semibold"><?php echo Text::_('COM_JDOWNLOADS_SEARCH_KEYWORD'); ?></label>
<div class="input-group input-group-lg">
<span class="input-group-text"><span class="icon-search" aria-hidden="true"></span></span>
<input type="text" name="searchword" title="<?php echo Text::_('COM_JDOWNLOADS_SEARCH_KEYWORD'); ?>" placeholder="<?php echo Text::_('COM_JDOWNLOADS_SEARCH_KEYWORD'); ?>" id="search-searchword" maxlength="<?php echo $upper_limit; ?>" value="<?php echo $this->escape($this->origkeyword); ?>" class="form-control" />
</div>
</div>
<div class="col-12 col-md-6 col-lg-3">
<label for="ordering" class="form-label fw-semibold"><?php echo Text::_('COM_JDOWNLOADS_SEARCH_ORDERING');?></label>
<?php echo $this->lists['ordering'];?>
</div>
<div class="col-12 col-md-6 col-lg-3 d-grid gap-2">
<button name="Search" onclick="this.form.submit()" class="btn btn-primary hasTooltip" title="<?php echo HTMLHelper::_('tooltipText', 'COM_JDOWNLOADS_SEARCH');?>">
<span class="icon-search" aria-hidden="true"></span>
<?php echo Text::_('COM_JDOWNLOADS_SEARCH'); ?>
</button>
<button name="Resetit" onclick="this.form.reset.value = 1;this.form.submit();" class="btn btn-outline-secondary hasTooltip" title="<?php echo HTMLHelper::_('tooltipText', 'COM_JDOWNLOADS_SEARCH_RESET');?>">
<span class="icon-refresh" aria-hidden="true"></span>
<?php echo Text::_('COM_JDOWNLOADS_SEARCH_RESET'); ?>
</button>
</div>
</div>
<input type="hidden" name="task" value="search" />
<input type="hidden" name="reset" value="" />
<?php echo HTMLHelper::_('form.token'); ?>
<?php echo $search_error_html; ?>
<div class="row g-4 mt-1">
<div class="col-12 col-lg-8">
<fieldset class="border rounded-3 p-1">
<legend class="float-none w-auto px-2 fs-6 fw-semibold mb-2"><?php echo Text::_('COM_JDOWNLOADS_SEARCH_FOR');?></legend>
<div class="d-flex flex-wrap align-items-center gap-2">
<?php echo $searchphrase_markup; ?>
</div>
</fieldset>
</div>
<?php if ($this->params->get('search_areas') == 1) : ?>
<div class="col-12 col-lg-4">
<fieldset class="border rounded-3 p-2">
<legend class="float-none w-auto px-2 fs-6 fw-semibold mb-2"><?php echo Text::_('COM_JDOWNLOADS_SEARCH_ONLY_IN');?></legend>
<div class="d-flex flex-column gap-2 mb-3">
<?php foreach ($this->searchareas['search'] as $val => $txt) :
$checked = is_array($this->searchareas['active']) && in_array($val, $this->searchareas['active']) ? 'checked="checked"' : '';
?>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="areas[]" value="<?php echo $val;?>" id="area-<?php echo $val;?>" <?php echo $checked;?> />
<label class="form-check-label" for="area-<?php echo $val;?>"><?php echo Text::_($txt); ?></label>
</div>
<?php endforeach; ?>
</div>
<div>
<label for="searchcat" class="form-label fw-semibold"><?php echo Text::_('COM_JDOWNLOADS_SEARCH_CATEGORY').':';?></label>
<?php echo $this->listbox;?>
</div>
</fieldset>
</div>
<?php endif; ?>
</div>
<?php if (!empty($this->searchword)):?>
<div class="alert alert-light border mt-2 mb-0" role="status"><?php echo Text::plural('COM_JDOWNLOADS_SEARCH_KEYWORD_N_RESULTS', '<span class="badge text-bg-info d-inline-flex align-items-center lh-sm">' . $this->total . '</span>'); ?></div>
<?php endif;?>
<?php if ($this->total > 5 && $this->pagination) : ?>
<div class="d-flex flex-column flex-md-row align-items-md-center justify-content-between gap-3 mt-4 pt-2 border-top">
<div>
<label for="limit" class="form-label mb-1"><?php echo Text::_('JGLOBAL_DISPLAY_NUM'); ?></label>
<div><?php echo $limit_box; ?></div>
</div>
<p class="text-body-secondary mb-0"><?php echo $this->pagination->getPagesCounter(); ?></p>
</div>
<?php endif; ?>
</div>
</div>
</div>
</form>