File: /home/nyiet8349bzl/www/oldwebsite.sbsc.in/wp-content/plugins/Newnoticeboard/includes/functions.php
<?php
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
// Get notices from uploads folder and their metadata
function enb_get_notices() {
$upload_dir = plugin_dir_path(dirname(__FILE__)) . 'uploads/';
$files = glob($upload_dir . '*.{pdf,jpg,jpeg,png}', GLOB_BRACE);
$notices = [];
foreach ($files as $file_path) {
$file_name = basename($file_path);
$base_name = pathinfo($file_name, PATHINFO_FILENAME);
$meta_file = $upload_dir . $base_name . '.json';
if (file_exists($meta_file)) {
$meta = json_decode(file_get_contents($meta_file), true);
if (is_array($meta)) {
$meta['file'] = plugin_dir_url(dirname(__FILE__)) . 'uploads/' . $file_name;
$notices[] = $meta;
}
}
}
return $notices;
}
// Display notices using shortcode
function enb_display_notices() {
$notices = enb_get_notices();
ob_start();
echo '<div class="enb-notice-scroll-container">';
echo '<ul class="enb-notice-list">';
if (!empty($notices)) {
foreach ($notices as $notice) {
echo '<li>';
echo '<a href="' . esc_url($notice['file']) . '" target="_blank">' . esc_html($notice['title']) . '</a>';
echo '</li>';
}
} else {
echo '<li>No notices available.</li>';
}
echo '</ul>';
echo '</div>';
return ob_get_clean();
}