[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/components/com_finder/tmpl/search/ -> default_result.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  com_finder
   6   *
   7   * @copyright   (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  defined('_JEXEC') or die;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Router\Route;
  17  use Joomla\Component\Finder\Administrator\Helper\LanguageHelper;
  18  use Joomla\Component\Finder\Administrator\Indexer\Helper;
  19  use Joomla\Component\Finder\Administrator\Indexer\Taxonomy;
  20  use Joomla\String\StringHelper;
  21  
  22  $user             = Factory::getApplication()->getIdentity();
  23  $show_description = $this->params->get('show_description', 1);
  24  
  25  if ($show_description) {
  26      // Calculate number of characters to display around the result
  27      $term_length = StringHelper::strlen($this->query->input);
  28      $desc_length = $this->params->get('description_length', 255);
  29      $pad_length  = $term_length < $desc_length ? (int) floor(($desc_length - $term_length) / 2) : 0;
  30  
  31      // Make sure we highlight term both in introtext and fulltext
  32      $full_description = $this->result->description;
  33      if (!empty($this->result->summary) && !empty($this->result->body)) {
  34          $full_description = Helper::parse($this->result->summary . $this->result->body);
  35      }
  36  
  37      // Find the position of the search term
  38      $pos = $term_length ? StringHelper::strpos(StringHelper::strtolower($full_description), StringHelper::strtolower($this->query->input)) : false;
  39  
  40      // Find a potential start point
  41      $start = ($pos && $pos > $pad_length) ? $pos - $pad_length : 0;
  42  
  43      // Find a space between $start and $pos, start right after it.
  44      $space = StringHelper::strpos($full_description, ' ', $start > 0 ? $start - 1 : 0);
  45      $start = ($space && $space < $pos) ? $space + 1 : $start;
  46  
  47      $description = HTMLHelper::_('string.truncate', StringHelper::substr($full_description, $start), $desc_length, true);
  48  }
  49  
  50  $showImage  = $this->params->get('show_image', 0);
  51  $imageClass = $this->params->get('image_class', '');
  52  $extraAttr  = [];
  53  
  54  if ($showImage && !empty($this->result->imageUrl) && $imageClass !== '') {
  55      $extraAttr['class'] = $imageClass;
  56  }
  57  
  58  $icon = '';
  59  if (!empty($this->result->mime)) {
  60      $icon = '<span class="icon-file-' . $this->result->mime . '" aria-hidden="true"></span> ';
  61  }
  62  
  63  
  64  $show_url = '';
  65  if ($this->params->get('show_url', 1)) {
  66      $show_url = '<cite class="result__title-url">' . $this->baseUrl . Route::_($this->result->cleanURL) . '</cite>';
  67  }
  68  ?>
  69  <li class="result__item">
  70      <?php if ($showImage && isset($this->result->imageUrl)) : ?>
  71          <figure class="<?php echo htmlspecialchars($imageClass, ENT_COMPAT, 'UTF-8'); ?> result__image">
  72              <?php if ($this->params->get('link_image') && $this->result->route) : ?>
  73                  <a href="<?php echo Route::_($this->result->route); ?>">
  74                      <?php echo HTMLHelper::_('image', $this->result->imageUrl, $this->result->imageAlt, $extraAttr); ?>
  75                  </a>
  76              <?php else : ?>
  77                  <?php echo HTMLHelper::_('image', $this->result->imageUrl, $this->result->imageAlt, $extraAttr); ?>
  78              <?php endif; ?>
  79          </figure>
  80      <?php endif; ?>
  81      <p class="result__title">
  82          <?php if ($this->result->route) : ?>
  83              <?php echo HTMLHelper::link(
  84                  Route::_($this->result->route),
  85                  '<span class="result__title-text">' . $icon . $this->result->title . '</span>' . $show_url,
  86                  [
  87                              'class' => 'result__title-link'
  88                      ]
  89              ); ?>
  90          <?php else : ?>
  91              <?php echo $this->result->title; ?>
  92          <?php endif; ?>
  93      </p>
  94      <?php if ($show_description && $description !== '') : ?>
  95          <p class="result__description">
  96              <?php if ($this->result->start_date && $this->params->get('show_date', 1)) : ?>
  97                  <time class="result__date" datetime="<?php echo HTMLHelper::_('date', $this->result->start_date, 'c'); ?>">
  98                      <?php echo HTMLHelper::_('date', $this->result->start_date, Text::_('DATE_FORMAT_LC3')); ?>
  99                  </time>
 100              <?php endif; ?>
 101              <?php echo $description; ?>
 102          </p>
 103      <?php endif; ?>
 104      <?php $taxonomies = $this->result->getTaxonomy(); ?>
 105      <?php if (count($taxonomies) && $this->params->get('show_taxonomy', 1)) : ?>
 106          <ul class="result__taxonomy">
 107              <?php foreach ($taxonomies as $type => $taxonomy) : ?>
 108                  <?php $branch = Taxonomy::getBranch($type); ?>
 109                  <?php if ($branch->state == 1 && in_array($branch->access, $user->getAuthorisedViewLevels())) : ?>
 110                      <?php $taxonomy_text = []; ?>
 111                      <?php foreach ($taxonomy as $node) : ?>
 112                          <?php if ($node->state == 1 && in_array($node->access, $user->getAuthorisedViewLevels())) : ?>
 113                              <?php $taxonomy_text[] = $node->title; ?>
 114                          <?php endif; ?>
 115                      <?php endforeach; ?>
 116                      <?php if (count($taxonomy_text)) : ?>
 117                          <li class="result__taxonomy-item result__taxonomy--<?php echo $type; ?>">
 118                              <span><?php echo Text::_(LanguageHelper::branchSingular($type)); ?>:</span> <?php echo implode(',', $taxonomy_text); ?>
 119                          </li>
 120                      <?php endif; ?>
 121                  <?php endif; ?>
 122              <?php endforeach; ?>
 123          </ul>
 124      <?php endif; ?>
 125  </li>


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer