<?php
	$detail=mysql_query("SELECT * FROM berita 
										left join users on berita.username=users.username
											left join kategori on berita.id_kategori=kategori.id_kategori
												where judul_seo='$_GET[judul]'");
	$d   = mysql_fetch_array($detail);
	$tgl = tgl_indo($d[tanggal]);
	$baca = $d[dibaca]+1;
	
			$BatasAwal = 5000;
			if (!empty($_GET['page'])) {
				$hal = $_GET['page'] - 1;
				$MulaiAwal = $BatasAwal * $hal;
			} else if (!empty($_GET['page']) and $_GET['page'] == 1) {
				$MulaiAwal = 0;
			} else if (empty($_GET['page'])) {
				$MulaiAwal = 0;
			}
			
	$isi_berita = $d['isi_berita']; 
	$isi = substr($isi_berita,$MulaiAwal,$BatasAwal); 
	$total = strlen($isi_berita);
	mysql_query("UPDATE berita SET dibaca=$d[dibaca]+1 
              WHERE judul_seo='$_GET[judul]'");
			  
	$komen3 = "SELECT * FROM komentar WHERE id_berita = '".$d['id_berita']."'";
	$komentar3 = mysql_query($komen3);
	$total_komentar = mysql_num_rows($komentar3);
?>	
						<div class="full-width">
							<div class="article-title">
								<div class="share-block right">
									<div>
										<div class="share-article left">
											<span>Social media</span>
											<strong>Share this article</strong>
										</div>
										<div class="left">
											<script language="javascript">
											document.write("<a href='http://www.facebook.com/share.php?u=" + document.URL + " ' target='_blank' class='custom-soc icon-text'>&#62220;</a> <a href='http://twitter.com/home/?status=" + document.URL + "' target='_blank' class='custom-soc icon-text'>&#62217;</a> <a href='https://plus.google.com/share?url=" + document.URL + "' target='_blank' class='custom-soc icon-text'>&#62223;</a>");
											</script>
											<a href="#" class="custom-soc icon-text">&#62232;</a>
											<a href="#" class="custom-soc icon-text">&#62226;</a>
										</div>
										<div class="clear-float"></div>
									</div>
									<div>
										<a href="javascript:printArticle();" class="small-button"><span class="icon-text">&#59158;</span>&nbsp;&nbsp;Print this article</a>
										<a href="#" class="small-button"><span class="icon-text">&#9993;</span>&nbsp;&nbsp;Send e-mail</a>
									</div>
								</div>

								<h1><?php echo "<b>$d[judul]</b>"; ?></h1>
								<div class="author">
									<span class="hover-effect left">
									<?php $test = md5(strtolower(trim($d['email']))); 
										echo "<img src=\"http://www.gravatar.com/avatar/".$test.".jpg?s=100&d=".$_GET['d']."\" />";
									?>
									</span>
									<div class="a-content">
										<span>By <b><?php echo "$d[nama_lengkap]"; ?></b></span>
										<span class="meta"><?php echo "$tgl, $d[jam] WIB"; ?><span class="tag" style="background-color: #2a8ece;"><a href="<?php echo "kategori-$d[id_kategori]-$d[kategori_seo].html"; ?>"><?php echo "$d[nama_kategori]"; ?></a></span></span>
									</div>
								</div>
							</div>

						</div>

						<div class="main-page left">
							<div class="single-block">
								<div class="content-block main left">
									
									<div class="block">
										<div class="block-content">
												
											<p><span style="height:10%; overflow:hidden; background:none;" class="hover-effect">
											<?php
												if ($d[gambar] !=''){
													echo "<img style='width:890px;' src='foto_berita/$d[gambar]' alt='$d[judul]' /></a>";
												}
											?>
											
											</span></p>
											
											<div class="shortcode-content">

												<div class="paragraph-row">
													<div class="column3">
														<h3 class="highlight-title">Informasi Populer</h3>
														<ul>
															<?php 
																$random2 = mysql_query("SELECT * FROM berita 
																								left join users on berita.username=users.username
																									left join kategori on berita.id_kategori=kategori.id_kategori
																										order by dibaca DESC LIMIT 3");

																while ($r2 = mysql_fetch_array($random2)){
																	$tglr2 = tgl_indo($r2['tanggal']);
																	echo "<li><a href='berita-$r2[judul_seo].html'>$r2[judul]</a></li>";
																}
															?>
														</ul>
														<h3 class="highlight-title">Informasi Terkait</h3>
														<ul>
															<?php
																  $pisah_kata  = explode(",",$d[tag]);
																  $jml_katakan = (integer)count($pisah_kata);

																  $jml_kata = $jml_katakan-1; 
																  $ambil_id = substr($d[id_berita],0,4);

																  $cari = "SELECT * FROM berita WHERE (id_berita<'$ambil_id') and (id_berita!='$ambil_id') and (" ;
																  for ($i=0; $i<=$jml_kata; $i++){
																  $cari .= "tag LIKE '%$pisah_kata[$i]%'";
																  if ($i < $jml_kata ){
																  $cari .= " OR ";}}
																  $cari .= ") ORDER BY id_berita DESC LIMIT 3";

																  $hasil  = mysql_query($cari);
																  while($h=mysql_fetch_array($hasil)){
																	$komen1 = "SELECT * FROM komentar WHERE id_berita = '".$h['id_berita']."'";
																	$komentar1 = mysql_query($komen1);
																	$total_komentar1 = mysql_num_rows($komentar1);
																  echo "<li><a href=berita-$h[judul_seo].html>$h[judul]</a><a href='#' class='h-comment'>$total_komentar1</a></li>";}      
																  mysql_query("UPDATE berita SET dibaca=$d[dibaca]+1 WHERE judul_seo='$_GET[judul]'");
															?>
														</ul>
													</div>
													<div class="column9">
														<?php 
															echo "$isi "; 
															
															$jumlahData = strlen($d['isi_berita']);
															echo "<br><div style='float:left' class='pagination'>";
															if ($jumlahData >= $BatasAwal) {
																echo "<b style='color:red'>Next : </b>";
																$a = explode(".", $jumlahData / $BatasAwal);
																$b = $a[0];
																$b2 = $a[1];
																	if ($b2 == ''){
																	  $c = $b;
																	}else{
																	  $c = $b + 1;
																	}
																for ($i = 1; $i <= $c; $i++) {
																	if ($_GET[page]==$i){
																		echo "<a style='text-decoration:none; color:red' href='detail-berita-$d[judul_seo]-page-$i.html'> $i </a>";
																	}else{
																		echo "<a style='text-decoration:none;' href='detail-berita-$d[judul_seo]-page-$i.html'> $i </a>";
																	}
																}
															}
															echo "</div><div style='clear:both'></div>";
															
															if ($d[youtube]!=''){
																  echo "<h4>Video Terkait:</h4>
																  <iframe width='100%' height='350' src='$d[youtube]' frameborder='0' allowfullscreen></iframe>
																  <div class='garis'></div><br/>";
															}
														?>
													</div>
												</div>

												<div class="article-title">
													<div class="share-block right">
														<div>
															<div class="share-article left">
																<span>Social media</span>
																<strong>Share this article</strong>
															</div>
															<div class="left">
																<script language="javascript">
																document.write("<a href='http://www.facebook.com/share.php?u=" + document.URL + " ' target='_blank' class='custom-soc icon-text'>&#62220;</a> <a href='http://twitter.com/home/?status=" + document.URL + "' target='_blank' class='custom-soc icon-text'>&#62217;</a> <a href='https://plus.google.com/share?url=" + document.URL + "' target='_blank' class='custom-soc icon-text'>&#62223;</a>");
																</script>
																<a href="#" class="custom-soc icon-text">&#62232;</a>
																<a href="#" class="custom-soc icon-text">&#62226;</a>
															</div>
														</div>
														
													</div>

													<div style="margin-top:0px" class="article-tags tag-cloud">
														<strong>TAGS:</strong>
														<?php
															$tags = (explode(",",$d[tag]));
															$hitung = count($tags);
															for ($x=0; $x<=$hitung; $x++) {
																if ($tags[$x] == ''){
																}else{
																	echo "<a href='#'>$tags[$x]</a>";
																}
															}
															
														?>
													</div>
													
												</div>

											</div>

										</div>
										
										<div id="fb-root"></div>
										<script>(function(d, s, id) {
										  var js, fjs = d.getElementsByTagName(s)[0];
										  if (d.getElementById(id)) return;
										  js = d.createElement(s); js.id = id;
										  js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.0";
										  fjs.parentNode.insertBefore(js, fjs);
										}(document, 'script', 'facebook-jssdk'));</script>
										<div id="viewcomment" class="block-title">
											<a href="#writecomment" class="right">Write a Facebook Comment</a>
											<h2>
												Tuliskan Komentar anda dari account Facebook
											</h2>
										</div>
										<div class="block-content">
											<div class="comment-block">
												<div class="fb-comments" data-href="<?php echo $iden[url].'/berita-'.$d[judul_seo].'.html'; ?>" data-width="855" data-numposts="5" data-colorscheme="light"></div> 
											</div>
										</div>

									</div>
								</div>
							</div>
						</div>