<?php
$gallery_items = json_decode($the_gallery['gallery_items'], TRUE);
$gallery_featured = $gallery_items['storyimage'];
$gallery_link = "photos/".$the_gallery['gallery_url']."/";

$tt_page_info = array(
  'Page_Info' =>   array(
    'Title' => $the_gallery['gallery_title'],
    'Description' => '',
    'Keyword' =>'',
  ),
  'Social_og' => array(
    'Image' => $gallery_featured,
    'Type' => 'website',
    'URL' => $gallery_link,
  ),
);

 // Count View
 UpdateData('mahamudfutureit_gallery', 'id', $the_gallery['id'],   array("gallery_view"=> $the_gallery['gallery_view'] + 1));


// Post Writer Information
if ($the_gallery['gallery_author_name'] !='') {
  $post_writer = $the_gallery['gallery_author_name'];
  $post_writer_profile = "#";
  $post_writer_avater = $advancenews['PostWriterDefaultImage'];
  $post_writer_designation = $the_gallery['gallery_author_designation'];
}else{
  $post_writer = getSingleValue('tt_accounts', 'UserID',  $the_gallery['gallery_author'], 'UserName');
  $post_writer_profile = userProfile($the_gallery['gallery_author']);
  $post_writer_avater = userAvater($the_gallery['gallery_author']);
  $post_writer_designation = getSingleValue('tt_accounts', 'UserID',  $the_gallery['gallery_author'], 'UserDesignation');
}

require_once('./header.php'); // Include Footer
?>
<script type="application/ld+json">
  {
       "@context": "https://schema.org",
       "@type": "NewsArticle",
       "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "<?php echo $site_domain.$gallery_link ?>"
       },
       "headline": "<?php echo htmlentities($the_gallery['gallery_title'], ENT_QUOTES, 'utf-8'); ?>",
       "image": "<?php echo $gallery_featured ?>",
       "datePublished": "<?php echo $the_gallery['gallery_date'] ?>",
       "dateModified": "<?php echo $the_gallery['gallery_date'] ?>",

     "author": {
            "@type": "Person",
            "name": "<?php echo $post_writer ?>",
            "url": "<?php echo $post_writer_profile ?>"
       },
       "publisher": {
            "@type": "Organization",
            "name": "<?php echo $advancenews['Website_title'] ?>",
            "logo": {
                 "@type": "ImageObject",
                 "url": "<?php echo $advancenews['Website_Logo'] ?>"
            }
       }

  }
  </script>

<section class="  d-print-none  py-4">
  <div class="container">
    <?php
    $post_ads_1 = showAds($advancenews['PostAds1'], $advancenews['PostAdsCtl']);
    if ($post_ads_1 != '') {
      ?>
      <div class="  mb-3">
        <?php echo $post_ads_1 ?>
      </div>
      <?php
    }
    ?>
    <div class="mb-4">
      <a href="<?php echo $site_domain ?>photos/">
        <h4 class="m-0 p_post_cat2 d-inline-block  ">ফটো গ্যালারি </h4>
      </a>
    </div>

    <div class="row g-4 ">
      <div class="col-md-8">
        <div class=" ">
          <h1 class="m-0 mb-4 h1 fw-bold tt-text" style="font-size:var(--tt_post_title_fs)"><?php echo htmlentities($the_gallery['gallery_title'], ENT_QUOTES, 'utf-8'); ?></h1>
          <hr class="d-block d-lg-none">
          <div class="row g-4 align-items-center">
            <div class="col-12 col-md-6">
              <div class="d-flex align-items-center">
                <a href="<?php echo $post_writer_profile ?>">
                  <img class="rounded-circle" height="50px" width="auto" src="<?php echo $post_writer_avater ?>" alt="<?php echo htmlentities($post_writer, ENT_QUOTES, 'utf-8'); ?>">
                </a>
                <div class="ms-2">
                  <a href="<?php echo $post_writer_profile ?>" class="tt-text">
                    <h5 class="m-0 h5 fw-bold"><?php echo htmlentities($post_writer, ENT_QUOTES, 'utf-8'); ?>
                      <?php
                      if ($post_writer_designation !='') {
                        ?>
                        <small class="opacity-75 fw-normal"><?php echo $post_writer_designation ?></small>
                        <?php
                      }
                      ?>
                    </h5>
                  </a>
                  <span class="tt-text">প্রকাশ : <?php echo dokanDate($the_gallery['gallery_date']) ?></span>
                </div>
              </div>
            </div>
            <!-- share -->
            <div class="col-12 col-md-6">
              <div class="myshare-mahamudfutureit">
                <div class="sharethis-inline-share-buttons text-start text-lg-end"   data-title="<?php echo $the_gallery['gallery_title'] ?>" data-url="<?php echo  $site_domain.$gallery_link ?>"></div>
              </div>
            </div>
          </div>
          <hr class="d-none d-lg-block">
          <?php
          foreach ($gallery_items as $the_gitem) {
            if ($the_gitem['storyimage'] !='') {
              ?>
              <div class="story-image popup-gallery mb-2">
                <a class=" overflow-hidden" title="<?php echo htmlentities($the_gitem['storycaption'], ENT_QUOTES, 'utf-8'); ?>" href="<?php echo $the_gitem['storyimage']; ?>">
                  <img  class="w-100 rounded-2" src="<?php echo $advancenews['ArticlePreloader'] ?>"  data-src="<?php echo $the_gitem['storyimage']; ?>" alt="<?php echo htmlentities($the_gallery['gallery_title'], ENT_QUOTES, 'utf-8'); ?>">
                </a>
              </div>
              <?php
              if ($the_gitem['storycaption'] !='') {
                ?>
                <div class="story-details tt-text mb-2">
                  <p><?php echo $the_gitem['storycaption'] ?></p>
                </div>
                <?php
              }
            }
          }
          ?>
        </div>
        <?php
        $post_ads_5 = showAds($advancenews['PostAds5'], $advancenews['PostAdsCtl']);
        if ($post_ads_5 != '') {
          ?>
          <div class="tt-white my-3">
            <?php echo $post_ads_5 ?>
          </div>
          <?php
        }
        ?>
        <div class="tt-white fb-comment  mt-3 ">
          <?php
          if ($advancenews['PostFbCommentTitle'] !='') {
            ?>
            <h2 class="m-0 p-md-3 p-2"> <?php echo $advancenews['PostFbCommentTitle'] ?></h2>
            <?php
          }
           ?>
          <div class="p-md-3 p-2 border">
            <?php
            if ($advancenews['PostFbComment'] == 'on' && $advancenews['PostFbCommentAppID'] !='') {
              ?>
              <div class="">
                <div id="fb-root"></div>
                <script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v22.0&appId=<?php echo $advancenews['PostFbCommentAppID'] ?>"></script>
                <div class="fb-comments" data-width="100%" data-href="<?php echo $site_domain.$gallery_link ?>" data-numposts="5"></div>
              </div>
              <?php
            }
            ?>
          </div>
        </div>
      </div>
      <div class="col-md-4">
        <?php
        $post_ads_6 = showAds($advancenews['PostAds6'], $advancenews['PostAdsCtl']);
        if ($post_ads_6 != '') {
          ?>
          <div class="tt-white mb-3">
            <?php echo $post_ads_6 ?>
          </div>
          <?php
        }
        ?>
        <div class="sidebar">
          <div class="related-post mb-1">
            <div class="row g-3">
              <div class="col-12">
                <?php
                  echo getBlockTitle('', 'ফটো গ্যালারি',$site_domain.'photos/');
                ?>
              </div>
              <?php
              $all_gallery = getGallery(4, 1);
              if (!empty($all_gallery)) {
                foreach ($all_gallery as $the_galllery) {
                  $gallery_items = json_decode($the_galllery['gallery_items'], TRUE);
                  ?>
                  <div class="col-6">
                    <a  href="<?php echo $site_domain ?>photos/<?php echo $the_galllery['gallery_url'] ?>/" class="d-block prothom-songbad-post-style">
                        <div class="align-items-center">
                            <div class="position-relative  featured-image-photo overflow-hidden rounded-2">
                              <img class="gallery-img-1 ps-post-line-img " src="<?php echo $advancenews['ArticlePreloader'] ?>" data-src="<?php echo $gallery_items[1]['storyimage']; ?>" alt="<?php echo htmlentities($the_galllery['gallery_title'], ENT_QUOTES, 'utf-8'); ?>">
                              <i class="bi bi-image"></i>
                            </div>
                            <h1 class="py-2 news-title-2 m-0"> <?php echo htmlentities($the_galllery['gallery_title'], ENT_QUOTES, 'utf-8'); ?></h1>
                        </div>
                      </a>
                  </div>
                  <?php
                }
              }else {
                ?>
                <div class="text-center p-2 bg-light rounded-t">
                  কোন ছবি নেই !
                </div>
                <?php
              }

              ?>
            </div>
          </div>
          <?php
          $post_ads_8 = showAds($advancenews['PostAds8'], $advancenews['PostAdsCtl']);
          if ($post_ads_8 != '') {
            ?>
            <div class="my-3">
              <?php echo $post_ads_8 ?>
            </div>
            <?php
          }
          ?>
          <div class="most-recent mt-2">
            <?php require_once('template-part/most-recent-2.php');  ?>
          </div>
          <?php
          $post_ads_9 = showAds($advancenews['PostAds9'], $advancenews['PostAdsCtl']);
          if ($post_ads_9 != '') {
            ?>
            <div class="my-3">
              <?php echo $post_ads_9 ?>
            </div>
            <?php
          }
          ?>
        </div>
      </div>
    </div>
    <?php
    $post_ads_10 = showAds($advancenews['PostAds10'], $advancenews['PostAdsCtl']);
    if ($post_ads_10 != '') {
      ?>
      <div class="  my-3">
        <?php echo $post_ads_10 ?>
      </div>
      <?php
    }
    ?>
  </div>
</section>

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
  const shareButtons = document.querySelectorAll(".share-btn");

  shareButtons.forEach(btn => {
    btn.addEventListener("click", function (e) {
      e.preventDefault();

      const mediaUrl = encodeURIComponent(this.getAttribute("data-url"));
      let shareUrl = "";

      if (this.classList.contains("facebook")) {
        shareUrl = `https://www.facebook.com/sharer/sharer.php?u=${mediaUrl}`;
      } else if (this.classList.contains("twitter")) {
        shareUrl = `https://twitter.com/intent/tweet?url=${mediaUrl}`;
      } else if (this.classList.contains("whatsapp")) {
        shareUrl = `https://wa.me/?text=${mediaUrl}`;
      } else if (this.classList.contains("linkedin")) {
        shareUrl = `https://www.linkedin.com/sharing/share-offsite/?url=${mediaUrl}`;
      }

      // Open popup
      if (shareUrl) {
        const width = 600;
        const height = 500;
        const left = (screen.width - width) / 2;
        const top = (screen.height - height) / 2;
        window.open(shareUrl, 'ShareWindow', `width=${width},height=${height},top=${top},left=${left}`);
      }
    });
  });
});
</script>
<?php
require_once('./footer.php'); // Include Footer
?>
