<?php
$query = "SELECT * FROM  main_article WHERE article_id = '$middle_article_id' AND active='yes'";
$result = mysql_query ($query) or die("<b>$query</b>".mysql_error());
if($result && mysql_num_rows($result)>0) {
	$line = mysql_fetch_assoc($result);
	//echo '<pre>', var_export($line, true), '</pre>';
	if(trim($line["url"]) != ""){
		$ahref = return_link_article('article_', $line['_blank'], $line['url'], $line['friendly_url'], $line["article_id"]);
		?>
		<div class="article_list_title_link">
			<p class="article_list_title_link">
				<a class="article_class" href="<?php  echo $ahref['link'];?>" target="<?php  echo $ahref['target'];?>"><span><?php  echo $line["title_en"];?></span></a>
			</p>
		</div>
		<?php 
	}
	else {
		$show_title = ($line["active_title_en"] == "yes") ? true : false;
		$show_abstract = true;
		$article_title = stripslashes(trim($line["title_en"]));
		$article_friendly_url = trim($line['friendly_url']);
		$page_title = stripslashes($line['page_title_en']);
		if($article_title == "") $show_title = false;
		$article_description = stripslashes(trim($line["description_en"]));
		$article_meta_description = stripslashes(trim($line["meta_description_en"]));
		$article_meta_keywords = stripslashes(trim($line["meta_keywords_en"]));
		
		
		// Get host data
		$_host = $_SERVER['HTTP_HOST'];
		if(str_replace('www.', '', $ultra_domainname) != str_replace('www.', '', $_host)) {
			$_host .= "/$ultra_addonname";
		}
		
		$is_h1 = true;
		
		$article_url = $protocol . $_host . "/article/$article_friendly_url.html";
		$page_url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		$page_url_parts = parse_url($page_url);
		$page_url = $page_url_parts['scheme'] . '://' . $page_url_parts['host'] . $page_url_parts['path'];
		
		
		if($article_url != $page_url) {
			$is_h1 = false;
		}
		
		
		/*
		if(isset($module_params['main_article_link_title']) && trim($module_params['main_article_link_title']) != "") {
			$article_title = trim(stripslashes($module_params['main_article_link_title']));
			
			$show_title = true;
		}
		*/
		
		if(isset($module_params['main_article_show_abstract']) && intval($module_params['main_article_show_abstract']) == 0) {
			$show_abstract = false;
		}

		

		
				
		if($show_title) {
			/* Social Media plugin **********/
			/*$sm_class_overload = "sm-categ";
			include(dirname(__FILE__) . "/../sm/sm.php");*/
			/***************************/
			if($is_h1) {
				?>
                <header>
                    <h1 itemprop="name"><?php  echo $article_title; ?></h1>
                    <!--[/SocialShareButtons/]-->
                </header>
				<?php
			}
			else {
				?>
				<h2 itemprop="name"><?php  echo $article_title; ?></h2>
				<?php
			}
		}
		
		// Get photos
		$main_photo = array();
		$art_photos = array();
		$q = "select * from main_article_images where article_id='$middle_article_id' order by pos asc;";
		$r = @mysql_query($q);
		if($r && mysql_num_rows($r) > 0) {
			
			$optres['js'][] = $_SERVER['DOCUMENT_ROOT'] . "/js/galleria-1.2.9.min.js";
			while ($row = mysql_fetch_assoc($r)) {
				if(count($main_photo) == 0) {
					$main_photo = $row;
				}
				
				$art_photos [] = array_map("stripslashes", $row);
			}
		}
		
		?>
        <meta itemprop="headline" content="<?php  echo $article_title; ?>">
		<div class="article-body cyprus <?php echo ($article_description == "") ? "no-margin": "";?>" itemprop="articleBody">
            <?php
            if($content_type == "news") {
                ?>
                <div class="news-date">
                    <i class="fa fa-clock-o"></i>
                    <?php
                    if(!isset($news_location)) {
                        echo '<span class="news-posted-text" itemprop="dateline">Cyprus</span> | ';
                    }
                    else {
                        echo '<span class="news-posted-text" itemprop="dateline">',$news_location,'</span> | ';
                    }
                    ?>
                    <span class="news-posted-text">Posted: </span>
                    <meta itemprop="datePublished" content="<?=date('c', $created_timestamp);?>">
                    <time datetime="<?php echo $created; ?>"  pubdate=""><?php echo $created_str; ?></time>
                </div>
                <?php
            }
            ?>
			<div class="article_description">
				<?php
				if(isset($art_photos) && count($art_photos) > 0) {
					//echo '<pre>', var_export($art_photos, true), '</pre>';
					?>
                    <div id="galleria" class="article-gallery">
						<?php
						$www_root = $_SERVER['HTTP_HOST'];
						if(str_replace('www.', '', $www_root) != str_replace('www.', '', $ultra_domainname) ) {
							$www_root .= "/$ultra_addonname";
						}
						
						foreach ($art_photos as $i=>$img) {
							$thumb_file = dirname(__FILE__) . "/../../images/articles/$domain_id/$middle_article_id/gallery/thumbs/" . $img['filename'];
							$thumb_url = $protocol . $_SERVER['HTTP_HOST'] . "/images/articles/$domain_id/$middle_article_id/gallery/thumbs/" . $img['filename'];
							$image_file = dirname(__FILE__) . "/../../images/articles/$domain_id/$middle_article_id/gallery/" . $img['filename'];
							$image_url = $protocol . $_SERVER['HTTP_HOST'] . "/images/articles/$domain_id/$middle_article_id/gallery/" . $img['filename'];
							
							if(intval( $img['iwt'] <= 16)) $img['iwt'] = 90;
							if(intval( $img['iht'] <= 16)) $img['iht'] = 90;
							
							$data_title = $img['title'];
							$data_description = $img['description'];
							
							if(file_exists($thumb_file) && file_exists($image_file)) {
								if($i == 0) {
									echo '<a href="', $image_url, '" itemprop="image"><img src="',$thumb_url,'" data-big="',$image_url,'" data-title="',$data_title,'" data-description="',$data_description,'"  alt="',$data_title,'" width="',$img['iwt'],'" height="',$img['iht'],'"/></a>';
								}
								else {
									echo '<a href="', $image_url, '"><img src="',$thumb_url,'" data-big="',$image_url,'" data-title="',$data_title,'" data-description="',$data_description,'"  alt="',$data_title,'" width="',$img['iwt'],'" height="',$img['iht'],'"/></a>';
								}
							}
							else {
								// echo "<br/>$thumb_file does not exists";
							}
						}
						?>
					</div>
					<?php
				}
				$article_description = str_replace("../images/", $path ."images/", $article_description);
				$article_description = str_replace(array('<p></p>', '<p> </p>', '<p>&nbsp;</p>'), '', $article_description);
				if($show_title) {
					$article_description = str_ireplace(array('<h1', '</h1'), array('<h2', '</h2'), $article_description);
				}
				echo $article_description;
				?>
			</div>
		</div>
		<?php
		
		if(str_replace("/" . $line['friendly_url'].'.html', '', $_SERVER['REQUEST_URI']) != $_SERVER['REQUEST_URI']) {
			$webpage_title_en = $page_title;
			if($article_meta_description != "") {
				$meta['description'] = $article_meta_description;
			}
			else {
				if(trim(strip_tags($line['short_descr_en'])) != "" && $line['use_meta'] == 1) {
					$meta['description'] = mb_substr(trim(fix_stripped_words(stripslashes($line['short_descr_en']))), 0, 150, 'UTF-8');
				}
				else {
					$meta['description'] = mb_substr(trim(fix_stripped_words($article_description)), 0, 150, 'UTF-8');
				}
			}
			
			if($article_meta_keywords != "") {
				$meta['keywords'] = $article_meta_keywords;
			}
			else {
				$meta['keywords'] = $article_title . ', ' . $meta['keywords'];
			}
		}
		
	}
}
?>