Skip to content

Commit

Permalink
Fix issue Wrong image position in featured view #875
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Nov 22, 2024
1 parent 04f51cc commit d297a45
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 319 deletions.
2 changes: 1 addition & 1 deletion assets/vendor/astroid/scss/joomla/_com_content.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.blog {
.com-content-category-blog__items + .com-content-category-blog__items {
.blog-items + .blog-items {
margin-top: 3rem;
}
.item-content.border-top {
Expand Down
186 changes: 3 additions & 183 deletions framework/html/com_content/category/blog_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,189 +3,9 @@
/**
* @package Astroid Framework
* @author Astroid Framework https://astroidframe.work
* @copyright Copyright (C) 2023 AstroidFrame.work.
* @copyright Copyright (C) 2024 AstroidFrame.work.
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\Registry\Registry;
use Astroid\Framework;
use Astroid\Article;

// Astroid Article/Blog
if (!isset($astroidArticle)) {
$astroidArticle = new Article($this->item, true);
}

$template = Framework::getTemplate();
$document = Framework::getDocument();

$is_lead = $this->item->is_leaditem ?? false;
$is_intro = $this->item->is_introitem ?? false;

// Create shortcuts to some parameters.
$params = $this->item->params;
$canEdit = $params->get('access-edit');
$info = $params->get('info_block_position', 0);
$images = json_decode($this->item->images);

// Check if associations are implemented. If they are, define the parameter.
$assocParam = (Associations::isEnabled() && $params->get('show_associations'));

$tpl_params = $template->getParams();

// Post Format
$post_attribs = new Registry(json_decode($this->item->attribs));
$post_format = $post_attribs->get('post_format', 'standard');
$astroid_article_type = $post_attribs->get('astroid_article_type', '');
$astroid_article_video_type = $post_attribs->get('astroid_article_video_type', '');

// Image position
$image_width = array();
if ($is_lead) {
$image_width = Article::getImageWidth($params, 'lead', $this->item->key_idx);
$image_position = $image_width['position'];
} elseif ($is_intro) {
$image_width = Article::getImageWidth($params, 'intro', $this->item->key_idx);
$image_position = $image_width['position'];
} else {
$image_position = 'top';
}

if (empty($image_position)) {
$image_position = 'top';
}

$image_width_cls = '';
if ($image_position == 'left' || $image_position == 'right') {
$image_width_cls = $image_width['xl'] . $image_width['lg'] . $image_width['md'] . $image_width['sm'] . $image_width['default'];
}

$currentDate = Factory::getDate()->format('Y-m-d H:i:s');
$isUnpublished = ($this->item->state == ContentComponent::CONDITION_UNPUBLISHED || $this->item->publish_up > $currentDate)
|| ($this->item->publish_down < $currentDate && $this->item->publish_down !== null);

$clsItemContainer = $astroidArticle->getStyle('container');
$clsItemBody = $astroidArticle->getStyle('body');
?>
<div class="item-content position-relative<?php echo (!empty($clsItemContainer) ? ' '.$clsItemContainer : ''); echo ($image_position == 'left' || $image_position == 'right') ? ' border-top media-'.$image_position : ''; ?>">
<?php if ($isUnpublished) : ?>
<div class="system-unpublished">
<?php endif; ?>
<?php
if ($astroid_article_type == 'video' && $astroid_article_video_type == 'local') {
$astroid_article_video_local = $post_attribs->get('astroid_article_video_local', '');
$image = '<div class="as-article-video-local h-100 ratio ratio-16x9" data-as-video-bg="'.Uri::base('true').'/images/'.$astroid_article_video_local.'"'.(!empty($images->image_intro) ? ' data-as-video-poster="'.Uri::base('true').'/'.$images->image_intro.'"' : '').'></div>';
} else {
$image = $astroidArticle->getImage();
}
if (((!empty($images->image_intro)) && $post_format == 'standard') || (is_string($image) && !empty($image))) {
if ($image_position == 'left' || $image_position == 'right' || $image_position == 'bottom') {
if ($image_position == 'left' || $image_position == 'right') {
echo '<div class="row g-0 position-relative">';
echo '<div class="astroid-media-'.$image_position. ' astroid-img-cover position-relative' .$image_width_cls.'">';
} else {
echo '<div class="astroid-media-'.$image_position.' mt-4 order-1">';
}
}
}
// Generate media
if ((!empty($images->image_intro)) && $post_format == 'standard' && ($astroid_article_type !== 'video' || $astroid_article_video_type !== 'local')) {
echo LayoutHelper::render('joomla.content.intro_image', $this->item);
} else if (is_string($image) && !empty($image)) {
echo '<div class="item-image">';
if ($astroid_article_type == 'video' && $astroid_article_video_type == 'local') {
$document->loadVideoBG();
echo $image;
} else {
$document->include('blog.modules.image', ['image' => $image, 'title' => $this->item->title, 'item' => $this->item]);
}
echo '</div>';
} else {
echo LayoutHelper::render('joomla.content.post_formats.post_' . $post_format, array('params' => $post_attribs, 'item' => $this->item));
}

if (((!empty($images->image_intro)) && $post_format == 'standard') || (is_string($image) && !empty($image))) {
if ($image_position == 'left' || $image_position == 'right' || $image_position == 'bottom') {
echo '</div>';
echo ($image_position == 'left' || $image_position == 'right') ? '<div class="astroid-content-media-'.$image_position.' col'.$image_width['expand'].'">' : '';
}
}
?>
<div class="d-flex flex-column<?php echo $tpl_params->get('show_post_format') ? ' has-post-format' : ''; ?><?php echo (!empty($image) ? ' has-image' : ''); ?><?php echo (!empty($clsItemBody) ? ' '.$clsItemBody : ''); ?>">
<?php $astroidArticle->renderPostTypeIcon(); ?>
<?php $astroidArticle->renderArticleBadge(); ?>

<?php if ($canEdit) : ?>
<?php echo LayoutHelper::render('joomla.content.icons', ['params' => $params, 'item' => $this->item]); ?>
<?php endif; ?>

<?php // @todo Not that elegant would be nice to group the params ?>
<?php $useDefList = ($params->get('show_modify_date') || $params->get('show_publish_date') || $params->get('show_create_date')
|| $params->get('show_hits') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author') || $assocParam); ?>

<div class="article-title item-title">
<?php echo LayoutHelper::render('joomla.content.blog_style_default_item_title', $this->item); ?>
</div>
<?php if ($useDefList && ($info == 0 || $info == 2)) : ?>
<?php echo LayoutHelper::render('joomla.content.info_block', array('item' => $this->item, 'params' => $params, 'astroidArticle' => $astroidArticle, 'position' => 'above')); ?>
<?php endif; ?>
<?php if ($info == 0 && $params->get('show_tags', 1) && !empty($this->item->tags->itemTags)) : ?>
<?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?>
<?php endif; ?>

<?php if (!$params->get('show_intro')) : ?>
<?php // Content is generated by content plugin event "onContentAfterTitle" ?>
<?php echo $this->item->event->afterDisplayTitle; ?>
<?php endif; ?>

<?php // Content is generated by content plugin event "onContentBeforeDisplay" ?>
<?php echo $this->item->event->beforeDisplayContent; ?>
<div class="article-intro-text">
<?php echo $this->item->introtext; ?>
</div>

<?php if ($info == 1 || $info == 2) : ?>
<?php if ($useDefList) : ?>
<?php echo LayoutHelper::render('joomla.content.info_block', array('item' => $this->item, 'params' => $params, 'astroidArticle' => $astroidArticle, 'position' => 'below')); ?>
<?php endif; ?>
<?php if ($params->get('show_tags', 1) && !empty($this->item->tags->itemTags)) : ?>
<?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?>
<?php endif; ?>
<?php endif; ?>

<?php if ($params->get('show_readmore') && $this->item->readmore) :
if ($params->get('access-view')) :
$link = Route::_(RouteHelper::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language));
else :
$menu = Factory::getApplication()->getMenu();
$active = $menu->getActive();
$itemId = $active->id;
$link = new Uri(Route::_('index.php?option=com_users&view=login&Itemid=' . $itemId, false));
$link->setVar('return', base64_encode(RouteHelper::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)));
endif; ?>

<?php echo LayoutHelper::render('joomla.content.readmore', ['item' => $this->item, 'params' => $params, 'link' => $link]); ?>
<?php endif; ?>
</div>
<?php
if (((!empty($images->image_intro)) && $post_format == 'standard') || (is_string($image) && !empty($image))) {
if (($image_position == 'left' || $image_position == 'right')) {
echo '</div>';
echo '</div>';
}
}
?>
<?php if ($isUnpublished) : ?>
</div>
<?php endif; ?>
<?php // Content is generated by content plugin event "onContentAfterDisplay" ?>
<?php echo $this->item->event->afterDisplayContent; ?>
</div>
defined('_JEXEC') or die;
require \Joomla\Filesystem\Path::clean(JPATH_LIBRARIES . '/astroid/framework/html/layouts/joomla/content/blog_item.php');
46 changes: 31 additions & 15 deletions framework/html/com_content/featured/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
defined('_JEXEC') or die;

use Astroid\Framework;
$use_masonry = $this->params->get('use_masonry', 0);

if ($use_masonry) {
$document = Framework::getDocument();
$document->loadMasonry('.as-masonry');
}
?>
<div class="blog-featured<?php echo $this->pageclass_sfx; ?>">
<div class="blog blog-featured<?php echo $this->pageclass_sfx; ?>">
<?php if ($this->params->get('show_page_heading') != 0) : ?>
<div class="page-header">
<h1>
Expand All @@ -18,9 +26,11 @@
<?php endif; ?>
<?php if (!empty($this->lead_items)) : ?>
<div class="blog-items items-leading <?php echo $this->params->get('blog_class_leading'); ?>">
<?php foreach ($this->lead_items as &$item) : ?>
<?php foreach ($this->lead_items as $key => &$item) : ?>
<div class="blog-item">
<?php
$item->is_leaditem = true;
$item->key_idx = $key;
$this->item = & $item;
echo $this->loadTemplate('item');
?>
Expand All @@ -34,15 +44,19 @@
<?php if ((int) $this->params->get('num_columns') > 1) : ?>
<?php $blogClass .= ' gx-xl-5 gy-5 row-cols-lg-'.$this->params->get('num_columns'); ?>
<?php endif; ?>
<div class="blog-items items-row row <?php echo $blogClass; ?>">
<?php foreach ($this->intro_items as $key => &$item) : ?>
<div class="blog-item">
<?php
$this->item = & $item;
echo $this->loadTemplate('item');
?>
</div>
<?php endforeach; ?>
<div class="blog-items items-row">
<div class="row gx-xl-5 gy-5 <?php echo $blogClass; ?>">
<?php foreach ($this->intro_items as $key => &$item) : ?>
<div class="blog-item">
<?php
$item->is_introitem = true;
$item->key_idx = $key;
$this->item = & $item;
echo $this->loadTemplate('item');
?>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>

Expand All @@ -52,14 +66,16 @@
</div>
<?php endif; ?>

<?php if ($this->params->def('show_pagination', 2) == 1 || ($this->params->get('show_pagination') == 2 && $this->pagination->pagesTotal > 1)) : ?>
<div class="w-100">
<?php if (($this->params->def('show_pagination', 1) == 1 || ($this->params->get('show_pagination') == 2)) && ($this->pagination->pagesTotal > 1)) : ?>
<div class="com-content-category-blog__navigation w-100">
<?php if ($this->params->def('show_pagination_results', 1)) : ?>
<p class="counter float-end pt-3 pe-2">
<p class="com-content-category-blog__counter counter pt-3 pe-2">
<?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php endif; ?>
<?php echo $this->pagination->getPagesLinks(); ?>
<div class="com-content-category-blog__pagination">
<?php echo $this->pagination->getPagesLinks(); ?>
</div>
</div>
<?php endif; ?>
</div>
Loading

0 comments on commit d297a45

Please sign in to comment.