<?php
/* ======================================================
# Monthly Archive - Joomla! Component v4.3.3 (PRO version)
# -------------------------------------------------------
# For Joomla! 3.x
# Author: Yiannis Christodoulou (yiannis@web357.eu)
# Copyright (©) 2009-2018 Web357. All rights reserved.
# License: GNU/GPLv3, http://www.gnu.org/licenses/gpl-3.0.html
# Website: https://www.web357.eu/
# Demo: http://demo.web357.eu/?item=monthlyarchive
# Support: support@web357.eu
# Last modified: 09 Feb 2018, 13:55:18
========================================================= */

// No direct access
defined('_JEXEC') or die; 

if ($this->content_type == 'default')
{
	JHtml::addIncludePath(JPATH_SITE . '/components/com_content/helpers');
}

// Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file'); ?>

<script>
jMA(document).ready(function($) {
    "use strict";

	// UIkit run in scope mode to avoid conflicts
	UIkit.container = '.uk-scope'; // UIkit.util.$('.uk-scope');

	// Search button validation
	$('button#search-button-home, button#search-button-page').on('click', function () {

		var filter_search 	= $('#filter_search').val();
		var filter_author 	= $('#filter_author').val();
		var filter_category = $('#filter_category').val();

		if (
			(filter_search === null || filter_search === "") && 
			(filter_author === null || filter_author === "") && 
			(filter_category === null || filter_category === "")
		   )
		{
			$("#filter_search, #filter_author, #filter_category").css("border", "1px solid red");
			UIkit.modal.alert("<?php echo JText::_('COM_MONTHLYARCHIVE_ALERT_ERROR_EMPTY_FORM'); ?>");
			return false;
		}
		else if (filter_search.length < 3)
		{
			$("#filter_search").css("border", "1px solid red");
			UIkit.modal.alert("<?php echo JText::_('COM_MONTHLYARCHIVE_ALERT_MAXLENGHT_SEARCH_INPUT_FORM'); ?>");
			return false;
		}
	});		

	// bind change event to select
	$('#filter_date, #filter_orderby, #filter_author, #filter_category').on('change', function () {

		var filter_date = $('#filter_date').val(); // get selected value
		var filter_orderby = $('#filter_orderby').val(); // get selected value
		var filter_category = $('#filter_category').val(); // get selected value
		var filter_author = $('#filter_author').val(); // get selected value
		var menu_item_id = $('#menu_item_id').val(); // get selected value

		var url = 'index.php?option=com_monthlyarchive<?php echo (!$this->sef ? '&view=archive' : ''); ?>';

		if (filter_date) 
		{
			var date_arr = filter_date.split("-");
			var year = date_arr[0];
			var month = date_arr[1];

			if (year)
			{
				url += '&year=' + year;
			}

			if (month)
			{
				url += '&month=' + month;
			}
		}
		else
		{
			url += '&year=all';
		}

		if (filter_orderby) 
		{
			url += '&orderby=' + filter_orderby;
		}

		if (filter_category) 
		{
			url += '&category=' + filter_category;
		}

		if (filter_author) 
		{
			url += '&author=' + filter_author;
		}

		if (menu_item_id) 
		{
			url += '&Itemid=' + menu_item_id;
		}

		url += '&task=archive.goToURL';

		$('#adminForm').attr('action', url);
		$('#adminForm').submit();
	});

	// CLEAR FILTERS
	$('button#clear-search-button-home, #back-to-monthly-archive').on('click', function () {
		$('#filter_search').val('');
		$('#filter_orderby').val('most_recent_first');
		$('#filter_author').val('');
		$('#filter_category').val('');
		$('#filter_date').val('all');
		$('#filter_year').val('');
		$('#filter_month').val('');
		$('#adminForm').attr('action', '<?php echo ($this->sef ? JRoute::_('index.php?option=com_monthlyarchive'.$this->menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive'.$this->menu_item_id); ?>');
		$('#adminForm').submit();
	});
	$('button#clear-search-button-page').on('click', function () {
		$('#filter_search').val('');
		$('#filter_orderby').val('most_recent_first');
		$('#filter_author').val('');
		$('#filter_category').val('');
		$('#filter_date').val('all');
		$('#filter_year').val('');
		$('#filter_month').val('');
		$('#adminForm').attr('action', '<?php echo ($this->sef ? JRoute::_('index.php?option=com_monthlyarchive&year=all'.$this->menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive&year=all'.$this->menu_item_id); ?>');
		$('#adminForm').submit();
	});
});
</script>

<?php $page_heading = (!empty($this->menu_browser_page_title)) ? $this->menu_browser_page_title : JText::_('MONTHLY_ARCHIVE'); ?>

<div class="uk-scope">
	<div id="ma-container" class="uk-container uk-padding-remove uk-margin-remove">

		<?php
		// =============================================
		// LIST OF MONTHS AND YEARS
		// =============================================
		// If year or month are not detected, display a list of months and $monthsyears_arr
		if ($this->display_type == 'list_of_months_and_years' && $this->get_year != 'all' && (empty($this->get_year) && empty($this->get_month))) : ?> 

			<?php $this->document->setTitle(!empty($this->menu_browser_page_title) ? $this->menu_browser_page_title : ($this->show_page_title_list_of_months_and_years ? $this->page_title_list_of_months_and_years : JText::_('COM_MONTHLYARCHIVE'))); ?>

			<?php if (!empty($this->menu_page_heading)): ?>
				<h1 class="uk-heading-bullet uk-h2 ma-page-heading"><?php echo $this->menu_page_heading; ?></h1>
			<?php elseif ($this->show_page_title_list_of_months_and_years): ?>
				<h1 class="uk-heading-bullet uk-h2 ma-page-heading"><?php echo $this->page_title_list_of_months_and_years; ?></h1>
			<?php endif; ?>

			<?php if ($this->show_welcome_message_list_of_months_and_years): ?>
				<div class="uk-margin-top uk-margin-bottom ma-welcome-message"><?php echo sprintf($this->welcome_message_list_of_months_and_years, count($this->content_items)); ?></div>
			<?php endif; ?>

			<?php 
			$monthsyears_arr = array();
			foreach ($this->items as $i => $item) : ?>
		
				<?php 
				if ($this->show_date_beside_articles_type == 'publish_up')
				{
					if ($item->publish_up != '0000-00-00 00:00:00'):
						$year = JHTML::_('date', $item->publish_up, "Y");
						$month = JHTML::_('date', $item->publish_up, "m");
					endif;
				}
				else
				{
					if ($item->created != '0000-00-00 00:00:00'):
						$year = JHTML::_('date', $item->created, "Y");
						$month = JHTML::_('date', $item->created, "m");
					endif;
				}
				$monthsyears_arr[$year][] = $month;
				$monthsyears_arr_count_years[$year][] = $item->id;
				$monthsyears_arr_count_months[$year][$month][] = $item->id;
				?>
		
			<?php endforeach; ?>

			<form action="<?php echo ($this->sef ? JRoute::_('index.php?option=com_monthlyarchive&year=all'.$this->menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive&year=all'.$this->menu_item_id); ?>" method="post" name="adminForm" id="adminForm" class="uk-form-stacked ma-form ma-form-list-of-months-and-years">
				
				<fieldset class="uk-fieldset ma-fieldset">
				
					<?php if ($this->select_category_home || $this->select_author_home || $this->search_input_home): ?>
					
						<div class="uk-margin-medium-bottom ma-form-fields">

							<?php if($this->select_category_home || $this->select_author_home): ?>
								<div class="uk-grid-small uk-margin uk-child-width-expand@s" uk-grid>
									<?php if($this->select_category_home): ?>
										<div class="ma-select-category">
											<div class="uk-form-controls">
												<?php echo $this->categories_list; ?>
											</div>
										</div>
									<?php endif; ?>
									<?php if($this->select_author_home): ?>
										<div class="ma-select-author">
											<div class="uk-form-controls">
												<?php echo $this->authors_list; ?>
											</div>
										</div>
									<?php endif; ?>
								</div>
							<?php endif; ?>

							<?php if($this->search_input_home): ?>
								<div class="uk-grid-small uk-margin uk-margin-remove-bottom ma-search-input-grid" uk-grid>
									<div class="uk-width-3-5@s ma-search-input-form-field">
										<?php echo $this->search_input; ?>
									</div>
									<div class="uk-width-2-5@s uk-text-right@s">
										<div class="uk-grid-small" uk-grid>
											<div class="uk-width-2-3">
												<button type="submit" id="search-button-home" class="uk-button uk-button-default uk-width-1-1 ma-search-btn"><span uk-icon="icon: search; ratio: 0.6"></span> <?php echo JText::_('COM_MONTHLYARCHIVE_SEARCH'); ?></button>
											</div>
											<div class="uk-width-1-3">
												<button type="button" id="clear-search-button-home" class="uk-button uk-button-default uk-width-1-1 ma-clear-btn" data-tooltip="<?php echo JText::_('COM_MONTHLYARCHIVE_CLEAR_FORM'); ?>"><span uk-icon="icon: close"></span></button>
											</div>
										</div>
									</div>
								</div>
							<?php endif; ?>
					
						</div>

					<?php endif; ?>

					<?php if ($this->ma_layout == 'accordion'): ?>
						<ul class="uk-margin-remove ma-accordion-list" uk-accordion>
					<?php endif; ?>

					<?php
					// Years ordering
					if ($this->sort_years_by == 'newest_first'):
						krsort($monthsyears_arr); // high to low (most recent years first)
					elseif ($this->sort_years_by == 'oldest_first'):
						ksort($monthsyears_arr); // low to high (oldest years first)
					endif;
					?>

					<?php
					$count_year = 1;
					$count_month = 1;
					foreach ($monthsyears_arr as $year=>$months): ?>

						<?php
						if ($this->show_year || $this->ma_layout == 'accordion'):
							$limit_of_years = $this->limit_of_years;
						else:
							$limit_of_years = 24;
						endif;
						?>

						<?php if ($count_year++ <= $limit_of_years): ?>

							<?php if ($this->ma_layout == 'accordion'): ?>
								<li class="ma-accordion-list-item">
							<?php endif; ?>		

							<?php if ($this->show_year || $this->ma_layout == 'accordion'): ?>

								<?php $count_articles_by_year = count($monthsyears_arr_count_years[$year]); ?>
								
								<?php if ($this->ma_layout == 'accordion'): ?>

									<h3 class="uk-accordion-title ma-accordion-title">
										<?php echo $year; ?>
										<?php if($this->show_count_of_articles_beside_years): ?>
											<div class="uk-display-inline-block">
												(<?php echo $count_articles_by_year; ?> <?php echo ($count_articles_by_year > 1 ? JText::_('COM_MONTHLYARCHIVE_ARTICLES') : JText::_('COM_MONTHLYARCHIVE_ARTICLE')); ?>)
											</div>
										<?php endif; ?>
									</h3>
								
								<?php elseif ($this->ma_layout == 'default'): ?>
									
									<?php $margin_year = (($this->show_year && !$this->show_month) || $this->ma_layout == 'accordion') ? 'uk-margin-small-bottom' : 'uk-margin-remove'; ?>

									<div class="uk-clearfix">
										<h3 class="uk-text-bold uk-display-inline-block ma-year-heading <?php echo $margin_year; ?>">
											<a href="<?php echo ($this->sef ? JRoute::_('index.php?option=com_monthlyarchive&year='.(int) $year.$this->menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive&year='.(int) $year.$this->menu_item_id); ?>"<?php echo $this->rel_nofollow; ?>>
												<?php echo $year; ?>
											</a>
										</h3>

										<?php if($this->show_count_of_articles_beside_years): ?>
											<div class="uk-display-inline-block">
												(<?php echo $count_articles_by_year; ?> <?php echo ($count_articles_by_year > 1 ? JText::_('COM_MONTHLYARCHIVE_ARTICLES') : JText::_('COM_MONTHLYARCHIVE_ARTICLE')); ?>)
											</div>
										<?php endif; ?>
										
									</div>

								<?php endif; ?>
									
							<?php endif; ?>
							
							<?php if ($this->show_month || $this->ma_layout == 'accordion'): ?>

								<?php 
								if (($this->show_year && $this->show_month) || $this->ma_layout == 'accordion')
								{
									$margin_class = ($this->ma_layout == 'accordion') ? 'uk-margin-remove-left' : 'uk-margin-remove-left uk-margin-bottom uk-margin-small-top';
								}
								elseif (($this->show_year && !$this->show_month) || $this->ma_layout == 'accordion')
								{
									$margin_class = 'uk-margin-remove';
								}
								elseif ((!$this->show_year && $this->show_month) || $this->ma_layout == 'accordion')
								{
									$margin_class = 'uk-margin-small-bottom uk-margin-remove-left uk-margin-remove-top';
								}
								else
								{
									$margin_class = '';
								}
								?>

									<?php if ($this->ma_layout == 'accordion'): ?>
										<div class="uk-accordion-content ma-accordion-content">
									<?php endif; ?>

									<ul class="uk-list ma-list <?php echo $margin_class; ?>">
										<?php 

										$months_arr_reverse = array_reverse(array_values(array_unique($months)));
										$months_arr = array_values(array_unique($months));

										// Months ordering
										if ($this->sort_months_by == 'asc'):
											asort($months_arr); // low to high (order months desc)
										elseif ($this->sort_months_by == 'desc'):
											arsort($months_arr); // high to low (order months asc)
										endif;
											
										// re-index array
										$months_arr = array_values($months_arr);

										for ($i=0;$i<count($months_arr);$i++): 

											if (!$this->show_year && $this->ma_layout == 'default' && $count_month > $this->limit_of_months):
												break;
											endif; 

											$month = $months_arr[$i] < 10 ? '0'. (int) $months_arr[$i] : (int) $months_arr[$i];
											$dateObj   = DateTime::createFromFormat('!m', (int) $month);
											$month_name = $dateObj->format('F');
											$month_name = JText::_($month_name."_FULL");
											$count_articles_by_month = count($monthsyears_arr_count_months[$year][$month]);
											?>
												<li>
													<a href="<?php echo ($this->sef ? JRoute::_('index.php?option=com_monthlyarchive&year='.(int) $year.'&month='.$month.$this->menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive&year='.(int) $year.'&month='.$month.$this->menu_item_id); ?>"<?php echo $this->rel_nofollow; ?>>
														<?php echo $month_name.' '.$year; ?>
													</a>
													<?php if($this->show_count_of_articles_beside_months): ?>
														<span>(<?php echo $count_articles_by_month; ?> <?php echo ($count_articles_by_month > 1 ? JText::_('COM_MONTHLYARCHIVE_ARTICLES') : JText::_('COM_MONTHLYARCHIVE_ARTICLE')); ?>)</span>
													<?php endif; ?>
												</li>

										<?php
										$count_month++;
										endfor;
										?>
									</ul>

									<?php if ($this->ma_layout == 'accordion'): ?>
										</div>
									<?php endif; ?>
							
							<?php endif; ?>

							<?php if ($this->ma_layout == 'accordion'): ?>
								</li>
							<?php endif; ?>

						<?php endif; ?>

					<?php endforeach; ?>

					<?php if ($this->ma_layout == 'accordion'): ?>
						</ul>
					<?php endif; ?>

					<input type="hidden" name="menu_item_id" id="menu_item_id" value="<?php echo $this->menu_item_id_value; ?>"/>
					<?php echo JHtml::_('form.token'); ?>
				
				</fieldset>

			</form>

		<?php else: ?>
			
			<?php 
			// =============================================
			// LIST OF ALL ARTICLES
			// =============================================
			
			// Title
			if (empty($this->get_year) || $this->get_year == 'all'): ?>
			
				<?php $this->document->setTitle(JText::_($page_heading)); ?>

				<?php if (!empty($this->menu_page_heading)): ?>
					<h1 class="uk-heading-bullet uk-h2 uk-display-inline-block uk-margin-right ma-page-heading"><?php echo $this->menu_page_heading; ?></h1>
				<?php elseif ($this->show_page_title_list_of_all_articles): ?>
					<h1 class="uk-heading-bullet uk-h2 uk-display-inline-block uk-margin-right ma-page-heading"><?php echo $this->page_title_list_of_all_articles; ?></h1>
				<?php endif; ?>

				<?php if ($this->display_type == 'list_of_months_and_years' && $this->show_back_btn): ?>
					<div class="uk-display-inline-block ma-back-btn-area"><button type="button" class="uk-button uk-button-link uk-text-lowercase ma-back-btn" id="back-to-monthly-archive"><?php echo JText::_('COM_MONTHLYARCHIVE_BACK'); ?> <span uk-icon="icon: arrow-right"></span></button></div>
				<?php endif; ?>

			<?php elseif (!empty($this->get_year) && (is_numeric($this->get_year) && strlen($this->get_year) == 4)): ?>

				<?php 
				$dateObj   = DateTime::createFromFormat('!m', (int) $this->get_month);
				$month_name = $dateObj->format('m');
				//$month_name = JText::_($month_name."_FULL");
				$date_page_heading = (!empty($this->get_month) ? $this->get_year . '年' . $month_name.'月' : '');
				$this->document->setTitle(JText::_($date_page_heading) . ' - ' . JText::_($page_heading)); 
				?>

				<?php if (!empty($this->menu_page_heading)): ?>
					<h1 class="uk-heading-bullet uk-h2 uk-display-inline-block uk-margin-right ma-page-heading"><?php echo $this->menu_page_heading; ?></h1>
				<?php elseif ($this->show_page_title_list_of_all_articles): ?>
					<h1 class="uk-heading-bullet uk-h2 uk-display-inline-block uk-margin-right ma-page-heading"><?php echo $this->page_title_list_of_all_articles; ?></h1>
				<?php endif; ?>

				<?php if ($this->display_type == 'list_of_months_and_years' && $this->show_back_btn): ?>
					<div class="uk-display-inline-block ma-back-btn-area"><button type="button" class="uk-button uk-button-link uk-text-lowercase ma-back-btn" id="back-to-monthly-archive"><?php echo JText::_('COM_MONTHLYARCHIVE_BACK'); ?><span uk-icon="icon: arrow-right"></span></button></div>
				<?php endif; ?>

				<h2 class="uk-h3 uk-margin-top uk-margin-bottom ma-page-heading-date"><?php echo JText::_($date_page_heading); ?></h2>

			<?php endif; ?>

			<?php if ($this->show_welcome_message_list_of_all_articles): ?>
				
				<?php
				// get results counter
				$get_results_counter_html = $this->pagination->getResultsCounter();
				$get_results_counter_matches = array();
				if (!empty($get_results_counter_html))
				{
					preg_match_all('/[0-9]+/', $get_results_counter_html, $get_results_counter_matches);
					$get_results_counter = (int) (isset($get_results_counter_matches[0][2]) ? $get_results_counter_matches[0][2] : count($this->items));
				}
				else
				{
					$get_results_counter = (int) count($this->items);
				}
				?>

				<div class="uk-margin-top uk-margin-bottom ma-welcome-message">
					<?php echo sprintf($this->welcome_message_list_of_all_articles, $get_results_counter); ?>
				</div>
				
			<?php endif; ?>

			<form action="<?php echo ($this->sef ? JRoute::_('index.php?option=com_monthlyarchive&year='.$this->get_year.'&month='.$this->get_month.$this->menu_item_id) : 'index.php?option=com_monthlyarchive&view=archive&year='.$this->get_year.'&month='.$this->get_month.$this->menu_item_id); ?>" method="post" name="adminForm" id="adminForm" class="uk-form-stacked ma-form ma-form-list-of-articles">
			
				<fieldset class="uk-fieldset ma-fieldset">

					<?php if($this->select_months_page || $this->select_order_page || $this->select_category_page || $this->select_author_page): ?>
						<div class="uk-grid-small uk-margin uk-child-width-expand@s" uk-grid>
							<?php if($this->select_months_page): ?>
								<div class="ma-select-date">
									<div class="uk-form-controls">
										<?php echo $this->date_list; ?>
									</div>
								</div>
							<?php endif; ?>
							
							<?php if($this->select_order_page): ?>
								<div class="ma-select-order">
									<div class="uk-form-controls">
										<?php echo $this->orderby_list; ?>
									</div>
								</div>
							<?php endif; ?>
			
							<?php if($this->select_category_page): ?>
								<div class="ma-select-category">
									<div class="uk-form-controls">
										<?php echo $this->categories_list; ?>
									</div>
								</div>
							<?php endif; ?>

							<?php if($this->select_author_page): ?>
								<div class="ma-select-author">
									<div class="uk-form-controls">
										<?php echo $this->authors_list; ?>
									</div>
								</div>
							<?php endif; ?>
						</div>
					<?php endif; ?>

					<?php if($this->search_input_page): ?>
						<div class="uk-grid-small uk-margin ma-search-input-grid" uk-grid>
							<div class="uk-width-3-5@s ma-search-input-form-field">
								<?php echo $this->search_input; ?>
							</div>
							<div class="uk-width-2-5@s uk-text-right@s">
								<div class="uk-grid-small" uk-grid>
									<div class="uk-width-2-3">
										<button type="submit" id="search-button-page" class="uk-button uk-button-default uk-width-1-1 ma-search-btn"><span uk-icon="icon: search; ratio: 0.6"></span> <?php echo JText::_('COM_MONTHLYARCHIVE_SEARCH'); ?></button>
									</div>
									<div class="uk-width-1-3">
										<button type="button" id="clear-search-button-page" class="uk-button uk-button-default uk-width-1-1 ma-clear-btn" data-tooltip="<?php echo JText::_('COM_MONTHLYARCHIVE_CLEAR_FORM'); ?>"><span uk-icon="icon: close"></span></button>
									</div>
								</div>
							</div>
						</div>
					<?php endif; ?>

					<div class="uk-clearfix uk-margin-bottom ma-clearfix"></div>






					
					<?php if (count($this->items) > 0): ?>
						
						<div class="ma-articles-list">
							
							<?php foreach ($this->items as $i => $item): ?>
							
								<?php 
								// date format
								if ($this->default_date_format == 'custom' && !empty($this->custom_date_format))
								{
									$date_format = $this->custom_date_format;
								}
								else
								{
									$date_format = $this->default_date_format;
								}

								// date format for tooltip
								if ($this->default_date_format_for_tooltip == 'custom' && !empty($this->custom_date_format_for_tooltip))
								{
									$date_format_for_tooltip = $this->custom_date_format_for_tooltip;
								}
								else
								{
									$date_format_for_tooltip = $this->default_date_format_for_tooltip;
								}

								// article's content
								if ($this->display_content_type == 'introtext')
								{
									$article_text = $item->introtext;
								}
								elseif ($this->display_content_type == 'fulltext')
								{
									if (!empty($item->fulltext))
									{
										$article_text = $item->fulltext;
									}
									elseif (!empty($item->introtext))
									{
										$article_text = $item->introtext;
									}
									else
									{
										$article_text = 'There is no text for this item';
									}
								}
								else
								{
									$article_text = $item->introtext.$item->fulltext;
								}

								// article text before limited or striped
								$article_text_fullcode = (!empty($article_text)) ? $article_text : 'empty';
								
								// limit chars
								if ($this->article_limit_chars > 0)
								{
									$article_text_limited  = JString::substr(strip_tags($article_text), 0, $this->article_limit_chars);
									$article_text_limited .= ($this->article_limit_chars < strip_tags($article_text)) ? '<span class="uk-display-inline">...</span>' : '';
									$article_text 		   = $article_text_limited;
								}

								// Allowed html tags
								$allowed_html_tags = str_replace(' ', '', $this->allowed_html_tags);
								$allowed_html_tags_arr = array();
								$allowed_html_tags_arr = explode(',', $allowed_html_tags);
								$allowed_html_tags_format = '';
								foreach ($allowed_html_tags_arr as $tag):
									$allowed_html_tags_format .= '<'.$tag.'>';
								endforeach;
								
								// article text
								if (!empty($allowed_html_tags)):
									$article_text = strip_tags($article_text, $allowed_html_tags_format);
								endif;

								// Article's Image
								if ($this->display_image || $this->display_image_in_modal)
								{
									// define variables
									$image_src_intro = ''; 
									$image_src_full = ''; 
									$image_src_auto = ''; 
									$image_src_blank = '';
									
									// global
									$blank_image_src = 'components'.DS.'com_monthlyarchive'.DS.'assets'.DS.'images'.DS.'blank-image.png';
									$image_alt = $this->escape($item->title);

									// com_k2
									if ($this->content_type == 'k2' && $this->isActive('com_k2'))
									{
										// get k2 image
										$image_src_intro = 'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg';
										$image_src_full = 'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg';
										
										// get k2 image (auto detect)
										$dom = new domDocument;
										$dom->loadHTML($article_text_fullcode);
										$dom->preserveWhiteSpace = true;
										$images = $dom->getElementsByTagName('img');
										$article_images_arr = array();
										foreach ($images as $image) {
											$article_images_arr[] = $image->getAttribute('src');
										}
						
										if (!empty($article_images_arr))
										{
											if ($this->auto_image_order == "random_image")
											{
												shuffle($article_images_arr);
											}

											if (isset($article_images_arr[0]) && JFile::exists($article_images_arr[0]))
											{
												$image_src_auto = $article_images_arr[0];
											}
											else
											{
												$image_src_auto = '';
											}
										}
										else
										{
											$image_src_auto = '';
										}
										
										// blank
										$image_src_blank = $blank_image_src;

										// IMAGE PRIORITY
										if (!empty(${"image_src_".$this->image_priority_1})):
											$image_src = ${"image_src_".$this->image_priority_1};
										elseif (!empty(${"image_src_".$this->image_priority_2})):
											$image_src = ${"image_src_".$this->image_priority_2};
										elseif (!empty(${"image_src_".$this->image_priority_3})):
											$image_src = ${"image_src_".$this->image_priority_3};
										elseif (!empty(${"image_src_".$this->image_priority_4})):
											$image_src = ${"image_src_".$this->image_priority_4};
										endif;
									}
									else
									{
									// com_content

										// get image object from com_content
										$image = json_decode($item->images);

										if (!empty($image->image_intro))
										{
											$image_src_intro = $image->image_intro;
											$image_alt = (!empty($image->image_intro_alt)) ? $image->image_intro_alt : $image_alt;
										}
										
										if (!empty($image->image_fulltext))
										{
											$image_src_full	= $image->image_fulltext;
											$image_alt = (!empty($image->image_fulltext_alt)) ? $image->image_fulltext_alt : $image_alt;
										}
										
										$dom = new domDocument;
										libxml_use_internal_errors(true); // Disable libxml errors
										$dom->loadHTML($article_text_fullcode);
										$dom->preserveWhiteSpace = true;
										$images = $dom->getElementsByTagName('img');
										$article_images_arr = array();
										foreach ($images as $image) {
											$article_images_arr[] = $image->getAttribute('src');
										}

										if (!empty($article_images_arr))
										{
											if ($this->auto_image_order == "random_image")
											{
												shuffle($article_images_arr);
											}
											
											if (isset($article_images_arr[0]) && JFile::exists($article_images_arr[0]))
											{
												$image_src_auto = $article_images_arr[0];
											}
											else
											{
												$image_src_auto = '';
											}
										}
										else
										{
											$image_src_auto = '';
										}
										
										// blank
										$image_src_blank = $blank_image_src;
										
										// IMAGE PRIORITY
										if (!empty(${"image_src_".$this->image_priority_1})):
											$image_src = ${"image_src_".$this->image_priority_1};
										elseif (!empty(${"image_src_".$this->image_priority_2})):
											$image_src = ${"image_src_".$this->image_priority_2};
										elseif (!empty(${"image_src_".$this->image_priority_3})):
											$image_src = ${"image_src_".$this->image_priority_3};
										elseif (!empty(${"image_src_".$this->image_priority_4})):
											$image_src = ${"image_src_".$this->image_priority_4};
										endif;

									}
									
								}
								?>
								
								<?php if ($this->link_type == 'modal'): ?>
									<!-- Modal Dialog -->
									<div id="modal-container-<?php echo $item->id; ?>" class="uk-modal-container" uk-modal>
										<div class="uk-modal-dialog uk-modal-body">
											<button class="uk-modal-close-outside" type="button" uk-close></button>
											<h2 class="uk-modal-title"><?php echo $this->maHighlight($this->escape($item->title), $this->filter_search); ?></h2>
											
											<?php 
											// =====
											// IMAGE IN MODAL
											// =====
											?>
											<?php if ($this->display_image_in_modal): ?>
												<?php if (!empty($image_src)): ?>
													<div class="uk-align-center ma-image-in-modal uk-text-center">
														<img 
														src="<?php echo $image_src; ?>" 
														title="<?php echo $this->escape($item->title); ?>" 
														<?php echo (!empty($image_alt) ? 'alt="'.$image_alt.'"' : ''); ?> 
														<?php echo (!empty($this->img_width) ? 'style="max-width: '.$this->img_width.'px;" width="'.$this->img_width.'"' : ''); ?> 
														<?php echo (!empty($this->img_height) ? 'style="max-height: '.$this->img_height.'px;" height="'.$this->img_height.'"' : ''); ?> 
														>
													</div>
												<?php endif; ?>
											<?php endif; ?>
											<?php 
											// import content prepare plugin         
											echo JHtml::_('content.prepare', $this->maHighlight($item->introtext.$item->fulltext, $this->filter_search));
											?>
										</div>
									</div>
								<?php endif; ?>

								<?php
								// =========================
								// BEGIN: Display Item (row)
								// =========================
								?>
								
								<div class="uk-grid-small ma-article" uk-grid>

									<?php 
									// =====
									// IMAGE
									// =====
									?>
									<?php if ($this->display_image): ?>

										<?php if (!empty($image_src)): ?>
											<div class="uk-width-1-3@s ma-image uk-text-center">

												<?php if ($this->link_to_image): ?>
													<?php if ($this->content_type == 'k2' && $this->isActive('com_k2')): ?>

														<?php if ($this->link_type == 'modal'): ?>
															<a title="<?php echo $this->escape($item->title); ?>" href="#modal-container-<?php echo $item->id; ?>" uk-toggle="container: #ma-container" <?php echo $this->rel_nofollow; ?>>
														<?php else: ?>
															<a title="<?php echo $this->escape($item->title); ?>" href="<?php echo JRoute::_(K2HelperRoute::getItemRoute($item->id,  $item->catid, $item->language)); ?>" <?php echo $this->rel_nofollow; ?>>
														<?php endif; ?>

													<?php else: ?>

														<?php if ($this->link_type == 'modal'): ?>
															<a title="<?php echo $this->escape($item->title); ?>" href="#modal-container-<?php echo $item->id; ?>" uk-toggle="container: #ma-container" <?php echo $this->rel_nofollow; ?>>
														<?php else: ?>
															<a title="<?php echo $this->escape($item->title); ?>" href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($item->id,  $item->catid, $item->language)); ?>" <?php echo $this->rel_nofollow; ?>>
														<?php endif; ?>

													<?php endif; ?>
												<?php endif; ?>
													<img 
													src="<?php echo $image_src; ?>" 
													title="<?php echo $this->escape($item->title); ?>" 
													<?php echo (!empty($image_alt) ? 'alt="'.$image_alt.'"' : ''); ?> 
													<?php echo (!empty($this->img_width) ? 'style="max-width: '.$this->img_width.'px;" width="'.$this->img_width.'"' : ''); ?> 
													<?php echo (!empty($this->img_height) ? 'style="max-height: '.$this->img_height.'px;" height="'.$this->img_height.'"' : ''); ?> 
													>
												<?php if ($this->link_to_image): ?>
													</a>
												<?php endif; ?>
												
											</div>
										<?php endif; ?>

									<?php endif; ?>

									<?php 
									// =====
									// CONTENT
									// =====
									?>
									<div class="uk-width-expand@s ma-content-item">

										<?php 
										// datetime, category, author, hits, comments
										if ($this->show_date_beside_articles || $this->show_category_beside_article || $this->show_author_beside_article || $this->show_hits || ($this->show_count_comments && !empty($item->comments_count))): ?>
									
										<div class="ma-meta-info">
											
											<?php 
											// datetime
											if ($this->show_date_beside_articles): ?>
												<?php if ($this->show_date_beside_articles_type == 'created'): ?>

													<div class="uk-display-inline-block uk-margin-right uk-margin-bottom ma-date" data-tooltip2="<?php echo JText::_( 'COM_MONTHLYARCHIVE_WRITTEN_ON' ); ?> <?php echo JHTML::_('date', $item->created, $date_format_for_tooltip); ?>"><span uk-icon="icon: clock; ratio: 0.7"></span> <time datetime="<?php echo JHTML::_('date', $item->created, 'Y-m-d H:i:s'); ?>"><?php echo JHTML::_('date', $item->created, $date_format); ?></time></div>

												<?php elseif ($this->show_date_beside_articles_type == 'publish_up'): ?>

													<div class="uk-display-inline-block uk-margin-right uk-margin-bottom ma-date" data-tooltip2="<?php echo JText::_( 'COM_MONTHLYARCHIVE_WRITTEN_ON' ); ?> <?php echo JHTML::_('date', $item->publish_up, $date_format_for_tooltip); ?>"><span uk-icon="icon: clock; ratio: 0.7"></span> <time datetime="<?php echo JHTML::_('date', $item->publish_up, 'Y-m-d H:i:s'); ?>"><?php echo JHTML::_('date', $item->publish_up, $date_format); ?></time></div>

												<?php endif; ?>
											<?php endif; ?>

											<?php 
											// category
											if ($this->show_category_beside_article): ?>
												<div class="uk-display-inline-block uk-margin-right uk-margin-bottom ma-category" data-tooltip2="<?php echo sprintf(JText::_( 'COM_MONTHLYARCHIVE_PUBLISHED_IN' ), $item->category_title); ?>"><span uk-icon="icon: folder; ratio: 0.7"></span> <?php echo $item->category_title; ?></div>
											<?php endif; ?>

											<?php 
											// author
											if ($this->show_author_beside_article): ?>
												<?php if ($this->author_name_type == 'author_name'): ?>
													<div class="uk-display-inline-block uk-margin-right uk-margin-bottom ma-author" data-tooltip2="<?php echo JText::_( 'COM_MONTHLYARCHIVE_WRITTEN_BY' ); ?> <?php echo $item->author_name; ?>."><span uk-icon="icon: user; ratio: 0.7"></span> <?php echo $item->author_name; ?></div>
												<?php elseif ($this->author_name_type == 'author_username'): ?>
													<div class="uk-display-inline-block uk-margin-right uk-margin-bottom ma-author" data-tooltip="<?php echo JText::_( 'COM_MONTHLYARCHIVE_WRITTEN_BY' ); ?> <?php echo $item->author_username; ?>."><span uk-icon="icon: user; ratio: 0.7"></span> <?php echo $item->author_username; ?></div>
												<?php endif; ?>
											<?php endif; ?>

											<?php 
											// hits
											if ($this->show_hits): ?>
												<div class="uk-display-inline-block uk-margin-right uk-margin-bottom ma-hits" data-tooltip2="<?php echo sprintf(JText::_( 'COM_MONTHLYARCHIVE_VIEWED_X_TIMES' ), (int) $item->hits); ?>"><span uk-icon="icon: bolt; ratio: 0.7"></span> <?php echo $item->hits; ?></div>
											<?php endif; ?>

											<?php 
											// edit Joomla! article
											if ($this->content_type == 'default'):

												// Technically guest could edit an article, but lets not check that to improve performance a little.
												$canEdit = false;
												$user = JFactory::getUser();
												if (!$user->get('guest'))
												{
													$userId = $user->get('id');
													$asset = 'com_content.article.' . $item->id;

													// Check general edit permission first.
													if ($user->authorise('core.edit', $asset))
													{
														$canEdit = true;
													}

													// Now check if edit.own is available.
													elseif (!empty($userId) && $user->authorise('core.edit.own', $asset))
													{
														// Check for a valid user and that they are the owner.
														if ($userId == $item->created_by)
														{
															$canEdit = true;
														}
													}
												}

												if ($canEdit): ?>
													<div class="uk-display-inline-block uk-margin-right uk-margin-bottom ma-edit-article">
														<span uk-icon="icon: pencil; ratio: 0.7"></span> 
														<?php
														$edit_article_link_with_img = JHtml::_('icon.edit', $item, $this->com_content_params, array('class'=>'ma-edit-article-link', 'uk-tooltip'=>''), true);
														$edit_article_link = preg_replace("/<img[^>]+\>/i", JText::_('JGLOBAL_EDIT_TITLE'), $edit_article_link_with_img); 
														echo $edit_article_link;
														?>
													</div>
												<?php endif; ?>

											<?php endif; ?>

											<?php
											// comments
											if ($this->show_count_comments && !empty($item->comments_count)): ?>
												<?php if ($item->comments_count > 0): ?>
													<div class="uk-display-inline-block uk-margin-bottom ma-comments" data-tooltip="<?php echo sprintf(JText::_( 'COM_MONTHLYARCHIVE_COMMENTED_X_TIMES' ), (int) $item->comments_count); ?>"><span uk-icon="icon: comments; ratio: 0.7"></span> <?php echo (int) $item->comments_count; ?></div>
												<?php endif; ?>
											<?php endif; ?>

										</div>

										<?php endif; ?>
										
										<div>
											
											<!-- TITLE -->
											<h3 class="uk-margin-small-bottom ma-title">
												<?php if ($this->link_to_article): ?>
													<?php if ($this->content_type == 'k2' && $this->isActive('com_k2')): ?>

														<?php if ($this->link_type == 'modal'): ?>
															
														<?php else: ?>
															
														<?php endif; ?>

													<?php else: ?>

														<?php if ($this->link_type == 'modal'): ?>
															
														<?php else: ?>
															
														<?php endif; ?>

													<?php endif; ?>
												<?php endif; ?>
													<?php echo $this->maHighlight($this->escape($item->title), $this->filter_search); ?>
												<?php if ($this->link_to_article): ?>
													
												<?php endif; ?>
											</h3>

											<!-- INTROTEXT -->
											<div class="ma-introtext">

												<?php 
												// import content prepare plugin
												echo $article_text_fullcode;
												?>
										
												<?php 
												// readmore link
												if ($this->show_readmore_link && $this->article_limit_chars > 0): ?>
					
													<?php if ($this->content_type == 'k2' && $this->isActive('com_k2')): ?>

														<?php if ($this->link_type == 'modal'): ?>
															<a class="uk-display-inline ma-readmore-link" href="#modal-container-<?php echo $item->id; ?>" uk-toggle="container: #ma-container" <?php echo $this->rel_nofollow; ?>>
														<?php else: ?>
															<a class="uk-display-inline ma-readmore-link" href="<?php echo JRoute::_(K2HelperRoute::getItemRoute($item->id,  $item->catid, $item->language)); ?>" <?php echo $this->rel_nofollow; ?>>
														<?php endif; ?>

													<?php else: ?>

														<?php if ($this->link_type == 'modal'): ?>
															<a class="uk-display-inline ma-readmore-link" href="#modal-container-<?php echo $item->id; ?>" uk-toggle="container: #ma-container" <?php echo $this->rel_nofollow; ?>>
														<?php else: ?>
															<a class="uk-display-inline ma-readmore-link" href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($item->id,  $item->catid, $item->language)); ?>" <?php echo $this->rel_nofollow; ?>>
														<?php endif; ?>

													<?php endif; ?>
														<?php echo JText::_( 'COM_MONTHLYARCHIVE_READMORE'); ?>
													</a>

												<?php endif; ?>

											</div>
										</div>
										
									</div>
								
								</div>
								
								<hr class="uk-text-center uk-margin-top uk-margin-bottom ma-divider">

								<?php
								// =========================
								// END: Display Item (row)
								// =========================
								?>

							<?php endforeach; ?>
						</div>
						
						<?php if ($this->display_pagination): ?>
							<div class="uk-text-center ma-pagination">
								<div class="uk-display-block ma-pagination-list-footer pagination"><?php echo $this->pagination->getPagesLinks(); ?></div>
								<div class="uk-display-block ma-pagination-results-counter"><?php echo $this->pagination->getResultsCounter(); ?></div>
							</div>
						<?php endif; ?>
							
					<?php endif; ?>
				
				</fieldset>

				<input type="hidden" name="menu_item_id" id="menu_item_id" value="<?php echo $this->menu_item_id_value; ?>"/>
				<?php echo JHtml::_('form.token'); ?>
			</form>

		<?php endif; ?>

		<?php if (count($this->items) == 0): ?>

			<div class="uk-margin-small-top ma-no-results">
				<?php 
				$filter_search_state = $this->getState('filter.search');
				if (!empty($filter_search_state)):
					echo sprintf(JText::_( 'COM_MONTHLYARCHIVE_EMPTY_SEARCH_RESULTS' ), $this->getState('filter.search'));
				else:
					echo JText::_( 'COM_MONTHLYARCHIVE_NO_RESULTS' );
				endif;
				?>
			</div>

		<?php endif; ?>

		<?php
		// Copyright message
		if ($this->copyright):
			echo '<div class="uk-margin-top uk-text-center ma-copyright uk-text-muted">'.JText::_('COM_MONTHLYARCHIVE_POWERED_BY').' <a href="https://www.web357.eu/joomla-extensions/monthly-archive?utm_source=CLIENT&utm_medium=CLIENT-CopyrightLink-monthlyarchive&utm_content=CLIENT-CopyrightLink&utm_campaign=monthlyarchive" rel="nofollow" target="_blank">'.JText::_('MONTHLY_ARCHIVE').'</a></div>';
		endif;
		?>

	</div>
</div>