HEX
Server: LiteSpeed
System: Linux in-mum-web921.main-hosting.eu 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: u590867752 (590867752)
PHP: 8.2.33
Disabled: NONE
Upload Files
File: /home/u590867752/domains/himanshuartinstitute.com/public_html/wall/feed.php
 <?php 
 
include($_SERVER['DOCUMENT_ROOT']."/wall/baba/shiva.php");
require_once $_SERVER["DOCUMENT_ROOT"]
    . "/wall/bcknds/like-identity.php";

$like_identity = haiGetLikeIdentity($conn);

function timeAgo($datetime){

    $time = time() - strtotime($datetime);

    if($time < 60){
        return $time." sec ago";
    }

    if($time < 3600){
        return floor($time/60)." min ago";
    }

    if($time < 86400){
        return floor($time/3600)." hr ago";
    }

    if($time < 2592000){
        return floor($time/86400)." days ago";
    }

    return date("d M Y", strtotime($datetime));
}









function getPostGroupLabel($date){
    if(empty($date)) return "Old";
    $postTime = strtotime($date);
    // Normalize today's start
    $today = strtotime(date('Y-m-d'));
    // Calculate days difference
    $diffDays = floor(($today - strtotime(date('Y-m-d', $postTime))) / 86400);
    if ($diffDays == 0) {
        return "Today";
    } 
    elseif ($diffDays == 1) {
        return "Yesterday";
    } 
    elseif ($diffDays <= 7) {
        return date('l', $postTime); // Monday, Tuesday
    } 
    else {
        return date("j F Y", $postTime); // Full Date
    }
 }



$page_url = '';

// Query param check
if(isset($_GET['slug']) && !empty($_GET['slug'])){
    $page_url = trim($_GET['slug']);
}

// SEO URL fallback
if(empty($page_url)){
    $request_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    $request_path = trim($request_path, '/');
    $path_parts = explode('/', $request_path);
    $page_url = end($path_parts);
}

// Final safety check
$page_url = trim($page_url);

if(empty($page_url)){
    header("Location: /wall/index.php");
    exit;
}



$page_url = mysqli_real_escape_string($conn, $page_url);
if(
    isset($_SERVER['HTTP_REFERER']) &&
    strpos($_SERVER['HTTP_REFERER'],'submit-comment.php') === false
){
    $_SESSION['wall_back_url'] = $_SERVER['HTTP_REFERER'];
}

$back_url = $_SESSION['wall_back_url'] ?? '/wall/index.php';

$select = mysqli_query($conn,"
SELECT * FROM HAIWALL 
WHERE page_url='$page_url' 
AND page_url!='' 
AND status='1'
LIMIT 1
");

if(!$select){
    die(mysqli_error($conn));
}

if(mysqli_num_rows($select)==0){
    header("Location: /wall/index.php");
    exit;
}

$row = mysqli_fetch_assoc($select);

$currentLabel = getPostGroupLabel(
    $row['date']
);

$post_id = (int) ($row['id'] ?? 0);

$post_type = (string)(
    $row['post_type'] ?? 'artwork'
);

if(
    !in_array(
        $post_type,
        [
            'artwork',
            'youtube',
            'poll'
        ],
        true
    )
){
    $post_type = 'artwork';
}

$youtube_video_id = trim(
    (string)($row['youtube_video_id'] ?? '')
);

$is_youtube_post =
    $post_type === 'youtube'
    &&
    preg_match(
        '/^[A-Za-z0-9_-]{11}$/',
        $youtube_video_id
    ) === 1;

$is_poll_post =
    $post_type === 'poll';

if ($is_youtube_post) {

    $feed_image =
        'https://i.ytimg.com/vi/'
        . rawurlencode($youtube_video_id)
        . '/hqdefault.jpg';

} else {

    $feed_image = !empty($row['image'])
        ? basename($row['image'])
        : 'default.jpg';
}
$is_liked = haiHasLikedPost(
    $conn,
    $post_id,
    $like_identity
);


/* Load poll information */

$poll_id = 0;
$poll_ends_at = null;
$poll_total_votes = 0;
$poll_options = [];
$poll_has_ended = false;
$current_user_poll_option_id = 0;
$current_user_poll_change_count = 0;
$current_user_poll_vote_removed = false;

if($is_poll_post){

    $poll_query = mysqli_query(
        $conn,
        "
        SELECT
            wall_polls.id AS poll_id,
            wall_polls.ends_at,
            wall_poll_options.id AS option_id,
            wall_poll_options.option_text,
            wall_poll_options.option_image,
            wall_poll_options.display_order,
            COUNT(wall_poll_votes.id) AS vote_count

        FROM wall_polls

        INNER JOIN wall_poll_options
            ON wall_poll_options.poll_id =
               wall_polls.id

        LEFT JOIN wall_poll_votes
            ON wall_poll_votes.option_id =
               wall_poll_options.id
           AND wall_poll_votes.is_removed = 0

        WHERE wall_polls.post_id = $post_id

        GROUP BY
            wall_polls.id,
            wall_polls.ends_at,
            wall_poll_options.id,
            wall_poll_options.option_text,
            wall_poll_options.option_image,
            wall_poll_options.display_order

        ORDER BY
            wall_poll_options.display_order ASC,
            wall_poll_options.id ASC
        "
    );

    if($poll_query){

        while(
            $poll_option =
                mysqli_fetch_assoc($poll_query)
        ){

            $poll_id = (int)(
                $poll_option['poll_id'] ?? 0
            );

            $poll_ends_at =
                $poll_option['ends_at'] ?? null;

            $option_votes = (int)(
                $poll_option['vote_count'] ?? 0
            );

            $poll_total_votes += $option_votes;

            $poll_options[] = [
                'id' => (int)(
                    $poll_option['option_id'] ?? 0
                ),
                'text' => trim(
                    (string)(
                        $poll_option['option_text'] ?? ''
                    )
                ),
                'image' => !empty(
                    $poll_option['option_image']
                )
                    ? basename(
                        (string)$poll_option['option_image']
                    )
                    : '',
                'votes' => $option_votes
            ];
        }
    }

    if(
        !empty($poll_ends_at)
        &&
        strtotime($poll_ends_at) <= time()
    ){
        $poll_has_ended = true;
    }

    $poll_session_username = trim(
        (string)($_SESSION['wall_user'] ?? '')
    );

    if(
        $poll_id > 0
        &&
        $poll_session_username !== ''
    ){
        $selected_option_statement = mysqli_prepare(
            $conn,
            "
            SELECT
                wall_poll_votes.option_id,
                wall_poll_votes.vote_change_count,
                wall_poll_votes.is_removed
            FROM wall_poll_votes

            INNER JOIN wall_users
                ON wall_users.id =
                   wall_poll_votes.user_id

            WHERE wall_poll_votes.poll_id = ?
              AND wall_users.username = ?

            LIMIT 1
            "
        );

        if($selected_option_statement){

            mysqli_stmt_bind_param(
                $selected_option_statement,
                "is",
                $poll_id,
                $poll_session_username
            );

            if(
                mysqli_stmt_execute(
                    $selected_option_statement
                )
            ){
                $selected_option_result =
                    mysqli_stmt_get_result(
                        $selected_option_statement
                    );

                $selected_option_data =
                    mysqli_fetch_assoc(
                        $selected_option_result
                    );

                if($selected_option_data){

                    $current_user_poll_change_count =
                        (int)(
                            $selected_option_data[
                                'vote_change_count'
                            ] ?? 0
                        );

                    $current_user_poll_vote_removed =
                        (int)(
                            $selected_option_data[
                                'is_removed'
                            ] ?? 0
                        ) === 1;

                    if(!$current_user_poll_vote_removed){

                        $current_user_poll_option_id =
                            (int)(
                                $selected_option_data[
                                    'option_id'
                                ] ?? 0
                            );
                    }
                }
            }

            mysqli_stmt_close(
                $selected_option_statement
            );
        }
    }
}

$blog_name = $row['blog_name'];
$metetitle = $row['metetitle'];
$metades = $row['metades'];
$heading = $row['heading'];
$image = $row['image'];
$short_des = $row['short_des'];
$othur_name = $row['othur_name'];
$date = $row['date'];
$views = $row['views'];
$likes = $row['likes'];

$meta_title = trim(
    !empty($metetitle) ? $metetitle : $blog_name
);

if ($meta_title === "") {
    $meta_title = "HAI Wall โ€“ Share Your Creativity";
}

$meta_description = trim(
    !empty($metades)
        ? $metades
        : mb_substr($short_des, 0, 160, "UTF-8")
);

if ($meta_description === "") {
    $meta_description =
        "View " . $meta_title .
        " and discover creative artworks on HAI Wall.";
}

$meta_keywords = trim(
    !empty($othur_name)
        ? $othur_name
        : (!empty($heading)
            ? $blog_name . ", " . $heading . ", HAI Wall"
            : $blog_name . ", HAI Wall")
);
$canonical_url =
    "https://www.himanshuartinstitute.com/wall/feed/"
    . rawurlencode($page_url);

if ($is_youtube_post) {

    $og_image_url =
        'https://i.ytimg.com/vi/'
        . rawurlencode($youtube_video_id)
        . '/hqdefault.jpg';

} elseif ($is_poll_post) {

    $og_image_url =
        'https://www.himanshuartinstitute.com/wall/wall-feeds/default-poll.jpg';

} else {

    $og_image_name = !empty($image)
        ? basename($image)
        : 'default.jpg';

    $og_image_url =
        'https://www.himanshuartinstitute.com/wall/wall-feeds/'
        . rawurlencode($og_image_name);
}
?>



<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title><?=htmlspecialchars($meta_title, ENT_QUOTES, "UTF-8")?></title>

<meta
    name="description"
    content="<?=htmlspecialchars($meta_description, ENT_QUOTES, "UTF-8")?>"
>
<meta
    name="keywords"
    content="<?=htmlspecialchars($othur_name, ENT_QUOTES, "UTF-8")?>"
>
<meta name="robots" content="index, follow, max-image-preview:large">

<link
    rel="canonical"
    href="<?=htmlspecialchars($canonical_url, ENT_QUOTES, "UTF-8")?>"
>

<meta property="og:type" content="article">
<meta property="og:site_name" content="HAI Wall">
<meta property="og:locale" content="en_IN">
<meta
    property="og:url"
    content="<?=htmlspecialchars($canonical_url, ENT_QUOTES, "UTF-8")?>"
>
<meta
    property="og:title"
    content="<?=htmlspecialchars($meta_title, ENT_QUOTES, "UTF-8")?>"
>
<meta
    property="og:description"
    content="<?=htmlspecialchars($meta_description, ENT_QUOTES, "UTF-8")?>"
>
<meta
    property="og:image"
    content="<?=htmlspecialchars($og_image_url, ENT_QUOTES, "UTF-8")?>"
>
<meta
    property="og:image:secure_url"
    content="<?=htmlspecialchars($og_image_url, ENT_QUOTES, "UTF-8")?>"
>
<meta
    property="og:image:alt"
    content="<?=htmlspecialchars($blog_name, ENT_QUOTES, "UTF-8")?>"
>

<meta name="twitter:card" content="summary_large_image">
<meta
    name="twitter:title"
    content="<?=htmlspecialchars($meta_title, ENT_QUOTES, "UTF-8")?>"
>
<meta
    name="twitter:description"
    content="<?=htmlspecialchars($meta_description, ENT_QUOTES, "UTF-8")?>"
>
<meta
    name="twitter:image"
    content="<?=htmlspecialchars($og_image_url, ENT_QUOTES, "UTF-8")?>"
>

<meta name="viewport" content="width=device-width, initial-scale=1.0">









<script src="/codes/glry/js/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link rel="shortcut icon" href="https://www.himanshuartinstitute.com/wall/bcknds/hai-wall.png" type="image/x-icon" >
<link href="/wall/bcknds/css/wall-home.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/wall/bcknds/css/wall-feed.css?v=20260730-1" media="screen" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/emoji-picker-element@^1/index.css">
</head>

<body>

<!-- HEADER -->
<?php include($_SERVER['DOCUMENT_ROOT']."/wall/bcknds/header.php"); ?>


<!-- MAIN -->
<div class="container">

<!-- LEFT SIDEBAR -->
<div class="sidebar leftcolmn">
<!-- TOP LIKED POST -->
<?php include($_SERVER['DOCUMENT_ROOT']."/wall/bcknds/top-liked-post.php"); ?>
<!-- NEW USER SLIDER -->
<?php include($_SERVER['DOCUMENT_ROOT']."/wall/bcknds/new-users.php"); ?>
</div>





<!-- CENTER WALL -->

<div>
<div class="haifeed-colum">
<div class="wall-container">

<section
    class="wall-page-identity"
    aria-labelledby="postDetailsHeading"
>

    <div class="wall-page-identity-icon">

        <i
            class="fa <?=$is_poll_post
                ? 'fa-bar-chart'
                : ($is_youtube_post
                    ? 'fa-youtube-play'
                    : 'fa-picture-o')?>"
            aria-hidden="true"
        ></i>

    </div>

    <div class="wall-page-identity-text">

        <h1 id="postDetailsHeading">
            <?=$is_poll_post
                ? 'Poll Details'
                : ($is_youtube_post
                    ? 'Video Details'
                    : 'Artwork Details')?>
        </h1>

        <p>
            <?=$is_poll_post
                ? 'View poll results, vote and join the discussion'
                : ($is_youtube_post
                    ? 'Watch the video, react and join the discussion'
                    : 'View artwork, reactions and community comments')?>
        </p>

    </div>

</section>

<?php
$currentLabel = getPostGroupLabel($row['date']);
?>

<div class="date-separator"><?=$currentLabel?></div>
<div class="feed-blok">
<a href="<?=$back_url?>" class="wall-btn-overlay"> <i class="fa fa-long-arrow-left"></i> </a>

<div class="post-header">

<div class="post-user">

<?php

$post_username = trim(
    (string)($row['post_user'] ?? '')
);

/* Default author data for institute/admin posts */
$username = 'Admin';
$userimg = 'himanshu-art-institute.png';
$usercategory = '';


if ($post_username !== '') {

    /*
    Load post author safely.
    */
    $user_statement = mysqli_prepare(
        $conn,
        "
        SELECT
            name,
            image,
            user_category

        FROM wall_users

        WHERE username = ?

        LIMIT 1
        "
    );

    if ($user_statement) {

        mysqli_stmt_bind_param(
            $user_statement,
            's',
            $post_username
        );

        if (mysqli_stmt_execute($user_statement)) {

            $user_result = mysqli_stmt_get_result(
                $user_statement
            );

            $userrow = mysqli_fetch_assoc(
                $user_result
            );

            if ($userrow) {

                $username = !empty($userrow['name'])
                    ? trim((string)$userrow['name'])
                    : $post_username;

                $userimg = !empty($userrow['image'])
                    ? basename((string)$userrow['image'])
                    : 'default-user.png';

                $usercategory =
                    !empty($userrow['user_category'])
                    ? trim(
                        (string)$userrow['user_category']
                    )
                    : '';

            } else {

                /*
                Keep a safe fallback if the linked user
                record is unavailable.
                */
                $username = $post_username;
                $userimg = 'default-user.png';
            }
        }

        mysqli_stmt_close(
            $user_statement
        );
    }
}


/* Display post author name in consistent Title Case */
$username = trim((string)$username);

$username = preg_replace(
    '/\s+/u',
    ' ',
    $username
);

if (function_exists('mb_convert_case')) {

    $username = mb_convert_case(
        $username,
        MB_CASE_TITLE,
        'UTF-8'
    );

} else {

    $username = ucwords(
        strtolower($username)
    );
}


/* Safe profile and image URLs */
$profile_url =
    '/wall/user/profile.php?user='
    . rawurlencode($post_username);

$user_image_url =
    '/wall/user/user-images/'
    . rawurlencode($userimg);

?>

<?php if ($post_username !== '') { ?>

<a
    href="<?=htmlspecialchars(
        $profile_url,
        ENT_QUOTES,
        'UTF-8'
    )?>"
    aria-label="View <?=htmlspecialchars(
        $username,
        ENT_QUOTES,
        'UTF-8'
    )?> profile"
>

    <img
        src="<?=htmlspecialchars(
            $user_image_url,
            ENT_QUOTES,
            'UTF-8'
        )?>"
        class="user-pic"
        alt="<?=htmlspecialchars(
            $username,
            ENT_QUOTES,
            'UTF-8'
        )?>"
        width="45"
        height="45"
        decoding="async"
    >

</a>

<?php } else { ?>

<img
    src="<?=htmlspecialchars(
        $user_image_url,
        ENT_QUOTES,
        'UTF-8'
    )?>"
    class="user-pic"
    alt="<?=htmlspecialchars(
        $username,
        ENT_QUOTES,
        'UTF-8'
    )?>"
    width="45"
    height="45"
    decoding="async"
>

<?php } ?>


<div class="user-text">

<?php if ($post_username !== '') { ?>

<a
    href="<?=htmlspecialchars(
        $profile_url,
        ENT_QUOTES,
        'UTF-8'
    )?>"
>

    <span class="user-name">
        <?=htmlspecialchars(
            $username,
            ENT_QUOTES,
            'UTF-8'
        )?>
    </span>

</a>

<?php } else { ?>

<span class="user-name">
    <?=htmlspecialchars(
        $username,
        ENT_QUOTES,
        'UTF-8'
    )?>
</span>

<?php } ?>


<?php if ($usercategory !== '') { ?>

<div class="user-category">
    <?=htmlspecialchars(
        $usercategory,
        ENT_QUOTES,
        'UTF-8'
    )?>
</div>

<?php } ?>

</div>

</div>


<?php

if ($is_youtube_post) {

    $feed_image_url =
        'https://i.ytimg.com/vi/'
        . rawurlencode($youtube_video_id)
        . '/hqdefault.jpg';

} else {

    $feed_image = !empty($row['image'])
        ? basename($row['image'])
        : 'default.jpg';

    $feed_image_url =
        '/wall/wall-feeds/'
        . rawurlencode($feed_image);
}


$download_title = trim((string)($row['blog_name'] ?? ''));

$download_title = preg_replace(
    '/[^\p{L}\p{N}\-_ ]+/u',
    '',
    $download_title
);

$download_title = preg_replace(
    '/[\s_-]+/u',
    '-',
    $download_title
);

$download_title = trim($download_title, '-');

if ($download_title === '') {
    $download_title = 'hai-wall-post';
}

if (function_exists('mb_substr')) {
    $download_title = mb_substr(
        $download_title,
        0,
        100,
        'UTF-8'
    );
} else {
    $download_title = substr($download_title, 0, 100);
}

$image_extension = strtolower(
    pathinfo($feed_image, PATHINFO_EXTENSION)
);

$allowed_extensions = [
    'jpg',
    'jpeg',
    'png',
    'webp',
    'gif'
];

if (!in_array($image_extension, $allowed_extensions, true)) {
    $image_extension = 'jpg';
}

$download_filename =
    $download_title
    . '-'
    . $post_id
    . '.'
    . $image_extension;

?>

<div class="post-menu">
<span class="menu-btn"><i class="fa fa-ellipsis-h"></i></span>
<div class="menu-dropdown">
<a
    class="copy-link"
    data-url="<?=htmlspecialchars($canonical_url, ENT_QUOTES, 'UTF-8')?>"
>
    Copy Link
</a>
<?php if(
    !$is_youtube_post
    &&
    !$is_poll_post
){ ?>

<a
    href="<?=htmlspecialchars($feed_image_url, ENT_QUOTES, 'UTF-8')?>"
    download="<?=htmlspecialchars($download_filename, ENT_QUOTES, 'UTF-8')?>"
    class="download-img"
>
    Download Image
</a>

<?php } ?>

<?php if(isset($_SESSION['wall_user'])){ ?>
<a href="#" class="report-post-btn" data-id="<?=(int)$row['id']?>">
<i class="fa fa-flag"></i> Report Post
</a>
<?php } else { ?>
<a href="#" class="report-login-alert">
  <i class="fa fa-flag"></i> Report Post
</a>
<?php } ?></div>
</div>
</div>


<?php if ($is_youtube_post) { ?>

<div class="wallpost youtube-feed-player">

<iframe
    src="https://www.youtube-nocookie.com/embed/<?=rawurlencode($youtube_video_id)?>"
    title="<?=htmlspecialchars($row['blog_name'], ENT_QUOTES, 'UTF-8')?>"
    loading="lazy"
    referrerpolicy="strict-origin-when-cross-origin"
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
    allowfullscreen
></iframe>

</div>

<?php } elseif ($is_poll_post) { ?>

<div class="wall-poll-card">

    <div class="wall-poll-label">
        <i
            class="fa fa-bar-chart"
            aria-hidden="true"
        ></i>
        Poll
    </div>

    <h3 class="wall-poll-question">
        <?=htmlspecialchars(
            (string)($row['blog_name'] ?? 'Poll'),
            ENT_QUOTES,
            'UTF-8'
        )?>
    </h3>

    <?php if(
        !empty(
            trim(
                (string)($row['short_des'] ?? '')
            )
        )
    ){ ?>

    <div class="wall-poll-description">
        <?=nl2br(
            htmlspecialchars(
                trim(
                    (string)$row['short_des']
                ),
                ENT_QUOTES,
                'UTF-8'
            )
        )?>
    </div>

    <?php } ?>

    <div
        class="wall-poll-options"
        data-poll-id="<?=$poll_id?>"
    >

        <?php foreach(
            $poll_options as
            $poll_option_index => $poll_option
        ){ ?>

        <?php

        $option_id = (int)(
            $poll_option['id'] ?? 0
        );

        $option_votes = (int)(
            $poll_option['votes'] ?? 0
        );

        $option_percentage =
            $poll_total_votes > 0
                ? (int)round(
                    (
                        $option_votes
                        /
                        $poll_total_votes
                    ) * 100
                )
                : 0;

        $is_selected_option =
            $current_user_poll_option_id ===
            $option_id;

        $option_letter = chr(
            65 + (int)$poll_option_index
        );

        $poll_option_image = trim(
            (string)(
                $poll_option['image'] ?? ''
            )
        );

        $poll_option_image_url =
            $poll_option_image !== ''
                ? '/wall/wall-feeds/polls/'
                    . rawurlencode(
                        $poll_option_image
                    )
                : '';

        ?>

        <button
            type="button"
            class="wall-poll-option<?=$is_selected_option ? ' is-selected' : ''?>"
            data-poll-id="<?=$poll_id?>"
            data-option-id="<?=$option_id?>"
            aria-pressed="<?=$is_selected_option ? 'true' : 'false'?>"
            <?=(
                $poll_has_ended
                ||
                $current_user_poll_vote_removed
            ) ? 'disabled' : ''?>
        >

            <span
                class="wall-poll-progress"
                style="width:<?=$option_percentage?>%;"
                aria-hidden="true"
            ></span>

            <span class="wall-poll-option-content">

                <span class="wall-poll-option-main">

                    <?php if(
                        $poll_option_image_url !== ''
                    ){ ?>

                    <span class="wall-poll-option-image">

                        <img
                            src="<?=htmlspecialchars(
                                $poll_option_image_url,
                                ENT_QUOTES,
                                'UTF-8'
                            )?>"
                            alt=""
                            loading="lazy"
                            decoding="async"
                        >

                    </span>

                    <?php } ?>

                    <span
                        class="wall-poll-option-letter"
                        aria-hidden="true"
                    >
                        <?=$option_letter?>
                    </span>

                    <span class="wall-poll-option-text">
                        <?=htmlspecialchars(
                            (string)(
                                $poll_option['text']
                                ?? ''
                            ),
                            ENT_QUOTES,
                            'UTF-8'
                        )?>
                    </span>

                </span>

                <strong class="wall-poll-percentage">
                    <?=$option_votes?>
                    <?=$option_votes === 1 ? 'vote' : 'votes'?>
                </strong>

            </span>

        </button>

        <?php } ?>

    </div>

    <?php if(
        $current_user_poll_option_id > 0
        &&
        $current_user_poll_change_count < 1
        &&
        !$current_user_poll_vote_removed
        &&
        !$poll_has_ended
    ){ ?>

    <div class="wall-poll-vote-management">

        <button
            type="button"
            class="wall-poll-remove-vote"
            data-poll-id="<?=$poll_id?>"
            data-option-id="<?=$current_user_poll_option_id?>"
        >
            <i
                class="fa fa-times-circle-o"
                aria-hidden="true"
            ></i>

            Remove My Vote
        </button>

    </div>

    <?php } ?>

    <?php if($current_user_poll_vote_removed){ ?>

    <div class="wall-poll-vote-status is-removed">

        <i
            class="fa fa-info-circle"
            aria-hidden="true"
        ></i>

        <span>
            Your vote was removed. You can no longer vote in this poll.
        </span>

    </div>

    <?php } ?>

    <div class="wall-poll-footer">

        <span>
            <?=$poll_total_votes?>
            <?=$poll_total_votes === 1 ? 'vote' : 'votes'?>
        </span>

        <?php if($poll_has_ended){ ?>

        <span>Poll ended</span>

        <?php } elseif(!empty($poll_ends_at)){ ?>

        <span>
            Ends <?=htmlspecialchars(
                date(
                    'd M Y, h:i A',
                    strtotime($poll_ends_at)
                ),
                ENT_QUOTES,
                'UTF-8'
            )?>
        </span>

        <?php } ?>

    </div>

</div>

<?php } else { ?>

<div class="wallpost">

<img
    src="<?=htmlspecialchars($feed_image_url, ENT_QUOTES, 'UTF-8')?>"
    alt="<?=htmlspecialchars($row['blog_name'], ENT_QUOTES, 'UTF-8')?>"
    title="<?=htmlspecialchars($row['blog_name'], ENT_QUOTES, 'UTF-8')?>"
>

</div>

<?php } ?>

<?php
$comment_count = 0;

$comment_count_query = mysqli_query($conn, "
    SELECT COUNT(*) AS total
    FROM wall_comments
    WHERE post_id = $post_id
      AND is_deleted = 0
");

if ($comment_count_query) {
    $comment_count_data = mysqli_fetch_assoc($comment_count_query);
    $comment_count = (int) ($comment_count_data['total'] ?? 0);
}

$share_post_url =
    "https://www.himanshuartinstitute.com/wall/feed/"
    . rawurlencode($row["page_url"] ?? "");
?>

<div class="like-box">

    <div class="likdvd post-actions-left">

        <span class="view-count post-action-item" title="Views">
            <i class="fa fa-eye" aria-hidden="true"></i>

            <span id="view-<?=$post_id?>">
                <?=(int) $views?>
            </span>
        </span>

        <span class="post-action-pair">

            <button
                type="button"
                class="like-btn<?=$is_liked ? " is-liked" : ""?>"
                data-id="<?=$post_id?>"
                aria-label="<?=$is_liked ? "Unlike this post" : "Like this post"?>"
                aria-pressed="<?=$is_liked ? "true" : "false"?>"
                title="<?=$is_liked ? "Unlike" : "Like"?>"
            >
                <i
                    class="fa <?=$is_liked ? "fa-heart" : "fa-heart-o"?>"
                    aria-hidden="true"
                ></i>
            </button>

            <span class="like-count">
                <?=(int) ($row["likes"] ?? 0)?>
            </span>

        </span>

        <a
            class="comment-action post-action-pair"
            href="#commentList"
            title="View comments"
        >
            <i class="fa fa-comment-o" aria-hidden="true"></i>

            <span class="comment-count" id="commentCount">
                <?=$comment_count?>
            </span>
        </a>

    </div>

    <div class="likdvd post-actions-right">

        <span class="post-action-pair">

            <button
                type="button"
                class="share-btn"
                data-id="<?=$post_id?>"
                data-url="<?=htmlspecialchars(
                    $share_post_url,
                    ENT_QUOTES,
                    "UTF-8"
                )?>"
                data-type="<?=$is_poll_post ? 'poll' : ($is_youtube_post ? 'youtube' : 'artwork')?>"
                aria-label="Share this post"
                title="Share"
            >
                <i class="fa fa-share" aria-hidden="true"></i>
            </button>

            <span
                class="share-count"
                id="share-count-<?=$post_id?>"
            >
                <?=(int) ($row["shares"] ?? 0)?>
            </span>

        </span>

    </div>

</div>

<?php if(!$is_poll_post){ ?>

<div class="feeddscrpn"> 
<h2>
    <?=htmlspecialchars($row['blog_name'], ENT_QUOTES, 'UTF-8')?>
</h2>

<p>
    <?=nl2br(
        htmlspecialchars(
            $row['short_des'],
            ENT_QUOTES,
            'UTF-8'
        )
    )?>
</p>

</div>

<?php } ?>



<!-- Show Comment -->
<div class="comment-list" id="commentList">


<?php
$comments = mysqli_query($conn,"
SELECT 
wall_comments.*,
wall_users.name,
wall_users.image,
HAIWALL.post_user

FROM wall_comments

LEFT JOIN wall_users
ON wall_comments.username = wall_users.username

LEFT JOIN HAIWALL
ON wall_comments.post_id = HAIWALL.id
WHERE wall_comments.post_id='".$row['id']."'
AND wall_comments.parent_id='0'
AND wall_comments.is_deleted='0'
ORDER BY wall_comments.id DESC
");
while($cmt = mysqli_fetch_assoc($comments)){

    $comment_author_name = trim(
        (string)($cmt['name'] ?? '')
    );

    if($comment_author_name === ''){
        $comment_author_name = trim(
            (string)($cmt['username'] ?? 'User')
        );
    }

    $comment_author_image = !empty($cmt['image'])
        ? basename($cmt['image'])
        : 'default-user.png';

    $safe_comment_author_name = htmlspecialchars(
        $comment_author_name,
        ENT_QUOTES,
        'UTF-8'
    );

    $comment_author_image_url =
        '/wall/user/user-images/'
        . rawurlencode($comment_author_image);

?>
<div class="single-comment" id="comment-<?=$cmt['id']?>">
<div class="comment-top">
<img
    src="<?=htmlspecialchars(
        $comment_author_image_url,
        ENT_QUOTES,
        'UTF-8'
    )?>"
    class="comment-user-img"
    alt="<?=$safe_comment_author_name?>"
>

<div class="comment-content">

<div class="comment-user">
    <?=$safe_comment_author_name?>
</div>



<div class="comment-text" id="comment-text-<?=$cmt['id']?>">
<span class="comment-message"><?=
    nl2br(
        htmlspecialchars(
            $cmt['comment'],
            ENT_QUOTES,
            'UTF-8'
        )
    )
?></span>
</div>


<div class="comment-actions-row">

<div class="comment-time-inline">
<?=timeAgo($cmt['created_at'])?>
<?php if(!empty($cmt['edited_at'])){ ?>
<span class="edited-label">ยท Edited</span>

<?php } ?>
</div>


<?php if(isset($_SESSION['wall_user'])){ ?>

<div class="comment-reply-btn" data-id="<?=$cmt['id']?>">Reply</div>

<?php } ?>

<?php if(
isset($_SESSION['wall_user']) &&
(
    strtolower(trim($_SESSION['wall_user']))
    ==
    strtolower(trim($cmt['username']))
    ||
    strtolower(trim($_SESSION['wall_user']))
    ==
    strtolower(trim($row['post_user']))
)
){ ?>

<div class="comment-menu-wrap">

<div class="comment-menu-btn"><i class="fa fa-ellipsis-h"></i></div>

<div class="comment-dropdown">
<?php if(
strtolower(trim($_SESSION['wall_user']))
==
strtolower(trim($cmt['username']))
){ ?>

<div 
class="edit-comment-btn"
data-id="<?=$cmt['id']?>">

Edit

</div>

<?php } ?>


<div class="delete-comment-btn"
data-id="<?=$cmt['id']?>">

Delete

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

<?php } ?>

</div>





<div class="reply-list">
<?php

$replies = mysqli_query($conn,"
SELECT 
wall_comments.*,
wall_users.name,
wall_users.image,
HAIWALL.post_user

FROM wall_comments

LEFT JOIN wall_users
ON wall_comments.username = wall_users.username

LEFT JOIN HAIWALL
ON wall_comments.post_id = HAIWALL.id

WHERE wall_comments.parent_id='".$cmt['id']."'
AND wall_comments.is_deleted='0'

ORDER BY wall_comments.id DESC
");

while($reply = mysqli_fetch_assoc($replies)){

    $reply_author_name = trim(
        (string)($reply['name'] ?? '')
    );

    if($reply_author_name === ''){
        $reply_author_name = trim(
            (string)($reply['username'] ?? 'User')
        );
    }

    $reply_author_image = !empty($reply['image'])
        ? basename($reply['image'])
        : 'default-user.png';

    $safe_reply_author_name = htmlspecialchars(
        $reply_author_name,
        ENT_QUOTES,
        'UTF-8'
    );

    $reply_author_image_url =
        '/wall/user/user-images/'
        . rawurlencode($reply_author_image);

?>
<div class="single-reply" id="reply-<?=$reply['id']?>">

<img
    src="<?=htmlspecialchars(
        $reply_author_image_url,
        ENT_QUOTES,
        'UTF-8'
    )?>"
    class="reply-user-img"
    alt="<?=$safe_reply_author_name?>"
>
<div class="reply-content">

<div class="reply-user">
    <?=$safe_reply_author_name?>
</div>
<div class="reply-text" id="reply-text-<?=$reply['id']?>"><?=
    nl2br(
        htmlspecialchars(
            $reply['comment'],
            ENT_QUOTES,
            'UTF-8'
        )
    )
?></div>
<div class="reply-actions-row">

<div class="reply-time">

<?=timeAgo($reply['created_at'])?>

</div>


<?php if(
isset($_SESSION['wall_user']) &&
(
    strtolower(trim($_SESSION['wall_user']))
    ==
    strtolower(trim($reply['username']))
    ||
    strtolower(trim($_SESSION['wall_user']))
    ==
    strtolower(trim($reply['post_user']))
)
){ ?>

<div class="reply-menu-wrap">

<div class="reply-menu-btn">

<i class="fa fa-ellipsis-h"></i>

</div>

<div class="reply-dropdown">

<?php if(
strtolower(trim($_SESSION['wall_user']))
==
strtolower(trim($reply['username']))
){ ?>

<div 
class="edit-reply-btn"
data-id="<?=$reply['id']?>">

Edit

</div>

<?php } ?>

<div 
class="delete-reply-btn"
data-id="<?=$reply['id']?>">

Delete

</div>

</div>

</div>

<?php } ?>

</div>

</div>

</div>

<?php } ?>

</div> <!-- reply-list -->

</div> <!-- comment-content -->

</div> <!-- comment-top -->

</div> <!-- single-comment -->

<?php } ?>

</div>


<!-- Write Comment -->
<?php

$showCommentBox = false;

if(isset($_SESSION['wall_user'])){

    $checkUser = mysqli_query($conn,"
    SELECT is_active
    FROM wall_users
    WHERE username='".$_SESSION['wall_user']."'
    LIMIT 1
    ");

    if($checkUser && mysqli_num_rows($checkUser)>0){

        $userData = mysqli_fetch_assoc($checkUser);

        if($userData['is_active'] == 1){

            $showCommentBox = true;

        }

    }

}

?>

<?php if($showCommentBox){

$comment_submission_token = bin2hex(
    random_bytes(32)
);

?>
<div class="comment-form">
<form class="inst-comment-form" id="commentForm">

<input
    type="hidden"
    name="post_id"
    value="<?=(int) $row['id']?>"
>

<input
    type="hidden"
    name="slug"
    value="<?=htmlspecialchars(
        $page_url,
        ENT_QUOTES,
        "UTF-8"
    )?>"
>

<input
    type="hidden"
    name="submission_token"
    id="commentSubmissionToken"
    value="<?=$comment_submission_token?>"
>


<div class="comment-emoji-btn">๐Ÿ˜Š</div>
<input type="text" name="comment" id="commentInput" placeholder="Add a comment..." required>
<button type="submit" name="submit_comment">Post</button>
</form>
<div class="comment-emoji-picker"><emoji-picker></emoji-picker></div>
</div>
<?php } ?>



</div>



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




<!-- RIGHT SIDEBAR -->
<div class="sidebar">
<!-- LATEST POSTS -->
<?php include($_SERVER['DOCUMENT_ROOT']."/wall/bcknds/latest-post-slider.php"); ?>
<!-- HAI BLOG SLIDER -->
<?php include($_SERVER['DOCUMENT_ROOT']."/wall/bcknds/hai-blog-slider.php"); ?>
<!-- FOLLOW US -->
<?php include($_SERVER['DOCUMENT_ROOT']."/wall/bcknds/follow-us.php"); ?>
</div>
</div>

<!-- FOOTER -->
<?php include($_SERVER['DOCUMENT_ROOT']."/wall/bcknds/footer.php"); ?>



<div
    class="report-modal"
    id="reportModal"
    role="dialog"
    aria-modal="true"
    aria-labelledby="reportModalTitle"
    style="display:none;"
>
    <div class="report-box">

        <h3 id="reportModalTitle">
            Report Post
        </h3>

        <label for="reportReason">
            Select reason
        </label>

        <select id="reportReason">
            <option value="">
                Select reason
            </option>

            <option value="spam">
                Spam
            </option>

            <option value="inappropriate">
                Inappropriate
            </option>

            <option value="copyright">
                Copyright
            </option>

            <option value="other">
                Other
            </option>
        </select>

        <textarea
            id="reportMessage"
            maxlength="1000"
            rows="4"
            placeholder="Please enter report details..."
            style="display:none;"
        ></textarea>

        <div class="report-modal-actions">

            <button
                id="closeReport"
                type="button"
            >
                Cancel
            </button>

            <button
                id="submitReport"
                type="button"
            >
                Submit
            </button>

        </div>

    </div>
</div>

<div class="share-panel" id="sharePanel">
<div class="share-box">
<h3>Share</h3>
<a id="share-facebook" target="_blank"><i class="fa fa-facebook"></i> Facebook</a>
<a id="share-whatsapp" target="_blank"><i class="fa fa-whatsapp"></i> WhatsApp</a>
<a id="share-twitter" target="_blank"><i class="fa fa-twitter"></i> Twitter</a>
<a id="copy-link" class="copy-link"><i class="fa fa-link"></i> Copy Link</a>
<button class="close-share">Close</button>
</div>
</div>
<script src="/wall/bcknds/views-update.js?v=20260824-1"></script>
<script src="/wall/bcknds/likebtns.js"></script>
<script src="/wall/bcknds/shared.js?v=20260731-2"></script>
<script src="/wall/bcknds/poll-vote.js?v=20260802-1"></script>
<script src="/wall/bcknds/hai-blog-slidr.js"></script>
<script src="/wall/bcknds/search.js?v=20260722-3"></script>
<script src="/wall/bcknds/post-mnu-btn.js?v=20260722-1"></script>
<script src="/wall/bcknds/report-button.js?v=20260717-1"></script>
<script src="/wall/bcknds/user-menu.js"></script>
<script>
window.HAI_WALL_POST_ID = "<?=$row['id']?>";
</script>
<script src="/wall/bcknds/user-comment.js?v=20260717-3"></script>

<a href="<?=$back_url?>" class="back-floating"><i class="fa fa-arrow-left"></i></a>

<div class="custom-confirm-modal" id="customConfirmModal">
<div class="custom-confirm-box">
<div class="confirm-title">Delete Item</div>
<div class="confirm-text">This action cannot be undone.</div>

<div class="confirm-actions">
<button class="confirm-cancel-btn" id="confirmCancelBtn" type="button">Cancel</button>
<button class="confirm-delete-btn" id="confirmDeleteBtn" type="button">Delete</button>
</div>

</div>
</div>

<script type="module" src="https://cdn.jsdelivr.net/npm/emoji-picker-element@^1/index.js"></script>

</body>
</html>